text
stringlengths
1
1.05M
MODULE MDATAP0 INTERMISION_PATTERNS_0 incbin "intermission_0.til" INTERMISION_COLORS_0 incbin "intermission_0.col" INTERMISION_PATTERNS_1 incbin "intermission_1.til" INTERMISION_COLORS_1 incbin "intermission_1.col" INTERMISION_PATTERNS_2 incbin "intermission_2.til" INTERMISION_COLORS_2 incbin "intermission_2.col" INTRO_PATTERNS_0 incbin "intro_0.til" INTRO_COLORS_0 incbin "intro_0.col" INTRO_PATTERNS_1 incbin "intro_1.til" INTRO_COLORS_1 incbin "intro_1.col" INTRO_PATTERNS_2 incbin "intro_2.til" INTRO_COLORS_2 incbin "intro_2.col" COMMON_ENDING_COLORS_1 incbin "common_ending_1.col" COMMON_ENDING_PATTERNS_1 incbin "common_ending_1.til" GOOD_ENDING_COLORS_2 incbin "good_ending_2.col" GOOD_ENDING_PATTERNS_2 incbin "good_ending_2.til" BAD_ENDING_COLORS_2 incbin "bad_ending_2.col" BAD_ENDING_PATTERNS_2 incbin "bad_ending_2.til" HALF_QUEST_COLORS_0 incbin "half_quest_0.col" HALF_QUEST_PATTERNS_0 incbin "half_quest_0.til" HALF_QUEST_COLORS_1 incbin "half_quest_1.col" HALF_QUEST_PATTERNS_1 incbin "half_quest_1.til" ALPHABET_COLORS incbin "alphabet.col" ALPHABET_PATTERNS incbin "alphabet.til" BLUE_HOUSES_COLOR incbin "tileset_blue.col" BLUE_HOUSES_PATTERNS incbin "tileset_blue.til" STAFF_PATTERNS incbin "staff.til" STAFF_COLORS incbin "staff.col" STAFF_TILES incbin "staff.scr" ENDMODULE
; A124388: 27*n+18. ; 18,45,72,99,126,153,180,207,234,261,288,315,342,369,396,423,450,477,504,531,558,585,612,639,666,693,720,747,774,801,828,855,882,909,936,963,990,1017,1044,1071,1098,1125,1152,1179,1206,1233,1260,1287,1314,1341,1368,1395,1422,1449,1476,1503,1530,1557,1584,1611,1638,1665,1692,1719,1746,1773,1800,1827,1854,1881,1908,1935,1962,1989,2016,2043,2070,2097,2124,2151,2178,2205,2232,2259,2286,2313,2340,2367,2394,2421,2448,2475,2502,2529,2556,2583,2610,2637,2664,2691 mul $0,27 add $0,18
/* +----------------------------------------------------------------------+ | HipHop for PHP | +----------------------------------------------------------------------+ | Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ */ #include "hphp/util/maphuge.h" #include "hphp/util/kernel-version.h" #include <unistd.h> #include <sys/mman.h> namespace HPHP { void hintHuge(void* mem, size_t length) { #ifdef MADV_HUGEPAGE if (hugePagesSupported()) { madvise(mem, length, MADV_HUGEPAGE); } #endif } bool hugePagesSupported() { #ifdef MADV_HUGEPAGE static KernelVersion kv; // This kernel fixed a panic when using MADV_HUGEPAGE. static KernelVersion minKv("3.2.28-72_fbk12"); return KernelVersion::cmp(kv, minKv); #else return false; #endif } }
#pragma once constexpr auto DEFAULT_DESC = "Have fun coding, put in your project's description here."; constexpr auto README_CMAKE_BOILERPLATE = "${{CPPROJ_PROJECT_NAME}}\n" "----\n" "\n" "${{CPPROJ_PROJECT_DESC}}\n" "\n" "## Dependencies\n" "\n" "To make development faster, the project used:\n" "\n" "## Building\n" "\n" "Required a compiler supporting C++${{CPPROJ_CXX_STANDARD}}\n" "\n" "```\n" "mkdir build && cd build\n" "cmake ..\n" "cmake --build .\n" "```\n" "\n" "## Future\n" "\n" "* Future scope of the project, OR your TODO list, that you may not be implementing now\n" "\n" ":copyright: Author ${{CPPROJ_YEAR}}\n" "\n"; constexpr auto README_MAKE_BOILERPLATE = "${{CPPROJ_PROJECT_NAME}}\n" "----\n" "\n" "Have fun coding, put in your project's description\n" "\n" "## Dependencies\n" "\n" "To make development faster, the project used:\n" "\n" "## Building\n" "\n" "Required a compiler supporting C++${{CPPROJ_CXX_STANDARD}}\n" "\n" "```\n" "make" "```\n" "> Add more relevant commands according to your project\n" "\n" "## Future\n" "\n" "* Future scope of the project, OR your TODO list, that you may not be implementing now\n" "\n" ":copyright: Author ${{CPPROJ_YEAR}}\n" "\n";
; Startup for Excalibur 64 ; ; Stefano Bodrato - 2019 ; ; $Id: excali64_crt0.asm $ ; ; ; ; To run at position $6000: ; ; POKE -957,96 ; POKE -958,0 ; PRINT USR(0) ; ; To change loading speed (CLOADM, ecc..): 01 = 1200 baud 02 = 600 baud 04 = 300 baud ; POKE -1053,n MODULE excali64_crt0 ;-------- ; Include zcc_opt.def to find out some info ;-------- defc crt0 = 1 INCLUDE "zcc_opt.def" ;-------- ; Some scope definitions ;-------- EXTERN _main ;main() is always external to crt0 code PUBLIC cleanup ;jp'd to by exit() PUBLIC l_dcal ;jp(hl) IF !DEFINED_CRT_ORG_CODE defc CRT_ORG_CODE = $4100 ; BASIC startup mode ENDIF ; Now, getting to the real stuff now! defc CONSOLE_ROWS = 24 defc CONSOLE_COLUMNS = 80 defc TAR__no_ansifont = 1 defc TAR__clib_exit_stack_size = 32 ;defc TAR__register_sp = $5fff defc TAR__register_sp = -1 defc __CPU_CLOCK = 4000000 INCLUDE "crt/classic/crt_rules.inc" org CRT_ORG_CODE start: ld (start1+1),sp INCLUDE "crt/classic/crt_init_sp.asm" INCLUDE "crt/classic/crt_init_atexit.asm" 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 "crt/classic/crt_init_amalloc.asm" ENDIF call _main cleanup: push hl call crt0_exit pop hl start1: ld sp,0 jp $1904 ; pass HL as a result to the USR(n) BASIC function ;ret l_dcal: jp (hl) INCLUDE "crt/classic/crt_runtime_selection.asm" INCLUDE "crt/classic/crt_section.asm" SECTION code_crt_init
; size_t w_vector_insert_n(w_vector_t *v, size_t idx, size_t n, void *item) SECTION code_clib SECTION code_adt_w_vector PUBLIC w_vector_insert_n EXTERN asm_w_vector_insert_n w_vector_insert_n: pop ix pop af pop de pop bc pop hl push hl push bc push de push af push ix jp asm_w_vector_insert_n ; SDCC bridge for Classic IF __CLASSIC PUBLIC _w_vector_insert_n defc _w_vector_insert_n = w_vector_insert_n ENDIF
*= $0801 .byte $4c,$16,$08,$00,$97,$32 .byte $2c,$30,$3a,$9e,$32,$30 .byte $37,$30,$00,$00,$00,$a9 .byte $01,$85,$02 jsr print .byte 13 .text "(up)adcz" .byte 0 lda #%00011011 sta db lda #%11000110 sta ab lda #%10110001 sta xb lda #%01101100 sta yb lda #0 sta pb tsx stx sb lda #0 sta db sta ab next lda pb and #%00001000 bne decmode lda db sta 172 sta dr sta cmd0+1 and #$7f sta cmd1+1 clc lda pb and #1 beq noc sec noc php lda ab cmd0 adc #0 sta ar lda pb ora #%00110000 and #%00111100 bcc noc1 ora #1 noc1 tax lda ab and #$7f plp cmd1 adc #0 bmi neg txa and #1 beq cont set txa ora #%01000000 tax jmp cont neg txa and #1 beq set cont lda ar cmp #0 bne nozero txa ora #%00000010 tax nozero lda ar bpl noneg txa ora #%10000000 tax noneg stx pr jmp deccont decmode .block lda db sta 172 sta dr and #$0f sta l0+1 lda pb ora #%00110000 and #%00111100 tax lda pb lsr a lda ab and #$0f l0 adc #0 ldy #$00 cmp #$0a bcc l1 sec sbc #$0a and #$0f ldy #$08 l1 sta ar sty l2+1 sty l3+1 lda db and #$f0 ora l3+1 sta l3+1 lda ab and #$f0 l2 ora #0 clc l3 adc #0 php bcs l4 cmp #$a0 bcc l5 l4 sec sbc #$a0 inx l5 ora ar sta ar plp bvc nov php txa ora #%01000000 tax plp nov bpl non txa ora #%10000000 tax non lda pb lsr a lda ab adc db bne noz txa ora #%00000010 tax noz stx pr .bend deccont lda xb sta xr lda yb sta yr lda sb sta sr ldx sb txs lda pb pha lda ab ldx xb ldy yb plp cmd adc 172 php cld sta aa stx xa sty ya pla sta pa tsx stx sa lda 172 sta da jsr check clc lda db adc #17 sta db bcc jmpnext lda #0 sta db clc lda ab adc #17 sta ab bcc jmpnext lda #0 sta ab inc pb beq nonext jmpnext jmp next nonext jsr print .text " - ok" .byte 13,0 lda 2 beq load wait jsr $ffe4 beq wait jmp $8000 load jsr print name .text "adczx" namelen = *-name .byte 0 lda #0 sta $0a sta $b9 lda #namelen sta $b7 lda #<name sta $bb lda #>name sta $bc pla pla jmp $e16f db .byte 0 ab .byte 0 xb .byte 0 yb .byte 0 pb .byte 0 sb .byte 0 da .byte 0 aa .byte 0 xa .byte 0 ya .byte 0 pa .byte 0 sa .byte 0 dr .byte 0 ar .byte 0 xr .byte 0 yr .byte 0 pr .byte 0 sr .byte 0 check .block lda da cmp dr bne error lda aa cmp ar bne error lda xa cmp xr bne error lda ya cmp yr bne error lda pa cmp pr bne error lda sa cmp sr bne error rts error jsr print .byte 13 .null "before " ldx #<db ldy #>db jsr showregs jsr print .byte 13 .null "after " ldx #<da ldy #>da jsr showregs jsr print .byte 13 .null "right " ldx #<dr ldy #>dr jsr showregs lda #13 jsr $ffd2 wait jsr $ffe4 beq wait cmp #3 beq stop rts stop lda 2 beq basic jmp $8000 basic jmp ($a002) showregs stx 172 sty 173 ldy #0 lda (172),y jsr hexb lda #32 jsr $ffd2 lda #32 jsr $ffd2 iny lda (172),y jsr hexb lda #32 jsr $ffd2 iny lda (172),y jsr hexb lda #32 jsr $ffd2 iny lda (172),y jsr hexb lda #32 jsr $ffd2 iny lda (172),y ldx #"n" asl a bcc ok7 ldx #"N" ok7 pha txa jsr $ffd2 pla ldx #"v" asl a bcc ok6 ldx #"V" ok6 pha txa jsr $ffd2 pla ldx #"0" asl a bcc ok5 ldx #"1" ok5 pha txa jsr $ffd2 pla ldx #"b" asl a bcc ok4 ldx #"B" ok4 pha txa jsr $ffd2 pla ldx #"d" asl a bcc ok3 ldx #"D" ok3 pha txa jsr $ffd2 pla ldx #"i" asl a bcc ok2 ldx #"I" ok2 pha txa jsr $ffd2 pla ldx #"z" asl a bcc ok1 ldx #"Z" ok1 pha txa jsr $ffd2 pla ldx #"c" asl a bcc ok0 ldx #"C" ok0 pha txa jsr $ffd2 pla lda #32 jsr $ffd2 iny lda (172),y .bend hexb pha lsr a lsr a lsr a lsr a jsr hexn pla and #$0f hexn ora #$30 cmp #$3a bcc hexn0 adc #6 hexn0 jmp $ffd2 print pla .block sta print0+1 pla sta print0+2 ldx #1 print0 lda !*,x beq print1 jsr $ffd2 inx bne print0 print1 sec txa adc print0+1 sta print2+1 lda #0 adc print0+2 sta print2+2 print2 jmp !* .bend
Music_DefeatedTrainer_Ch1:: tempo 224 volume 7, 7 duty_cycle 2 toggle_perfect_pitch tempo 224 note_type 4, 10, 2 octave 4 note D_, 2 tempo 224 note_type 4, 10, 2 note D_, 2 note D_, 2 note D_, 2 octave 3 note A_, 2 octave 4 note D_, 2 note_type 4, 11, 3 note F#, 12 duty_cycle 1 tempo 224 Music_DefeatedTrainer_branch_23a76:: note_type 4, 6, 3 octave 3 note A_, 6 note F#, 3 note A_, 3 note B_, 6 note G#, 3 note B_, 3 octave 4 note C#, 3 octave 3 note B_, 3 note A_, 3 note G_, 3 note A_, 3 note B_, 3 note A_, 3 note G_, 3 note A_, 6 note F#, 3 note A_, 3 note B_, 6 note G#, 3 note B_, 3 octave 4 note C#, 3 note D_, 3 note E_, 3 note F#, 3 note C#, 3 octave 3 note B_, 3 note A_, 3 octave 4 note C#, 3 octave 3 note A_, 6 note F#, 3 note A_, 3 note B_, 6 note G#, 3 note B_, 3 octave 4 note C_, 6 octave 3 note A_, 3 octave 4 note C_, 3 note D_, 3 octave 3 note B_, 3 octave 4 note D_, 6 note C#, 3 octave 3 note B_, 3 note A_, 3 note G_, 3 note F#, 3 note G_, 3 note A_, 3 note B_, 3 note A_, 3 note G_, 3 note F#, 3 note E_, 3 note F#, 3 note G_, 3 note A_, 3 note B_, 3 sound_loop 0, Music_DefeatedTrainer_branch_23a76 Music_DefeatedTrainer_Ch2:: duty_cycle 2 note_type 4, 12, 3 octave 4 note A_, 2 note_type 4, 12, 3 note A_, 2 note A_, 2 note A_, 2 note B_, 2 octave 5 note C#, 2 note_type 4, 12, 4 note D_, 12 Music_DefeatedTrainer_branch_23ad2:: note_type 4, 8, 5 octave 4 note D_, 6 octave 3 note A_, 3 octave 4 note D_, 3 note E_, 6 octave 3 note B_, 3 octave 4 note E_, 3 note F#, 3 note G_, 3 note A_, 6 note E_, 3 note F#, 3 note G_, 6 note D_, 6 octave 3 note A_, 3 octave 4 note D_, 3 note E_, 6 octave 3 note B_, 3 octave 4 note E_, 3 note F#, 3 note G_, 3 note A_, 6 note F#, 3 note G_, 3 note A_, 6 note D_, 6 octave 3 note A_, 3 octave 4 note D_, 3 note E_, 6 octave 3 note B_, 3 octave 4 note E_, 3 note F_, 6 note C_, 3 note F_, 3 note G_, 3 note D_, 3 note G_, 6 note_type 4, 7, 0 note F#, 12 note_type 4, 7, 7 note F#, 12 note_type 4, 6, 0 note E_, 12 note_type 4, 6, 7 note E_, 12 sound_loop 0, Music_DefeatedTrainer_branch_23ad2 Music_DefeatedTrainer_Ch3:: note_type 4, 1, 0 octave 5 note D_, 2 note_type 4, 1, 0 note D_, 2 note D_, 2 octave 4 note B_, 2 note A_, 2 note G_, 2 note A_, 12 note_type 4, 2, 1 Music_DefeatedTrainer_branch_23b24:: note F#, 3 rest 3 note F#, 3 rest 3 note G#, 3 rest 3 note G#, 3 rest 3 note A_, 3 rest 3 note A_, 3 rest 3 note B_, 3 rest 3 note B_, 3 rest 3 note F#, 3 rest 3 note F#, 3 rest 3 note G#, 3 rest 3 note G#, 3 rest 3 note A_, 3 rest 3 note A_, 3 rest 3 octave 5 note C#, 3 rest 3 note C#, 3 octave 4 note A_, 3 note F#, 3 octave 5 note D_, 3 octave 4 note F#, 3 rest 3 note G#, 3 octave 5 note E_, 3 octave 4 note G#, 3 rest 3 note A_, 3 octave 5 note F_, 3 octave 4 note A_, 3 rest 3 note B_, 3 octave 5 note G_, 3 octave 4 note B_, 3 note A#, 3 note A_, 3 rest 3 note A_, 3 rest 3 note A_, 3 rest 3 note A_, 3 octave 5 note C_, 3 note C#, 3 rest 3 note C#, 3 rest 3 note C#, 3 rest 3 note C#, 3 octave 4 note A_, 3 sound_loop 0, Music_DefeatedTrainer_branch_23b24
; A151780: 5^{wt(n)-1}. ; 1,1,5,1,5,5,25,1,5,5,25,5,25,25,125,1,5,5,25,5,25,25,125,5,25,25,125,25,125,125,625,1,5,5,25,5,25,25,125,5,25,25,125,25,125,125,625,5,25,25,125,25,125,125,625,25,125,125,625,125,625,625,3125,1,5,5,25,5,25,25,125,5 seq $0,48881 ; a(n) = A000120(n+1) - 1 = wt(n+1) - 1. mov $1,5 pow $1,$0 mov $0,$1
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r14 push %r15 push %rcx push %rdi push %rsi lea addresses_WC_ht+0x16f45, %rsi lea addresses_WC_ht+0x10f0b, %rdi nop nop nop nop nop add $51699, %r10 mov $25, %rcx rep movsb nop nop inc %r14 lea addresses_WC_ht+0x14c0b, %r15 nop dec %r10 movl $0x61626364, (%r15) nop nop nop nop xor $27174, %r10 pop %rsi pop %rdi pop %rcx pop %r15 pop %r14 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r13 push %r15 push %rdx push %rsi // Faulty Load lea addresses_normal+0x1950b, %r10 nop nop nop nop nop sub %r11, %r11 mov (%r10), %dx lea oracles, %r13 and $0xff, %rdx shlq $12, %rdx mov (%r13,%rdx,1), %rdx pop %rsi pop %rdx pop %r15 pop %r13 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_normal', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 0}} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_normal', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 0}} <gen_prepare_buffer> {'OP': 'REPM', 'src': {'same': False, 'congruent': 0, 'type': 'addresses_WC_ht'}, 'dst': {'same': False, 'congruent': 9, 'type': 'addresses_WC_ht'}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 7}} {'34': 21829} 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 */
; =============================================================== ; Dec 2013 ; =============================================================== ; ; void *obstack_int_grow(struct obstack *ob, int data) ; ; Append int to the growing object. ; ; =============================================================== SECTION code_clib SECTION code_alloc_obstack PUBLIC obstack_int_grow_callee EXTERN asm_obstack_int_grow obstack_int_grow_callee: pop hl pop bc ex (sp),hl jp asm_obstack_int_grow
; A132351: Partial sums of A132350. ; 1,2,3,3,4,5,6,6,6,7,8,9,10,11,12,12,13,14,15,16,17,18,19,20,20,21,21,22,23,24,25,25,26,27,28,28,29,30,31,32,33,34,35,36,37,38,39,40,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,54,55,56,57,58,59,60,61,62,63,64,65,66 mov $2,$0 add $2,1 mov $3,$0 lpb $2 mov $0,$3 sub $2,1 sub $0,$2 seq $0,132350 ; If n > 1 is a k-th power with k >= 2 then a(n) = 0, otherwise a(n) = 1. add $1,$0 lpe mov $0,$1
# Variaveis associadas aos registradores: # endBase -> $16 .data A: .word -2 .text .globl main main: addi $16, $0, 0x1001 # endBase = 0x00001001 sll $16, $16, 0x10 # endBase = 0x10010000 lw $8, 0x0($16) # t0 = mem[ 0 + endBase ] sra $9, $8, 0x19 # t0 >> 31 beq $9, $0, fim # if (t0 == 0) goto fim sub $8, $0, $8 # t0 = 0 - t0 sw $8, 0x0($16) # mem[0 + endBase] = t0 fim: nop
; A017417: a(n) = (11*n+2)^5. ; 32,371293,7962624,52521875,205962976,601692057,1453933568,3077056399,5904900000,10510100501,17623416832,28153056843,43204003424,64097340625,92389579776,129891985607,178689902368,241162079949,320000000000,418227202051,539218609632 mul $0,11 add $0,2 pow $0,5
; A165751: a(n) = 4 - 3*2^n. ; 1,-2,-8,-20,-44,-92,-188,-380,-764,-1532,-3068,-6140,-12284,-24572,-49148,-98300,-196604,-393212,-786428,-1572860,-3145724,-6291452,-12582908,-25165820,-50331644,-100663292,-201326588,-402653180,-805306364,-1610612732,-3221225468,-6442450940,-12884901884,-25769803772,-51539607548,-103079215100,-206158430204,-412316860412,-824633720828,-1649267441660,-3298534883324,-6597069766652,-13194139533308,-26388279066620,-52776558133244,-105553116266492,-211106232532988,-422212465065980,-844424930131964,-1688849860263932,-3377699720527868,-6755399441055740 mov $1,2 pow $1,$0 mul $1,-1 add $1,1 mul $1,3 add $1,1
Sound_D6_Header: smpsHeaderStartSong 3 smpsHeaderVoice Sound_D6_Voices smpsHeaderTempoSFX $01 smpsHeaderChanSFX $01 smpsHeaderSFXChannel cFM3, Sound_D6_FM3, $10, $04 ; FM3 Data Sound_D6_FM3: smpsSetvoice $00 smpsModSet $01, $01, $0C, $01 Sound_D6_Loop00: dc.b nC0, $08, nC0 smpsContinuousLoop Sound_D6_Loop00 smpsStop Sound_D6_Voices: ; Voice $00 ; $F9 ; $22, $31, $11, $32, $0F, $0E, $1F, $1F, $05, $18, $09, $02 ; $0B, $1F, $10, $05, $1F, $2F, $4F, $2F, $0E, $17, $14, $80 smpsVcAlgorithm $01 smpsVcFeedback $07 smpsVcUnusedBits $03 smpsVcDetune $03, $01, $03, $02 smpsVcCoarseFreq $02, $01, $01, $02 smpsVcRateScale $00, $00, $00, $00 smpsVcAttackRate $1F, $1F, $0E, $0F smpsVcAmpMod $00, $00, $00, $00 smpsVcDecayRate1 $02, $09, $18, $05 smpsVcDecayRate2 $05, $10, $1F, $0B smpsVcDecayLevel $02, $04, $02, $01 smpsVcReleaseRate $0F, $0F, $0F, $0F smpsVcTotalLevel $00, $14, $17, $0E
; A052602: E.g.f. x^2*(1-x)/(1-x-x^2). ; Submitted by Jamie Morken(s2) ; 0,0,2,0,24,120,1440,15120,201600,2903040,47174400,838252800,16286054400,342486144000,7758867916800,188305108992000,4875010043904000,134094160392192000,3905447960494080000 mov $2,$0 sub $0,1 lpb $0 mov $3,$2 mul $3,$0 sub $0,1 mov $2,$1 add $1,$3 mul $1,$0 lpe mov $0,$3
%ifndef RESET_CURSOR %define RESET_CURSOR resetCursor: mov ah, 0x02 mov bh, 0x00 mov dh, 0x00 mov dl, 0x00 int 0x10 ret %endif
frame 0, 04 setrepeat 2 frame 1, 10 frame 2, 12 frame 1, 08 frame 0, 08 dorepeat 2 endanim
db DEWGONG ; 087 db 90, 70, 80, 70, 70, 95 ; hp atk def spd sat sdf db WATER, ICE ; type db 75 ; catch rate db 176 ; base exp db NO_ITEM, NO_ITEM ; items db GENDER_F50 ; gender ratio db 100 ; unknown 1 db 20 ; step cycles to hatch db 5 ; unknown 2 INCBIN "gfx/pokemon/dewgong/front.dimensions" db 0, 0, 0, 0 ; padding db GROWTH_MEDIUM_FAST ; growth rate dn EGG_WATER_1, EGG_GROUND ; egg groups ; tm/hm learnset tmhm HEADBUTT, CURSE, TOXIC, HIDDEN_POWER, SNORE, BLIZZARD, HYPER_BEAM, ICY_WIND, PROTECT, RAIN_DANCE, ENDURE, FRUSTRATION, RETURN, DOUBLE_TEAM, SWAGGER, SLEEP_TALK, REST, ATTRACT, SURF, WHIRLPOOL, WATERFALL, ICE_BEAM ; end
#include "HelloWorldScene.h" USING_NS_CC; USING_NS_CC_EXT; Scene* HelloWorld::createScene() { // 'scene' is an autorelease object auto scene = Scene::create(); // 'layer' is an autorelease object auto layer = HelloWorld::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene; } // on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object auto closeItem = MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 , origin.y + closeItem->getContentSize().height/2)); // create menu, it's an autorelease object auto menu = Menu::create(closeItem, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label auto label = LabelTTF::create("Hello World", "Arial", 24); // position the label on the center of the screen label->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label->getContentSize().height)); // add the label as a child to this layer this->addChild(label, 1); // add "HelloWorld" splash screen" auto sprite = Sprite::create("HelloWorld.png"); // position the sprite on the center of the screen //sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer //this->addChild(sprite, 0); //Size size = Size(visibleSize.width + origin.x, visibleSize.height + origin.y); Size size = Size(200, 200); ScrollView* sc = ScrollView::create(size); sc->setDirection(ScrollView::Direction::VERTICAL); sc->setContainer(sprite); sc->setContentSize(sprite->getContentSize()); sc->setDelegate(this); sc->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); this->addChild(sc); bar = ScrollBarView::create(sc, ScrollBarView::BarType::VERTICAL_IN); return true; } void HelloWorld::scrollViewDidScroll(ScrollView *view) { bar->refresh(); } void HelloWorld::scrollViewDidZoom(ScrollView *view) { } void HelloWorld::menuCloseCallback(Ref* pSender) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert"); return; #endif Director::getInstance()->end(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) exit(0); #endif }
/* ///////////////////////////////////////////////////////////////////////// * File: implicit_link.cpp * * Purpose: Implicit link file for the test.unit.bundle.winini project. * * Created: 12th April 2008 * Updated: 26th September 2015 * * Status: Wizard-generated * * License: (Licensed under the Synesis Software Open License) * * Copyright (c) 2008-2015, Synesis Software Pty Ltd. * All rights reserved. * * www: http://www.synesis.com.au/software * * ////////////////////////////////////////////////////////////////////// */ /* FastFormat header files */ #include <fastformat/implicit_link.h> /* UNIXem header files */ #include <platformstl/platformstl.h> #if defined(PLATFORMSTL_OS_IS_UNIX) && \ defined(_WIN32) # include <unixem/implicit_link.h> #endif /* operating system */ /* xTests header files */ #include <xtests/implicit_link.h> /* ///////////////////////////// end of file //////////////////////////// */
; ; Word: ! ; Dictionary: (d a - ) ; Date: 1st February 2018 ; Macro: Yes ; Notes: ; pop ix pop hl ex de,hl ld (hl),e inc hl ld (hl),d pop de jp (ix)
;* * * * * Small-C/Plus z88dk * * * * * ; Version: 16894-223f580fd-20200818 ; ; Reconstructed for z80 Module Assembler ; ; Module compile time: Wed Jul 7 12:41:42 2021 C_LINE 0,"asinf16.c" MODULE asinf16_c INCLUDE "z80_crt0.hdr" C_LINE 0,"math16.h" C_LINE 0,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 8,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 9,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 10,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 12,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 13,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 14,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 16,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 17,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 18,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 20,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 21,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 22,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 24,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 25,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 26,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 28,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 29,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 30,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 60,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 63,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 81,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 82,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/stdint.h" C_LINE 34,"math16.h" C_LINE 0,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 22,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 39,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 51,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 172,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 175,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 178,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 181,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 182,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 187,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 190,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 193,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 197,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 200,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 203,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 207,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 210,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 213,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 217,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 220,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 223,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 226,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 227,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 231,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 234,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 235,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 239,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 240,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 244,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 245,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 250,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 253,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 256,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 259,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 262,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 266,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 269,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 270,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 275,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 276,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 280,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 283,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 287,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 290,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 293,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 296,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 300,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 303,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 306,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 309,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 312,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 315,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 318,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 321,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 325,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 326,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 330,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 331,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 335,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 336,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 340,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 341,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 346,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 347,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 351,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 355,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 356,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 360,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 361,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 366,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 367,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 372,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 373,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 377,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 378,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 383,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 384,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 389,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 390,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 394,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 395,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 399,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 400,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 404,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 405,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 409,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 410,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 414,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 415,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 485,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 488,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 492,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 495,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 499,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 502,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 505,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 508,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 512,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 515,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 518,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 521,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 524,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 527,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 531,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 532,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 536,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 537,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 541,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 542,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 546,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 547,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 552,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 553,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 557,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 558,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 562,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 563,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 568,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 571,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 575,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 579,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 582,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 585,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 588,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 589,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 593,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 594,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 599,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 602,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 605,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 608,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 609,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 614,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 617,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 620,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 624,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 627,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 630,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 633,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 636,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 639,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 642,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 643,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 648,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 651,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 654,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 657,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 661,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 662,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 666,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 667,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 671,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 672,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 676,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 677,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 681,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 682,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 686,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 687,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 691,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 692,"/home/phillip/Z80/z88dk/lib/config/../..//include/_DEVELOPMENT/sccz80/math.h" C_LINE 35,"math16.h" C_LINE 2,"asinf16.c" C_LINE 4,"asinf16.c" SECTION code_compiler ; Function asinf16 flags 0x00000288 __smallc __z88dk_fastcall ; _Float16 half_tasinf16(_Float16 x) ; parameter '_Float16 x' at sp+2 size(2) C_LINE 5,"asinf16.c::asinf16::0::0" .asinf16 GLOBAL _asinf16 ._asinf16 push hl push bc push hl ld hl,4 ;const add hl,sp ld a,(hl) ;l_gint inc hl ld h,(hl) ld l,a call l_f16_mul ld bc,15360 ;const push bc call l_f16_sub call sqrtf16 pop bc pop de push de ex de,hl push de push hl ex de,hl call l_f16_div call atanf16 pop bc pop bc ret ; --- Start of Static Variables --- SECTION bss_compiler SECTION code_compiler ; --- Start of Scope Defns --- GLOBAL acos GLOBAL asin GLOBAL atan GLOBAL atan2 GLOBAL atan2_callee GLOBAL cos GLOBAL sin GLOBAL tan GLOBAL acosh GLOBAL asinh GLOBAL atanh GLOBAL cosh GLOBAL sinh GLOBAL tanh GLOBAL exp GLOBAL exp2 GLOBAL expm1 GLOBAL frexp GLOBAL frexp_callee GLOBAL ilogb GLOBAL ldexp GLOBAL ldexp_callee GLOBAL scalbn GLOBAL scalbn_callee GLOBAL scalbln GLOBAL scalbln_callee GLOBAL log GLOBAL log10 GLOBAL log1p GLOBAL log2 GLOBAL logb GLOBAL fabs GLOBAL hypot GLOBAL hypot_callee GLOBAL pow GLOBAL pow_callee GLOBAL sqrt GLOBAL cbrt GLOBAL erf GLOBAL erfc GLOBAL lgamma GLOBAL tgamma GLOBAL ceil GLOBAL floor GLOBAL nearbyint GLOBAL rint GLOBAL lrint GLOBAL round GLOBAL lround GLOBAL trunc GLOBAL modf GLOBAL modf_callee GLOBAL fmod GLOBAL fmod_callee GLOBAL remainder GLOBAL remainder_callee GLOBAL remquo GLOBAL remquo_callee GLOBAL copysign GLOBAL copysign_callee GLOBAL nan GLOBAL nextafter GLOBAL nextafter_callee GLOBAL nexttoward GLOBAL nexttoward_callee GLOBAL fdim GLOBAL fdim_callee GLOBAL fmax GLOBAL fmax_callee GLOBAL fmin GLOBAL fmin_callee GLOBAL fma GLOBAL fma_callee GLOBAL isgreater GLOBAL isgreater_callee GLOBAL isgreaterequal GLOBAL isgreaterequal_callee GLOBAL isless GLOBAL isless_callee GLOBAL islessequal GLOBAL islessequal_callee GLOBAL islessgreater GLOBAL islessgreater_callee GLOBAL isunordered GLOBAL isunordered_callee GLOBAL f16_f48 GLOBAL f48_f16 GLOBAL f16_f32 GLOBAL f32_f16 GLOBAL i16_f16 GLOBAL u16_f16 GLOBAL i32_f16 GLOBAL u32_f16 GLOBAL f16_i8 GLOBAL f16_i16 GLOBAL f16_i32 GLOBAL f16_u8 GLOBAL f16_u16 GLOBAL f16_u32 GLOBAL addf16 GLOBAL addf16_callee GLOBAL subf16 GLOBAL subf16_callee GLOBAL mulf16 GLOBAL mulf16_callee GLOBAL divf16 GLOBAL divf16_callee GLOBAL fmaf16 GLOBAL fmaf16_callee GLOBAL polyf16 GLOBAL polyf16_callee GLOBAL hypotf16 GLOBAL hypotf16_callee GLOBAL invf16 GLOBAL invsqrtf16 GLOBAL sqrtf16 GLOBAL div2f16 GLOBAL mul2f16 GLOBAL mul10f16 GLOBAL frexpf16 GLOBAL frexpf16_callee GLOBAL ldexpf16 GLOBAL ldexpf16_callee GLOBAL acosf16 GLOBAL asinf16 GLOBAL atanf16 GLOBAL atan2f16 GLOBAL atan2f16_callee GLOBAL cosf16 GLOBAL sinf16 GLOBAL tanf16 GLOBAL expf16 GLOBAL exp2f16 GLOBAL exp10f16 GLOBAL logf16 GLOBAL log2f16 GLOBAL log10f16 GLOBAL powf16 GLOBAL powf16_callee GLOBAL fabsf16 GLOBAL negf16 GLOBAL ceilf16 GLOBAL floorf16 GLOBAL isgreaterf16 GLOBAL isgreaterf16_callee GLOBAL isgreaterequalf16 GLOBAL isgreaterequalf16_callee GLOBAL islessf16 GLOBAL islessf16_callee GLOBAL islessequalf16 GLOBAL islessequalf16_callee GLOBAL islessgreaterf16 GLOBAL islessgreaterf16_callee GLOBAL isnotequalf16 GLOBAL isnotequalf16_callee GLOBAL isunorderedf16 GLOBAL isunorderedf16_callee ; --- End of Scope Defns --- ; --- End of Compilation ---
// Author: Matthieu Garrigues matthieu.garrigues@gmail.com // // Single header version the lithium_pgsql library. // https://github.com/matt-42/lithium // // This file is generated do not edit it. #pragma once #include <any> #include <arpa/inet.h> #include <atomic> #include <boost/lexical_cast.hpp> #include <cassert> #include <cstring> #include <deque> #include <iostream> #if __APPLE__ #include <libkern/OSByteOrder.h> #endif #include <libpq-fe.h> #if __APPLE__ #include <machine/endian.h> #endif #include <map> #include <memory> #include <mutex> #include <optional> #include <sstream> #include <string> #if __linux__ #include <sys/epoll.h> #endif #if __APPLE__ #include <sys/event.h> #endif #include <thread> #include <tuple> #include <unistd.h> #include <unordered_map> #include <utility> #include <vector> #if _WIN32 #include <winsock2.h> #endif #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_DATABASE_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_DATABASE_HH #if not defined _WIN32 #endif #include "libpq-fe.h" #if __linux__ #elif __APPLE__ #endif #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_CALLABLE_TRAITS_CALLABLE_TRAITS_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_CALLABLE_TRAITS_CALLABLE_TRAITS_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_CALLABLE_TRAITS_TYPELIST_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_CALLABLE_TRAITS_TYPELIST_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_TUPLE_UTILS_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_TUPLE_UTILS_HH namespace li { template <typename... E, typename F> constexpr void apply_each(F&& f, E&&... e) { (void)std::initializer_list<int>{((void)f(std::forward<E>(e)), 0)...}; } template <typename... E, typename F, typename R> constexpr auto tuple_map_reduce_impl(F&& f, R&& reduce, E&&... e) { return reduce(f(std::forward<E>(e))...); } template <typename T, typename F> constexpr void tuple_map(T&& t, F&& f) { return std::apply([&](auto&&... e) { apply_each(f, std::forward<decltype(e)>(e)...); }, std::forward<T>(t)); } template <typename T, typename F> constexpr auto tuple_reduce(T&& t, F&& f) { return std::apply(std::forward<F>(f), std::forward<T>(t)); } template <typename T, typename F, typename R> decltype(auto) tuple_map_reduce(T&& m, F map, R reduce) { auto fun = [&](auto... e) { return tuple_map_reduce_impl(map, reduce, e...); }; return std::apply(fun, m); } template <typename F> constexpr inline std::tuple<> tuple_filter_impl() { return std::make_tuple(); } template <typename F, typename... M, typename M1> constexpr auto tuple_filter_impl(M1 m1, M... m) { if constexpr (std::is_same<M1, F>::value) return tuple_filter_impl<F>(m...); else return std::tuple_cat(std::make_tuple(m1), tuple_filter_impl<F>(m...)); } template <typename F, typename... M> constexpr auto tuple_filter(const std::tuple<M...>& m) { auto fun = [](auto... e) { return tuple_filter_impl<F>(e...); }; return std::apply(fun, m); } } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_TUPLE_UTILS_HH namespace li { template <typename... T> struct typelist {}; template <typename... T1, typename... T2> constexpr auto typelist_cat(typelist<T1...> t1, typelist<T2...> t2) { return typelist<T1..., T2...>(); } template <typename T> struct typelist_to_tuple {}; template <typename... T> struct typelist_to_tuple<typelist<T...>> { typedef std::tuple<T...> type; }; template <typename T> struct tuple_to_typelist {}; template <typename... T> struct tuple_to_typelist<std::tuple<T...>> { typedef typelist<T...> type; }; template <typename T> using typelist_to_tuple_t = typename typelist_to_tuple<T>::type; template <typename T> using tuple_to_typelist_t = typename tuple_to_typelist<T>::type; template <typename T, typename U> struct typelist_embeds : public std::false_type {}; template <typename... T, typename U> struct typelist_embeds<typelist<T...>, U> : public std::integral_constant<bool, count_first_falses(std::is_same<T, U>::value...) != sizeof...(T)> {}; template <typename T, typename E> struct typelist_embeds_any_ref_of : public std::false_type {}; template <typename U, typename... T> struct typelist_embeds_any_ref_of<typelist<T...>, U> : public typelist_embeds<typelist<std::decay_t<T>...>, std::decay_t<U>> {}; } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_CALLABLE_TRAITS_TYPELIST_HH namespace li { namespace internal { template <typename T> struct has_parenthesis_operator { template <typename C> static char test(decltype(&C::operator())); template <typename C> static int test(...); static const bool value = sizeof(test<T>(0)) == 1; }; } // namespace internal // Traits on callable (function, functors and lambda functions). // callable_traits<F>::is_callable = true_type if F is callable. // callable_traits<F>::arity = N if F takes N arguments. // callable_traits<F>::arguments_tuple_type = tuple<Arg1, ..., ArgN> template <typename F, typename X = void> struct callable_traits { typedef std::false_type is_callable; static const int arity = 0; typedef std::tuple<> arguments_tuple; typedef typelist<> arguments_list; typedef void return_type; }; template <typename F, typename X> struct callable_traits<F&, X> : public callable_traits<F, X> {}; template <typename F, typename X> struct callable_traits<F&&, X> : public callable_traits<F, X> {}; template <typename F, typename X> struct callable_traits<const F&, X> : public callable_traits<F, X> {}; template <typename F> struct callable_traits<F, std::enable_if_t<internal::has_parenthesis_operator<F>::value>> { typedef callable_traits<decltype(&F::operator())> super; typedef std::true_type is_callable; static const int arity = super::arity; typedef typename super::arguments_tuple arguments_tuple; typedef typename super::arguments_list arguments_list; typedef typename super::return_type return_type; }; template <typename C, typename R, typename... ARGS> struct callable_traits<R (C::*)(ARGS...) const> { typedef std::true_type is_callable; static const int arity = sizeof...(ARGS); typedef std::tuple<ARGS...> arguments_tuple; typedef typelist<ARGS...> arguments_list; typedef R return_type; }; template <typename C, typename R, typename... ARGS> struct callable_traits<R (C::*)(ARGS...)> { typedef std::true_type is_callable; static const int arity = sizeof...(ARGS); typedef std::tuple<ARGS...> arguments_tuple; typedef typelist<ARGS...> arguments_list; typedef R return_type; }; template <typename R, typename... ARGS> struct callable_traits<R(ARGS...)> { typedef std::true_type is_callable; static const int arity = sizeof...(ARGS); typedef std::tuple<ARGS...> arguments_tuple; typedef typelist<ARGS...> arguments_list; typedef R return_type; }; template <typename R, typename... ARGS> struct callable_traits<R (*)(ARGS...)> { typedef std::true_type is_callable; static const int arity = sizeof...(ARGS); typedef std::tuple<ARGS...> arguments_tuple; typedef typelist<ARGS...> arguments_list; typedef R return_type; }; template <typename F> using callable_arguments_tuple_t = typename callable_traits<F>::arguments_tuple; template <typename F> using callable_arguments_list_t = typename callable_traits<F>::arguments_list; template <typename F> using callable_return_type_t = typename callable_traits<F>::return_type; template <typename F> struct is_callable : public callable_traits<F>::is_callable {}; template <typename F, typename... A> struct callable_with { template <typename G, typename... B> static char test(int x, std::remove_reference_t<decltype(std::declval<G>()(std::declval<B>()...))>* = 0); template <typename G, typename... B> static int test(...); static const bool value = sizeof(test<F, A...>(0)) == 1; }; } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_CALLABLE_TRAITS_CALLABLE_TRAITS_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_METAMAP_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_METAMAP_HH namespace li { namespace internal { struct reduce_add_type { template <typename A, typename... B> constexpr auto operator()(A&& a, B&&... b) { auto result = a; using expand_variadic_pack = int[]; (void)expand_variadic_pack{0, ((result += b), 0)...}; return result; } }; #ifdef _WIN32 __declspec(selectany) reduce_add_type reduce_add; #else reduce_add_type reduce_add [[gnu::weak]]; #endif } // namespace internal template <typename... Ms> struct metamap; template <typename F, typename... M> constexpr decltype(auto) find_first(metamap<M...>&& map, F fun); template <typename... Ms> struct metamap; template <typename M1, typename... Ms> struct metamap<M1, Ms...> : public M1, public Ms... { typedef metamap<M1, Ms...> self; // Constructors. inline metamap() = default; inline metamap(self&&) = default; inline metamap(const self&) = default; self& operator=(const self&) = default; self& operator=(self&&) = default; // metamap(self& other) // : metamap(const_cast<const self&>(other)) {} template <typename M> using get_value_type = typename M::_iod_value_type; constexpr inline metamap(get_value_type<M1>&& m1, get_value_type<Ms>&&... members) : M1{m1}, Ms{std::forward<get_value_type<Ms>>(members)}... {} constexpr inline metamap(M1&& m1, Ms&&... members) : M1(m1), Ms(std::forward<Ms>(members))... {} constexpr inline metamap(const M1& m1, const Ms&... members) : M1(m1), Ms((members))... {} // Assignemnt ? // Retrive a value. template <typename K> constexpr decltype(auto) operator[](K k) { return symbol_member_access(*this, k); } template <typename K> constexpr decltype(auto) operator[](K k) const { return symbol_member_access(*this, k); } }; template <> struct metamap<> { typedef metamap<> self; // Constructors. constexpr inline metamap() = default; // inline metamap(self&&) = default; constexpr inline metamap(const self&) = default; // self& operator=(const self&) = default; // metamap(self& other) // : metamap(const_cast<const self&>(other)) {} // Assignemnt ? // Retrive a value. template <typename K> constexpr decltype(auto) operator[](K k) { return symbol_member_access(*this, k); } template <typename K> constexpr decltype(auto) operator[](K k) const { return symbol_member_access(*this, k); } }; template <typename... Ms> constexpr auto size(metamap<Ms...>) { return sizeof...(Ms); } template <typename M> struct metamap_size_t {}; template <typename... Ms> struct metamap_size_t<metamap<Ms...>> { enum { value = sizeof...(Ms) }; }; template <typename M> constexpr int metamap_size() { return metamap_size_t<std::decay_t<M>>::value; } template <typename... Ks> constexpr decltype(auto) metamap_values(const metamap<Ks...>& map) { return std::forward_as_tuple(map[typename Ks::_iod_symbol_type()]...); } template <typename... Ks> constexpr decltype(auto) metamap_values(metamap<Ks...>& map) { return std::forward_as_tuple(map[typename Ks::_iod_symbol_type()]...); } template <typename... Ks> constexpr decltype(auto) metamap_keys(const metamap<Ks...>& map) { return std::make_tuple(typename Ks::_iod_symbol_type()...); } template <typename K, typename M> constexpr auto has_key(M&& map, K k) { return decltype(has_member(map, k)){}; } template <typename M, typename K> constexpr auto has_key(K k) { return decltype(has_member(std::declval<M>(), std::declval<K>())){}; } template <typename M, typename K> constexpr auto has_key() { return decltype(has_member(std::declval<M>(), std::declval<K>())){}; } template <typename K, typename M, typename O> constexpr auto get_or(M&& map, K k, O default_) { if constexpr (has_key<M, decltype(k)>()) { return map[k]; } else return default_; } template <typename X> struct is_metamap { enum { value = false }; }; template <typename... M> struct is_metamap<metamap<M...>> { enum { value = true }; }; } // namespace li #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_CAT_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_CAT_HH namespace li { template <typename... T, typename... U> constexpr inline decltype(auto) cat(const metamap<T...>& a, const metamap<U...>& b) { return metamap<T..., U...>(*static_cast<const T*>(&a)..., *static_cast<const U*>(&b)...); } } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_CAT_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_INTERSECTION_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_INTERSECTION_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_MAKE_METAMAP_SKIP_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_MAKE_METAMAP_SKIP_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_MAKE_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_MAKE_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SYMBOL_AST_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SYMBOL_AST_HH namespace li { template <typename E> struct Exp {}; template <typename E> struct array_subscriptable; template <typename E> struct callable; template <typename E> struct assignable; template <typename E> struct array_subscriptable; template <typename M, typename... A> struct function_call_exp : public array_subscriptable<function_call_exp<M, A...>>, public callable<function_call_exp<M, A...>>, public assignable<function_call_exp<M, A...>>, public Exp<function_call_exp<M, A...>> { using assignable<function_call_exp<M, A...>>::operator=; function_call_exp(const M& m, A&&... a) : method(m), args(std::forward<A>(a)...) {} M method; std::tuple<A...> args; }; template <typename O, typename M> struct array_subscript_exp : public array_subscriptable<array_subscript_exp<O, M>>, public callable<array_subscript_exp<O, M>>, public assignable<array_subscript_exp<O, M>>, public Exp<array_subscript_exp<O, M>> { using assignable<array_subscript_exp<O, M>>::operator=; array_subscript_exp(const O& o, const M& m) : object(o), member(m) {} O object; M member; }; template <typename L, typename R> struct assign_exp : public Exp<assign_exp<L, R>> { typedef L left_t; typedef R right_t; // template <typename V> // assign_exp(L l, V&& r) : left(l), right(std::forward<V>(r)) {} // template <typename V> inline assign_exp(L l, R r) : left(l), right(r) {} // template <typename V> // inline assign_exp(L l, const V& r) : left(l), right(r) {} L left; R right; }; template <typename E> struct array_subscriptable { public: // Member accessor template <typename S> constexpr auto operator[](S&& s) const { return array_subscript_exp<E, S>(*static_cast<const E*>(this), std::forward<S>(s)); } }; template <typename E> struct callable { public: // Direct call. template <typename... A> constexpr auto operator()(A&&... args) const { return function_call_exp<E, A...>(*static_cast<const E*>(this), std::forward<A>(args)...); } }; template <typename E> struct assignable { public: template <typename L> auto operator=(L&& l) const { return assign_exp<E, L>(static_cast<const E&>(*this), std::forward<L>(l)); } template <typename L> auto operator=(L&& l) { return assign_exp<E, L>(static_cast<E&>(*this), std::forward<L>(l)); } template <typename T> auto operator=(const std::initializer_list<T>& l) const { return assign_exp<E, std::vector<T>>(static_cast<const E&>(*this), std::vector<T>(l)); } }; #define iod_query_declare_binary_op(OP, NAME) \ template <typename A, typename B> \ struct NAME##_exp : public assignable<NAME##_exp<A, B>>, public Exp<NAME##_exp<A, B>> { \ using assignable<NAME##_exp<A, B>>::operator=; \ NAME##_exp() {} \ NAME##_exp(A&& a, B&& b) : lhs(std::forward<A>(a)), rhs(std::forward<B>(b)) {} \ typedef A lhs_type; \ typedef B rhs_type; \ lhs_type lhs; \ rhs_type rhs; \ }; \ template <typename A, typename B> \ inline std::enable_if_t<std::is_base_of<Exp<A>, A>::value || std::is_base_of<Exp<B>, B>::value, \ NAME##_exp<A, B>> \ operator OP(const A& b, const B& a) { \ return NAME##_exp<std::decay_t<A>, std::decay_t<B>>{b, a}; \ } iod_query_declare_binary_op(+, plus); iod_query_declare_binary_op(-, minus); iod_query_declare_binary_op(*, mult); iod_query_declare_binary_op(/, div); iod_query_declare_binary_op(<<, shiftl); iod_query_declare_binary_op(>>, shiftr); iod_query_declare_binary_op(<, inf); iod_query_declare_binary_op(<=, inf_eq); iod_query_declare_binary_op(>, sup); iod_query_declare_binary_op(>=, sup_eq); iod_query_declare_binary_op(==, eq); iod_query_declare_binary_op(!=, neq); iod_query_declare_binary_op(&, logical_and); iod_query_declare_binary_op (^, logical_xor); iod_query_declare_binary_op(|, logical_or); iod_query_declare_binary_op(&&, and); iod_query_declare_binary_op(||, or); #undef iod_query_declare_binary_op } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SYMBOL_AST_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SYMBOL_SYMBOL_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SYMBOL_SYMBOL_HH namespace li { template <typename S> class symbol : public assignable<S>, public array_subscriptable<S>, public callable<S>, public Exp<S> {}; } // namespace li #ifdef LI_SYMBOL #undef LI_SYMBOL #endif #define LI_SYMBOL(NAME) \ namespace s { \ struct NAME##_t : li::symbol<NAME##_t> { \ \ using assignable<NAME##_t>::operator=; \ \ inline constexpr bool operator==(NAME##_t) { return true; } \ template <typename T> inline constexpr bool operator==(T) { return false; } \ \ template <typename V> struct variable_t { \ typedef NAME##_t _iod_symbol_type; \ typedef V _iod_value_type; \ V NAME; \ }; \ \ template <typename T, typename... A> \ static inline decltype(auto) symbol_method_call(T&& o, A... args) { \ return o.NAME(args...); \ } \ template <typename T, typename... A> static inline auto& symbol_member_access(T&& o) { \ return o.NAME; \ } \ template <typename T> \ static constexpr auto has_getter(int) \ -> decltype(std::declval<T>().NAME(), std::true_type{}) { \ return {}; \ } \ template <typename T> static constexpr auto has_getter(long) { return std::false_type{}; } \ template <typename T> \ static constexpr auto has_member(int) -> decltype(std::declval<T>().NAME, std::true_type{}) { \ return {}; \ } \ template <typename T> static constexpr auto has_member(long) { return std::false_type{}; } \ \ static inline auto symbol_string() { return #NAME; } \ static inline auto json_key_string() { return "\"" #NAME "\":"; } \ }; \ static constexpr NAME##_t NAME; \ } namespace li { template <typename S> inline decltype(auto) make_variable(S s, char const v[]) { typedef typename S::template variable_t<const char*> ret; return ret{v}; } template <typename V, typename S> inline decltype(auto) make_variable(S s, V v) { typedef typename S::template variable_t<std::remove_const_t<std::remove_reference_t<V>>> ret; return ret{v}; } template <typename K, typename V> inline decltype(auto) make_variable_reference(K s, V&& v) { typedef typename K::template variable_t<V> ret; return ret{v}; } template <typename T, typename S, typename... A> static inline decltype(auto) symbol_method_call(T&& o, S, A... args) { return S::symbol_method_call(o, std::forward<A>(args)...); } template <typename T, typename S> static inline decltype(auto) symbol_member_access(T&& o, S) { return S::symbol_member_access(o); } template <typename T, typename S> constexpr auto has_member(T&& o, S) { return S::template has_member<T>(0); } template <typename T, typename S> constexpr auto has_member() { return S::template has_member<T>(0); } template <typename T, typename S> constexpr auto has_getter(T&& o, S) { return decltype(S::template has_getter<T>(0)){}; } template <typename T, typename S> constexpr auto has_getter() { return decltype(S::template has_getter<T>(0)){}; } template <typename S, typename T> struct CANNOT_FIND_REQUESTED_MEMBER_IN_TYPE {}; template <typename T, typename S> decltype(auto) symbol_member_or_getter_access(T&& o, S) { if constexpr (has_getter<T, S>()) { return symbol_method_call(o, S{}); } else if constexpr (has_member<T, S>()) { return symbol_member_access(o, S{}); } else { return CANNOT_FIND_REQUESTED_MEMBER_IN_TYPE<S, T>::error; } } template <typename S> auto symbol_string(symbol<S> v) { return S::symbol_string(); } template <typename V> auto symbol_string(V v, typename V::_iod_symbol_type* = 0) { return V::_iod_symbol_type::symbol_string(); } } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SYMBOL_SYMBOL_HH namespace li { template <typename... Ms> struct metamap; namespace internal { template <typename S, typename V> constexpr decltype(auto) exp_to_variable_ref(const assign_exp<S, V>& e) { return make_variable_reference(S{}, e.right); } template <typename S, typename V> constexpr decltype(auto) exp_to_variable(const assign_exp<S, V>& e) { typedef std::remove_const_t<std::remove_reference_t<V>> vtype; return make_variable(S{}, e.right); } template <typename S> decltype(auto) constexpr exp_to_variable(const symbol<S>& e) { return exp_to_variable(S() = int()); } template <typename... T> constexpr inline decltype(auto) make_metamap_helper(T&&... args) { return metamap<T...>(std::forward<T>(args)...); } } // namespace internal // Store copies of values in the map template <typename... T> constexpr inline decltype(auto) mmm(T&&... args) { // Copy values. return internal::make_metamap_helper(internal::exp_to_variable(std::forward<T>(args))...); } // Store references of values in the map template <typename... T> constexpr inline decltype(auto) make_metamap_reference(T&&... args) { // Keep references. return internal::make_metamap_helper(internal::exp_to_variable_ref(std::forward<T>(args))...); } template <typename... Ks> constexpr decltype(auto) metamap_clone(const metamap<Ks...>& map) { return mmm((typename Ks::_iod_symbol_type() = map[typename Ks::_iod_symbol_type()])...); } namespace internal { template <typename... V> auto make_metamap_type(typelist<V...> variables) { return mmm(V(*(typename V::left_t*)0, *(typename V::right_t*)0)...); }; template <typename T1, typename T2, typename... V, typename... T> auto make_metamap_type(typelist<V...> variables, T1, T2, T... args) { return make_metamap_type(typelist<V..., assign_exp<T1, T2>>{}, args...); }; } // Helper to make a metamap type: // metamap_t<s::name_t, string, s::age_t, int> // instead of decltype(mmm(s::name = string(), s::age = int())); template <typename... T> using metamap_t = decltype(internal::make_metamap_type(typelist<>{}, std::declval<T>()...)); } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_MAKE_HH namespace li { struct skip {}; static struct { template <typename... M, typename... T> constexpr inline decltype(auto) run(metamap<M...> map, skip, T&&... args) const { return run(map, std::forward<T>(args)...); } template <typename T1, typename... M, typename... T> constexpr inline decltype(auto) run(metamap<M...> map, T1&& a, T&&... args) const { return run( cat(map, internal::make_metamap_helper(internal::exp_to_variable(std::forward<T1>(a)))), std::forward<T>(args)...); } template <typename... M> constexpr inline decltype(auto) run(metamap<M...> map) const { return map; } template <typename... T> constexpr inline decltype(auto) operator()(T&&... args) const { // Copy values. return run(metamap<>{}, std::forward<T>(args)...); } } make_metamap_skip; } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_MAKE_METAMAP_SKIP_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_MAP_REDUCE_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_MAP_REDUCE_HH namespace li { // Map a function(key, value) on all kv pair template <typename... M, typename F> constexpr void map(const metamap<M...>& m, F fun) { auto apply = [&](auto key) -> decltype(auto) { return fun(key, m[key]); }; apply_each(apply, typename M::_iod_symbol_type{}...); } // Map a function(key, value) on all kv pair. Ensure that the calling order // is kept. // template <typename O, typename F> // void map_sequential2(F fun, O& obj) // {} // template <typename O, typename M1, typename... M, typename F> // void map_sequential2(F fun, O& obj, M1 m1, M... ms) // { // auto apply = [&] (auto key) -> decltype(auto) // { // return fun(key, obj[key]); // }; // apply(m1); // map_sequential2(fun, obj, ms...); // } // template <typename... M, typename F> // void map_sequential(const metamap<M...>& m, F fun) // { // auto apply = [&] (auto key) -> decltype(auto) // { // return fun(key, m[key]); // }; // map_sequential2(fun, m, typename M::_iod_symbol_type{}...); // } // Map a function(key, value) on all kv pair (non const). template <typename... M, typename F> constexpr void map(metamap<M...>& m, F fun) { auto apply = [&](auto key) -> decltype(auto) { return fun(key, m[key]); }; apply_each(apply, typename M::_iod_symbol_type{}...); } template <typename... E, typename F, typename R> constexpr auto apply_each2(F&& f, R&& r, E&&... e) { return r(f(std::forward<E>(e))...); //(void)std::initializer_list<int>{ // ((void)f(std::forward<E>(e)), 0)...}; } // Map a function(key, value) on all kv pair an reduce // all the results value with the reduce(r1, r2, ...) function. template <typename... M, typename F, typename R> constexpr decltype(auto) map_reduce(const metamap<M...>& m, F map, R reduce) { auto apply = [&](auto key) -> decltype(auto) { // return map(key, std::forward<decltype(m[key])>(m[key])); return map(key, m[key]); }; return apply_each2(apply, reduce, typename M::_iod_symbol_type{}...); // return reduce(apply(typename M::_iod_symbol_type{})...); } // Map a function(key, value) on all kv pair an reduce // all the results value with the reduce(r1, r2, ...) function. template <typename... M, typename R> constexpr decltype(auto) reduce(const metamap<M...>& m, R reduce) { return reduce(m[typename M::_iod_symbol_type{}]...); } } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_MAP_REDUCE_HH namespace li { template <typename... T, typename... U> constexpr inline decltype(auto) intersection(const metamap<T...>& a, const metamap<U...>& b) { return map_reduce(a, [&](auto k, auto&& v) -> decltype(auto) { if constexpr (has_key<metamap<U...>, decltype(k)>()) { return k = std::forward<decltype(v)>(v); } else return skip{}; }, make_metamap_skip); } } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_INTERSECTION_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_SUBSTRACT_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_SUBSTRACT_HH namespace li { template <typename... T, typename... U> constexpr inline auto substract(const metamap<T...>& a, const metamap<U...>& b) { return map_reduce(a, [&](auto k, auto&& v) { if constexpr (!has_key<metamap<U...>, decltype(k)>()) { return k = std::forward<decltype(v)>(v); } else return skip{}; }, make_metamap_skip); } } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_SUBSTRACT_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_FORWARD_TUPLE_AS_METAMAP_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_FORWARD_TUPLE_AS_METAMAP_HH namespace li { namespace internal { template <typename... S, typename... V, typename T, T... I> constexpr auto forward_tuple_as_metamap_impl(std::tuple<S...> keys, std::tuple<V...>& values, std::integer_sequence<T, I...>) { return make_metamap_reference((std::get<I>(keys) = std::get<I>(values))...); } template <typename... S, typename... V, typename T, T... I> constexpr auto forward_tuple_as_metamap_impl(std::tuple<S...> keys, const std::tuple<V...>& values, std::integer_sequence<T, I...>) { return make_metamap_reference((std::get<I>(keys) = std::get<I>(values))...); } } // namespace internal template <typename... S, typename... V> constexpr auto forward_tuple_as_metamap(std::tuple<S...> keys, std::tuple<V...>& values) { return internal::forward_tuple_as_metamap_impl(keys, values, std::make_index_sequence<sizeof...(V)>{}); } template <typename... S, typename... V> constexpr auto forward_tuple_as_metamap(std::tuple<S...> keys, const std::tuple<V...>& values) { return internal::forward_tuple_as_metamap_impl(keys, values, std::make_index_sequence<sizeof...(V)>{}); } } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_ALGORITHMS_FORWARD_TUPLE_AS_METAMAP_HH #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_METAMAP_METAMAP_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_CONNECTION_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_CONNECTION_HH #if not defined(_WIN32) #endif #include "libpq-fe.h" #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_RESULT_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_RESULT_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_COMMON_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_COMMON_HH namespace li { struct sql_blob : public std::string { using std::string::string; using std::string::operator=; sql_blob() : std::string() {} }; struct sql_null_t {}; static sql_null_t null; template <unsigned SIZE> struct sql_varchar : public std::string { using std::string::string; using std::string::operator=; sql_varchar() : std::string() {} }; } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_COMMON_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_CONNECTION_DATA_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_CONNECTION_DATA_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_TYPE_HASHMAP_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_TYPE_HASHMAP_HH namespace li { template <typename V> struct type_hashmap { template <typename E, typename F> E& get_cache_entry(int& hash, F) { // Init hash if needed. if (hash == -1) { std::lock_guard lock(mutex_); if (hash == -1) hash = counter_++; } // Init cache if miss. if (hash >= values_.size() or !values_[hash].has_value()) { if (values_.size() < hash + 1) values_.resize(hash+1); values_[hash] = E(); } // Return existing cache entry. return std::any_cast<E&>(values_[hash]); } template <typename K, typename F> V& operator()(F f, K key) { static int hash = -1; return this->template get_cache_entry<std::unordered_map<K, V>>(hash, f)[key]; } template <typename F> V& operator()(F f) { static int hash = -1; return this->template get_cache_entry<V>(hash, f); } private: static std::mutex mutex_; static int counter_; std::vector<std::any> values_; }; template <typename V> std::mutex type_hashmap<V>::mutex_; template <typename V> int type_hashmap<V>::counter_ = 0; } #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_TYPE_HASHMAP_HH namespace li { struct pgsql_statement_data; struct pgsql_connection_data { ~pgsql_connection_data() { if (pgconn_) { cancel(); PQfinish(pgconn_); } } void cancel() { if (pgconn_) { // Cancel any pending request. PGcancel* cancel = PQgetCancel(pgconn_); char x[256]; if (cancel) { PQcancel(cancel, x, 256); PQfreeCancel(cancel); } } } template <typename Y> void flush(Y& fiber) { while(int ret = PQflush(pgconn_)) { if (ret == -1) { std::cerr << "PQflush error" << std::endl; } if (ret == 1) fiber.yield(); } } PGconn* pgconn_ = nullptr; int fd = -1; std::unordered_map<std::string, std::shared_ptr<pgsql_statement_data>> statements; type_hashmap<std::shared_ptr<pgsql_statement_data>> statements_hashmap; int error_ = 0; }; } #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_CONNECTION_DATA_HH namespace li { template <typename Y> struct pgsql_result { public: ~pgsql_result() { if (current_result_) PQclear(current_result_); } // Read metamap and tuples. template <typename T> bool read(T&& t1); long long int last_insert_id(); // Flush all results. void flush_results(); std::shared_ptr<pgsql_connection_data> connection_; Y& fiber_; int last_insert_id_ = -1; int row_i_ = 0; int current_result_nrows_ = 0; PGresult* current_result_ = nullptr; std::vector<Oid> curent_result_field_types_; std::vector<int> curent_result_field_positions_; private: // Wait for the next result. PGresult* wait_for_next_result(); // Fetch a string from a result field. template <typename... A> void fetch_value(std::string& out, int field_i, Oid field_type); // Fetch a blob from a result field. template <typename... A> void fetch_value(sql_blob& out, int field_i, Oid field_type); // Fetch an int from a result field. void fetch_value(int& out, int field_i, Oid field_type); // Fetch an unsigned int from a result field. void fetch_value(unsigned int& out, int field_i, Oid field_type); }; } // namespace li #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_RESULT_HPP #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_RESULT_HPP #ifdef _WIN32 #else #endif #include "libpq-fe.h" #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_INTERNAL_UTILS_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_INTERNAL_UTILS_HH namespace li { template <typename T> struct is_tuple_after_decay : std::false_type {}; template <typename... T> struct is_tuple_after_decay<std::tuple<T...>> : std::true_type {}; template <typename T> struct is_tuple : is_tuple_after_decay<std::decay_t<T>> {}; template <typename T> struct unconstref_tuple_elements {}; template <typename... T> struct unconstref_tuple_elements<std::tuple<T...>> { typedef std::tuple<std::remove_const_t<std::remove_reference_t<T>>...> ret; }; } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_INTERNAL_UTILS_HH #if __APPLE__ #endif //#include <catalog/pg_type_d.h> #if __APPLE__ // from https://gist.github.com/yinyin/2027912 #define be64toh(x) OSSwapBigToHostInt64(x) #elif _WIN32 // from https://gist.github.com/PkmX/63dd23f28ba885be53a5 #define be64toh(x) _byteswap_uint64(x) #endif #define INT8OID 20 #define INT2OID 21 #define INT4OID 23 namespace li { template <typename Y> PGresult* pg_wait_for_next_result(PGconn* connection, Y& fiber, int& connection_status, bool nothrow = false) { // std::cout << "WAIT ======================" << std::endl; while (true) { if (PQconsumeInput(connection) == 0) { connection_status = 1; if (!nothrow) throw std::runtime_error(std::string("PQconsumeInput() failed: ") + PQerrorMessage(connection)); else std::cerr << "PQconsumeInput() failed: " << PQerrorMessage(connection) << std::endl; #ifdef DEBUG assert(0); #endif } if (PQisBusy(connection)) { // std::cout << "isbusy" << std::endl; try { fiber.yield(); } catch (typename Y::exception_type& e) { // Free results. // Yield thrown a exception (probably because a closed connection). // Flush the remaining results. while (true) { if (PQconsumeInput(connection) == 0) { connection_status = 1; break; } if (!PQisBusy(connection)) { PGresult* res = PQgetResult(connection); if (res) PQclear(res); else break; } } throw std::move(e); } } else { // std::cout << "notbusy" << std::endl; PGresult* res = PQgetResult(connection); if (PQresultStatus(res) == PGRES_FATAL_ERROR and PQerrorMessage(connection)[0] != 0) { PQclear(res); connection_status = 1; if (!nothrow) throw std::runtime_error(std::string("Postresql fatal error:") + PQerrorMessage(connection)); else std::cerr << "Postgresql FATAL error: " << PQerrorMessage(connection) << std::endl; #ifdef DEBUG assert(0); #endif } else if (PQresultStatus(res) == PGRES_NONFATAL_ERROR) std::cerr << "Postgresql non fatal error: " << PQerrorMessage(connection) << std::endl; return res; } } } template <typename Y> PGresult* pgsql_result<Y>::wait_for_next_result() { return pg_wait_for_next_result(connection_->pgconn_, fiber_, connection_->error_); } template <typename Y> void pgsql_result<Y>::flush_results() { try { while (true) { if (connection_->error_ == 1) break; PGresult* res = pg_wait_for_next_result(connection_->pgconn_, fiber_, connection_->error_, true); if (res) PQclear(res); else break; } } catch (typename Y::exception_type& e) { // Forward fiber execptions. throw std::move(e); } } // Fetch a string from a result field. template <typename Y> template <typename... A> void pgsql_result<Y>::fetch_value(std::string& out, int field_i, Oid field_type) { // assert(!is_binary); // std::cout << "fetch string: " << length << " '"<< val <<"'" << std::endl; out = std::move(std::string(PQgetvalue(current_result_, row_i_, field_i), PQgetlength(current_result_, row_i_, field_i))); // out = std::move(std::string(val, strlen(val))); } // Fetch a blob from a result field. template <typename Y> template <typename... A> void pgsql_result<Y>::fetch_value(sql_blob& out, int field_i, Oid field_type) { // assert(is_binary); out = std::move(std::string(PQgetvalue(current_result_, row_i_, field_i), PQgetlength(current_result_, row_i_, field_i))); } // Fetch an int from a result field. template <typename Y> void pgsql_result<Y>::fetch_value(int& out, int field_i, Oid field_type) { assert(PQfformat(current_result_, field_i) == 1); // Assert binary format char* val = PQgetvalue(current_result_, row_i_, field_i); // TYPCATEGORY_NUMERIC // std::cout << "fetch integer " << length << " " << is_binary << std::endl; // std::cout << "fetch integer " << be64toh(*((uint64_t *) val)) << std::endl; if (field_type == INT8OID) { // std::cout << "fetch 64b integer " << std::hex << int(32) << std::endl; // std::cout << "fetch 64b integer " << std::hex << uint64_t(*((uint64_t *) val)) << std::endl; // std::cout << "fetch 64b integer " << std::hex << (*((uint64_t *) val)) << std::endl; // std::cout << "fetch 64b integer " << std::hex << be64toh(*((uint64_t *) val)) << std::endl; out = be64toh(*((uint64_t*)val)); } else if (field_type == INT4OID) out = (uint32_t)ntohl(*((uint32_t*)val)); else if (field_type == INT2OID) out = (uint16_t)ntohs(*((uint16_t*)val)); else throw std::runtime_error("The type of request result does not match the destination type"); } // Fetch an unsigned int from a result field. template <typename Y> void pgsql_result<Y>::fetch_value(unsigned int& out, int field_i, Oid field_type) { assert(PQfformat(current_result_, field_i) == 1); // Assert binary format char* val = PQgetvalue(current_result_, row_i_, field_i); // if (length == 8) if (field_type == INT8OID) out = be64toh(*((uint64_t*)val)); else if (field_type == INT4OID) out = ntohl(*((uint32_t*)val)); else if (field_type == INT2OID) out = ntohs(*((uint16_t*)val)); else assert(0); } template <typename B> template <typename T> bool pgsql_result<B>::read(T&& output) { if (!current_result_ || row_i_ == current_result_nrows_) { if (current_result_) { PQclear(current_result_); current_result_ = nullptr; } current_result_ = wait_for_next_result(); if (!current_result_) return false; row_i_ = 0; current_result_nrows_ = PQntuples(current_result_); if (current_result_nrows_ == 0) { PQclear(current_result_); current_result_ = nullptr; return false; } // Metamaps. if constexpr (is_metamap<std::decay_t<T>>::value) { curent_result_field_positions_.clear(); li::map(std::forward<T>(output), [&](auto k, auto& m) { curent_result_field_positions_.push_back(PQfnumber(current_result_, symbol_string(k))); if (curent_result_field_positions_.back() == -1) throw std::runtime_error(std::string("postgresql errror : Field ") + symbol_string(k) + " not found in result."); }); } if (curent_result_field_types_.size() == 0) { curent_result_field_types_.resize(PQnfields(current_result_)); for (int field_i = 0; field_i < curent_result_field_types_.size(); field_i++) curent_result_field_types_[field_i] = PQftype(current_result_, field_i); } } // Tuples if constexpr (is_tuple<T>::value) { int field_i = 0; int nfields = curent_result_field_types_.size(); if (nfields != std::tuple_size_v<std::decay_t<T>>) throw std::runtime_error("postgresql error: in fetch: Mismatch between the request number of " "field and the outputs."); tuple_map(std::forward<T>(output), [&](auto& m) { fetch_value(m, field_i, curent_result_field_types_[field_i]); field_i++; }); } else { // Metamaps. int i = 0; li::map(std::forward<T>(output), [&](auto k, auto& m) { int field_i = curent_result_field_positions_[i]; fetch_value(m, field_i, curent_result_field_types_[field_i]); i++; }); } this->row_i_++; return true; } // Get the last id of the row inserted by the last command. template <typename Y> long long int pgsql_result<Y>::last_insert_id() { // while (PGresult* res = wait_for_next_result()) // PQclear(res); // PQsendQuery(connection_, "LASTVAL()"); int t = 0; this->read(std::tie(t)); return t; // PGresult *PQexec(connection_, const char *command); // this->operator() // last_insert_id_ = PQoidValue(res); // std::cout << "id " << last_insert_id_ << std::endl; // PQclear(res); // } // return last_insert_id_; } } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_RESULT_HPP #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_RESULT_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_STATEMENT_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_STATEMENT_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SYMBOLS_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SYMBOLS_HH #ifndef LI_SYMBOL_ATTR #define LI_SYMBOL_ATTR LI_SYMBOL(ATTR) #endif #ifndef LI_SYMBOL_after_insert #define LI_SYMBOL_after_insert LI_SYMBOL(after_insert) #endif #ifndef LI_SYMBOL_after_remove #define LI_SYMBOL_after_remove LI_SYMBOL(after_remove) #endif #ifndef LI_SYMBOL_after_update #define LI_SYMBOL_after_update LI_SYMBOL(after_update) #endif #ifndef LI_SYMBOL_auto_increment #define LI_SYMBOL_auto_increment LI_SYMBOL(auto_increment) #endif #ifndef LI_SYMBOL_before_insert #define LI_SYMBOL_before_insert LI_SYMBOL(before_insert) #endif #ifndef LI_SYMBOL_before_remove #define LI_SYMBOL_before_remove LI_SYMBOL(before_remove) #endif #ifndef LI_SYMBOL_before_update #define LI_SYMBOL_before_update LI_SYMBOL(before_update) #endif #ifndef LI_SYMBOL_charset #define LI_SYMBOL_charset LI_SYMBOL(charset) #endif #ifndef LI_SYMBOL_computed #define LI_SYMBOL_computed LI_SYMBOL(computed) #endif #ifndef LI_SYMBOL_connections #define LI_SYMBOL_connections LI_SYMBOL(connections) #endif #ifndef LI_SYMBOL_database #define LI_SYMBOL_database LI_SYMBOL(database) #endif #ifndef LI_SYMBOL_host #define LI_SYMBOL_host LI_SYMBOL(host) #endif #ifndef LI_SYMBOL_id #define LI_SYMBOL_id LI_SYMBOL(id) #endif #ifndef LI_SYMBOL_max_async_connections_per_thread #define LI_SYMBOL_max_async_connections_per_thread LI_SYMBOL(max_async_connections_per_thread) #endif #ifndef LI_SYMBOL_max_connections #define LI_SYMBOL_max_connections LI_SYMBOL(max_connections) #endif #ifndef LI_SYMBOL_max_sync_connections #define LI_SYMBOL_max_sync_connections LI_SYMBOL(max_sync_connections) #endif #ifndef LI_SYMBOL_n_connections #define LI_SYMBOL_n_connections LI_SYMBOL(n_connections) #endif #ifndef LI_SYMBOL_password #define LI_SYMBOL_password LI_SYMBOL(password) #endif #ifndef LI_SYMBOL_port #define LI_SYMBOL_port LI_SYMBOL(port) #endif #ifndef LI_SYMBOL_primary_key #define LI_SYMBOL_primary_key LI_SYMBOL(primary_key) #endif #ifndef LI_SYMBOL_read_access #define LI_SYMBOL_read_access LI_SYMBOL(read_access) #endif #ifndef LI_SYMBOL_read_only #define LI_SYMBOL_read_only LI_SYMBOL(read_only) #endif #ifndef LI_SYMBOL_synchronous #define LI_SYMBOL_synchronous LI_SYMBOL(synchronous) #endif #ifndef LI_SYMBOL_user #define LI_SYMBOL_user LI_SYMBOL(user) #endif #ifndef LI_SYMBOL_validate #define LI_SYMBOL_validate LI_SYMBOL(validate) #endif #ifndef LI_SYMBOL_waiting_list #define LI_SYMBOL_waiting_list LI_SYMBOL(waiting_list) #endif #ifndef LI_SYMBOL_write_access #define LI_SYMBOL_write_access LI_SYMBOL(write_access) #endif #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SYMBOLS_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_RESULT_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_RESULT_HH namespace li { /** * @brief Provide access to the result of a sql query. */ template <typename I> struct sql_result { I impl_; sql_result() = delete; sql_result& operator=(sql_result&) = delete; sql_result(const sql_result&) = delete; sql_result(I&& impl) : impl_(std::forward<I>(impl)) {} inline ~sql_result() { this->flush_results(); } inline void flush_results() { impl_.flush_results(); } /** * @brief Return the last id generated by a insert comment. * With postgresql, it requires the previous command to use the "INSERT [...] returning id;" * syntax. * * @return the last inserted id. */ long long int last_insert_id() { return impl_.last_insert_id(); } /** * @brief read one row of the result set and advance to next row. * Throw an exception if the end of the result set is reached. * * @return If only one template argument is provided return this same type. * otherwise return a std::tuple of the requested types. */ template <typename T1, typename... T> auto read(); /** * @brief Like read<T>() but do not throw is the eand of the result set is reached, instead * it wraps the result in a std::optional that is empty if no data could be fetch. * */ template <typename T1, typename... T> auto read_optional(); /** * @brief read one row of the result set and advance to next row. * Throw an exception if the end of the result set is reached or if another error happened. * * Valid calls are: * read(std::tuple<...>& ) * fill the tuple according to the current row. The tuple must match * the number of fields in the request. * read(li::metamap<...>& ) * fill the metamap according to the current row. The metamap (value types and keys) must * match the fields (types and names) of the request. * read(A& a, B& b, C& c, ...) * fill a, b, c,... * with each field of the current row. Types of a, b, c... must match the types of the fields. * supported types : only values (i.e not tuples or metamaps) like std::string, integer and floating numbers. * @return T the result value. */ template <typename T1, typename... T> bool read(T1&& t1, T&... tail); template <typename T> void read(std::optional<T>& o); /** * @brief Call \param f on each row of the set. * The function must take as argument all the select fields of the request, it should * follow one of the signature of read (check read documentation for more info). * \param f can take arguments by reference to avoid copies but keep in mind that * there references will be invalid at the end of the function scope. * * @example connection.prepare("Select id,post from post_items;")().map( * [&](std::string id, std::string post) { * std::cout << id << post << std::endl; }); * * @param f the function. */ template <typename F> void map(F f); }; } // namespace li #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_RESULT_HPP #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_RESULT_HPP namespace li { template <typename B> template <typename T1, typename... T> bool sql_result<B>::read(T1&& t1, T&... tail) { // Metamap and tuples if constexpr (li::is_metamap<std::decay_t<T1>>::value || li::is_tuple<std::decay_t<T1>>::value) { static_assert(sizeof...(T) == 0); return impl_.read(std::forward<T1>(t1)); } // Scalar values. else return impl_.read(std::tie(t1, tail...)); } template <typename B> template <typename T1, typename... T> auto sql_result<B>::read() { auto t = [] { if constexpr (sizeof...(T) == 0) return T1{}; else return std::tuple<T1, T...>{}; }(); if (!this->read(t)) throw std::runtime_error("sql_result::read: error: Trying to read a request that did not return any data."); return t; } template <typename B> template <typename T> void sql_result<B>::read(std::optional<T>& o) { o = this->read_optional<T>(); } template <typename B> template <typename T1, typename... T> auto sql_result<B>::read_optional() { auto t = [] { if constexpr (sizeof...(T) == 0) return T1{}; else return std::tuple<T1, T...>{}; }(); if (this->read(t)) return std::make_optional(std::move(t)); else return std::optional<decltype(t)>{}; } namespace internal { template<typename T, typename F> constexpr auto is_valid(F&& f) -> decltype(f(std::declval<T>()), true) { return true; } template<typename> constexpr bool is_valid(...) { return false; } } #define IS_VALID(T, EXPR) internal::is_valid<T>( [](auto&& obj)->decltype(obj.EXPR){} ) template <typename B> template <typename F> void sql_result<B>::map(F map_function) { if constexpr (IS_VALID(B, map(map_function))) this->impl_.map(map_function); typedef typename unconstref_tuple_elements<callable_arguments_tuple_t<F>>::ret TP; typedef std::tuple_element_t<0, TP> TP0; auto t = [] { static_assert(std::tuple_size_v<TP> > 0, "sql_result map function must take at least 1 argument."); if constexpr (is_tuple<TP0>::value || is_metamap<TP0>::value) return TP0{}; else return TP{}; }(); while (this->read(t)) { if constexpr (is_tuple<TP0>::value || is_metamap<TP0>::value) map_function(t); else std::apply(map_function, t); } } } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_RESULT_HPP #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_RESULT_HH namespace li { struct pgsql_statement_data : std::enable_shared_from_this<pgsql_statement_data> { pgsql_statement_data(const std::string& s) : stmt_name(s) {} std::string stmt_name; }; template <typename Y> struct pgsql_statement { public: template <typename... T> sql_result<pgsql_result<Y>> operator()(T&&... args); std::shared_ptr<pgsql_connection_data> connection_; Y& fiber_; pgsql_statement_data& data_; private: // Bind statement param utils. template <unsigned N> void bind_param(sql_varchar<N>&& m, const char** values, int* lengths, int* binary); template <unsigned N> void bind_param(const sql_varchar<N>& m, const char** values, int* lengths, int* binary); void bind_param(const char* m, const char** values, int* lengths, int* binary); template <typename T> void bind_param(const std::vector<T>& m, const char** values, int* lengths, int* binary); template <typename T> void bind_param(const T& m, const char** values, int* lengths, int* binary); template <typename T> unsigned int bind_compute_nparam(const T& arg); template <typename... T> unsigned int bind_compute_nparam(const metamap<T...>& arg); template <typename T> unsigned int bind_compute_nparam(const std::vector<T>& arg); // Bind parameter to the prepared statement and execute it. // FIXME long long int affected_rows() { return pgsql_stmt_affected_rows(data_.stmt_); } }; } // namespace li #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_STATEMENT_HPP #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_STATEMENT_HPP #ifdef _WIN32 #endif namespace li { // Execute a request with placeholders. template <typename Y> template <unsigned N> void pgsql_statement<Y>::bind_param(sql_varchar<N>&& m, const char** values, int* lengths, int* binary) { // std::cout << "send param varchar " << m << std::endl; *values = m.c_str(); *lengths = m.size(); *binary = 0; } template <typename Y> template <unsigned N> void pgsql_statement<Y>::bind_param(const sql_varchar<N>& m, const char** values, int* lengths, int* binary) { // std::cout << "send param const varchar " << m << std::endl; *values = m.c_str(); *lengths = m.size(); *binary = 0; } template <typename Y> void pgsql_statement<Y>::bind_param(const char* m, const char** values, int* lengths, int* binary) { // std::cout << "send param const char*[N] " << m << std::endl; *values = m; *lengths = strlen(m); *binary = 0; } template <typename Y> template <typename T> void pgsql_statement<Y>::bind_param(const std::vector<T>& m, const char** values, int* lengths, int* binary) { int tsize = [&] { if constexpr (is_metamap<T>::value) return metamap_size<T>(); else return 1; }(); int i = 0; for (int i = 0; i < m.size(); i++) bind_param(m[i], values + i * tsize, lengths + i * tsize, binary + i * tsize); } template <typename Y> template <typename T> void pgsql_statement<Y>::bind_param(const T& m, const char** values, int* lengths, int* binary) { if constexpr (is_metamap<std::decay_t<decltype(m)>>::value) { int i = 0; li::map(m, [&](auto k, const auto& m) { bind_param(m, values + i, lengths + i, binary + i); i++; }); } else if constexpr (std::is_same<std::decay_t<decltype(m)>, std::string>::value or std::is_same<std::decay_t<decltype(m)>, std::string_view>::value) { // std::cout << "send param string: " << m << std::endl; *values = m.c_str(); *lengths = m.size(); *binary = 0; } else if constexpr (std::is_same<std::remove_reference_t<decltype(m)>, const char*>::value) { // std::cout << "send param const char* " << m << std::endl; *values = m; *lengths = strlen(m); *binary = 0; } else if constexpr (std::is_same<std::decay_t<decltype(m)>, int>::value) { *values = (char*)new int(htonl(m)); *lengths = sizeof(m); *binary = 1; } else if constexpr (std::is_same<std::decay_t<decltype(m)>, long long int>::value) { // FIXME send 64bit values. // std::cout << "long long int param: " << m << std::endl; *values = (char*)new int(htonl(uint32_t(m))); *lengths = sizeof(uint32_t); // does not work: // values = (char*)new uint64_t(htobe64((uint64_t) m)); // lengths = sizeof(uint64_t); *binary = 1; } } template <typename Y> template <typename T> unsigned int pgsql_statement<Y>::bind_compute_nparam(const T& arg) { return 1; } template <typename Y> template <typename... T> unsigned int pgsql_statement<Y>::bind_compute_nparam(const metamap<T...>& arg) { return sizeof...(T); } template <typename Y> template <typename T> unsigned int pgsql_statement<Y>::bind_compute_nparam(const std::vector<T>& arg) { return arg.size() * bind_compute_nparam(arg[0]); } // Bind parameter to the prepared statement and execute it. template <typename Y> template <typename... T> sql_result<pgsql_result<Y>> pgsql_statement<Y>::operator()(T&&... args) { unsigned int nparams = 0; if constexpr (sizeof...(T) > 0) nparams = (bind_compute_nparam(std::forward<T>(args)) + ...); #ifdef _WIN32 // MSVC does not support variable sized arrays. std::vector<const char*> values_(nparams); std::vector<int> lengths_(nparams); std::vector<int> binary_(nparams); const char** values = values_.data(); int* lengths = lengths_.data(); int* binary = binary_.data(); #else const char* values_[nparams]; int lengths_[nparams]; int binary_[nparams]; const char** values = values_; int* lengths = lengths_; int* binary = binary_; #endif int i = 0; tuple_map(std::forward_as_tuple(args...), [&](const auto& a) { bind_param(a, values + i, lengths + i, binary + i); i += bind_compute_nparam(a); }); if (!PQsendQueryPrepared(connection_->pgconn_, data_.stmt_name.c_str(), nparams, values, lengths, binary, 1)) { throw std::runtime_error(std::string("Postresql error:") + PQerrorMessage(connection_->pgconn_)); } // Now calling pqflush seems to work aswell... // connection_->flush(this->fiber_); return sql_result<pgsql_result<Y>>{ pgsql_result<Y>{this->connection_, this->fiber_}}; } // FIXME long long int affected_rows() { return pgsql_stmt_affected_rows(data_.stmt_); } } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_STATEMENT_HPP #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_STATEMENT_HH namespace li { struct pgsql_tag {}; // template <typename Y> void pq_wait(Y& yield, PGconn* con) { // while (PQisBusy(con)) // yield(); // } template <typename Y> struct pgsql_connection { Y& fiber_; std::shared_ptr<pgsql_connection_data> data_; std::unordered_map<std::string, std::shared_ptr<pgsql_statement_data>>& stm_cache_; PGconn* connection_; typedef pgsql_tag db_tag; inline pgsql_connection(const pgsql_connection&) = delete; inline pgsql_connection& operator=(const pgsql_connection&) = delete; inline pgsql_connection(pgsql_connection&& o) = default; inline pgsql_connection(Y& fiber, std::shared_ptr<pgsql_connection_data>& data) : fiber_(fiber), data_(data), stm_cache_(data->statements), connection_(data->pgconn_) { } // FIXME long long int last_insert_rowid() { return pgsql_insert_id(connection_); } // pgsql_statement<Y> operator()(const std::string& rq) { return prepare(rq)(); } auto operator()(const std::string& rq) { if (!PQsendQueryParams(connection_, rq.c_str(), 0, nullptr, nullptr, nullptr, nullptr, 1)) throw std::runtime_error(std::string("Postresql error:") + PQerrorMessage(connection_)); return sql_result<pgsql_result<Y>>{ pgsql_result<Y>{this->data_, this->fiber_, data_->error_}}; } // PQsendQueryParams template <typename F, typename... K> pgsql_statement<Y> cached_statement(F f, K... keys) { if (data_->statements_hashmap(f, keys...).get() == nullptr) { pgsql_statement<Y> res = prepare(f()); data_->statements_hashmap(f, keys...) = res.data_.shared_from_this(); return res; } else return pgsql_statement<Y>{data_, fiber_, *data_->statements_hashmap(f, keys...)}; } pgsql_statement<Y> prepare(const std::string& rq) { auto it = stm_cache_.find(rq); if (it != stm_cache_.end()) { return pgsql_statement<Y>{data_, fiber_, *it->second}; } std::string stmt_name = boost::lexical_cast<std::string>(stm_cache_.size()); if (!PQsendPrepare(connection_, stmt_name.c_str(), rq.c_str(), 0, nullptr)) { throw std::runtime_error(std::string("PQsendPrepare error") + PQerrorMessage(connection_)); } // flush results. while (PGresult* ret = pg_wait_for_next_result(connection_, fiber_, data_->error_)) PQclear(ret); auto pair = stm_cache_.emplace(rq, std::make_shared<pgsql_statement_data>(stmt_name)); return pgsql_statement<Y>{data_, fiber_, *pair.first->second}; } template <typename T> inline std::string type_to_string(const T&, std::enable_if_t<std::is_integral<T>::value>* = 0) { return "INT"; } template <typename T> inline std::string type_to_string(const T&, std::enable_if_t<std::is_floating_point<T>::value>* = 0) { return "DOUBLE"; } inline std::string type_to_string(const std::string&) { return "TEXT"; } inline std::string type_to_string(const sql_blob&) { return "BLOB"; } template <unsigned S> inline std::string type_to_string(const sql_varchar<S>) { std::ostringstream ss; ss << "VARCHAR(" << S << ')'; return ss.str(); } }; } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_CONNECTION_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_DATABASE_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_DATABASE_HH namespace li { // thread local map of sql_database<I>* -> sql_database_thread_local_data<I>*; // This is used to store the thread local async connection pool. // void* is used instead of concrete types to handle different I parameter. #ifndef _WIN32 thread_local std::unordered_map<void*, void*> sql_thread_local_data [[gnu::weak]]; #else __declspec(selectany) thread_local std::unordered_map<void*, void*> sql_thread_local_data; #endif template <typename I> struct sql_database_thread_local_data { typedef typename I::connection_data_type connection_data_type; // Async connection pools. std::deque<connection_data_type*> async_connections_; int n_connections_on_this_thread_ = 0; std::deque<int> fibers_waiting_for_connections_; }; struct active_yield { typedef std::runtime_error exception_type; int fiber_id = 0; inline void defer(std::function<void()>) {} inline void defer_fiber_resume(int fiber_id) {} inline void reassign_fd_to_this_fiber(int fd) {} inline void epoll_add(int fd, int flags) {} inline void epoll_mod(int fd, int flags) {} inline void yield() {} }; template <typename I> struct sql_database { I impl; typedef typename I::connection_data_type connection_data_type; typedef typename I::db_tag db_tag; // Sync connections pool. std::deque<connection_data_type*> sync_connections_; // Sync connections mutex. std::mutex sync_connections_mutex_; int n_sync_connections_ = 0; int max_sync_connections_ = 0; int max_async_connections_per_thread_ = 0; template <typename... O> sql_database(O&&... opts) : impl(std::forward<O>(opts)...) { auto options = mmm(opts...); max_async_connections_per_thread_ = get_or(options, s::max_async_connections_per_thread, 200); max_sync_connections_ = get_or(options, s::max_sync_connections, 2000); } ~sql_database() { clear_connections(); } void clear_connections() { auto it = sql_thread_local_data.find(this); if (it != sql_thread_local_data.end()) { auto store = (sql_database_thread_local_data<I>*) it->second; for (auto ptr : store->async_connections_) delete ptr; delete store; sql_thread_local_data.erase(this); } std::lock_guard<std::mutex> lock(this->sync_connections_mutex_); for (auto* ptr : this->sync_connections_) delete ptr; sync_connections_.clear(); n_sync_connections_ = 0; } auto& thread_local_data() { auto it = sql_thread_local_data.find(this); if (it == sql_thread_local_data.end()) { auto data = new sql_database_thread_local_data<I>; sql_thread_local_data[this] = data; return *data; } else return *(sql_database_thread_local_data<I>*) it->second; } /** * @brief Build aa new database connection. The connection provides RAII: it will be * placed back in the available connection pool whenever its constructor is called. * * @param fiber the fiber object providing the 3 non blocking logic methods: * * - void epoll_add(int fd, int flags); // Make the current epoll fiber wakeup on * file descriptor fd * - void epoll_mod(int fd, int flags); // Modify the epoll flags on file * descriptor fd * - void yield() // Yield the current epoll fiber. * * @return the new connection. */ template <typename Y> inline auto connect(Y& fiber) { auto& tldata = this->thread_local_data(); auto pool = [this, &tldata] { if constexpr (std::is_same_v<Y, active_yield>) // Synchonous mode return make_metamap_reference( s::connections = this->sync_connections_, s::n_connections = this->n_sync_connections_, s::max_connections = this->max_sync_connections_); else // Asynchonous mode return make_metamap_reference( s::connections = tldata.async_connections_, s::n_connections = tldata.n_connections_on_this_thread_, s::max_connections = this->max_async_connections_per_thread_, s::waiting_list = tldata.fibers_waiting_for_connections_); }(); connection_data_type* data = nullptr; bool reuse = false; time_t start_time = time(NULL); while (!data) { if (!pool.connections.empty()) { auto lock = [&pool, this] { if constexpr (std::is_same_v<Y, active_yield>) return std::lock_guard<std::mutex>(this->sync_connections_mutex_); else return 0; }(); data = pool.connections.back(); pool.connections.pop_back(); reuse = true; } else { if (pool.n_connections >= pool.max_connections) { if constexpr (std::is_same_v<Y, active_yield>) throw std::runtime_error("Maximum number of sql connection exeeded."); else { // std::cout << "Waiting for a free sql connection..." << std::endl; // pool.waiting_list.push_back(fiber.fiber_id); fiber.yield(); } continue; } pool.n_connections++; try { data = impl.new_connection(fiber); } catch (typename Y::exception_type& e) { pool.n_connections--; throw std::move(e); } if (!data) pool.n_connections--; } if (time(NULL) > start_time + 10) throw std::runtime_error("Timeout: Cannot connect to the database."); } assert(data); assert(data->error_ == 0); auto sptr = std::shared_ptr<connection_data_type>(data, [pool, this, &fiber](connection_data_type* data) { if (!data->error_ && pool.connections.size() < pool.max_connections) { auto lock = [&pool, this] { if constexpr (std::is_same_v<Y, active_yield>) return std::lock_guard<std::mutex>(this->sync_connections_mutex_); else return 0; }(); pool.connections.push_back(data); if constexpr (!std::is_same_v<Y, active_yield>) if (pool.waiting_list.size()) { int next_fiber_id = pool.waiting_list.front(); pool.waiting_list.pop_front(); fiber.defer_fiber_resume(next_fiber_id); } } else { // This is not an error since connection pool.max_connections can vary during execution. // It is ok just to discard extraneous in order to reach a lower pool.max_connections. // if (pool.connections.size() >= pool.max_connections) // std::cerr << "Error: connection pool size " << pool.connections.size() // << " exceed pool max_connections " << pool.max_connections << " " << pool.n_connections<< std::endl; pool.n_connections--; delete data; } }); if (reuse) fiber.reassign_fd_to_this_fiber(impl.get_socket(sptr)); return impl.scoped_connection(fiber, sptr); } /** * @brief Provide a new mysql blocking connection. The connection provides RAII: it will be * placed back in the available connection pool whenver its constructor is called. * * @return the connection. */ inline auto connect() { active_yield yield; return this->connect(yield); } }; } #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_DATABASE_HH namespace li { struct pgsql_database_impl { typedef pgsql_connection_data connection_data_type; typedef pgsql_tag db_tag; std::string host_, user_, passwd_, database_; unsigned int port_; std::string character_set_; template <typename... O> inline pgsql_database_impl(O... opts) { auto options = mmm(opts...); static_assert(has_key(options, s::host), "open_pgsql_connection requires the s::host argument"); static_assert(has_key(options, s::database), "open_pgsql_connection requires the s::databaser argument"); static_assert(has_key(options, s::user), "open_pgsql_connection requires the s::user argument"); static_assert(has_key(options, s::password), "open_pgsql_connection requires the s::password argument"); host_ = options.host; database_ = options.database; user_ = options.user; passwd_ = options.password; port_ = get_or(options, s::port, 5432); character_set_ = get_or(options, s::charset, "utf8"); if (!PQisthreadsafe()) throw std::runtime_error("LibPQ is not threadsafe."); } inline int get_socket(const std::shared_ptr<pgsql_connection_data>& data) { return PQsocket(data->pgconn_); } #ifndef __linux__ // Synchronized connection on Windows and MacOS because async hangs indefinitelly // on these plaforms. template <typename Y> inline pgsql_connection_data* new_connection(Y& fiber) { PGconn* connection = nullptr; int pgsql_fd = -1; std::stringstream coninfo; coninfo << "postgresql://" << user_ << ":" << passwd_ << "@" << host_ << ":" << port_ << "/" << database_; // std::cout << "Try to connect: " << coninfo.str() << std::endl; connection = PQconnectdb(coninfo.str().c_str()); if (!connection) { std::cerr << "Warning: PQconnectdb returned null." << std::endl; return nullptr; } pgsql_fd = PQsocket(connection); if (pgsql_fd == -1) { std::cerr << "Warning: PQsocket returned -1: " << PQerrorMessage(connection) << std::endl; // If PQsocket return -1, retry later. PQfinish(connection); return nullptr; } #if __linux__ fiber.epoll_add(pgsql_fd, EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET); #elif __APPLE__ fiber.epoll_add(pgsql_fd, EVFILT_READ | EVFILT_WRITE); #endif // pgsql_set_character_set(pgsql, character_set_.c_str()); return new pgsql_connection_data{connection, pgsql_fd}; } #else template <typename Y> inline pgsql_connection_data* new_connection(Y& fiber) { PGconn* connection = nullptr; int pgsql_fd = -1; std::stringstream coninfo; coninfo << "postgresql://" << user_ << ":" << passwd_ << "@" << host_ << ":" << port_ << "/" << database_; //std::cout << "Try to connect: " << coninfo.str() << std::endl; //connection = PQconnectdb(coninfo.str().c_str()); connection = PQconnectStart(coninfo.str().c_str()); if (!connection) { std::cerr << "Warning: PQconnectStart returned null." << std::endl; return nullptr; } if (PQsetnonblocking(connection, 1) == -1) { std::cerr << "Warning: PQsetnonblocking returned -1: " << PQerrorMessage(connection) << std::endl; PQfinish(connection); return nullptr; } int status = PQconnectPoll(connection); pgsql_fd = PQsocket(connection); if (pgsql_fd == -1) { std::cerr << "Warning: PQsocket returned -1: " << PQerrorMessage(connection) << std::endl; // If PQsocket return -1, retry later. PQfinish(connection); return nullptr; } #if __linux__ fiber.epoll_add(pgsql_fd, EPOLLIN | EPOLLOUT | EPOLLRDHUP); #elif __APPLE__ fiber.epoll_add(pgsql_fd, EVFILT_READ | EVFILT_WRITE); #endif try { int start_time = time(NULL); while (status != PGRES_POLLING_FAILED and status != PGRES_POLLING_OK) { if (time(NULL) > start_time + 10) { std::cerr << "Timeout: Cannot connect to postresql database. Make sure a PostgreSQL server is running " << " at " << host_ << ":" << port_ << std::endl; throw std::runtime_error("Timeout: Cannot connect to postresql database."); } int new_pgsql_fd = PQsocket(connection); if (new_pgsql_fd != pgsql_fd) { pgsql_fd = new_pgsql_fd; #if __linux__ fiber.epoll_add(pgsql_fd, EPOLLIN | EPOLLOUT | EPOLLRDHUP); #elif __APPLE__ fiber.epoll_add(pgsql_fd, EVFILT_READ | EVFILT_WRITE); #endif } fiber.yield(); status = PQconnectPoll(connection); } } catch (typename Y::exception_type& e) { // Yield thrown a exception (probably because a closed connection). PQfinish(connection); throw std::move(e); } // std::cout << "CONNECTED " << std::endl; #if __linux__ fiber.epoll_mod(pgsql_fd, EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET); #elif __APPLE__ fiber.epoll_mod(pgsql_fd, EVFILT_READ | EVFILT_WRITE); #endif if (status != PGRES_POLLING_OK) { std::cerr << "Warning: cannot connect to the postgresql server " << host_ << ": " << PQerrorMessage(connection) << std::endl; PQfinish(connection); return nullptr; } // pgsql_set_character_set(pgsql, character_set_.c_str()); return new pgsql_connection_data{connection, pgsql_fd}; } #endif template <typename Y> auto scoped_connection(Y& fiber, std::shared_ptr<pgsql_connection_data>& data) { return pgsql_connection<Y>(fiber, data); } }; typedef sql_database<pgsql_database_impl> pgsql_database; } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_DATABASE_HH #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_PGSQL_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_ORM_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_ORM_HH #ifndef LITHIUM_SINGLE_HEADER_GUARD_LI_CALLABLE_TRAITS_TUPLE_UTILS_HH #define LITHIUM_SINGLE_HEADER_GUARD_LI_CALLABLE_TRAITS_TUPLE_UTILS_HH namespace li { constexpr int count_first_falses() { return 0; } template <typename... B> constexpr int count_first_falses(bool b1, B... b) { if (b1) return 0; else return 1 + count_first_falses(b...); } template <typename E, typename... T> decltype(auto) arg_get_by_type_(void*, E* a1, T&&... args) { return std::forward<E*>(a1); } template <typename E, typename... T> decltype(auto) arg_get_by_type_(void*, const E* a1, T&&... args) { return std::forward<const E*>(a1); } template <typename E, typename... T> decltype(auto) arg_get_by_type_(void*, E& a1, T&&... args) { return std::forward<E&>(a1); } template <typename E, typename... T> decltype(auto) arg_get_by_type_(void*, const E& a1, T&&... args) { return std::forward<const E&>(a1); } template <typename E, typename T1, typename... T> decltype(auto) arg_get_by_type_(std::enable_if_t<!std::is_same<E, std::decay_t<T1>>::value>*, // void*, T1&&, T&&... args) { return arg_get_by_type_<E>((void*)0, std::forward<T>(args)...); } template <typename E, typename... T> decltype(auto) arg_get_by_type(T&&... args) { return arg_get_by_type_<std::decay_t<E>>(0, args...); } template <typename E, typename... T> decltype(auto) tuple_get_by_type(std::tuple<T...>& tuple) { typedef std::decay_t<E> DE; return std::get<count_first_falses((std::is_same<std::decay_t<T>, DE>::value)...)>(tuple); } template <typename E, typename... T> decltype(auto) tuple_get_by_type(std::tuple<T...>&& tuple) { typedef std::decay_t<E> DE; return std::get<count_first_falses((std::is_same<std::decay_t<T>, DE>::value)...)>(tuple); } template <typename T, typename U> struct tuple_embeds : public std::false_type {}; template <typename... T, typename U> struct tuple_embeds<std::tuple<T...>, U> : public std::integral_constant<bool, count_first_falses(std::is_same<T, U>::value...) != sizeof...(T)> {}; template <typename U, typename... T> struct tuple_embeds_any_ref_of : public std::false_type {}; template <typename U, typename... T> struct tuple_embeds_any_ref_of<std::tuple<T...>, U> : public tuple_embeds<std::tuple<std::decay_t<T>...>, std::decay_t<U>> {}; template <typename T> struct tuple_remove_references; template <typename... T> struct tuple_remove_references<std::tuple<T...>> { typedef std::tuple<std::remove_reference_t<T>...> type; }; template <typename T> using tuple_remove_references_t = typename tuple_remove_references<T>::type; template <typename T> struct tuple_remove_references_and_const; template <typename... T> struct tuple_remove_references_and_const<std::tuple<T...>> { typedef std::tuple<std::remove_const_t<std::remove_reference_t<T>>...> type; }; template <typename T> using tuple_remove_references_and_const_t = typename tuple_remove_references_and_const<T>::type; template <typename T, typename U, typename E> struct tuple_remove_element2; template <typename... T, typename... U, typename E1> struct tuple_remove_element2<std::tuple<E1, T...>, std::tuple<U...>, E1> : public tuple_remove_element2<std::tuple<T...>, std::tuple<U...>, E1> {}; template <typename... T, typename... U, typename T1, typename E1> struct tuple_remove_element2<std::tuple<T1, T...>, std::tuple<U...>, E1> : public tuple_remove_element2<std::tuple<T...>, std::tuple<U..., T1>, E1> {}; template <typename... U, typename E1> struct tuple_remove_element2<std::tuple<>, std::tuple<U...>, E1> { typedef std::tuple<U...> type; }; template <typename T, typename E> struct tuple_remove_element : public tuple_remove_element2<T, std::tuple<>, E> {}; template <typename T, typename... E> struct tuple_remove_elements; template <typename... T, typename E1, typename... E> struct tuple_remove_elements<std::tuple<T...>, E1, E...> { typedef typename tuple_remove_elements<typename tuple_remove_element<std::tuple<T...>, E1>::type, E...>::type type; }; template <typename... T> struct tuple_remove_elements<std::tuple<T...>> { typedef std::tuple<T...> type; }; template <typename A, typename B> struct tuple_minus; template <typename... T, typename... R> struct tuple_minus<std::tuple<T...>, std::tuple<R...>> { typedef typename tuple_remove_elements<std::tuple<T...>, R...>::type type; }; template <typename T, typename... E> using tuple_remove_elements_t = typename tuple_remove_elements<T, E...>::type; template <typename F, size_t... I, typename... T> inline F tuple_map(std::tuple<T...>& t, F f, std::index_sequence<I...>) { return (void)std::initializer_list<int>{((void)f(std::get<I>(t)), 0)...}, f; } template <typename F, typename... T> inline void tuple_map(std::tuple<T...>& t, F f) { tuple_map(t, f, std::index_sequence_for<T...>{}); } template <typename F, size_t... I, typename T> inline decltype(auto) tuple_transform(T&& t, F f, std::index_sequence<I...>) { return std::make_tuple(f(std::get<I>(std::forward<T>(t)))...); } template <typename F, typename T> inline decltype(auto) tuple_transform(T&& t, F f) { return tuple_transform(std::forward<T>(t), f, std::make_index_sequence<std::tuple_size<std::decay_t<T>>{}>{}); } template <template <class> class F, typename T, typename I, typename R, typename X = void> struct tuple_filter_sequence; template <template <class> class F, typename... T, typename R> struct tuple_filter_sequence<F, std::tuple<T...>, std::index_sequence<>, R> { using ret = R; }; template <template <class> class F, typename T1, typename... T, size_t I1, size_t... I, size_t... R> struct tuple_filter_sequence<F, std::tuple<T1, T...>, std::index_sequence<I1, I...>, std::index_sequence<R...>, std::enable_if_t<F<T1>::value>> { using ret = typename tuple_filter_sequence<F, std::tuple<T...>, std::index_sequence<I...>, std::index_sequence<R..., I1>>::ret; }; template <template <class> class F, typename T1, typename... T, size_t I1, size_t... I, size_t... R> struct tuple_filter_sequence<F, std::tuple<T1, T...>, std::index_sequence<I1, I...>, std::index_sequence<R...>, std::enable_if_t<!F<T1>::value>> { using ret = typename tuple_filter_sequence<F, std::tuple<T...>, std::index_sequence<I...>, std::index_sequence<R...>>::ret; }; template <std::size_t... I, typename T> decltype(auto) tuple_filter_impl(std::index_sequence<I...>, T&& t) { return std::make_tuple(std::get<I>(t)...); } template <template <class> class F, typename T> decltype(auto) tuple_filter(T&& t) { using seq = typename tuple_filter_sequence< F, std::decay_t<T>, std::make_index_sequence<std::tuple_size<std::decay_t<T>>::value>, std::index_sequence<>>::ret; return tuple_filter_impl(seq{}, t); } } // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_CALLABLE_TRAITS_TUPLE_UTILS_HH namespace li { struct sqlite_tag; struct mysql_tag; struct pgsql_tag; using s::auto_increment; using s::primary_key; using s::read_only; template <typename SCHEMA, typename C> struct sql_orm { typedef decltype(std::declval<SCHEMA>().all_fields()) O; typedef O object_type; ~sql_orm() { //assert(0); } sql_orm(sql_orm&&) = default; sql_orm(const sql_orm&) = delete; sql_orm& operator=(const sql_orm&) = delete; sql_orm(SCHEMA& schema, C&& con) : schema_(schema), con_(std::forward<C>(con)) {} template <typename S, typename... A> void call_callback(S s, A&&... args) { get_or(schema_.get_callbacks(), s, [] (A... args) {})(args...); // if constexpr (has_key<decltype(schema_.get_callbacks())>(S{})) // return schema_.get_callbacks().template operator[]<S>(s)(args...); } inline auto& drop_table_if_exists() { con_(std::string("DROP TABLE IF EXISTS ") + schema_.table_name()).flush_results(); return *this; } inline auto& create_table_if_not_exists() { std::ostringstream ss; ss << "CREATE TABLE if not exists " << schema_.table_name() << " ("; bool first = true; li::tuple_map(schema_.all_info(), [&](auto f) { auto f2 = schema_.get_field(f); typedef decltype(f) F; typedef decltype(f2) F2; typedef typename F2::left_t K; typedef typename F2::right_t V; bool auto_increment = SCHEMA::template is_auto_increment<F>::value; bool primary_key = SCHEMA::template is_primary_key<F>::value; K k{}; V v{}; if (!first) ss << ", "; ss << li::symbol_string(k) << " "; if (!std::is_same<typename C::db_tag, pgsql_tag>::value or !auto_increment) ss << con_.type_to_string(v); if (std::is_same<typename C::db_tag, sqlite_tag>::value) { if (auto_increment || primary_key) ss << " PRIMARY KEY "; } if (std::is_same<typename C::db_tag, mysql_tag>::value) { if (auto_increment) ss << " AUTO_INCREMENT NOT NULL"; if (primary_key) ss << " PRIMARY KEY "; } if (std::is_same<typename C::db_tag, pgsql_tag>::value) { if (auto_increment) ss << " SERIAL PRIMARY KEY "; } first = false; }); ss << ");"; try { con_(ss.str()).flush_results(); } catch (std::runtime_error e) { std::cerr << "Warning: Lithium::sql could not create the " << schema_.table_name() << " sql table." << std::endl << "You can ignore this message if the table already exists." << "The sql error is: " << e.what() << std::endl; } return *this; } std::string placeholder_string() { if (std::is_same<typename C::db_tag, pgsql_tag>::value) { placeholder_pos_++; std::stringstream ss; ss << '$' << placeholder_pos_; return ss.str(); } else return "?"; } template <typename W> void where_clause(W&& cond, std::ostringstream& ss) { ss << " WHERE "; bool first = true; map(cond, [&](auto k, auto v) { if (!first) ss << " and "; first = false; ss << li::symbol_string(k) << " = " << placeholder_string(); }); ss << " "; } template <typename... W, typename... A> auto find_one(metamap<W...> where, A&&... cb_args) { auto stmt = con_.cached_statement([&] { std::ostringstream ss; placeholder_pos_ = 0; ss << "SELECT "; bool first = true; O o; li::map(o, [&](auto k, auto v) { if (!first) ss << ","; first = false; ss << li::symbol_string(k); }); ss << " FROM " << schema_.table_name(); where_clause(where, ss); ss << "LIMIT 1"; return ss.str(); }); O result; bool read_success = li::tuple_reduce(metamap_values(where), stmt).read(metamap_values(result)); if (read_success) { call_callback(s::read_access, result, cb_args...); return std::make_optional<O>(std::move(result)); } else { return std::optional<O>{}; } } template <typename A, typename B, typename... O, typename... W> auto find_one(metamap<O...>&& o, assign_exp<A, B>&& w1, W... ws) { return find_one(cat(o, mmm(w1)), std::forward<W>(ws)...); } template <typename A, typename B, typename... W> auto find_one(assign_exp<A, B>&& w1, W&&... ws) { return find_one(mmm(w1), std::forward<W>(ws)...); } template <typename W> bool exists(W&& cond) { O o; auto stmt = con_.cached_statement([&] { std::ostringstream ss; placeholder_pos_ = 0; ss << "SELECT count(*) FROM " << schema_.table_name(); where_clause(cond, ss); ss << "LIMIT 1"; return ss.str(); }); return li::tuple_reduce(metamap_values(cond), stmt).template read<int>(); } template <typename A, typename B, typename... W> auto exists(assign_exp<A, B> w1, W... ws) { return exists(mmm(w1, ws...)); } // Save a ll fields except auto increment. // The db will automatically fill auto increment keys. template <typename N, typename... A> auto insert(N&& o, A&&... cb_args) { auto values = schema_.without_auto_increment(); map(o, [&](auto k, auto& v) { values[k] = o[k]; }); call_callback(s::validate, values, cb_args...); call_callback(s::before_insert, values, cb_args...); auto stmt = con_.cached_statement([&] { std::ostringstream ss; std::ostringstream vs; placeholder_pos_ = 0; ss << "INSERT into " << schema_.table_name() << "("; bool first = true; li::map(values, [&](auto k, auto v) { if (!first) { ss << ","; vs << ","; } first = false; ss << li::symbol_string(k); vs << placeholder_string(); }); ss << ") VALUES (" << vs.str() << ")"; if (std::is_same<typename C::db_tag, pgsql_tag>::value && has_key(schema_.all_fields(), s::id)) ss << " returning id;"; return ss.str(); }); auto request_res = li::reduce(values, stmt); call_callback(s::after_insert, o, cb_args...); if constexpr(has_key<decltype(schema_.all_fields())>(s::id)) return request_res.last_insert_id(); else return request_res.flush_results(); }; template <typename A, typename B, typename... O, typename... W> auto insert(metamap<O...>&& o, assign_exp<A, B> w1, W... ws) { return insert(cat(o, mmm(w1)), ws...); } template <typename A, typename B, typename... W> auto insert(assign_exp<A, B> w1, W... ws) { return insert(mmm(w1), ws...); } // template <typename S, typename V, typename... A> // long long int insert(const assign_exp<S, V>& a, A&&... tail) { // auto m = mmm(a, tail...); // return insert(m); // } // Iterate on all the rows of the table. template <typename F> void forall(F f) { typedef decltype(schema_.all_fields()) O; auto stmt = con_.cached_statement([&] { std::ostringstream ss; placeholder_pos_ = 0; ss << "SELECT "; bool first = true; O o; li::map(o, [&](auto k, auto v) { if (!first) ss << ","; first = false; ss << li::symbol_string(k); }); ss << " FROM " << schema_.table_name(); return ss.str(); }); // stmt().map([&](const O& o) { f(o); }); using values_tuple = tuple_remove_references_and_const_t<decltype(metamap_values(std::declval<O>()))>; using keys_tuple = decltype(metamap_keys(std::declval<O>())); stmt().map([&](const values_tuple& values) { f(forward_tuple_as_metamap(keys_tuple{}, values)); }); } // Update N's members except auto increment members. // N must have at least one primary key named id. // Only postgres is supported for now. template <typename N, typename... CB> void bulk_update(const N& elements, CB&&... args) { if constexpr(!std::is_same<typename C::db_tag, pgsql_tag>::value) for (const auto& o : elements) this->update(o); else { auto stmt = con_.cached_statement([&] { std::ostringstream ss; ss << "UPDATE " << schema_.table_name() << " SET "; int nfields = metamap_size<decltype(elements[0])>(); bool first = true; map(elements[0], [&](auto k, auto v) { if (!first) ss << ","; if (not li::has_key(schema_.primary_key(), k)) { ss << li::symbol_string(k) << " = tmp." << li::symbol_string(k); first = false; } }); ss << " FROM (VALUES "; for (int i = 0; i < elements.size(); i++) { if (i != 0) ss << ','; ss << "("; for (int j = 0; j < nfields; j++) { if (j != 0) ss << ","; ss << "$" << 1+i*nfields+j << "::int"; } ss << ")"; } ss << ") AS tmp("; first = true; map(elements[0], [&](auto k, auto v) { if (!first) ss << ","; first = false; ss << li::symbol_string(k); }); ss << ") WHERE tmp.id = " << schema_.table_name() << ".id"; // std::cout << ss.str() << std::endl; return ss.str(); }, elements.size()); for (const auto& o : elements) { call_callback(s::validate, o, args...); call_callback(s::write_access, o, args...); call_callback(s::before_update, o, args...); } stmt(elements).flush_results(); } } // Update N's members except auto increment members. // N must have at least one primary key. template <typename N, typename... CB> void update(const N& o, CB&&... args) { // check if N has at least one member of PKS. call_callback(s::validate, o, args...); call_callback(s::write_access, o, args...); call_callback(s::before_update, o, args...); // static_assert(metamap_size<decltype(intersect(o, schema_.read_only()))>(), //"You cannot give read only fields to the orm update method."); auto to_update = substract(o, schema_.read_only()); auto pk = intersection(o, schema_.primary_key()); auto stmt = con_.cached_statement([&] { static_assert(metamap_size<decltype(pk)>() > 0, "You must provide at least one primary key to update an object."); std::ostringstream ss; placeholder_pos_ = 0; ss << "UPDATE " << schema_.table_name() << " SET "; bool first = true; map(to_update, [&](auto k, auto v) { if (!first) ss << ","; first = false; ss << li::symbol_string(k) << " = " << placeholder_string(); }); where_clause(pk, ss); return ss.str(); }); li::tuple_reduce(std::tuple_cat(metamap_values(to_update), metamap_values(pk)), stmt); call_callback(s::after_update, o, args...); } template <typename A, typename B, typename... O, typename... W> void update(metamap<O...>&& o, assign_exp<A, B> w1, W... ws) { return update(cat(o, mmm(w1)), ws...); } template <typename A, typename B, typename... W> void update(assign_exp<A, B> w1, W... ws) { return update(mmm(w1), ws...); } inline int count() { return con_.prepare(std::string("SELECT count(*) from ") + schema_.table_name())().template read<int>(); } template <typename N, typename... CB> void remove(const N& o, CB&&... args) { call_callback(s::before_remove, o, args...); auto stmt = con_.cached_statement([&] { std::ostringstream ss; placeholder_pos_ = 0; ss << "DELETE from " << schema_.table_name() << " WHERE "; bool first = true; map(schema_.primary_key(), [&](auto k, auto v) { if (!first) ss << " and "; first = false; ss << li::symbol_string(k) << " = " << placeholder_string(); }); return ss.str(); }); auto pks = intersection(o, schema_.primary_key()); li::reduce(pks, stmt); call_callback(s::after_remove, o, args...); } template <typename A, typename B, typename... O, typename... W> void remove(metamap<O...>&& o, assign_exp<A, B> w1, W... ws) { return remove(cat(o, mmm(w1)), ws...); } template <typename A, typename B, typename... W> void remove(assign_exp<A, B> w1, W... ws) { return remove(mmm(w1), ws...); } auto& schema() { return schema_; } C& backend_connection() { return con_; } SCHEMA schema_; C con_; int placeholder_pos_ = 0; }; template <typename... F> struct orm_fields { orm_fields(F... fields) : fields_(fields...) { static_assert(sizeof...(F) == 0 || metamap_size<decltype(this->primary_key())>() != 0, "You must give at least one primary key to the ORM. Use " "s::your_field_name(s::primary_key) to add a primary_key"); } // Field extractor. template <typename M> auto get_field(M m) { return m; } template <typename M, typename T> auto get_field(assign_exp<M, T> e) { return e; } template <typename M, typename T, typename... A> auto get_field(assign_exp<function_call_exp<M, A...>, T> e) { return assign_exp<M, T>{M{}, e.right}; } // template <typename M> struct get_field { typedef M ret; }; // template <typename M, typename T> struct get_field<assign_exp<M, T>> { // typedef assign_exp<M, T> ret; // static auto ctor() { return assign_exp<M, T>{M{}, T()}; } // }; // template <typename M, typename T, typename... A> // struct get_field<assign_exp<function_call_exp<M, A...>, T>> : public get_field<assign_exp<M, // T>> { // }; // get_field<E>::ctor(); // field attributes checks. #define CHECK_FIELD_ATTR(ATTR) \ template <typename M> struct is_##ATTR : std::false_type {}; \ template <typename M, typename T, typename... A> \ struct is_##ATTR<assign_exp<function_call_exp<M, A...>, T>> \ : std::disjunction<std::is_same<std::decay_t<A>, s::ATTR##_t>...> {}; \ \ auto ATTR() { \ return tuple_map_reduce(fields_, \ [this](auto e) { \ typedef std::remove_reference_t<decltype(e)> E; \ if constexpr (is_##ATTR<E>::value) \ return get_field(e); \ else \ return skip{}; \ }, \ make_metamap_skip); \ } CHECK_FIELD_ATTR(primary_key); CHECK_FIELD_ATTR(read_only); CHECK_FIELD_ATTR(auto_increment); CHECK_FIELD_ATTR(computed); #undef CHECK_FIELD_ATTR // Do not remove this comment, this is used by the symbol generation. // s::primary_key s::read_only s::auto_increment s::computed auto all_info() { return fields_; } auto all_fields() { return tuple_map_reduce(fields_, [this](auto e) { // typedef std::remove_reference_t<decltype(e)> E; return get_field(e); }, [](auto... e) { return mmm(e...); }); } auto without_auto_increment() { return substract(all_fields(), auto_increment()); } auto all_fields_except_computed() { return substract(substract(all_fields(), computed()), auto_increment()); } std::tuple<F...> fields_; }; template <typename DB, typename MD = orm_fields<>, typename CB = decltype(mmm())> struct sql_orm_schema : public MD { sql_orm_schema(DB& db, const std::string& table_name, CB cb = CB(), MD md = MD()) : MD(md), database_(db), table_name_(table_name), callbacks_(cb) {} inline auto connect() { return sql_orm{*this, database_.connect()}; } template <typename Y> inline auto connect(Y& y) { return sql_orm{*this, database_.connect(y)}; } const std::string& table_name() const { return table_name_; } auto get_callbacks() const { return callbacks_; } template <typename... P> auto callbacks(P... params_list) const { auto cbs = mmm(params_list...); auto allowed_callbacks = mmm(s::before_insert, s::before_remove, s::before_update, s::after_insert, s::after_remove, s::after_update, s::validate); static_assert( metamap_size<decltype(substract(cbs, allowed_callbacks))>() == 0, "The only supported callbacks are: s::before_insert, s::before_remove, s::before_update," " s::after_insert, s::after_remove, s::after_update, s::validate"); return sql_orm_schema<DB, MD, decltype(cbs)>(database_, table_name_, cbs, *static_cast<const MD*>(this)); } template <typename... P> auto fields(P... p) const { return sql_orm_schema<DB, orm_fields<P...>, CB>(database_, table_name_, callbacks_, orm_fields<P...>(p...)); } DB& database_; std::string table_name_; CB callbacks_; }; }; // namespace li #endif // LITHIUM_SINGLE_HEADER_GUARD_LI_SQL_SQL_ORM_HH
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r13 push %rax push %rbx push %rcx push %rdi push %rsi lea addresses_normal_ht+0x5af4, %rsi lea addresses_WT_ht+0xd75a, %rdi nop nop nop add %rax, %rax mov $79, %rcx rep movsq nop nop nop nop xor $58060, %r12 lea addresses_D_ht+0xb2a8, %rdi clflush (%rdi) nop nop nop nop nop inc %rcx movups (%rdi), %xmm0 vpextrq $0, %xmm0, %r12 nop nop nop cmp %r12, %r12 lea addresses_UC_ht+0xef5a, %r13 nop nop nop add %rbx, %rbx movb $0x61, (%r13) nop sub %rbx, %rbx lea addresses_A_ht+0x371a, %rbx nop sub %rax, %rax mov $0x6162636465666768, %r13 movq %r13, (%rbx) nop nop nop nop dec %rdi lea addresses_WT_ht+0x935a, %rdi nop nop nop add %rsi, %rsi mov $0x6162636465666768, %rax movq %rax, %xmm4 vmovups %ymm4, (%rdi) nop dec %rsi pop %rsi pop %rdi pop %rcx pop %rbx pop %rax pop %r13 pop %r12 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r9 push %rax push %rcx push %rdi push %rsi // REPMOV lea addresses_RW+0x2712, %rsi lea addresses_UC+0x52da, %rdi nop nop nop nop inc %r12 mov $82, %rcx rep movsb nop cmp $4677, %r12 // Store lea addresses_normal+0xc99a, %r9 nop nop nop cmp $3581, %rax mov $0x5152535455565758, %rsi movq %rsi, %xmm4 vmovntdq %ymm4, (%r9) nop nop nop xor $2615, %rax // Store lea addresses_UC+0x71aa, %rax nop nop nop sub $7857, %r11 movw $0x5152, (%rax) nop nop nop nop nop cmp %r12, %r12 // Faulty Load lea addresses_RW+0xff5a, %rsi nop nop nop nop and %r12, %r12 movb (%rsi), %cl lea oracles, %rdi and $0xff, %rcx shlq $12, %rcx mov (%rdi,%rcx,1), %rcx pop %rsi pop %rdi pop %rcx pop %rax pop %r9 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0, 'same': True, 'type': 'addresses_RW'}, 'OP': 'LOAD'} {'src': {'congruent': 2, 'same': False, 'type': 'addresses_RW'}, 'dst': {'congruent': 6, 'same': False, 'type': 'addresses_UC'}, 'OP': 'REPM'} {'dst': {'NT': True, 'AVXalign': False, 'size': 32, 'congruent': 5, 'same': False, 'type': 'addresses_normal'}, 'OP': 'STOR'} {'dst': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 1, 'same': False, 'type': 'addresses_UC'}, 'OP': 'STOR'} [Faulty Load] {'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 0, 'same': True, 'type': 'addresses_RW'}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'congruent': 1, 'same': False, 'type': 'addresses_normal_ht'}, 'dst': {'congruent': 10, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'REPM'} {'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 1, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'} {'dst': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 11, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'STOR'} {'dst': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 6, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'STOR'} {'dst': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 9, 'same': True, 'type': 'addresses_WT_ht'}, 'OP': 'STOR'} {'32': 21829} 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 */
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r12 push %r9 push %rbp push %rbx push %rcx push %rdi push %rsi lea addresses_WT_ht+0x1a794, %r9 nop xor %rbx, %rbx movl $0x61626364, (%r9) nop nop nop nop xor %rbp, %rbp lea addresses_D_ht+0x2f2e, %rdi nop nop nop nop add %r12, %r12 movb $0x61, (%rdi) nop and $7376, %rbx lea addresses_A_ht+0x51c2, %r11 nop nop nop nop xor $16528, %rsi vmovups (%r11), %ymm3 vextracti128 $0, %ymm3, %xmm3 vpextrq $1, %xmm3, %rbx nop nop nop nop add %rbp, %rbp lea addresses_normal_ht+0x11a73, %rsi lea addresses_D_ht+0x5cc6, %rdi nop nop nop xor $44441, %r11 mov $60, %rcx rep movsq nop nop nop dec %rbx lea addresses_D_ht+0x1c346, %rsi lea addresses_normal_ht+0x1715a, %rdi inc %r9 mov $66, %rcx rep movsq nop add %rdi, %rdi lea addresses_A_ht+0x112c6, %rbp nop sub %rsi, %rsi mov $0x6162636465666768, %rbx movq %rbx, %xmm1 movups %xmm1, (%rbp) nop nop and $5980, %r11 pop %rsi pop %rdi pop %rcx pop %rbx pop %rbp pop %r9 pop %r12 pop %r11 ret .global s_faulty_load s_faulty_load: push %r10 push %r15 push %r9 push %rbp push %rbx push %rcx push %rsi // Store lea addresses_normal+0x17b6e, %rsi nop nop cmp %rbp, %rbp movb $0x51, (%rsi) nop nop nop nop xor $40573, %rbx // Store lea addresses_A+0x41c6, %r15 add $27204, %rcx mov $0x5152535455565758, %r10 movq %r10, %xmm1 movaps %xmm1, (%r15) sub %r9, %r9 // Load lea addresses_PSE+0xd47c, %rsi nop nop nop nop nop inc %r15 vmovups (%rsi), %ymm0 vextracti128 $0, %ymm0, %xmm0 vpextrq $1, %xmm0, %rbx nop sub %r15, %r15 // Store lea addresses_D+0x1de, %rbx nop nop nop nop dec %r10 mov $0x5152535455565758, %r9 movq %r9, %xmm7 movups %xmm7, (%rbx) nop nop nop cmp $37162, %rcx // Faulty Load lea addresses_D+0x1b2c6, %rbx nop nop and $52021, %rbp movb (%rbx), %r10b lea oracles, %r9 and $0xff, %r10 shlq $12, %r10 mov (%r9,%r10,1), %r10 pop %rsi pop %rcx pop %rbx pop %rbp pop %r9 pop %r15 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'size': 16, 'NT': False, 'type': 'addresses_D', 'same': False, 'AVXalign': False, 'congruent': 0}} {'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_normal', 'same': False, 'AVXalign': True, 'congruent': 3}} {'OP': 'STOR', 'dst': {'size': 16, 'NT': False, 'type': 'addresses_A', 'same': False, 'AVXalign': True, 'congruent': 5}} {'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_PSE', 'same': False, 'AVXalign': False, 'congruent': 1}} {'OP': 'STOR', 'dst': {'size': 16, 'NT': False, 'type': 'addresses_D', 'same': False, 'AVXalign': False, 'congruent': 0}} [Faulty Load] {'OP': 'LOAD', 'src': {'size': 1, 'NT': False, 'type': 'addresses_D', 'same': True, 'AVXalign': False, 'congruent': 0}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'size': 4, 'NT': False, 'type': 'addresses_WT_ht', 'same': False, 'AVXalign': False, 'congruent': 1}} {'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 2}} {'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_A_ht', 'same': False, 'AVXalign': False, 'congruent': 0}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_normal_ht', 'congruent': 0}, 'dst': {'same': False, 'type': 'addresses_D_ht', 'congruent': 7}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_D_ht', 'congruent': 4}, 'dst': {'same': False, 'type': 'addresses_normal_ht', 'congruent': 2}} {'OP': 'STOR', 'dst': {'size': 16, 'NT': False, 'type': 'addresses_A_ht', 'same': False, 'AVXalign': False, 'congruent': 11}} {'36': 21829} 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 */
; $Id: bit_open_di.asm,v 1.2 2008/12/11 16:42:22 stefano Exp $ ; ; Galaksija 1 bit sound functions ; ; Open sound and disable interrupts for exact timing ; ; Stefano Bodrato - 8/4/2008 ; XLIB bit_open_di XREF snd_tick .bit_open_di ld a,@10111000 ld (snd_tick),a di ld (8248),a ret
; ; Embedded C Library ; ; fgetc_cons ; ; Daniel Wallner - Mar. 2002 ; INCLUDE "ns16450.def" PUBLIC fgetc_cons .fgetc_cons ld bc,UART_BASE + LSR loop: in a,(c) and a,$1 jr z,loop ld bc,UART_BASE in a,(c) ld l,a ret
; ; Old School Computer Architecture - interfacing FLOS ; Stefano Bodrato, 2012 ; ; unsigned long file_sector_list (struct flos_file file); ; ; Get the current sector and update the sector/cluster counters ; ; $Id: file_sector_list.asm,v 1.4 2016-06-22 22:13:09 dom Exp $ ;---------------------------------------------------------------- ; ** doc related to kjt_file_sector_list ** ; ; Input registers: A = Sector offset (within current cluster) ; DE = Cluster number ; ; Output registers: A = Next sector offset ; DE = Updated cluster ; HL = Memory address of LSB of 4 byte sector location ; ; How to use: ; ; To obtain the list of sectors that a file uses, first call "kjt_find_file" with ; the filename in HL as normal. On return, DE will be equal the first cluster that ; the file occupies. Clear A (as we're starting at the first sector of this cluster), ; and call "kjt_file_sector_list". On return A and DE are updated to the values required ; for the next time the routine is called (so store them) and HL points to the lowest ; significant byte of the sector address (Sector_LBA0). Copy the 4 bytes from HL to HL+3 ; to your sector list buffer and loop around, calling "kjt_file_sector_list" (supplying ; it with the updated values for A and DE) for as many sectors as are used by the file ; (simply subtract 512 from a variable holding the file size every call until variable is = < 0) ; ; Notes: Obtaining the sector list is fast (it doesn't need to load the actual file data) ; and using an obtained sector list to load the file in question is much faster than ; the normal filesystem load routine. ; ; INCLUDE "flos.def" SECTION code_clib PUBLIC file_sector_list PUBLIC _file_sector_list file_sector_list: _file_sector_list: ; __FASTCALL__, HL=ptr to struct ld de,17 add hl,de push hl ; struct ptr ld e,(hl) ; get current cluster number inc hl ld d,(hl) inc hl ld a,(hl) ; get current sector call kjt_file_sector_list ex (sp),hl ; struct ptr <-> sector ptr ld (hl),e ; set current cluster number inc hl ld (hl),d inc hl ld (hl),a ; set current sector pop hl ; sector ptr ld e,(hl) ; get current cluster number inc hl ld d,(hl) inc hl ld a,(hl) ; get current cluster number inc hl ld h,(hl) ; get current cluster number ld l,a ex de,hl ret
; A157932: Numbers k such that (3^(35*k) + 5^(21*k) + 7^(15*k)) mod 105 is prime. ; 0,4,6,8,12,16,18,20,24,28,30,32,36,40,42,44,48,52,54,56,60,64,66,68,72,76,78,80,84,88,90,92,96,100,102,104,108,112,114,116,120,124,126,128,132,136,138,140,144,148,150,152,156,160,162,164,168,172,174,176,180,184,186,188,192,196,198,200,204,208,210,212,216,220,222,224,228,232,234,236,240,244,246,248,252,256,258,260,264,268,270,272,276,280,282,284,288,292,294,296,300,304,306,308,312,316,318,320,324,328,330,332,336,340,342,344,348,352,354,356,360,364,366,368,372,376,378,380,384,388,390,392,396,400,402,404,408,412,414,416,420,424,426,428,432,436,438,440,444,448,450,452,456,460,462,464,468,472,474,476,480,484,486,488,492,496,498,500,504,508,510,512,516,520,522,524,528,532,534,536,540,544,546,548,552,556,558,560,564,568,570,572,576,580,582,584,588,592,594,596,600,604,606,608,612,616,618,620,624,628,630,632,636,640,642,644,648,652,654,656,660,664,666,668,672,676,678,680,684,688,690,692,696,700,702,704,708,712,714,716,720,724,726,728,732,736,738,740,744,748 mov $1,$0 add $0,14 mod $0,4 mul $1,6 add $1,$0 div $1,4 mul $1,2
; A271800: Five steps forward, four steps back. ; Submitted by Jamie Morken(s3) ; 0,1,2,3,4,5,4,3,2,1,2,3,4,5,6,5,4,3,2,3,4,5,6,7,6,5,4,3,4,5,6,7,8,7,6,5,4,5,6,7,8,9,8,7,6,5,6,7,8,9,10,9,8,7,6,7,8,9,10,11,10,9,8,7,8,9,10,11,12,11,10,9,8,9,10,11,12,13,12,11,10,9,10,11,12,13,14,13,12,11,10,11,12,13,14,15,14,13,12,11 lpb $0 add $0,1 add $1,1 add $2,10 trn $2,$0 trn $0,10 add $0,$2 lpe add $0,$1
; A275863: Floor(r*a(n-1)) + floor(r*a(n-2)), where r = 5/2, a(0) = 1, a(1) = 1. ; Submitted by Christian Krause ; 1,1,4,12,40,130,425,1387,4529,14789,48294,157707,515002,1681772,5491935,17934267,58565504,191249427,624537327,2039466884,6660010527,21748693527,71021760134,231926134152,757369735715,2473239674667,8076523525954,26374408001552,86127328818765,281254342050792,918454177173892,2999271298061710,9794313688089005,31983962465376787,104445690383664479,341074132122603164,1113799556265669107,3637184220970680677,11877459443090874459,38786609160153887839,126660171508111905744,413616951670664483957 mov $2,1 mov $4,-1 lpb $0 sub $0,1 mul $2,5 div $2,2 mov $3,$4 mov $4,$2 add $2,$3 lpe mov $0,$2
; Assembly for qsort.bas ; compiled with mcbasic ; Equates for MC-10 MICROCOLOR BASIC 1.0 ; ; Direct page equates DP_LNUM .equ $E2 ; current line in BASIC DP_TABW .equ $E4 ; current tab width on console DP_LPOS .equ $E6 ; current line position on console DP_LWID .equ $E7 ; current line width of console ; ; Memory equates M_PMSK .equ $423C ; pixel mask for SET, RESET and POINT M_IKEY .equ $427F ; key code for INKEY$ M_CRSR .equ $4280 ; cursor location M_LBUF .equ $42B2 ; line input buffer (130 chars) M_MSTR .equ $4334 ; buffer for small string moves M_CODE .equ $4346 ; start of program space ; ; ROM equates R_BKMSG .equ $E1C1 ; 'BREAK' string location R_ERROR .equ $E238 ; generate error and restore direct mode R_BREAK .equ $E266 ; generate break and restore direct mode R_RESET .equ $E3EE ; setup stack and disable CONT R_SPACE .equ $E7B9 ; emit " " to console R_QUEST .equ $E7BC ; emit "?" to console R_REDO .equ $E7C1 ; emit "?REDO" to console R_EXTRA .equ $E8AB ; emit "?EXTRA IGNORED" to console R_DMODE .equ $F7AA ; display OK prompt and restore direct mode R_KPOLL .equ $F879 ; if key is down, do KEYIN, else set Z CCR flag R_KEYIN .equ $F883 ; poll key for key-down transition set Z otherwise R_PUTC .equ $F9C9 ; write ACCA to console R_MKTAB .equ $FA7B ; setup tabs for console R_GETLN .equ $FAA4 ; get line, returning with X pointing to M_BUF-1 R_SETPX .equ $FB44 ; write pixel character to X R_CLRPX .equ $FB59 ; clear pixel character in X R_MSKPX .equ $FB7C ; get pixel screen location X and mask in R_PMSK R_CLSN .equ $FBC4 ; clear screen with color code in ACCB R_CLS .equ $FBD4 ; clear screen with space character R_SOUND .equ $FFAB ; play sound with pitch in ACCA and duration in ACCB R_MCXID .equ $FFDA ; ID location for MCX BASIC ; direct page registers .org $80 strbuf .block 2 strend .block 2 strfree .block 2 strstop .block 2 dataptr .block 2 inptptr .block 2 redoptr .block 2 letptr .block 2 .org $a3 r1 .block 5 r2 .block 5 rend rvseed .block 2 curinst .block 2 nxtinst .block 2 tmp1 .block 2 tmp2 .block 2 tmp3 .block 2 tmp4 .block 2 tmp5 .block 2 argv .block 10 .org M_CODE .module mdmain ldx #program stx nxtinst mainloop ldx nxtinst stx curinst ldab ,x ldx #catalog abx abx ldx ,x jsr 0,x bra mainloop program .byte bytecode_progbegin .byte bytecode_clear LINE_10 ; DIM ST(50) .byte bytecode_ld_ir1_pb .byte 50 .byte bytecode_arrdim1_ir1_ix .byte bytecode_INTARR_ST LINE_20 ; SP=0 .byte bytecode_ld_ix_pb .byte bytecode_INTVAR_SP .byte 0 ; L=16384 .byte bytecode_ld_ix_pw .byte bytecode_INTVAR_L .word 16384 ; H=16895 .byte bytecode_ld_ix_pw .byte bytecode_INTVAR_H .word 16895 ; GOSUB 100 .byte bytecode_gosub_ix .word LINE_100 LINE_30 ; END .byte bytecode_progend LINE_100 ; A=PEEK(L) .byte bytecode_peek_ir1_ix .byte bytecode_INTVAR_L .byte bytecode_ld_ix_ir1 .byte bytecode_INTVAR_A LINE_110 ; B=PEEK(H) .byte bytecode_peek_ir1_ix .byte bytecode_INTVAR_H .byte bytecode_ld_ix_ir1 .byte bytecode_INTVAR_B LINE_120 ; IF A>B THEN .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_B .byte bytecode_ldlt_ir1_ir1_ix .byte bytecode_INTVAR_A .byte bytecode_jmpeq_ir1_ix .word LINE_130 ; POKE H,A .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_A .byte bytecode_poke_ix_ir1 .byte bytecode_INTVAR_H ; POKE L,B .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_B .byte bytecode_poke_ix_ir1 .byte bytecode_INTVAR_L LINE_130 ; Z=INT((H-L)/2) .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_H .byte bytecode_sub_ir1_ir1_ix .byte bytecode_INTVAR_L .byte bytecode_div_fr1_ir1_pb .byte 2 .byte bytecode_ld_ix_ir1 .byte bytecode_INTVAR_Z LINE_140 ; IF Z<1 THEN .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_Z .byte bytecode_ldlt_ir1_ir1_pb .byte 1 .byte bytecode_jmpeq_ir1_ix .word LINE_150 ; RETURN .byte bytecode_return LINE_150 ; Z+=L .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_L .byte bytecode_add_ix_ix_ir1 .byte bytecode_INTVAR_Z LINE_160 ; A=PEEK(Z) .byte bytecode_peek_ir1_ix .byte bytecode_INTVAR_Z .byte bytecode_ld_ix_ir1 .byte bytecode_INTVAR_A LINE_170 ; IF A<PEEK(L) THEN .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_A .byte bytecode_peek_ir2_ix .byte bytecode_INTVAR_L .byte bytecode_ldlt_ir1_ir1_ir2 .byte bytecode_jmpeq_ir1_ix .word LINE_180 ; A=PEEK(L) .byte bytecode_peek_ir1_ix .byte bytecode_INTVAR_L .byte bytecode_ld_ix_ir1 .byte bytecode_INTVAR_A LINE_180 ; IF A>PEEK(H) THEN .byte bytecode_peek_ir1_ix .byte bytecode_INTVAR_H .byte bytecode_ldlt_ir1_ir1_ix .byte bytecode_INTVAR_A .byte bytecode_jmpeq_ir1_ix .word LINE_190 ; A=PEEK(H) .byte bytecode_peek_ir1_ix .byte bytecode_INTVAR_H .byte bytecode_ld_ix_ir1 .byte bytecode_INTVAR_A LINE_190 ; LP=L .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_L .byte bytecode_ld_ix_ir1 .byte bytecode_INTVAR_LP ; HP=H .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_H .byte bytecode_ld_ix_ir1 .byte bytecode_INTVAR_HP LINE_200 ; IF A<=PEEK(LP) THEN .byte bytecode_peek_ir1_ix .byte bytecode_INTVAR_LP .byte bytecode_ldge_ir1_ir1_ix .byte bytecode_INTVAR_A .byte bytecode_jmpne_ir1_ix .word LINE_220 LINE_210 ; LP+=1 .byte bytecode_add_ix_ix_pb .byte bytecode_INTVAR_LP .byte 1 ; GOTO 200 .byte bytecode_goto_ix .word LINE_200 LINE_220 ; IF LP=HP THEN .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_LP .byte bytecode_ldeq_ir1_ir1_ix .byte bytecode_INTVAR_HP .byte bytecode_jmpne_ir1_ix .word LINE_270 LINE_230 ; IF A>PEEK(HP) THEN .byte bytecode_peek_ir1_ix .byte bytecode_INTVAR_HP .byte bytecode_ldlt_ir1_ir1_ix .byte bytecode_INTVAR_A .byte bytecode_jmpne_ir1_ix .word LINE_250 LINE_240 ; HP-=1 .byte bytecode_sub_ix_ix_pb .byte bytecode_INTVAR_HP .byte 1 ; GOTO 220 .byte bytecode_goto_ix .word LINE_220 LINE_250 ; IF LP=HP THEN .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_LP .byte bytecode_ldeq_ir1_ir1_ix .byte bytecode_INTVAR_HP .byte bytecode_jmpne_ir1_ix .word LINE_270 LINE_260 ; T=PEEK(LP) .byte bytecode_peek_ir1_ix .byte bytecode_INTVAR_LP .byte bytecode_ld_ix_ir1 .byte bytecode_INTVAR_T ; POKE LP,PEEK(HP) .byte bytecode_peek_ir1_ix .byte bytecode_INTVAR_HP .byte bytecode_poke_ix_ir1 .byte bytecode_INTVAR_LP ; POKE HP,T .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_T .byte bytecode_poke_ix_ir1 .byte bytecode_INTVAR_HP ; GOTO 200 .byte bytecode_goto_ix .word LINE_200 LINE_270 ; IF (A<>PEEK(L)) OR (L=H) THEN .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_A .byte bytecode_peek_ir2_ix .byte bytecode_INTVAR_L .byte bytecode_ldne_ir1_ir1_ir2 .byte bytecode_ld_ir2_ix .byte bytecode_INTVAR_L .byte bytecode_ldeq_ir2_ir2_ix .byte bytecode_INTVAR_H .byte bytecode_or_ir1_ir1_ir2 .byte bytecode_jmpne_ir1_ix .word LINE_290 LINE_280 ; L+=1 .byte bytecode_add_ix_ix_pb .byte bytecode_INTVAR_L .byte 1 ; GOTO 270 .byte bytecode_goto_ix .word LINE_270 LINE_290 ; IF LP<L THEN .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_LP .byte bytecode_ldlt_ir1_ir1_ix .byte bytecode_INTVAR_L .byte bytecode_jmpeq_ir1_ix .word LINE_300 ; LP=L .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_L .byte bytecode_ld_ix_ir1 .byte bytecode_INTVAR_LP LINE_300 ; ST(SP)=LP .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_SP .byte bytecode_arrref1_ir1_ix .byte bytecode_INTARR_ST .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_LP .byte bytecode_ld_ip_ir1 ; ST(SP+1)=H .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_SP .byte bytecode_add_ir1_ir1_pb .byte 1 .byte bytecode_arrref1_ir1_ix .byte bytecode_INTARR_ST .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_H .byte bytecode_ld_ip_ir1 ; SP+=2 .byte bytecode_add_ix_ix_pb .byte bytecode_INTVAR_SP .byte 2 LINE_310 ; H=LP .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_LP .byte bytecode_ld_ix_ir1 .byte bytecode_INTVAR_H ; GOSUB 100 .byte bytecode_gosub_ix .word LINE_100 LINE_320 ; SP-=2 .byte bytecode_sub_ix_ix_pb .byte bytecode_INTVAR_SP .byte 2 ; L=ST(SP) .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_SP .byte bytecode_arrval1_ir1_ix .byte bytecode_INTARR_ST .byte bytecode_ld_ix_ir1 .byte bytecode_INTVAR_L ; H=ST(SP+1) .byte bytecode_ld_ir1_ix .byte bytecode_INTVAR_SP .byte bytecode_add_ir1_ir1_pb .byte 1 .byte bytecode_arrval1_ir1_ix .byte bytecode_INTARR_ST .byte bytecode_ld_ix_ir1 .byte bytecode_INTVAR_H LINE_330 ; GOTO 100 .byte bytecode_goto_ix .word LINE_100 LLAST ; END .byte bytecode_progend ; Library Catalog bytecode_add_ir1_ir1_pb .equ 0 bytecode_add_ix_ix_ir1 .equ 1 bytecode_add_ix_ix_pb .equ 2 bytecode_arrdim1_ir1_ix .equ 3 bytecode_arrref1_ir1_ix .equ 4 bytecode_arrval1_ir1_ix .equ 5 bytecode_clear .equ 6 bytecode_div_fr1_ir1_pb .equ 7 bytecode_gosub_ix .equ 8 bytecode_goto_ix .equ 9 bytecode_jmpeq_ir1_ix .equ 10 bytecode_jmpne_ir1_ix .equ 11 bytecode_ld_ip_ir1 .equ 12 bytecode_ld_ir1_ix .equ 13 bytecode_ld_ir1_pb .equ 14 bytecode_ld_ir2_ix .equ 15 bytecode_ld_ix_ir1 .equ 16 bytecode_ld_ix_pb .equ 17 bytecode_ld_ix_pw .equ 18 bytecode_ldeq_ir1_ir1_ix .equ 19 bytecode_ldeq_ir2_ir2_ix .equ 20 bytecode_ldge_ir1_ir1_ix .equ 21 bytecode_ldlt_ir1_ir1_ir2 .equ 22 bytecode_ldlt_ir1_ir1_ix .equ 23 bytecode_ldlt_ir1_ir1_pb .equ 24 bytecode_ldne_ir1_ir1_ir2 .equ 25 bytecode_or_ir1_ir1_ir2 .equ 26 bytecode_peek_ir1_ix .equ 27 bytecode_peek_ir2_ix .equ 28 bytecode_poke_ix_ir1 .equ 29 bytecode_progbegin .equ 30 bytecode_progend .equ 31 bytecode_return .equ 32 bytecode_sub_ir1_ir1_ix .equ 33 bytecode_sub_ix_ix_pb .equ 34 catalog .word add_ir1_ir1_pb .word add_ix_ix_ir1 .word add_ix_ix_pb .word arrdim1_ir1_ix .word arrref1_ir1_ix .word arrval1_ir1_ix .word clear .word div_fr1_ir1_pb .word gosub_ix .word goto_ix .word jmpeq_ir1_ix .word jmpne_ir1_ix .word ld_ip_ir1 .word ld_ir1_ix .word ld_ir1_pb .word ld_ir2_ix .word ld_ix_ir1 .word ld_ix_pb .word ld_ix_pw .word ldeq_ir1_ir1_ix .word ldeq_ir2_ir2_ix .word ldge_ir1_ir1_ix .word ldlt_ir1_ir1_ir2 .word ldlt_ir1_ir1_ix .word ldlt_ir1_ir1_pb .word ldne_ir1_ir1_ir2 .word or_ir1_ir1_ir2 .word peek_ir1_ix .word peek_ir2_ix .word poke_ix_ir1 .word progbegin .word progend .word return .word sub_ir1_ir1_ix .word sub_ix_ix_pb .module mdalloc ; alloc D bytes in array memory. ; then relink strings. alloc std tmp1 ldx strfree addd strfree std strfree ldd strend addd tmp1 std strend sts tmp2 subd tmp2 blo _ok ldab #OM_ERROR jmp error _ok lds strfree des _again dex dex ldd ,x pshb psha cpx strbuf bhi _again lds tmp2 ldx strbuf ldd strbuf addd tmp1 std strbuf clra _nxtz staa ,x inx cpx strbuf blo _nxtz ldx strbuf ; relink permanent strings ; ENTRY: X points to offending link word in strbuf ; EXIT: X points to strend strlink cpx strend bhs _rts stx tmp1 ldd tmp1 addd #2 ldx ,x std 1,x ldab 0,x ldx 1,x abx bra strlink _rts rts .module mdbcode noargs ldx curinst inx stx nxtinst rts extend ldx curinst inx ldab ,x inx stx nxtinst ldx #symstart abx rts getaddr ldd curinst addd #3 std nxtinst ldx curinst ldx 1,x rts getbyte ldx curinst inx ldab ,x inx stx nxtinst rts getword ldx curinst inx ldd ,x inx inx stx nxtinst rts extbyte ldd curinst addd #3 std nxtinst ldx curinst ldab 2,x pshb ldab 1,x ldx #symstart abx pulb rts extword ldd curinst addd #4 std nxtinst ldx curinst ldd 2,x pshb ldab 1,x ldx #symstart abx pulb rts byteext ldd curinst addd #3 std nxtinst ldx curinst ldab 1,x pshb ldab 2,x ldx #symstart abx pulb rts wordext ldd curinst addd #4 std nxtinst ldx curinst ldd 1,x pshb ldab 3,x ldx #symstart abx pulb rts immstr ldx curinst inx ldab ,x inx pshx abx stx nxtinst pulx rts .module mddivflt ; divide X by Y ; ENTRY X contains dividend in (0,x 1,x 2,x 3,x 4,x) ; scratch in (5,x 6,x 7,x 8,x 9,x) ; Y in 0+argv, 1+argv, 2+argv, 3+argv, 4+argv ; EXIT X/Y in (0,x 1,x 2,x 3,x 4,x) ; uses tmp1,tmp1+1,tmp2,tmp2+1,tmp3,tmp3+1,tmp4 divflt clr tmp4 tst 0,x bpl _posX com tmp4 neg 4,x ngc 3,x ngc 2,x ngc 1,x ngc 0,x _posX tst 0+argv bpl _posA com tmp4 neg 4+argv ngc 3+argv ngc 2+argv ngc 1+argv ngc 0+argv divufl _posA ldd 3,x std 6,x ldd 1,x std 4,x ldab 0,x stab 3,x ldd #0 std 8,x std 1,x stab 0,x ldaa #41 staa tmp1 _nxtdiv ldd 3,x subd 3+argv std tmp3 ldd 1,x sbcb 2+argv sbca 1+argv std tmp2 ldab 0,x sbcb 0+argv stab tmp1+1 blo _shift ldd tmp3 std 3,x ldd tmp2 std 1,x ldab tmp1+1 stab 0,x _shift rol 9,x rol 8,x rol 7,x rol 6,x rol 5,x rol 4,x rol 3,x rol 2,x rol 1,x rol 0,x dec tmp1 bne _nxtdiv tst tmp4 bne _add1 ldd 8,x coma comb std 3,x ldd 6,x coma comb std 1,x ldab 5,x comb stab 0,x rts _add1 ldd 8,x addd #1 std 3,x ldd 6,x adcb #0 adca #0 std 1,x ldab 5,x adcb #0 stab 0,x rts .module mdgeteq geteq beq _1 ldd #0 rts _1 ldd #-1 rts .module mdgetge getge bge _1 ldd #0 rts _1 ldd #-1 rts .module mdgetlt getlt blt _1 ldd #0 rts _1 ldd #-1 rts .module mdgetne getne bne _1 ldd #0 rts _1 ldd #-1 rts .module mdprint print _loop ldaa ,x jsr R_PUTC inx decb bne _loop rts .module mdref1 ; validate offset from 1D descriptor X and argv ; if empty desc, then alloc D bytes in array memory and 11 elements. ; return word offset in D and byte offset in tmp1 ref1 std tmp1 ldd ,x bne _preexist ldd strbuf std ,x ldd #11 std 2,x ldd tmp1 pshx jsr alloc pulx _preexist ldd 0+argv subd 2,x bhi _err ldd 0+argv std tmp1 lsld rts _err ldab #BS_ERROR jmp error .module mdrefint ; return int/str array reference in D/tmp1 refint addd tmp1 addd 0,x std tmp1 rts add_ir1_ir1_pb ; numCalls = 2 .module modadd_ir1_ir1_pb jsr getbyte clra addd r1+1 std r1+1 ldab #0 adcb r1 stab r1 rts add_ix_ix_ir1 ; numCalls = 1 .module modadd_ix_ix_ir1 jsr extend ldd 1,x addd r1+1 std 1,x ldab 0,x adcb r1 stab 0,x rts add_ix_ix_pb ; numCalls = 3 .module modadd_ix_ix_pb jsr extbyte clra addd 1,x std 1,x ldab #0 adcb 0,x stab 0,x rts arrdim1_ir1_ix ; numCalls = 1 .module modarrdim1_ir1_ix jsr extend ldd ,x beq _ok ldab #DD_ERROR jmp error _ok ldd strbuf std ,x ldd r1+1 addd #1 std 2,x lsld addd 2,x jmp alloc arrref1_ir1_ix ; numCalls = 2 .module modarrref1_ir1_ix jsr extend ldd r1+1 std 0+argv ldd #33 jsr ref1 jsr refint std letptr rts arrval1_ir1_ix ; numCalls = 2 .module modarrval1_ir1_ix jsr extend ldd r1+1 std 0+argv ldd #33 jsr ref1 jsr refint ldx tmp1 ldab ,x stab r1 ldd 1,x std r1+1 rts clear ; numCalls = 1 .module modclear jsr noargs clra ldx #bss bra _start _again staa ,x inx _start cpx #bes bne _again stx strbuf stx strend inx inx stx strfree ldx #$8FFF stx strstop ldx #startdata stx dataptr rts div_fr1_ir1_pb ; numCalls = 1 .module moddiv_fr1_ir1_pb jsr getbyte stab 2+argv ldd #0 std 0+argv std 3+argv std r1+3 ldx #r1 jmp divflt gosub_ix ; numCalls = 2 .module modgosub_ix pulx jsr getaddr ldd nxtinst pshb psha ldab #3 pshb stx nxtinst jmp mainloop goto_ix ; numCalls = 5 .module modgoto_ix jsr getaddr stx nxtinst rts jmpeq_ir1_ix ; numCalls = 5 .module modjmpeq_ir1_ix jsr getaddr ldd r1+1 bne _rts ldaa r1 bne _rts stx nxtinst _rts rts jmpne_ir1_ix ; numCalls = 5 .module modjmpne_ir1_ix jsr getaddr ldd r1+1 bne _go ldaa r1 beq _rts _go stx nxtinst _rts rts ld_ip_ir1 ; numCalls = 2 .module modld_ip_ir1 jsr noargs ldx letptr ldd r1+1 std 1,x ldab r1 stab 0,x rts ld_ir1_ix ; numCalls = 22 .module modld_ir1_ix jsr extend ldd 1,x std r1+1 ldab 0,x stab r1 rts ld_ir1_pb ; numCalls = 1 .module modld_ir1_pb jsr getbyte stab r1+2 ldd #0 std r1 rts ld_ir2_ix ; numCalls = 1 .module modld_ir2_ix jsr extend ldd 1,x std r2+1 ldab 0,x stab r2 rts ld_ix_ir1 ; numCalls = 13 .module modld_ix_ir1 jsr extend ldd r1+1 std 1,x ldab r1 stab 0,x rts ld_ix_pb ; numCalls = 1 .module modld_ix_pb jsr extbyte stab 2,x ldd #0 std 0,x rts ld_ix_pw ; numCalls = 2 .module modld_ix_pw jsr extword std 1,x ldab #0 stab 0,x rts ldeq_ir1_ir1_ix ; numCalls = 2 .module modldeq_ir1_ir1_ix jsr extend ldd r1+1 subd 1,x bne _done ldab r1 cmpb 0,x _done jsr geteq std r1+1 stab r1 rts ldeq_ir2_ir2_ix ; numCalls = 1 .module modldeq_ir2_ir2_ix jsr extend ldd r2+1 subd 1,x bne _done ldab r2 cmpb 0,x _done jsr geteq std r2+1 stab r2 rts ldge_ir1_ir1_ix ; numCalls = 1 .module modldge_ir1_ir1_ix jsr extend ldd r1+1 subd 1,x ldab r1 sbcb 0,x jsr getge std r1+1 stab r1 rts ldlt_ir1_ir1_ir2 ; numCalls = 1 .module modldlt_ir1_ir1_ir2 jsr noargs ldd r1+1 subd r2+1 ldab r1 sbcb r2 jsr getlt std r1+1 stab r1 rts ldlt_ir1_ir1_ix ; numCalls = 4 .module modldlt_ir1_ir1_ix jsr extend ldd r1+1 subd 1,x ldab r1 sbcb 0,x jsr getlt std r1+1 stab r1 rts ldlt_ir1_ir1_pb ; numCalls = 1 .module modldlt_ir1_ir1_pb jsr getbyte clra std tmp1 ldd r1+1 subd tmp1 ldab r1 sbcb #0 jsr getlt std r1+1 stab r1 rts ldne_ir1_ir1_ir2 ; numCalls = 1 .module modldne_ir1_ir1_ir2 jsr noargs ldd r1+1 subd r2+1 bne _done ldab r1 cmpb r2 _done jsr getne std r1+1 stab r1 rts or_ir1_ir1_ir2 ; numCalls = 1 .module modor_ir1_ir1_ir2 jsr noargs ldd r2+1 orab r1+2 oraa r1+1 std r1+1 ldab r2 orab r1 stab r1 rts peek_ir1_ix ; numCalls = 10 .module modpeek_ir1_ix jsr extend ldx 1,x cpx #M_IKEY bne _nostore jsr R_KPOLL beq _nostore staa M_IKEY _nostore ldab ,x stab r1+2 ldd #0 std r1 rts peek_ir2_ix ; numCalls = 2 .module modpeek_ir2_ix jsr extend ldx 1,x cpx #M_IKEY bne _nostore jsr R_KPOLL beq _nostore staa M_IKEY _nostore ldab ,x stab r2+2 ldd #0 std r2 rts poke_ix_ir1 ; numCalls = 4 .module modpoke_ix_ir1 jsr extend ldab r1+2 ldx 1,x stab ,x rts progbegin ; numCalls = 1 .module modprogbegin jsr noargs ldx R_MCXID cpx #'h'*256+'C' bne _mcbasic pulx clrb pshb pshb pshb jmp ,x _reqmsg .text "?MICROCOLOR BASIC ROM REQUIRED" _mcbasic ldx #_reqmsg ldab #30 jsr print pulx rts progend ; numCalls = 2 .module modprogend jsr noargs pulx pula pula pula jsr R_RESET jmp R_DMODE NF_ERROR .equ 0 RG_ERROR .equ 4 OD_ERROR .equ 6 FC_ERROR .equ 8 OM_ERROR .equ 12 BS_ERROR .equ 16 DD_ERROR .equ 18 error jmp R_ERROR return ; numCalls = 1 .module modreturn pulx tsx clrb _nxt abx ldab ,x bne _ok ldab #RG_ERROR jmp error _ok cmpb #3 bne _nxt inx txs pulx stx nxtinst jmp mainloop sub_ir1_ir1_ix ; numCalls = 1 .module modsub_ir1_ir1_ix jsr extend ldd r1+1 subd 1,x std r1+1 ldab r1 sbcb 0,x stab r1 rts sub_ix_ix_pb ; numCalls = 2 .module modsub_ix_ix_pb jsr extbyte stab tmp1 ldd 1,x subb tmp1 sbca #0 std 1,x ldab 0,x sbcb #0 stab 0,x rts ; data table startdata enddata ; Bytecode equates bytecode_INTVAR_A .equ INTVAR_A-symstart bytecode_INTVAR_B .equ INTVAR_B-symstart bytecode_INTVAR_H .equ INTVAR_H-symstart bytecode_INTVAR_HP .equ INTVAR_HP-symstart bytecode_INTVAR_L .equ INTVAR_L-symstart bytecode_INTVAR_LP .equ INTVAR_LP-symstart bytecode_INTVAR_SP .equ INTVAR_SP-symstart bytecode_INTVAR_T .equ INTVAR_T-symstart bytecode_INTVAR_Z .equ INTVAR_Z-symstart bytecode_INTARR_ST .equ INTARR_ST-symstart symstart ; block started by symbol bss ; Numeric Variables INTVAR_A .block 3 INTVAR_B .block 3 INTVAR_H .block 3 INTVAR_HP .block 3 INTVAR_L .block 3 INTVAR_LP .block 3 INTVAR_SP .block 3 INTVAR_T .block 3 INTVAR_Z .block 3 ; String Variables ; Numeric Arrays INTARR_ST .block 4 ; dims=1 ; String Arrays ; block ended by symbol bes .end
lda ($fb),y jsr $ffd2
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r12 push %r8 push %rax push %rbp push %rcx push %rdi push %rsi lea addresses_A_ht+0x1d8f1, %rsi lea addresses_WT_ht+0x13801, %rdi nop nop nop nop nop xor %r8, %r8 mov $66, %rcx rep movsq nop nop nop nop nop add %rax, %rax lea addresses_WC_ht+0xc1d1, %rbp nop nop nop nop cmp $40153, %r10 movb (%rbp), %al nop and %rbp, %rbp lea addresses_WT_ht+0xb171, %rsi lea addresses_WC_ht+0x108f9, %rdi clflush (%rdi) nop nop nop nop inc %r12 mov $33, %rcx rep movsl nop nop nop nop nop cmp $21263, %rbp lea addresses_UC_ht+0x1a4bb, %rsi nop nop nop xor %rbp, %rbp movw $0x6162, (%rsi) xor $56334, %r8 lea addresses_UC_ht+0x3971, %rax clflush (%rax) nop nop nop cmp $11516, %rcx mov (%rax), %r12d nop nop nop nop add %rsi, %rsi pop %rsi pop %rdi pop %rcx pop %rbp pop %rax pop %r8 pop %r12 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r13 push %r15 push %rax push %rcx push %rsi // Store lea addresses_PSE+0x1f71, %r15 nop nop nop nop nop add %rax, %rax mov $0x5152535455565758, %r13 movq %r13, %xmm5 vmovups %ymm5, (%r15) nop nop nop dec %r13 // Faulty Load lea addresses_PSE+0x1b971, %r15 nop nop nop and $25528, %rsi mov (%r15), %r13w lea oracles, %rsi and $0xff, %r13 shlq $12, %r13 mov (%rsi,%r13,1), %r13 pop %rsi pop %rcx pop %rax pop %r15 pop %r13 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'AVXalign': False, 'congruent': 0, 'size': 32, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'AVXalign': False, 'congruent': 9, 'size': 32, 'same': False, 'NT': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': True, 'NT': False}} <gen_prepare_buffer> {'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 3, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 4, 'size': 1, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 8, 'same': True}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 2, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 1, 'size': 2, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 7, 'size': 4, 'same': True, 'NT': False}} {'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 */
/* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ #include <gmock/gmock.h> #include <gtest/gtest.h> #include <quic/server/state/ServerStateMachine.h> #include <quic/state/QuicStreamManager.h> #include <quic/state/test/Mocks.h> using namespace folly; using namespace testing; namespace quic { namespace test { class QuicStreamManagerTest : public Test { public: void SetUp() override { conn.flowControlState.peerAdvertisedInitialMaxStreamOffsetBidiLocal = kDefaultStreamWindowSize; conn.flowControlState.peerAdvertisedInitialMaxStreamOffsetBidiRemote = kDefaultStreamWindowSize; conn.flowControlState.peerAdvertisedInitialMaxStreamOffsetUni = kDefaultStreamWindowSize; conn.flowControlState.peerAdvertisedMaxOffset = kDefaultConnectionWindowSize; conn.streamManager->setMaxLocalBidirectionalStreams( kDefaultMaxStreamsBidirectional); conn.streamManager->setMaxLocalUnidirectionalStreams( kDefaultMaxStreamsUnidirectional); auto congestionController = std::make_unique<NiceMock<MockCongestionController>>(); mockController = congestionController.get(); conn.congestionController = std::move(congestionController); } QuicServerConnectionState conn; MockCongestionController* mockController; }; TEST_F(QuicStreamManagerTest, TestAppLimitedCreateBidiStream) { auto& manager = *conn.streamManager; EXPECT_FALSE(manager.isAppLimited()); // The app limiited state did not change. EXPECT_CALL(*mockController, setAppLimited(false, _)).Times(0); auto stream = manager.createNextBidirectionalStream(); StreamId id = stream.value()->id; EXPECT_FALSE(manager.isAppLimited()); EXPECT_CALL(*mockController, setAppLimited(true, _)); // Force transition to closed state stream.value()->send.state = StreamSendStates::Closed(); stream.value()->recv.state = StreamReceiveStates::Closed(); manager.removeClosedStream(stream.value()->id); EXPECT_TRUE(manager.isAppLimited()); EXPECT_EQ(manager.getStream(id), nullptr); } TEST_F(QuicStreamManagerTest, TestAppLimitedCreateUnidiStream) { auto& manager = *conn.streamManager; EXPECT_FALSE(manager.isAppLimited()); EXPECT_CALL(*mockController, setAppLimited(false, _)).Times(0); auto stream = manager.createNextUnidirectionalStream(); EXPECT_FALSE(manager.isAppLimited()); // Force transition to closed state EXPECT_CALL(*mockController, setAppLimited(true, _)); stream.value()->send.state = StreamSendStates::Closed(); stream.value()->recv.state = StreamReceiveStates::Closed(); manager.removeClosedStream(stream.value()->id); EXPECT_TRUE(manager.isAppLimited()); } TEST_F(QuicStreamManagerTest, TestAppLimitedExistingLocalStream) { auto& manager = *conn.streamManager; EXPECT_FALSE(manager.isAppLimited()); EXPECT_CALL(*mockController, setAppLimited(false, _)).Times(0); auto stream = manager.createNextUnidirectionalStream(); EXPECT_FALSE(manager.isAppLimited()); EXPECT_CALL(*mockController, setAppLimited(true, _)); manager.setStreamAsControl(*stream.value()); EXPECT_TRUE(manager.isAppLimited()); manager.getStream(stream.value()->id); EXPECT_TRUE(manager.isAppLimited()); } TEST_F(QuicStreamManagerTest, TestAppLimitedStreamAsControl) { auto& manager = *conn.streamManager; EXPECT_FALSE(manager.isAppLimited()); auto stream = manager.createNextUnidirectionalStream(); EXPECT_FALSE(manager.isAppLimited()); EXPECT_CALL(*mockController, setAppLimited(true, _)); manager.setStreamAsControl(*stream.value()); EXPECT_TRUE(manager.isAppLimited()); EXPECT_CALL(*mockController, setAppLimited(false, _)); manager.createNextUnidirectionalStream(); EXPECT_FALSE(manager.isAppLimited()); } TEST_F(QuicStreamManagerTest, TestAppLimitedCreatePeerStream) { auto& manager = *conn.streamManager; EXPECT_FALSE(manager.isAppLimited()); StreamId id = 0; auto stream = manager.getStream(id); EXPECT_FALSE(manager.isAppLimited()); EXPECT_CALL(*mockController, setAppLimited(true, _)); manager.setStreamAsControl(*stream); EXPECT_TRUE(manager.isAppLimited()); EXPECT_CALL(*mockController, setAppLimited(false, _)); StreamId id2 = 4; manager.getStream(id2); EXPECT_FALSE(manager.isAppLimited()); } TEST_F(QuicStreamManagerTest, TestAppLimitedExistingPeerStream) { auto& manager = *conn.streamManager; EXPECT_FALSE(manager.isAppLimited()); EXPECT_CALL(*mockController, setAppLimited(false, _)).Times(0); StreamId id = 0; auto stream = manager.getStream(id); EXPECT_FALSE(manager.isAppLimited()); EXPECT_CALL(*mockController, setAppLimited(true, _)); manager.setStreamAsControl(*stream); EXPECT_TRUE(manager.isAppLimited()); manager.getStream(id); EXPECT_TRUE(manager.isAppLimited()); } TEST_F(QuicStreamManagerTest, TestAppLimitedClosePeerStream) { auto& manager = *conn.streamManager; EXPECT_FALSE(manager.isAppLimited()); StreamId id = 0; auto stream = manager.getStream(id); EXPECT_FALSE(manager.isAppLimited()); EXPECT_CALL(*mockController, setAppLimited(true, _)); // Force transition to closed state stream->send.state = StreamSendStates::Closed(); stream->recv.state = StreamReceiveStates::Closed(); manager.removeClosedStream(stream->id); EXPECT_TRUE(manager.isAppLimited()); EXPECT_EQ(manager.getStream(id), nullptr); } TEST_F(QuicStreamManagerTest, TestAppLimitedCloseControlStream) { auto& manager = *conn.streamManager; EXPECT_FALSE(manager.isAppLimited()); EXPECT_CALL(*mockController, setAppLimited(false, _)).Times(0); StreamId id = 0; auto stream = manager.getStream(id); EXPECT_FALSE(manager.isAppLimited()); EXPECT_CALL(*mockController, setAppLimited(true, _)); manager.setStreamAsControl(*stream); EXPECT_TRUE(manager.isAppLimited()); // Force transition to closed state stream->send.state = StreamSendStates::Closed(); stream->recv.state = StreamReceiveStates::Closed(); manager.removeClosedStream(stream->id); EXPECT_TRUE(manager.isAppLimited()); } } // namespace test } // namespace quic
// stdafx.cpp : source file that includes just the standard includes // inf.pch will be the pre-compiled header // stdafx.obj will contain the pre-compiled type information #include "stdafx.h" // TODO: reference any additional headers you need in STDAFX.H // and not in this file
/*========================================================================= * * Copyright Insight Software Consortium * * 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.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * *=========================================================================*/ #include "itkConstSliceIterator.h" #include "itkImageRegionIterator.h" #include "itkNeighborhoodIterator.h" #include <iostream> template< typename T, unsigned int N > void FillRegionSequential(itk::SmartPointer< itk::Image<T, N> > I) { unsigned int iDim, ArrayLength, i; itk::Size<N> Index; unsigned long int Location[N]; unsigned int mult; T value; itk::ImageRegionIterator<itk::Image<T, N> > data(I, I->GetRequestedRegion()); Index = (I->GetRequestedRegion()).GetSize(); for (ArrayLength=1, iDim = 0; iDim<N; ++iDim) { Location[iDim] =0; ArrayLength *= Index[iDim]; } for (i=0; i<ArrayLength; ++i, ++data) { for (iDim=0, mult=1, value=0; iDim<N; ++iDim, mult*=10) { value += mult * Location[N-iDim-1]; } data.Set( value ); iDim = N-1; bool done=false; while(!done) { ++Location[iDim]; if(Location[iDim] == Index[(N-1)-iDim]) { Location[iDim] = 0; } else { done = true; } if(iDim == 0) { done = true; } else { --iDim; } } } } template< typename T, unsigned int VDimension > void PrintRegion(itk::SmartPointer< itk::Image<T, VDimension> > I) { unsigned int iDim; long rsz[VDimension]; long Location[VDimension]; std::copy(I->GetRequestedRegion().GetSize().m_Size, I->GetRequestedRegion().GetSize().m_Size+VDimension, rsz); std::fill_n(Location, VDimension, 0); for (iDim = 0; iDim < VDimension; ++iDim) { std::cout << "iDim = " << iDim << std::endl; std::cout << "\tRegionSize = " << I->GetRequestedRegion().GetSize().m_Size[iDim] << std::endl; std::cout << "\tRegionStartIndex = " << I->GetRequestedRegion().GetIndex()[iDim] << std::endl; } itk::ImageRegionIterator<itk::Image<T, VDimension> > iter( I, I->GetRequestedRegion()); for (; ! iter.IsAtEnd(); ++iter) { std::cout << iter.Get() << " "; iDim=VDimension-1; bool done=false; while(!done) { ++Location[iDim]; if(Location[iDim]==rsz[(VDimension-1)-iDim]) { std::cout << std::endl; Location[iDim]=0; } else { done = true; } if(iDim == 0) { done = true; } else { --iDim; } } } } template <typename TContainer> void PrintSlice(TContainer s) { std::cout << "["; for (s=s.Begin(); s < s.End(); s++) { std::cout << *s << " "; } std::cout << "]" << std::endl; } int itkSliceIteratorTest(int, char* [] ) { // tests non-const slice iterator try { itk::ImageRegion<2> reg; itk::Size<2> hoodRadius; itk::Size<2> imgSize; itk::Index<2> zeroIndex; zeroIndex[0]=zeroIndex[1]=0; imgSize[0]=imgSize[1]=20; hoodRadius[0]=hoodRadius[1]=2; reg.SetIndex(zeroIndex); reg.SetSize(imgSize); std::slice hslice(10, 5, 1); // slice through the horizontal center std::slice vslice(2, 5, 5); // slice through the vertical center itk::Neighborhood<int, 2> temp; itk::SliceIterator<int, itk::Neighborhood<int,2> > hnsi(&temp, hslice); itk::SliceIterator<int, itk::Neighborhood<int,2> > vnsi(&temp, vslice); itk::ConstSliceIterator<int, itk::Neighborhood<int,2> > hnsi2(&temp, hslice); itk::ConstSliceIterator<int, itk::Neighborhood<int,2> > vnsi2(&temp, vslice); itk::Neighborhood<int, 2> op; op.SetRadius(hoodRadius); itk::Index<2> idx; idx[0]=idx[1]=0; itk::Image<int, 2>::Pointer ip = itk::Image<int,2>::New(); ip->SetRequestedRegion(reg); ip->SetBufferedRegion(reg); ip->SetLargestPossibleRegion(reg); ip->Allocate(); FillRegionSequential<int, 2>(ip); PrintRegion<int,2>(ip); itk::NeighborhoodIterator<itk::Image<int,2> > it(hoodRadius, ip, reg); for (it.GoToBegin(); !it.IsAtEnd(); ++it) { temp = it.GetNeighborhood(); temp.Print(std::cout); PrintSlice(hnsi); PrintSlice(vnsi); PrintSlice(hnsi2); PrintSlice(vnsi2); } } catch (itk::ExceptionObject &err) { (&err)->Print(std::cerr); return 2; } return EXIT_SUCCESS; }
; A006257: Josephus problem: a(2*n) = 2*a(n)-1, a(2*n+1) = 2*a(n)+1. ; 0,1,1,3,1,3,5,7,1,3,5,7,9,11,13,15,1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,101,103,105,107,109,111,113,115,117,119,121,123,125,127,1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,101,103,105,107,109,111,113,115,117,119,121,123,125,127,129,131,133,135,137,139,141,143,145,147,149,151,153,155,157,159,161,163,165,167,169,171,173,175,177,179,181,183,185,187,189,191,193,195,197,199,201,203,205,207,209,211,213,215,217,219,221,223,225,227,229,231,233,235,237,239,241,243 mov $2,$0 lpb $0 mul $0,2 sub $0,1 mov $1,$0 trn $0,$2 lpe
#include <gtest/gtest.h> #include "base/bus.h" TEST(Test_BusBase_width, case1) { unsigned long _bus_width = 16; base::BusBase bus(_bus_width); EXPECT_EQ(bus.width(), _bus_width); } TEST(Test_BusBase_named, case2) { unsigned long _bus_width = 16; base::BusBase bus(_bus_width); bus.named("TestBus"); EXPECT_EQ(bus.name(), string("TestBus")); } TEST(Test_BusBase_io, case3) { unsigned long _bus_width = 8; base::BusBase bus(_bus_width); unsigned long _case0 = 0b11110000; bus.in(_case0); EXPECT_EQ(bus.out(), _case0); unsigned long _case1 = 0b111111111111111111; bus.in(_case1); EXPECT_NE(bus.out(), _case1); } TEST(Test_BusBase_io, case4) { unsigned long _bus_width = 16; base::BusBase bus(_bus_width); unsigned long _case0 = 0b1111111100000000; bus.in(_case0); EXPECT_EQ(bus.out(), _case0); unsigned long _case1 = 0b111111111111111111; bus.in(_case1); EXPECT_NE(bus.out(), _case1); } TEST(Test_BusBase_io, case5) { unsigned long _bus_width = 32; base::BusBase bus(_bus_width); unsigned long _case0 = 0b11111111111111110000000000000000; bus.in(_case0); EXPECT_EQ(bus.out(), _case0); unsigned long _case1 = 0b11111111111111111111111111111111111111; bus.in(_case1); EXPECT_NE(bus.out(), _case1); } TEST(Test_BusBase_io, case6) { unsigned long _bus_width = 64; base::BusBase bus(_bus_width); unsigned long _case0 = 0b1111111111111111111111110000000011111111111111111111111100000000; bus.in(_case0); EXPECT_EQ(bus.out(), _case0); } GTEST_API_ int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
; void mpn_sqr_basecase(mp_ptr, mp_srcptr, mp_size_t) ; Linux rdi rsi rdx ; Win64 rcx rdx r8 %include 'yasm_mac.inc' %define reg_save_list rbx, rsi, rdi, rbp, r12, r13, r14 text xalign 32 LEAF_PROC mpn_sqr_basecase cmp r8, 2 jae .0 mov rdx, [rdx] mulx rdx, rax, rdx mov [rcx], rax mov [rcx+8], rdx ret .0: jne .1 mov r11, [rdx+8] mov rdx, [rdx] mulx r10, r9, r11 mulx r8, rax, rdx mov rdx, r11 mulx rdx, r11, rdx add r9, r9 adc r10, r10 adc rdx, 0 add r8, r9 adc r10, r11 adc rdx, 0 mov [rcx], rax mov [rcx+8], r8 mov [rcx+16], r10 mov [rcx+24], rdx ret xalign 32 .1: FRAME_PROC mpn_sqr_basec1, 0, reg_save_list mov rdi, rcx mov rsi, rdx mov rdx, r8 cmp rdx, 4 jae .2 mov r8, [rsi] mov rdx, [rsi+8] mov r9, rdx mulx rax, r11, r8 mov rdx, [rsi+16] mulx rcx, r10, r8 mov r8, r11 add r10, rax adc rcx, 0 mulx rax, rdx, r9 add rdx, rcx mov [rdi+24], rdx adc rax, 0 mov [rdi+32], rax xor rcx, rcx mov rdx, [rsi] mulx r11, rax, rdx mov [rdi], rax add r8, r8 adc r10, r10 setc cl mov rdx, [rsi+8] mulx rdx, rax, rdx add r8, r11 adc r10, rax mov [rdi+8], r8 mov [rdi+16], r10 mov r8, [rdi+24] mov r10, [rdi+32] lea r11, [rdx+rcx] adc r8, r8 adc r10, r10 setc cl mov rdx, [rsi+16] mulx rdx, rax, rdx add r8, r11 adc r10, rax mov [rdi+24], r8 mov [rdi+32], r10 adc rdx, rcx mov [rdi+40], rdx EXIT_PROC reg_save_list .2: .3: mov r12, 0 sub r12, rdx mov [rsp+stack_use+8], r12 mov r8, [rsi] mov rdx, [rsi+8] lea rcx, [r12+2] sar rcx, 2 inc r12 mov r9, rdx test r12b, 1 jnz .7 .4: mulx r11, rbx, r8 mov rdx, [rsi+16] mov [rdi+8], rbx xor rbx, rbx mulx rbp, r10, r8 test r12b, 2 jz .6 .5: lea rdi, [rdi-8] lea rsi, [rsi-8] jmp .13 .6: lea rsi, [rsi+8] lea rdi, [rdi+8] jmp .11 .7: mulx rbp, r10, r8 mov rdx, [rsi+16] mov [rdi+8], r10 xor r10, r10 mulx r11, rbx, r8 test r12b, 2 jz .12 .8: lea rdi, [rdi+16] lea rsi, [rsi+16] jmp .10 xalign 32 .9: mulx r10, rax, r9 add rbx, rax mov rdx, [rsi] mulx r11, rax, r8 adc r10, 0 add rbx, rax .10:adc r11, 0 add rbx, rbp mov [rdi], rbx adc r11, 0 mulx rbx, rax, r9 add r10, rax mov rdx, [rsi+8] adc rbx, 0 mulx rbp, rax, r8 add r10, rax adc rbp, 0 .11:add r10, r11 mov [rdi+8], r10 adc rbp, 0 mulx r10, rax, r9 add rbx, rax mov rdx, [rsi+16] mulx r11, rax, r8 adc r10, 0 add rbx, rax adc r11, 0 .12:add rbx, rbp mov [rdi+16], rbx adc r11, 0 mulx rbx, rax, r9 add r10, rax mov rdx, [rsi+24] adc rbx, 0 mulx rbp, rax, r8 add r10, rax adc rbp, 0 .13:add r10, r11 lea rsi, [rsi+32] mov [rdi+24], r10 adc rbp, 0 inc rcx lea rdi, [rdi+32] jnz .9 .14:mulx rax, rdx, r9 add rbx, rdx adc rax, 0 add rbx, rbp mov [rdi], rbx adc rax, 0 mov [rdi+8], rax lea rsi, [rsi+16] lea rdi, [rdi-16] .15: .16: lea rsi, [rsi+r12*8] lea rdi, [rdi+r12*8+48] mov r8, [rsi-8] add r12, 2 cmp r12, -2 jge .30 mov r9, [rsi] lea rcx, [r12+1] sar rcx, 2 mov rdx, r9 test r12b, 1 jnz .20 .17:mov r13, [rdi] mov r14, [rdi+8] mulx r11, rax, r8 add r13, rax adc r11, 0 mov [rdi], r13 xor rbx, rbx test r12b, 2 jnz .19 .18:mov rdx, [rsi+8] lea rdi, [rdi+16] lea rsi, [rsi+16] jmp .26 .19:mov rdx, [rsi+8] mov r13, [rdi+16] lea rsi, [rsi+32] inc rcx mulx rbp, rax, r8 jz .29 jmp .24 .20:mov r14, [rdi] mov r13, [rdi+8] mulx rbp, rax, r8 mov rdx, [rsi+8] add r14, rax adc rbp, 0 xor r10, r10 mov [rdi], r14 mulx r11, rax, r8 test r12b, 2 jz .22 .21:mov r14, [rdi+16] lea rdi, [rdi+24] lea rsi, [rsi+24] jmp .25 .22:lea rdi, [rdi+8] lea rsi, [rsi+8] jmp .27 xalign 32 .23:mulx rbp, rax, r8 add r14, r10 adc rbx, 0 .24:add r14, rax adc rbp, 0 mulx r10, rax, r9 add r13, rax adc r10, 0 lea rdi, [rdi+32] add r14, r11 mov rdx, [rsi-16] mov [rdi-24], r14 adc rbp, 0 add r13, rbx mov r14, [rdi-8] mulx r11, rax, r8 adc r10, 0 .25:add r13, rax mulx rbx, rax, r9 adc r11, 0 add r13, rbp mov [rdi-16], r13 adc r11, 0 add r14, rax adc rbx, 0 add r14, r10 mov rdx, [rsi-8] adc rbx, 0 .26:mulx rbp, rax, r8 add r14, rax adc rbp, 0 mov r13, [rdi] mulx r10, rax, r9 add r13, rax adc r10, 0 add r14, r11 mov [rdi-8], r14 adc rbp, 0 mov rdx, [rsi] add r13, rbx mulx r11, rax, r8 adc r10, 0 .27:add r13, rax adc r11, 0 mulx rbx, rax, r9 add r13, rbp mov r14, [rdi+8] mov [rdi], r13 mov r13, [rdi+16] adc r11, 0 add r14, rax adc rbx, 0 mov rdx, [rsi+8] lea rsi, [rsi+32] inc rcx jnz .23 .28:mulx rbp, rax, r8 add r14, r10 adc rbx, 0 .29:add r14, rax adc rbp, 0 mulx rax, rdx, r9 add r14, r11 mov [rdi+8], r14 adc rbp, 0 add rdx, rbx adc rax, 0 add rbp, rdx mov [rdi+16], rbp adc rax, 0 mov [rdi+24], rax jmp .16 .30:mov r12, [rsp+stack_use+8] mov rdx, [rsi] jg .31 mov r9, rdx mov r13, [rdi] mov r14, rax mulx r11, rax, r8 add r13, rax adc r11, 0 mov [rdi], r13 mov rdx, [rsi+8] mulx rbp, rax, r8 add r14, rax adc rbp, 0 mulx rax, rdx, r9 add r14, r11 mov [rdi+8], r14 adc rbp, 0 add rdx, rbp mov [rdi+16], rdx adc rax, 0 mov [rdi+24], rax lea rdi, [rdi+32] lea rsi, [rsi+16] jmp .32 .31:mulx rbp, r14, r8 add r14, rax adc rbp, 0 mov [rdi], r14 mov [rdi+8], rbp lea rdi, [rdi+16] lea rsi, [rsi+8] .32: .33:lea rsi, [rsi+r12*8+8] lea rdi, [rdi+r12*8] lea rdi, [rdi+r12*8] inc r12 mov rdx, [rsi-8] xor rbx, rbx mulx r10, rax, rdx mov [rdi+8], rax mov r8, [rdi+16] mov r9, [rdi+24] jmp .35 xalign 16 .34:mov r8, [rdi+32] mov r9, [rdi+40] lea rdi, [rdi+16] lea r10, [rdx+rbx] .35:adc r8, r8 adc r9, r9 setc bl mov rdx, [rsi] lea rsi, [rsi+8] mulx rdx, rax, rdx add r8, r10 adc r9, rax mov [rdi+16], r8 mov [rdi+24], r9 inc r12 jnz .34 .36:adc rdx, rbx mov [rdi+32], rdx END_PROC reg_save_list
<% import collections import pwnlib.abi import pwnlib.constants import pwnlib.shellcraft import six %> <%docstring>fstat(fd, buf) -> str Invokes the syscall fstat. See 'man 2 fstat' for more information. Arguments: fd(int): fd buf(stat*): buf Returns: int </%docstring> <%page args="fd=0, buf=0"/> <% abi = pwnlib.abi.ABI.syscall() stack = abi.stack regs = abi.register_arguments[1:] allregs = pwnlib.shellcraft.registers.current() can_pushstr = [] can_pushstr_array = [] argument_names = ['fd', 'buf'] argument_values = [fd, buf] # Load all of the arguments into their destination registers / stack slots. register_arguments = dict() stack_arguments = collections.OrderedDict() string_arguments = dict() dict_arguments = dict() array_arguments = dict() syscall_repr = [] for name, arg in zip(argument_names, argument_values): if arg is not None: syscall_repr.append('%s=%r' % (name, arg)) # If the argument itself (input) is a register... if arg in allregs: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[index] = arg # The argument is not a register. It is a string value, and we # are expecting a string value elif name in can_pushstr and isinstance(arg, (six.binary_type, six.text_type)): if isinstance(arg, six.text_type): arg = arg.encode('utf-8') string_arguments[name] = arg # The argument is not a register. It is a dictionary, and we are # expecting K:V paris. elif name in can_pushstr_array and isinstance(arg, dict): array_arguments[name] = ['%s=%s' % (k,v) for (k,v) in arg.items()] # The arguent is not a register. It is a list, and we are expecting # a list of arguments. elif name in can_pushstr_array and isinstance(arg, (list, tuple)): array_arguments[name] = arg # The argument is not a register, string, dict, or list. # It could be a constant string ('O_RDONLY') for an integer argument, # an actual integer value, or a constant. else: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[target] = arg # Some syscalls have different names on various architectures. # Determine which syscall number to use for the current architecture. for syscall in ['SYS_fstat']: if hasattr(pwnlib.constants, syscall): break else: raise Exception("Could not locate any syscalls: %r" % syscalls) %> /* fstat(${', '.join(syscall_repr)}) */ %for name, arg in string_arguments.items(): ${pwnlib.shellcraft.pushstr(arg, append_null=(b'\x00' not in arg))} ${pwnlib.shellcraft.mov(regs[argument_names.index(name)], abi.stack)} %endfor %for name, arg in array_arguments.items(): ${pwnlib.shellcraft.pushstr_array(regs[argument_names.index(name)], arg)} %endfor %for name, arg in stack_arguments.items(): ${pwnlib.shellcraft.push(arg)} %endfor ${pwnlib.shellcraft.setregs(register_arguments)} ${pwnlib.shellcraft.syscall(syscall)}
; A051000: Sum of cubes of odd divisors of n. ; 1,1,28,1,126,28,344,1,757,126,1332,28,2198,344,3528,1,4914,757,6860,126,9632,1332,12168,28,15751,2198,20440,344,24390,3528,29792,1,37296,4914,43344,757,50654,6860,61544,126,68922,9632,79508,1332,95382,12168,103824,28,117993,15751,137592,2198,148878,20440,167832,344,192080,24390,205380,3528,226982,29792,260408,1,276948,37296,300764,4914,340704,43344,357912,757,389018,50654,441028,6860,458208,61544,493040,126,551881,68922,571788,9632,619164,79508,682920,1332,704970,95382,756112,12168,834176,103824,864360,28,912674,117993,1008324,15751 lpb $0 sub $0,1 mul $0,2 dif $0,4 lpe seq $0,1158 ; sigma_3(n): sum of cubes of divisors of n.
; A165568: a(n) = -1 - 2*n + n^2 + 2*n^3 + n^4. ; -1,1,31,137,391,889,1751,3121,5167,8081,12079,17401,24311,33097,44071,57569,73951,93601,116927,144361,176359,213401,255991,304657,359951,422449,492751,571481,659287,756841,864839,984001,1115071,1258817,1416031,1587529,1774151,1976761,2196247,2433521,2689519,2965201,3261551,3579577,3920311,4284809,4674151,5089441,5531807,6002401,6502399,7033001,7595431,8190937,8820791,9486289,10188751,10929521,11709967,12531481,13395479,14303401,15256711,16256897,17305471,18403969,19553951,20757001,22014727,23328761,24700759,26132401,27625391,29181457,30802351,32489849,34245751,36071881,37970087,39942241,41990239,44116001,46321471,48608617,50979431,53435929,55980151,58614161,61340047,64159921,67075919,70090201,73204951,76422377,79744711,83174209,86713151,90363841,94128607,98009801,102009799,106131001,110375831,114746737,119246191,123876689,128640751,133540921,138579767,143759881,149083879,154554401,160174111,165945697,171871871,177955369,184198951,190605401,197177527,203918161,210830159,217916401,225179791,232623257,240249751,248062249,256063751,264257281,272645887,281232641,290020639,299013001,308212871,317623417,327247831,337089329,347151151,357436561,367948847,378691321,389667319,400880201,412333351,424030177,435974111,448168609,460617151,473323241,486290407,499522201,513022199,526794001,540841231,555167537,569776591,584672089,599857751,615337321,631114567,647193281,663577279,680270401,697276511,714599497,732243271,750211769,768508951,787138801,806105327,825412561,845064559,865065401,885419191,906130057,927202151,948639649,970446751,992627681,1015186687,1038128041,1061456039,1085175001,1109289271,1133803217,1158721231,1184047729,1209787151,1235943961,1262522647,1289527721,1316963719,1344835201,1373146751,1401902977,1431108511,1460768009,1490886151,1521467641,1552517207,1584039601,1616039599,1648522001,1681491631,1714953337,1748911991,1783372489,1818339751,1853818721,1889814367,1926331681,1963375679,2000951401,2039063911,2077718297,2116919671,2156673169,2196983951,2237857201,2279298127,2321311961,2363903959,2407079401,2450843591,2495201857,2540159551,2585722049,2631894751,2678683081,2726092487,2774128441,2822796439,2872102001,2922050671,2972648017,3023899631,3075811129,3128388151,3181636361,3235561447,3290169121,3345465119,3401455201,3458145151,3515540777,3573647911,3632472409,3692020151,3752297041,3813309007,3875062001 mov $2,$0 mov $4,$0 add $0,1 mov $1,1 add $2,1 sub $1,$2 mul $1,$0 pow $1,2 mov $3,$2 add $4,1 add $3,$4 sub $1,$3 div $1,2 mul $1,2 add $1,1
; -------------------------------------- ; Test MOV using serial monitor output. ; -------------------------------------- Start: mvi a,0 ; Set initial register A value. inr a mov b,a ; Move register A content to each other registers. inr a ; Increment register A each time. mov c,a inr a mov d,a inr a mov e,a inr a mov h,a inr a mov l,a out 38 ; + regA: 6 = 006 = 00000110 ; + regB: 1 = 001 = 00000001 regC: 2 = 002 = 00000010 ; + regD: 3 = 003 = 00000011 regE: 4 = 004 = 00000100 ; + regH: 5 = 005 = 00000101 regL: 6 = 006 = 00000110 ; ; -------------------------------------- ; Test MOV with register B. inr a ; Keep incrementing up. mov b,a mov a,b inr b mov c,b inr b mov d,b inr b mov e,b inr b mov h,b inr b mov l,b ; regB is the same regL out 38 ; + regA: 7 = 007 = 00000111 ; + regB: 12 = 014 = 00001100 regC: 8 = 010 = 00001000 ; + regD: 9 = 011 = 00001001 regE: 10 = 012 = 00001010 ; + regH: 11 = 013 = 00001011 regL: 12 = 014 = 00001100 ; ; -------------------------------------- ; Test MOV with register C. inr b mov c,b ; Keep incrementing up. mov a,c inr c mov b,c inr c mov d,c inr c mov e,c inr c mov h,c inr c mov l,c out 38 ; + regA: 13 = 015 = 00001101 ; + regB: 14 = 016 = 00001110 regC: 18 = 022 = 00010010 ; + regD: 15 = 017 = 00001111 regE: 16 = 020 = 00010000 ; + regH: 17 = 021 = 00010001 regL: 18 = 022 = 00010010 ; ; -------------------------------------- ; Test MOV with register D. inr c mov d,c ; Keep incrementing up. mov a,d inr d mov b,d inr d mov c,d inr d mov e,d inr d mov h,d inr d mov l,d out 38 ; + regA: 19 = 023 = 00010011 ; + regB: 20 = 024 = 00010100 regC: 21 = 025 = 00010101 ; + regD: 24 = 030 = 00011000 regE: 22 = 026 = 00010110 ; + regH: 23 = 027 = 00010111 regL: 24 = 030 = 00011000 ; ; -------------------------------------- ; Test MOV with register E. inr d mov e,d ; Keep incrementing up. mov a,e inr e mov b,e inr e mov c,e inr e mov d,e inr e mov h,e inr e mov l,e out 38 ; + regA: 25 = 031 = 00011001 ; + regB: 26 = 032 = 00011010 regC: 27 = 033 = 00011011 ; + regD: 28 = 034 = 00011100 regE: 30 = 036 = 00011110 ; + regH: 29 = 035 = 00011101 regL: 30 = 036 = 00011110 ; ; -------------------------------------- ; Test MOV with register H. inr e mov h,e ; Keep incrementing up. mov a,h inr h mov b,h inr h mov c,h inr h mov d,h inr h mov e,h inr h mov l,h out 38 ; + regA: 31 = 037 = 00011111 ; + regB: 32 = 040 = 00100000 regC: 33 = 041 = 00100001 ; + regD: 34 = 042 = 00100010 regE: 35 = 043 = 00100011 ; + regH: 36 = 044 = 00100100 regL: 36 = 044 = 00100100 ; ; -------------------------------------- ; Test MOV with register L. inr h mov l,h ; Keep incrementing up. mov a,l inr l mov b,l inr l mov c,l inr l mov d,l inr l mov e,l inr l mov h,l out 38 ; + regA: 37 = 045 = 00100101 ; + regB: 38 = 046 = 00100110 regC: 39 = 047 = 00100111 ; + regD: 40 = 050 = 00101000 regE: 41 = 051 = 00101001 ; + regH: 42 = 052 = 00101010 regL: 42 = 052 = 00101010 ; ; -------------------------------------- ; Test MOV with register M, an address(hb:lb). ; inr l mov a,l ; Move # to register A. sta 168 ; Store register A's data value to the address H:L. mvi a,0 ; Reset A. mvi l,168 ; Set address H:L to 128 which is the address to m. mvi h,0 ; mov a,m inr m ; Increment the byte(M) at address H:L. mov b,m inr m ; Increment the byte(M) at address H:L. mov c,m inr m ; Increment the byte(M) at address H:L. mov d,m inr m ; Increment the byte(M) at address H:L. mov e,m inr m ; Increment the byte(M) at address H:L. mov h,m ; This changes the address value ; -------------------------------------- sta 170 ; Store register A. mov a,h sta 171 ; Store register H. mvi h,0 ; Reset regH, which is part of address H:L to 128 which is the address to m. ; inr m ; Increment the byte(M) at address H:L. mov l,m ; This changes the address value ; lda 171 ; Restore register H. mov h,a lda 170 ; Restore register A. ; out 38 ; Print the registers. ; -------------------------------------- mvi a,'\r' out 3 mvi a,'\n' out 3 hlt ; The program will halt at each iteration, after the first. jmp Start ; Jump back to the early halt command. ; -------------------------------------- end ; -------------------------------------- ; Successful run: + runProcessor() ------------ + regA: 6 = 006 = 00000110 + regB: 1 = 001 = 00000001 regC: 2 = 002 = 00000010 + regD: 3 = 003 = 00000011 regE: 4 = 004 = 00000100 + regH: 5 = 005 = 00000101 regL: 6 = 006 = 00000110 ------------------------ + regA: 7 = 007 = 00000111 + regB: 12 = 014 = 00001100 regC: 8 = 010 = 00001000 + regD: 9 = 011 = 00001001 regE: 10 = 012 = 00001010 + regH: 11 = 013 = 00001011 regL: 12 = 014 = 00001100 ------------------------ + regA: 13 = 015 = 00001101 + regB: 14 = 016 = 00001110 regC: 18 = 022 = 00010010 + regD: 15 = 017 = 00001111 regE: 16 = 020 = 00010000 + regH: 17 = 021 = 00010001 regL: 18 = 022 = 00010010 ------------------------ + regA: 19 = 023 = 00010011 + regB: 20 = 024 = 00010100 regC: 21 = 025 = 00010101 + regD: 24 = 030 = 00011000 regE: 22 = 026 = 00010110 + regH: 23 = 027 = 00010111 regL: 24 = 030 = 00011000 ------------------------ + regA: 25 = 031 = 00011001 + regB: 26 = 032 = 00011010 regC: 27 = 033 = 00011011 + regD: 28 = 034 = 00011100 regE: 30 = 036 = 00011110 + regH: 29 = 035 = 00011101 regL: 30 = 036 = 00011110 ------------------------ + regA: 31 = 037 = 00011111 + regB: 32 = 040 = 00100000 regC: 33 = 041 = 00100001 + regD: 34 = 042 = 00100010 regE: 35 = 043 = 00100011 + regH: 36 = 044 = 00100100 regL: 36 = 044 = 00100100 ------------------------ + regA: 37 = 045 = 00100101 + regB: 38 = 046 = 00100110 regC: 39 = 047 = 00100111 + regD: 40 = 050 = 00101000 regE: 41 = 051 = 00101001 + regH: 42 = 052 = 00101010 regL: 42 = 052 = 00101010 ------------ + regA: 43 = 053 = 00101011 + regB: 44 = 054 = 00101100 regC: 45 = 055 = 00101101 + regD: 46 = 056 = 00101110 regE: 47 = 057 = 00101111 + regH: 48 = 060 = 00110000 regL: 49 = 061 = 00110001 ------------ ++ HALT, host_read_status_led_WAIT() = 0 ; ; --------------------------------------
;------------------------------------------------------------------------------ ; ; Copyright (c) 2015 - 2018, 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: ; ; MpFuncs.nasm ; ; Abstract: ; ; This is the assembly code for MP support ; ;------------------------------------------------------------------------------- %include "MpEqu.inc" extern ASM_PFX(InitializeFloatingPointUnits) SECTION .text ;------------------------------------------------------------------------------------- ;RendezvousFunnelProc procedure follows. All APs execute their procedure. This ;procedure serializes all the AP processors through an Init sequence. It must be ;noted that APs arrive here very raw...ie: real mode, no stack. ;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PROC ;IS IN MACHINE CODE. ;------------------------------------------------------------------------------------- global ASM_PFX(RendezvousFunnelProc) ASM_PFX(RendezvousFunnelProc): RendezvousFunnelProcStart: ; At this point CS = 0x(vv00) and ip= 0x0. BITS 16 mov ebp, eax ; save BIST information mov ax, cs mov ds, ax mov es, ax mov ss, ax xor ax, ax mov fs, ax mov gs, ax mov si, BufferStartLocation mov ebx, [si] mov si, DataSegmentLocation mov edx, [si] ; ; Get start address of 32-bit code in low memory (<1MB) ; mov edi, ModeTransitionMemoryLocation mov si, GdtrLocation o32 lgdt [cs:si] mov si, IdtrLocation o32 lidt [cs:si] ; ; Switch to protected mode ; mov eax, cr0 ; Get control register 0 or eax, 000000003h ; Set PE bit (bit #0) & MP mov cr0, eax ; Switch to 32-bit code in executable memory (>1MB) o32 jmp far [cs:di] ; ; Following code may be copied to memory with type of EfiBootServicesCode. ; This is required at DXE phase if NX is enabled for EfiBootServicesCode of ; memory. ; BITS 32 Flat32Start: ; protected mode entry point mov ds, dx mov es, dx mov fs, dx mov gs, dx mov ss, dx mov esi, ebx ; Increment the number of APs executing here as early as possible ; This is decremented in C code when AP is finished executing mov edi, esi add edi, NumApsExecutingLocation lock inc dword [edi] mov edi, esi add edi, EnableExecuteDisableLocation cmp byte [edi], 0 jz SkipEnableExecuteDisable ; ; Enable IA32 PAE execute disable ; mov ecx, 0xc0000080 rdmsr bts eax, 11 wrmsr mov edi, esi add edi, Cr3Location mov eax, dword [edi] mov cr3, eax mov eax, cr4 bts eax, 5 mov cr4, eax mov eax, cr0 bts eax, 31 mov cr0, eax SkipEnableExecuteDisable: mov edi, esi add edi, InitFlagLocation cmp dword [edi], 1 ; 1 == ApInitConfig jnz GetApicId ; AP init mov edi, esi add edi, LockLocation mov eax, NotVacantFlag TestLock: xchg [edi], eax cmp eax, NotVacantFlag jz TestLock mov ecx, esi add ecx, ApIndexLocation inc dword [ecx] mov ebx, [ecx] Releaselock: mov eax, VacantFlag xchg [edi], eax mov edi, esi add edi, StackSizeLocation mov eax, [edi] mov ecx, ebx inc ecx mul ecx ; EAX = StackSize * (CpuNumber + 1) mov edi, esi add edi, StackStartAddressLocation add eax, [edi] mov esp, eax jmp CProcedureInvoke GetApicId: mov eax, 0 cpuid cmp eax, 0bh jb NoX2Apic ; CPUID level below CPUID_EXTENDED_TOPOLOGY mov eax, 0bh xor ecx, ecx cpuid test ebx, 0ffffh jz NoX2Apic ; CPUID.0BH:EBX[15:0] is zero ; Processor is x2APIC capable; 32-bit x2APIC ID is already in EDX jmp GetProcessorNumber NoX2Apic: ; Processor is not x2APIC capable, so get 8-bit APIC ID mov eax, 1 cpuid shr ebx, 24 mov edx, ebx GetProcessorNumber: ; ; Get processor number for this AP ; Note that BSP may become an AP due to SwitchBsp() ; xor ebx, ebx lea eax, [esi + CpuInfoLocation] mov edi, [eax] GetNextProcNumber: cmp [edi], edx ; APIC ID match? jz ProgramStack add edi, 20 inc ebx jmp GetNextProcNumber ProgramStack: mov esp, [edi + 12] CProcedureInvoke: push ebp ; push BIST data at top of AP stack xor ebp, ebp ; clear ebp for call stack trace push ebp mov ebp, esp mov eax, ASM_PFX(InitializeFloatingPointUnits) call eax ; Call assembly function to initialize FPU per UEFI spec push ebx ; Push ApIndex mov eax, esi add eax, LockLocation push eax ; push address of exchange info data buffer mov edi, esi add edi, ApProcedureLocation mov eax, [edi] call eax ; Invoke C function jmp $ ; Never reach here RendezvousFunnelProcEnd: ;------------------------------------------------------------------------------------- ; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfApStack, CountTofinish); ;------------------------------------------------------------------------------------- global ASM_PFX(AsmRelocateApLoop) ASM_PFX(AsmRelocateApLoop): AsmRelocateApLoopStart: mov eax, esp mov esp, [eax + 16] ; TopOfApStack push dword [eax] ; push return address for stack trace push ebp mov ebp, esp mov ebx, [eax + 8] ; ApTargetCState mov ecx, [eax + 4] ; MwaitSupport mov eax, [eax + 20] ; CountTofinish lock dec dword [eax] ; (*CountTofinish)-- cmp cl, 1 ; Check mwait-monitor support jnz HltLoop MwaitLoop: cli mov eax, esp xor ecx, ecx xor edx, edx monitor mov eax, ebx ; Mwait Cx, Target C-State per eax[7:4] shl eax, 4 mwait jmp MwaitLoop HltLoop: cli hlt jmp HltLoop AsmRelocateApLoopEnd: ;------------------------------------------------------------------------------------- ; AsmGetAddressMap (&AddressMap); ;------------------------------------------------------------------------------------- global ASM_PFX(AsmGetAddressMap) ASM_PFX(AsmGetAddressMap): pushad mov ebp,esp mov ebx, [ebp + 24h] mov dword [ebx], RendezvousFunnelProcStart mov dword [ebx + 4h], Flat32Start - RendezvousFunnelProcStart mov dword [ebx + 8h], RendezvousFunnelProcEnd - RendezvousFunnelProcStart mov dword [ebx + 0Ch], AsmRelocateApLoopStart mov dword [ebx + 10h], AsmRelocateApLoopEnd - AsmRelocateApLoopStart mov dword [ebx + 14h], Flat32Start - RendezvousFunnelProcStart popad ret ;------------------------------------------------------------------------------------- ;AsmExchangeRole procedure follows. This procedure executed by current BSP, that is ;about to become an AP. It switches it'stack with the current AP. ;AsmExchangeRole (IN CPU_EXCHANGE_INFO *MyInfo, IN CPU_EXCHANGE_INFO *OthersInfo); ;------------------------------------------------------------------------------------- global ASM_PFX(AsmExchangeRole) ASM_PFX(AsmExchangeRole): ; DO NOT call other functions in this function, since 2 CPU may use 1 stack ; at the same time. If 1 CPU try to call a function, stack will be corrupted. pushad mov ebp,esp ; esi contains MyInfo pointer mov esi, [ebp + 24h] ; edi contains OthersInfo pointer mov edi, [ebp + 28h] ;Store EFLAGS, GDTR and IDTR register to stack pushfd mov eax, cr4 push eax ; push cr4 firstly mov eax, cr0 push eax sgdt [esi + 8] sidt [esi + 14] ; Store the its StackPointer mov [esi + 4],esp ; update its switch state to STORED mov byte [esi], CPU_SWITCH_STATE_STORED WaitForOtherStored: ; wait until the other CPU finish storing its state cmp byte [edi], CPU_SWITCH_STATE_STORED jz OtherStored pause jmp WaitForOtherStored OtherStored: ; Since another CPU already stored its state, load them ; load GDTR value lgdt [edi + 8] ; load IDTR value lidt [edi + 14] ; load its future StackPointer mov esp, [edi + 4] ; update the other CPU's switch state to LOADED mov byte [edi], CPU_SWITCH_STATE_LOADED WaitForOtherLoaded: ; wait until the other CPU finish loading new state, ; otherwise the data in stack may corrupt cmp byte [esi], CPU_SWITCH_STATE_LOADED jz OtherLoaded pause jmp WaitForOtherLoaded OtherLoaded: ; since the other CPU already get the data it want, leave this procedure pop eax mov cr0, eax pop eax mov cr4, eax popfd popad ret
;*! ;* \copy ;* Copyright (c) 2009-2013, Cisco Systems ;* All rights reserved. ;* ;* 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. ;* ;* ;* satd_sad.asm ;* ;* Abstract ;* WelsSampleSatd4x4_sse2 ;* WelsSampleSatd8x8_sse2 ;* WelsSampleSatd16x8_sse2 ;* WelsSampleSatd8x16_sse2 ;* WelsSampleSatd16x16_sse2 ;* ;* WelsSampleSad16x8_sse2 ;* WelsSampleSad16x16_sse2 ;* ;* History ;* 8/5/2009 Created ;* 24/9/2009 modified ;* ;* ;*************************************************************************/ %include "asm_inc.asm" ;*********************************************************************** ; Data ;*********************************************************************** SECTION .rodata align=16 align 16 HSumSubDB1: db 1,1,1,1,1,1,1,1,1,-1,1,-1,1,-1,1,-1 align 16 HSumSubDW1: dw 1,-1,1,-1,1,-1,1,-1 align 16 PDW1: dw 1,1,1,1,1,1,1,1 align 16 PDQ2: dw 2,0,0,0,2,0,0,0 align 16 HSwapSumSubDB1: times 2 db 1, 1, 1, 1, 1, -1, 1, -1 ;*********************************************************************** ; Code ;*********************************************************************** SECTION .text ;*********************************************************************** ; ;Pixel_satd_wxh_sse2 BEGIN ; ;*********************************************************************** %macro MMX_DW_1_2REG 2 pxor %1, %1 pcmpeqw %2, %2 psubw %1, %2 %endmacro %macro SSE2_SumWHorizon1 2 movdqa %2, %1 psrldq %2, 8 paddusw %1, %2 movdqa %2, %1 psrldq %2, 4 paddusw %1, %2 movdqa %2, %1 psrldq %2, 2 paddusw %1, %2 %endmacro %macro SSE2_HDMTwo4x4 5 ;in: xmm1,xmm2,xmm3,xmm4 pOut: xmm4,xmm2,xmm1,xmm3 SSE2_SumSub %1, %2, %5 SSE2_SumSub %3, %4, %5 SSE2_SumSub %2, %4, %5 SSE2_SumSub %1, %3, %5 %endmacro %macro SSE2_SumAbs4 7 WELS_AbsW %1, %3 WELS_AbsW %2, %3 WELS_AbsW %4, %6 WELS_AbsW %5, %6 paddusw %1, %2 paddusw %4, %5 paddusw %7, %1 paddusw %7, %4 %endmacro %macro SSE2_SumWHorizon 3 movhlps %2, %1 ; x2 = xx xx xx xx d7 d6 d5 d4 paddw %1, %2 ; x1 = xx xx xx xx d37 d26 d15 d04 punpcklwd %1, %3 ; x1 = d37 d26 d15 d04 movhlps %2, %1 ; x2 = xxxx xxxx d37 d26 paddd %1, %2 ; x1 = xxxx xxxx d1357 d0246 pshuflw %2, %1, 0x4e ; x2 = xxxx xxxx d0246 d1357 paddd %1, %2 ; x1 = xxxx xxxx xxxx d01234567 %endmacro %macro SSE2_GetSatd8x8 0 SSE2_LoadDiff8P xmm0,xmm4,xmm7,[r0],[r2] SSE2_LoadDiff8P xmm1,xmm5,xmm7,[r0+r1],[r2+r3] lea r0, [r0+2*r1] lea r2, [r2+2*r3] SSE2_LoadDiff8P xmm2,xmm4,xmm7,[r0],[r2] SSE2_LoadDiff8P xmm3,xmm5,xmm7,[r0+r1],[r2+r3] SSE2_HDMTwo4x4 xmm0,xmm1,xmm2,xmm3,xmm4 SSE2_TransTwo4x4W xmm3,xmm1,xmm0,xmm2,xmm4 SSE2_HDMTwo4x4 xmm3,xmm1,xmm2,xmm4,xmm5 SSE2_SumAbs4 xmm4,xmm1,xmm0,xmm2,xmm3,xmm5,xmm6 lea r0, [r0+2*r1] lea r2, [r2+2*r3] SSE2_LoadDiff8P xmm0,xmm4,xmm7,[r0],[r2] SSE2_LoadDiff8P xmm1,xmm5,xmm7,[r0+r1],[r2+r3] lea r0, [r0+2*r1] lea r2, [r2+2*r3] SSE2_LoadDiff8P xmm2,xmm4,xmm7,[r0],[r2] SSE2_LoadDiff8P xmm3,xmm5,xmm7,[r0+r1],[r2+r3] SSE2_HDMTwo4x4 xmm0,xmm1,xmm2,xmm3,xmm4 SSE2_TransTwo4x4W xmm3,xmm1,xmm0,xmm2,xmm4 SSE2_HDMTwo4x4 xmm3,xmm1,xmm2,xmm4,xmm5 SSE2_SumAbs4 xmm4,xmm1,xmm0,xmm2,xmm3,xmm5,xmm6 %endmacro ;*********************************************************************** ; ;int32_t WelsSampleSatd4x4_sse2( uint8_t *, int32_t, uint8_t *, int32_t ); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatd4x4_sse2 %assign push_num 0 LOAD_4_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d movd xmm0, [r0] movd xmm1, [r0+r1] lea r0 , [r0+2*r1] movd xmm2, [r0] movd xmm3, [r0+r1] punpckldq xmm0, xmm2 punpckldq xmm1, xmm3 movd xmm4, [r2] movd xmm5, [r2+r3] lea r2 , [r2+2*r3] movd xmm6, [r2] movd xmm7, [r2+r3] punpckldq xmm4, xmm6 punpckldq xmm5, xmm7 pxor xmm6, xmm6 punpcklbw xmm0, xmm6 punpcklbw xmm1, xmm6 punpcklbw xmm4, xmm6 punpcklbw xmm5, xmm6 psubw xmm0, xmm4 psubw xmm1, xmm5 movdqa xmm2, xmm0 paddw xmm0, xmm1 psubw xmm2, xmm1 SSE2_XSawp qdq, xmm0, xmm2, xmm3 movdqa xmm4, xmm0 paddw xmm0, xmm3 psubw xmm4, xmm3 movdqa xmm2, xmm0 punpcklwd xmm0, xmm4 punpckhwd xmm4, xmm2 SSE2_XSawp dq, xmm0, xmm4, xmm3 SSE2_XSawp qdq, xmm0, xmm3, xmm5 movdqa xmm7, xmm0 paddw xmm0, xmm5 psubw xmm7, xmm5 SSE2_XSawp qdq, xmm0, xmm7, xmm1 movdqa xmm2, xmm0 paddw xmm0, xmm1 psubw xmm2, xmm1 WELS_AbsW xmm0, xmm3 paddusw xmm6, xmm0 WELS_AbsW xmm2, xmm4 paddusw xmm6, xmm2 SSE2_SumWHorizon1 xmm6, xmm4 movd retrd, xmm6 and retrd, 0xffff shr retrd, 1 POP_XMM LOAD_4_PARA_POP ret ;*********************************************************************** ; ;int32_t WelsSampleSatd8x8_sse2( uint8_t *, int32_t, uint8_t *, int32_t, ); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatd8x8_sse2 %assign push_num 0 LOAD_4_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d pxor xmm6, xmm6 pxor xmm7, xmm7 SSE2_GetSatd8x8 psrlw xmm6, 1 SSE2_SumWHorizon xmm6,xmm4,xmm7 movd retrd, xmm6 POP_XMM LOAD_4_PARA_POP ret ;*********************************************************************** ; ;int32_t WelsSampleSatd8x16_sse2( uint8_t *, int32_t, uint8_t *, int32_t, ); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatd8x16_sse2 %assign push_num 0 LOAD_4_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d pxor xmm6, xmm6 pxor xmm7, xmm7 SSE2_GetSatd8x8 lea r0, [r0+2*r1] lea r2, [r2+2*r3] SSE2_GetSatd8x8 psrlw xmm6, 1 SSE2_SumWHorizon xmm6,xmm4,xmm7 movd retrd, xmm6 POP_XMM LOAD_4_PARA_POP ret ;*********************************************************************** ; ;int32_t WelsSampleSatd16x8_sse2( uint8_t *, int32_t, uint8_t *, int32_t, ); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatd16x8_sse2 %assign push_num 0 LOAD_4_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d push r0 push r2 pxor xmm6, xmm6 pxor xmm7, xmm7 SSE2_GetSatd8x8 pop r2 pop r0 add r0, 8 add r2, 8 SSE2_GetSatd8x8 psrlw xmm6, 1 SSE2_SumWHorizon xmm6,xmm4,xmm7 movd retrd, xmm6 POP_XMM LOAD_4_PARA_POP ret ;*********************************************************************** ; ;int32_t WelsSampleSatd16x16_sse2( uint8_t *, int32_t, uint8_t *, int32_t, ); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatd16x16_sse2 %assign push_num 0 LOAD_4_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d push r0 push r2 pxor xmm6, xmm6 pxor xmm7, xmm7 SSE2_GetSatd8x8 lea r0, [r0+2*r1] lea r2, [r2+2*r3] SSE2_GetSatd8x8 pop r2 pop r0 add r0, 8 add r2, 8 SSE2_GetSatd8x8 lea r0, [r0+2*r1] lea r2, [r2+2*r3] SSE2_GetSatd8x8 ; each column sum of SATD is necessarily even, so we don't lose any precision by shifting first. psrlw xmm6, 1 SSE2_SumWHorizon xmm6,xmm4,xmm7 movd retrd, xmm6 POP_XMM LOAD_4_PARA_POP ret ;*********************************************************************** ; ;Pixel_satd_wxh_sse2 END ; ;*********************************************************************** ;*********************************************************************** ; ;Pixel_satd_intra_sse2 BEGIN ; ;*********************************************************************** %macro SSE_DB_1_2REG 2 pxor %1, %1 pcmpeqw %2, %2 psubb %1, %2 %endmacro ;*********************************************************************** ; ;int32_t WelsSampleSatdThree4x4_sse2( uint8_t *pDec, int32_t iLineSizeDec, uint8_t *pEnc, int32_t iLinesizeEnc, ; uint8_t* pRed, int32_t* pBestMode, int32_t, int32_t, int32_t); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatdThree4x4_sse2 %ifdef X86_32 push r3 push r4 push r5 push r6 %assign push_num 4 %else %assign push_num 0 %endif PUSH_XMM 8 mov r2, arg3 mov r3, arg4 SIGN_EXTENSION r3, r3d ; load source 4x4 samples and Hadamard transform movd xmm0, [r2] movd xmm1, [r2+r3] lea r2 , [r2+2*r3] movd xmm2, [r2] movd xmm3, [r2+r3] punpckldq xmm0, xmm2 punpckldq xmm1, xmm3 pxor xmm6, xmm6 punpcklbw xmm0, xmm6 punpcklbw xmm1, xmm6 movdqa xmm2, xmm0 paddw xmm0, xmm1 psubw xmm2, xmm1 SSE2_XSawp qdq, xmm0, xmm2, xmm3 movdqa xmm4, xmm0 paddw xmm0, xmm3 psubw xmm4, xmm3 movdqa xmm2, xmm0 punpcklwd xmm0, xmm4 punpckhwd xmm4, xmm2 SSE2_XSawp dq, xmm0, xmm4, xmm3 SSE2_XSawp qdq, xmm0, xmm3, xmm5 movdqa xmm7, xmm0 paddw xmm0, xmm5 psubw xmm7, xmm5 SSE2_XSawp qdq, xmm0, xmm7, xmm1 ; Hadamard transform results are saved in xmm0 and xmm2 movdqa xmm2, xmm0 paddw xmm0, xmm1 psubw xmm2, xmm1 ;load top boundary samples: [a b c d] mov r0, arg1 mov r1, arg2 SIGN_EXTENSION r1, r1d sub r0, r1 %ifdef UNIX64 push r4 push r5 %endif movzx r2d, byte [r0] movzx r3d, byte [r0+1] movzx r4d, byte [r0+2] movzx r5d, byte [r0+3] ; get the transform results of top boundary samples: [a b c d] add r3d, r2d ; r3d = a + b add r5d, r4d ; r5d = c + d add r2d, r2d ; r2d = a + a add r4d, r4d ; r4d = c + c sub r2d, r3d ; r2d = a + a - a - b = a - b sub r4d, r5d ; r4d = c + c - c - d = c - d add r5d, r3d ; r5d = (a + b) + (c + d) add r3d, r3d sub r3d, r5d ; r3d = (a + b) - (c + d) add r4d, r2d ; r4d = (a - b) + (c - d) add r2d, r2d sub r2d, r4d ; r2d = (a - b) - (c - d) ; [r5d r3d r2d r4d] movdqa xmm6, xmm0 movdqa xmm7, xmm2 movd xmm5, r5d ; store the edi for DC mode pxor xmm3, xmm3 pxor xmm4, xmm4 pinsrw xmm3, r5d, 0 pinsrw xmm3, r4d, 4 psllw xmm3, 2 pinsrw xmm4, r3d, 0 pinsrw xmm4, r2d, 4 psllw xmm4, 2 ; get the satd of H psubw xmm0, xmm3 psubw xmm2, xmm4 WELS_AbsW xmm0, xmm1 WELS_AbsW xmm2, xmm1 paddusw xmm0, xmm2 SSE2_SumWHorizon1 xmm0, xmm1 ; satd of V is stored in xmm0 ;load left boundary samples: [a b c d]' add r0, r1 movzx r2d, byte [r0-1] movzx r3d, byte [r0+r1-1] lea r0 , [r0+2*r1] movzx r4d, byte [r0-1] movzx r5d, byte [r0+r1-1] ; get the transform results of left boundary samples: [a b c d]' add r3d, r2d ; r3d = a + b add r5d, r4d ; r5d = c + d add r2d, r2d ; r2d = a + a add r4d, r4d ; r4d = c + c sub r2d, r3d ; r2d = a + a - a - b = a - b sub r4d, r5d ; r4d = c + c - c - d = c - d add r5d, r3d ; r5d = (a + b) + (c + d) add r3d, r3d sub r3d, r5d ; r3d = (a + b) - (c + d) add r4d, r2d ; r4d = (a - b) + (c - d) add r2d, r2d sub r2d, r4d ; r2d = (a - b) - (c - d) ; [r5d r3d r2d r4d] ; store the transform results in xmm3 movd xmm3, r5d pinsrw xmm3, r3d, 1 pinsrw xmm3, r2d, 2 pinsrw xmm3, r4d, 3 psllw xmm3, 2 ; get the satd of V movdqa xmm2, xmm6 movdqa xmm4, xmm7 psubw xmm2, xmm3 WELS_AbsW xmm2, xmm1 WELS_AbsW xmm4, xmm1 paddusw xmm2, xmm4 SSE2_SumWHorizon1 xmm2, xmm1 ; satd of H is stored in xmm2 ; DC result is stored in xmm1 add r5d, 4 movd xmm1, r5d paddw xmm1, xmm5 psrlw xmm1, 3 movdqa xmm5, xmm1 psllw xmm1, 4 ; get the satd of DC psubw xmm6, xmm1 WELS_AbsW xmm6, xmm1 WELS_AbsW xmm7, xmm1 paddusw xmm6, xmm7 SSE2_SumWHorizon1 xmm6, xmm1 ; satd of DC is stored in xmm6 %ifdef UNIX64 pop r5 pop r4 %endif ; comparing order: DC H V mov r4, arg5 movd r2d, xmm6 movd r3d, xmm2 movd r6d, xmm0 and r2d, 0xffff shr r2d, 1 and r3d, 0xffff shr r3d, 1 and r6d, 0xffff shr r6d, 1 add r2d, dword arg7 add r3d, dword arg8 add r6d, dword arg9 cmp r2w, r3w jg near not_dc cmp r2w, r6w jg near not_dc_h ; for DC mode movd r3d, xmm5 imul r3d, 0x01010101 movd xmm5, r3d pshufd xmm5, xmm5, 0 movdqa [r4], xmm5 mov r5, arg6 mov dword [r5], 0x02 mov retrd, r2d POP_XMM %ifdef X86_32 pop r6 pop r5 pop r4 pop r3 %endif ret not_dc: cmp r3w, r6w jg near not_dc_h ; for H mode SSE_DB_1_2REG xmm6, xmm7 sub r0, r1 sub r0, r1 movzx r6d, byte [r0-1] movd xmm0, r6d pmuludq xmm0, xmm6 movzx r6d, byte [r0+r1-1] movd xmm1, r6d pmuludq xmm1, xmm6 punpckldq xmm0, xmm1 lea r0, [r0+r1*2] movzx r6d, byte [r0-1] movd xmm2, r6d pmuludq xmm2, xmm6 movzx r6d, byte [r0+r1-1] movd xmm3, r6d pmuludq xmm3, xmm6 punpckldq xmm2, xmm3 punpcklqdq xmm0, xmm2 movdqa [r4],xmm0 mov retrd, r3d mov r5, arg6 mov dword [r5], 0x01 POP_XMM %ifdef X86_32 pop r6 pop r5 pop r4 pop r3 %endif ret not_dc_h: sub r0, r1 sub r0, r1 sub r0, r1 movd xmm0, [r0] pshufd xmm0, xmm0, 0 movdqa [r4],xmm0 mov retrd, r6d mov r5, arg6 mov dword [r5], 0x00 POP_XMM %ifdef X86_32 pop r6 pop r5 pop r4 pop r3 %endif ret %macro SSE41_I16x16Get8WSumSub 3 ;xmm5 HSumSubDB1, xmm6 HSumSubDW1, xmm7 PDW1 : in %1, pOut %1, %3 pmaddubsw %1, xmm5 movdqa %2, %1 pmaddwd %1, xmm7 pmaddwd %2, xmm6 movdqa %3, %1 punpckldq %1, %2 punpckhdq %2, %3 movdqa %3, %1 punpcklqdq %1, %2 punpckhqdq %3, %2 paddd xmm4, %1 ;for dc paddd xmm4, %3 ;for dc packssdw %1, %3 psllw %1, 2 %endmacro %macro SSE41_ChromaGet8WSumSub 4 ;xmm5 HSumSubDB1, xmm6 HSumSubDW1, xmm7 PDW1 : in %1, pOut %1, %3 : %4 tempsse2 pmaddubsw %1, xmm5 movdqa %2, %1 pmaddwd %1, xmm7 pmaddwd %2, xmm6 movdqa %3, %1 punpckldq %1, %2 punpckhdq %2, %3 movdqa %3, %1 punpcklqdq %1, %2 punpckhqdq %3, %2 ; paddd xmm4, %1 ;for dc ; paddd xmm4, %3 ;for dc movdqa %4, %1 punpcklqdq %4, %3 packssdw %1, %3 psllw %1, 2 %endmacro %macro SSE41_GetX38x4SatdDec 0 pxor xmm7, xmm7 movq xmm0, [r2] movq xmm1, [r2+r3] lea r2, [r2+2*r3] movq xmm2, [r2] movq xmm3, [r2+r3] lea r2, [r2+2*r3] punpcklbw xmm0, xmm7 punpcklbw xmm1, xmm7 punpcklbw xmm2, xmm7 punpcklbw xmm3, xmm7 SSE2_HDMTwo4x4 xmm0,xmm1,xmm2,xmm3,xmm7 SSE2_TransTwo4x4W xmm3,xmm1,xmm0,xmm2,xmm7 SSE2_HDMTwo4x4 xmm3,xmm1,xmm2,xmm7,xmm0 ;pOut xmm7,xmm1,xmm3,xmm2 ;doesn't need another transpose %endmacro %macro SSE41_GetX38x4SatdV 2 pxor xmm0, xmm0 pinsrw xmm0, word[r6+%2], 0 pinsrw xmm0, word[r6+%2+8], 4 psubsw xmm0, xmm7 pabsw xmm0, xmm0 paddw xmm4, xmm0 pxor xmm0, xmm0 pinsrw xmm0, word[r6+%2+2], 0 pinsrw xmm0, word[r6+%2+10], 4 psubsw xmm0, xmm1 pabsw xmm0, xmm0 paddw xmm4, xmm0 pxor xmm0, xmm0 pinsrw xmm0, word[r6+%2+4], 0 pinsrw xmm0, word[r6+%2+12], 4 psubsw xmm0, xmm3 pabsw xmm0, xmm0 paddw xmm4, xmm0 pxor xmm0, xmm0 pinsrw xmm0, word[r6+%2+6], 0 pinsrw xmm0, word[r6+%2+14], 4 psubsw xmm0, xmm2 pabsw xmm0, xmm0 paddw xmm4, xmm0 %endmacro %macro SSE41_GetX38x4SatdH 3 movq xmm0, [r6+%3+8*%1] punpcklqdq xmm0, xmm0 psubsw xmm0, xmm7 pabsw xmm0, xmm0 paddw xmm5, xmm0 pabsw xmm1, xmm1 pabsw xmm2, xmm2 pabsw xmm3, xmm3 paddw xmm2, xmm1;for DC paddw xmm2, xmm3;for DC paddw xmm5, xmm2 %endmacro %macro SSE41_I16X16GetX38x4SatdDC 0 pxor xmm0, xmm0 movq2dq xmm0, mm4 punpcklqdq xmm0, xmm0 psubsw xmm0, xmm7 pabsw xmm0, xmm0 paddw xmm6, xmm0 paddw xmm6, xmm2 %endmacro %macro SSE41_ChromaGetX38x4SatdDC 1 shl %1, 4 movdqa xmm0, [r6+32+%1] psubsw xmm0, xmm7 pabsw xmm0, xmm0 paddw xmm6, xmm0 paddw xmm6, xmm2 %endmacro %macro SSE41_I16x16GetX38x4Satd 2 SSE41_GetX38x4SatdDec SSE41_GetX38x4SatdV %1, %2 SSE41_GetX38x4SatdH %1, %2, 32 SSE41_I16X16GetX38x4SatdDC %endmacro %macro SSE41_ChromaGetX38x4Satd 2 SSE41_GetX38x4SatdDec SSE41_GetX38x4SatdV %1, %2 SSE41_GetX38x4SatdH %1, %2, 16 SSE41_ChromaGetX38x4SatdDC %1 %endmacro %macro SSE41_HSum8W 3 pmaddwd %1, %2 movhlps %3, %1 paddd %1, %3 pshuflw %3, %1,0Eh paddd %1, %3 %endmacro WELS_EXTERN WelsIntra16x16Combined3Satd_sse41 %assign push_num 0 LOAD_7_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d SIGN_EXTENSION r5, r5d %ifndef X86_32 push r12 mov r12, r2 %endif pxor xmm4, xmm4 movdqa xmm5, [HSumSubDB1] movdqa xmm6, [HSumSubDW1] movdqa xmm7, [PDW1] sub r0, r1 movdqu xmm0, [r0] movhlps xmm1, xmm0 punpcklqdq xmm0, xmm0 punpcklqdq xmm1, xmm1 SSE41_I16x16Get8WSumSub xmm0, xmm2, xmm3 SSE41_I16x16Get8WSumSub xmm1, xmm2, xmm3 movdqa [r6], xmm0 ;V movdqa [r6+16], xmm1 add r0, r1 pinsrb xmm0, byte[r0-1], 0 pinsrb xmm0, byte[r0+r1-1], 1 lea r0, [r0+2*r1] pinsrb xmm0, byte[r0-1], 2 pinsrb xmm0, byte[r0+r1-1], 3 lea r0, [r0+2*r1] pinsrb xmm0, byte[r0-1], 4 pinsrb xmm0, byte[r0+r1-1], 5 lea r0, [r0+2*r1] pinsrb xmm0, byte[r0-1], 6 pinsrb xmm0, byte[r0+r1-1], 7 lea r0, [r0+2*r1] pinsrb xmm0, byte[r0-1], 8 pinsrb xmm0, byte[r0+r1-1], 9 lea r0, [r0+2*r1] pinsrb xmm0, byte[r0-1], 10 pinsrb xmm0, byte[r0+r1-1], 11 lea r0, [r0+2*r1] pinsrb xmm0, byte[r0-1], 12 pinsrb xmm0, byte[r0+r1-1], 13 lea r0, [r0+2*r1] pinsrb xmm0, byte[r0-1], 14 pinsrb xmm0, byte[r0+r1-1], 15 movhlps xmm1, xmm0 punpcklqdq xmm0, xmm0 punpcklqdq xmm1, xmm1 SSE41_I16x16Get8WSumSub xmm0, xmm2, xmm3 SSE41_I16x16Get8WSumSub xmm1, xmm2, xmm3 movdqa [r6+32], xmm0 ;H movdqa [r6+48], xmm1 movd r0d, xmm4 ;dc add r0d, 16 ;(sum+16) shr r0d, 5 ;((sum+16)>>5) shl r0d, 4 ; movd mm4, r0d ; mm4 copy DC pxor xmm4, xmm4 ;V pxor xmm5, xmm5 ;H pxor xmm6, xmm6 ;DC %ifdef UNIX64 push r4 %endif mov r0, 0 mov r4, 0 .loop16x16_get_satd: .loopStart1: SSE41_I16x16GetX38x4Satd r0, r4 inc r0 cmp r0, 4 jl .loopStart1 cmp r4, 16 je .loop16x16_get_satd_end %ifdef X86_32 mov r2, arg3 %else mov r2, r12 %endif add r2, 8 mov r0, 0 add r4, 16 jmp .loop16x16_get_satd .loop16x16_get_satd_end: MMX_DW_1_2REG xmm0, xmm1 psrlw xmm4, 1 ;/2 psrlw xmm5, 1 ;/2 psrlw xmm6, 1 ;/2 SSE41_HSum8W xmm4, xmm0, xmm1 SSE41_HSum8W xmm5, xmm0, xmm1 SSE41_HSum8W xmm6, xmm0, xmm1 %ifdef UNIX64 pop r4 %endif ; comparing order: DC H V movd r3d, xmm6 ;DC movd r1d, xmm5 ;H movd r0d, xmm4 ;V %ifndef X86_32 pop r12 %endif shl r5d, 1 add r1d, r5d add r3d, r5d mov r4, arg5 cmp r3d, r1d jge near not_dc_16x16 cmp r3d, r0d jge near not_dc_h_16x16 ; for DC mode mov dword[r4], 2;I16_PRED_DC mov retrd, r3d jmp near return_satd_intra_16x16_x3 not_dc_16x16: ; for H mode cmp r1d, r0d jge near not_dc_h_16x16 mov dword[r4], 1;I16_PRED_H mov retrd, r1d jmp near return_satd_intra_16x16_x3 not_dc_h_16x16: ; for V mode mov dword[r4], 0;I16_PRED_V mov retrd, r0d return_satd_intra_16x16_x3: WELSEMMS POP_XMM LOAD_7_PARA_POP ret %macro SSE41_ChromaGetX38x8Satd 0 movdqa xmm5, [HSumSubDB1] movdqa xmm6, [HSumSubDW1] movdqa xmm7, [PDW1] sub r0, r1 movq xmm0, [r0] punpcklqdq xmm0, xmm0 SSE41_ChromaGet8WSumSub xmm0, xmm2, xmm3, xmm4 movdqa [r6], xmm0 ;V add r0, r1 pinsrb xmm0, byte[r0-1], 0 pinsrb xmm0, byte[r0+r1-1], 1 lea r0, [r0+2*r1] pinsrb xmm0, byte[r0-1], 2 pinsrb xmm0, byte[r0+r1-1], 3 lea r0, [r0+2*r1] pinsrb xmm0, byte[r0-1], 4 pinsrb xmm0, byte[r0+r1-1], 5 lea r0, [r0+2*r1] pinsrb xmm0, byte[r0-1], 6 pinsrb xmm0, byte[r0+r1-1], 7 punpcklqdq xmm0, xmm0 SSE41_ChromaGet8WSumSub xmm0, xmm2, xmm3, xmm1 movdqa [r6+16], xmm0 ;H ;(sum+2)>>2 movdqa xmm6, [PDQ2] movdqa xmm5, xmm4 punpckhqdq xmm5, xmm1 paddd xmm5, xmm6 psrld xmm5, 2 ;(sum1+sum2+4)>>3 paddd xmm6, xmm6 paddd xmm4, xmm1 paddd xmm4, xmm6 psrld xmm4, 3 ;satd *16 pslld xmm5, 4 pslld xmm4, 4 ;temp satd movdqa xmm6, xmm4 punpcklqdq xmm4, xmm5 psllq xmm4, 32 psrlq xmm4, 32 movdqa [r6+32], xmm4 punpckhqdq xmm5, xmm6 psllq xmm5, 32 psrlq xmm5, 32 movdqa [r6+48], xmm5 pxor xmm4, xmm4 ;V pxor xmm5, xmm5 ;H pxor xmm6, xmm6 ;DC mov r0, 0 SSE41_ChromaGetX38x4Satd r0, 0 inc r0 SSE41_ChromaGetX38x4Satd r0, 0 %endmacro %macro SSEReg2MMX 3 movdq2q %2, %1 movhlps %1, %1 movdq2q %3, %1 %endmacro %macro MMXReg2SSE 4 movq2dq %1, %3 movq2dq %2, %4 punpcklqdq %1, %2 %endmacro ;for reduce the code size of WelsIntraChroma8x8Combined3Satd_sse41 WELS_EXTERN WelsIntraChroma8x8Combined3Satd_sse41 %assign push_num 0 LOAD_7_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d SIGN_EXTENSION r5, r5d loop_chroma_satdx3: SSE41_ChromaGetX38x8Satd SSEReg2MMX xmm4, mm0,mm1 SSEReg2MMX xmm5, mm2,mm3 SSEReg2MMX xmm6, mm5,mm6 mov r0, arg8 mov r2, arg9 SSE41_ChromaGetX38x8Satd MMXReg2SSE xmm0, xmm3, mm0, mm1 MMXReg2SSE xmm1, xmm3, mm2, mm3 MMXReg2SSE xmm2, xmm3, mm5, mm6 paddw xmm4, xmm0 paddw xmm5, xmm1 paddw xmm6, xmm2 MMX_DW_1_2REG xmm0, xmm1 psrlw xmm4, 1 ;/2 psrlw xmm5, 1 ;/2 psrlw xmm6, 1 ;/2 SSE41_HSum8W xmm4, xmm0, xmm1 SSE41_HSum8W xmm5, xmm0, xmm1 SSE41_HSum8W xmm6, xmm0, xmm1 ; comparing order: DC H V movd r3d, xmm6 ;DC movd r1d, xmm5 ;H movd r0d, xmm4 ;V shl r5d, 1 add r1d, r5d add r0d, r5d cmp r3d, r1d jge near not_dc_8x8 cmp r3d, r0d jge near not_dc_h_8x8 ; for DC mode mov dword[r4], 0;I8_PRED_DC mov retrd, r3d jmp near return_satd_intra_8x8_x3 not_dc_8x8: ; for H mode cmp r1d, r0d jge near not_dc_h_8x8 mov dword[r4], 1;I8_PRED_H mov retrd, r1d jmp near return_satd_intra_8x8_x3 not_dc_h_8x8: ; for V mode mov dword[r4], 2;I8_PRED_V mov retrd, r0d return_satd_intra_8x8_x3: WELSEMMS POP_XMM LOAD_7_PARA_POP ret ;*********************************************************************** ; ;Pixel_satd_intra_sse2 END ; ;*********************************************************************** %macro SSSE3_Get16BSadHVDC 2 movd xmm6,%1 pshufb xmm6,xmm1 movdqa %1, xmm6 movdqa xmm0,%2 psadbw xmm0,xmm7 paddw xmm4,xmm0 movdqa xmm0,%2 psadbw xmm0,xmm5 paddw xmm2,xmm0 psadbw xmm6,%2 paddw xmm3,xmm6 %endmacro %macro WelsAddDCValue 4 movzx %2, byte %1 mov %3, %2 add %4, %2 %endmacro ;*********************************************************************** ; ;Pixel_sad_intra_ssse3 BEGIN ; ;*********************************************************************** WELS_EXTERN WelsIntra16x16Combined3Sad_ssse3 %assign push_num 0 LOAD_7_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d SIGN_EXTENSION r5, r5d push r5 push r4 push r3 sub r0, r1 movdqa xmm5,[r0] pxor xmm0,xmm0 psadbw xmm0,xmm5 movhlps xmm1,xmm0 paddw xmm0,xmm1 movd r5d, xmm0 add r0,r1 lea r3,[r1+2*r1] ;ebx r3 WelsAddDCValue [r0-1 ], r4d, [r6 ], r5d ; esi r4d, eax r5d WelsAddDCValue [r0-1+r1 ], r4d, [r6+16], r5d WelsAddDCValue [r0-1+r1*2], r4d, [r6+32], r5d WelsAddDCValue [r0-1+r3 ], r4d, [r6+48], r5d lea r0, [r0+4*r1] add r6, 64 WelsAddDCValue [r0-1 ], r4d, [r6 ], r5d WelsAddDCValue [r0-1+r1 ], r4d, [r6+16], r5d WelsAddDCValue [r0-1+r1*2], r4d, [r6+32], r5d WelsAddDCValue [r0-1+r3 ], r4d, [r6+48], r5d lea r0, [r0+4*r1] add r6, 64 WelsAddDCValue [r0-1 ], r4d, [r6 ], r5d WelsAddDCValue [r0-1+r1 ], r4d, [r6+16], r5d WelsAddDCValue [r0-1+r1*2], r4d, [r6+32], r5d WelsAddDCValue [r0-1+r3 ], r4d, [r6+48], r5d lea r0, [r0+4*r1] add r6, 64 WelsAddDCValue [r0-1 ], r4d, [r6 ], r5d WelsAddDCValue [r0-1+r1 ], r4d, [r6+16], r5d WelsAddDCValue [r0-1+r1*2], r4d, [r6+32], r5d WelsAddDCValue [r0-1+r3 ], r4d, [r6+48], r5d sub r6, 192 add r5d,10h shr r5d,5 movd xmm7,r5d pxor xmm1,xmm1 pshufb xmm7,xmm1 pxor xmm4,xmm4 pxor xmm3,xmm3 pxor xmm2,xmm2 ;sad begin pop r3 lea r4, [r3+2*r3] ;esi r4 SSSE3_Get16BSadHVDC [r6], [r2] SSSE3_Get16BSadHVDC [r6+16], [r2+r3] SSSE3_Get16BSadHVDC [r6+32], [r2+2*r3] SSSE3_Get16BSadHVDC [r6+48], [r2+r4] add r6, 64 lea r2, [r2+4*r3] SSSE3_Get16BSadHVDC [r6], [r2] SSSE3_Get16BSadHVDC [r6+16], [r2+r3] SSSE3_Get16BSadHVDC [r6+32], [r2+2*r3] SSSE3_Get16BSadHVDC [r6+48], [r2+r4] add r6, 64 lea r2, [r2+4*r3] SSSE3_Get16BSadHVDC [r6], [r2] SSSE3_Get16BSadHVDC [r6+16], [r2+r3] SSSE3_Get16BSadHVDC [r6+32], [r2+2*r3] SSSE3_Get16BSadHVDC [r6+48], [r2+r4] add r6, 64 lea r2, [r2+4*r3] SSSE3_Get16BSadHVDC [r6], [r2] SSSE3_Get16BSadHVDC [r6+16], [r2+r3] SSSE3_Get16BSadHVDC [r6+32], [r2+2*r3] SSSE3_Get16BSadHVDC [r6+48], [r2+r4] pop r4 pop r5 pslldq xmm3,4 por xmm3,xmm2 movhlps xmm1,xmm3 paddw xmm3,xmm1 movhlps xmm0,xmm4 paddw xmm4,xmm0 ; comparing order: DC H V movd r1d, xmm4 ;DC ;ebx r1d movd r0d, xmm3 ;V ;ecx r0d psrldq xmm3, 4 movd r2d, xmm3 ;H ;esi r2d ;mov eax, [esp+36] ;lamda ;eax r5 shl r5d, 1 add r2d, r5d add r1d, r5d ;mov edx, [esp+32] ;edx r4 cmp r1d, r2d jge near not_dc_16x16_sad cmp r1d, r0d jge near not_dc_h_16x16_sad ; for DC mode mov dword[r4], 2;I16_PRED_DC mov retrd, r1d sub r6, 192 %assign x 0 %rep 16 movdqa [r6+16*x], xmm7 %assign x x+1 %endrep jmp near return_sad_intra_16x16_x3 not_dc_16x16_sad: ; for H mode cmp r2d, r0d jge near not_dc_h_16x16_sad mov dword[r4], 1;I16_PRED_H mov retrd, r2d jmp near return_sad_intra_16x16_x3 not_dc_h_16x16_sad: ; for V mode mov dword[r4], 0;I16_PRED_V mov retrd, r0d sub r6, 192 %assign x 0 %rep 16 movdqa [r6+16*x], xmm5 %assign x x+1 %endrep return_sad_intra_16x16_x3: POP_XMM LOAD_7_PARA_POP ret ;*********************************************************************** ; ;Pixel_sad_intra_ssse3 END ; ;*********************************************************************** ;*********************************************************************** ; ;Pixel_satd_wxh_sse41 BEGIN ; ;*********************************************************************** ;SSE4.1 %macro SSE41_GetSatd8x4 0 movq xmm0, [r0] punpcklqdq xmm0, xmm0 pmaddubsw xmm0, xmm7 movq xmm1, [r0+r1] punpcklqdq xmm1, xmm1 pmaddubsw xmm1, xmm7 movq xmm2, [r2] punpcklqdq xmm2, xmm2 pmaddubsw xmm2, xmm7 movq xmm3, [r2+r3] punpcklqdq xmm3, xmm3 pmaddubsw xmm3, xmm7 psubsw xmm0, xmm2 psubsw xmm1, xmm3 movq xmm2, [r0+2*r1] punpcklqdq xmm2, xmm2 pmaddubsw xmm2, xmm7 movq xmm3, [r0+r4] punpcklqdq xmm3, xmm3 pmaddubsw xmm3, xmm7 movq xmm4, [r2+2*r3] punpcklqdq xmm4, xmm4 pmaddubsw xmm4, xmm7 movq xmm5, [r2+r5] punpcklqdq xmm5, xmm5 pmaddubsw xmm5, xmm7 psubsw xmm2, xmm4 psubsw xmm3, xmm5 SSE2_HDMTwo4x4 xmm0, xmm1, xmm2, xmm3, xmm4 pabsw xmm0, xmm0 pabsw xmm2, xmm2 pabsw xmm1, xmm1 pabsw xmm3, xmm3 movdqa xmm4, xmm3 pblendw xmm3, xmm1, 0xAA pslld xmm1, 16 psrld xmm4, 16 por xmm1, xmm4 pmaxuw xmm1, xmm3 paddw xmm6, xmm1 movdqa xmm4, xmm0 pblendw xmm0, xmm2, 0xAA pslld xmm2, 16 psrld xmm4, 16 por xmm2, xmm4 pmaxuw xmm0, xmm2 paddw xmm6, xmm0 %endmacro %macro SSSE3_SumWHorizon 4 ;eax, srcSSE, tempSSE, tempSSE MMX_DW_1_2REG %3, %4 pmaddwd %2, %3 movhlps %4, %2 paddd %2, %4 pshuflw %4, %2,0Eh paddd %2, %4 movd %1, %2 %endmacro ;*********************************************************************** ; ;int32_t WelsSampleSatd4x4_sse41( uint8_t *, int32_t, uint8_t *, int32_t ); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatd4x4_sse41 %assign push_num 0 LOAD_4_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d movdqa xmm4,[HSwapSumSubDB1] movd xmm2,[r2] movd xmm5,[r2+r3] shufps xmm2,xmm5,0 movd xmm3,[r2+r3*2] lea r2, [r3*2+r2] movd xmm5,[r2+r3] shufps xmm3,xmm5,0 movd xmm0,[r0] movd xmm5,[r0+r1] shufps xmm0,xmm5,0 movd xmm1,[r0+r1*2] lea r0, [r1*2+r0] movd xmm5,[r0+r1] shufps xmm1,xmm5,0 pmaddubsw xmm0,xmm4 pmaddubsw xmm1,xmm4 pmaddubsw xmm2,xmm4 pmaddubsw xmm3,xmm4 psubw xmm0,xmm2 psubw xmm1,xmm3 movdqa xmm2,xmm0 paddw xmm0,xmm1 psubw xmm1,xmm2 movdqa xmm2,xmm0 punpcklqdq xmm0,xmm1 punpckhqdq xmm2,xmm1 movdqa xmm1,xmm0 paddw xmm0,xmm2 psubw xmm2,xmm1 movdqa xmm1,xmm0 pblendw xmm0,xmm2,0AAh pslld xmm2,16 psrld xmm1,16 por xmm2,xmm1 pabsw xmm0,xmm0 pabsw xmm2,xmm2 pmaxsw xmm0,xmm2 SSSE3_SumWHorizon retrd, xmm0, xmm5, xmm7 POP_XMM LOAD_4_PARA_POP ret ;*********************************************************************** ; ;int32_t WelsSampleSatd8x8_sse41( uint8_t *, int32_t, uint8_t *, int32_t, ); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatd8x8_sse41 %ifdef X86_32 push r4 push r5 %endif %assign push_num 2 LOAD_4_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d movdqa xmm7, [HSumSubDB1] lea r4, [r1+r1*2] lea r5, [r3+r3*2] pxor xmm6, xmm6 SSE41_GetSatd8x4 lea r0, [r0+4*r1] lea r2, [r2+4*r3] SSE41_GetSatd8x4 SSSE3_SumWHorizon retrd, xmm6, xmm5, xmm7 POP_XMM LOAD_4_PARA_POP %ifdef X86_32 pop r5 pop r4 %endif ret ;*********************************************************************** ; ;int32_t WelsSampleSatd8x16_sse41( uint8_t *, int32_t, uint8_t *, int32_t, ); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatd8x16_sse41 %ifdef X86_32 push r4 push r5 push r6 %endif %assign push_num 3 LOAD_4_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d movdqa xmm7, [HSumSubDB1] lea r4, [r1+r1*2] lea r5, [r3+r3*2] pxor xmm6, xmm6 mov r6, 0 loop_get_satd_8x16: SSE41_GetSatd8x4 lea r0, [r0+4*r1] lea r2, [r2+4*r3] inc r6 cmp r6, 4 jl loop_get_satd_8x16 SSSE3_SumWHorizon retrd, xmm6, xmm5, xmm7 POP_XMM LOAD_4_PARA_POP %ifdef X86_32 pop r6 pop r5 pop r4 %endif ret ;*********************************************************************** ; ;int32_t WelsSampleSatd16x8_sse41( uint8_t *, int32_t, uint8_t *, int32_t, ); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatd16x8_sse41 %ifdef X86_32 push r4 push r5 %endif %assign push_num 2 LOAD_4_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d push r0 push r2 movdqa xmm7, [HSumSubDB1] lea r4, [r1+r1*2] lea r5, [r3+r3*2] pxor xmm6, xmm6 SSE41_GetSatd8x4 lea r0, [r0+4*r1] lea r2, [r2+4*r3] SSE41_GetSatd8x4 pop r2 pop r0 add r0, 8 add r2, 8 SSE41_GetSatd8x4 lea r0, [r0+4*r1] lea r2, [r2+4*r3] SSE41_GetSatd8x4 SSSE3_SumWHorizon retrd, xmm6, xmm5, xmm7 POP_XMM LOAD_4_PARA_POP %ifdef X86_32 pop r5 pop r4 %endif ret ;*********************************************************************** ; ;int32_t WelsSampleSatd16x16_sse41( uint8_t *, int32_t, uint8_t *, int32_t, ); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatd16x16_sse41 %ifdef X86_32 push r4 push r5 push r6 %endif %assign push_num 3 LOAD_4_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d push r0 push r2 movdqa xmm7, [HSumSubDB1] lea r4, [r1+r1*2] lea r5, [r3+r3*2] pxor xmm6, xmm6 mov r6, 0 loop_get_satd_16x16_left: SSE41_GetSatd8x4 lea r0, [r0+4*r1] lea r2, [r2+4*r3] inc r6 cmp r6, 4 jl loop_get_satd_16x16_left pop r2 pop r0 add r0, 8 add r2, 8 mov r6, 0 loop_get_satd_16x16_right: SSE41_GetSatd8x4 lea r0, [r0+4*r1] lea r2, [r2+4*r3] inc r6 cmp r6, 4 jl loop_get_satd_16x16_right SSSE3_SumWHorizon retrd, xmm6, xmm5, xmm7 POP_XMM LOAD_4_PARA_POP %ifdef X86_32 pop r6 pop r5 pop r4 %endif ret ;*********************************************************************** ; ;Pixel_satd_wxh_sse41 END ; ;*********************************************************************** ;*********************************************************************** ; ;Pixel_satd_wxh_avx2 BEGIN ; ;*********************************************************************** ; out=%1 pSrcA=%2 pSrcB=%3 HSumSubDB1_256=%4 ymm_clobber=%5 %macro AVX2_LoadDiffSatd16x1 5 vbroadcasti128 %1, [%2] vpmaddubsw %1, %1, %4 ; hadamard neighboring horizontal sums and differences vbroadcasti128 %5, [%3] vpmaddubsw %5, %5, %4 ; hadamard neighboring horizontal sums and differences vpsubw %1, %1, %5 ; diff srcA srcB %endmacro ; out=%1 pSrcA=%2 pSrcA+4*iStride=%3 pSrcB=%4 pSrcB+4*iStride=%5 HSumSubDB1_128x2=%6 ymm_clobber=%7,%8 %macro AVX2_LoadDiffSatd8x2 8 vpbroadcastq %1, [%2] vpbroadcastq %7, [%3] vpblendd %1, %1, %7, 11110000b vpmaddubsw %1, %1, %6 ; hadamard neighboring horizontal sums and differences vpbroadcastq %7, [%4] vpbroadcastq %8, [%5] vpblendd %7, %7, %8, 11110000b vpmaddubsw %7, %7, %6 ; hadamard neighboring horizontal sums and differences vpsubw %1, %1, %7 ; diff srcA srcB %endmacro ; in/out=%1,%2,%3,%4 clobber=%5 %macro AVX2_HDMFour4x4 5 vpsubw %5, %1, %4 ; s3 = x0 - x3 vpaddw %1, %1, %4 ; s0 = x0 + x3 vpsubw %4, %2, %3 ; s2 = x1 - x2 vpaddw %2, %2, %3 ; s1 = x1 + x2 vpsubw %3, %1, %2 ; y2 = s0 - s1 vpaddw %1, %1, %2 ; y0 = s0 + s1 vpaddw %2, %5, %4 ; y1 = s3 + s2 vpsubw %4, %5, %4 ; y3 = s3 - s2 %endmacro ; out=%1 in=%1,%2,%3,%4 clobber=%5 %macro AVX2_SatdFour4x4 5 AVX2_HDMFour4x4 %1, %2, %3, %4, %5 vpabsw %1, %1 vpabsw %2, %2 vpabsw %3, %3 vpabsw %4, %4 ; second stage of horizontal hadamard. ; utilizes that |a + b| + |a - b| = 2 * max(|a|, |b|) vpblendw %5, %1, %2, 10101010b vpslld %2, %2, 16 vpsrld %1, %1, 16 vpor %2, %2, %1 vpmaxuw %2, %2, %5 vpblendw %5, %3, %4, 10101010b vpslld %4, %4, 16 vpsrld %3, %3, 16 vpor %4, %4, %3 vpmaxuw %3, %5, %4 vpaddw %1, %2, %3 %endmacro ; out=%1 pSrcA=%2 iStrideA=%3 3*iStrideA=%4 pSrcB=%5 iStrideB=%6 3*iStrideB=%7 HSumSubDB1_256=%8 ymm_clobber=%9,%10,%11,%12 %macro AVX2_GetSatd16x4 12 AVX2_LoadDiffSatd16x1 %1, %2 + 0 * %3, %5 + 0 * %6, %8, %12 AVX2_LoadDiffSatd16x1 %9, %2 + 1 * %3, %5 + 1 * %6, %8, %12 AVX2_LoadDiffSatd16x1 %10, %2 + 2 * %3, %5 + 2 * %6, %8, %12 AVX2_LoadDiffSatd16x1 %11, %2 + 1 * %4, %5 + 1 * %7, %8, %12 AVX2_SatdFour4x4 %1, %9, %10, %11, %12 %endmacro ; out=%1 pSrcA=%2 iStrideA=%3 3*iStrideA=%4 pSrcB=%5 iStrideB=%6 3*iStrideB=%7 HSumSubDB1_128x2=%8 ymm_clobber=%9,%10,%11,%12,%13 %macro AVX2_GetSatd8x8 13 AVX2_LoadDiffSatd8x2 %1, %2 + 0 * %3, %2 + 4 * %3, %5 + 0 * %6, %5 + 4 * %6, %8, %12, %13 AVX2_LoadDiffSatd8x2 %10, %2 + 2 * %3, %2 + 2 * %4, %5 + 2 * %6, %5 + 2 * %7, %8, %12, %13 add %2, %3 add %5, %6 AVX2_LoadDiffSatd8x2 %9, %2 + 0 * %3, %2 + 4 * %3, %5 + 0 * %6, %5 + 4 * %6, %8, %12, %13 AVX2_LoadDiffSatd8x2 %11, %2 + 2 * %3, %2 + 2 * %4, %5 + 2 * %6, %5 + 2 * %7, %8, %12, %13 AVX2_SatdFour4x4 %1, %9, %10, %11, %12 %endmacro ; d_out=%1 mm_in=%2 mm_clobber=%3 %macro AVX2_SumWHorizon 3 WELS_DW1_VEX y%3 vpmaddwd y%2, y%2, y%3 vextracti128 x%3, y%2, 1 vpaddd x%2, x%2, x%3 vpunpckhqdq x%3, x%2, x%2 vpaddd x%2, x%2, x%3 vpsrldq x%3, x%2, 4 vpaddd x%2, x%2, x%3 vmovd %1, x%2 %endmacro ;*********************************************************************** ; ;int32_t WelsSampleSatd8x16_avx2( uint8_t *, int32_t, uint8_t *, int32_t, ); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatd8x16_avx2 %assign push_num 0 %ifdef X86_32 push r4 %assign push_num 1 %endif mov r4, 2 ; loop cnt jmp WelsSampleSatd8x8N_avx2 ;*********************************************************************** ; ;int32_t WelsSampleSatd8x8_avx2( uint8_t *, int32_t, uint8_t *, int32_t, ); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatd8x8_avx2 %assign push_num 0 %ifdef X86_32 push r4 %assign push_num 1 %endif mov r4, 1 ; loop cnt ; fall through WelsSampleSatd8x8N_avx2: %ifdef X86_32 push r5 push r6 %assign push_num push_num+2 %endif LOAD_4_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d vbroadcasti128 ymm7, [HSumSubDB1] lea r5, [3 * r1] lea r6, [3 * r3] vpxor ymm6, ymm6, ymm6 .loop: AVX2_GetSatd8x8 ymm0, r0, r1, r5, r2, r3, r6, ymm7, ymm1, ymm2, ymm3, ymm4, ymm5 vpaddw ymm6, ymm6, ymm0 sub r4, 1 jbe .loop_end add r0, r5 add r2, r6 lea r0, [r0 + 4 * r1] lea r2, [r2 + 4 * r3] jmp .loop .loop_end: AVX2_SumWHorizon retrd, mm6, mm5 vzeroupper POP_XMM LOAD_4_PARA_POP %ifdef X86_32 pop r6 pop r5 pop r4 %endif ret ;*********************************************************************** ; ;int32_t WelsSampleSatd16x16_avx2( uint8_t *, int32_t, uint8_t *, int32_t, ); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatd16x16_avx2 %assign push_num 0 %ifdef X86_32 push r4 %assign push_num 1 %endif mov r4, 4 ; loop cnt jmp WelsSampleSatd16x4N_avx2 ;*********************************************************************** ; ;int32_t WelsSampleSatd16x8_avx2( uint8_t *, int32_t, uint8_t *, int32_t, ); ; ;*********************************************************************** WELS_EXTERN WelsSampleSatd16x8_avx2 %assign push_num 0 %ifdef X86_32 push r4 %assign push_num 1 %endif mov r4, 2 ; loop cnt ; fall through WelsSampleSatd16x4N_avx2: %ifdef X86_32 push r5 push r6 %assign push_num push_num+2 %endif LOAD_4_PARA PUSH_XMM 7 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d vpbroadcastq xmm0, [HSumSubDB1] vpbroadcastq ymm6, [HSumSubDB1 + 8] vpblendd ymm6, ymm0, ymm6, 11110000b lea r5, [3 * r1] lea r6, [3 * r3] vpxor ymm5, ymm5, ymm5 .loop: AVX2_GetSatd16x4 ymm0, r0, r1, r5, r2, r3, r6, ymm6, ymm1, ymm2, ymm3, ymm4 vpaddw ymm5, ymm5, ymm0 lea r0, [r0 + 4 * r1] lea r2, [r2 + 4 * r3] sub r4, 1 ja .loop AVX2_SumWHorizon retrd, mm5, mm0 vzeroupper POP_XMM LOAD_4_PARA_POP %ifdef X86_32 pop r6 pop r5 pop r4 %endif ret ;*********************************************************************** ; ;Pixel_satd_wxh_avx2 END ; ;*********************************************************************** ;*********************************************************************** ; ;Pixel_sad_wxh_sse2 BEGIN ; ;*********************************************************************** %macro SSE2_GetSad2x16 0 lea r0, [r0+2*r1] lea r2, [r2+2*r3] movdqu xmm1, [r2] MOVDQ xmm2, [r0];[eax] must aligned 16 psadbw xmm1, xmm2 paddw xmm0, xmm1 movdqu xmm1, [r2+r3] MOVDQ xmm2, [r0+r1] psadbw xmm1, xmm2 paddw xmm0, xmm1 %endmacro %macro SSE2_GetSad4x16 0 movdqu xmm0, [r2] MOVDQ xmm2, [r0] psadbw xmm0, xmm2 paddw xmm7, xmm0 movdqu xmm1, [r2+r3] MOVDQ xmm2, [r0+r1] psadbw xmm1, xmm2 paddw xmm7, xmm1 movdqu xmm1, [r2+2*r3] MOVDQ xmm2, [r0+2*r1];[eax] must aligned 16 psadbw xmm1, xmm2 paddw xmm7, xmm1 movdqu xmm1, [r2+r5] MOVDQ xmm2, [r0+r4] psadbw xmm1, xmm2 paddw xmm7, xmm1 %endmacro %macro SSE2_GetSad8x4 0 movq xmm0, [r0] movq xmm1, [r0+r1] lea r0, [r0+2*r1] movhps xmm0, [r0] movhps xmm1, [r0+r1] movq xmm2, [r2] movq xmm3, [r2+r3] lea r2, [r2+2*r3] movhps xmm2, [r2] movhps xmm3, [r2+r3] psadbw xmm0, xmm2 psadbw xmm1, xmm3 paddw xmm6, xmm0 paddw xmm6, xmm1 %endmacro ;*********************************************************************** ; ;int32_t WelsSampleSad16x16_sse2( uint8_t *, int32_t, uint8_t *, int32_t, ) ;First parameter can align to 16 bytes, ;In wels, the third parameter can't align to 16 bytes. ; ;*********************************************************************** WELS_EXTERN WelsSampleSad16x16_sse2 %ifdef X86_32 push r4 push r5 %endif %assign push_num 2 LOAD_4_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d lea r4, [3*r1] lea r5, [3*r3] pxor xmm7, xmm7 SSE2_GetSad4x16 lea r0, [r0+4*r1] lea r2, [r2+4*r3] SSE2_GetSad4x16 lea r0, [r0+4*r1] lea r2, [r2+4*r3] SSE2_GetSad4x16 lea r0, [r0+4*r1] lea r2, [r2+4*r3] SSE2_GetSad4x16 movhlps xmm0, xmm7 paddw xmm0, xmm7 movd retrd, xmm0 POP_XMM LOAD_4_PARA_POP %ifdef X86_32 pop r5 pop r4 %endif ret ;*********************************************************************** ; ;int32_t WelsSampleSad16x8_sse2( uint8_t *, int32_t, uint8_t *, int32_t, ) ;First parameter can align to 16 bytes, ;In wels, the third parameter can't align to 16 bytes. ; ;*********************************************************************** WELS_EXTERN WelsSampleSad16x8_sse2 %assign push_num 0 LOAD_4_PARA SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d movdqu xmm0, [r2] MOVDQ xmm2, [r0] psadbw xmm0, xmm2 movdqu xmm1, [r2+r3] MOVDQ xmm2, [r0+r1] psadbw xmm1, xmm2 paddw xmm0, xmm1 SSE2_GetSad2x16 SSE2_GetSad2x16 SSE2_GetSad2x16 movhlps xmm1, xmm0 paddw xmm0, xmm1 movd retrd, xmm0 LOAD_4_PARA_POP ret WELS_EXTERN WelsSampleSad8x16_sse2 %assign push_num 0 LOAD_4_PARA PUSH_XMM 7 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d pxor xmm6, xmm6 SSE2_GetSad8x4 lea r0, [r0+2*r1] lea r2, [r2+2*r3] SSE2_GetSad8x4 lea r0, [r0+2*r1] lea r2, [r2+2*r3] SSE2_GetSad8x4 lea r0, [r0+2*r1] lea r2, [r2+2*r3] SSE2_GetSad8x4 movhlps xmm0, xmm6 paddw xmm0, xmm6 movd retrd, xmm0 POP_XMM LOAD_4_PARA_POP ret %macro CACHE_SPLIT_CHECK 3 ; address, width, cacheline and %1, 0x1f|(%3>>1) cmp %1, (32-%2)|(%3>>1) %endmacro WELS_EXTERN WelsSampleSad8x8_sse21 %assign push_num 0 mov r2, arg3 push r2 CACHE_SPLIT_CHECK r2, 8, 64 jle near .pixel_sad_8x8_nsplit pop r2 %ifdef X86_32 push r3 push r4 push r5 %endif %assign push_num 3 PUSH_XMM 8 mov r0, arg1 mov r1, arg2 SIGN_EXTENSION r1, r1d pxor xmm7, xmm7 ;ecx r2, edx r4, edi r5 mov r5, r2 and r5, 0x07 sub r2, r5 mov r4, 8 sub r4, r5 shl r5, 3 shl r4, 3 movd xmm5, r5d movd xmm6, r4d mov r5, 8 add r5, r2 mov r3, arg4 SIGN_EXTENSION r3, r3d movq xmm0, [r0] movhps xmm0, [r0+r1] movq xmm1, [r2] movq xmm2, [r5] movhps xmm1, [r2+r3] movhps xmm2, [r5+r3] psrlq xmm1, xmm5 psllq xmm2, xmm6 por xmm1, xmm2 psadbw xmm0, xmm1 paddw xmm7, xmm0 lea r0, [r0+2*r1] lea r2, [r2+2*r3] lea r5, [r5+2*r3] movq xmm0, [r0] movhps xmm0, [r0+r1] movq xmm1, [r2] movq xmm2, [r5] movhps xmm1, [r2+r3] movhps xmm2, [r5+r3] psrlq xmm1, xmm5 psllq xmm2, xmm6 por xmm1, xmm2 psadbw xmm0, xmm1 paddw xmm7, xmm0 lea r0, [r0+2*r1] lea r2, [r2+2*r3] lea r5, [r5+2*r3] movq xmm0, [r0] movhps xmm0, [r0+r1] movq xmm1, [r2] movq xmm2, [r5] movhps xmm1, [r2+r3] movhps xmm2, [r5+r3] psrlq xmm1, xmm5 psllq xmm2, xmm6 por xmm1, xmm2 psadbw xmm0, xmm1 paddw xmm7, xmm0 lea r0, [r0+2*r1] lea r2, [r2+2*r3] lea r5, [r5+2*r3] movq xmm0, [r0] movhps xmm0, [r0+r1] movq xmm1, [r2] movq xmm2, [r5] movhps xmm1, [r2+r3] movhps xmm2, [r5+r3] psrlq xmm1, xmm5 psllq xmm2, xmm6 por xmm1, xmm2 psadbw xmm0, xmm1 paddw xmm7, xmm0 movhlps xmm0, xmm7 paddw xmm0, xmm7 movd retrd, xmm0 POP_XMM %ifdef X86_32 pop r5 pop r4 pop r3 %endif jmp .return .pixel_sad_8x8_nsplit: pop r2 %assign push_num 0 LOAD_4_PARA PUSH_XMM 7 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d pxor xmm6, xmm6 SSE2_GetSad8x4 lea r0, [r0+2*r1] lea r2, [r2+2*r3] SSE2_GetSad8x4 movhlps xmm0, xmm6 paddw xmm0, xmm6 movd retrd, xmm0 POP_XMM LOAD_4_PARA_POP .return: ret ;*********************************************************************** ; ;Pixel_sad_wxh_sse2 END ; ;*********************************************************************** ;*********************************************************************** ; ;Pixel_sad_4_wxh_sse2 BEGIN ; ;*********************************************************************** %macro SSE2_Get4LW16Sad 5 ;s-1l, s, s+1l, d, address psadbw %1, %4 paddw xmm5, %1 psadbw %4, %3 paddw xmm4, %4 movdqu %4, [%5-1] psadbw %4, %2 paddw xmm6, %4 movdqu %4, [%5+1] psadbw %4, %2 paddw xmm7, %4 %endmacro WELS_EXTERN WelsSampleSadFour16x16_sse2 %assign push_num 0 LOAD_5_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d pxor xmm4, xmm4 ;sad pRefMb-i_stride_ref pxor xmm5, xmm5 ;sad pRefMb+i_stride_ref pxor xmm6, xmm6 ;sad pRefMb-1 pxor xmm7, xmm7 ;sad pRefMb+1 movdqa xmm0, [r0] sub r2, r3 movdqu xmm3, [r2] psadbw xmm3, xmm0 paddw xmm4, xmm3 movdqa xmm1, [r0+r1] movdqu xmm3, [r2+r3] psadbw xmm3, xmm1 paddw xmm4, xmm3 movdqu xmm2, [r2+r3-1] psadbw xmm2, xmm0 paddw xmm6, xmm2 movdqu xmm3, [r2+r3+1] psadbw xmm3, xmm0 paddw xmm7, xmm3 lea r0, [r0+2*r1] lea r2, [r2+2*r3] movdqa xmm2, [r0] movdqu xmm3, [r2] SSE2_Get4LW16Sad xmm0, xmm1, xmm2, xmm3, r2 movdqa xmm0, [r0+r1] movdqu xmm3, [r2+r3] SSE2_Get4LW16Sad xmm1, xmm2, xmm0, xmm3, r2+r3 lea r0, [r0+2*r1] lea r2, [r2+2*r3] movdqa xmm1, [r0] movdqu xmm3, [r2] SSE2_Get4LW16Sad xmm2, xmm0, xmm1, xmm3, r2 movdqa xmm2, [r0+r1] movdqu xmm3, [r2+r3] SSE2_Get4LW16Sad xmm0, xmm1, xmm2, xmm3, r2+r3 lea r0, [r0+2*r1] lea r2, [r2+2*r3] movdqa xmm0, [r0] movdqu xmm3, [r2] SSE2_Get4LW16Sad xmm1, xmm2, xmm0, xmm3, r2 movdqa xmm1, [r0+r1] movdqu xmm3, [r2+r3] SSE2_Get4LW16Sad xmm2, xmm0, xmm1, xmm3, r2+r3 lea r0, [r0+2*r1] lea r2, [r2+2*r3] movdqa xmm2, [r0] movdqu xmm3, [r2] SSE2_Get4LW16Sad xmm0, xmm1, xmm2, xmm3, r2 movdqa xmm0, [r0+r1] movdqu xmm3, [r2+r3] SSE2_Get4LW16Sad xmm1, xmm2, xmm0, xmm3, r2+r3 lea r0, [r0+2*r1] lea r2, [r2+2*r3] movdqa xmm1, [r0] movdqu xmm3, [r2] SSE2_Get4LW16Sad xmm2, xmm0, xmm1, xmm3, r2 movdqa xmm2, [r0+r1] movdqu xmm3, [r2+r3] SSE2_Get4LW16Sad xmm0, xmm1, xmm2, xmm3, r2+r3 lea r0, [r0+2*r1] lea r2, [r2+2*r3] movdqa xmm0, [r0] movdqu xmm3, [r2] SSE2_Get4LW16Sad xmm1, xmm2, xmm0, xmm3, r2 movdqa xmm1, [r0+r1] movdqu xmm3, [r2+r3] SSE2_Get4LW16Sad xmm2, xmm0, xmm1, xmm3, r2+r3 lea r0, [r0+2*r1] lea r2, [r2+2*r3] movdqa xmm2, [r0] movdqu xmm3, [r2] SSE2_Get4LW16Sad xmm0, xmm1, xmm2, xmm3, r2 movdqa xmm0, [r0+r1] movdqu xmm3, [r2+r3] SSE2_Get4LW16Sad xmm1, xmm2, xmm0, xmm3, r2+r3 lea r2, [r2+2*r3] movdqu xmm3, [r2] psadbw xmm2, xmm3 paddw xmm5, xmm2 movdqu xmm2, [r2-1] psadbw xmm2, xmm0 paddw xmm6, xmm2 movdqu xmm3, [r2+1] psadbw xmm3, xmm0 paddw xmm7, xmm3 movdqu xmm3, [r2+r3] psadbw xmm0, xmm3 paddw xmm5, xmm0 movhlps xmm0, xmm4 paddw xmm4, xmm0 movhlps xmm0, xmm5 paddw xmm5, xmm0 movhlps xmm0, xmm6 paddw xmm6, xmm0 movhlps xmm0, xmm7 paddw xmm7, xmm0 punpckldq xmm4, xmm5 punpckldq xmm6, xmm7 punpcklqdq xmm4, xmm6 movdqa [r4],xmm4 POP_XMM LOAD_5_PARA_POP ret WELS_EXTERN WelsSampleSadFour16x8_sse2 %assign push_num 0 LOAD_5_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d pxor xmm4, xmm4 ;sad pRefMb-i_stride_ref pxor xmm5, xmm5 ;sad pRefMb+i_stride_ref pxor xmm6, xmm6 ;sad pRefMb-1 pxor xmm7, xmm7 ;sad pRefMb+1 movdqa xmm0, [r0] sub r2, r3 movdqu xmm3, [r2] psadbw xmm3, xmm0 paddw xmm4, xmm3 movdqa xmm1, [r0+r1] movdqu xmm3, [r2+r3] psadbw xmm3, xmm1 paddw xmm4, xmm3 movdqu xmm2, [r2+r3-1] psadbw xmm2, xmm0 paddw xmm6, xmm2 movdqu xmm3, [r2+r3+1] psadbw xmm3, xmm0 paddw xmm7, xmm3 lea r0, [r0+2*r1] lea r2, [r2+2*r3] movdqa xmm2, [r0] movdqu xmm3, [r2] SSE2_Get4LW16Sad xmm0, xmm1, xmm2, xmm3, r2 movdqa xmm0, [r0+r1] movdqu xmm3, [r2+r3] SSE2_Get4LW16Sad xmm1, xmm2, xmm0, xmm3, r2+r3 lea r0, [r0+2*r1] lea r2, [r2+2*r3] movdqa xmm1, [r0] movdqu xmm3, [r2] SSE2_Get4LW16Sad xmm2, xmm0, xmm1, xmm3, r2 movdqa xmm2, [r0+r1] movdqu xmm3, [r2+r3] SSE2_Get4LW16Sad xmm0, xmm1, xmm2, xmm3, r2+r3 lea r0, [r0+2*r1] lea r2, [r2+2*r3] movdqa xmm0, [r0] movdqu xmm3, [r2] SSE2_Get4LW16Sad xmm1, xmm2, xmm0, xmm3, r2 movdqa xmm1, [r0+r1] movdqu xmm3, [r2+r3] SSE2_Get4LW16Sad xmm2, xmm0, xmm1, xmm3, r2+r3 lea r2, [r2+2*r3] movdqu xmm3, [r2] psadbw xmm0, xmm3 paddw xmm5, xmm0 movdqu xmm0, [r2-1] psadbw xmm0, xmm1 paddw xmm6, xmm0 movdqu xmm3, [r2+1] psadbw xmm3, xmm1 paddw xmm7, xmm3 movdqu xmm3, [r2+r3] psadbw xmm1, xmm3 paddw xmm5, xmm1 movhlps xmm0, xmm4 paddw xmm4, xmm0 movhlps xmm0, xmm5 paddw xmm5, xmm0 movhlps xmm0, xmm6 paddw xmm6, xmm0 movhlps xmm0, xmm7 paddw xmm7, xmm0 punpckldq xmm4, xmm5 punpckldq xmm6, xmm7 punpcklqdq xmm4, xmm6 movdqa [r4],xmm4 POP_XMM LOAD_5_PARA_POP ret WELS_EXTERN WelsSampleSadFour8x16_sse2 %assign push_num 0 LOAD_5_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d pxor xmm4, xmm4 ;sad pRefMb-i_stride_ref pxor xmm5, xmm5 ;sad pRefMb+i_stride_ref pxor xmm6, xmm6 ;sad pRefMb-1 pxor xmm7, xmm7 ;sad pRefMb+1 movq xmm0, [r0] movhps xmm0, [r0+r1] sub r2, r3 movq xmm3, [r2] movhps xmm3, [r2+r3] psadbw xmm3, xmm0 paddw xmm4, xmm3 movq xmm1, [r2+r3-1] movq xmm3, [r2+r3+1] lea r0, [r0+2*r1] lea r2, [r2+2*r3] movhps xmm1, [r2-1] movhps xmm3, [r2+1] psadbw xmm1, xmm0 paddw xmm6, xmm1 psadbw xmm3, xmm0 paddw xmm7, xmm3 movq xmm3, [r2] movhps xmm3, [r2+r3] psadbw xmm0, xmm3 paddw xmm5, xmm0 movq xmm0, [r0] movhps xmm0, [r0+r1] psadbw xmm3, xmm0 paddw xmm4, xmm3 movq xmm1, [r2+r3-1] movq xmm3, [r2+r3+1] lea r0, [r0+2*r1] lea r2, [r2+2*r3] movhps xmm1, [r2-1] movhps xmm3, [r2+1] psadbw xmm1, xmm0 paddw xmm6, xmm1 psadbw xmm3, xmm0 paddw xmm7, xmm3 movq xmm3, [r2] movhps xmm3, [r2+r3] psadbw xmm0, xmm3 paddw xmm5, xmm0 movq xmm0, [r0] movhps xmm0, [r0+r1] psadbw xmm3, xmm0 paddw xmm4, xmm3 movq xmm1, [r2+r3-1] movq xmm3, [r2+r3+1] lea r0, [r0+2*r1] lea r2, [r2+2*r3] movhps xmm1, [r2-1] movhps xmm3, [r2+1] psadbw xmm1, xmm0 paddw xmm6, xmm1 psadbw xmm3, xmm0 paddw xmm7, xmm3 movq xmm3, [r2] movhps xmm3, [r2+r3] psadbw xmm0, xmm3 paddw xmm5, xmm0 movq xmm0, [r0] movhps xmm0, [r0+r1] psadbw xmm3, xmm0 paddw xmm4, xmm3 movq xmm1, [r2+r3-1] movq xmm3, [r2+r3+1] lea r0, [r0+2*r1] lea r2, [r2+2*r3] movhps xmm1, [r2-1] movhps xmm3, [r2+1] psadbw xmm1, xmm0 paddw xmm6, xmm1 psadbw xmm3, xmm0 paddw xmm7, xmm3 movq xmm3, [r2] movhps xmm3, [r2+r3] psadbw xmm0, xmm3 paddw xmm5, xmm0 movq xmm0, [r0] movhps xmm0, [r0+r1] psadbw xmm3, xmm0 paddw xmm4, xmm3 movq xmm1, [r2+r3-1] movq xmm3, [r2+r3+1] lea r0, [r0+2*r1] lea r2, [r2+2*r3] movhps xmm1, [r2-1] movhps xmm3, [r2+1] psadbw xmm1, xmm0 paddw xmm6, xmm1 psadbw xmm3, xmm0 paddw xmm7, xmm3 movq xmm3, [r2] movhps xmm3, [r2+r3] psadbw xmm0, xmm3 paddw xmm5, xmm0 movq xmm0, [r0] movhps xmm0, [r0+r1] psadbw xmm3, xmm0 paddw xmm4, xmm3 movq xmm1, [r2+r3-1] movq xmm3, [r2+r3+1] lea r0, [r0+2*r1] lea r2, [r2+2*r3] movhps xmm1, [r2-1] movhps xmm3, [r2+1] psadbw xmm1, xmm0 paddw xmm6, xmm1 psadbw xmm3, xmm0 paddw xmm7, xmm3 movq xmm3, [r2] movhps xmm3, [r2+r3] psadbw xmm0, xmm3 paddw xmm5, xmm0 movq xmm0, [r0] movhps xmm0, [r0+r1] psadbw xmm3, xmm0 paddw xmm4, xmm3 movq xmm1, [r2+r3-1] movq xmm3, [r2+r3+1] lea r0, [r0+2*r1] lea r2, [r2+2*r3] movhps xmm1, [r2-1] movhps xmm3, [r2+1] psadbw xmm1, xmm0 paddw xmm6, xmm1 psadbw xmm3, xmm0 paddw xmm7, xmm3 movq xmm3, [r2] movhps xmm3, [r2+r3] psadbw xmm0, xmm3 paddw xmm5, xmm0 movq xmm0, [r0] movhps xmm0, [r0+r1] psadbw xmm3, xmm0 paddw xmm4, xmm3 movq xmm1, [r2+r3-1] movq xmm3, [r2+r3+1] lea r0, [r0+2*r1] lea r2, [r2+2*r3] movhps xmm1, [r2-1] movhps xmm3, [r2+1] psadbw xmm1, xmm0 paddw xmm6, xmm1 psadbw xmm3, xmm0 paddw xmm7, xmm3 movq xmm3, [r2] movhps xmm3, [r2+r3] psadbw xmm0, xmm3 paddw xmm5, xmm0 movhlps xmm0, xmm4 paddw xmm4, xmm0 movhlps xmm0, xmm5 paddw xmm5, xmm0 movhlps xmm0, xmm6 paddw xmm6, xmm0 movhlps xmm0, xmm7 paddw xmm7, xmm0 punpckldq xmm4, xmm5 punpckldq xmm6, xmm7 punpcklqdq xmm4, xmm6 movdqa [r4],xmm4 POP_XMM LOAD_5_PARA_POP ret WELS_EXTERN WelsSampleSadFour8x8_sse2 %assign push_num 0 LOAD_5_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d pxor xmm4, xmm4 ;sad pRefMb-i_stride_ref pxor xmm5, xmm5 ;sad pRefMb+i_stride_ref pxor xmm6, xmm6 ;sad pRefMb-1 pxor xmm7, xmm7 ;sad pRefMb+1 movq xmm0, [r0] movhps xmm0, [r0+r1] sub r2, r3 movq xmm3, [r2] movhps xmm3, [r2+r3] psadbw xmm3, xmm0 paddw xmm4, xmm3 movq xmm1, [r2+r3-1] movq xmm3, [r2+r3+1] lea r0, [r0+2*r1] lea r2, [r2+2*r3] movhps xmm1, [r2-1] movhps xmm3, [r2+1] psadbw xmm1, xmm0 paddw xmm6, xmm1 psadbw xmm3, xmm0 paddw xmm7, xmm3 movq xmm3, [r2] movhps xmm3, [r2+r3] psadbw xmm0, xmm3 paddw xmm5, xmm0 movq xmm0, [r0] movhps xmm0, [r0+r1] psadbw xmm3, xmm0 paddw xmm4, xmm3 movq xmm1, [r2+r3-1] movq xmm3, [r2+r3+1] lea r0, [r0+2*r1] lea r2, [r2+2*r3] movhps xmm1, [r2-1] movhps xmm3, [r2+1] psadbw xmm1, xmm0 paddw xmm6, xmm1 psadbw xmm3, xmm0 paddw xmm7, xmm3 movq xmm3, [r2] movhps xmm3, [r2+r3] psadbw xmm0, xmm3 paddw xmm5, xmm0 movq xmm0, [r0] movhps xmm0, [r0+r1] psadbw xmm3, xmm0 paddw xmm4, xmm3 movq xmm1, [r2+r3-1] movq xmm3, [r2+r3+1] lea r0, [r0+2*r1] lea r2, [r2+2*r3] movhps xmm1, [r2-1] movhps xmm3, [r2+1] psadbw xmm1, xmm0 paddw xmm6, xmm1 psadbw xmm3, xmm0 paddw xmm7, xmm3 movq xmm3, [r2] movhps xmm3, [r2+r3] psadbw xmm0, xmm3 paddw xmm5, xmm0 movq xmm0, [r0] movhps xmm0, [r0+r1] psadbw xmm3, xmm0 paddw xmm4, xmm3 movq xmm1, [r2+r3-1] movq xmm3, [r2+r3+1] lea r0, [r0+2*r1] lea r2, [r2+2*r3] movhps xmm1, [r2-1] movhps xmm3, [r2+1] psadbw xmm1, xmm0 paddw xmm6, xmm1 psadbw xmm3, xmm0 paddw xmm7, xmm3 movq xmm3, [r2] movhps xmm3, [r2+r3] psadbw xmm0, xmm3 paddw xmm5, xmm0 movhlps xmm0, xmm4 paddw xmm4, xmm0 movhlps xmm0, xmm5 paddw xmm5, xmm0 movhlps xmm0, xmm6 paddw xmm6, xmm0 movhlps xmm0, xmm7 paddw xmm7, xmm0 punpckldq xmm4, xmm5 punpckldq xmm6, xmm7 punpcklqdq xmm4, xmm6 movdqa [r4],xmm4 POP_XMM LOAD_5_PARA_POP ret WELS_EXTERN WelsSampleSadFour4x4_sse2 %assign push_num 0 LOAD_5_PARA PUSH_XMM 8 SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d movd xmm0, [r0] movd xmm1, [r0+r1] lea r0, [r0+2*r1] movd xmm2, [r0] movd xmm3, [r0+r1] punpckldq xmm0, xmm1 punpckldq xmm2, xmm3 punpcklqdq xmm0, xmm2 sub r2, r3 movd xmm1, [r2] movd xmm2, [r2+r3] punpckldq xmm1, xmm2 movd xmm2, [r2+r3-1] movd xmm3, [r2+r3+1] lea r2, [r2+2*r3] movd xmm4, [r2] movd xmm5, [r2-1] punpckldq xmm2, xmm5 movd xmm5, [r2+1] punpckldq xmm3, xmm5 movd xmm5, [r2+r3] punpckldq xmm4, xmm5 punpcklqdq xmm1, xmm4 ;-L movd xmm5, [r2+r3-1] movd xmm6, [r2+r3+1] lea r2, [r2+2*r3] movd xmm7, [r2-1] punpckldq xmm5, xmm7 punpcklqdq xmm2, xmm5 ;-1 movd xmm7, [r2+1] punpckldq xmm6, xmm7 punpcklqdq xmm3, xmm6 ;+1 movd xmm6, [r2] movd xmm7, [r2+r3] punpckldq xmm6, xmm7 punpcklqdq xmm4, xmm6 ;+L psadbw xmm1, xmm0 psadbw xmm2, xmm0 psadbw xmm3, xmm0 psadbw xmm4, xmm0 movhlps xmm0, xmm1 paddw xmm1, xmm0 movhlps xmm0, xmm2 paddw xmm2, xmm0 movhlps xmm0, xmm3 paddw xmm3, xmm0 movhlps xmm0, xmm4 paddw xmm4, xmm0 punpckldq xmm1, xmm4 punpckldq xmm2, xmm3 punpcklqdq xmm1, xmm2 movdqa [r4],xmm1 POP_XMM LOAD_5_PARA_POP ret ;*********************************************************************** ; ;Pixel_sad_4_wxh_sse2 END ; ;*********************************************************************** ;*********************************************************************** ; int32_t WelsSampleSad4x4_mmx (uint8_t *, int32_t, uint8_t *, int32_t ) ;*********************************************************************** WELS_EXTERN WelsSampleSad4x4_mmx %assign push_num 0 LOAD_4_PARA SIGN_EXTENSION r1, r1d SIGN_EXTENSION r3, r3d movd mm0, [r0] movd mm1, [r0+r1] punpckldq mm0, mm1 movd mm3, [r2] movd mm4, [r2+r3] punpckldq mm3, mm4 psadbw mm0, mm3 lea r0, [r0+2*r1] lea r2, [r2+2*r3] movd mm1, [r0] movd mm2, [r0+r1] punpckldq mm1, mm2 movd mm3, [r2] movd mm4, [r2+r3] punpckldq mm3, mm4 psadbw mm1, mm3 paddw mm0, mm1 movd retrd, mm0 WELSEMMS LOAD_4_PARA_POP ret
; Rectangle, Intervals and Points ; 05.2006 aralbrec PUBLIC r_IsPtInIval16 EXTERN RIsPtInIval16 ; int r_IsPtInIval16(uint x, struct r_Ival16 *i) .r_IsPtInIval16 ld hl,2 add hl,sp ld e,(hl) inc hl ld d,(hl) inc hl push hl ex de,hl ld c,(hl) inc hl ld b,(hl) inc hl ld e,(hl) inc hl ld d,(hl) pop hl ld a,(hl) inc hl ld h,(hl) ld l,a call RIsPtInIval16 ld hl,0 ret nc inc l ret
; A070401: a(n) = 6^n mod 47. ; 1,6,36,28,27,21,32,4,24,3,18,14,37,34,16,2,12,25,9,7,42,17,8,1,6,36,28,27,21,32,4,24,3,18,14,37,34,16,2,12,25,9,7,42,17,8,1,6,36,28,27,21,32,4,24,3,18,14,37,34,16,2,12,25,9,7,42,17,8,1,6,36,28,27,21,32,4,24,3,18,14,37,34,16,2,12,25,9,7,42,17,8,1,6,36,28,27,21,32,4,24,3,18,14,37,34,16,2,12,25,9,7,42,17,8,1,6,36,28,27,21,32,4,24,3,18,14,37,34,16,2,12,25,9,7,42,17,8,1,6,36,28,27,21,32,4,24,3,18,14,37,34,16,2,12,25,9,7,42,17,8,1,6,36,28,27,21,32,4,24,3,18,14,37,34,16,2,12,25,9,7,42,17,8,1,6,36,28,27,21,32,4,24,3,18,14,37,34,16,2,12,25,9,7,42,17,8,1,6,36,28,27,21,32,4,24,3,18,14,37,34,16,2,12,25,9,7,42,17,8,1,6,36,28,27,21,32,4,24,3,18,14,37,34,16,2,12,25,9,7 mov $1,1 mov $2,$0 lpb $2 mul $1,6 mod $1,47 sub $2,1 lpe
org 0x100 cpu 8086 jmp loader newInt10: cmp ax,0x13 jne notMode13 pushf call far[cs:oldInt10] mov dx,0x03d4 mov ax,0x0100 out dx,ax ; Reset sequencer mov ax,0x0901 out dx,ax ; Set double pixel width mov dl,0xc2 mov al,0x27 out dx,al ; Set 28.322 MHz clock, polarity for 200 lines mov dl,0xc4 mov ax,0x0300 out dx,ax ; Unreset sequencer mov dl,0xd4 mov ax,0x0e11 out dx,ax ; Unprotect CRTC registers mov ax,0x6b00 out dx,ax ; Horizontal Total = character 112 mov ax,0x4f01 out dx,ax ; Horizontal Display Enable End = character 80 mov ax,0x5002 out dx,ax ; Start Horizontal Blanking = character 81 mov ax,0x8e03 out dx,ax ; End Horizontal Blanking = character 110 mov ax,0x5e04 out dx,ax ; Start Horizontal Retrace = character 94 mov ax,0x8605 out dx,ax ; End Horizontal Retrace = character 102 mov ax,0x0506 out dx,ax ; Vertical total = scanline 262 mov ax,0x0107 out dx,ax ; Overflows all 0 except Vertical Total mov ax,0x4009 out dx,ax ; 1 scanline per vertical pixel mov ax,0xe010 out dx,ax ; Vertical Retrace Start = scanline 224 mov ax,0x8311 out dx,ax ; Vertical Retrace End = scanline 227, CRTC protected mov ax,0xc712 out dx,ax ; Vertical Display Enable End = scanline 200 mov ax,0xcb15 out dx,ax ; Start Vertical Blanking = scanline 203 mov ax,0x0216 out dx,ax ; End Vertical Blanking = scanline 258 iret notMode13: jmp far[cs:oldInt10] oldInt10: dw 0, 0 loader: xor ax,ax mov ds,ax cli mov bx,[0x10*4] mov [cs:oldInt10],bx mov word[0x10*4],newInt10 mov ax,word[0x10*4+2] mov word[cs:oldInt10+2],ax mov [0x10*4+2],cs sti mov dx,loader add dx,0x0f mov cx,4 shr dx,cl mov ax,0x3100 int 0x21
; A276886: Sums-complement of the Beatty sequence for 2 + phi. ; 1,2,5,6,9,12,13,16,17,20,23,24,27,30,31,34,35,38,41,42,45,46,49,52,53,56,59,60,63,64,67,70,71,74,77,78,81,82,85,88,89,92,93,96,99,100,103,106,107,110,111,114,117,118,121,122,125,128,129,132,135,136 mov $1,$0 pow $0,2 mov $2,$0 lpb $2 sub $2,1 sub $2,$1 add $1,2 lpe mov $0,$1 add $0,1
; A002004: Davenport-Schinzel numbers of degree 4 on n symbols. ; 1,4,8,12,17,22,27,32,37,42,47,53,58,64,69,75,81,86,92,98,104 mov $2,1 mov $4,$0 add $0,8 add $4,1 add $2,$4 mov $1,$2 mul $1,2 mov $3,120 mul $4,2 pow $4,2 div $4,$0 add $3,$4 add $1,$3 mul $1,5 sub $1,620 div $1,5 add $1,1 mov $0,$1
;* ;* keymon5.asm : OS/2 keyboard monitor ;***************************************************************************** SetBxInkb MACRO ;* address inkb struct with bx mov bx,[di].pinkbCur ;* assume [di] == rgwKbdData ENDM SetBxInos MACRO ;* address inosDrv struct with bx mov bx,pinos ENDM PushFld MACRO fld ;* assume [di] == structure push [di+fld] ;* [di].fld won't replace fld!! ENDM Os2Call MACRO ofn ;* Call through link table call [bx+lpfn&ofn&Inos] ENDM ;* Special call-back if in thread (DS:0 => KTHD) ThreadCall MACRO ofn ;* Call through link table mov es,ds:[selAppKthd] mov bx,pinos ;* load BX from code segment call es:[bx+lpfn&ofn&Inos] ENDM ;***************************************************************************** ;********** EnableKeyboardKbd ********** ;* entry: pinkb => INKB data ;* fEnable => whether to enable or disable ;* fExiting => exiting if !fEnable ;* * enable or disable the keyboard handler ;* exit : n/a cProc EnableKeyboardKbd,<ATOMIC>,<DI> parmDP pinkb parmW fEnable parmW fExiting cBegin EnableKeyboardKbd ;* * save pointer to INKB data mov di,OFF_lpwDataKbd ;* Data in data segment mov bx,pinkb mov [di].pinkbCur,bx mov bx,drvOffset Disable mov cx,fEnable jcxz do_it mov bx,drvOffset Enable do_it: call bx ;* call Enable or Disable cEnd EnableKeyboardKbd ;***************************************************************************** ;********** Disable ********** ;* entry: DS:DI => driver data ;* * since OS/2 will not kill buffers properly, we turn the keyboard ;* * monitor into a literal copy monitor when disabled ;* exit: n/a cProc Disable,<NEAR, PUBLIC> cBegin Disable AssertEQ di,OFF_lpwDataKbd xor ax,ax mov [di].fEnabled,al ;* disable -> get old status mov [di].fEnableMonitor,al ;* disable monitor -- keep running cEnd Disable ;***************************************************************************** ;********** Enable ********** ;* entry: DS:DI => driver data ;* * opens a new keyboard monitor and creates a thread to manage ;* this monitor. ;* exit: n/a szKbd db 'KBD$',0 ; device string name (Keyboard) cProc Enable,<NEAR, PUBLIC> localW wFiller cBegin Enable AssertEQ di,OFF_lpwDataKbd SetBxInos ; prepare for indirect call cmp [di].fEnabled,0 je @F ;* enable it jmp enable_done @@: ;* * if we have started the monitor then skip cmp [di].selKthd,0 je @F jmp enable_ok ;* already have thread @@: ;* * One-shot initialization follows ;* * OPEN Keyboard device PushArg <cs,drvOffset(szKbd)> lea ax,[di].hDevice PushArg <ds,ax> lea ax,wFiller PushArg <ss,ax> xor ax,ax PushArg <ax,ax> ; filesize (zero) PushArg <ax> ; file attribute (zero) push 1 ; open flag (open existing file) push 0000000011000000b ; open mode ; DWFRRRRRISSSRAAA (private, deny none, read only) PushArg <ax,ax> ; reserved Os2Call DosOpen or ax,ax jnz init_error2 ;* * Open Keyboard monitor PushArg <cs, drvOffset(szKbd)> lea ax,[di].hMonitor PushArg <ds,ax> Os2Call DosMonOpen or ax,ax jnz init_error2 ;* * allocate KTHD segment lea ax,[di].selKthd ;* segment selector PushArg <(size KTHD), ds, ax, 0> Os2Call DosAllocSeg or ax,ax jnz init_error2 @@: mov es,[di].selKthd ;* * Register monitor PushFld hMonitor mov ax,offset rgbBufferInKthd PushArg <es, ax> cCall InitBuffer, <ax> mov ax,offset rgbBufferOutKthd PushArg <es, ax> cCall InitBuffer, <ax> PushArg <2> ; Posflag (back) PushArg <-1> ; index = -1 (current group) Os2Call DosMonReg or ax,ax init_error2: jnz init_error ;* * create keyboard thread, ES:0 => KTHD PushArg <cs, drvOffset(KbdThread)> lea ax,[di].idThread PushArg <ds,ax> mov es:[selAppKthd],ss ;* point to main App stack PushArg <es, (rgbStackKthd + cbStack - 10H)> ;* leave space before end of segment Os2Call DosCreateThread or ax,ax jnz init_error ;* * bump priority of thread PushArg <2> ; scope = 2 (thread) PushArg <3> ; class = 3 (time-critical) PushArg <15> ; delta = 15(???) PushFld idThread Os2Call DosSetPrty or ax,ax jnz init_error ;* * set for keyboard type (no problem in assuming enhanced) mov [di].pmpscvwPlain,drvOffset mpscvwPlainRonco mov [di].pmpscvwShift,drvOffset mpscvwShiftRonco enable_ok: ;* ok to enable mov [di].fEnabled,1 ;* we are now enabled mov [di].fEnableMonitor,1 ;* enable monitor jmp short enable_done init_error: PushArg <1, 08001H> Os2Call DosExit ;* exit, kill process (return 0x8001). ;* * can't accept input => we're screwed mov [di].fEnabled,0 enable_done: cEnd Enable ;********** InitBuffer ********** ;* entry: ES => segment containing monitor buffer ;* pbBuff = near pointer to start of monitor buffer ;* * Initialize monitor buffer ;* exit: n/a (ES retained) cProc InitBuffer, <NEAR, ATOMIC>, <DI> parmW pbBuff cBegin InitBuffer mov di,pbBuff mov ax,cbBuffer stosw ;* set length of buffer ;* * OS/2 1.0 has a problem registering non-zero initialized buffers mov cx,(cbBuffer - 2)/2 xor ax,ax rep stosw cEnd InitBuffer ;***************************************************************************** ;* KbdThread - Keyboard monitor thread ;* * literal monitor mode (propagate key -- leave it alone) literal_monitor: call XmitKey jmp short ThreadMain PUBLIC KbdThread KbdThread PROC FAR push ss pop ds xor di,di ;* DS:DI => KTHD ThreadMain: mov [di].cbMonKthd,SIZE KBRD ;* * read record from monitor PushArg <ds,offset(rgbBufferInKthd)> push 0 ; WaitFlag=0 (wait) PushArg <ds,offset(kbrdKthd)> PushArg <ds,offset(cbMonKthd)> ThreadCall DosMonRead ;* this may put us to sleep or ax,ax je @F jmp Close @@: mov es,ds:[selAppKthd] mov bx,OFF_lpwDataKbd ;* * see if in we are closing cmp es:[bx].fEnableMonitor,0 ;* monitor enabled ? je literal_monitor cmp es:[bx].fEnabled,0 je literal_monitor ;* keyboard is disabled lea si,[di].kbrdKthd mov ax,[si].MonFlags test ax,fOpen OR fFlush OR fClose jnz noDefault ;* * a normal event, process it mov ax,[si].KbdFlags and al,mAction jz TakeNormalKey cmp al,7 ;* shift ?? je TakeShiftKey cmp al,12H ;* pseudo-break (CTRL-C) ? jz TakeNormalKey ;* just like control C cmp al,2 ;* extend alone ? je ThreadMain ;* eat it cmp al,9 ;* CTRL-S ? je TakeNormalKey ;* treat like normal cmp al,15H ;* CTRL-P ? je TakeNormalKey ;* treat like normal cmp al,0AH ;* wake-up? je ThreadMain ;* eat it cmp al,011H ;* Break? je ThreadMain ;* eat it cmp al,3fH ;* not-translated jne xmit_key ;* * take a shot at translating ALT key test [si].ssKbrd,SS_ALT ;* ALT down jz TakeNormalKey cmp [si].XlatedScan,1 ;* ALT-ESC ? jne TakeNormalKey ;* try if not ALT-ESC ;* * transmit all other keys xmit_key: call XmitKey jmp short ThreadMain2 TakeShiftKey: mov word ptr [si].XlatedChar,0 ;* set no character (just to be sure) TakeNormalKey: call TakeKey jmp short ThreadMain2 noDefault: test ax,fOpen jz noOpen jmp short ThreadMain2 ; do nothing if Open noOpen: test ax,fFlush jz Close ; can be nothing except close call XmitKey ; Xmit Flush to next monitor (if any) ;* * end after flushing (since we do not get a close packet). or ax,ax jne Close ThreadMain2: jmp ThreadMain ;* * Die Close: xor ax,ax PushArg <ax,ax> ThreadCall DosExit ;* exit, return 0, kill just this thread KbdThread ENDP ;***************************************************************************** ; XmitKey - Transmit monitor record to next XmitKey proc near PushArg <ds,offset(rgbBufferOutKthd)> PushArg <ds,offset(kbrdKthd)> PushArg [di].cbMonKthd ThreadCall DosMonWrite ret XmitKey endp ;***************************************************************************** ;********** TakeKey ********** ;* entry: DS:SI => keyboard monitor record ;* DS:0 => KTHD ;* * translate and send scan code to event proc ;* * (don't transmit to next monitor) cProc TakeKey, <NEAR, ATOMIC>, <DS, DI, SI> cBegin TakeKey mov es, ds:[selAppKthd] mov di,OFF_lpwDataKbd ;* * load up registers for call to XlateKey Assert <XlatedScan EQ XlatedChar+1> mov ax,word ptr [si].XlatedChar mov dx,[si].ssKbrd or al, al ;* some scan codes need to be jnz no_convert ;* converted for DOS3 compatibility or ah, ah ;* (only check key events) jz no_convert test dl, SS_CONTROL OR SS_ALT jz no_convert cmp ah, SC_1 jb no_convert cmp ah, SC_9 ja no_cvt1_9 mov al, ah add al, '1' - SC_1 jmp short no_convert no_cvt1_9: mov al, '0' cmp ah, SC_0 je cvt_char mov al, '=' cmp ah, SC_EQUALS je cvt_char mov al, ',' cmp ah, SC_COMMA je cvt_char mov al, '.' cmp ah, SC_PERIOD je cvt_char mov al, '-' cmp ah, SC_SUBTRACT ;* Alt SUBTRACT je cvt_char mov ch, SC_SUBTRACT cmp ah, 8Eh ;* Ctrl SUBTRACT je cvt_scan mov al, '+' cmp ah, SC_ADD ;* Alt ADD je cvt_char mov ch, SC_ADD cmp ah, 90h ;* Ctrl ADD je cvt_scan cmp ah, SC_ADD ;* Alt ADD je cvt_scan mov al, 9 mov ch, SC_TAB cmp ah, 94h ;* Ctrl TAB je cvt_scan xor al, al jmp short no_convert cvt_scan: mov ah, ch cvt_char: no_convert: and dx,NOT SS_EXTENDED ;* fix left Alt key or dx,SS_SPACE ;* assume on test [si].KbdFlags,fBreak ;* break ? push es ;* (switch to data seg) pop ds jnz take_keyup ;* Fast key repeat mov si, [di].pinkbCur mov [si].fKeyIsUpInkb, 0 cmp ax, word ptr es:[di].chPrev ;* wait until 2nd same key jne take_keydown mov cx, [si].wRateKeyRepeatInkb or cx, cx jle take_keydown ;* default, don't mess w/ it shl cx, 1 ;* to emulate DOS3 timer add [di].ckeyRepeat, cx ;* add a bunch of repeats mov [di].ssPrev, dx ;* keep SS's up-to-date take_repeat: cCall [si].lpfnFTestKeyboardEmptyInkb or ax, ax jnz @F mov [di].ckeyRepeat, ax ;0 ;* minimize overruns jmp short take_done @@: mov ax, word ptr [di].chPrev mov dx, [di].ssPrev cCall XlateKey dec [di].ckeyRepeat jnz take_repeat jmp short take_done take_keyup: ;* * for key up, just update shift states mov [di].ckeyRepeat, 0 ;* cancel pending repeats mov si, [di].pinkbCur mov [si].fKeyIsUpInkb, 1 mov [si].fKeyWasUpInkb, 1 cmp al,' ' jne not_space_up and dx,NOT SS_SPACE ;* generate space up not_space_up: xor ax,ax ;* no key take_keydown: mov word ptr [di].chPrev, ax ;* save prev ch and sc mov [di].ssPrev, dx cCall XlateKey take_done: cEnd TakeKey ;***************************************************************************** ;* Key flush NonStandard FlushKeyRgchKbd ;********** FlushKeyRgchKbd ********** ;* * KBD entry point (see documentation for interface) ;* * send keys to next monitors ;* * the keyboard monitor is assumed to be still alive cProc FlushKeyRgchKbd, <FAR, PUBLIC, ATOMIC>, <SI, DI> parmDP rgchBuffer cBegin FlushKeyRgchKbd mov di,OFF_lpwDataKbd ;* Data in data segment SetBxInos ; prepare for indirect call mov cx,[di].selKthd jcxz end_flush ;* no extra segment mov es,cx ;* * Flush the CW event queue buffer mov si,rgchBuffer loop_flush_1: lodsb or al,al jz done_flush_1 ;* * put that 1 character into the keyboard monitor mov dl,al ;* character mov es,[di].selKthd mov bx,offset kbrdKthd ;* es:bx => KBRD ;* * clear the KBRD record push di mov di,bx xor ax,ax mov cx,size KBRD / 2 rep stosw pop di ;* * set character (other fields 0) mov es:[bx].XlatedChar,dl ;* * write the buffer PushArg <es,offset(rgbBufferOutKthd)> PushArg <es,bx> PushArg es:[cbMonKthd] SetBxInos ; prepare for indirect call Os2Call DosMonWrite or ax,ax jz loop_flush_1 ;* go while no error int 3 ;* write error ! done_flush_1: end_flush: cEnd FlushKeyRgchKbd ;************************************************************************** ;* Set shift states NonStandard SetShiftKkKbd ;*********** SetShiftKkKbd ************* ;* * KBD entry point ;* * set the actual shift states given a KK ; cProc SetShiftKkKbd, <FAR, PUBLIC, ATOMIC>, <SI, DI> parmW kkParm Assert <(size KBST) EQ 10> localT kbstTmp cBegin SetShiftKkKbd mov di, OFF_lpwDataKbd SetBxInos ;* get the current keyboard status lea si, (kbstTmp) mov ss:[si].cbKbst, (size KBST) PushArg <ss, si> push 0 ;* system keyboard handle Os2Call KbdGetStatus ;* set the we're-gonna-change-shift-states flag mov ax, ss:[si].fsMask or ax, 10h mov ss:[si].fsMask, ax ;* translate new KK to SS mov ax, (kkParm) and ah, SS_CAPLOCK or SS_NUMLOCK or SS_SCRLOCK or SS_ALT or SS_CONTROL or SS_LSHIFT mov byte ptr ss:[si].fsState, ah ;* reset the keyboard status to new shift state PushArg <ss, si> push 0 ;* system keyboard handle Os2Call KbdSetStatus mov ax, ss:[si].fsState cCall DoShift, <ax> cEnd SetShiftKkKbd ;**************************************************************************
; long __FASTCALL__ atol(char *s) ; 12.2006 aralbrec XLIB atol LIB l_long_neg, asm_isspace ; FASTCALL ; enter : hl = char* ; exit : dehl = long result ; bc = & next char to interpret in char* .atol ld a,(hl) ; eat whitespace inc hl call asm_isspace jr z, atol ; ate up one too many chars, see if it's a sign cp '+' jr z, signdone dec hl cp '-' jr nz, signdone inc hl ; this is a negative number call signdone ; do atol but come back here to negate result jp l_long_neg ; dehl = -dehl .signdone ld b,h ld c,l ld de,0 ld l,e ld h,d ; bc = char * ; dehl = result dec bc .loop inc bc ld a,(bc) sub '0' ; inlined isdigit ret c cp 10 ret nc ; dehl *= 10 add hl,hl ex de,hl adc hl,hl ex de,hl push de push hl ; save dehl*2 add hl,hl ex de,hl adc hl,hl ex de,hl add hl,hl ex de,hl adc hl,hl ; long is hlde ex (sp),hl add hl,de pop de ex (sp),hl adc hl,de ex de,hl pop hl add a,l ld l,a jp nc, loop inc h jp nz, loop inc de jp loop
//+------------------------------------------------------------------------ // // Microsoft Forms // Copyright (C) Microsoft Corporation, 1992 - 1995. // // File: encode.cxx // // Contents: Support for HTML character set encoding // //------------------------------------------------------------------------- #include "headers.hxx" #pragma MARK_DATA(__FILE__) #pragma MARK_CODE(__FILE__) #pragma MARK_CONST(__FILE__) #ifndef X_ENCODE_HXX_ #define X_ENCODE_HXX_ #include "encode.hxx" #endif #ifndef X_INTL_HXX_ #define X_INTL_HXX_ #include "intl.hxx" #endif #ifdef WIN16 #define MB_PRECOMPOSED 0 #define MB_ERR_INVALID_CHARS 0 #endif DeclareTag(tagEncGeneral, "Enc", "Encode: General"); DeclareTag(tagEncAlwaysUseMlang, "Enc", "Encode: Always Use Mlang"); MtDefine(CEncodeReader, Utilities, "CEncodeReader") MtDefine(CEncodeReaderPbBuf, CEncodeReader, "CEncodeReader::_pbBuffer") MtDefine(CEncodeWriter, Utilities, "CEncodeWriter") MtDefine(CEncodeWriterPbBuf, CEncodeWriter, "CEncodeWriter::_pbBuffer") MtDefine(CEncodeWriterPchBuf, CEncodeWriter, "CEncodeWriter::_pchBuffer") MtDefine(CToUnicodeConverterPchBuf, Utilities, "CToUnicodeConverter") struct ENCODINGREADFUNC { CODEPAGE cp; DECLARE_ENCODING_FUNCTION( (CEncodeReader::*pfnWCFromMB) ); }; struct ENCODINGWRITEFUNC { CODEPAGE cp; DECLARE_ENCODING_FUNCTION( (CEncodeWriter::*pfnMBFromWC) ); }; BOOL IsSameEncoding(CODEPAGE cp1, CODEPAGE cp2) { if (cp1 == cp2) return TRUE; // For now, all encodings are different except for windows-1252 and ISO-8859 if (cp1 == CP_1252 && cp2 == CP_ISO_8859_1 || cp1 == CP_ISO_8859_1 && cp2 == CP_1252) return TRUE; return FALSE; } CEncode::CEncode( size_t nBlockSize ) { _cp = CP_UNDEFINED; _nBlockSize = nBlockSize; _dwState = 0UL; } CEncode::~CEncode() { } CEncodeReader::CEncodeReader( CODEPAGE cp, size_t nBlockSize ) : CEncode( nBlockSize ) { _fCheckedForUnicode = FALSE; _fDiscardUtf7BOM = FALSE; _fDetectionFailed = FALSE; _cbScanStart = 0; _pfnWideCharFromMultiByte = NULL; _pchBuffer = NULL; _pbBuffer = NULL; SwitchCodePage( cp, NULL ); // sets _pfnWideCharFromMultiByte } CEncodeReader::~CEncodeReader() { if (_pchBuffer) { MemFree(_pchBuffer); _pchBuffer = NULL; } if (_pbBuffer) { MemFree(_pbBuffer); _pbBuffer = NULL; } } BOOL CEncodeReader::Exhausted() { // If we're left with a only few DBCS orphan characters at the end, // consider ourselves exhausted. The orphan characters will come // back to life in the next iteration of CEncodeReader::PrepareForRead(). // Note that if we're in autodetect mode, we can have _cbScanStart != 0. // What this means is that we've scanned that many bytes without being // able determine the encoding. We leave _pbBufferPtr as is because // that's where we need to start converting, but there's no point in // rescanning from there when we read more bytes. We start scanning from // _cbScanStart bytes in to _pbBufferPtr. return _pbBuffer && (_cbBuffer - ( _pbBufferPtr + _cbScanStart - _pbBuffer ) < ENCODE_DBCS_THRESHOLD); } BOOL CEncodeReader::ForceSwitchCodePage( CODEPAGE cp, BOOL *pfDifferentEncoding ) { BOOL fSwitched = FALSE; fSwitched = CEncodeReader::SwitchCodePage(cp, pfDifferentEncoding); // see if we wanted to switch but failed if (cp != _cp && !fSwitched) { // check to see if the codepage can be jit-in if (S_OK == THR(mlang().IsCodePageInstallable(cp))) { fSwitched = TRUE; if (pfDifferentEncoding) { *pfDifferentEncoding = !IsSameEncoding(cp, _cp); } _cp = cp; } } return fSwitched; } BOOL CEncodeReader::SwitchCodePage( CODEPAGE cp, BOOL *pfDifferentEncoding, BOOL fNeedRestart) { BOOL fSuccess = FALSE, fSwitched; static const struct ENCODINGREADFUNC aEncodingFuncs[] = { { CP_1252, &CEncodeReader::WideCharFromMultiByteGeneric }, { CP_ISO_8859_1, &CEncodeReader::WideCharFromMultiByteGeneric }, #ifndef WINCE { CP_UTF_8, &CEncodeReader::WideCharFromUtf8 }, #endif // WINCE { CP_UCS_2, &CEncodeReader::WideCharFromUcs2 }, { CP_1250, &CEncodeReader::WideCharFromMultiByteGeneric }, { CP_1251, &CEncodeReader::WideCharFromMultiByteGeneric }, { CP_1253, &CEncodeReader::WideCharFromMultiByteGeneric }, { CP_1254, &CEncodeReader::WideCharFromMultiByteGeneric }, { CP_1257, &CEncodeReader::WideCharFromMultiByteGeneric }, }; const struct ENCODINGREADFUNC * p = aEncodingFuncs; const struct ENCODINGREADFUNC * pStop = aEncodingFuncs + ARRAY_SIZE( aEncodingFuncs ); // Nothing has changed, quickly bail. if (cp == _cp && _pfnWideCharFromMultiByte) goto Cleanup; Assert(cp != CP_ACP); #if DBG == 1 if (!IsTagEnabled(tagEncAlwaysUseMlang)) { #endif // See if we can handle this codepage natively. for (;p < pStop;p++) { if (cp == p->cp) break; } if (p < pStop) { // Check to see if we can go from the native codepage to Unicode. fSuccess = IsStraightToUnicodeCodePage(cp); if (!fSuccess) { UINT uCP = WindowsCodePageFromCodePage( cp ); CPINFO cpinfo; fSuccess = GetCPInfo( uCP, &cpinfo ); if (fSuccess) { _uMaxCharSize = cpinfo.MaxCharSize; } } } #if DBG == 1 } else { p = pStop; TraceTag((tagEncAlwaysUseMlang, "Forcing mlang use for codepage %d", cp)); } #endif // If we cannot handle this codepage natively, hand it over to mlang if (!fSuccess) { fSuccess = (S_OK == THR(mlang().IsConvertible(cp, CP_UCS_2))); } if (fSuccess) { _pfnWideCharFromMultiByte = p == pStop ? &CEncodeReader::WideCharFromMultiByteMlang : p->pfnWCFromMB; } else { // If we failed, do not switch code pages. TraceTag((tagEncGeneral, "Don't know how to read with codepage: %d", cp)); cp = _cp; } TraceTag((tagEncGeneral, "CEncodeReader switching to codepage: %d", cp)); Cleanup: if (!_pfnWideCharFromMultiByte) { // If we still haven't come up with an encoding use 1252 _pfnWideCharFromMultiByte = &CEncodeReader::WideCharFromMultiByteGeneric; cp = CP_1252; _uMaxCharSize = 1; } fSwitched = _cp != cp; if (pfDifferentEncoding) { *pfDifferentEncoding = !IsSameEncoding(cp, _cp); } _cp = cp; return fSwitched; } HRESULT CEncodeReader::PrepareToEncode() { HRESULT hr = S_OK; if (!_pbBuffer) { _cbBufferMax = BlockSize() + ENCODE_DBCS_THRESHOLD; _cbBuffer = _cbBufferMax; _pbBuffer = (unsigned char *)MemAlloc(Mt(CEncodeReaderPbBuf), _cbBufferMax ); if (!_pbBuffer) { hr = E_OUTOFMEMORY; goto Cleanup; } _pbBufferPtr = _pbBuffer + _cbBuffer; } // // _cbBuffer is the number of valid multibyte characters in our // multibyte buffer. It is non-zero when (a) you've split a multibyte // character at a read boundary, or (b) autodetection has not yet been // able to correctly identify the encoding. // _cbBuffer -= (INT)(_pbBufferPtr - _pbBuffer); memmove( _pbBuffer, _pbBufferPtr, _cbBuffer ); if (_cbBuffer > ENCODE_DBCS_THRESHOLD) { // Ensure that we have space to read an BlockSize() chunk. _cbBufferMax = _cbBuffer + BlockSize(); hr = THR( MemRealloc(Mt(CEncodeReaderPbBuf), (void **)&_pbBuffer , _cbBufferMax ) ); if (hr) goto Cleanup; } _pbBufferPtr = _pbBuffer + _cbBuffer; Cleanup: RRETURN(hr); } HRESULT CEncodeReader::WideCharFromMultiByte( BOOL fReadEof, int * pcch ) { HRESULT hr; #ifndef WIN16 // Do a quick check for Unicode files if (!_fCheckedForUnicode) { AssertSz(_pbBufferPtr == _pbBuffer, "We should be at the beginning of the buffer."); BOOL fCheckNoFurther = FALSE; for (;;) { if (_cbBuffer > 1) { WCHAR uSignature = *(WCHAR *)_pbBuffer; // TODO (davidd) Support NON/NATIVE_UNICODE_CODEPAGE (sizeof(WCHAR) == 4/2) if (NATIVE_UNICODE_SIGNATURE == uSignature) { // (davidd) CP_UCS_2 does not currently distinguish between // 2/4 byte unicode so it is the right answer for native // unicode reading.. should be NATIVE_UNICODE_CODEPAGE SwitchCodePage( CP_UCS_2 ); _pbBufferPtr += sizeof(WCHAR); fCheckNoFurther = TRUE; break; } else if (NONNATIVE_UNICODE_SIGNATURE == uSignature) { SwitchCodePage( CP_UCS_2_BIGENDIAN ); _pbBufferPtr += sizeof(WCHAR); fCheckNoFurther = TRUE; break; } } if (_cbBuffer > 2) { if ( _pbBufferPtr[0] == 0xEF && _pbBufferPtr[1] == 0xBB && _pbBufferPtr[2] == 0xBF) { SwitchCodePage( CP_UTF_8 ); _pbBufferPtr += 3; fCheckNoFurther = TRUE; break; } } if (_cbBuffer > 3) { if ( _pbBufferPtr[0] == '+' && _pbBufferPtr[1] == '/' && _pbBufferPtr[2] == 'v' && ( _pbBufferPtr[3] == '8' || _pbBufferPtr[3] == '9' || _pbBufferPtr[3] == '+' || _pbBufferPtr[3] == '/')) { SwitchCodePage( CP_UTF_7 ); _fDiscardUtf7BOM = TRUE; } fCheckNoFurther = TRUE; } break; } _fCheckedForUnicode = fCheckNoFurther; } #endif //!WIN16 hr = THR( CALL_METHOD( this, _pfnWideCharFromMultiByte, ( fReadEof, pcch )) ); RRETURN(hr); } HRESULT CEncodeReader::WideCharFromMultiByteGeneric( BOOL fReadEof, int * pcch ) { size_t cb = _cbBuffer - (_pbBufferPtr - _pbBuffer); size_t cch = 0; HRESULT hr = S_OK; CODEPAGE cp = _cp; // PERF HACK (grzegorz): We are using WideCharFromMultiByteGeneric to convert // from CP_ISO_8859_1 to Unicode, but MultiByteToWideChar in this case // doesn't converts all characters properly (example: 0x80 (euro)). // MLang has a hack for this case, they are using CP_1252. To make the // behavior consistent we need to do the same. if (cp == CP_ISO_8859_1) cp = CP_1252; // If we have a multibyte character encoding, we are at risk of splitting // some characters at the read boundary. We must Make sure we have a // discrete number of characters first. Assert( _uMaxCharSize ); if (_uMaxCharSize > 1) { UINT uMax = _uMaxCharSize; cb++;// pre-increment do { cch = MultiByteToWideChar( cp, MB_ERR_INVALID_CHARS | MB_PRECOMPOSED, (char *)_pbBufferPtr, --cb, NULL, 0 ); --uMax; } while (!cch && uMax && cb); } else { cch = cb; } if (cch == 0) { cch = MultiByteToWideChar( cp, MB_PRECOMPOSED, (char*)_pbBufferPtr, cb, NULL, 0 ); } if (cch) { hr = THR(MakeRoomForChars(cch)); if (hr) goto Cleanup; cch = MultiByteToWideChar( cp, MB_PRECOMPOSED, (char *)_pbBufferPtr, cb, _pchEnd, cch ); } *pcch = cch; _pbBufferPtr += cb; Cleanup: RRETURN(hr); } #ifndef NO_MLANG HRESULT CEncodeReader::WideCharFromMultiByteMlang( BOOL fReadEof, int * pcch ) { HRESULT hr; UINT cch = 0, cb = _cbBuffer - (_pbBufferPtr - _pbBuffer); DWORD dwState = _dwState; hr = THR(mlang().ConvertStringToUnicode(&dwState, _cp, (CHAR *)_pbBufferPtr, &cb, NULL, &cch)); if (FAILED(hr)) goto Cleanup; hr = THR(MakeRoomForChars(cch)); if (hr) goto Cleanup; hr = THR(mlang().ConvertStringToUnicode(&_dwState, _cp, (CHAR *)_pbBufferPtr, &cb, (WCHAR *)_pchEnd, &cch)); if (FAILED(hr)) goto Cleanup; if (IsAutodetectCodePage(_cp)) { // Mlang stuffs the actual codepage into the hiword of the state CODEPAGE cpDetected = HIWORD(_dwState); // if cpDetected is zero, it implies that there was insufficient data // (typically all-ASCII data) to determine the charset. We will // continue to encode in autodetect mode in this case. If non-zero, // we'll switch the doc so that we can submit, etc., correctly. if (cpDetected) { // if we're getting codepage detecting result from // mlang, chances are that we have not processed // the stream at all because the system didn't have // the corresponding codepage installed. // we need to start over and get the codepage JIT-in. // BOOL fNeedRestart = _fDetectionFailed; if (_cp == CP_AUTO) { MIMECPINFO cpinfo; ZeroMemory(&cpinfo, sizeof(MIMECPINFO)); if ( (mlang().GetCodePageInfo(cpDetected, MLGetUILanguage(), &cpinfo) == S_OK) && !(cpinfo.dwFlags & MIMECONTF_VALID)) { fNeedRestart = TRUE; } } _fDetectionFailed = FALSE; SwitchCodePage(cpDetected, NULL, fNeedRestart); } else _fDetectionFailed = TRUE; } else if (_fDiscardUtf7BOM) { // Discard the BOM. Note we can't do this sooner because part of the // first character is mixed in with the BOM bytes. --cch; memmove( _pchEnd, _pchEnd + 1, cch * sizeof(wchar_t)); _fDiscardUtf7BOM = FALSE; } hr = S_OK; *pcch = cch; _pbBufferPtr += cb; Cleanup: RRETURN(hr); } #endif // !NO_MLANG HRESULT CEncodeReader::MakeRoomForChars( int cch ) { // call my superclass first! _pchEndLast = _pchEnd; _pbBufferPtrLast = _pbBufferPtr; RRETURN(S_OK); } //--------------------------------------------------------------------- CEncodeWriter::CEncodeWriter( CODEPAGE cp, size_t nBlockSize ) : CEncode( nBlockSize ) { _pfnMultiByteFromWideChar = NULL; _pchBuffer = NULL; _cchBuffer = _cchBufferMax = 0; _pbBuffer = NULL; _cbBuffer = _cbBufferMax = 0; _cDefaultChar = '?'; _fEntitizeUnknownChars = TRUE; // Choose something sane for _uiWinCodepage _uiWinCodepage = g_cpDefault; SwitchCodePage( cp ); // sets _pfnWideCharFromMultiByte } CEncodeWriter::~CEncodeWriter() { if (_pchBuffer) { MemFree(_pchBuffer); _pchBuffer = NULL; _cchBuffer = _cchBufferMax = 0; } if (_pbBuffer) { MemFree(_pbBuffer); _pbBuffer = NULL; _cbBuffer = _cbBufferMax = 0; } } BOOL CEncodeWriter::SwitchCodePage( CODEPAGE cp, BOOL *pfDifferentEncoding, BOOL fNeedRestart ) { BOOL fSuccess = FALSE, fSwitched; static const struct ENCODINGWRITEFUNC aEncodingFuncs[] = { { CP_1252, &CEncodeWriter::MultiByteFromWideCharGeneric }, { CP_ISO_8859_1, &CEncodeWriter::MultiByteFromWideCharGeneric }, #ifndef WINCE { CP_UTF_8, &CEncodeWriter::Utf8FromWideChar }, #endif // WINCE { CP_UCS_2, &CEncodeWriter::UnicodeFromWideChar }, { CP_1250, &CEncodeWriter::MultiByteFromWideCharGeneric }, { CP_1251, &CEncodeWriter::MultiByteFromWideCharGeneric }, { CP_1253, &CEncodeWriter::MultiByteFromWideCharGeneric }, { CP_1254, &CEncodeWriter::MultiByteFromWideCharGeneric }, { CP_1257, &CEncodeWriter::MultiByteFromWideCharGeneric }, }; const struct ENCODINGWRITEFUNC * p = aEncodingFuncs; const struct ENCODINGWRITEFUNC * pStop = aEncodingFuncs + ARRAY_SIZE(aEncodingFuncs); // Nothing has changed, quickly bail. if (cp == _cp && _pfnMultiByteFromWideChar) goto Cleanup; Assert(cp != CP_ACP); // See if we can handle this codepage natively. for (;p < pStop; p++) { if (cp == p->cp) break; } fSuccess = (p < pStop); // If we cannot handle this codepage natively, hand it over to mlang if (!fSuccess) { fSuccess = (S_OK == THR(mlang().IsConvertible(CP_UCS_2, cp))); } if (fSuccess) { if (p == pStop) { if (mlang().IsMLangAvailable()) _pfnMultiByteFromWideChar = &CEncodeWriter::MultiByteFromWideCharMlang2; else { _pfnMultiByteFromWideChar = MultiByteFromWideCharGeneric; CPINFO cpinfo; fSuccess = GetCPInfo(cp, &cpinfo); } } else _pfnMultiByteFromWideChar = p->pfnMBFromWC; } if (!fSuccess) { _pfnMultiByteFromWideChar = &CEncodeWriter::MultiByteFromWideCharMlang2; cp = g_cpDefault; // desperation } TraceTag((tagEncGeneral, "CEncodeWriter switching to codepage: %d", cp)); Cleanup: fSwitched = _cp != cp; if (pfDifferentEncoding) { *pfDifferentEncoding = fSwitched; } _cp = cp; // Cache the windows codepage for the new cp _uiWinCodepage = WindowsCodePageFromCodePage( _cp ); if (fSwitched) { _dwState = 0; } return fSwitched; } HRESULT CEncodeWriter::PrepareToEncode() { HRESULT hr = S_OK; // // Allocate a unicode buffer the size of our block size, if we haven't already. // if (!_pchBuffer) { _cchBufferMax = BlockSize(); _cchBuffer = 0; _pchBuffer = (TCHAR*)MemAlloc(Mt(CEncodeWriterPchBuf), _cchBufferMax*sizeof(TCHAR) ); if (!_pchBuffer) { hr = E_OUTOFMEMORY; goto Cleanup; } } Cleanup: RRETURN(hr); } HRESULT CEncodeWriter::MultiByteFromWideChar( BOOL fReadEof, int * pcch ) { HRESULT hr; Assert( _pfnMultiByteFromWideChar != NULL ); hr = THR( CALL_METHOD( this, _pfnMultiByteFromWideChar, ( fReadEof, pcch ) )); RRETURN(hr); } HRESULT CEncodeWriter::MultiByteFromWideCharGeneric( BOOL fReadEof, int * pcch ) { HRESULT hr; UINT cchTotal; cchTotal = WideCharToMultiByte(_uiWinCodepage, 0, _pchBuffer, _cchBuffer, NULL, 0, NULL, NULL); hr = THR(MakeRoomForChars(cchTotal)); if (hr) goto Cleanup; cchTotal = WideCharToMultiByte(_uiWinCodepage, 0, _pchBuffer, _cchBuffer, (char*)_pbBuffer + _cbBuffer, _cbBufferMax - _cbBuffer, &_cDefaultChar, NULL); if (!_fEntitizeUnknownChars) { _cbBuffer += cchTotal; } else { BOOL fEntitizeMode = FALSE; WCHAR * pchOrig; WCHAR * pchNew; UINT cchUnicode; // Convert output buffer back to Unicode to find out which characters // need to be entitized (&#xxxxx;). cchUnicode = MultiByteToWideChar(_uiWinCodepage, 0, (char*)_pbBuffer + _cbBuffer, cchTotal, NULL, 0); WCHAR * pch = (WCHAR *)MemAlloc(Mt(CEncodeWriter), cchUnicode * sizeof(WCHAR)); if (!pch) { hr = E_OUTOFMEMORY; goto Cleanup; } cchUnicode = MultiByteToWideChar(_uiWinCodepage, 0, (char*)_pbBuffer + _cbBuffer, cchTotal, pch, cchUnicode); // Compare results, and if they: // 1) match, use already converted string // 2) don't match, we need to switch to entitize mode, replace unknown characters // with &#xxxxx; Need to go one byte at a time. Assert(_cchBuffer == cchUnicode); pchOrig = _pchBuffer; pchNew = pch; for (UINT i = 0; i < _cchBuffer; i++) { if (*pchNew++ != *pchOrig++) { fEntitizeMode = TRUE; break; } } if (fEntitizeMode) { unsigned char *pb = _pbBuffer + _cbBuffer; unsigned char *pbStart; UINT cchNeed = cchTotal; // we need at least this much room in the buffer cchTotal = 0; pchOrig = _pchBuffer; pchNew = pch; for (UINT i = 0; i < _cchBuffer; i++) { if (*pchNew == *pchOrig) { LONG cchTemp = WideCharToMultiByte(_uiWinCodepage, 0, pchOrig, 1, (char*)pb, _cbBufferMax - _cbBuffer, NULL, 0); pb += cchTemp; cchTotal += cchTemp; cchNeed -= cchTemp; } else { // Fill in an entitity reference instead // Allocate eight more characters for the numeric entity hr = THR(MakeRoomForChars(cchTotal + 8 + cchNeed)); if (hr) goto Cleanup; // _pbBuffer can change in MakeRoomForChars pb = pbStart = _pbBuffer + _cbBuffer + cchTotal; *pb++ = '&'; *pb++ = '#'; _ultoa((unsigned long)*pchOrig, (char*)pb, 10); pb += lstrlenA((const char*)pb); *pb++ = ';'; AssertSz(pb <= _pbBuffer + _cbBufferMax, "Entitizing overflow"); cchTotal += (UINT)(pb - pbStart); } ++pchNew; ++pchOrig; } } _cbBuffer += cchTotal; MemFree(pch); } *pcch = cchTotal; Cleanup: RRETURN( hr ); } #ifndef NO_MLANG HRESULT CEncodeWriter::MultiByteFromWideCharMlang( BOOL fReadEof, int * pcch ) { HRESULT hr; UINT cb = 0, cch = _cchBuffer; DWORD dwState; _dwState |= _fEntitizeUnknownChars ? 0x00008000 : 0; dwState = _dwState; hr = THR(mlang().ConvertStringFromUnicode(&dwState, _cp, (WCHAR *)_pchBuffer, &cch, NULL, &cb)); if (FAILED(hr)) goto Cleanup; hr = THR(MakeRoomForChars(cb)); if( hr ) goto Cleanup; hr = THR(mlang().ConvertStringFromUnicode(&_dwState, _cp, (WCHAR *)_pchBuffer, &cch, (CHAR *)_pbBuffer + _cbBuffer, &cb)); if (FAILED(hr)) goto Cleanup; // NB (cthrash) MLANG returns S_FALSE when everything converted fine, except // there were WC chars not native to the codepage _cp. These are entitized, // so there's no error. We don't want to propagate the S_FALSE up to the caller. hr = S_OK; *pcch = cb; _cbBuffer += cb; Cleanup: RRETURN( hr ); } HRESULT CEncodeWriter::MultiByteFromWideCharMlang2( BOOL fReadEof, int * pcch ) { HRESULT hr; UINT cb = 0, cch = _cchBuffer; DWORD dwArg = _fEntitizeUnknownChars ? (MLCONVCHARF_NAME_ENTITIZE | MLCONVCHARF_NCR_ENTITIZE) : 0; DWORD dwState = _dwState; hr = THR(mlang().ConvertStringFromUnicodeEx(&dwState, _cp, (WCHAR *)_pchBuffer, &cch, NULL, &cb, dwArg, NULL)); if (FAILED(hr)) goto Cleanup; hr = THR(MakeRoomForChars(cb)); if( hr ) goto Cleanup; hr = THR(mlang().ConvertStringFromUnicodeEx(&_dwState, _cp, (WCHAR *)_pchBuffer, &cch, (CHAR *)_pbBuffer + _cbBuffer, &cb, dwArg, NULL)); if (FAILED(hr)) goto Cleanup; // NB (cthrash) MLANG returns S_FALSE when everything converted fine, except // there were WC chars not native to the codepage _cp. These are entitized, // so there's no error. We don't want to propagate the S_FALSE up to the caller. hr = S_OK; *pcch = cb; _cbBuffer += cb; Cleanup: RRETURN( hr ); } #endif // !NO_MLANG HRESULT CEncodeWriter::MakeRoomForChars( int cch ) { HRESULT hr = S_OK; if (!_pbBuffer) { // round up to block size multiple >= cch+1 _cbBufferMax = (cch + _nBlockSize*2 - 1) & ~(_nBlockSize*2 - 1); _pbBuffer = (unsigned char*)MemAlloc(Mt(CEncodeWriterPbBuf), _cbBufferMax); if (!_pbBuffer) RRETURN( E_OUTOFMEMORY ); } else { int cchNeed = _cbBuffer + cch; // Reallocate the chunk if we need more memory for the extra characters. if (cchNeed >= _cbBufferMax) { // round up to WBUFF_SIZE*2 cchNeed = (cchNeed + _nBlockSize*2 - 1) & ~(_nBlockSize*2 - 1); hr = THR(MemRealloc(Mt(CEncodeWriterPbBuf), (void**)&_pbBuffer, cchNeed ) ); if (hr) goto Cleanup; _cbBufferMax = cchNeed; } } Cleanup: RRETURN( hr ); } //+---------------------------------------------------------------------------- // // Function: CToUnicodeConverter::Convert // // Synopsis: Convert a multibyte string to a Unicode string. // // Input: pbBuffer - multibyte string. // // cbBuffer - byte count of pbBuffer, or -1. // -1 implies that the string is nul-terminated. // // Returns: HRESULT - S_OK/E_OUTOFMEMORY // // *ppchBuffer - Unicode buffer. Allocated by this object. // Should be freed by caller. // // *pcch - Character count of string in *ppchBuffer // //----------------------------------------------------------------------------- HRESULT CToUnicodeConverter::Convert( const char *pbBuffer, // IN const int cbBuffer, // IN TCHAR ** ppchBuffer, // OUT int *pcch ) // OUT { HRESULT hr = S_OK; Assert(pbBuffer && cbBuffer >= -1); _fMakeRoomForNUL = (cbBuffer != -1); _pbBuffer = _pbBufferPtr = (unsigned char *)pbBuffer; _cbBuffer = _cbBufferMax = _fMakeRoomForNUL ? cbBuffer : lstrlenA(pbBuffer) + 1; hr = THR(WideCharFromMultiByte(TRUE, pcch)); if (FAILED(hr)) goto Cleanup; if (AutoDetectionFailed()) { SwitchCodePage( g_cpDefault ); _fMakeRoomForNUL = (cbBuffer != -1); _pbBuffer = _pbBufferPtr = (unsigned char *)pbBuffer; _cbBuffer = _cbBufferMax = _fMakeRoomForNUL ? cbBuffer : lstrlenA(pbBuffer) + 1; hr = THR(WideCharFromMultiByte(TRUE, pcch)); if (FAILED(hr)) goto Cleanup; } *ppchBuffer = _pchBuffer; Cleanup: RRETURN(hr); } //+---------------------------------------------------------------------------- // // Function: CToUnicodeConverter::MakeRoomForChars // // Synopsis: Allocate a Unicode string buffer. // // Input: cch = Unicode character count // // Returns: HRESULT - S_OK/E_OUTOFMEMORY // //----------------------------------------------------------------------------- HRESULT CToUnicodeConverter::MakeRoomForChars( int cch ) { HRESULT hr = S_OK; if (!_pchBuffer || cch > _cchBuffer) { if (_fMakeRoomForNUL) ++cch; if( !_pchBuffer ) { _pchBuffer = (TCHAR *)MemAlloc(_mt, cch * sizeof(TCHAR)); if (!_pchBuffer) { hr = E_OUTOFMEMORY; goto Cleanup; } } else if( cch > 0 ) { // If we did this for cch == 0, Realloc would free the buffer, and that'd be // substantially different. hr = THR( MemRealloc(_mt, (void **)&_pchBuffer, cch * sizeof(TCHAR))); if( hr ) goto Cleanup; } _cchBuffer = cch; _pchEnd = _pchBuffer; } IGNORE_HR(CEncodeReader::MakeRoomForChars(cch)); Cleanup: RRETURN(hr); } //+---------------------------------------------------------------------------- // // Function: CToUnicodeConverter dtor // // Synopsis: Caller should free both the multibyte and unicode string // buffers. To prevent the base class CEncodeReader from freeing // if for you, we NULL out the pointers. // //----------------------------------------------------------------------------- CToUnicodeConverter::~CToUnicodeConverter() { // Let the caller free this memory _pbBuffer = NULL; _pchBuffer = NULL; }
dc.w word_8F090-Map_Rockn dc.w word_8F098-Map_Rockn dc.w word_8F0A0-Map_Rockn dc.w word_8F0A8-Map_Rockn dc.w word_8F0B0-Map_Rockn word_8F090: dc.w 1 ; DATA XREF: ROM:0008F086o dc.b $F8, 9, 0, 0, $FF, $F4 word_8F098: dc.w 1 ; DATA XREF: ROM:0008F086o dc.b $F8, 9, 0, 6, $FF, $F4 word_8F0A0: dc.w 1 ; DATA XREF: ROM:0008F086o dc.b $F8, $D, 0, $C, $FF, $F0 word_8F0A8: dc.w 1 ; DATA XREF: ROM:0008F086o dc.b $F8, 5, 0, $14, $FF, $E8 word_8F0B0: dc.w 1 ; DATA XREF: ROM:0008F086o dc.b 0, 4, 0, $18, $FF, $E8
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // -*- Mode: C++ -*- // // Copyright (C) 2020 Google, Inc. // // Author: Matthias Maennich /// @file /// /// This program tests symtab invariants through abg-corpus. #include <iostream> #include <limits> #include <vector> #include "abg-corpus.h" #include "abg-dwarf-reader.h" #include "abg-ir.h" #include "lib/catch.hpp" #include "test-utils.h" using namespace abigail; using dwarf_reader::create_read_context; using dwarf_reader::read_context_sptr; using dwarf_reader::read_corpus_from_elf; using ir::environment; using ir::environment_sptr; static const std::string test_data_dir = std::string(abigail::tests::get_src_dir()) + "/tests/data/test-symtab/"; dwarf_reader::status read_corpus(const std::string path, corpus_sptr& result) { const std::string& absolute_path = test_data_dir + path; environment_sptr env(new environment); const std::vector<char**> debug_info_root_paths; read_context_sptr ctxt = create_read_context( absolute_path, debug_info_root_paths, env.get(), /* load_all_type = */ true, /* linux_kernel_mode = */ true); dwarf_reader::status status = dwarf_reader::STATUS_UNKNOWN; result = read_corpus_from_elf(*ctxt, status); REQUIRE(status != dwarf_reader::STATUS_UNKNOWN); return status; } TEST_CASE("Symtab::Empty", "[symtab, basic]") { const std::string binary = "basic/empty.so"; corpus_sptr corpus_ptr; const dwarf_reader::status status = read_corpus(binary, corpus_ptr); REQUIRE(corpus_ptr); REQUIRE((status & dwarf_reader::STATUS_OK)); // TODO: Those two assertions are currently not met. Empty symtabs are // currently treated like the error case. // REQUIRE((status & dwarf_reader::STATUS_OK)); // REQUIRE((status & dwarf_reader::STATUS_NO_SYMBOLS_FOUND)); } TEST_CASE("Symtab::NoDebugInfo", "[symtab, basic]") { const std::string binary = "basic/no_debug_info.so"; corpus_sptr corpus_ptr; const dwarf_reader::status status = read_corpus(binary, corpus_ptr); REQUIRE(corpus_ptr); REQUIRE(status == (dwarf_reader::STATUS_OK | dwarf_reader::STATUS_DEBUG_INFO_NOT_FOUND)); } // this value indicates in the following helper method, that we do not want to // assert for this particular value. In other words, N is a placeholder for an // arbitrary value. #define N std::numeric_limits<size_t>::max() corpus_sptr assert_symbol_count(const std::string& path, size_t function_symbols = 0, size_t variable_symbols = 0, size_t undefined_function_symbols = 0, size_t undefined_variable_symbols = 0) { corpus_sptr corpus_ptr; const dwarf_reader::status status = read_corpus(path, corpus_ptr); REQUIRE(corpus_ptr); REQUIRE((status & dwarf_reader::STATUS_OK)); const corpus& corpus = *corpus_ptr; if (function_symbols != N) { CHECK(corpus.get_sorted_fun_symbols().size() == function_symbols); CHECK(corpus.get_fun_symbol_map().size() == function_symbols); CHECK(corpus.get_fun_symbol_map_sptr()->size() == function_symbols); } if (variable_symbols != N) { CHECK(corpus.get_sorted_var_symbols().size() == variable_symbols); CHECK(corpus.get_var_symbol_map().size() == variable_symbols); CHECK(corpus.get_var_symbol_map_sptr()->size() == variable_symbols); } if (undefined_variable_symbols != N) { CHECK(corpus.get_sorted_undefined_fun_symbols().size() == undefined_function_symbols); CHECK(corpus.get_undefined_fun_symbol_map().size() == undefined_function_symbols); CHECK(corpus.get_undefined_fun_symbol_map_sptr()->size() == undefined_function_symbols); } if (undefined_function_symbols != N) { CHECK(corpus.get_sorted_undefined_var_symbols().size() == undefined_variable_symbols); CHECK(corpus.get_undefined_var_symbol_map().size() == undefined_variable_symbols); CHECK(corpus.get_undefined_var_symbol_map_sptr()->size() == undefined_variable_symbols); } return corpus_ptr; } TEST_CASE("Symtab::SimpleSymtabs", "[symtab, basic]") { GIVEN("a binary with no exported symbols") { // TODO: should pass, but does currently not as empty tables are treated // like the error case, but this is an edge case anyway. // assert_symbol_count("empty.so"); } GIVEN("a binary with a single exported function") { const std::string binary = "basic/single_function.so"; const corpus_sptr& corpus = assert_symbol_count(binary, 1, 0); const elf_symbol_sptr& symbol = corpus->lookup_function_symbol("exported_function"); REQUIRE(symbol); CHECK(!corpus->lookup_variable_symbol("exported_function")); CHECK(symbol == corpus->lookup_function_symbol(*symbol)); CHECK(symbol != corpus->lookup_variable_symbol(*symbol)); } GIVEN("a binary with a single exported variable") { const std::string binary = "basic/single_variable.so"; const corpus_sptr& corpus = assert_symbol_count(binary, 0, 1); const elf_symbol_sptr& symbol = corpus->lookup_variable_symbol("exported_variable"); REQUIRE(symbol); CHECK(!corpus->lookup_function_symbol("exported_variable")); CHECK(symbol == corpus->lookup_variable_symbol(*symbol)); CHECK(symbol != corpus->lookup_function_symbol(*symbol)); } GIVEN("a binary with one function and one variable exported") { const std::string binary = "basic/one_function_one_variable.so"; const corpus_sptr& corpus = assert_symbol_count(binary, 1, 1); CHECK(corpus->lookup_function_symbol("exported_function")); CHECK(!corpus->lookup_variable_symbol("exported_function")); CHECK(corpus->lookup_variable_symbol("exported_variable")); CHECK(!corpus->lookup_function_symbol("exported_variable")); } GIVEN("a binary with a single undefined function") { const std::string binary = "basic/single_undefined_function.so"; const corpus_sptr corpus = assert_symbol_count(binary, 0, 0, 1, 0); } GIVEN("a binary with a single undefined variable") { const std::string binary = "basic/single_undefined_variable.so"; const corpus_sptr corpus = assert_symbol_count(binary, 0, 0, 0, 1); } GIVEN("a binary with one function and one variable undefined") { const std::string binary = "basic/one_function_one_variable_undefined.so"; const corpus_sptr corpus = assert_symbol_count(binary, 0, 0, 1, 1); } } static const char* kernel_versions[] = { "4.14", "4.19", "5.4", "5.6" }; static const size_t nr_kernel_versions = sizeof(kernel_versions) / sizeof(kernel_versions[0]); TEST_CASE("Symtab::SimpleKernelSymtabs", "[symtab, basic, kernel, ksymtab]") { for (size_t i = 0; i < nr_kernel_versions; ++i) { const std::string base_path = "kernel-" + std::string(kernel_versions[i]) + "/"; GIVEN("The binaries in " + base_path) { GIVEN("a kernel module with no exported symbols") { // TODO: should pass, but does currently not as empty tables are // treated // like the error case, but this is an edge case anyway. // assert_symbol_count(base_path + "empty.so"); } GIVEN("a kernel module with a single exported function") { const std::string binary = base_path + "single_function.ko"; const corpus_sptr& corpus = assert_symbol_count(binary, 1, 0); const elf_symbol_sptr& symbol = corpus->lookup_function_symbol("exported_function"); REQUIRE(symbol); CHECK(!corpus->lookup_variable_symbol("exported_function")); CHECK(symbol == corpus->lookup_function_symbol(*symbol)); CHECK(symbol != corpus->lookup_variable_symbol(*symbol)); } GIVEN("a kernel module with a single GPL exported function") { const std::string binary = base_path + "single_function_gpl.ko"; const corpus_sptr& corpus = assert_symbol_count(binary, 1, 0); const elf_symbol_sptr& symbol = corpus->lookup_function_symbol("exported_function_gpl"); REQUIRE(symbol); CHECK(!corpus->lookup_variable_symbol("exported_function_gpl")); CHECK(symbol == corpus->lookup_function_symbol(*symbol)); CHECK(symbol != corpus->lookup_variable_symbol(*symbol)); } GIVEN("a binary with a single exported variable") { const std::string binary = base_path + "single_variable.ko"; const corpus_sptr& corpus = assert_symbol_count(binary, 0, 1); const elf_symbol_sptr& symbol = corpus->lookup_variable_symbol("exported_variable"); REQUIRE(symbol); CHECK(!corpus->lookup_function_symbol("exported_variable")); CHECK(symbol == corpus->lookup_variable_symbol(*symbol)); CHECK(symbol != corpus->lookup_function_symbol(*symbol)); } GIVEN("a binary with a single GPL exported variable") { const std::string binary = base_path + "single_variable_gpl.ko"; const corpus_sptr& corpus = assert_symbol_count(binary, 0, 1); const elf_symbol_sptr& symbol = corpus->lookup_variable_symbol("exported_variable_gpl"); REQUIRE(symbol); CHECK(!corpus->lookup_function_symbol("exported_variable_gpl")); CHECK(symbol == corpus->lookup_variable_symbol(*symbol)); CHECK(symbol != corpus->lookup_function_symbol(*symbol)); } GIVEN("a binary with one function and one variable (GPL) exported") { const std::string binary = base_path + "one_of_each.ko"; const corpus_sptr& corpus = assert_symbol_count(binary, 2, 2); CHECK(corpus->lookup_function_symbol("exported_function")); CHECK(!corpus->lookup_variable_symbol("exported_function")); CHECK(corpus->lookup_function_symbol("exported_function_gpl")); CHECK(!corpus->lookup_variable_symbol("exported_function_gpl")); CHECK(corpus->lookup_variable_symbol("exported_variable")); CHECK(!corpus->lookup_function_symbol("exported_variable")); CHECK(corpus->lookup_variable_symbol("exported_variable_gpl")); CHECK(!corpus->lookup_function_symbol("exported_variable_gpl")); } } } }
; A037528: Base-3 digits are, in order, the first n terms of the periodic sequence with initial period 1,1,2. ; Submitted by Jamie Morken(s2.) ; 1,4,14,43,130,392,1177,3532,10598,31795,95386,286160,858481,2575444,7726334,23179003,69537010,208611032,625833097,1877499292,5632497878,16897493635,50692480906,152077442720,456232328161 mov $1,3 pow $1,$0 sub $1,1 mul $1,42 add $1,28 div $1,26 mov $0,$1
; A062402: a(n) = sigma(phi(n)). ; 1,1,3,3,7,3,12,7,12,7,18,7,28,12,15,15,31,12,39,15,28,18,36,15,42,28,39,28,56,15,72,31,42,31,60,28,91,39,60,31,90,28,96,42,60,36,72,31,96,42,63,60,98,39,90,60,91,56,90,31,168,72,91,63,124,42,144,63,84,60,144,60,195,91,90,91,168,60,168,63,120,90,126,60,127,96,120,90,180,60,195,84,168,72,195,63,252,96,168,90,217,63,216,124,124,98,162,91,280,90,195,124,248,91,180,120,195,90,252,63,216,168,186,168,217,91,312,127,224,124,252,90,280,144,195,127,270,84,288,124,168,144,360,124,248,195,224,195,266,90,372,195,252,168,360,124,392,168,210,127,336,120,363,186,186,126,252,124,392,127,280,224,308,120,360,186,210,180,270,124,546,195,360,180,403,168,378,168,280,195,360,127,508,252,252,224,399,168,468,186,336,217,480,127,378,216,336,252,546,124,576,210,336,162,480,195,546,280,403,186,508,195,456,252,360,248,342,195,560,180,360,248,450,195,360,210,392,252,432,127,744,216,363,360,480,186,600,360,294,217 cal $0,10 ; Euler totient function phi(n): count numbers <= n and prime to n. sub $0,1 cal $0,88580 ; a(n) = 1 + sigma(n). sub $0,1 mul $0,2 mov $1,$0 sub $1,2 div $1,2 add $1,1
/*----------------------------------------------------------------------- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"; you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -----------------------------------------------------------------------*/ #include "ContinuousProperty.h" #include <limits> #include <sstream> #include <hdf5.h> #include "../common/AbstractHdfProxy.h" #include "../common/EnumStringMapper.h" #include "../resqml2/AbstractRepresentation.h" #include "PropertyKind.h" using namespace std; using namespace RESQML2_0_1_NS; using namespace gsoap_resqml2_0_1; const char* ContinuousProperty::XML_TAG = "ContinuousProperty"; void ContinuousProperty::init(RESQML2_NS::AbstractRepresentation * rep, const std::string & guid, const std::string & title, unsigned int dimension, gsoap_resqml2_0_1::resqml20__IndexableElements attachmentKind) { gsoapProxy2_0_1 = soap_new_resqml20__obj_USCOREContinuousProperty(rep->getGsoapContext()); _resqml20__ContinuousProperty* prop = static_cast<_resqml20__ContinuousProperty*>(gsoapProxy2_0_1); prop->IndexableElement = attachmentKind; prop->Count = dimension; initMandatoryMetadata(); setMetadata(guid, title, std::string(), -1, std::string(), std::string(), -1, std::string()); setRepresentation(rep); } ContinuousProperty::ContinuousProperty(RESQML2_NS::AbstractRepresentation * rep, const string & guid, const string & title, unsigned int dimension, gsoap_resqml2_0_1::resqml20__IndexableElements attachmentKind, gsoap_resqml2_0_1::resqml20__ResqmlUom uom, resqml20__ResqmlPropertyKind energisticsPropertyKind) { init(rep, guid, title, dimension, attachmentKind); static_cast<_resqml20__ContinuousProperty*>(gsoapProxy2_0_1)->UOM = uom; resqml20__StandardPropertyKind* xmlStandardPropKind = soap_new_resqml20__StandardPropertyKind(gsoapProxy2_0_1->soap); xmlStandardPropKind->Kind = energisticsPropertyKind; static_cast<_resqml20__ContinuousProperty*>(gsoapProxy2_0_1)->PropertyKind = xmlStandardPropKind; } ContinuousProperty::ContinuousProperty(RESQML2_NS::AbstractRepresentation * rep, const string & guid, const string & title, unsigned int dimension, gsoap_resqml2_0_1::resqml20__IndexableElements attachmentKind, gsoap_resqml2_0_1::resqml20__ResqmlUom uom, COMMON_NS::PropertyKind * localPropKind) { init(rep, guid, title, dimension, attachmentKind); static_cast<_resqml20__ContinuousProperty*>(gsoapProxy2_0_1)->UOM = uom; setLocalPropertyKind(localPropKind); } ContinuousProperty::ContinuousProperty(RESQML2_NS::AbstractRepresentation * rep, const string & guid, const string & title, unsigned int dimension, gsoap_resqml2_0_1::resqml20__IndexableElements attachmentKind, const std::string & nonStandardUom, resqml20__ResqmlPropertyKind energisticsPropertyKind) { init(rep, guid, title, dimension, attachmentKind); static_cast<_resqml20__ContinuousProperty*>(gsoapProxy2_0_1)->UOM = gsoap_resqml2_0_1::resqml20__ResqmlUom__Euc; pushBackExtraMetadata("Uom", nonStandardUom); resqml20__StandardPropertyKind* xmlStandardPropKind = soap_new_resqml20__StandardPropertyKind(gsoapProxy2_0_1->soap); xmlStandardPropKind->Kind = energisticsPropertyKind; static_cast<_resqml20__ContinuousProperty*>(gsoapProxy2_0_1)->PropertyKind = xmlStandardPropKind; } ContinuousProperty::ContinuousProperty(RESQML2_NS::AbstractRepresentation * rep, const string & guid, const string & title, unsigned int dimension, gsoap_resqml2_0_1::resqml20__IndexableElements attachmentKind, const std::string & nonStandardUom, COMMON_NS::PropertyKind * localPropKind) { init(rep, guid, title, dimension, attachmentKind); static_cast<_resqml20__ContinuousProperty*>(gsoapProxy2_0_1)->UOM = gsoap_resqml2_0_1::resqml20__ResqmlUom__Euc; pushBackExtraMetadata("Uom", nonStandardUom); setLocalPropertyKind(localPropKind); } const gsoap_resqml2_0_1::resqml20__ResqmlUom & ContinuousProperty::getUom() const { return static_cast<_resqml20__ContinuousProperty*>(gsoapProxy2_0_1)->UOM; } std::string ContinuousProperty::getUomAsString() const { return gsoap_resqml2_0_1::soap_resqml20__ResqmlUom2s(gsoapProxy2_0_1->soap, getUom()); } void ContinuousProperty::pushBackDoubleHdf5Array1dOfValues(const double * values, ULONG64 valueCount, COMMON_NS::AbstractHdfProxy * proxy, double minimumValue, double maximumValue) { const hsize_t valueCountPerDimension = valueCount; if (minimumValue == minimumValue && maximumValue == maximumValue) { pushBackDoubleHdf5ArrayOfValues(values, &valueCountPerDimension, 1, proxy, &minimumValue, &maximumValue); } else { pushBackDoubleHdf5ArrayOfValues(values, &valueCountPerDimension, 1, proxy); } } void ContinuousProperty::pushBackDoubleHdf5Array2dOfValues(const double * values, ULONG64 valueCountInFastestDim, ULONG64 valueCountInSlowestDim, COMMON_NS::AbstractHdfProxy * proxy, double minimumValue, double maximumValue) { const hsize_t valueCountPerDimension[2] = {valueCountInSlowestDim, valueCountInFastestDim}; if (minimumValue == minimumValue && maximumValue == maximumValue) { pushBackDoubleHdf5ArrayOfValues(values, valueCountPerDimension, 2, proxy, &minimumValue, &maximumValue); } else { pushBackDoubleHdf5ArrayOfValues(values, valueCountPerDimension, 2, proxy); } } void ContinuousProperty::pushBackDoubleHdf5Array3dOfValues(const double * values, ULONG64 valueCountInFastestDim, ULONG64 valueCountInMiddleDim, ULONG64 valueCountInSlowestDim, COMMON_NS::AbstractHdfProxy * proxy, double minimumValue, double maximumValue) { const hsize_t valueCountPerDimension[3] = {valueCountInSlowestDim, valueCountInMiddleDim, valueCountInFastestDim}; if (minimumValue == minimumValue && maximumValue == maximumValue) { pushBackDoubleHdf5ArrayOfValues(values, valueCountPerDimension, 3, proxy, &minimumValue, &maximumValue); } else { pushBackDoubleHdf5ArrayOfValues(values, valueCountPerDimension, 3, proxy); } } void ContinuousProperty::pushBackDoubleHdf5ArrayOfValues(double const * values, unsigned long long const * numValues, unsigned int numArrayDimensions, COMMON_NS::AbstractHdfProxy * proxy, double * minimumValue, double * maximumValue) { if (proxy == nullptr) { proxy = getRepository()->getDefaultHdfProxy(); if (proxy == nullptr) { throw std::invalid_argument("A (default) HDF Proxy must be provided."); } } const string datasetName = pushBackRefToExistingDataset(proxy, ""); setPropertyMinMax(values, numValues, numArrayDimensions, minimumValue, maximumValue); // HDF proxy->writeArrayNd(gsoapProxy2_0_1->uuid, datasetName, H5T_NATIVE_DOUBLE, values, numValues, numArrayDimensions); } void ContinuousProperty::pushBackFloatHdf5Array1dOfValues(const float * values, ULONG64 valueCount, COMMON_NS::AbstractHdfProxy * proxy, float minimumValue, float maximumValue) { const hsize_t valueCountPerDimension = valueCount; if (minimumValue == minimumValue && maximumValue == maximumValue) { pushBackFloatHdf5ArrayOfValues(values, &valueCountPerDimension, 1, proxy, &minimumValue, &maximumValue); } else { pushBackFloatHdf5ArrayOfValues(values, &valueCountPerDimension, 1, proxy); } } void ContinuousProperty::pushBackFloatHdf5Array2dOfValues(const float * values, ULONG64 valueCountInFastestDim, ULONG64 valueCountInSlowestDim, COMMON_NS::AbstractHdfProxy * proxy, float minimumValue, float maximumValue) { const hsize_t valueCountPerDimension[2] = {valueCountInSlowestDim, valueCountInFastestDim}; if (minimumValue == minimumValue && maximumValue == maximumValue) { pushBackFloatHdf5ArrayOfValues(values, valueCountPerDimension, 2, proxy, &minimumValue, &maximumValue); } else { pushBackFloatHdf5ArrayOfValues(values, valueCountPerDimension, 2, proxy); } } void ContinuousProperty::pushBackFloatHdf5Array3dOfValues(const float * values, ULONG64 valueCountInFastestDim, ULONG64 valueCountInMiddleDim, ULONG64 valueCountInSlowestDim, COMMON_NS::AbstractHdfProxy * proxy, float minimumValue, float maximumValue) { const hsize_t valueCountPerDimension[3] = {valueCountInSlowestDim, valueCountInMiddleDim, valueCountInFastestDim}; if (minimumValue == minimumValue && maximumValue == maximumValue) { pushBackFloatHdf5ArrayOfValues(values, valueCountPerDimension, 3, proxy, &minimumValue, &maximumValue); } else { pushBackFloatHdf5ArrayOfValues(values, valueCountPerDimension, 3, proxy); } } std::string ContinuousProperty::pushBackRefToExistingDataset(COMMON_NS::AbstractHdfProxy* proxy, const std::string & datasetName) { if (proxy == nullptr) { proxy = getRepository()->getDefaultHdfProxy(); if (proxy == nullptr) { throw std::invalid_argument("A (default) HDF Proxy must be provided."); } } getRepository()->addRelationship(this, proxy); gsoap_resqml2_0_1::resqml20__AbstractValuesProperty* prop = static_cast<gsoap_resqml2_0_1::resqml20__AbstractValuesProperty*>(gsoapProxy2_0_1); gsoap_resqml2_0_1::resqml20__PatchOfValues* patch = gsoap_resqml2_0_1::soap_new_resqml20__PatchOfValues(gsoapProxy2_0_1->soap); patch->RepresentationPatchIndex = static_cast<ULONG64*>(soap_malloc(gsoapProxy2_0_1->soap, sizeof(ULONG64))); *(patch->RepresentationPatchIndex) = prop->PatchOfValues.size(); // XML gsoap_resqml2_0_1::resqml20__DoubleHdf5Array* xmlValues = gsoap_resqml2_0_1::soap_new_resqml20__DoubleHdf5Array(gsoapProxy2_0_1->soap); xmlValues->Values = gsoap_resqml2_0_1::soap_new_eml20__Hdf5Dataset(gsoapProxy2_0_1->soap); xmlValues->Values->HdfProxy = proxy->newResqmlReference(); if (datasetName.empty()) { ostringstream ossForHdf; ossForHdf << "values_patch" << *(patch->RepresentationPatchIndex); xmlValues->Values->PathInHdfFile = "/RESQML/" + prop->uuid + "/" + ossForHdf.str(); } else { xmlValues->Values->PathInHdfFile = datasetName; } patch->Values = xmlValues; prop->PatchOfValues.push_back(patch); return xmlValues->Values->PathInHdfFile; } void ContinuousProperty::pushBackFloatHdf5Array3dOfValues( ULONG64 valueCountInFastestDim, ULONG64 valueCountInMiddleDim, ULONG64 valueCountInSlowestDim, COMMON_NS::AbstractHdfProxy* proxy, float minimumValue, float maximumValue) { const hsize_t valueCountPerDimension[3] = {valueCountInSlowestDim, valueCountInMiddleDim, valueCountInFastestDim}; if (minimumValue == minimumValue && maximumValue == maximumValue) { pushBackFloatHdf5ArrayOfValues(valueCountPerDimension, 3, proxy, &minimumValue, &maximumValue); } else { pushBackFloatHdf5ArrayOfValues(valueCountPerDimension, 3, proxy); } } void ContinuousProperty::setValuesOfFloatHdf5Array3dOfValues( float const * values, ULONG64 valueCountInFastestDim, ULONG64 valueCountInMiddleDim, ULONG64 valueCountInSlowestDim, ULONG64 offsetInFastestDim, ULONG64 offsetInMiddleDim, ULONG64 offsetInSlowestDim, bool computeMinMax, COMMON_NS::AbstractHdfProxy* proxy, unsigned int patchIndex) { const hsize_t valueCountPerDimension[3] = {valueCountInSlowestDim, valueCountInMiddleDim, valueCountInFastestDim}; const hsize_t offsetPerDimension[3] = {offsetInSlowestDim, offsetInMiddleDim, offsetInFastestDim}; setValuesOfFloatHdf5ArrayOfValues( values, valueCountPerDimension, offsetPerDimension, 3, computeMinMax, proxy, patchIndex ); } void ContinuousProperty::pushBackFloatHdf5ArrayOfValues(float const * values, unsigned long long const * numValues, unsigned int numArrayDimensions, COMMON_NS::AbstractHdfProxy * proxy, float * minimumValue, float * maximumValue) { if ((minimumValue == nullptr && maximumValue != nullptr) || (minimumValue != nullptr && maximumValue == nullptr)) { throw std::invalid_argument("You cannot set the minimum value without the maximum value and viceversa."); } if (proxy == nullptr) { proxy = getRepository()->getDefaultHdfProxy(); if (proxy == nullptr) { throw std::invalid_argument("A (default) HDF Proxy must be provided."); } } const string datasetName = pushBackRefToExistingDataset(proxy, ""); if (minimumValue != nullptr) { // implies that maximumValue != nullptr as well. setPropertyMinMax(values, numValues, numArrayDimensions, minimumValue, maximumValue); } // HDF proxy->writeArrayNd(gsoapProxy2_0_1->uuid, datasetName, H5T_NATIVE_FLOAT, values, numValues, numArrayDimensions); } void ContinuousProperty::pushBackFloatHdf5ArrayOfValues( unsigned long long const * numValues, unsigned int numArrayDimensions, COMMON_NS::AbstractHdfProxy* proxy, float * minimumValue, float * maximumValue) { if (proxy == nullptr) { proxy = getRepository()->getDefaultHdfProxy(); if (proxy == nullptr) { throw std::invalid_argument("A (default) HDF Proxy must be provided."); } } const string datasetName = pushBackRefToExistingDataset(proxy, ""); gsoap_resqml2_0_1::_resqml20__ContinuousProperty* prop = static_cast<gsoap_resqml2_0_1::_resqml20__ContinuousProperty*>(gsoapProxy2_0_1); if (minimumValue != nullptr && maximumValue != nullptr) { setPropertyMinMax((float*)nullptr, numValues, numArrayDimensions, minimumValue, maximumValue); } // HDF proxy->createArrayNd(prop->uuid, datasetName, H5T_NATIVE_FLOAT, numValues, numArrayDimensions); } void ContinuousProperty::setValuesOfFloatHdf5ArrayOfValues( float const * values, unsigned long long const * numValuesInEachDimension, unsigned long long const * offsetInEachDimension, unsigned int numArrayDimensions, bool computeMinMax, COMMON_NS::AbstractHdfProxy* proxy, unsigned int patchIndex) { _resqml20__ContinuousProperty const * prop = static_cast<_resqml20__ContinuousProperty *>(gsoapProxy2_0_1); if (computeMinMax) { setPropertyMinMax(values, numValuesInEachDimension, numArrayDimensions); } ostringstream oss; oss << "values_patch"; if (patchIndex == (numeric_limits<unsigned int>::max)()) { oss << prop->PatchOfValues.size() - 1; } else { oss << patchIndex; } // HDF if (proxy == nullptr) { proxy = getRepository()->getDefaultHdfProxy(); if (proxy == nullptr) { throw std::invalid_argument("A (default) HDF Proxy must be provided."); } } proxy->writeArrayNdSlab( prop->uuid, oss.str(), H5T_NATIVE_FLOAT, values, numValuesInEachDimension, offsetInEachDimension, numArrayDimensions); } void ContinuousProperty::getDoubleValuesOfPatch(unsigned int patchIndex, double * values) const { _resqml20__ContinuousProperty const * prop = static_cast<_resqml20__ContinuousProperty*>(gsoapProxy2_0_1); eml20__Hdf5Dataset const * dataset = static_cast<resqml20__DoubleHdf5Array*>(prop->PatchOfValues[patchIndex]->Values) ->Values; COMMON_NS::AbstractHdfProxy * hdfProxy = getHdfProxyFromDataset(dataset); hdfProxy->readArrayNdOfDoubleValues(dataset->PathInHdfFile, values); } void ContinuousProperty::getFloatValuesOfPatch(unsigned int patchIndex, float * values) const { _resqml20__ContinuousProperty const * prop = static_cast<_resqml20__ContinuousProperty*>(gsoapProxy2_0_1); eml20__Hdf5Dataset const * dataset = static_cast<resqml20__DoubleHdf5Array*>(prop->PatchOfValues[patchIndex]->Values)->Values; COMMON_NS::AbstractHdfProxy * hdfProxy = getHdfProxyFromDataset(dataset); hdfProxy->readArrayNdOfFloatValues(dataset->PathInHdfFile, values); } void ContinuousProperty::getFloatValuesOfPatch( unsigned int patchIndex, float* values, unsigned long long const * numValuesInEachDimension, unsigned long long const * offsetInEachDimension, unsigned int numArrayDimensions) const { _resqml20__ContinuousProperty const * prop = static_cast<_resqml20__ContinuousProperty*>(gsoapProxy2_0_1); eml20__Hdf5Dataset const * dataset = static_cast<resqml20__DoubleHdf5Array*>(prop->PatchOfValues[patchIndex]->Values)->Values; COMMON_NS::AbstractHdfProxy * hdfProxy = getHdfProxyFromDataset(dataset); hdfProxy->readArrayNdOfFloatValues( dataset->PathInHdfFile, values, numValuesInEachDimension, offsetInEachDimension, numArrayDimensions); } void ContinuousProperty::getFloatValuesOf3dPatch( unsigned int patchIndex, float* values, ULONG64 valueCountInFastestDim, ULONG64 valueCountInMiddleDim, ULONG64 valueCountInSlowestDim, ULONG64 offsetInFastestDim, ULONG64 offsetInMiddleDim, ULONG64 offsetInSlowestDim) const { hsize_t valueCountPerDimension[3] = {valueCountInSlowestDim, valueCountInMiddleDim, valueCountInFastestDim}; hsize_t offsetPerDimension[3] = {offsetInSlowestDim, offsetInMiddleDim, offsetInFastestDim}; getFloatValuesOfPatch( patchIndex, values, valueCountPerDimension, offsetPerDimension, 3 ); } double ContinuousProperty::getMinimumValue() const { _resqml20__ContinuousProperty* prop = static_cast<_resqml20__ContinuousProperty*>(gsoapProxy2_0_1); return prop->MinimumValue.empty() ? std::numeric_limits<double>::quiet_NaN() : prop->MinimumValue[0]; } double ContinuousProperty::getMaximumValue() const { _resqml20__ContinuousProperty* prop = static_cast<_resqml20__ContinuousProperty*>(gsoapProxy2_0_1); return prop->MaximumValue.empty() ? std::numeric_limits<double>::quiet_NaN() : prop->MaximumValue[0]; } bool ContinuousProperty::validatePropertyKindAssociation(COMMON_NS::PropertyKind* pk) { if (pk == nullptr) { throw invalid_argument("The property kind to validate cannot be null."); } if (!pk->isPartial()) { if (pk->isAbstract()) { repository->addWarning("The continuous property " + getUuid() + " cannot be associated to a local property kind " + pk->getUuid() + " which is abstract. This property will be assumed to be a partial one."); changeToPartialObject(); return false; } if (repository->getPropertyKindMapper() != nullptr) { if (pk->isParentPartial()) { repository->addWarning("Cannot verify if the local property kind " + pk->getUuid() + " of the continuous property " + getUuid() + " is right because one if its parent property kind is abstract."); return true; } if (!pk->isChildOf(resqml20__ResqmlPropertyKind__continuous)) { repository->addWarning("The continuous property " + getUuid() + " cannot be associated to a local property kind " + pk->getUuid() + " which does not derive from the continuous standard property kind. This property will be assumed to be a partial one."); changeToPartialObject(); return false; } } else { repository->addWarning("Cannot verify if the local property kind " + pk->getUuid() + " of the continuous property " + getUuid() + " is right because no property kind mapping files have been loaded."); } } else { repository->addWarning("Cannot verify if the local property kind " + pk->getUuid() + " of the continuous property " + getUuid() + " is right because it is abstract."); } return true; } bool ContinuousProperty::validatePropertyKindAssociation(gsoap_resqml2_0_1::resqml20__ResqmlPropertyKind pk) { COMMON_NS::EnumStringMapper tmp; std::string pkName = tmp.getEnergisticsPropertyKindName(pk); PropertyKindMapper* pkMapper = repository->getPropertyKindMapper(); if (pkMapper != nullptr) { if (pkMapper->isAbstract(pk)) { repository->addWarning("The continuous property " + getUuid() + " cannot be associated to a resqml property kind \"" + pkName + "\" which is abstract. This property will be assumed to be a partial one."); changeToPartialObject(); return false; } if (!pkMapper->isChildOf(pk, resqml20__ResqmlPropertyKind__continuous)) { repository->addWarning("The continuous property " + getUuid() + " cannot be associated to a resqml property kind \"" + pkName + "\" which does not derive from the continuous standard property kind. This property will be assumed to be a partial one."); changeToPartialObject(); return false; } } else { repository->addWarning("Cannot verify if the resqml property kind \"" + pkName + "\" of the continuous property " + getUuid() + " is right because no property kind mapping files have been loaded."); } return true; }
; A293673: a(n) is the integer k that minimizes |k/Fibonacci(n) - 4/5|. ; 0,1,1,2,2,4,6,10,17,27,44,71,115,186,302,488,790,1278,2067,3345,5412,8757,14169,22926,37094,60020,97114,157134,254249,411383,665632,1077015,1742647,2819662,4562310,7381972,11944282,19326254,31270535,50596789,81867324,132464113,214331437,346795550,561126986,907922536,1469049522,2376972058,3846021581,6222993639,10069015220,16292008859,26361024079,42653032938,69014057018,111667089956,180681146974,292348236930,473029383903,765377620833,1238407004736,2003784625569,3242191630305,5245976255874,8488167886178,13734144142052,22222312028230,35956456170282,58178768198513,94135224368795,152313992567308,246449216936103,398763209503411,645212426439514,1043975635942926,1689188062382440,2733163698325366,4422351760707806,7155515459033171,11577867219740977,18733382678774148,30311249898515125,49044632577289273,79355882475804398,128400515053093670,207756397528898068,336156912581991738,543913310110889806,880070222692881545,1423983532803771351,2304053755496652896,3728037288300424247,6032091043797077143,9760128332097501390,15792219375894578534,25552347707992079924,41344567083886658458,66896914791878738382,108241481875765396839,175138396667644135221 seq $0,22087 ; Fibonacci sequence beginning 0, 4. add $0,2 div $0,5
#pragma once #include <memory> #include <functional> #include "IUnsubscribable.hpp" #include "Observers/IErrorObserver.hpp" namespace cm { using OnError = std::function<void(const std::exception &)>; struct IErrorObservable { using Ptr = std::shared_ptr<IErrorObservable>; virtual IUnsubscribable::Ptr subscribe(const OnError &onError) = 0; virtual IUnsubscribable::Ptr subscribe(IErrorObserver &observer) = 0; virtual ~IErrorObservable() {} }; }
; A037644: Base 9 digits are, in order, the first n terms of the periodic sequence with initial period 2,3,1. ; Submitted by Jon Maiga ; 2,21,190,1712,15411,138700,1248302,11234721,101112490,910012412,8190111711,73711005400,663399048602,5970591437421,53735322936790,483617906431112,4352561157880011,39173050420920100,352557453788280902,3173017084094528121 mov $2,1 lpb $0 sub $0,1 add $2,1 add $1,$2 mul $1,9 mod $2,3 lpe add $1,$2 mov $0,$1 add $0,1
/**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the Qt Linguist of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 or version 3 as published by the Free ** Software Foundation and appearing in the file LICENSE.LGPLv21 and ** LICENSE.LGPLv3 included in the packaging of this file. Please review the ** following information to ensure the GNU Lesser General Public License ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** As a special exception, The Qt Company gives you certain additional ** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include <QtTest/QtTest> #include <QtCore/QFile> class tst_lconvert : public QObject { Q_OBJECT public: tst_lconvert() : dataDir(QFINDTESTDATA("data/")) , lconvert(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/lconvert") {} private slots: void initTestCase(); void readverifies_data(); void readverifies(); void converts_data(); void converts(); void roundtrips_data(); void roundtrips(); #if 0 void chains_data(); void chains(); #endif void merge(); private: void doWait(QProcess *cvt, int stage); void doCompare(QIODevice *actual, const QString &expectedFn); void verifyReadFail(const QString &fn); // args can be empty or have one element less than stations void convertChain(const QString &inFileName, const QString &outFileName, const QStringList &stations, const QList<QStringList> &args); void convertRoundtrip(const QString &fileName, const QStringList &stations, const QList<QStringList> &args); QString dataDir; QString lconvert; }; void tst_lconvert::initTestCase() { if (!QFile::exists(dataDir + QLatin1String("plural-1.po"))) QProcess::execute(QLatin1String("perl"), QStringList() << dataDir + QLatin1String("makeplurals.pl") << dataDir + QLatin1String("")); QVERIFY(QFile::exists(dataDir + QLatin1String("plural-1.po"))); } void tst_lconvert::doWait(QProcess *cvt, int stage) { if (QTest::currentTestFailed()) { cvt->kill(); cvt->waitForFinished(); } else { QVERIFY2(cvt->waitForFinished(3000), qPrintable(QString("Process %1 hung").arg(stage))); QVERIFY2(cvt->exitStatus() == QProcess::NormalExit, qPrintable(QString("Process %1 crashed").arg(stage))); QVERIFY2(cvt->exitCode() == 0, qPrintable(QString("Process %1 exited with status %2. Errors:\n%3") .arg(stage).arg(cvt->exitCode()) .arg(QString::fromUtf8(cvt->readAllStandardError())))); } } void tst_lconvert::doCompare(QIODevice *actualDev, const QString &expectedFn) { QList<QByteArray> actual = actualDev->readAll().split('\n'); QFile file(expectedFn); QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); QList<QByteArray> expected = file.readAll().split('\n'); int i = 0, ei = expected.size(), gi = actual.size(); for (; ; i++) { if (i == gi) { if (i == ei) return; gi = 0; break; } else if (i == ei) { ei = 0; break; } else if (actual.at(i) != expected.at(i)) { while ((ei - 1) >= i && (gi - 1) >= i && actual.at(gi - 1) == expected.at(ei - 1)) ei--, gi--; break; } } QByteArray diff; for (int j = qMax(0, i - 3); j < i; j++) diff += expected.at(j) + '\n'; diff += "<<<<<<< got\n"; for (int j = i; j < gi; j++) { diff += actual.at(j) + '\n'; if (j >= i + 5) { diff += "...\n"; break; } } diff += "=========\n"; for (int j = i; j < ei; j++) { diff += expected.at(j) + '\n'; if (j >= i + 5) { diff += "...\n"; break; } } diff += ">>>>>>> expected\n"; for (int j = ei; j < qMin(ei + 3, expected.size()); j++) diff += expected.at(j) + '\n'; QFAIL(qPrintable("Output for " + expectedFn + " does not meet expectations:\n" + diff)); } void tst_lconvert::verifyReadFail(const QString &fn) { QProcess cvt; cvt.start(lconvert, QStringList() << (dataDir + fn)); QVERIFY(cvt.waitForFinished(10000)); QVERIFY(cvt.exitStatus() == QProcess::NormalExit); QVERIFY2(cvt.exitCode() == 2, "Accepted invalid input"); } void tst_lconvert::convertChain(const QString &_inFileName, const QString &_outFileName, const QStringList &stations, const QList<QStringList> &argList) { QList<QProcess *> cvts; QString fileName = dataDir + _inFileName; QString outFileName = dataDir + _outFileName; for (int i = 0; i < stations.size() - 1; i++) { QProcess *cvt = new QProcess(this); if (cvts.isEmpty()) cvt->setStandardInputFile(fileName); else cvts.last()->setStandardOutputProcess(cvt); cvts.append(cvt); } for (int i = 0; i < stations.size() - 1; i++) { QStringList args; if (!argList.isEmpty()) args += argList[i]; args << "-if" << stations[i] << "-i" << "-" << "-of" << stations[i + 1]; cvts.at(i)->start(lconvert, args, QIODevice::ReadWrite | QIODevice::Text); } int st = 0; foreach (QProcess *cvt, cvts) doWait(cvt, ++st); if (!QTest::currentTestFailed()) doCompare(cvts.last(), outFileName); qDeleteAll(cvts); } void tst_lconvert::convertRoundtrip(const QString &_fileName, const QStringList &stations, const QList<QStringList> &argList) { convertChain(_fileName, _fileName, stations, argList); } void tst_lconvert::readverifies_data() { QTest::addColumn<QString>("fileName"); QTest::addColumn<QString>("format"); QTest::newRow("ts") << "test20.ts" << "ts"; QTest::newRow("empty comment") << "test-empty-comment.po" << "po"; QTest::newRow("translator comment") << "test-translator-comment.po" << "po"; QTest::newRow("developer comment") << "test-developer-comment.po" << "po"; QTest::newRow("kde context") << "test-kde-ctxt.po" << "po"; QTest::newRow("kde fuzzy") << "test-kde-fuzzy.po" << "po"; QTest::newRow("kde plurals") << "test-kde-plurals.po" << "po"; QTest::newRow("kde multiline") << "test-kde-multiline.po" << "po"; QTest::newRow("po linewrapping") << "wrapping.po" << "po"; QTest::newRow("relative locations") << "relative.ts" << "ts"; QTest::newRow("message ids") << "msgid.ts" << "ts"; QTest::newRow("length variants") << "variants.ts" << "ts"; QTest::newRow("qph") << "phrasebook.qph" << "qph"; } void tst_lconvert::readverifies() { QFETCH(QString, fileName); QFETCH(QString, format); convertRoundtrip(fileName, QStringList() << format << format, QList<QStringList>()); } void tst_lconvert::converts_data() { QTest::addColumn<QString>("inFileName"); QTest::addColumn<QString>("outFileName"); QTest::addColumn<QString>("format"); QTest::newRow("broken utf8") << "test-broken-utf8.po" << "test-broken-utf8.po.out" << "po"; QTest::newRow("line joins") << "test-slurp.po" << "test-slurp.po.out" << "po"; QTest::newRow("escapes") << "test-escapes.po" << "test-escapes.po.out" << "po"; } void tst_lconvert::converts() { QFETCH(QString, inFileName); QFETCH(QString, outFileName); QFETCH(QString, format); QString outFileNameFq = dataDir + outFileName; QProcess cvt; cvt.start(lconvert, QStringList() << "-i" << (dataDir + inFileName) << "-of" << format, QIODevice::ReadWrite | QIODevice::Text); doWait(&cvt, 0); if (QTest::currentTestFailed()) return; doCompare(&cvt, outFileNameFq); } Q_DECLARE_METATYPE(QList<QStringList>); #if 0 void tst_lconvert::chains_data() { QTest::addColumn<QString>("inFileName"); QTest::addColumn<QString>("outFileName"); QTest::addColumn<QStringList>("stations"); QTest::addColumn<QList<QStringList> >("args"); } void tst_lconvert::chains() { QFETCH(QString, inFileName); QFETCH(QString, outFileName); QFETCH(QStringList, stations); QFETCH(QList<QStringList>, args); convertChain(inFileName, outFileName, stations, args); } #endif void tst_lconvert::roundtrips_data() { QTest::addColumn<QString>("fileName"); QTest::addColumn<QStringList>("stations"); QTest::addColumn<QList<QStringList> >("args"); QStringList poTsPo; poTsPo << "po" << "ts" << "po"; QStringList poXlfPo; poXlfPo << "po" << "xlf" << "po"; QStringList tsPoTs; tsPoTs << "ts" << "po" << "ts"; QStringList tsXlfTs; tsXlfTs << "ts" << "xlf" << "ts"; QStringList tsQmTs; tsQmTs << "ts" << "qm" << "ts"; QList<QStringList> noArgs; QList<QStringList> filterPoArgs; filterPoArgs << QStringList() << (QStringList() << "-drop-tag" << "po:*"); QList<QStringList> outDeArgs; outDeArgs << QStringList() << (QStringList() << "-target-language" << "de"); QList<QStringList> outCnArgs; outCnArgs << QStringList() << (QStringList() << "-target-language" << "cn"); QTest::newRow("po-ts-po (translator comment)") << "test-translator-comment.po" << poTsPo << noArgs; QTest::newRow("po-xliff-po (translator comment)") << "test-translator-comment.po" << poXlfPo << noArgs; QTest::newRow("po-ts-po (developer comment)") << "test-developer-comment.po" << poTsPo << noArgs; QTest::newRow("po-xliff-po (developer comment)") << "test-developer-comment.po" << poXlfPo << noArgs; QTest::newRow("ts20-po-ts20") << "test20.ts" << tsPoTs << filterPoArgs; QTest::newRow("po-ts-po (de)") << "test1-de.po" << poTsPo << noArgs; QTest::newRow("po-ts-po (cn)") << "test1-cn.po" << poTsPo << noArgs; QTest::newRow("po-xliff-po (de)") << "test1-de.po" << poXlfPo << noArgs; QTest::newRow("po-xliff-po (cn)") << "test1-cn.po" << poXlfPo << noArgs; QTest::newRow("po-ts-po (singular)") << "singular.po" << poTsPo << noArgs; QTest::newRow("po-ts-po (plural-1)") << "plural-1.po" << poTsPo << noArgs; QTest::newRow("po-ts-po (plural-2)") << "plural-2.po" << poTsPo << noArgs; QTest::newRow("po-ts-po (plural-3)") << "plural-3.po" << poTsPo << noArgs; QTest::newRow("po-xliff-po (singular)") << "singular.po" << poXlfPo << noArgs; QTest::newRow("po-xliff-po (plural-1)") << "plural-1.po" << poXlfPo << noArgs; QTest::newRow("po-xliff-po (plural-2)") << "plural-2.po" << poXlfPo << noArgs; QTest::newRow("po-xliff-po (plural-3)") << "plural-3.po" << poXlfPo << noArgs; QTest::newRow("po-ts-po (references)") << "test-refs.po" << poTsPo << noArgs; QTest::newRow("ts-qm-ts (plurals-de)") << "plurals-de.ts" << tsQmTs << outDeArgs; QTest::newRow("ts-qm-ts (plurals-cn)") << "plurals-cn.ts" << tsQmTs << outCnArgs; QTest::newRow("ts-qm-ts (variants)") << "variants.ts" << tsQmTs << outDeArgs; QTest::newRow("ts-po-ts (msgid)") << "msgid.ts" << tsPoTs << noArgs; QTest::newRow("ts-xliff-ts (msgid)") << "msgid.ts" << tsXlfTs << noArgs; QTest::newRow("ts-po-ts (endless loop)") << "endless-po-loop.ts" << tsPoTs << noArgs; } void tst_lconvert::roundtrips() { QFETCH(QString, fileName); QFETCH(QStringList, stations); QFETCH(QList<QStringList>, args); convertRoundtrip(fileName, stations, args); } void tst_lconvert::merge() { QProcess cvt; QStringList args; args << (dataDir + "idxmerge.ts") << (dataDir + "idxmerge-add.ts"); cvt.start(lconvert, args, QIODevice::ReadWrite | QIODevice::Text); doWait(&cvt, 1); if (!QTest::currentTestFailed()) doCompare(&cvt, dataDir + "idxmerge.ts.out"); } QTEST_APPLESS_MAIN(tst_lconvert) #include "tst_lconvert.moc"
@R2 M=0 (LOOP) @R1 D=M; @END D;JEQ @R0 D=M @R2 M=D+M @R1 M=M-1 @LOOP 0;JMP (END) @END 0;JMP
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r13 push %r15 push %r8 push %rax push %rcx push %rdi push %rsi lea addresses_WC_ht+0x13bf, %rsi lea addresses_WT_ht+0x18717, %rdi nop nop nop nop nop inc %rax mov $76, %rcx rep movsb nop nop nop nop nop add $29566, %r15 lea addresses_WT_ht+0xbb17, %rsi lea addresses_WC_ht+0x12041, %rdi nop sub %r15, %r15 mov $45, %rcx rep movsb xor %rsi, %rsi lea addresses_WT_ht+0x13617, %r12 sub %r13, %r13 movw $0x6162, (%r12) nop nop nop nop add $39849, %r12 lea addresses_A_ht+0x12907, %rsi lea addresses_WT_ht+0xac03, %rdi nop nop nop nop add %r8, %r8 mov $6, %rcx rep movsq nop nop nop nop dec %rdi lea addresses_WC_ht+0xe4e7, %r15 nop and $61222, %r12 and $0xffffffffffffffc0, %r15 vmovntdqa (%r15), %ymm4 vextracti128 $1, %ymm4, %xmm4 vpextrq $1, %xmm4, %rsi nop xor $46611, %r13 lea addresses_D_ht+0x1da29, %rsi lea addresses_normal_ht+0x19e17, %rdi nop nop nop nop nop and %r8, %r8 mov $15, %rcx rep movsw and %rsi, %rsi pop %rsi pop %rdi pop %rcx pop %rax pop %r8 pop %r15 pop %r13 pop %r12 ret .global s_faulty_load s_faulty_load: push %r14 push %r9 push %rax push %rbx push %rdi push %rdx push %rsi // Load lea addresses_US+0xbe57, %r9 nop nop nop inc %rax vmovaps (%r9), %ymm3 vextracti128 $0, %ymm3, %xmm3 vpextrq $0, %xmm3, %rsi nop nop nop nop nop sub $10522, %rax // Faulty Load mov $0x5900a40000000e17, %rbx cmp $9921, %rdx mov (%rbx), %esi lea oracles, %r9 and $0xff, %rsi shlq $12, %rsi mov (%r9,%rsi,1), %rsi pop %rsi pop %rdx pop %rdi pop %rbx pop %rax pop %r9 pop %r14 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_NC', 'same': False, 'size': 32, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_US', 'same': False, 'size': 32, 'congruent': 6, 'NT': False, 'AVXalign': True}, 'OP': 'LOAD'} [Faulty Load] {'src': {'type': 'addresses_NC', 'same': True, 'size': 4, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_WC_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_WT_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': True}, 'OP': 'REPM'} {'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 2, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_A_ht', 'congruent': 3, 'same': True}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_WC_ht', 'same': True, 'size': 32, 'congruent': 1, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_D_ht', 'congruent': 1, 'same': True}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}, 'OP': 'REPM'} {'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 */
; A033353: a(n) = floor(33/n). ; 33,16,11,8,6,5,4,4,3,3,3,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 add $0,1 mov $1,33 div $1,$0 mov $0,$1
; A048509: a(n) = T(4,n), array T given by A048505. ; 1,26,87,233,577,1377,3217,7409,16881,38129,85489,190449,421873,929777,2039793,4456433,9699313,21037041,45481969,98041841,210763761,451936241,966787057,2063597553,4395630577,9344909297,19830669297,42010148849,88852135921,187636383729,395673862129,833223655409,1752346656753,3680786972657,7722351198193,16183436771313,33878702030833,70849780514801,148021752889329,308962767405041,644313813876721,1342503697514481,2794958557806577,5814217487679473 add $0,5 mov $1,$0 add $0,1 add $1,3 bin $1,2 lpb $0,1 sub $0,1 mul $1,2 add $1,$0 lpe add $1,1 mul $1,2 sub $1,4102 div $1,256 add $1,1
; $Revision: 9.0 $ include rules.asi Header@ DENOM EQU 0 NUMER EQU 12 PREV_CW EQU 28 ; 24 + 4 (return size) PATCH_CW EQU 32 ; 28 + 4 (return size) MAIN_DENOM EQU 4 MAIN_NUMER EQU 16 STACK_SIZE EQU 44 ONESMASK EQU 0e000000h fdivp_sti MACRO reg_index, reg_index_minus1 fstp tbyte ptr [esp+DENOM] IF reg_index_minus1 GE 1 fxch st(reg_index_minus1) ENDIF fstp tbyte ptr [esp+NUMER] call fdiv_main_routine IF reg_index_minus1 GE 1 fxch st(reg_index_minus1) ENDIF add esp, STACK_SIZE ENDM Data_seg@ fdiv_risc_table DB 0, 1, 0, 0, 4, 0, 0, 7, 0, 0, 10, 0, 0, 13, 0, 0 fdiv_scale_1 DD 03f700000h ;0.9375 fdiv_scale_2 DD 03f880000h ;1.0625 one_shl_63 DD 05f000000h ; ; This is the flag that is tested by all the compiler branches ; before the divide instruction. ; ; 0 = unknown whether running on a part with the flaw ; 1 = running on a part with no flaw ; -1= running on a part with the flaw ; public __fdivflag __fdivflag DD 0h ; ; The following are initializers for known values that cause ; the divide problem. ; test_dividend DB 0,0,0,0c0h,07eh,01h,050h,041h ; x = 4195835.0 test_divisor DB 0,0,0,080h,0ffh,0ffh,047h,041h ; y = 3145727.0 one DB 0,0,0,0,0,0,0f0h,03fh Data_EndS@ Code_seg@ fdiv_main_routine PROC NEAR fld tbyte ptr [esp+MAIN_NUMER] ; load the numerator fld tbyte ptr [esp+MAIN_DENOM] ; load the denominator retry: ; The following three lines test for denormals and zeros. ; A denormal or zero has a 0 in the explicit digit to the left of the ; binary point. Since that bit is the high bit of the word, adding ; it to itself will produce a carry if and only if the number is not ; denormal or zero. ; mov eax, [esp+MAIN_DENOM+4] ; get mantissa bits 32-64 add eax,eax ; shift the one's bit onto carry jnc denormal ; if no carry, we're denormal ; The following three lines test the three bits after the four bit ; pattern (1,4,7,a,d). If these three bits are not all one, then ; the denominator cannot expose the flaw. This condition is tested by ; inverting the bits and testing that all are equal to zero afterward. xor eax, ONESMASK ; invert the bits that must be ones test eax, ONESMASK ; and make sure they are all ones jz scale_if_needed ; if all are one scale numbers fdivp st(1), st ; use of hardware is OK. ret ; ; Now we test the four bits for one of the five patterns. ; scale_if_needed: shr eax, 28 ; keep first 4 bits after point cmp byte ptr fdiv_risc_table[eax], 0 ; check for (1,4,7,a,d) jnz divide_scaled ; are in potential problem area fdivp st(1), st ; use of hardware is OK. ret divide_scaled: mov eax, [esp + MAIN_DENOM+8] ; test denominator exponent and eax, 07fffh ; if pseudodenormal ensure that only jz invalid_denom ; invalid exception flag is set cmp eax, 07fffh ; if NaN or infinity ensure that only je invalid_denom ; invalid exception flag is set ; ; The following six lines turn off exceptions and set the ; precision control to 80 bits. The former is necessary to ; force any traps to be taken at the divide instead of the scaling ; code. The latter is necessary in order to get full precision for ; codes with incoming 32 and 64 bit precision settings. If ; it can be guaranteed that before reaching this point, the underflow ; exception is masked and the precision control is at 80 bits, these ; six lines can be omitted. ; fnstcw [esp+PREV_CW] ; save caller's control word mov eax, [esp+PREV_CW] or eax, 033fh ; mask exceptions, pc=80 and eax, 0f3ffh ; set rounding mode to nearest mov [esp+PATCH_CW], eax fldcw [esp+PATCH_CW] ; mask exceptions & pc=80 ; The following lines check the numerator exponent before scaling. ; This in order to prevent undeflow when scaling the numerator, ; which will cause a denormal exception flag to be set when the ; actual divide is preformed. This flag would not have been set ; normally. If there is a risk of underflow, the scale factor is ; 17/16 instead of 15/16. ; mov eax, [esp+MAIN_NUMER+8] ; test numerator exponent and eax, 07fffh cmp eax, 00001h je small_numer fmul fdiv_scale_1 ; scale denominator by 15/16 fxch fmul fdiv_scale_1 ; scale numerator by 15/16 fxch ; ; The next line restores the users control word. If the incoming ; control word had the underflow exception masked and precision ; control set to 80 bits, this line can be omitted. ; fldcw [esp+PREV_CW] ; restore caller's control word fdivp st(1), st ; use of hardware is OK. ret small_numer: fmul fdiv_scale_2 ; scale denominator by 17/16 fxch fmul fdiv_scale_2 ; scale numerator by 17/16 fxch ; ; The next line restores the users control word. If the incoming ; control word had the underflow exception masked and precision ; control set to 80 bits, this line can be omitted. ; fldcw [esp+PREV_CW] ; restore caller's control word fdivp st(1), st ; use of hardware is OK. ret denormal: mov eax, [esp+MAIN_DENOM] ; test for whole mantissa == 0 or eax, [esp+MAIN_DENOM+4] ; test for whole mantissa == 0 jnz denormal_divide_scaled ; denominator is not zero invalid_denom: ; zero or invalid denominator fdivp st(1), st ; use of hardware is OK. ret denormal_divide_scaled: mov eax, [esp + MAIN_DENOM + 8] ; get exponent and eax, 07fffh ; check for zero exponent jnz invalid_denom ; ; ; The following six lines turn off exceptions and set the ; precision control to 80 bits. The former is necessary to ; force any traps to be taken at the divide instead of the scaling ; code. The latter is necessary in order to get full precision for ; codes with incoming 32 and 64 bit precision settings. If ; it can be guaranteed that before reaching this point, the underflow ; exception is masked and the precision control is at 80 bits, these ; six lines can be omitted. ; fnstcw [esp+PREV_CW] ; save caller's control word mov eax, [esp+PREV_CW] or eax, 033fh ; mask exceptions, pc=80 and eax, 0f3ffh ; set rounding mode to nearest mov [esp+PATCH_CW], eax fldcw [esp+PATCH_CW] ; mask exceptions & pc=80 mov eax, [esp + MAIN_NUMER +8] ; test numerator exponent and eax, 07fffh ; check for denormal numerator je denormal_numer cmp eax, 07fffh ; NaN or infinity je invalid_numer mov eax, [esp + MAIN_NUMER + 4] ; get bits 32..63 of mantissa add eax, eax ; shift the first bit into carry jnc invalid_numer ; if there is no carry, we have an ; invalid numer jmp numer_ok denormal_numer: mov eax, [esp + MAIN_NUMER + 4] ; get bits 32..63 of mantissa add eax, eax ; shift the first bit into carry jc invalid_numer ; if there is a carry, we have an ; invalid numer numer_ok: fxch fstp st ; pop numerator fld st ; make copy of denominator fmul dword ptr[one_shl_63] ; make denominator not denormal fstp tbyte ptr [esp+MAIN_DENOM] ; save modified denominator fld tbyte ptr [esp+MAIN_NUMER] ; load numerator fxch ; restore proper order fwait ; The next line restores the users control word. If the incoming ; control word had the underflow exception masked and precision ; control set to 80 bits, this line can be omitted. ; fldcw [esp+PREV_CW] ; restore caller's control word jmp retry ; start the whole thing over invalid_numer: ; ; The next line restores the users control word. If the incoming ; control word had the underflow exception masked and precision ; control set to 80 bits, this line can be omitted. ; fldcw [esp + PREV_CW] fdivp st(1), st ; use of hardware is OK. ret fdiv_main_routine ENDP ;; Performs an fdivp st(1),st public __fdiv __fdiv PROC NEAR push eax sub esp, STACK_SIZE fdivp_sti 1 0 ; Macro cleans up stack pop eax ret __fdiv ENDP ; ; int fdiv_detect(void) ; FDIV_DETECT PROC NEAR fld qword ptr [test_dividend] fwait fdiv qword ptr [test_divisor] ; no_error = ((x - (x / y)*y) < 1.0 fwait fmul qword ptr [test_divisor] fwait fsubr qword ptr [test_dividend] fwait fcomp qword ptr [one] fwait fstsw ax fwait and eax, 0100h ; 0: uninitialized shr eax, 7 sub eax, 1 mov __fdivflag, eax ret FDIV_DETECT ENDP Code_EndS@ Init_seg@ db 0 ; near call db 1 ; priority 1 dd offset FDIV_DETECT Init_EndS@ end
; --------------------------------------------------------------------------- ; Sprite mappings - waterfalls (LZ) ; --------------------------------------------------------------------------- Map_WFall_internal: dc.w @vertnarrow-Map_WFall_internal dc.w @cornerwide-Map_WFall_internal dc.w @cornermedium-Map_WFall_internal dc.w @cornernarrow-Map_WFall_internal dc.w @cornermedium2-Map_WFall_internal dc.w @cornernarrow2-Map_WFall_internal dc.w @cornernarrow3-Map_WFall_internal dc.w @vertwide-Map_WFall_internal dc.w @diagonal-Map_WFall_internal dc.w @splash1-Map_WFall_internal dc.w @splash2-Map_WFall_internal dc.w @splash3-Map_WFall_internal @vertnarrow: dc.b 1 dc.b $F0, 7, 0, 0, $F8 @cornerwide: dc.b 2 dc.b $F8, 4, 0, 8, $FC dc.b 0, 8, 0, $A, $F4 @cornermedium: dc.b 2 dc.b $F8, 0, 0, 8, 0 dc.b 0, 4, 0, $D, $F8 @cornernarrow: dc.b 1 dc.b $F8, 1, 0, $F, 0 @cornermedium2: dc.b 2 dc.b $F8, 0, 0, 8, 0 dc.b 0, 4, 0, $D, $F8 @cornernarrow2: dc.b 1 dc.b $F8, 1, 0, $11, 0 @cornernarrow3: dc.b 1 dc.b $F8, 1, 0, $13, 0 @vertwide: dc.b 1 dc.b $F0, 7, 0, $15, $F8 @diagonal: dc.b 2 dc.b $F8, $C, 0, $1D, $F6 dc.b 0, $C, 0, $21, $E8 @splash1: dc.b 2 dc.b $F0, $B, 0, $25, $E8 dc.b $F0, $B, 0, $31, 0 @splash2: dc.b 2 dc.b $F0, $B, 0, $3D, $E8 dc.b $F0, $B, 0, $49, 0 @splash3: dc.b 2 dc.b $F0, $B, 0, $55, $E8 dc.b $F0, $B, 0, $61, 0 even
#pragma once #include <string> namespace CaptainAsteroidCPP { namespace Def { // Enums and Struct used by API to Unity enum GameState : std::uint32_t { GS_Start = 1 << 0, GS_Playing = 1 << 1, GS_GameOver = 1 << 2, GS_Victory = 1 << 3, }; enum EntityType : std::uint32_t { Asteroid_XXL = 1 << 0, Asteroid_M = 1 << 1, Asteroid_S = 1 << 2, LaserShot = 1 << 3, }; struct InitParams { float boundaryDomainV; float boundaryDomainH; int initNbAsteroidsXXL; int initNbAsteroidsM; int initNbAsteroidsS; int maxNbAsteroidsByType; }; struct KeyState { enum class Keys : std::uint32_t { Left = 1 << 0, Right = 1 << 1, Up = 1 << 2, Down = 1 << 3, Space = 1 << 4, }; std::uint32_t State; inline bool pressed(Keys key) const { return (State & (std::uint32_t)key) != 0; } }; constexpr float PI = 3.14159274101257324219; }// namespace Def }// namespace CaptainAsteroidCPP
SECTION code_fp_math32 PUBLIC ___fssub_callee EXTERN cm32_sdcc_fssub_callee defc ___fssub_callee = cm32_sdcc_fssub_callee
.code ; int Core_Math_Sum_(int a, int b) Core_Math_Sum_ proc add ecx, edx mov eax, ecx ret Core_Math_Sum_ endp ; int Core_Math_Div_(int a, int b, int* quotient, int* remainder) Core_Math_Div_ proc ; Error if < 0 cmp edx, 0 je InvalidDivisor mov r10d, edx ; Backup the divisor value mov eax, ecx ; Convert an int stored in eax to long, where: ; eax: contains least significant bits (32 bits) ; edx: contains most significant bits (32 bits) {that's the reason for the backup above} cdq ; Divides eax by the operand and place: ; quotient: eax ; remainder: edx idiv r10d mov dword ptr [r8], eax mov dword ptr [r9], edx mov eax, 1 ret InvalidDivisor: xor eax, eax ret Core_Math_Div_ endp end
//------------------------------------------------------------------------------ // Copyright 2007-2011 by Jyh-Ming Lien and George Mason University // See the file "LICENSE" for more information //------------------------------------------------------------------------------ #include "polygon.h" #include "intersection.h" #include "bpc.h" #include <vector> namespace masc { namespace polygon { ply_vertex * ply_vertex_extra::getDihedralPre() { assert(other_v); //comment by Guilin //assert(isPM()); return other_v->getPre()->getExtra().other_v; } ply_vertex * ply_vertex_extra::getDihedralNext() { assert(other_v); //comment by Guilin //assert(isPM()); return other_v->getNext()->getExtra().other_v; } // //ply_vertex * ply_vertex_extra::getDihedralPre(){ // assert(concavity_bpc); // ply_vertex * v=concavity_bpc->getConcavity(); // for(short i=0;i<4;i++) v=v->getPre(); // return v; //} //ply_vertex * ply_vertex_extra::getDihedralNext(){ // assert(concavity_bpc); // ply_vertex * v=concavity_bpc->getConcavity(); // for(short i=0;i<4;i++) v=v->getNext(); // return v; //} ply_vertex::~ply_vertex() { //doing nothing for now } // - compute normal // - check if the vertex is reflex or not void ply_vertex::computeExtraInfo() { reflex=true; //compute normal direction if(next!=NULL){ Vector2d v=next->pos-pos; if( v[0]==0 ){ if(v[1]>0){ normal[0]=1; normal[1]=0; } else{ normal[0]=-1; normal[1]=0; } } else if( v[0]>0 ){ normal[1]=-1; normal[0]=(v[1]/v[0]); } else{//v[0]<0 normal[1]=1; normal[0]=-(v[1]/v[0]); } normal=normal.normalize(); if(pre!=NULL){ //compute if left or right turn Vector2d u=pos-pre->pos; float z=u[0]*v[1]-u[1]*v[0]; if(z>0) reflex=false; } }//end if(next!=NULL) } void ply_vertex::negate() { normal=-normal; pos[0]=-pos[0]; pos[1]=-pos[1]; } void ply_vertex::reverse() { swap(next,pre); //normal=-normal; computeExtraInfo(); } void ply_vertex::copy(ply_vertex * other) { pos=other->pos; normal=other->normal; reflex=other->reflex; vid=other->vid; } void ply_vertex::rotate(double r) { double cos_r=cos(r); double sin_r=sin(r); //rotate pos double x=pos[0]*cos_r-pos[1]*sin_r; double y=pos[0]*sin_r+pos[1]*cos_r; pos.set(x,y); //rotate normal x=normal[0]*cos_r-normal[1]*sin_r; y=normal[0]*sin_r+normal[1]*cos_r; normal.set(x,y); } float ply_vertex::distanceTo(ply_vertex* other) { if(other == NULL) assert(false); return (this->pos - other->pos).norm(); } /////////////////////////////////////////////////////////////////////////////// //copy from the given ply void c_ply::copy(const c_ply& other) { destroy();//detroy myself first ply_vertex* ptr=other.head; beginPoly(); do{ ply_vertex * v=new ply_vertex(); assert(v); //check for memory v->copy(ptr); addVertex(v); ptr=ptr->getNext(); }while( ptr!=other.head ); //endPoly(); //finish up tail->setNext(head); //copy extra info area=other.area; center=other.center; radius=other.radius; type=other.type; } // clean up the space allocated void c_ply::destroy() { if( head==NULL ) return; ply_vertex* ptr=head; do{ ply_vertex * n=ptr->getNext(); delete ptr; ptr=n; } while( ptr!=head && ptr!=NULL); head=tail=NULL; all.clear(); } // Create a empty polygon void c_ply::beginPoly() { head=tail=NULL; all.clear(); } // Add a vertex to the polygonal chian ply_vertex * c_ply::addVertex( double x, double y, bool remove_duplicate ) { Point2d pt(x,y); if(tail!=NULL){ if(tail->getPos()==pt && remove_duplicate){ cout<<"duplicated vertex"<<endl; return NULL; //don't add } } ply_vertex * v=new ply_vertex(pt); if( tail!=NULL ){ tail->setNext(v); } tail=v; if( head==NULL ) head=tail; v->setVID(all.size()); //id of the vertex in this ply all.push_back(v); return v; } // Add a vertex to the polygonal chian ply_vertex * c_ply::addVertex( ply_vertex * v ) { if( tail!=NULL ){ tail->setNext(v); } tail=v; if( head==NULL ) head=tail; v->setVID(all.size()); //id of the vertex in this ply all.push_back(v); return v; } // finish building the polygon void c_ply::endPoly(bool remove_duplicate) { if(head!=NULL && tail!=NULL){ if(remove_duplicate){ if(head->getPos()==tail->getPos()){ //remove tail.. delete tail; all.pop_back(); tail=all.back(); } }// } tail->setNext(head); doInit(); } // initialize property of the this polychain // Compute normals and find reflective vertices bool c_ply::doInit() { bool b = true; //compute area getArea(); if(this->area<0 && type==POUT){ //cerr<<"! Warning: polygon type is POUT but has negative area. Reverse the vertex ordering."<<endl; reverse(); b = false; } else if(this->area>0 && type==PIN){ //cerr<<"! Warning: polygon type is PIN but has positive area. Reverse the vertex ordering."<<endl; reverse(); b = false; } //compute normals ply_vertex* ptr=head; do{ ptr->computeExtraInfo(); ptr=ptr->getNext(); }while( ptr!=head ); return b; } const Point2d& c_ply::getCenter() { if(radius<0){ center.set(0,0); ply_vertex * ptr=head; const Point2d& first=ptr->getPos(); uint size=0; do{ size++; Vector2d v=ptr->getPos()-first; center[0]+=v[0]; center[1]+=v[1]; ptr=ptr->getNext(); }while(ptr!=head); //end while center[0]=(center[0]/size)+first[0]; center[1]=(center[1]/size)+first[1]; radius=0; } return center; } /////////////////////////////////////////////////////////////////////////// void c_ply::negate() { ply_vertex * ptr=head; do{ ptr->negate(); ptr=ptr->getNext(); }while(ptr!=head); //end while } //reverse the order of the vertices void c_ply::reverse() { ply_vertex * ptr=head; do{ ptr->reverse(); ptr=ptr->getNext(); } while(ptr!=head); //end while this->area=-this->area; all.clear(); } void c_ply::reverseType() { reverse(); type=(type==PIN)?POUT:PIN; } /////////////////////////////////////////////////////////////////////////// void c_ply::translate(const Vector2d& v) { ply_vertex * ptr=head; do{ ptr->translate(v); ptr=ptr->getNext(); }while(ptr!=head); //end while } void c_ply::rotate(double radius) { ply_vertex * ptr=head; do{ ptr->rotate(radius); ptr=ptr->getNext(); }while(ptr!=head); //end while } /////////////////////////////////////////////////////////////////////////// //compute the Radius of the poly chain float c_ply::getRadius() { if(radius<0) getCenter(); if(radius==0){ ply_vertex * ptr=head; do{ float d=(center-ptr->getPos()).normsqr(); if(d>radius) radius=d; ptr=ptr->getNext(); }while(ptr!=head); //end while radius=sqrt(radius); } return radius; } float c_ply::getArcLength() { if (arclength == -FLT_MAX){ arclength = 0; ply_vertex * ptr = head; do{ ply_vertex * next = ptr->getNext(); const Point2d& p1 = ptr->getPos(); const Point2d& p2 = next->getPos(); arclength += (p1 - p2).norm(); ptr = next; } while (ptr != head); //end while } return arclength; } float c_ply::getArea() { if(area==-FLT_MAX){ area=0; getCenter(); ply_vertex * ptr=head; do{ ply_vertex * next=ptr->getNext(); const Point2d& p1=ptr->getPos(); const Point2d& p2=next->getPos(); area+=Area(p1.get(),p2.get(),center.get()); ptr=next; }while(ptr!=head); //end while } return area; } //check if convex bool c_ply::is_convex() const { ply_vertex * ptr=head; do{ if(ptr->isReflex()) return false; ptr=ptr->getNext(); }while(ptr!=head); //end while return true; } void c_ply::delete_vertex(ply_vertex * v) { ply_vertex *pre=v->getPre(); ply_vertex *next=v->getNext(); pre->setNext(next); next->setPre(pre); pre->computeExtraInfo(); //recompute info if(head==v){ head=next; tail=pre; } delete v; all.clear(); //not valid anymore } void c_ply::build_all() { uint vid=0; all.clear(); ply_vertex * ptr=head; do{ ptr->setVID(vid++); all.push_back(ptr); ptr=ptr->getNext(); }while(ptr!=head); //end while } void c_ply::scale(float f) { ply_vertex * ptr=head; do{ const Point2d& p = ptr->getPos(); Point2d np(p[0]*f,p[1]*f); ptr->setPos(np); ptr=ptr->getNext(); }while(ptr!=head); //end while area=-FLT_MAX; radius=-FLT_MAX; } // // Compute the center and the box of a list of plys // void c_plylist::buildBoxAndCenter() { //typedef list<c_ply>::iterator IT; box[0]=box[2]=FLT_MAX; box[1]=box[3]=-FLT_MAX; for(iterator i=begin();i!=end();i++){ ply_vertex * ptr=i->getHead(); do{ const Point2d& p=ptr->getPos(); if(p[0]<box[0]) box[0]=p[0]; if(p[0]>box[1]) box[1]=p[0]; if(p[1]<box[2]) box[2]=p[1]; if(p[1]>box[3]) box[3]=p[1]; ptr=ptr->getNext(); } while(ptr!=i->getHead()); //end while } center[0]=(box[0]+box[1])/2; center[1]=(box[2]+box[3])/2; is_buildboxandcenter_called=true; } // // Compute the center and the box of a list of plys // void c_plylist::translate(const Vector2d& v) { for(iterator i=begin();i!=end();i++) i->translate(v); } // // rotate all polychains // void c_plylist::rotate(double r) { for(iterator i=begin();i!=end();i++) i->rotate(r); } void c_plylist::negate() { for(iterator i=begin();i!=end();i++) i->negate(); } void c_polygon::reverse() { for(iterator i=begin();i!=end();i++) i->reverse(); all.clear(); } bool c_polygon::valid() //check if this is a valid polygon { typedef list<c_ply>::iterator IT; if(empty()) return false; if(front().getType()!=c_ply::POUT) return false; for(iterator i=++begin();i!=end();i++) if(i->getType()!=c_ply::PIN) return false; return true; } //copy from the given polygon void c_polygon::copy(const c_polygon& other) { clear(); all.clear(); for(const_iterator i=other.begin();i!=other.end();i++){ c_ply p(c_ply::UNKNOWN); p.copy(*i); push_back(p); } } list<c_polygon> c_polygon::split() { list<c_polygon> sub; for(iterator i=begin();i!=end();i++){ if(i->getType()==c_ply::POUT){ c_polygon tmp; tmp.push_back(*i); sub.push_back(tmp); } else{ if(sub.empty()){ cerr<<"! Error: Invalid polygon type: Holes are defined without external boundary."<<endl; continue; //can't do anything about this... } sub.back().push_back(*i); } } return sub; } void c_polygon::scale(float factor) { for(iterator i=begin();i!=end();i++) i->scale(factor); } void c_polygon::normalize() { float r=front().getRadius(); scale(1.0/r); } void c_polygon::destroy() { for(iterator i=begin();i!=end();i++){ i->destroy(); } clear(); //remove all ply from this list all.clear(); } bool c_polygon::is_convex() const { if(size()>1) return false; //contains hole return front().is_convex(); } void c_polygon::build_all() { uint vid=0; for(iterator i=begin();i!=end();i++){ uint vsize=i->getSize(); for(uint j=0;j<vsize;j++){ (*i)[j]->setVID(vid++); //id of vertex in the polygons all.push_back((*i)[j]); } }//end for i } float c_polygon::getArea() { if(area==0){ for(iterator i=begin();i!=end();i++){ area+=i->getArea(); }//end for i } return area; } float c_polygon::getArcLength() { if (arclength == 0){ for (iterator i = begin(); i != end(); i++){ arclength += i->getArcLength(); }//end for i } return arclength; } istream& operator>>( istream& is, c_ply& poly) { int vsize; string str_type; is>>vsize>>str_type; if( str_type.find("out")!=string::npos ) poly.type=c_ply::POUT; else poly.type=c_ply::PIN; poly.beginPoly(); //read in all the vertices int iv; vector< pair<double,double> > pts; pts.reserve(vsize); for( iv=0;iv<vsize;iv++ ){ double x,y; is>>x>>y; pts.push_back(pair<double,double>(x,y)); //double d=x*x+y*y; } int id; for( iv=0;iv<vsize;iv++ ){ is>>id; id=id-1; poly.addVertex(pts[id].first,pts[id].second,true); } poly.endPoly(); return is; } istream& operator>>( istream& is, c_plylist& p) { //remove header commnets do{ char tmp[1024]; char c=is.peek(); if(isspace(c)) is.get(c); //eat it else if(c=='#') { is.getline(tmp,1024); } else break; }while(true); //start reading uint size; is>>size; uint vid=0; for(uint i=0;i<size;i++){ c_ply poly(c_ply::UNKNOWN); is>>poly; p.push_back(poly); uint vsize=poly.getSize(); for(uint j=0;j<vsize;j++){ poly[j]->setVID(vid++); //id of vertex in the polygons //p.all.push_back(poly[j]); } } return is; } ostream& operator<<( ostream& os, c_ply& p) { os<<p.getSize()<<" "<<((p.type==c_ply::PIN)?"in":"out")<<"\n"; ply_vertex * ptr=p.head; do{ os<<ptr->getPos()[0]<<" "<<ptr->getPos()[1]<<"\n"; ptr=ptr->getNext(); }while(ptr!=p.head); for(int i=0;i<p.getSize();i++) os<<i+1<<" "; os<<"\n"; return os; } ostream& operator<<( ostream& out, c_plylist& p) { out<<p.size()<<"\n"; typedef c_plylist::iterator PIT; for(PIT i=p.begin();i!=p.end();i++) out<<*i; return out; } }//end namespace polygon }//end namespace masc
db 0 ; species ID placeholder db 100, 85, 60, 90, 95, 60 ; hp atk def spd sat sdf db GRASS, GRASS ; type db 45 ; catch rate db 141 ; base exp db NO_ITEM, NO_ITEM ; items db GENDER_F12_5 ; gender ratio db 100 ; unknown 1 db 20 ; step cycles to hatch db 5 ; unknown 2 INCBIN "gfx/pokemon/bayleef/front.dimensions" db 0, 0, 0, 0 ; padding db GROWTH_MEDIUM_SLOW ; growth rate dn EGG_MONSTER, EGG_PLANT ; egg groups ; tm/hm learnset tmhm HEADBUTT, CURSE, TOXIC, ROCK_SMASH, HIDDEN_POWER, SUNNY_DAY, SWEET_SCENT, SNORE, PROTECT, GIGA_DRAIN, ENDURE, FRUSTRATION, SOLARBEAM, IRON_TAIL, RETURN, MUD_SLAP, DOUBLE_TEAM, SWAGGER, SLEEP_TALK, DETECT, REST, ATTRACT, FURY_CUTTER, UPROOT, BRIGHT_MOSS ; end
# crti.s for sysv4 # Copyright (C) 1996 Free Software Foundation, Inc. # Written By Michael Meissner # # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2, or (at your option) any # later version. # # In addition to the permissions in the GNU General Public License, the # Free Software Foundation gives you unlimited permission to link the # compiled version of this file with other programs, and to distribute # those programs without any restriction coming from the use of this # file. (The General Public License restrictions do apply in other # respects; for example, they cover modification of the file, and # distribution when not linked into another program.) # # This file 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; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # # As a special exception, if you link this library with files # compiled with GCC to produce an executable, this does not cause # the resulting executable to be covered by the GNU General Public License. # This exception does not however invalidate any other reasons why # the executable file might be covered by the GNU General Public License. # # This file just supplies labeled starting points for the .got* and other # special sections. It is linked in first before other modules. .file "scrti.s" .ident "GNU C scrti.s" # Start of .text .section ".text" .globl _ex_text0 _ex_text0: # Exception range .section ".exception_ranges","aw" .globl _ex_range0 _ex_range0: # List of C++ constructors .section ".ctors","aw" .globl __CTOR_LIST__ .type __CTOR_LIST__,@object __CTOR_LIST__: # List of C++ destructors .section ".dtors","aw" .globl __DTOR_LIST__ .type __DTOR_LIST__,@object __DTOR_LIST__: # Head of _init function used for static constructors .section ".init","ax" .align 2 .globl _init .type _init,@function _init: stwu %r1,-16(%r1) mflr %r0 stw %r31,12(%r1) stw %r0,16(%r1) bl _GLOBAL_OFFSET_TABLE_-4 # get the GOT address mflr %r31 # lwz %r3,_ex_shared0@got(%r31) # lwz %r4,-8(%r3) # _ex_register or 0 # cmpi %cr0,%r4,0 # beq .Lno_reg # mtlr %r4 # blrl #.Lno_reg: # Head of _fini function used for static destructors .section ".fini","ax" .align 2 .globl _fini .type _fini,@function _fini: stwu %r1,-16(%r1) mflr %r0 stw %r31,12(%r1) stw %r0,16(%r1) bl _GLOBAL_OFFSET_TABLE_-4 # get the GOT address mflr %r31 # _environ and its evil twin environ, pointing to the environment .section ".sdata","aw" .align 2 .globl _environ .space 4 .weak environ .set environ,_environ
; A168178: a(n) = n^3*(n^2 + 1)/2. ; 0,1,20,135,544,1625,3996,8575,16640,29889,50500,81191,125280,186745,270284,381375,526336,712385,947700,1241479,1604000,2046681,2582140,3224255,3988224,4890625,5949476,7184295,8616160,10267769,12163500,14329471,16793600,19585665,22737364,26282375,30256416,34697305,39645020,45141759,51232000,57962561,65382660,73543975,82500704,92309625,103030156,114724415,127457280,141296449,156312500,172578951,190172320,209172185,229661244,251725375,275453696,300938625,328275940,357564839,388908000,422411641,458185580,496343295,537001984,580282625,626310036,675212935,727124000,782179929,840521500,902293631,967645440,1036730305,1109705924,1186734375,1267982176,1353620345,1443824460,1538774719,1638656000,1743657921,1853974900,1969806215,2091356064,2218833625,2352453116,2492433855,2639000320,2792382209,2952814500,3120537511,3295796960,3478844025,3669935404,3869333375,4077305856,4294126465,4520074580,4755435399 mov $1,$0 pow $0,5 pow $1,3 add $0,$1 div $0,2
; ------------------------------------------------------------------------------ ; memory address values ENUM $0 BASE $BC current_level: BASE $BD current_world: BASE $72 current_lives: BASE $71 game_state: ; 01 -> normal, 05 -> star-spin flying? BASE $6F game_state_b: ; bit 7: hard mode. bit 6: hell mode. BASE $D0 camera_speed: BASE $7F item_drop_counter: ; ----------------------------------------------------------------------------- ; buffer of length 0x20. First four entries are reserved for the players. BASE $200 object_ids: ; object x: BASE $4A object_x: BASE $360 object_y: BASE $2E0 object_state_a: BASE $3F0 object_state_b: ; used as a timer by skeleton BASE $300 object_state_c: BASE $2A0 object_yspeed_int: BASE $2C0 object_yspeed_frac: BASE $260 object_xspeed_int: BASE $280 object_xspeed_frac: BASE $440 object_hp: ; ------------------------------------------------------------------------------ ; music BASE $17 mus_tempo: ; number of frames between notes. BASE $18 mus_tempo_timer: ; current frame mod mus_tempo. BASE $4C4 mus_current_song: ; these are each arrays of length 6. The first 4 indices are for each channel, the second two are for sfx. ; the following two define the current "nibble" position of the track, as an offset in nibbles BASE $8000. BASE $466 mus_pattern_l: BASE $46C mus_pattern_u: ; how many tempo units to wait until proceeding to next command. BASE $472 mus_wait: ; second nibble is remaining duration this note will be held for (in frames). F means no release. BASE $478 mus_hold_duration: BASE $47E mus_note_articulation: ; the style of note articulation used. BASE $484 mus_pitch_l: ; the pitch for this note (least-significant digits) BASE $48a mus_pitch_h: ; the pitch for this note (most-significant digit) BASE $490 mus_dynamics: ; the dynamics (volume) for this note BASE $496 mus_key: ; this is transforms (adds to?) the note's pitch. Effectively, this is the "key" of the current pattern. BASE $49C mus_slide: ; this is a slide effect applied to the note BASE $4A2 mus_var8: ; number of times current "repeat" section has executed. BASE $4A8 mus_repeat_idx: ; return address for music subroutine BASE $4AE mus_reta_l: BASE $4B2 mus_reta_u: ; these are each arrays of length 4 BASE $4B2 mus_var9: ; the number of times the subroutine has repeated. BASE $4B6 mus_subrepeat_idx: ; unknown ; every note played, this resets to 0 and increments until a cap. BASE $4BA mus_varC: BASE $4C6 mus_varD: ; length not known BASE $4CA mus_varE: ; the amount of time this note has been playing so far ; every note, this resets to 0. BASE $4BE mus_note_timer: BASE $4F5 mus_varA: BASE $4F9 mus_varB: BASE $580 text_ppuAddr: ; ------------------------------------------------------------------------------ ; points to next 4 (8 when mirrored) macro-tiles. BASE $C0 level_data: ; when loading macro tiles, this value stores the seam (mirror) position. ; this address has other uses too. BASE $E3 seam_accumulator: ; these contain the minitile data per medtile. BASE $EB medtile_data_a: BASE $ED medtile_data_b: BASE $EF medtile_data_c: BASE $F1 medtile_data_d: ; ------------------------------------------------------------------------------ ; NES peripheral registers BASE $2002 PPUSTATUS: BASE $2005 PPUSCROLL: BASE $2006 PPUADDR: BASE $2007 PPUDATA: ENDE
TITLE LLSCREEN - Screen Statement Interface ;*** ;LLSCREEN - Screen Statement Interface ; ; Copyright <C> 1987, Microsoft Corporation ; ;Purpose: ; This module contains B$SCRSTT, the screen statement support routine. ; ;***************************************************************************** INCLUDE switch.inc INCLUDE rmacros.inc USESEG _DATA USESEG _BSS USESEG GR_TEXT USESEG RT_TEXT INCLUDE seg.inc INCLUDE ibmunv.inc sBegin _BSS ; Warning!!! These two bytes must be contiguous!!! staticB ModeSpec,,1 ;Set = 1 iff Mode/burst specified in SCREEN staticB PageSpec,,1 ; Set iff Act/Vis page specified in SCREEN ; Warning!!! These two bytes must be contiguous!!! staticB OldBiosMode,,1 ;old BIOS mode externW b$AlphaDim externB b$BiosMode externW b$CurPages externB b$MaxPage externW b$ModeBurst externW b$OldScrnBurst ;old Screen Mode and burst externB b$ScreenMode externB b$ScrHeight externB b$ScrWidth externW b$SetMode externW b$SetPages externW b$PalReset externB b$CurEquip sEnd sBegin _DATA externW b$CURSOR ; current cursor location sEnd sBegin RT_TEXT externNP B$FixTextPage externNP B$ChkMonitor ; set VGA monitor type sEnd sBegin GR_TEXT assumes CS,GR_TEXT externNP B$GETCSRDATA externNP B$GetParm externNP B$SCINIT externNP B$SCNCLR externNP B$SCNLOC externNP B$SCNSWI externNP B$ScreenN externNP B$OFFCSR externNP B$SetAdapter ;*** ;B$SCRSTT - SCREEN Statement parsing and execution support ;OEM-interface routine ; ;Purpose: ; This routine provides mode-independent support for the SCREEN ; statement. ; ;Syntax: ; The syntax of the IBM screen statement is: ; ; SCREEN [mode] [,[burst] [,[apage] [,vpage]]] ; ; The semantics of the statement are as follows: ; ; mode = requested BASIC screen mode ; ; burst = 0 - request black and white screen (configuration dependent) ; x - request color screen ; ; apage = desired active display page ; ; vpage = requests visual page to display ; ; These values are interpreted only in this routine, so ; an alternate set of semantics can easily be assigned. ; ;Algorithm: ; Each mode is supported in a mode-dependent module whose only ; PUBLIC symbols are of the form "B$ScreenX", where X is the ; BASIC screen mode. B$SCRSTT calls these routines to set up ; mode-dependent data and function vectors to be used later by ; various higher-level functions in as mode-independent a manner ; as possible. ; ; This routine must also do the following: ; 1.) If delayed screen initialization is being supported, ; B$SCNINIT must be called before any changes. ; 2.) lets BASIC know new screen dimensions via B$SCNSWI ; 3.) Home cursors and clear screen via B$SCNCLR ; (must be done after #2 and after all screen state variables ; have been set) ; 4.) Set the default foreground and background colors. ; 5.) (OS/2 only) Clear the screen by calling B$CLRSCN with ; a parameter of 0. ; ;Entry: ; [SI] = address of the high end of the parameter list ; (parameters run from high to low memory) ; [CX] = count of words in parameter list ; (uses B$GetParm to get parameters) ; ;Exit: ; PSW.C = set indicates that an error was encountered ; ;Uses: ; Per convention ; ;Exceptions: ; None ;**** cProc B$SCRSTT,<PUBLIC,NEAR> ;NOTE: B$SCRSTT and B$WIDTH share a common ; exit at ErrorRestore cBegin CALL B$SCINIT ;init screen if not already done XOR AX,AX MOV WORD PTR ModeSpec,AX ; assume mode for screen not specified ; Check to see if the user has executed a POKE statement to change ; the equipment list. ; NOTE: This could be better done through the POKE filter. PUSH DS ;look at equipment flag in low memory MOV DS,AX ;(located at 0:410) to see whether user MOV AL,DS:[BiosEquip] ;has POKEd a new value to toggle monitors POP DS CMP AL,b$CurEquip ;this compares with previous setting JZ SCREN0 ;BRIF no change; continue MOV b$CurEquip,AL ;otherwise update BASIC's current equip CALL B$SetAdapter ;check out new hardware SCREN0: ; ; Start of new parameter parsing ; For BASICA compatibility, if the mode is specified, the default burst is not ; the present one, but 1 for screen mode 0, 0 for screen modes 1 and above. ; This always sets the color burst on for modes 0 & 1 and ignores the burst of ; rmodes 2 and above. The following table gives the logic coded below: ; ; -------------- --------------- ----------- ; Mode specified Burst specified Value in BH ; -------------- --------------- ----------- ; Yes Yes Specified Burst ; Yes No BH = 1/0 for text/mode 1 ; No Yes Specified Burst ; No No Old burst value ; JCXZ ScrError ;Error if no args passed cCALL B$GetParm ;Get first parameter - mode value mov bx,b$ModeBurst ;get old BIOS mode and burst mov OldBiosMode,bl ;save old BIOS mode for later mov bl,b$ScreenMode ;Get old screen mode mov b$OldScrnBurst,bx ;save old values for later MOV DX,b$CurPages JZ GET_BURST ;Brif no mode specified MOV ModeSpec,1 ;Mode was specified OR AL,AL ; graphics mode? (AH = 0 after B$GetParm) JNZ NO_BURST ; brif so -- default to zero burst INC AH ; burst defaults to 1 if text NO_BURST: XCHG BX,AX ;BX = BURST:MODE GET_BURST: cCALL B$GetParm ;See if burst is also specified JZ GET_APAGE ;Brif not MOV ModeSpec,1 ;Mode was specified NEG AL ;PSW.C = AL==0?0:1 rcl bh,1 ;carry to LSB of BH GET_APAGE: AND BH,01 ;Retain only LSB of burst cCALL B$GetParm ;Check if active-page given JZ GET_VPAGE ;Brif not INC PageSpec ; pages were specified XCHG AX,DX ;DL = Active-page MOV DH,DL ;DH = default visual-page GET_VPAGE: cCALL B$GetParm ;Check if visual-page specified JZ CHECK_REST ;Brif not INC PageSpec ; pages were specified MOV DH,AL ;DH = visual-page CHECK_REST: ;At this point CX should be zero JCXZ PROCESS_SCRSTT ;No more arguments - all is well ScrError: jmp SCREEN_ERROR ;exit w/error if not PROCESS_SCRSTT: xchg ax,bx ;ax = new BURST:MODE ; ;at this point: ; AL = new Mode ; AH = new Burst ; DL = new Active-page ; DH = new Video-page ; ; To be compatible with QB, let us first check if any of the input parameters ; changed. This needs to be done only if the caller is not WIDTH statement ; (where at least the screen height would have changed). ; cmp b$CurPages,dx ; Apage/Vpage changed? jne SCRSTT_CONT ;go if so cmp b$OldScrnBurst,ax ; Mode/Burst changed? je SCRSTT_RETURN ;go if not - simply exit cmp PageSpec,0 ; were pages specified? jnz SCRSTT_CONT ; brif so - use specified pages xor dx,dx ; else use page zero in new mode SCRSTT_CONT: ; ; Now for establishing the new mode. But one problem: We want to error check ; the new active and visual pages before we set the new mode. But we can't ; determine valid ranges in a mode-independent way until the mode has been ; established. To do that, b$ScreenX and b$AlphaDim function vectors only set ; up the mode-dependent data and make no actual screen changes. Then we can ; verify the page ranges and, if valid, set the mode via the b$SetMode function ; vector. If invalid, we must restore the old mode data again and exit with an ; error. ; push ax push dx mov dx,b$CURSOR ; turn cursor off at present location, in call B$OFFCSR ; order to physically move the cursor prior ; to possibly changing pages pop dx pop ax mov cl,b$ScrWidth ;Get current width of the screen mov ch,b$ScrHeight ; and height call B$ScreenN ;invoke screen AL to set mode-dependent data jc SCREEN_ERROR ;go if error, (nothing was done) xchg bx,cx ;width/height to BX push bx ;save: old width/height push dx ; pages mov bl,b$ScrWidth ;new width is fine call [b$AlphaDim] ;set text dimensions pop dx pop cx cmp dl,b$MaxPage ;check active page range ja ErrorRestore ;go if bad to restore old mode data cmp dh,b$MaxPage ;check visual page range ja ErrorRestore ;go if bad to restore old mode data push dx ;save pages mov al,b$ScrWidth mov cl,b$ScrHeight cCALL B$SCNSWI ;Inform Hi-Level about dimensions change cmp ModeSpec,0 ;SetMode only if je NoSetMode ; mode was specified mov al,b$BiosMode ;and cmp al,OldBiosMode ; BIOS mode actually changed je NoSetMode call B$ChkMonitor ; Set VGA monitor type before setting mode call [b$SetMode] ;set the actual mode CALL B$SCNCLR ;setup the screen (homes user cursor) call [b$PalReset] ;initialize the palette NoSetMode: ; jump past the call to [b$PalReset] call B$FixTextPage pop ax call [b$SetPages] ;set current page data CALL B$GETCSRDATA ;get cursor position for this page, since ;the active page might have changed. CALL B$SCNLOC ;update high-level cursor postion and turn ;on the user cursor SCRSTT_RETURN: CLC ;Indicate no error and exit jmp short SCRSTT_EXIT ErrorRestore: ;restore old screen mode data and return w/error mov ax,b$OldScrnBurst call B$ScreenN ;reset mode-dependent data xchg bx,cx ;width/height to BX call [b$AlphaDim] ;reset text dimensions call B$FixTextPage SCREEN_ERROR: ;indicate error and exit STC SCRSTT_EXIT: cEnd sEnd END
object_const_def ; object_event constants const CERULEANGYMBADGESPEECHHOUSE_POKEFAN_M CeruleanGymBadgeSpeechHouse_MapScripts: db 0 ; scene scripts db 0 ; callbacks CeruleanGymBadgeSpeechHousePokefanMScript: jumptextfaceplayer CeruleanGymBadgeSpeechHousePokefanMText CeruleanGymBadgeSpeechHousePokefanMText: text "Are you collecting" line "KANTO GYM BADGES?" done CeruleanGymBadgeSpeechHouse_MapEvents: db 0, 0 ; filler db 2 ; warp events warp_event 2, 7, CERULEAN_CITY, 1 warp_event 3, 7, CERULEAN_CITY, 1 db 0 ; coord events db 0 ; bg events db 1 ; object events object_event 2, 3, SPRITE_POKEFAN_M, SPRITEMOVEDATA_STANDING_RIGHT, 0, 0, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, CeruleanGymBadgeSpeechHousePokefanMScript, -1
; A039825: a(n) = floor((n^2 + n + 8) / 4). ; 2,3,5,7,9,12,16,20,24,29,35,41,47,54,62,70,78,87,97,107,117,128,140,152,164,177,191,205,219,234,250,266,282,299,317,335,353,372,392,412,432,453,475,497,519,542,566,590,614,639 add $0,2 bin $0,2 div $0,2 mov $1,$0 add $1,2
; A257286: a(n) = 5*6^n-4*5^n. ; 1,10,80,580,3980,26380,170780,1087180,6835580,42575980,263268380,1618672780,9907349180,60420657580,367406757980,2228854610380,13495197974780,81581539411180,492540994279580,2970504754739980,17899322473752380 mov $1,3 mov $2,$0 mov $3,3 lpb $2,1 add $1,$3 mul $1,5 sub $2,1 mul $3,6 lpe sub $1,3 div $1,3 add $1,1
copyright zengfr site:http://github.com/zengfr/romhack 00042A move.l D1, (A0)+ 00042C dbra D0, $42a 00494C move.l D0, (A4)+ 00494E move.l D0, (A4)+ 004D3A move.l D0, (A4)+ 004D3C move.l D0, (A4)+ 010D5E move.l #$4000000, ($4,A3) [etc+ 2] 010D66 clr.b ($7a,A3) [etc+ 4, etc+ 6] 0124BA move.l #$2020000, ($4,A3) [etc+ 0] 0124C2 clr.b ($7a,A3) [etc+ 4, etc+ 6] 074FB6 addq.b #2, ($4,A6) 074FBA move.b #$1, ($1,A6) [etc+ 4] 075040 addq.b #2, ($4,A6) 075044 rts [etc+ 4] 07529E addq.b #2, ($4,A6) 0752A2 bsr $752b2 [etc+ 4] 0752C0 move.b #$6, ($4,A6) 0752C6 rts [etc+ 4] 075440 addq.b #2, ($4,A6) 075444 move.b #$f, ($a0,A6) [etc+ 4] 0754EC addq.b #2, ($4,A6) 0754F0 rts [etc+ 4] 076D38 addq.b #2, ($4,A6) 076D3C rts [etc+ 4] 076D94 addq.b #2, ($4,A6) 076D98 move.b #$40, ($a0,A6) [etc+ 4] 0789EE move.b ($4,A6), D0 0789F2 move.w ($6,PC,D0.w), D1 [etc+ 4] 078A20 addq.b #2, ($4,A6) [etc+6E] 078A24 move.b #$3, ($80,A6) [etc+ 4] 078A32 addq.b #2, ($4,A6) 078A36 rts [etc+ 4] 078A54 addq.b #2, ($4,A6) 078A58 rts [etc+ 4] 078B5A move.b ($4,A6), D0 078B5E move.w (A0,D0.w), D0 [etc+ 4] 078B76 addq.b #2, ($4,A6) 078B7A move.b #$1, ($a0,A6) [etc+ 4] 078BA6 addq.b #2, ($4,A6) 078BAA rts [etc+ 4] 078FE6 addq.b #2, ($4,A6) [etc+6E] 078FEA moveq #$0, D0 [etc+ 4] 079034 addq.b #2, ($4,A6) [etc+A0] 079038 rts [etc+ 4] 07B0E2 addq.b #2, ($4,A6) 07B0E6 move.w #$8, ($a0,A6) [etc+ 4] 07B0F4 addq.b #2, ($4,A6) 07B0F8 rts [etc+ 4] 07B102 addq.b #2, ($4,A6) 07B106 rts [etc+ 4] 07B260 addq.b #2, ($4,A6) 07B264 move.w #$40, ($8,A6) [etc+ 4] 07B276 addq.b #2, ($4,A6) [etc+10] 07B27A bsr $7b2a4 [etc+ 4] 07B29E addq.b #2, ($4,A6) 07B2A2 rts [etc+ 4] 07B336 move.b ($4,A6), D0 07B33A move.w ($6,PC,D0.w), D0 [etc+ 4] 07B376 addq.b #2, ($4,A6) 07B37A rts [etc+ 4] 07B45C move.w #$200, ($4,A6) [base+50C] 07B462 rts [etc+ 4] 07B4EA move.w #$600, ($4,A6) 07B4F0 rts [etc+ 4] 07B4FE move.w #$600, ($4,A6) 07B504 rts [etc+ 4] 07B512 move.w #$600, ($4,A6) 07B518 rts [etc+ 4] 07B556 move.b ($4,A6), D0 07B55A move.w ($6,PC,D0.w), D1 [etc+ 4] 07B56A addq.b #2, ($4,A6) 07B56E movea.l ($54,PC) ; ($7b5c4), A0 [etc+ 4] 07B6D8 addq.b #2, ($4,A6) [etc+A8] 07B6DC tst.b ($5,A6) [etc+ 4] 07B798 move.w #$200, ($4,A6) 07B79E rts [etc+ 4] 07BB70 move.b ($4,A6), D0 07BB74 move.w ($6,PC,D0.w), D0 [etc+ 4] 07BB96 addq.b #2, ($4,A6) [base+4FE] 07BB9A move.w ($4fe,A5), D0 [etc+ 4] 07BD42 move.b ($4,A6), D0 07BD46 move.w ($6,PC,D0.w), D0 [etc+ 4] 07BD56 addq.b #2, ($4,A6) 07BD5A move.b #$2, ($81,A6) [etc+ 4] 07BDA8 addq.b #2, ($4,A6) 07BDAC rts [etc+ 4] 07BDC4 move.b ($4,A6), D0 07BDC8 move.w ($6,PC,D0.w), D0 [etc+ 4] 07BDD8 addq.b #2, ($4,A6) 07BDDC bsr $7bdea [etc+ 4] 07BDE4 addq.b #2, ($4,A6) 07BDE8 rts [etc+ 4] 07BF30 addq.b #2, ($4,A6) 07BF34 rts [etc+ 4] 07C0CE move.b #$6, ($4,A6) 07C0D4 clr.b ($7a9,A5) [etc+ 4] 07E7D2 addq.b #2, ($4,A6) 07E7D6 jsr $48a8.l [etc+ 4] 07E860 addq.b #2, ($4,A6) 07E864 movea.l ($58,A6), A3 [etc+ 4] 07E8DE addq.b #2, ($4,A6) 07E8E2 rts [etc+ 4] 07EBBC addq.b #2, ($4,A6) 07EBC0 jsr $48a8.l [etc+ 4] 07EBF8 addq.b #2, ($4,A6) 07EBFC jmp $49c0.l [etc+ 4] 07EC0A addq.b #2, ($4,A6) 07EC0E movea.l ($58,A6), A3 [etc+ 4] 07EC5C move.b #$2, ($4,A6) 07EC62 move.b #$2, ($0,A6) [etc+ 4] 07EEAE addq.b #2, ($4,A6) 07EEB2 rts [etc+ 4] 07EECE addq.b #2, ($4,A6) 07EED2 move.b #$f, ($a0,A6) [etc+ 4] 07EF06 addq.b #2, ($4,A6) 07EF0A rts [etc+ 4] 081046 move.b ($4,A6), D0 08104A move.w ($6,PC,D0.w), D1 [etc+ 4] 0810B2 addq.b #2, ($4,A6) [etc+25] 0810B6 bra $8114e [etc+ 4] 0836A4 move.b ($4,A6), D0 0836A8 move.w ($6,PC,D0.w), D0 [etc+ 4] 0836B8 addq.b #2, ($4,A6) 0836BC move.b #$1, ($1,A6) [etc+ 4] 0844FE addq.b #2, ($4,A6) 084502 rts [etc+ 4] 084F66 addq.b #2, ($4,A6) 084F6A rts [etc+ 4] 086D76 move.b ($4,A6), D0 086D7A move.w ($6,PC,D0.w), D1 [etc+ 4] 086DA8 addq.b #2, ($4,A6) 086DAC move.w ($26,A6), D1 [etc+ 4] 0871F6 addq.b #2, ($4,A6) 0871FA rts [etc+ 4] 08881A move.b ($4,A6), D0 08881E move.w ($6,PC,D0.w), D1 [etc+ 4] 08882E addq.b #2, ($4,A6) 088832 move.w ($26,A6), D0 [etc+ 4] 0888B2 move.b ($4,A6), D0 0888B6 move.w ($6,PC,D0.w), D1 [etc+ 4] 0888C6 addq.b #2, ($4,A6) 0888CA bsr $88922 [etc+ 4] 088A42 move.b #$4, ($4,A6) 088A48 jmp $49c0.l [etc+ 4] 088A84 move.b ($4,A6), D0 088A88 move.w ($6,PC,D0.w), D1 089998 move.b #$2, ($4,A6) 08999E move.b #$2, ($0,A6) [etc+ 4] 0899F0 move.b #$4, ($4,A6) 0899F6 bra $89ab2 [etc+ 4] 089ABA move.b ($4,A6), D0 089ABE move.w ($6,PC,D0.w), D1 [etc+ 4] 089ACE move.b #$2, ($4,A6) 089AD4 move.b #$2, ($0,A6) [etc+ 4] 089B48 move.b ($4,A6), D0 089B4C move.w ($6,PC,D0.w), D1 [etc+ 4] 089B5C move.b #$2, ($4,A6) 089B62 move.b #$2, ($0,A6) [etc+ 4] 089EF2 move.b #$2, ($4,A6) 089EF8 move.b #$2, ($0,A6) [etc+ 4] 089FD6 addi.b #$2, ($4,A6) [base+7E4] 089FDC rts [etc+ 4] 08A596 move.b #$2, ($4,A6) 08A59C move.w #$78, ($a0,A6) [etc+ 4] 08BE60 addq.b #2, ($4,A6) 08BE64 rts [etc+ 4] 08C08C move.w #$200, ($4,A6) 08C092 clr.b ($4d5,A5) [etc+ 4] 08C1E0 move.l #$4000000, ($4,A6) 08C1E8 rts [etc+ 4, etc+ 6] 08C1FC move.w #$200, ($4,A6) 08C202 move.b #$1, ($0,A6) [etc+ 4] 08C878 move.w #$600, ($4,A6) 08C87E rts [etc+ 4] 091FE4 move.b #$2, ($4,A6) 091FEA move.w #$12c, ($a0,A6) [etc+ 4] 0921A6 move.b #$2, ($4,A6) 0921AC rts [etc+ 4] 0921EE move.b #$2, ($4,A6) 0921F4 move.w #$128, ($a0,A6) [etc+ 4] 092234 addq.b #2, ($4,A6) 092238 move.w ($26,A6), D0 [etc+ 4] 092396 addq.b #2, ($4,A6) 09239A jsr $a5ea.l [etc+ 4] 0923AC addq.b #2, ($4,A6) 0923B0 moveq #$0, D0 [etc+ 4] 0A6612 addq.b #2, ($4,A6) 0A6616 rts [etc+ 4] 0AAACA move.l (A0), D2 0AAACC move.w D0, (A0) [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1] 0AAACE move.w D0, ($2,A0) 0AAAD2 cmp.l (A0), D0 0AAAD4 bne $aaafc 0AAAD8 move.l D2, (A0)+ 0AAADA cmpa.l A0, A1 [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1] 0AAAE6 move.l (A0), D2 0AAAE8 move.w D0, (A0) [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1] 0AAAF4 move.l D2, (A0)+ 0AAAF6 cmpa.l A0, A1 [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1] copyright zengfr site:http://github.com/zengfr/romhack
; A298271: Expansion of x/((1 - x)*(1 - 322*x + x^2)). ; Submitted by Christian Krause ; 0,1,323,104006,33489610,10783550415,3472269744021,1118060074024348,360011871566096036,115922704584208899245,37326750864243699460855,12019097855581887017496066,3870112182746503375934272398,1246164103746518505163818216091,401260971294196212159373531308905,129204786592627433796813113263251320,41603540021854739486361663097235616136,13396210682250633487174658704196605144473,4313538236144682128130753741088209620904171,1388945915827905394624615529971699301325998590 mov $3,1 lpb $0 sub $0,1 mov $1,$3 mul $1,16 add $2,$1 add $3,$2 lpe pow $3,2 mov $0,$3 div $0,288
; Copyright Oliver Kowalke 2009. ; 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) ; ---------------------------------------------------------------------------------- ; | 0 | 1 | | ; ---------------------------------------------------------------------------------- ; | 0x0 | 0x4 | | ; ---------------------------------------------------------------------------------- ; | <indicator> | | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- ; | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ; ---------------------------------------------------------------------------------- ; | 0x8 | 0xc | 0x10 | 0x14 | 0x18 | 0x1c | 0x20 | 0x24 | ; ---------------------------------------------------------------------------------- ; | SEE registers (XMM6-XMM15) | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- ; | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | ; ---------------------------------------------------------------------------------- ; | 0x28 | 0x2c | 0x30 | 0x34 | 0x38 | 0x3c | 0x40 | 0x44 | ; ---------------------------------------------------------------------------------- ; | SEE registers (XMM6-XMM15) | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- ; | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | ; ---------------------------------------------------------------------------------- ; | 0x48 | 0x4c | 0x50 | 0x54 | 0x58 | 0x5c | 0x60 | 0x64 | ; ---------------------------------------------------------------------------------- ; | SEE registers (XMM6-XMM15) | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- ; | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | ; ---------------------------------------------------------------------------------- ; | 0x68 | 0x6c | 0x70 | 0x74 | 0x78 | 0x7c | 0x80 | 0x84 | ; ---------------------------------------------------------------------------------- ; | SEE registers (XMM6-XMM15) | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- ; | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | ; ---------------------------------------------------------------------------------- ; | 0x88 | 0x8c | 0x90 | 0x94 | 0x98 | 0x9c | 0xa0 | 0xa4 | ; ---------------------------------------------------------------------------------- ; | SEE registers (XMM6-XMM15) | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- ; | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | ; ---------------------------------------------------------------------------------- ; | 0xa8 | 0xac | 0xb0 | 0xb4 | 0xb8 | 0xbc | 0xc0 | 0xc4 | ; ---------------------------------------------------------------------------------- ; | fc_mxcsr|fc_x87_cw| <alignment> | fbr_strg | fc_dealloc | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- ; | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | ; ---------------------------------------------------------------------------------- ; | 0xc8 | 0xcc | 0xd0 | 0xd4 | 0xd8 | 0xdc | 0xe0 | 0xe4 | ; ---------------------------------------------------------------------------------- ; | limit | base | R12 | R13 | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- ; | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | ; ---------------------------------------------------------------------------------- ; | 0xe8 | 0xec | 0xf0 | 0xf4 | 0xf8 | 0xfc | 0x100 | 0x104 | ; ---------------------------------------------------------------------------------- ; | R14 | R15 | RDI | RSI | ; ---------------------------------------------------------------------------------- ; ---------------------------------------------------------------------------------- ; | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | ; ---------------------------------------------------------------------------------- ; | 0x108 | 0x10c | 0x110 | 0x114 | 0x118 | 0x11c | 0x120 | 0x124 | ; ---------------------------------------------------------------------------------- ; | RBX | RBP | RIP | EXIT | ; ---------------------------------------------------------------------------------- .code jump_fcontext_v1 PROC BOOST_CONTEXT_EXPORT FRAME .endprolog push rbp ; save RBP push rbx ; save RBX push rsi ; save RSI push rdi ; save RDI push r15 ; save R15 push r14 ; save R14 push r13 ; save R13 push r12 ; save R12 ; load NT_TIB mov r10, gs:[030h] ; save current stack base mov rax, [r10+08h] push rax ; save current stack limit mov rax, [r10+010h] push rax ; save current deallocation stack mov rax, [r10+01478h] push rax ; save fiber local storage mov rax, [r10+018h] push rax ; prepare stack for FPU lea rsp, [rsp-0a8h] ; test for flag preserve_fpu test r9, r9 je nxt1 ; save MMX control- and status-word stmxcsr [rsp+0a0h] ; save x87 control-word fnstcw [rsp+0a4h] ; save XMM storage movaps [rsp], xmm6 movaps [rsp+010h], xmm7 movaps [rsp+020h], xmm8 movaps [rsp+030h], xmm9 movaps [rsp+040h], xmm10 movaps [rsp+050h], xmm11 movaps [rsp+060h], xmm12 movaps [rsp+070h], xmm13 movaps [rsp+080h], xmm14 movaps [rsp+090h], xmm15 nxt1: ; set R10 to zero xor r10, r10 ; set indicator push r10 ; store RSP (pointing to context-data) in RCX mov [rcx], rsp ; restore RSP (pointing to context-data) from RDX mov rsp, rdx ; load indicator pop r10 ; test for flag preserve_fpu test r9, r9 je nxt2 ; restore MMX control- and status-word ldmxcsr [rsp+0a0h] ; save x87 control-word fldcw [rsp+0a4h] ; restore XMM storage movaps xmm6, [rsp] movaps xmm7, [rsp+010h] movaps xmm8, [rsp+020h] movaps xmm9, [rsp+030h] movaps xmm10, [rsp+040h] movaps xmm11, [rsp+050h] movaps xmm12, [rsp+060h] movaps xmm13, [rsp+070h] movaps xmm14, [rsp+080h] movaps xmm15, [rsp+090h] nxt2: ; set offset of stack mov rcx, 0a8h ; test for indicator test r10, r10 je nxt3 add rcx, 08h nxt3: ; prepare stack for FPU lea rsp, [rsp+rcx] ; load NT_TIB mov r10, gs:[030h] ; restore fiber local storage pop rax mov [r10+018h], rax ; restore deallocation stack pop rax mov [r10+01478h], rax ; restore stack limit pop rax mov [r10+010h], rax ; restore stack base pop rax mov [r10+08h], rax pop r12 ; restore R12 pop r13 ; restore R13 pop r14 ; restore R14 pop r15 ; restore R15 pop rdi ; restore RDI pop rsi ; restore RSI pop rbx ; restore RBX pop rbp ; restore RBP ; restore return-address pop r10 ; use third arg as return-value after jump mov rax, r8 ; use third arg as first arg in context function mov rcx, r8 ; indirect jump to context jmp r10 jump_fcontext_v1 ENDP END
.data input_text: .asciiz "Enter int: " output_odd: .asciiz "The number is odd" output_even: .asciiz "The number is even" .text la $a0,input_text li $v0, 4 syscall li $v0,5 #set value syscall move $t0, $v0 loop: bne $t0,1,exitodd bne $t0,0,exiteven srl $t0,$t0,1 j loop exitodd: li $v0, 4 la $a0, output_odd syscall j end exiteven: li $v0, 4 la $a0, output_even syscall end:
#include <evnt/evnt.hpp> #include <gtest/gtest.h> #include <cstdlib> class int_event { public: int value; }; TEST(event_manager_tests, test_emit_event_lvalue_reference) { evnt::event_manager event_manager; int value = 0; event_manager.connect<int_event>([&value](int_event& event) { value = event.value; }); int_event evt{ 5 }; event_manager.emit(evt); ASSERT_EQ(value, 5); } TEST(event_manager_tests, test_emit_event_rvalue_reference) { evnt::event_manager event_manager; int value = 0; event_manager.connect<int_event>([&value](int_event& event) { value = event.value; }); int_event evt{ 5 }; event_manager.emit(evt); ASSERT_EQ(value, 5); } class int_event_Listener : public evnt::event_listener<int_event> { public: int_event_Listener(int& value) : value_ptr(&value) {} ~int_event_Listener() { if (value_ptr) *value_ptr *= 10; } void receive(int_event& event) { *value_ptr = event.value; } int* value_ptr; }; TEST(event_manager_tests, test_listener_auto_deconnection) { int value = 0; { evnt::event_manager event_manager; { int_event_Listener listener(value); event_manager.connect<int_event>(listener); event_manager.emit(int_event{ 5 }); ASSERT_EQ(value, 5); } ASSERT_EQ(value, 5 * 10); event_manager.emit(int_event{ 200 }); ASSERT_EQ(value, 5 * 10); } ASSERT_EQ(value, 5 * 10); } TEST(event_manager_tests, test_listener_deconnection) { int value = 0; { evnt::event_manager event_manager; { int_event_Listener listener(value); event_manager.connect<int_event>(listener); event_manager.emit(int_event{ 5 }); ASSERT_EQ(value, 5); listener.disconnect<int_event>(); event_manager.emit(int_event{ 7 }); ASSERT_EQ(value, 5); } ASSERT_EQ(value, 5 * 10); event_manager.emit(int_event{ 200 }); ASSERT_EQ(value, 5 * 10); } ASSERT_EQ(value, 5 * 10); } class int_event_2 { public: int value; }; class multi_event_listener : public evnt::event_listener<int_event, int_event_2> { public: multi_event_listener(int& value, int& value_2) : value_ptr(&value), value_ptr_2(&value_2) {} ~multi_event_listener() { *value_ptr += 100; *value_ptr_2 += 100; } void receive(int_event& event) { *value_ptr = event.value + 1; } void receive(int_event_2& event) { *value_ptr_2 = event.value + 2; } int* value_ptr; int* value_ptr_2; }; TEST(event_manager_tests, test_multi_listener_connection_and_auto_deconnection) { int value = 0; int value_2 = 0; { evnt::event_manager event_manager; { multi_event_listener listener(value, value_2); event_manager.connect<int_event>(listener); event_manager.connect<int_event_2>(listener); event_manager.emit(int_event{ 5 }); event_manager.emit(int_event_2{ 7 }); ASSERT_EQ(value, 6); ASSERT_EQ(value_2, 9); } ASSERT_EQ(value, 6 + 100); ASSERT_EQ(value_2, 9 + 100); event_manager.emit(int_event{ 10 }); event_manager.emit(int_event_2{ 13 }); ASSERT_EQ(value, 6 + 100); ASSERT_EQ(value_2, 9 + 100); } ASSERT_EQ(value, 6 + 100); ASSERT_EQ(value_2, 9 + 100); } TEST(event_manager_tests, test_multi_listener_deconnections_and_reconnection) { int value = 0; int value_2 = 0; { evnt::event_manager event_manager; { multi_event_listener listener(value, value_2); event_manager.connect<int_event>(listener); event_manager.connect<int_event_2>(listener); event_manager.emit(int_event{ 5 }); event_manager.emit(int_event_2{ 7 }); ASSERT_EQ(value, 6); ASSERT_EQ(value_2, 9); listener.disconnect<int_event>(); event_manager.emit(int_event{ 10 }); event_manager.emit(int_event_2{ 10 }); ASSERT_EQ(value, 6); ASSERT_EQ(value_2, 12); event_manager.connect<int_event>(listener); event_manager.emit(int_event{ 10 }); event_manager.emit(int_event_2{ 20 }); ASSERT_EQ(value, 11); ASSERT_EQ(value_2, 22); listener.disconnect_all(); event_manager.emit(int_event{ -10 }); event_manager.emit(int_event_2{ -20 }); ASSERT_EQ(value, 11); ASSERT_EQ(value_2, 22); } ASSERT_EQ(value, 111); ASSERT_EQ(value_2, 122); event_manager.emit(int_event{ 20 }); event_manager.emit(int_event_2{ 23 }); ASSERT_EQ(value, 111); ASSERT_EQ(value_2, 122); } ASSERT_EQ(value, 111); ASSERT_EQ(value_2, 122); } int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
//Loading transition Text($00115BC4, "Please wait...") ; fill 8 //Action Menu Text($43B54940, "Attack") ; fill 6 Text($43B53EA4, "Attack") ; fill 6 Text($00114E44, "Block") ; fill 4 Text($43B53EB0, "Block") ; fill 4 Text($43B5494C, "Block") ; fill 4 Text($43B560D8, "Status") ; fill 2 Text($43B560E0, "Points") ; fill 6 Text($43B560EC, "Items") ; fill 7 Text($43B560F8, "Skill") ; fill 3 Text($43B56100, "Ask") ; fill 9 Text($43B56114, "Examine") ; fill 5 Text($43B56128, "Talk") ; fill 4 Text($43B56130, "Team Up") ; fill 5 Text($43B5613C, "Respawn") ; fill 5 Text($43CF0DC8, "Respawn") ; fill 5 Text($00114F20, "Respawn") ; fill 5 Text($43CF0E8C, "Run") ; fill 5 Text($43B561F8, "Run") ; fill 5 Text($43CEF61C, "Block") ; fill 4 Text($43CF1738, "Block") ; fill 4 Text($43B5610C, "Open") ; fill 4 Text($43CF0D90, "Open") ; fill 4 Text($43B56200, "Wait") ; fill 8 Text($43CEFD64, "Wait") ; fill 8 //Item Menu Text($43B5620C, "I do not have any items") ; fill 5 Text($43B56228, "Use") ; fill 5 Text($43B56240, "Drop") ; fill 4 Text($43B56248, "Give") ; fill 8 Text($00199DC0, "Equip") ; fill 3 Text($43B56230, "Equip") ; fill 3 Text($3C08BCC7, "Equip") ; fill 2 Text($43CF0EC4, "Equip") ; fill 3 Text($43B56238, "Unequip") ; fill 1 Text($43CF0ECC, "Unequip") ; fill 1 //Team Menu Text($43B56390, "Join Team") ; fill 3 Text($43B5639C, "Leave Team") ; fill 2 //Settings Menu Text($43B564CC, "Battling Zoom") ; fill 5 Text($43B564DC, "Skill Pointer") ; fill 3 Text($43B564EC, "BGM Volume") ; fill 10 Text($43B56500, " SE Volume") ; fill 6 //Pause Menu Text($001160F8, " Saving") ; fill 1 Text($00116180, "Adventure has been saved.") ; fill 3 Text($00116C90, "Save") ; fill 5 Text($00116C9C, "Quit") ; fill 7 Text($00116CD0, "Settings") ; fill 1 Text($00116CE8, "Save adventure to memory card?") ; fill 2 Text($00116D08, "Save adventure to memory card?") ; fill 2 Text($00116D78, "Save and exit to the Main Menu?") ; fill 1 Text($00116DFC, "Would you like to save and return home?") ; fill 4 Text($00199E28, "History") ; fill 1 Text($0019A198, "History") ; fill 1 //Respawn Menu Text($43B56148, "Respawn and return to a safe place?") ; fill 9 Text($43CF0DD4, "Respawn and return to a safe place?") ; fill 9 Text($00199BE0, "Yes") ; fill 2 Text($00199C70, "Yes") ; fill 2 Text($41C05442, "Yes") ; fill 2 Text($00199BE8, "No") ; fill 5 Text($00199C5F, "No") ; fill 5 Text($00199C60, "No") ; fill 5 Text($00199D78, "No") ; fill 5 Text($3CF8DD48, "No") ; fill 5 Text($3CF906CC, "No") ; fill 5 Text($3EA73F77, "No") ; fill 5 Text($3EA74D12, "No") ; fill 5 Text($3EE6D7BF, "No") ; fill 5 Text($41BD646B, "No") ; fill 5 Text($41C05447, "No") ; fill 5 //Skills Text($43B43370, "Call Somone") ; fill 4 Text($43CE2688, "Call Somone") ; fill 4 Text($49B491B4, "Call Somone") ; fill 4 Text($43B43F18, "Loud voice reaches around the world") ; fill 1 Text($43B43F18, "Loud voice reaches around the world") ; fill 1 Text($43CE3230, "Loud voice reaches around the world") ; fill 1 Text($43B43380, "Heal") ; fill 4 Text($43CE2698, "Heal") ; fill 4 Text($49B491C4, "Heal") ; fill 4 Text($43B43F3C, "Recover Life") ; fill 8 Text($43CE3254, "Recover Life") ; fill 8 //Mascot Text($43ADDF6C, "Block") ; fill 7 Text($43ADDF90, "Pinnock") ; fill 5 Text($43ADDFD0, "Ganto") ; fill 3 Text($43B242B4, RED) ; db "B Button", BLACK, ": Quit & Return" ; fill 11 Text($43B3D704, "Exchange Item") ; fill 3 Text($43B434B8, "Guts") ; fill 4 Text($43B44194, "Increase force") ; fill 2 Text($43B55730, " Sort Items") ; fill 2 TextShiftJIS($43B54790, "Joining") ; fill 2 TextShiftJIS($43B55B90, "Thinking") ; db $81, $63 ; fill 2 TextShiftJIS($43B55BEC, "ForceUp+") ; db $25, $44 ; fill 2 TextShiftJIS($43B55EF0, "ForceNormal") ; fill 2 Text($43B56570, "[Block Mascot]\n") db " The Block is part of a tribe of toys who live in a town.\n" db " Weak in power, exert your personality to grow stronger." ; fill 11 Text($43B56784, "[Pinnock Mascot]\n") db " A tribe of friendly dolls living in a village.\n" db " Can injure monsters, also has cure as an ability." ; fill 17 Text($43B56A80, "[Ganto Mascot]\n") db " A tribe of large builders, protecting the fort of Parumara.\n" db " It has outstanding offensive & destructive power." ; fill 10 Text($43B56D18, "There is no Mascot here yet.") ; fill 8 Text($43B56D3C, "I'm already on an adventure") ; fill 1 //Stats and Level up menu Text($43B58BF4, "/ ") ; fill 2 Text($43B58BF8, "Until Next Level:") ; fill 3 Text($43B58C0C, "Current Completion:") ; fill 1 Text($43B58C44, " Exp:") ; fill 3 Text($43B56428, "Normal") ; fill 6 Text($43B58B90, "Clear Points") ; fill 4 Text($43B58BA0, " points") ; fill 1 Text($43B58BA8, " Force:") ; fill 3 Text($43B58E00, " Force:") ; fill 3 Text($43CF3EE8, " Force:") ; fill 3 Text($43CF4140, " Force:") ; fill 3 Text($43B58BB4, " Agility:") ; fill 3 Text($43B58E0C, " Agility:") ; fill 3 Text($43CF414C, " Agility:") ; fill 3 Text($43CF3EF4, " Agility:") ; fill 4 Text($43B58BC0, " Mind:") ; fill 3 Text($43B58E18, " Mind:") ; fill 3 Text($43CF4158, " Mind:") ; fill 3 Text($43CF3F00, " Mind:") ; fill 3 Text($00114B74, "Attack") ; fill 6 Text($43CEF610, "Attack") ; fill 6 Text($43CF172C, "Attack") ; fill 6 Text($43B58BCC, " Attack:") ; fill 3 Text($43B58E24, " Attack:") ; fill 3 Text($43CF3F0C, " Attack:") ; fill 3 Text($43CF4164, " Attack:") ; fill 3 Text($43B58BD8, " Defense:") ; fill 3 Text($43CF3F18, " Defense:") ; fill 3 Text($43B58E34, " Defense:") ; fill 3 Text($43CF4174, " Defense:") ; fill 3 Text($3C08BE14, " Pow") ; fill 1 Text($43B4AC37, " Pow") ; fill 5 Text($43B58F7C, " Pow") ; fill 1 Text($43CF42BC, " Pow") ; fill 1 Text($43CF3F24, " Power:") ; fill 2 Text($43B58BEC, " Power:") ; fill 2 Text($3C08BE2D, "Life") ; fill 1 Text($43B58F60, "Life") ; fill 1 Text($43CF42A0, "Life") ; fill 1 Text($43B58BE4, " Life:") ; fill 1 Text($3C08BE3D, " Level") ; fill 2 Text($43B58C3C, " Level") ; fill 2 Text($43B58C3C, " Level") ; fill 2 Text($43B58F58, " Level") ; fill 2 Text($43CF3F7C, " Level") ; fill 2 Text($43CF4298, " Level") ; fill 2 //End Stats menu // Start Game Text($57051B14, "Are you a boy or a girl?") ; fill 24 Text($57051B44, "Please name your character.") ; fill 1 Text($57051B60, "You cannot use the same name which exists on this memory card.") ; fill 2 Text($57051BA0, "Adventure will start with this name.") ; fill 4 Text($57051BC8, "New adventure data has been stored on this memory card.") ; fill 7 Text($57051D18, "%03d hours %02d mins") ; fill 4 Text($57051F54, "Check memory card SlotA") ; fill 1 Text($57051F6C, "Edit this memory card") ; fill 11 Text($57051F8C, "Start without saving data") ; fill 23 Text($57051FBC, "Is it OK to erase this data?") ; fill 8 Text($57051FE0, "Are you sure about erasing this data?") ; fill 11 Text($570520E8, "Is it OK to erase this data?") ; fill 8 Text($5705210C, "Are you sure about erasing this data?") ; fill 11 Text($57052168, "Failed to load this memory card") ; fill 9 Text($570523A8, " Play Time:") ; fill 8 // Start Screen Text($57052600, "Weapons") ; fill 1 Text($57052608, "Shields") ; fill 1 Text($57052610, "Items") ; fill 3 Text($57052618, "You have %D EXP") ; fill 4 Text($5705262C, "New Game") ; fill 12 Text($57052640, "Network") ; fill 9 Text($57052650, "Network Setup") ; fill 3 Text($57052660, "Connection Test") ; fill 1 Text($57052670, "Credits") ; fill 13 Text($57052684, "Go To The Network Settings. \n") Text($570526A7, "Is This OK?") ; fill 14 // Memory Card Text($00115982, " ON") ; fill 7 Text($0011598C, " OFF") ; db $81, $E8 ; fill 5 Text($00115998, "It has been set") ; fill 5 Text($001159AE, " Memorize") ; fill 5 Text($001159BE, " Reset") ; db $81, $E8 ; fill 7 Text($00115B38, "An error has occured.") ; fill 7 Text($00115CFC, "There is a problem with the memory card in SlotA.\n") Text($00115D2E, "It might get fixed by initializing it, \n") Text($00115D5A, "but all the data will be lost. \n") Text($00115D7B, "Do you want to initialize?") ; fill 3 Text($00115DE8, "Initializing memory card. Is this OK?") ; fill 7 Text($00115E6C, "It is now initialized.") ; fill 2 Text($00115EC0, "It will not be able to save your progress in the game.") ; fill 6 Text($00116084, "The memory card in Slot A is used to record the adventure.\n") Text($001160BF, "Please do not turn off the power or remove the card.") ; fill 5 //Shop menu Text($43B563BC, "Sell") ; fill 4 Text($43CF1050, "Sell") ; fill 4 Text($43B563E0, "Bulk Sell") ; fill 7 Text($43CF1074, "Bulk Sell") ; fill 7 Text($43B563B4, "Buy") ; fill 5 Text($43CF1048, "Buy") ; fill 5 Text($43B563D0, "Buy In Bulk") ; fill 5 Text($43CF1064, "Buy In Bulk") ; fill 5 Text($24C3F5A9, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($24C43446, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($26687FAA, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($27A61F30, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($27F950E1, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($27F975AA, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($297B9B51, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($297BBF76, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($2AEF2936, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($2B13B6AD, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($2B13E516, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($2BE3AB54, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($2C19C886, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($2C68B3A1, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($2C68D6DE, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($2D1D15B6, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($2E494015, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($2FAD3E73, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($3051001E, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($306E6226, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($30DB8DA6, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($3305DAC6, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($3349E63B, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($334AA071, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($337E694C, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($3404AD95, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($345B94A3, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($345BBFAA, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($3492C67D, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($3492EE62, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($35BB2112, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($362A338E, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($37115F0E, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($37317A2F, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($37E864A6, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($3A234D28, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2 Text($3FDA1135, "Shopping") ; fill 7 ; db "Sell Stuff" ; fill 5 ; db "Close" ; fill 2
.data array: .space 180 # Declaracao do array com 180 bits(espaco para 45 inteiros) .text #Iniciando contadores addi $s0, $zero,0 # Auxiliar no fibonnaci addi $s1, $zero,1 # Primeiro termo da serie fibonnaci li $t0 , 0 # Contador da posicao do array sw $s1, array($t0) # Salvando o primeiro termo da serie fibonnnaci no array while: beq $t0,184,exit # Sair do loop , se t0 for igual a 184 add $s2,$s1,$s0 # soma dos termos add $s1,$zero,$s0 # Auxiliar agora com o valor do primeiro termo add $s0,$zero,$s2 # salvando o valor da soma fibonnaci sw $s2,array($t0) # salvando a soma no array add $t0,$t0,4 # aumentando o contador j while # voltando ao while exit:
VermilionGym_Object: db $3 ; border block db 2 ; warps warp 4, 17, 3, -1 warp 5, 17, 3, -1 db 0 ; signs db 5 ; objects object SPRITE_ROCKER, 5, 1, STAY, DOWN, 1, OPP_LT_SURGE, 1 object SPRITE_GENTLEMAN, 9, 6, STAY, LEFT, 2, OPP_GENTLEMAN, 3 object SPRITE_BLACK_HAIR_BOY_2, 3, 8, STAY, LEFT, 3, OPP_ROCKER, 1 object SPRITE_SAILOR, 0, 10, STAY, RIGHT, 4, OPP_SAILOR, 8 object SPRITE_GYM_HELPER, 4, 14, STAY, DOWN, 5 ; person ; warp-to warp_to 4, 17, VERMILION_GYM_WIDTH warp_to 5, 17, VERMILION_GYM_WIDTH
; sp1_InvUpdateStruct ; 03.2006 aralbrec, Sprite Pack v3.0 ; sinclair zx version SECTION code_temp_sp1 PUBLIC sp1_InvUpdateStruct sp1_InvUpdateStruct: INCLUDE "temp/sp1/zx/updater/asm_sp1_InvUpdateStruct.asm"
CeruleanCaveB1F_Script: call EnableAutoTextBoxDrawing ld hl, CeruleanCaveB1FTrainerHeaders ld de, CeruleanCaveB1F_ScriptPointers ld a, [wCeruleanCaveB1FCurScript] call ExecuteCurMapScriptInTable ld [wCeruleanCaveB1FCurScript], a ret CeruleanCaveB1F_ScriptPointers: dw CheckFightingMapTrainers dw DisplayEnemyTrainerTextAndStartBattle dw EndTrainerBattle CeruleanCaveB1F_TextPointers: dw MewtwoText dw PickUpItemText dw PickUpItemText CeruleanCaveB1FTrainerHeaders: def_trainers MewtwoTrainerHeader: trainer EVENT_BEAT_MEWTWO, 0, MewtwoBattleText, MewtwoBattleText, MewtwoBattleText db -1 ; end MewtwoText: text_asm ld hl, MewtwoTrainerHeader call TalkToTrainer jp TextScriptEnd MewtwoBattleText: text_far _MewtwoBattleText text_asm ld a, MEWTWO call PlayCry call WaitForSoundToFinish jp TextScriptEnd
// 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 "modules/presentation/PresentationRequest.h" #include "bindings/core/v8/CallbackPromiseAdapter.h" #include "bindings/core/v8/ExceptionState.h" #include "bindings/core/v8/ScriptPromise.h" #include "bindings/core/v8/ScriptPromiseResolver.h" #include "core/dom/Document.h" #include "core/dom/ExecutionContext.h" #include "core/frame/Settings.h" #include "core/frame/UseCounter.h" #include "modules/EventTargetModules.h" #include "modules/presentation/PresentationAvailability.h" #include "modules/presentation/PresentationAvailabilityCallbacks.h" #include "modules/presentation/PresentationConnection.h" #include "modules/presentation/PresentationConnectionCallbacks.h" #include "modules/presentation/PresentationController.h" #include "modules/presentation/PresentationError.h" #include "platform/UserGestureIndicator.h" namespace blink { namespace { // TODO(mlamouri): refactor in one common place. WebPresentationClient* presentationClient(ExecutionContext* executionContext) { ASSERT(executionContext && executionContext->isDocument()); Document* document = toDocument(executionContext); if (!document->frame()) return nullptr; PresentationController* controller = PresentationController::from(*document->frame()); return controller ? controller->client() : nullptr; } Settings* settings(ExecutionContext* executionContext) { ASSERT(executionContext && executionContext->isDocument()); Document* document = toDocument(executionContext); return document->settings(); } } // anonymous namespace // static PresentationRequest* PresentationRequest::create(ExecutionContext* executionContext, const String& url, ExceptionState& exceptionState) { KURL parsedUrl = KURL(executionContext->url(), url); if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { exceptionState.throwTypeError("'" + url + "' can't be resolved to a valid URL."); return nullptr; } PresentationRequest* request = new PresentationRequest(executionContext, parsedUrl); request->suspendIfNeeded(); return request; } const AtomicString& PresentationRequest::interfaceName() const { return EventTargetNames::PresentationRequest; } ExecutionContext* PresentationRequest::getExecutionContext() const { return ActiveDOMObject::getExecutionContext(); } void PresentationRequest::addedEventListener(const AtomicString& eventType, RegisteredEventListener& registeredListener) { EventTargetWithInlineData::addedEventListener(eventType, registeredListener); if (eventType == EventTypeNames::connectionavailable) UseCounter::count(getExecutionContext(), UseCounter::PresentationRequestConnectionAvailableEventListener); } bool PresentationRequest::hasPendingActivity() const { if (!getExecutionContext() || getExecutionContext()->activeDOMObjectsAreStopped()) return false; // Prevents garbage collecting of this object when not hold by another // object but still has listeners registered. return hasEventListeners(); } ScriptPromise PresentationRequest::start(ScriptState* scriptState) { ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); ScriptPromise promise = resolver->promise(); Settings* contextSettings = settings(getExecutionContext()); bool isUserGestureRequired = !contextSettings || contextSettings->presentationRequiresUserGesture(); if (isUserGestureRequired && !UserGestureIndicator::utilizeUserGesture()) { resolver->reject(DOMException::create(InvalidAccessError, "PresentationRequest::start() requires user gesture.")); return promise; } WebPresentationClient* client = presentationClient(getExecutionContext()); if (!client) { resolver->reject(DOMException::create(InvalidStateError, "The PresentationRequest is no longer associated to a frame.")); return promise; } client->startSession(m_url.getString(), new PresentationConnectionCallbacks(resolver, this)); return promise; } ScriptPromise PresentationRequest::reconnect(ScriptState* scriptState, const String& id) { ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); ScriptPromise promise = resolver->promise(); WebPresentationClient* client = presentationClient(getExecutionContext()); if (!client) { resolver->reject(DOMException::create(InvalidStateError, "The PresentationRequest is no longer associated to a frame.")); return promise; } client->joinSession(m_url.getString(), id, new PresentationConnectionCallbacks(resolver, this)); return promise; } ScriptPromise PresentationRequest::getAvailability(ScriptState* scriptState) { ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); ScriptPromise promise = resolver->promise(); WebPresentationClient* client = presentationClient(getExecutionContext()); if (!client) { resolver->reject(DOMException::create(InvalidStateError, "The object is no longer associated to a frame.")); return promise; } client->getAvailability(m_url.getString(), new PresentationAvailabilityCallbacks(resolver, m_url)); return promise; } const KURL& PresentationRequest::url() const { return m_url; } DEFINE_TRACE(PresentationRequest) { EventTargetWithInlineData::trace(visitor); ActiveDOMObject::trace(visitor); } PresentationRequest::PresentationRequest(ExecutionContext* executionContext, const KURL& url) : ActiveScriptWrappable(this) , ActiveDOMObject(executionContext) , m_url(url) { } } // namespace blink
int main(){ try{ string nombre_archivo; cout << "Introduce el nombre del archivo a analizar: "; cin >> nombre_achivo; Anaylizer myAnalyzer{nombre_archivo}; myAnalyzer.showAnalysis(); cout << "Introduce el nombre del archivo donde guardar los resultados: "; cin >> nombre_archivo; myAnalyzer.saveAnalysis(nombre_archivo); cout << "Finalizado" << endl; }catch(string e){ cout << e << endl; return 1; } return 0; }
; A021860: Decimal expansion of 1/856. ; Submitted by Jon Maiga ; 0,0,1,1,6,8,2,2,4,2,9,9,0,6,5,4,2,0,5,6,0,7,4,7,6,6,3,5,5,1,4,0,1,8,6,9,1,5,8,8,7,8,5,0,4,6,7,2,8,9,7,1,9,6,2,6,1,6,8,2,2,4,2,9,9,0,6,5,4,2,0,5,6,0,7,4,7,6,6,3,5,5,1,4,0,1,8,6,9,1,5,8,8,7,8,5,0,4,6 seq $0,199685 ; a(n) = 5*10^n+1. div $0,428 mod $0,10
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r12 push %r14 push %rax push %rcx push %rdi push %rdx push %rsi lea addresses_D_ht+0x8054, %r10 nop nop nop xor $21463, %r12 movups (%r10), %xmm7 vpextrq $0, %xmm7, %rdx nop nop nop nop sub $10766, %rdx lea addresses_normal_ht+0x187d4, %rdx and %rax, %rax movups (%rdx), %xmm0 vpextrq $1, %xmm0, %r14 nop and %r12, %r12 lea addresses_A_ht+0x12708, %rsi lea addresses_normal_ht+0x17ad4, %rdi nop nop nop sub %r12, %r12 mov $19, %rcx rep movsl nop nop nop and %rdi, %rdi lea addresses_UC_ht+0x1ebd4, %rsi lea addresses_A_ht+0xcd54, %rdi cmp $36881, %rdx mov $124, %rcx rep movsb nop nop nop add %rdx, %rdx lea addresses_D_ht+0x1c454, %r14 add %rdx, %rdx movb (%r14), %cl nop and %r12, %r12 lea addresses_A_ht+0x2b94, %rax nop nop nop sub $35999, %r10 mov (%rax), %r12 cmp $30963, %r14 lea addresses_WC_ht+0x111fa, %rsi lea addresses_WC_ht+0x12fd4, %rdi nop nop nop nop xor $37514, %r12 mov $113, %rcx rep movsw nop sub $49912, %rdi lea addresses_D_ht+0x1448c, %rdi nop nop sub $47347, %rax movl $0x61626364, (%rdi) nop nop nop nop cmp $62763, %r14 pop %rsi pop %rdx pop %rdi pop %rcx pop %rax pop %r14 pop %r12 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r12 push %rbp push %rcx push %rdi push %rsi // Store lea addresses_WT+0x15a54, %r11 nop nop add %r10, %r10 movl $0x51525354, (%r11) nop nop inc %r12 // REPMOV lea addresses_A+0x1cc74, %rsi lea addresses_A+0x6b78, %rdi nop nop nop dec %rbp mov $5, %rcx rep movsq nop xor %rcx, %rcx // Load lea addresses_D+0x2ed4, %r11 dec %r12 mov (%r11), %cx nop sub %r10, %r10 // Faulty Load lea addresses_PSE+0x177d4, %r12 nop add %rbp, %rbp movb (%r12), %cl lea oracles, %rbp and $0xff, %rcx shlq $12, %rcx mov (%rbp,%rcx,1), %rcx pop %rsi pop %rdi pop %rcx pop %rbp pop %r12 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'NT': True, 'AVXalign': False, 'size': 2, 'congruent': 0, 'same': False, 'type': 'addresses_PSE'}, 'OP': 'LOAD'} {'dst': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 7, 'same': False, 'type': 'addresses_WT'}, 'OP': 'STOR'} {'src': {'congruent': 5, 'same': False, 'type': 'addresses_A'}, 'dst': {'congruent': 0, 'same': False, 'type': 'addresses_A'}, 'OP': 'REPM'} {'src': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 7, 'same': False, 'type': 'addresses_D'}, 'OP': 'LOAD'} [Faulty Load] {'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 0, 'same': True, 'type': 'addresses_PSE'}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 7, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'} {'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 11, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'LOAD'} {'src': {'congruent': 2, 'same': False, 'type': 'addresses_A_ht'}, 'dst': {'congruent': 6, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'REPM'} {'src': {'congruent': 8, 'same': False, 'type': 'addresses_UC_ht'}, 'dst': {'congruent': 7, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'REPM'} {'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 4, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'} {'src': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 6, 'same': True, 'type': 'addresses_A_ht'}, 'OP': 'LOAD'} {'src': {'congruent': 1, 'same': False, 'type': 'addresses_WC_ht'}, 'dst': {'congruent': 9, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM'} {'dst': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'STOR'} {'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 */
/**************************************************************************** ** Meta object code from reading C++ file 'templateloader.h' ** ** Created by: The Qt Meta Object Compiler version 67 (Qt 5.10.0) ** ** WARNING! All changes made in this file will be lost! *****************************************************************************/ #include "../../QtWebApp/templateengine/templateloader.h" #include <QtCore/qbytearray.h> #include <QtCore/qmetatype.h> #if !defined(Q_MOC_OUTPUT_REVISION) #error "The header file 'templateloader.h' doesn't include <QObject>." #elif Q_MOC_OUTPUT_REVISION != 67 #error "This file was generated using the moc from 5.10.0. It" #error "cannot be used with the include files from this version of Qt." #error "(The moc has changed too much.)" #endif QT_BEGIN_MOC_NAMESPACE QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED struct qt_meta_stringdata_stefanfrings__TemplateLoader_t { QByteArrayData data[1]; char stringdata0[29]; }; #define QT_MOC_LITERAL(idx, ofs, len) \ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ qptrdiff(offsetof(qt_meta_stringdata_stefanfrings__TemplateLoader_t, stringdata0) + ofs \ - idx * sizeof(QByteArrayData)) \ ) static const qt_meta_stringdata_stefanfrings__TemplateLoader_t qt_meta_stringdata_stefanfrings__TemplateLoader = { { QT_MOC_LITERAL(0, 0, 28) // "stefanfrings::TemplateLoader" }, "stefanfrings::TemplateLoader" }; #undef QT_MOC_LITERAL static const uint qt_meta_data_stefanfrings__TemplateLoader[] = { // content: 7, // revision 0, // classname 0, 0, // classinfo 0, 0, // methods 0, 0, // properties 0, 0, // enums/sets 0, 0, // constructors 0, // flags 0, // signalCount 0 // eod }; void stefanfrings::TemplateLoader::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) { Q_UNUSED(_o); Q_UNUSED(_id); Q_UNUSED(_c); Q_UNUSED(_a); } const QMetaObject stefanfrings::TemplateLoader::staticMetaObject = { { &QObject::staticMetaObject, qt_meta_stringdata_stefanfrings__TemplateLoader.data, qt_meta_data_stefanfrings__TemplateLoader, qt_static_metacall, nullptr, nullptr} }; const QMetaObject *stefanfrings::TemplateLoader::metaObject() const { return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; } void *stefanfrings::TemplateLoader::qt_metacast(const char *_clname) { if (!_clname) return nullptr; if (!strcmp(_clname, qt_meta_stringdata_stefanfrings__TemplateLoader.stringdata0)) return static_cast<void*>(this); return QObject::qt_metacast(_clname); } int stefanfrings::TemplateLoader::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); return _id; } QT_WARNING_POP QT_END_MOC_NAMESPACE
; ; Copyright (c) 2010 The WebM 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 "vpx_ports/x86_abi_support.asm" ;macro in deblock functions %macro FIRST_2_ROWS 0 movdqa xmm4, xmm0 movdqa xmm6, xmm0 movdqa xmm5, xmm1 pavgb xmm5, xmm3 ;calculate absolute value psubusb xmm4, xmm1 psubusb xmm1, xmm0 psubusb xmm6, xmm3 psubusb xmm3, xmm0 paddusb xmm4, xmm1 paddusb xmm6, xmm3 ;get threshold movdqa xmm2, flimit pxor xmm1, xmm1 movdqa xmm7, xmm2 ;get mask psubusb xmm2, xmm4 psubusb xmm7, xmm6 pcmpeqb xmm2, xmm1 pcmpeqb xmm7, xmm1 por xmm7, xmm2 %endmacro %macro SECOND_2_ROWS 0 movdqa xmm6, xmm0 movdqa xmm4, xmm0 movdqa xmm2, xmm1 pavgb xmm1, xmm3 ;calculate absolute value psubusb xmm6, xmm2 psubusb xmm2, xmm0 psubusb xmm4, xmm3 psubusb xmm3, xmm0 paddusb xmm6, xmm2 paddusb xmm4, xmm3 pavgb xmm5, xmm1 ;get threshold movdqa xmm2, flimit pxor xmm1, xmm1 movdqa xmm3, xmm2 ;get mask psubusb xmm2, xmm6 psubusb xmm3, xmm4 pcmpeqb xmm2, xmm1 pcmpeqb xmm3, xmm1 por xmm7, xmm2 por xmm7, xmm3 pavgb xmm5, xmm0 ;decide if or not to use filtered value pand xmm0, xmm7 pandn xmm7, xmm5 paddusb xmm0, xmm7 %endmacro %macro UPDATE_FLIMIT 0 movdqu xmm2, XMMWORD PTR [rbx] movdqu [rsp], xmm2 add rbx, 16 %endmacro SECTION .text ;void vpx_post_proc_down_and_across_mb_row_sse2 ;( ; unsigned char *src_ptr, ; unsigned char *dst_ptr, ; int src_pixels_per_line, ; int dst_pixels_per_line, ; int cols, ; int *flimits, ; int size ;) globalsym(vpx_post_proc_down_and_across_mb_row_sse2) sym(vpx_post_proc_down_and_across_mb_row_sse2): push rbp mov rbp, rsp SHADOW_ARGS_TO_STACK 7 SAVE_XMM 7 push rbx push rsi push rdi ; end prolog ALIGN_STACK 16, rax sub rsp, 16 ; put flimit on stack mov rbx, arg(5) ;flimits ptr UPDATE_FLIMIT %define flimit [rsp] mov rsi, arg(0) ;src_ptr mov rdi, arg(1) ;dst_ptr movsxd rax, DWORD PTR arg(2) ;src_pixels_per_line movsxd rcx, DWORD PTR arg(6) ;rows in a macroblock .nextrow: xor rdx, rdx ;col .nextcol: ;load current and next 2 rows movdqu xmm0, XMMWORD PTR [rsi] movdqu xmm1, XMMWORD PTR [rsi + rax] movdqu xmm3, XMMWORD PTR [rsi + 2*rax] FIRST_2_ROWS ;load above 2 rows neg rax movdqu xmm1, XMMWORD PTR [rsi + 2*rax] movdqu xmm3, XMMWORD PTR [rsi + rax] SECOND_2_ROWS movdqu XMMWORD PTR [rdi], xmm0 neg rax ; positive stride add rsi, 16 add rdi, 16 add rdx, 16 cmp edx, dword arg(4) ;cols jge .downdone UPDATE_FLIMIT jmp .nextcol .downdone: ; done with the all cols, start the across filtering in place sub rsi, rdx sub rdi, rdx mov rbx, arg(5) ; flimits UPDATE_FLIMIT ; dup the first byte into the left border 8 times movq mm1, [rdi] punpcklbw mm1, mm1 punpcklwd mm1, mm1 punpckldq mm1, mm1 mov rdx, -8 movq [rdi+rdx], mm1 ; dup the last byte into the right border movsxd rdx, dword arg(4) movq mm1, [rdi + rdx + -1] punpcklbw mm1, mm1 punpcklwd mm1, mm1 punpckldq mm1, mm1 movq [rdi+rdx], mm1 xor rdx, rdx movq mm0, QWORD PTR [rdi-16]; movq mm1, QWORD PTR [rdi-8]; .acrossnextcol: movdqu xmm0, XMMWORD PTR [rdi + rdx] movdqu xmm1, XMMWORD PTR [rdi + rdx -2] movdqu xmm3, XMMWORD PTR [rdi + rdx -1] FIRST_2_ROWS movdqu xmm1, XMMWORD PTR [rdi + rdx +1] movdqu xmm3, XMMWORD PTR [rdi + rdx +2] SECOND_2_ROWS movq QWORD PTR [rdi+rdx-16], mm0 ; store previous 8 bytes movq QWORD PTR [rdi+rdx-8], mm1 ; store previous 8 bytes movdq2q mm0, xmm0 psrldq xmm0, 8 movdq2q mm1, xmm0 add rdx, 16 cmp edx, dword arg(4) ;cols jge .acrossdone UPDATE_FLIMIT jmp .acrossnextcol .acrossdone: ; last 16 pixels movq QWORD PTR [rdi+rdx-16], mm0 cmp edx, dword arg(4) jne .throw_last_8 movq QWORD PTR [rdi+rdx-8], mm1 .throw_last_8: ; done with this rwo add rsi,rax ;next src line mov eax, dword arg(3) ;dst_pixels_per_line add rdi,rax ;next destination mov eax, dword arg(2) ;src_pixels_per_line mov rbx, arg(5) ;flimits UPDATE_FLIMIT dec rcx ;decrement count jnz .nextrow ;next row add rsp, 16 pop rsp ; begin epilog pop rdi pop rsi pop rbx RESTORE_XMM UNSHADOW_ARGS pop rbp ret %undef flimit ;void vpx_mbpost_proc_across_ip_sse2(unsigned char *src, ; int pitch, int rows, int cols,int flimit) globalsym(vpx_mbpost_proc_across_ip_sse2) sym(vpx_mbpost_proc_across_ip_sse2): push rbp mov rbp, rsp SHADOW_ARGS_TO_STACK 5 SAVE_XMM 7 GET_GOT rbx push rsi push rdi ; end prolog ALIGN_STACK 16, rax sub rsp, 16 ; create flimit4 at [rsp] mov eax, dword ptr arg(4) ;flimit mov [rsp], eax mov [rsp+4], eax mov [rsp+8], eax mov [rsp+12], eax %define flimit4 [rsp] ;for(r=0;r<rows;r++) .ip_row_loop: xor rdx, rdx ;sumsq=0; xor rcx, rcx ;sum=0; mov rsi, arg(0); s ; dup the first byte into the left border 8 times movq mm1, [rsi] punpcklbw mm1, mm1 punpcklwd mm1, mm1 punpckldq mm1, mm1 mov rdi, -8 movq [rsi+rdi], mm1 ; dup the last byte into the right border movsxd rdx, dword arg(3) movq mm1, [rsi + rdx + -1] punpcklbw mm1, mm1 punpcklwd mm1, mm1 punpckldq mm1, mm1 movq [rsi+rdx], mm1 .ip_var_loop: ;for(i=-8;i<=6;i++) ;{ ; sumsq += s[i]*s[i]; ; sum += s[i]; ;} movzx eax, byte [rsi+rdi] add ecx, eax mul al add edx, eax add rdi, 1 cmp rdi, 6 jle .ip_var_loop ;mov rax, sumsq ;movd xmm7, rax movd xmm7, edx ;mov rax, sum ;movd xmm6, rax movd xmm6, ecx mov rsi, arg(0) ;s xor rcx, rcx movsxd rdx, dword arg(3) ;cols add rdx, 8 pxor mm0, mm0 pxor mm1, mm1 pxor xmm0, xmm0 .nextcol4: movd xmm1, DWORD PTR [rsi+rcx-8] ; -8 -7 -6 -5 movd xmm2, DWORD PTR [rsi+rcx+7] ; +7 +8 +9 +10 punpcklbw xmm1, xmm0 ; expanding punpcklbw xmm2, xmm0 ; expanding punpcklwd xmm1, xmm0 ; expanding to dwords punpcklwd xmm2, xmm0 ; expanding to dwords psubd xmm2, xmm1 ; 7--8 8--7 9--6 10--5 paddd xmm1, xmm1 ; -8*2 -7*2 -6*2 -5*2 paddd xmm1, xmm2 ; 7+-8 8+-7 9+-6 10+-5 pmaddwd xmm1, xmm2 ; squared of 7+-8 8+-7 9+-6 10+-5 paddd xmm6, xmm2 paddd xmm7, xmm1 pshufd xmm6, xmm6, 0 ; duplicate the last ones pshufd xmm7, xmm7, 0 ; duplicate the last ones psrldq xmm1, 4 ; 8--7 9--6 10--5 0000 psrldq xmm2, 4 ; 8--7 9--6 10--5 0000 pshufd xmm3, xmm1, 3 ; 0000 8--7 8--7 8--7 squared pshufd xmm4, xmm2, 3 ; 0000 8--7 8--7 8--7 squared paddd xmm6, xmm4 paddd xmm7, xmm3 pshufd xmm3, xmm1, 01011111b ; 0000 0000 9--6 9--6 squared pshufd xmm4, xmm2, 01011111b ; 0000 0000 9--6 9--6 squared paddd xmm7, xmm3 paddd xmm6, xmm4 pshufd xmm3, xmm1, 10111111b ; 0000 0000 8--7 8--7 squared pshufd xmm4, xmm2, 10111111b ; 0000 0000 8--7 8--7 squared paddd xmm7, xmm3 paddd xmm6, xmm4 movdqa xmm3, xmm6 pmaddwd xmm3, xmm3 movdqa xmm5, xmm7 pslld xmm5, 4 psubd xmm5, xmm7 psubd xmm5, xmm3 psubd xmm5, flimit4 psrad xmm5, 31 packssdw xmm5, xmm0 packsswb xmm5, xmm0 movd xmm1, DWORD PTR [rsi+rcx] movq xmm2, xmm1 punpcklbw xmm1, xmm0 punpcklwd xmm1, xmm0 paddd xmm1, xmm6 paddd xmm1, [GLOBAL(four8s)] psrad xmm1, 4 packssdw xmm1, xmm0 packuswb xmm1, xmm0 pand xmm1, xmm5 pandn xmm5, xmm2 por xmm5, xmm1 movd [rsi+rcx-8], mm0 movq mm0, mm1 movdq2q mm1, xmm5 psrldq xmm7, 12 psrldq xmm6, 12 add rcx, 4 cmp rcx, rdx jl .nextcol4 ;s+=pitch; movsxd rax, dword arg(1) add arg(0), rax sub dword arg(2), 1 ;rows-=1 cmp dword arg(2), 0 jg .ip_row_loop add rsp, 16 pop rsp ; begin epilog pop rdi pop rsi RESTORE_GOT RESTORE_XMM UNSHADOW_ARGS pop rbp ret %undef flimit4 SECTION_RODATA align 16 four8s: times 4 dd 8
SECTION code_clib SECTION code_stdio PUBLIC __stdio_printf_g EXTERN __dtog__, __stdio_printf_float_tail __stdio_printf_g: ; %g, %G converter called from vfprintf() ; ; enter : ix = FILE * ; hl = void *stack_param ; de = void *buffer_digits ; hl'= current output tally ; stack = buffer_digits, width, precision ; ; exit : carry set if stream error ; ; NOTE: (buffer_digits - 3) points at buffer space of three free bytes ; snprintf requires bc',de' to be preserved pop bc ; bc = precision ex (sp),hl ; hl = width exx ex (sp),hl ; save tally, hl = stack_param * push de ; save snprintf variable push bc ; save snprintf variable ex de,hl ld hl,-65 add hl,sp ld sp,hl ex de,hl push ix IF __SDCC | __SDCC_IX | __SDCC_IY EXTERN dload call dload ; exx set = double x ELSE EXTERN dloadb call dloadb ; exx set = double x ENDIF ; exx occurred push hl ; save width ex de,hl ; hl = void *buffer_digits ld e,c ld d,b ; de = precision ; de = precision ; hl = buffer * ; ix = FILE * ; exx = double x ; stack = buffer_digits, tally, de', bc', BUFFER_65, FILE *, width ld c,(ix+5) ; c = printf flags bit 0,c jr nz, prec_defined ld de,6 ; default precision is six prec_defined: call __dtog__ ; generate hexadecimal string ; bc = workspace length ; de = workspace * ; stack = buffer_digits, tally, de', bc', BUFFER_65, FILE *, width ; ; (IX-6) = flags, bit 7 = 'N', bit 4 = '#', bit 0 = precision==0 ; (IX-5) = iz (number of zeroes to insert before .) ; (IX-4) = fz (number of zeroes to insert after .) ; (IX-3) = tz (number of zeroes to append) ; (IX-2) = ignore ; (IX-1) = '0' marks start of buffer ; ; carry set = special form just output buffer with sign jp __stdio_printf_float_tail