text stringlengths 1 1.05M |
|---|
;
; Sharp OZ family functions
;
; ported from the OZ-7xx SDK by by Alexander R. Pruss
; by Stefano Bodrato - Oct. 2003
;
;
; custom interrupt code + key scanning
;
;
; ------
; $Id: ozcustomisr.asm,v 1.5 2012/04/16 08:44:34 stefano Exp $
;
XLIB ozcustomisr
XDEF serial_hook
XDEF ozkeyclick
XDEF oz1hz
XDEF oz64hz_word
XDEF oz64hz_dword
XDEF ozi64hztime
XDEF oz4sec_word
XDEF ozi64hzcount
XDEF ozdisablepowerkey
XDEF ozgreyscale
XDEF ozgreycount
XDEF s_64hz_hook
XDEF s_64hz_return
XREF cleanup ; exit in oz_crt0
XREF s_init_unblank ; exit quickly "
XREF KeyboardBuffer
XREF KeyBufGetPos
XREF KeyBufPutPos
; settings
XREF ozkeyrepeatspeed
XREF ozkeyrepeatdelay
XREF ozclick_setting
defc PauseFirst = 32
PowerOff:
ld a,(ozdisablepowerkey)
or a
jp nz,NotPowerOff
inc a
ld (ozdisablepowerkey),a
ld hl,kPower
ld (KeyboardBuffer),hl
ld a,0bh
ld (KeyBufGetPos),a
xor a
ld (KeyBufPutPos),a
;jp _exit
jp cleanup
FastClock:
ld a,(ozgreyscale)
or a
jp z,FastClockDone
push hl
ld hl,(ozgreycount)
dec hl
ld (ozgreycount),hl
ld a,l
or h
jp nz,pophl_FastClockDone
in a,(22h)
xor 4
out (22h),a
ld hl,110
jr z,NotAdd ;; second page -- only 300 delay
add hl,hl
NotAdd:
ld (ozgreycount),hl
pophl_FastClockDone:
pop hl
FastClockDone:
ld a,d
and 0ffh - 64
jr nz,FromFastClock
ei
ret
; ------------------------------------
ozcustomisr:
in a,(5)
ld d,a
ld a,0ffh
out (6),a
in a,(7) ;; mask
cpl
and d
ld d,a
bit 6,d
jp nz,FastClock
FromFastClock:
bit 0,d ;; e ;; get keyboard bit
call nz,KbdHit
in a,(46h)
and 16
jp nz,PowerOff ;; power switch depressed
NotPowerOff:
in a,(12h)
and 128
;jp z,__exit ;; battery switch flipped - get out rapidly
jp z,s_init_unblank ;; battery switch flipped - get out rapidly
serial_hook:
jp GetOutPopAF
;$serial_hook equ $-2
GetOutPopAF:
bit 4,d ;; 1hz
jr nz,Inc1hz
notInc1hz:
bit 5,d ;; 64hz
jp nz,KbdAndClock
ei
ret
Inc1hz:
push hl
ld hl,(oz1hz)
inc hl
ld (oz1hz),hl
pop hl
jr notInc1hz
KbdHit:
ozi64hztime:
ld a,PauseFirst+1
;__ozi64hztime equ $-1
ld (ozi64hzcount),a
or a
ret z
in a,(7)
and 255-32 ;; enable 64hz interrupt
or 1 ;; disable keyboard interrupt for now
out (7),a
ret
KbdAndClock:
ld a,(keybusy)
or a
ret nz
dec a ; a=ff
ld (keybusy),a
ei
jp key_isr
key_isr_ret:
xor a
ld (keybusy),a
ret
ozdisablepowerkey:
defs 1
ozi64hzcount:
defs 1
ozgreyscale:
defs 1
ozgreycount:
defs 2
oz1hz:
defs 2
oz64hz_word:
oz64hz_dword:
defs 1
oz4sec_word:
defs 1
defs 2
keybusy:
defs 1
; Keyboard driver adapted from software labeled:
; Source code free for non-commercial use
; Assembled program (C)2000 OZdev <http://www.ozdev.com/>
; Benjamin Green <benjamin@lh.co.nz>
keyTable: defs 10
mask10: defs 1
mask11: defs 1
repeatcount: defs 1
repeatkey: defs 2
mask12: defs 1
defc Mask2nd = 01h
defc MaskNew = 02h
defc MaskInv = 04h
defc MaskShift = 08h
defc kPower = 803Ah
defc kUpperMenu = 8068h
defc kUpperEnter = 8066h
defc kUpperEsc = 8067h
defc kEnter = 8038h
defc kLShift = 0000h
defc kRShift = 8836h
defc k2nd = 8137h
defc kEsc = 8058h
defc kMenu = 8032h
defc kNew = 8233h
defc kInv = 8435h
defc kUp = 8040h
defc kDown = 8041h
defc kRight = 8043h
defc kLeft = 8042h
defc kMain = 7025h
defc kTel = 70e9h
defc kSched = 70eah
defc kMemo = 70ebh
defc kMyProg = 7015h
defc kLight = 803bh
defc kPageUp = 8044h
defc kPageDown = 8045h
key_isr:
push bc
push de
push hl
ld hl,ozi64hzcount
ld a,(hl)
or a
jr z,skipCountDown
dec a
ld (hl),a
jr nz,skipCountDown
in a,(7)
or 32 ;; disable 64hz interrupt
and 255-1 ;; but enable keyboard interrupt
out (7),a
skipCountDown:
ld hl,(oz64hz_dword)
ld bc,1
add hl,bc
ld (oz64hz_dword),hl
ld hl,(oz64hz_dword+2)
ld bc,0
adc hl,bc
ld (oz64hz_dword+2),hl
; global $64hz_hook,$64hz_return
s_64hz_hook:
jp s_64hz_return
;$64hz_hook equ $-2
s_64hz_return:
rxxoff_hook:
jp noxoff
;$rxxoff_hook equ $-2
noxoff:
ld a,(KeyBufPutPos)
inc a
cp 0ch
jr c,dontzero
xor a
dontzero:
ld b,a
ld a,(KeyBufGetPos)
cp b
jp z,KBufferFull
xor a
out (11h),a
ld a,2
out (12h),a
ld (mask12),a
ld hl,keyTable+8
in a,(10h)
ld b,(hl)
ld (hl),a
or b
xor b
and a
jr z,noProgKey1
bitP0: bit 0,a
jr z,bitP1
ld a,56
ld l,1
jp lookup
bitP1: bit 1,a
jr z,bitP2
ld a,57
ld l,2
jr lookup
bitP2: bit 2,a
jr z,bitP3
ld a,58
ld l,4
jr lookup
bitP3: bit 3,a
jr z,bitP4
ld a,59
ld l,8
jr lookup
bitP4: bit 4,a
jr z,bitP6
ld a,60
ld l,16
jr lookup
bitP6: bit 6,a
jr z,noProgKey1
ld a,61
ld l,64
jr lookup
noProgKey1:
ld a,1
out (12h),a
ld (mask12),a
ld hl,keyTable+9
in a,(10h)
ld b,(hl)
ld (hl),a
or b
xor b
and a
jr z,noProgKey2
abitP0: bit 0,a
jr z,abitP3
ld a,62
ld l,1
jp lookup
abitP3: bit 3,a
jr z,abitP4
ld a,63
ld l,8
jr lookup
abitP4: bit 4,a
jr z,abitP5
ld a,64
ld l,16
jr lookup
abitP5: bit 5,a
jr z,abitP6
ld a,65
ld l,32
jr lookup
abitP6: bit 6,a
jr z,noProgKey2
ld a,66
ld l,64
lookup: ld e,a
xor a
ld (mask11),a
ld a,l
ld (mask10),a
jr lookup2
noProgKey2:
xor a
out (12h),a
ld hl,keyTable
ld de,100h
keyscan:
ld a,d
out (11h),a
in a,(10h)
ld b,(hl)
ld (hl),a
or b
xor b
and a
jr nz,bit0
inc e
inc hl
sla d
jr nz,keyscan
bit0: bit 0,a
jr z,bit1
ld a,e
ld l,1
jr rlookup
bit1: bit 1,a
jr z,bit2
ld a,e
add a,8
ld l,2
jr rlookup
bit2: bit 2,a
jr z,bit3
ld a,e
add a,16
ld l,4
jr rlookup
bit3: bit 3,a
jr z,bit4
ld a,e
add a,24
ld l,8
jr rlookup
bit4: bit 4,a
jr z,bit5
ld a,e
add a,32
ld l,16
jr rlookup
bit5: bit 5,a
jr z,bit6
ld a,e
add a,40
ld l,32
jr rlookup
bit6: bit 6,a
jp z,nokey
ld a,e
add a,48
ld l,64
rlookup:
ld e,a
ld a,l
ld hl,mask10
ld (hl),a
inc hl ; =mask11
ld (hl),d
xor a
ld (mask12),a
lookup2:
xor a
ld hl,keyTable
ld b,(hl)
bit 6,b
jr z,no2nd
ld a,Mask2nd
no2nd: bit 5,b
jr nz,shift
ld hl,keyTable+6
bit 3,(hl)
jr z,noShift
shift: or MaskShift
noShift:
ld hl,keyTable+3
bit 6,(hl)
jr z,noInv
or MaskInv
noInv:
dec hl
bit 6,(hl)
jr z,noNew
or MaskNew
noNew:
lookupKey:
ld b,a
ld hl,keys
ld d,0
add hl,de
add hl,de
ld a,(hl)
ld c,a
inc hl
ld a,(hl)
xor b
ld b,a
ld hl,repeatcount
ld a,(ozkeyrepeatdelay)
ld (hl),a
inc hl ; =repeatkey
ld (hl),c
inc hl
ld (hl),b
putinbuf:
call KbdHit
ld a,(ozclick_setting)
or a
call nz,ozkeyclick
putinbuf_noclick:
ld a,(KeyBufPutPos)
inc a
cp 0ch
jr c,dontzero2
xor a
dontzero2:
ld (KeyBufPutPos),a
ld e,a
ld d,0
ld hl,KeyboardBuffer
add hl,de
add hl,de
ld (hl),c
inc hl
ld (hl),b
KBufferFull:
iret: ld a,0ffh
out (11h),a
out (12h),a
pop hl
pop de
pop bc
jp key_isr_ret
clearrepeat:
xor a
ld hl,mask11
ld (hl),a ; hl=mask11
inc hl
ld (hl),a ; hl=mask12
jr iret
nokey:
ld a,(mask12)
ld hl,mask11
ld c,(hl) ; c=(mask11)
or c
jr z,iret ; nothing to repeat
inc hl ; =repeatcount
inc hl ; =repeatkey
ld hl,repeatkey
xor a
ld b,(hl)
or b
jr z,clearrepeat ; lower shift - do not repeat
inc hl
ld a,080h
and (hl)
jr z,doRepeat ; not any other shift key
ld a,b
cp kRShift ~ 0ffh
jr z,clearrepeat
cp kNew ~ 0ffh
jr z,clearrepeat
cp kInv ~ 0ffh
jr z,clearrepeat
cp k2nd ~ 0ffh
jr z,clearrepeat
doRepeat:
ld hl,mask10
ld a,c
out (11h),a ; set mask
ld a,(mask12)
out (12h),a
in a,(10h)
and (hl) ; (mask10)
inc hl ; =mask11
jr z,clearrepeat ; key to be repeated released
inc hl ; =repeatcount
dec (hl)
ld a,(hl)
or a
jr nz,iret ; not time yet
ld a,(ozkeyrepeatspeed)
ld (hl),a
inc hl ; =repeatkey
ld c,(hl)
inc hl
ld b,(hl)
jp putinbuf_noclick
keys: defw kEsc,'1','2','3','4','5','6','7'
defw 'q','w','e','r','t','8','9','0'
defw 0,'y','u','i','o','p',8,'.'
defw 'g','h','j','k','l',13,kRShift,','
defw 'a','s','d','f',kLeft,kDown,kRight,kUp
defw kLShift,'z','x','c','v','b','n','m'
defw k2nd,kMenu,kNew,kInv,' ','-',kEnter,0
defw kMain,kTel,kSched,kMemo,kMyProg,kLight
defw kUpperMenu,kUpperEsc,kUpperEnter,kPageUp,kPageDown
ozkeyclick:
in a,(15h)
and a
ret nz ; bell char takes priority
ld a,1
out (19h),a
out (16h),a
xor a
keyclick: dec a
jr nz,keyclick
out (16h),a
dontClick:
ret
|
org 100h
A DB 5 DUP(2,3,4,5,6)
ret
|
#include "MultiFuncShield.h"
inline bool Button1() { return !digitalRead(BUTTON_1_PIN); };
inline bool Button2() { return !digitalRead(BUTTON_2_PIN); };
inline bool Button3() { return !digitalRead(BUTTON_3_PIN); };
void button1_func();
void button2_func();
void button3_func();
|
if 0
println "zero"
else
println "one"
if 1
println "A"
else
println "B"
elif 2
println "C"
else
println "D"
endc
elif 2
println "two"
else
println "three"
endc
|
; Copyright © 2018, VideoLAN and dav1d authors
; Copyright © 2018, Two Orioles, LLC
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
;
; 1. Redistributions of source code must retain the above copyright notice, this
; list of conditions and the following disclaimer.
;
; 2. Redistributions in binary form must reproduce the above copyright notice,
; this list of conditions and the following disclaimer in the documentation
; and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%include "config.asm"
%include "ext/x86/x86inc.asm"
%if ARCH_X86_64
SECTION_RODATA 32
; Note: The order of (at least some of) those constants matter!
iadst4_dconly2a: dw 10568, 10568, 10568, 10568, 19856, 19856, 19856, 19856
iadst4_dconly2b: dw 26752, 26752, 26752, 26752, 30424, 30424, 30424, 30424
iadst4_dconly1a: dw 10568, 19856, 26752, 30424
iadst4_dconly1b: dw 30424, 26752, 19856, 10568
deint_shuf: db 0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15
%macro COEF_PAIR 2
pw_%1_%2: dw %1, %2
pw_m%2_%1: dw -%2, %1
%endmacro
; ADST-only
pw_3803_1321: dw 3803, 1321
pw_m1321_2482: dw -1321, 2482
pw_2482_3344: dw 2482, 3344
pw_m3803_3344: dw -3803, 3344
pw_m3803_m6688: dw -3803, -6688
%define pw_3344x8 iadst4_dconly2b
pw_5: times 2 dw 5
pw_2048: times 2 dw 2048
pw_4096: times 2 dw 4096
pw_8192: times 2 dw 8192
pw_16384: times 2 dw 16384
pw_2896x8: times 2 dw 2896*8
pw_5793x4: times 2 dw 5793*4
pd_2048: dd 2048
COEF_PAIR 1567, 3784
COEF_PAIR 3784, 1567
COEF_PAIR 201, 4091
COEF_PAIR 995, 3973
COEF_PAIR 1751, 3703
COEF_PAIR 2440, 3290
COEF_PAIR 3035, 2751
COEF_PAIR 3513, 2106
COEF_PAIR 3857, 1380
COEF_PAIR 4052, 601
COEF_PAIR 401, 4076
COEF_PAIR 1931, 3612
COEF_PAIR 3166, 2598
COEF_PAIR 3920, 1189
COEF_PAIR 799, 4017
COEF_PAIR 3406, 2276
pw_m799_m4017: dw -799, -4017
pw_m1567_m3784: dw -1567, -3784
pw_m3406_m2276: dw -3406, -2276
pw_m401_m4076: dw -401, -4076
pw_m3166_m2598: dw -3166, -2598
pw_m1931_m3612: dw -1931, -3612
pw_m3920_m1189: dw -3920, -1189
COEF_PAIR 2276, 3406
COEF_PAIR 4017, 799
%macro COEF_X8 1-*
%rep %0
dw %1*8, %1*8
%rotate 1
%endrep
%endmacro
pw_3703x8: COEF_X8 3703
pw_1751x8: COEF_X8 1751
pw_m1380x8: COEF_X8 -1380
pw_3857x8: COEF_X8 3857
pw_3973x8: COEF_X8 3973
pw_995x8: COEF_X8 995
pw_m2106x8: COEF_X8 -2106
pw_3513x8: COEF_X8 3513
pw_3290x8: COEF_X8 3290
pw_2440x8: COEF_X8 2440
pw_m601x8: COEF_X8 -601
pw_4052x8: COEF_X8 4052
idct64_mul: COEF_X8 4095, 101, 4065, 501, 2967, -2824, 3229, -2520
COEF_X8 3745, 1660, 3564, 2019, 3822, -1474, 3948, -1092
COEF_X8 3996, 897, 3889, 1285, 3461, -2191, 3659, -1842
COEF_X8 3349, 2359, 3102, 2675, 4036, -700, 4085, -301
%define o_idct64_offset idct64_mul - (o_base) - 8
SECTION .text
; Code size reduction trickery: Intead of using rip-relative loads with
; mandatory 4-byte offsets everywhere, we can set up a base pointer with a
; single rip-relative lea and then address things relative from that with
; 1-byte offsets as long as data is within +-128 bytes of the base pointer.
%define o_base iadst4_dconly2a + 128
%define o(x) (rax - (o_base) + (x))
%macro REPX 2-*
%xdefine %%f(x) %1
%rep %0 - 1
%rotate 1
%%f(%1)
%endrep
%endmacro
%define m(x) mangle(private_prefix %+ _ %+ x %+ SUFFIX)
; flags: 1 = swap, 2 = interleave, 4: coef_regs
%macro ITX_MUL2X_PACK 6-7 0 ; dst/src, tmp[1-2], rnd, coef[1-2], flags
%if %7 & 4
pmaddwd m%2, m%5, m%1
pmaddwd m%1, m%6
%else
%if %7 & 1
vpbroadcastd m%2, [o(pw_%5_%6)]
vpbroadcastd m%3, [o(pw_m%6_%5)]
%else
vpbroadcastd m%2, [o(pw_m%6_%5)]
vpbroadcastd m%3, [o(pw_%5_%6)]
%endif
pmaddwd m%2, m%1
pmaddwd m%1, m%3
%endif
paddd m%2, m%4
paddd m%1, m%4
%if %7 & 2
pslld m%2, 4
psrld m%1, 12
pblendw m%1, m%2, 0xaa
%else
psrad m%2, 12
psrad m%1, 12
packssdw m%1, m%2
%endif
%endmacro
; flags: 1 = swap, 2 = interleave, 4 = coef_regs
%macro ITX_MUL4X_PACK 9-10 0 ; dst/src, tmp[1-3], rnd, coef[1-4], flags
%if %10 & 1
vpbroadcastd m%3, [o(pw_%8_%9)]
vpbroadcastd m%4, [o(pw_m%9_%8)]
vpbroadcastd xm%2, [o(pw_%6_%7)]
vpblendd m%2, m%2, m%3, 0xf0
vpbroadcastd xm%3, [o(pw_m%7_%6)]
%else
vpbroadcastd m%3, [o(pw_m%9_%8)]
vpbroadcastd m%4, [o(pw_%8_%9)]
vpbroadcastd xm%2, [o(pw_m%7_%6)]
vpblendd m%2, m%2, m%3, 0xf0
vpbroadcastd xm%3, [o(pw_%6_%7)]
%endif
vpblendd m%3, m%3, m%4, 0xf0
ITX_MUL2X_PACK %1, %4, _, %5, %2, %3, (4|%10)
%endmacro
; dst1 = (src1 * coef1 - src2 * coef2 + rnd) >> 12
; dst2 = (src1 * coef2 + src2 * coef1 + rnd) >> 12
%macro ITX_MULSUB_2W 7 ; dst/src[1-2], tmp[1-2], rnd, coef[1-2]
punpckhwd m%3, m%2, m%1
punpcklwd m%2, m%1
%if %7 < 32
pmaddwd m%1, m%7, m%2
pmaddwd m%4, m%7, m%3
%else
vpbroadcastd m%1, [o(pw_m%7_%6)]
pmaddwd m%4, m%3, m%1
pmaddwd m%1, m%2
%endif
paddd m%4, m%5
paddd m%1, m%5
psrad m%4, 12
psrad m%1, 12
packssdw m%1, m%4
%if %7 < 32
pmaddwd m%3, m%6
pmaddwd m%2, m%6
%else
vpbroadcastd m%4, [o(pw_%6_%7)]
pmaddwd m%3, m%4
pmaddwd m%2, m%4
%endif
paddd m%3, m%5
paddd m%2, m%5
psrad m%3, 12
psrad m%2, 12
packssdw m%2, m%3
%endmacro
%macro ITX_MULHRSW_SHL3 4 ; dst/src, tmp, coef[1-2]
vpbroadcastd m%2, [pw_%3_%4]
psllw m%2, 3
pmulhrsw m%1, m%2
%endmacro
%macro IDCT4_1D 7 ; src[1-4], tmp[1-2], pd_2048
ITX_MULSUB_2W %2, %4, %5, %6, %7, 1567, 3784 ; t2, t3
vpbroadcastd m%6, [o(pw_2896x8)]
paddw m%5, m%1, m%3
psubw m%1, m%3
pmulhrsw m%1, m%6 ; t1
pmulhrsw m%5, m%6 ; t0
psubw m%3, m%1, m%2
paddw m%2, m%1
paddw m%1, m%5, m%4
psubw m%4, m%5, m%4
%endmacro
%macro IDCT8_1D 11 ; src[1-8], tmp[1-2], pd_2048
ITX_MULSUB_2W %6, %4, %9, %10, %11, 3406, 2276 ; t5a, t6a
ITX_MULSUB_2W %2, %8, %9, %10, %11, 799, 4017 ; t4a, t7a
ITX_MULSUB_2W %3, %7, %9, %10, %11, 1567, 3784 ; t2, t3
paddw m%9, m%2, m%6 ; t4
psubw m%2, m%6 ; t5a
paddw m%10, m%8, m%4 ; t7
psubw m%8, m%4 ; t6a
vpbroadcastd m%4, [o(pw_2896x8)]
psubw m%6, m%1, m%5
paddw m%1, m%5
psubw m%5, m%8, m%2
paddw m%8, m%2
pmulhrsw m%1, m%4 ; t0
pmulhrsw m%6, m%4 ; t1
pmulhrsw m%8, m%4 ; t6
pmulhrsw m%5, m%4 ; t5
psubw m%4, m%1, m%7 ; dct4 out3
paddw m%1, m%7 ; dct4 out0
paddw m%7, m%6, m%3 ; dct4 out1
psubw m%6, m%3 ; dct4 out2
paddw m%2, m%7, m%8 ; out1
psubw m%7, m%8 ; out6
psubw m%8, m%1, m%10 ; out7
paddw m%1, m%10 ; out0
paddw m%3, m%6, m%5 ; out2
psubw m%6, m%5 ; out5
psubw m%5, m%4, m%9 ; out4
paddw m%4, m%9 ; out3
%endmacro
; in1 = %1, in3 = %2, in5 = %3, in7 = %4
; in9 = %5, in11 = %6, in13 = %7, in15 = %8
%macro IDCT16_1D_ODDHALF 11 ; src[1-8], tmp[1-2], pd_2048
ITX_MULSUB_2W %1, %8, %9, %10, %11, 401, 4076 ; t8a, t15a
ITX_MULSUB_2W %5, %4, %9, %10, %11, 3166, 2598 ; t9a, t14a
ITX_MULSUB_2W %3, %6, %9, %10, %11, 1931, 3612 ; t10a, t13a
ITX_MULSUB_2W %7, %2, %9, %10, %11, 3920, 1189 ; t11a, t12a
psubw m%9, m%2, m%6 ; t13
paddw m%6, m%2 ; t12
psubw m%2, m%8, m%4 ; t14
paddw m%8, m%4 ; t15
psubw m%4, m%7, m%3 ; t10
paddw m%3, m%7 ; t11
psubw m%7, m%1, m%5 ; t9
paddw m%1, m%5 ; t8
ITX_MULSUB_2W %2, %7, %5, %10, %11, 1567, 3784 ; t9a, t14a
ITX_MULSUB_2W %9, %4, %5, %10, %11, m3784, 1567 ; t10a, t13a
vpbroadcastd m%10, [o(pw_2896x8)]
psubw m%5, m%2, m%9 ; t10
paddw m%2, m%9 ; t9
psubw m%9, m%1, m%3 ; t11a
paddw m%1, m%3 ; t8a
psubw m%3, m%7, m%4 ; t13
paddw m%7, m%4 ; t14
psubw m%4, m%8, m%6 ; t12a
paddw m%8, m%6 ; t15a
paddw m%6, m%3, m%5 ; t13a
psubw m%3, m%5 ; t10a
paddw m%5, m%4, m%9 ; t12
psubw m%4, m%9 ; t11
REPX {pmulhrsw x, m%10}, m%6, m%3, m%5, m%4
%endmacro
%macro WRAP_XMM 1+
INIT_XMM cpuname
%1
INIT_YMM cpuname
%endmacro
%macro ITX4_END 4-5 2048 ; row[1-4], rnd
%if %5
vpbroadcastd m2, [o(pw_%5)]
pmulhrsw m0, m2
pmulhrsw m1, m2
%endif
lea r2, [dstq+strideq*2]
%assign %%i 1
%rep 4
%if %1 & 2
CAT_XDEFINE %%row_adr, %%i, r2 + strideq*(%1&1)
%else
CAT_XDEFINE %%row_adr, %%i, dstq + strideq*(%1&1)
%endif
%assign %%i %%i + 1
%rotate 1
%endrep
movd m2, [%%row_adr1]
pinsrd m2, [%%row_adr2], 1
movd m3, [%%row_adr3]
pinsrd m3, [%%row_adr4], 1
pmovzxbw m2, m2
pmovzxbw m3, m3
paddw m0, m2
paddw m1, m3
packuswb m0, m1
movd [%%row_adr1], m0
pextrd [%%row_adr2], m0, 1
pextrd [%%row_adr3], m0, 2
pextrd [%%row_adr4], m0, 3
ret
%endmacro
%macro IWHT4_1D_PACKED 0
punpckhqdq m3, m0, m1 ; in1 in3
punpcklqdq m0, m1 ; in0 in2
psubw m2, m0, m3
paddw m0, m3
punpckhqdq m2, m2 ; t2 t2
punpcklqdq m0, m0 ; t0 t0
psubw m1, m0, m2
psraw m1, 1
psubw m1, m3 ; t1 t3
psubw m0, m1 ; ____ out0
paddw m2, m1 ; out3 ____
%endmacro
INIT_XMM avx2
cglobal inv_txfm_add_wht_wht_4x4, 3, 3, 4, dst, stride, c
mova m0, [cq+16*0]
mova m1, [cq+16*1]
pxor m2, m2
mova [cq+16*0], m2
mova [cq+16*1], m2
psraw m0, 2
psraw m1, 2
IWHT4_1D_PACKED
punpckhwd m0, m1
punpcklwd m3, m1, m2
punpckhdq m1, m0, m3
punpckldq m0, m3
IWHT4_1D_PACKED
vpblendd m0, m0, m2, 0x03
ITX4_END 3, 0, 2, 1, 0
%macro INV_TXFM_FN 4 ; type1, type2, fast_thresh, size
cglobal inv_txfm_add_%1_%2_%4, 4, 5, 0, dst, stride, c, eob, tx2
%undef cmp
%define %%p1 m(i%1_%4_internal)
lea rax, [o_base]
; Jump to the 1st txfm function if we're not taking the fast path, which
; in turn performs an indirect jump to the 2nd txfm function.
lea tx2q, [m(i%2_%4_internal).pass2]
%if %3 > 0
cmp eobd, %3
jg %%p1
%elif %3 == 0
test eobd, eobd
jnz %%p1
%else
; jump to the 1st txfm function unless it's located directly after this
times ((%%end - %%p1) >> 31) & 1 jmp %%p1
ALIGN function_align
%%end:
%endif
%endmacro
%macro INV_TXFM_4X4_FN 2-3 -1 ; type1, type2, fast_thresh
INV_TXFM_FN %1, %2, %3, 4x4
%ifidn %1_%2, dct_identity
vpbroadcastd m0, [o(pw_2896x8)]
pmulhrsw m0, [cq]
vpbroadcastd m1, [o(pw_5793x4)]
paddw m0, m0
pmulhrsw m0, m1
punpcklwd m0, m0
punpckhdq m1, m0, m0
punpckldq m0, m0
jmp m(iadst_4x4_internal).end
%elifidn %1_%2, identity_dct
mova m0, [cq+16*0]
packusdw m0, [cq+16*1]
vpbroadcastd m2, [o(pw_5793x4)]
vpbroadcastd m3, [o(pw_2896x8)]
packusdw m0, m0
paddw m0, m0
pmulhrsw m0, m2
pmulhrsw m0, m3
mova m1, m0
jmp m(iadst_4x4_internal).end
%elif %3 >= 0
vpbroadcastw m0, [cq]
%ifidn %1, dct
vpbroadcastd m1, [o(pw_2896x8)]
pmulhrsw m0, m1
%elifidn %1, adst
movddup m1, [o(iadst4_dconly1a)]
pmulhrsw m0, m1
%elifidn %1, flipadst
movddup m1, [o(iadst4_dconly1b)]
pmulhrsw m0, m1
%endif
mov [cq], eobd ; 0
%ifidn %2, dct
%ifnidn %1, dct
vpbroadcastd m1, [o(pw_2896x8)]
%endif
pmulhrsw m0, m1
mova m1, m0
jmp m(iadst_4x4_internal).end2
%else ; adst / flipadst
pmulhrsw m1, m0, [o(iadst4_dconly2b)]
pmulhrsw m0, [o(iadst4_dconly2a)]
jmp m(i%2_4x4_internal).end2
%endif
%endif
%endmacro
%macro IDCT4_1D_PACKED 0-1 ; pw_2896x8
vpbroadcastd m4, [o(pd_2048)]
punpckhwd m2, m1, m0
psubw m3, m0, m1
paddw m0, m1
punpcklqdq m0, m3
ITX_MUL2X_PACK 2, 1, 3, 4, 1567, 3784
%if %0 == 1
pmulhrsw m0, m%1
%else
vpbroadcastd m4, [o(pw_2896x8)]
pmulhrsw m0, m4 ; t0 t1
%endif
psubw m1, m0, m2 ; out3 out2
paddw m0, m2 ; out0 out1
%endmacro
%macro IADST4_1D_PACKED 0
punpcklwd m2, m1, m0
punpckhwd m3, m1, m0
psubw m0, m1
punpckhqdq m1, m1
paddw m1, m0 ; in0 - in2 + in3
vpbroadcastd m0, [o(pw_3803_1321)]
vpbroadcastd m4, [o(pw_m1321_2482)]
pmaddwd m0, m2
pmaddwd m2, m4
vpbroadcastd m4, [o(pw_2482_3344)]
vpbroadcastd m5, [o(pw_m3803_3344)]
pmaddwd m4, m3
pmaddwd m5, m3
paddd m4, m0 ; 1321*in0 + 3344*in1 + 3803*in2 + 2482*in3
vpbroadcastd m0, [o(pw_m3803_m6688)]
pmaddwd m3, m0
vpbroadcastd m0, [o(pw_3344x8)]
pmulhrsw m1, m0 ; out2 ____
vpbroadcastd m0, [o(pd_2048)]
paddd m2, m0
paddd m0, m4
paddd m5, m2 ; 2482*in0 + 3344*in1 - 1321*in2 - 3803*in3
paddd m2, m4
paddd m2, m3
psrad m0, 12
psrad m5, 12
psrad m2, 12
packssdw m0, m5 ; out0 out1
packssdw m2, m2 ; out3 out3
%endmacro
INV_TXFM_4X4_FN dct, dct, 0
INV_TXFM_4X4_FN dct, adst, 0
INV_TXFM_4X4_FN dct, flipadst, 0
INV_TXFM_4X4_FN dct, identity, 3
cglobal idct_4x4_internal, 0, 5, 6, dst, stride, c, eob, tx2
mova m0, [cq+16*0]
mova m1, [cq+16*1]
IDCT4_1D_PACKED
mova m2, [o(deint_shuf)]
shufps m3, m0, m1, q1331
shufps m0, m0, m1, q0220
pshufb m0, m2
pshufb m1, m3, m2
jmp tx2q
.pass2:
IDCT4_1D_PACKED
pxor m2, m2
mova [cq+16*0], m2
mova [cq+16*1], m2
ITX4_END 0, 1, 3, 2
INV_TXFM_4X4_FN adst, dct, 0
INV_TXFM_4X4_FN adst, adst, 0
INV_TXFM_4X4_FN adst, flipadst, 0
INV_TXFM_4X4_FN adst, identity
cglobal iadst_4x4_internal, 0, 5, 6, dst, stride, c, eob, tx2
mova m0, [cq+16*0]
mova m1, [cq+16*1]
call .main
punpckhwd m3, m0, m2
punpcklwd m0, m1
punpckhwd m1, m0, m3
punpcklwd m0, m3
jmp tx2q
.pass2:
call .main
vpblendd m1, m1, m2, 0x0c ; out2 out3
.end:
pxor m2, m2
mova [cq+16*0], m2
mova [cq+16*1], m2
.end2:
ITX4_END 0, 1, 2, 3
ALIGN function_align
.main:
IADST4_1D_PACKED
ret
INV_TXFM_4X4_FN flipadst, dct, 0
INV_TXFM_4X4_FN flipadst, adst, 0
INV_TXFM_4X4_FN flipadst, flipadst, 0
INV_TXFM_4X4_FN flipadst, identity
cglobal iflipadst_4x4_internal, 0, 5, 6, dst, stride, c, eob, tx2
mova m0, [cq+16*0]
mova m1, [cq+16*1]
call m(iadst_4x4_internal).main
punpcklwd m1, m0
punpckhwd m2, m0
punpcklwd m0, m2, m1
punpckhwd m1, m2, m1
jmp tx2q
.pass2:
call m(iadst_4x4_internal).main
vpblendd m1, m1, m2, 0x0c ; out2 out3
.end:
pxor m2, m2
mova [cq+16*0], m2
mova [cq+16*1], m2
.end2:
ITX4_END 3, 2, 1, 0
INV_TXFM_4X4_FN identity, dct, 3
INV_TXFM_4X4_FN identity, adst
INV_TXFM_4X4_FN identity, flipadst
INV_TXFM_4X4_FN identity, identity
cglobal iidentity_4x4_internal, 0, 5, 6, dst, stride, c, eob, tx2
mova m0, [cq+16*0]
mova m1, [cq+16*1]
vpbroadcastd m2, [o(pw_5793x4)]
paddw m0, m0
paddw m1, m1
pmulhrsw m0, m2
pmulhrsw m1, m2
punpckhwd m2, m0, m1
punpcklwd m0, m1
punpckhwd m1, m0, m2
punpcklwd m0, m2
jmp tx2q
.pass2:
vpbroadcastd m2, [o(pw_5793x4)]
paddw m0, m0
paddw m1, m1
pmulhrsw m0, m2
pmulhrsw m1, m2
jmp m(iadst_4x4_internal).end
%macro WRITE_4X8 2 ; coefs[1-2]
movd xm4, [dstq+strideq*0]
pinsrd xm4, [dstq+strideq*1], 1
movd xm5, [dstq+strideq*2]
pinsrd xm5, [dstq+r3 ], 1
pinsrd xm4, [r2 +strideq*0], 2
pinsrd xm4, [r2 +strideq*1], 3
pinsrd xm5, [r2 +strideq*2], 2
pinsrd xm5, [r2 +r3 ], 3
pmovzxbw m4, xm4
pmovzxbw m5, xm5
paddw m4, m%1
paddw m5, m%2
packuswb m4, m5
vextracti128 xm5, m4, 1
movd [dstq+strideq*0], xm4
pextrd [dstq+strideq*1], xm4, 1
pextrd [dstq+strideq*2], xm4, 2
pextrd [dstq+r3 ], xm4, 3
movd [r2 +strideq*0], xm5
pextrd [r2 +strideq*1], xm5, 1
pextrd [r2 +strideq*2], xm5, 2
pextrd [r2 +r3 ], xm5, 3
%endmacro
%macro INV_TXFM_4X8_FN 2-3 -1 ; type1, type2, fast_thresh
INV_TXFM_FN %1, %2, %3, 4x8
%if %3 >= 0
%ifidn %1_%2, dct_identity
vpbroadcastd xm0, [o(pw_2896x8)]
pmulhrsw xm1, xm0, [cq]
vpbroadcastd xm2, [o(pw_4096)]
pmulhrsw xm1, xm0
pmulhrsw xm1, xm2
vpermq m1, m1, q1100
punpcklwd m1, m1
punpckldq m0, m1, m1
punpckhdq m1, m1
jmp m(iadst_4x8_internal).end3
%elifidn %1_%2, identity_dct
movd xm0, [cq+16*0]
punpcklwd xm0, [cq+16*1]
movd xm1, [cq+16*2]
punpcklwd xm1, [cq+16*3]
vpbroadcastd xm2, [o(pw_2896x8)]
vpbroadcastd xm3, [o(pw_5793x4)]
vpbroadcastd xm4, [o(pw_2048)]
punpckldq xm0, xm1
pmulhrsw xm0, xm2
paddw xm0, xm0
pmulhrsw xm0, xm3
pmulhrsw xm0, xm2
pmulhrsw xm0, xm4
vpbroadcastq m0, xm0
mova m1, m0
jmp m(iadst_4x8_internal).end3
%elifidn %1_%2, dct_dct
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_2048)]
mov [cq], eobd
pmulhrsw xm0, xm1
pmulhrsw xm0, xm1
pmulhrsw xm0, xm2
vpbroadcastw m0, xm0
mova m1, m0
jmp m(iadst_4x8_internal).end4
%else ; adst_dct / flipadst_dct
vpbroadcastw xm0, [cq]
vpbroadcastd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1
pmulhrsw xm0, [o(iadst4_dconly1a)]
vpbroadcastd xm2, [o(pw_2048)]
mov [cq], eobd
pmulhrsw xm0, xm1
pmulhrsw xm0, xm2
%ifidn %1, adst
vpbroadcastq m0, xm0
%else ; flipadst
vpermq m0, m0, q1111
%endif
mova m1, m0
jmp m(iadst_4x8_internal).end4
%endif
%endif
%endmacro
%macro IDCT8_1D_PACKED 0
vpbroadcastd m6, [o(pd_2048)]
punpckhwd m5, m3, m0 ; in7 in1
punpckhwd m4, m1, m2 ; in3 in5
punpcklwd m3, m1 ; in2 in6
psubw m1, m0, m2
paddw m0, m2
punpcklqdq m0, m1 ; in0+in4 in0-in4
ITX_MUL2X_PACK 5, 1, 2, 6, 799, 4017, 1 ; t4a t7a
ITX_MUL2X_PACK 4, 1, 2, 6, 3406, 2276, 1 ; t5a t6a
ITX_MUL2X_PACK 3, 1, 2, 6, 1567, 3784 ; t3 t2
vpbroadcastd m6, [o(pw_2896x8)]
psubw m2, m5, m4 ; t4 t7
paddw m5, m4 ; t5a t6a
pshufd m4, m2, q1032
psubw m1, m2, m4
paddw m4, m2
vpblendd m4, m4, m1, 0xcc
pmulhrsw m0, m6 ; t0 t1
pmulhrsw m4, m6 ; t6 t5
psubw m1, m0, m3 ; tmp3 tmp2
paddw m0, m3 ; tmp0 tmp1
shufps m2, m5, m4, q1032 ; t7 t6
vpblendd m5, m5, m4, 0xcc ; t4 t5
psubw m3, m0, m2 ; out7 out6
paddw m0, m2 ; out0 out1
psubw m2, m1, m5 ; out4 out5
paddw m1, m5 ; out3 out2
%endmacro
%macro IADST8_1D_PACKED 0
vpbroadcastd m6, [o(pd_2048)]
punpckhwd m0, m4, m3 ; 0 7
punpckhwd m1, m5, m2 ; 2 5
punpcklwd m2, m5 ; 4 3
punpcklwd m3, m4 ; 6 1
ITX_MUL2X_PACK 0, 4, 5, 6, 401, 4076 ; t0a t1a
ITX_MUL2X_PACK 1, 4, 5, 6, 1931, 3612 ; t2a t3a
ITX_MUL2X_PACK 2, 4, 5, 6, 3166, 2598 ; t4a t5a
ITX_MUL2X_PACK 3, 4, 5, 6, 3920, 1189 ; t6a t7a
psubw m4, m0, m2 ; t4 t5
paddw m0, m2 ; t0 t1
psubw m5, m1, m3 ; t6 t7
paddw m1, m3 ; t2 t3
shufps m2, m5, m4, q1032
punpckhwd m4, m2
punpcklwd m5, m2
ITX_MUL2X_PACK 4, 2, 3, 6, 1567, 3784, 1 ; t5a t4a
ITX_MUL2X_PACK 5, 2, 3, 6, 3784, 1567 ; t7a t6a
psubw m2, m0, m1 ; t2 t3
paddw m0, m1 ; out0 -out7
psubw m1, m4, m5 ; t7 t6
paddw m4, m5 ; out6 -out1
vpbroadcastd m5, [o(pw_2896x8)]
vpblendd m3, m0, m4, 0x33 ; out6 -out7
vpblendd m0, m0, m4, 0xcc ; out0 -out1
shufps m4, m2, m1, q1032 ; t3 t7
vpblendd m1, m2, m1, 0xcc ; t2 t6
psubw m2, m1, m4 ; t2-t3 t6-t7
paddw m1, m4 ; t2+t3 t6+t7
pmulhrsw m2, m5 ; out4 -out5
pshufd m1, m1, q1032
pmulhrsw m1, m5 ; out2 -out3
%endmacro
INIT_YMM avx2
INV_TXFM_4X8_FN dct, dct, 0
INV_TXFM_4X8_FN dct, identity, 7
INV_TXFM_4X8_FN dct, adst
INV_TXFM_4X8_FN dct, flipadst
cglobal idct_4x8_internal, 0, 5, 7, dst, stride, c, eob, tx2
vpermq m0, [cq+32*0], q3120
vpermq m1, [cq+32*1], q3120
vpbroadcastd m5, [o(pw_2896x8)]
pmulhrsw m0, m5
pmulhrsw m1, m5
IDCT4_1D_PACKED 5
vbroadcasti128 m2, [o(deint_shuf)]
shufps m3, m0, m1, q1331
shufps m0, m0, m1, q0220
pshufb m0, m2
pshufb m1, m3, m2
jmp tx2q
.pass2:
vextracti128 xm2, m0, 1
vextracti128 xm3, m1, 1
call .main
vpbroadcastd m4, [o(pw_2048)]
vinserti128 m0, m0, xm2, 1
vinserti128 m1, m1, xm3, 1
pshufd m1, m1, q1032
jmp m(iadst_4x8_internal).end2
ALIGN function_align
.main:
WRAP_XMM IDCT8_1D_PACKED
ret
INV_TXFM_4X8_FN adst, dct, 0
INV_TXFM_4X8_FN adst, adst
INV_TXFM_4X8_FN adst, flipadst
INV_TXFM_4X8_FN adst, identity
cglobal iadst_4x8_internal, 0, 5, 7, dst, stride, c, eob, tx2
vpermq m0, [cq+32*0], q3120
vpermq m1, [cq+32*1], q3120
vpbroadcastd m2, [o(pw_2896x8)]
pmulhrsw m0, m2
pmulhrsw m1, m2
call m(iadst_8x4_internal).main
punpckhwd m3, m0, m2
punpcklwd m0, m1
punpckhwd m1, m0, m3
punpcklwd m0, m3
jmp tx2q
.pass2:
vextracti128 xm2, m0, 1
vextracti128 xm3, m1, 1
pshufd xm4, xm0, q1032
pshufd xm5, xm1, q1032
call .main
vpbroadcastd m4, [o(pw_2048)]
vinserti128 m0, m0, xm2, 1
vinserti128 m1, m1, xm3, 1
pxor m5, m5
psubw m5, m4
.end:
vpblendd m4, m4, m5, 0xcc
.end2:
pmulhrsw m0, m4
pmulhrsw m1, m4
WIN64_RESTORE_XMM
.end3:
pxor m2, m2
mova [cq+32*0], m2
mova [cq+32*1], m2
.end4:
lea r2, [dstq+strideq*4]
lea r3, [strideq*3]
WRITE_4X8 0, 1
RET
ALIGN function_align
.main:
WRAP_XMM IADST8_1D_PACKED
ret
INV_TXFM_4X8_FN flipadst, dct, 0
INV_TXFM_4X8_FN flipadst, adst
INV_TXFM_4X8_FN flipadst, flipadst
INV_TXFM_4X8_FN flipadst, identity
cglobal iflipadst_4x8_internal, 0, 5, 7, dst, stride, c, eob, tx2
vpermq m0, [cq+32*0], q3120
vpermq m1, [cq+32*1], q3120
vpbroadcastd m2, [o(pw_2896x8)]
pmulhrsw m0, m2
pmulhrsw m1, m2
call m(iadst_8x4_internal).main
punpcklwd m3, m1, m0
punpckhwd m1, m2, m0
punpcklwd m0, m1, m3
punpckhwd m1, m3
jmp tx2q
.pass2:
vextracti128 xm2, m0, 1
vextracti128 xm3, m1, 1
pshufd xm4, xm0, q1032
pshufd xm5, xm1, q1032
call m(iadst_4x8_internal).main
vpbroadcastd m5, [o(pw_2048)]
vinserti128 m3, m3, xm1, 1
vinserti128 m2, m2, xm0, 1
pxor m4, m4
psubw m4, m5
pshufd m0, m3, q1032
pshufd m1, m2, q1032
jmp m(iadst_4x8_internal).end
INV_TXFM_4X8_FN identity, dct, 3
INV_TXFM_4X8_FN identity, adst
INV_TXFM_4X8_FN identity, flipadst
INV_TXFM_4X8_FN identity, identity
cglobal iidentity_4x8_internal, 0, 5, 7, dst, stride, c, eob, tx2
vpermq m2, [cq+32*0], q3120
vpermq m0, [cq+32*1], q3120
vpbroadcastd m3, [o(pw_2896x8)]
vpbroadcastd m4, [o(pw_5793x4)]
punpcklwd m1, m2, m0
punpckhwd m2, m0
pmulhrsw m1, m3
pmulhrsw m2, m3
punpcklwd m0, m1, m2
punpckhwd m1, m2
paddw m0, m0
paddw m1, m1
pmulhrsw m0, m4
pmulhrsw m1, m4
jmp tx2q
.pass2:
vpbroadcastd m4, [o(pw_4096)]
jmp m(iadst_4x8_internal).end2
%macro INV_TXFM_4X16_FN 2-3 -1 ; type1, type2, fast_thresh
INV_TXFM_FN %1, %2, %3, 4x16
%if %3 >= 0
%ifidn %1_%2, dct_identity
vpbroadcastd m0, [o(pw_2896x8)]
pmulhrsw m0, [cq]
vpbroadcastd m1, [o(pw_16384)]
vpbroadcastd m2, [o(pw_5793x4)]
vpbroadcastd m3, [o(pw_2048)]
pmulhrsw m0, m1
psllw m0, 2
pmulhrsw m0, m2
pmulhrsw m3, m0
punpcklwd m1, m3, m3
punpckhwd m3, m3
punpckldq m0, m1, m1
punpckhdq m1, m1
punpckldq m2, m3, m3
punpckhdq m3, m3
jmp m(iadst_4x16_internal).end3
%elifidn %1_%2, identity_dct
movd xm0, [cq+32*0]
punpcklwd xm0, [cq+32*1]
movd xm1, [cq+32*2]
punpcklwd xm1, [cq+32*3]
vpbroadcastd xm2, [o(pw_5793x4)]
vpbroadcastd xm3, [o(pw_16384)]
vpbroadcastd xm4, [o(pw_2896x8)]
punpckldq xm0, xm1
paddw xm0, xm0
pmulhrsw xm0, xm2
pmulhrsw xm0, xm3
psrlw xm3, 3 ; pw_2048
pmulhrsw xm0, xm4
pmulhrsw xm0, xm3
vpbroadcastq m0, xm0
mova m1, m0
mova m2, m0
mova m3, m0
jmp m(iadst_4x16_internal).end3
%elifidn %1_%2, dct_dct
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_16384)]
movd xm3, [o(pw_2048)]
mov [cq], eobd
pmulhrsw xm0, xm2
pmulhrsw xm0, xm1
pmulhrsw xm0, xm3
vpbroadcastw m0, xm0
mova m1, m0
mova m2, m0
mova m3, m0
jmp m(iadst_4x16_internal).end4
%else ; adst_dct / flipadst_dct
vpbroadcastw xm0, [cq]
pmulhrsw xm0, [o(iadst4_dconly1a)]
vpbroadcastd xm1, [o(pw_16384)]
vpbroadcastd xm2, [o(pw_2896x8)]
mov [cq], eobd
pmulhrsw xm0, xm1
psrlw xm1, 3 ; pw_2048
pmulhrsw xm0, xm2
pmulhrsw xm0, xm1
%ifidn %1, adst
vpbroadcastq m0, xm0
%else ; flipadst
vpermq m0, m0, q1111
%endif
mova m1, m0
mova m2, m0
mova m3, m0
jmp m(iadst_4x16_internal).end4
%endif
%endif
%endmacro
%macro IDCT16_1D_PACKED 0
vpbroadcastd m10, [o(pd_2048)]
.main2:
punpckhwd m8, m7, m0 ; dct16 in15 in1
paddw m9, m0, m4
psubw m0, m4
punpcklqdq m9, m0 ; dct4 in0+in2 in0-in2
punpckhwd m0, m3, m4 ; dct16 in7 in9
punpcklwd m7, m1 ; dct8 in7 in1
punpckhwd m1, m6 ; dct16 in3 in13
punpcklwd m3, m5 ; dct8 in3 in5
punpckhwd m5, m2 ; dct16 in11 in5
punpcklwd m6, m2 ; dct4 in3 in1
ITX_MUL2X_PACK 8, 2, 4, 10, 401, 4076, 3 ; t8a t15a
ITX_MUL2X_PACK 0, 2, 4, 10, 3166, 2598, 3 ; t9a t14a
ITX_MUL2X_PACK 1, 2, 4, 10, 3920, 1189, 3 ; t11a t12a
ITX_MUL2X_PACK 5, 2, 4, 10, 1931, 3612, 3 ; t10a t13a
ITX_MUL2X_PACK 7, 2, 4, 10, 799, 4017, 1 ; t4a t7a
ITX_MUL2X_PACK 3, 2, 4, 10, 3406, 2276, 1 ; t5a t6a
ITX_MUL2X_PACK 6, 2, 4, 10, 1567, 3784 ; t3 t2
psubw m2, m8, m0 ; t9 t14
paddw m8, m0 ; t8 t15
psubw m0, m1, m5 ; t10 t13
paddw m1, m5 ; t11 t12
%if mmsize > 16
vbroadcasti128 m5, [o(deint_shuf)]
%else
mova m5, [o(deint_shuf)]
%endif
pshufb m8, m5
pshufb m1, m5
vpbroadcastd m5, [o(pw_m3784_1567)] ; reuse pw_1567_3784
ITX_MUL2X_PACK 2, 4, _, 10, 4, 5, 4 ; t9a t14a
vpbroadcastd m4, [o(pw_m1567_m3784)] ; reuse pw_m3784_1567
ITX_MUL2X_PACK 0, 5, _, 10, 5, 4, 4 ; t10a t13a
psubw m5, m7, m3 ; t5a t6a
paddw m7, m3 ; t4 t7
psubw m4, m8, m1 ; t11a t12a
paddw m8, m1 ; t8a t15a
paddw m1, m2, m0 ; t9 t14
psubw m2, m0 ; t10 t13
punpckhqdq m0, m8, m1 ; t15a t14
punpcklqdq m8, m1 ; t8a t9
pshufd m3, m5, q1032
psubw m1, m5, m3
paddw m3, m5
vpblendd m3, m3, m1, 0xcc ; t6 t5
vpbroadcastd m1, [o(pw_2896x8)]
punpckhqdq m5, m4, m2 ; t12a t13
punpcklqdq m2, m4, m2 ; t11a t10
psubw m4, m5, m2
paddw m5, m2
pmulhrsw m9, m1 ; t0 t1
pmulhrsw m3, m1 ; t6 t5
pmulhrsw m4, m1 ; t11 t10a
pmulhrsw m5, m1 ; t12 t13a
shufps m2, m7, m3, q1032 ; t7 t6
vpblendd m7, m7, m3, 0xcc ; t4 t5
psubw m1, m9, m6 ; dct4 out3 out2
paddw m9, m6 ; dct4 out0 out1
psubw m3, m9, m2 ; dct8 out7 out6
paddw m9, m2 ; dct8 out0 out1
psubw m2, m1, m7 ; dct8 out4 out5
paddw m1, m7 ; dct8 out3 out2
psubw m7, m9, m0 ; out15 out14
paddw m0, m9 ; out0 out1
psubw m6, m1, m5 ; out12 out13
paddw m1, m5 ; out3 out2
psubw m5, m2, m4 ; out11 out10
paddw m2, m4 ; out4 out5
psubw m4, m3, m8 ; out8 out9
paddw m3, m8 ; out7 out6
%endmacro
INV_TXFM_4X16_FN dct, dct, 0
INV_TXFM_4X16_FN dct, identity, 15
INV_TXFM_4X16_FN dct, adst
INV_TXFM_4X16_FN dct, flipadst
cglobal idct_4x16_internal, 0, 5, 11, dst, stride, c, eob, tx2
mova m0, [cq+32*0]
mova m1, [cq+32*1]
mova m2, [cq+32*2]
mova m3, [cq+32*3]
call m(idct_16x4_internal).main
vpbroadcastd m5, [o(pw_16384)]
punpckhwd m4, m2, m3
punpcklwd m2, m3
punpckhwd m3, m0, m1
punpcklwd m0, m1
REPX {pmulhrsw x, m5}, m0, m4, m2, m3
punpckhdq m1, m0, m2
punpckldq m0, m2
punpckldq m2, m3, m4
punpckhdq m3, m4
jmp tx2q
.pass2:
vextracti128 xm4, m0, 1
vextracti128 xm5, m1, 1
vextracti128 xm6, m2, 1
vextracti128 xm7, m3, 1
call .main
vinserti128 m0, m0, xm4, 1
vinserti128 m1, m1, xm5, 1
vpbroadcastd m5, [o(pw_2048)]
vinserti128 m2, m2, xm6, 1
vinserti128 m3, m3, xm7, 1
pshufd m1, m1, q1032
pshufd m3, m3, q1032
jmp m(iadst_4x16_internal).end2
ALIGN function_align
.main:
WRAP_XMM IDCT16_1D_PACKED
ret
INV_TXFM_4X16_FN adst, dct, 0
INV_TXFM_4X16_FN adst, adst
INV_TXFM_4X16_FN adst, flipadst
INV_TXFM_4X16_FN adst, identity
cglobal iadst_4x16_internal, 0, 5, 11, dst, stride, c, eob, tx2
mova m0, [cq+32*0]
mova m1, [cq+32*1]
mova m2, [cq+32*2]
mova m3, [cq+32*3]
call m(iadst_16x4_internal).main
vpbroadcastd m5, [o(pw_16384)]
punpckhwd m4, m2, m3
punpcklwd m2, m3
punpckhwd m3, m0, m1
punpcklwd m0, m1
REPX {pmulhrsw x, m5}, m4, m2, m3, m0
punpckhdq m1, m0, m2
punpckldq m0, m2
punpckldq m2, m3, m4
punpckhdq m3, m4
jmp tx2q
.pass2:
call .main
pshufd m1, m1, q1032
vpbroadcastd m5, [o(pw_2048)]
vpblendd m4, m1, m0, 0x33
vpblendd m0, m0, m2, 0x33
vpblendd m2, m2, m3, 0x33
vpblendd m3, m3, m1, 0x33
vpermq m0, m0, q2031
vpermq m1, m2, q1302
vpermq m2, m3, q3120
vpermq m3, m4, q0213
psubw m6, m7, m5
.end:
vpblendd m5, m5, m6, 0xcc
.end2:
REPX {pmulhrsw x, m5}, m0, m1, m2, m3
WIN64_RESTORE_XMM
.end3:
pxor m4, m4
mova [cq+32*0], m4
mova [cq+32*1], m4
mova [cq+32*2], m4
mova [cq+32*3], m4
.end4:
lea r2, [dstq+strideq*8]
lea r3, [strideq*3]
WRITE_4X8 0, 1
lea dstq, [dstq+strideq*4]
lea r2, [r2 +strideq*4]
WRITE_4X8 2, 3
RET
ALIGN function_align
.main:
vpblendd m4, m1, m0, 0xcc
vpblendd m1, m1, m0, 0x33
vpblendd m5, m2, m3, 0xcc
vpblendd m2, m2, m3, 0x33
vperm2i128 m3, m5, m2, 0x31
vinserti128 m0, m1, xm4, 1 ; in0 in3 in2 in1
vperm2i128 m4, m1, m4, 0x31
vinserti128 m1, m5, xm2, 1 ; in4 in7 in6 in5
pshufd m3, m3, q1032 ; in12 in15 in13 in14
pshufd m2, m4, q1032 ; in11 in8 in9 in10
.main2:
vpbroadcastd m8, [o(pd_2048)]
pxor m7, m7
punpckhwd m4, m3, m0 ; in12 in3 in14 in1
punpcklwd m0, m3 ; in0 in15 in2 in13
punpckhwd m3, m2, m1 ; in8 in7 in10 in5
punpcklwd m1, m2 ; in4 in11 in6 in9
ITX_MUL4X_PACK 0, 2, 5, 6, 8, 201, 4091, 995, 3973, 3
ITX_MUL4X_PACK 1, 2, 5, 6, 8, 1751, 3703, 2440, 3290, 3
ITX_MUL4X_PACK 3, 2, 5, 6, 8, 3035, 2751, 3513, 2106, 3
ITX_MUL4X_PACK 4, 2, 5, 6, 8, 3857, 1380, 4052, 601, 3
psubw m2, m0, m3 ; t9a t8a t11a t10a
paddw m0, m3 ; t1a t0a t3a t2a
psubw m3, m1, m4 ; t13a t12a t15a t14a
paddw m1, m4 ; t5a t4a t7a t6a
ITX_MUL4X_PACK 2, 4, 5, 6, 8, 799, 4017, 3406, 2276, 3
psubw m6, m7, m5
ITX_MUL2X_PACK 3, 5, _, 8, 6, 4, 6
vpbroadcastd m6, [o(pw_m3784_1567)]
vpbroadcastd m5, [o(pw_1567_3784)]
psubw m4, m0, m1 ; t5 t4 t7 t6
paddw m0, m1 ; t1 t0 t3 t2
psubw m1, m2, m3 ; t13a t12a t15a t14a
paddw m2, m3 ; t9a t8a t11a t10a
psubw m3, m7, m6
vpblendd m6, m6, m3, 0xf0
ITX_MUL2X_PACK 4, 3, _, 8, 6, 5, 4 ; t4a t5a t7a t6a
ITX_MUL2X_PACK 1, 3, _, 8, 6, 5, 4 ; t12 t13 t15 t14
vbroadcasti128 m5, [o(deint_shuf)]
pshufb m0, m5
pshufb m2, m5
vperm2i128 m3, m0, m2, 0x31 ; t3 t2 t11a t10a
vinserti128 m0, m0, xm2, 1 ; t1 t0 t9a t8a
vperm2i128 m2, m4, m1, 0x31 ; t7a t6a t15 t14
vinserti128 m4, m4, xm1, 1 ; t4a t5a t12 t13
vpbroadcastd m5, [o(pw_2896x8)]
pshufd m2, m2, q1032 ; t6a t7a t14 t15
psubw m1, m0, m3 ; t3a t2a t11 t10
paddw m0, m3 ; -out15 out0 out14 -out1
paddw m3, m4, m2 ; -out3 out12 out2 -out13
psubw m4, m2 ; t6 t7 t14a t15a
shufps m2, m1, m4, q1032 ; t2a t6 t10 t14a
vpblendd m4, m4, m1, 0x33 ; t3a t7 t11 t15a
paddw m1, m2, m4
psubw m2, m4
pmulhrsw m1, m5 ; -out7 out4 out6 -out5
pmulhrsw m2, m5 ; out8 -out11 -out9 out10
ret
INV_TXFM_4X16_FN flipadst, dct, 0
INV_TXFM_4X16_FN flipadst, adst
INV_TXFM_4X16_FN flipadst, flipadst
INV_TXFM_4X16_FN flipadst, identity
cglobal iflipadst_4x16_internal, 0, 5, 11, dst, stride, c, eob, tx2
mova m0, [cq+32*0]
mova m1, [cq+32*1]
mova m2, [cq+32*2]
mova m3, [cq+32*3]
call m(iadst_16x4_internal).main
vpbroadcastd m5, [o(pw_16384)]
punpcklwd m4, m1, m0
punpckhwd m1, m0
punpcklwd m0, m3, m2
punpckhwd m3, m2
REPX {pmulhrsw x, m5}, m4, m1, m0, m3
punpckldq m2, m3, m1
punpckhdq m3, m1
punpckhdq m1, m0, m4
punpckldq m0, m4
jmp tx2q
.pass2:
call m(iadst_4x16_internal).main
pshufd m1, m1, q1032
vpbroadcastd m6, [o(pw_2048)]
vpblendd m4, m0, m2, 0x33
vpblendd m0, m0, m1, 0xcc
vpblendd m1, m1, m3, 0xcc
vpblendd m2, m2, m3, 0x33
vpermq m0, m0, q3120
vpermq m1, m1, q0213
vpermq m2, m2, q2031
vpermq m3, m4, q1302
psubw m5, m7, m6
jmp m(iadst_4x16_internal).end
INV_TXFM_4X16_FN identity, dct, 3
INV_TXFM_4X16_FN identity, adst
INV_TXFM_4X16_FN identity, flipadst
INV_TXFM_4X16_FN identity, identity
cglobal iidentity_4x16_internal, 0, 5, 11, dst, stride, c, eob, tx2
mova m3, [cq+32*0]
mova m2, [cq+32*1]
mova m4, [cq+32*2]
mova m0, [cq+32*3]
vpbroadcastd m5, [o(pw_5793x4)]
punpcklwd m1, m3, m2
punpckhwd m3, m2
punpcklwd m2, m4, m0
punpckhwd m4, m0
REPX {paddw x, x }, m1, m2, m3, m4
REPX {pmulhrsw x, m5}, m1, m2, m3, m4
vpbroadcastd m5, [o(pw_16384)]
punpckldq m0, m1, m2
punpckhdq m1, m2
punpckldq m2, m3, m4
punpckhdq m3, m4
REPX {pmulhrsw x, m5}, m0, m1, m2, m3
jmp tx2q
.pass2:
vpbroadcastd m4, [o(pw_5793x4)]
vpbroadcastd m5, [o(pw_2048)]
REPX {psllw x, 2 }, m0, m1, m2, m3
REPX {pmulhrsw x, m4}, m0, m1, m2, m3
jmp m(iadst_4x16_internal).end2
%macro WRITE_8X4 4-7 strideq*1, strideq*2, r3, ; coefs[1-2], tmp[1-2], off[1-3]
movq xm%3, [dstq ]
movhps xm%3, [dstq+%5]
movq xm%4, [dstq+%6]
movhps xm%4, [dstq+%7]
pmovzxbw m%3, xm%3
pmovzxbw m%4, xm%4
%ifnum %1
paddw m%3, m%1
%else
paddw m%3, %1
%endif
%ifnum %2
paddw m%4, m%2
%else
paddw m%4, %2
%endif
packuswb m%3, m%4
vextracti128 xm%4, m%3, 1
movq [dstq ], xm%3
movhps [dstq+%6], xm%3
movq [dstq+%5], xm%4
movhps [dstq+%7], xm%4
%endmacro
%macro INV_TXFM_8X4_FN 2-3 -1 ; type1, type2, fast_thresh
INV_TXFM_FN %1, %2, %3, 8x4
%if %3 >= 0
%ifidn %1_%2, dct_identity
vpbroadcastd xm0, [o(pw_2896x8)]
pmulhrsw xm1, xm0, [cq]
vpbroadcastd xm2, [o(pw_5793x4)]
vpbroadcastd xm3, [o(pw_2048)]
pmulhrsw xm1, xm0
paddw xm1, xm1
pmulhrsw xm1, xm2
pmulhrsw xm1, xm3
punpcklwd xm1, xm1
punpckldq xm0, xm1, xm1
punpckhdq xm1, xm1
vpermq m0, m0, q1100
vpermq m1, m1, q1100
%elifidn %1_%2, identity_dct
mova xm0, [cq+16*0]
packusdw xm0, [cq+16*1]
mova xm1, [cq+16*2]
packusdw xm1, [cq+16*3]
vpbroadcastd xm2, [o(pw_2896x8)]
vpbroadcastd xm3, [o(pw_2048)]
packusdw xm0, xm1
pmulhrsw xm0, xm2
paddw xm0, xm0
pmulhrsw xm0, xm2
pmulhrsw xm0, xm3
vinserti128 m0, m0, xm0, 1
mova m1, m0
%else
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
pmulhrsw xm0, xm1
%ifidn %2, dct
movd xm2, [o(pw_2048)]
pmulhrsw xm0, xm1
pmulhrsw xm0, xm2
vpbroadcastw m0, xm0
mova m1, m0
%else ; adst / flipadst
vpbroadcastw m0, xm0
pmulhrsw m0, [o(iadst4_dconly2a)]
vpbroadcastd m1, [o(pw_2048)]
pmulhrsw m1, m0
%ifidn %2, adst
vpermq m0, m1, q1100
vpermq m1, m1, q3322
%else ; flipadst
vpermq m0, m1, q2233
vpermq m1, m1, q0011
%endif
%endif
%endif
jmp m(iadst_8x4_internal).end3
%endif
%endmacro
INV_TXFM_8X4_FN dct, dct, 0
INV_TXFM_8X4_FN dct, adst, 0
INV_TXFM_8X4_FN dct, flipadst, 0
INV_TXFM_8X4_FN dct, identity, 3
cglobal idct_8x4_internal, 0, 5, 7, dst, stride, c, eob, tx2
vpbroadcastd xm3, [o(pw_2896x8)]
pmulhrsw xm0, xm3, [cq+16*0]
pmulhrsw xm1, xm3, [cq+16*1]
pmulhrsw xm2, xm3, [cq+16*2]
pmulhrsw xm3, [cq+16*3]
call m(idct_4x8_internal).main
vbroadcasti128 m4, [o(deint_shuf)]
vinserti128 m3, m1, xm3, 1
vinserti128 m1, m0, xm2, 1
shufps m0, m1, m3, q0220
shufps m1, m1, m3, q1331
pshufb m0, m4
pshufb m1, m4
jmp tx2q
.pass2:
IDCT4_1D_PACKED
vpermq m0, m0, q3120
vpermq m1, m1, q2031
jmp m(iadst_8x4_internal).end2
INV_TXFM_8X4_FN adst, dct
INV_TXFM_8X4_FN adst, adst
INV_TXFM_8X4_FN adst, flipadst
INV_TXFM_8X4_FN adst, identity
cglobal iadst_8x4_internal, 0, 5, 7, dst, stride, c, eob, tx2
vpbroadcastd xm0, [o(pw_2896x8)]
pshufd xm4, [cq+16*0], q1032
pmulhrsw xm3, xm0, [cq+16*3]
pshufd xm5, [cq+16*1], q1032
pmulhrsw xm2, xm0, [cq+16*2]
pmulhrsw xm4, xm0
pmulhrsw xm5, xm0
call m(iadst_4x8_internal).main
vinserti128 m0, m0, xm2, 1
vinserti128 m1, m1, xm3, 1
punpckhwd m2, m0, m1
punpcklwd m0, m1
pxor m3, m3
psubw m3, m2
punpckhwd m1, m0, m3
punpcklwd m0, m3
jmp tx2q
.pass2:
call .main
vpblendd m1, m1, m2, 0xcc
.end:
vpermq m0, m0, q3120
vpermq m1, m1, q3120
.end2:
vpbroadcastd m2, [o(pw_2048)]
pmulhrsw m0, m2
pmulhrsw m1, m2
WIN64_RESTORE_XMM
.end3:
pxor m2, m2
mova [cq+32*0], m2
mova [cq+32*1], m2
lea r3, [strideq*3]
WRITE_8X4 0, 1, 4, 5
RET
ALIGN function_align
.main:
IADST4_1D_PACKED
ret
INV_TXFM_8X4_FN flipadst, dct
INV_TXFM_8X4_FN flipadst, adst
INV_TXFM_8X4_FN flipadst, flipadst
INV_TXFM_8X4_FN flipadst, identity
cglobal iflipadst_8x4_internal, 0, 5, 7, dst, stride, c, eob, tx2
vpbroadcastd xm0, [o(pw_2896x8)]
pshufd xm4, [cq+16*0], q1032
pmulhrsw xm3, xm0, [cq+16*3]
pshufd xm5, [cq+16*1], q1032
pmulhrsw xm2, xm0, [cq+16*2]
pmulhrsw xm4, xm0
pmulhrsw xm5, xm0
call m(iadst_4x8_internal).main
vinserti128 m3, m3, xm1, 1
vinserti128 m2, m2, xm0, 1
punpckhwd m1, m3, m2
punpcklwd m3, m2
pxor m0, m0
psubw m0, m1
punpckhwd m1, m0, m3
punpcklwd m0, m3
jmp tx2q
.pass2:
call m(iadst_8x4_internal).main
vpblendd m2, m2, m1, 0x33
vpermq m1, m0, q2031
vpermq m0, m2, q2031
jmp m(iadst_8x4_internal).end2
INV_TXFM_8X4_FN identity, dct, 7
INV_TXFM_8X4_FN identity, adst
INV_TXFM_8X4_FN identity, flipadst
INV_TXFM_8X4_FN identity, identity
cglobal iidentity_8x4_internal, 0, 5, 7, dst, stride, c, eob, tx2
mova xm2, [cq+16*0]
mova xm0, [cq+16*1]
vinserti128 m2, m2, [cq+16*2], 1
vinserti128 m0, m0, [cq+16*3], 1
vpbroadcastd m3, [o(pw_2896x8)]
punpcklwd m1, m2, m0
punpckhwd m2, m0
pmulhrsw m1, m3
pmulhrsw m2, m3
punpcklwd m0, m1, m2
punpckhwd m1, m2
paddw m0, m0
paddw m1, m1
jmp tx2q
.pass2:
vpbroadcastd m2, [o(pw_5793x4)]
paddw m0, m0
paddw m1, m1
pmulhrsw m0, m2
pmulhrsw m1, m2
jmp m(iadst_8x4_internal).end
%macro INV_TXFM_8X8_FN 2-3 -1 ; type1, type2, fast_thresh
INV_TXFM_FN %1, %2, %3, 8x8
%ifidn %1_%2, dct_identity
vpbroadcastd xm0, [o(pw_2896x8)]
pmulhrsw xm0, [cq]
vpbroadcastd xm1, [o(pw_16384)]
pmulhrsw xm0, xm1
psrlw xm1, 2 ; pw_4096
pmulhrsw xm0, xm1
pshufb xm0, [o(deint_shuf)]
vpermq m3, m0, q1100
punpcklwd m3, m3
pshufd m0, m3, q0000
pshufd m1, m3, q1111
pshufd m2, m3, q2222
pshufd m3, m3, q3333
jmp m(iadst_8x8_internal).end4
%elif %3 >= 0
%ifidn %1, dct
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_16384)]
mov [cq], eobd
pmulhrsw xm0, xm2
psrlw xm2, 3 ; pw_2048
pmulhrsw xm0, xm1
pmulhrsw xm0, xm2
vpbroadcastw m0, xm0
.end:
mov r2d, 2
.end2:
lea r3, [strideq*3]
.loop:
WRITE_8X4 0, 0, 1, 2
lea dstq, [dstq+strideq*4]
dec r2d
jg .loop
RET
%else ; identity
mova m0, [cq+32*0]
punpcklwd m0, [cq+32*1]
mova m1, [cq+32*2]
punpcklwd m1, [cq+32*3]
vpbroadcastd m2, [o(pw_2896x8)]
vpbroadcastd m3, [o(pw_2048)]
pxor m4, m4
mova [cq+32*0], m4
mova [cq+32*1], m4
mova [cq+32*2], m4
mova [cq+32*3], m4
punpckldq m0, m1
vpermq m1, m0, q3232
vpermq m0, m0, q1010
punpcklwd m0, m1
pmulhrsw m0, m2
pmulhrsw m0, m3
jmp m(inv_txfm_add_dct_dct_8x8).end
%endif
%endif
%endmacro
INV_TXFM_8X8_FN dct, dct, 0
INV_TXFM_8X8_FN dct, identity, 7
INV_TXFM_8X8_FN dct, adst
INV_TXFM_8X8_FN dct, flipadst
cglobal idct_8x8_internal, 0, 5, 7, dst, stride, c, eob, tx2
vpermq m0, [cq+32*0], q3120 ; 0 1
vpermq m3, [cq+32*3], q3120 ; 6 7
vpermq m2, [cq+32*2], q3120 ; 4 5
vpermq m1, [cq+32*1], q3120 ; 2 3
call .main
shufps m4, m0, m1, q0220
shufps m5, m0, m1, q1331
shufps m1, m2, m3, q0220
shufps m3, m2, m3, q1331
vbroadcasti128 m0, [o(deint_shuf)]
vpbroadcastd m2, [o(pw_16384)]
REPX {pshufb x, m0}, m4, m5, m1, m3
REPX {pmulhrsw x, m2}, m4, m5, m1, m3
vinserti128 m0, m4, xm1, 1
vperm2i128 m2, m4, m1, 0x31
vinserti128 m1, m5, xm3, 1
vperm2i128 m3, m5, m3, 0x31
jmp tx2q
.pass2:
call .main
vpbroadcastd m4, [o(pw_2048)]
vpermq m0, m0, q3120
vpermq m1, m1, q2031
vpermq m2, m2, q3120
vpermq m3, m3, q2031
jmp m(iadst_8x8_internal).end2
ALIGN function_align
.main:
IDCT8_1D_PACKED
ret
INV_TXFM_8X8_FN adst, dct
INV_TXFM_8X8_FN adst, adst
INV_TXFM_8X8_FN adst, flipadst
INV_TXFM_8X8_FN adst, identity
cglobal iadst_8x8_internal, 0, 5, 7, dst, stride, c, eob, tx2
vpermq m4, [cq+32*0], q1302 ; 1 0
vpermq m3, [cq+32*3], q3120 ; 6 7
vpermq m5, [cq+32*1], q1302 ; 3 2
vpermq m2, [cq+32*2], q3120 ; 4 5
call .main
vpbroadcastd m5, [o(pw_16384)]
punpcklwd m4, m0, m1
punpckhwd m0, m1
punpcklwd m1, m2, m3
punpckhwd m2, m3
pxor m3, m3
psubw m3, m5 ; negate odd elements during rounding
pmulhrsw m4, m5
pmulhrsw m0, m3
pmulhrsw m1, m5
pmulhrsw m2, m3
punpcklwd m3, m4, m0
punpckhwd m4, m0
punpcklwd m0, m1, m2
punpckhwd m1, m2
vperm2i128 m2, m3, m0, 0x31
vinserti128 m0, m3, xm0, 1
vperm2i128 m3, m4, m1, 0x31
vinserti128 m1, m4, xm1, 1
jmp tx2q
.pass2:
pshufd m4, m0, q1032
pshufd m5, m1, q1032
call .main
vpbroadcastd m5, [o(pw_2048)]
vpbroadcastd xm4, [o(pw_4096)]
psubw m4, m5 ; lower half = 2048, upper half = -2048
.end:
REPX {vpermq x, x, q3120}, m0, m1, m2, m3
.end2:
pmulhrsw m0, m4
pmulhrsw m1, m4
.end3:
pmulhrsw m2, m4
pmulhrsw m3, m4
WIN64_RESTORE_XMM
.end4:
pxor m4, m4
mova [cq+32*0], m4
mova [cq+32*1], m4
mova [cq+32*2], m4
mova [cq+32*3], m4
lea r3, [strideq*3]
WRITE_8X4 0, 1, 4, 5
lea dstq, [dstq+strideq*4]
WRITE_8X4 2, 3, 4, 5
RET
ALIGN function_align
.main:
IADST8_1D_PACKED
ret
INV_TXFM_8X8_FN flipadst, dct
INV_TXFM_8X8_FN flipadst, adst
INV_TXFM_8X8_FN flipadst, flipadst
INV_TXFM_8X8_FN flipadst, identity
cglobal iflipadst_8x8_internal, 0, 5, 7, dst, stride, c, eob, tx2
vpermq m4, [cq+32*0], q1302 ; 1 0
vpermq m3, [cq+32*3], q3120 ; 6 7
vpermq m5, [cq+32*1], q1302 ; 3 2
vpermq m2, [cq+32*2], q3120 ; 4 5
call m(iadst_8x8_internal).main
vpbroadcastd m5, [o(pw_16384)]
punpckhwd m4, m3, m2
punpcklwd m3, m2
punpckhwd m2, m1, m0
punpcklwd m1, m0
pxor m0, m0
psubw m0, m5
pmulhrsw m4, m0
pmulhrsw m3, m5
pmulhrsw m2, m0
pmulhrsw m1, m5
punpckhwd m0, m4, m3
punpcklwd m4, m3
punpckhwd m3, m2, m1
punpcklwd m2, m1
vinserti128 m1, m0, xm3, 1
vperm2i128 m3, m0, m3, 0x31
vinserti128 m0, m4, xm2, 1
vperm2i128 m2, m4, m2, 0x31
jmp tx2q
.pass2:
pshufd m4, m0, q1032
pshufd m5, m1, q1032
call m(iadst_8x8_internal).main
vpbroadcastd m4, [o(pw_2048)]
vpbroadcastd xm5, [o(pw_4096)]
psubw m4, m5 ; lower half = -2048, upper half = 2048
vpermq m5, m3, q2031
vpermq m3, m0, q2031
vpermq m0, m2, q2031
vpermq m2, m1, q2031
pmulhrsw m1, m0, m4
pmulhrsw m0, m5, m4
jmp m(iadst_8x8_internal).end3
INV_TXFM_8X8_FN identity, dct, 7
INV_TXFM_8X8_FN identity, adst
INV_TXFM_8X8_FN identity, flipadst
INV_TXFM_8X8_FN identity, identity
cglobal iidentity_8x8_internal, 0, 5, 7, dst, stride, c, eob, tx2
mova xm3, [cq+16*0]
mova xm2, [cq+16*1]
vinserti128 m3, m3, [cq+16*4], 1
vinserti128 m2, m2, [cq+16*5], 1
mova xm4, [cq+16*2]
mova xm0, [cq+16*3]
vinserti128 m4, m4, [cq+16*6], 1
vinserti128 m0, m0, [cq+16*7], 1
punpcklwd m1, m3, m2
punpckhwd m3, m2
punpcklwd m2, m4, m0
punpckhwd m4, m0
punpckldq m0, m1, m2
punpckhdq m1, m2
punpckldq m2, m3, m4
punpckhdq m3, m4
jmp tx2q
.pass2:
vpbroadcastd m4, [o(pw_4096)]
jmp m(iadst_8x8_internal).end
%macro INV_TXFM_8X16_FN 2-3 -1 ; type1, type2, fast_thresh
INV_TXFM_FN %1, %2, %3, 8x16
%ifidn %1_%2, dct_dct
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_16384)]
mov [cq], eobd
pmulhrsw xm0, xm1
pmulhrsw xm0, xm2
psrlw xm2, 3 ; pw_2048
pmulhrsw xm0, xm1
pmulhrsw xm0, xm2
vpbroadcastw m0, xm0
mov r2d, 4
jmp m(inv_txfm_add_dct_dct_8x8).end2
%elifidn %1_%2, dct_identity
WIN64_SPILL_XMM 13
vpbroadcastd m0, [o(pw_2896x8)]
pmulhrsw m7, m0, [cq]
vpbroadcastd m1, [o(pw_16384)]
vpbroadcastd m2, [o(pw_5793x4)]
pxor m3, m3
mova [cq], m3
pmulhrsw m7, m0
pmulhrsw m7, m1
psrlw m1, 3 ; pw_2048
psllw m7, 2
pmulhrsw m7, m2
pmulhrsw m7, m1
punpcklwd m5, m7, m7
punpckhwd m7, m7
punpcklwd m4, m5, m5
punpckhwd m5, m5
punpcklwd m6, m7, m7
punpckhwd m7, m7
vpermq m0, m4, q1100
vpermq m1, m5, q1100
vpermq m2, m6, q1100
vpermq m3, m7, q1100
vpermq m4, m4, q3322
vpermq m5, m5, q3322
vpermq m6, m6, q3322
vpermq m7, m7, q3322
jmp m(idct_8x16_internal).end4
%elifidn %1_%2, identity_dct
movd xm0, [cq+32*0]
punpcklwd xm0, [cq+32*1]
movd xm2, [cq+32*2]
punpcklwd xm2, [cq+32*3]
add cq, 32*4
movd xm1, [cq+32*0]
punpcklwd xm1, [cq+32*1]
movd xm3, [cq+32*2]
punpcklwd xm3, [cq+32*3]
vpbroadcastd xm4, [o(pw_2896x8)]
vpbroadcastd xm5, [o(pw_2048)]
xor eax, eax
mov [cq-32*4], eax
mov [cq-32*3], eax
mov [cq-32*2], eax
mov [cq-32*1], eax
punpckldq xm0, xm2
punpckldq xm1, xm3
punpcklqdq xm0, xm1
pmulhrsw xm0, xm4
pmulhrsw xm0, xm4
pmulhrsw xm0, xm5
mov [cq+32*0], eax
mov [cq+32*1], eax
mov [cq+32*2], eax
mov [cq+32*3], eax
vinserti128 m0, m0, xm0, 1
mov r2d, 4
jmp m(inv_txfm_add_dct_dct_8x8).end2
%endif
%endmacro
%macro ITX_8X16_LOAD_COEFS 0
vpbroadcastd m4, [o(pw_2896x8)]
pmulhrsw m0, m4, [cq+32*0]
add cq, 32*4
pmulhrsw m7, m4, [cq+32*3]
pmulhrsw m1, m4, [cq-32*3]
pmulhrsw m6, m4, [cq+32*2]
pmulhrsw m2, m4, [cq-32*2]
pmulhrsw m5, m4, [cq+32*1]
pmulhrsw m3, m4, [cq-32*1]
pmulhrsw m4, [cq+32*0]
%endmacro
INV_TXFM_8X16_FN dct, dct, 0
INV_TXFM_8X16_FN dct, identity, 15
INV_TXFM_8X16_FN dct, adst
INV_TXFM_8X16_FN dct, flipadst
cglobal idct_8x16_internal, 0, 5, 13, dst, stride, c, eob, tx2
ITX_8X16_LOAD_COEFS
call m(idct_16x8_internal).main
vpbroadcastd m10, [o(pw_16384)]
.pass1_end:
vperm2i128 m9, m3, m7, 0x31
vinserti128 m3, m3, xm7, 1
vperm2i128 m8, m2, m6, 0x31
vinserti128 m2, m2, xm6, 1
vperm2i128 m6, m1, m5, 0x31
vinserti128 m1, m1, xm5, 1
vperm2i128 m5, m0, m4, 0x31
vinserti128 m0, m0, xm4, 1
punpckhwd m4, m2, m3
punpcklwd m2, m3
punpckhwd m3, m0, m1
punpcklwd m0, m1
.pass1_end2:
punpckhwd m7, m5, m6
punpcklwd m5, m6
punpcklwd m6, m8, m9
punpckhwd m8, m9
REPX {pmulhrsw x, m10}, m2, m0, m4, m3, m5, m6, m7, m8
punpckhdq m1, m0, m2
punpckldq m0, m2
punpckldq m2, m3, m4
punpckhdq m3, m4
punpckldq m4, m5, m6
punpckhdq m5, m6
punpckldq m6, m7, m8
punpckhdq m7, m8
jmp tx2q
.pass2:
call .main
REPX {vpermq x, x, q3120}, m0, m2, m4, m6
REPX {vpermq x, x, q2031}, m1, m3, m5, m7
.end:
vpbroadcastd m8, [o(pw_2048)]
.end2:
REPX {pmulhrsw x, m8}, m0, m1, m2, m3, m4, m5, m6, m7
.end3:
pxor m8, m8
REPX {mova [cq+32*x], m8}, -4, -3, -2, -1, 0, 1, 2, 3
.end4:
lea r3, [strideq*3]
WRITE_8X4 0, 1, 8, 9
lea dstq, [dstq+strideq*4]
WRITE_8X4 2, 3, 0, 1
lea dstq, [dstq+strideq*4]
WRITE_8X4 4, 5, 0, 1
lea dstq, [dstq+strideq*4]
WRITE_8X4 6, 7, 0, 1
RET
ALIGN function_align
.main:
IDCT16_1D_PACKED
ret
INV_TXFM_8X16_FN adst, dct
INV_TXFM_8X16_FN adst, adst
INV_TXFM_8X16_FN adst, flipadst
INV_TXFM_8X16_FN adst, identity
cglobal iadst_8x16_internal, 0, 5, 13, dst, stride, c, eob, tx2
ITX_8X16_LOAD_COEFS
call m(iadst_16x8_internal).main
vpbroadcastd m10, [o(pw_16384)]
pslld m9, m10, 17
psubw m10, m9 ; 16384, -16384
jmp m(idct_8x16_internal).pass1_end
ALIGN function_align
.pass2:
call .main
vpbroadcastd m9, [o(pw_2048)]
vpbroadcastd xm8, [o(pw_4096)]
psubw m8, m9
REPX {vpermq x, x, q2031}, m0, m1, m2, m3
REPX {vpermq x, x, q3120}, m4, m5, m6, m7
jmp m(idct_8x16_internal).end2
ALIGN function_align
.main:
REPX {pshufd x, x, q1032}, m7, m1, m5, m3
.main2:
vpbroadcastd m10, [o(pd_2048)]
punpckhwd m8, m7, m0 ; in14 in1
punpcklwd m0, m7 ; in0 in15
punpcklwd m7, m6, m1 ; in12 in3
punpckhwd m1, m6 ; in2 in13
punpckhwd m6, m5, m2 ; in10 in5
punpcklwd m2, m5 ; in4 in11
punpcklwd m5, m4, m3 ; in8 in7
punpckhwd m3, m4 ; in6 in9
ITX_MUL2X_PACK 0, 4, 9, 10, 201, 4091, 3 ; t0 t1
ITX_MUL2X_PACK 1, 4, 9, 10, 995, 3973, 3 ; t2 t3
ITX_MUL2X_PACK 2, 4, 9, 10, 1751, 3703, 3 ; t4 t5
ITX_MUL2X_PACK 3, 4, 9, 10, 2440, 3290, 3 ; t6 t7
ITX_MUL2X_PACK 5, 4, 9, 10, 3035, 2751, 3 ; t8 t9
ITX_MUL2X_PACK 6, 4, 9, 10, 3513, 2106, 3 ; t10 t11
ITX_MUL2X_PACK 7, 4, 9, 10, 3857, 1380, 3 ; t12 t13
ITX_MUL2X_PACK 8, 4, 9, 10, 4052, 601, 3 ; t14 t15
psubw m4, m0, m5 ; t9a t8a
paddw m0, m5 ; t1a t0a
psubw m5, m1, m6 ; t11a t10a
paddw m1, m6 ; t3a t2a
psubw m6, m2, m7 ; t13a t12a
paddw m2, m7 ; t5a t4a
psubw m7, m3, m8 ; t15a t14a
paddw m3, m8 ; t7a t6a
vpbroadcastd m11, [o(pw_m4017_799)]
vpbroadcastd m12, [o(pw_799_4017)]
pxor m9, m9
ITX_MUL2X_PACK 4, 8, _, 10, 11, 12, 6 ; t8 t9
psubw m8, m9, m11
ITX_MUL2X_PACK 6, 12, _, 10, 12, 8, 6 ; t12 t13
vpbroadcastd m11, [o(pw_m2276_3406)]
vpbroadcastd m12, [o(pw_3406_2276)]
ITX_MUL2X_PACK 5, 8, _, 10, 11, 12, 6 ; t10 t11
psubw m8, m9, m11
ITX_MUL2X_PACK 7, 12, _, 10, 12, 8, 6 ; t14 t15
psubw m8, m1, m3 ; t7 t6
paddw m1, m3 ; t3 t2
psubw m3, m0, m2 ; t5 t4
paddw m0, m2 ; t1 t0
psubw m2, m5, m7 ; t14a t15a
paddw m7, m5 ; t10a t11a
psubw m5, m4, m6 ; t12a t13a
paddw m4, m6 ; t8a t9a
vpbroadcastd m11, [o(pw_m3784_1567)]
vpbroadcastd m12, [o(pw_1567_3784)]
ITX_MUL2X_PACK 3, 6, _, 10, 11, 12, 4 ; t4a t5a
psubw m6, m9, m11
ITX_MUL2X_PACK 8, 12, _, 10, 12, 6, 4 ; t6a t7a
vpbroadcastd m11, [o(pw_m1567_3784)]
vpbroadcastd m12, [o(pw_3784_1567)]
ITX_MUL2X_PACK 2, 6, _, 10, 11, 12, 4 ; t15 t14
psubw m6, m9, m11
ITX_MUL2X_PACK 5, 12, _, 10, 12, 6, 4 ; t13 t12
vbroadcasti128 m11, [o(deint_shuf)]
vpbroadcastd m12, [o(pw_2896x8)]
psubw m6, m0, m1 ; t3a t2a
paddw m0, m1 ; -out15 out0
paddw m1, m2, m5 ; -out13 out2
psubw m5, m2 ; t15a t14a
paddw m2, m4, m7 ; -out1 out14
psubw m4, m7 ; t10 t11
psubw m7, m3, m8 ; t6 t7
paddw m8, m3 ; -out3 out12
REPX {pshufb x, m11}, m6, m4, m0, m2
vpblendd m3, m6, m4, 0xcc ; t3a t11
shufps m6, m6, m4, q1032 ; t2a t10
vpblendd m4, m5, m7, 0xcc ; t15a t7
shufps m5, m5, m7, q1032 ; t14a t6
shufps m7, m2, m0, q1032 ; out14 -out15
vpblendd m0, m0, m2, 0x33 ; -out1 out0
paddw m2, m5, m4 ; -out5 out4
psubw m5, m4 ; out10 -out11
psubw m4, m6, m3 ; out8 -out9
paddw m3, m6 ; -out7 out6
shufps m6, m8, m1, q1032 ; out12 -out13
vpblendd m1, m1, m8, 0x33 ; -out3 out2
REPX {pmulhrsw x, m12}, m2, m3, m4, m5
ret
INV_TXFM_8X16_FN flipadst, dct
INV_TXFM_8X16_FN flipadst, adst
INV_TXFM_8X16_FN flipadst, flipadst
INV_TXFM_8X16_FN flipadst, identity
cglobal iflipadst_8x16_internal, 0, 5, 13, dst, stride, c, eob, tx2
ITX_8X16_LOAD_COEFS
call m(iadst_16x8_internal).main
vpbroadcastd m9, [o(pw_16384)]
pslld m10, m9, 17
psubw m10, m9 ; -16384, 16384
vperm2i128 m9, m4, m0, 0x31
vinserti128 m0, m4, xm0, 1
vperm2i128 m8, m5, m1, 0x31
vinserti128 m4, m5, xm1, 1
vperm2i128 m5, m7, m3, 0x31
vinserti128 m3, m7, xm3, 1
vinserti128 m1, m6, xm2, 1
vperm2i128 m6, m6, m2, 0x31
punpcklwd m2, m4, m0
punpckhwd m4, m0
punpcklwd m0, m3, m1
punpckhwd m3, m1
jmp m(idct_8x16_internal).pass1_end2
.pass2:
call m(iadst_8x16_internal).main
vpbroadcastd m8, [o(pw_2048)]
vpbroadcastd xm9, [o(pw_4096)]
psubw m8, m9
vpermq m9, m0, q3120
vpermq m0, m7, q2031
vpermq m7, m1, q3120
vpermq m1, m6, q2031
vpermq m6, m2, q3120
vpermq m2, m5, q2031
vpermq m5, m3, q3120
vpermq m3, m4, q2031
pmulhrsw m0, m8
pmulhrsw m1, m8
pmulhrsw m2, m8
pmulhrsw m3, m8
pmulhrsw m4, m5, m8
pmulhrsw m5, m6, m8
pmulhrsw m6, m7, m8
pmulhrsw m7, m9, m8
jmp m(idct_8x16_internal).end3
INV_TXFM_8X16_FN identity, dct, 7
INV_TXFM_8X16_FN identity, adst
INV_TXFM_8X16_FN identity, flipadst
INV_TXFM_8X16_FN identity, identity
cglobal iidentity_8x16_internal, 0, 5, 13, dst, stride, c, eob, tx2
mova xm3, [cq+16*0]
mova xm2, [cq+16*2]
add cq, 16*8
vinserti128 m3, m3, [cq+16*0], 1
vinserti128 m2, m2, [cq+16*2], 1
vpbroadcastd m9, [o(pw_2896x8)]
mova xm4, [cq-16*4]
mova xm5, [cq-16*2]
vinserti128 m4, m4, [cq+16*4], 1
vinserti128 m5, m5, [cq+16*6], 1
mova xm7, [cq-16*7]
mova xm6, [cq-16*5]
vinserti128 m7, m7, [cq+16*1], 1
vinserti128 m6, m6, [cq+16*3], 1
mova xm8, [cq-16*3]
mova xm0, [cq-16*1]
vinserti128 m8, m8, [cq+16*5], 1
vinserti128 m0, m0, [cq+16*7], 1
punpcklwd m1, m3, m2
punpckhwd m3, m2
punpcklwd m2, m4, m5
punpckhwd m4, m5
punpcklwd m5, m7, m6
punpckhwd m7, m6
punpcklwd m6, m8, m0
punpckhwd m8, m0
REPX {pmulhrsw x, m9}, m1, m2, m3, m4, m5, m6, m7, m8
punpckldq m0, m1, m2
punpckhdq m1, m2
punpckldq m2, m3, m4
punpckhdq m3, m4
punpckldq m4, m5, m6
punpckhdq m5, m6
punpckldq m6, m7, m8
punpckhdq m7, m8
jmp tx2q
.pass2:
vpbroadcastd m8, [o(pw_5793x4)]
REPX {psllw x, 2 }, m0, m1, m2, m3, m4, m5, m6, m7
REPX {vpermq x, x, q3120}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {pmulhrsw x, m8 }, m0, m1, m2, m3, m4, m5, m6, m7
jmp m(idct_8x16_internal).end
%macro WRITE_16X2 6 ; coefs[1-2], tmp[1-2], offset[1-2]
pmovzxbw m%3, [dstq+%5]
%ifnum %1
paddw m%3, m%1
%else
paddw m%3, %1
%endif
pmovzxbw m%4, [dstq+%6]
%ifnum %2
paddw m%4, m%2
%else
paddw m%4, %2
%endif
packuswb m%3, m%4
vpermq m%3, m%3, q3120
mova [dstq+%5], xm%3
vextracti128 [dstq+%6], m%3, 1
%endmacro
%macro INV_TXFM_16X4_FN 2-3 -1 ; type1, type2, fast_thresh
INV_TXFM_FN %1, %2, %3, 16x4
%if %3 >= 0
%ifidn %1_%2, dct_identity
vpbroadcastd xm3, [o(pw_2896x8)]
pmulhrsw xm3, [cq]
vpbroadcastd xm0, [o(pw_16384)]
vpbroadcastd xm1, [o(pw_5793x4)]
pmulhrsw xm3, xm0
psrlw xm0, 3 ; pw_2048
paddw xm3, xm3
pmulhrsw xm3, xm1
pmulhrsw xm3, xm0
punpcklwd xm3, xm3
punpckldq xm1, xm3, xm3
punpckhdq xm3, xm3
vpbroadcastq m0, xm1
vpermq m1, m1, q1111
vpbroadcastq m2, xm3
vpermq m3, m3, q1111
jmp m(iadst_16x4_internal).end2
%elifidn %1_%2, identity_dct
mova xm0, [cq+16*0]
mova xm2, [cq+16*1]
vinserti128 m0, m0, [cq+16*4], 1
vinserti128 m2, m2, [cq+16*5], 1
mova xm1, [cq+16*2]
mova xm3, [cq+16*3]
vinserti128 m1, m1, [cq+16*6], 1
vinserti128 m3, m3, [cq+16*7], 1
vpbroadcastd m4, [o(pw_5793x4)]
vpbroadcastd m5, [o(pw_16384)]
packusdw m0, m2
packusdw m1, m3
packusdw m0, m1
vpbroadcastd m1, [o(pw_2896x8)]
psllw m0, 2
pmulhrsw m0, m4
pmulhrsw m0, m5
psrlw m5, 3 ; pw_2048
pmulhrsw m0, m1
pmulhrsw m0, m5
mov r3d, 2
.end:
pxor m3, m3
.end_loop:
mova [cq+32*0], m3
mova [cq+32*1], m3
add cq, 32*2
WRITE_16X2 0, 0, 1, 2, strideq*0, strideq*1
lea dstq, [dstq+strideq*2]
dec r3d
jg .end_loop
RET
%else
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
%ifidn %2, dct
movd xm2, [o(pw_16384)]
mov [cq], eobd
mov r2d, 2
.dconly:
pmulhrsw xm0, xm2
movd xm2, [pw_2048] ; intentionally rip-relative
pmulhrsw xm0, xm1
pmulhrsw xm0, xm2
vpbroadcastw m0, xm0
pxor m3, m3
.dconly_loop:
mova xm1, [dstq]
vinserti128 m1, m1, [dstq+strideq], 1
punpckhbw m2, m1, m3
punpcklbw m1, m3
paddw m2, m0
paddw m1, m0
packuswb m1, m2
mova [dstq], xm1
vextracti128 [dstq+strideq], m1, 1
lea dstq, [dstq+strideq*2]
dec r2d
jg .dconly_loop
RET
%else ; adst / flipadst
movd xm2, [o(pw_16384)]
pmulhrsw xm0, xm2
vpbroadcastw m0, xm0
pmulhrsw m0, [o(iadst4_dconly2a)]
vpbroadcastd m3, [o(pw_2048)]
mov [cq], eobd
pmulhrsw m3, m0
%ifidn %2, adst
vpbroadcastq m0, xm3
vpermq m1, m3, q1111
vpermq m2, m3, q2222
vpermq m3, m3, q3333
%else ; flipadst
vpermq m0, m3, q3333
vpermq m1, m3, q2222
vpermq m2, m3, q1111
vpbroadcastq m3, xm3
%endif
jmp m(iadst_16x4_internal).end3
%endif
%endif
%endif
%endmacro
INV_TXFM_16X4_FN dct, dct, 0
INV_TXFM_16X4_FN dct, adst, 0
INV_TXFM_16X4_FN dct, flipadst, 0
INV_TXFM_16X4_FN dct, identity, 3
cglobal idct_16x4_internal, 0, 5, 11, dst, stride, c, eob, tx2
mova xm0, [cq+16*0]
mova xm1, [cq+16*1]
mova xm2, [cq+16*2]
mova xm3, [cq+16*3]
mova xm4, [cq+16*4]
mova xm5, [cq+16*5]
mova xm6, [cq+16*6]
mova xm7, [cq+16*7]
call m(idct_4x16_internal).main
vinserti128 m6, m2, xm6, 1
vinserti128 m2, m0, xm4, 1
vinserti128 m0, m1, xm5, 1
vinserti128 m1, m3, xm7, 1
punpcklwd m3, m2, m6
punpckhwd m2, m6
vpbroadcastd m6, [o(pw_16384)]
punpckhwd m4, m0, m1
punpcklwd m0, m1
mova m1, m6
jmp m(iadst_16x4_internal).pass1_end
.pass2:
call .main
jmp m(iadst_16x4_internal).end
ALIGN function_align
.main:
vpbroadcastd m6, [o(pd_2048)]
IDCT4_1D 0, 1, 2, 3, 4, 5, 6
ret
INV_TXFM_16X4_FN adst, dct
INV_TXFM_16X4_FN adst, adst
INV_TXFM_16X4_FN adst, flipadst
INV_TXFM_16X4_FN adst, identity
cglobal iadst_16x4_internal, 0, 5, 11, dst, stride, c, eob, tx2
vpermq m0, [cq+32*0], q1230
vpermq m3, [cq+32*3], q2103
vpermq m1, [cq+32*1], q1230
vpermq m2, [cq+32*2], q2103
call m(iadst_4x16_internal).main2
pshufd m2, m2, q1032
punpcklwd m4, m3, m1
punpcklwd m5, m2, m0
punpckhwd m0, m1
punpckhwd m2, m3
vpbroadcastd m1, [o(pw_16384)]
vinserti128 m3, m0, xm2, 1
vperm2i128 m2, m0, m2, 0x31
vinserti128 m0, m4, xm5, 1
vperm2i128 m4, m4, m5, 0x31
psubw m6, m7, m1
.pass1_end:
pmulhrsw m3, m1
pmulhrsw m2, m6
pmulhrsw m4, m1
pmulhrsw m0, m6
punpcklwd m1, m3, m2
punpckhwd m3, m2
punpcklwd m2, m4, m0
punpckhwd m4, m0
punpckldq m0, m1, m2
punpckhdq m1, m2
punpckldq m2, m3, m4
punpckhdq m3, m4
jmp tx2q
.pass2:
call .main
.end:
vpbroadcastd m4, [o(pw_2048)]
REPX {pmulhrsw x, m4}, m0, m1, m2, m3
WIN64_RESTORE_XMM
.end2:
pxor m4, m4
mova [cq+32*0], m4
mova [cq+32*1], m4
mova [cq+32*2], m4
mova [cq+32*3], m4
.end3:
WRITE_16X2 0, 1, 4, 5, strideq*0, strideq*1
lea dstq, [dstq+strideq*2]
WRITE_16X2 2, 3, 4, 5, strideq*0, strideq*1
RET
ALIGN function_align
.main:
vpbroadcastd m7, [o(pw_3803_1321)]
vpbroadcastd m8, [o(pw_m1321_2482)]
vpbroadcastd m9, [o(pw_2482_3344)]
punpcklwd m4, m2, m0 ; in2 in0 l
psubw m6, m0, m2
punpckhwd m2, m0 ; in2 in0 h
paddw m6, m3 ; t2
pmaddwd m0, m7, m4 ; t0:02 l
pmaddwd m7, m2 ; t0:02 h
pmaddwd m4, m8 ; t1:02 l
pmaddwd m8, m2 ; t1:02 h
punpckhwd m2, m3, m1 ; in3 in1 h
punpcklwd m3, m1 ; in3 in1 l
vpbroadcastd m1, [o(pd_2048)]
pmaddwd m5, m9, m3
pmaddwd m9, m2
paddd m0, m1
paddd m7, m1
paddd m0, m5 ; t0 + t3 + 2048 l
paddd m7, m9 ; t0 + t3 + 2048 h
vpbroadcastd m9, [o(pw_m3803_3344)]
pmaddwd m5, m9, m2
pmaddwd m9, m3
paddd m5, m1 ; t1:13 + 2048 h
paddd m1, m9 ; t1:13 + 2048 l
vpbroadcastd m9, [o(pw_m3803_m6688)]
pmaddwd m2, m9
pmaddwd m3, m9
paddd m5, m8 ; t1 + t3 + 2048 h
paddd m1, m4 ; t1 + t3 + 2048 l
paddd m8, m7
paddd m4, m0
paddd m2, m8 ; t0 + t1 - t3 + 2048 h
paddd m3, m4 ; t0 + t1 - t3 + 2048 l
REPX {psrad x, 12}, m0, m7, m5, m1, m2, m3
packssdw m0, m7
packssdw m1, m5
packssdw m3, m2
vpbroadcastd m2, [o(pw_3344x8)]
pmulhrsw m2, m6
ret
INV_TXFM_16X4_FN flipadst, dct
INV_TXFM_16X4_FN flipadst, adst
INV_TXFM_16X4_FN flipadst, flipadst
INV_TXFM_16X4_FN flipadst, identity
cglobal iflipadst_16x4_internal, 0, 5, 11, dst, stride, c, eob, tx2
vpermq m0, [cq+32*0], q1230
vpermq m3, [cq+32*3], q2103
vpermq m1, [cq+32*1], q1230
vpermq m2, [cq+32*2], q2103
call m(iadst_4x16_internal).main2
pshufd m2, m2, q1032
punpckhwd m4, m3, m2
punpckhwd m5, m1, m0
punpcklwd m0, m2
punpcklwd m1, m3
vpbroadcastd m6, [o(pw_16384)]
vinserti128 m3, m0, xm1, 1
vperm2i128 m2, m0, m1, 0x31
vinserti128 m0, m4, xm5, 1
vperm2i128 m4, m4, m5, 0x31
psubw m1, m7, m6
jmp m(iadst_16x4_internal).pass1_end
ALIGN function_align
.pass2:
call m(iadst_16x4_internal).main
vpbroadcastd m4, [o(pw_2048)]
REPX {pmulhrsw x, m4}, m3, m2, m1, m0
pxor m4, m4
mova [cq+32*0], m4
mova [cq+32*1], m4
mova [cq+32*2], m4
mova [cq+32*3], m4
WRITE_16X2 3, 2, 4, 5, strideq*0, strideq*1
lea dstq, [dstq+strideq*2]
WRITE_16X2 1, 0, 4, 5, strideq*0, strideq*1
RET
INV_TXFM_16X4_FN identity, dct, 15
INV_TXFM_16X4_FN identity, adst
INV_TXFM_16X4_FN identity, flipadst
INV_TXFM_16X4_FN identity, identity
cglobal iidentity_16x4_internal, 0, 5, 11, dst, stride, c, eob, tx2
mova xm2, [cq+16*0]
mova xm4, [cq+16*1]
vinserti128 m2, m2, [cq+16*4], 1
vinserti128 m4, m4, [cq+16*5], 1
mova xm0, [cq+16*2]
mova xm1, [cq+16*3]
vinserti128 m0, m0, [cq+16*6], 1
vinserti128 m1, m1, [cq+16*7], 1
vpbroadcastd m5, [o(pw_5793x4)]
punpcklwd m3, m2, m4
punpckhwd m2, m4
punpcklwd m4, m0, m1
punpckhwd m0, m1
REPX {psllw x, 2}, m3, m2, m4, m0
punpcklwd m1, m3, m2
punpckhwd m3, m2
punpcklwd m2, m4, m0
punpckhwd m4, m0
REPX {pmulhrsw x, m5}, m1, m3, m2, m4
vpbroadcastd m5, [o(pw_16384)]
punpcklqdq m0, m1, m2
punpckhqdq m1, m2
punpcklqdq m2, m3, m4
punpckhqdq m3, m4
REPX {pmulhrsw x, m5}, m0, m1, m2, m3
jmp tx2q
.pass2:
vpbroadcastd m4, [o(pw_5793x4)]
REPX {paddw x, x }, m0, m1, m2, m3
REPX {pmulhrsw x, m4}, m0, m1, m2, m3
jmp m(iadst_16x4_internal).end
%macro INV_TXFM_16X8_FN 2-3 -1 ; type1, type2, fast_thresh
INV_TXFM_FN %1, %2, %3, 16x8
%ifidn %1_%2, dct_dct
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_16384)]
mov [cq], eobd
pmulhrsw xm0, xm1
mov r2d, 4
jmp m(inv_txfm_add_dct_dct_16x4).dconly
%elifidn %1_%2, dct_identity
WIN64_SPILL_XMM 13
vbroadcasti128 m7, [cq]
vpbroadcastd m0, [o(pw_2896x8)]
vpbroadcastd m1, [o(pw_16384)]
pxor xm2, xm2
mova [cq], xm2
pmulhrsw m7, m0
pmulhrsw m7, m0
pmulhrsw m7, m1
psrlw m1, 2 ; pw_4096
pmulhrsw m7, m1
punpcklwd m3, m7, m7
punpckhwd m7, m7
pshufd m0, m3, q0000
pshufd m1, m3, q1111
pshufd m2, m3, q2222
pshufd m3, m3, q3333
pshufd m4, m7, q0000
pshufd m5, m7, q1111
pshufd m6, m7, q2222
pshufd m7, m7, q3333
lea r3, [strideq*3]
WRITE_16X2 0, 1, 8, 0, strideq*0, strideq*1
WRITE_16X2 2, 3, 0, 1, strideq*2, r3
jmp m(idct_16x8_internal).end4
%elifidn %1_%2, identity_dct
mova m0, [cq+32*0]
packusdw m0, [cq+32*1]
mova m2, [cq+32*2]
packusdw m2, [cq+32*3]
mova m1, [cq+32*4]
packusdw m1, [cq+32*5]
mova m3, [cq+32*6]
packusdw m3, [cq+32*7]
vpbroadcastd m4, [o(pw_2896x8)]
vpbroadcastd m5, [o(pw_5793x4)]
packusdw m0, m2
packusdw m1, m3
vpbroadcastd m2, [o(pw_16384)]
packusdw m0, m1
vpermq m1, m0, q3322
vpermq m0, m0, q1100
punpcklwd m0, m1
pmulhrsw m0, m4
psllw m0, 2
pmulhrsw m0, m5
pmulhrsw m0, m2
psrlw m2, 3 ; pw_2048
pmulhrsw m0, m4
pmulhrsw m0, m2
mov r3d, 4
jmp m(inv_txfm_add_identity_dct_16x4).end
%endif
%endmacro
%macro ITX_16X8_LOAD_COEFS 1 ; shuf_odd
vpbroadcastd m8, [o(pw_2896x8)]
vpermq m0, [cq+32*0], q3120
add cq, 32*4
vpermq m7, [cq+32*3], q%1
vpermq m1, [cq-32*3], q%1
vpermq m6, [cq+32*2], q3120
vpermq m2, [cq-32*2], q3120
vpermq m5, [cq+32*1], q%1
vpermq m3, [cq-32*1], q%1
vpermq m4, [cq+32*0], q3120
REPX {pmulhrsw x, m8}, m0, m7, m1, m6, m2, m5, m3, m4
%endmacro
INV_TXFM_16X8_FN dct, dct, 0
INV_TXFM_16X8_FN dct, identity, 7
INV_TXFM_16X8_FN dct, adst
INV_TXFM_16X8_FN dct, flipadst
cglobal idct_16x8_internal, 0, 5, 13, dst, stride, c, eob, tx2
ITX_16X8_LOAD_COEFS 3120
call m(idct_8x16_internal).main
vpbroadcastd m10, [o(pw_16384)]
punpckhwd m8, m0, m2
punpcklwd m0, m2
punpckhwd m2, m1, m3
punpcklwd m1, m3
punpcklwd m9, m4, m6
punpckhwd m4, m6
punpcklwd m6, m5, m7
punpckhwd m5, m7
REPX {pmulhrsw x, m10}, m8, m1, m4, m6
.pass1_end:
REPX {pmulhrsw x, m10}, m0, m2, m9, m5
punpckhwd m3, m0, m8
punpcklwd m0, m8
punpckhwd m8, m2, m1
punpcklwd m2, m1
punpcklwd m7, m9, m4
punpckhwd m9, m4
punpcklwd m4, m5, m6
punpckhwd m5, m6
punpckhdq m1, m0, m2
punpckldq m0, m2
punpckldq m2, m3, m8
punpckhdq m3, m8
punpckldq m6, m7, m4
punpckhdq m7, m4
punpckldq m8, m9, m5
punpckhdq m9, m5
vperm2i128 m4, m0, m6, 0x31
vinserti128 m0, m0, xm6, 1
vperm2i128 m5, m1, m7, 0x31
vinserti128 m1, m1, xm7, 1
vperm2i128 m6, m2, m8, 0x31
vinserti128 m2, m2, xm8, 1
vperm2i128 m7, m3, m9, 0x31
vinserti128 m3, m3, xm9, 1
jmp tx2q
.pass2:
call .main
vpbroadcastd m8, [o(pw_2048)]
.end:
REPX {pmulhrsw x, m8}, m0, m2, m4, m6
.end2:
REPX {pmulhrsw x, m8}, m1, m3, m5, m7
lea r3, [strideq*3]
WRITE_16X2 0, 1, 8, 0, strideq*0, strideq*1
WRITE_16X2 2, 3, 0, 1, strideq*2, r3
.end3:
pxor m0, m0
REPX {mova [cq+32*x], m0}, -4, -3, -2, -1, 0, 1, 2, 3
.end4:
lea dstq, [dstq+strideq*4]
WRITE_16X2 4, 5, 0, 1, strideq*0, strideq*1
WRITE_16X2 6, 7, 0, 1, strideq*2, r3
RET
ALIGN function_align
.main:
vpbroadcastd m10, [o(pd_2048)]
.main2:
IDCT8_1D 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
ret
INV_TXFM_16X8_FN adst, dct
INV_TXFM_16X8_FN adst, adst
INV_TXFM_16X8_FN adst, flipadst
INV_TXFM_16X8_FN adst, identity
cglobal iadst_16x8_internal, 0, 5, 13, dst, stride, c, eob, tx2
ITX_16X8_LOAD_COEFS 1302
call m(iadst_8x16_internal).main2
vpbroadcastd m10, [o(pw_16384)]
psubw m11, m9, m10
punpcklwd m8, m0, m2
punpckhwd m0, m2
punpckhwd m2, m1, m3
punpcklwd m1, m3
punpcklwd m9, m4, m6
punpckhwd m4, m6
punpckhwd m6, m5, m7
punpcklwd m5, m7
REPX {pmulhrsw x, m11}, m8, m1, m4, m6
jmp m(idct_16x8_internal).pass1_end
ALIGN function_align
.pass2:
call .main
vpbroadcastd m9, [o(pw_2048)]
pxor m8, m8
psubw m8, m9
REPX {pmulhrsw x, m9}, m0, m2, m4, m6
jmp m(idct_16x8_internal).end2
ALIGN function_align
.main:
vpbroadcastd m10, [o(pd_2048)]
ITX_MULSUB_2W 7, 0, 8, 9, 10, 401, 4076 ; t1a, t0a
ITX_MULSUB_2W 3, 4, 8, 9, 10, 3166, 2598 ; t5a, t4a
ITX_MULSUB_2W 1, 6, 8, 9, 10, 3920, 1189 ; t7a, t6a
ITX_MULSUB_2W 5, 2, 8, 9, 10, 1931, 3612 ; t3a, t2a
psubw m8, m2, m6 ; t6
paddw m2, m6 ; t2
psubw m6, m0, m4 ; t4
paddw m0, m4 ; t0
psubw m4, m5, m1 ; t7
paddw m5, m1 ; t3
psubw m1, m7, m3 ; t5
paddw m7, m3 ; t1
ITX_MULSUB_2W 6, 1, 3, 9, 10, 1567, 3784 ; t5a, t4a
ITX_MULSUB_2W 4, 8, 3, 9, 10, 3784, 1567 ; t6a, t7a
psubw m9, m6, m8 ; t7
paddw m6, m8 ; out6
vpbroadcastd m8, [o(pw_2896x8)]
psubw m3, m7, m5 ; t3
paddw m7, m5 ; -out7
psubw m5, m0, m2 ; t2
paddw m0, m2 ; out0
psubw m2, m1, m4 ; t6
paddw m1, m4 ; -out1
psubw m4, m5, m3
paddw m3, m5
psubw m5, m2, m9
paddw m2, m9
pmulhrsw m2, m8 ; out2
pmulhrsw m3, m8 ; -out3
pmulhrsw m4, m8 ; out4
pmulhrsw m5, m8 ; -out5
ret
INV_TXFM_16X8_FN flipadst, dct
INV_TXFM_16X8_FN flipadst, adst
INV_TXFM_16X8_FN flipadst, flipadst
INV_TXFM_16X8_FN flipadst, identity
cglobal iflipadst_16x8_internal, 0, 5, 13, dst, stride, c, eob, tx2
ITX_16X8_LOAD_COEFS 1302
call m(iadst_8x16_internal).main2
vpbroadcastd m10, [o(pw_16384)]
psubw m9, m10
punpcklwd m8, m6, m4
punpckhwd m6, m4
punpcklwd m4, m7, m5
punpckhwd m7, m5
punpckhwd m5, m3, m1
punpcklwd m3, m1
punpckhwd m1, m2, m0
punpcklwd m2, m0
REPX {pmulhrsw x, m10}, m8, m4, m5, m1
REPX {pmulhrsw x, m9 }, m6, m7, m3, m2
punpcklwd m0, m7, m4
punpckhwd m7, m4
punpckhwd m4, m6, m8
punpcklwd m6, m8
punpckhwd m8, m3, m5
punpcklwd m3, m5
punpcklwd m5, m2, m1
punpckhwd m2, m1
punpckhdq m1, m0, m6
punpckldq m0, m6
punpckldq m6, m7, m4
punpckhdq m7, m4
punpckhdq m4, m3, m5
punpckldq m3, m5
punpckldq m5, m8, m2
punpckhdq m8, m2
vinserti128 m2, m6, xm5, 1
vperm2i128 m6, m6, m5, 0x31
vperm2i128 m5, m1, m4, 0x31
vinserti128 m1, m1, xm4, 1
vperm2i128 m4, m0, m3, 0x31
vinserti128 m0, m0, xm3, 1
vinserti128 m3, m7, xm8, 1
vperm2i128 m7, m7, m8, 0x31
jmp tx2q
.pass2:
call m(iadst_16x8_internal).main
vpbroadcastd m9, [o(pw_2048)]
pxor m8, m8
psubw m8, m9
pmulhrsw m10, m7, m8
pmulhrsw m7, m0, m9
pmulhrsw m0, m6, m9
pmulhrsw m6, m1, m8
pmulhrsw m1, m5, m8
pmulhrsw m5, m2, m9
pmulhrsw m2, m4, m9
pmulhrsw m4, m3, m8
lea r3, [strideq*3]
WRITE_16X2 10, 0, 8, 9, strideq*0, strideq*1
WRITE_16X2 1, 2, 0, 1, strideq*2, r3
jmp m(idct_16x8_internal).end3
INV_TXFM_16X8_FN identity, dct, 15
INV_TXFM_16X8_FN identity, adst
INV_TXFM_16X8_FN identity, flipadst
INV_TXFM_16X8_FN identity, identity
cglobal iidentity_16x8_internal, 0, 5, 13, dst, stride, c, eob, tx2
mova xm7, [cq+16*0]
mova xm2, [cq+16*1]
add cq, 16*8
vpbroadcastd m3, [o(pw_2896x8)]
vinserti128 m7, m7, [cq+16*0], 1
vinserti128 m2, m2, [cq+16*1], 1
mova xm6, [cq-16*6]
mova xm4, [cq-16*5]
vinserti128 m6, m6, [cq+16*2], 1
vinserti128 m4, m4, [cq+16*3], 1
mova xm8, [cq-16*4]
mova xm5, [cq-16*3]
vinserti128 m8, m8, [cq+16*4], 1
vinserti128 m5, m5, [cq+16*5], 1
mova xm0, [cq-16*2]
mova xm1, [cq-16*1]
vinserti128 m0, m0, [cq+16*6], 1
vinserti128 m1, m1, [cq+16*7], 1
vpbroadcastd m9, [o(pw_5793x4)]
vpbroadcastd m10, [o(pw_16384)]
REPX {pmulhrsw x, m3}, m7, m2, m6, m4, m8, m5, m0, m1
punpcklwd m3, m7, m2
punpckhwd m7, m2
punpcklwd m2, m6, m4
punpckhwd m6, m4
punpcklwd m4, m8, m5
punpckhwd m8, m5
punpcklwd m5, m0, m1
punpckhwd m0, m1
REPX {psllw x, 2}, m3, m7, m2, m6, m4, m8, m5, m0
punpckldq m1, m3, m2
punpckhdq m3, m2
punpckldq m2, m4, m5
punpckhdq m4, m5
punpckldq m5, m7, m6
punpckhdq m7, m6
punpckldq m6, m8, m0
punpckhdq m8, m0
REPX {pmulhrsw x, m9}, m1, m3, m2, m4, m5, m7, m6, m8
punpcklqdq m0, m1, m2
punpckhqdq m1, m2
punpcklqdq m2, m3, m4
punpckhqdq m3, m4
punpcklqdq m4, m5, m6
punpckhqdq m5, m6
punpcklqdq m6, m7, m8
punpckhqdq m7, m8
REPX {pmulhrsw x, m10}, m0, m1, m2, m3, m4, m5, m6, m7
jmp tx2q
.pass2:
vpbroadcastd m8, [o(pw_4096)]
jmp m(idct_16x8_internal).end
%define o_base pw_5 + 128
%macro INV_TXFM_16X16_FN 2-3 -1 ; type1, type2, fast_thresh
INV_TXFM_FN %1, %2, %3, 16x16
%ifidn %1_%2, dct_dct
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_8192)]
mov [cq], eobd
mov r2d, 8
jmp m(inv_txfm_add_dct_dct_16x4).dconly
%elifidn %1_%2, dct_identity
WIN64_SPILL_XMM 7
vpbroadcastd m3, [o(pw_2896x8)]
pmulhrsw m3, [cq]
vpbroadcastd m0, [o(pw_8192)]
vpbroadcastd m1, [o(pw_5793x4)]
vpbroadcastw m4, [o(deint_shuf)] ; pb_0_1
pcmpeqb m5, m5
pxor m6, m6
mova [cq], m6
paddb m5, m5 ; pb_m2
pmulhrsw m3, m0
psrlw m0, 2 ; pw_2048
psllw m3, 2
pmulhrsw m3, m1
pmulhrsw m3, m0
mov r3d, 8
.loop:
mova xm1, [dstq]
vinserti128 m1, m1, [dstq+strideq*8], 1
pshufb m0, m3, m4
psubb m4, m5 ; += 2
punpckhbw m2, m1, m6
punpcklbw m1, m6
paddw m2, m0
paddw m1, m0
packuswb m1, m2
mova [dstq], xm1
vextracti128 [dstq+strideq*8], m1, 1
add dstq, strideq
dec r3d
jg .loop
RET
%elifidn %1_%2, identity_dct
movd xm0, [cq+32*0 ]
movd xm2, [cq+32*1 ]
movd xm1, [cq+32*2 ]
movd xm3, [cq+32*3 ]
vinserti128 m0, m0, [cq+32*8 ], 1
vinserti128 m2, m2, [cq+32*9 ], 1
vinserti128 m1, m1, [cq+32*10], 1
vinserti128 m3, m3, [cq+32*11], 1
punpcklwd m0, m2
punpcklwd m1, m3
punpckldq m0, m1
movd xm1, [cq+32*4 ]
movd xm3, [cq+32*5 ]
movd xm2, [cq+32*6 ]
movd xm4, [cq+32*7 ]
vinserti128 m1, m1, [cq+32*12], 1
vinserti128 m3, m3, [cq+32*13], 1
vinserti128 m2, m2, [cq+32*14], 1
vinserti128 m4, m4, [cq+32*15], 1
punpcklwd m1, m3
vpbroadcastd m3, [o(pw_5793x4)]
punpcklwd m2, m4
vpbroadcastd m4, [o(pw_8192)]
punpckldq m1, m2
vpbroadcastd m2, [o(pw_2896x8)]
punpcklqdq m0, m1
psllw m0, 2
pmulhrsw m0, m3
pmulhrsw m0, m4
psrlw m4, 2 ; pw_2048
pmulhrsw m0, m2
pmulhrsw m0, m4
mov r3d, 8
jmp m(inv_txfm_add_identity_dct_16x4).end
%endif
%endmacro
%macro ITX_16X16_LOAD_COEFS 0
mova m0, [cq+32*0]
mova m1, [cq+32*1]
mova m2, [cq+32*2]
mova m3, [cq+32*3]
add cq, 32*8
mova m4, [cq-32*4]
mova m5, [cq-32*3]
mova m6, [cq-32*2]
mova m7, [cq-32*1]
mova m8, [cq+32*0]
mova m9, [cq+32*1]
mova m10, [cq+32*2]
mova m11, [cq+32*3]
mova m12, [cq+32*4]
mova m13, [cq+32*5]
mova m14, [cq+32*6]
mova m15, [cq+32*7]
mova [rsp], m15
%endmacro
INV_TXFM_16X16_FN dct, dct, 0
INV_TXFM_16X16_FN dct, identity, 15
INV_TXFM_16X16_FN dct, adst
INV_TXFM_16X16_FN dct, flipadst
cglobal idct_16x16_internal, 0, 5, 16, 32*3, dst, stride, c, eob, tx2
ITX_16X16_LOAD_COEFS
call .main
.pass1_end:
vpbroadcastd m1, [o(pw_8192)]
REPX {pmulhrsw x, m1}, m0, m2, m4, m6, m8, m10, m12, m14
vextracti128 [rsp+16*5], m8, 1
mova [rsp+16*1], xm8
.pass1_end2:
vextracti128 [rsp+16*4], m0, 1
mova [rsp+16*0], xm0
REPX {pmulhrsw x, m1}, m3, m5, m7, m9, m11, m13, m15
pmulhrsw m1, [rsp+32*1]
vperm2i128 m8, m1, m9, 0x31
vinserti128 m1, m1, xm9, 1
vperm2i128 m9, m2, m10, 0x31
vinserti128 m2, m2, xm10, 1
vperm2i128 m10, m3, m11, 0x31
vinserti128 m3, m3, xm11, 1
vperm2i128 m11, m4, m12, 0x31
vinserti128 m4, m4, xm12, 1
vperm2i128 m12, m5, m13, 0x31
vinserti128 m5, m5, xm13, 1
vperm2i128 m13, m6, m14, 0x31
vinserti128 m6, m6, xm14, 1
vperm2i128 m14, m7, m15, 0x31
vinserti128 m7, m7, xm15, 1
mova m15, [rsp+32*2]
.pass1_end3:
punpcklwd m0, m9, m10
punpckhwd m9, m10
punpcklwd m10, m15, m8
punpckhwd m15, m8
punpckhwd m8, m11, m12
punpcklwd m11, m12
punpckhwd m12, m13, m14
punpcklwd m13, m14
punpckhdq m14, m11, m13
punpckldq m11, m13
punpckldq m13, m15, m9
punpckhdq m15, m9
punpckldq m9, m10, m0
punpckhdq m10, m0
punpckhdq m0, m8, m12
punpckldq m8, m12
punpcklqdq m12, m13, m8
punpckhqdq m13, m8
punpcklqdq m8, m9, m11
punpckhqdq m9, m11
punpckhqdq m11, m10, m14
punpcklqdq m10, m14
punpcklqdq m14, m15, m0
punpckhqdq m15, m0
mova m0, [rsp]
mova [rsp], m15
punpckhwd m15, m4, m5
punpcklwd m4, m5
punpckhwd m5, m0, m1
punpcklwd m0, m1
punpckhwd m1, m6, m7
punpcklwd m6, m7
punpckhwd m7, m2, m3
punpcklwd m2, m3
punpckhdq m3, m0, m2
punpckldq m0, m2
punpckldq m2, m4, m6
punpckhdq m4, m6
punpckhdq m6, m5, m7
punpckldq m5, m7
punpckldq m7, m15, m1
punpckhdq m15, m1
punpckhqdq m1, m0, m2
punpcklqdq m0, m2
punpcklqdq m2, m3, m4
punpckhqdq m3, m4
punpcklqdq m4, m5, m7
punpckhqdq m5, m7
punpckhqdq m7, m6, m15
punpcklqdq m6, m15
jmp tx2q
.pass2:
call .main
.end:
vpbroadcastd m1, [o(pw_2048)]
REPX {pmulhrsw x, m1}, m0, m2, m4, m6, m8, m10, m12, m14
mova [rsp], m6
.end2:
REPX {pmulhrsw x, m1}, m3, m5, m7, m9, m11, m13, m15
pmulhrsw m1, [rsp+32*1]
lea r3, [strideq*3]
WRITE_16X2 0, 1, 6, 0, strideq*0, strideq*1
WRITE_16X2 2, 3, 0, 1, strideq*2, r3
lea dstq, [dstq+strideq*4]
WRITE_16X2 4, 5, 0, 1, strideq*0, strideq*1
WRITE_16X2 [rsp], 7, 0, 1, strideq*2, r3
.end3:
pxor m2, m2
REPX {mova [cq+32*x], m2}, -8, -7, -6, -5, -4, -3, -2, -1
lea dstq, [dstq+strideq*4]
WRITE_16X2 8, 9, 0, 1, strideq*0, strideq*1
WRITE_16X2 10, 11, 0, 1, strideq*2, r3
REPX {mova [cq+32*x], m2}, 0, 1, 2, 3, 4, 5, 6, 7
lea dstq, [dstq+strideq*4]
WRITE_16X2 12, 13, 0, 1, strideq*0, strideq*1
WRITE_16X2 14, 15, 0, 1, strideq*2, r3
RET
ALIGN function_align
.main:
vpbroadcastd m15, [o(pd_2048)]
mova [rsp+gprsize+32*1], m1
mova [rsp+gprsize+32*2], m9
IDCT8_1D 0, 2, 4, 6, 8, 10, 12, 14, 1, 9, 15
mova m1, [rsp+gprsize+32*2] ; in9
mova [rsp+gprsize+32*2], m14 ; tmp7
mova m9, [rsp+gprsize+32*1] ; in1
mova [rsp+gprsize+32*1], m10 ; tmp5
mova m14, [rsp+gprsize+32*0] ; in15
mova [rsp+gprsize+32*0], m6 ; tmp3
IDCT16_1D_ODDHALF 9, 3, 5, 7, 1, 11, 13, 14, 6, 10, 15
mova m6, [rsp+gprsize+32*1] ; tmp5
psubw m15, m0, m14 ; out15
paddw m0, m14 ; out0
psubw m14, m2, m13 ; out14
paddw m2, m13 ; out1
mova [rsp+gprsize+32*1], m2
psubw m13, m4, m11 ; out13
paddw m2, m4, m11 ; out2
psubw m11, m8, m7 ; out11
paddw m4, m8, m7 ; out4
mova m7, [rsp+gprsize+32*2] ; tmp7
psubw m10, m6, m5 ; out10
paddw m5, m6 ; out5
psubw m8, m7, m9 ; out8
paddw m7, m9 ; out7
psubw m9, m12, m3 ; out9
paddw m6, m12, m3 ; out6
mova m3, [rsp+gprsize+32*0] ; tmp3
psubw m12, m3, m1 ; out12
paddw m3, m1 ; out3
ret
INV_TXFM_16X16_FN adst, dct
INV_TXFM_16X16_FN adst, adst
INV_TXFM_16X16_FN adst, flipadst
cglobal iadst_16x16_internal, 0, 5, 16, 32*3, dst, stride, c, eob, tx2
ITX_16X16_LOAD_COEFS
call .main
vpbroadcastd m1, [o(pw_8192)]
REPX {pmulhrsw x, m1}, m0, m2, m4, m6, m8, m10, m12, m14
vextracti128 [rsp+16*5], m8, 1
mova [rsp+16*1], xm8
pxor m8, m8
psubw m1, m8, m1
jmp m(idct_16x16_internal).pass1_end2
ALIGN function_align
.pass2:
call .main
vpbroadcastd m1, [o(pw_2048)]
REPX {pmulhrsw x, m1}, m0, m2, m4, m6, m8, m10, m12, m14
mova [rsp+32*0], m6
pxor m6, m6
psubw m1, m6, m1
jmp m(idct_16x16_internal).end2
ALIGN function_align
.main:
vpbroadcastd m15, [o(pd_2048)]
mova [rsp+gprsize+32*1], m0
mova [rsp+gprsize+32*2], m4
ITX_MULSUB_2W 13, 2, 0, 4, 15, 995, 3973 ; t3, t2
ITX_MULSUB_2W 9, 6, 0, 4, 15, 2440, 3290 ; t7, t6
ITX_MULSUB_2W 5, 10, 0, 4, 15, 3513, 2106 ; t11, t10
ITX_MULSUB_2W 1, 14, 0, 4, 15, 4052, 601 ; t15, t14
psubw m0, m2, m10 ; t10a
paddw m2, m10 ; t2a
psubw m10, m13, m5 ; t11a
paddw m13, m5 ; t3a
psubw m5, m6, m14 ; t14a
paddw m6, m14 ; t6a
psubw m14, m9, m1 ; t15a
paddw m9, m1 ; t7a
ITX_MULSUB_2W 0, 10, 1, 4, 15, 3406, 2276 ; t11, t10
ITX_MULSUB_2W 14, 5, 1, 4, 15, 2276, 3406 ; t14, t15
psubw m1, m10, m14 ; t14a
paddw m10, m14 ; t10a
psubw m14, m0, m5 ; t15a
paddw m0, m5 ; t11a
psubw m5, m2, m6 ; t6
paddw m2, m6 ; t2
psubw m6, m13, m9 ; t7
paddw m13, m9 ; t3
ITX_MULSUB_2W 6, 5, 4, 9, 15, 3784, 1567 ; t6a, t7a
ITX_MULSUB_2W 14, 1, 4, 9, 15, 3784, 1567 ; t14, t15
mova m9, [rsp+gprsize+32*0] ; in15
mova [rsp+gprsize+32*0], m10 ; t10a
mova m4, [rsp+gprsize+32*1] ; in0
mova [rsp+gprsize+32*1], m6 ; t6a
mova m6, [rsp+gprsize+32*2] ; in4
mova [rsp+gprsize+32*2], m2 ; t2
ITX_MULSUB_2W 9, 4, 2, 10, 15, 201, 4091 ; t1, t0
ITX_MULSUB_2W 11, 6, 2, 10, 15, 1751, 3703 ; t5, t4
ITX_MULSUB_2W 7, 8, 2, 10, 15, 3035, 2751 ; t9, t8
ITX_MULSUB_2W 3, 12, 2, 10, 15, 3857, 1380 ; t13, t12
psubw m10, m4, m8 ; t8a
paddw m8, m4 ; t0a
psubw m4, m9, m7 ; t9a
paddw m9, m7 ; t1a
psubw m7, m6, m12 ; t12a
paddw m6, m12 ; t4a
psubw m12, m11, m3 ; t13a
paddw m11, m3 ; t5a
ITX_MULSUB_2W 10, 4, 2, 3, 15, 799, 4017 ; t9, t8
ITX_MULSUB_2W 12, 7, 2, 3, 15, 4017, 799 ; t12, t13
psubw m3, m9, m11 ; t5
paddw m9, m11 ; t1
psubw m11, m4, m12 ; t12a
paddw m4, m12 ; t8a
paddw m12, m8, m6 ; t0
psubw m8, m6 ; t4
paddw m6, m10, m7 ; t9a
psubw m10, m7 ; t13a
ITX_MULSUB_2W 8, 3, 2, 7, 15, 1567, 3784 ; t5a, t4a
ITX_MULSUB_2W 11, 10, 2, 7, 15, 1567, 3784 ; t13, t12
mova m7, [rsp+gprsize+32*0] ; t10a
mova m2, [rsp+gprsize+32*1] ; t6a
paddw m15, m9, m13 ; -out15
psubw m9, m13 ; t3a
paddw m13, m11, m1 ; -out13
psubw m11, m1 ; t15a
psubw m1, m4, m7 ; t10
paddw m7, m4 ; -out1
psubw m4, m3, m2 ; t6
paddw m3, m2 ; -out3
paddw m2, m10, m14 ; out2
psubw m10, m14 ; t14a
paddw m14, m6, m0 ; out14
psubw m6, m0 ; t11
mova m0, [rsp+gprsize+32*2] ; t2
mova [rsp+gprsize+32*1], m7
psubw m7, m12, m0 ; t2a
paddw m0, m12 ; out0
paddw m12, m8, m5 ; out12
psubw m8, m5 ; t7
paddw m5, m10, m11 ; -out5
psubw m10, m11 ; out10
psubw m11, m4, m8 ; -out11
paddw m4, m8 ; out4
psubw m8, m7, m9 ; out8
paddw m7, m9 ; -out7
psubw m9, m1, m6 ; -out9
paddw m6, m1 ; out6
vpbroadcastd m1, [o(pw_2896x8)]
REPX {pmulhrsw x, m1}, m4, m5, m6, m7, m8, m9, m10, m11
ret
INV_TXFM_16X16_FN flipadst, dct
INV_TXFM_16X16_FN flipadst, adst
INV_TXFM_16X16_FN flipadst, flipadst
cglobal iflipadst_16x16_internal, 0, 5, 16, 32*3, dst, stride, c, eob, tx2
ITX_16X16_LOAD_COEFS
call m(iadst_16x16_internal).main
vpbroadcastd m1, [o(pw_8192)]
pmulhrsw m6, m1
mova [rsp+32*2], m6
pmulhrsw m6, m1, m4
pmulhrsw m4, m1, m10
pmulhrsw m10, m1, m12
pmulhrsw m12, m1, m2
pmulhrsw m2, m1, m8
pmulhrsw m8, m1, m14
pmulhrsw m14, m1, m0
pxor m0, m0
psubw m0, m1
REPX {pmulhrsw x, m0}, m3, m5, m7, m11, m15
pmulhrsw m1, m0, m9
pmulhrsw m9, m0, m13
pmulhrsw m0, [rsp+32*1]
mova [rsp+16*0], xm15
mova [rsp+16*1], xm7
vperm2i128 m15, m15, m7, 0x31
vinserti128 m7, m2, xm14, 1
vperm2i128 m14, m2, m14, 0x31
vinserti128 m2, m9, xm5, 1
vperm2i128 m9, m9, m5, 0x31
vinserti128 m5, m4, xm12, 1
vperm2i128 m12, m4, m12, 0x31
vinserti128 m4, m11, xm3, 1
vperm2i128 m11, m11, m3, 0x31
vinserti128 m3, m10, xm6, 1
vperm2i128 m10, m10, m6, 0x31
vinserti128 m6, m1, xm0, 1
vperm2i128 m13, m1, m0, 0x31
vinserti128 m1, m8, [rsp+32*2], 1
vperm2i128 m8, m8, [rsp+32*2], 0x31
jmp m(idct_16x16_internal).pass1_end3
.pass2:
call m(iadst_16x16_internal).main
vpbroadcastd m1, [o(pw_2048)]
pmulhrsw m0, m1
pmulhrsw m8, m1
mova [rsp+32*0], m0
mova [rsp+32*2], m8
pxor m0, m0
psubw m0, m1
pmulhrsw m8, m0, m7
pmulhrsw m7, m0, m9
pmulhrsw m9, m1, m6
pmulhrsw m6, m1, m10
pmulhrsw m10, m0, m5
pmulhrsw m5, m0, m11
pmulhrsw m11, m1, m4
pmulhrsw m4, m1, m12
pmulhrsw m12, m0, m3
pmulhrsw m3, m0, m13
pmulhrsw m13, m1, m2
pmulhrsw m1, m14
pmulhrsw m14, m0, [rsp+32*1]
pmulhrsw m0, m15
lea r3, [strideq*3]
WRITE_16X2 0, 1, 2, 0, strideq*0, strideq*1
mova m15, [rsp+32*0]
WRITE_16X2 3, 4, 0, 1, strideq*2, r3
lea dstq, [dstq+strideq*4]
WRITE_16X2 5, 6, 0, 1, strideq*0, strideq*1
WRITE_16X2 7, [rsp+32*2], 0, 1, strideq*2, r3
jmp m(idct_16x16_internal).end3
INV_TXFM_16X16_FN identity, dct, 15
INV_TXFM_16X16_FN identity, identity
cglobal iidentity_16x16_internal, 0, 5, 16, 32*3, dst, stride, c, eob, tx2
mova xm0, [cq+16*0]
mova xm15, [cq+16*1]
mova xm1, [cq+16*2]
mova xm8, [cq+16*3]
mova xm2, [cq+16*4]
mova xm9, [cq+16*5]
mova xm3, [cq+16*6]
mova xm10, [cq+16*7]
add cq, 16*16
vinserti128 m0, m0, [cq+16*0], 1
vinserti128 m15, m15, [cq+16*1], 1
mova xm4, [cq-16*8]
mova xm11, [cq-16*7]
vinserti128 m1, m1, [cq+16*2], 1
vinserti128 m8, m8, [cq+16*3], 1
mova xm5, [cq-16*6]
mova xm12, [cq-16*5]
vinserti128 m2, m2, [cq+16*4], 1
vinserti128 m9, m9, [cq+16*5], 1
mova xm6, [cq-16*4]
mova xm13, [cq-16*3]
vinserti128 m3, m3, [cq+16*6], 1
vinserti128 m10, m10, [cq+16*7], 1
mova xm7, [cq-16*2]
mova xm14, [cq-16*1]
vinserti128 m4, m4, [cq+16*8], 1
vinserti128 m11, m11, [cq+16*9], 1
vinserti128 m5, m5, [cq+16*10], 1
vinserti128 m12, m12, [cq+16*11], 1
vinserti128 m6, m6, [cq+16*12], 1
vinserti128 m13, m13, [cq+16*13], 1
vinserti128 m7, m7, [cq+16*14], 1
vinserti128 m14, m14, [cq+16*15], 1
REPX {psllw x, 2 }, m0, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14, m15
mova [rsp], m0
vpbroadcastd m0, [o(pw_5793x4)]
REPX {pmulhrsw x, m0}, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14, m15
pmulhrsw m0, [rsp]
mova [rsp], m1
vpbroadcastd m1, [o(pw_8192)]
REPX {pmulhrsw x, m1}, m0, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14, m15
pmulhrsw m1, [rsp]
mova [rsp], m0
jmp m(idct_16x16_internal).pass1_end3
ALIGN function_align
.pass2:
vpbroadcastd m15, [o(pw_5793x4)]
REPX {psllw x, 2 }, m0, m1, m2, m3, m4, m5, m6, m7
REPX {pmulhrsw x, m15}, m0, m1, m2, m3, m4, m5, m6, m7
mova [rsp+32*1], m1
mova m1, [rsp+32*0]
REPX {psllw x, 2 }, m8, m9, m10, m11, m12, m13, m14, m1
REPX {pmulhrsw x, m15}, m8, m9, m10, m11, m12, m13, m14
pmulhrsw m15, m1
jmp m(idct_16x16_internal).end
%define o_base iadst4_dconly2a + 128
%macro LOAD_8ROWS 2-3 0 ; src, stride, is_rect2
%if %3
vpbroadcastd m15, [o(pw_2896x8)]
pmulhrsw m0, m15, [%1+%2*0]
pmulhrsw m1, m15, [%1+%2*1]
pmulhrsw m2, m15, [%1+%2*2]
pmulhrsw m3, m15, [%1+%2*3]
pmulhrsw m4, m15, [%1+%2*4]
pmulhrsw m5, m15, [%1+%2*5]
pmulhrsw m6, m15, [%1+%2*6]
pmulhrsw m7, m15, [%1+%2*7]
%else
mova m0, [%1+%2*0]
mova m1, [%1+%2*1]
mova m2, [%1+%2*2]
mova m3, [%1+%2*3]
mova m4, [%1+%2*4]
mova m5, [%1+%2*5]
mova m6, [%1+%2*6]
mova m7, [%1+%2*7]
%endif
%endmacro
%macro LOAD_8ROWS_H 2-3 0 ; src, stride, is_rect2
%if %3
%if %3 == 1
vpbroadcastd m15, [o(pw_2896x8)]
%endif
pmulhrsw m8, m15, [%1+%2*0]
pmulhrsw m9, m15, [%1+%2*1]
pmulhrsw m10, m15, [%1+%2*2]
pmulhrsw m11, m15, [%1+%2*3]
pmulhrsw m12, m15, [%1+%2*4]
pmulhrsw m13, m15, [%1+%2*5]
pmulhrsw m14, m15, [%1+%2*6]
pmulhrsw m15, [%1+%2*7]
%else
mova m8, [%1+%2*0]
mova m9, [%1+%2*1]
mova m10, [%1+%2*2]
mova m11, [%1+%2*3]
mova m12, [%1+%2*4]
mova m13, [%1+%2*5]
mova m14, [%1+%2*6]
mova m15, [%1+%2*7]
%endif
%endmacro
cglobal inv_txfm_add_dct_dct_8x32, 4, 4, 0, dst, stride, c, eob
lea rax, [o_base]
test eobd, eobd
jz .dconly
PROLOGUE 0, 4, 16, 32*3, dst, stride, c, eob
%undef cmp
cmp eobd, 106
jle .fast
LOAD_8ROWS cq+32*1, 32*2
call m(idct_16x8_internal).main
vperm2i128 m11, m0, m4, 0x31
vinserti128 m0, m0, xm4, 1
vperm2i128 m4, m1, m5, 0x31
vinserti128 m1, m1, xm5, 1
vperm2i128 m5, m2, m6, 0x31
vinserti128 m2, m2, xm6, 1
vperm2i128 m6, m3, m7, 0x31
vinserti128 m3, m3, xm7, 1
pxor m7, m7
REPX {mova [cq+32*x], m7}, 1, 3, 5, 7, 9, 11, 13, 15
punpckhwd m7, m0, m1
punpcklwd m0, m1
punpckhwd m1, m2, m3
punpcklwd m2, m3
punpcklwd m3, m11, m4
punpckhwd m11, m4
punpckhwd m4, m5, m6
punpcklwd m5, m6
punpckhdq m6, m0, m2
punpckldq m0, m2
punpckldq m2, m3, m5
punpckhdq m3, m5
punpckhdq m5, m11, m4
punpckldq m11, m4
punpckldq m4, m7, m1
punpckhdq m7, m1
punpckhqdq m12, m6, m0
punpcklqdq m0, m6 ; out4
punpckhqdq m13, m7, m4
punpcklqdq m4, m7 ; out5
punpckhqdq m14, m3, m2
punpcklqdq m2, m3 ; out6
punpckhqdq m15, m5, m11
punpcklqdq m11, m5 ; out7
mova [rsp+32*0], m0
mova [rsp+32*1], m4
mova [rsp+32*2], m2
.fast:
LOAD_8ROWS cq+32*0, 32*2
call m(idct_16x8_internal).main
vperm2i128 m8, m0, m4, 0x31
vinserti128 m0, m0, xm4, 1
vperm2i128 m4, m1, m5, 0x31
vinserti128 m1, m1, xm5, 1
vperm2i128 m5, m2, m6, 0x31
vinserti128 m2, m2, xm6, 1
vperm2i128 m6, m3, m7, 0x31
vinserti128 m3, m3, xm7, 1
vpbroadcastd m9, [o(pw_8192)]
pxor m7, m7
REPX {mova [cq+32*x], m7}, 0, 2, 4, 6, 8, 10, 12, 14
punpckhwd m7, m0, m1
punpcklwd m0, m1
punpckhwd m1, m2, m3
punpcklwd m2, m3
punpckhwd m3, m8, m4
punpcklwd m8, m4
punpckhwd m4, m5, m6
punpcklwd m5, m6
punpckhdq m6, m0, m2
punpckldq m0, m2
punpckldq m2, m8, m5
punpckhdq m8, m5
punpckhdq m5, m3, m4
punpckldq m3, m4
punpckhdq m4, m7, m1
punpckldq m7, m1
punpcklqdq m1, m7, m4
punpckhqdq m7, m4 ; out9
punpckhqdq m4, m2, m8 ; out10
punpcklqdq m2, m8
punpckhqdq m8, m3, m5
punpcklqdq m3, m5
punpckhqdq m5, m0, m6 ; out8
punpcklqdq m0, m6
REPX {pmulhrsw x, m9}, m0, m1, m2, m3, m4, m5, m7
cmp eobd, 106
jg .full
mova [rsp+32*0], m5
mova [rsp+32*1], m7
mova [rsp+32*2], m4
pmulhrsw m11, m9, m8
pxor m4, m4
REPX {mova x, m4}, m5, m6, m7
call .main_fast
jmp .pass2
.dconly:
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_8192)]
mov [cq], eobd
pmulhrsw xm0, xm2
psrlw xm2, 2 ; pw_2048
pmulhrsw xm0, xm1
pmulhrsw xm0, xm2
vpbroadcastw m0, xm0
mov r2d, 8
jmp m(inv_txfm_add_dct_dct_8x8).end2
.full:
REPX {pmulhrsw x, m9}, m12, m13, m14, m15
pmulhrsw m6, m9, [rsp+32*2]
mova [rsp+32*2], m4
pmulhrsw m4, m9, [rsp+32*0]
mova [rsp+32*0], m5
pmulhrsw m5, m9, [rsp+32*1]
mova [rsp+32*1], m7
pmulhrsw m7, m9, m11
pmulhrsw m11, m9, m8
call .main
.pass2:
vpbroadcastd m12, [o(pw_2048)]
REPX {pmulhrsw x, m12}, m0, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m13, m14, m15
pmulhrsw m12, [rsp]
REPX {vpermq x, x, q3120}, m0, m2, m4, m6, m8, m10, m12, m14
REPX {vpermq x, x, q2031}, m1, m3, m5, m7, m9, m11, m13, m15
mova [rsp+32*0], m4
mova [rsp+32*1], m6
lea r3, [strideq*3]
WRITE_8X4 0, 1, 4, 6
lea dstq, [dstq+strideq*4]
WRITE_8X4 2, 3, 4, 6
lea dstq, [dstq+strideq*4]
WRITE_8X4 [rsp+32*0], 5, 4, 6
lea dstq, [dstq+strideq*4]
WRITE_8X4 [rsp+32*1], 7, 4, 6
lea dstq, [dstq+strideq*4]
WRITE_8X4 8, 9, 4, 6
lea dstq, [dstq+strideq*4]
WRITE_8X4 10, 11, 4, 6
lea dstq, [dstq+strideq*4]
WRITE_8X4 12, 13, 4, 6
lea dstq, [dstq+strideq*4]
WRITE_8X4 14, 15, 4, 6
RET
ALIGN function_align
.main_fast: ; bottom half is zero
call m(idct_8x16_internal).main
mova m8, [rsp+gprsize+0*32]
mova [rsp+gprsize+0*32], m0
mova m9, [rsp+gprsize+1*32]
mova [rsp+gprsize+1*32], m1
mova m0, [rsp+gprsize+2*32]
mova [rsp+gprsize+2*32], m6
punpcklwd m1, m8, m8
punpckhwd m8, m8
punpcklwd m15, m9, m9
punpckhwd m9, m9
punpcklwd m14, m0, m0
punpckhwd m0, m0
punpcklwd m13, m11, m11
punpckhwd m11, m11
ITX_MULHRSW_SHL3 1, 6, 201, 4091 ; t16a, t31a
ITX_MULHRSW_SHL3 8, 6, m601, 4052 ; t23a, t24a
ITX_MULHRSW_SHL3 15, 6, 995, 3973 ; t20a, t27a
ITX_MULHRSW_SHL3 9, 6, m1380, 3857 ; t19a, t28a
ITX_MULHRSW_SHL3 14, 6, 1751, 3703 ; t18a, t29a
ITX_MULHRSW_SHL3 0, 6, m2106, 3513 ; t21a, t26a
ITX_MULHRSW_SHL3 13, 6, 2440, 3290 ; t22a, t25a
ITX_MULHRSW_SHL3 11, 6, m2751, 3035 ; t17a, t30a
jmp .main2
ALIGN function_align
.main:
call m(idct_8x16_internal).main
mova m8, [rsp+gprsize+0*32]
mova [rsp+gprsize+0*32], m0
mova m9, [rsp+gprsize+1*32]
mova [rsp+gprsize+1*32], m1
mova m0, [rsp+gprsize+2*32]
mova [rsp+gprsize+2*32], m6
punpcklwd m1, m15, m8 ; in31 in1
punpckhwd m8, m15 ; in3 in29
punpcklwd m15, m14, m9 ; in27 in5
punpckhwd m9, m14 ; in7 in25
punpcklwd m14, m13, m0 ; in23 in9
punpckhwd m0, m13 ; in11 in21
punpcklwd m13, m12, m11 ; in19 in13
punpckhwd m11, m12 ; in15 in17
ITX_MUL2X_PACK 1, 6, 12, 10, 201, 4091, 3 ; t16a, t31a
ITX_MUL2X_PACK 8, 6, 12, 10, 4052, 601, 3 ; t23a, t24a
ITX_MUL2X_PACK 15, 6, 12, 10, 995, 3973, 3 ; t20a, t27a
ITX_MUL2X_PACK 9, 6, 12, 10, 3857, 1380, 3 ; t19a, t28a
ITX_MUL2X_PACK 14, 6, 12, 10, 1751, 3703, 3 ; t18a, t29a
ITX_MUL2X_PACK 0, 6, 12, 10, 3513, 2106, 3 ; t21a, t26a
ITX_MUL2X_PACK 13, 6, 12, 10, 2440, 3290, 3 ; t22a, t25a
ITX_MUL2X_PACK 11, 6, 12, 10, 3035, 2751, 3 ; t17a, t30a
.main2:
psubw m6, m1, m11 ; t17 t30
paddw m1, m11 ; t16 t31
psubw m11, m9, m14 ; t18 t29
paddw m9, m14 ; t19 t28
psubw m14, m15, m0 ; t21 t26
paddw m15, m0 ; t20 t27
psubw m0, m8, m13 ; t22 t25
paddw m8, m13 ; t23 t24
ITX_MUL2X_PACK 6, 12, 13, 10, 799, 4017, 3 ; t17a t30a
ITX_MUL2X_PACK 11, 12, 13, 10, m4017, 799, 3 ; t18a t29a
ITX_MUL2X_PACK 14, 12, 13, 10, 3406, 2276, 3 ; t21a t26a
ITX_MUL2X_PACK 0, 12, 13, 10, m2276, 3406, 3 ; t22a t25a
psubw m13, m1, m9 ; t19a t28a
paddw m1, m9 ; t16a t31a
psubw m9, m8, m15 ; t20a t27a
paddw m8, m15 ; t23a t24a
psubw m15, m6, m11 ; t18 t29
paddw m6, m11 ; t17 t30
psubw m11, m0, m14 ; t21 t26
paddw m0, m14 ; t22 t25
ITX_MUL2X_PACK 15, 12, 14, 10, 1567, 3784, 1 ; t18a t29a
ITX_MUL2X_PACK 13, 12, 14, 10, 1567, 3784, 1 ; t19 t28
ITX_MUL2X_PACK 9, 12, 14, 10, m3784, 1567, 1 ; t20 t27
ITX_MUL2X_PACK 11, 12, 14, 10, m3784, 1567, 1 ; t21a t26a
vbroadcasti128 m12, [o(deint_shuf)]
REPX {pshufb x, m12}, m0, m1, m6, m8
psubw m14, m1, m8 ; t23 t24
paddw m1, m8 ; t16 t31
psubw m8, m6, m0 ; t22a t25a
paddw m6, m0 ; t17a t30a
psubw m0, m15, m11 ; t21 t26
paddw m15, m11 ; t18 t29
psubw m11, m13, m9 ; t20a t27a
paddw m13, m9 ; t19a t28a
vpbroadcastd m12, [o(pw_2896x8)]
punpcklqdq m9, m11, m0 ; t20a t21
punpckhqdq m11, m0 ; t27a t26
punpcklqdq m0, m14, m8 ; t23 t22a
punpckhqdq m14, m8 ; t24 t25a
psubw m8, m11, m9 ; t20 t21a
paddw m11, m9 ; t27 t26a
psubw m9, m14, m0 ; t23a t22
paddw m14, m0 ; t24a t25
REPX {pmulhrsw x, m12}, m8, m9, m14, m11
punpcklqdq m0, m1, m6 ; t16 t17a
punpckhqdq m1, m6 ; t31 t30a
psubw m10, m5, m8 ; out20 out21
paddw m5, m8 ; out11 out10
psubw m6, m3, m14 ; out24 out25
paddw m3, m14 ; out7 out6
psubw m8, m7, m0 ; out16 out17
paddw m7, m0 ; out15 out14
mova m0, [rsp+gprsize+0*32]
punpcklqdq m12, m13, m15 ; t19a t18
punpckhqdq m13, m15 ; t28a t29
psubw m15, m0, m1 ; out31 out30
paddw m0, m1 ; out0 out1
mova m1, [rsp+gprsize+1*32]
mova [rsp+gprsize+0*32], m6
mova m6, [rsp+gprsize+2*32]
psubw m14, m1, m13 ; out28 out29
paddw m1, m13 ; out3 out2
psubw m13, m2, m11 ; out27 out26
paddw m2, m11 ; out4 out5
psubw m11, m4, m9 ; out23 out22
paddw m4, m9 ; out8 out9
psubw m9, m6, m12 ; out19 out18
paddw m6, m12 ; out12 out13
ret
%macro LOAD_PACKED_16X2 4 ; dst, tmp, row[1-2]
vbroadcasti128 m%1, [cq+16*%3]
vbroadcasti128 m%2, [cq+16*%4]
shufpd m%1, m%1, m%2, 0x0c
%endmacro
cglobal inv_txfm_add_dct_dct_32x8, 4, 4, 0, dst, stride, c, eob
lea rax, [o_base]
test eobd, eobd
jnz .normal
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_8192)]
mov [cq], eobd
mov r2d, 8
.dconly:
pmulhrsw xm0, xm2
movd xm2, [pw_2048] ; intentionally rip-relative
pmulhrsw xm0, xm1
pmulhrsw xm0, xm2
vpbroadcastw m0, xm0
pxor m3, m3
.dconly_loop:
mova m1, [dstq]
punpckhbw m2, m1, m3
punpcklbw m1, m3
paddw m2, m0
paddw m1, m0
packuswb m1, m2
mova [dstq], m1
add dstq, strideq
dec r2d
jg .dconly_loop
RET
.normal:
PROLOGUE 0, 4, 16, 32*3, dst, stride, c, eob
%undef cmp
LOAD_PACKED_16X2 0, 7, 0, 2 ; in0 in2
LOAD_PACKED_16X2 4, 7, 1, 3 ; in1 in3
LOAD_PACKED_16X2 1, 7, 4, 6 ; in4 in6
LOAD_PACKED_16X2 5, 7, 5, 7 ; in5 in7
pxor m8, m8
REPX {mova [cq+32*x], m8}, 0, 1, 2, 3
add cq, 16*16
LOAD_PACKED_16X2 2, 7, -8, -6 ; in8 in10
LOAD_PACKED_16X2 6, 7, -7, -5 ; in9 in11
LOAD_PACKED_16X2 3, 7, -4, -2 ; in12 in14
LOAD_PACKED_16X2 11, 7, -3, -1 ; in13 in15
REPX {mova [cq+32*x], m8}, -4, -3, -2, -1
mova [rsp+32*0], m4
mova [rsp+32*1], m5
mova [rsp+32*2], m6
cmp eobd, 106
jg .full
pxor m4, m4
REPX {mova x, m4}, m5, m6, m7
call m(inv_txfm_add_dct_dct_8x32).main_fast
jmp .pass2
.full:
LOAD_PACKED_16X2 4, 7, 0, 2 ; in16 in18
LOAD_PACKED_16X2 12, 7, 3, 1 ; in19 in17
LOAD_PACKED_16X2 5, 7, 4, 6 ; in20 in22
LOAD_PACKED_16X2 13, 7, 7, 5 ; in23 in21
REPX {mova [cq+32*x], m8}, 0, 1, 2, 3
add cq, 16*8
LOAD_PACKED_16X2 6, 7, 0, 2 ; in24 in26
LOAD_PACKED_16X2 14, 7, 3, 1 ; in27 in25
LOAD_PACKED_16X2 7, 8, 4, 6 ; in28 in30
LOAD_PACKED_16X2 15, 8, 7, 5 ; in31 in29
pxor m8, m8
REPX {mova [cq+32*x], m8}, 0, 1, 2, 3
call m(inv_txfm_add_dct_dct_8x32).main
.pass2:
vpbroadcastd m12, [o(pw_8192)]
REPX {pmulhrsw x, m12}, m8, m9, m10, m11, m13, m14, m15
mova [rsp+32*1], m9
mova [rsp+32*2], m10
punpckhwd m9, m0, m2
punpcklwd m0, m2
punpckhwd m2, m1, m3
punpcklwd m1, m3
punpcklwd m10, m4, m6
punpckhwd m4, m6
punpcklwd m6, m5, m7
punpckhwd m5, m7
punpckhwd m3, m0, m9
punpcklwd m0, m9
punpckhwd m9, m2, m1
punpcklwd m2, m1
punpcklwd m7, m10, m4
punpckhwd m10, m4
punpcklwd m4, m5, m6
punpckhwd m5, m6
punpckhdq m1, m0, m2
punpckldq m0, m2
punpckldq m2, m3, m9
punpckhdq m3, m9
punpckldq m6, m7, m4
punpckhdq m7, m4
punpckldq m9, m10, m5
punpckhdq m10, m5
REPX {pmulhrsw x, m12}, m0, m1, m2, m3, m6, m7, m9, m10
pmulhrsw m12, [rsp+32*0]
mova [rsp+32*0], m8
vperm2i128 m4, m0, m6, 0x31
vinserti128 m0, m0, xm6, 1
vperm2i128 m5, m1, m7, 0x31
vinserti128 m1, m1, xm7, 1
vperm2i128 m6, m2, m9, 0x31
vinserti128 m2, m2, xm9, 1
vperm2i128 m7, m3, m10, 0x31
vinserti128 m3, m3, xm10, 1
call m(idct_16x8_internal).main
vpbroadcastd m8, [o(pw_2048)]
REPX {pmulhrsw x, m8}, m0, m1, m2, m3, m4, m5, m6, m7
lea r2, [strideq*3]
WRITE_16X2 0, 1, 8, 0, strideq*0, strideq*1
WRITE_16X2 2, 3, 0, 1, strideq*2, r2
lea r3, [dstq+strideq*4]
%define dstq r3
WRITE_16X2 4, 5, 0, 1, strideq*0, strideq*1
WRITE_16X2 6, 7, 0, 1, strideq*2, r2
mova m0, [rsp+32*0]
mova m1, [rsp+32*1]
mova m2, [rsp+32*2]
punpckhwd m7, m0, m2
punpcklwd m0, m2
punpckhwd m2, m1, m11
punpcklwd m1, m11
punpckhwd m4, m12, m14
punpcklwd m12, m14
punpckhwd m5, m13, m15
punpcklwd m13, m15
punpckhwd m3, m0, m7
punpcklwd m0, m7
punpckhwd m9, m2, m1
punpcklwd m2, m1
punpcklwd m7, m12, m4
punpckhwd m12, m4
punpcklwd m4, m5, m13
punpckhwd m5, m13
punpckhdq m1, m0, m2
punpckldq m0, m2
punpckldq m2, m3, m9
punpckhdq m3, m9
punpckldq m6, m7, m4
punpckhdq m7, m4
punpckldq m9, m12, m5
punpckhdq m12, m5
vperm2i128 m4, m0, m6, 0x31
vinserti128 m0, m0, xm6, 1
vperm2i128 m5, m1, m7, 0x31
vinserti128 m1, m1, xm7, 1
vperm2i128 m6, m2, m9, 0x31
vinserti128 m2, m2, xm9, 1
vperm2i128 m7, m3, m12, 0x31
vinserti128 m3, m3, xm12, 1
call m(idct_16x8_internal).main2
vpbroadcastd m8, [o(pw_2048)]
REPX {pmulhrsw x, m8}, m0, m1, m2, m3, m4, m5, m6, m7
add r0, 16
add r3, 16
%define dstq r0
WRITE_16X2 0, 1, 8, 0, strideq*0, strideq*1
WRITE_16X2 2, 3, 0, 1, strideq*2, r2
%define dstq r3
WRITE_16X2 4, 5, 0, 1, strideq*0, strideq*1
WRITE_16X2 6, 7, 0, 1, strideq*2, r2
RET
cglobal inv_txfm_add_identity_identity_8x32, 4, 5, 11, dst, stride, c, eob
vpbroadcastd m9, [pw_5]
lea r4, [strideq*3]
sub eobd, 107 ; loop_iterations = 1 + (eobd >= 107)
.loop:
mova xm0, [cq+16* 0]
mova xm1, [cq+16* 4]
vinserti128 m0, m0, [cq+16* 1], 1
vinserti128 m1, m1, [cq+16* 5], 1
pxor m8, m8
mova [cq+32*0], m8
mova [cq+32*2], m8
add cq, 16*16
mova xm2, [cq-16* 8]
mova xm3, [cq-16* 4]
vinserti128 m2, m2, [cq-16* 7], 1
vinserti128 m3, m3, [cq-16* 3], 1
mova xm4, [cq+16* 0]
mova xm5, [cq+16* 4]
vinserti128 m4, m4, [cq+16* 1], 1
vinserti128 m5, m5, [cq+16* 5], 1
mova xm6, [cq+16* 8]
mova xm7, [cq+16*12]
vinserti128 m6, m6, [cq+16* 9], 1
vinserti128 m7, m7, [cq+16*13], 1
REPX {mova [cq+32*x], m8}, -4, -2, 0, 2, 4, 6
REPX {paddw x, m9}, m0, m1, m2, m3, m4, m5, m6, m7
call .transpose8x8
REPX {psraw x, 3 }, m0, m1, m2, m3, m4, m5, m6, m7
WRITE_8X4 0, 4, 8, 10, strideq*8, strideq*4, r4*4
add dstq, strideq
WRITE_8X4 1, 5, 0, 4, strideq*8, strideq*4, r4*4
add dstq, strideq
WRITE_8X4 2, 6, 0, 4, strideq*8, strideq*4, r4*4
add dstq, strideq
WRITE_8X4 3, 7, 0, 4, strideq*8, strideq*4, r4*4
add dstq, strideq
sub cq, 16*16-32
lea dstq, [dstq+r4*4]
add eobd, 0x80000000
jnc .loop
RET
ALIGN function_align
.transpose8x8:
punpckhwd m8, m4, m5
punpcklwd m4, m5
punpckhwd m5, m0, m1
punpcklwd m0, m1
punpckhwd m1, m6, m7
punpcklwd m6, m7
punpckhwd m7, m2, m3
punpcklwd m2, m3
punpckhdq m3, m0, m2
punpckldq m0, m2
punpckldq m2, m4, m6
punpckhdq m4, m6
punpckhdq m6, m5, m7
punpckldq m5, m7
punpckldq m7, m8, m1
punpckhdq m8, m1
punpckhqdq m1, m0, m2
punpcklqdq m0, m2
punpcklqdq m2, m3, m4
punpckhqdq m3, m4
punpcklqdq m4, m5, m7
punpckhqdq m5, m7
punpckhqdq m7, m6, m8
punpcklqdq m6, m8
ret
cglobal inv_txfm_add_identity_identity_32x8, 4, 6, 10, dst, stride, c, eob
add cq, 16*8
vpbroadcastd m9, [pw_4096]
lea r4, [strideq*3]
lea r5, [dstq+strideq*4]
sub eobd, 107
.loop:
mova xm0, [cq-16*8]
mova xm1, [cq-16*7]
vinserti128 m0, m0, [cq+16*0], 1
vinserti128 m1, m1, [cq+16*1], 1
mova xm2, [cq-16*6]
mova xm3, [cq-16*5]
vinserti128 m2, m2, [cq+16*2], 1
vinserti128 m3, m3, [cq+16*3], 1
mova xm4, [cq-16*4]
mova xm5, [cq-16*3]
vinserti128 m4, m4, [cq+16*4], 1
vinserti128 m5, m5, [cq+16*5], 1
mova xm6, [cq-16*2]
mova xm7, [cq-16*1]
vinserti128 m6, m6, [cq+16*6], 1
vinserti128 m7, m7, [cq+16*7], 1
pxor m8, m8
REPX {mova [cq+32*x], m8}, -4, -3, -2, -1, 0, 1, 2, 3
call m(inv_txfm_add_identity_identity_8x32).transpose8x8
REPX {pmulhrsw x, m9}, m0, m1, m2, m3, m4, m5, m6, m7
WRITE_16X2 0, 1, 8, 0, strideq*0, strideq*1
WRITE_16X2 2, 3, 0, 1, strideq*2, r4
%define dstq r5
WRITE_16X2 4, 5, 0, 1, strideq*0, strideq*1
WRITE_16X2 6, 7, 0, 1, strideq*2, r4
add cq, 16*16
add r0, 16
add r5, 16
add eobd, 0x80000000
jnc .loop
RET
%define o_base pw_5 + 128
%macro LOAD_16ROWS 2-4 0, 1 ; src, stride, is_rect2, zero_coefs
%if %3
vpbroadcastd m15, [o(pw_2896x8)]
pmulhrsw m0, m15, [%1+%2* 0]
pmulhrsw m1, m15, [%1+%2* 1]
pmulhrsw m2, m15, [%1+%2* 2]
pmulhrsw m3, m15, [%1+%2* 3]
pmulhrsw m4, m15, [%1+%2* 4]
pmulhrsw m5, m15, [%1+%2* 5]
pmulhrsw m6, m15, [%1+%2* 6]
pmulhrsw m7, m15, [%1+%2* 7]
pmulhrsw m8, m15, [%1+%2* 8]
pmulhrsw m9, m15, [%1+%2* 9]
pmulhrsw m10, m15, [%1+%2*10]
pmulhrsw m11, m15, [%1+%2*11]
pmulhrsw m12, m15, [%1+%2*12]
pmulhrsw m13, m15, [%1+%2*13]
pmulhrsw m14, m15, [%1+%2*14]
pmulhrsw m15, [%1+%2*15]
%else
mova m0, [%1+%2* 0]
mova m1, [%1+%2* 1]
mova m2, [%1+%2* 2]
mova m3, [%1+%2* 3]
mova m4, [%1+%2* 4]
mova m5, [%1+%2* 5]
mova m6, [%1+%2* 6]
mova m7, [%1+%2* 7]
mova m8, [%1+%2* 8]
mova m9, [%1+%2* 9]
mova m10, [%1+%2*10]
mova m11, [%1+%2*11]
mova m12, [%1+%2*12]
mova m13, [%1+%2*13]
mova m14, [%1+%2*14]
mova m15, [%1+%2*15]
%endif
mova [rsp], m15
%if %4
pxor m15, m15
REPX {mova [%1+%2*x], m15}, 0, 1, 2, 3, 4, 5, 6, 7, \
8, 9, 10, 11, 12, 13, 14, 15
%endif
%endmacro
%macro IDCT32_PASS2_END 7 ; coefs[1-2], tmp[1-2], rnd, offset[1-2]
mova m%4, [%2]
paddw m%3, m%1, m%4
psubw m%1, m%4
pmovzxbw m%4, [dstq+%6]
pmulhrsw m%3, m%5
pmulhrsw m%1, m%5
paddw m%3, m%4
pmovzxbw m%4, [r2+%7]
paddw m%1, m%4
packuswb m%3, m%1
vpermq m%3, m%3, q3120
mova [dstq+%6], xm%3
vextracti128 [r2+%7], m%3, 1
%endmacro
cglobal inv_txfm_add_dct_dct_16x32, 4, 4, 0, dst, stride, c, eob
lea rax, [o_base]
test eobd, eobd
jz .dconly
PROLOGUE 0, 8, 16, 32*35, dst, stride, c, eob, tmp1, tmp2, \
base, tmp3
%undef cmp
LOAD_16ROWS cq, 64, 1
call m(idct_16x16_internal).main
lea tmp1q, [rsp+32*7]
lea tmp2q, [tmp1q+32*8]
lea tmp3q, [tmp1q+32*16]
mova m1, [rsp+32*1]
mova [rsp+32*0], m6
mova [rsp+32*1], m7
vpbroadcastd m7, [o(pw_16384)]
call .transpose_2x8x8_round
mova m15, [rsp+32*0]
mova [tmp3q-32*4+ 0], xm0
vextracti128 [tmp3q+32*0+ 0], m0, 1
mova [tmp3q-32*3+ 0], xm2
vextracti128 [tmp3q+32*1+ 0], m2, 1
mova [tmp3q-32*2+ 0], xm4
vextracti128 [tmp3q+32*2+ 0], m4, 1
mova [tmp3q-32*1+ 0], xm6
vextracti128 [tmp3q+32*3+ 0], m6, 1
mova [tmp3q-32*4+16], xm8
vextracti128 [tmp3q+32*0+16], m8, 1
mova [tmp3q-32*3+16], xm10
vextracti128 [tmp3q+32*1+16], m10, 1
mova [tmp3q-32*2+16], xm12
vextracti128 [tmp3q+32*2+16], m12, 1
mova [tmp3q-32*1+16], xm14
vextracti128 [tmp3q+32*3+16], m14, 1
cmp eobd, 150
jg .full
vinserti128 m0, m1, xm9, 1
vperm2i128 m4, m1, m9, 0x31
vinserti128 m2, m5, xm13, 1
vperm2i128 m6, m5, m13, 0x31
vinserti128 m1, m3, xm11, 1
vperm2i128 m5, m3, m11, 0x31
vinserti128 m3, m7, xm15, 1
vperm2i128 m7, m7, m15, 0x31
call .main_oddhalf_fast
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14, m15
jmp .idct16
.dconly:
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_16384)]
mov [cq], eobd
pmulhrsw xm0, xm1
mov r2d, 16
jmp m(inv_txfm_add_dct_dct_16x4).dconly
.full:
mova [tmp1q-32*4], m1
mova [tmp1q-32*3], m3
mova [tmp1q-32*2], m5
mova [tmp1q-32*1], m7
mova [tmp1q+32*0], m9
mova [tmp1q+32*1], m11
mova [tmp1q+32*2], m13
mova [tmp1q+32*3], m15
LOAD_16ROWS cq+32, 64, 1
call m(idct_16x16_internal).main
lea r2, [tmp3q+32*8]
mova m1, [rsp+32*1]
mova [rsp+32*0], m6
mova [rsp+32*1], m7
vpbroadcastd m7, [o(pw_16384)]
call .transpose_2x8x8_round
mova m15, [rsp+32*0]
mova [r2-32*4+ 0], xm0
vextracti128 [r2+32*0+ 0], m0, 1
mova [r2-32*3+ 0], xm2
vextracti128 [r2+32*1+ 0], m2, 1
mova [r2-32*2+ 0], xm4
vextracti128 [r2+32*2+ 0], m4, 1
mova [r2-32*1+ 0], xm6
vextracti128 [r2+32*3+ 0], m6, 1
mova [r2-32*4+16], xm8
vextracti128 [r2+32*0+16], m8, 1
mova [r2-32*3+16], xm10
vextracti128 [r2+32*1+16], m10, 1
mova [r2-32*2+16], xm12
vextracti128 [r2+32*2+16], m12, 1
mova [r2-32*1+16], xm14
vextracti128 [r2+32*3+16], m14, 1
vinserti128 m8, m1, xm9, 1
vperm2i128 m12, m1, m9, 0x31
mova xm0, [tmp1q-32*4]
mova xm1, [tmp1q-32*3]
vinserti128 m0, m0, [tmp1q+32*0], 1
vinserti128 m1, m1, [tmp1q+32*1], 1
vinserti128 m10, m5, xm13, 1
vperm2i128 m14, m5, m13, 0x31
mova xm4, [tmp1q-32*4+16]
mova xm5, [tmp1q-32*3+16]
vinserti128 m4, m4, [tmp1q+32*0+16], 1
vinserti128 m5, m5, [tmp1q+32*1+16], 1
vinserti128 m9, m3, xm11, 1
vperm2i128 m13, m3, m11, 0x31
mova xm2, [tmp1q-32*2]
mova xm3, [tmp1q-32*1]
vinserti128 m2, m2, [tmp1q+32*2], 1
vinserti128 m3, m3, [tmp1q+32*3], 1
vinserti128 m11, m7, xm15, 1
vperm2i128 m15, m7, m15, 0x31
mova xm6, [tmp1q-32*2+16]
mova xm7, [tmp1q-32*1+16]
vinserti128 m6, m6, [tmp1q+32*2+16], 1
vinserti128 m7, m7, [tmp1q+32*3+16], 1
call .main_oddhalf
LOAD_8ROWS_H r2-32*4, 32
.idct16:
LOAD_8ROWS tmp3q-32*4, 32
mova [rsp], m15
call m(idct_16x16_internal).main
imul r2, strideq, 19
lea r3, [strideq*3]
add r2, dstq
call .pass2_end
RET
ALIGN function_align
.main_oddhalf_fast: ; lower half is zero
mova [rsp+gprsize+32*1], m7
pxor m7, m7
mova [rsp+gprsize+32*0], m7
mova [rsp+gprsize+32*2], m7
vpbroadcastd m11, [o(pw_3703x8)]
vpbroadcastd m7, [o(pw_1751x8)]
vpbroadcastd m12, [o(pw_m1380x8)]
vpbroadcastd m8, [o(pw_3857x8)]
vpbroadcastd m13, [o(pw_3973x8)]
vpbroadcastd m15, [o(pw_995x8)]
pmulhrsw m11, m4 ; t29a
pmulhrsw m4, m7 ; t18a
pmulhrsw m12, m3 ; t19a
pmulhrsw m3, m8 ; t28a
pmulhrsw m13, m2 ; t27a
pmulhrsw m2, m15 ; t20a
vpbroadcastd m10, [o(pw_m2106x8)]
vpbroadcastd m7, [o(pw_3513x8)]
vpbroadcastd m9, [o(pw_3290x8)]
vpbroadcastd m8, [o(pw_2440x8)]
vpbroadcastd m14, [o(pw_m601x8)]
vpbroadcastd m15, [o(pw_4052x8)]
pmulhrsw m10, m5 ; t21a
pmulhrsw m5, m7 ; t26a
pmulhrsw m9, m6 ; t25a
pmulhrsw m6, m8 ; t22a
pmulhrsw m14, m1 ; t23a
pmulhrsw m1, m15 ; t24a
vpbroadcastd m15, [o(pd_2048)]
jmp .main2
ALIGN function_align
.main_oddhalf:
mova [rsp+gprsize+32*0], m15
mova [rsp+gprsize+32*1], m7
mova [rsp+gprsize+32*2], m8
vpbroadcastd m15, [o(pd_2048)]
ITX_MULSUB_2W 4, 11, 7, 8, 15, 1751, 3703 ; t18a, t29a
ITX_MULSUB_2W 12, 3, 7, 8, 15, 3857, 1380 ; t19a, t28a
ITX_MULSUB_2W 2, 13, 7, 8, 15, 995, 3973 ; t20a, t27a
ITX_MULSUB_2W 10, 5, 7, 8, 15, 3513, 2106 ; t21a, t26a
ITX_MULSUB_2W 6, 9, 7, 8, 15, 2440, 3290 ; t22a, t25a
ITX_MULSUB_2W 14, 1, 7, 8, 15, 4052, 601 ; t23a, t24a
.main2:
psubw m7, m12, m4 ; t18
paddw m12, m4 ; t19
psubw m4, m2, m10 ; t21
paddw m2, m10 ; t20
psubw m10, m14, m6 ; t22
paddw m14, m6 ; t23
psubw m6, m1, m9 ; t25
paddw m1, m9 ; t24
psubw m9, m13, m5 ; t26
paddw m13, m5 ; t27
psubw m5, m3, m11 ; t29
paddw m3, m11 ; t28
ITX_MULSUB_2W 5, 7, 8, 11, 15, m4017, 799 ; t18a, t29a
ITX_MULSUB_2W 9, 4, 8, 11, 15, 3406, 2276 ; t21a, t26a
ITX_MULSUB_2W 6, 10, 8, 11, 15, m2276, 3406 ; t22a, t25a
psubw m8, m14, m2 ; t20a
paddw m14, m2 ; t23a
psubw m2, m1, m13 ; t27a
paddw m1, m13 ; t24a
psubw m13, m6, m9 ; t21
paddw m6, m9 ; t22
psubw m9, m10, m4 ; t26
paddw m10, m4 ; t25
ITX_MULSUB_2W 2, 8, 4, 11, 15, m3784, 1567 ; t20, t27
ITX_MULSUB_2W 9, 13, 4, 11, 15, m3784, 1567 ; t21a, t26a
mova m4, [rsp+gprsize+32*0] ; in31
mova [rsp+gprsize+32*0], m6 ; t22
mova m6, [rsp+gprsize+32*1] ; in15
mova [rsp+gprsize+32*1], m14 ; t23a
mova m14, [rsp+gprsize+32*2] ; in17
mova [rsp+gprsize+32*2], m1 ; t24a
ITX_MULSUB_2W 0, 4, 1, 11, 15, 201, 4091 ; t16a, t31a
ITX_MULSUB_2W 14, 6, 1, 11, 15, 3035, 2751 ; t17a, t30a
psubw m1, m0, m14 ; t17
paddw m0, m14 ; t16
psubw m14, m4, m6 ; t30
paddw m4, m6 ; t31
ITX_MULSUB_2W 14, 1, 6, 11, 15, 799, 4017 ; t17a, t30a
psubw m6, m0, m12 ; t19a
paddw m0, m12 ; t16a
psubw m12, m4, m3 ; t28a
paddw m4, m3 ; t31a
psubw m3, m14, m5 ; t18
paddw m14, m5 ; t17
psubw m5, m1, m7 ; t29
paddw m1, m7 ; t30
ITX_MULSUB_2W 5, 3, 7, 11, 15, 1567, 3784 ; t18a, t29a
ITX_MULSUB_2W 12, 6, 7, 11, 15, 1567, 3784 ; t19, t28
psubw m7, m1, m10 ; t25a
paddw m1, m10 ; t30a
psubw m10, m5, m9 ; t21
paddw m5, m9 ; t18
psubw m9, m12, m2 ; t20a
paddw m12, m2 ; t19a
psubw m2, m3, m13 ; t26
paddw m3, m13 ; t29
psubw m13, m6, m8 ; t27a
paddw m6, m8 ; t28a
mova [tmp1q-32*2], m5
mova [tmp1q-32*1], m12
mova [tmp2q+32*0], m6
mova [tmp2q+32*1], m3
mova [tmp2q+32*2], m1
mova m5, [rsp+gprsize+32*0] ; t22
mova m6, [rsp+gprsize+32*1] ; t23
mova m3, [rsp+gprsize+32*2] ; t24a
vpbroadcastd m8, [o(pw_2896x8)]
psubw m1, m14, m5 ; t22a
paddw m14, m5 ; t17a
psubw m5, m0, m6 ; t23
paddw m0, m6 ; t16
psubw m6, m4, m3 ; t24
paddw m4, m3 ; t31
mova [tmp1q-32*4], m0
mova [tmp1q-32*3], m14
mova [tmp2q+32*3], m4
psubw m3, m13, m9 ; t20
paddw m13, m9 ; t27
psubw m9, m2, m10 ; t21a
paddw m2, m10 ; t26a
psubw m10, m7, m1 ; t22
paddw m7, m1 ; t25
psubw m1, m6, m5 ; t23a
paddw m6, m5 ; t24a
REPX {pmulhrsw x, m8}, m3, m13, m9, m2, m10, m7, m1, m6
mova [tmp1q+32*0], m3
mova [tmp1q+32*1], m9
mova [tmp1q+32*2], m10
mova [tmp1q+32*3], m1
mova [tmp2q-32*4], m6
mova [tmp2q-32*3], m7
mova [tmp2q-32*2], m2
mova [tmp2q-32*1], m13
ret
ALIGN function_align
.transpose_2x8x8_round:
punpckhwd m6, m12, m13
punpcklwd m12, m13
punpckhwd m13, m8, m9
punpcklwd m8, m9
punpckhwd m9, m14, m15
punpcklwd m14, m15
punpckhwd m15, m10, m11
punpcklwd m10, m11
REPX {pmulhrsw x, m7}, m0, m1, m2, m3, m4, m5
punpckhdq m11, m8, m10
punpckldq m8, m10
punpckldq m10, m12, m14
punpckhdq m12, m14
punpckhdq m14, m13, m15
punpckldq m13, m15
punpckldq m15, m6, m9
punpckhdq m6, m9
punpckhqdq m9, m8, m10
punpcklqdq m8, m10
punpcklqdq m10, m11, m12
punpckhqdq m11, m12
punpcklqdq m12, m13, m15
punpckhqdq m13, m15
punpckhqdq m15, m14, m6
punpcklqdq m14, m6
pmulhrsw m6, m7, [rsp+gprsize+32*0]
REPX {pmulhrsw x, m7}, m8, m9, m10, m11, m12, m13, m14, m15
pmulhrsw m7, [rsp+gprsize+32*1]
mova [rsp+gprsize+32*0], m15
punpckhwd m15, m4, m5
punpcklwd m4, m5
punpckhwd m5, m0, m1
punpcklwd m0, m1
punpckhwd m1, m6, m7
punpcklwd m6, m7
punpckhwd m7, m2, m3
punpcklwd m2, m3
punpckhdq m3, m0, m2
punpckldq m0, m2
punpckldq m2, m4, m6
punpckhdq m4, m6
punpckhdq m6, m5, m7
punpckldq m5, m7
punpckldq m7, m15, m1
punpckhdq m15, m1
punpckhqdq m1, m0, m2
punpcklqdq m0, m2
punpcklqdq m2, m3, m4
punpckhqdq m3, m4
punpcklqdq m4, m5, m7
punpckhqdq m5, m7
punpckhqdq m7, m6, m15
punpcklqdq m6, m15
ret
ALIGN function_align
.pass2_end:
mova [rsp+gprsize+32*0], m7
mova [rsp+gprsize+32*2], m15
vpbroadcastd m15, [o(pw_2048)]
IDCT32_PASS2_END 0, tmp2q+32*3, 1, 7, 15, strideq*0, r3*4
IDCT32_PASS2_END 4, tmp2q-32*1, 0, 7, 15, strideq*4, strideq*8
IDCT32_PASS2_END 8, tmp1q+32*3, 0, 4, 15, strideq*8, strideq*4
IDCT32_PASS2_END 12, tmp1q-32*1, 0, 4, 15, r3*4, strideq*0
add dstq, strideq
sub r2, strideq
mova m1, [rsp+gprsize+32*1]
IDCT32_PASS2_END 1, tmp2q+32*2, 0, 4, 15, strideq*0, r3*4
IDCT32_PASS2_END 5, tmp2q-32*2, 0, 4, 15, strideq*4, strideq*8
IDCT32_PASS2_END 9, tmp1q+32*2, 0, 4, 15, strideq*8, strideq*4
IDCT32_PASS2_END 13, tmp1q-32*2, 0, 4, 15, r3*4, strideq*0
add dstq, strideq
sub r2, strideq
IDCT32_PASS2_END 2, tmp2q+32*1, 0, 4, 15, strideq*0, r3*4
IDCT32_PASS2_END 6, tmp2q-32*3, 0, 4, 15, strideq*4, strideq*8
IDCT32_PASS2_END 10, tmp1q+32*1, 0, 4, 15, strideq*8, strideq*4
IDCT32_PASS2_END 14, tmp1q-32*3, 0, 4, 15, r3*4, strideq*0
add dstq, strideq
sub r2, strideq
mova m7, [rsp+gprsize+32*0]
mova m1, [rsp+gprsize+32*2]
IDCT32_PASS2_END 3, tmp2q+32*0, 0, 4, 15, strideq*0, r3*4
IDCT32_PASS2_END 7, tmp2q-32*4, 0, 4, 15, strideq*4, strideq*8
IDCT32_PASS2_END 11, tmp1q+32*0, 0, 4, 15, strideq*8, strideq*4
IDCT32_PASS2_END 1, tmp1q-32*4, 0, 4, 15, r3*4, strideq*0
ret
; Perform the final sumsub step and YMM lane shuffling
%macro IDCT32_PASS1_END 4 ; row[1-2], tmp[1-2]
mova m%3, [tmp2q+32*( 3-%1)]
psubw m%4, m%1, m%3
paddw m%1, m%3
mova m%3, [tmp1q+32*(11-%2)]
mova [tmp1q+32*(11-%2)+16], xm%4
vextracti128 [tmp2q+32*( 3-%1)+16], m%4, 1
paddw m%4, m%2, m%3
psubw m%2, m%3
mova [tmp1q+32*(11-%2)], xm%2
vextracti128 [tmp2q+32*( 3-%1)], m%2, 1
vperm2i128 m%2, m%1, m%4, 0x31
vinserti128 m%1, m%1, xm%4, 1
%endmacro
cglobal inv_txfm_add_dct_dct_32x16, 4, 4, 0, dst, stride, c, eob
lea rax, [o_base]
test eobd, eobd
jnz .normal
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_16384)]
mov [cq], eobd
pmulhrsw xm0, xm1
mov r2d, 16
jmp m(inv_txfm_add_dct_dct_32x8).dconly
.normal:
PROLOGUE 0, 6, 16, 32*19, dst, stride, c, eob, tmp1, tmp2
vpbroadcastd m15, [o(pw_2896x8)]
pmulhrsw m0, m15, [cq+32* 1]
pmulhrsw m1, m15, [cq+32* 3]
pmulhrsw m2, m15, [cq+32* 5]
pmulhrsw m3, m15, [cq+32* 7]
pmulhrsw m4, m15, [cq+32* 9]
pmulhrsw m5, m15, [cq+32*11]
pmulhrsw m6, m15, [cq+32*13]
pmulhrsw m7, m15, [cq+32*15]
pmulhrsw m8, m15, [cq+32*17]
pmulhrsw m9, m15, [cq+32*19]
pmulhrsw m10, m15, [cq+32*21]
pmulhrsw m11, m15, [cq+32*23]
pmulhrsw m12, m15, [cq+32*25]
pmulhrsw m13, m15, [cq+32*27]
pmulhrsw m14, m15, [cq+32*29]
pmulhrsw m15, [cq+32*31]
lea tmp1q, [rsp+32*7]
lea tmp2q, [tmp1q+32*8]
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf
LOAD_16ROWS cq+32*0, 32*2, 1, 0
pxor m15, m15
mov r3d, 8
.zero_loop:
mova [cq+32*0], m15
mova [cq+32*1], m15
mova [cq+32*2], m15
mova [cq+32*3], m15
add cq, 32*4
dec r3d
jg .zero_loop
call m(idct_16x16_internal).main
call .pass1_end
lea r2, [strideq*3]
mov r3, dstq
.pass2:
vpbroadcastd m7, [o(pw_16384)]
call m(inv_txfm_add_dct_dct_16x32).transpose_2x8x8_round
call m(idct_16x16_internal).main
mova [rsp+32*2], m15
vpbroadcastd m15, [o(pw_2048)]
REPX {pmulhrsw x, m15}, m2, m3, m0
WRITE_16X2 2, 3, 1, 2, strideq*2, r2
pmulhrsw m1, m15, [rsp+32*1]
WRITE_16X2 0, 1, 2, 3, strideq*0, strideq*1
lea dstq, [dstq+strideq*4]
REPX {pmulhrsw x, m15}, m4, m5, m6, m7
WRITE_16X2 4, 5, 2, 3, strideq*0, strideq*1
WRITE_16X2 6, 7, 2, 3, strideq*2, r2
lea dstq, [dstq+strideq*4]
REPX {pmulhrsw x, m15}, m8, m9, m10, m11
WRITE_16X2 8, 9, 2, 3, strideq*0, strideq*1
WRITE_16X2 10, 11, 2, 3, strideq*2, r2
lea dstq, [dstq+strideq*4]
REPX {pmulhrsw x, m15}, m11, m12, m13, m14
pmulhrsw m15, [rsp+32*2]
WRITE_16X2 12, 13, 2, 3, strideq*0, strideq*1
WRITE_16X2 14, 15, 2, 3, strideq*2, r2
test r3, r3
jnz .right_half
RET
.right_half:
LOAD_8ROWS tmp1q-32*4, 32
LOAD_8ROWS_H tmp2q-32*4, 32
lea dstq, [r3+16]
xor r3d, r3d
mova [rsp+32*0], m6
mova [rsp+32*1], m7
jmp .pass2
ALIGN function_align
.pass1_end:
mova [rsp+gprsize+32*0], m9
IDCT32_PASS1_END 0, 8, 1, 9
IDCT32_PASS1_END 2, 10, 1, 9
IDCT32_PASS1_END 3, 11, 1, 9
IDCT32_PASS1_END 4, 12, 1, 9
IDCT32_PASS1_END 5, 13, 1, 9
IDCT32_PASS1_END 6, 14, 1, 9
IDCT32_PASS1_END 7, 15, 1, 9
mova m1, [rsp+gprsize+32*1]
mova m9, [rsp+gprsize+32*0]
mova [rsp+gprsize+32*0], m6
mova [rsp+gprsize+32*1], m7
IDCT32_PASS1_END 1, 9, 6, 7
ret
cglobal inv_txfm_add_identity_identity_16x32, 4, 5, 12, dst, stride, c, eob
%undef cmp
lea rax, [o_base]
vpbroadcastd m9, [o(pw_2896x8)]
vpbroadcastd m10, [o(pw_5793x4)]
vpbroadcastd m11, [o(pw_5)]
cmp eobd, 43 ; if (eob > 43)
setg r4b ; iteration_count++
cmp eobd, 150 ; if (eob > 150)
setg al ; iteration_count++
add eobd, -279 ; if (eob > 278)
adc r4b, al ; iteration_count++
lea r3, [strideq*3]
mov rax, cq
.loop:
mova xm0, [cq+64* 0]
mova xm1, [cq+64* 1]
vinserti128 m0, m0, [cq+64* 8], 1
vinserti128 m1, m1, [cq+64* 9], 1
mova xm2, [cq+64* 2]
mova xm3, [cq+64* 3]
vinserti128 m2, m2, [cq+64*10], 1
vinserti128 m3, m3, [cq+64*11], 1
mova xm4, [cq+64* 4]
mova xm5, [cq+64* 5]
vinserti128 m4, m4, [cq+64*12], 1
vinserti128 m5, m5, [cq+64*13], 1
mova xm6, [cq+64* 6]
mova xm7, [cq+64* 7]
vinserti128 m6, m6, [cq+64*14], 1
vinserti128 m7, m7, [cq+64*15], 1
REPX {pmulhrsw x, m9 }, m0, m1, m2, m3, m4, m5, m6, m7
REPX {psllw x, 2 }, m0, m1, m2, m3, m4, m5, m6, m7
call m(inv_txfm_add_identity_identity_8x32).transpose8x8
REPX {pmulhrsw x, m10}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {paddw x, m11}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {psraw x, 3 }, m0, m1, m2, m3, m4, m5, m6, m7
WRITE_16X2 0, 1, 8, 0, strideq*0, strideq*1
WRITE_16X2 2, 3, 0, 1, strideq*2, r3
lea dstq, [dstq+strideq*4]
WRITE_16X2 4, 5, 0, 1, strideq*0, strideq*1
WRITE_16X2 6, 7, 0, 1, strideq*2, r3
lea dstq, [dstq+strideq*4]
add cq, 16
dec r4b
jge .loop
sub cq, 32
pxor m0, m0
mov r0d, 8
cmp cq, rax
jg .zero_loop
.zero_loop_half:
mova [rax+64*0], m0
mova [rax+64*1], m0
mova [rax+64*2], m0
mova [rax+64*3], m0
add rax, 64*4
sub r0d, 2
jg .zero_loop_half
RET
.zero_loop:
mova [rax+32*0], m0
mova [rax+32*1], m0
mova [rax+32*2], m0
mova [rax+32*3], m0
add rax, 32*4
dec r0d
jg .zero_loop
RET
cglobal inv_txfm_add_identity_identity_32x16, 4, 6, 12, dst, stride, c, eob
%undef cmp
lea rax, [o_base]
vpbroadcastd m9, [o(pw_2896x8)]
vpbroadcastd m10, [o(pw_5793x4)]
vpbroadcastd m11, [o(pw_2048)]
cmp eobd, 35 ; if (eob > 35)
setg r4b ; iteration_count++
cmp eobd, 150 ; if (eob > 150)
setg r3b ; iteration_count += 2
lea r4d, [r4+r3*2]
lea r3, [strideq*3]
mov r5, dstq
mov rax, cq
.loop:
mova xm0, [cq+32* 0]
mova xm1, [cq+32* 1]
vinserti128 m0, m0, [cq+32* 8], 1
vinserti128 m1, m1, [cq+32* 9], 1
mova xm2, [cq+32* 2]
mova xm3, [cq+32* 3]
vinserti128 m2, m2, [cq+32*10], 1
vinserti128 m3, m3, [cq+32*11], 1
mova xm4, [cq+32* 4]
mova xm5, [cq+32* 5]
vinserti128 m4, m4, [cq+32*12], 1
vinserti128 m5, m5, [cq+32*13], 1
mova xm6, [cq+32* 6]
mova xm7, [cq+32* 7]
vinserti128 m6, m6, [cq+32*14], 1
vinserti128 m7, m7, [cq+32*15], 1
REPX {pmulhrsw x, m9 }, m0, m1, m2, m3, m4, m5, m6, m7
REPX {psllw x, 3 }, m0, m1, m2, m3, m4, m5, m6, m7
call m(inv_txfm_add_identity_identity_8x32).transpose8x8
REPX {pmulhrsw x, m10}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {pmulhrsw x, m11}, m0, m1, m2, m3, m4, m5, m6, m7
WRITE_16X2 0, 1, 8, 0, strideq*0, strideq*1
WRITE_16X2 2, 3, 0, 1, strideq*2, r3
lea dstq, [dstq+strideq*4]
WRITE_16X2 4, 5, 0, 1, strideq*0, strideq*1
WRITE_16X2 6, 7, 0, 1, strideq*2, r3
lea dstq, [dstq+strideq*4]
add cq, 16
dec r4b
jl .ret
test r4b, 1
jz .loop
add cq, 32*15
lea dstq, [r5+16]
jmp .loop
.ret:
sub cq, 32
pxor m0, m0
mov r0d, 4
mov r1d, 8
cmp cq, rax
cmovg r0d, r1d
.zero_loop:
mova [rax+32*0], m0
mova [rax+32*1], m0
mova [rax+32*2], m0
mova [rax+32*3], m0
add rax, 32*4
dec r0d
jg .zero_loop
RET
cglobal inv_txfm_add_dct_dct_32x32, 4, 4, 0, dst, stride, c, eob
lea rax, [o_base]
test eobd, eobd
jnz .normal
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_8192)]
mov [cq], eobd
mov r2d, 32
jmp m(inv_txfm_add_dct_dct_32x8).dconly
.normal:
PROLOGUE 0, 9, 16, 32*67, dst, stride, c, eob, tmp1, tmp2, \
base, tmp3, tmp4
%undef cmp
lea tmp1q, [rsp+32*7]
lea tmp2q, [tmp1q+32*8]
sub eobd, 136
mov tmp4d, eobd
.pass1_loop:
LOAD_8ROWS cq+64*1, 64*2
pxor m8, m8
REPX {mova [cq+64*x], m8}, 1, 3, 5, 7, 9, 11, 13, 15
test tmp4d, tmp4d
jl .fast
LOAD_8ROWS_H cq+64*17, 64*2
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf
LOAD_8ROWS_H cq+64*16, 64*2
pxor m0, m0
REPX {mova [cq+64*x], m0}, 16, 17, 18, 19, 20, 21, 22, 23, \
24, 25, 26, 27, 28, 29, 30, 31
mova [rsp], m15
jmp .idct16
.fast:
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf_fast
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14
mova [rsp], m8
.idct16:
LOAD_8ROWS cq+64*0, 64*2
pxor m15, m15
REPX {mova [cq+64*x], m15}, 0, 2, 4, 6, 8, 10, 12, 14
call m(idct_16x16_internal).main
call m(inv_txfm_add_dct_dct_32x16).pass1_end
vpbroadcastd m7, [o(pw_8192)]
call m(inv_txfm_add_dct_dct_16x32).transpose_2x8x8_round
lea tmp3q, [tmp1q+32*32]
mova m15, [rsp]
mova [tmp3q-32*4], m0
mova [tmp3q-32*3], m2
mova [tmp3q-32*2], m4
mova [tmp3q-32*1], m6
mova [tmp3q+32*0], m8
mova [tmp3q+32*1], m10
mova [tmp3q+32*2], m12
mova [tmp3q+32*3], m14
add tmp3q, 32*8
mova [tmp3q-32*4], m1
mova [tmp3q-32*3], m3
mova [tmp3q-32*2], m5
mova [tmp3q-32*1], m7
mova [tmp3q+32*0], m9
mova [tmp3q+32*1], m11
mova [tmp3q+32*2], m13
mova [tmp3q+32*3], m15
vpbroadcastd m9, [o(pw_8192)]
pmulhrsw m0, m9, [tmp1q-32*4]
pmulhrsw m1, m9, [tmp1q-32*3]
pmulhrsw m2, m9, [tmp1q-32*2]
pmulhrsw m3, m9, [tmp1q-32*1]
pmulhrsw m4, m9, [tmp1q+32*0]
pmulhrsw m5, m9, [tmp1q+32*1]
pmulhrsw m6, m9, [tmp1q+32*2]
pmulhrsw m7, m9, [tmp1q+32*3]
call m(inv_txfm_add_identity_identity_8x32).transpose8x8
mova [tmp1q-32*4], m0
pmulhrsw m0, m9, [tmp2q-32*4]
mova [tmp2q-32*4], m1
pmulhrsw m1, m9, [tmp2q-32*3]
mova [tmp1q-32*3], m2
pmulhrsw m2, m9, [tmp2q-32*2]
mova [tmp2q-32*3], m3
pmulhrsw m3, m9, [tmp2q-32*1]
mova [tmp1q-32*2], m4
pmulhrsw m4, m9, [tmp2q+32*0]
mova [tmp2q-32*2], m5
pmulhrsw m5, m9, [tmp2q+32*1]
mova [tmp1q-32*1], m6
pmulhrsw m6, m9, [tmp2q+32*2]
mova [tmp2q-32*1], m7
pmulhrsw m7, m9, [tmp2q+32*3]
call m(inv_txfm_add_identity_identity_8x32).transpose8x8
mova [tmp1q+32*0], m0
mova [tmp2q+32*0], m1
mova [tmp1q+32*1], m2
mova [tmp2q+32*1], m3
mova [tmp1q+32*2], m4
mova [tmp2q+32*2], m5
mova [tmp1q+32*3], m6
mova [tmp2q+32*3], m7
add cq, 32
add tmp1q, 32*16
add tmp2q, 32*16
add eobd, 0x80000000
jnc .pass1_loop
add tmp1q, 32*24
imul r2, strideq, 19
lea r3, [strideq*3]
add r2, dstq
test tmp4d, tmp4d
jge .pass2_loop
add tmp1q, 32*16
add tmp2q, 32*16
add tmp3q, 32*16
.pass2_loop:
LOAD_8ROWS tmp2q-32*4, 32
test tmp4d, tmp4d
jl .fast2
LOAD_8ROWS_H tmp3q-32*4, 32
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf
sub tmp3q, 32*8
LOAD_8ROWS_H tmp3q-32*4, 32
sub tmp3q, 32*16
jmp .pass2_loop_end
.fast2:
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf_fast
sub tmp3q, 32*24
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14, m15
.pass2_loop_end:
LOAD_8ROWS tmp3q-32*4, 32
mova [rsp], m15
call m(idct_16x16_internal).main
call m(inv_txfm_add_dct_dct_16x32).pass2_end
lea tmp3q, [tmp1q-32*32]
cmp tmp2q, tmp3q
jl .ret
sub tmp2q, 32*32
sub dstq, r3
lea r2, [r2+r3+16]
add dstq, 16
jmp .pass2_loop
.ret:
RET
cglobal inv_txfm_add_identity_identity_32x32, 4, 6, 10, dst, stride, c, eob
%undef cmp
vpbroadcastd m9, [pw_8192]
sub eobd, 136 ; if (eob < 136)
shr eobd, 30 ; topleft 16x16 only
lea eobd, [eobq*2-8]
lea r4, [strideq*3]
mov r5, dstq
lea rax, [cq+32]
.loop:
mova xm0, [cq+64* 0]
mova xm1, [cq+64* 1]
vinserti128 m0, m0, [cq+64* 8], 1
vinserti128 m1, m1, [cq+64* 9], 1
mova xm2, [cq+64* 2]
mova xm3, [cq+64* 3]
vinserti128 m2, m2, [cq+64*10], 1
vinserti128 m3, m3, [cq+64*11], 1
mova xm4, [cq+64* 4]
mova xm5, [cq+64* 5]
vinserti128 m4, m4, [cq+64*12], 1
vinserti128 m5, m5, [cq+64*13], 1
mova xm6, [cq+64* 6]
mova xm7, [cq+64* 7]
vinserti128 m6, m6, [cq+64*14], 1
vinserti128 m7, m7, [cq+64*15], 1
call m(inv_txfm_add_identity_identity_8x32).transpose8x8
REPX {pmulhrsw x, m9}, m0, m1, m2, m3, m4, m5, m6, m7
WRITE_16X2 0, 1, 8, 0, strideq*0, strideq*1
WRITE_16X2 2, 3, 0, 1, strideq*2, r4
lea dstq, [dstq+strideq*4]
WRITE_16X2 4, 5, 0, 1, strideq*0, strideq*1
WRITE_16X2 6, 7, 0, 1, strideq*2, r4
lea dstq, [dstq+strideq*4]
add cq, 16
inc eobd
jz .ret
test eobd, 3
jnz .loop
add cq, 64*15
lea dstq, [r5+16]
jmp .loop
.ret:
pxor m0, m0
mov r0d, 16
cmp cq, rax
jne .zero_loop
.zero_loop_topleft:
mova [rax-32*1], m0
mova [rax+32*1], m0
mova [rax+32*3], m0
mova [rax+32*5], m0
add rax, 64*4
sub r0d, 4
jg .zero_loop_topleft
RET
.zero_loop:
mova [rax-32*1], m0
mova [rax+32*0], m0
mova [rax+32*1], m0
mova [rax+32*2], m0
add rax, 32*4
dec r0d
jg .zero_loop
RET
%macro IDCT64_PART2_END 6-10 ; out, src[1-2], tmp[1-3], (offset[1-4])
%if %1 & 1
mova m%5, [tmp2q-32*(51-%1)] ; idct16 out 0+n
mova m%4, [tmp1q-32*(14+%1)] ; idct32 out31-n
%else
mova m%5, [tmp1q-32*(45-%1)]
mova m%4, [tmp2q-32*(20+%1)]
%endif
psubw m%6, m%5, m%4 ; idct32 out31-n
paddw m%5, m%4 ; idct32 out 0+n
psubw m%4, m%6, m%3 ; out32+n
paddw m%6, m%3 ; out31-n
psubw m%3, m%5, m%2 ; out63-n
paddw m%5, m%2 ; out 0+n
%if %0 == 6 ; pass 1
%if %1 & 1
mova [tmp2q-32*(19-%1)], m%4
mova [tmp1q-32*(14+%1)], m%6
mova [tmp1q+32*(18-%1)], m%3
mova [tmp2q-32*(51-%1)], m%5
%else
mova [tmp1q-32*(13-%1)], m%4
mova [tmp2q-32*(20+%1)], m%6
mova [tmp2q+32*(12-%1)], m%3
mova [tmp1q-32*(45-%1)], m%5
%endif
%else ; pass 2
REPX {pmulhrsw x, m14}, m%4, m%6, m%3, m%5
%if %1 & 1
%define %%d0 r2
%define %%d1 dstq
%else
%define %%d0 dstq
%define %%d1 r2
%endif
pmovzxbw m%2, [%%d0+%9 ]
paddw m%2, m%4
pmovzxbw m%4, [%%d1+%8 ]
paddw m%4, m%6
pmovzxbw m%6, [%%d1+%10]
paddw m%3, m%6
pmovzxbw m%6, [%%d0+%7 ]
paddw m%5, m%6
packuswb m%2, m%4
packuswb m%3, m%5
vpermq m%2, m%2, q3120
vpermq m%3, m%3, q3120
mova [%%d0+%9 ], xm%2
vextracti128 [%%d1+%8 ], m%2, 1
mova [%%d1+%10], xm%3
vextracti128 [%%d0+%7 ], m%3, 1
%endif
%endmacro
cglobal inv_txfm_add_dct_dct_16x64, 4, 4, 0, dst, stride, c, eob
lea rax, [o_base]
test eobd, eobd
jnz .normal
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_8192)]
mov [cq], eobd
mov r2d, 32
jmp m(inv_txfm_add_dct_dct_16x4).dconly
.normal:
PROLOGUE 0, 10, 16, 32*67, dst, stride, c, eob, tmp1, tmp2
%undef cmp
lea tmp1q, [rsp+32*23]
lea tmp2q, [tmp1q+32*24]
sub eobd, 151
mov r7d, eobd
.pass1_loop:
LOAD_16ROWS cq, 64
call m(idct_16x16_internal).main
mova m1, [rsp+32*1]
mova [rsp+32*0], m6
mova [rsp+32*1], m7
vpbroadcastd m7, [o(pw_8192)]
call m(inv_txfm_add_dct_dct_16x32).transpose_2x8x8_round
mova m15, [rsp+32*0]
mova [tmp1q-32*4], m0
mova [tmp1q-32*3], m2
mova [tmp1q-32*2], m4
mova [tmp1q-32*1], m6
mova [tmp1q+32*0], m8
mova [tmp1q+32*1], m10
mova [tmp1q+32*2], m12
mova [tmp1q+32*3], m14
mova [tmp2q-32*4], m1
mova [tmp2q-32*3], m3
mova [tmp2q-32*2], m5
mova [tmp2q-32*1], m7
mova [tmp2q+32*0], m9
mova [tmp2q+32*1], m11
mova [tmp2q+32*2], m13
mova [tmp2q+32*3], m15
add cq, 32
add tmp1q, 32*8
add tmp2q, 32*8
add eobd, 0x80000000
jnc .pass1_loop
lea r2, [rsp+32*23]
mova xm0, [r2-32*4+ 0]
mova xm1, [r2-32*2+ 0]
vinserti128 m0, m0, [r2+32*0+ 0], 1
vinserti128 m1, m1, [r2+32*2+ 0], 1
mova xm2, [r2-32*4+16]
mova xm3, [r2-32*2+16]
vinserti128 m2, m2, [r2+32*0+16], 1
vinserti128 m3, m3, [r2+32*2+16], 1
pxor m4, m4
REPX {mova x, m4}, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14
test r7d, r7d
jl .fast
lea r3, [r2+32*8]
mova xm4, [r3-32*4+ 0]
mova xm5, [r3-32*2+ 0]
vinserti128 m4, m4, [r3+32*0+ 0], 1
vinserti128 m5, m5, [r3+32*2+ 0], 1
mova xm6, [r3-32*4+16]
mova xm7, [r3-32*2+16]
vinserti128 m6, m6, [r3+32*0+16], 1
vinserti128 m7, m7, [r3+32*2+16], 1
.fast:
mova [rsp], m8
lea tmp1q, [rsp+32*7]
call m(idct_16x16_internal).main
mova m1, [rsp+32*1]
mova [tmp1q-32*4], m0
mova [tmp1q-32*3], m1
mova [tmp1q-32*2], m2
mova [tmp1q-32*1], m3
mova [tmp1q+32*0], m4
mova [tmp1q+32*1], m5
mova [tmp1q+32*2], m6
mova [tmp1q+32*3], m7
add tmp1q, 32*8
mova [tmp1q-32*4], m8
mova [tmp1q-32*3], m9
mova [tmp1q-32*2], m10
mova [tmp1q-32*1], m11
mova [tmp1q+32*0], m12
mova [tmp1q+32*1], m13
mova [tmp1q+32*2], m14
mova [tmp1q+32*3], m15
mova xm0, [r2-32*3+ 0]
mova xm1, [r2-32*1+ 0]
vinserti128 m0, m0, [r2+32*1+ 0], 1
vinserti128 m1, m1, [r2+32*3+ 0], 1
mova xm2, [r2-32*3+16]
mova xm3, [r2-32*1+16]
vinserti128 m2, m2, [r2+32*1+16], 1
vinserti128 m3, m3, [r2+32*3+16], 1
pxor m4, m4
REPX {mova x, m4}, m5, m6, m7
test r7d, r7d
jl .fast2
mova xm4, [r3-32*3+ 0]
mova xm5, [r3-32*1+ 0]
vinserti128 m4, m4, [r3+32*1+ 0], 1
vinserti128 m5, m5, [r3+32*3+ 0], 1
mova xm6, [r3-32*3+16]
mova xm7, [r3-32*1+16]
vinserti128 m6, m6, [r3+32*1+16], 1
vinserti128 m7, m7, [r3+32*3+16], 1
.fast2:
add tmp1q, 32*8
lea tmp2q, [tmp1q+32*8]
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf_fast
add r2, 32*24
vpbroadcastd m15, [o(pd_2048)]
add tmp1q, 32*16
add tmp2q, 32*32
mova xm0, [r2-32*4+ 0]
mova xm3, [r2-32*1+16]
vinserti128 m0, m0, [r2+32*0+ 0], 1
vinserti128 m3, m3, [r2+32*3+16], 1
mova xm4, [r2-32*4+16]
mova xm7, [r2-32*1+ 0]
vinserti128 m4, m4, [r2+32*0+16], 1
vinserti128 m7, m7, [r2+32*3+ 0], 1
pxor m1, m1
REPX {mova x, m1}, m2, m5, m6
test r7d, r7d
jl .fast3
add r3, 32*24
mova xm1, [r3-32*1+16]
mova xm2, [r3-32*4+ 0]
vinserti128 m1, m1, [r3+32*3+16], 1
vinserti128 m2, m2, [r3+32*0+ 0], 1
mova xm5, [r3-32*1+ 0]
mova xm6, [r3-32*4+16]
vinserti128 m5, m5, [r3+32*3+ 0], 1
vinserti128 m6, m6, [r3+32*0+16], 1
.fast3:
add rax, o_idct64_offset
call m(inv_txfm_add_dct_dct_16x64).main_part1
add rax, 8
add tmp1q, 32*8
sub tmp2q, 32*8
mova xm0, [r2-32*2+ 0]
mova xm3, [r2-32*3+16]
vinserti128 m0, m0, [r2+32*2+ 0], 1
vinserti128 m3, m3, [r2+32*1+16], 1
mova xm4, [r2-32*2+16]
mova xm7, [r2-32*3+ 0]
vinserti128 m4, m4, [r2+32*2+16], 1
vinserti128 m7, m7, [r2+32*1+ 0], 1
pxor m1, m1
REPX {mova x, m1}, m2, m5, m6
test r7d, r7d
jl .fast4
mova xm1, [r3-32*3+16]
mova xm2, [r3-32*2+ 0]
vinserti128 m1, m1, [r3+32*1+16], 1
vinserti128 m2, m2, [r3+32*2+ 0], 1
mova xm5, [r3-32*3+ 0]
mova xm6, [r3-32*2+16]
vinserti128 m5, m5, [r3+32*1+ 0], 1
vinserti128 m6, m6, [r3+32*2+16], 1
.fast4:
call m(inv_txfm_add_dct_dct_16x64).main_part1
call m(inv_txfm_add_dct_dct_16x64).main_part2_pass2
RET
ALIGN function_align
%define o_base idct64_mul - 8
.main_part1:
; idct64 steps 1-5:
; in1/31/17/15/ 9/23/25/ 7 ->
; t32a/33/34a/35/36/37a/38/39a/56a/57/58a/59/60/61a/62/63a
; in5/27/21/11/13/19/29/ 3 ->
; t40a/41/42a/43/44/45a/46/47a/48a/49/50a/51/52/53a/54/55a
vpbroadcastd m11, [o(idct64_mul+4* 0)]
vpbroadcastd m13, [o(idct64_mul+4* 1)]
vpbroadcastd m10, [o(idct64_mul+4* 4)]
vpbroadcastd m12, [o(idct64_mul+4* 5)]
pmulhrsw m11, m0 ; t63a
pmulhrsw m0, m13 ; t32a
pmulhrsw m10, m1 ; t62a
pmulhrsw m1, m12 ; t33a
vpbroadcastd m9, [o(idct64_mul+4* 8)]
vpbroadcastd m13, [o(idct64_mul+4* 9)]
vpbroadcastd m8, [o(idct64_mul+4*12)]
vpbroadcastd m12, [o(idct64_mul+4*13)]
pmulhrsw m9, m2 ; t61a
pmulhrsw m2, m13 ; t34a
pmulhrsw m8, m3 ; t60a
pmulhrsw m3, m12 ; t35a
psubw m12, m0, m1 ; t33
paddw m0, m1 ; t32
psubw m1, m3, m2 ; t34
paddw m3, m2 ; t35
psubw m2, m8, m9 ; t61
paddw m8, m9 ; t60
psubw m9, m11, m10 ; t62
paddw m11, m10 ; t63
ITX_MULSUB_2W 2, 1, 10, 13, 15, m4076, 401 ; t34a, t61a
vpbroadcastd m14, [o(pw_401_4076)]
ITX_MULSUB_2W 9, 12, 10, 13, 15, 14, 13 ; t33a, t62a
psubw m10, m0, m3 ; t35a
paddw m0, m3 ; t32a
psubw m3, m11, m8 ; t60a
paddw m11, m8 ; t63a
psubw m8, m9, m2 ; t34
paddw m9, m2 ; t33
psubw m2, m12, m1 ; t61
paddw m12, m1 ; t62
mova [tmp1q-32*4], m0
mova [tmp1q-32*3], m9
mova [tmp2q+32*2], m12
mova [tmp2q+32*3], m11
vpbroadcastd m13, [o(pw_m4017_799)]
vpbroadcastd m14, [o(pw_799_4017)]
ITX_MULSUB_2W 2, 8, 0, 1, 15, 14, 13 ; t34a, t61a
ITX_MULSUB_2W 3, 10, 0, 1, 15, 14, 13 ; t35, t60
mova [tmp1q-32*2], m2
mova [tmp1q-32*1], m3
mova [tmp2q+32*0], m10
mova [tmp2q+32*1], m8
vpbroadcastd m3, [o(idct64_mul+4*16)]
vpbroadcastd m11, [o(idct64_mul+4*17)]
vpbroadcastd m2, [o(idct64_mul+4*20)]
vpbroadcastd m10, [o(idct64_mul+4*21)]
vpbroadcastd m1, [o(idct64_mul+4*24)]
vpbroadcastd m9, [o(idct64_mul+4*25)]
vpbroadcastd m0, [o(idct64_mul+4*28)]
vpbroadcastd m8, [o(idct64_mul+4*29)]
pmulhrsw m3, m4 ; t59a
pmulhrsw m4, m11 ; t36a
pmulhrsw m2, m5 ; t58a
pmulhrsw m5, m10 ; t37a
pmulhrsw m1, m6 ; t57a
pmulhrsw m6, m9 ; t38a
pmulhrsw m0, m7 ; t56a
pmulhrsw m7, m8 ; t39a
psubw m8, m4, m5 ; t37
paddw m4, m5 ; t36
psubw m5, m7, m6 ; t38
paddw m7, m6 ; t39
psubw m6, m0, m1 ; t57
paddw m0, m1 ; t56
psubw m1, m3, m2 ; t58
paddw m3, m2 ; t59
ITX_MULSUB_2W 6, 5, 2, 9, 15, m2598, 3166 ; t38a, t57a
vpbroadcastd m10, [o(pw_3166_2598)]
ITX_MULSUB_2W 1, 8, 2, 9, 15, 10, 9 ; t37a, t58a
psubw m2, m7, m4 ; t36a
paddw m7, m4 ; t39a
psubw m4, m0, m3 ; t59a
paddw m0, m3 ; t56a
psubw m3, m6, m1 ; t37
paddw m6, m1 ; t38
psubw m1, m5, m8 ; t58
paddw m5, m8 ; t57
mova [tmp1q+32*2], m6
mova [tmp1q+32*3], m7
mova [tmp2q-32*4], m0
mova [tmp2q-32*3], m5
vpbroadcastd m6, [o(pw_m799_m4017)]
vpbroadcastd m7, [o(pw_m4017_799)]
ITX_MULSUB_2W 4, 2, 0, 5, 15, 7, 6 ; t36, t59
ITX_MULSUB_2W 1, 3, 0, 5, 15, 7, 6 ; t37a, t58a
mova [tmp1q+32*0], m4
mova [tmp1q+32*1], m1
mova [tmp2q-32*2], m3
mova [tmp2q-32*1], m2
ret
%define o_base pw_5 + 128
.main_part2_pass1: ; idct64 steps 6-9 + idct16/32/64 sumsub
sub rax, o_idct64_offset + 8
vpbroadcastd m11, [o(pw_1567_3784)]
vpbroadcastd m12, [o(pw_m3784_1567)]
vpbroadcastd m13, [o(pw_m1567_m3784)]
vpbroadcastd m14, [o(pw_2896x8)]
.main_part2_pass1_loop:
call .main_part2_internal
REPX {pmulhrsw x, m14}, m1, m2, m4, m3
IDCT64_PART2_END 0, 7, 0, 6, 9, 10
IDCT64_PART2_END 7, 8, 5, 0, 6, 7
IDCT64_PART2_END 8, 2, 1, 0, 6, 7
IDCT64_PART2_END 15, 3, 4, 0, 6, 7
cmp tmp1q, tmp2q
jne .main_part2_pass1_loop
ret
.main_part2_internal:
mova m0, [tmp1q-32*12] ; t32a
mova m1, [tmp2q-32*13] ; t39a
mova m2, [tmp1q-32* 4] ; t40a
mova m5, [tmp2q+32* 3] ; t55a
add tmp1q, 32
sub tmp2q, 32
mova m4, [tmp1q+32* 3] ; t48a
mova m3, [tmp2q-32* 4] ; t47a
mova m6, [tmp1q+32*11] ; t56a
mova m7, [tmp2q+32*12] ; t63a
psubw m8, m0, m1 ; t39
paddw m0, m1 ; t32
psubw m1, m3, m2 ; t40
paddw m3, m2 ; t47
psubw m2, m4, m5 ; t55
paddw m4, m5 ; t48
psubw m5, m7, m6 ; t56
paddw m7, m6 ; t63
ITX_MULSUB_2W 5, 8, 6, 9, 15, 11, 12 ; t39a, t56a
ITX_MULSUB_2W 2, 1, 6, 9, 15, 12, 13 ; t40a, t55a
psubw m6, m0, m3 ; t47a
paddw m0, m3 ; t32a
psubw m3, m7, m4 ; t48a
paddw m7, m4 ; t63a
psubw m4, m5, m2 ; t40
paddw m5, m2 ; t39
psubw m2, m8, m1 ; t55
paddw m8, m1 ; t56
psubw m1, m2, m4 ; t40a
paddw m2, m4 ; t55a
psubw m4, m3, m6 ; t47
paddw m3, m6 ; t48
ret
.main_part2_pass2:
sub rax, o_idct64_offset + 8
vpbroadcastd m11, [o(pw_1567_3784)]
vpbroadcastd m12, [o(pw_m3784_1567)]
vpbroadcastd m13, [o(pw_m1567_m3784)]
vpbroadcastd m14, [o(pw_2048)]
lea r9, [strideq*5] ; stride*5
lea r3, [r9+strideq*1] ; stride*6
lea r7, [r9+strideq*2] ; stride*7
lea r8, [r3+strideq*2] ; stride*8
lea r2, [dstq+r7]
.main_part2_pass2_loop:
call .main_part2_internal
vpbroadcastd m10, [o(pw_2896x8)]
REPX {pmulhrsw x, m10}, m1, m2, m4, m3
IDCT64_PART2_END 0, 7, 0, 6, 9, 10, strideq*0, r3*4, r8*4, r7*8
IDCT64_PART2_END 7, 8, 5, 0, 6, 7, strideq*0, r3*4, r8*4, r7*8
IDCT64_PART2_END 8, 2, 1, 0, 6, 7, strideq*8, r8*2, r9*8, r3*8
IDCT64_PART2_END 15, 3, 4, 0, 6, 7, strideq*8, r8*2, r9*8, r3*8
add dstq, strideq
sub r2, strideq
cmp tmp1q, tmp2q
jne .main_part2_pass2_loop
ret
cglobal inv_txfm_add_dct_dct_64x16, 4, 4, 0, dst, stride, c, eob
lea rax, [o_base]
test eobd, eobd
jnz .normal
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_8192)]
mov [cq], eobd
mov r2d, 16
.dconly:
pmulhrsw xm0, xm2
movd xm2, [o(pw_2048)]
pmulhrsw xm0, xm1
pmulhrsw xm0, xm2
vpbroadcastw m0, xm0
pxor m1, m1
.dconly_loop:
mova m2, [dstq+32*0]
mova m3, [dstq+32*1]
punpckhbw m4, m2, m1
punpcklbw m2, m1
punpckhbw m5, m3, m1
punpcklbw m3, m1
paddw m4, m0
paddw m2, m0
paddw m5, m0
paddw m3, m0
packuswb m2, m4
packuswb m3, m5
mova [dstq+32*0], m2
mova [dstq+32*1], m3
add dstq, strideq
dec r2d
jg .dconly_loop
RET
.normal:
PROLOGUE 0, 7, 16, 32*67, dst, stride, c, eob, tmp1, tmp2
LOAD_8ROWS cq+32*0, 32*4
pxor m8, m8
REPX {mova [cq+32*x], m8}, 0, 4, 8, 12, 16, 20, 24, 28
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14
mova [rsp], m8
lea tmp1q, [rsp+32*7]
call m(idct_16x16_internal).main
mova m1, [rsp+32*1]
mova [tmp1q-32*4], m0
mova [tmp1q-32*3], m1
mova [tmp1q-32*2], m2
mova [tmp1q-32*1], m3
mova [tmp1q+32*0], m4
mova [tmp1q+32*1], m5
mova [tmp1q+32*2], m6
mova [tmp1q+32*3], m7
add tmp1q, 32*8
mova [tmp1q-32*4], m8
mova [tmp1q-32*3], m9
mova [tmp1q-32*2], m10
mova [tmp1q-32*1], m11
mova [tmp1q+32*0], m12
mova [tmp1q+32*1], m13
mova [tmp1q+32*2], m14
mova [tmp1q+32*3], m15
LOAD_8ROWS cq+32*2, 32*4
pxor m8, m8
REPX {mova [cq+32*x], m8}, 2, 6, 10, 14, 18, 22, 26, 30
add tmp1q, 32*8
lea tmp2q, [tmp1q+32*8]
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf_fast
vpbroadcastd m15, [o(pd_2048)]
add tmp1q, 32*16
add tmp2q, 32*32
mova m0, [cq+32* 1]
mova m1, [cq+32*31]
mova m2, [cq+32*17]
mova m3, [cq+32*15]
mova m4, [cq+32* 9]
mova m5, [cq+32*23]
mova m6, [cq+32*25]
mova m7, [cq+32* 7]
pxor m8, m8
REPX {mova [cq+32*x], m8}, 1, 31, 17, 15, 9, 23, 25, 7
add rax, o_idct64_offset
call m(inv_txfm_add_dct_dct_16x64).main_part1
add rax, 8
add tmp1q, 32*8
sub tmp2q, 32*8
mova m0, [cq+32* 5]
mova m1, [cq+32*27]
mova m2, [cq+32*21]
mova m3, [cq+32*11]
mova m4, [cq+32*13]
mova m5, [cq+32*19]
mova m6, [cq+32*29]
mova m7, [cq+32* 3]
pxor m8, m8
REPX {mova [cq+32*x], m8}, 5, 27, 21, 11, 13, 19, 29, 3
call m(inv_txfm_add_dct_dct_16x64).main_part1
call m(inv_txfm_add_dct_dct_16x64).main_part2_pass1
sub tmp1q, 32*36
lea r2, [strideq*3]
mov tmp2d, 4
.pass2_loop:
lea r3, [tmp1q-32*8]
mova xm0, [r3 -32*4]
mova xm1, [r3 -32*3]
vinserti128 m0, m0, [tmp1q-32*4], 1
vinserti128 m1, m1, [tmp1q-32*3], 1
mova xm2, [r3 -32*2]
mova xm3, [r3 -32*1]
vinserti128 m2, m2, [tmp1q-32*2], 1
vinserti128 m3, m3, [tmp1q-32*1], 1
mova xm4, [r3 +32*0]
mova xm5, [r3 +32*1]
vinserti128 m4, m4, [tmp1q+32*0], 1
vinserti128 m5, m5, [tmp1q+32*1], 1
mova xm6, [r3 +32*2]
mova xm7, [r3 +32*3]
vinserti128 m6, m6, [tmp1q+32*2], 1
vinserti128 m7, m7, [tmp1q+32*3], 1
mova xm8, [r3 -32*4+16]
mova xm9, [r3 -32*3+16]
vinserti128 m8, m8, [tmp1q-32*4+16], 1
vinserti128 m9, m9, [tmp1q-32*3+16], 1
mova xm10, [r3 -32*2+16]
mova xm11, [r3 -32*1+16]
vinserti128 m10, m10, [tmp1q-32*2+16], 1
vinserti128 m11, m11, [tmp1q-32*1+16], 1
mova xm12, [r3 +32*0+16]
mova xm13, [r3 +32*1+16]
vinserti128 m12, m12, [tmp1q+32*0+16], 1
vinserti128 m13, m13, [tmp1q+32*1+16], 1
mova xm14, [r3 +32*2+16]
mova xm15, [r3 +32*3+16]
vinserti128 m14, m14, [tmp1q+32*2+16], 1
vinserti128 m15, m15, [tmp1q+32*3+16], 1
mova [rsp+32*0], m6
mova [rsp+32*1], m7
vpbroadcastd m7, [o(pw_8192)]
call m(inv_txfm_add_dct_dct_16x32).transpose_2x8x8_round
call m(idct_16x16_internal).main
mova [rsp+32*0], m15
vpbroadcastd m15, [o(pw_2048)]
REPX {pmulhrsw x, m15}, m0, m2, m3, m4, m5, m6, m7
WRITE_16X2 2, 3, 1, 2, strideq*2, r2
pmulhrsw m1, m15, [rsp+32*1]
WRITE_16X2 0, 1, 2, 3, strideq*0, strideq*1
lea r3, [dstq+strideq*4]
%define dstq r3
WRITE_16X2 4, 5, 2, 3, strideq*0, strideq*1
WRITE_16X2 6, 7, 2, 3, strideq*2, r2
REPX {pmulhrsw x, m15}, m8, m9, m10, m11, m12, m13, m14
lea r3, [r3+strideq*4]
WRITE_16X2 8, 9, 2, 3, strideq*0, strideq*1
WRITE_16X2 10, 11, 2, 3, strideq*2, r2
pmulhrsw m15, [rsp+32*0]
lea r3, [r3+strideq*4]
WRITE_16X2 12, 13, 2, 3, strideq*0, strideq*1
WRITE_16X2 14, 15, 2, 3, strideq*2, r2
add tmp1q, 32*16
add r0, 16
dec tmp2d
jg .pass2_loop
RET
cglobal inv_txfm_add_dct_dct_32x64, 4, 4, 0, dst, stride, c, eob
lea rax, [o_base]
test eobd, eobd
jnz .normal
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_16384)]
mov [cq], eobd
pmulhrsw xm0, xm1
mov r2d, 64
jmp m(inv_txfm_add_dct_dct_32x8).dconly
.normal:
PROLOGUE 0, 11, 16, 32*99, dst, stride, c, eob, tmp1, tmp2
lea tmp1q, [rsp+32*7]
lea r10d, [eobq-136]
sar r10d, 31
.pass1_loop:
lea tmp2q, [tmp1q+32*16]
LOAD_8ROWS cq+64*1, 64*2, 1
pxor m8, m8
REPX {mova [cq+64*x], m8}, 1, 3, 5, 7, 9, 11, 13, 15
test r10b, r10b
jnz .fast
LOAD_8ROWS_H cq+64*17, 64*2, 2
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf
LOAD_8ROWS_H cq+64*16, 64*2, 1
mova [rsp], m15
pxor m15, m15
REPX {mova [cq+64*x], m15}, 16, 17, 18, 19, 20, 21, 22, 23, \
24, 25, 26, 27, 28, 29, 30, 31
jmp .idct16
.fast:
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf_fast
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14
mova [rsp], m8
.idct16:
LOAD_8ROWS cq+64*0, 64*2, 1
pxor m15, m15
REPX {mova [cq+64*x], m15}, 0, 2, 4, 6, 8, 10, 12, 14
call m(idct_16x16_internal).main
call m(inv_txfm_add_dct_dct_32x16).pass1_end
vpbroadcastd m7, [o(pw_16384)]
call m(inv_txfm_add_dct_dct_16x32).transpose_2x8x8_round
lea r3, [tmp1q+32*48]
mova m15, [rsp]
mova [r3-32*4], m0
mova [r3-32*3], m2
mova [r3-32*2], m4
mova [r3-32*1], m6
mova [r3+32*0], m8
mova [r3+32*1], m10
mova [r3+32*2], m12
mova [r3+32*3], m14
add r3, 32*24
mova [r3-32*4], m1
mova [r3-32*3], m3
mova [r3-32*2], m5
mova [r3-32*1], m7
mova [r3+32*0], m9
mova [r3+32*1], m11
mova [r3+32*2], m13
mova [r3+32*3], m15
vpbroadcastd m9, [o(pw_16384)]
pmulhrsw m0, m9, [tmp1q-32*4]
pmulhrsw m1, m9, [tmp1q-32*3]
pmulhrsw m2, m9, [tmp1q-32*2]
pmulhrsw m3, m9, [tmp1q-32*1]
pmulhrsw m4, m9, [tmp1q+32*0]
pmulhrsw m5, m9, [tmp1q+32*1]
pmulhrsw m6, m9, [tmp1q+32*2]
pmulhrsw m7, m9, [tmp1q+32*3]
call m(inv_txfm_add_identity_identity_8x32).transpose8x8
mova [tmp1q-32*4], m0
pmulhrsw m0, m9, [tmp2q-32*4]
mova [tmp2q-32*4], m1
pmulhrsw m1, m9, [tmp2q-32*3]
mova [tmp1q-32*3], m2
pmulhrsw m2, m9, [tmp2q-32*2]
mova [tmp2q-32*3], m3
pmulhrsw m3, m9, [tmp2q-32*1]
mova [tmp1q-32*2], m4
pmulhrsw m4, m9, [tmp2q+32*0]
mova [tmp2q-32*2], m5
pmulhrsw m5, m9, [tmp2q+32*1]
mova [tmp1q-32*1], m6
pmulhrsw m6, m9, [tmp2q+32*2]
mova [tmp2q-32*1], m7
pmulhrsw m7, m9, [tmp2q+32*3]
call m(inv_txfm_add_identity_identity_8x32).transpose8x8
mova [tmp1q+32*0], m0
mova [tmp2q+32*0], m1
mova [tmp1q+32*1], m2
mova [tmp2q+32*1], m3
mova [tmp1q+32*2], m4
mova [tmp2q+32*2], m5
mova [tmp1q+32*3], m6
mova [tmp2q+32*3], m7
add cq, 32
add tmp1q, 32*8
add r10d, 0x80000000
jnc .pass1_loop
lea r2, [rsp+32*55]
lea r7, [r2+32*24]
.pass2_loop:
lea r3, [r2+32*8]
lea r8, [r7+32*8]
mova m0, [r2-32*4]
mova m1, [r2-32*2]
mova m2, [r2+32*0]
mova m3, [r2+32*2]
pxor m4, m4
REPX {mova x, m4}, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14
test r10b, r10b
jnz .fast2
mova m4, [r3-32*4]
mova m5, [r3-32*2]
mova m6, [r3+32*0]
mova m7, [r3+32*2]
.fast2:
mova [rsp], m8
lea tmp1q, [rsp+32*39]
call m(idct_16x16_internal).main
mova m1, [rsp+32*1]
mova [tmp1q-32*4], m0
mova [tmp1q-32*3], m1
mova [tmp1q-32*2], m2
mova [tmp1q-32*1], m3
mova [tmp1q+32*0], m4
mova [tmp1q+32*1], m5
mova [tmp1q+32*2], m6
mova [tmp1q+32*3], m7
add tmp1q, 32*8
mova [tmp1q-32*4], m8
mova [tmp1q-32*3], m9
mova [tmp1q-32*2], m10
mova [tmp1q-32*1], m11
mova [tmp1q+32*0], m12
mova [tmp1q+32*1], m13
mova [tmp1q+32*2], m14
mova [tmp1q+32*3], m15
mova m0, [r2-32*3]
mova m1, [r2-32*1]
mova m2, [r2+32*1]
mova m3, [r2+32*3]
pxor m4, m4
REPX {mova x, m4}, m5, m6, m7
test r10b, r10b
jnz .fast3
mova m4, [r3-32*3]
mova m5, [r3-32*1]
mova m6, [r3+32*1]
mova m7, [r3+32*3]
.fast3:
add tmp1q, 32*8
lea tmp2q, [tmp1q+32*8]
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf_fast
vpbroadcastd m15, [o(pd_2048)]
add tmp1q, 32*16
add tmp2q, 32*32
mova m0, [r7-32*4]
mova m3, [r7+32*3]
mova m4, [r7+32*0]
mova m7, [r7-32*1]
pxor m1, m1
REPX {mova x, m1}, m2, m5, m6
test r10b, r10b
jnz .fast4
mova m1, [r8+32*3]
mova m2, [r8-32*4]
mova m5, [r8-32*1]
mova m6, [r8+32*0]
.fast4:
add rax, o_idct64_offset
call m(inv_txfm_add_dct_dct_16x64).main_part1
add rax, 8
add tmp1q, 32*8
sub tmp2q, 32*8
mova m0, [r7-32*2]
mova m3, [r7+32*1]
mova m4, [r7+32*2]
mova m7, [r7-32*3]
pxor m1, m1
REPX {mova x, m1}, m2, m5, m6
test r10b, r10b
jnz .fast5
mova m1, [r8+32*1]
mova m2, [r8-32*2]
mova m5, [r8-32*3]
mova m6, [r8+32*2]
.fast5:
call m(inv_txfm_add_dct_dct_16x64).main_part1
call m(inv_txfm_add_dct_dct_16x64).main_part2_pass2
add r10d, 0x80000000
jc .ret
lea r2, [rsp+32*7]
lea r7, [r2+32*16]
sub dstq, r8
lea dstq, [dstq+strideq*4+16]
jmp .pass2_loop
.ret:
RET
cglobal inv_txfm_add_dct_dct_64x32, 4, 4, 0, dst, stride, c, eob
lea rax, [o_base]
test eobd, eobd
jnz .normal
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_16384)]
mov [cq], eobd
pmulhrsw xm0, xm1
mov r2d, 32
jmp m(inv_txfm_add_dct_dct_64x16).dconly
.normal:
PROLOGUE 0, 9, 16, 32*131, dst, stride, c, eob, tmp1, tmp2, \
base, tmp3, tmp4
lea tmp1q, [rsp+32*7]
lea tmp4d, [eobq-136]
.pass1_loop:
LOAD_8ROWS cq+64*0, 64*4, 1
pxor m8, m8
REPX {mova [cq+64*x], m8}, 0, 4, 8, 12, 16, 20, 24, 28
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14
mova [rsp], m8
call m(idct_16x16_internal).main
mova m1, [rsp+32*1]
mova [tmp1q-32*4], m0
mova [tmp1q-32*3], m1
mova [tmp1q-32*2], m2
mova [tmp1q-32*1], m3
mova [tmp1q+32*0], m4
mova [tmp1q+32*1], m5
mova [tmp1q+32*2], m6
mova [tmp1q+32*3], m7
add tmp1q, 32*8
mova [tmp1q-32*4], m8
mova [tmp1q-32*3], m9
mova [tmp1q-32*2], m10
mova [tmp1q-32*1], m11
mova [tmp1q+32*0], m12
mova [tmp1q+32*1], m13
mova [tmp1q+32*2], m14
mova [tmp1q+32*3], m15
LOAD_8ROWS cq+64*2, 64*4, 1
pxor m8, m8
REPX {mova [cq+64*x], m8}, 2, 6, 10, 14, 18, 22, 26, 30
add tmp1q, 32*8
lea tmp2q, [tmp1q+32*8]
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf_fast
vpbroadcastd m15, [o(pd_2048)]
add tmp1q, 32*16
add tmp2q, 32*32
vpbroadcastd m7, [o(pw_2896x8)]
pmulhrsw m0, m7, [cq+64* 1]
pmulhrsw m1, m7, [cq+64*31]
pmulhrsw m2, m7, [cq+64*17]
pmulhrsw m3, m7, [cq+64*15]
pmulhrsw m4, m7, [cq+64* 9]
pmulhrsw m5, m7, [cq+64*23]
pmulhrsw m6, m7, [cq+64*25]
pmulhrsw m7, [cq+64* 7]
pxor m8, m8
REPX {mova [cq+64*x], m8}, 1, 31, 17, 15, 9, 23, 25, 7
add rax, o_idct64_offset
call m(inv_txfm_add_dct_dct_16x64).main_part1
vpbroadcastd m7, [o(pw_2896x8-(o_idct64_offset))]
add rax, 8
add tmp1q, 32*8
sub tmp2q, 32*8
pmulhrsw m0, m7, [cq+64* 5]
pmulhrsw m1, m7, [cq+64*27]
pmulhrsw m2, m7, [cq+64*21]
pmulhrsw m3, m7, [cq+64*11]
pmulhrsw m4, m7, [cq+64*13]
pmulhrsw m5, m7, [cq+64*19]
pmulhrsw m6, m7, [cq+64*29]
pmulhrsw m7, [cq+64* 3]
pxor m8, m8
REPX {mova [cq+64*x], m8}, 5, 27, 21, 11, 13, 19, 29, 3
call m(inv_txfm_add_dct_dct_16x64).main_part1
call m(inv_txfm_add_dct_dct_16x64).main_part2_pass1
sub tmp1q, 32*44
vpbroadcastd m10, [o(pw_16384)]
call m(inv_txfm_add_dct_dct_64x32).transpose_round_interleave
add cq, 32
add tmp4d, 0x80000000
jnc .pass1_loop
lea tmp1q, [rsp+32*15]
imul r2, strideq, 19
lea r3, [strideq*3]
add r2, dstq
mov tmp4b, 4
.pass2_loop:
lea tmp2q, [tmp1q+32*64]
LOAD_8ROWS tmp1q-32*4, 32
test tmp4d, 0x40000000
jnz .fast
LOAD_8ROWS_H tmp2q-32*4, 32
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf
lea tmp3q, [tmp2q-32*8]
LOAD_8ROWS_H tmp3q-32*4, 32
mova [rsp], m15
jmp .idct16
.fast:
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf_fast
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14
mova [rsp], m8
.idct16:
lea tmp3q, [tmp1q-32*8]
LOAD_8ROWS tmp3q-32*4, 32
call m(idct_16x16_internal).main
call m(inv_txfm_add_dct_dct_16x32).pass2_end
add tmp1q, 32*16
sub dstq, r3
lea r2, [r2+r3+16]
add dstq, 16
dec tmp4b
jg .pass2_loop
RET
ALIGN function_align
.transpose_round_interleave:
mov tmp3d, 4
.loop:
lea tmp2q, [tmp1q+32*8]
mova xm0, [tmp1q-32*4]
mova xm1, [tmp1q-32*3]
vinserti128 m0, m0, [tmp2q-32*4], 1
vinserti128 m1, m1, [tmp2q-32*3], 1
mova xm2, [tmp1q-32*2]
mova xm3, [tmp1q-32*1]
vinserti128 m2, m2, [tmp2q-32*2], 1
vinserti128 m3, m3, [tmp2q-32*1], 1
mova xm4, [tmp1q+32*0]
mova xm5, [tmp1q+32*1]
vinserti128 m4, m4, [tmp2q+32*0], 1
vinserti128 m5, m5, [tmp2q+32*1], 1
mova xm6, [tmp1q+32*2]
mova xm7, [tmp1q+32*3]
vinserti128 m6, m6, [tmp2q+32*2], 1
vinserti128 m7, m7, [tmp2q+32*3], 1
REPX {pmulhrsw x, m10}, m0, m1, m2, m3, m4, m5, m6, m7
call m(inv_txfm_add_identity_identity_8x32).transpose8x8
mova xm8, [tmp1q-32*4+16]
mova xm9, [tmp1q-32*3+16]
vinserti128 m8, m8, [tmp2q-32*4+16], 1
vinserti128 m9, m9, [tmp2q-32*3+16], 1
mova [tmp1q-32*4], m0
mova [tmp2q-32*4], m1
mova [tmp1q-32*3], m2
mova [tmp2q-32*3], m3
mova xm2, [tmp1q-32*2+16]
mova xm3, [tmp1q-32*1+16]
vinserti128 m2, m2, [tmp2q-32*2+16], 1
vinserti128 m3, m3, [tmp2q-32*1+16], 1
mova [tmp1q-32*2], m4
mova [tmp2q-32*2], m5
mova [tmp1q-32*1], m6
mova [tmp2q-32*1], m7
mova xm4, [tmp1q+32*0+16]
mova xm5, [tmp1q+32*1+16]
vinserti128 m4, m4, [tmp2q+32*0+16], 1
vinserti128 m5, m5, [tmp2q+32*1+16], 1
mova xm6, [tmp1q+32*2+16]
mova xm7, [tmp1q+32*3+16]
vinserti128 m6, m6, [tmp2q+32*2+16], 1
vinserti128 m7, m7, [tmp2q+32*3+16], 1
pmulhrsw m0, m8, m10
pmulhrsw m1, m9, m10
REPX {pmulhrsw x, m10}, m2, m3, m4, m5, m6, m7
call m(inv_txfm_add_identity_identity_8x32).transpose8x8
mova [tmp1q+32*0], m0
mova [tmp2q+32*0], m1
mova [tmp1q+32*1], m2
mova [tmp2q+32*1], m3
mova [tmp1q+32*2], m4
mova [tmp2q+32*2], m5
mova [tmp1q+32*3], m6
mova [tmp2q+32*3], m7
add tmp1q, 32*16
dec tmp3d
jg .loop
ret
cglobal inv_txfm_add_dct_dct_64x64, 4, 4, 0, dst, stride, c, eob
lea rax, [o_base]
test eobd, eobd
jnz .normal
movd xm1, [o(pw_2896x8)]
pmulhrsw xm0, xm1, [cq]
movd xm2, [o(pw_8192)]
mov [cq], eobd
mov r2d, 64
jmp m(inv_txfm_add_dct_dct_64x16).dconly
.normal:
PROLOGUE 0, 11, 16, 32*199, dst, stride, c, eob, tmp1, tmp2
lea tmp1q, [rsp+32*71]
lea r10d, [eobq-136]
.pass1_loop:
LOAD_8ROWS cq+64*0, 64*4
pxor m8, m8
REPX {mova [cq+64*x], m8}, 0, 4, 8, 12, 16, 20, 24, 28
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14
mova [rsp], m8
call m(idct_16x16_internal).main
mova m1, [rsp+32*1]
mova [tmp1q-32*4], m0
mova [tmp1q-32*3], m1
mova [tmp1q-32*2], m2
mova [tmp1q-32*1], m3
mova [tmp1q+32*0], m4
mova [tmp1q+32*1], m5
mova [tmp1q+32*2], m6
mova [tmp1q+32*3], m7
add tmp1q, 32*8
mova [tmp1q-32*4], m8
mova [tmp1q-32*3], m9
mova [tmp1q-32*2], m10
mova [tmp1q-32*1], m11
mova [tmp1q+32*0], m12
mova [tmp1q+32*1], m13
mova [tmp1q+32*2], m14
mova [tmp1q+32*3], m15
LOAD_8ROWS cq+64*2, 64*4
pxor m8, m8
REPX {mova [cq+64*x], m8}, 2, 6, 10, 14, 18, 22, 26, 30
add tmp1q, 32*8
lea tmp2q, [tmp1q+32*8]
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf_fast
vpbroadcastd m15, [o(pd_2048)]
add tmp1q, 32*16
add tmp2q, 32*32
mova m0, [cq+64* 1]
mova m1, [cq+64*31]
mova m2, [cq+64*17]
mova m3, [cq+64*15]
mova m4, [cq+64* 9]
mova m5, [cq+64*23]
mova m6, [cq+64*25]
mova m7, [cq+64* 7]
pxor m8, m8
REPX {mova [cq+64*x], m8}, 1, 31, 17, 15, 9, 23, 25, 7
add rax, o_idct64_offset
call m(inv_txfm_add_dct_dct_16x64).main_part1
add rax, 8
add tmp1q, 32*8
sub tmp2q, 32*8
mova m0, [cq+64* 5]
mova m1, [cq+64*27]
mova m2, [cq+64*21]
mova m3, [cq+64*11]
mova m4, [cq+64*13]
mova m5, [cq+64*19]
mova m6, [cq+64*29]
mova m7, [cq+64* 3]
pxor m8, m8
REPX {mova [cq+64*x], m8}, 5, 27, 21, 11, 13, 19, 29, 3
call m(inv_txfm_add_dct_dct_16x64).main_part1
call m(inv_txfm_add_dct_dct_16x64).main_part2_pass1
sub tmp1q, 32*44
vpbroadcastd m10, [o(pw_8192)]
call m(inv_txfm_add_dct_dct_64x32).transpose_round_interleave
add cq, 32
add r10d, 0x80000000
jnc .pass1_loop
lea tmp1q, [rsp+32*7]
mov r10b, 4
.pass2_loop:
lea r2, [tmp1q+32*64]
mova m0, [r2-32*4]
mova m1, [r2-32*2]
mova m2, [r2+32*0]
mova m3, [r2+32*2]
pxor m4, m4
REPX {mova x, m4}, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14
mova [rsp], m4
test r10d, 0x40000000
jnz .fast
lea r3, [r2+32*64]
mova m4, [r3-32*4]
mova m5, [r3-32*2]
mova m6, [r3+32*0]
mova m7, [r3+32*2]
.fast:
call m(idct_16x16_internal).main
mova m1, [rsp+32*1]
mova [tmp1q-32*4], m0
mova [tmp1q-32*3], m1
mova [tmp1q-32*2], m2
mova [tmp1q-32*1], m3
mova [tmp1q+32*0], m4
mova [tmp1q+32*1], m5
mova [tmp1q+32*2], m6
mova [tmp1q+32*3], m7
add tmp1q, 32*8
mova [tmp1q-32*4], m8
mova [tmp1q-32*3], m9
mova [tmp1q-32*2], m10
mova [tmp1q-32*1], m11
mova [tmp1q+32*0], m12
mova [tmp1q+32*1], m13
mova [tmp1q+32*2], m14
mova [tmp1q+32*3], m15
mova m0, [r2-32*3]
mova m1, [r2-32*1]
mova m2, [r2+32*1]
mova m3, [r2+32*3]
pxor m4, m4
REPX {mova x, m4}, m5, m6, m7
test r10d, 0x40000000
jnz .fast2
mova m4, [r3-32*3]
mova m5, [r3-32*1]
mova m6, [r3+32*1]
mova m7, [r3+32*3]
.fast2:
add tmp1q, 32*8
lea tmp2q, [tmp1q+32*8]
call m(inv_txfm_add_dct_dct_16x32).main_oddhalf_fast
vpbroadcastd m15, [o(pd_2048)]
add r2, 32*8
add r3, 32*8
add tmp1q, 32*16
add tmp2q, 32*32
mova m0, [r2-32*4] ; 1
mova m3, [r2+32*3] ; 15
mova m4, [r2+32*0] ; 9
mova m7, [r2-32*1] ; 7
pxor m1, m1
REPX {mova x, m1}, m2, m5, m6
test r10d, 0x40000000
jnz .fast3
mova m1, [r3+32*3] ; 31
mova m2, [r3-32*4] ; 17
mova m5, [r3-32*1] ; 23
mova m6, [r3+32*0] ; 25
.fast3:
add rax, o_idct64_offset
call m(inv_txfm_add_dct_dct_16x64).main_part1
add rax, 8
add tmp1q, 32*8
sub tmp2q, 32*8
mova m0, [r2-32*2] ; 5
mova m3, [r2+32*1] ; 11
mova m4, [r2+32*2] ; 13
mova m7, [r2-32*3] ; 3
pxor m1, m1
REPX {mova x, m1}, m2, m5, m6
test r10d, 0x40000000
jnz .fast4
mova m1, [r3+32*1] ; 27
mova m2, [r3-32*2] ; 21
mova m5, [r3-32*3] ; 19
mova m6, [r3+32*2] ; 29
.fast4:
call m(inv_txfm_add_dct_dct_16x64).main_part1
call m(inv_txfm_add_dct_dct_16x64).main_part2_pass2
sub tmp1q, 32*28
sub dstq, r8
lea dstq, [dstq+strideq*4+16]
dec r10b
jg .pass2_loop
RET
%endif ; ARCH_X86_64
|
; A055947: n - reversal of base 3 digits of n (written in base 10).
; 0,0,0,2,0,-2,4,2,0,8,0,-8,8,0,-8,8,0,-8,16,8,0,16,8,0,16,8,0,26,0,-26,20,-6,-32,14,-12,-38,32,6,-20,26,0,-26,20,-6,-32,38,12,-14,32,6,-20,26,0,-26,52,26,0,46,20,-6,40,14,-12,58,32,6,52,26,0,46,20,-6,64,38,12,58,32,6,52,26,0,80,0,-80,56,-24,-104,32,-48,-128,80,0,-80,56,-24,-104,32,-48,-128,80,0,-80,56,-24,-104,32,-48,-128,104,24,-56,80,0,-80,56,-24,-104,104,24,-56,80,0,-80,56,-24,-104,104,24,-56,80,0,-80,56,-24,-104,128,48,-32,104,24,-56,80,0,-80,128,48,-32,104,24,-56,80,0,-80,128,48,-32,104,24,-56,80,0,-80,160,80,0,136,56,-24,112,32,-48,160,80,0,136,56,-24,112,32,-48,160,80,0,136,56,-24,112,32,-48,184,104,24,160,80,0,136,56,-24,184,104,24,160,80,0,136,56,-24,184,104,24,160,80,0,136,56,-24,208,128,48,184,104,24,160,80,0,208,128,48,184,104,24,160,80,0,208,128,48,184,104,24,160,80,0,242,0,-242,164,-78,-320,86
mov $1,$0
cal $0,30102 ; Base-3 reversal of n (written in base 10).
sub $1,$0
|
/// @ingroup MOD_MEXCEP
/// @file mexception.cpp
/// @brief Implementation of the new exception class methods
/// @author Matheus Pimenta
#include "mexception.hpp"
mexception::mexception (const std::string& what) throw () : what_ ( what )
{
}
mexception::~mexception () throw ()
{
}
const char* mexception::what () const throw ()
{
return what_.c_str ();
}
void mexception::logerr () const throw ()
{
std::cout << "Logging error...\n";
std::fstream f ( "./ErrorLog.txt",
std::fstream::out | std::fstream::app );
time_t rawtime = time ( NULL );
f << "- Error: ";
f << what_;
f << ". Occured on ";
f << ctime ( &rawtime );
f.close ();
}
|
db 0 ; species ID placeholder
db 50, 52, 48, 55, 65, 50
; hp atk def spd sat sdf
db WATER, WATER ; type
db 190 ; catch rate
db 80 ; 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/psyduck/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 DYNAMICPUNCH, HEADBUTT, CURSE, TOXIC, ROCK_SMASH, PSYCH_UP, HIDDEN_POWER, SNORE, BLIZZARD, ICY_WIND, PROTECT, RAIN_DANCE, ENDURE, FRUSTRATION, IRON_TAIL, RETURN, DIG, MUD_SLAP, DOUBLE_TEAM, ICE_PUNCH, SWAGGER, SLEEP_TALK, SWIFT, REST, ATTRACT, WATER_SPORT, STRONG_ARM, WHIRLPOOL, ICE_BEAM
; end
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; MKDIR.ASM
;;
;; NDOS Make directory
;;
;; On start, dma contains command line argument length byte
;; and command line.
;; Stack pointer should be within CCP.
;; Check for NDOS; display error if not running.
;; Copy command line arguments to buf and call NDOS to send it.
;; Call NDOS to receive response.
;; On a=0(success), print new current working directory in response buf.
;; On a=0FFh(failure), print error.
;;
maclib ndos
org tpa
start: lxi h,0
dad sp ; hl = sp
shld savestack ; save original stack pointer
lxi sp,stack
mvi c,n?ver
call bdosv
cpi 10h
jc nondos
; NDOS is present
; copy command line args from dmabuf
lxi d,msgbuf+2 ; point to start of data
lxi h,defdma ; command-line
mov a,m ; command-line length
ora a
jz docwd
mov c,a
loop: inx h
mov a,m
stax d
inx d
dcr c
jnz loop
docwd: lda defdma
adi 3 ; include LEN, CMD, and CHK bytes
sta msgbuf
mvi c,n?smsg
lxi d,msgbuf
call bdosv
mvi c,n?rmsg
lxi d,buffer
call bdosv
ora a
jnz timeout
; check response code from server
; lda buffer+2
; ora a
; jnz serverr
; print response from server
lda buffer
dcr a
mov e,a
mvi d,0
lxi h,buffer
dad d
mvi m,'$'
lxi d,buffer+3
mvi c,prnstr
call bdosv
jmp quit
; NDOS not found
nondos: mvi c,prnstr
lxi d,nondoserr
call bdosv
jmp quit
; Timeout contacting server
timeout:mvi c,prnstr
lxi d,toerr
call bdosv
jmp quit
; Error status from server
serverr:mvi c,prnstr
lxi d,serr
call bdosv
quit: lhld savestack
sphl ; sp = hl
ret ; quit
nondoserr:
db 'NDOS not loaded',cr,lf,'$'
toerr: db 'Timeout',cr,lf,'$'
serr: db 'Error',cr,lf,'$'
;; NDOS request message
msgbuf: db 0 ; LEN
db NMKDIR ; CMD
ds 148 ; DATA and CHK
;; NDOS response buffer
buffer: ds 150
savestack:
dw 0
ds 16
stack:
end start
|
SECTION code_fp_math48
PUBLIC _ilogb_fastcall
EXTERN cm48_sdcciy_ilogb_fastcall
defc _ilogb_fastcall = cm48_sdcciy_ilogb_fastcall
|
/*
* Copyright 2016 The Cartographer Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "cartographer/mapping/internal/2d/scan_matching/fast_correlative_scan_matcher_2d.h"
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <limits>
#include "Eigen/Geometry"
#include "cartographer/common/make_unique.h"
#include "cartographer/common/math.h"
#include "cartographer/mapping/2d/grid_2d.h"
#include "cartographer/sensor/point_cloud.h"
#include "cartographer/transform/transform.h"
#include "glog/logging.h"
namespace cartographer {
namespace mapping {
namespace scan_matching {
namespace {
// A collection of values which can be added and later removed, and the maximum
// of the current values in the collection can be retrieved.
// All of it in (amortized) O(1).
class SlidingWindowMaximum {
public:
void AddValue(const float value) {
while (!non_ascending_maxima_.empty() &&
value > non_ascending_maxima_.back()) {
non_ascending_maxima_.pop_back();
}
non_ascending_maxima_.push_back(value);
}
void RemoveValue(const float value) {
// DCHECK for performance, since this is done for every value in the
// precomputation grid.
DCHECK(!non_ascending_maxima_.empty());
DCHECK_LE(value, non_ascending_maxima_.front());
if (value == non_ascending_maxima_.front()) {
non_ascending_maxima_.pop_front();
}
}
float GetMaximum() const {
// DCHECK for performance, since this is done for every value in the
// precomputation grid.
DCHECK_GT(non_ascending_maxima_.size(), 0);
return non_ascending_maxima_.front();
}
void CheckIsEmpty() const { CHECK_EQ(non_ascending_maxima_.size(), 0); }
private:
// Maximum of the current sliding window at the front. Then the maximum of the
// remaining window that came after this values first occurrence, and so on.
std::deque<float> non_ascending_maxima_;
};
} // namespace
proto::FastCorrelativeScanMatcherOptions2D
CreateFastCorrelativeScanMatcherOptions2D(
common::LuaParameterDictionary* const parameter_dictionary) {
proto::FastCorrelativeScanMatcherOptions2D options;
options.set_linear_search_window(
parameter_dictionary->GetDouble("linear_search_window"));
options.set_angular_search_window(
parameter_dictionary->GetDouble("angular_search_window"));
options.set_branch_and_bound_depth(
parameter_dictionary->GetInt("branch_and_bound_depth"));
return options;
}
PrecomputationGrid2D::PrecomputationGrid2D(
const Grid2D& grid, const CellLimits& limits, const int width,
std::vector<float>* reusable_intermediate_grid)
: offset_(-width + 1, -width + 1),
wide_limits_(limits.num_x_cells + width - 1,
limits.num_y_cells + width - 1),
min_score_(1.f - grid.GetMaxCorrespondenceCost()),
max_score_(1.f - grid.GetMinCorrespondenceCost()),
cells_(wide_limits_.num_x_cells * wide_limits_.num_y_cells) {
CHECK_GE(width, 1);
CHECK_GE(limits.num_x_cells, 1);
CHECK_GE(limits.num_y_cells, 1);
const int stride = wide_limits_.num_x_cells;
// First we compute the maximum probability for each (x0, y) achieved in the
// span defined by x0 <= x < x0 + width.
std::vector<float>& intermediate = *reusable_intermediate_grid;
intermediate.resize(wide_limits_.num_x_cells * limits.num_y_cells);
for (int y = 0; y != limits.num_y_cells; ++y) {
SlidingWindowMaximum current_values;
current_values.AddValue(
1.f - std::abs(grid.GetCorrespondenceCost(Eigen::Array2i(0, y))));
for (int x = -width + 1; x != 0; ++x) {
intermediate[x + width - 1 + y * stride] = current_values.GetMaximum();
if (x + width < limits.num_x_cells) {
current_values.AddValue(1.f - std::abs(grid.GetCorrespondenceCost(
Eigen::Array2i(x + width, y))));
}
}
for (int x = 0; x < limits.num_x_cells - width; ++x) {
intermediate[x + width - 1 + y * stride] = current_values.GetMaximum();
current_values.RemoveValue(
1.f - std::abs(grid.GetCorrespondenceCost(Eigen::Array2i(x, y))));
current_values.AddValue(1.f - std::abs(grid.GetCorrespondenceCost(
Eigen::Array2i(x + width, y))));
}
for (int x = std::max(limits.num_x_cells - width, 0);
x != limits.num_x_cells; ++x) {
intermediate[x + width - 1 + y * stride] = current_values.GetMaximum();
current_values.RemoveValue(
1.f - std::abs(grid.GetCorrespondenceCost(Eigen::Array2i(x, y))));
}
current_values.CheckIsEmpty();
}
// For each (x, y), we compute the maximum probability in the width x width
// region starting at each (x, y) and precompute the resulting bound on the
// score.
for (int x = 0; x != wide_limits_.num_x_cells; ++x) {
SlidingWindowMaximum current_values;
current_values.AddValue(intermediate[x]);
for (int y = -width + 1; y != 0; ++y) {
cells_[x + (y + width - 1) * stride] =
ComputeCellValue(current_values.GetMaximum());
if (y + width < limits.num_y_cells) {
current_values.AddValue(intermediate[x + (y + width) * stride]);
}
}
for (int y = 0; y < limits.num_y_cells - width; ++y) {
cells_[x + (y + width - 1) * stride] =
ComputeCellValue(current_values.GetMaximum());
current_values.RemoveValue(intermediate[x + y * stride]);
current_values.AddValue(intermediate[x + (y + width) * stride]);
}
for (int y = std::max(limits.num_y_cells - width, 0);
y != limits.num_y_cells; ++y) {
cells_[x + (y + width - 1) * stride] =
ComputeCellValue(current_values.GetMaximum());
current_values.RemoveValue(intermediate[x + y * stride]);
}
current_values.CheckIsEmpty();
}
}
uint8 PrecomputationGrid2D::ComputeCellValue(const float probability) const {
const int cell_value = common::RoundToInt(
(probability - min_score_) * (255.f / (max_score_ - min_score_)));
CHECK_GE(cell_value, 0);
CHECK_LE(cell_value, 255);
return cell_value;
}
PrecomputationGridStack2D::PrecomputationGridStack2D(
const Grid2D& grid,
const proto::FastCorrelativeScanMatcherOptions2D& options) {
CHECK_GE(options.branch_and_bound_depth(), 1);
const int max_width = 1 << (options.branch_and_bound_depth() - 1);
precomputation_grids_.reserve(options.branch_and_bound_depth());
std::vector<float> reusable_intermediate_grid;
const CellLimits limits = grid.limits().cell_limits();
reusable_intermediate_grid.reserve((limits.num_x_cells + max_width - 1) *
limits.num_y_cells);
for (int i = 0; i != options.branch_and_bound_depth(); ++i) {
const int width = 1 << i;
precomputation_grids_.emplace_back(grid, limits, width,
&reusable_intermediate_grid);
}
}
FastCorrelativeScanMatcher2D::FastCorrelativeScanMatcher2D(
const Grid2D& grid,
const proto::FastCorrelativeScanMatcherOptions2D& options)
: options_(options),
limits_(grid.limits()),
precomputation_grid_stack_(
common::make_unique<PrecomputationGridStack2D>(grid, options)) {}
FastCorrelativeScanMatcher2D::~FastCorrelativeScanMatcher2D() {}
bool FastCorrelativeScanMatcher2D::Match(
const transform::Rigid2d& initial_pose_estimate,
const sensor::PointCloud& point_cloud, const float min_score, float* score,
transform::Rigid2d* pose_estimate) const {
const SearchParameters search_parameters(options_.linear_search_window(),
options_.angular_search_window(),
point_cloud, limits_.resolution());
return MatchWithSearchParameters(search_parameters, initial_pose_estimate,
point_cloud, min_score, score,
pose_estimate);
}
//这里进匹配,与submap全局匹配
bool FastCorrelativeScanMatcher2D::MatchFullSubmap(
const sensor::PointCloud& point_cloud, float min_score, float* score,
transform::Rigid2d* pose_estimate) const {
// Compute a search window around the center of the submap that includes it
// fully.
const SearchParameters search_parameters(
1e6 * limits_.resolution(), // Linear search window, 1e6 cells/direction.
M_PI, // Angular search window, 180 degrees in both directions.
point_cloud, limits_.resolution());
const transform::Rigid2d center = transform::Rigid2d::Translation(
limits_.max() - 0.5 * limits_.resolution() *
Eigen::Vector2d(limits_.cell_limits().num_y_cells,
limits_.cell_limits().num_x_cells));
return MatchWithSearchParameters(search_parameters, center, point_cloud,
min_score, score, pose_estimate);
}
//这个函数调用的branchandBound
bool FastCorrelativeScanMatcher2D::MatchWithSearchParameters(
SearchParameters search_parameters,
const transform::Rigid2d& initial_pose_estimate,
const sensor::PointCloud& point_cloud, float min_score, float* score,
transform::Rigid2d* pose_estimate) const {
CHECK_NOTNULL(score);
CHECK_NOTNULL(pose_estimate);
const Eigen::Rotation2Dd initial_rotation = initial_pose_estimate.rotation();
const sensor::PointCloud rotated_point_cloud = sensor::TransformPointCloud(
point_cloud,
transform::Rigid3f::Rotation(Eigen::AngleAxisf(
initial_rotation.cast<float>().angle(), Eigen::Vector3f::UnitZ())));
const std::vector<sensor::PointCloud> rotated_scans =
GenerateRotatedScans(rotated_point_cloud, search_parameters);
const std::vector<DiscreteScan2D> discrete_scans = DiscretizeScans(
limits_, rotated_scans,
Eigen::Translation2f(initial_pose_estimate.translation().x(),
initial_pose_estimate.translation().y()));
search_parameters.ShrinkToFit(discrete_scans, limits_.cell_limits());
const std::vector<Candidate2D> lowest_resolution_candidates =
ComputeLowestResolutionCandidates(discrete_scans, search_parameters);
const Candidate2D best_candidate = BranchAndBound(
discrete_scans, search_parameters, lowest_resolution_candidates,
precomputation_grid_stack_->max_depth(), min_score);
if (best_candidate.score > min_score) {
*score = best_candidate.score;
*pose_estimate = transform::Rigid2d(
{initial_pose_estimate.translation().x() + best_candidate.x,
initial_pose_estimate.translation().y() + best_candidate.y},
initial_rotation * Eigen::Rotation2Dd(best_candidate.orientation));
return true;
}
return false;
}
std::vector<Candidate2D>
FastCorrelativeScanMatcher2D::ComputeLowestResolutionCandidates(
const std::vector<DiscreteScan2D>& discrete_scans,
const SearchParameters& search_parameters) const {
std::vector<Candidate2D> lowest_resolution_candidates =
GenerateLowestResolutionCandidates(search_parameters);
ScoreCandidates(
precomputation_grid_stack_->Get(precomputation_grid_stack_->max_depth()),
discrete_scans, search_parameters, &lowest_resolution_candidates);
return lowest_resolution_candidates;
}
std::vector<Candidate2D>
FastCorrelativeScanMatcher2D::GenerateLowestResolutionCandidates(
const SearchParameters& search_parameters) const {
const int linear_step_size = 1 << precomputation_grid_stack_->max_depth();
int num_candidates = 0;
for (int scan_index = 0; scan_index != search_parameters.num_scans;
++scan_index) {
const int num_lowest_resolution_linear_x_candidates =
(search_parameters.linear_bounds[scan_index].max_x -
search_parameters.linear_bounds[scan_index].min_x + linear_step_size) /
linear_step_size;
const int num_lowest_resolution_linear_y_candidates =
(search_parameters.linear_bounds[scan_index].max_y -
search_parameters.linear_bounds[scan_index].min_y + linear_step_size) /
linear_step_size;
num_candidates += num_lowest_resolution_linear_x_candidates *
num_lowest_resolution_linear_y_candidates;
}
std::vector<Candidate2D> candidates;
candidates.reserve(num_candidates);
for (int scan_index = 0; scan_index != search_parameters.num_scans;
++scan_index) {
for (int x_index_offset = search_parameters.linear_bounds[scan_index].min_x;
x_index_offset <= search_parameters.linear_bounds[scan_index].max_x;
x_index_offset += linear_step_size) {
for (int y_index_offset =
search_parameters.linear_bounds[scan_index].min_y;
y_index_offset <= search_parameters.linear_bounds[scan_index].max_y;
y_index_offset += linear_step_size) {
candidates.emplace_back(scan_index, x_index_offset, y_index_offset,
search_parameters);
}
}
}
CHECK_EQ(candidates.size(), num_candidates);
return candidates;
}
void FastCorrelativeScanMatcher2D::ScoreCandidates(
const PrecomputationGrid2D& precomputation_grid,
const std::vector<DiscreteScan2D>& discrete_scans,
const SearchParameters& search_parameters,
std::vector<Candidate2D>* const candidates) const {
for (Candidate2D& candidate : *candidates) {
int sum = 0;
for (const Eigen::Array2i& xy_index :
discrete_scans[candidate.scan_index]) {
const Eigen::Array2i proposed_xy_index(
xy_index.x() + candidate.x_index_offset,
xy_index.y() + candidate.y_index_offset);
sum += precomputation_grid.GetValue(proposed_xy_index);
}
candidate.score = precomputation_grid.ToScore(
sum / static_cast<float>(discrete_scans[candidate.scan_index].size()));
}
std::sort(candidates->begin(), candidates->end(),
std::greater<Candidate2D>());
}
Candidate2D FastCorrelativeScanMatcher2D::BranchAndBound(
const std::vector<DiscreteScan2D>& discrete_scans,
const SearchParameters& search_parameters,
const std::vector<Candidate2D>& candidates, const int candidate_depth,
float min_score) const {
if (candidate_depth == 0) {
// Return the best candidate.
return *candidates.begin();
}
Candidate2D best_high_resolution_candidate(0, 0, 0, search_parameters);
best_high_resolution_candidate.score = min_score;
for (const Candidate2D& candidate : candidates) {
if (candidate.score <= min_score) {
break;
}
std::vector<Candidate2D> higher_resolution_candidates;
const int half_width = 1 << (candidate_depth - 1);
for (int x_offset : {0, half_width}) {
if (candidate.x_index_offset + x_offset >
search_parameters.linear_bounds[candidate.scan_index].max_x) {
break;
}
for (int y_offset : {0, half_width}) {
if (candidate.y_index_offset + y_offset >
search_parameters.linear_bounds[candidate.scan_index].max_y) {
break;
}
higher_resolution_candidates.emplace_back(
candidate.scan_index, candidate.x_index_offset + x_offset,
candidate.y_index_offset + y_offset, search_parameters);
}
}
ScoreCandidates(precomputation_grid_stack_->Get(candidate_depth - 1),
discrete_scans, search_parameters,
&higher_resolution_candidates);
best_high_resolution_candidate = std::max(
best_high_resolution_candidate,
BranchAndBound(discrete_scans, search_parameters,
higher_resolution_candidates, candidate_depth - 1,
best_high_resolution_candidate.score));
}
return best_high_resolution_candidate;
}
} // namespace scan_matching
} // namespace mapping
} // namespace cartographer
|
; A155499: a(n) = n + (n+1)^(n+2).
; 1,9,83,1027,15629,279941,5764807,134217735,3486784409,100000000009,3138428376731,106993205379083,3937376385699301,155568095557812237,6568408355712890639,295147905179352825871,14063084452067724991025,708235345355337676357649,37589973457545958193355619,2097152000000000000000000019,122694327386105632949003612861,7511413302012830262726227918869,480250763996501976790165756943063,32009658644406818986777955348250647
mov $2,$0
add $0,2
add $2,1
pow $2,$0
add $0,$2
sub $0,2
|
; $Id: ex1.asm,v 1.2 2011/04/12 09:05:29 sraj Exp $
;
; This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
;
; Copyright 2007-2020 Broadcom Inc. All rights reserved.
;
;
;Here is an example program for programming the LEDs on the 5605.
;This is about as simple as it gets.
;
;The situation is this:
;
; 26 ports (port 0-25) each have one LED.
;
; The LED is dark if there has been no activity,
; or is on if there has been either RX, TX, or Collision.
;
; We shift out port 0 status first, port 25 last.
;
;
;-------------------------- start of program --------------------------
begin:
ld A,0 ; start with port 0
ld (portnum),A
portloop:
port A ; specify which port we're dealing with
pushst RX
pushst TX
tor ; RX | TX
pushst COLL
tor ; RX | TX | COLL
pack ; send to output buffer
inc (portnum)
ld A,(portnum)
cmp A,26
jnz portloop
send 26 ; send 26 LED pulses and halt
; data storage
portnum equ 0x7F ; temp to hold which port we're working on
; symbolic labels
; this gives symbolic names to the various bits of the port status fields
RX equ 0x0 ; received packet
TX equ 0x1 ; transmitted packet
COLL equ 0x2 ; collision indicator
SPEED_C equ 0x3 ; 100 Mbps
SPEED_M equ 0x4 ; 1000 Mbps
DUPLEX equ 0x5 ; half/full duplex
FLOW equ 0x6 ; flow control capable
LINKUP equ 0x7 ; link down/up status
LINKEN equ 0x8 ; link disabled/enabled status
;-------------------------- end of program --------------------------
;
;This program is 23 bytes in length and uses one data storage location.
;This wasn't necessary, as the B register could have been used, but
;the point was to show some of the instructions.
|
;*******************************************************************************
; msg.nasm - core message passing routines.
; Copyright (c) 2003 RET & COM Research.
;*******************************************************************************
module kernel.ipc.msg
%include "sys.ah"
%include "errors.ah"
%include "thread.ah"
%include "pool.ah"
%include "msg.ah"
%include "tm/process.ah"
%include "cpu/paging.ah"
publicproc IPC_PulseInit
publicproc sys_MsgSendv, sys_MsgSendvnc, sys_MsgReplyv, sys_MsgReceivev
publicproc sys_MsgWritev, sys_MsgReadv, sys_MsgReadIOV
publicproc sys_MsgSendPulse, sys_MsgReceivePulsev
publicproc sys_MsgInfo, sys_MsgError, sys_MsgKeyData
exportproc K_DecodeRcvid, K_SendPulse, AllocPulseDesc, FreePulseDesc
externproc K_ChanDescAddr, K_ConnDescAddr
externproc K_PoolInit, K_PoolAllocChunk, K_PoolFreeChunk
externproc K_PoolChunkNumber, K_PoolChunkAddr
externproc K_SemP, K_SemV
externproc K_CopyFromAct, K_CopyToAct, K_CopyOut, BZero
externproc SLin2Phys, DLin2Phys
externproc MT_ThreadSleep, MT_ThreadWakeup, MT_Schedule, MT_FindTCBbyNum
section .bss
?MaxPulses RESD 1 ; Maximum number of pulses
?PulseCount RESD 1 ; Number of allocated pulses
?PulsePool RESB tMasterPool_size
section .text
%include "msgcopy.nasm"
; IPC_PulseInit - initialize the pulse pool.
; Input: EAX=maximum number of pulses.
; Output: none.
proc IPC_PulseInit
mov [?MaxPulses],eax
mov ebx,?PulsePool
xor ecx,ecx
mov [?PulseCount],ecx
mov cl,tPulseDesc_size
xor dl,dl
call K_PoolInit
ret
endp ;---------------------------------------------------------------
; Allocate a pulse descriptor.
; Input: none.
; Output: CF=0 - OK, EBX=pulse descriptor address;
; CF=1 - error, EAX=errno.
proc AllocPulseDesc
mpush ecx,esi
mov eax,[?PulseCount]
cmp eax,[?MaxPulses]
jae .Err
mov ebx,?PulsePool
call K_PoolAllocChunk
jc .Exit
mov ebx,esi
mov ecx,tPulseDesc_size
call BZero
mSemInit esi+tPulseDesc.Lock
inc dword [?PulseCount]
clc
.Exit: mpop esi,ecx
ret
.Err: mov eax,-EAGAIN
stc
jmp .Exit
endp ;---------------------------------------------------------------
; Free a pulse descriptor.
; Input: EBX=pulse descriptor address.
; Output: CF=0 - OK;
; CF=1 - error, AX=error code.
proc FreePulseDesc
push esi
mov esi,ebx
call K_PoolFreeChunk
jc .Exit
dec dword [?PulseCount]
.Exit: pop esi
ret
endp ;---------------------------------------------------------------
; Find a TCB by a given rcvid.
; Input: EAX=rcvid.
; Output: CF=0 - OK, EBX=TCB address;
; CF=1 - error, EAX=errno.
; Note: currently rcvid consists of 16-bit TCB chunk number
; (system-wide, low word) and 16-bit ConnDesc chunk
; number (system-wide, high word). This will most
; probably change when the support of native networking
; will be added.
proc K_DecodeRcvid
and eax,0FFFFh
call MT_FindTCBbyNum
jnc .Ret
mov eax,-ESRCH
.Ret: ret
endp ;---------------------------------------------------------------
; Fill in the message information structure.
; Input: EBX=address of sending TCB,
; EDI=information structure address (user).
; Output: CF=0 - OK:
; EAX=0,
; EDI=info structure address (kernel);
; CF=1 - error, EAX=errno.
; Note: modifies ESI.
proc FillMessageInfo
; Check if a user buffer is OK
add edi,USERAREASTART
jc .Fault
mov eax,edi
add eax,tMsgInfo_size-1
jc .Fault
; Fill in the buffer
mov eax,[ebx+tTCB.TID]
mov [edi+tMsgInfo.TID],eax
mov eax,[ebx+tTCB.PCB]
mov eax,[eax+tProcDesc.PID]
mov [edi+tMsgInfo.PID],eax
mov esi,[ebx+tTCB.ConnDesc]
Mov32 edi+tMsgInfo.CoID,esi+tConnDesc.ID
Mov32 edi+tMsgInfo.ScoID,esi+tConnDesc.ScoID
xor eax,eax
.Exit: ret
.Fault: mov eax,-EFAULT
jmp .Exit
.NotFound: mov eax,-ESRCH
jmp .Exit
endp ;---------------------------------------------------------------
; Send a pulse to the channel. This routine is used
; by MsgSendPulse and MsgDeliverEvent.
; Input: AL=pulse code,
; ECX=pulse value,
; EBX=address of TCB,
; EDI=address of connection descriptor.
; Output: none.
proc K_SendPulse
mpush ebx,edx,esi,eax
; Get a pulse descriptor and fill it in
mov edx,ebx
call AllocPulseDesc
jc near .Exit
mLockCB ebx, tPulseDesc
mov al,[esp]
mov [ebx+tPulse.Code],al
mov [ebx+tPulse.SigValue],ecx
mov [ebx+tPulseDesc.TCB],edx
mov [ebx+tPulseDesc.ConnDesc],edi
; Put the pulse into the queue
mov esi,[edi+tConnDesc.ChanDesc]
mEnqueue dword [esi+tChanDesc.PulseQueue], Next, Prev, ebx, tPulseDesc, edx
mUnlockCB ebx, tPulseDesc
; If there is somebody in the receive queue, wake him up
mov ebx,[esi+tChanDesc.ReceiveWaitQ]
or ebx,ebx
jz .Exit
mDequeue dword [esi+tChanDesc.ReceiveWaitQ], RcvNext, RcvPrev, ebx, tTCB, edx
call MT_ThreadWakeup
.Exit: mpop eax,esi,edx,ebx
ret
endp ;---------------------------------------------------------------
; --- System call routines -----------------------------------------------------
; int MsgSendvnc(int coid, const iov_t *siov, int sparts,
; const iov_t *riov, int rparts);
; int MsgSendnc(int coid, const void *smsg, int sbytes,
; void *rmsg, int rbytes);
; int MsgSendsvnc(int coid, const void *smsg, int sbytes,
; const iov_t *riov, int rparts);
; int MsgSendvsnc(int coid, const iov_t *siov, int sparts,
; void *rmsg, int rbytes);
proc sys_MsgSendvnc
arg coid, smsg, sparts, rmsg, rparts
prologue
; Get current thread
mCurrThread ebx
; Get connection descriptor address
mov eax,[%$coid]
mov esi,[ebx+tTCB.PCB]
call K_ConnDescAddr
jc near .Exit
; Fill in the fields in TCB
mLockCB ebx, tTCB
mov [ebx+tTCB.ConnDesc],edi
mov eax,[%$smsg]
mov [ebx+tTCB.SendBuf],eax
mov eax,[%$sparts]
mov [ebx+tTCB.SendSize],eax
mov eax,[%$rmsg]
mov [ebx+tTCB.ReplyBuf],eax
mov eax,[%$rparts]
mov [ebx+tTCB.ReplySize],eax
; Put the message into the send queue
mov esi,[edi+tConnDesc.ChanDesc]
mEnqueue dword [esi+tChanDesc.SendWaitQ], SendReplyNext, SendReplyPrev, ebx, tTCB, edx
mUnlockCB ebx, tTCB
; If there is somebody in the receive queue, wake him up
mov ebx,[esi+tChanDesc.ReceiveWaitQ]
or ebx,ebx
jz .Sleep
mDequeue dword [esi+tChanDesc.ReceiveWaitQ], RcvNext, RcvPrev, ebx, tTCB, edi
call MT_ThreadWakeup
; Block ourselves until we get reply or error
.Sleep: mCurrThread ebx
mov al,THRSTATE_SEND
cli
call MT_ThreadSleep
call MT_Schedule
; Get a status and free message descriptor
mov eax,[ebx+tTCB.MsgStatus]
.Exit: epilogue
ret
endp ;---------------------------------------------------------------
; int MsgSendv(int coid, const iov_t *siov, int sparts,
; const iov_t *riov, int rparts);
; int MsgSend(int coid, const void *smsg, int sbytes,
; void *rmsg, int rbytes);
; int MsgSendsv(int coid, const void *smsg, int sbytes,
; const iov_t *riov, int rparts);
; int MsgSendvs(int coid, const iov_t *siov, int sparts,
; void *rmsg, int rbytes);
proc sys_MsgSendv
jmp sys_MsgSendvnc
endp ;---------------------------------------------------------------
; int MsgReceivev(int chid, const iov_t *riov, int rparts,
; struct _msg_info *info);
; int MsgReceive(int chid, void *msg, int bytes,
; struct _msg_info *info);
proc sys_MsgReceivev
arg chid, msg, parts, info
prologue
; Get an address of channel descriptor
mCurrThread
mov esi,[eax+tTCB.PCB]
mov eax,[%$chid]
call K_ChanDescAddr
jc near .Exit
; If there is a message or pulse pending, we won't block
.WaitLoop: mov ebx,[esi+tChanDesc.PulseQueue]
or ebx,ebx
jnz near .GotPulse
mov ebx,[esi+tChanDesc.SendWaitQ]
or ebx,ebx
jnz .GotMsg
mCurrThread ebx
mEnqueue dword [esi+tChanDesc.ReceiveWaitQ], RcvNext, RcvPrev, ebx, tTCB, edx
mov al,THRSTATE_RECEIVE
cli
call MT_ThreadSleep
call MT_Schedule
jmp .WaitLoop
; Change sender status to REPLY-blocked
.GotMsg: mov byte [ebx+tTCB.State],THRSTATE_REPLY
; Copy the message
mov ecx,[%$parts]
xor edx,edx
mov edi,[%$msg]
call CopyVtoAct
jc near .Exit
mov ecx,eax
; Delete the TCB from the send queue and put it into a
; reply queue
mLockCB ebx, tTCB
mDequeue dword [esi+tChanDesc.SendWaitQ], SendReplyNext, SendReplyPrev, ebx, tTCB, edx
mEnqueue dword [esi+tChanDesc.ReplyWaitQ], SendReplyNext, SendReplyPrev, ebx, tTCB, edx
mUnlockCB ebx, tTCB
; Get a rcvid
mov esi,ebx
call K_PoolChunkNumber
jc .MkErrno
mov edx,eax
; Fill in the message information if it was requested
mov edi,[%$info]
or edi,edi
jz .OK
call FillMessageInfo
jc .Exit
mov [edi+tMsgInfo.MsgLen],ecx
.OK: mov eax,edx
.Exit: epilogue
ret
.MkErrno: mErrno
jmp .Exit
; We got a pulse. Simply copy it.
.GotPulse: mov ecx,[%$parts]
mov edi,[%$msg]
call CopyPulseToAct
jc .Exit
; Delete the descriptor from pulse queue and free it
mLockCB ebx, tPulseDesc
mDequeue dword [esi+tChanDesc.PulseQueue], Next, Prev, ebx, tPulseDesc, ecx
mUnlockCB ebx, tPulseDesc
call FreePulseDesc
jc .MkErrno
; Return 0, which means "pulse is received"
xor eax,eax
jmp .Exit
endp ;---------------------------------------------------------------
; int MsgReplyv(int rcvid, int status, const iov_t *riov, int rparts);
; int MsgReply(int rcvid, int status, const void *msg, int size);
proc sys_MsgReplyv
arg rcvid, status, msg, parts
prologue
; Get the sending TCB address
mov eax,[%$rcvid]
call K_DecodeRcvid
jc .Exit
; Copy the message
mov ecx,[%$parts]
xor edx,edx
mov esi,[%$msg]
call CopyVfromAct
jc .Exit
; Fill the status and remove the TCB from reply queue
mov edi,[ebx+tTCB.ConnDesc]
mov esi,[edi+tConnDesc.ChanDesc]
mov eax,[%$status]
mov [ebx+tTCB.MsgStatus],eax
mLockCB ebx, tTCB
mDequeue dword [esi+tChanDesc.ReplyWaitQ], SendReplyNext, SendReplyPrev, ebx, tTCB, ecx
mUnlockCB ebx, tTCB
; Finally, unblock the sender and return success
call MT_ThreadWakeup
xor eax,eax
.Exit: epilogue
ret
endp ;---------------------------------------------------------------
; int MsgError(int rcvid, int error);
proc sys_MsgError
arg rcvid, errno
prologue
; Get the sending TCB address
mov eax,[%$rcvid]
call K_DecodeRcvid
jc .Exit
; Set the status and thread's errno, then remove the TCB from
; the channel's reply wait queue
mov edi,[ebx+tTCB.ConnDesc]
mov esi,[edi+tConnDesc.ChanDesc]
Mov32 ebx+tTCB.MsgStatus,%$errno
mLockCB ebx, tTCB
mDequeue dword [esi+tChanDesc.ReplyWaitQ], SendReplyNext, SendReplyPrev, ebx, tTCB, edi
mUnlockCB ebx, tTCB
; Unblock the sender and return success
call MT_ThreadWakeup
xor eax,eax
.Exit: epilogue
ret
endp ;---------------------------------------------------------------
; int MsgReadv(int rcvid, const iov_t *riov, int rparts, int offset);
; int MsgRead(int rcvid, void *msg, int bytes, int offset);
proc sys_MsgReadv
arg rcvid, msg, parts, offs
prologue
; Get the sending TCB address
mov eax,[%$rcvid]
call K_DecodeRcvid
jc .Exit
; Copy the data
mov ecx,[%$parts]
mov edx,[%$offs]
mov edi,[%$msg]
call CopyVtoAct
.Exit: epilogue
ret
endp ;---------------------------------------------------------------
; int MsgWritev(int rcvid, const iov_t *iov, int parts, int offset);
; int MsgWrite(int rcvid, const void *msg, int size, int offset);
proc sys_MsgWritev
arg rcvid, msg, parts, offs
prologue
; Get the sending TCB address
mov eax,[%$rcvid]
call K_DecodeRcvid
jc .Exit
; Copy the data
mov ecx,[%$parts]
mov edx,[%$offs]
mov esi,[%$msg]
call CopyVfromAct
.Exit: epilogue
ret
endp ;---------------------------------------------------------------
; int MsgReadIOV(int rcvid, const struct iovec *iov, int parts,
; int offset, int flags);
proc sys_MsgReadIOV
arg rcvid, iov, parts, offset, flags
prologue
MISSINGSYSCALL
epilogue
ret
endp ;---------------------------------------------------------------
; int MsgSendPulse(int coid, int priority, int code, int value);
proc sys_MsgSendPulse
arg coid, priority, code, value
prologue
; Get an address of current TCB
mCurrThread ebx
; Get connection descriptor address
mov eax,[%$coid]
mov esi,[ebx+tTCB.PCB]
call K_ConnDescAddr
jc .Exit
; Send the pulse
mov al,[%$code]
mov ecx,[%$value]
call K_SendPulse
; No error
xor eax,eax
.Exit: epilogue
ret
endp ;---------------------------------------------------------------
; int MsgReceivePulsev(int chid, const iov_t *piov, int parts,
; struct _msg_info *info);
; int MsgReceivePulse(int chid, void *pulse, int bytes,
; struct _msg_info *info);
proc sys_MsgReceivePulsev
arg chid, pulse, parts, info
prologue
; Get an address of channel descriptor
mCurrThread
mov esi,[eax+tTCB.PCB]
mov eax,[%$chid]
call K_ChanDescAddr
jc near .MkErrno
; If pulse queue is empty - suspend ourselves
.WaitLoop: mov ebx,[esi+tChanDesc.PulseQueue]
or ebx,ebx
jnz .GotPulse
mCurrThread ebx
mEnqueue dword [esi+tChanDesc.ReceiveWaitQ], RcvNext, RcvPrev, ebx, tTCB, ecx
mov al,THRSTATE_RECEIVE
cli
call MT_ThreadSleep
call MT_Schedule
jmp .WaitLoop
; Copy the pulse
.GotPulse: mov ecx,[%$parts]
mov edi,[%$pulse]
call CopyPulseToAct
jc .Exit
; Delete the descriptor from pulse queue and free it
mLockCB ebx, tPulseDesc
mDequeue dword [esi+tChanDesc.PulseQueue], Next, Prev, ebx, tPulseDesc, ecx
mUnlockCB ebx, tPulseDesc
call FreePulseDesc
jc .MkErrno
; Return 0, that means "pulse is received"
xor eax,eax
.Exit: epilogue
ret
.MkErrno: mErrno
jmp .Exit
endp ;---------------------------------------------------------------
; int MsgKeyData(int rcvid, int oper, uint32 key, uint32 *newkey,
; const struct iovec *iov, int parts);
proc sys_MsgKeyData
arg rcvid, oper, key, newkey, iov, parts
prologue
MISSINGSYSCALL
epilogue
ret
endp ;---------------------------------------------------------------
; int MsgInfo(int rcvid, struct _msg_info *info);
proc sys_MsgInfo
arg rcvid, info
prologue
; Get the sending TCB address
mov eax,[%$rcvid]
call K_DecodeRcvid
jc .Exit
; Fill in the buffer
mov edi,[%$info]
call FillMessageInfo
.Exit: epilogue
ret
endp ;---------------------------------------------------------------
|
// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "message.h"
#include "daemon_rpc_version.h"
#include "serialization/json_object.h"
namespace cryptonote
{
namespace rpc
{
const char* Message::STATUS_OK = "OK";
const char* Message::STATUS_RETRY = "Retry";
const char* Message::STATUS_FAILED = "Failed";
const char* Message::STATUS_BAD_REQUEST = "Invalid request type";
const char* Message::STATUS_BAD_JSON = "Malformed json";
namespace
{
constexpr const char error_field[] = "error";
constexpr const char id_field[] = "id";
constexpr const char method_field[] = "method";
constexpr const char params_field[] = "params";
constexpr const char result_field[] = "result";
const rapidjson::Value& get_method_field(const rapidjson::Value& src)
{
const auto member = src.FindMember(method_field);
if (member == src.MemberEnd())
throw cryptonote::json::MISSING_KEY{method_field};
if (!member->value.IsString())
throw cryptonote::json::WRONG_TYPE{"Expected string"};
return member->value;
}
}
void Message::toJson(rapidjson::Writer<epee::byte_stream>& dest) const
{
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, status, status);
INSERT_INTO_JSON_OBJECT(dest, error_details, error_details);
INSERT_INTO_JSON_OBJECT(dest, rpc_version, DAEMON_RPC_VERSION_ZMQ);
doToJson(dest);
dest.EndObject();
}
void Message::fromJson(const rapidjson::Value& val)
{
GET_FROM_JSON_OBJECT(val, status, status);
GET_FROM_JSON_OBJECT(val, error_details, error_details);
GET_FROM_JSON_OBJECT(val, rpc_version, rpc_version);
}
FullMessage::FullMessage(const std::string& json_string, bool request)
{
doc.Parse(json_string.c_str());
if (doc.HasParseError() || !doc.IsObject())
{
throw cryptonote::json::PARSE_FAIL();
}
OBJECT_HAS_MEMBER_OR_THROW(doc, "jsonrpc")
if (request)
{
get_method_field(doc); // throws on errors
OBJECT_HAS_MEMBER_OR_THROW(doc, params_field)
}
else
{
if (!doc.HasMember(result_field) && !doc.HasMember(error_field))
{
throw cryptonote::json::MISSING_KEY("error/result");
}
}
}
std::string FullMessage::getRequestType() const
{
return get_method_field(doc).GetString();
}
const rapidjson::Value& FullMessage::getMessage() const
{
if (doc.HasMember(params_field))
{
return doc[params_field];
}
else if (doc.HasMember(result_field))
{
return doc[result_field];
}
//else
OBJECT_HAS_MEMBER_OR_THROW(doc, error_field)
return doc[error_field];
}
rapidjson::Value FullMessage::getMessageCopy()
{
return rapidjson::Value(getMessage(), doc.GetAllocator());
}
const rapidjson::Value& FullMessage::getID() const
{
OBJECT_HAS_MEMBER_OR_THROW(doc, id_field)
return doc[id_field];
}
cryptonote::rpc::error FullMessage::getError()
{
cryptonote::rpc::error err;
err.use = false;
if (doc.HasMember(error_field))
{
GET_FROM_JSON_OBJECT(doc, err, error);
err.use = true;
}
return err;
}
epee::byte_slice FullMessage::getRequest(const std::string& request, const Message& message, const unsigned id)
{
epee::byte_stream buffer;
{
rapidjson::Writer<epee::byte_stream> dest{buffer};
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, jsonrpc, (boost::string_ref{"2.0", 3}));
dest.Key(id_field);
json::toJsonValue(dest, id);
dest.Key(method_field);
json::toJsonValue(dest, request);
dest.Key(params_field);
message.toJson(dest);
dest.EndObject();
if (!dest.IsComplete())
throw std::logic_error{"Invalid JSON tree generated"};
}
return epee::byte_slice{std::move(buffer)};
}
epee::byte_slice FullMessage::getResponse(const Message& message, const rapidjson::Value& id)
{
epee::byte_stream buffer;
{
rapidjson::Writer<epee::byte_stream> dest{buffer};
dest.StartObject();
INSERT_INTO_JSON_OBJECT(dest, jsonrpc, (boost::string_ref{"2.0", 3}));
dest.Key(id_field);
json::toJsonValue(dest, id);
if (message.status == Message::STATUS_OK)
{
dest.Key(result_field);
message.toJson(dest);
}
else
{
cryptonote::rpc::error err;
err.error_str = message.status;
err.message = message.error_details;
INSERT_INTO_JSON_OBJECT(dest, error, err);
}
dest.EndObject();
if (!dest.IsComplete())
throw std::logic_error{"Invalid JSON tree generated"};
}
return epee::byte_slice{std::move(buffer)};
}
// convenience functions for bad input
epee::byte_slice BAD_REQUEST(const std::string& request)
{
rapidjson::Value invalid;
return BAD_REQUEST(request, invalid);
}
epee::byte_slice BAD_REQUEST(const std::string& request, const rapidjson::Value& id)
{
Message fail;
fail.status = Message::STATUS_BAD_REQUEST;
fail.error_details = std::string("\"") + request + "\" is not a valid request.";
return FullMessage::getResponse(fail, id);
}
epee::byte_slice BAD_JSON(const std::string& error_details)
{
rapidjson::Value invalid;
Message fail;
fail.status = Message::STATUS_BAD_JSON;
fail.error_details = error_details;
return FullMessage::getResponse(fail, invalid);
}
} // namespace rpc
} // namespace cryptonote
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r14
push %rax
push %rbx
lea addresses_D_ht+0x2720, %r14
nop
nop
nop
cmp %rax, %rax
mov $0x6162636465666768, %r11
movq %r11, %xmm7
vmovups %ymm7, (%r14)
add %rbx, %rbx
pop %rbx
pop %rax
pop %r14
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r13
push %r15
push %rbp
push %rbx
push %rcx
push %rsi
// Store
lea addresses_WT+0x6ef6, %rbx
clflush (%rbx)
nop
nop
nop
cmp %rcx, %rcx
movw $0x5152, (%rbx)
nop
nop
nop
nop
xor %rbx, %rbx
// Faulty Load
lea addresses_US+0x7ef6, %r15
nop
nop
nop
nop
inc %rbp
mov (%r15), %bx
lea oracles, %r13
and $0xff, %rbx
shlq $12, %rbx
mov (%r13,%rbx,1), %rbx
pop %rsi
pop %rcx
pop %rbx
pop %rbp
pop %r15
pop %r13
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_US'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 11, 'AVXalign': True, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_WT'}}
[Faulty Load]
{'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 2, 'NT': False, 'type': 'addresses_US'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'congruent': 1, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_D_ht'}}
{'52': 15}
52 52 52 52 52 52 52 52 52 52 52 52 52 52 52
*/
|
_assTest: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#define N_PAGES 24
char* data[N_PAGES];
volatile int main(int argc, char *argv[]) {
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 56 push %esi
e: 53 push %ebx
f: 51 push %ecx
int i = 0;
int n = N_PAGES;
for (i = 0; i < n ;)
10: 31 db xor %ebx,%ebx
volatile int main(int argc, char *argv[]) {
12: 83 ec 0c sub $0xc,%esp
15: 8d 76 00 lea 0x0(%esi),%esi
{
data[i] = sbrk(PGSIZE);
18: 83 ec 0c sub $0xc,%esp
1b: 68 00 10 00 00 push $0x1000
20: e8 25 05 00 00 call 54a <sbrk>
25: 89 04 9d a0 0c 00 00 mov %eax,0xca0(,%ebx,4)
data[i][0] = 00 + i;
2c: 88 18 mov %bl,(%eax)
data[i][1] = 10 + i;
2e: 8d 53 0a lea 0xa(%ebx),%edx
31: 8b 04 9d a0 0c 00 00 mov 0xca0(,%ebx,4),%eax
38: 88 50 01 mov %dl,0x1(%eax)
data[i][2] = 20 + i;
3b: 8b 04 9d a0 0c 00 00 mov 0xca0(,%ebx,4),%eax
42: 8d 53 14 lea 0x14(%ebx),%edx
45: 88 50 02 mov %dl,0x2(%eax)
data[i][3] = 30 + i;
48: 8b 04 9d a0 0c 00 00 mov 0xca0(,%ebx,4),%eax
4f: 8d 53 1e lea 0x1e(%ebx),%edx
52: 88 50 03 mov %dl,0x3(%eax)
data[i][4] = 40 + i;
55: 8b 04 9d a0 0c 00 00 mov 0xca0(,%ebx,4),%eax
5c: 8d 53 28 lea 0x28(%ebx),%edx
5f: 88 50 04 mov %dl,0x4(%eax)
data[i][5] = 50 + i;
62: 8b 04 9d a0 0c 00 00 mov 0xca0(,%ebx,4),%eax
69: 8d 53 32 lea 0x32(%ebx),%edx
6c: 88 50 05 mov %dl,0x5(%eax)
data[i][6] = 60 + i;
6f: 8b 04 9d a0 0c 00 00 mov 0xca0(,%ebx,4),%eax
76: 8d 53 3c lea 0x3c(%ebx),%edx
79: 88 50 06 mov %dl,0x6(%eax)
data[i][7] = 70 + i;
7c: 8b 04 9d a0 0c 00 00 mov 0xca0(,%ebx,4),%eax
83: 8d 53 46 lea 0x46(%ebx),%edx
86: 88 50 07 mov %dl,0x7(%eax)
printf(1, "allocated new page #%d in: %x\n", i, data[i]);
89: ff 34 9d a0 0c 00 00 pushl 0xca0(,%ebx,4)
90: 53 push %ebx
91: 68 68 09 00 00 push $0x968
i++;
96: 83 c3 01 add $0x1,%ebx
printf(1, "allocated new page #%d in: %x\n", i, data[i]);
99: 6a 01 push $0x1
9b: e8 70 05 00 00 call 610 <printf>
for (i = 0; i < n ;)
a0: 83 c4 20 add $0x20,%esp
a3: 83 fb 18 cmp $0x18,%ebx
a6: 0f 85 6c ff ff ff jne 18 <main+0x18>
}
int j;
for(j = 1; j < n; j++)
ac: be 01 00 00 00 mov $0x1,%esi
b1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
{
printf(1,"j: %d\n",j);
b8: 83 ec 04 sub $0x4,%esp
for(i = 0; i < j; i++) {
bb: 31 db xor %ebx,%ebx
printf(1,"j: %d\n",j);
bd: 56 push %esi
be: 68 bc 09 00 00 push $0x9bc
c3: 6a 01 push $0x1
c5: e8 46 05 00 00 call 610 <printf>
ca: 83 c4 10 add $0x10,%esp
cd: 8d 76 00 lea 0x0(%esi),%esi
data[i][10] = 2; // access to the i-th page
d0: 8b 04 9d a0 0c 00 00 mov 0xca0(,%ebx,4),%eax
printf(1,"%d, ",i);
d7: 83 ec 04 sub $0x4,%esp
data[i][10] = 2; // access to the i-th page
da: c6 40 0a 02 movb $0x2,0xa(%eax)
printf(1,"%d, ",i);
de: 53 push %ebx
for(i = 0; i < j; i++) {
df: 83 c3 01 add $0x1,%ebx
printf(1,"%d, ",i);
e2: 68 c4 09 00 00 push $0x9c4
e7: 6a 01 push $0x1
e9: e8 22 05 00 00 call 610 <printf>
for(i = 0; i < j; i++) {
ee: 83 c4 10 add $0x10,%esp
f1: 39 f3 cmp %esi,%ebx
f3: 75 db jne d0 <main+0xd0>
}
printf(1,"\n");
f5: 83 ec 08 sub $0x8,%esp
for(j = 1; j < n; j++)
f8: 8d 73 01 lea 0x1(%ebx),%esi
printf(1,"\n");
fb: 68 c2 09 00 00 push $0x9c2
100: 6a 01 push $0x1
102: e8 09 05 00 00 call 610 <printf>
for(j = 1; j < n; j++)
107: 83 c4 10 add $0x10,%esp
10a: 83 fe 18 cmp $0x18,%esi
10d: 75 a9 jne b8 <main+0xb8>
}
int k;
int pid = fork();
10f: e8 a6 03 00 00 call 4ba <fork>
if (pid)
114: 85 c0 test %eax,%eax
116: 74 0a je 122 <main+0x122>
wait();
118: e8 ad 03 00 00 call 4ca <wait>
// data[j][10] = 0;
// printf(1,"%d, ",j);
printf(1,"\n");
}
}
exit();
11d: e8 a0 03 00 00 call 4c2 <exit>
printf(1, "\nGo through same 8 pages and different 8 others\n");
122: 50 push %eax
123: 50 push %eax
for(j = 0; j < 8; j++){
124: 31 f6 xor %esi,%esi
printf(1, "\nGo through same 8 pages and different 8 others\n");
126: 68 88 09 00 00 push $0x988
12b: 6a 01 push $0x1
12d: e8 de 04 00 00 call 610 <printf>
132: 83 c4 10 add $0x10,%esp
135: 8d 76 00 lea 0x0(%esi),%esi
for(i = 20; i < 24; i++) {
138: bb 14 00 00 00 mov $0x14,%ebx
data[i][10] = 1;
13d: 8b 04 9d a0 0c 00 00 mov 0xca0(,%ebx,4),%eax
printf(1,"%d, ",i);
144: 83 ec 04 sub $0x4,%esp
data[i][10] = 1;
147: c6 40 0a 01 movb $0x1,0xa(%eax)
printf(1,"%d, ",i);
14b: 53 push %ebx
for(i = 20; i < 24; i++) {
14c: 83 c3 01 add $0x1,%ebx
printf(1,"%d, ",i);
14f: 68 c4 09 00 00 push $0x9c4
154: 6a 01 push $0x1
156: e8 b5 04 00 00 call 610 <printf>
for(i = 20; i < 24; i++) {
15b: 83 c4 10 add $0x10,%esp
15e: 83 fb 18 cmp $0x18,%ebx
161: 75 da jne 13d <main+0x13d>
printf(1,"\n");
163: 83 ec 08 sub $0x8,%esp
166: 68 c2 09 00 00 push $0x9c2
16b: 6a 01 push $0x1
16d: e8 9e 04 00 00 call 610 <printf>
switch (j%4) {
172: 89 f0 mov %esi,%eax
174: 83 c4 10 add $0x10,%esp
177: 83 e0 03 and $0x3,%eax
17a: 83 f8 02 cmp $0x2,%eax
17d: 0f 84 af 00 00 00 je 232 <main+0x232>
183: 83 f8 03 cmp $0x3,%eax
186: 74 7d je 205 <main+0x205>
188: 83 f8 01 cmp $0x1,%eax
18b: 74 4b je 1d8 <main+0x1d8>
for(k = 0; k < 4; k++) {
18d: 31 db xor %ebx,%ebx
data[k][10] = 1;
18f: 8b 04 9d a0 0c 00 00 mov 0xca0(,%ebx,4),%eax
printf(1,"%d, ",k);
196: 83 ec 04 sub $0x4,%esp
data[k][10] = 1;
199: c6 40 0a 01 movb $0x1,0xa(%eax)
printf(1,"%d, ",k);
19d: 53 push %ebx
for(k = 0; k < 4; k++) {
19e: 83 c3 01 add $0x1,%ebx
printf(1,"%d, ",k);
1a1: 68 c4 09 00 00 push $0x9c4
1a6: 6a 01 push $0x1
1a8: e8 63 04 00 00 call 610 <printf>
for(k = 0; k < 4; k++) {
1ad: 83 c4 10 add $0x10,%esp
1b0: 83 fb 04 cmp $0x4,%ebx
1b3: 75 da jne 18f <main+0x18f>
printf(1,"\n");
1b5: 83 ec 08 sub $0x8,%esp
for(j = 0; j < 8; j++){
1b8: 83 c6 01 add $0x1,%esi
printf(1,"\n");
1bb: 68 c2 09 00 00 push $0x9c2
1c0: 6a 01 push $0x1
1c2: e8 49 04 00 00 call 610 <printf>
for(j = 0; j < 8; j++){
1c7: 83 c4 10 add $0x10,%esp
1ca: 83 fe 08 cmp $0x8,%esi
1cd: 0f 85 65 ff ff ff jne 138 <main+0x138>
1d3: e9 45 ff ff ff jmp 11d <main+0x11d>
for(k = 4; k < 8; k++) {
1d8: bb 04 00 00 00 mov $0x4,%ebx
data[k][10] = 1;
1dd: 8b 04 9d a0 0c 00 00 mov 0xca0(,%ebx,4),%eax
printf(1,"%d, ",k);
1e4: 83 ec 04 sub $0x4,%esp
data[k][10] = 1;
1e7: c6 40 0a 01 movb $0x1,0xa(%eax)
printf(1,"%d, ",k);
1eb: 53 push %ebx
for(k = 4; k < 8; k++) {
1ec: 83 c3 01 add $0x1,%ebx
printf(1,"%d, ",k);
1ef: 68 c4 09 00 00 push $0x9c4
1f4: 6a 01 push $0x1
1f6: e8 15 04 00 00 call 610 <printf>
for(k = 4; k < 8; k++) {
1fb: 83 c4 10 add $0x10,%esp
1fe: 83 fb 08 cmp $0x8,%ebx
201: 75 da jne 1dd <main+0x1dd>
203: eb b0 jmp 1b5 <main+0x1b5>
for(k = 12; k < 16; k++) {
205: bb 0c 00 00 00 mov $0xc,%ebx
data[k][10] = 1;
20a: 8b 04 9d a0 0c 00 00 mov 0xca0(,%ebx,4),%eax
printf(1,"%d, ",k);
211: 83 ec 04 sub $0x4,%esp
data[k][10] = 1;
214: c6 40 0a 01 movb $0x1,0xa(%eax)
printf(1,"%d, ",k);
218: 53 push %ebx
for(k = 12; k < 16; k++) {
219: 83 c3 01 add $0x1,%ebx
printf(1,"%d, ",k);
21c: 68 c4 09 00 00 push $0x9c4
221: 6a 01 push $0x1
223: e8 e8 03 00 00 call 610 <printf>
for(k = 12; k < 16; k++) {
228: 83 c4 10 add $0x10,%esp
22b: 83 fb 10 cmp $0x10,%ebx
22e: 75 da jne 20a <main+0x20a>
230: eb 83 jmp 1b5 <main+0x1b5>
for(k = 8; k < 12; k++) {
232: bb 08 00 00 00 mov $0x8,%ebx
data[k][10] = 1;
237: 8b 04 9d a0 0c 00 00 mov 0xca0(,%ebx,4),%eax
printf(1,"%d, ",k);
23e: 83 ec 04 sub $0x4,%esp
data[k][10] = 1;
241: c6 40 0a 01 movb $0x1,0xa(%eax)
printf(1,"%d, ",k);
245: 53 push %ebx
for(k = 8; k < 12; k++) {
246: 83 c3 01 add $0x1,%ebx
printf(1,"%d, ",k);
249: 68 c4 09 00 00 push $0x9c4
24e: 6a 01 push $0x1
250: e8 bb 03 00 00 call 610 <printf>
for(k = 8; k < 12; k++) {
255: 83 c4 10 add $0x10,%esp
258: 83 fb 0c cmp $0xc,%ebx
25b: 75 da jne 237 <main+0x237>
25d: e9 53 ff ff ff jmp 1b5 <main+0x1b5>
262: 66 90 xchg %ax,%ax
264: 66 90 xchg %ax,%ax
266: 66 90 xchg %ax,%ax
268: 66 90 xchg %ax,%ax
26a: 66 90 xchg %ax,%ax
26c: 66 90 xchg %ax,%ax
26e: 66 90 xchg %ax,%ax
00000270 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
270: 55 push %ebp
271: 89 e5 mov %esp,%ebp
273: 53 push %ebx
274: 8b 45 08 mov 0x8(%ebp),%eax
277: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
27a: 89 c2 mov %eax,%edx
27c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
280: 83 c1 01 add $0x1,%ecx
283: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
287: 83 c2 01 add $0x1,%edx
28a: 84 db test %bl,%bl
28c: 88 5a ff mov %bl,-0x1(%edx)
28f: 75 ef jne 280 <strcpy+0x10>
;
return os;
}
291: 5b pop %ebx
292: 5d pop %ebp
293: c3 ret
294: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
29a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
000002a0 <strcmp>:
int
strcmp(const char *p, const char *q)
{
2a0: 55 push %ebp
2a1: 89 e5 mov %esp,%ebp
2a3: 53 push %ebx
2a4: 8b 55 08 mov 0x8(%ebp),%edx
2a7: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
2aa: 0f b6 02 movzbl (%edx),%eax
2ad: 0f b6 19 movzbl (%ecx),%ebx
2b0: 84 c0 test %al,%al
2b2: 75 1c jne 2d0 <strcmp+0x30>
2b4: eb 2a jmp 2e0 <strcmp+0x40>
2b6: 8d 76 00 lea 0x0(%esi),%esi
2b9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
2c0: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
2c3: 0f b6 02 movzbl (%edx),%eax
p++, q++;
2c6: 83 c1 01 add $0x1,%ecx
2c9: 0f b6 19 movzbl (%ecx),%ebx
while(*p && *p == *q)
2cc: 84 c0 test %al,%al
2ce: 74 10 je 2e0 <strcmp+0x40>
2d0: 38 d8 cmp %bl,%al
2d2: 74 ec je 2c0 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
2d4: 29 d8 sub %ebx,%eax
}
2d6: 5b pop %ebx
2d7: 5d pop %ebp
2d8: c3 ret
2d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
2e0: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
2e2: 29 d8 sub %ebx,%eax
}
2e4: 5b pop %ebx
2e5: 5d pop %ebp
2e6: c3 ret
2e7: 89 f6 mov %esi,%esi
2e9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000002f0 <strlen>:
uint
strlen(const char *s)
{
2f0: 55 push %ebp
2f1: 89 e5 mov %esp,%ebp
2f3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
2f6: 80 39 00 cmpb $0x0,(%ecx)
2f9: 74 15 je 310 <strlen+0x20>
2fb: 31 d2 xor %edx,%edx
2fd: 8d 76 00 lea 0x0(%esi),%esi
300: 83 c2 01 add $0x1,%edx
303: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
307: 89 d0 mov %edx,%eax
309: 75 f5 jne 300 <strlen+0x10>
;
return n;
}
30b: 5d pop %ebp
30c: c3 ret
30d: 8d 76 00 lea 0x0(%esi),%esi
for(n = 0; s[n]; n++)
310: 31 c0 xor %eax,%eax
}
312: 5d pop %ebp
313: c3 ret
314: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
31a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000320 <memset>:
void*
memset(void *dst, int c, uint n)
{
320: 55 push %ebp
321: 89 e5 mov %esp,%ebp
323: 57 push %edi
324: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
327: 8b 4d 10 mov 0x10(%ebp),%ecx
32a: 8b 45 0c mov 0xc(%ebp),%eax
32d: 89 d7 mov %edx,%edi
32f: fc cld
330: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
332: 89 d0 mov %edx,%eax
334: 5f pop %edi
335: 5d pop %ebp
336: c3 ret
337: 89 f6 mov %esi,%esi
339: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000340 <strchr>:
char*
strchr(const char *s, char c)
{
340: 55 push %ebp
341: 89 e5 mov %esp,%ebp
343: 53 push %ebx
344: 8b 45 08 mov 0x8(%ebp),%eax
347: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
34a: 0f b6 10 movzbl (%eax),%edx
34d: 84 d2 test %dl,%dl
34f: 74 1d je 36e <strchr+0x2e>
if(*s == c)
351: 38 d3 cmp %dl,%bl
353: 89 d9 mov %ebx,%ecx
355: 75 0d jne 364 <strchr+0x24>
357: eb 17 jmp 370 <strchr+0x30>
359: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
360: 38 ca cmp %cl,%dl
362: 74 0c je 370 <strchr+0x30>
for(; *s; s++)
364: 83 c0 01 add $0x1,%eax
367: 0f b6 10 movzbl (%eax),%edx
36a: 84 d2 test %dl,%dl
36c: 75 f2 jne 360 <strchr+0x20>
return (char*)s;
return 0;
36e: 31 c0 xor %eax,%eax
}
370: 5b pop %ebx
371: 5d pop %ebp
372: c3 ret
373: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
379: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000380 <gets>:
char*
gets(char *buf, int max)
{
380: 55 push %ebp
381: 89 e5 mov %esp,%ebp
383: 57 push %edi
384: 56 push %esi
385: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
386: 31 f6 xor %esi,%esi
388: 89 f3 mov %esi,%ebx
{
38a: 83 ec 1c sub $0x1c,%esp
38d: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
390: eb 2f jmp 3c1 <gets+0x41>
392: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
398: 8d 45 e7 lea -0x19(%ebp),%eax
39b: 83 ec 04 sub $0x4,%esp
39e: 6a 01 push $0x1
3a0: 50 push %eax
3a1: 6a 00 push $0x0
3a3: e8 32 01 00 00 call 4da <read>
if(cc < 1)
3a8: 83 c4 10 add $0x10,%esp
3ab: 85 c0 test %eax,%eax
3ad: 7e 1c jle 3cb <gets+0x4b>
break;
buf[i++] = c;
3af: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
3b3: 83 c7 01 add $0x1,%edi
3b6: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
3b9: 3c 0a cmp $0xa,%al
3bb: 74 23 je 3e0 <gets+0x60>
3bd: 3c 0d cmp $0xd,%al
3bf: 74 1f je 3e0 <gets+0x60>
for(i=0; i+1 < max; ){
3c1: 83 c3 01 add $0x1,%ebx
3c4: 3b 5d 0c cmp 0xc(%ebp),%ebx
3c7: 89 fe mov %edi,%esi
3c9: 7c cd jl 398 <gets+0x18>
3cb: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
3cd: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
3d0: c6 03 00 movb $0x0,(%ebx)
}
3d3: 8d 65 f4 lea -0xc(%ebp),%esp
3d6: 5b pop %ebx
3d7: 5e pop %esi
3d8: 5f pop %edi
3d9: 5d pop %ebp
3da: c3 ret
3db: 90 nop
3dc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
3e0: 8b 75 08 mov 0x8(%ebp),%esi
3e3: 8b 45 08 mov 0x8(%ebp),%eax
3e6: 01 de add %ebx,%esi
3e8: 89 f3 mov %esi,%ebx
buf[i] = '\0';
3ea: c6 03 00 movb $0x0,(%ebx)
}
3ed: 8d 65 f4 lea -0xc(%ebp),%esp
3f0: 5b pop %ebx
3f1: 5e pop %esi
3f2: 5f pop %edi
3f3: 5d pop %ebp
3f4: c3 ret
3f5: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
3f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000400 <stat>:
int
stat(const char *n, struct stat *st)
{
400: 55 push %ebp
401: 89 e5 mov %esp,%ebp
403: 56 push %esi
404: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
405: 83 ec 08 sub $0x8,%esp
408: 6a 00 push $0x0
40a: ff 75 08 pushl 0x8(%ebp)
40d: e8 f0 00 00 00 call 502 <open>
if(fd < 0)
412: 83 c4 10 add $0x10,%esp
415: 85 c0 test %eax,%eax
417: 78 27 js 440 <stat+0x40>
return -1;
r = fstat(fd, st);
419: 83 ec 08 sub $0x8,%esp
41c: ff 75 0c pushl 0xc(%ebp)
41f: 89 c3 mov %eax,%ebx
421: 50 push %eax
422: e8 f3 00 00 00 call 51a <fstat>
close(fd);
427: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
42a: 89 c6 mov %eax,%esi
close(fd);
42c: e8 b9 00 00 00 call 4ea <close>
return r;
431: 83 c4 10 add $0x10,%esp
}
434: 8d 65 f8 lea -0x8(%ebp),%esp
437: 89 f0 mov %esi,%eax
439: 5b pop %ebx
43a: 5e pop %esi
43b: 5d pop %ebp
43c: c3 ret
43d: 8d 76 00 lea 0x0(%esi),%esi
return -1;
440: be ff ff ff ff mov $0xffffffff,%esi
445: eb ed jmp 434 <stat+0x34>
447: 89 f6 mov %esi,%esi
449: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000450 <atoi>:
int
atoi(const char *s)
{
450: 55 push %ebp
451: 89 e5 mov %esp,%ebp
453: 53 push %ebx
454: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
457: 0f be 11 movsbl (%ecx),%edx
45a: 8d 42 d0 lea -0x30(%edx),%eax
45d: 3c 09 cmp $0x9,%al
n = 0;
45f: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
464: 77 1f ja 485 <atoi+0x35>
466: 8d 76 00 lea 0x0(%esi),%esi
469: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
470: 8d 04 80 lea (%eax,%eax,4),%eax
473: 83 c1 01 add $0x1,%ecx
476: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
while('0' <= *s && *s <= '9')
47a: 0f be 11 movsbl (%ecx),%edx
47d: 8d 5a d0 lea -0x30(%edx),%ebx
480: 80 fb 09 cmp $0x9,%bl
483: 76 eb jbe 470 <atoi+0x20>
return n;
}
485: 5b pop %ebx
486: 5d pop %ebp
487: c3 ret
488: 90 nop
489: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000490 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
490: 55 push %ebp
491: 89 e5 mov %esp,%ebp
493: 56 push %esi
494: 53 push %ebx
495: 8b 5d 10 mov 0x10(%ebp),%ebx
498: 8b 45 08 mov 0x8(%ebp),%eax
49b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
49e: 85 db test %ebx,%ebx
4a0: 7e 14 jle 4b6 <memmove+0x26>
4a2: 31 d2 xor %edx,%edx
4a4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
4a8: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
4ac: 88 0c 10 mov %cl,(%eax,%edx,1)
4af: 83 c2 01 add $0x1,%edx
while(n-- > 0)
4b2: 39 d3 cmp %edx,%ebx
4b4: 75 f2 jne 4a8 <memmove+0x18>
return vdst;
}
4b6: 5b pop %ebx
4b7: 5e pop %esi
4b8: 5d pop %ebp
4b9: c3 ret
000004ba <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
4ba: b8 01 00 00 00 mov $0x1,%eax
4bf: cd 40 int $0x40
4c1: c3 ret
000004c2 <exit>:
SYSCALL(exit)
4c2: b8 02 00 00 00 mov $0x2,%eax
4c7: cd 40 int $0x40
4c9: c3 ret
000004ca <wait>:
SYSCALL(wait)
4ca: b8 03 00 00 00 mov $0x3,%eax
4cf: cd 40 int $0x40
4d1: c3 ret
000004d2 <pipe>:
SYSCALL(pipe)
4d2: b8 04 00 00 00 mov $0x4,%eax
4d7: cd 40 int $0x40
4d9: c3 ret
000004da <read>:
SYSCALL(read)
4da: b8 05 00 00 00 mov $0x5,%eax
4df: cd 40 int $0x40
4e1: c3 ret
000004e2 <write>:
SYSCALL(write)
4e2: b8 10 00 00 00 mov $0x10,%eax
4e7: cd 40 int $0x40
4e9: c3 ret
000004ea <close>:
SYSCALL(close)
4ea: b8 15 00 00 00 mov $0x15,%eax
4ef: cd 40 int $0x40
4f1: c3 ret
000004f2 <kill>:
SYSCALL(kill)
4f2: b8 06 00 00 00 mov $0x6,%eax
4f7: cd 40 int $0x40
4f9: c3 ret
000004fa <exec>:
SYSCALL(exec)
4fa: b8 07 00 00 00 mov $0x7,%eax
4ff: cd 40 int $0x40
501: c3 ret
00000502 <open>:
SYSCALL(open)
502: b8 0f 00 00 00 mov $0xf,%eax
507: cd 40 int $0x40
509: c3 ret
0000050a <mknod>:
SYSCALL(mknod)
50a: b8 11 00 00 00 mov $0x11,%eax
50f: cd 40 int $0x40
511: c3 ret
00000512 <unlink>:
SYSCALL(unlink)
512: b8 12 00 00 00 mov $0x12,%eax
517: cd 40 int $0x40
519: c3 ret
0000051a <fstat>:
SYSCALL(fstat)
51a: b8 08 00 00 00 mov $0x8,%eax
51f: cd 40 int $0x40
521: c3 ret
00000522 <link>:
SYSCALL(link)
522: b8 13 00 00 00 mov $0x13,%eax
527: cd 40 int $0x40
529: c3 ret
0000052a <mkdir>:
SYSCALL(mkdir)
52a: b8 14 00 00 00 mov $0x14,%eax
52f: cd 40 int $0x40
531: c3 ret
00000532 <chdir>:
SYSCALL(chdir)
532: b8 09 00 00 00 mov $0x9,%eax
537: cd 40 int $0x40
539: c3 ret
0000053a <dup>:
SYSCALL(dup)
53a: b8 0a 00 00 00 mov $0xa,%eax
53f: cd 40 int $0x40
541: c3 ret
00000542 <getpid>:
SYSCALL(getpid)
542: b8 0b 00 00 00 mov $0xb,%eax
547: cd 40 int $0x40
549: c3 ret
0000054a <sbrk>:
SYSCALL(sbrk)
54a: b8 0c 00 00 00 mov $0xc,%eax
54f: cd 40 int $0x40
551: c3 ret
00000552 <sleep>:
SYSCALL(sleep)
552: b8 0d 00 00 00 mov $0xd,%eax
557: cd 40 int $0x40
559: c3 ret
0000055a <uptime>:
SYSCALL(uptime)
55a: b8 0e 00 00 00 mov $0xe,%eax
55f: cd 40 int $0x40
561: c3 ret
562: 66 90 xchg %ax,%ax
564: 66 90 xchg %ax,%ax
566: 66 90 xchg %ax,%ax
568: 66 90 xchg %ax,%ax
56a: 66 90 xchg %ax,%ax
56c: 66 90 xchg %ax,%ax
56e: 66 90 xchg %ax,%ax
00000570 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
570: 55 push %ebp
571: 89 e5 mov %esp,%ebp
573: 57 push %edi
574: 56 push %esi
575: 53 push %ebx
576: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
579: 85 d2 test %edx,%edx
{
57b: 89 45 c0 mov %eax,-0x40(%ebp)
neg = 1;
x = -xx;
57e: 89 d0 mov %edx,%eax
if(sgn && xx < 0){
580: 79 76 jns 5f8 <printint+0x88>
582: f6 45 08 01 testb $0x1,0x8(%ebp)
586: 74 70 je 5f8 <printint+0x88>
x = -xx;
588: f7 d8 neg %eax
neg = 1;
58a: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
} else {
x = xx;
}
i = 0;
591: 31 f6 xor %esi,%esi
593: 8d 5d d7 lea -0x29(%ebp),%ebx
596: eb 0a jmp 5a2 <printint+0x32>
598: 90 nop
599: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
do{
buf[i++] = digits[x % base];
5a0: 89 fe mov %edi,%esi
5a2: 31 d2 xor %edx,%edx
5a4: 8d 7e 01 lea 0x1(%esi),%edi
5a7: f7 f1 div %ecx
5a9: 0f b6 92 d0 09 00 00 movzbl 0x9d0(%edx),%edx
}while((x /= base) != 0);
5b0: 85 c0 test %eax,%eax
buf[i++] = digits[x % base];
5b2: 88 14 3b mov %dl,(%ebx,%edi,1)
}while((x /= base) != 0);
5b5: 75 e9 jne 5a0 <printint+0x30>
if(neg)
5b7: 8b 45 c4 mov -0x3c(%ebp),%eax
5ba: 85 c0 test %eax,%eax
5bc: 74 08 je 5c6 <printint+0x56>
buf[i++] = '-';
5be: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1)
5c3: 8d 7e 02 lea 0x2(%esi),%edi
5c6: 8d 74 3d d7 lea -0x29(%ebp,%edi,1),%esi
5ca: 8b 7d c0 mov -0x40(%ebp),%edi
5cd: 8d 76 00 lea 0x0(%esi),%esi
5d0: 0f b6 06 movzbl (%esi),%eax
write(fd, &c, 1);
5d3: 83 ec 04 sub $0x4,%esp
5d6: 83 ee 01 sub $0x1,%esi
5d9: 6a 01 push $0x1
5db: 53 push %ebx
5dc: 57 push %edi
5dd: 88 45 d7 mov %al,-0x29(%ebp)
5e0: e8 fd fe ff ff call 4e2 <write>
while(--i >= 0)
5e5: 83 c4 10 add $0x10,%esp
5e8: 39 de cmp %ebx,%esi
5ea: 75 e4 jne 5d0 <printint+0x60>
putc(fd, buf[i]);
}
5ec: 8d 65 f4 lea -0xc(%ebp),%esp
5ef: 5b pop %ebx
5f0: 5e pop %esi
5f1: 5f pop %edi
5f2: 5d pop %ebp
5f3: c3 ret
5f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
5f8: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
5ff: eb 90 jmp 591 <printint+0x21>
601: eb 0d jmp 610 <printf>
603: 90 nop
604: 90 nop
605: 90 nop
606: 90 nop
607: 90 nop
608: 90 nop
609: 90 nop
60a: 90 nop
60b: 90 nop
60c: 90 nop
60d: 90 nop
60e: 90 nop
60f: 90 nop
00000610 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
610: 55 push %ebp
611: 89 e5 mov %esp,%ebp
613: 57 push %edi
614: 56 push %esi
615: 53 push %ebx
616: 83 ec 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
619: 8b 75 0c mov 0xc(%ebp),%esi
61c: 0f b6 1e movzbl (%esi),%ebx
61f: 84 db test %bl,%bl
621: 0f 84 b3 00 00 00 je 6da <printf+0xca>
ap = (uint*)(void*)&fmt + 1;
627: 8d 45 10 lea 0x10(%ebp),%eax
62a: 83 c6 01 add $0x1,%esi
state = 0;
62d: 31 ff xor %edi,%edi
ap = (uint*)(void*)&fmt + 1;
62f: 89 45 d4 mov %eax,-0x2c(%ebp)
632: eb 2f jmp 663 <printf+0x53>
634: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
638: 83 f8 25 cmp $0x25,%eax
63b: 0f 84 a7 00 00 00 je 6e8 <printf+0xd8>
write(fd, &c, 1);
641: 8d 45 e2 lea -0x1e(%ebp),%eax
644: 83 ec 04 sub $0x4,%esp
647: 88 5d e2 mov %bl,-0x1e(%ebp)
64a: 6a 01 push $0x1
64c: 50 push %eax
64d: ff 75 08 pushl 0x8(%ebp)
650: e8 8d fe ff ff call 4e2 <write>
655: 83 c4 10 add $0x10,%esp
658: 83 c6 01 add $0x1,%esi
for(i = 0; fmt[i]; i++){
65b: 0f b6 5e ff movzbl -0x1(%esi),%ebx
65f: 84 db test %bl,%bl
661: 74 77 je 6da <printf+0xca>
if(state == 0){
663: 85 ff test %edi,%edi
c = fmt[i] & 0xff;
665: 0f be cb movsbl %bl,%ecx
668: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
66b: 74 cb je 638 <printf+0x28>
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
66d: 83 ff 25 cmp $0x25,%edi
670: 75 e6 jne 658 <printf+0x48>
if(c == 'd'){
672: 83 f8 64 cmp $0x64,%eax
675: 0f 84 05 01 00 00 je 780 <printf+0x170>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
67b: 81 e1 f7 00 00 00 and $0xf7,%ecx
681: 83 f9 70 cmp $0x70,%ecx
684: 74 72 je 6f8 <printf+0xe8>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
686: 83 f8 73 cmp $0x73,%eax
689: 0f 84 99 00 00 00 je 728 <printf+0x118>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
68f: 83 f8 63 cmp $0x63,%eax
692: 0f 84 08 01 00 00 je 7a0 <printf+0x190>
putc(fd, *ap);
ap++;
} else if(c == '%'){
698: 83 f8 25 cmp $0x25,%eax
69b: 0f 84 ef 00 00 00 je 790 <printf+0x180>
write(fd, &c, 1);
6a1: 8d 45 e7 lea -0x19(%ebp),%eax
6a4: 83 ec 04 sub $0x4,%esp
6a7: c6 45 e7 25 movb $0x25,-0x19(%ebp)
6ab: 6a 01 push $0x1
6ad: 50 push %eax
6ae: ff 75 08 pushl 0x8(%ebp)
6b1: e8 2c fe ff ff call 4e2 <write>
6b6: 83 c4 0c add $0xc,%esp
6b9: 8d 45 e6 lea -0x1a(%ebp),%eax
6bc: 88 5d e6 mov %bl,-0x1a(%ebp)
6bf: 6a 01 push $0x1
6c1: 50 push %eax
6c2: ff 75 08 pushl 0x8(%ebp)
6c5: 83 c6 01 add $0x1,%esi
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
6c8: 31 ff xor %edi,%edi
write(fd, &c, 1);
6ca: e8 13 fe ff ff call 4e2 <write>
for(i = 0; fmt[i]; i++){
6cf: 0f b6 5e ff movzbl -0x1(%esi),%ebx
write(fd, &c, 1);
6d3: 83 c4 10 add $0x10,%esp
for(i = 0; fmt[i]; i++){
6d6: 84 db test %bl,%bl
6d8: 75 89 jne 663 <printf+0x53>
}
}
}
6da: 8d 65 f4 lea -0xc(%ebp),%esp
6dd: 5b pop %ebx
6de: 5e pop %esi
6df: 5f pop %edi
6e0: 5d pop %ebp
6e1: c3 ret
6e2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
state = '%';
6e8: bf 25 00 00 00 mov $0x25,%edi
6ed: e9 66 ff ff ff jmp 658 <printf+0x48>
6f2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
printint(fd, *ap, 16, 0);
6f8: 83 ec 0c sub $0xc,%esp
6fb: b9 10 00 00 00 mov $0x10,%ecx
700: 6a 00 push $0x0
702: 8b 7d d4 mov -0x2c(%ebp),%edi
705: 8b 45 08 mov 0x8(%ebp),%eax
708: 8b 17 mov (%edi),%edx
70a: e8 61 fe ff ff call 570 <printint>
ap++;
70f: 89 f8 mov %edi,%eax
711: 83 c4 10 add $0x10,%esp
state = 0;
714: 31 ff xor %edi,%edi
ap++;
716: 83 c0 04 add $0x4,%eax
719: 89 45 d4 mov %eax,-0x2c(%ebp)
71c: e9 37 ff ff ff jmp 658 <printf+0x48>
721: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
s = (char*)*ap;
728: 8b 45 d4 mov -0x2c(%ebp),%eax
72b: 8b 08 mov (%eax),%ecx
ap++;
72d: 83 c0 04 add $0x4,%eax
730: 89 45 d4 mov %eax,-0x2c(%ebp)
if(s == 0)
733: 85 c9 test %ecx,%ecx
735: 0f 84 8e 00 00 00 je 7c9 <printf+0x1b9>
while(*s != 0){
73b: 0f b6 01 movzbl (%ecx),%eax
state = 0;
73e: 31 ff xor %edi,%edi
s = (char*)*ap;
740: 89 cb mov %ecx,%ebx
while(*s != 0){
742: 84 c0 test %al,%al
744: 0f 84 0e ff ff ff je 658 <printf+0x48>
74a: 89 75 d0 mov %esi,-0x30(%ebp)
74d: 89 de mov %ebx,%esi
74f: 8b 5d 08 mov 0x8(%ebp),%ebx
752: 8d 7d e3 lea -0x1d(%ebp),%edi
755: 8d 76 00 lea 0x0(%esi),%esi
write(fd, &c, 1);
758: 83 ec 04 sub $0x4,%esp
s++;
75b: 83 c6 01 add $0x1,%esi
75e: 88 45 e3 mov %al,-0x1d(%ebp)
write(fd, &c, 1);
761: 6a 01 push $0x1
763: 57 push %edi
764: 53 push %ebx
765: e8 78 fd ff ff call 4e2 <write>
while(*s != 0){
76a: 0f b6 06 movzbl (%esi),%eax
76d: 83 c4 10 add $0x10,%esp
770: 84 c0 test %al,%al
772: 75 e4 jne 758 <printf+0x148>
774: 8b 75 d0 mov -0x30(%ebp),%esi
state = 0;
777: 31 ff xor %edi,%edi
779: e9 da fe ff ff jmp 658 <printf+0x48>
77e: 66 90 xchg %ax,%ax
printint(fd, *ap, 10, 1);
780: 83 ec 0c sub $0xc,%esp
783: b9 0a 00 00 00 mov $0xa,%ecx
788: 6a 01 push $0x1
78a: e9 73 ff ff ff jmp 702 <printf+0xf2>
78f: 90 nop
write(fd, &c, 1);
790: 83 ec 04 sub $0x4,%esp
793: 88 5d e5 mov %bl,-0x1b(%ebp)
796: 8d 45 e5 lea -0x1b(%ebp),%eax
799: 6a 01 push $0x1
79b: e9 21 ff ff ff jmp 6c1 <printf+0xb1>
putc(fd, *ap);
7a0: 8b 7d d4 mov -0x2c(%ebp),%edi
write(fd, &c, 1);
7a3: 83 ec 04 sub $0x4,%esp
putc(fd, *ap);
7a6: 8b 07 mov (%edi),%eax
write(fd, &c, 1);
7a8: 6a 01 push $0x1
ap++;
7aa: 83 c7 04 add $0x4,%edi
putc(fd, *ap);
7ad: 88 45 e4 mov %al,-0x1c(%ebp)
write(fd, &c, 1);
7b0: 8d 45 e4 lea -0x1c(%ebp),%eax
7b3: 50 push %eax
7b4: ff 75 08 pushl 0x8(%ebp)
7b7: e8 26 fd ff ff call 4e2 <write>
ap++;
7bc: 89 7d d4 mov %edi,-0x2c(%ebp)
7bf: 83 c4 10 add $0x10,%esp
state = 0;
7c2: 31 ff xor %edi,%edi
7c4: e9 8f fe ff ff jmp 658 <printf+0x48>
s = "(null)";
7c9: bb c9 09 00 00 mov $0x9c9,%ebx
while(*s != 0){
7ce: b8 28 00 00 00 mov $0x28,%eax
7d3: e9 72 ff ff ff jmp 74a <printf+0x13a>
7d8: 66 90 xchg %ax,%ax
7da: 66 90 xchg %ax,%ax
7dc: 66 90 xchg %ax,%ax
7de: 66 90 xchg %ax,%ax
000007e0 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
7e0: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
7e1: a1 80 0c 00 00 mov 0xc80,%eax
{
7e6: 89 e5 mov %esp,%ebp
7e8: 57 push %edi
7e9: 56 push %esi
7ea: 53 push %ebx
7eb: 8b 5d 08 mov 0x8(%ebp),%ebx
bp = (Header*)ap - 1;
7ee: 8d 4b f8 lea -0x8(%ebx),%ecx
7f1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
7f8: 39 c8 cmp %ecx,%eax
7fa: 8b 10 mov (%eax),%edx
7fc: 73 32 jae 830 <free+0x50>
7fe: 39 d1 cmp %edx,%ecx
800: 72 04 jb 806 <free+0x26>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
802: 39 d0 cmp %edx,%eax
804: 72 32 jb 838 <free+0x58>
break;
if(bp + bp->s.size == p->s.ptr){
806: 8b 73 fc mov -0x4(%ebx),%esi
809: 8d 3c f1 lea (%ecx,%esi,8),%edi
80c: 39 fa cmp %edi,%edx
80e: 74 30 je 840 <free+0x60>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
810: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
813: 8b 50 04 mov 0x4(%eax),%edx
816: 8d 34 d0 lea (%eax,%edx,8),%esi
819: 39 f1 cmp %esi,%ecx
81b: 74 3a je 857 <free+0x77>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
81d: 89 08 mov %ecx,(%eax)
freep = p;
81f: a3 80 0c 00 00 mov %eax,0xc80
}
824: 5b pop %ebx
825: 5e pop %esi
826: 5f pop %edi
827: 5d pop %ebp
828: c3 ret
829: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
830: 39 d0 cmp %edx,%eax
832: 72 04 jb 838 <free+0x58>
834: 39 d1 cmp %edx,%ecx
836: 72 ce jb 806 <free+0x26>
{
838: 89 d0 mov %edx,%eax
83a: eb bc jmp 7f8 <free+0x18>
83c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
bp->s.size += p->s.ptr->s.size;
840: 03 72 04 add 0x4(%edx),%esi
843: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
846: 8b 10 mov (%eax),%edx
848: 8b 12 mov (%edx),%edx
84a: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
84d: 8b 50 04 mov 0x4(%eax),%edx
850: 8d 34 d0 lea (%eax,%edx,8),%esi
853: 39 f1 cmp %esi,%ecx
855: 75 c6 jne 81d <free+0x3d>
p->s.size += bp->s.size;
857: 03 53 fc add -0x4(%ebx),%edx
freep = p;
85a: a3 80 0c 00 00 mov %eax,0xc80
p->s.size += bp->s.size;
85f: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
862: 8b 53 f8 mov -0x8(%ebx),%edx
865: 89 10 mov %edx,(%eax)
}
867: 5b pop %ebx
868: 5e pop %esi
869: 5f pop %edi
86a: 5d pop %ebp
86b: c3 ret
86c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000870 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
870: 55 push %ebp
871: 89 e5 mov %esp,%ebp
873: 57 push %edi
874: 56 push %esi
875: 53 push %ebx
876: 83 ec 0c sub $0xc,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
879: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
87c: 8b 15 80 0c 00 00 mov 0xc80,%edx
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
882: 8d 78 07 lea 0x7(%eax),%edi
885: c1 ef 03 shr $0x3,%edi
888: 83 c7 01 add $0x1,%edi
if((prevp = freep) == 0){
88b: 85 d2 test %edx,%edx
88d: 0f 84 9d 00 00 00 je 930 <malloc+0xc0>
893: 8b 02 mov (%edx),%eax
895: 8b 48 04 mov 0x4(%eax),%ecx
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
898: 39 cf cmp %ecx,%edi
89a: 76 6c jbe 908 <malloc+0x98>
89c: 81 ff 00 10 00 00 cmp $0x1000,%edi
8a2: bb 00 10 00 00 mov $0x1000,%ebx
8a7: 0f 43 df cmovae %edi,%ebx
p = sbrk(nu * sizeof(Header));
8aa: 8d 34 dd 00 00 00 00 lea 0x0(,%ebx,8),%esi
8b1: eb 0e jmp 8c1 <malloc+0x51>
8b3: 90 nop
8b4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
8b8: 8b 02 mov (%edx),%eax
if(p->s.size >= nunits){
8ba: 8b 48 04 mov 0x4(%eax),%ecx
8bd: 39 f9 cmp %edi,%ecx
8bf: 73 47 jae 908 <malloc+0x98>
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
8c1: 39 05 80 0c 00 00 cmp %eax,0xc80
8c7: 89 c2 mov %eax,%edx
8c9: 75 ed jne 8b8 <malloc+0x48>
p = sbrk(nu * sizeof(Header));
8cb: 83 ec 0c sub $0xc,%esp
8ce: 56 push %esi
8cf: e8 76 fc ff ff call 54a <sbrk>
if(p == (char*)-1)
8d4: 83 c4 10 add $0x10,%esp
8d7: 83 f8 ff cmp $0xffffffff,%eax
8da: 74 1c je 8f8 <malloc+0x88>
hp->s.size = nu;
8dc: 89 58 04 mov %ebx,0x4(%eax)
free((void*)(hp + 1));
8df: 83 ec 0c sub $0xc,%esp
8e2: 83 c0 08 add $0x8,%eax
8e5: 50 push %eax
8e6: e8 f5 fe ff ff call 7e0 <free>
return freep;
8eb: 8b 15 80 0c 00 00 mov 0xc80,%edx
if((p = morecore(nunits)) == 0)
8f1: 83 c4 10 add $0x10,%esp
8f4: 85 d2 test %edx,%edx
8f6: 75 c0 jne 8b8 <malloc+0x48>
return 0;
}
}
8f8: 8d 65 f4 lea -0xc(%ebp),%esp
return 0;
8fb: 31 c0 xor %eax,%eax
}
8fd: 5b pop %ebx
8fe: 5e pop %esi
8ff: 5f pop %edi
900: 5d pop %ebp
901: c3 ret
902: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
if(p->s.size == nunits)
908: 39 cf cmp %ecx,%edi
90a: 74 54 je 960 <malloc+0xf0>
p->s.size -= nunits;
90c: 29 f9 sub %edi,%ecx
90e: 89 48 04 mov %ecx,0x4(%eax)
p += p->s.size;
911: 8d 04 c8 lea (%eax,%ecx,8),%eax
p->s.size = nunits;
914: 89 78 04 mov %edi,0x4(%eax)
freep = prevp;
917: 89 15 80 0c 00 00 mov %edx,0xc80
}
91d: 8d 65 f4 lea -0xc(%ebp),%esp
return (void*)(p + 1);
920: 83 c0 08 add $0x8,%eax
}
923: 5b pop %ebx
924: 5e pop %esi
925: 5f pop %edi
926: 5d pop %ebp
927: c3 ret
928: 90 nop
929: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
base.s.ptr = freep = prevp = &base;
930: c7 05 80 0c 00 00 84 movl $0xc84,0xc80
937: 0c 00 00
93a: c7 05 84 0c 00 00 84 movl $0xc84,0xc84
941: 0c 00 00
base.s.size = 0;
944: b8 84 0c 00 00 mov $0xc84,%eax
949: c7 05 88 0c 00 00 00 movl $0x0,0xc88
950: 00 00 00
953: e9 44 ff ff ff jmp 89c <malloc+0x2c>
958: 90 nop
959: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
prevp->s.ptr = p->s.ptr;
960: 8b 08 mov (%eax),%ecx
962: 89 0a mov %ecx,(%edx)
964: eb b1 jmp 917 <malloc+0xa7>
|
; A048005: Number of nonempty subsets of {1,2,...,n} in which exactly 1/2 of the elements are <= (n-1)/3.
; 0,0,0,3,4,5,20,27,35,119,164,219,714,1000,1364,4367,6187,8567,27131,38759,54263,170543,245156,346103,1081574,1562274,2220074,6906899,10015004,14307149,44352164,64512239,92561039,286097759
mov $1,1
add $1,$0
div $0,3
bin $1,$0
sub $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 "arrow/json/chunker.h"
#include <algorithm>
#include <utility>
#include <vector>
#include "arrow/json/rapidjson_defs.h"
#include "rapidjson/reader.h"
#include "arrow/buffer.h"
#include "arrow/json/options.h"
#include "arrow/util/logging.h"
#include "arrow/util/make_unique.h"
#include "arrow/util/string_view.h"
namespace arrow {
namespace json {
namespace rj = arrow::rapidjson;
using internal::make_unique;
using util::string_view;
static size_t ConsumeWhitespace(string_view view) {
#if defined(ARROW_RAPIDJSON_SKIP_WHITESPACE_SIMD)
auto data = view.data();
auto nonws_begin = rj::SkipWhitespace_SIMD(data, data + view.size());
return nonws_begin - data;
#else
auto ws_count = view.find_first_not_of(" \t\r\n");
if (ws_count == string_view::npos) {
return 0;
} else {
return ws_count;
}
#endif
}
/// RapidJson custom stream for reading JSON stored in multiple buffers
/// http://rapidjson.org/md_doc_stream.html#CustomStream
class MultiStringStream {
public:
using Ch = char;
explicit MultiStringStream(std::vector<string_view> strings)
: strings_(std::move(strings)) {
std::reverse(strings_.begin(), strings_.end());
}
explicit MultiStringStream(const BufferVector& buffers) : strings_(buffers.size()) {
for (size_t i = 0; i < buffers.size(); ++i) {
strings_[i] = string_view(*buffers[i]);
}
std::reverse(strings_.begin(), strings_.end());
}
char Peek() const {
if (strings_.size() == 0) return '\0';
return strings_.back()[0];
}
char Take() {
if (strings_.size() == 0) return '\0';
char taken = strings_.back()[0];
if (strings_.back().size() == 1) {
strings_.pop_back();
} else {
strings_.back() = strings_.back().substr(1);
}
++index_;
return taken;
}
size_t Tell() { return index_; }
void Put(char) { ARROW_LOG(FATAL) << "not implemented"; }
void Flush() { ARROW_LOG(FATAL) << "not implemented"; }
char* PutBegin() {
ARROW_LOG(FATAL) << "not implemented";
return nullptr;
}
size_t PutEnd(char*) {
ARROW_LOG(FATAL) << "not implemented";
return 0;
}
private:
size_t index_ = 0;
std::vector<string_view> strings_;
};
template <typename Stream>
static size_t ConsumeWholeObject(Stream&& stream) {
static constexpr unsigned parse_flags = rj::kParseIterativeFlag |
rj::kParseStopWhenDoneFlag |
rj::kParseNumbersAsStringsFlag;
rj::BaseReaderHandler<rj::UTF8<>> handler;
rj::Reader reader;
// parse a single JSON object
switch (reader.Parse<parse_flags>(stream, handler).Code()) {
case rj::kParseErrorNone:
return stream.Tell();
case rj::kParseErrorDocumentEmpty:
return 0;
default:
// rapidjson emitted an error, the most recent object was partial
return string_view::npos;
}
}
namespace {
// A BoundaryFinder implementation that assumes JSON objects can contain raw newlines,
// and uses actual JSON parsing to delimit them.
class ParsingBoundaryFinder : public BoundaryFinder {
public:
Status FindFirst(string_view partial, string_view block, int64_t* out_pos) override {
// NOTE: We could bubble up JSON parse errors here, but the actual parsing
// step will detect them later anyway.
auto length = ConsumeWholeObject(MultiStringStream({partial, block}));
if (length == string_view::npos) {
*out_pos = -1;
} else {
DCHECK_GE(length, partial.size());
DCHECK_LE(length, partial.size() + block.size());
*out_pos = static_cast<int64_t>(length - partial.size());
}
return Status::OK();
}
Status FindLast(util::string_view block, int64_t* out_pos) override {
const size_t block_length = block.size();
size_t consumed_length = 0;
while (consumed_length < block_length) {
rj::MemoryStream ms(reinterpret_cast<const char*>(block.data()), block.size());
using InputStream = rj::EncodedInputStream<rj::UTF8<>, rj::MemoryStream>;
auto length = ConsumeWholeObject(InputStream(ms));
if (length == string_view::npos || length == 0) {
// found incomplete object or block is empty
break;
}
consumed_length += length;
block = block.substr(length);
}
if (consumed_length == 0) {
*out_pos = -1;
} else {
consumed_length += ConsumeWhitespace(block);
DCHECK_LE(consumed_length, block_length);
*out_pos = static_cast<int64_t>(consumed_length);
}
return Status::OK();
}
};
} // namespace
std::unique_ptr<Chunker> MakeChunker(const ParseOptions& options) {
std::shared_ptr<BoundaryFinder> delimiter;
if (options.newlines_in_values) {
delimiter = std::make_shared<ParsingBoundaryFinder>();
} else {
delimiter = MakeNewlineBoundaryFinder();
}
return std::unique_ptr<Chunker>(new Chunker(std::move(delimiter)));
}
} // namespace json
} // namespace arrow
|
;/*
; * FreeRTOS Kernel V10.4.3
; * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
; *
; * Permission is hereby granted, free of charge, to any person obtaining a copy of
; * this software and associated documentation files (the "Software"), to deal in
; * the Software without restriction, including without limitation the rights to
; * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
; * the Software, and to permit persons to whom the Software is furnished to do so,
; * subject to the following conditions:
; *
; * The above copyright notice and this permission notice shall be included in all
; * copies or substantial portions of the Software.
; *
; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
; * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
; * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
; * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
; * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
; *
; * https://www.FreeRTOS.org
; * https://github.com/FreeRTOS
; *
; * 1 tab == 4 spaces!
; */
.thumb
.ref pxCurrentTCB
.ref vTaskSwitchContext
.ref ulMaxSyscallInterruptPriority
.def xPortPendSVHandler
.def ulPortGetIPSR
.def vPortSVCHandler
.def vPortStartFirstTask
.def vPortEnableVFP
NVICOffsetConst: .word 0xE000ED08
CPACRConst: .word 0xE000ED88
pxCurrentTCBConst: .word pxCurrentTCB
ulMaxSyscallInterruptPriorityConst: .word ulMaxSyscallInterruptPriority
; -----------------------------------------------------------
.align 4
ulPortGetIPSR: .asmfunc
mrs r0, ipsr
bx r14
.endasmfunc
; -----------------------------------------------------------
.align 4
vPortSetInterruptMask: .asmfunc
push {r0}
ldr r0, ulMaxSyscallInterruptPriorityConst
msr basepri, r0
pop {r0}
bx r14
.endasmfunc
; -----------------------------------------------------------
.align 4
xPortPendSVHandler: .asmfunc
mrs r0, psp
isb
;/* Get the location of the current TCB. */
ldr r3, pxCurrentTCBConst
ldr r2, [r3]
;/* Is the task using the FPU context? If so, push high vfp registers. */
tst r14, #0x10
it eq
vstmdbeq r0!, {s16-s31}
;/* Save the core registers. */
stmdb r0!, {r4-r11, r14}
;/* Save the new top of stack into the first member of the TCB. */
str r0, [r2]
stmdb sp!, {r0, r3}
ldr r0, ulMaxSyscallInterruptPriorityConst
ldr r1, [r0]
msr basepri, r1
dsb
isb
bl vTaskSwitchContext
mov r0, #0
msr basepri, r0
ldmia sp!, {r0, r3}
;/* The first item in pxCurrentTCB is the task top of stack. */
ldr r1, [r3]
ldr r0, [r1]
;/* Pop the core registers. */
ldmia r0!, {r4-r11, r14}
;/* Is the task using the FPU context? If so, pop the high vfp registers
;too. */
tst r14, #0x10
it eq
vldmiaeq r0!, {s16-s31}
msr psp, r0
isb
bx r14
.endasmfunc
; -----------------------------------------------------------
.align 4
vPortSVCHandler: .asmfunc
;/* Get the location of the current TCB. */
ldr r3, pxCurrentTCBConst
ldr r1, [r3]
ldr r0, [r1]
;/* Pop the core registers. */
ldmia r0!, {r4-r11, r14}
msr psp, r0
isb
mov r0, #0
msr basepri, r0
bx r14
.endasmfunc
; -----------------------------------------------------------
.align 4
vPortStartFirstTask: .asmfunc
;/* Use the NVIC offset register to locate the stack. */
ldr r0, NVICOffsetConst
ldr r0, [r0]
ldr r0, [r0]
;/* Set the msp back to the start of the stack. */
msr msp, r0
;/* Clear the bit that indicates the FPU is in use in case the FPU was used
;before the scheduler was started - which would otherwise result in the
;unnecessary leaving of space in the SVC stack for lazy saving of FPU
;registers. */
mov r0, #0
msr control, r0
;/* Call SVC to start the first task. */
cpsie i
cpsie f
dsb
isb
svc #0
.endasmfunc
; -----------------------------------------------------------
.align 4
vPortEnableVFP: .asmfunc
;/* The FPU enable bits are in the CPACR. */
ldr.w r0, CPACRConst
ldr r1, [r0]
;/* Enable CP10 and CP11 coprocessors, then save back. */
orr r1, r1, #( 0xf << 20 )
str r1, [r0]
bx r14
.endasmfunc
.end
; -----------------------------------------------------------
|
; A032261: Number of bracelets with n labeled beads of 3 colors.
; Submitted by Jon Maiga
; 1,3,9,27,243,2916,43740,787320,16533720,396809280,10713850560,321415516800,10606712054400,381841633958400,14891823724377600,625456596423859200,28145546839073664000,1350986248275535872000,68900298662052329472000,3720616127750825791488000,212075119281797070114816000,12724507156907824206888960000,801643950885192925034004480000,52908500758422733052244295680000,3650686552331168580604856401920000,262849431767844137803549660938240000,19713707382588310335266224570368000000
mov $1,1
lpb $0
sub $0,1
add $2,3
mul $1,$2
add $3,2
lpe
gcd $3,$1
div $1,$3
mov $0,$1
|
// Autogenerated from CppHeaderCreator
// Created by Sc2ad
// =========================================================================
#pragma once
// Begin includes
#include "extern/beatsaber-hook/shared/utils/typedefs.h"
#include "extern/beatsaber-hook/shared/utils/byref.hpp"
// Including type: System.ValueType
#include "System/ValueType.hpp"
// Including type: UnityEngine.Playables.PlayableOutput
#include "UnityEngine/Playables/PlayableOutput.hpp"
// Completed includes
// Begin forward declares
// Forward declaring namespace: UnityEngine::Playables
namespace UnityEngine::Playables {
// Forward declaring type: PlayState
struct PlayState;
// Skipping declaration: Flags because it is already included!
}
// Completed forward declares
// Type namespace: UnityEngine.Playables
namespace UnityEngine::Playables {
// Size: 0x3C
#pragma pack(push, 1)
// WARNING Layout: Sequential may not be correctly taken into account!
// Autogenerated type: UnityEngine.Playables.FrameData
// [TokenAttribute] Offset: FFFFFFFF
struct FrameData/*, public System::ValueType*/ {
public:
// Nested type: UnityEngine::Playables::FrameData::Flags
struct Flags;
// Nested type: UnityEngine::Playables::FrameData::EvaluationType
struct EvaluationType;
// Size: 0x4
#pragma pack(push, 1)
// Autogenerated type: UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags
// [TokenAttribute] Offset: FFFFFFFF
// [FlagsAttribute] Offset: FFFFFFFF
struct Flags/*, public System::Enum*/ {
public:
// public System.Int32 value__
// Size: 0x4
// Offset: 0x0
int value;
// Field size check
static_assert(sizeof(int) == 0x4);
// Creating value type constructor for type: Flags
constexpr Flags(int value_ = {}) noexcept : value{value_} {}
// Creating interface conversion operator: operator System::Enum
operator System::Enum() noexcept {
return *reinterpret_cast<System::Enum*>(this);
}
// Creating conversion operator: operator int
constexpr operator int() const noexcept {
return value;
}
// static field const value: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags Evaluate
static constexpr const int Evaluate = 1;
// Get static field: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags Evaluate
static UnityEngine::Playables::FrameData::Flags _get_Evaluate();
// Set static field: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags Evaluate
static void _set_Evaluate(UnityEngine::Playables::FrameData::Flags value);
// static field const value: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags SeekOccured
static constexpr const int SeekOccured = 2;
// Get static field: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags SeekOccured
static UnityEngine::Playables::FrameData::Flags _get_SeekOccured();
// Set static field: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags SeekOccured
static void _set_SeekOccured(UnityEngine::Playables::FrameData::Flags value);
// static field const value: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags Loop
static constexpr const int Loop = 4;
// Get static field: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags Loop
static UnityEngine::Playables::FrameData::Flags _get_Loop();
// Set static field: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags Loop
static void _set_Loop(UnityEngine::Playables::FrameData::Flags value);
// static field const value: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags Hold
static constexpr const int Hold = 8;
// Get static field: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags Hold
static UnityEngine::Playables::FrameData::Flags _get_Hold();
// Set static field: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags Hold
static void _set_Hold(UnityEngine::Playables::FrameData::Flags value);
// static field const value: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags EffectivePlayStateDelayed
static constexpr const int EffectivePlayStateDelayed = 16;
// Get static field: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags EffectivePlayStateDelayed
static UnityEngine::Playables::FrameData::Flags _get_EffectivePlayStateDelayed();
// Set static field: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags EffectivePlayStateDelayed
static void _set_EffectivePlayStateDelayed(UnityEngine::Playables::FrameData::Flags value);
// static field const value: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags EffectivePlayStatePlaying
static constexpr const int EffectivePlayStatePlaying = 32;
// Get static field: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags EffectivePlayStatePlaying
static UnityEngine::Playables::FrameData::Flags _get_EffectivePlayStatePlaying();
// Set static field: static public UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags EffectivePlayStatePlaying
static void _set_EffectivePlayStatePlaying(UnityEngine::Playables::FrameData::Flags value);
// Get instance field: public System.Int32 value__
int _get_value__();
// Set instance field: public System.Int32 value__
void _set_value__(int value);
}; // UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags
#pragma pack(pop)
static check_size<sizeof(FrameData::Flags), 0 + sizeof(int)> __UnityEngine_Playables_FrameData_FlagsSizeCheck;
static_assert(sizeof(FrameData::Flags) == 0x4);
// System.UInt64 m_FrameID
// Size: 0x8
// Offset: 0x0
uint64_t m_FrameID;
// Field size check
static_assert(sizeof(uint64_t) == 0x8);
// System.Double m_DeltaTime
// Size: 0x8
// Offset: 0x8
double m_DeltaTime;
// Field size check
static_assert(sizeof(double) == 0x8);
// System.Single m_Weight
// Size: 0x4
// Offset: 0x10
float m_Weight;
// Field size check
static_assert(sizeof(float) == 0x4);
// System.Single m_EffectiveWeight
// Size: 0x4
// Offset: 0x14
float m_EffectiveWeight;
// Field size check
static_assert(sizeof(float) == 0x4);
// System.Double m_EffectiveParentDelay
// Size: 0x8
// Offset: 0x18
double m_EffectiveParentDelay;
// Field size check
static_assert(sizeof(double) == 0x8);
// System.Single m_EffectiveParentSpeed
// Size: 0x4
// Offset: 0x20
float m_EffectiveParentSpeed;
// Field size check
static_assert(sizeof(float) == 0x4);
// System.Single m_EffectiveSpeed
// Size: 0x4
// Offset: 0x24
float m_EffectiveSpeed;
// Field size check
static_assert(sizeof(float) == 0x4);
// UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags m_Flags
// Size: 0x4
// Offset: 0x28
UnityEngine::Playables::FrameData::Flags m_Flags;
// Field size check
static_assert(sizeof(UnityEngine::Playables::FrameData::Flags) == 0x4);
// Padding between fields: m_Flags and: m_Output
char __padding7[0x4] = {};
// UnityEngine.Playables.PlayableOutput m_Output
// Size: 0xC
// Offset: 0x30
UnityEngine::Playables::PlayableOutput m_Output;
// Field size check
static_assert(sizeof(UnityEngine::Playables::PlayableOutput) == 0xC);
// Creating value type constructor for type: FrameData
constexpr FrameData(uint64_t m_FrameID_ = {}, double m_DeltaTime_ = {}, float m_Weight_ = {}, float m_EffectiveWeight_ = {}, double m_EffectiveParentDelay_ = {}, float m_EffectiveParentSpeed_ = {}, float m_EffectiveSpeed_ = {}, UnityEngine::Playables::FrameData::Flags m_Flags_ = {}, UnityEngine::Playables::PlayableOutput m_Output_ = {}) noexcept : m_FrameID{m_FrameID_}, m_DeltaTime{m_DeltaTime_}, m_Weight{m_Weight_}, m_EffectiveWeight{m_EffectiveWeight_}, m_EffectiveParentDelay{m_EffectiveParentDelay_}, m_EffectiveParentSpeed{m_EffectiveParentSpeed_}, m_EffectiveSpeed{m_EffectiveSpeed_}, m_Flags{m_Flags_}, m_Output{m_Output_} {}
// Creating interface conversion operator: operator System::ValueType
operator System::ValueType() noexcept {
return *reinterpret_cast<System::ValueType*>(this);
}
// Get instance field: System.UInt64 m_FrameID
uint64_t _get_m_FrameID();
// Set instance field: System.UInt64 m_FrameID
void _set_m_FrameID(uint64_t value);
// Get instance field: System.Double m_DeltaTime
double _get_m_DeltaTime();
// Set instance field: System.Double m_DeltaTime
void _set_m_DeltaTime(double value);
// Get instance field: System.Single m_Weight
float _get_m_Weight();
// Set instance field: System.Single m_Weight
void _set_m_Weight(float value);
// Get instance field: System.Single m_EffectiveWeight
float _get_m_EffectiveWeight();
// Set instance field: System.Single m_EffectiveWeight
void _set_m_EffectiveWeight(float value);
// Get instance field: System.Double m_EffectiveParentDelay
double _get_m_EffectiveParentDelay();
// Set instance field: System.Double m_EffectiveParentDelay
void _set_m_EffectiveParentDelay(double value);
// Get instance field: System.Single m_EffectiveParentSpeed
float _get_m_EffectiveParentSpeed();
// Set instance field: System.Single m_EffectiveParentSpeed
void _set_m_EffectiveParentSpeed(float value);
// Get instance field: System.Single m_EffectiveSpeed
float _get_m_EffectiveSpeed();
// Set instance field: System.Single m_EffectiveSpeed
void _set_m_EffectiveSpeed(float value);
// Get instance field: UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags m_Flags
UnityEngine::Playables::FrameData::Flags _get_m_Flags();
// Set instance field: UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags m_Flags
void _set_m_Flags(UnityEngine::Playables::FrameData::Flags value);
// Get instance field: UnityEngine.Playables.PlayableOutput m_Output
UnityEngine::Playables::PlayableOutput _get_m_Output();
// Set instance field: UnityEngine.Playables.PlayableOutput m_Output
void _set_m_Output(UnityEngine::Playables::PlayableOutput value);
// public System.Single get_deltaTime()
// Offset: 0xF851A0
float get_deltaTime();
// public System.Single get_effectiveSpeed()
// Offset: 0xF851AC
float get_effectiveSpeed();
// public UnityEngine.Playables.FrameData/UnityEngine.Playables.EvaluationType get_evaluationType()
// Offset: 0xF851B4
UnityEngine::Playables::FrameData::EvaluationType get_evaluationType();
// public System.Boolean get_seekOccurred()
// Offset: 0xF851C4
bool get_seekOccurred();
// public System.Boolean get_timeLooped()
// Offset: 0xF851D0
bool get_timeLooped();
// public System.Boolean get_timeHeld()
// Offset: 0xF851DC
bool get_timeHeld();
// public UnityEngine.Playables.PlayableOutput get_output()
// Offset: 0xF851E8
UnityEngine::Playables::PlayableOutput get_output();
// public UnityEngine.Playables.PlayState get_effectivePlayState()
// Offset: 0xF851F4
UnityEngine::Playables::PlayState get_effectivePlayState();
// private System.Boolean HasFlags(UnityEngine.Playables.FrameData/UnityEngine.Playables.Flags flag)
// Offset: 0xF85190
bool HasFlags(UnityEngine::Playables::FrameData::Flags flag);
}; // UnityEngine.Playables.FrameData
#pragma pack(pop)
static check_size<sizeof(FrameData), 48 + sizeof(UnityEngine::Playables::PlayableOutput)> __UnityEngine_Playables_FrameDataSizeCheck;
static_assert(sizeof(FrameData) == 0x3C);
}
#include "extern/beatsaber-hook/shared/utils/il2cpp-type-check.hpp"
DEFINE_IL2CPP_ARG_TYPE(UnityEngine::Playables::FrameData, "UnityEngine.Playables", "FrameData");
DEFINE_IL2CPP_ARG_TYPE(UnityEngine::Playables::FrameData::Flags, "UnityEngine.Playables", "FrameData/Flags");
#include "extern/beatsaber-hook/shared/utils/il2cpp-utils-methods.hpp"
// Writing MetadataGetter for method: UnityEngine::Playables::FrameData::get_deltaTime
// Il2CppName: get_deltaTime
template<>
struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<float (UnityEngine::Playables::FrameData::*)()>(&UnityEngine::Playables::FrameData::get_deltaTime)> {
static const MethodInfo* get() {
return ::il2cpp_utils::FindMethod(classof(UnityEngine::Playables::FrameData), "get_deltaTime", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{});
}
};
// Writing MetadataGetter for method: UnityEngine::Playables::FrameData::get_effectiveSpeed
// Il2CppName: get_effectiveSpeed
template<>
struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<float (UnityEngine::Playables::FrameData::*)()>(&UnityEngine::Playables::FrameData::get_effectiveSpeed)> {
static const MethodInfo* get() {
return ::il2cpp_utils::FindMethod(classof(UnityEngine::Playables::FrameData), "get_effectiveSpeed", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{});
}
};
// Writing MetadataGetter for method: UnityEngine::Playables::FrameData::get_evaluationType
// Il2CppName: get_evaluationType
template<>
struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<UnityEngine::Playables::FrameData::EvaluationType (UnityEngine::Playables::FrameData::*)()>(&UnityEngine::Playables::FrameData::get_evaluationType)> {
static const MethodInfo* get() {
return ::il2cpp_utils::FindMethod(classof(UnityEngine::Playables::FrameData), "get_evaluationType", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{});
}
};
// Writing MetadataGetter for method: UnityEngine::Playables::FrameData::get_seekOccurred
// Il2CppName: get_seekOccurred
template<>
struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<bool (UnityEngine::Playables::FrameData::*)()>(&UnityEngine::Playables::FrameData::get_seekOccurred)> {
static const MethodInfo* get() {
return ::il2cpp_utils::FindMethod(classof(UnityEngine::Playables::FrameData), "get_seekOccurred", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{});
}
};
// Writing MetadataGetter for method: UnityEngine::Playables::FrameData::get_timeLooped
// Il2CppName: get_timeLooped
template<>
struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<bool (UnityEngine::Playables::FrameData::*)()>(&UnityEngine::Playables::FrameData::get_timeLooped)> {
static const MethodInfo* get() {
return ::il2cpp_utils::FindMethod(classof(UnityEngine::Playables::FrameData), "get_timeLooped", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{});
}
};
// Writing MetadataGetter for method: UnityEngine::Playables::FrameData::get_timeHeld
// Il2CppName: get_timeHeld
template<>
struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<bool (UnityEngine::Playables::FrameData::*)()>(&UnityEngine::Playables::FrameData::get_timeHeld)> {
static const MethodInfo* get() {
return ::il2cpp_utils::FindMethod(classof(UnityEngine::Playables::FrameData), "get_timeHeld", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{});
}
};
// Writing MetadataGetter for method: UnityEngine::Playables::FrameData::get_output
// Il2CppName: get_output
template<>
struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<UnityEngine::Playables::PlayableOutput (UnityEngine::Playables::FrameData::*)()>(&UnityEngine::Playables::FrameData::get_output)> {
static const MethodInfo* get() {
return ::il2cpp_utils::FindMethod(classof(UnityEngine::Playables::FrameData), "get_output", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{});
}
};
// Writing MetadataGetter for method: UnityEngine::Playables::FrameData::get_effectivePlayState
// Il2CppName: get_effectivePlayState
template<>
struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<UnityEngine::Playables::PlayState (UnityEngine::Playables::FrameData::*)()>(&UnityEngine::Playables::FrameData::get_effectivePlayState)> {
static const MethodInfo* get() {
return ::il2cpp_utils::FindMethod(classof(UnityEngine::Playables::FrameData), "get_effectivePlayState", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{});
}
};
// Writing MetadataGetter for method: UnityEngine::Playables::FrameData::HasFlags
// Il2CppName: HasFlags
template<>
struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<bool (UnityEngine::Playables::FrameData::*)(UnityEngine::Playables::FrameData::Flags)>(&UnityEngine::Playables::FrameData::HasFlags)> {
static const MethodInfo* get() {
static auto* flag = &::il2cpp_utils::GetClassFromName("UnityEngine.Playables", "FrameData/Flags")->byval_arg;
return ::il2cpp_utils::FindMethod(classof(UnityEngine::Playables::FrameData), "HasFlags", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{flag});
}
};
|
; A004154: Omit trailing zeros from factorial numbers.
; 1,1,2,6,24,12,72,504,4032,36288,36288,399168,4790016,62270208,871782912,1307674368,20922789888,355687428096,6402373705728,121645100408832,243290200817664,5109094217170944,112400072777760768,2585201673888497664,62044840173323943936,15511210043330985984,403291461126605635584,10888869450418352160768,304888344611713860501504,8841761993739701954543616,26525285981219105863630848,822283865417792281772556288,26313083693369353016721801216,868331761881188649551819440128,29523279903960414084761860964352,103331479663861449296666513375232,3719933267899012174679994481508352,137637530912263450463159795815809024
mov $1,1
lpb $0
mul $1,$0
sub $0,1
dif $1,10
lpe
mov $0,$1
|
Label -mem-manager-initialize
DLabel $heap-start-ptr
DataZ 4
DLabel $heap-after-ptr
DataZ 4
DLabel $heap-first-free
DataZ 4
DLabel $mmgr-newblock-block
DataZ 4
DLabel $mmgr-newblock-size
DataZ 4
PushD $heap-memory
Duplicate
PushD $heap-start-ptr
Exchange
StoreI
PushD $heap-after-ptr
Exchange
StoreI
PushI 0
PushD $heap-first-free
Exchange
StoreI
Jump $$main
DLabel $eat-location-zero
DataZ 8
DLabel $print-format-integer
DataC 37 %% "%d"
DataC 100
DataC 0
DLabel $print-format-floating
DataC 37 %% "%g"
DataC 103
DataC 0
DLabel $print-format-boolean
DataC 37 %% "%s"
DataC 115
DataC 0
DLabel $print-format-character
DataC 37 %% "%c"
DataC 99
DataC 0
DLabel $print-format-string
DataC 37 %% "%s"
DataC 115
DataC 0
DLabel $print-format-tab
DataC 9 %% "\t"
DataC 0
DLabel $print-format-newline
DataC 10 %% "\n"
DataC 0
DLabel $print-format-space
DataC 32 %% " "
DataC 0
DLabel $boolean-true-string
DataC 116 %% "true"
DataC 114
DataC 117
DataC 101
DataC 0
DLabel $boolean-false-string
DataC 102 %% "false"
DataC 97
DataC 108
DataC 115
DataC 101
DataC 0
DLabel $dash-string
DataC 95 %% "_"
DataC 0
DLabel $divide-sign-string
DataC 47 %% "/"
DataC 0
DLabel $minus-sign-string
DataC 45 %% "-"
DataC 0
DLabel $open-bracket-string
DataC 91 %% "["
DataC 0
DLabel $close-bracket-string
DataC 93 %% "]"
DataC 0
DLabel $comma-string
DataC 44 %% ","
DataC 0
DLabel $errors-general-message
DataC 82 %% "Runtime error: %s\n"
DataC 117
DataC 110
DataC 116
DataC 105
DataC 109
DataC 101
DataC 32
DataC 101
DataC 114
DataC 114
DataC 111
DataC 114
DataC 58
DataC 32
DataC 37
DataC 115
DataC 10
DataC 0
Label $$general-runtime-error
PushD $errors-general-message
Printf
Halt
DLabel $errors-int-divide-by-zero
DataC 105 %% "integer divide by zero"
DataC 110
DataC 116
DataC 101
DataC 103
DataC 101
DataC 114
DataC 32
DataC 100
DataC 105
DataC 118
DataC 105
DataC 100
DataC 101
DataC 32
DataC 98
DataC 121
DataC 32
DataC 122
DataC 101
DataC 114
DataC 111
DataC 0
Label $$i-divide-by-zero
PushD $errors-int-divide-by-zero
Jump $$general-runtime-error
DLabel $errors-float-divide-by-zero
DataC 102 %% "float divide by zero"
DataC 108
DataC 111
DataC 97
DataC 116
DataC 32
DataC 100
DataC 105
DataC 118
DataC 105
DataC 100
DataC 101
DataC 32
DataC 98
DataC 121
DataC 32
DataC 122
DataC 101
DataC 114
DataC 111
DataC 0
Label $$f-divide-by-zero
PushD $errors-float-divide-by-zero
Jump $$general-runtime-error
DLabel $null-array-runtime-error
DataC 110 %% "null array"
DataC 117
DataC 108
DataC 108
DataC 32
DataC 97
DataC 114
DataC 114
DataC 97
DataC 121
DataC 0
Label $$null-array
PushD $null-array-runtime-error
Jump $$general-runtime-error
DLabel $index-out-of-bound-error
DataC 97 %% "array index out of bound"
DataC 114
DataC 114
DataC 97
DataC 121
DataC 32
DataC 105
DataC 110
DataC 100
DataC 101
DataC 120
DataC 32
DataC 111
DataC 117
DataC 116
DataC 32
DataC 111
DataC 102
DataC 32
DataC 98
DataC 111
DataC 117
DataC 110
DataC 100
DataC 0
Label $$index-out-of-bound
PushD $index-out-of-bound-error
Jump $$general-runtime-error
DLabel $zero-denominator-error
DataC 111 %% "over zero denominator"
DataC 118
DataC 101
DataC 114
DataC 32
DataC 122
DataC 101
DataC 114
DataC 111
DataC 32
DataC 100
DataC 101
DataC 110
DataC 111
DataC 109
DataC 105
DataC 110
DataC 97
DataC 116
DataC 111
DataC 114
DataC 0
Label $$over-zero-denominator
PushD $zero-denominator-error
Jump $$general-runtime-error
DLabel $expressover-divide-by-zero
DataC 101 %% "expressover divide by zero"
DataC 120
DataC 112
DataC 114
DataC 101
DataC 115
DataC 115
DataC 111
DataC 118
DataC 101
DataC 114
DataC 32
DataC 100
DataC 105
DataC 118
DataC 105
DataC 100
DataC 101
DataC 32
DataC 98
DataC 121
DataC 32
DataC 122
DataC 101
DataC 114
DataC 111
DataC 0
Label $$rational-expressover-divide-by-zero
PushD $expressover-divide-by-zero
Jump $$general-runtime-error
DLabel $rationalize-divide-by-zero
DataC 114 %% "rationalize divide by zero"
DataC 97
DataC 116
DataC 105
DataC 111
DataC 110
DataC 97
DataC 108
DataC 105
DataC 122
DataC 101
DataC 32
DataC 100
DataC 105
DataC 118
DataC 105
DataC 100
DataC 101
DataC 32
DataC 98
DataC 121
DataC 32
DataC 122
DataC 101
DataC 114
DataC 111
DataC 0
Label $$rationalize-divide-by-zero
PushD $rationalize-divide-by-zero
Jump $$general-runtime-error
DLabel $negative-array-length
DataC 110 %% "negative array length"
DataC 101
DataC 103
DataC 97
DataC 116
DataC 105
DataC 118
DataC 101
DataC 32
DataC 97
DataC 114
DataC 114
DataC 97
DataC 121
DataC 32
DataC 108
DataC 101
DataC 110
DataC 103
DataC 116
DataC 104
DataC 0
Label $$negative-length-array
PushD $negative-array-length
Jump $$general-runtime-error
DLabel $null-string-runtime-error
DataC 110 %% "null string"
DataC 117
DataC 108
DataC 108
DataC 32
DataC 115
DataC 116
DataC 114
DataC 105
DataC 110
DataC 103
DataC 0
Label $$null-string
PushD $null-string-runtime-error
Jump $$general-runtime-error
DLabel $no-return
DataC 110 %% "no return"
DataC 111
DataC 32
DataC 114
DataC 101
DataC 116
DataC 117
DataC 114
DataC 110
DataC 0
Label $$no return
PushD $no-return
Jump $$general-runtime-error
DLabel $a-indexing-array
DataZ 4
DLabel $a-indexing-index
DataZ 4
DLabel $express-over-denominator
DataZ 4
DLabel $rational-denominator-temp
DataZ 4
DLabel $rational-numerator-temp
DataZ 4
DLabel $rational-denominator-temp2
DataZ 4
DLabel $rational-numerator-temp2
DataZ 4
DLabel $rational-print-integer-part
DataZ 4
DLabel $rational-print-remainder
DataZ 4
DLabel $rational-print-sign
DataZ 4
DLabel $record-creation-temp
DataZ 4
DLabel $array-datasize-temp
DataZ 4
DLabel $array-identifier-temp
DataZ 4
DLabel $array-status-temp
DataZ 4
DLabel $array-subtype-size-temp
DataZ 4
DLabel $array-length-temp
DataZ 4
DLabel $array-element-temp
DataZ 4
DLabel $cloned-array-temp
DataZ 4
DLabel $print-string-temp
DataZ 4
DLabel $print-string-length
DataZ 4
DLabel $frame-pointer
DataZ 4
DLabel $stack-pointer
DataZ 4
Label $lowest-term-subroutine
DLabel $lowest-term-return
DataZ 4
PushD $lowest-term-return
Exchange
StoreI
Duplicate
JumpFalse $$over-zero-denominator
DLabel $lowest-term-denominator
DataZ 4
DLabel $lowest-term-numerator
DataZ 4
DLabel $lowest-term-gcd
DataZ 4
DLabel $lowest-term-tmpa
DataZ 4
DLabel $lowest-term-tmpb
DataZ 4
PushD $lowest-term-denominator
Exchange
StoreI
PushD $lowest-term-numerator
Exchange
StoreI
PushD $lowest-term-numerator
LoadI
PushD $lowest-term-denominator
LoadI
Subtract
JumpNeg -lowest-term-subroutine-6-exchange
PushD $lowest-term-numerator
LoadI
PushD $lowest-term-denominator
LoadI
Jump -lowest-term-subroutine-6-loop-start
Label -lowest-term-subroutine-6-exchange
PushD $lowest-term-denominator
LoadI
PushD $lowest-term-numerator
LoadI
Label -lowest-term-subroutine-6-loop-start
PushD $lowest-term-tmpb
Exchange
StoreI
PushD $lowest-term-tmpa
Exchange
StoreI
PushD $lowest-term-tmpa
LoadI
PushD $lowest-term-tmpb
LoadI
Duplicate
JumpFalse -lowest-term-subroutine-6-end
Remainder
PushD $lowest-term-tmpb
LoadI
Exchange
Jump -lowest-term-subroutine-6-loop-start
Label -lowest-term-subroutine-6-end
Pop
PushD $lowest-term-gcd
Exchange
StoreI
PushD $lowest-term-numerator
LoadI
PushD $lowest-term-gcd
LoadI
Divide
PushD $lowest-term-denominator
LoadI
PushD $lowest-term-gcd
LoadI
Divide
PushD $lowest-term-return
LoadI
Return
Label $clear-n-bytes-subroutine
DLabel $clear-n-bytes-return-address
DataZ 4
PushD $clear-n-bytes-return-address
Exchange
StoreI
DLabel $clear-n-bytes-element-size
DataZ 4
PushD $clear-n-bytes-element-size
Exchange
StoreI
DLabel $clear-n-bytes-element-addr
DataZ 4
PushD $clear-n-bytes-element-addr
Exchange
StoreI
Label -clear-n-bytes-subroutine-7-loop-start
PushD $clear-n-bytes-element-size
LoadI
JumpFalse -clear-n-bytes-subroutine-7-end
PushI 0
PushD $clear-n-bytes-element-addr
Exchange
StoreC
PushI 1
PushD $clear-n-bytes-element-addr
LoadI
Add
PushD $clear-n-bytes-element-addr
Exchange
StoreI
PushI -1
PushD $clear-n-bytes-element-size
LoadI
Add
PushD $clear-n-bytes-element-size
Exchange
StoreI
Jump -clear-n-bytes-subroutine-7-loop-start
Label -clear-n-bytes-subroutine-7-end
PushD $clear-n-bytes-return-address
LoadI
Return
Label $print-array-subroutine
DLabel -print-array-recursive-8-return-address
DataZ 4
PushD -print-array-recursive-8-return-address
Exchange
StoreI
DLabel -print-array-recursive-8-type
DataZ 4
PushD -print-array-recursive-8-type
Exchange
StoreI
DLabel -print-array-recursive-8-element
DataZ 4
DLabel -print-array-recursive-8-length
DataZ 4
DLabel -print-array-recursive-8-elem-size
DataZ 4
Duplicate
JumpFalse $$null-array
Duplicate
Duplicate
Duplicate
PushI 16
Add
PushD -print-array-recursive-8-element
Exchange
StoreI
PushI 12
Add
LoadI
PushD -print-array-recursive-8-length
Exchange
StoreI
PushI 8
Add
LoadI
PushD -print-array-recursive-8-elem-size
Exchange
StoreI
PushD $open-bracket-string
PushD $print-format-string
Printf
PushI 4
Add
LoadI
PushI 2
BTAnd
JumpFalse -print-array-recursive-8-one-dim
Label -print-array-recursive-8-loop-start
PushD -print-array-recursive-8-length
LoadI
JumpFalse -print-array-recursive-8-end
PushD -print-array-recursive-8-return-address
LoadI
PushD -print-array-recursive-8-type
LoadI
PushD -print-array-recursive-8-element
LoadI
PushD -print-array-recursive-8-length
LoadI
PushD -print-array-recursive-8-elem-size
LoadI
PushD -print-array-recursive-8-element
LoadI
LoadI
Duplicate
PushI 0
Add
LoadI
PushI 6
Subtract
JumpFalse -print-array-recursive-8-one-dim
PushD -print-array-recursive-8-type
LoadI
Call $print-array-subroutine
PushD -print-array-recursive-8-elem-size
Exchange
StoreI
PushD -print-array-recursive-8-length
Exchange
StoreI
PushD -print-array-recursive-8-element
Exchange
StoreI
PushD -print-array-recursive-8-type
Exchange
StoreI
PushD -print-array-recursive-8-return-address
Exchange
StoreI
PushD -print-array-recursive-8-elem-size
LoadI
PushD -print-array-recursive-8-element
LoadI
Add
PushD -print-array-recursive-8-element
Exchange
StoreI
PushI -1
PushD -print-array-recursive-8-length
LoadI
Add
PushD -print-array-recursive-8-length
Exchange
StoreI
PushD -print-array-recursive-8-length
LoadI
PushI 0
Subtract
JumpFalse -print-array-recursive-8-loop-start
PushD $comma-string
PushD $print-format-string
Printf
PushD $print-format-space
PushD $print-format-string
Printf
Jump -print-array-recursive-8-loop-start
Label -print-array-recursive-8-one-dim
Label -print-array-recursive-8-loop-start-2
PushD -print-array-recursive-8-length
LoadI
JumpFalse -print-array-recursive-8-end
PushD -print-array-recursive-8-element
LoadI
PushD -print-array-recursive-8-type
LoadI
PushI 1
Subtract
JumpFalse -print-array-recursive-8-int-label
PushD -print-array-recursive-8-type
LoadI
PushI 2
Subtract
JumpFalse -print-array-recursive-8-float-label
PushD -print-array-recursive-8-type
LoadI
PushI 3
Subtract
JumpFalse -print-array-recursive-8-char-label
PushD -print-array-recursive-8-type
LoadI
PushI 4
Subtract
JumpFalse -print-array-recursive-8-string-label
PushD -print-array-recursive-8-type
LoadI
PushI 5
Subtract
JumpFalse -print-array-recursive-8-rat-label
PushD -print-array-recursive-8-type
LoadI
PushI 6
Subtract
JumpFalse -print-array-recursive-8-bool-label
Label -print-array-recursive-8-int-label
LoadI
PushD $print-format-integer
Printf
Jump -print-array-recursive-8-join-label
Label -print-array-recursive-8-float-label
LoadF
PushD $print-format-floating
Printf
Jump -print-array-recursive-8-join-label
Label -print-array-recursive-8-char-label
LoadC
PushD $print-format-character
Printf
Jump -print-array-recursive-8-join-label
Label -print-array-recursive-8-rat-label
Duplicate
LoadI
Exchange
PushI 4
Add
LoadI
Call $print-rational
Jump -print-array-recursive-8-join-label
Label -print-array-recursive-8-bool-label
LoadC
Call $convert-to-string-if-bool-subroutine
PushD $print-format-boolean
Printf
Jump -print-array-recursive-8-join-label
Label -print-array-recursive-8-string-label
LoadI
Call $print-string
Jump -print-array-recursive-8-join-label
Label -print-array-recursive-8-join-label
PushD -print-array-recursive-8-elem-size
LoadI
PushD -print-array-recursive-8-element
LoadI
Add
PushD -print-array-recursive-8-element
Exchange
StoreI
PushI -1
PushD -print-array-recursive-8-length
LoadI
Add
PushD -print-array-recursive-8-length
Exchange
StoreI
PushD -print-array-recursive-8-length
LoadI
PushI 0
Subtract
JumpFalse -print-array-recursive-8-loop-start-2
PushD $comma-string
PushD $print-format-string
Printf
PushD $print-format-space
PushD $print-format-string
Printf
Jump -print-array-recursive-8-loop-start-2
Label -print-array-recursive-8-end
PushD $close-bracket-string
PushD $print-format-string
Printf
PushD -print-array-recursive-8-return-address
LoadI
Return
Label $print-rational
DLabel $print-rational-return-address
DataZ 4
PushD $print-rational-return-address
Exchange
StoreI
PushI 1
PushD $rational-print-sign
Exchange
StoreI
Duplicate
JumpFalse $$over-zero-denominator
Duplicate
JumpPos -print-rational-9-denominator-pos
PushD $rational-print-sign
LoadI
Negate
PushD $rational-print-sign
Exchange
StoreI
Negate
Label -print-rational-9-denominator-pos
PushD $rational-denominator-temp
Exchange
StoreI
Duplicate
Duplicate
JumpFalse -print-rational-9-zero-numerator
JumpPos -print-rational-9-numerator-pos
PushD $rational-print-sign
LoadI
Negate
PushD $rational-print-sign
Exchange
StoreI
Negate
Label -print-rational-9-numerator-pos
PushD $rational-numerator-temp
Exchange
StoreI
PushD $rational-numerator-temp
LoadI
PushD $rational-denominator-temp
LoadI
Remainder
PushD $rational-numerator-temp
LoadI
PushD $rational-denominator-temp
LoadI
Divide
PushD $rational-print-integer-part
Exchange
StoreI
PushD $rational-print-remainder
Exchange
StoreI
PushD $rational-print-remainder
LoadI
PushD $rational-print-integer-part
LoadI
PushD $rational-print-sign
LoadI
JumpPos -print-rational-9-rational-pos
PushD $minus-sign-string
PushD $print-format-string
Printf
Label -print-rational-9-rational-pos
JumpFalse -print-rational-9-fraction
PushD $rational-print-integer-part
LoadI
PushD $print-format-integer
Printf
Label -print-rational-9-fraction
JumpFalse -print-rational-9-end
PushD $dash-string
PushD $print-format-string
Printf
PushD $rational-print-remainder
LoadI
PushD $print-format-integer
Printf
PushD $divide-sign-string
PushD $print-format-string
Printf
PushD $rational-denominator-temp
LoadI
PushD $print-format-integer
Printf
Jump -print-rational-9-end
Label -print-rational-9-zero-numerator
PushD $print-format-integer
Printf
Pop
Label -print-rational-9-end
PushD $print-rational-return-address
LoadI
Return
Label $print-string
DLabel $print-string-return-address
DataZ 4
PushD $print-string-return-address
Exchange
StoreI
Duplicate
JumpFalse $$null-string
Duplicate
PushI 12
Add
PushD $print-string-temp
Exchange
StoreI
PushI 8
Add
LoadI
PushD $print-string-length
Exchange
StoreI
Label -print-string-10-loop-start
PushD $print-string-length
LoadI
JumpFalse -print-string-10-end
PushD $print-string-temp
LoadI
LoadC
PushD $print-format-character
Printf
PushI 1
PushD $print-string-temp
LoadI
Add
PushD $print-string-temp
Exchange
StoreI
PushI -1
PushD $print-string-length
LoadI
Add
PushD $print-string-length
Exchange
StoreI
Jump -print-string-10-loop-start
Label -print-string-10-end
PushD $print-string-return-address
LoadI
Return
Label $convert-to-string-if-bool-subroutine
DLabel $convert-to-string-if-bool-return-address
DataZ 4
PushD $convert-to-string-if-bool-return-address
Exchange
StoreI
JumpTrue -print-boolean-11-true
PushD $boolean-false-string
Jump -print-boolean-11-join
Label -print-boolean-11-true
PushD $boolean-true-string
Label -print-boolean-11-join
PushD $convert-to-string-if-bool-return-address
LoadI
Return
DLabel -release-record-12-length
DataZ 4
DLabel -release-record-12-element-size
DataZ 4
DLabel -release-record-12-element
DataZ 4
Label $release-record
DLabel $release-record-return-address
DataZ 4
PushD $release-record-return-address
Exchange
StoreI
Duplicate
PushI 4
Add
LoadI
Duplicate
Duplicate
PushI 4
BTAnd
JumpTrue -release-record-12-end
PushI 8
BTAnd
JumpTrue -release-record-12-end
PushI 2
BTAnd
JumpFalse -release-record-12-release
Duplicate
Duplicate
PushI 12
Add
LoadI
PushD -release-record-12-length
Exchange
StoreI
PushI 8
Add
LoadI
PushD -release-record-12-element-size
Exchange
StoreI
PushI 16
Add
PushD -release-record-12-element
Exchange
StoreI
Jump -release-record-12-join
Label -release-record-12-string-record
Duplicate
PushI 8
Add
LoadI
PushD -release-record-12-length
Exchange
StoreI
PushI 1
PushD -release-record-12-element-size
Exchange
StoreI
PushI 12
Add
PushD -release-record-12-element
Exchange
StoreI
Label -release-record-12-join
Label -release-record-12-loop-start
PushD -release-record-12-length
LoadI
JumpFalse -release-record-12-end
PushD -release-record-12-element
LoadI
PushD -release-record-12-length
LoadI
PushD -release-record-12-element-size
LoadI
PushD $release-record-return-address
LoadI
PushD -release-record-12-element
LoadI
LoadI
Duplicate
PushI 0
Add
LoadI
PushI 6
Subtract
JumpFalse -release-record-12-release
Call $release-record
PushD $release-record-return-address
Exchange
StoreI
PushD -release-record-12-element-size
Exchange
StoreI
PushD -release-record-12-length
Exchange
StoreI
PushD -release-record-12-element
Exchange
StoreI
PushD -release-record-12-element-size
LoadI
PushD -release-record-12-element
LoadI
Add
PushD -release-record-12-element
Exchange
StoreI
PushI -1
PushD -release-record-12-length
LoadI
Add
PushD -release-record-12-length
Exchange
StoreI
Jump -release-record-12-loop-start
Label -release-record-12-release
Duplicate
Duplicate
PushI 4
Add
LoadI
PushI 4
Add
Exchange
PushI 4
Add
Exchange
StoreI
Call -mem-manager-deallocate
Label -release-record-12-end
PushD $release-record-return-address
LoadI
Return
Label $subtract-rational
DLabel $subtract-rational-return-address
DataZ 4
PushD $subtract-rational-return-address
Exchange
StoreI
PushD $rational-denominator-temp2
Exchange
StoreI
PushD $rational-numerator-temp2
Exchange
StoreI
PushD $rational-denominator-temp
Exchange
StoreI
PushD $rational-numerator-temp
Exchange
StoreI
PushD $rational-denominator-temp
LoadI
PushD $rational-denominator-temp2
LoadI
Multiply
PushD $rational-denominator-temp2
LoadI
PushD $rational-numerator-temp
LoadI
Multiply
PushD $rational-denominator-temp
LoadI
PushD $rational-numerator-temp2
LoadI
Multiply
Subtract
Exchange
Call $lowest-term-subroutine
PushD $subtract-rational-return-address
LoadI
Return
DLabel $usable-memory-start
DLabel $global-memory-block
DataZ 64
Label $$main
Memtop
PushD $stack-pointer
Exchange
StoreI
Memtop
PushD $frame-pointer
Exchange
StoreI
PushD $global-memory-block
PushI 0
Add %% f1
DLabel -function-body-14-return-addr
DataZ 4
Jump -function-body-14--end
Label -function-definition-1-f1-start
PushD $frame-pointer
LoadI
PushD $stack-pointer
LoadI
PushI 4
Subtract
Exchange
StoreI
PushD $stack-pointer
LoadI
PushI 8
Subtract
Exchange
StoreI
PushD $stack-pointer
LoadI
PushD $frame-pointer
Exchange
StoreI
PushI -8
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $frame-pointer
LoadI
PushI 0
Add %% a
LoadI
Jump -function-body-13--exit-handshake
Jump $$no return
Label -function-body-13--exit-handshake
PushD $frame-pointer
LoadI
PushI 8
Subtract
LoadI
PushD -function-body-14-return-addr
Exchange
StoreI
PushD $frame-pointer
LoadI
PushI 4
Subtract
LoadI
PushD $frame-pointer
Exchange
StoreI
PushI 12
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD -function-body-14-return-addr
LoadI
Return
Label -function-body-14--end
PushD -function-definition-1-f1-start
StoreI
PushD $global-memory-block
PushI 4
Add %% f2
DLabel -function-body-16-return-addr
DataZ 4
Jump -function-body-16--end
Label -function-definition-2-f2-start
PushD $frame-pointer
LoadI
PushD $stack-pointer
LoadI
PushI 4
Subtract
Exchange
StoreI
PushD $stack-pointer
LoadI
PushI 8
Subtract
Exchange
StoreI
PushD $stack-pointer
LoadI
PushD $frame-pointer
Exchange
StoreI
PushI -8
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushI 10
PushI 1
Add
PushI 12
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 6
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 9
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushI 10
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 22
Add
Exchange
StoreC
PushI 102
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreC
PushI 117
PushD $record-creation-temp
LoadI
PushI 13
Add
Exchange
StoreC
PushI 110
PushD $record-creation-temp
LoadI
PushI 14
Add
Exchange
StoreC
PushI 99
PushD $record-creation-temp
LoadI
PushI 15
Add
Exchange
StoreC
PushI 45
PushD $record-creation-temp
LoadI
PushI 16
Add
Exchange
StoreC
PushI 115
PushD $record-creation-temp
LoadI
PushI 17
Add
Exchange
StoreC
PushI 116
PushD $record-creation-temp
LoadI
PushI 18
Add
Exchange
StoreC
PushI 114
PushD $record-creation-temp
LoadI
PushI 19
Add
Exchange
StoreC
PushI 45
PushD $record-creation-temp
LoadI
PushI 20
Add
Exchange
StoreC
PushI 50
PushD $record-creation-temp
LoadI
PushI 21
Add
Exchange
StoreC
PushD $record-creation-temp
LoadI
Jump -function-body-15--exit-handshake
Jump $$no return
Label -function-body-15--exit-handshake
PushD $frame-pointer
LoadI
PushI 8
Subtract
LoadI
PushD -function-body-16-return-addr
Exchange
StoreI
PushD $frame-pointer
LoadI
PushI 4
Subtract
LoadI
PushD $frame-pointer
Exchange
StoreI
PushI 8
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD -function-body-16-return-addr
LoadI
Return
Label -function-body-16--end
PushD -function-definition-2-f2-start
StoreI
PushD $global-memory-block
PushI 8
Add %% f3
DLabel -function-body-18-return-addr
DataZ 4
Jump -function-body-18--end
Label -function-definition-3-f3-start
PushD $frame-pointer
LoadI
PushD $stack-pointer
LoadI
PushI 4
Subtract
Exchange
StoreI
PushD $stack-pointer
LoadI
PushI 8
Subtract
Exchange
StoreI
PushD $stack-pointer
LoadI
PushD $frame-pointer
Exchange
StoreI
PushI -8
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushI 10
PushI 1
Add
PushI 12
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 6
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 9
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushI 10
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 22
Add
Exchange
StoreC
PushI 102
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreC
PushI 117
PushD $record-creation-temp
LoadI
PushI 13
Add
Exchange
StoreC
PushI 110
PushD $record-creation-temp
LoadI
PushI 14
Add
Exchange
StoreC
PushI 99
PushD $record-creation-temp
LoadI
PushI 15
Add
Exchange
StoreC
PushI 45
PushD $record-creation-temp
LoadI
PushI 16
Add
Exchange
StoreC
PushI 115
PushD $record-creation-temp
LoadI
PushI 17
Add
Exchange
StoreC
PushI 116
PushD $record-creation-temp
LoadI
PushI 18
Add
Exchange
StoreC
PushI 114
PushD $record-creation-temp
LoadI
PushI 19
Add
Exchange
StoreC
PushI 45
PushD $record-creation-temp
LoadI
PushI 20
Add
Exchange
StoreC
PushI 51
PushD $record-creation-temp
LoadI
PushI 21
Add
Exchange
StoreC
PushD $record-creation-temp
LoadI
Jump -function-body-17--exit-handshake
Jump $$no return
Label -function-body-17--exit-handshake
PushD $frame-pointer
LoadI
PushI 8
Subtract
LoadI
PushD -function-body-18-return-addr
Exchange
StoreI
PushD $frame-pointer
LoadI
PushI 4
Subtract
LoadI
PushD $frame-pointer
Exchange
StoreI
PushI 8
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD -function-body-18-return-addr
LoadI
Return
Label -function-body-18--end
PushD -function-definition-3-f3-start
StoreI
PushD $global-memory-block
PushI 12
Add %% f4
DLabel -function-body-20-return-addr
DataZ 4
Jump -function-body-20--end
Label -function-definition-4-f4-start
PushD $frame-pointer
LoadI
PushD $stack-pointer
LoadI
PushI 4
Subtract
Exchange
StoreI
PushD $stack-pointer
LoadI
PushI 8
Subtract
Exchange
StoreI
PushD $stack-pointer
LoadI
PushD $frame-pointer
Exchange
StoreI
PushI -8
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushI 10
PushI 1
Add
PushI 12
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 6
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 9
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushI 10
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 22
Add
Exchange
StoreC
PushI 102
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreC
PushI 117
PushD $record-creation-temp
LoadI
PushI 13
Add
Exchange
StoreC
PushI 110
PushD $record-creation-temp
LoadI
PushI 14
Add
Exchange
StoreC
PushI 99
PushD $record-creation-temp
LoadI
PushI 15
Add
Exchange
StoreC
PushI 45
PushD $record-creation-temp
LoadI
PushI 16
Add
Exchange
StoreC
PushI 115
PushD $record-creation-temp
LoadI
PushI 17
Add
Exchange
StoreC
PushI 116
PushD $record-creation-temp
LoadI
PushI 18
Add
Exchange
StoreC
PushI 114
PushD $record-creation-temp
LoadI
PushI 19
Add
Exchange
StoreC
PushI 45
PushD $record-creation-temp
LoadI
PushI 20
Add
Exchange
StoreC
PushI 52
PushD $record-creation-temp
LoadI
PushI 21
Add
Exchange
StoreC
PushD $record-creation-temp
LoadI
Jump -function-body-19--exit-handshake
Jump $$no return
Label -function-body-19--exit-handshake
PushD $frame-pointer
LoadI
PushI 8
Subtract
LoadI
PushD -function-body-20-return-addr
Exchange
StoreI
PushD $frame-pointer
LoadI
PushI 4
Subtract
LoadI
PushD $frame-pointer
Exchange
StoreI
PushI 8
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD -function-body-20-return-addr
LoadI
Return
Label -function-body-20--end
PushD -function-definition-4-f4-start
StoreI
PushD $global-memory-block
PushI 16
Add %% f5
DLabel -function-body-22-return-addr
DataZ 4
Jump -function-body-22--end
Label -function-definition-5-f5-start
PushD $frame-pointer
LoadI
PushD $stack-pointer
LoadI
PushI 4
Subtract
Exchange
StoreI
PushD $stack-pointer
LoadI
PushI 8
Subtract
Exchange
StoreI
PushD $stack-pointer
LoadI
PushD $frame-pointer
Exchange
StoreI
PushI -8
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushI 10
PushI 1
Add
PushI 12
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 6
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 9
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushI 10
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 22
Add
Exchange
StoreC
PushI 102
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreC
PushI 117
PushD $record-creation-temp
LoadI
PushI 13
Add
Exchange
StoreC
PushI 110
PushD $record-creation-temp
LoadI
PushI 14
Add
Exchange
StoreC
PushI 99
PushD $record-creation-temp
LoadI
PushI 15
Add
Exchange
StoreC
PushI 45
PushD $record-creation-temp
LoadI
PushI 16
Add
Exchange
StoreC
PushI 115
PushD $record-creation-temp
LoadI
PushI 17
Add
Exchange
StoreC
PushI 116
PushD $record-creation-temp
LoadI
PushI 18
Add
Exchange
StoreC
PushI 114
PushD $record-creation-temp
LoadI
PushI 19
Add
Exchange
StoreC
PushI 45
PushD $record-creation-temp
LoadI
PushI 20
Add
Exchange
StoreC
PushI 53
PushD $record-creation-temp
LoadI
PushI 21
Add
Exchange
StoreC
PushD $record-creation-temp
LoadI
Jump -function-body-21--exit-handshake
Jump $$no return
Label -function-body-21--exit-handshake
PushD $frame-pointer
LoadI
PushI 8
Subtract
LoadI
PushD -function-body-22-return-addr
Exchange
StoreI
PushD $frame-pointer
LoadI
PushI 4
Subtract
LoadI
PushD $frame-pointer
Exchange
StoreI
PushI 8
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD -function-body-22-return-addr
LoadI
Return
Label -function-body-22--end
PushD -function-definition-5-f5-start
StoreI
PushD $global-memory-block
PushI 20
Add %% a1
PushI 1
PushI 1
Add
PushI 12
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 6
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 9
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushI 1
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 13
Add
Exchange
StoreC
PushI 73
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreC
PushD $record-creation-temp
LoadI
StoreI
PushD $global-memory-block
PushI 24
Add %% a2
PushI 2
PushI 1
Add
PushI 12
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 6
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 9
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushI 2
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 14
Add
Exchange
StoreC
PushI 65
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreC
PushI 109
PushD $record-creation-temp
LoadI
PushI 13
Add
Exchange
StoreC
PushD $record-creation-temp
LoadI
StoreI
PushD $global-memory-block
PushI 28
Add %% a3
PushI 4
PushI 1
Add
PushI 12
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 6
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 9
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushI 4
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 16
Add
Exchange
StoreC
PushI 103
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreC
PushI 111
PushD $record-creation-temp
LoadI
PushI 13
Add
Exchange
StoreC
PushI 111
PushD $record-creation-temp
LoadI
PushI 14
Add
Exchange
StoreC
PushI 100
PushD $record-creation-temp
LoadI
PushI 15
Add
Exchange
StoreC
PushD $record-creation-temp
LoadI
StoreI
PushD $global-memory-block
PushI 32
Add %% a4
PushI 3
PushI 1
Add
PushI 12
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 6
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 9
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushI 3
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 15
Add
Exchange
StoreC
PushI 98
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreC
PushI 97
PushD $record-creation-temp
LoadI
PushI 13
Add
Exchange
StoreC
PushI 100
PushD $record-creation-temp
LoadI
PushI 14
Add
Exchange
StoreC
PushD $record-creation-temp
LoadI
StoreI
PushD $global-memory-block
PushI 36
Add %% space
PushI 1
PushI 1
Add
PushI 12
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 6
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 9
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushI 1
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 13
Add
Exchange
StoreC
PushI 32
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreC
PushD $record-creation-temp
LoadI
StoreI
PushI 4
PushI 5
Multiply
PushI 16
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 7
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 2
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushI 5
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreI
PushI 4
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
DLabel -populate-creation-23-elemAddr
DataZ 4
PushD $record-creation-temp
LoadI
Duplicate
PushI 16
Add
PushD -populate-creation-23-elemAddr
Exchange
StoreI
PushD -populate-creation-23-elemAddr
LoadI
PushD $global-memory-block
PushI 20
Add %% a1
LoadI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD $global-memory-block
PushI 0
Add %% f1
LoadI
CallV
PushD $stack-pointer
LoadI
LoadI
PushI 4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
StoreI
PushI 4
PushD -populate-creation-23-elemAddr
LoadI
Add
PushD -populate-creation-23-elemAddr
Exchange
StoreI
PushD -populate-creation-23-elemAddr
LoadI
PushD $global-memory-block
PushI 36
Add %% space
LoadI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD $global-memory-block
PushI 0
Add %% f1
LoadI
CallV
PushD $stack-pointer
LoadI
LoadI
PushI 4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
StoreI
PushI 4
PushD -populate-creation-23-elemAddr
LoadI
Add
PushD -populate-creation-23-elemAddr
Exchange
StoreI
PushD -populate-creation-23-elemAddr
LoadI
PushD $global-memory-block
PushI 24
Add %% a2
LoadI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD $global-memory-block
PushI 0
Add %% f1
LoadI
CallV
PushD $stack-pointer
LoadI
LoadI
PushI 4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
StoreI
PushI 4
PushD -populate-creation-23-elemAddr
LoadI
Add
PushD -populate-creation-23-elemAddr
Exchange
StoreI
PushD -populate-creation-23-elemAddr
LoadI
PushD $global-memory-block
PushI 36
Add %% space
LoadI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD $global-memory-block
PushI 0
Add %% f1
LoadI
CallV
PushD $stack-pointer
LoadI
LoadI
PushI 4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
StoreI
PushI 4
PushD -populate-creation-23-elemAddr
LoadI
Add
PushD -populate-creation-23-elemAddr
Exchange
StoreI
PushD -populate-creation-23-elemAddr
LoadI
PushD $global-memory-block
PushI 28
Add %% a3
LoadI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD $global-memory-block
PushI 0
Add %% f1
LoadI
CallV
PushD $stack-pointer
LoadI
LoadI
PushI 4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
StoreI
PushI 4
PushD -populate-creation-23-elemAddr
LoadI
Add
PushD -populate-creation-23-elemAddr
Exchange
StoreI
PushI 4
Call $print-array-subroutine
PushD $print-format-newline
Printf
PushI 4
PushI 4
Multiply
PushI 16
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 7
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushI 4
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreI
PushI 4
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
DLabel -populate-creation-24-elemAddr
DataZ 4
PushD $record-creation-temp
LoadI
Duplicate
PushI 16
Add
PushD -populate-creation-24-elemAddr
Exchange
StoreI
PushD -populate-creation-24-elemAddr
LoadI
PushD $global-memory-block
PushI 4
Add %% f2
LoadI
StoreI
PushI 4
PushD -populate-creation-24-elemAddr
LoadI
Add
PushD -populate-creation-24-elemAddr
Exchange
StoreI
PushD -populate-creation-24-elemAddr
LoadI
PushD $global-memory-block
PushI 8
Add %% f3
LoadI
StoreI
PushI 4
PushD -populate-creation-24-elemAddr
LoadI
Add
PushD -populate-creation-24-elemAddr
Exchange
StoreI
PushD -populate-creation-24-elemAddr
LoadI
PushD $global-memory-block
PushI 12
Add %% f4
LoadI
StoreI
PushI 4
PushD -populate-creation-24-elemAddr
LoadI
Add
PushD -populate-creation-24-elemAddr
Exchange
StoreI
PushD -populate-creation-24-elemAddr
LoadI
PushD $global-memory-block
PushI 16
Add %% f5
LoadI
StoreI
PushI 4
PushD -populate-creation-24-elemAddr
LoadI
Add
PushD -populate-creation-24-elemAddr
Exchange
StoreI
PushI 1
Call $print-array-subroutine
PushD $global-memory-block
PushI 40
Add %% arr1
PushI 4
Duplicate
JumpNeg $$negative-length-array
Duplicate
PushI 4
Multiply
Duplicate
PushD $array-datasize-temp
Exchange
StoreI
PushI 16
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 7
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
PushI 16
Add
PushD $array-datasize-temp
LoadI
Call $clear-n-bytes-subroutine
PushI 4
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
StoreI
PushD $global-memory-block
PushI 40
Add %% arr1
LoadI
PushI 0
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-25-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-25-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
PushD $global-memory-block
PushI 4
Add %% f2
LoadI
StoreI
PushD $global-memory-block
PushI 40
Add %% arr1
LoadI
PushI 1
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-26-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-26-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
PushD $global-memory-block
PushI 8
Add %% f3
LoadI
StoreI
PushD $global-memory-block
PushI 40
Add %% arr1
LoadI
PushI 2
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-27-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-27-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
PushD $global-memory-block
PushI 12
Add %% f4
LoadI
StoreI
PushD $global-memory-block
PushI 40
Add %% arr1
LoadI
PushI 3
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-28-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-28-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
PushD $global-memory-block
PushI 16
Add %% f5
LoadI
StoreI
PushD $global-memory-block
PushI 40
Add %% arr1
LoadI
PushI 1
Call $print-array-subroutine
PushD $print-format-newline
Printf
PushD $global-memory-block
PushI 40
Add %% arr1
LoadI
PushI 0
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-29-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-29-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
LoadI
CallV
PushD $stack-pointer
LoadI
LoadI
PushI 4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
Call $print-string
PushD $print-format-space
Printf
PushD $global-memory-block
PushI 40
Add %% arr1
LoadI
PushI 1
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-30-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-30-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
LoadI
CallV
PushD $stack-pointer
LoadI
LoadI
PushI 4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
Call $print-string
PushD $print-format-space
Printf
PushD $global-memory-block
PushI 40
Add %% arr1
LoadI
PushI 2
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-31-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-31-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
LoadI
CallV
PushD $stack-pointer
LoadI
LoadI
PushI 4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
Call $print-string
PushD $print-format-space
Printf
PushD $global-memory-block
PushI 40
Add %% arr1
LoadI
PushI 3
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-32-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-32-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
LoadI
CallV
PushD $stack-pointer
LoadI
LoadI
PushI 4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
Call $print-string
PushD $print-format-newline
Printf
PushD $global-memory-block
PushI 44
Add %% arr2
PushI 5
Duplicate
JumpNeg $$negative-length-array
Duplicate
PushI 4
Multiply
Duplicate
PushD $array-datasize-temp
Exchange
StoreI
PushI 16
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 7
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 2
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
PushI 16
Add
PushD $array-datasize-temp
LoadI
Call $clear-n-bytes-subroutine
PushI 4
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
StoreI
PushD $global-memory-block
PushI 44
Add %% arr2
LoadI
PushI 0
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-33-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-33-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
PushD $global-memory-block
PushI 20
Add %% a1
LoadI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD $global-memory-block
PushI 0
Add %% f1
LoadI
CallV
PushD $stack-pointer
LoadI
LoadI
PushI 4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
StoreI
PushD $global-memory-block
PushI 44
Add %% arr2
LoadI
PushI 1
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-34-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-34-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
PushD $global-memory-block
PushI 36
Add %% space
LoadI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD $global-memory-block
PushI 0
Add %% f1
LoadI
CallV
PushD $stack-pointer
LoadI
LoadI
PushI 4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
StoreI
PushD $global-memory-block
PushI 44
Add %% arr2
LoadI
PushI 2
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-35-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-35-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
PushD $global-memory-block
PushI 24
Add %% a2
LoadI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD $global-memory-block
PushI 0
Add %% f1
LoadI
CallV
PushD $stack-pointer
LoadI
LoadI
PushI 4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
StoreI
PushD $global-memory-block
PushI 44
Add %% arr2
LoadI
PushI 3
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-36-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-36-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
PushD $global-memory-block
PushI 36
Add %% space
LoadI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD $global-memory-block
PushI 0
Add %% f1
LoadI
CallV
PushD $stack-pointer
LoadI
LoadI
PushI 4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
StoreI
PushD $global-memory-block
PushI 44
Add %% arr2
LoadI
PushI 4
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-37-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-37-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
PushD $global-memory-block
PushI 32
Add %% a4
LoadI
PushI -4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
PushD $stack-pointer
LoadI
Exchange
StoreI
PushD $global-memory-block
PushI 0
Add %% f1
LoadI
CallV
PushD $stack-pointer
LoadI
LoadI
PushI 4
PushD $stack-pointer
LoadI
Add
PushD $stack-pointer
Exchange
StoreI
StoreI
PushD $global-memory-block
PushI 44
Add %% arr2
LoadI
PushI 4
Call $print-array-subroutine
PushD $global-memory-block
PushI 48
Add %% arr3
PushD $global-memory-block
PushI 44
Add %% arr2
LoadI
Duplicate
JumpFalse $$null-array
PushD $cloned-array-temp
Exchange
StoreI
PushD $cloned-array-temp
LoadI
PushI 0
Add
LoadI
PushD $array-identifier-temp
Exchange
StoreI
PushD $cloned-array-temp
LoadI
PushI 4
Add
LoadI
PushD $array-status-temp
Exchange
StoreI
PushD $cloned-array-temp
LoadI
PushI 12
Add
LoadI
Duplicate
PushD $array-length-temp
Exchange
StoreI
PushD $cloned-array-temp
LoadI
PushI 8
Add
LoadI
Duplicate
PushD $array-subtype-size-temp
Exchange
StoreI
Multiply
Duplicate
PushD $array-datasize-temp
Exchange
StoreI
PushI 16
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushD $array-identifier-temp
LoadI
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushD $array-status-temp
LoadI
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushD $array-subtype-size-temp
LoadI
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushD $array-length-temp
LoadI
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreI
PushI 0
PushD $array-element-temp
Exchange
StoreI
Label -clone-element-38-loop-start
PushD $array-datasize-temp
LoadI
PushD $array-element-temp
LoadI
Subtract
JumpFalse -clone-element-38-end
PushD $record-creation-temp
LoadI
PushI 16
Add
PushD $array-element-temp
LoadI
Add
PushD $cloned-array-temp
LoadI
PushI 16
Add
PushD $array-element-temp
LoadI
Add
LoadC
StoreC
PushI 1
PushD $array-element-temp
LoadI
Add
PushD $array-element-temp
Exchange
StoreI
Jump -clone-element-38-loop-start
Label -clone-element-38-end
PushD $record-creation-temp
LoadI
StoreI
PushD $global-memory-block
PushI 48
Add %% arr3
LoadI
PushI 4
Call $print-array-subroutine
PushD $print-format-newline
Printf
PushD $global-memory-block
PushI 44
Add %% arr2
LoadI
Duplicate
JumpFalse $$null-array
PushI 12
Add
LoadI
PushD $print-format-integer
Printf
PushD $print-format-space
Printf
PushD $global-memory-block
PushI 48
Add %% arr3
LoadI
Duplicate
JumpFalse $$null-array
PushI 12
Add
LoadI
PushD $print-format-integer
Printf
PushD $print-format-newline
Printf
PushD $global-memory-block
PushI 52
Add %% arr4
PushI 4
PushI 2
Multiply
PushI 16
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 7
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 2
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushI 2
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreI
PushI 4
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
DLabel -populate-creation-41-elemAddr
DataZ 4
PushD $record-creation-temp
LoadI
Duplicate
PushI 16
Add
PushD -populate-creation-41-elemAddr
Exchange
StoreI
PushD -populate-creation-41-elemAddr
LoadI
PushI 4
PushI 2
Multiply
PushI 16
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 7
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushI 2
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreI
PushI 4
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
DLabel -populate-creation-39-elemAddr
DataZ 4
PushD $record-creation-temp
LoadI
Duplicate
PushI 16
Add
PushD -populate-creation-39-elemAddr
Exchange
StoreI
PushD -populate-creation-39-elemAddr
LoadI
PushD $global-memory-block
PushI 4
Add %% f2
LoadI
StoreI
PushI 4
PushD -populate-creation-39-elemAddr
LoadI
Add
PushD -populate-creation-39-elemAddr
Exchange
StoreI
PushD -populate-creation-39-elemAddr
LoadI
PushD $global-memory-block
PushI 8
Add %% f3
LoadI
StoreI
PushI 4
PushD -populate-creation-39-elemAddr
LoadI
Add
PushD -populate-creation-39-elemAddr
Exchange
StoreI
StoreI
PushI 4
PushD -populate-creation-41-elemAddr
LoadI
Add
PushD -populate-creation-41-elemAddr
Exchange
StoreI
PushD -populate-creation-41-elemAddr
LoadI
PushI 4
PushI 2
Multiply
PushI 16
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 7
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushI 2
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreI
PushI 4
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
DLabel -populate-creation-40-elemAddr
DataZ 4
PushD $record-creation-temp
LoadI
Duplicate
PushI 16
Add
PushD -populate-creation-40-elemAddr
Exchange
StoreI
PushD -populate-creation-40-elemAddr
LoadI
PushD $global-memory-block
PushI 8
Add %% f3
LoadI
StoreI
PushI 4
PushD -populate-creation-40-elemAddr
LoadI
Add
PushD -populate-creation-40-elemAddr
Exchange
StoreI
PushD -populate-creation-40-elemAddr
LoadI
PushD $global-memory-block
PushI 12
Add %% f4
LoadI
StoreI
PushI 4
PushD -populate-creation-40-elemAddr
LoadI
Add
PushD -populate-creation-40-elemAddr
Exchange
StoreI
StoreI
PushI 4
PushD -populate-creation-41-elemAddr
LoadI
Add
PushD -populate-creation-41-elemAddr
Exchange
StoreI
StoreI
PushD $global-memory-block
PushI 52
Add %% arr4
LoadI
PushI 1
Call $print-array-subroutine
PushD $print-format-newline
Printf
PushD $global-memory-block
PushI 56
Add %% arr5
PushI 2
Duplicate
JumpNeg $$negative-length-array
Duplicate
PushI 4
Multiply
Duplicate
PushD $array-datasize-temp
Exchange
StoreI
PushI 16
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 7
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 2
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
PushI 16
Add
PushD $array-datasize-temp
LoadI
Call $clear-n-bytes-subroutine
PushI 4
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
StoreI
PushD $global-memory-block
PushI 56
Add %% arr5
LoadI
PushI 0
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-42-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-42-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
PushI 4
Duplicate
JumpNeg $$negative-length-array
Duplicate
PushI 4
Multiply
Duplicate
PushD $array-datasize-temp
Exchange
StoreI
PushI 16
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 7
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
PushI 16
Add
PushD $array-datasize-temp
LoadI
Call $clear-n-bytes-subroutine
PushI 4
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
StoreI
PushD $global-memory-block
PushI 56
Add %% arr5
LoadI
PushI 0
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-43-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-43-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
PushD $global-memory-block
PushI 40
Add %% arr1
LoadI
StoreI
PushD $global-memory-block
PushI 56
Add %% arr5
LoadI
PushI 1
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-44-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-44-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
PushI 2
Duplicate
JumpNeg $$negative-length-array
Duplicate
PushI 4
Multiply
Duplicate
PushD $array-datasize-temp
Exchange
StoreI
PushI 16
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushI 7
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushI 0
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
PushI 16
Add
PushD $array-datasize-temp
LoadI
Call $clear-n-bytes-subroutine
PushI 4
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreI
PushD $record-creation-temp
LoadI
StoreI
PushD $global-memory-block
PushI 56
Add %% arr5
LoadI
PushI 1
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-45-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-45-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
PushD $global-memory-block
PushI 52
Add %% arr4
LoadI
PushI 1
PushD $a-indexing-index
Exchange
StoreI
PushD $a-indexing-array
Exchange
StoreI
PushD $a-indexing-array
LoadI
JumpFalse $$null-array
PushD $a-indexing-index
LoadI
JumpNeg $$index-out-of-bound
PushD $a-indexing-index
LoadI
PushD $a-indexing-array
LoadI
PushI 12
Add
LoadI
Subtract
JumpNeg -array-indexing-46-in-bounds
Jump $$index-out-of-bound
Label -array-indexing-46-in-bounds
Nop
PushD $a-indexing-array
LoadI
PushI 16
Add
PushD $a-indexing-index
LoadI
PushI 4
Multiply
Add
LoadI
StoreI
PushD $global-memory-block
PushI 56
Add %% arr5
LoadI
PushI 1
Call $print-array-subroutine
PushD $print-format-newline
Printf
PushD $global-memory-block
PushI 60
Add %% arr6
PushD $global-memory-block
PushI 56
Add %% arr5
LoadI
Duplicate
JumpFalse $$null-array
PushD $cloned-array-temp
Exchange
StoreI
PushD $cloned-array-temp
LoadI
PushI 0
Add
LoadI
PushD $array-identifier-temp
Exchange
StoreI
PushD $cloned-array-temp
LoadI
PushI 4
Add
LoadI
PushD $array-status-temp
Exchange
StoreI
PushD $cloned-array-temp
LoadI
PushI 12
Add
LoadI
Duplicate
PushD $array-length-temp
Exchange
StoreI
PushD $cloned-array-temp
LoadI
PushI 8
Add
LoadI
Duplicate
PushD $array-subtype-size-temp
Exchange
StoreI
Multiply
Duplicate
PushD $array-datasize-temp
Exchange
StoreI
PushI 16
Add
Call -mem-manager-allocate
PushD $record-creation-temp
Exchange
StoreI
PushD $array-identifier-temp
LoadI
PushD $record-creation-temp
LoadI
PushI 0
Add
Exchange
StoreI
PushD $array-status-temp
LoadI
PushD $record-creation-temp
LoadI
PushI 4
Add
Exchange
StoreI
PushD $array-subtype-size-temp
LoadI
PushD $record-creation-temp
LoadI
PushI 8
Add
Exchange
StoreI
PushD $array-length-temp
LoadI
PushD $record-creation-temp
LoadI
PushI 12
Add
Exchange
StoreI
PushI 0
PushD $array-element-temp
Exchange
StoreI
Label -clone-element-47-loop-start
PushD $array-datasize-temp
LoadI
PushD $array-element-temp
LoadI
Subtract
JumpFalse -clone-element-47-end
PushD $record-creation-temp
LoadI
PushI 16
Add
PushD $array-element-temp
LoadI
Add
PushD $cloned-array-temp
LoadI
PushI 16
Add
PushD $array-element-temp
LoadI
Add
LoadC
StoreC
PushI 1
PushD $array-element-temp
LoadI
Add
PushD $array-element-temp
Exchange
StoreI
Jump -clone-element-47-loop-start
Label -clone-element-47-end
PushD $record-creation-temp
LoadI
StoreI
PushD $global-memory-block
PushI 60
Add %% arr6
LoadI
PushI 1
Call $print-array-subroutine
Halt
Label -mem-manager-make-tags
DLabel $mmgr-tags-size
DataZ 4
DLabel $mmgr-tags-start
DataZ 4
DLabel $mmgr-tags-available
DataZ 4
DLabel $mmgr-tags-nextptr
DataZ 4
DLabel $mmgr-tags-prevptr
DataZ 4
DLabel $mmgr-tags-return
DataZ 4
PushD $mmgr-tags-return
Exchange
StoreI
PushD $mmgr-tags-size
Exchange
StoreI
PushD $mmgr-tags-start
Exchange
StoreI
PushD $mmgr-tags-available
Exchange
StoreI
PushD $mmgr-tags-nextptr
Exchange
StoreI
PushD $mmgr-tags-prevptr
Exchange
StoreI
PushD $mmgr-tags-prevptr
LoadI
PushD $mmgr-tags-size
LoadI
PushD $mmgr-tags-available
LoadI
PushD $mmgr-tags-start
LoadI
Call -mem-manager-one-tag
PushD $mmgr-tags-nextptr
LoadI
PushD $mmgr-tags-size
LoadI
PushD $mmgr-tags-available
LoadI
PushD $mmgr-tags-start
LoadI
Duplicate
PushI 4
Add
LoadI
Add
PushI 9
Subtract
Call -mem-manager-one-tag
PushD $mmgr-tags-return
LoadI
Return
Label -mem-manager-one-tag
DLabel $mmgr-onetag-return
DataZ 4
DLabel $mmgr-onetag-location
DataZ 4
DLabel $mmgr-onetag-available
DataZ 4
DLabel $mmgr-onetag-size
DataZ 4
DLabel $mmgr-onetag-pointer
DataZ 4
PushD $mmgr-onetag-return
Exchange
StoreI
PushD $mmgr-onetag-location
Exchange
StoreI
PushD $mmgr-onetag-available
Exchange
StoreI
PushD $mmgr-onetag-size
Exchange
StoreI
PushD $mmgr-onetag-location
LoadI
PushI 0
Add
Exchange
StoreI
PushD $mmgr-onetag-size
LoadI
PushD $mmgr-onetag-location
LoadI
PushI 4
Add
Exchange
StoreI
PushD $mmgr-onetag-available
LoadI
PushD $mmgr-onetag-location
LoadI
PushI 8
Add
Exchange
StoreC
PushD $mmgr-onetag-return
LoadI
Return
Label -mem-manager-allocate
DLabel $mmgr-alloc-return
DataZ 4
DLabel $mmgr-alloc-size
DataZ 4
DLabel $mmgr-alloc-current-block
DataZ 4
DLabel $mmgr-alloc-remainder-block
DataZ 4
DLabel $mmgr-alloc-remainder-size
DataZ 4
PushD $mmgr-alloc-return
Exchange
StoreI
PushI 18
Add
PushD $mmgr-alloc-size
Exchange
StoreI
PushD $heap-first-free
LoadI
PushD $mmgr-alloc-current-block
Exchange
StoreI
Label -mmgr-alloc-process-current
PushD $mmgr-alloc-current-block
LoadI
JumpFalse -mmgr-alloc-no-block-works
Label -mmgr-alloc-test-block
PushD $mmgr-alloc-current-block
LoadI
PushI 4
Add
LoadI
PushD $mmgr-alloc-size
LoadI
Subtract
PushI 1
Add
JumpPos -mmgr-alloc-found-block
PushD $mmgr-alloc-current-block
LoadI
Duplicate
PushI 4
Add
LoadI
Add
PushI 9
Subtract
PushI 0
Add
LoadI
PushD $mmgr-alloc-current-block
Exchange
StoreI
Jump -mmgr-alloc-process-current
Label -mmgr-alloc-found-block
PushD $mmgr-alloc-current-block
LoadI
Call -mem-manager-remove-block
PushD $mmgr-alloc-current-block
LoadI
PushI 4
Add
LoadI
PushD $mmgr-alloc-size
LoadI
Subtract
PushI 26
Subtract
JumpNeg -mmgr-alloc-return-userblock
PushD $mmgr-alloc-current-block
LoadI
PushD $mmgr-alloc-size
LoadI
Add
PushD $mmgr-alloc-remainder-block
Exchange
StoreI
PushD $mmgr-alloc-size
LoadI
PushD $mmgr-alloc-current-block
LoadI
PushI 4
Add
LoadI
Exchange
Subtract
PushD $mmgr-alloc-remainder-size
Exchange
StoreI
PushI 0
PushI 0
PushI 0
PushD $mmgr-alloc-current-block
LoadI
PushD $mmgr-alloc-size
LoadI
Call -mem-manager-make-tags
PushI 0
PushI 0
PushI 1
PushD $mmgr-alloc-remainder-block
LoadI
PushD $mmgr-alloc-remainder-size
LoadI
Call -mem-manager-make-tags
PushD $mmgr-alloc-remainder-block
LoadI
PushI 9
Add
Call -mem-manager-deallocate
Jump -mmgr-alloc-return-userblock
Label -mmgr-alloc-no-block-works
PushD $mmgr-alloc-size
LoadI
PushD $mmgr-newblock-size
Exchange
StoreI
PushD $heap-after-ptr
LoadI
PushD $mmgr-newblock-block
Exchange
StoreI
PushD $mmgr-newblock-size
LoadI
PushD $heap-after-ptr
LoadI
Add
PushD $heap-after-ptr
Exchange
StoreI
PushI 0
PushI 0
PushI 0
PushD $mmgr-newblock-block
LoadI
PushD $mmgr-newblock-size
LoadI
Call -mem-manager-make-tags
PushD $mmgr-newblock-block
LoadI
PushD $mmgr-alloc-current-block
Exchange
StoreI
Label -mmgr-alloc-return-userblock
PushD $mmgr-alloc-current-block
LoadI
PushI 9
Add
PushD $mmgr-alloc-return
LoadI
Return
Label -mem-manager-deallocate
DLabel $mmgr-dealloc-return
DataZ 4
DLabel $mmgr-dealloc-block
DataZ 4
PushD $mmgr-dealloc-return
Exchange
StoreI
PushI 9
Subtract
PushD $mmgr-dealloc-block
Exchange
StoreI
PushD $heap-first-free
LoadI
JumpFalse -mmgr-bypass-firstFree
PushD $mmgr-dealloc-block
LoadI
PushD $heap-first-free
LoadI
PushI 0
Add
Exchange
StoreI
Label -mmgr-bypass-firstFree
PushI 0
PushD $mmgr-dealloc-block
LoadI
PushI 0
Add
Exchange
StoreI
PushD $heap-first-free
LoadI
PushD $mmgr-dealloc-block
LoadI
Duplicate
PushI 4
Add
LoadI
Add
PushI 9
Subtract
PushI 0
Add
Exchange
StoreI
PushI 1
PushD $mmgr-dealloc-block
LoadI
PushI 8
Add
Exchange
StoreC
PushI 1
PushD $mmgr-dealloc-block
LoadI
Duplicate
PushI 4
Add
LoadI
Add
PushI 9
Subtract
PushI 8
Add
Exchange
StoreC
PushD $mmgr-dealloc-block
LoadI
PushD $heap-first-free
Exchange
StoreI
PushD $mmgr-dealloc-return
LoadI
Return
Label -mem-manager-remove-block
DLabel $mmgr-remove-return
DataZ 4
DLabel $mmgr-remove-block
DataZ 4
DLabel $mmgr-remove-prev
DataZ 4
DLabel $mmgr-remove-next
DataZ 4
PushD $mmgr-remove-return
Exchange
StoreI
PushD $mmgr-remove-block
Exchange
StoreI
PushD $mmgr-remove-block
LoadI
PushI 0
Add
LoadI
PushD $mmgr-remove-prev
Exchange
StoreI
PushD $mmgr-remove-block
LoadI
Duplicate
PushI 4
Add
LoadI
Add
PushI 9
Subtract
PushI 0
Add
LoadI
PushD $mmgr-remove-next
Exchange
StoreI
Label -mmgr-remove-process-prev
PushD $mmgr-remove-prev
LoadI
JumpFalse -mmgr-remove-no-prev
PushD $mmgr-remove-next
LoadI
PushD $mmgr-remove-prev
LoadI
Duplicate
PushI 4
Add
LoadI
Add
PushI 9
Subtract
PushI 0
Add
Exchange
StoreI
Jump -mmgr-remove-process-next
Label -mmgr-remove-no-prev
PushD $mmgr-remove-next
LoadI
PushD $heap-first-free
Exchange
StoreI
Label -mmgr-remove-process-next
PushD $mmgr-remove-next
LoadI
JumpFalse -mmgr-remove-done
PushD $mmgr-remove-prev
LoadI
PushD $mmgr-remove-next
LoadI
PushI 0
Add
Exchange
StoreI
Label -mmgr-remove-done
PushD $mmgr-remove-return
LoadI
Return
DLabel $heap-memory
|
// (C) Copyright David Gleich 2007
//
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0 (See accompanying file
// LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
#include <vector>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/core_numbers.hpp>
#include <boost/property_map/property_map.hpp>
#include <stdio.h>
using namespace boost;
const char* errstr = "";
int test_1() {
// core numbers of sample graph
typedef adjacency_list<vecS,vecS,undirectedS> Graph;
Graph G(21);
add_edge(0,1,G);
add_edge(1,2,G);
add_edge(1,3,G);
add_edge(2,3,G);
add_edge(1,4,G);
add_edge(3,4,G);
add_edge(4,5,G);
add_edge(4,6,G);
add_edge(5,6,G);
add_edge(4,7,G);
add_edge(5,7,G);
add_edge(6,7,G);
add_edge(7,8,G);
add_edge(3,9,G);
add_edge(8,9,G);
add_edge(8,10,G);
add_edge(9,10,G);
add_edge(10,11,G);
add_edge(10,12,G);
add_edge(3,13,G);
add_edge(9,13,G);
add_edge(3,14,G);
add_edge(9,14,G);
add_edge(13,14,G);
add_edge(16,17,G);
add_edge(16,18,G);
add_edge(17,19,G);
add_edge(18,19,G);
add_edge(19,20,G);
std::vector<int> core_nums(num_vertices(G));
core_numbers(G,
make_iterator_property_map(core_nums.begin(), get(vertex_index,G)));
for (size_t i=0; i<num_vertices(G); ++i) {
printf("vertex %3zu : %i\n", i, core_nums[i]);
}
int correct[21]={1,2,2,3,3,3,3,3,2,3,2,1,1,3,3,0,2,2,2,2,1};
for (size_t i=0; i<num_vertices(G); ++i) {
if (core_nums[i] != correct[i]) {
return 1; // error!
}
}
return 0;
}
int test_2() {
// core numbers of sample graph
typedef adjacency_list < listS, vecS, undirectedS,
no_property, property < edge_weight_t, int > > graph_t;
int num_nodes = 3;
typedef std::pair<int,int> Edge;
Edge edge_array[] = { Edge(0,1), Edge(0,2), Edge(1,2) };
int weights[] = {-1, -2, -2};
int num_arcs = sizeof(edge_array) / sizeof(Edge);
graph_t G(edge_array, edge_array + num_arcs, weights, num_nodes);
property_map<graph_t, edge_weight_t>::type weightmap = get(edge_weight, G);
std::vector<int> core_nums(num_vertices(G));
weighted_core_numbers(G,
make_iterator_property_map(core_nums.begin(), get(vertex_index,G)));
for (size_t i=0; i<num_vertices(G); ++i) {
printf("vertex %3zu : %i\n", i, core_nums[i]);
}
int correct[3]={-1,-1,-4};
for (size_t i=0; i<num_vertices(G); ++i) {
if (core_nums[i] != correct[i]) {
return 1; // error!
}
}
return 0;
}
int test_3() {
// core numbers of a directed graph, the core numbers of a directed
// cycle are always one
typedef adjacency_list < vecS, vecS, directedS > graph_t;
int num_nodes = 5;
typedef std::pair<int,int> Edge;
Edge edge_array[] = { Edge(0,1),Edge(1,2),Edge(2,3),Edge(3,4),Edge(4,0) };
int num_arcs = sizeof(edge_array) / sizeof(Edge);
graph_t G(edge_array, edge_array + num_arcs, num_nodes);
std::vector<int> core_nums(num_vertices(G));
core_numbers(G,
make_iterator_property_map(core_nums.begin(), get(vertex_index,G)));
for (size_t i=0; i<num_vertices(G); ++i) {
printf("vertex %3zu : %i\n", i, core_nums[i]);
}
int correct[5]={1,1,1,1,1};
for (size_t i=0; i<num_vertices(G); ++i) {
if (core_nums[i] != correct[i]) {
return 1; // error!
}
}
return 0;
}
int main(int argc, char **argv) {
int nfail = 0, ntotal = 0;
int rval;
const char* name;
name= "core_numbers";
rval= test_1(); ntotal++;
if (rval!= 0) { nfail++; printf("%20s %50s\n", name, errstr); }
else { printf("%20s success\n", name); }
name= "weighted_core_numbers";
rval= test_2(); ntotal++;
if (rval!= 0) { nfail++; printf("%20s %50s\n", name, errstr); }
else { printf("%20s success\n", name); }
name= "directed_corenums";
rval= test_3(); ntotal++;
if (rval!= 0) { nfail++; printf("%20s %50s\n", name, errstr); }
else { printf("%20s success\n", name); }
printf("\n");
printf("Total tests : %3i\n", ntotal);
printf("Total failed : %3i\n", nfail);
return nfail!=0;
}
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %r8
push %rax
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0xfbee, %rcx
nop
nop
nop
nop
nop
sub %rax, %rax
mov $0x6162636465666768, %r12
movq %r12, %xmm5
movups %xmm5, (%rcx)
and $51181, %rax
lea addresses_normal_ht+0xbe6e, %rsi
lea addresses_normal_ht+0x13d6e, %rdi
clflush (%rsi)
nop
sub %r11, %r11
mov $49, %rcx
rep movsw
nop
nop
nop
nop
inc %r12
lea addresses_UC_ht+0x1c0a6, %rsi
lea addresses_WC_ht+0x66a, %rdi
nop
nop
nop
nop
nop
and $3828, %rbp
mov $40, %rcx
rep movsl
nop
nop
nop
xor $43366, %r12
lea addresses_UC_ht+0xdb0e, %r12
nop
nop
nop
nop
xor %rax, %rax
mov $0x6162636465666768, %rbp
movq %rbp, %xmm3
movups %xmm3, (%r12)
nop
nop
sub %rcx, %rcx
lea addresses_WT_ht+0x112ae, %rsi
lea addresses_A_ht+0x1cee, %rdi
nop
nop
nop
nop
nop
inc %rbp
mov $45, %rcx
rep movsq
nop
nop
nop
inc %rdi
lea addresses_normal_ht+0x1689e, %rcx
nop
inc %rbp
mov (%rcx), %rax
nop
nop
nop
nop
nop
xor $40059, %r12
lea addresses_WT_ht+0xa3ee, %rsi
lea addresses_normal_ht+0xbaee, %rdi
nop
nop
nop
nop
xor %r8, %r8
mov $58, %rcx
rep movsl
nop
nop
nop
xor %rcx, %rcx
lea addresses_WT_ht+0x13a60, %r8
nop
nop
nop
nop
nop
sub %rcx, %rcx
movups (%r8), %xmm3
vpextrq $1, %xmm3, %rbp
nop
inc %r11
lea addresses_WC_ht+0x1abee, %rcx
nop
nop
nop
sub %rax, %rax
vmovups (%rcx), %ymm6
vextracti128 $1, %ymm6, %xmm6
vpextrq $0, %xmm6, %rdi
dec %rsi
lea addresses_WC_ht+0xabe6, %rax
nop
nop
sub %rbp, %rbp
vmovups (%rax), %ymm5
vextracti128 $0, %ymm5, %xmm5
vpextrq $0, %xmm5, %r12
nop
nop
add %rdi, %rdi
lea addresses_A_ht+0xb7ea, %rsi
lea addresses_A_ht+0x1bf6, %rdi
clflush (%rsi)
nop
nop
nop
sub $43779, %r11
mov $118, %rcx
rep movsl
dec %rcx
lea addresses_WT_ht+0x82ba, %r8
nop
nop
nop
nop
add $10063, %r12
movl $0x61626364, (%r8)
nop
nop
nop
nop
nop
xor $10626, %rdi
lea addresses_D_ht+0x103ee, %rsi
lea addresses_A_ht+0x16b4e, %rdi
nop
nop
nop
nop
nop
and %r8, %r8
mov $35, %rcx
rep movsb
nop
nop
nop
nop
nop
sub $38209, %rcx
lea addresses_A_ht+0x1e16e, %rsi
lea addresses_normal_ht+0x103ee, %rdi
nop
sub %r12, %r12
mov $50, %rcx
rep movsl
nop
nop
nop
nop
add $9171, %r11
lea addresses_WT_ht+0x7bee, %rcx
nop
nop
inc %rax
movl $0x61626364, (%rcx)
nop
nop
nop
nop
lfence
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r8
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r14
push %r9
push %rcx
// Faulty Load
lea addresses_UC+0xd3ee, %r11
cmp $46801, %r12
mov (%r11), %r9
lea oracles, %r12
and $0xff, %r9
shlq $12, %r9
mov (%r12,%r9,1), %r9
pop %rcx
pop %r9
pop %r14
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_UC', 'same': False, 'size': 1, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'type': 'addresses_UC', 'same': True, 'size': 8, 'congruent': 0, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 16, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_normal_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_UC_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 2, 'same': True}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_UC_ht', 'same': False, 'size': 16, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_normal_ht', 'same': False, 'size': 8, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 8, 'same': True}, 'OP': 'REPM'}
{'src': {'type': 'addresses_WT_ht', 'same': False, 'size': 16, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WC_ht', 'same': True, 'size': 32, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 32, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_A_ht', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 4, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 1, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_A_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 4, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'37': 21829}
37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37
*/
|
#include "vnl/vnl_matrix_fixed_ref.hxx"
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 1, 1);
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 2, 2);
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 2, 3);
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 3, 2);
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 3, 3);
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 3, 4);
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 3, 12);
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 4, 3);
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 4, 4);
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 5, 5);
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 6, 6);
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 7, 7);
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 8, 8);
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 9, 9);
VNL_MATRIX_FIXED_REF_INSTANTIATE(float, 10, 10);
|
/*------------------------------------------------------------------------------
CGMF-1.1
Copyright TRIAD/LANL/DOE - see file LICENSE
For any questions about CGMF, please contact us at cgmf-help@lanl.gov
-------------------------------------------------------------------------------*/
//
// cgmf.cpp
//
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
#include <unistd.h>
#include <cstdlib>
#include "cgmfEvents.h"
#include "rngcgm.h"
#include "config.h"
#include "config-ff.h"
#ifdef MPIRUN
#include <mpi.h>
#endif
using namespace std;
void readUserInput (int, char *[], int);
void recordEvent (cgmfEvent *);
void printEventToFile (FILE *fp, cgmfEvent *, double);
void printSummaryEvents (cgmfEvent *);
// Default user input values
string path = "";
double incidentEnergy=-1;
int ZAIDt=0;
int nevents=0;
int startingEvent=1;
string outfilename="";
double timeCoincidenceWindow=1e-8;
int sumALF=0, sumAHF=0, sumZLF=0, sumZHF=0;
int sumNuLF=0, sumNuHF=0, sumNuPre=0, sumNuTot=0;
int sumNugLF=0, sumNugHF=0, sumNugTot=0;
double sumKELF=0.0, sumKEHF=0.0, sumTKE=0.0;
double sumXELF=0.0, sumXEHF=0.0, sumTXE=0.0;
double sumJLF=0.0, sumJHF=0.0, sumJ=0.0;
double sumEcmLF=0.0, sumEcmHF=0.0;
double sumElabLF=0.0, sumElabHF=0.0;
double sumEnPre=0.0;
double sumEcm=0.0, sumElab=0.0;
double sumEgLF=0.0, sumEgHF=0.0, sumEg=0.0;
//////////////////////////////////////////////////////////////////////////////////////
// MAIN DRIVER
//////////////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[]) {
int ip=0;
cgmfEvent* event = 0;
cgmfYields* yields;
#ifdef MPIRUN
MPI_Init (&argc, &argv);
MPI_Comm_rank (MPI_COMM_WORLD, &ip);
#endif
readUserInput(argc, argv, ip); // check the validity of the user input
// initialize random number generator
UniformRNG rng(1);
if (nevents<0) {
if(ip==0){
#ifdef MPIRUN
cout << "Not implemented: Fission fragment yields calculation (negative -nevents option) will run with a single MPI rank.\n";
#endif
rng.set_seed(startingEvent);
set_rng(rng);
yields = new cgmfYields (ZAIDt, incidentEnergy, -nevents, outfilename);
printf("\n/// CGMF-generated scission fragment yields Y(Z,A,KE,U,J,Pi,px,py,pz) saved in file %s ///\n", outfilename.c_str());
}
} else {
FILE *fp = fopen(&outfilename[0],"w");
if(ip==0) fprintf(fp, "# %5i %g %g\n", ZAIDt, incidentEnergy,timeCoincidenceWindow);
for (int i=0; i<nevents; i++) {
rng.set_seed(i+ip*nevents+startingEvent);
set_rng(rng);
if (nevents>=1000 and (i+1)%(nevents/100)==0 and ip==0) printf("%5.2f%%\n",float(i+1)/float(nevents)*100.0);
if (event != 0) delete event;
event = new cgmfEvent(ZAIDt, incidentEnergy, 0.0, timeCoincidenceWindow);
recordEvent (event);
printEventToFile (fp, event, timeCoincidenceWindow);
}
fclose(fp);
printSummaryEvents (event);
}
cgmf_cleanup();
if (event != 0) delete event;
#ifdef MPIRUN
MPI_Finalize();
#endif
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////
// THE END
//////////////////////////////////////////////////////////////////////////////////////////////
/*!
------------------------------------------------------------------------------
\brief Record a CGMF event into arrays to provide summary of N events
------------------------------------------------------------------------------
*/
void recordEvent (cgmfEvent *event) {
static int i=0;
int nuLF, nuHF, nuPre, nuTot;
int nugLF, nugHF, nugTot;
// Light fragment (Z,A)
sumALF += event->getLightFragmentMass();
sumZLF += event->getLightFragmentCharge();
// Heavy fragment (Z,A)
sumAHF += event->getHeavyFragmentMass();
sumZHF += event->getHeavyFragmentCharge();
// Kinetic energies (MeV)
sumKELF += event->getLightFragmentKineticEnergy();
sumKEHF += event->getHeavyFragmentKineticEnergy();
sumTKE = sumKELF+sumKEHF;
// Excitation energies (MeV)
sumXELF += event->getLightFragmentExcitationEnergy();
sumXEHF += event->getHeavyFragmentExcitationEnergy();
sumTXE = sumXELF+sumXEHF;
// Spin (hbar)
sumJLF += event->getLightFragmentSpin();
sumJHF += event->getHeavyFragmentSpin();
sumJ = (sumJLF+sumJHF)/2;
// Neutron multiplicities (n/f)
nuLF = event->getLightFragmentNeutronNu();
nuHF = event->getHeavyFragmentNeutronNu();
nuPre = event->getPreFissionNeutronNu();
sumNuLF += nuLF;
sumNuHF += nuHF;
sumNuPre += nuPre;
sumNuTot = sumNuLF + sumNuHF + sumNuPre;
// Neutron energies emitted from light fragment, in center-of-mass and lab frame (MeV)
for (int j=0; j<nuLF; j++) {
sumEcmLF += event->getCmNeutronEnergy(j);
sumElabLF += event->getNeutronEnergy(j);
}
// Neutron energies emitted from heavy fragment, in center-of-mass and lab frame (MeV)
for (int j=nuLF; j<nuLF+nuHF; j++) {
sumEcmHF += event->getCmNeutronEnergy(j);
sumElabHF += event->getNeutronEnergy(j);
}
// Pre-fission neutron kinetic energies (MeV)
for (int j=0; j<nuPre; j++) sumEnPre += event->getPreFissionNeutronEnergy(j);
sumEcm = sumEcmLF + sumEcmHF + sumEnPre;
sumElab = sumElabLF + sumElabHF + sumEnPre;
// Photon multiplicities (g/f)
nugLF = event->getLightFragmentPhotonNu();
nugHF = event->getHeavyFragmentPhotonNu();
nugTot = nugLF+nugHF;
sumNugLF += nugLF;
sumNugHF += nugHF;
sumNugTot = sumNugLF + sumNugHF;
// Gamma energies (MeV)
for (int j=0; j<nugLF; j++) sumEgLF += event->getPhotonEnergy(j); // Light fragment
for (int j=nugLF; j<nugLF+nugHF; j++) sumEgHF += event->getPhotonEnergy(j); // Heavy fragment
sumEg = sumEgLF + sumEgHF;
i++;
return;
}
/*!
------------------------------------------------------------------------------
\brief Print a summary of all CGMF events
------------------------------------------------------------------------------
*/
void printSummaryEvents (cgmfEvent* event) {
int ip=0,np=1;
#ifdef MPIRUN
MPI_Comm_rank (MPI_COMM_WORLD, &ip);
MPI_Comm_size (MPI_COMM_WORLD, &np);
int itmp;
MPI_Reduce(&sumZLF, &itmp, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumZLF=itmp;
MPI_Reduce(&sumALF, &itmp, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumALF=itmp;
MPI_Reduce(&sumZHF, &itmp, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumZHF=itmp;
MPI_Reduce(&sumAHF, &itmp, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumAHF=itmp;
double rtmp;
MPI_Reduce(&sumKELF, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumKELF=rtmp;
MPI_Reduce(&sumKEHF, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumKEHF=rtmp;
MPI_Reduce(&sumTKE, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumTKE=rtmp;
MPI_Reduce(&sumXELF, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumXELF=rtmp;
MPI_Reduce(&sumXEHF, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumXEHF=rtmp;
MPI_Reduce(&sumTXE, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumTXE=rtmp;
MPI_Reduce(&sumJLF, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumJLF=rtmp;
MPI_Reduce(&sumJHF, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumJHF=rtmp;
MPI_Reduce(&sumJ, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumJ=rtmp;
MPI_Reduce(&sumNuLF, &itmp, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumNuLF=itmp;
MPI_Reduce(&sumNuHF, &itmp, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumNuHF=itmp;
MPI_Reduce(&sumNuPre, &itmp, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumNuPre=itmp;
MPI_Reduce(&sumNuTot, &itmp, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumNuTot=itmp;
MPI_Reduce(&sumEcmLF, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumEcmLF=rtmp;
MPI_Reduce(&sumEcmHF, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumEcmHF=rtmp;
MPI_Reduce(&sumEcm, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumEcm=rtmp;
MPI_Reduce(&sumElabLF, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumElabLF=rtmp;
MPI_Reduce(&sumElabHF, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumElabHF=rtmp;
MPI_Reduce(&sumElab, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumElab=rtmp;
MPI_Reduce(&sumEnPre, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumEnPre=rtmp;
MPI_Reduce(&sumNugLF, &itmp, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumNugLF=itmp;
MPI_Reduce(&sumNugHF, &itmp, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumNugHF=itmp;
MPI_Reduce(&sumNugTot, &itmp, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumNugTot=itmp;
MPI_Reduce(&sumEgLF, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumEgLF=rtmp;
MPI_Reduce(&sumEgHF, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumEgHF=rtmp;
MPI_Reduce(&sumEg, &rtmp, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD ) ;
if(ip==0)
sumEg=rtmp;
nevents=np*nevents;
#endif
if(ip==0){
printf("\n\n //// CGMF Results ////\n\n");
int ZAIDt=event->getTargetNucleus();
int Zt=int(ZAIDt/1000.0);
int At=ZAIDt-1000.0*Zt;
if (incidentEnergy==0.0) {
printf("Reaction: spontaneous fission of (%2i,%3i)\n\n", Zt, At);
} else {
printf("Reaction: (n,f) on (%2i,%3i) at En=%7.2e MeV\n\n", Zt, At, event->getIncidentEnergy());
}
printf("Average Light Fragment (Z,A) = (%.2f,%.2f)\n", double(sumZLF)/nevents, double(sumALF)/nevents);
printf("Average Heavy Fragment (Z,A) = (%.2f,%.2f)\n\n", double(sumZHF)/nevents, double(sumAHF)/nevents);
printf("Average Kinetic Energies: LF = %.2f MeV ; HF = %.2f MeV ; <TKE> = %.2f MeV\n",
sumKELF/nevents,sumKEHF/nevents,sumTKE/nevents);
printf("Average Excitation Energies: LF = %.2f MeV ; HF = %.2f MeV ; <TXE> = %.2f MeV\n\n",
sumXELF/nevents,sumXEHF/nevents,sumTXE/nevents);
printf("Average Fragment Spins: <J>_LF = %.2f hbar ; <J>_HF = %.2f hbar ; <J> = %.2f hbar\n",
sumJLF/nevents,sumJHF/nevents,sumJ/nevents);
printf("\n*** Prompt Fission Neutrons ***\n\n");
printf("Multiplicities (n/f): <nu>_LF = %.2f ; <nu>_HF = %.2f ; <nu>_prefission = %.2f ; <nu>_tot = %.2f \n",
double(sumNuLF)/nevents,double(sumNuHF)/nevents,double(sumNuPre)/nevents,double(sumNuTot)/nevents);
printf("c-o-m Energies: <Ecm>_LF = %.2f MeV ; <Ecm>_HF = %.2f MeV ; <Ecm>_prefission = %.2f MeV ; <Ecm>_tot = %.2f MeV\n",
sumEcmLF/max(sumNuLF,1),sumEcmHF/max(sumNuHF,1),sumEnPre/max(sumNuPre,1),sumEcm/max(sumNuTot,1));
printf("Lab. Energies: <Elab>_LF = %.2f MeV ; <Elab>_HF = %.2f MeV ; <Elab>_prefission = %.2f MeV ; <Elab>_tot = %.2f MeV\n",
sumElabLF/max(sumNuLF,1),sumElabHF/max(sumNuHF,1),sumEnPre/max(sumNuPre,1),sumElab/max(sumNuTot,1));
printf("\n*** Prompt Fission Gammas ***\n\n");
printf("Multiplicities (g/f): <nu_g>_LF = %.2f ; <nu_g>_HF = %.2f ; <nu_g>_tot = %.2f \n",
double(sumNugLF)/nevents,double(sumNugHF)/nevents,double(sumNugTot)/nevents);
printf("Gamma Energies: <Eg>_LF = %.2f MeV ; <Eg>_HF = %.2f MeV ; <Eg>_tot = %.2f MeV\n",
sumEgLF/max(sumNugLF,1),sumEgHF/max(sumNugHF,1),sumEg/max(sumNugTot,1));
printf("\n\n //// THE END ////\n\n");
}
return;
}
/*!
------------------------------------------------------------------------------
\brief read user input from the command line, set data directory path, and
initialize random number generator.
------------------------------------------------------------------------------
*/
void readUserInput (int argc, char *argv[], int ip) {
int p;
// read user input from command line
while ((p=getopt(argc,argv,"e:n:i:f:t:d:s:"))!=-1) {
switch(p){
case 'e':
incidentEnergy=atof(optarg);
break;
case 'n':
nevents=atoi(optarg);
break;
case 'i':
ZAIDt=atoi(optarg);
break;
case 'f':
outfilename=optarg;
break;
case 't':
timeCoincidenceWindow=atof(optarg);
break;
case 'd':
path=optarg;
break;
case 's':
startingEvent=atoi(optarg);
break;
default:
break;
}
}
stringstream sip;
sip << ip;
if (outfilename=="") {
if (nevents>0) { outfilename="histories.cgmf"; } else { outfilename="yields.cgmf"; }
}
outfilename += "."+sip.str();
if(timeCoincidenceWindow<0.){
if(timeCoincidenceWindow!=-1.){
cerr << "The time coincidence window can only be -1 (infinite time coincidence window) or positive" << endl;
cerr << "Execution terminated" << endl;
#ifdef MPIRUN
MPI_Finalize();
#endif
exit(-1);
}
}
// set data directory path
if (path == "") {
if (getenv("CGMFDATA") != NULL) {
path = string(getenv("CGMFDATA"));
}
}
setdatapath(path);
return;
}
/*!
------------------------------------------------------------------------------
\brief Print a fission event in an output file.
------------------------------------------------------------------------------
*/
void printEventToFile (FILE *fp, cgmfEvent *event, double timeCoincidenceWindow) {
double eng; // energy
double diru, dirv, dirw; // directional cosines
double age; // time of emission of a photon
// LIGHT FRAGMENT --------------------------
int nul = event->getLightFragmentNeutronNu();
int nugl = event->getLightFragmentPhotonNu();
fprintf(fp, " %i %i %.3f %.1f %i %.3f %.3f %i %i 0\n", event->getLightFragmentMass(),
event->getLightFragmentCharge(), event->getLightFragmentExcitationEnergy(),
event->getLightFragmentSpin(), event->getLightFragmentParity(),
event->getLightFragmentKineticEnergy(), event->getLightFragmentKineticEnergyPost(),
event->getLightFragmentNeutronNu(), event->getLightFragmentPhotonNu());
fprintf(fp, " %.3f %.3f %.3f %.3f %.3f %.3f\n", event->getLightFragmentPreMomentumX(),
event->getLightFragmentPreMomentumY(), event->getLightFragmentPreMomentumZ(),
event->getLightFragmentPostMomentumX(), event->getLightFragmentPostMomentumY(),
event->getLightFragmentPostMomentumZ());
// Center-of-Mass neutron (energy, directional cosines) from light fragment
for (int n1=0; n1<nul; n1++) {
eng = event->getCmNeutronEnergy(n1);
diru = event->getCmNeutronDircosu(n1);
dirv = event->getCmNeutronDircosv(n1);
dirw = event->getCmNeutronDircosw(n1);
fprintf(fp, "%.3f %.3f %.3f %.3f ", diru, dirv, dirw, eng);
}
if (nul>0) fprintf(fp, "\n");
// LAB neutron (energy, directional cosines) from light fragment
for (int n1=0; n1<nul; n1++) {
eng = event->getNeutronEnergy(n1);
diru = event->getNeutronDircosu(n1);
dirv = event->getNeutronDircosv(n1);
dirw = event->getNeutronDircosw(n1);
fprintf(fp, "%.3f %.3f %.3f %.3f ", diru, dirv, dirw, eng);
}
if (nul>0) fprintf(fp, "\n");
// Photons from light fragment
for(int n1=0; n1<nugl; n1++) {
eng = event->getPhotonEnergy(n1);
diru = event->getPhotonDircosu(n1);
dirv = event->getPhotonDircosv(n1);
dirw = event->getPhotonDircosw(n1);
if (timeCoincidenceWindow<0) {
age = event->getPhotonAge(n1);
fprintf(fp, "%.3f %.3f %.3f %.3f %g ", diru, dirv, dirw, eng, age);
} else {
fprintf(fp, "%.3f %.3f %.3f %.3f ", diru, dirv, dirw, eng);
}
}
if (nugl>0) fprintf(fp, "\n");
// HEAVY FRAGMENT --------------------------
int nuh = event->getHeavyFragmentNeutronNu();
int nugh = event->getHeavyFragmentPhotonNu();
int nup = event->getPreFissionNeutronNu();
fprintf(fp, " %i %i %.3f %.1f %i %.3f %.3f %i %i %i\n", event->getHeavyFragmentMass(),
event->getHeavyFragmentCharge(), event->getHeavyFragmentExcitationEnergy(),
event->getHeavyFragmentSpin(), event->getHeavyFragmentParity(),
event->getHeavyFragmentKineticEnergy(), event->getHeavyFragmentKineticEnergyPost(),
event->getHeavyFragmentNeutronNu(), event->getHeavyFragmentPhotonNu(), nup);
fprintf(fp, " %.3f %.3f %.3f %.3f %.3f %.3f\n", event->getHeavyFragmentPreMomentumX(),
event->getHeavyFragmentPreMomentumY(), event->getHeavyFragmentPreMomentumZ(),
event->getHeavyFragmentPostMomentumX(), event->getHeavyFragmentPostMomentumY(),
event->getHeavyFragmentPostMomentumZ());
// Center-of-Mass neutron (energy, directional cosines) from heavy fragment
for (int n1=nul; n1<nul+nuh; n1++) {
eng = event->getCmNeutronEnergy(n1);
diru = event->getCmNeutronDircosu(n1);
dirv = event->getCmNeutronDircosv(n1);
dirw = event->getCmNeutronDircosw(n1);
fprintf(fp, "%.3f %.3f %.3f %.3f ", diru, dirv, dirw, eng);
}
if (nuh>0) fprintf(fp, "\n");
// LAB neutron (energy, directional cosines) from heavy fragment
for (int n1=nul; n1<nul+nuh; n1++) {
eng = event->getNeutronEnergy(n1);
diru = event->getNeutronDircosu(n1);
dirv = event->getNeutronDircosv(n1);
dirw = event->getNeutronDircosw(n1);
fprintf(fp, "%.3f %.3f %.3f %.3f ", diru, dirv, dirw, eng);
}
if (nuh>0) fprintf(fp, "\n");
// Photons from heavy fragment
for(int n1=nugl; n1<nugl+nugh; n1++) {
eng = event->getPhotonEnergy(n1);
diru = event->getPhotonDircosu(n1);
dirv = event->getPhotonDircosv(n1);
dirw = event->getPhotonDircosw(n1);
if (timeCoincidenceWindow<0) {
age = event->getPhotonAge(n1);
fprintf(fp, "%.3f %.3f %.3f %.3f %g ", diru, dirv, dirw, eng, age);
} else {
fprintf(fp, "%.3f %.3f %.3f %.3f ", diru, dirv, dirw, eng);
}
}
if (nugh>0) fprintf(fp, "\n");
if (event->getPreFissionNeutronNu()>0) {
for (int i=0; i<event->getPreFissionNeutronNu(); i++) {
eng = event->getPreFissionNeutronEnergy(i);
diru = event->getPreFissionNeutronDircosu(i);
dirv = event->getPreFissionNeutronDircosv(i);
dirw = event->getPreFissionNeutronDircosw(i);
fprintf(fp, "%.3f %.3f %.3f %.3f ", diru, dirv, dirw, eng);
}
fprintf(fp, "\n");
}
return;
}
|
#include "modules/mapred/map_task.h"
#include "modules/mapred/sorter.h"
#include "modules/io/utils.h"
#include "modules/io/file_io.h"
#include "modules/io/make_unique.h"
REGISTER_TASK(map_task);
REGISTER_TASK(map_part_task);
void map_task::run()
{
if (m_subtasks.size() == 0 && input.get_num_records() != 0) {
SPLOG_P(LOG_DEBUG, "map_task::run> Stage 1");
split_progress(0.02, 0.05);
std::vector<input_stream_params> inputs;
input.split_by_goal_size(inputs, input_goal_size);
for (size_t i = 0; i < inputs.size(); i++) {
if (is_pipe) {
m_subtasks.push_back(make_map_pipe_task(inputs[i]));
}
else {
m_subtasks.push_back(make_map_part_task(inputs[i]));
}
update_progress(double(i) / double(inputs.size()));
}
return;
}
SPLOG_P(LOG_DEBUG, "map_task::run> Stage 2");
std::string out_sort = sort;
if (stable_sort && input.get_sort() != "" && sort == "") {
out_sort = input.get_sort();
}
manifest out(out_sort, num_partitions);
for (size_t i = 0; i < m_subtasks.size(); i++) {
manifest subout;
get_output(subout, m_subtasks[i]);
out.add(subout);
update_progress(.85 * double(i) / double(m_subtasks.size()));
}
set_output(out);
}
subtask_id map_task::make_map_part_task(const input_stream_params & the_input_stream_params)
{
auto task = make_unique<map_part_task>();
task->input_stream = the_input_stream_params;
task->output_stream.goal_size = output_goal_size;
task->output_stream.num_partitions = num_partitions;
if (stable_sort && input.get_sort() != "" && sort == "") {
task->output_stream.presorted = true;
task->output_stream.sort = input.get_sort();
}
else {
task->output_stream.sort = sort;
}
task->output_stream.reduce = reduce;
task->output_stream.reduce_param = reduce_param;
task->map = map;
task->map_param = map_param;
task->update_freq = update_freq;
return add_subtask(std::move(task));
}
task_requirements map_part_task::get_requirements()
{
make_mapper();
return m_mapper->get_requirements();
}
void map_part_task::make_mapper()
{
if (!m_mapper) {
m_mapper = mapper_registry::get(map, map_param);
if (!m_mapper) {
throw io_exception(printstring("Unknown mapper: %s", map.c_str()));
}
}
}
void map_part_task::send_update()
{
double val = double(m_num_proc) / double(input_stream.num_records);
if (val > 1.0) {
val = 1.0;
}
update_progress(val);
}
void map_part_task::run()
{
manifest mout;
SPLOG_P(LOG_DEBUG, "map_part_task::run> Making mapper %s", map.c_str());
m_num_proc = 0;
make_mapper();
m_mapper->set_watchdog(std::bind(&map_part_task::send_update, this));
m_mapper->setup();
SPLOG_P(LOG_DEBUG, "map_part_task::run> Building Input Stream");
m_input = input_stream.build();
SPLOG_P(LOG_DEBUG, "map_part_task::run> Building Output Stream");
m_output = output_stream.build(get_root(), "map", mout);
// Do the actual work
std::string key;
std::string value;
SPLOG_P(LOG_DEBUG, "map_part_task::run> Entering main loop");
while (m_input->read(key, value)) {
m_mapper->map(key, value, *m_output);
m_num_proc++;
send_update();
}
m_mapper->install_metadata(mout.metadata());
SPLOG_P(LOG_DEBUG, "map_part_task::run> Closing output");
m_output->close();
SPLOG_P(LOG_DEBUG, "map_part_task::run> Writing manifest");
set_output(mout);
SPLOG_P(LOG_DEBUG, "map_part_task::run> Done");
}
|
; A042403: Denominators of continued fraction convergents to sqrt(728).
; Submitted by Christian Krause
; 1,1,53,54,2861,2915,154441,157356,8336953,8494309,450041021,458535330,24293878181,24752413511,1311419380753,1336171794264,70792352682481,72128524476745,3821475625473221,3893604149949966,206288891422871453,210182495572821419,11135778661209585241,11345961156782406660,601125758813894731561,612471719970677138221,32449655197289105919053,33062126917259783057274,1751680254894797824897301,1784742381812057607954575,94558284109121793438535201,96343026490933851046489776,5104395661637682047856003553
add $0,1
mov $3,1
lpb $0
sub $0,1
add $3,$1
add $2,$3
mov $3,$1
mov $1,$2
dif $2,2
mod $2,$1
mul $2,18
add $3,$1
add $3,$1
add $3,$2
mov $2,$1
lpe
dif $2,4
mov $0,$2
|
#include "Platform.inc"
#include "TailCalls.inc"
#include "PollChain.inc"
radix decimal
extern POLL_AFTER_TEMPERATURESENSOR
TemperatureSensor code
global pollTemperatureSensor
pollTemperatureSensor:
.unknownBank
tcall POLL_AFTER_TEMPERATURESENSOR
end
|
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20714
//
//
///
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_PrimitiveID 0 x 0 PRIMID uint x
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
ps_4_0
dcl_input_ps_sgv v0.x, primitive_id
dcl_output o0.xyzw
dcl_temps 1
utof r0.x, v0.x
mul o0.yzw, r0.xxxx, l(0.000000, 2.000000, 0.015625, 0.031250)
mov o0.x, r0.x
ret
// Approximately 4 instruction slots used
|
section .text
extern printf
global main
main:
; invoke sys_read
mov eax, 3
mov ebx, 0
mov ecx, storage
mov edx, 128
int 0x80
;
; check char by char and count brackets
;
; eax/al = current char
; ebx = char counter
; ecx = bracket counter
xor ebx, ebx
xor ecx, ecx
lp:
mov al, [storage+ebx]
cmp eax, 0 ; 0x00 terminates a string
je loopEnd
cmp eax, 0x28 ; (
jne skipOpen
; if ecx/bracket counter value is >0, there was a closing
; bracket too much, so this must stay in error mode
cmp ecx, 0
jl skipOpen
inc ecx ; found opening
skipOpen:
cmp eax, 0x29 ; )
jne skipClose
dec ecx ; found closing
skipClose:
inc ebx
jmp lp;
loopEnd:
; if ecx is 0, all brackets match
cmp ecx, 0
je end
mov ecx, 1 ; if not return non-zero exit code
end:
; exit
mov eax, 1 ; sys_exit
mov ebx, ecx ; error-code = ecx
int 0x80 ; invoke kernel again
section .data
; data section
; format db '%s' ; save string
section .bss
storage: resb 128 ; reserve 128 byte |
; A181475: a(n) = 3*n^4 + 6*n^3 - 3*n + 1.
; 1,7,91,397,1141,2611,5167,9241,15337,24031,35971,51877,72541,98827,131671,172081,221137,279991,349867,432061,527941,638947,766591,912457,1078201,1265551,1476307,1712341,1975597,2268091,2591911,2949217,3342241,3773287,4244731,4759021,5318677,5926291,6584527,7296121,8063881,8890687,9779491,10733317,11755261,12848491,14016247,15261841,16588657,18000151,19499851,21091357,22778341,24564547,26453791,28449961,30557017,32778991,35119987,37584181,40175821,42899227,45758791,48758977,51904321,55199431,58648987,62257741,66030517,69972211,74087791,78382297,82860841,87528607,92390851,97452901,102720157,108198091,113892247,119808241,125951761,132328567,138944491,145805437,152917381,160286371,167918527,175820041,183997177,192456271,201203731,210246037,219589741,229241467,239207911,249495841,260112097,271063591,282357307,294000301,305999701,318362707,331096591,344208697,357706441,371597311,385888867,400588741,415704637,431244331,447215671,463626577,480485041,497799127,515576971,533826781,552556837,571775491,591491167,611712361,632447641,653705647,675495091,697824757,720703501,744140251,768144007,792723841,817888897,843648391,870011611,896987917,924586741,952817587,981690031,1011213721,1041398377,1072253791,1103789827,1136016421,1168943581,1202581387,1236939991,1272029617,1307860561,1344443191,1381787947,1419905341,1458805957,1498500451,1538999551,1580314057,1622454841,1665432847,1709259091,1753944661,1799500717,1845938491,1893269287,1941504481,1990655521,2040733927,2091751291,2143719277,2196649621,2250554131,2305444687,2361333241,2418231817,2476152511,2535107491,2595108997,2656169341,2718300907,2781516151,2845827601,2911247857,2977789591,3045465547,3114288541,3184271461,3255427267,3327768991,3401309737,3476062681,3552041071,3629258227,3707727541,3787462477,3868476571,3950783431,4034396737,4119330241,4205597767,4293213211,4382190541,4472543797,4564287091,4657434607,4752000601,4847999401,4945445407,5044353091,5144736997,5246611741,5349992011,5454892567,5561328241,5669313937,5778864631,5889995371,6002721277,6117057541,6233019427,6350622271,6469881481,6590812537,6713430991,6837752467,6963792661,7091567341,7221092347,7352383591,7485457057,7620328801,7757014951,7895531707,8035895341,8178122197,8322228691,8468231311,8616146617,8765991241,8917781887,9071535331,9227268421,9384998077,9544741291,9706515127,9870336721,10036223281,10204192087,10374260491,10546445917,10720765861,10897237891,11075879647,11256708841,11439743257,11625000751
mov $1,$0
pow $0,2
add $1,$0
bin $1,2
mul $1,6
add $1,1
|
;
;
; Support char table (pseudo graph symbols) for the Mattel Aquarius
; Version for the 2x3 graphics symbols
; Sequence: blank, top-left, top-right, top-half, medium-left, top-left + medium-left, etc..
;
; $Id: textpixl6.asm,v 1.2 2015/01/19 01:32:46 pauloscustodio Exp $
;
;
PUBLIC textpixl
.textpixl
defb 160, 161, 162 ,163, 164, 165, 166, 167
defb 168, 169, 170, 171, 172, 173, 174, 175
defb 176, 177, 178, 179, 180, 181, 182, 183
defb 184, 185, 186, 187, 188, 189, 190, 191
; O#
; ## = 190
; #O
; ##
; ## = 191
; #O 31
; OO
; OO = 224 ? (it is slightly thicker)
; O#
; #O
; OO = 225
; O# 33
; O#
; OO = 226
; O#
defb 215, 225, 226, 227, 228, 229, 230, 231
defb 232, 233, 234, 235, 236, 237, 238, 239
defb 240, 241, 242, 243, 244, 245, 246, 247
defb 248, 249, 250, 251, 252, 253, 254, 255
|
; A007953: Digital sum (i.e., sum of digits) of n; also called digsum(n).
; 0,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,10,2,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,12,4,5,6,7,8,9,10,11,12,13,5,6,7,8,9,10,11,12,13,14,6,7,8,9,10,11,12,13,14,15,7,8,9,10,11,12,13,14,15,16,8,9,10,11,12,13,14,15,16,17,9,10,11,12,13,14,15,16,17,18,1,2,3,4,5,6,7,8,9,10,2,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,12,4,5,6,7,8,9,10,11,12,13,5,6,7,8,9,10,11,12,13,14,6,7,8,9,10,11,12,13,14,15,7,8,9,10,11,12,13,14,15,16,8,9,10,11,12,13,14,15,16,17,9,10,11,12,13,14,15,16,17,18,10,11,12,13,14,15,16,17,18,19,2,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,12,4,5,6,7,8,9,10,11,12,13,5,6,7,8,9,10,11,12,13,14,6,7,8,9,10,11,12,13,14,15
mov $1,204
lpb $0
mov $2,$0
div $0,10
mod $2,10
add $1,$2
lpe
sub $1,204
|
_rm: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "stat.h"
#include "user.h"
int
main(int argc, char *argv[])
{
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 57 push %edi
e: 56 push %esi
f: 53 push %ebx
10: 51 push %ecx
11: bf 01 00 00 00 mov $0x1,%edi
16: 83 ec 08 sub $0x8,%esp
19: 8b 31 mov (%ecx),%esi
1b: 8b 59 04 mov 0x4(%ecx),%ebx
1e: 83 c3 04 add $0x4,%ebx
int i;
if(argc < 2){
21: 83 fe 01 cmp $0x1,%esi
24: 7e 3e jle 64 <main+0x64>
26: 8d 76 00 lea 0x0(%esi),%esi
29: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
printf(2, "Usage: rm files...\n");
exit();
}
for(i = 1; i < argc; i++){
if(unlink(argv[i]) < 0){
30: 83 ec 0c sub $0xc,%esp
33: ff 33 pushl (%ebx)
35: e8 d8 02 00 00 call 312 <unlink>
3a: 83 c4 10 add $0x10,%esp
3d: 85 c0 test %eax,%eax
3f: 78 0f js 50 <main+0x50>
if(argc < 2){
printf(2, "Usage: rm files...\n");
exit();
}
for(i = 1; i < argc; i++){
41: 83 c7 01 add $0x1,%edi
44: 83 c3 04 add $0x4,%ebx
47: 39 fe cmp %edi,%esi
49: 75 e5 jne 30 <main+0x30>
printf(2, "rm: %s failed to delete\n", argv[i]);
break;
}
}
exit();
4b: e8 72 02 00 00 call 2c2 <exit>
exit();
}
for(i = 1; i < argc; i++){
if(unlink(argv[i]) < 0){
printf(2, "rm: %s failed to delete\n", argv[i]);
50: 50 push %eax
51: ff 33 pushl (%ebx)
53: 68 44 07 00 00 push $0x744
58: 6a 02 push $0x2
5a: e8 b1 03 00 00 call 410 <printf>
break;
5f: 83 c4 10 add $0x10,%esp
62: eb e7 jmp 4b <main+0x4b>
main(int argc, char *argv[])
{
int i;
if(argc < 2){
printf(2, "Usage: rm files...\n");
64: 52 push %edx
65: 52 push %edx
66: 68 30 07 00 00 push $0x730
6b: 6a 02 push $0x2
6d: e8 9e 03 00 00 call 410 <printf>
exit();
72: e8 4b 02 00 00 call 2c2 <exit>
77: 66 90 xchg %ax,%ax
79: 66 90 xchg %ax,%ax
7b: 66 90 xchg %ax,%ax
7d: 66 90 xchg %ax,%ax
7f: 90 nop
00000080 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
80: 55 push %ebp
81: 89 e5 mov %esp,%ebp
83: 53 push %ebx
84: 8b 45 08 mov 0x8(%ebp),%eax
87: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
8a: 89 c2 mov %eax,%edx
8c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
90: 83 c1 01 add $0x1,%ecx
93: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
97: 83 c2 01 add $0x1,%edx
9a: 84 db test %bl,%bl
9c: 88 5a ff mov %bl,-0x1(%edx)
9f: 75 ef jne 90 <strcpy+0x10>
;
return os;
}
a1: 5b pop %ebx
a2: 5d pop %ebp
a3: c3 ret
a4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
aa: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
000000b0 <strcmp>:
int
strcmp(const char *p, const char *q)
{
b0: 55 push %ebp
b1: 89 e5 mov %esp,%ebp
b3: 56 push %esi
b4: 53 push %ebx
b5: 8b 55 08 mov 0x8(%ebp),%edx
b8: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
bb: 0f b6 02 movzbl (%edx),%eax
be: 0f b6 19 movzbl (%ecx),%ebx
c1: 84 c0 test %al,%al
c3: 75 1e jne e3 <strcmp+0x33>
c5: eb 29 jmp f0 <strcmp+0x40>
c7: 89 f6 mov %esi,%esi
c9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
d0: 83 c2 01 add $0x1,%edx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
d3: 0f b6 02 movzbl (%edx),%eax
p++, q++;
d6: 8d 71 01 lea 0x1(%ecx),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
d9: 0f b6 59 01 movzbl 0x1(%ecx),%ebx
dd: 84 c0 test %al,%al
df: 74 0f je f0 <strcmp+0x40>
e1: 89 f1 mov %esi,%ecx
e3: 38 d8 cmp %bl,%al
e5: 74 e9 je d0 <strcmp+0x20>
p++, q++;
return (uchar)*p - (uchar)*q;
e7: 29 d8 sub %ebx,%eax
}
e9: 5b pop %ebx
ea: 5e pop %esi
eb: 5d pop %ebp
ec: c3 ret
ed: 8d 76 00 lea 0x0(%esi),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
f0: 31 c0 xor %eax,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
f2: 29 d8 sub %ebx,%eax
}
f4: 5b pop %ebx
f5: 5e pop %esi
f6: 5d pop %ebp
f7: c3 ret
f8: 90 nop
f9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000100 <strlen>:
uint
strlen(const char *s)
{
100: 55 push %ebp
101: 89 e5 mov %esp,%ebp
103: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
106: 80 39 00 cmpb $0x0,(%ecx)
109: 74 12 je 11d <strlen+0x1d>
10b: 31 d2 xor %edx,%edx
10d: 8d 76 00 lea 0x0(%esi),%esi
110: 83 c2 01 add $0x1,%edx
113: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
117: 89 d0 mov %edx,%eax
119: 75 f5 jne 110 <strlen+0x10>
;
return n;
}
11b: 5d pop %ebp
11c: c3 ret
uint
strlen(const char *s)
{
int n;
for(n = 0; s[n]; n++)
11d: 31 c0 xor %eax,%eax
;
return n;
}
11f: 5d pop %ebp
120: c3 ret
121: eb 0d jmp 130 <memset>
123: 90 nop
124: 90 nop
125: 90 nop
126: 90 nop
127: 90 nop
128: 90 nop
129: 90 nop
12a: 90 nop
12b: 90 nop
12c: 90 nop
12d: 90 nop
12e: 90 nop
12f: 90 nop
00000130 <memset>:
void*
memset(void *dst, int c, uint n)
{
130: 55 push %ebp
131: 89 e5 mov %esp,%ebp
133: 57 push %edi
134: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
137: 8b 4d 10 mov 0x10(%ebp),%ecx
13a: 8b 45 0c mov 0xc(%ebp),%eax
13d: 89 d7 mov %edx,%edi
13f: fc cld
140: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
142: 89 d0 mov %edx,%eax
144: 5f pop %edi
145: 5d pop %ebp
146: c3 ret
147: 89 f6 mov %esi,%esi
149: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000150 <strchr>:
char*
strchr(const char *s, char c)
{
150: 55 push %ebp
151: 89 e5 mov %esp,%ebp
153: 53 push %ebx
154: 8b 45 08 mov 0x8(%ebp),%eax
157: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
15a: 0f b6 10 movzbl (%eax),%edx
15d: 84 d2 test %dl,%dl
15f: 74 1d je 17e <strchr+0x2e>
if(*s == c)
161: 38 d3 cmp %dl,%bl
163: 89 d9 mov %ebx,%ecx
165: 75 0d jne 174 <strchr+0x24>
167: eb 17 jmp 180 <strchr+0x30>
169: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
170: 38 ca cmp %cl,%dl
172: 74 0c je 180 <strchr+0x30>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
174: 83 c0 01 add $0x1,%eax
177: 0f b6 10 movzbl (%eax),%edx
17a: 84 d2 test %dl,%dl
17c: 75 f2 jne 170 <strchr+0x20>
if(*s == c)
return (char*)s;
return 0;
17e: 31 c0 xor %eax,%eax
}
180: 5b pop %ebx
181: 5d pop %ebp
182: c3 ret
183: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
189: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000190 <gets>:
char*
gets(char *buf, int max)
{
190: 55 push %ebp
191: 89 e5 mov %esp,%ebp
193: 57 push %edi
194: 56 push %esi
195: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
196: 31 f6 xor %esi,%esi
cc = read(0, &c, 1);
198: 8d 7d e7 lea -0x19(%ebp),%edi
return 0;
}
char*
gets(char *buf, int max)
{
19b: 83 ec 1c sub $0x1c,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
19e: eb 29 jmp 1c9 <gets+0x39>
cc = read(0, &c, 1);
1a0: 83 ec 04 sub $0x4,%esp
1a3: 6a 01 push $0x1
1a5: 57 push %edi
1a6: 6a 00 push $0x0
1a8: e8 2d 01 00 00 call 2da <read>
if(cc < 1)
1ad: 83 c4 10 add $0x10,%esp
1b0: 85 c0 test %eax,%eax
1b2: 7e 1d jle 1d1 <gets+0x41>
break;
buf[i++] = c;
1b4: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
1b8: 8b 55 08 mov 0x8(%ebp),%edx
1bb: 89 de mov %ebx,%esi
if(c == '\n' || c == '\r')
1bd: 3c 0a cmp $0xa,%al
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
1bf: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
1c3: 74 1b je 1e0 <gets+0x50>
1c5: 3c 0d cmp $0xd,%al
1c7: 74 17 je 1e0 <gets+0x50>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
1c9: 8d 5e 01 lea 0x1(%esi),%ebx
1cc: 3b 5d 0c cmp 0xc(%ebp),%ebx
1cf: 7c cf jl 1a0 <gets+0x10>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
1d1: 8b 45 08 mov 0x8(%ebp),%eax
1d4: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
1d8: 8d 65 f4 lea -0xc(%ebp),%esp
1db: 5b pop %ebx
1dc: 5e pop %esi
1dd: 5f pop %edi
1de: 5d pop %ebp
1df: c3 ret
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
1e0: 8b 45 08 mov 0x8(%ebp),%eax
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
1e3: 89 de mov %ebx,%esi
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
1e5: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
1e9: 8d 65 f4 lea -0xc(%ebp),%esp
1ec: 5b pop %ebx
1ed: 5e pop %esi
1ee: 5f pop %edi
1ef: 5d pop %ebp
1f0: c3 ret
1f1: eb 0d jmp 200 <stat>
1f3: 90 nop
1f4: 90 nop
1f5: 90 nop
1f6: 90 nop
1f7: 90 nop
1f8: 90 nop
1f9: 90 nop
1fa: 90 nop
1fb: 90 nop
1fc: 90 nop
1fd: 90 nop
1fe: 90 nop
1ff: 90 nop
00000200 <stat>:
int
stat(const char *n, struct stat *st)
{
200: 55 push %ebp
201: 89 e5 mov %esp,%ebp
203: 56 push %esi
204: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
205: 83 ec 08 sub $0x8,%esp
208: 6a 00 push $0x0
20a: ff 75 08 pushl 0x8(%ebp)
20d: e8 f0 00 00 00 call 302 <open>
if(fd < 0)
212: 83 c4 10 add $0x10,%esp
215: 85 c0 test %eax,%eax
217: 78 27 js 240 <stat+0x40>
return -1;
r = fstat(fd, st);
219: 83 ec 08 sub $0x8,%esp
21c: ff 75 0c pushl 0xc(%ebp)
21f: 89 c3 mov %eax,%ebx
221: 50 push %eax
222: e8 f3 00 00 00 call 31a <fstat>
227: 89 c6 mov %eax,%esi
close(fd);
229: 89 1c 24 mov %ebx,(%esp)
22c: e8 b9 00 00 00 call 2ea <close>
return r;
231: 83 c4 10 add $0x10,%esp
234: 89 f0 mov %esi,%eax
}
236: 8d 65 f8 lea -0x8(%ebp),%esp
239: 5b pop %ebx
23a: 5e pop %esi
23b: 5d pop %ebp
23c: c3 ret
23d: 8d 76 00 lea 0x0(%esi),%esi
int fd;
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
240: b8 ff ff ff ff mov $0xffffffff,%eax
245: eb ef jmp 236 <stat+0x36>
247: 89 f6 mov %esi,%esi
249: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000250 <atoi>:
return r;
}
int
atoi(const char *s)
{
250: 55 push %ebp
251: 89 e5 mov %esp,%ebp
253: 53 push %ebx
254: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
257: 0f be 11 movsbl (%ecx),%edx
25a: 8d 42 d0 lea -0x30(%edx),%eax
25d: 3c 09 cmp $0x9,%al
25f: b8 00 00 00 00 mov $0x0,%eax
264: 77 1f ja 285 <atoi+0x35>
266: 8d 76 00 lea 0x0(%esi),%esi
269: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
270: 8d 04 80 lea (%eax,%eax,4),%eax
273: 83 c1 01 add $0x1,%ecx
276: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
27a: 0f be 11 movsbl (%ecx),%edx
27d: 8d 5a d0 lea -0x30(%edx),%ebx
280: 80 fb 09 cmp $0x9,%bl
283: 76 eb jbe 270 <atoi+0x20>
n = n*10 + *s++ - '0';
return n;
}
285: 5b pop %ebx
286: 5d pop %ebp
287: c3 ret
288: 90 nop
289: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000290 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
290: 55 push %ebp
291: 89 e5 mov %esp,%ebp
293: 56 push %esi
294: 53 push %ebx
295: 8b 5d 10 mov 0x10(%ebp),%ebx
298: 8b 45 08 mov 0x8(%ebp),%eax
29b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
29e: 85 db test %ebx,%ebx
2a0: 7e 14 jle 2b6 <memmove+0x26>
2a2: 31 d2 xor %edx,%edx
2a4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
2a8: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
2ac: 88 0c 10 mov %cl,(%eax,%edx,1)
2af: 83 c2 01 add $0x1,%edx
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
2b2: 39 da cmp %ebx,%edx
2b4: 75 f2 jne 2a8 <memmove+0x18>
*dst++ = *src++;
return vdst;
}
2b6: 5b pop %ebx
2b7: 5e pop %esi
2b8: 5d pop %ebp
2b9: c3 ret
000002ba <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
2ba: b8 01 00 00 00 mov $0x1,%eax
2bf: cd 40 int $0x40
2c1: c3 ret
000002c2 <exit>:
SYSCALL(exit)
2c2: b8 02 00 00 00 mov $0x2,%eax
2c7: cd 40 int $0x40
2c9: c3 ret
000002ca <wait>:
SYSCALL(wait)
2ca: b8 03 00 00 00 mov $0x3,%eax
2cf: cd 40 int $0x40
2d1: c3 ret
000002d2 <pipe>:
SYSCALL(pipe)
2d2: b8 04 00 00 00 mov $0x4,%eax
2d7: cd 40 int $0x40
2d9: c3 ret
000002da <read>:
SYSCALL(read)
2da: b8 05 00 00 00 mov $0x5,%eax
2df: cd 40 int $0x40
2e1: c3 ret
000002e2 <write>:
SYSCALL(write)
2e2: b8 10 00 00 00 mov $0x10,%eax
2e7: cd 40 int $0x40
2e9: c3 ret
000002ea <close>:
SYSCALL(close)
2ea: b8 15 00 00 00 mov $0x15,%eax
2ef: cd 40 int $0x40
2f1: c3 ret
000002f2 <kill>:
SYSCALL(kill)
2f2: b8 06 00 00 00 mov $0x6,%eax
2f7: cd 40 int $0x40
2f9: c3 ret
000002fa <exec>:
SYSCALL(exec)
2fa: b8 07 00 00 00 mov $0x7,%eax
2ff: cd 40 int $0x40
301: c3 ret
00000302 <open>:
SYSCALL(open)
302: b8 0f 00 00 00 mov $0xf,%eax
307: cd 40 int $0x40
309: c3 ret
0000030a <mknod>:
SYSCALL(mknod)
30a: b8 11 00 00 00 mov $0x11,%eax
30f: cd 40 int $0x40
311: c3 ret
00000312 <unlink>:
SYSCALL(unlink)
312: b8 12 00 00 00 mov $0x12,%eax
317: cd 40 int $0x40
319: c3 ret
0000031a <fstat>:
SYSCALL(fstat)
31a: b8 08 00 00 00 mov $0x8,%eax
31f: cd 40 int $0x40
321: c3 ret
00000322 <link>:
SYSCALL(link)
322: b8 13 00 00 00 mov $0x13,%eax
327: cd 40 int $0x40
329: c3 ret
0000032a <mkdir>:
SYSCALL(mkdir)
32a: b8 14 00 00 00 mov $0x14,%eax
32f: cd 40 int $0x40
331: c3 ret
00000332 <chdir>:
SYSCALL(chdir)
332: b8 09 00 00 00 mov $0x9,%eax
337: cd 40 int $0x40
339: c3 ret
0000033a <dup>:
SYSCALL(dup)
33a: b8 0a 00 00 00 mov $0xa,%eax
33f: cd 40 int $0x40
341: c3 ret
00000342 <getpid>:
SYSCALL(getpid)
342: b8 0b 00 00 00 mov $0xb,%eax
347: cd 40 int $0x40
349: c3 ret
0000034a <sbrk>:
SYSCALL(sbrk)
34a: b8 0c 00 00 00 mov $0xc,%eax
34f: cd 40 int $0x40
351: c3 ret
00000352 <sleep>:
SYSCALL(sleep)
352: b8 0d 00 00 00 mov $0xd,%eax
357: cd 40 int $0x40
359: c3 ret
0000035a <uptime>:
SYSCALL(uptime)
35a: b8 0e 00 00 00 mov $0xe,%eax
35f: cd 40 int $0x40
361: c3 ret
00000362 <getreadcount>:
SYSCALL(getreadcount)
362: b8 16 00 00 00 mov $0x16,%eax
367: cd 40 int $0x40
369: c3 ret
36a: 66 90 xchg %ax,%ax
36c: 66 90 xchg %ax,%ax
36e: 66 90 xchg %ax,%ax
00000370 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
370: 55 push %ebp
371: 89 e5 mov %esp,%ebp
373: 57 push %edi
374: 56 push %esi
375: 53 push %ebx
376: 89 c6 mov %eax,%esi
378: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
37b: 8b 5d 08 mov 0x8(%ebp),%ebx
37e: 85 db test %ebx,%ebx
380: 74 7e je 400 <printint+0x90>
382: 89 d0 mov %edx,%eax
384: c1 e8 1f shr $0x1f,%eax
387: 84 c0 test %al,%al
389: 74 75 je 400 <printint+0x90>
neg = 1;
x = -xx;
38b: 89 d0 mov %edx,%eax
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
38d: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
x = -xx;
394: f7 d8 neg %eax
396: 89 75 c0 mov %esi,-0x40(%ebp)
} else {
x = xx;
}
i = 0;
399: 31 ff xor %edi,%edi
39b: 8d 5d d7 lea -0x29(%ebp),%ebx
39e: 89 ce mov %ecx,%esi
3a0: eb 08 jmp 3aa <printint+0x3a>
3a2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
do{
buf[i++] = digits[x % base];
3a8: 89 cf mov %ecx,%edi
3aa: 31 d2 xor %edx,%edx
3ac: 8d 4f 01 lea 0x1(%edi),%ecx
3af: f7 f6 div %esi
3b1: 0f b6 92 64 07 00 00 movzbl 0x764(%edx),%edx
}while((x /= base) != 0);
3b8: 85 c0 test %eax,%eax
x = xx;
}
i = 0;
do{
buf[i++] = digits[x % base];
3ba: 88 14 0b mov %dl,(%ebx,%ecx,1)
}while((x /= base) != 0);
3bd: 75 e9 jne 3a8 <printint+0x38>
if(neg)
3bf: 8b 45 c4 mov -0x3c(%ebp),%eax
3c2: 8b 75 c0 mov -0x40(%ebp),%esi
3c5: 85 c0 test %eax,%eax
3c7: 74 08 je 3d1 <printint+0x61>
buf[i++] = '-';
3c9: c6 44 0d d8 2d movb $0x2d,-0x28(%ebp,%ecx,1)
3ce: 8d 4f 02 lea 0x2(%edi),%ecx
3d1: 8d 7c 0d d7 lea -0x29(%ebp,%ecx,1),%edi
3d5: 8d 76 00 lea 0x0(%esi),%esi
3d8: 0f b6 07 movzbl (%edi),%eax
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
3db: 83 ec 04 sub $0x4,%esp
3de: 83 ef 01 sub $0x1,%edi
3e1: 6a 01 push $0x1
3e3: 53 push %ebx
3e4: 56 push %esi
3e5: 88 45 d7 mov %al,-0x29(%ebp)
3e8: e8 f5 fe ff ff call 2e2 <write>
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
3ed: 83 c4 10 add $0x10,%esp
3f0: 39 df cmp %ebx,%edi
3f2: 75 e4 jne 3d8 <printint+0x68>
putc(fd, buf[i]);
}
3f4: 8d 65 f4 lea -0xc(%ebp),%esp
3f7: 5b pop %ebx
3f8: 5e pop %esi
3f9: 5f pop %edi
3fa: 5d pop %ebp
3fb: c3 ret
3fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
} else {
x = xx;
400: 89 d0 mov %edx,%eax
static char digits[] = "0123456789ABCDEF";
char buf[16];
int i, neg;
uint x;
neg = 0;
402: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
409: eb 8b jmp 396 <printint+0x26>
40b: 90 nop
40c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000410 <printf>:
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
410: 55 push %ebp
411: 89 e5 mov %esp,%ebp
413: 57 push %edi
414: 56 push %esi
415: 53 push %ebx
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
416: 8d 45 10 lea 0x10(%ebp),%eax
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
419: 83 ec 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
41c: 8b 75 0c mov 0xc(%ebp),%esi
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
41f: 8b 7d 08 mov 0x8(%ebp),%edi
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
422: 89 45 d0 mov %eax,-0x30(%ebp)
425: 0f b6 1e movzbl (%esi),%ebx
428: 83 c6 01 add $0x1,%esi
42b: 84 db test %bl,%bl
42d: 0f 84 b0 00 00 00 je 4e3 <printf+0xd3>
433: 31 d2 xor %edx,%edx
435: eb 39 jmp 470 <printf+0x60>
437: 89 f6 mov %esi,%esi
439: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
440: 83 f8 25 cmp $0x25,%eax
443: 89 55 d4 mov %edx,-0x2c(%ebp)
state = '%';
446: ba 25 00 00 00 mov $0x25,%edx
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
44b: 74 18 je 465 <printf+0x55>
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
44d: 8d 45 e2 lea -0x1e(%ebp),%eax
450: 83 ec 04 sub $0x4,%esp
453: 88 5d e2 mov %bl,-0x1e(%ebp)
456: 6a 01 push $0x1
458: 50 push %eax
459: 57 push %edi
45a: e8 83 fe ff ff call 2e2 <write>
45f: 8b 55 d4 mov -0x2c(%ebp),%edx
462: 83 c4 10 add $0x10,%esp
465: 83 c6 01 add $0x1,%esi
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
468: 0f b6 5e ff movzbl -0x1(%esi),%ebx
46c: 84 db test %bl,%bl
46e: 74 73 je 4e3 <printf+0xd3>
c = fmt[i] & 0xff;
if(state == 0){
470: 85 d2 test %edx,%edx
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
472: 0f be cb movsbl %bl,%ecx
475: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
478: 74 c6 je 440 <printf+0x30>
if(c == '%'){
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
47a: 83 fa 25 cmp $0x25,%edx
47d: 75 e6 jne 465 <printf+0x55>
if(c == 'd'){
47f: 83 f8 64 cmp $0x64,%eax
482: 0f 84 f8 00 00 00 je 580 <printf+0x170>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
488: 81 e1 f7 00 00 00 and $0xf7,%ecx
48e: 83 f9 70 cmp $0x70,%ecx
491: 74 5d je 4f0 <printf+0xe0>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
493: 83 f8 73 cmp $0x73,%eax
496: 0f 84 84 00 00 00 je 520 <printf+0x110>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
49c: 83 f8 63 cmp $0x63,%eax
49f: 0f 84 ea 00 00 00 je 58f <printf+0x17f>
putc(fd, *ap);
ap++;
} else if(c == '%'){
4a5: 83 f8 25 cmp $0x25,%eax
4a8: 0f 84 c2 00 00 00 je 570 <printf+0x160>
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
4ae: 8d 45 e7 lea -0x19(%ebp),%eax
4b1: 83 ec 04 sub $0x4,%esp
4b4: c6 45 e7 25 movb $0x25,-0x19(%ebp)
4b8: 6a 01 push $0x1
4ba: 50 push %eax
4bb: 57 push %edi
4bc: e8 21 fe ff ff call 2e2 <write>
4c1: 83 c4 0c add $0xc,%esp
4c4: 8d 45 e6 lea -0x1a(%ebp),%eax
4c7: 88 5d e6 mov %bl,-0x1a(%ebp)
4ca: 6a 01 push $0x1
4cc: 50 push %eax
4cd: 57 push %edi
4ce: 83 c6 01 add $0x1,%esi
4d1: e8 0c fe ff ff call 2e2 <write>
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
4d6: 0f b6 5e ff movzbl -0x1(%esi),%ebx
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
4da: 83 c4 10 add $0x10,%esp
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
4dd: 31 d2 xor %edx,%edx
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
4df: 84 db test %bl,%bl
4e1: 75 8d jne 470 <printf+0x60>
putc(fd, c);
}
state = 0;
}
}
}
4e3: 8d 65 f4 lea -0xc(%ebp),%esp
4e6: 5b pop %ebx
4e7: 5e pop %esi
4e8: 5f pop %edi
4e9: 5d pop %ebp
4ea: c3 ret
4eb: 90 nop
4ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
4f0: 83 ec 0c sub $0xc,%esp
4f3: b9 10 00 00 00 mov $0x10,%ecx
4f8: 6a 00 push $0x0
4fa: 8b 5d d0 mov -0x30(%ebp),%ebx
4fd: 89 f8 mov %edi,%eax
4ff: 8b 13 mov (%ebx),%edx
501: e8 6a fe ff ff call 370 <printint>
ap++;
506: 89 d8 mov %ebx,%eax
508: 83 c4 10 add $0x10,%esp
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
50b: 31 d2 xor %edx,%edx
if(c == 'd'){
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
ap++;
50d: 83 c0 04 add $0x4,%eax
510: 89 45 d0 mov %eax,-0x30(%ebp)
513: e9 4d ff ff ff jmp 465 <printf+0x55>
518: 90 nop
519: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
} else if(c == 's'){
s = (char*)*ap;
520: 8b 45 d0 mov -0x30(%ebp),%eax
523: 8b 18 mov (%eax),%ebx
ap++;
525: 83 c0 04 add $0x4,%eax
528: 89 45 d0 mov %eax,-0x30(%ebp)
if(s == 0)
s = "(null)";
52b: b8 5d 07 00 00 mov $0x75d,%eax
530: 85 db test %ebx,%ebx
532: 0f 44 d8 cmove %eax,%ebx
while(*s != 0){
535: 0f b6 03 movzbl (%ebx),%eax
538: 84 c0 test %al,%al
53a: 74 23 je 55f <printf+0x14f>
53c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
540: 88 45 e3 mov %al,-0x1d(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
543: 8d 45 e3 lea -0x1d(%ebp),%eax
546: 83 ec 04 sub $0x4,%esp
549: 6a 01 push $0x1
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
54b: 83 c3 01 add $0x1,%ebx
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
54e: 50 push %eax
54f: 57 push %edi
550: e8 8d fd ff ff call 2e2 <write>
} else if(c == 's'){
s = (char*)*ap;
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
555: 0f b6 03 movzbl (%ebx),%eax
558: 83 c4 10 add $0x10,%esp
55b: 84 c0 test %al,%al
55d: 75 e1 jne 540 <printf+0x130>
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
55f: 31 d2 xor %edx,%edx
561: e9 ff fe ff ff jmp 465 <printf+0x55>
566: 8d 76 00 lea 0x0(%esi),%esi
569: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
570: 83 ec 04 sub $0x4,%esp
573: 88 5d e5 mov %bl,-0x1b(%ebp)
576: 8d 45 e5 lea -0x1b(%ebp),%eax
579: 6a 01 push $0x1
57b: e9 4c ff ff ff jmp 4cc <printf+0xbc>
} else {
putc(fd, c);
}
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
580: 83 ec 0c sub $0xc,%esp
583: b9 0a 00 00 00 mov $0xa,%ecx
588: 6a 01 push $0x1
58a: e9 6b ff ff ff jmp 4fa <printf+0xea>
58f: 8b 5d d0 mov -0x30(%ebp),%ebx
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
592: 83 ec 04 sub $0x4,%esp
595: 8b 03 mov (%ebx),%eax
597: 6a 01 push $0x1
599: 88 45 e4 mov %al,-0x1c(%ebp)
59c: 8d 45 e4 lea -0x1c(%ebp),%eax
59f: 50 push %eax
5a0: 57 push %edi
5a1: e8 3c fd ff ff call 2e2 <write>
5a6: e9 5b ff ff ff jmp 506 <printf+0xf6>
5ab: 66 90 xchg %ax,%ax
5ad: 66 90 xchg %ax,%ax
5af: 90 nop
000005b0 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
5b0: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5b1: a1 08 0a 00 00 mov 0xa08,%eax
static Header base;
static Header *freep;
void
free(void *ap)
{
5b6: 89 e5 mov %esp,%ebp
5b8: 57 push %edi
5b9: 56 push %esi
5ba: 53 push %ebx
5bb: 8b 5d 08 mov 0x8(%ebp),%ebx
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5be: 8b 10 mov (%eax),%edx
void
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
5c0: 8d 4b f8 lea -0x8(%ebx),%ecx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5c3: 39 c8 cmp %ecx,%eax
5c5: 73 19 jae 5e0 <free+0x30>
5c7: 89 f6 mov %esi,%esi
5c9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
5d0: 39 d1 cmp %edx,%ecx
5d2: 72 1c jb 5f0 <free+0x40>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5d4: 39 d0 cmp %edx,%eax
5d6: 73 18 jae 5f0 <free+0x40>
static Header base;
static Header *freep;
void
free(void *ap)
{
5d8: 89 d0 mov %edx,%eax
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5da: 39 c8 cmp %ecx,%eax
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5dc: 8b 10 mov (%eax),%edx
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5de: 72 f0 jb 5d0 <free+0x20>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5e0: 39 d0 cmp %edx,%eax
5e2: 72 f4 jb 5d8 <free+0x28>
5e4: 39 d1 cmp %edx,%ecx
5e6: 73 f0 jae 5d8 <free+0x28>
5e8: 90 nop
5e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
break;
if(bp + bp->s.size == p->s.ptr){
5f0: 8b 73 fc mov -0x4(%ebx),%esi
5f3: 8d 3c f1 lea (%ecx,%esi,8),%edi
5f6: 39 d7 cmp %edx,%edi
5f8: 74 19 je 613 <free+0x63>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
5fa: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
5fd: 8b 50 04 mov 0x4(%eax),%edx
600: 8d 34 d0 lea (%eax,%edx,8),%esi
603: 39 f1 cmp %esi,%ecx
605: 74 23 je 62a <free+0x7a>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
607: 89 08 mov %ecx,(%eax)
freep = p;
609: a3 08 0a 00 00 mov %eax,0xa08
}
60e: 5b pop %ebx
60f: 5e pop %esi
610: 5f pop %edi
611: 5d pop %ebp
612: c3 ret
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
break;
if(bp + bp->s.size == p->s.ptr){
bp->s.size += p->s.ptr->s.size;
613: 03 72 04 add 0x4(%edx),%esi
616: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
619: 8b 10 mov (%eax),%edx
61b: 8b 12 mov (%edx),%edx
61d: 89 53 f8 mov %edx,-0x8(%ebx)
} else
bp->s.ptr = p->s.ptr;
if(p + p->s.size == bp){
620: 8b 50 04 mov 0x4(%eax),%edx
623: 8d 34 d0 lea (%eax,%edx,8),%esi
626: 39 f1 cmp %esi,%ecx
628: 75 dd jne 607 <free+0x57>
p->s.size += bp->s.size;
62a: 03 53 fc add -0x4(%ebx),%edx
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
freep = p;
62d: a3 08 0a 00 00 mov %eax,0xa08
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
if(p + p->s.size == bp){
p->s.size += bp->s.size;
632: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
635: 8b 53 f8 mov -0x8(%ebx),%edx
638: 89 10 mov %edx,(%eax)
} else
p->s.ptr = bp;
freep = p;
}
63a: 5b pop %ebx
63b: 5e pop %esi
63c: 5f pop %edi
63d: 5d pop %ebp
63e: c3 ret
63f: 90 nop
00000640 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
640: 55 push %ebp
641: 89 e5 mov %esp,%ebp
643: 57 push %edi
644: 56 push %esi
645: 53 push %ebx
646: 83 ec 0c sub $0xc,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
649: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
64c: 8b 15 08 0a 00 00 mov 0xa08,%edx
malloc(uint nbytes)
{
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
652: 8d 78 07 lea 0x7(%eax),%edi
655: c1 ef 03 shr $0x3,%edi
658: 83 c7 01 add $0x1,%edi
if((prevp = freep) == 0){
65b: 85 d2 test %edx,%edx
65d: 0f 84 a3 00 00 00 je 706 <malloc+0xc6>
663: 8b 02 mov (%edx),%eax
665: 8b 48 04 mov 0x4(%eax),%ecx
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
668: 39 cf cmp %ecx,%edi
66a: 76 74 jbe 6e0 <malloc+0xa0>
66c: 81 ff 00 10 00 00 cmp $0x1000,%edi
672: be 00 10 00 00 mov $0x1000,%esi
677: 8d 1c fd 00 00 00 00 lea 0x0(,%edi,8),%ebx
67e: 0f 43 f7 cmovae %edi,%esi
681: ba 00 80 00 00 mov $0x8000,%edx
686: 81 ff ff 0f 00 00 cmp $0xfff,%edi
68c: 0f 46 da cmovbe %edx,%ebx
68f: eb 10 jmp 6a1 <malloc+0x61>
691: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
698: 8b 02 mov (%edx),%eax
if(p->s.size >= nunits){
69a: 8b 48 04 mov 0x4(%eax),%ecx
69d: 39 cf cmp %ecx,%edi
69f: 76 3f jbe 6e0 <malloc+0xa0>
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
6a1: 39 05 08 0a 00 00 cmp %eax,0xa08
6a7: 89 c2 mov %eax,%edx
6a9: 75 ed jne 698 <malloc+0x58>
char *p;
Header *hp;
if(nu < 4096)
nu = 4096;
p = sbrk(nu * sizeof(Header));
6ab: 83 ec 0c sub $0xc,%esp
6ae: 53 push %ebx
6af: e8 96 fc ff ff call 34a <sbrk>
if(p == (char*)-1)
6b4: 83 c4 10 add $0x10,%esp
6b7: 83 f8 ff cmp $0xffffffff,%eax
6ba: 74 1c je 6d8 <malloc+0x98>
return 0;
hp = (Header*)p;
hp->s.size = nu;
6bc: 89 70 04 mov %esi,0x4(%eax)
free((void*)(hp + 1));
6bf: 83 ec 0c sub $0xc,%esp
6c2: 83 c0 08 add $0x8,%eax
6c5: 50 push %eax
6c6: e8 e5 fe ff ff call 5b0 <free>
return freep;
6cb: 8b 15 08 0a 00 00 mov 0xa08,%edx
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
if((p = morecore(nunits)) == 0)
6d1: 83 c4 10 add $0x10,%esp
6d4: 85 d2 test %edx,%edx
6d6: 75 c0 jne 698 <malloc+0x58>
return 0;
6d8: 31 c0 xor %eax,%eax
6da: eb 1c jmp 6f8 <malloc+0xb8>
6dc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
if(p->s.size == nunits)
6e0: 39 cf cmp %ecx,%edi
6e2: 74 1c je 700 <malloc+0xc0>
prevp->s.ptr = p->s.ptr;
else {
p->s.size -= nunits;
6e4: 29 f9 sub %edi,%ecx
6e6: 89 48 04 mov %ecx,0x4(%eax)
p += p->s.size;
6e9: 8d 04 c8 lea (%eax,%ecx,8),%eax
p->s.size = nunits;
6ec: 89 78 04 mov %edi,0x4(%eax)
}
freep = prevp;
6ef: 89 15 08 0a 00 00 mov %edx,0xa08
return (void*)(p + 1);
6f5: 83 c0 08 add $0x8,%eax
}
if(p == freep)
if((p = morecore(nunits)) == 0)
return 0;
}
}
6f8: 8d 65 f4 lea -0xc(%ebp),%esp
6fb: 5b pop %ebx
6fc: 5e pop %esi
6fd: 5f pop %edi
6fe: 5d pop %ebp
6ff: c3 ret
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
if(p->s.size == nunits)
prevp->s.ptr = p->s.ptr;
700: 8b 08 mov (%eax),%ecx
702: 89 0a mov %ecx,(%edx)
704: eb e9 jmp 6ef <malloc+0xaf>
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
706: c7 05 08 0a 00 00 0c movl $0xa0c,0xa08
70d: 0a 00 00
710: c7 05 0c 0a 00 00 0c movl $0xa0c,0xa0c
717: 0a 00 00
base.s.size = 0;
71a: b8 0c 0a 00 00 mov $0xa0c,%eax
71f: c7 05 10 0a 00 00 00 movl $0x0,0xa10
726: 00 00 00
729: e9 3e ff ff ff jmp 66c <malloc+0x2c>
|
#include <iostream>
#include <utility>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t, n;
cin >> t;
while(t--) {
cin >> n;
auto a = new pair<int, int>*[n];
for(int i = 0; i < n; i++) {
a[i] = new pair<int, int>[i + 1];
for(int j = 0; j <= i; j++) a[i][j].first = 1, cin >> a[i][j].second;
}
for(int i = n - 1; i > 0; i--) {
for(int j = 0; j < i; j++) {
if(a[i][j].second == a[i][j + 1].second) {
a[i - 1][j].first = a[i][j].first + a[i][j + 1].first;
a[i - 1][j].second += a[i][j].second;
}
else if(a[i][j].second > a[i][j + 1].second) {
a[i - 1][j].first = a[i][j].first;
a[i - 1][j].second += a[i][j].second;
}
else {
a[i - 1][j].first = a[i][j + 1].first;
a[i - 1][j].second += a[i][j + 1].second;
}
}
}
cout << a[0][0].first << '\n';
for(int i = 0; i < n; i++) delete[] a[i];
delete[] a;
}
} |
;------------------------------------------------------------------------------
;*
;* Copyright 2006 - 2007, Intel Corporation
;* All rights reserved. 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.
;*
;* start16.asm
;*
;* Abstract:
;*
;------------------------------------------------------------------------------
.model small
.stack
.486p
.code
FAT_DIRECTORY_ENTRY_SIZE EQU 020h
FAT_DIRECTORY_ENTRY_SHIFT EQU 5
BLOCK_SIZE EQU 0200h
BLOCK_MASK EQU 01ffh
BLOCK_SHIFT EQU 9
org 0h
Ia32Jump:
jmp BootSectorEntryPoint ; JMP inst - 3 bytes
nop
OemId db "INTEL " ; OemId - 8 bytes
SectorSize dw 0 ; Sector Size - 16 bits
SectorsPerCluster db 0 ; Sector Per Cluster - 8 bits
ReservedSectors dw 0 ; Reserved Sectors - 16 bits
NoFats db 0 ; Number of FATs - 8 bits
RootEntries dw 0 ; Root Entries - 16 bits
Sectors dw 0 ; Number of Sectors - 16 bits
Media db 0 ; Media - 8 bits - ignored
SectorsPerFat dw 0 ; Sectors Per FAT - 16 bits
SectorsPerTrack dw 0 ; Sectors Per Track - 16 bits - ignored
Heads dw 0 ; Heads - 16 bits - ignored
HiddenSectors dd 0 ; Hidden Sectors - 32 bits - ignored
LargeSectors dd 0 ; Large Sectors - 32 bits
PhysicalDrive db 0 ; PhysicalDriveNumber - 8 bits - ignored
CurrentHead db 0 ; Current Head - 8 bits
Signature db 0 ; Signature - 8 bits - ignored
VolId db " " ; Volume Serial Number- 4 bytes
FatLabel db " " ; Label - 11 bytes
SystemId db "FAT16 " ; SystemId - 8 bytes
BootSectorEntryPoint:
ASSUME ds:@code
ASSUME ss:@code
; ds = 1000, es = 2000 + x (size of first cluster >> 4)
; cx = Start Cluster of EfiLdr
; dx = Start Cluster of Efivar.bin
; Re use the BPB data stored in Boot Sector
mov bp,07c00h
push cx
; Read Efivar.bin
; 1000:dx = DirectoryEntry of Efivar.bin -> BS.com has filled already
mov ax,01900h
mov es,ax
test dx,dx
jnz CheckVarStoreSize
mov al,1
NoVarStore:
push es
; Set the 5th byte start @ 0:19000 to non-zero indicating we should init var store header in DxeIpl
mov byte ptr es:[4],al
jmp SaveVolumeId
CheckVarStoreSize:
mov di,dx
cmp dword ptr ds:[di+2], 04000h
mov al,2
jne NoVarStore
LoadVarStore:
mov al,0
mov byte ptr es:[4],al
mov cx,word ptr[di]
; ES:DI = 1500:0
xor di,di
push es
mov ax,01500h
mov es,ax
call ReadFile
SaveVolumeId:
pop es
mov ax,word ptr [bp+VolId]
mov word ptr es:[0],ax ; Save Volume Id to 0:19000. we will find the correct volume according to this VolumeId
mov ax,word ptr [bp+VolId+2]
mov word ptr es:[2],ax
; Read Efildr
pop cx
; cx = Start Cluster of Efildr -> BS.com has filled already
; ES:DI = 2000:0, first cluster will be read again
xor di,di ; di = 0
mov ax,02000h
mov es,ax
call ReadFile
mov ax,cs
mov word ptr cs:[JumpSegment],ax
JumpFarInstruction:
db 0eah
JumpOffset:
dw 0200h
JumpSegment:
dw 2000h
; ****************************************************************************
; ReadFile
;
; Arguments:
; CX = Start Cluster of File
; ES:DI = Buffer to store file content read from disk
;
; Return:
; (ES << 4 + DI) = end of file content Buffer
;
; ****************************************************************************
ReadFile:
; si = NumberOfClusters
; cx = ClusterNumber
; dx = CachedFatSectorNumber
; ds:0000 = CacheFatSectorBuffer
; es:di = Buffer to load file
; bx = NextClusterNumber
pusha
mov si,1 ; NumberOfClusters = 1
push cx ; Push Start Cluster onto stack
mov dx,0fffh ; CachedFatSectorNumber = 0xfff
FatChainLoop:
mov ax,cx ; ax = ClusterNumber
and ax,0fff8h ; ax = ax & 0xfff8
cmp ax,0fff8h ; See if this is the last cluster
je FoundLastCluster ; Jump if last cluster found
mov ax,cx ; ax = ClusterNumber
shl ax,1 ; FatOffset = ClusterNumber * 2
push si ; Save si
mov si,ax ; si = FatOffset
shr ax,BLOCK_SHIFT ; ax = FatOffset >> BLOCK_SHIFT
add ax,word ptr [bp+ReservedSectors] ; ax = FatSectorNumber = ReservedSectors + (FatOffset >> BLOCK_OFFSET)
and si,BLOCK_MASK ; si = FatOffset & BLOCK_MASK
cmp ax,dx ; Compare FatSectorNumber to CachedFatSectorNumber
je SkipFatRead
mov bx,2
push es
push ds
pop es
call ReadBlocks ; Read 2 blocks starting at AX storing at ES:DI
pop es
mov dx,ax ; CachedFatSectorNumber = FatSectorNumber
SkipFatRead:
mov bx,word ptr [si] ; bx = NextClusterNumber
mov ax,cx ; ax = ClusterNumber
pop si ; Restore si
dec bx ; bx = NextClusterNumber - 1
cmp bx,cx ; See if (NextClusterNumber-1)==ClusterNumber
jne ReadClusters
inc bx ; bx = NextClusterNumber
inc si ; NumberOfClusters++
mov cx,bx ; ClusterNumber = NextClusterNumber
jmp FatChainLoop
ReadClusters:
inc bx
pop ax ; ax = StartCluster
push bx ; StartCluster = NextClusterNumber
mov cx,bx ; ClusterNumber = NextClusterNumber
sub ax,2 ; ax = StartCluster - 2
xor bh,bh
mov bl,byte ptr [bp+SectorsPerCluster] ; bx = SectorsPerCluster
mul bx ; ax = (StartCluster - 2) * SectorsPerCluster
add ax, word ptr [bp] ; ax = FirstClusterLBA + (StartCluster-2)*SectorsPerCluster
push ax ; save start sector
mov ax,si ; ax = NumberOfClusters
mul bx ; ax = NumberOfClusters * SectorsPerCluster
mov bx,ax ; bx = Number of Sectors
pop ax ; ax = Start Sector
call ReadBlocks
mov si,1 ; NumberOfClusters = 1
jmp FatChainLoop
FoundLastCluster:
pop cx
popa
ret
; ****************************************************************************
; ReadBlocks - Reads a set of blocks from a block device
;
; AX = Start LBA
; BX = Number of Blocks to Read
; ES:DI = Buffer to store sectors read from disk
; ****************************************************************************
; cx = Blocks
; bx = NumberOfBlocks
; si = StartLBA
ReadBlocks:
pusha
add eax,dword ptr [bp+LBAOffsetForBootSector] ; Add LBAOffsetForBootSector to Start LBA
add eax,dword ptr [bp+HiddenSectors] ; Add HiddenSectors to Start LBA
mov esi,eax ; esi = Start LBA
mov cx,bx ; cx = Number of blocks to read
ReadCylinderLoop:
mov bp,07bfch ; bp = 0x7bfc
mov eax,esi ; eax = Start LBA
xor edx,edx ; edx = 0
movzx ebx,word ptr [bp] ; bx = MaxSector
div ebx ; ax = StartLBA / MaxSector
inc dx ; dx = (StartLBA % MaxSector) + 1
mov bx,word ptr [bp] ; bx = MaxSector
sub bx,dx ; bx = MaxSector - Sector
inc bx ; bx = MaxSector - Sector + 1
cmp cx,bx ; Compare (Blocks) to (MaxSector - Sector + 1)
jg LimitTransfer
mov bx,cx ; bx = Blocks
LimitTransfer:
push ax ; save ax
mov ax,es ; ax = es
shr ax,(BLOCK_SHIFT-4) ; ax = Number of blocks into mem system
and ax,07fh ; ax = Number of blocks into current seg
add ax,bx ; ax = End Block number of transfer
cmp ax,080h ; See if it crosses a 64K boundry
jle NotCrossing64KBoundry ; Branch if not crossing 64K boundry
sub ax,080h ; ax = Number of blocks past 64K boundry
sub bx,ax ; Decrease transfer size by block overage
NotCrossing64KBoundry:
pop ax ; restore ax
push cx
mov cl,dl ; cl = (StartLBA % MaxSector) + 1 = Sector
xor dx,dx ; dx = 0
div word ptr [bp+2] ; ax = ax / (MaxHead + 1) = Cylinder
; dx = ax % (MaxHead + 1) = Head
push bx ; Save number of blocks to transfer
mov dh,dl ; dh = Head
mov bp,07c00h ; bp = 0x7c00
mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
mov ch,al ; ch = Cylinder
mov al,bl ; al = Blocks
mov ah,2 ; ah = Function 2
mov bx,di ; es:bx = Buffer address
int 013h
jc DiskError
pop bx
pop cx
movzx ebx,bx
add esi,ebx ; StartLBA = StartLBA + NumberOfBlocks
sub cx,bx ; Blocks = Blocks - NumberOfBlocks
mov ax,es
shl bx,(BLOCK_SHIFT-4)
add ax,bx
mov es,ax ; es:di = es:di + NumberOfBlocks*BLOCK_SIZE
cmp cx,0
jne ReadCylinderLoop
popa
ret
DiskError:
push cs
pop ds
lea si, [ErrorString]
mov cx, 7
jmp PrintStringAndHalt
PrintStringAndHalt:
mov ax,0b800h
mov es,ax
mov di,160
rep movsw
Halt:
jmp Halt
ErrorString:
db 'S', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
org 01fah
LBAOffsetForBootSector:
dd 0h
org 01feh
dw 0aa55h
;******************************************************************************
;******************************************************************************
;******************************************************************************
DELAY_PORT equ 0edh ; Port to use for 1uS delay
KBD_CONTROL_PORT equ 060h ; 8042 control port
KBD_STATUS_PORT equ 064h ; 8042 status port
WRITE_DATA_PORT_CMD equ 0d1h ; 8042 command to write the data port
ENABLE_A20_CMD equ 0dfh ; 8042 command to enable A20
org 200h
jmp start
Em64String:
db 'E', 0ch, 'm', 0ch, '6', 0ch, '4', 0ch, 'T', 0ch, ' ', 0ch, 'U', 0ch, 'n', 0ch, 's', 0ch, 'u', 0ch, 'p', 0ch, 'p', 0ch, 'o', 0ch, 'r', 0ch, 't', 0ch, 'e', 0ch, 'd', 0ch, '!', 0ch
start:
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
mov sp,MyStack
; mov ax,0b800h
; mov es,ax
; mov byte ptr es:[160],'a'
; mov ax,cs
; mov es,ax
mov ebx,0
lea edi,MemoryMap
MemMapLoop:
mov eax,0e820h
mov ecx,20
mov edx,'SMAP'
int 15h
jc MemMapDone
add edi,20
cmp ebx,0
je MemMapDone
jmp MemMapLoop
MemMapDone:
lea eax,MemoryMap
sub edi,eax ; Get the address of the memory map
mov dword ptr [MemoryMapSize],edi ; Save the size of the memory map
xor ebx,ebx
mov bx,cs ; BX=segment
shl ebx,4 ; BX="linear" address of segment base
lea eax,[GDT_BASE + ebx] ; EAX=PHYSICAL address of gdt
mov dword ptr [gdtr + 2],eax ; Put address of gdt into the gdtr
lea eax,[IDT_BASE + ebx] ; EAX=PHYSICAL address of idt
mov dword ptr [idtr + 2],eax ; Put address of idt into the idtr
lea edx,[MemoryMapSize + ebx] ; Physical base address of the memory map
add ebx,01000h ; Source of EFI32
mov dword ptr [JUMP+2],ebx
add ebx,01000h
mov esi,ebx ; Source of EFILDR32
; mov ax,0b800h
; mov es,ax
; mov byte ptr es:[162],'b'
; mov ax,cs
; mov es,ax
;
; Enable A20 Gate
;
mov ax,2401h ; Enable A20 Gate
int 15h
jnc A20GateEnabled ; Jump if it suceeded
;
; If INT 15 Function 2401 is not supported, then attempt to Enable A20 manually.
;
call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
jnz Timeout8042 ; Jump if the 8042 timed out
out DELAY_PORT,ax ; Delay 1 uS
mov al,WRITE_DATA_PORT_CMD ; 8042 cmd to write output port
out KBD_STATUS_PORT,al ; Send command to the 8042
call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
jnz Timeout8042 ; Jump if the 8042 timed out
mov al,ENABLE_A20_CMD ; gate address bit 20 on
out KBD_CONTROL_PORT,al ; Send command to thre 8042
call Empty8042InputBuffer ; Empty the Input Buffer on the 8042 controller
mov cx,25 ; Delay 25 uS for the command to complete on the 8042
Delay25uS:
out DELAY_PORT,ax ; Delay 1 uS
loop Delay25uS
Timeout8042:
A20GateEnabled:
;
; DISABLE INTERRUPTS - Entering Protected Mode
;
cli
; mov ax,0b800h
; mov es,ax
; mov byte ptr es:[164],'c'
; mov ax,cs
; mov es,ax
db 66h
lgdt fword ptr [gdtr]
db 66h
lidt fword ptr [idtr]
mov eax,cr0
or al,1
mov cr0,eax
mov eax,0008h ; Flat data descriptor
mov ebp,000400000h ; Destination of EFILDR32
mov ebx,000070000h ; Length of copy
JUMP:
; jmp far 0010:00020000
db 066h
db 0eah
dd 000020000h
dw 00010h
Empty8042InputBuffer:
mov cx,0
Empty8042Loop:
out DELAY_PORT,ax ; Delay 1us
in al,KBD_STATUS_PORT ; Read the 8042 Status Port
and al,02h ; Check the Input Buffer Full Flag
loopnz Empty8042Loop ; Loop until the input buffer is empty or a timout of 65536 uS
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 02h
gdtr dw GDT_END - GDT_BASE - 1 ; GDT limit
dd 0 ; (GDT base gets set above)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; global descriptor table (GDT)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 02h
public GDT_BASE
GDT_BASE:
; null descriptor
NULL_SEL equ $-GDT_BASE
dw 0 ; limit 15:0
dw 0 ; base 15:0
db 0 ; base 23:16
db 0 ; type
db 0 ; limit 19:16, flags
db 0 ; base 31:24
; linear data segment descriptor
LINEAR_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 092h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; linear code segment descriptor
LINEAR_CODE_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 09Ah ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; system data segment descriptor
SYS_DATA_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 092h ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; system code segment descriptor
SYS_CODE_SEL equ $-GDT_BASE
dw 0FFFFh ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 09Ah ; present, ring 0, data, expand-up, writable
db 0CFh ; page-granular, 32-bit
db 0
; spare segment descriptor
SPARE3_SEL equ $-GDT_BASE
dw 0 ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 0 ; present, ring 0, data, expand-up, writable
db 0 ; page-granular, 32-bit
db 0
; spare segment descriptor
SPARE4_SEL equ $-GDT_BASE
dw 0 ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 0 ; present, ring 0, data, expand-up, writable
db 0 ; page-granular, 32-bit
db 0
; spare segment descriptor
SPARE5_SEL equ $-GDT_BASE
dw 0 ; limit 0xFFFFF
dw 0 ; base 0
db 0
db 0 ; present, ring 0, data, expand-up, writable
db 0 ; page-granular, 32-bit
db 0
GDT_END:
align 02h
idtr dw IDT_END - IDT_BASE - 1 ; IDT limit
dd 0 ; (IDT base gets set above)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; interrupt descriptor table (IDT)
;
; Note: The hardware IRQ's specified in this table are the normal PC/AT IRQ
; mappings. This implementation only uses the system timer and all other
; IRQs will remain masked. The descriptors for vectors 33+ are provided
; for convenience.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;idt_tag db "IDT",0
align 02h
public IDT_BASE
IDT_BASE:
; divide by zero (INT 0)
DIV_ZERO_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; debug exception (INT 1)
DEBUG_EXCEPT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; NMI (INT 2)
NMI_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; soft breakpoint (INT 3)
BREAKPOINT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; overflow (INT 4)
OVERFLOW_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; bounds check (INT 5)
BOUNDS_CHECK_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; invalid opcode (INT 6)
INVALID_OPCODE_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; device not available (INT 7)
DEV_NOT_AVAIL_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; double fault (INT 8)
DOUBLE_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; Coprocessor segment overrun - reserved (INT 9)
RSVD_INTR_SEL1 equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; invalid TSS (INT 0ah)
INVALID_TSS_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; segment not present (INT 0bh)
SEG_NOT_PRESENT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; stack fault (INT 0ch)
STACK_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; general protection (INT 0dh)
GP_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; page fault (INT 0eh)
PAGE_FAULT_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; Intel reserved - do not use (INT 0fh)
RSVD_INTR_SEL2 equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; floating point error (INT 10h)
FLT_POINT_ERR_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; type = 386 interrupt gate, present
dw 0 ; offset 31:16
; alignment check (INT 11h)
ALIGNMENT_CHECK_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; machine check (INT 12h)
MACHINE_CHECK_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; SIMD floating-point exception (INT 13h)
SIMD_EXCEPTION_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; 85 unspecified descriptors, First 12 of them are reserved, the rest are avail
db (85 * 8) dup(0)
; IRQ 0 (System timer) - (INT 68h)
IRQ0_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 1 (8042 Keyboard controller) - (INT 69h)
IRQ1_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; Reserved - IRQ 2 redirect (IRQ 2) - DO NOT USE!!! - (INT 6ah)
IRQ2_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 3 (COM 2) - (INT 6bh)
IRQ3_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 4 (COM 1) - (INT 6ch)
IRQ4_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 5 (LPT 2) - (INT 6dh)
IRQ5_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 6 (Floppy controller) - (INT 6eh)
IRQ6_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 7 (LPT 1) - (INT 6fh)
IRQ7_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 8 (RTC Alarm) - (INT 70h)
IRQ8_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 9 - (INT 71h)
IRQ9_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 10 - (INT 72h)
IRQ10_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 11 - (INT 73h)
IRQ11_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 12 (PS/2 mouse) - (INT 74h)
IRQ12_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 13 (Floating point error) - (INT 75h)
IRQ13_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 14 (Secondary IDE) - (INT 76h)
IRQ14_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
; IRQ 15 (Primary IDE) - (INT 77h)
IRQ15_SEL equ $-IDT_BASE
dw 0 ; offset 15:0
dw SYS_CODE_SEL ; selector 15:0
db 0 ; 0 for interrupt gate
db 0eh OR 80h ; (10001110)type = 386 interrupt gate, present
dw 0 ; offset 31:16
IDT_END:
align 02h
MemoryMapSize dd 0
MemoryMap dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 0,0,0,0,0,0,0,0
dd 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
dd 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
org 0fe0h
MyStack:
; below is the pieces of the IVT that is used to redirect INT 68h - 6fh
; back to INT 08h - 0fh when in real mode... It is 'org'ed to a
; known low address (20f00) so it can be set up by PlMapIrqToVect in
; 8259.c
int 8
iret
int 9
iret
int 10
iret
int 11
iret
int 12
iret
int 13
iret
int 14
iret
int 15
iret
org 0ffeh
BlockSignature:
dw 0aa55h
end
|
; Weapon Tank Graphics
lorom
; place at a suitable location in bank $89, then point the
; item_data for custom graphics to it in weapon-tank.xkas-06.asm
; (change the 9400 there to the latter 2/3 of this org)
org $899400
; frame 1
DB $3F,$3F,$50,$7F,$98,$F7,$3F,$D0,$1C,$90,$1D,$F0,$1D,$90,$7F,$90,$3F,$00,$7F,$00,$FF,$08,$FF,$0C,$FF,$0C,$DF,$6D,$FF,$0D,$FF,$0F
DB $FC,$FC,$0A,$FE,$19,$EF,$FC,$0B,$38,$09,$B8,$0F,$B8,$09,$FE,$09,$FC,$00,$FE,$00,$FF,$10,$FF,$30,$FF,$30,$FF,$B6,$FF,$B0,$FF,$F0
DB $3F,$D0,$92,$FD,$50,$7F,$3F,$3F,$0C,$0C,$08,$04,$66,$78,$66,$78,$FF,$07,$FF,$02,$7F,$10,$3F,$00,$0C,$00,$0C,$00,$7F,$01,$7F,$01
DB $FC,$0B,$29,$DF,$0A,$FE,$FC,$FC,$30,$30,$10,$20,$66,$1E,$66,$1E,$FF,$70,$FF,$20,$FE,$08,$FC,$00,$30,$00,$30,$00,$FE,$80,$FE,$80
; frame 2
DB $3F,$3F,$50,$7F,$90,$F7,$33,$D0,$10,$90,$10,$90,$10,$90,$70,$90,$3F,$00,$7F,$00,$F7,$08,$F3,$0C,$F3,$0C,$F2,$6D,$F2,$0D,$F0,$0F
DB $FC,$FC,$0A,$FE,$09,$EF,$CC,$0B,$08,$09,$08,$09,$08,$09,$0E,$09,$FC,$00,$FE,$00,$EF,$10,$CF,$30,$CF,$30,$4F,$B6,$4F,$B0,$0F,$F0
DB $31,$D0,$90,$FB,$50,$7F,$3F,$3F,$0C,$0C,$08,$04,$64,$78,$64,$78,$F1,$0E,$FB,$04,$7F,$10,$3F,$00,$0C,$00,$0C,$00,$7F,$01,$7F,$01
DB $8C,$0B,$09,$DF,$0A,$FE,$FC,$FC,$30,$30,$10,$20,$26,$1E,$26,$1E,$8F,$70,$DF,$20,$FE,$08,$FC,$00,$30,$00,$30,$00,$FE,$80,$FE,$80
|
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2018, Sebastian Schlenkrich
*/
#ifndef quantlib_qgcalibrator_hpp
#define quantlib_qgcalibrator_hpp
#include <ql/indexes/swapindex.hpp>
#include <ql/instruments/swaption.hpp>
#include <ql/termstructures/volatility/swaption/swaptionvolstructure.hpp>
#include <ql/math/optimization/constraint.hpp>
#include <ql/math/optimization/levenbergmarquardt.hpp>
#include <ql/experimental/basismodels/swaptioncfs.hpp>
#include <ql/experimental/templatemodels/qgaussian2/qgaverageswapratemodelT.hpp>
#define _MIN_( a, b ) ( (a) < (b) ? (a) : (b) )
#define _MAX_( a, b ) ( (a) > (b) ? (a) : (b) )
namespace QuantLib {
typedef QuasiGaussianModel2T<QuantLib::Time, QuantLib::Real, QuantLib::Real> QuasiGaussianModel;
typedef QGSwaprateModelT<QuantLib::Time, QuantLib::Real, QuantLib::Real> QGSwaprateModel;
typedef QGAverageSwaprateModelT<QuantLib::Time, QuantLib::Real, QuantLib::Real> QGAverageSwaprateModel;
// calibrate Quasi Gaussian model to implied normal volatilities
class QGCalibrator {
// the Quasi-Gaussian model aimed to be calibrated
ext::shared_ptr<QuasiGaussianModel> model_;
// the resulting calibrated Quasi-Gaussian model
ext::shared_ptr<QuasiGaussianModel> calibratedModel_;
// we may use a MC simulation to adjust for closed form vs MC bias
// ext::shared_ptr<RealMCSimulation> mcSimulation_;
// calibration target volatilities
Handle<SwaptionVolatilityStructure> volTS_;
// we calibrate to strips of swaption volatilities; maybe also co-terminals can be relevant
std::vector< ext::shared_ptr<SwapIndex> > swapIndices_;
// we want to control calibration by individual weights
Real sigmaWeight_, slopeWeight_, etaWeight_;
// apply a penalty on differing slope and skew values per factor
Real penaltySigma_, penaltySlope_;
// constraints for input model parameters
Real sigmaMin_, sigmaMax_, slopeMin_, slopeMax_, etaMin_, etaMax_;
// transformation (-inf, +inf) -> (a, b)
static const Real direct(const Real x, const Real a, const Real b) {
//return (b-a)*(atan(x)/M_PI + 0.5) + a;
return TemplateAuxilliaries::direct(x, a, b);
}
// transformation (a, b) -> (-inf, +inf)
static const Real inverse(const Real y, const Real a, const Real b) {
//return tan( ((y-a)/(b-a)-0.5) * M_PI );
return TemplateAuxilliaries::inverse(y, a, b);
}
// we need to know when to stop iterating
EndCriteria endCriteria_;
// parameters for quasi-Gaussian swaption model
Real modelTimesStepSize_; // in year fractions
bool useExpectedXY_;
// we do some logging for degugging purposes
std::vector< std::string > debugLog_;
// the objective function controls the actual calibration step
class Objective : public CostFunction {
private:
// reference to access model, swaptions and targets
QGCalibrator *calibrator_;
// we work on a copy of the initial model (better safe then sorry)
ext::shared_ptr<QuasiGaussianModel> model_;
// specify parameters used for optimisation; dimension [modeltimes] x [ d (sigma) + d (slope) + 1 (eta) ]
std::vector< std::vector< Real > > isInput_;
// specify targets used for optimisation; dimension [exercises] x [ swapterm (SigmaATM) + swapterm (Skew) + swapterm (Smile) ]
std::vector< std::vector< Real > > isOutput_;
// count inputs and outputs
Size inputSize_;
Size outputSize_;
// container for single curve swaption cash flow representation and calibration targets; initialised at inception
class CalibSwaption : public SwapCashFlows {
// cash flows are inherited from base class
// targets
Real sigmaATM_, skew_, smile_;
// auxilliaries
std::vector< Real > modelTimes_;
public:
CalibSwaption ( Date expiryDate,
const ext::shared_ptr<SwapIndex>& swapindex,
const Handle<YieldTermStructure>& discountCurve,
const Handle<SwaptionVolatilityStructure> volTS,
bool contTenorSpread = true,
Real modelTimesStepSize = 1.0/12.0);
// inspectors
inline Real sigmaATM() const { return sigmaATM_; }
inline Real skew() const { return skew_; }
inline Real smile() const { return smile_; }
inline const std::vector<Real>& modelTimes() const { return modelTimes_; }
};
std::vector< std::vector< ext::shared_ptr<CalibSwaption> > > calibSwaptions_;
public:
const Size inputSize() const { return inputSize_; }
const Size outputSize() const { return outputSize_; }
Objective( QGCalibrator *calibrator,
const std::vector< std::vector< Real > >& isInput,
const std::vector< std::vector< Real > >& isOutput );
// initialize state X with model parameters and apply inverse transformation
Array initialise();
// allocate X with inputSize
// for all isInput[i]
// for j=0.. d-1, isInput[i][j] ? sigma -> inverseSigma -> X[idx], ++idx
// for j=d..2d-1, isInput[i][j] ? slope -> inverseSlope -> X[idx], ++idx
// for j=2d, isInput[i][j] ? eta -> inverseEta -> X[idx], ++idx
// apply direct transformation and update model parameters
void update(const Array& X) const;
// for all isInput[i]
// for j=0.. d-1, isInput[i][j] ? X[idx] -> inverseSigma -> lambda, ++idx
// for j=d..2d-1, isInput[i][j] ? X[idx] -> inverseSlope -> b , ++idx
// for j=2d, isInput[i][j] ? X[idx] -> inverseEta -> eta , ++idx
// model->update(lambda,b,eta)
// CostFunction interface
virtual Disposable<Array> values(const Array& x) const;
// update(x)
// allocate Y with outputSize()
// for k=0..swaptions_.size() construct QGSwaprateModel swpModel[k]
// for all isOutput[i], j=0..swapterm-1
// isOutput[i][0*swapterm+j] ? swpModel[k] -> sigmaATM -> Y[idx], Y[idx] -= sigmaATM[k], ++idx
// isOutput[i][1*swapterm+j] ? swpModel[k] -> skew -> Y[idx], Y[idx] -= skew[k], ++idx
// isOutput[i][2*swapterm+j] ? swpModel[k] -> smile -> Y[idx], Y[idx] -= smile[k], ++idx
// ++k
// 0.5 ||Y||^2
virtual Real value(const Array& x) const;
// return the model for a given input state
const ext::shared_ptr<QuasiGaussianModel> model(const Array& x);
};
public:
// constructor
QGCalibrator( const ext::shared_ptr<QuasiGaussianModel>& model,
const Handle<SwaptionVolatilityStructure>& volTS,
const std::vector< ext::shared_ptr<SwapIndex> >& swapIndices,
const Real modelTimesStepSize,
const bool useExpectedXY,
const Real sigmaMax,
const Real slopeMax,
const Real etaMax,
const Real sigmaWeight,
const Real slopeWeight,
const Real etaWeight,
const Real penaltySigma,
const Real penaltySlope,
const EndCriteria& endCriteria );
// a single optimisation run
Integer calibrate( const std::vector< std::vector< Real > >& isInput,
const std::vector< std::vector< Real > >& isOutput,
Real epsfcn = 1.0e-4 ); // delta for finite differences
// inspectors
inline const ext::shared_ptr<QuasiGaussianModel> calibratedModel() const { return calibratedModel_; }
inline const std::vector<std::string>& debugLog() const { return debugLog_; }
inline void acceptCalibration() { model_ = calibratedModel_; }
};
}
#undef _MIN_
#undef _MAX_
#endif /* ifndef quantlib_qgcalibrator_hpp */
|
; file: main.asm target: ATmega128L-4MHz-STK300
; An EPFL MT-BA4 microcontroller project
; Authors: Marcus Cemes, Julien Moreno, Charlotte Vadori
; === Top-level includes === ;
; May only contain definitions and macros.
.include "m128def.inc"
.include "definitions.inc"
.include "macros.asm"
; === Interrupt vector table === ;
.org 0x0000
jmp reset
.org INT6addr
jmp int6_handler
; === Device reset === ;
reset:
LDSP RAMEND ; initialise stack pointer
SMBI MCUCR, (1<<SRE)+(1<<SRW10) ; enable external SRAM
rcall LCD_init ; initialise LCD
rcall RE_init ; initialise Rotary Encoder
rcall wire1_init ; initialize 1-wire(R) interface
OUTI EIMSK, (1<<6) ; Configure interrupts
OUTI EICRB, 0x00 ; Interrupt on low-level
clr d3 ; Reset Application Configuration Register
jmp main
; === Imports === ;
.include "lib/printf.asm"
.include "drivers/lcd.asm"
.include "drivers/rotary_encoder.asm"
.include "drivers/wire1.asm"
.include "run.asm"
.include "interrupt.asm"
.include "menu.asm"
; === Entry point === ;
main:
LCD_PL greet_msg_0, greet_msg_1
WAIT_MS 2000
rcall show_menu
jmp run
; === Program termination === ;
stop_msg:
rcall LCD_clear
PRINTF LCD
.db " Program", LF, " terminated", 0
stop:
rjmp stop
; === Binary payloads === ;
greet_msg_0: .db "MICRO-210 proj.", 0
greet_msg_1: .db "EPFL MT-BA4 2021", 0, 0
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r9
push %rax
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0x92c4, %rcx
nop
nop
nop
nop
sub %rbp, %rbp
mov $0x6162636465666768, %r9
movq %r9, (%rcx)
sub $49956, %r11
lea addresses_A_ht+0xba54, %r10
sub $27746, %rdi
mov (%r10), %rax
nop
cmp $34021, %rax
lea addresses_WT_ht+0xb254, %r10
nop
nop
cmp $47033, %rbp
mov $0x6162636465666768, %rcx
movq %rcx, %xmm1
movups %xmm1, (%r10)
sub %rbp, %rbp
lea addresses_WC_ht+0x1a698, %r9
nop
nop
nop
nop
sub %rax, %rax
mov $0x6162636465666768, %rbp
movq %rbp, (%r9)
nop
nop
nop
nop
dec %rbp
lea addresses_D_ht+0x13154, %r10
nop
nop
and $18498, %r9
mov (%r10), %r11
nop
dec %r9
lea addresses_A_ht+0x1cf5c, %r11
clflush (%r11)
nop
nop
nop
nop
nop
xor %rax, %rax
mov (%r11), %r10d
nop
nop
nop
nop
nop
and $50446, %r9
lea addresses_WC_ht+0x5a54, %r10
nop
nop
nop
nop
add %r11, %r11
mov $0x6162636465666768, %rdi
movq %rdi, %xmm6
movups %xmm6, (%r10)
nop
nop
inc %rax
lea addresses_WT_ht+0x14654, %rsi
lea addresses_WT_ht+0x10b14, %rdi
nop
nop
and %r11, %r11
mov $89, %rcx
rep movsl
nop
nop
nop
nop
nop
and $54302, %rsi
lea addresses_WC_ht+0x11894, %rax
nop
xor %r11, %r11
movl $0x61626364, (%rax)
nop
xor $10614, %r10
lea addresses_normal_ht+0x19254, %rsi
lea addresses_UC_ht+0xdac4, %rdi
nop
nop
dec %r11
mov $60, %rcx
rep movsb
nop
nop
nop
nop
add %r10, %r10
lea addresses_WC_ht+0x214c, %rsi
lea addresses_WT_ht+0xad4, %rdi
nop
nop
nop
nop
xor %r10, %r10
mov $16, %rcx
rep movsb
nop
nop
nop
nop
nop
sub $48151, %r9
lea addresses_WT_ht+0x14dd4, %rax
cmp $26405, %r11
mov $0x6162636465666768, %rdi
movq %rdi, (%rax)
nop
nop
nop
nop
and %r11, %r11
lea addresses_WC_ht+0x10e54, %r11
nop
nop
nop
nop
nop
xor $46056, %rbp
mov $0x6162636465666768, %rsi
movq %rsi, (%r11)
nop
nop
nop
nop
cmp %r10, %r10
lea addresses_A_ht+0x14a54, %rdi
and %r9, %r9
mov $0x6162636465666768, %rsi
movq %rsi, (%rdi)
nop
nop
nop
nop
nop
dec %rsi
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r9
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r13
push %r14
push %r15
push %r8
push %rbp
// Faulty Load
lea addresses_D+0x18254, %r14
cmp $58471, %r13
vmovups (%r14), %ymm2
vextracti128 $1, %ymm2, %xmm2
vpextrq $1, %xmm2, %rbp
lea oracles, %r8
and $0xff, %rbp
shlq $12, %rbp
mov (%r8,%rbp,1), %rbp
pop %rbp
pop %r8
pop %r15
pop %r14
pop %r13
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_D', 'same': False, 'size': 16, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'type': 'addresses_D', 'same': True, 'size': 32, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'dst': {'type': 'addresses_D_ht', 'same': False, 'size': 8, 'congruent': 4, 'NT': True, 'AVXalign': True}, 'OP': 'STOR'}
{'src': {'type': 'addresses_A_ht', 'same': False, 'size': 8, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 16, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 8, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_D_ht', 'same': False, 'size': 8, 'congruent': 8, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_A_ht', 'same': False, 'size': 4, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 16, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_WT_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 4, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_normal_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_WC_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 8, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_A_ht', 'same': False, 'size': 8, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'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
*/
|
; A131970: 1 followed by 2n 2's.
; 1,122,12222,1222222,122222222,12222222222,1222222222222,122222222222222,12222222222222222,1222222222222222222,122222222222222222222,12222222222222222222222,1222222222222222222222222,122222222222222222222222222,12222222222222222222222222222,1222222222222222222222222222222,122222222222222222222222222222222,12222222222222222222222222222222222
mov $1,100
pow $1,$0
div $1,99
mul $1,121
add $1,1
mov $0,$1
|
dnl x86-64 mpn_divrem_1 -- mpn by limb division.
dnl Copyright 2004, 2005, 2007-2010, 2012, 2014 Free Software Foundation, Inc.
dnl This file is part of the GNU MP Library.
dnl
dnl The GNU MP Library is free software; you can redistribute it and/or modify
dnl it under the terms of either:
dnl
dnl * the GNU Lesser General Public License as published by the Free
dnl Software Foundation; either version 3 of the License, or (at your
dnl option) any later version.
dnl
dnl or
dnl
dnl * the GNU General Public License as published by the Free Software
dnl Foundation; either version 2 of the License, or (at your option) any
dnl later version.
dnl
dnl or both in parallel, as here.
dnl
dnl The GNU MP Library is distributed in the hope that it will be useful, but
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
dnl for more details.
dnl
dnl You should have received copies of the GNU General Public License and the
dnl GNU Lesser General Public License along with the GNU MP Library. If not,
dnl see https://www.gnu.org/licenses/.
include(`../config.m4')
C norm unorm frac
C AMD K8,K9 15 15 12
C AMD K10 15 15 12
C Intel P4 44 44 43
C Intel core2 24 24 19.5
C Intel corei 19 19 18
C Intel atom 51 51 36
C VIA nano 46 44 22.5
C mp_limb_t
C mpn_divrem_1 (mp_ptr qp, mp_size_t fn,
C mp_srcptr np, mp_size_t nn, mp_limb_t d)
C mp_limb_t
C mpn_preinv_divrem_1 (mp_ptr qp, mp_size_t fn,
C mp_srcptr np, mp_size_t nn, mp_limb_t d,
C mp_limb_t dinv, int cnt)
C INPUT PARAMETERS
define(`qp', `%rdi')
define(`fn_param', `%rsi')
define(`up_param', `%rdx')
define(`un_param', `%rcx')
define(`d', `%r8')
define(`dinv', `%r9') C only for mpn_preinv_divrem_1
C shift passed on stack C only for mpn_preinv_divrem_1
define(`cnt', `%rcx')
define(`up', `%rsi')
define(`fn', `%r12')
define(`un', `%rbx')
C rax rbx rcx rdx rsi rdi rbp r8 r9 r10 r11 r12 r13 r14 r15
C cnt qp d dinv
ABI_SUPPORT(DOS64)
ABI_SUPPORT(STD64)
IFSTD(`define(`CNTOFF', `40($1)')')
IFDOS(`define(`CNTOFF', `104($1)')')
ASM_START()
TEXT
ALIGN(16)
PROLOGUE(mpn_preinv_divrem_1)
FUNC_ENTRY(4)
IFDOS(` mov 56(%rsp), %r8 ')
IFDOS(` mov 64(%rsp), %r9 ')
xor R32(%rax), R32(%rax)
push %r13
push %r12
push %rbp
push %rbx
mov fn_param, fn
mov un_param, un
add fn_param, un_param
mov up_param, up
lea -8(qp,un_param,8), qp
mov CNTOFF(%rsp), R8(cnt)
shl R8(cnt), d
jmp L(ent)
EPILOGUE()
ALIGN(16)
PROLOGUE(mpn_divrem_1)
FUNC_ENTRY(4)
IFDOS(` mov 56(%rsp), %r8 ')
xor R32(%rax), R32(%rax)
push %r13
push %r12
push %rbp
push %rbx
mov fn_param, fn
mov un_param, un
add fn_param, un_param
mov up_param, up
je L(ret)
lea -8(qp,un_param,8), qp
xor R32(%rbp), R32(%rbp)
L(unnormalized):
test un, un
je L(44)
mov -8(up,un,8), %rax
cmp d, %rax
jae L(44)
mov %rbp, (qp)
mov %rax, %rbp
lea -8(qp), qp
je L(ret)
dec un
L(44):
bsr d, %rcx
not R32(%rcx)
sal R8(%rcx), d
sal R8(%rcx), %rbp
push %rcx
IFSTD(` push %rdi ')
IFSTD(` push %rsi ')
push %r8
IFSTD(` sub $8, %rsp ')
IFSTD(` mov d, %rdi ')
IFDOS(` sub $40, %rsp ')
IFDOS(` mov d, %rcx ')
ASSERT(nz, `test $15, %rsp')
CALL( mpn_invert_limb)
IFSTD(` add $8, %rsp ')
IFDOS(` add $40, %rsp ')
pop %r8
IFSTD(` pop %rsi ')
IFSTD(` pop %rdi ')
pop %rcx
mov %rax, dinv
mov %rbp, %rax
test un, un
je L(frac)
L(ent): mov -8(up,un,8), %rbp
shr R8(%rcx), %rax
shld R8(%rcx), %rbp, %rax
sub $2, un
js L(end)
ALIGN(16)
L(top): lea 1(%rax), %r11
mul dinv
mov (up,un,8), %r10
shld R8(%rcx), %r10, %rbp
mov %rbp, %r13
add %rax, %r13
adc %r11, %rdx
mov %rdx, %r11
imul d, %rdx
sub %rdx, %rbp
lea (d,%rbp), %rax
sub $8, qp
cmp %r13, %rbp
cmovc %rbp, %rax
adc $-1, %r11
cmp d, %rax
jae L(ufx)
L(uok): dec un
mov %r11, 8(qp)
mov %r10, %rbp
jns L(top)
L(end): lea 1(%rax), %r11
sal R8(%rcx), %rbp
mul dinv
add %rbp, %rax
adc %r11, %rdx
mov %rax, %r11
mov %rdx, %r13
imul d, %rdx
sub %rdx, %rbp
mov d, %rax
add %rbp, %rax
cmp %r11, %rbp
cmovc %rbp, %rax
adc $-1, %r13
cmp d, %rax
jae L(efx)
L(eok): mov %r13, (qp)
sub $8, qp
jmp L(frac)
L(ufx): sub d, %rax
inc %r11
jmp L(uok)
L(efx): sub d, %rax
inc %r13
jmp L(eok)
L(frac):mov d, %rbp
neg %rbp
jmp L(fent)
ALIGN(16) C K8-K10 P6-CNR P6-NHM P4
L(ftop):mul dinv C 0,12 0,17 0,17
add %r11, %rdx C 5 8 10
mov %rax, %r11 C 4 8 3
mov %rdx, %r13 C 6 9 11
imul %rbp, %rdx C 6 9 11
mov d, %rax C
add %rdx, %rax C 10 14 14
cmp %r11, %rdx C 10 14 14
cmovc %rdx, %rax C 11 15 15
adc $-1, %r13 C
mov %r13, (qp) C
sub $8, qp C
L(fent):lea 1(%rax), %r11 C
dec fn C
jns L(ftop) C
shr R8(%rcx), %rax
L(ret): pop %rbx
pop %rbp
pop %r12
pop %r13
FUNC_EXIT()
ret
EPILOGUE()
|
<%
from pwnlib.shellcraft.arm.linux import syscall
%>
<%page args=""/>
<%docstring>
Invokes the syscall geteuid. See 'man 2 geteuid' for more information.
Arguments:
</%docstring>
${syscall('SYS_geteuid')}
|
stx $fd
lda {m1}
sta $fe
lda {m1}+1
sta $ff
lda ($fe),y
cmp $fd
bne {la1} |
0F88 C5
0F89 D5
0F8A E5
0F8B 11 CA 0B
0F8E 21 9B 0F
0F91 01 30 00
0F94 ED B0
0F96 E1
0F97 D1
0F98 C1
0F99 DF 5B
0F9B 53 50 20 20
0F9F 20 50 43 20
0FA3 20 20 41 20
0FA7 46 20 20 48
0FAB 20 4C 20 20
0FAF 44 20 45 20
0FB3 20 42 20 43
0FB7 20 20 49 20
0FBB 20 20 49 58
0FBF 20 20 20 49
0FC3 59 20 20 46
0FC7 6C 61 67 73
|
; A100775: a(n) = 97*n + 101.
; 101,198,295,392,489,586,683,780,877,974,1071,1168,1265,1362,1459,1556,1653,1750,1847,1944,2041,2138,2235,2332,2429,2526,2623,2720,2817,2914,3011,3108,3205,3302,3399,3496,3593,3690,3787,3884,3981,4078,4175,4272,4369,4466,4563,4660,4757,4854,4951,5048,5145,5242,5339,5436,5533,5630,5727,5824,5921,6018,6115,6212,6309,6406,6503,6600,6697,6794,6891,6988,7085,7182,7279,7376,7473,7570,7667,7764,7861,7958,8055,8152,8249,8346,8443,8540,8637,8734,8831,8928,9025,9122,9219,9316,9413,9510,9607,9704
mul $0,97
add $0,101
|
/* Copyright 2017 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow_serving/servables/tensorflow/get_model_metadata_impl.h"
#include <memory>
#include <string>
#include <utility>
#include "google/protobuf/wrappers.pb.h"
#include "google/protobuf/map.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/cc/saved_model/loader.h"
#include "tensorflow/cc/saved_model/signature_constants.h"
#include "tensorflow/contrib/session_bundle/bundle_shim.h"
#include "tensorflow/contrib/session_bundle/session_bundle.h"
#include "tensorflow/core/lib/core/error_codes.pb.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/protobuf/meta_graph.pb.h"
#include "tensorflow_serving/apis/model.pb.h"
#include "tensorflow_serving/config/model_server_config.pb.h"
#include "tensorflow_serving/config/platform_config.pb.h"
#include "tensorflow_serving/core/aspired_version_policy.h"
#include "tensorflow_serving/core/availability_preserving_policy.h"
#include "tensorflow_serving/core/servable_handle.h"
#include "tensorflow_serving/model_servers/model_platform_types.h"
#include "tensorflow_serving/model_servers/platform_config_util.h"
#include "tensorflow_serving/servables/tensorflow/saved_model_bundle_source_adapter.pb.h"
#include "tensorflow_serving/servables/tensorflow/session_bundle_config.pb.h"
#include "tensorflow_serving/servables/tensorflow/session_bundle_source_adapter.pb.h"
#include "tensorflow_serving/test_util/test_util.h"
namespace tensorflow {
namespace serving {
namespace {
constexpr char kTestModelName[] = "test_model";
constexpr int kTestModelVersion = 123;
class GetModelMetadataImplTest : public ::testing::TestWithParam<bool> {
public:
static void SetUpTestCase() {
const string session_bundle_path = test_util::TestSrcDirPath(
"/servables/tensorflow/testdata/half_plus_two");
TF_ASSERT_OK(CreateServerCore(session_bundle_path, false, &server_core_));
const string saved_model_path = test_util::TensorflowTestSrcDirPath(
"cc/saved_model/testdata/half_plus_two");
TF_ASSERT_OK(
CreateServerCore(saved_model_path, true, &saved_model_server_core_));
}
static void TearDownTestCase() {
server_core_.reset();
saved_model_server_core_.reset();
}
protected:
static Status CreateServerCore(const string& model_path,
bool saved_model_on_disk,
std::unique_ptr<ServerCore>* server_core) {
ModelServerConfig config;
auto model_config = config.mutable_model_config_list()->add_config();
model_config->set_name(kTestModelName);
model_config->set_base_path(model_path);
model_config->set_model_platform(kTensorFlowModelPlatform);
// For ServerCore Options, we leave servable_state_monitor_creator
// unspecified so the default servable_state_monitor_creator will be used.
ServerCore::Options options;
options.model_server_config = config;
options.platform_config_map =
CreateTensorFlowPlatformConfigMap(SessionBundleConfig(), true);
options.aspired_version_policy =
std::unique_ptr<AspiredVersionPolicy>(new AvailabilityPreservingPolicy);
// Reduce the number of initial load threads to be num_load_threads to avoid
// timing out in tests.
options.num_initial_load_threads = options.num_load_threads;
return ServerCore::Create(std::move(options), server_core);
}
ServerCore* GetServerCore() {
if (GetParam()) {
return saved_model_server_core_.get();
}
return server_core_.get();
}
private:
static std::unique_ptr<ServerCore> server_core_;
static std::unique_ptr<ServerCore> saved_model_server_core_;
};
std::unique_ptr<ServerCore> GetModelMetadataImplTest::server_core_;
std::unique_ptr<ServerCore> GetModelMetadataImplTest::saved_model_server_core_;
SignatureDefMap GetSignatureDefMap(ServerCore* server_core,
const ModelSpec& model_spec) {
SignatureDefMap signature_def_map;
ServableHandle<SavedModelBundle> bundle;
TF_EXPECT_OK(server_core->GetServableHandle(model_spec, &bundle));
for (const auto& signature : bundle->meta_graph_def.signature_def()) {
(*signature_def_map.mutable_signature_def())[signature.first] =
signature.second;
}
return signature_def_map;
}
TEST_P(GetModelMetadataImplTest, EmptyOrInvalidMetadataFieldList) {
GetModelMetadataRequest request;
GetModelMetadataResponse response;
// Empty metadata field list is invalid.
EXPECT_EQ(tensorflow::error::INVALID_ARGUMENT,
GetModelMetadataImpl::GetModelMetadata(GetServerCore(), request,
&response)
.code());
request.add_metadata_field("some_stuff");
// Field enum is outside of valid range.
EXPECT_EQ(tensorflow::error::INVALID_ARGUMENT,
GetModelMetadataImpl::GetModelMetadata(GetServerCore(), request,
&response)
.code());
}
TEST_P(GetModelMetadataImplTest, MissingOrEmptyModelSpec) {
GetModelMetadataRequest request;
GetModelMetadataResponse response;
request.add_metadata_field(GetModelMetadataImpl::kSignatureDef);
EXPECT_EQ(tensorflow::error::INVALID_ARGUMENT,
GetModelMetadataImpl::GetModelMetadata(GetServerCore(), request,
&response)
.code());
ModelSpec* model_spec = request.mutable_model_spec();
model_spec->clear_name();
// Model name is not specified.
EXPECT_EQ(tensorflow::error::INVALID_ARGUMENT,
GetModelMetadataImpl::GetModelMetadata(GetServerCore(), request,
&response)
.code());
// Model name is wrong, not found.
model_spec->set_name("test");
EXPECT_EQ(tensorflow::error::NOT_FOUND,
GetModelMetadataImpl::GetModelMetadata(GetServerCore(), request,
&response)
.code());
}
TEST_P(GetModelMetadataImplTest, ReturnsSignaturesForValidModel) {
GetModelMetadataRequest request;
GetModelMetadataResponse response;
ModelSpec* model_spec = request.mutable_model_spec();
model_spec->set_name(kTestModelName);
model_spec->mutable_version()->set_value(kTestModelVersion);
request.add_metadata_field(GetModelMetadataImpl::kSignatureDef);
TF_EXPECT_OK(GetModelMetadataImpl::GetModelMetadata(GetServerCore(), request,
&response));
EXPECT_THAT(response.model_spec(),
test_util::EqualsProto(request.model_spec()));
EXPECT_EQ(response.metadata_size(), 1);
SignatureDefMap received_signature_def_map;
response.metadata()
.at(GetModelMetadataImpl::kSignatureDef)
.UnpackTo(&received_signature_def_map);
SignatureDefMap expected_signature_def_map =
GetSignatureDefMap(GetServerCore(), request.model_spec());
EXPECT_THAT(response.model_spec(),
test_util::EqualsProto(request.model_spec()));
EXPECT_EQ(expected_signature_def_map.signature_def().size(),
received_signature_def_map.signature_def().size());
if (GetParam()) {
EXPECT_THAT(
expected_signature_def_map.signature_def().at("regress_x_to_y"),
test_util::EqualsProto(
received_signature_def_map.signature_def().at("regress_x_to_y")));
} else {
EXPECT_THAT(expected_signature_def_map.signature_def().at("regress"),
test_util::EqualsProto(
received_signature_def_map.signature_def().at("regress")));
}
EXPECT_THAT(
expected_signature_def_map.signature_def().at(
kDefaultServingSignatureDefKey),
test_util::EqualsProto(received_signature_def_map.signature_def().at(
kDefaultServingSignatureDefKey)));
}
// Verifies that GetModelMetadataWithModelSpec() uses the model spec override
// rather than the one in the request.
TEST_P(GetModelMetadataImplTest, ModelSpecOverride) {
auto request = test_util::CreateProto<GetModelMetadataRequest>(
"model_spec {"
" name: \"test_model\""
"}");
request.add_metadata_field(GetModelMetadataImpl::kSignatureDef);
auto model_spec_override =
test_util::CreateProto<ModelSpec>("name: \"nonexistent_model\"");
GetModelMetadataResponse response;
EXPECT_NE(tensorflow::error::NOT_FOUND,
GetModelMetadataImpl::GetModelMetadata(GetServerCore(), request,
&response)
.code());
EXPECT_EQ(tensorflow::error::NOT_FOUND,
GetModelMetadataImpl::GetModelMetadataWithModelSpec(
GetServerCore(), model_spec_override, request, &response)
.code());
}
// Test all ClassifierTest test cases with both SessionBundle and SavedModel.
INSTANTIATE_TEST_CASE_P(UseSavedModel, GetModelMetadataImplTest,
::testing::Bool());
} // namespace
} // namespace serving
} // namespace tensorflow
|
// Copyright (c) 2014 The Bitcoin Core developers
// Copyright (c) 2014-2015 The Dash developers
// Copyright (c) 2018 The Leduro coin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "primitives/transaction.h"
#include "main.h"
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(main_tests)
CAmount nMoneySupplyPoWEnd = 3000000000 * COIN;
BOOST_AUTO_TEST_CASE(subsidy_limit_test)
{
CAmount nSum = 0;
for (int nHeight = 0; nHeight < 1; nHeight += 1) {
/* premine in block 1 (60,001 LDR) */
CAmount nSubsidy = GetBlockValue(nHeight);
BOOST_CHECK(nSubsidy <= 60001 * COIN);
nSum += nSubsidy;
}
for (int nHeight = 1; nHeight < 86400; nHeight += 1) {
/* PoW Phase One */
CAmount nSubsidy = GetBlockValue(nHeight);
BOOST_CHECK(nSubsidy <= 250 * COIN);
nSum += nSubsidy;
}
for (int nHeight = 86400; nHeight < 151200; nHeight += 1) {
/* PoW Phase Two */
CAmount nSubsidy = GetBlockValue(nHeight);
BOOST_CHECK(nSubsidy <= 225 * COIN);
nSum += nSubsidy;
}
for (int nHeight = 151200; nHeight < 259200; nHeight += 1) {
/* PoW Phase Two */
CAmount nSubsidy = GetBlockValue(nHeight);
BOOST_CHECK(nSubsidy <= 45 * COIN);
BOOST_CHECK(MoneyRange(nSubsidy));
nSum += nSubsidy;
BOOST_CHECK(nSum > 0 && nSum <= nMoneySupplyPoWEnd);
}
BOOST_CHECK(nSum == 4109975100000000ULL);
}
BOOST_AUTO_TEST_SUITE_END()
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include "string.h"
#include <new>
#include <base/math.h>
#include <engine/shared/config.h>
#include "gamecontext.h"
#include <game/gamecore.h>
#include "stats.h"
#include <string.h>
#include <stdio.h>
#include <sys/time.h>
#include "player.h"
#include <stdlib.h>
#include <string.h>
//#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
tstats::tstats (CGameContext *game_srv, const char *stats_dir)
{
game_server = game_srv;
stat_dir = stats_dir;
m_pServer = game_srv->Server();
memset(round_stats, 0, sizeof(round_stats));
memset(round_names, 0, sizeof(round_names));
memset(current, 0, sizeof(current));
num_totals = 0;
round_index = 0;
ertimer = 0;
struct dirent *ds;
DIR *dp;
if ((dp = opendir(stats_dir))) {
while ((ds = readdir(dp)))
++num_totals;
closedir(dp);
} else {
printf("error reading stats\n");
}
last_reqd = (int)time(NULL);
last_reqds = (int)time(NULL);
max_totals = num_totals + 256;
num_totals = 0;
total_stats = (struct tee_stats *)calloc(max_totals, sizeof(struct tee_stats));
total_names = (char **)calloc(max_totals, sizeof(char *));
for (int i = 0; i < 512; i++)
round_names[i] = (char *)calloc(sizeof(char), 64);
if ((dp = opendir(stats_dir))) {
while ((ds = readdir(dp)))
if (*ds->d_name != '.') {
total_stats[num_totals] = read_statsfile(ds->d_name, 0);
total_names[num_totals] = strdup(ds->d_name);
num_totals++;
}
closedir(dp);
}
printf("**** initialized stats object with %d total\n", num_totals);
}
tstats::~tstats()
{
for (int i = 0; i < num_totals; i++)
free(total_names[i]);
free(total_names);
free(total_stats);
for (int i = 0; i < 512; i++)
free(round_names[i]);
printf("**** freed stats object with %d total\n", num_totals);
}
void tstats::on_enter (int ClientID, const char *name)
{
struct tee_stats ts;
memset(&ts, 0, sizeof(ts));
ts.id = ClientID;
ts.join_time = time(NULL);
add_round_entry(ts, name);
}
void tstats::SendChat(int ChatterClientID, int Team, const char *pText)
{
game_server->SendChat(ChatterClientID, Team, pText);
}
void tstats::SendChatTarget(int To, const char *pText)
{
game_server->SendChatTarget(To, pText);
}
void tstats::on_namechange (int ClientID, const char *name)
{
for (int i = 0; i < 512; i++) {
if (round_stats[i].id == ClientID) {
printf("client id %d found at %d name %s\n", ClientID, i,
round_names[i]);
strncpy(round_names[i], name, 64);
break;
}
}
}
void tstats::on_drop (int ClientID, const char *pReason)
{
struct tee_stats *t;
if ((t = current[ClientID])) {
t->spree = 0; /* thanks SP | Someone :D */
t->num_games++;
t->id = -1;
current[ClientID] = NULL;
}
if (t && pReason && *pReason) {
char entry[256] = { 0 };
char aIP[16] = { 0 };
int fd, len;
Server()->GetClientAddr(ClientID, aIP, sizeof(aIP));
snprintf(entry, sizeof(entry), "%s left (%s) %s\n", ID_NAME(ClientID),
pReason, aIP);
len = (int)strlen(entry);
printf("%s", entry);
if ((fd = open("leaving.txt", O_RDWR|O_CREAT|O_APPEND, 0777)) < 0)
perror("open");
else
if (write(fd, entry, len) != len)
perror("write");
close(fd);
}
}
double tstats::print_best_group (char *dst, struct tee_stats *stats, char **names,
int num, double (*callback)(struct tee_stats, char *), double max)
{
int i, len;
double kd = 0, best = 0;
char tmp_buf[256] = { 0 };
char call_buf[128] = { 0 };
for (i = 0; i < num; i++) {
if (!names[i][0])
continue;
kd = callback(stats[i], call_buf);
if ((kd > best) && (kd < max))
best = kd;
}
for (i = 0; i < num; i++) {
if (!names[i][0])
continue;
memset(call_buf, 0, sizeof(call_buf));
kd = callback(stats[i], call_buf);
if (kd == best) {
len = strlen(call_buf) + strlen(tmp_buf) + strlen(names[i]) + 5;
if (len >= sizeof(tmp_buf))
break;
strcat(tmp_buf, names[i]);
if (strlen(call_buf)) {
strcat(tmp_buf, " (");
strcat(tmp_buf, call_buf);
strcat(tmp_buf, ")");
}
strcat(tmp_buf, ", ");
}
}
tmp_buf[strlen(tmp_buf) - 2] = 0;
if (callback == get_kd || callback == get_kd_all)
sprintf(dst, "%.02f (%s)", best, ((best != 0) ? tmp_buf : "None"));
else if (callback == get_accuracy || callback == get_accuracy_all)
sprintf(dst, "%.02f%% (%s)", best, ((best != 0) ? tmp_buf : "None"));
else if (callback == get_neg_steals)
sprintf(dst, "%d (%s)", (int)(-best), ((best != 0) ? tmp_buf : "None"));
else
sprintf(dst, "%d (%s)", (int)best, ((best != 0) ? tmp_buf : "None"));
return best;
}
#define PLACEHOLDER 9999999999
void tstats::print_best (const char *msg, int max,
double (*callback)(struct tee_stats, char *), int all)
{
double tmp, best = PLACEHOLDER;
char buf[256];
char buf1[256] = { 0 };
while (max--) {
memset(buf, 0, sizeof(buf));
if (all)
tmp = print_best_group(buf, total_stats, total_names,
num_totals, callback, best);
else
tmp = print_best_group(buf, round_stats, round_names,
round_index, callback, best);
if ((tmp >= best) || (best < PLACEHOLDER && tmp == 0))
break;
if (msg) {
snprintf(buf1, sizeof(buf1), "- %s %s, ", msg, buf);
msg = NULL;
} else {
if ((strlen(buf) + strlen(buf1)) > 50) {
SendChat(-1, CGameContext::CHAT_ALL, buf1);
memset(buf1, 0, sizeof(buf1));
strcat(buf1, " - ");
}
strcat(buf1, buf);
strcat(buf1, ", ");
}
best = tmp;
if (best == 0)
break;
}
if (strlen(buf1) > 3)
buf1[strlen(buf1) - 2] = 0;
SendChat(-1, CGameContext::CHAT_ALL, buf1);
}
void tstats::send_stats (const char *name, int req_by, struct tee_stats *ct, int is_all)
{
char buf[256];
int c, d, e;
str_format(buf, sizeof(buf), "%s stats for '%s' (req. by '%s') client version: %d",
is_all ? "total" : "round", name, Server()->ClientName(req_by), ct->version);
SendChat(-1, CGameContext::CHAT_ALL, buf);
d = ct->deaths ? ct->deaths : 1;
c = ct->kills + ct->kills_x2 + ct->kills_wrong;
e = ct->shots ? ct->shots : 1;
str_format(buf, sizeof(buf), "- k/d: %d/%d = %.03f | accuracy: %.03f%%", c,
ct->deaths, (float)c / (float)d, 100 * ((float)ct->freezes / (float)e));
SendChat(-1, CGameContext::CHAT_ALL, buf);
str_format(buf, sizeof(buf), "- net steals: %d - %d = %d", ct->steals,
ct->stolen_from, ct->steals - ct->stolen_from);
SendChat(-1, CGameContext::CHAT_ALL, buf);
str_format(buf, sizeof(buf), "- avg ping: %d | shots: %d | wallshots: %d",
ct->avg_ping, ct->shots, ct->bounce_shots);
SendChat(-1, CGameContext::CHAT_ALL, buf);
str_format(buf, sizeof(buf), "- freezes: %d/%d | hammers: %d/%d | suicides: %d",
ct->freezes, ct->frozen, ct->hammers, ct->hammered, ct->suicides);
SendChat(-1, CGameContext::CHAT_ALL, buf);
if (!is_all) {
time_t diff = (time(NULL) - ct->join_time);
str_format(buf, sizeof(buf),
"- time: %d:%.02d | max spree: %d | max multi: %d:",
diff / 60, diff % 60, ct->spree_max, ct->max_multi);
SendChat(-1, CGameContext::CHAT_ALL, buf);
} else {
str_format(buf, sizeof(buf),
"- wrong-shrine kills: %d | max spree: %d | max multi: %d:",
ct->kills_wrong, ct->spree_max, ct->max_multi);
SendChat(-1, CGameContext::CHAT_ALL, buf);
struct stat attrib;
char date[64], path[64];
snprintf(path, sizeof(path), "%s/%s", STATS_DIR, name);
if (stat(path, &attrib)) {
printf("error stat %s\n", path);
strncpy(date, "---", sizeof(date));
} else {
strftime(date, sizeof(date), "%F %r",
localtime(&(attrib.st_mtime)));
}
str_format(buf, sizeof(buf), "- last seen: %s", date);
SendChat(-1, CGameContext::CHAT_ALL, buf);
}
/* ranks! */
if (ct->multis[0]) {
str_format(buf, sizeof(buf), "- ** double kills: %d", ct->multis[0]);
SendChat(-1, CGameContext::CHAT_ALL, buf);
} if (ct->multis[1]) {
str_format(buf, sizeof(buf), "- ** triple kills: %d", ct->multis[1]);
SendChat(-1, CGameContext::CHAT_ALL, buf);
} if (ct->multis[2]) {
str_format(buf, sizeof(buf), "- ** quad kills: %d", ct->multis[2]);
SendChat(-1, CGameContext::CHAT_ALL, buf);
} if (ct->multis[3]) {
str_format(buf, sizeof(buf), "- ** penta kills: %d", ct->multis[3]);
SendChat(-1, CGameContext::CHAT_ALL, buf);
} if (ct->multis[4]) {
str_format(buf, sizeof(buf), "- ** ultra kills: %d", ct->multis[4]);
SendChat(-1, CGameContext::CHAT_ALL, buf);
} if (ct->multis[5]) {
str_format(buf, sizeof(buf), "- ** god kills: %d", ct->multis[5]);
SendChat(-1, CGameContext::CHAT_ALL, buf);
}
}
struct tee_stats tstats::read_statsfile (const char *name, time_t create)
{
char path[128];
int src_fd;
struct tee_stats ret;
memset(&ret, 0, sizeof(ret));
snprintf(path, sizeof(path), "%s/%s", stat_dir, name);
if ((src_fd = open(path, O_RDWR, 0777)) < 0) {
if (create) {
fprintf(stderr, "creating file %d / %d totals\n", num_totals, max_totals);
if ((src_fd = open(path, O_WRONLY|O_CREAT, 0777)) < 0) {
fprintf(stderr, "error creating file %s\n", path);
return ret;
}
ret.join_time = 0;//create;
write(src_fd, &ret, sizeof(ret));
total_stats[num_totals].join_time = 0;//create;
total_names[num_totals] = strdup(name);
if (++num_totals >= max_totals - 5) {
max_totals += 256;
total_stats = (struct tee_stats *)realloc(total_stats,
max_totals * sizeof(struct tee_stats));
total_names = (char **)realloc(total_names,
max_totals * sizeof(char *));
}
}
} else {
read(src_fd, &ret, sizeof(ret));
}
close(src_fd);
//ret.join_time = 0;
return ret;
}
double tstats::get_ping (struct tee_stats fstats, char *buf)
{
return (double)fstats.avg_ping;
}
double tstats::get_wrong (struct tee_stats fstats, char *buf)
{
return (double)fstats.kills_wrong;
}
double tstats::get_max_multi (struct tee_stats fstats, char *buf)
{
return (double)fstats.max_multi;
}
double tstats::get_max_spree (struct tee_stats fstats, char *buf)
{
return (double)fstats.spree_max;
}
double tstats::get_steals (struct tee_stats fstats, char *buf)
{
/*int k = fstats.kills + fstats.kills_x2 + fstats.kills_wrong;
if (k && buf)
sprintf(buf, "%.02f%%",
((double)fstats.steals / (double)k) * 100);
*/
return (double)(fstats.steals - fstats.stolen_from);
}
double tstats::get_neg_steals (struct tee_stats fstats, char *buf)
{
return (double)(fstats.stolen_from - fstats.steals);
}
double tstats::get_kd (struct tee_stats fstats, char *buf)
{
int k = fstats.kills + fstats.kills_x2 + fstats.kills_wrong;
int d = fstats.deaths ? fstats.deaths : 1;
return (double)k / (double)d;
}
double tstats::get_kd_all (struct tee_stats fstats, char *buf)
{
int k = fstats.kills + fstats.kills_x2 + fstats.kills_wrong;
if (k < 1000)
return 0.0f;
int d = fstats.deaths ? fstats.deaths : 1;
return (double)k / (double)d;
}
double tstats::get_kills (struct tee_stats fstats, char *buf)
{
return (double)(fstats.kills + fstats.kills_x2 + fstats.kills_wrong);
}
double tstats::get_accuracy (struct tee_stats fstats, char *buf)
{
if (fstats.shots < 10)
return 0.0f;
if (buf)
sprintf(buf, "%d ping", fstats.avg_ping);
int d = fstats.shots ? fstats.shots : 1;
return 100 * (double)fstats.freezes / (double)d;
}
double tstats::get_accuracy_all (struct tee_stats fstats, char *buf)
{
if (fstats.shots < 2000)
return 0.0f;
if (buf)
sprintf(buf, "%d ping", fstats.avg_ping);
int d = fstats.shots ? fstats.shots : 1;
return 100 * (double)fstats.freezes / (double)d;
}
double tstats::get_bounces (struct tee_stats fstats, char *buf)
{
return (double)fstats.bounce_shots;
}
double tstats::get_hammers (struct tee_stats fstats, char *buf)
{
return (double)fstats.hammers;
}
double tstats::get_suicides (struct tee_stats fstats, char *buf)
{
return (double)fstats.suicides;
}
void tstats::update_stats (struct tee_stats *dst, struct tee_stats *src)
{
if (!dst || !src) {
printf("[%s]: dst = %p, src = %p\n", __func__, dst, src);
return;
}
if (!dst->join_time)
dst->join_time = time(NULL);
if (src->spree_max > dst->spree_max)
dst->spree_max = src->spree_max;
if (src->max_multi > dst->max_multi)
dst->max_multi = src->max_multi;
for (int i = 0; i < 6; i++)
dst->multis[i] += src->multis[i];
printf("[%s]: kills = %d += %d\n", __func__, dst->kills, src->kills);
dst->version = src->version;
dst->id = src->id;
dst->kills += src->kills;
dst->kills_x2 += src->kills_x2;
dst->kills_wrong += src->kills_wrong;
dst->deaths += src->deaths;
dst->steals += src->steals;
dst->suicides += src->suicides;
dst->shots += src->shots;
dst->freezes += src->freezes;
dst->frozen += src->frozen;
dst->hammers += src->hammers;
dst->hammered += src->hammered;
dst->bounce_shots += src->bounce_shots;
dst->stolen_from += src->stolen_from;
if (src->is_bot)
dst->is_bot += 1;
dst->join_time += (time(NULL) - src->join_time);
dst->avg_ping = src->avg_ping;
//(unsigned short)ADD_AVG(src->avg_ping,
// dst->avg_ping,
/// dst->num_samples);
//(unsigned short)((float)(src->avg_ping +
// (float)(dst->num_samples *
// dst->avg_ping)) /
// (++dst->num_samples));
}
void tstats::merge_into (const char *src, const char *dst)
{
struct tee_stats *srcs, *dsts;
char pb[128];
int src_fd;
printf("merge %s -> %s\n", src, dst);
if (!(srcs = find_total_entry(src)) || !(dsts = find_total_entry(dst))) {
printf("couldnt retrieve stats\n");
return;
}
snprintf(pb, sizeof(pb), "merge %s (%d shots) into %s (%d shots)",
src, srcs->shots, dst, dsts->shots);
SendChat(-1, CGameContext::CHAT_ALL, pb);
update_stats(dsts, srcs);
snprintf(pb, sizeof(pb), "%s/%s", stat_dir, dst);
if ((src_fd = open(pb, O_RDWR, 0777)) < 0) {
fprintf(stderr, "creating file\n");
if ((src_fd = open(pb, O_WRONLY|O_CREAT, 0777)) < 0) {
fprintf(stderr, "error creating %s\n", pb);
return;
}
}
if (write(src_fd, dsts, sizeof(struct tee_stats)) != sizeof(struct tee_stats))
printf("write failed\n");
close(src_fd);
memset(srcs, 0, sizeof(struct tee_stats));
snprintf(pb, sizeof(pb), "%s/%s", stat_dir, src);
remove(pb);
snprintf(pb, sizeof(pb), "merged %s (%d shots) into %s (%d shots)",
src, srcs->shots, dst, dsts->shots);
SendChat(-1, CGameContext::CHAT_ALL, pb);
}
void tstats::on_round_end (void)
{
int i, j, src_fd, len;
struct tee_stats totals;
char path[128];
print_best("most net steals:", 2, &get_steals, 0);
print_best("best spree:", 1, &get_max_spree, 0);
print_best("best multi:", 1, &get_max_multi, 0);
print_best("best k/d:", 2, &get_kd, 0);
print_best("most wallshots:", 2, &get_bounces, 0);
print_best("most kills:", 3, &get_kills, 0);
print_best("best accuracy:", 4, &get_accuracy, 0);
for (i = 0; i < round_index; i++) {
if (!round_names[i][0]) {
printf("[%s]: no entry found at %d\n", __func__, i);
continue;
}
len = (int)strlen(round_names[i]);
for (j = 0; j < num_totals; j++) {
if ((strlen(total_names[j]) == len) &&
!memcmp(round_names[i], total_names[j], len))
break;
}
printf("search for %s found at %d (%s)\n", round_names[i],
j, total_names[j]);
if (j == num_totals)
total_stats[j] = read_statsfile(round_names[i], time(NULL));
update_stats(&total_stats[j], &round_stats[i]);
snprintf(path, sizeof(path), "%s/%s", stat_dir, round_names[i]);
if ((src_fd = open(path, O_RDWR, 0777)) < 0) {
fprintf(stderr, "creating file\n");
if ((src_fd = open(path, O_WRONLY|O_CREAT, 0777)) < 0) {
fprintf(stderr, "error creating %s\n", path);
perror("a");
continue;
}
}
write(src_fd, &total_stats[j], sizeof(struct tee_stats));
close(src_fd);
}
memset(round_stats, 0, sizeof(round_stats));
for (i = 0; i < 512; i++)
memset(round_names[i], 0, 64);
round_index = 0;
printf("round ended !\n");
for (i = 0; i < MAX_CLIENTS; i++) {
int version, id;
if (!game_server->m_apPlayers[i])
continue;
id = game_server->m_apPlayers[i]->GetCID();
memset(&totals, 0, sizeof(totals));
totals = read_statsfile(ID_NAME(id), 0);
version = totals.version;
memset(&totals, 0, sizeof(totals));
totals.join_time = time(NULL);
totals.id = id;
totals.version = version;
add_round_entry(totals, ID_NAME(id));
printf("re-added player %d %s v %d\n", id, ID_NAME(id), version);
}
}
struct tee_stats *tstats::find_round_entry (const char *name)
{
int i, len = (int)strlen(name);
for (i = 0; i < 512; i++)
if (strlen(round_names[i]) == len && !memcmp(name, round_names[i], len))
return &round_stats[i];
return NULL;
}
struct tee_stats *tstats::find_total_entry (const char *name)
{
int j, len = (int)strlen(name);
for (j = 0; j < num_totals; j++) {
if (strlen(total_names[j]) == len && !memcmp(name, total_names[j], len)) {
printf("search %s found at %d (%s)\n", name, j, total_names[j]);
return &total_stats[j];
}
}
printf("[%s]: player %s not found\n", __func__, name);
return NULL;
}
struct tee_stats *tstats::add_round_entry (struct tee_stats st, const char *name)
{
int i;
for (i = 0; i < 512; i++)
if (!strncmp(name, round_names[i], strlen(name)))
break;
if (i == 512)
i = round_index++;
if (i >= 512) {
printf("exceeded max round player entries!\n");
return NULL;
}
printf("adding round entry for %s (%d) id %d\n", name, i, st.id);
strcpy(round_names[i], name);
update_stats(&round_stats[i], &st);
current[st.id] = &round_stats[i];
return &round_stats[i];
}
#define ID_ENTRY(i) (game_server->m_pController->t_stats->current[i])
void tstats::do_kill_messages (struct tee_stats *s_killer, struct tee_stats *s_victim)
{
if (!s_killer || !s_victim)
return;
const char *kname = Server()->ClientName(s_killer->id);
int Victim = s_victim->id;
s_victim->deaths++;
if (s_victim->frozeby != s_killer->id && s_victim->frozeby >= 0) {
struct tee_stats *s_owner = ID_ENTRY(s_victim->frozeby);
if (s_owner) {
s_killer->steals++;
s_owner->stolen_from++;
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "'%s' stole '%s' kill!",
kname, Server()->ClientName(s_victim->frozeby));
game_server->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
} else {
printf("no owner found with id %d\n", s_victim->frozeby);
}
}
/* handle spree */
if (((++s_killer->spree) % 5) == 0) {
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "'%s' is on a spree of %d kills!",
kname, s_killer->spree);
game_server->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
}
if (s_victim->spree >= 5) {
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "'%s' spree of %d kills ended by '%s'!",
Server()->ClientName(Victim), s_victim->spree, kname);
game_server->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
}
if (s_killer->spree > s_killer->spree_max)
s_killer->spree_max = s_killer->spree;
s_victim->spree = 0;
/* handle multis */
time_t ttmp = time(NULL);
if ((ttmp - s_killer->lastkilltime) <= 5) {
s_killer->multi++;
if (s_killer->max_multi < s_killer->multi)
s_killer->max_multi = s_killer->multi;
int index = s_killer->multi - 2;
s_killer->multis[index > 5 ? 5 : index]++;
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "'%s' multi x%d!",
kname, s_killer->multi);
game_server->SendChat(-1, CGameContext::CHAT_ALL, aBuf);
} else {
s_killer->multi = 1;
}
s_killer->lastkilltime = ttmp;
s_victim->frozeby = -1;
}
void tstats::top_special (const char *message, int ClientID)
{
if (strncmp(message, "/topping", 8) == 0) {
print_best("highest ping:", 12, &get_ping, (message[8] == 'a'));
} else if (strncmp(message, "/topwrong", 9) == 0) {
print_best("most wrong-shrine kills:", 12, &get_wrong, (message[9] == 'a'));
} else if (strncmp(message, "/topkills", 9) == 0) {
print_best("most kills:", 12, &get_kills, (message[9] == 'a'));
} else if (strncmp(message, "/topsteals", 10) == 0) {
print_best("most net steals:", 12, &get_steals, (message[10] == 'a'));
} else if (strncmp(message, "/fewsteals", 10) == 0) {
print_best("fewest net steals:", 12, &get_neg_steals, (message[10] == 'a'));
} else if (strncmp(message, "/topwalls", 9) == 0) {
print_best("most wallshots:", 12, &get_bounces, (message[9] == 'a'));
} else if (strncmp(message, "/topkd", 6) == 0) {
if (message[6] == 'a')
print_best("best kd (>1000 kills):", 20, &get_kd_all, 1);
else
print_best("best kd:", 12, &get_kd, 0);
} else if (strncmp(message, "/topaccuracy", 12) == 0) {
if (message[12] == 'a')
print_best("best accuracy (>2000 shots):", 20, &get_accuracy_all, 1);
else
print_best("best accuracy:", 12, &get_accuracy, 0);
} else if (strncmp(message, "/tophammers", 11) == 0) {
print_best("most hammers:", 11, &get_hammers,
(message[11] == 'a'));
} else if (strncmp(message, "/topsuicides", 12) == 0) {
print_best("most suicides:", 12, &get_suicides,
(message[12] == 'a'));
} else if (strncmp(message, "/topall", 7) == 0) {
char mg[128] = { 0 };
snprintf(mg, sizeof(mg), "all-time stats req by %s",
ID_NAME(ClientID));
SendChat(-1, CGameContext::CHAT_ALL, mg);
print_best("most steals:", 4, &get_steals, 1);
print_best("most wallshots:", 4, &get_bounces, 1);
print_best("best multi:", 2, &get_max_multi, 1);
print_best("best spree:", 4, &get_max_spree, 1);
print_best("most hammers:", 4, &get_hammers, 1);
print_best("most kills:", 4, &get_kills, 1);
} else {
print_best("most net steals:", 2, &get_steals, 0);
print_best("best spree:", 1, &get_max_spree, 0);
print_best("best multi:", 1, &get_max_multi, 0);
print_best("best k/d:", 2, &get_kd, 0);
print_best("most wallshots:", 2, &get_bounces, 0);
print_best("most kills:", 3, &get_kills, 0);
print_best("best accuracy:", 4, &get_accuracy, 0);
}
last_reqd = (int)time(NULL);
}
void tstats::on_msg (const char *message, int ClientID)
{
printf("[cmd msg] %s: %s\n", ID_NAME(ClientID), message);
if (strncmp(message, "/statsall", 9) == 0) {
int tl = (int)time(NULL) - last_reqds;
if (tl < 5) {
char buf[64] = { 0 };
snprintf(buf, sizeof(buf), "please wait %d seconds", 5 - tl);
SendChatTarget(ClientID, buf);
} else {
struct tee_stats tmp;
if (strlen(message) > 10) {
char namebuf[64] = { 0 };
strcpy(namebuf, message + 10);
char *ptr = namebuf + strlen(namebuf) - 1;
if (*ptr == ' ')
*ptr = 0;
tmp = read_statsfile(namebuf, 0);
if (!tmp.shots) {
SendChatTarget(ClientID, "invalid player");
printf("invalid player %s\n", namebuf);
} else {
send_stats(namebuf, ClientID, &tmp, 1);
}
} else {
tmp = read_statsfile(ID_NAME(ClientID), 0);
send_stats(ID_NAME(ClientID), ClientID, &tmp, 1);
}
last_reqds = (int)time(NULL);
}
} else if (strncmp(message, "/stats", 6) == 0) {
int tl = (int)time(NULL) - last_reqds;
if (tl < 5) {
char buf[64] = { 0 };
snprintf(buf, sizeof(buf), "please wait %d seconds", 5 - tl);
SendChatTarget(ClientID, buf);
} else {
struct tee_stats *tmp;
if (strlen(message) > 7) {
char namebuf[64] = { 0 };
strcpy(namebuf, message + 7);
char *ptr = namebuf + strlen(namebuf) - 1;
if (*ptr == ' ')
*ptr = 0;
if (!(tmp = find_round_entry(namebuf))) {
SendChatTarget(ClientID, "invalid player");
printf("invalid player %s\n", namebuf);
} else {
send_stats(namebuf, ClientID, tmp, 0);
}
} else {
if ((tmp = current[ClientID]))
send_stats(ID_NAME(ClientID), ClientID, tmp, 0);
}
last_reqds = (int)time(NULL);
}
} else if (strncmp(message, "/top", 3) == 0 || strncmp(message, "/few", 3) == 0) {
int tl = (int)time(NULL) - last_reqd;
if (tl < 10) {
char buf[64] = { 0 };
snprintf(buf, sizeof(buf), "please wait %d seconds", 10 - tl);
SendChatTarget(ClientID, buf);
} else {
top_special(message, ClientID);
}
} else if (strncmp(message, "/earrape", 8) == 0 &&
game_server->m_apPlayers[ClientID] &&
game_server->m_apPlayers[ClientID]->GetCharacter()) {
if ((time(NULL) - ertimer) < (60 * 100)) {
SendChatTarget(ClientID, "spammer");
} else {
for (int c = 0; c < 30; c++)
game_server->CreateSound(game_server->m_apPlayers
[ClientID]->GetCharacter()->m_Pos, SOUND_MENU);
ertimer = time(NULL);
}
} else if (strncmp(message, "/crash", 6) == 0 &&
game_server->m_apPlayers[ClientID] &&
game_server->m_apPlayers[ClientID]->GetCharacter()) {
game_server->m_apPlayers[ClientID]->GetCharacter()->force_weapon();
} else if (strncmp(message, "/dump", 5) == 0) {
int i, tl = (int)time(NULL) - last_reqd;
if (tl > 5) {
char abuf[128];
for (i = 0; i < MAX_CLIENTS; i++) {
memset(abuf, 0, sizeof(abuf));
CPlayer *pt = game_server->m_apPlayers[i];
if (!pt)
continue;
int tbn = pt->tb_num;
if (tbn == 0)
continue;
float perc1 = ((float)pt->tb_under10 / (float)tbn);
float perc = ((float)pt->tb_under100k / (float)tbn);
char name1[5] = { ' ' };
snprintf(name1, 5, "%5s", ID_NAME(pt->GetCID()));
int pd400 = (int)(((float)pt->d400 / (float)pt->tb_num) * 100);
snprintf(abuf, sizeof(abuf),
"* %s %4d %4d %2d%% %2d%% %2d%% %d %d %3d %3d %3d %3d",
name1, tbn, pt->tb_noammo, (int)(perc1 * 100),
(int)(perc * 100), pd400, pt->max50, pt->max300, pt->r5max,
pt->r7min / 1000, pt->r10min / 1000, pt->maxrl);
SendChat(-1, CGameContext::CHAT_ALL, abuf);
}
last_reqd = (int)time(NULL);
}
}
}
|
; void *heap_destroy(void *heap)
SECTION code_alloc_malloc
PUBLIC heap_destroy
defc heap_destroy = asm_heap_destroy
INCLUDE "alloc/malloc/z80/asm_heap_destroy.asm"
|
; A154926: Signed version of Pascal's triangle. Diagonal positive, rest negative.
; Submitted by Christian Krause
; 1,-1,1,-1,-2,1,-1,-3,-3,1,-1,-4,-6,-4,1,-1,-5,-10,-10,-5,1,-1,-6,-15,-20,-15,-6,1,-1,-7,-21,-35,-35,-21,-7,1,-1,-8,-28,-56,-70,-56,-28,-8,1
lpb $0
add $1,1
sub $0,$1
mov $2,$1
sub $2,$0
min $2,1
lpe
bin $1,$0
add $2,1
div $2,-2
mul $2,$1
mul $2,2
add $2,$1
mov $0,$2
|
%ifdef CONFIG
{
"RegData": {
"MM6": ["0x8A51407DA8345C92", "0x3FFE"],
"MM7": ["0xD76AA47848677021", "0x3FFE"]
},
"Mode": "32BIT"
}
%endif
lea edx, [data]
fld tword [edx + 8 * 0]
fsincos
hlt
align 8
data:
dt 1.0
dq 0
|
Route17Mons:
db $19
db 20,SPEAROW
db 22,SPEAROW
db 25,RATICATE
db 24,DODUO
db 27,RATICATE
db 26,DODUO
db 28,DODUO
db 29,RATICATE
db 25,FEAROW
db 27,FEAROW
db $00
|
[sonic2013_v48]
moduleMatches = 0xC5691A40
; load Linksonic on top of Sonic
0x02A60414 = nop
0x02A53680 = nop
; load ef_dl3_linksonic_speedrun instead of ef_ch_son_yh1_speedrun_loop
0x02A43FE0 = nop
0x02A44058 = nop
; load chr_Linksonic shadow model instead of chr_Sonic shadow model
0x02A607F8 = nop
|
/*
* Copyright (c) 2019, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cudf/cudf.h>
#include <jit/type.h>
#include <nvstrings/NVCategory.h>
#include <utilities/cudf_utils.h>
#include <bitmask/legacy/bitmask_ops.hpp>
#include <bitmask/legacy/legacy_bitmask.hpp>
#include <cudf/copying.hpp>
#include <cudf/utilities/legacy/nvcategory_util.hpp>
#include <utilities/error_utils.hpp>
#include <utilities/column_utils.hpp>
#include <cudf/legacy/column.hpp>
#include <jit/launcher.h>
#include <jit/type.h>
#include <jit/parser.h>
#include "jit/code/code.h"
#include <types.h.jit>
namespace cudf {
namespace transformation {
/**---------------------------------------------------------------------------*
* @brief Computes output valid mask for op between a column and a scalar
*
* @param out_null_coun[out] number of nulls in output
* @param valid_out preallocated output mask
* @param valid_col input mask of column
* @param num_values number of values in input mask valid_col
*---------------------------------------------------------------------------**/
namespace jit {
void unary_operation(gdf_column& output, const gdf_column& input,
const std::string& udf, gdf_dtype output_type, bool is_ptx) {
std::string hash = "prog_tranform."
+ std::to_string(std::hash<std::string>{}(udf));
std::string cuda_source;
if(is_ptx){
cuda_source =
cudf::jit::parse_single_function_ptx(
udf, "GENERIC_UNARY_OP",
cudf::jit::getTypeName(output_type), {0}
) + code::kernel;
}else{
cuda_source =
cudf::jit::parse_single_function_cuda(
udf, "GENERIC_UNARY_OP") + code::kernel;
}
// Launch the jitify kernel
cudf::jit::launcher(
hash, cuda_source,
{ cudf_types_h },
{ "-std=c++14" }, nullptr
).set_kernel_inst(
"kernel", // name of the kernel we are launching
{ cudf::jit::getTypeName(output.dtype), // list of template arguments
cudf::jit::getTypeName(input.dtype) }
).launch(
output.size,
output.data,
input.data
);
}
} // namespace jit
} // namespace transformation
gdf_column transform(const gdf_column& input,
const std::string& unary_udf,
gdf_dtype output_type, bool is_ptx) {
// First create a gdf_column and then call the above function
gdf_column output = allocate_column(output_type, input.size, input.valid != nullptr);
output.null_count = input.null_count;
// Check for 0 sized data
if (input.size == 0){
return output;
}
// Check for null data pointer
CUDF_EXPECTS((input.data != nullptr), "Input column data pointers are null");
// Check for datatype
CUDF_EXPECTS( input.dtype != GDF_STRING && input.dtype != GDF_CATEGORY,
"Invalid/Unsupported input datatype" );
if (input.valid != nullptr) {
gdf_size_type num_bitmask_elements = gdf_num_bitmask_elements(input.size);
CUDA_TRY(cudaMemcpy(output.valid, input.valid, num_bitmask_elements, cudaMemcpyDeviceToDevice));
}
transformation::jit::unary_operation(output, input, unary_udf, output_type, is_ptx);
return output;
}
} // namespace cudf
|
// Copyright 2020 DeepMind Technologies Limited
//
// 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
//
// https://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 "dm_robotics/mujoco/utils.h"
#include <algorithm>
#include <array>
#include <limits>
#include <string>
#include <utility>
#include "dm_robotics/support/logging.h"
#include "absl/container/btree_set.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/substitute.h"
#include "absl/types/optional.h"
#include "absl/types/span.h"
#include "dm_robotics/mujoco/mjlib.h"
#include "dm_robotics/mujoco/types.h"
#include "Eigen/Core"
namespace dm_robotics {
namespace {
// Internally, it is more efficient to use geom IDs instead of the string-based
// GeomGroups/CollisionPairs. The integers in GeomIdGroup are always guaranteed
// to be positive.
using GeomIdGroup = absl::btree_set<int>;
using CollisionIdPair = std::pair<GeomIdGroup, GeomIdGroup>;
// Helper function for re-creating MuJoCo's max contact array. This array maps
// pairs of geom types to the maximum number of contacts that can be detected by
// MuJoCo's collision mechanism between both geoms.
//
// Note that only the upper-right triangle is initialized.
// The returned values are guaranteed to be positive integers or 0.
constexpr std::array<std::array<int, mjNGEOMTYPES>, mjNGEOMTYPES>
GetMujocoMaxContactsArray() {
std::array<std::array<int, mjNGEOMTYPES>, mjNGEOMTYPES> max_contacts{};
// Plane
max_contacts[mjGEOM_PLANE][mjGEOM_PLANE] = 0;
max_contacts[mjGEOM_PLANE][mjGEOM_HFIELD] = 0;
max_contacts[mjGEOM_PLANE][mjGEOM_SPHERE] = 1;
max_contacts[mjGEOM_PLANE][mjGEOM_CAPSULE] = 2;
max_contacts[mjGEOM_PLANE][mjGEOM_ELLIPSOID] = 1;
max_contacts[mjGEOM_PLANE][mjGEOM_CYLINDER] = 3;
max_contacts[mjGEOM_PLANE][mjGEOM_BOX] = 4;
max_contacts[mjGEOM_PLANE][mjGEOM_MESH] = 3;
// HField
max_contacts[mjGEOM_HFIELD][mjGEOM_HFIELD] = 0;
max_contacts[mjGEOM_HFIELD][mjGEOM_SPHERE] = mjMAXCONPAIR;
max_contacts[mjGEOM_HFIELD][mjGEOM_CAPSULE] = mjMAXCONPAIR;
max_contacts[mjGEOM_HFIELD][mjGEOM_ELLIPSOID] = mjMAXCONPAIR;
max_contacts[mjGEOM_HFIELD][mjGEOM_CYLINDER] = mjMAXCONPAIR;
max_contacts[mjGEOM_HFIELD][mjGEOM_BOX] = mjMAXCONPAIR;
max_contacts[mjGEOM_HFIELD][mjGEOM_MESH] = mjMAXCONPAIR;
// Sphere
max_contacts[mjGEOM_SPHERE][mjGEOM_SPHERE] = 1;
max_contacts[mjGEOM_SPHERE][mjGEOM_CAPSULE] = 1;
max_contacts[mjGEOM_SPHERE][mjGEOM_ELLIPSOID] = 1;
max_contacts[mjGEOM_SPHERE][mjGEOM_CYLINDER] = 1;
max_contacts[mjGEOM_SPHERE][mjGEOM_BOX] = 1;
max_contacts[mjGEOM_SPHERE][mjGEOM_MESH] = 1;
// Capsule
max_contacts[mjGEOM_CAPSULE][mjGEOM_CAPSULE] = 2;
max_contacts[mjGEOM_CAPSULE][mjGEOM_ELLIPSOID] = 1;
max_contacts[mjGEOM_CAPSULE][mjGEOM_CYLINDER] = 1;
max_contacts[mjGEOM_CAPSULE][mjGEOM_BOX] = 2;
max_contacts[mjGEOM_CAPSULE][mjGEOM_MESH] = 1;
// Ellipsoid
max_contacts[mjGEOM_ELLIPSOID][mjGEOM_ELLIPSOID] = 1;
max_contacts[mjGEOM_ELLIPSOID][mjGEOM_CYLINDER] = 1;
max_contacts[mjGEOM_ELLIPSOID][mjGEOM_BOX] = 1;
max_contacts[mjGEOM_ELLIPSOID][mjGEOM_MESH] = 1;
// Cylinder
max_contacts[mjGEOM_CYLINDER][mjGEOM_CYLINDER] = 1;
max_contacts[mjGEOM_CYLINDER][mjGEOM_BOX] = 1;
max_contacts[mjGEOM_CYLINDER][mjGEOM_MESH] = 1;
// Box
max_contacts[mjGEOM_BOX][mjGEOM_BOX] = 8;
max_contacts[mjGEOM_BOX][mjGEOM_MESH] = 1;
// Mesh
max_contacts[mjGEOM_MESH][mjGEOM_MESH] = 1;
return max_contacts;
}
constexpr std::array<std::array<int, mjNGEOMTYPES>, mjNGEOMTYPES>
kMujocoMaxContacts = GetMujocoMaxContactsArray();
// Returns all geom names inside `model` as a single string with line endings
// after each name.
std::string GetAllGeomNames(const MjLib& lib, const mjModel& model) {
std::string names;
for (int i = 0; i < model.ngeom; i++) {
absl::StrAppend(&names, lib.mj_id2name(&model, mjOBJ_GEOM, i), "\n");
}
return names;
}
// Converts a GeomGroup into a GeomIdGroup.
GeomIdGroup NamedGroupToIdGroup(const MjLib& lib, const mjModel& model,
const GeomGroup& named_group) {
GeomIdGroup id_group;
for (const auto& geom_name : named_group) {
const int id = lib.mj_name2id(&model, mjOBJ_GEOM, geom_name.c_str());
CHECK(id >= 0) << absl::Substitute(
"NamedGroupToIdGroup: Geom with name [$0] does not exist in model. "
"Please find the full list of geoms below:\n$1",
geom_name, GetAllGeomNames(lib, model));
id_group.insert(id);
}
return id_group;
}
// Converts a CollisionPair into a CollisionIdPair.
absl::btree_set<CollisionIdPair> NamedPairsToIdPairs(
const MjLib& lib, const mjModel& model,
const absl::btree_set<CollisionPair>& named_pairs) {
absl::btree_set<CollisionIdPair> id_pairs;
for (const auto& named_pair : named_pairs) {
GeomIdGroup id_group_first =
NamedGroupToIdGroup(lib, model, named_pair.first);
GeomIdGroup id_group_second =
NamedGroupToIdGroup(lib, model, named_pair.second);
id_pairs.emplace(std::move(id_group_first), std::move(id_group_second));
}
return id_pairs;
}
// Returns true if geom1 and geom2 are part of the same body, or of bodies that
// are welded together.
//
// It is the caller's responsibility to ensure that the provided IDs are valid.
bool IsWeldedTogether(const mjModel& model, const int geom_id1,
const int geom_id2) {
const int body1 = model.geom_bodyid[geom_id1];
const int body2 = model.geom_bodyid[geom_id2];
const int weld1 = model.body_weldid[body1];
const int weld2 = model.body_weldid[body2];
return weld1 == weld2;
}
// Returns true iff the provided geom_id is attached to the worldbody or to a
// body that is welded to the worldbody.
//
// It is the caller's responsibility to ensure that the provided ID is valid.
bool IsWeldedToWorldbody(const mjModel& model, const int geom_id) {
const int body_id = model.geom_bodyid[geom_id];
return model.body_weldid[body_id] == 0;
}
// Returns true iff the bodies have a parent-child relationship, treating all
// welded bodies as a single body. In other words, returns true if any body
// welded to the first geom's body is a child of any body welded to the second
// geom's body, or vice versa. Note that if both geoms are in the worldbody,
// this function returns true, as MuJoCo's convention is that the worldbody is
// its own parent.
//
// Example:
// (0)worldbody->(1)grandparent->(2)parent->(3)welded_to_parent->(4)child
// ->(5)welded_to_child
//
// AreGeomBodiesParentChild(parent, welded_to_child) -> true.
// parent (body_weldid 2, weld_parent_weldid 1);
// welded_to_child (body_weldid 4, weld_parent_weldid 2).
//
// AreGeomBodiesParentChild(parent, welded_to_parent) -> false.
// parent (body_weldid 2, weld_parent_weldid 1);
// welded_to_parent(body_weldid 2, weld_parent_weldid 1).
//
// AreGeomBodiesParentChild(grandparent, worldbody) -> true.
// grandparent(body_weldid 1, weld_parent_weldid 0);
// worldbody(body_weldid 0, weld_parent_weldid 0)
// will return true
//
// It is the caller's responsibility to ensure that the provided IDs are valid.
bool AreGeomBodiesParentChild(const mjModel& model, const int geom_id1,
const int geom_id2) {
const int body_id1 = model.geom_bodyid[geom_id1];
const int body_id2 = model.geom_bodyid[geom_id2];
// body_weldid is the ID of the body's weld.
const int body_weldid1 = model.body_weldid[body_id1];
const int body_weldid2 = model.body_weldid[body_id2];
// weld_parent_id is the ID of the parent of the body's weld.
const int weld_parent_id1 = model.body_parentid[body_weldid1];
const int weld_parent_id2 = model.body_parentid[body_weldid2];
// weld_parent_weldid is the weld ID of the parent of the body's weld.
const int weld_parent_weldid1 = model.body_weldid[weld_parent_id1];
const int weld_parent_weldid2 = model.body_weldid[weld_parent_id2];
return body_weldid1 == weld_parent_weldid2 ||
body_weldid2 == weld_parent_weldid1;
}
// Returns true if the bounding spheres of the geoms are closer than
// collision_detection_distance, or if any of the geoms is a plane.
//
// If true, other procedures are necessary to determine if the two geoms are
// colliding. If false, we can assume that the objects are not colliding.
bool AreBoundingSpheresInCollision(const MjLib& lib, const mjModel& model,
const mjData& data, const int geom1_id,
const int geom2_id,
const double collision_detection_distance) {
// Note that in MuJoCo's implementation planes always have an rbound field of
// 0.0, but this function always returns true in this case.
if (model.geom_type[geom1_id] == mjtGeom::mjGEOM_PLANE ||
model.geom_type[geom2_id] == mjtGeom::mjGEOM_PLANE) {
return true;
}
// geom_rbound defines the radius of each bounding sphere centered at the
// geom_xpos for each geom.
const double geom1_rbound = model.geom_rbound[geom1_id];
const double geom2_rbound = model.geom_rbound[geom2_id];
// Compute the center-to-center distance.
const double geom_dist = lib.mju_dist3(&data.geom_xpos[3 * geom1_id],
&data.geom_xpos[3 * geom2_id]);
// The distance between the spheres is computed by subtracting each of the
// spheres radii from their center-to-center distance.
const double sphere_dist = geom_dist - geom1_rbound - geom2_rbound;
return sphere_dist < collision_detection_distance;
}
// Runs MuJoCo's collision detection function and returns the number of
// collisions between geoms with IDs `geom1_id` and `geom2_id` and fills the
// `contacts` array with one contact for each collision detected.
//
// The `contacts` array is always of a fixed size equal to mjMAXCONPAIR, to
// ensure that all possible contacts can be detected, but only the first
// elements of the array are filled. This is because if the contact buffer is
// full, MuJoCo logs a warning but does not signal this through a returned
// value.
//
// Check-fails if:
// - the geoms have invalid IDs;
// - both geoms have the same ID;
// - MuJoCo collision detection mechanism failed.
int ComputeContactsBetweenGeoms(const MjLib& lib, const mjModel& model,
const mjData& data, int geom1_id, int geom2_id,
double collision_detection_distance,
std::array<mjContact, mjMAXCONPAIR>* contacts) {
// Ensure geom pair is valid.
bool is_id_invalid = geom1_id < 0 || geom1_id >= model.ngeom ||
geom2_id >= model.ngeom || geom2_id < 0;
CHECK(!is_id_invalid) << absl::Substitute(
"ComputeContactsBetweenGeoms: Invalid geom ID. First geom ID [$0], "
"second geom ID [$1]. Model number of geoms: [$2].",
geom1_id, geom2_id, model.ngeom);
CHECK(geom1_id != geom2_id) << absl::Substitute(
"ComputeContactsBetweenGeoms: Both geom IDs cannot be the same. First "
"geom ID [$0], second geom ID [$1].",
geom1_id, geom2_id);
// Swap order to ensure we only use upper-right triangular elements of
// mjCOLLISIONFUNC. Note that model.geom_type is guaranteed to have valid
// geom type elements, i.e. geom_type < mjtGeom::mjNGEOMTYPES.
int geom1_type = model.geom_type[geom1_id];
int geom2_type = model.geom_type[geom2_id];
if (geom1_type > geom2_type) {
std::swap(geom1_type, geom2_type);
std::swap(geom1_id, geom2_id);
}
int num_collisions;
if (!AreBoundingSpheresInCollision(lib, model, data, geom1_id, geom2_id,
collision_detection_distance)) {
num_collisions = 0;
} else {
num_collisions = lib.mjCOLLISIONFUNC[geom1_type][geom2_type](
&model, &data, contacts->data(), geom1_id, geom2_id,
collision_detection_distance);
}
// Check-fail if MuJoCo failed. This should never happen.
CHECK(num_collisions >= 0) << absl::Substitute(
"ComputeContactsBetweenGeoms: MuJoCo failed with return "
"value [$0] when computing contacts between geom [$1] with ID "
"[$2] and geom [$3] with ID [$4] with collision detection "
"distance [$5].",
num_collisions, lib.mj_id2name(&model, mjOBJ_GEOM, geom1_id), geom1_id,
lib.mj_id2name(&model, mjOBJ_GEOM, geom2_id), geom2_id,
collision_detection_distance);
// Fill geom IDs.
for (int i = 0; i < num_collisions; ++i) {
contacts->at(i).geom1 = geom1_id;
contacts->at(i).geom2 = geom2_id;
}
return num_collisions;
}
} // namespace
int GetJointDofSize(const mjModel& model, int joint_id) {
CHECK(0 <= joint_id && joint_id < model.njnt) << absl::Substitute(
"GetJointDofSize: `joint_id` [$0] is invalid for the provided model, "
"which has [$1] joints.",
joint_id, model.njnt);
const mjtJoint type = static_cast<mjtJoint>(model.jnt_type[joint_id]);
switch (type) {
case mjtJoint::mjJNT_SLIDE:
case mjtJoint::mjJNT_HINGE:
return 1;
case mjtJoint::mjJNT_BALL:
return 3;
case mjtJoint::mjJNT_FREE:
return 6;
}
LOG(FATAL) << absl::Substitute(
"GetJointDofSize: `joint_id` [$0] corresponds to an invalid joint type "
"[$1] in the provided model.",
joint_id, model.jnt_type[joint_id]);
}
int GetJointQposSize(const mjModel& model, int joint_id) {
CHECK(0 <= joint_id && joint_id < model.njnt) << absl::Substitute(
"GetJointQposSize: `joint_id` [$0] is invalid for the provided model, "
"which has [$1] joints.",
joint_id, model.njnt);
const mjtJoint type = static_cast<mjtJoint>(model.jnt_type[joint_id]);
switch (type) {
case mjtJoint::mjJNT_SLIDE:
case mjtJoint::mjJNT_HINGE:
return 1;
case mjtJoint::mjJNT_BALL:
return 4;
case mjtJoint::mjJNT_FREE:
return 7;
}
LOG(FATAL) << absl::Substitute(
"GetJointQposSize: `joint_id` [$0] corresponds to an invalid joint type "
"[$1] in the provided model.",
joint_id, model.jnt_type[joint_id]);
}
absl::btree_set<int> JointIdsToDofIds(const mjModel& model,
const absl::btree_set<int>& joint_ids) {
absl::btree_set<int> dof_ids;
for (int joint_id : joint_ids) {
for (int i = 0; i < GetJointDofSize(model, joint_id); ++i) {
// In MuJoCo models, the jnt_dofadr for a specific joint represents the
// first DoF ID for that joint. If the joint has more than 1 DoF, the
// remaining DoF IDs can be obtained as increments from the jnt_dofadr.
dof_ids.insert(model.jnt_dofadr[joint_id] + i);
}
}
return dof_ids;
}
int ComputeMaximumNumberOfContacts(
const mjModel& model,
const absl::btree_set<std::pair<int, int>>& geom_pairs) {
int max_num_contacts = 0;
for (const auto [geom_a, geom_b] : geom_pairs) {
// Ensure only the upper-triangle of kMujocoMaxContacts is used.
const int first_type =
std::min(model.geom_type[geom_a], model.geom_type[geom_b]);
const int second_type =
std::max(model.geom_type[geom_a], model.geom_type[geom_b]);
max_num_contacts += kMujocoMaxContacts[first_type][second_type];
}
return max_num_contacts;
}
absl::btree_set<std::pair<int, int>> CollisionPairsToGeomIdPairs(
const MjLib& lib, const mjModel& model,
const absl::btree_set<CollisionPair>& collision_pairs,
bool allow_parent_child_collisions, bool allow_worldbody_collisions) {
// Loop for every pair of geom groups.
absl::btree_set<std::pair<int, int>> geom_id_pairs;
for (const auto& id_pair : NamedPairsToIdPairs(lib, model, collision_pairs)) {
// Look at every possible geom pair, and add to the list if they pass all
// tests.
for (const auto& geomid_a : id_pair.first) {
for (const auto& geomid_b : id_pair.second) {
// Condition 1: Geoms are not part of the same weld.
const bool is_pass_weld_body_condition =
!IsWeldedTogether(model, geomid_a, geomid_b);
// Condition 2:
// Parent-child filter collisions are allowed
// OR geoms do not have a parent-child relationship.
const bool is_pass_parent_child_condition =
allow_parent_child_collisions ||
!AreGeomBodiesParentChild(model, geomid_a, geomid_b);
// Condition 3:
// Worlbody collision is enabled
// AND exactly one of the geoms is welded to the worldbody.
const bool is_pass_worldbody_condition =
allow_worldbody_collisions &&
IsWeldedToWorldbody(model, geomid_a) !=
IsWeldedToWorldbody(model, geomid_b);
if (is_pass_weld_body_condition &&
(is_pass_parent_child_condition || is_pass_worldbody_condition)) {
geom_id_pairs.insert(std::make_pair(std::min(geomid_a, geomid_b),
std::max(geomid_a, geomid_b)));
}
}
}
}
return geom_id_pairs;
}
absl::StatusOr<int> ComputeContactsForGeomPairs(
const MjLib& lib, const mjModel& model, const mjData& data,
const absl::btree_set<std::pair<int, int>>& geom_pairs,
double collision_detection_distance, absl::Span<mjContact> contacts) {
// We make a buffer so that we can detect if we are out of memory and return
// an appropriate error.
std::array<mjContact, mjMAXCONPAIR> contact_buffer;
int contacts_counter = 0;
for (auto [geom1_id, geom2_id] : geom_pairs) {
const int num_collisions = ComputeContactsBetweenGeoms(
lib, model, data, geom1_id, geom2_id, collision_detection_distance,
&contact_buffer);
// Return if size is not enough.
const int new_contacts_size = contacts_counter + num_collisions;
if (new_contacts_size > contacts.size()) {
return absl::OutOfRangeError(absl::Substitute(
"ComputeContactsForCollisionPairs: Provided `contacts` parameter of "
"size [$0] is too small to hold all the detected contacts. Failed "
"when requesting a size of [$1], but note that the necessary total "
"size may be much larger since not all geoms may have been checked "
"yet.",
contacts.size(), new_contacts_size));
}
// Copy contact information and continue.
for (int i = contacts_counter, j = 0; i < new_contacts_size; ++i, ++j) {
const mjContact& from_contact = contact_buffer[j];
mjContact& to_contact = contacts[i];
to_contact.dist = from_contact.dist;
std::copy_n(&from_contact.pos[0], 3, &to_contact.pos[0]);
std::copy_n(&from_contact.frame[0], 3, &to_contact.frame[0]);
to_contact.geom1 = from_contact.geom1;
to_contact.geom2 = from_contact.geom2;
}
contacts_counter += num_collisions;
}
return contacts_counter;
}
void ComputeContactNormalJacobian(const MjLib& lib, const mjModel& model,
const mjData& data, const mjContact& contact,
absl::Span<double> jacobian_buffer,
absl::Span<double> jacobian) {
CHECK(jacobian_buffer.size() == 3 * model.nv) << absl::Substitute(
"ComputeContactNormalJacobian: Provided `jacobian_buffer` size [$0] is "
"not the correct size. Expected 3*model.nv=[$1] elements.",
jacobian_buffer.size(), 3 * model.nv);
CHECK(jacobian.size() == model.nv) << absl::Substitute(
"ComputeContactNormalJacobian: Provided `jacobian` size [$0] is not the "
"correct size. Expected model.nv=[$1] elements.",
jacobian.size(), model.nv);
// The normal always points geom1 -> geom2.
const int geom1_body = model.geom_bodyid[contact.geom1];
const int geom2_body = model.geom_bodyid[contact.geom2];
const double dist = contact.dist;
Eigen::Map<const Eigen::Vector3d> pos_map(contact.pos);
Eigen::Map<const Eigen::Vector3d> normal_map(contact.frame);
Eigen::Map<Eigen::Matrix<double, 1, Eigen::Dynamic>> jacobian_map(
jacobian.data(), 1, model.nv);
Eigen::Map<Eigen::Matrix<double, 3, Eigen::Dynamic, Eigen::RowMajor>>
jacobian_buffer_map(jacobian_buffer.data(), 3, model.nv);
// Compute the contact position of each geom. This is done by using the normal
// from the mid-point to move towards the geom with a magnitude dist/2.
const Eigen::Vector3d geom1_contact_pos = pos_map - 0.5 * dist * normal_map;
const Eigen::Vector3d geom2_contact_pos = pos_map + 0.5 * dist * normal_map;
// Compute the Jacobian for the point in geom2, and project it into the
// normal. Eigen's noalias is necessary to prevent dynamic memory allocation.
lib.mj_jac(&model, &data, jacobian_buffer_map.data(), nullptr,
geom2_contact_pos.data(), geom2_body);
jacobian_map.noalias() = normal_map.transpose() * jacobian_buffer_map;
// Compute the Jacobian for the point in geom1, project it into the normal,
// and subtract from the Jacobian for the point in geom2. This is the
// resulting normal contact Jacobian.
lib.mj_jac(&model, &data, jacobian_buffer_map.data(), nullptr,
geom1_contact_pos.data(), geom1_body);
jacobian_map.noalias() -= normal_map.transpose() * jacobian_buffer_map;
}
absl::optional<double> ComputeMinimumContactDistance(
const MjLib& lib, const mjModel& model, const mjData& data, int geom1_id,
int geom2_id, double collision_detection_distance) {
std::array<mjContact, mjMAXCONPAIR> contact_buffer;
int num_collisions = ComputeContactsBetweenGeoms(
lib, model, data, geom1_id, geom2_id, collision_detection_distance,
&contact_buffer);
// If no collision are detected, do not return a value.
if (num_collisions == 0) {
return absl::nullopt;
}
// Return the minimum distance of all the contacts detected.
double minimum_contact_distance = std::numeric_limits<double>::infinity();
for (int i = 0; i < num_collisions; ++i) {
minimum_contact_distance =
std::min(minimum_contact_distance, contact_buffer[i].dist);
}
return minimum_contact_distance;
}
void ComputeObject6dJacobian(const MjLib& lib, const mjModel& model,
const mjData& data, mjtObj object_type,
int object_id, absl::Span<double> jacobian) {
switch (object_type) {
case mjtObj::mjOBJ_BODY:
lib.mj_jacBody(&model, &data, &jacobian[0], &jacobian[3 * model.nv],
object_id);
break;
case mjtObj::mjOBJ_GEOM:
lib.mj_jacGeom(&model, &data, &jacobian[0], &jacobian[3 * model.nv],
object_id);
break;
case mjtObj::mjOBJ_SITE:
lib.mj_jacSite(&model, &data, &jacobian[0], &jacobian[3 * model.nv],
object_id);
break;
default:
LOG(FATAL) << absl::Substitute(
"Compute6dVelocityJacobian: Invalid object_type [$0]. Only bodies, "
"geoms, and sites are supported.",
lib.mju_type2Str(object_type));
}
}
} // namespace dm_robotics
|
; A139477: Number of binary digits in A001109(n).
; 1,3,6,8,11,13,16,18,21,23,26,29,31,34,36,39,41,44,46,49,51,54,56,59,62,64,67,69,72,74,77,79,82,84,87,90,92,95,97,100,102,105,107,110,112,115,118,120,123,125
mov $2,$0
add $2,1
mov $6,$0
lpb $2
mov $0,$6
sub $2,1
sub $0,$2
mov $4,$0
mov $8,2
lpb $8
sub $8,1
add $0,$8
sub $0,1
mov $5,$0
mul $5,54
add $5,1
div $5,35
mov $7,$8
lpb $7
mov $3,$5
sub $7,1
lpe
lpe
lpb $4
sub $3,$5
mov $4,0
lpe
mov $5,$3
add $5,1
add $1,$5
lpe
mov $0,$1
|
// push constant 17
@17
D=A
@SP
A=M
M=D
@SP
M=M+1
// push constant 17
@17
D=A
@SP
A=M
M=D
@SP
M=M+1
// eq
@SP
AM=M-1
D=M
A=A-1
D=M-D
@c0_if_eq
D;JEQ
D=0
@c0_else
0;JMP
(c0_if_eq)
D=-1
(c0_else)
@SP
A=M-1
M=D
// push constant 17
@17
D=A
@SP
A=M
M=D
@SP
M=M+1
// push constant 16
@16
D=A
@SP
A=M
M=D
@SP
M=M+1
// eq
@SP
AM=M-1
D=M
A=A-1
D=M-D
@c1_if_eq
D;JEQ
D=0
@c1_else
0;JMP
(c1_if_eq)
D=-1
(c1_else)
@SP
A=M-1
M=D
// push constant 16
@16
D=A
@SP
A=M
M=D
@SP
M=M+1
// push constant 17
@17
D=A
@SP
A=M
M=D
@SP
M=M+1
// eq
@SP
AM=M-1
D=M
A=A-1
D=M-D
@c2_if_eq
D;JEQ
D=0
@c2_else
0;JMP
(c2_if_eq)
D=-1
(c2_else)
@SP
A=M-1
M=D
// push constant 892
@892
D=A
@SP
A=M
M=D
@SP
M=M+1
// push constant 891
@891
D=A
@SP
A=M
M=D
@SP
M=M+1
// lt
@SP
AM=M-1
D=M
A=A-1
D=M-D
@c3_if_lt
D;JLT
D=0
@c3_else
0;JMP
(c3_if_lt)
D=-1
(c3_else)
@SP
A=M-1
M=D
// push constant 891
@891
D=A
@SP
A=M
M=D
@SP
M=M+1
// push constant 892
@892
D=A
@SP
A=M
M=D
@SP
M=M+1
// lt
@SP
AM=M-1
D=M
A=A-1
D=M-D
@c4_if_lt
D;JLT
D=0
@c4_else
0;JMP
(c4_if_lt)
D=-1
(c4_else)
@SP
A=M-1
M=D
// push constant 891
@891
D=A
@SP
A=M
M=D
@SP
M=M+1
// push constant 891
@891
D=A
@SP
A=M
M=D
@SP
M=M+1
// lt
@SP
AM=M-1
D=M
A=A-1
D=M-D
@c5_if_lt
D;JLT
D=0
@c5_else
0;JMP
(c5_if_lt)
D=-1
(c5_else)
@SP
A=M-1
M=D
// push constant 32767
@32767
D=A
@SP
A=M
M=D
@SP
M=M+1
// push constant 32766
@32766
D=A
@SP
A=M
M=D
@SP
M=M+1
// gt
@SP
AM=M-1
D=M
A=A-1
D=M-D
@c6_if_gt
D;JGT
D=0
@c6_else
0;JMP
(c6_if_gt)
D=-1
(c6_else)
@SP
A=M-1
M=D
// push constant 32766
@32766
D=A
@SP
A=M
M=D
@SP
M=M+1
// push constant 32767
@32767
D=A
@SP
A=M
M=D
@SP
M=M+1
// gt
@SP
AM=M-1
D=M
A=A-1
D=M-D
@c7_if_gt
D;JGT
D=0
@c7_else
0;JMP
(c7_if_gt)
D=-1
(c7_else)
@SP
A=M-1
M=D
// push constant 32766
@32766
D=A
@SP
A=M
M=D
@SP
M=M+1
// push constant 32766
@32766
D=A
@SP
A=M
M=D
@SP
M=M+1
// gt
@SP
AM=M-1
D=M
A=A-1
D=M-D
@c8_if_gt
D;JGT
D=0
@c8_else
0;JMP
(c8_if_gt)
D=-1
(c8_else)
@SP
A=M-1
M=D
// push constant 57
@57
D=A
@SP
A=M
M=D
@SP
M=M+1
// push constant 31
@31
D=A
@SP
A=M
M=D
@SP
M=M+1
// push constant 53
@53
D=A
@SP
A=M
M=D
@SP
M=M+1
// add
@SP
AM=M-1
D=M
A=A-1
M=M+D
// push constant 112
@112
D=A
@SP
A=M
M=D
@SP
M=M+1
// sub
@SP
AM=M-1
D=M
A=A-1
M=M-D
// neg
@SP
A=M-1
M=-M
// and
@SP
AM=M-1
D=M
A=A-1
M=M&D
// push constant 82
@82
D=A
@SP
A=M
M=D
@SP
M=M+1
// or
@SP
AM=M-1
D=M
A=A-1
M=M|D
// not
@SP
A=M-1
M=!M
(EXIT)
@EXIT
0;JMP
|
; A319645: Number of non-isomorphic weight-n antichains of distinct multisets whose dual is a chain of distinct multisets.
; Submitted by Christian Krause
; 1,1,1,2,3,4,7,9,16,22,38
add $0,1
mov $3,1
lpb $0
sub $0,1
add $1,3
add $2,$3
mov $3,$1
mov $1,$0
dif $2,2
add $3,$2
lpe
mov $0,$2
div $0,18
add $0,1
|
#include "tic_tac_toe_3.h"
/*
class function check_column_win
Win by column if and return true if
0,3, and 6 are equal
1, 4, and 7
2, 5, and 8
else
false
*/
/*
class function check_row_win
Win by row if
0, 1, 2 are equal
3,4,5 are equal
6,7,8 are equal
*/
/*
class function check_diagonal_win
Win diagonally
0 1 2
3 4 5
6 7 8
*/
bool TicTacToe3::check_row_win()
{
for (std::size_t i = 0; i < 9; i += 3)
{
if (pegs[i] == pegs[i + 1] && pegs[i + 1] == pegs[i + 2] && pegs[i] != " ")
{
return true;
}
}
return false;
}
bool TicTacToe3::check_column_win()
{
for (std::size_t i = 0; i < 3; i++)
{
if (pegs[i] == pegs[i + 3] && pegs[i + 3] == pegs[i + 6]
&& pegs[i + 6] != " ")
{
return true;
}
}
return false;
}
bool TicTacToe3::check_diagonal_win()
{
if (pegs[0] == pegs[4] && pegs[4] == pegs[8] && pegs[0] != " " ||
pegs[2] == pegs[4] && pegs[4] == pegs[6] && pegs[2] != " ")
{
return true;
}
return false;
}
|
;Z88 Small C Library functions, linked using the z80 module assembler
;Small C Z88 converted by Dominic Morris <djm@jb.man.ac.uk>
;
;Exit routine, rewritten 27/11/98 so to traverse the atexit stack
;
;Constantly revisited through April
;Some of the opt rules cause this routine to be jumped to instead
;of called, so we don't use the stack, instead we use hl as our
;entrance variable...we're buggered if we define a pointer to here
;though...
;
; -----
; $Id: exit.asm,v 1.5 2007/01/09 21:54:21 stefano Exp $
XLIB exit
XREF cleanup, exitsp, exitcount
LIB l_jphl
XDEF ASMDISP_EXIT
; FASTCALL
;This also allows for an atexit function to print a bye bye message
;or whatever... - no parameters are passed into it...
.exit
push hl ; save exit value
ld a,(exitcount)
or a
jr z, end
ld b,a ; b = number of registered functions
add a,a
ld e,a
ld d,0
ld hl,(exitsp) ; hl = & atexit stack
add hl,de ; hl = & last function in exit stack + 2b
.loop ; now traverse atexit stack in reverse order
push bc
dec hl
ld a,(hl)
dec hl
push hl
ld l,(hl)
ld h,a ; hl = atexit function
call l_jphl
pop hl
pop bc
djnz loop
.end ; disrupt stack completely and exit with error value
pop hl
ld a,l ; was here so left as is, something to do with z88?
jp cleanup ; perhaps should be in the z88 crt0?
DEFC ASMDISP_EXIT = 0
|
SECTION .text
USE16
; provide function for printing in x86 real mode
; a newline
newline: db 0xD, 0xA, 0
; print a string and a newline
; IN
; si: points at zero-terminated String
; CLOBBER
; ax
print_line:
mov si, newline
call print
ret
; print a string
; IN
; si: points at zero-terminated String
; CLOBBER
; ax
print:
lodsb
test al, al
jz .done
call print_char
jmp print
.done:
ret
; print a character
; IN
; al: character to print
; CLOBBER
; ah
print_char:
mov ah, 0x0e
int 0x10
ret
; print a number in hex
; IN
; bx: the number
; CLOBBER
; cx, ax
print_num:
mov cx, 4
.lp:
mov al, bh
shr al, 4
cmp al, 0xA
jb .below_0xA
add al, 'A' - 0xA - '0'
.below_0xA:
add al, '0'
call print_char
shl bx, 4
loop .lp
ret
|
; Copyright (c) 2004, 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:
;
; EnablePaging64.Asm
;
; Abstract:
;
; AsmEnablePaging64 function
;
; Notes:
;
;------------------------------------------------------------------------------
.code
;------------------------------------------------------------------------------
; VOID
; EFIAPI
; InternalX86EnablePaging64 (
; IN UINT16 Cs,
; IN UINT64 EntryPoint,
; IN UINT64 Context1, OPTIONAL
; IN UINT64 Context2, OPTIONAL
; IN UINT64 NewStack
; );
;------------------------------------------------------------------------------
InternalX86EnablePaging64 PROC
cli
pop rax ; skip the return address
call @Base
@Base:
add dword ptr [rsp], @F - @Base ; offset for far retf, seg is the 1st arg
mov rax, cr4 ; mov eax, cr4
or al, (1 SHL 5)
mov cr4, rax ; enable PAE
mov ecx, 0c0000080h
rdmsr
or ah, 1 ; set LME
wrmsr
mov rax, cr0 ; mov eax, cr0
bts eax, 31
mov cr0, rax ; enable paging
retf
@@: ; long mode starts here
mov rbx, [esp]
mov rcx, [esp + 8]
mov rdx, [esp + 10h]
mov rsp, [esp + 18h]
add rsp, -20h
call rbx
hlt ; halt processor if EntryPoint() returned
InternalX86EnablePaging64 ENDP
END
|
// Copyright 2018 The Fuchsia 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 <gtest/gtest.h>
#include "amlogic-video.h"
#include "tests/test_support.h"
/*
namespace amlogic_decoder {
namespace test {
TEST(Binding, Destruction) {
auto video = std::make_unique<AmlogicVideo>();
ASSERT_TRUE(video);
zx_status_t status = video->InitRegisters(TestSupport::parent_device());
EXPECT_EQ(ZX_OK, status);
video.reset();
}
} // namespace test
} // namespace amlogic_decoder
*/
|
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <alibabacloud/ddoscoo/model/DescribeWebPreciseAccessRuleResult.h>
#include <json/json.h>
using namespace AlibabaCloud::Ddoscoo;
using namespace AlibabaCloud::Ddoscoo::Model;
DescribeWebPreciseAccessRuleResult::DescribeWebPreciseAccessRuleResult() :
ServiceResult()
{}
DescribeWebPreciseAccessRuleResult::DescribeWebPreciseAccessRuleResult(const std::string &payload) :
ServiceResult()
{
parse(payload);
}
DescribeWebPreciseAccessRuleResult::~DescribeWebPreciseAccessRuleResult()
{}
void DescribeWebPreciseAccessRuleResult::parse(const std::string &payload)
{
Json::Reader reader;
Json::Value value;
reader.parse(payload, value);
setRequestId(value["RequestId"].asString());
auto allPreciseAccessConfigListNode = value["PreciseAccessConfigList"]["PreciseAccessConfig"];
for (auto valuePreciseAccessConfigListPreciseAccessConfig : allPreciseAccessConfigListNode)
{
PreciseAccessConfig preciseAccessConfigListObject;
if(!valuePreciseAccessConfigListPreciseAccessConfig["Domain"].isNull())
preciseAccessConfigListObject.domain = valuePreciseAccessConfigListPreciseAccessConfig["Domain"].asString();
auto allRuleListNode = valuePreciseAccessConfigListPreciseAccessConfig["RuleList"]["Rule"];
for (auto valuePreciseAccessConfigListPreciseAccessConfigRuleListRule : allRuleListNode)
{
PreciseAccessConfig::Rule ruleListObject;
if(!valuePreciseAccessConfigListPreciseAccessConfigRuleListRule["Owner"].isNull())
ruleListObject.owner = valuePreciseAccessConfigListPreciseAccessConfigRuleListRule["Owner"].asString();
if(!valuePreciseAccessConfigListPreciseAccessConfigRuleListRule["Expires"].isNull())
ruleListObject.expires = std::stol(valuePreciseAccessConfigListPreciseAccessConfigRuleListRule["Expires"].asString());
if(!valuePreciseAccessConfigListPreciseAccessConfigRuleListRule["Name"].isNull())
ruleListObject.name = valuePreciseAccessConfigListPreciseAccessConfigRuleListRule["Name"].asString();
if(!valuePreciseAccessConfigListPreciseAccessConfigRuleListRule["Action"].isNull())
ruleListObject.action = valuePreciseAccessConfigListPreciseAccessConfigRuleListRule["Action"].asString();
auto allConditionListNode = valuePreciseAccessConfigListPreciseAccessConfigRuleListRule["ConditionList"]["Condition"];
for (auto valuePreciseAccessConfigListPreciseAccessConfigRuleListRuleConditionListCondition : allConditionListNode)
{
PreciseAccessConfig::Rule::Condition conditionListObject;
if(!valuePreciseAccessConfigListPreciseAccessConfigRuleListRuleConditionListCondition["MatchMethod"].isNull())
conditionListObject.matchMethod = valuePreciseAccessConfigListPreciseAccessConfigRuleListRuleConditionListCondition["MatchMethod"].asString();
if(!valuePreciseAccessConfigListPreciseAccessConfigRuleListRuleConditionListCondition["Field"].isNull())
conditionListObject.field = valuePreciseAccessConfigListPreciseAccessConfigRuleListRuleConditionListCondition["Field"].asString();
if(!valuePreciseAccessConfigListPreciseAccessConfigRuleListRuleConditionListCondition["HeaderName"].isNull())
conditionListObject.headerName = valuePreciseAccessConfigListPreciseAccessConfigRuleListRuleConditionListCondition["HeaderName"].asString();
if(!valuePreciseAccessConfigListPreciseAccessConfigRuleListRuleConditionListCondition["Content"].isNull())
conditionListObject.content = valuePreciseAccessConfigListPreciseAccessConfigRuleListRuleConditionListCondition["Content"].asString();
ruleListObject.conditionList.push_back(conditionListObject);
}
preciseAccessConfigListObject.ruleList.push_back(ruleListObject);
}
preciseAccessConfigList_.push_back(preciseAccessConfigListObject);
}
}
std::vector<DescribeWebPreciseAccessRuleResult::PreciseAccessConfig> DescribeWebPreciseAccessRuleResult::getPreciseAccessConfigList()const
{
return preciseAccessConfigList_;
}
|
/*
* See header file for a description of this class.
*
* \author S. Bolognesi and G. Cerminara - INFN Torino
*/
#include <iostream>
#include <map>
#include "DataFormats/DTRecHit/interface/DTRecHitCollection.h"
#include "DataFormats/DTRecHit/interface/DTRecSegment2DCollection.h"
#include "DataFormats/MuonDetId/interface/DTWireId.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "Geometry/DTGeometry/interface/DTGeometry.h"
#include "Geometry/DTGeometry/interface/DTSuperLayer.h"
#include "Geometry/Records/interface/MuonGeometryRecord.h"
#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
#include "Validation/DTRecHits/interface/DTHitQualityUtils.h"
#include "DTSegment2DQuality.h"
#include "Histograms.h"
using namespace std;
using namespace edm;
namespace dtsegment2d {
struct Histograms {
std::unique_ptr<HRes2DHit> h2DHitRPhi;
std::unique_ptr<HRes2DHit> h2DHitRZ;
std::unique_ptr<HRes2DHit> h2DHitRZ_W0;
std::unique_ptr<HRes2DHit> h2DHitRZ_W1;
std::unique_ptr<HRes2DHit> h2DHitRZ_W2;
std::unique_ptr<HEff2DHit> h2DHitEff_RPhi;
std::unique_ptr<HEff2DHit> h2DHitEff_RZ;
std::unique_ptr<HEff2DHit> h2DHitEff_RZ_W0;
std::unique_ptr<HEff2DHit> h2DHitEff_RZ_W1;
std::unique_ptr<HEff2DHit> h2DHitEff_RZ_W2;
};
} // namespace dtsegment2d
using namespace dtsegment2d;
// Constructor
DTSegment2DQuality::DTSegment2DQuality(const ParameterSet &pset) {
// get the debug parameter for verbose output
debug_ = pset.getUntrackedParameter<bool>("debug");
DTHitQualityUtils::debug = debug_;
// the name of the simhit collection
simHitLabel_ = pset.getUntrackedParameter<InputTag>("simHitLabel");
simHitToken_ = consumes<PSimHitContainer>(pset.getUntrackedParameter<InputTag>("simHitLabel"));
// the name of the 2D rec hit collection
segment2DLabel_ = pset.getUntrackedParameter<InputTag>("segment2DLabel");
segment2DToken_ = consumes<DTRecSegment2DCollection>(pset.getUntrackedParameter<InputTag>("segment2DLabel"));
// sigma resolution on position
sigmaResPos_ = pset.getParameter<double>("sigmaResPos");
// sigma resolution on angle
sigmaResAngle_ = pset.getParameter<double>("sigmaResAngle");
if (debug_) {
cout << "[DTSegment2DQuality] Constructor called " << endl;
}
}
void DTSegment2DQuality::bookHistograms(DQMStore::IBooker &booker,
edm::Run const &run,
edm::EventSetup const &setup,
Histograms &histograms) const {
histograms.h2DHitRPhi = std::make_unique<HRes2DHit>("RPhi", booker, true, true);
histograms.h2DHitRZ = std::make_unique<HRes2DHit>("RZ", booker, true, true);
histograms.h2DHitRZ_W0 = std::make_unique<HRes2DHit>("RZ_W0", booker, true, true);
histograms.h2DHitRZ_W1 = std::make_unique<HRes2DHit>("RZ_W1", booker, true, true);
histograms.h2DHitRZ_W2 = std::make_unique<HRes2DHit>("RZ_W2", booker, true, true);
histograms.h2DHitEff_RPhi = std::make_unique<HEff2DHit>("RPhi", booker);
histograms.h2DHitEff_RZ = std::make_unique<HEff2DHit>("RZ", booker);
histograms.h2DHitEff_RZ_W0 = std::make_unique<HEff2DHit>("RZ_W0", booker);
histograms.h2DHitEff_RZ_W1 = std::make_unique<HEff2DHit>("RZ_W1", booker);
histograms.h2DHitEff_RZ_W2 = std::make_unique<HEff2DHit>("RZ_W2", booker);
if (debug_) {
cout << "[DTSegment2DQuality] hitsos created " << endl;
}
}
// The real analysis
void DTSegment2DQuality::dqmAnalyze(edm::Event const &event,
edm::EventSetup const &setup,
Histograms const &histograms) const {
// Get the DT Geometry
ESHandle<DTGeometry> dtGeom;
setup.get<MuonGeometryRecord>().get(dtGeom);
// Get the SimHit collection from the event
edm::Handle<PSimHitContainer> simHits;
event.getByToken(simHitToken_, simHits); // FIXME: second string to be removed
// Map simHits by sl
map<DTSuperLayerId, PSimHitContainer> simHitsPerSl;
for (const auto &simHit : *simHits) {
// Create the id of the sl (the simHits in the DT known their wireId)
DTSuperLayerId slId = ((DTWireId(simHit.detUnitId())).layerId()).superlayerId();
// Fill the map
simHitsPerSl[slId].push_back(simHit);
}
// Get the 2D rechits from the event
Handle<DTRecSegment2DCollection> segment2Ds;
event.getByToken(segment2DToken_, segment2Ds);
if (not segment2Ds.isValid()) {
if (debug_) {
cout << "[DTSegment2DQuality]**Warning: no 2DSegments with label: " << segment2DLabel_
<< " in this event, skipping !" << endl;
}
return;
}
// Loop over all superlayers containing a segment
DTRecSegment2DCollection::id_iterator slId;
for (slId = segment2Ds->id_begin(); slId != segment2Ds->id_end(); ++slId) {
//------------------------- simHits ---------------------------//
// Get simHits of each superlayer
PSimHitContainer simHits = simHitsPerSl[(*slId)];
// Map simhits per wire
map<DTWireId, PSimHitContainer> simHitsPerWire = DTHitQualityUtils::mapSimHitsPerWire(simHits);
map<DTWireId, const PSimHit *> muSimHitPerWire = DTHitQualityUtils::mapMuSimHitsPerWire(simHitsPerWire);
int nMuSimHit = muSimHitPerWire.size();
if (nMuSimHit == 0 or nMuSimHit == 1) {
if (debug_ and nMuSimHit == 1) {
cout << "[DTSegment2DQuality] Only " << nMuSimHit << " mu SimHit in this SL, skipping !" << endl;
}
continue; // If no or only one mu SimHit is found skip this SL
}
if (debug_) {
cout << "=== SL " << (*slId) << " has " << nMuSimHit << " SimHits" << endl;
}
// Find outer and inner mu SimHit to build a segment
pair<const PSimHit *, const PSimHit *> inAndOutSimHit = DTHitQualityUtils::findMuSimSegment(muSimHitPerWire);
// Check that outermost and innermost SimHit are not the same
if (inAndOutSimHit.first == inAndOutSimHit.second) {
cout << "[DTHitQualityUtils]***Warning: outermost and innermost SimHit "
"are the same !"
<< endl;
continue;
}
// Find direction and position of the sim Segment in SL RF
pair<LocalVector, LocalPoint> dirAndPosSimSegm =
DTHitQualityUtils::findMuSimSegmentDirAndPos(inAndOutSimHit, (*slId), &(*dtGeom));
LocalVector simSegmLocalDir = dirAndPosSimSegm.first;
LocalPoint simSegmLocalPos = dirAndPosSimSegm.second;
if (debug_) {
cout << " Simulated segment: local direction " << simSegmLocalDir << endl
<< " local position " << simSegmLocalPos << endl;
}
const DTSuperLayer *superLayer = dtGeom->superLayer(*slId);
GlobalPoint simSegmGlobalPos = superLayer->toGlobal(simSegmLocalPos);
// Atan(x/z) angle and x position in SL RF
float angleSimSeg = DTHitQualityUtils::findSegmentAlphaAndBeta(simSegmLocalDir).first;
float posSimSeg = simSegmLocalPos.x();
// Position (in eta, phi coordinates) in the global RF
float etaSimSeg = simSegmGlobalPos.eta();
float phiSimSeg = simSegmGlobalPos.phi();
//---------------------------- recHits --------------------------//
// Get the range of rechit for the corresponding slId
bool recHitFound = false;
DTRecSegment2DCollection::range range = segment2Ds->get(*slId);
int nsegm = distance(range.first, range.second);
if (debug_) {
cout << " Sl: " << *slId << " has " << nsegm << " 2D segments" << endl;
}
if (nsegm != 0) {
// Find the best RecHit: look for the 2D RecHit with the angle closest
// to that of segment made of SimHits.
// RecHits must have delta alpha and delta position within 5 sigma of
// the residual distribution (we are looking for residuals of segments
// usefull to the track fit) for efficency purpose
const DTRecSegment2D *bestRecHit = nullptr;
bool bestRecHitFound = false;
double deltaAlpha = 99999;
// Loop over the recHits of this slId
for (DTRecSegment2DCollection::const_iterator segment2D = range.first; segment2D != range.second; ++segment2D) {
// Check the dimension
if ((*segment2D).dimension() != 2) {
if (debug_) {
cout << "[DTSegment2DQuality]***Error: This is not 2D segment !!!" << endl;
}
abort();
}
// Segment Local Direction and position (in SL RF)
LocalVector recSegDirection = (*segment2D).localDirection();
LocalPoint recSegPosition = (*segment2D).localPosition();
float recSegAlpha = DTHitQualityUtils::findSegmentAlphaAndBeta(recSegDirection).first;
if (debug_) {
cout << " RecSegment direction: " << recSegDirection << endl
<< " position : " << recSegPosition << endl
<< " alpha : " << recSegAlpha << endl;
}
if (fabs(recSegAlpha - angleSimSeg) < deltaAlpha) {
deltaAlpha = fabs(recSegAlpha - angleSimSeg);
bestRecHit = &(*segment2D);
bestRecHitFound = true;
}
} // End of Loop over all 2D RecHits
if (bestRecHitFound) {
// Best rechit direction and position in SL RF
LocalPoint bestRecHitLocalPos = bestRecHit->localPosition();
LocalVector bestRecHitLocalDir = bestRecHit->localDirection();
LocalError bestRecHitLocalPosErr = bestRecHit->localPositionError();
LocalError bestRecHitLocalDirErr = bestRecHit->localDirectionError();
float angleBestRHit = DTHitQualityUtils::findSegmentAlphaAndBeta(bestRecHitLocalDir).first;
if (fabs(angleBestRHit - angleSimSeg) < 5 * sigmaResAngle_ and
fabs(bestRecHitLocalPos.x() - posSimSeg) < 5 * sigmaResPos_) {
recHitFound = true;
}
// Fill Residual histos
HRes2DHit *hRes = nullptr;
if ((*slId).superlayer() == 1 or (*slId).superlayer() == 3) { // RPhi SL
hRes = histograms.h2DHitRPhi.get();
} else if ((*slId).superlayer() == 2) { // RZ SL
histograms.h2DHitRZ->fill(angleSimSeg,
angleBestRHit,
posSimSeg,
bestRecHitLocalPos.x(),
etaSimSeg,
phiSimSeg,
sqrt(bestRecHitLocalPosErr.xx()),
sqrt(bestRecHitLocalDirErr.xx()));
if (abs((*slId).wheel()) == 0) {
hRes = histograms.h2DHitRZ_W0.get();
} else if (abs((*slId).wheel()) == 1) {
hRes = histograms.h2DHitRZ_W1.get();
} else if (abs((*slId).wheel()) == 2) {
hRes = histograms.h2DHitRZ_W2.get();
}
}
hRes->fill(angleSimSeg,
angleBestRHit,
posSimSeg,
bestRecHitLocalPos.x(),
etaSimSeg,
phiSimSeg,
sqrt(bestRecHitLocalPosErr.xx()),
sqrt(bestRecHitLocalDirErr.xx()));
}
} // end of if (nsegm != 0)
// Fill Efficiency plot
HEff2DHit *hEff = nullptr;
if ((*slId).superlayer() == 1 or (*slId).superlayer() == 3) { // RPhi SL
hEff = histograms.h2DHitEff_RPhi.get();
} else if ((*slId).superlayer() == 2) { // RZ SL
histograms.h2DHitEff_RZ->fill(etaSimSeg, phiSimSeg, posSimSeg, angleSimSeg, recHitFound);
if (abs((*slId).wheel()) == 0) {
hEff = histograms.h2DHitEff_RZ_W0.get();
} else if (abs((*slId).wheel()) == 1) {
hEff = histograms.h2DHitEff_RZ_W1.get();
} else if (abs((*slId).wheel()) == 2) {
hEff = histograms.h2DHitEff_RZ_W2.get();
}
}
hEff->fill(etaSimSeg, phiSimSeg, posSimSeg, angleSimSeg, recHitFound);
} // End of loop over superlayers
}
// declare this as a framework plugin
#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(DTSegment2DQuality);
|
; A037833: Number of i such that d(i)>=d(i-1), where Sum{d(i)*10^i: i=0,1,...,m} is base 10 representation of n.
; 0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,0,1
lpb $0
mul $0,2
add $0,23
div $0,22
mul $0,10
sub $0,2
mov $1,2
lpe
div $1,2
mov $0,$1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r13
push %r14
push %r8
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_D_ht+0x1b5d4, %rsi
lea addresses_normal_ht+0x934, %rdi
clflush (%rdi)
nop
nop
nop
and %r14, %r14
mov $105, %rcx
rep movsw
nop
nop
nop
and $52502, %rsi
lea addresses_WC_ht+0x1b34, %rsi
lea addresses_WT_ht+0x2934, %rdi
nop
nop
nop
nop
nop
dec %rdx
mov $36, %rcx
rep movsl
nop
cmp %rcx, %rcx
lea addresses_WT_ht+0x1ad34, %rdx
nop
nop
nop
nop
sub %rcx, %rcx
movups (%rdx), %xmm1
vpextrq $0, %xmm1, %r14
cmp $52813, %rdi
lea addresses_WC_ht+0xa734, %r13
nop
nop
nop
nop
xor %rax, %rax
movb $0x61, (%r13)
nop
nop
sub %r13, %r13
lea addresses_UC_ht+0x13134, %rdx
clflush (%rdx)
nop
nop
nop
nop
nop
and $29105, %rax
mov $0x6162636465666768, %r14
movq %r14, %xmm3
movups %xmm3, (%rdx)
nop
dec %rdx
lea addresses_normal_ht+0x1a5c0, %rsi
lea addresses_WT_ht+0x15536, %rdi
nop
add %r8, %r8
mov $78, %rcx
rep movsl
nop
nop
and %r13, %r13
lea addresses_UC_ht+0xa3e4, %r8
add $62432, %r13
mov (%r8), %rdi
and $7493, %r13
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r8
pop %r14
pop %r13
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r8
push %r9
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
// Store
lea addresses_WT+0x1db74, %r12
nop
add $46280, %rbx
mov $0x5152535455565758, %r9
movq %r9, %xmm0
movups %xmm0, (%r12)
xor $22691, %rbx
// REPMOV
lea addresses_D+0x7024, %rsi
lea addresses_PSE+0x19734, %rdi
nop
nop
nop
nop
sub $41476, %r8
mov $8, %rcx
rep movsl
sub %r9, %r9
// Faulty Load
lea addresses_PSE+0x19734, %rbp
clflush (%rbp)
xor $613, %r8
movups (%rbp), %xmm0
vpextrq $0, %xmm0, %r9
lea oracles, %rdi
and $0xff, %r9
shlq $12, %r9
mov (%rdi,%r9,1), %r9
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r9
pop %r8
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_PSE', 'same': False, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_WT', 'same': False, 'size': 16, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_D', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_PSE', 'congruent': 0, 'same': True}, 'OP': 'REPM'}
[Faulty Load]
{'src': {'type': 'addresses_PSE', 'same': True, 'size': 16, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_D_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_WC_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 8, 'same': True}, 'OP': 'REPM'}
{'src': {'type': 'addresses_WT_ht', 'same': False, 'size': 16, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 1, 'congruent': 11, 'NT': True, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_UC_ht', 'same': False, 'size': 16, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_normal_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_UC_ht', 'same': False, 'size': 8, 'congruent': 4, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'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
*/
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r14
push %r8
push %rbp
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WC_ht+0xaad3, %rbp
nop
nop
nop
nop
nop
xor %r14, %r14
mov (%rbp), %r8w
and $18346, %r14
lea addresses_normal_ht+0x25f3, %rcx
nop
nop
nop
cmp $43675, %rdx
movw $0x6162, (%rcx)
nop
sub %rdx, %rdx
lea addresses_A_ht+0x11bd3, %r8
nop
nop
add %r12, %r12
mov (%r8), %rbp
nop
nop
nop
nop
dec %rdx
lea addresses_A_ht+0x6d3, %rsi
lea addresses_WC_ht+0x121d3, %rdi
add $37396, %rbp
mov $57, %rcx
rep movsl
nop
nop
sub %rsi, %rsi
lea addresses_UC_ht+0x1e40b, %rbp
nop
nop
and %rsi, %rsi
mov $0x6162636465666768, %rdi
movq %rdi, %xmm0
movups %xmm0, (%rbp)
cmp %rcx, %rcx
lea addresses_WT_ht+0x129d9, %rsi
clflush (%rsi)
nop
nop
nop
nop
nop
sub $12038, %r8
mov $0x6162636465666768, %r12
movq %r12, %xmm5
vmovups %ymm5, (%rsi)
nop
nop
dec %rsi
lea addresses_D_ht+0x15a53, %rdi
nop
nop
nop
cmp %rdx, %rdx
mov (%rdi), %si
nop
nop
cmp $21063, %rbp
lea addresses_D_ht+0x138d3, %rsi
lea addresses_WC_ht+0x516, %rdi
nop
nop
xor %r8, %r8
mov $7, %rcx
rep movsq
nop
nop
sub %r12, %r12
lea addresses_D_ht+0x50d3, %r12
nop
nop
nop
nop
nop
sub $6582, %rcx
movw $0x6162, (%r12)
nop
nop
cmp %rcx, %rcx
lea addresses_A_ht+0x18cd3, %rdi
clflush (%rdi)
nop
cmp %rdx, %rdx
mov $0x6162636465666768, %r8
movq %r8, (%rdi)
nop
nop
dec %rdi
lea addresses_A_ht+0x15113, %rdi
xor %rdx, %rdx
mov $0x6162636465666768, %r8
movq %r8, %xmm3
vmovups %ymm3, (%rdi)
nop
nop
sub %rcx, %rcx
lea addresses_A_ht+0x47bf, %r12
nop
nop
and $1710, %rbp
movl $0x61626364, (%r12)
nop
nop
nop
add $56656, %r8
lea addresses_normal_ht+0xa7d3, %rdi
nop
nop
add %r8, %r8
mov (%rdi), %dx
nop
cmp %rcx, %rcx
lea addresses_UC_ht+0x1d393, %rcx
nop
cmp %rdx, %rdx
movw $0x6162, (%rcx)
nop
nop
xor $17451, %rcx
lea addresses_D_ht+0x1b6d3, %rdi
nop
nop
nop
nop
xor %rbp, %rbp
movw $0x6162, (%rdi)
nop
nop
nop
add %r14, %r14
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbp
pop %r8
pop %r14
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r12
push %r13
push %r14
push %r8
push %rax
// Load
lea addresses_PSE+0x109a3, %r10
nop
nop
nop
nop
nop
cmp %rax, %rax
movb (%r10), %r11b
nop
nop
nop
add $31372, %r11
// Faulty Load
lea addresses_D+0xe2d3, %r14
nop
nop
add $61609, %r13
mov (%r14), %rax
lea oracles, %r8
and $0xff, %rax
shlq $12, %rax
mov (%r8,%rax,1), %rax
pop %rax
pop %r8
pop %r14
pop %r13
pop %r12
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_D', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'}
{'src': {'NT': False, 'same': False, 'congruent': 3, 'type': 'addresses_PSE', 'AVXalign': False, 'size': 1}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_D', 'AVXalign': True, 'size': 8}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'NT': True, 'same': False, 'congruent': 11, 'type': 'addresses_WC_ht', 'AVXalign': True, 'size': 2}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 2}}
{'src': {'NT': False, 'same': False, 'congruent': 8, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 8}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 10, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 8, 'type': 'addresses_WC_ht'}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': True, 'congruent': 3, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 16}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 32}}
{'src': {'NT': True, 'same': False, 'congruent': 6, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 7, 'type': 'addresses_D_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 0, 'type': 'addresses_WC_ht'}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 9, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 2}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 9, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 8}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 32}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 4}}
{'src': {'NT': False, 'same': False, 'congruent': 8, 'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 6, 'type': 'addresses_UC_ht', 'AVXalign': True, 'size': 2}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 10, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 2}}
{'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
*/
|
; float log2(float x)
SECTION code_fp_math48
PUBLIC cm48_sdccix_log2
EXTERN cm48_sdccix_log2_fastcall
cm48_sdccix_log2:
pop af
pop hl
pop de
push de
push hl
push af
jp cm48_sdccix_log2_fastcall
|
db DEX_DEWGONG ; pokedex id
db 90 ; base hp
db 70 ; base attack
db 80 ; base defense
db 70 ; base speed
db 95 ; base special
db WATER ; species type 1
db ICE ; species type 2
db 60 ; catch rate
db 176 ; base exp yield
INCBIN "pic/ymon/dewgong.pic",0,1 ; 66, sprite dimensions
dw DewgongPicFront
dw DewgongPicBack
; attacks known at lvl 0
db HEADBUTT
db GROWL
db AURORA_BEAM
db 0
db 0 ; growth rate
; learnset
tmlearn 6,7,8
tmlearn 9,10,11,12,13,14,15,16
tmlearn 20
tmlearn 31,32
tmlearn 34,40
tmlearn 44
tmlearn 50,53,54
db BANK(DewgongPicFront)
|
; A244239: Number of partitions of n into 3 parts such that every i-th smallest part (counted with multiplicity) is different from i.
; 1,3,4,6,7,9,11,13,15,18,20,23,26,29,32,36,39,43,47,51,55,60,64,69,74,79,84,90,95,101,107,113,119,126,132,139,146,153,160,168,175,183,191,199,207,216,224,233,242,251,260,270,279,289,299,309,319,330,340,351,362,373,384,396,407,419,431,443,455,468,480,493,506,519,532,546,559,573,587,601,615,630,644,659,674,689,704,720,735,751,767,783,799,816,832,849,866,883,900,918,935,953,971,989,1007,1026,1044,1063,1082,1101,1120,1140,1159,1179,1199,1219,1239,1260,1280,1301,1322,1343,1364,1386,1407,1429,1451,1473,1495,1518,1540,1563,1586,1609,1632,1656,1679,1703,1727,1751,1775,1800,1824,1849,1874,1899,1924,1950,1975,2001,2027,2053,2079,2106,2132,2159,2186,2213,2240,2268,2295,2323,2351,2379,2407,2436,2464,2493,2522,2551,2580,2610,2639,2669,2699,2729,2759,2790,2820,2851,2882,2913,2944,2976,3007,3039,3071,3103,3135,3168,3200,3233,3266,3299,3332,3366,3399,3433,3467,3501,3535,3570,3604,3639,3674,3709,3744,3780,3815,3851,3887,3923,3959,3996,4032,4069,4106,4143,4180,4218,4255,4293,4331,4369,4407,4446,4484,4523,4562,4601,4640,4680,4719,4759,4799,4839,4879,4920,4960,5001,5042,5083,5124,5166,5207,5249,5291,5333,5375,5418
mov $2,$0
lpb $0
add $1,$2
mul $1,2
lpb $0
trn $0,2
sub $1,$2
add $1,$0
trn $2,3
lpe
add $1,1
lpe
add $1,1
|
; A182067: a(n) = floor(n) - floor(n/2) - floor(n/3) - floor(n/5) + floor(n/30).
; 0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,1,1,1,1,0,1,1,1
mov $3,$0
lpb $3
mod $0,6
sub $3,$0
mov $4,$0
add $0,1
seq $4,20639 ; Lpf(n): least prime dividing n (when n > 1); a(1) = 1. Or, smallest prime factor of n, or smallest prime divisor of n.
mul $0,$4
add $2,9
mov $1,$2
lpe
mod $1,2
mov $0,$1
|
; 2000 djm
; 2007 aralbrec - use bcbc' rather than bytes indexed by ix per djm suggestion
SECTION code_math
PUBLIC l_small_mul_32_32x32, l0_small_mul_32_32x32
l_small_mul_32_32x32:
; multiplication of two 32-bit numbers into a 32-bit product
;
; enter : dehl = 32-bit multiplicand
; dehl'= 32-bit multiplicand (more leading zeroes = better performance)
;
; exit : dehl = 32-bit product
; carry reset
;
; uses : af, bc, de, hl, bc', de', hl'
xor a
push hl
exx
ld c,l
ld b,h
pop hl
push de
ex de,hl
ld l,a
ld h,a
exx
pop bc
ld l,a
ld h,a
l0_small_mul_32_32x32:
; dede' = 32-bit multiplicand
; bcbc' = 32-bit multiplicand
; hlhl' = 0
ld a,b
ld b,32
loop_0:
rra
rr c
exx
rr b
rr c
jr nc, loop_1
add hl,de
exx
adc hl,de
exx
loop_1:
sla e
rl d
exx
rl e
rl d
djnz loop_0
push hl
exx
pop de
or a
ret
|
; strcpy function for use with far pointers
; 31/3/00 GWL
;
; $Id: strcpy_far.asm,v 1.5 2017/01/02 20:37:10 aralbrec Exp $
;
SECTION code_clib
EXTERN farseg1,incfar
PUBLIC strcpy_far
PUBLIC _strcpy_far
;far *strcpy(far *s1,far *s2)
; copies s2 to s1
.strcpy_far
._strcpy_far
ld ix,2
add ix,sp
ld c,(ix+4)
ld b,(ix+5)
ld e,(ix+6) ; E'B'C'=s1
exx
ld c,(ix+0)
ld b,(ix+1)
ld e,(ix+2) ; EBC=s2
ld a,($04d1)
ex af,af' ; save seg 1 binding
.strcpy1
call farseg1
ld a,(hl) ; char from s2
ld iyl,a
call incfar
exx
call farseg1
ld a,iyl
ld (hl),a ; place at s1
call incfar
exx
and a
jr nz,strcpy1
ex af,af'
ld ($04d1),a
out ($d1),a ; rebind segment 1
ld l,(ix+4)
ld h,(ix+5)
ld e,(ix+6) ; EHL=s1
ret
|
copyright zengfr site:http://github.com/zengfr/romhack
00042A move.l D1, (A0)+
00042C dbra D0, $42a
004D94 move.l D1, (A1)+
004D96 dbra D0, $4d94
006886 move.w A0, ($70,A6) [123p+ 90]
00688A move.b #$12, ($c8,A6) [123p+ 70]
0068C8 move.w A6, ($70,A0) [123p+ 10]
0068CC move.b #$12, ($c8,A0) [123p+ 70]
006922 movea.w ($70,A6), A0
006926 tst.b ($0,A0) [123p+ 70]
0108B6 move.w A3, ($70,A2)
0108BA move.b ($72,A3), ($73,A2) [123p+ 70]
010952 move.w A3, ($70,A2)
010956 bra $1095e [123p+ 70]
012528 movea.w ($70,A6), A3
01252C move.w A6, ($68,A3) [123p+ 70]
01420C movea.w ($70,A0), A1
014210 tst.b ($0,A1) [123p+ 70]
019474 clr.w ($70,A6) [123p+ B2]
019478 move.b #$10, ($c8,A6) [123p+ 70]
0195B2 move.w ($70,A6), D0
0195B6 beq $19614 [123p+ 70]
01A36E movea.w ($70,A6), A0
01A372 tst.b ($2c,A0) [123p+ 70]
01D34E movea.w ($70,A6), A0
01D352 tst.b ($2c,A0) [123p+ 70]
01D4B8 movea.w ($70,A6), A0
01D4BC tst.b ($0,A0) [123p+ 70]
01D69C movea.w ($70,A6), A0 [123p+ 4, 123p+ 6]
01D6A0 cmpi.b #$e, ($2e,A0) [123p+ 70]
01D6FA movea.w ($70,A6), A0
01D6FE move.b ($72,A0), ($73,A6) [123p+ 70]
01D8D0 tst.w ($70,A6)
01D8D4 beq $1d93c [123p+ 70]
01D938 clr.w ($70,A6) [enemy+ C]
01D93C rts [123p+ 70]
048EA6 move.w A6, ($70,A0)
048EAA move.l #$2060000, ($4,A0) [123p+ 70]
04EF88 move.w A6, ($70,A0)
04EF8C move.l #$2060000, ($4,A0) [123p+ 70]
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
|
SECTION "Memory", ROM0
include "registers.asm"
include "memory.asm"
include "common.asm"
; We assume the source address is $C100
; dma_transfer is stored in HRAM ($FF80)
dma_transfer_start:
ld a, high(DMA_OAM)
ld [DMA],a
ld a,$28
.wait:
dec a
; the assembler is stupid
; I can't do proper relative jump
; with constants :) so we just
; write the op codes by hand
db $20
db $FD
;jr nz,$FD
ret
dma_transfer_end:
init_dma::
ld de,dma_transfer_start
ld hl,$FF80
ld bc,dma_transfer_end-dma_transfer_start
call unsafe_memcpy
ld hl,DMA_OAM
xor a
ld b,a
.clean_dma_oam:
ld [hl],b
inc hl
ld a,l
cp $00
jr nz,.clean_dma_oam
ret
;Warning, A is thrashed
;de = source address
;hl = destination address
;bc = buffer size
unsafe_memcpy::
.rep_memstore:
ld a,[de]
ld [hl+],a
dec bc
inc de
ld a,c
cp $00
jr nz,.rep_memstore
ld a,b
cp $00
jr nz,.rep_memstore
ret
;Warning, A and D are thrashed
;a = value
;hl = destination address
;bc = buffer size
unsafe_memset::
ld d,a
.rep_memstore:
ld a,d
ld [hl+],a
dec bc
ld a,c
cp $00
jr nz,.rep_memstore
ld a,b
cp $00
jr nz,.rep_memstore
ret
;Warning, A and D are thrashed
;e = value
;hl = destination address
;bc = buffer size
safe_vram_memset::
.check_vram_access:
ld a,[LCDS]
and a,$3
cp $00
jr nz,.check_vram_access
ld a,e
.rep_memstore:
ld [hl+],a
dec bc
ld a,c
cp $00
jr nz,.check_vram_access
ld a,b
cp $00
jr nz,.check_vram_access
ret
;Warning, A register is thrashed
;de = source address
;hl = destination address
;bc = buffer size
safe_vram_memcpy::
.check_vram_access:
ld a,[LCDS]
and a,$3
cp $00
jr nz,.check_vram_access
.rep_memstore:
ld a,[de]
ld [hl+],a
dec bc
inc de
ld a,c
cp $00
jr nz,.check_vram_access
ld a,b
cp $00
jr nz,.check_vram_access
ret
;Warning, A register is thrashed
;de = source address
;hl = destination address
;bc = buffer size
safe_oam_memcpy::
.check_oam_access:
ld a,[LCDS]
and a,$3
cp $3
jr z,.check_oam_access
cp $2
jr z,.check_oam_access
.rep_memstore:
ld a,[de]
ld [hl+],a
dec bc
inc de
ld a,c
cp $00
jr nz,.check_oam_access
ld a,b
cp $00
jr nz,.check_oam_access
ret
;Warning, A is thrashed
;d = value
;hl = destination address
;bc = buffer size
unsafe_buffer_add::
.loop:
ld a, [hl]
add a, d
ld [hl+], a
dec bc
ld a,c
cp 0
jr nz,.loop
ld a,b
cp 0
jr nz,.loop
ret
section "dbg",WRAM0
dbg_tmp: ds 1
memcpy_offset_value:: ds 1
|
Sound_46_Header:
smpsHeaderStartSong 3
smpsHeaderVoice Sound_46_Voices
smpsHeaderTempoSFX $01
smpsHeaderChanSFX $01
smpsHeaderSFXChannel cFM5, Sound_46_FM5, $00, $00
; FM5 Data
Sound_46_FM5:
smpsSetvoice $00
smpsModSet $05, $01, $1B, $37
dc.b nC5, $30
smpsStop
Sound_46_Voices:
; Voice $00
; $07
; $03, $13, $23, $33, $0F, $0F, $0F, $0F, $00, $00, $00, $00
; $0B, $0B, $0A, $0C, $0F, $0F, $0F, $0F, $80, $80, $80, $80
smpsVcAlgorithm $07
smpsVcFeedback $00
smpsVcUnusedBits $00
smpsVcDetune $03, $02, $01, $00
smpsVcCoarseFreq $03, $03, $03, $03
smpsVcRateScale $00, $00, $00, $00
smpsVcAttackRate $0F, $0F, $0F, $0F
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $00, $00, $00, $00
smpsVcDecayRate2 $0C, $0A, $0B, $0B
smpsVcDecayLevel $00, $00, $00, $00
smpsVcReleaseRate $0F, $0F, $0F, $0F
smpsVcTotalLevel $00, $00, $00, $00
|
// license:BSD-3-Clause
// copyright-holders:Nicola Salmoria
/***************************************************************************
Time Pilot
driver by Nicola Salmoria
****************************************************************************
memory map (preliminary)
Main processor memory map.
0000-5fff ROM
a000-a3ff Color RAM
a400-a7ff Video RAM
a800-afff RAM
b000-b7ff sprite RAM (only areas 0xb010 and 0xb410 are used).
memory mapped ports:
read:
c000 video scan line. This is used by the program to multiplex the cloud
sprites, drawing them twice offset by 128 pixels.
c200 DSW2
c300 IN0
c320 IN1
c340 IN2
c360 DSW1
write:
c000 command for the audio CPU
c200 watchdog reset
c300 interrupt enable
c302 flip screen
c304 trigger interrupt on audio CPU
c308 video enable (?). Protection ??? Stuffs in some values computed
from ROM content
c30a coin counter 1
c30c coin counter 2
interrupts:
standard NMI at 0x66
SOUND BOARD:
same as Pooyan
***************************************************************************/
#include "emu.h"
#include "includes/timeplt.h"
#include "includes/konamipt.h"
#include "audio/timeplt.h"
#include "cpu/z80/z80.h"
#include "machine/watchdog.h"
#include "sound/ay8910.h"
#define MASTER_CLOCK XTAL(18'432'000)
/*************************************
*
* Interrupts
*
*************************************/
WRITE_LINE_MEMBER(timeplt_state::vblank_irq)
{
if (state && m_nmi_enable)
m_maincpu->set_input_line(INPUT_LINE_NMI, ASSERT_LINE);
}
WRITE_LINE_MEMBER(timeplt_state::nmi_enable_w)
{
m_nmi_enable = state;
if (!m_nmi_enable)
m_maincpu->set_input_line(INPUT_LINE_NMI, CLEAR_LINE);
}
/*************************************
*
* I/O
*
*************************************/
WRITE_LINE_MEMBER(timeplt_state::coin_counter_1_w)
{
machine().bookkeeping().coin_counter_w(0, state);
}
WRITE_LINE_MEMBER(timeplt_state::coin_counter_2_w)
{
machine().bookkeeping().coin_counter_w(1, state);
}
uint8_t timeplt_state::psurge_protection_r()
{
return 0x80;
}
// chkun has access to an extra soundchip via ay2 port a
void timeplt_state::chkun_sound_w(uint8_t data)
{
// d0-d3: P0-P3
// d5: /R (unused?)
// d6: /W
if (~data & 0x40)
m_tc8830f->write_p(data & 0xf);
// d4 (or d7?): /ACL
if (~data & 0x10)
m_tc8830f->reset();
}
READ_LINE_MEMBER(timeplt_state::chkun_hopper_status_r)
{
// temp workaround, needs hopper
return machine().rand();
}
/*************************************
*
* Memory maps
*
*************************************/
void timeplt_state::timeplt_main_map(address_map &map)
{
map.unmap_value_high();
map(0x0000, 0x5fff).rom();
map(0xa000, 0xa3ff).ram().w(FUNC(timeplt_state::colorram_w)).share("colorram");
map(0xa400, 0xa7ff).ram().w(FUNC(timeplt_state::videoram_w)).share("videoram");
map(0xa800, 0xafff).ram();
map(0xb000, 0xb0ff).mirror(0x0b00).ram().share("spriteram");
map(0xb400, 0xb4ff).mirror(0x0b00).ram().share("spriteram2");
map(0xc000, 0xc000).mirror(0x0cff).r(FUNC(timeplt_state::scanline_r)).w("timeplt_audio", FUNC(timeplt_audio_device::sound_data_w));
map(0xc200, 0xc200).mirror(0x0cff).portr("DSW1").w("watchdog", FUNC(watchdog_timer_device::reset_w));
map(0xc300, 0xc300).mirror(0x0c9f).portr("IN0");
map(0xc300, 0xc30f).lw8(NAME([this] (offs_t offset, u8 data) { m_mainlatch->write_d0(offset >> 1, data); }));
map(0xc320, 0xc320).mirror(0x0c9f).portr("IN1");
map(0xc340, 0xc340).mirror(0x0c9f).portr("IN2");
map(0xc360, 0xc360).mirror(0x0c9f).portr("DSW0");
}
void timeplt_state::psurge_main_map(address_map &map)
{
timeplt_main_map(map);
map(0x6004, 0x6004).r(FUNC(timeplt_state::psurge_protection_r));
}
void timeplt_state::chkun_main_map(address_map &map)
{
timeplt_main_map(map);
map(0x6000, 0x67ff).ram();
}
/*************************************
*
* Port definitions
*
*************************************/
static INPUT_PORTS_START( timeplt )
PORT_START("IN0")
KONAMI8_SYSTEM_UNK
PORT_START("IN1")
KONAMI8_MONO_B1_UNK
PORT_START("IN2")
KONAMI8_COCKTAIL_B1_UNK
PORT_START("DSW0")
KONAMI_COINAGE_LOC(DEF_STR( Free_Play ), DEF_STR( Free_Play ), SW1)
PORT_START("DSW1")
PORT_DIPNAME( 0x03, 0x03, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW2:1,2")
PORT_DIPSETTING( 0x03, "3" )
PORT_DIPSETTING( 0x02, "4" )
PORT_DIPSETTING( 0x01, "5" )
PORT_DIPSETTING( 0x00, "255 (Cheat)")
PORT_DIPNAME( 0x04, 0x00, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("SW2:3")
PORT_DIPSETTING( 0x00, DEF_STR( Upright ) )
PORT_DIPSETTING( 0x04, DEF_STR( Cocktail ) )
PORT_DIPNAME( 0x08, 0x08, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("SW2:4")
PORT_DIPSETTING( 0x08, "10000 50000" )
PORT_DIPSETTING( 0x00, "20000 60000" )
PORT_DIPNAME( 0x70, 0x40, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW2:5,6,7")
PORT_DIPSETTING( 0x70, "1 (Easiest)" )
PORT_DIPSETTING( 0x60, "2" )
PORT_DIPSETTING( 0x50, "3" )
PORT_DIPSETTING( 0x40, "4" )
PORT_DIPSETTING( 0x30, "5" )
PORT_DIPSETTING( 0x20, "6" )
PORT_DIPSETTING( 0x10, "7" )
PORT_DIPSETTING( 0x00, "8 (Difficult)" )
PORT_DIPNAME( 0x80, 0x00, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW2:8")
PORT_DIPSETTING( 0x80, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
INPUT_PORTS_END
static INPUT_PORTS_START( psurge )
PORT_INCLUDE(timeplt)
PORT_MODIFY("DSW0")
PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW1:1")
PORT_DIPSETTING( 0x01, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW1:2")
PORT_DIPSETTING( 0x02, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW1:3")
PORT_DIPSETTING( 0x04, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
PORT_DIPNAME( 0x08, 0x08, "Initial Energy" ) PORT_DIPLOCATION("SW1:4")
PORT_DIPSETTING( 0x00, "4" )
PORT_DIPSETTING( 0x08, "6" )
PORT_DIPNAME( 0x30, 0x30, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW1:5,6")
PORT_DIPSETTING( 0x30, "3" )
PORT_DIPSETTING( 0x20, "4" )
PORT_DIPSETTING( 0x10, "5" )
PORT_DIPSETTING( 0x00, "6" )
PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW1:7")
PORT_DIPSETTING( 0x40, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
PORT_DIPNAME( 0x80, 0x80, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("SW1:8")
PORT_DIPSETTING( 0x80, DEF_STR( Upright ) )
PORT_DIPSETTING( 0x00, DEF_STR( Cocktail ) )
PORT_MODIFY("DSW1")
PORT_DIPNAME( 0x03, 0x03, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SW2:1,2")
PORT_DIPSETTING( 0x02, DEF_STR( 2C_1C ) )
PORT_DIPSETTING( 0x03, DEF_STR( 1C_1C ) )
PORT_DIPSETTING( 0x01, DEF_STR( 1C_3C ) )
PORT_DIPSETTING( 0x00, DEF_STR( 1C_5C ) )
PORT_DIPNAME( 0x0c, 0x0c, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("SW2:3,4")
PORT_DIPSETTING( 0x08, DEF_STR( 2C_1C ) )
PORT_DIPSETTING( 0x0c, DEF_STR( 1C_1C ) )
PORT_DIPSETTING( 0x04, DEF_STR( 1C_3C ) )
PORT_DIPSETTING( 0x00, DEF_STR( 1C_5C ) )
PORT_DIPNAME( 0x10, 0x10, "Infinite Shots (Cheat)") PORT_DIPLOCATION("SW2:5")
PORT_DIPSETTING( 0x10, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW2:6")
PORT_DIPSETTING( 0x20, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW2:7")
PORT_DIPSETTING( 0x40, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
PORT_DIPNAME( 0x80, 0x00, "Stop at Junctions" ) PORT_DIPLOCATION("SW2:8")
PORT_DIPSETTING( 0x80, DEF_STR( No ) )
PORT_DIPSETTING( 0x00, DEF_STR( Yes ) )
INPUT_PORTS_END
static INPUT_PORTS_START( chkun )
PORT_START("IN0")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_GAMBLE_KEYOUT )
PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )
PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_START("IN1")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("Bet 3B")
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_CUSTOM ) PORT_READ_LINE_MEMBER(timeplt_state, chkun_hopper_status_r)
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Bet 1B")
PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("Bet 2B")
PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("Bet HR")
PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_START("IN2")
PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_START("DSW0") // 12m
PORT_DIPUNKNOWN_DIPLOC( 0x01, 0x01, "SW1:1" )
PORT_DIPUNKNOWN_DIPLOC( 0x02, 0x02, "SW1:2" )
PORT_DIPUNKNOWN_DIPLOC( 0x04, 0x04, "SW1:3" )
PORT_DIPUNKNOWN_DIPLOC( 0x08, 0x08, "SW1:4" )
PORT_DIPUNKNOWN_DIPLOC( 0x10, 0x10, "SW1:5" )
PORT_DIPUNKNOWN_DIPLOC( 0x20, 0x20, "SW1:6" )
PORT_SERVICE_DIPLOC( 0x40, IP_ACTIVE_LOW, "SW1:7" )
PORT_DIPNAME( 0x80, 0x00, "Freeze" ) PORT_DIPLOCATION("SW1:8")
PORT_DIPSETTING( 0x00, DEF_STR( Off ) )
PORT_DIPSETTING( 0x80, DEF_STR( On ) )
PORT_START("DSW1") // 13m
PORT_DIPNAME( 0x01, 0x01, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SW2:1")
PORT_DIPSETTING( 0x01, DEF_STR( 2C_1C ) )
PORT_DIPSETTING( 0x00, DEF_STR( 1C_1C ) )
PORT_DIPUNKNOWN_DIPLOC( 0x02, 0x02, "SW2:2" )
PORT_DIPUNKNOWN_DIPLOC( 0x04, 0x04, "SW2:3" )
PORT_DIPUNKNOWN_DIPLOC( 0x08, 0x08, "SW2:4" )
PORT_DIPUNKNOWN_DIPLOC( 0x10, 0x10, "SW2:5" )
PORT_DIPUNKNOWN_DIPLOC( 0x20, 0x20, "SW2:6" )
PORT_DIPUNKNOWN_DIPLOC( 0x40, 0x40, "SW2:7" )
PORT_DIPUNKNOWN_DIPLOC( 0x80, 0x80, "SW2:8" )
INPUT_PORTS_END
static INPUT_PORTS_START( bikkuric )
PORT_START("IN0")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_GAMBLE_KEYOUT )
PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_START("IN1")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT )
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_CUSTOM ) PORT_READ_LINE_MEMBER(timeplt_state, chkun_hopper_status_r)
PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )
PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN )
PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT )
PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_START("IN2")
PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNUSED )
PORT_START("DSW0") // 12m
PORT_DIPUNKNOWN_DIPLOC( 0x01, 0x01, "SW1:1" )
PORT_DIPUNKNOWN_DIPLOC( 0x02, 0x02, "SW1:2" )
PORT_DIPUNKNOWN_DIPLOC( 0x04, 0x04, "SW1:3" )
PORT_DIPUNKNOWN_DIPLOC( 0x08, 0x08, "SW1:4" )
PORT_DIPUNKNOWN_DIPLOC( 0x10, 0x10, "SW1:5" )
PORT_DIPUNKNOWN_DIPLOC( 0x20, 0x20, "SW1:6" )
PORT_DIPUNKNOWN_DIPLOC( 0x40, 0x40, "SW1:7" )
PORT_DIPUNKNOWN_DIPLOC( 0x80, 0x80, "SW1:8" )
PORT_START("DSW1") // 13m
PORT_DIPNAME( 0x01, 0x01, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SW2:1")
PORT_DIPSETTING( 0x01, DEF_STR( 2C_1C ) )
PORT_DIPSETTING( 0x00, DEF_STR( 1C_1C ) )
PORT_DIPUNKNOWN_DIPLOC( 0x02, 0x02, "SW2:2" )
PORT_DIPUNKNOWN_DIPLOC( 0x04, 0x04, "SW2:3" )
PORT_DIPUNKNOWN_DIPLOC( 0x08, 0x08, "SW2:4" )
PORT_DIPUNKNOWN_DIPLOC( 0x10, 0x10, "SW2:5" )
PORT_DIPUNKNOWN_DIPLOC( 0x20, 0x20, "SW2:6" )
PORT_DIPUNKNOWN_DIPLOC( 0x40, 0x40, "SW2:7" )
PORT_DIPUNKNOWN_DIPLOC( 0x80, 0x80, "SW2:8" )
INPUT_PORTS_END
/*************************************
*
* Graphics layouts
*
*************************************/
static const gfx_layout charlayout =
{
8,8,
RGN_FRAC(1,1),
2,
{ 4, 0 },
{ STEP4(0,1), STEP4(8*8,1) },
{ STEP8(0,8) },
16*8
};
static const gfx_layout spritelayout =
{
16,16,
RGN_FRAC(1,1),
2,
{ 4, 0 },
{ STEP4(0,1), STEP4(8*8,1), STEP4(16*8,1), STEP4(24*8,1) },
{ STEP8(0,8), STEP8(32*8,8) },
64*8
};
static GFXDECODE_START( gfx_timeplt )
GFXDECODE_ENTRY( "gfx1", 0, charlayout, 0, 32 )
GFXDECODE_ENTRY( "gfx2", 0, spritelayout, 32*4, 64 )
GFXDECODE_END
static const gfx_layout chkun_spritelayout =
{
16,16,
RGN_FRAC(1,1),
2,
{ 0, 4 },
{ STEP4(0,1), STEP4(8*8,1), STEP4(16*8,1), STEP4(24*8,1) },
{ STEP8(0,8), STEP8(32*8,8) },
64*8
};
static GFXDECODE_START( gfx_chkun )
GFXDECODE_ENTRY( "gfx1", 0, charlayout, 0, 32 )
GFXDECODE_ENTRY( "gfx2", 0, chkun_spritelayout, 32*4, 64 )
GFXDECODE_END
/*************************************
*
* Machine drivers
*
*************************************/
void timeplt_state::machine_start()
{
save_item(NAME(m_nmi_enable));
}
void timeplt_state::machine_reset()
{
}
void timeplt_state::timeplt(machine_config &config)
{
/* basic machine hardware */
Z80(config, m_maincpu, MASTER_CLOCK/3/2); /* not confirmed, but common for Konami games of the era */
m_maincpu->set_addrmap(AS_PROGRAM, &timeplt_state::timeplt_main_map);
LS259(config, m_mainlatch); // B3
m_mainlatch->q_out_cb<0>().set(FUNC(timeplt_state::nmi_enable_w));
m_mainlatch->q_out_cb<1>().set(FUNC(timeplt_state::flipscreen_w));
m_mainlatch->q_out_cb<2>().set("timeplt_audio", FUNC(timeplt_audio_device::sh_irqtrigger_w));
m_mainlatch->q_out_cb<3>().set("timeplt_audio", FUNC(timeplt_audio_device::mute_w));
m_mainlatch->q_out_cb<4>().set(FUNC(timeplt_state::video_enable_w));
m_mainlatch->q_out_cb<5>().set(FUNC(timeplt_state::coin_counter_1_w));
m_mainlatch->q_out_cb<6>().set(FUNC(timeplt_state::coin_counter_2_w));
m_mainlatch->q_out_cb<7>().set_nop(); // PAY OUT - not used
WATCHDOG_TIMER(config, "watchdog");
/* video hardware */
SCREEN(config, m_screen, SCREEN_TYPE_RASTER);
m_screen->set_video_attributes(VIDEO_UPDATE_SCANLINE);
m_screen->set_refresh_hz(60);
m_screen->set_size(32*8, 32*8);
m_screen->set_visarea(0*8, 32*8-1, 2*8, 30*8-1);
m_screen->set_screen_update(FUNC(timeplt_state::screen_update));
m_screen->set_palette(m_palette);
m_screen->screen_vblank().set(FUNC(timeplt_state::vblank_irq));
GFXDECODE(config, m_gfxdecode, m_palette, gfx_timeplt);
PALETTE(config, m_palette, FUNC(timeplt_state::timeplt_palette), 32*4 + 64*4);
/* sound hardware */
TIMEPLT_AUDIO(config, "timeplt_audio");
}
void timeplt_state::psurge(machine_config &config)
{
timeplt(config);
/* basic machine hardware */
m_maincpu->set_addrmap(AS_PROGRAM, &timeplt_state::psurge_main_map);
m_screen->screen_vblank().set_inputline("maincpu", INPUT_LINE_NMI);
m_mainlatch->q_out_cb<0>().set_nop();
m_mainlatch->q_out_cb<4>().set_nop();
m_mainlatch->q_out_cb<5>().set_nop();
m_mainlatch->q_out_cb<6>().set_nop();
MCFG_VIDEO_START_OVERRIDE(timeplt_state,psurge)
}
void timeplt_state::bikkuric(machine_config &config)
{
timeplt(config);
m_gfxdecode->set_info(gfx_chkun);
/* basic machine hardware */
m_maincpu->set_addrmap(AS_PROGRAM, &timeplt_state::chkun_main_map);
MCFG_VIDEO_START_OVERRIDE(timeplt_state,chkun)
}
void timeplt_state::chkun(machine_config &config)
{
bikkuric(config);
m_gfxdecode->set_info(gfx_chkun);
/* sound hardware */
subdevice<ay8910_device>("timeplt_audio:ay2")->port_a_write_callback().set(FUNC(timeplt_state::chkun_sound_w));
TC8830F(config, m_tc8830f, XTAL(512'000));
m_tc8830f->add_route(ALL_OUTPUTS, "timeplt_audio:mono", 0.10);
}
/*************************************
*
* ROM definitions
*
*************************************/
ROM_START( timeplt )
ROM_REGION( 0x10000, "maincpu", 0 )
ROM_LOAD( "tm1", 0x0000, 0x2000, CRC(1551f1b9) SHA1(c72f30988ac00cbe6549b71c3bcb414511e8b997) )
ROM_LOAD( "tm2", 0x2000, 0x2000, CRC(58636cb5) SHA1(ab517efa93ae7be780af55faea82a6e83edd828c) )
ROM_LOAD( "tm3", 0x4000, 0x2000, CRC(ff4e0d83) SHA1(ef98a1abb45b22d7498a0aca520f43bbee248b22) )
ROM_REGION( 0x10000, "timeplt_audio:tpsound", 0 )
ROM_LOAD( "tm7", 0x0000, 0x1000, CRC(d66da813) SHA1(408fca4515e8af84211df3e204c8776b2f8adb23) )
ROM_REGION( 0x2000, "gfx1", 0 )
ROM_LOAD( "tm6", 0x0000, 0x2000, CRC(c2507f40) SHA1(07221875e3f81d9def67c57a7ccd82d52ce65e01) )
ROM_REGION( 0x4000, "gfx2", 0 )
ROM_LOAD( "tm4", 0x0000, 0x2000, CRC(7e437c3e) SHA1(cbe2ccd2cd503af62f009cd5aab73aa7366230b1) )
ROM_LOAD( "tm5", 0x2000, 0x2000, CRC(e8ca87b9) SHA1(5dd30d3fb9fd8cf9e6a8e37e7ea858c7fd038a7e) )
ROM_REGION( 0x0240, "proms", 0 )
ROM_LOAD( "timeplt.b4", 0x0000, 0x0020, CRC(34c91839) SHA1(f62e279e21fce171231d3139be7adabe1f4b8c2e) ) /* palette */
ROM_LOAD( "timeplt.b5", 0x0020, 0x0020, CRC(463b2b07) SHA1(9ad275365eba4869f94749f39ff8705d92056a10) ) /* palette */
ROM_LOAD( "timeplt.e9", 0x0040, 0x0100, CRC(4bbb2150) SHA1(678433b21aae1daa938e32d3293eeed529a42ef9) ) /* sprite lookup table */
ROM_LOAD( "timeplt.e12", 0x0140, 0x0100, CRC(f7b7663e) SHA1(151bd2dff4e4ef76d6438c1ab2cae71f987b9dad) ) /* char lookup table */
ROM_END
ROM_START( timeplta )
ROM_REGION( 0x10000, "maincpu", 0 )
ROM_LOAD( "cd_e1.bin", 0x0000, 0x2000, CRC(a4513b35) SHA1(1b1944ec5317d71af86e21e0691caae180dee7b5) )
ROM_LOAD( "cd_e2.bin", 0x2000, 0x2000, CRC(38b0c72a) SHA1(8f0950deb2f9e2b65714318b9e837a1c837f52a9) )
ROM_LOAD( "cd_e3.bin", 0x4000, 0x2000, CRC(83846870) SHA1(b1741e7e5674f9e63e113ead0cb7f5ef874eac5f) )
ROM_REGION( 0x10000, "timeplt_audio:tpsound", 0 )
ROM_LOAD( "tm7", 0x0000, 0x1000, CRC(d66da813) SHA1(408fca4515e8af84211df3e204c8776b2f8adb23) )
ROM_REGION( 0x2000, "gfx1", 0 )
ROM_LOAD( "tm6", 0x0000, 0x2000, CRC(c2507f40) SHA1(07221875e3f81d9def67c57a7ccd82d52ce65e01) )
ROM_REGION( 0x4000, "gfx2", 0 )
ROM_LOAD( "tm4", 0x0000, 0x2000, CRC(7e437c3e) SHA1(cbe2ccd2cd503af62f009cd5aab73aa7366230b1) )
ROM_LOAD( "tm5", 0x2000, 0x2000, CRC(e8ca87b9) SHA1(5dd30d3fb9fd8cf9e6a8e37e7ea858c7fd038a7e) )
ROM_REGION( 0x0240, "proms", 0 )
ROM_LOAD( "timeplt.b4", 0x0000, 0x0020, CRC(34c91839) SHA1(f62e279e21fce171231d3139be7adabe1f4b8c2e) ) /* palette */
ROM_LOAD( "timeplt.b5", 0x0020, 0x0020, CRC(463b2b07) SHA1(9ad275365eba4869f94749f39ff8705d92056a10) ) /* palette */
ROM_LOAD( "timeplt.e9", 0x0040, 0x0100, CRC(4bbb2150) SHA1(678433b21aae1daa938e32d3293eeed529a42ef9) ) /* sprite lookup table */
ROM_LOAD( "timeplt.e12", 0x0140, 0x0100, CRC(f7b7663e) SHA1(151bd2dff4e4ef76d6438c1ab2cae71f987b9dad) ) /* char lookup table */
ROM_END
ROM_START( timepltc )
ROM_REGION( 0x10000, "maincpu", 0 )
ROM_LOAD( "cd1y", 0x0000, 0x2000, CRC(83ec72c2) SHA1(f3dbc8362f6bdad1baa65cf5d95611e79de381a4) )
ROM_LOAD( "cd2y", 0x2000, 0x2000, CRC(0dcf5287) SHA1(c36628367e81ac07f5ace72b45ebb7140b6aa116) )
ROM_LOAD( "cd3y", 0x4000, 0x2000, CRC(c789b912) SHA1(dead7b20a40769e48738fccc3a17e2266aac445d) )
ROM_REGION( 0x10000, "timeplt_audio:tpsound", 0 )
ROM_LOAD( "tm7", 0x0000, 0x1000, CRC(d66da813) SHA1(408fca4515e8af84211df3e204c8776b2f8adb23) )
ROM_REGION( 0x2000, "gfx1", 0 )
ROM_LOAD( "tm6", 0x0000, 0x2000, CRC(c2507f40) SHA1(07221875e3f81d9def67c57a7ccd82d52ce65e01) )
ROM_REGION( 0x4000, "gfx2", 0 )
ROM_LOAD( "tm4", 0x0000, 0x2000, CRC(7e437c3e) SHA1(cbe2ccd2cd503af62f009cd5aab73aa7366230b1) )
ROM_LOAD( "tm5", 0x2000, 0x2000, CRC(e8ca87b9) SHA1(5dd30d3fb9fd8cf9e6a8e37e7ea858c7fd038a7e) )
ROM_REGION( 0x0240, "proms", 0 )
ROM_LOAD( "timeplt.b4", 0x0000, 0x0020, CRC(34c91839) SHA1(f62e279e21fce171231d3139be7adabe1f4b8c2e) ) /* palette */
ROM_LOAD( "timeplt.b5", 0x0020, 0x0020, CRC(463b2b07) SHA1(9ad275365eba4869f94749f39ff8705d92056a10) ) /* palette */
ROM_LOAD( "timeplt.e9", 0x0040, 0x0100, CRC(4bbb2150) SHA1(678433b21aae1daa938e32d3293eeed529a42ef9) ) /* sprite lookup table */
ROM_LOAD( "timeplt.e12", 0x0140, 0x0100, CRC(f7b7663e) SHA1(151bd2dff4e4ef76d6438c1ab2cae71f987b9dad) ) /* char lookup table */
ROM_END
ROM_START( spaceplt )
ROM_REGION( 0x10000, "maincpu", 0 )
ROM_LOAD( "sp1", 0x0000, 0x2000, CRC(ac8ca3ae) SHA1(9781138becd17aa70e877138e126ebb1fbff6192) )
ROM_LOAD( "sp2", 0x2000, 0x2000, CRC(1f0308ef) SHA1(dd88378fc4cefe473f310d4730268c98354a4a44) )
ROM_LOAD( "sp3", 0x4000, 0x2000, CRC(90aeca50) SHA1(9c6fddfeafa84f5284ec8f7c9d46216b110badc1) )
ROM_REGION( 0x10000, "timeplt_audio:tpsound", 0 )
ROM_LOAD( "tm7", 0x0000, 0x1000, CRC(d66da813) SHA1(408fca4515e8af84211df3e204c8776b2f8adb23) )
ROM_REGION( 0x2000, "gfx1", 0 )
ROM_LOAD( "sp6", 0x0000, 0x2000, CRC(76caa8af) SHA1(f81bb73877d415a6587a32bddaad6db8a8fd4941) )
ROM_REGION( 0x4000, "gfx2", 0 )
ROM_LOAD( "sp4", 0x0000, 0x2000, CRC(3781ce7a) SHA1(68bb73f67494c3b24f7fd0d79153c9793f4b3a5b) )
ROM_LOAD( "tm5", 0x2000, 0x2000, CRC(e8ca87b9) SHA1(5dd30d3fb9fd8cf9e6a8e37e7ea858c7fd038a7e) )
ROM_REGION( 0x0240, "proms", 0 )
ROM_LOAD( "timeplt.b4", 0x0000, 0x0020, CRC(34c91839) SHA1(f62e279e21fce171231d3139be7adabe1f4b8c2e) ) /* palette */
ROM_LOAD( "timeplt.b5", 0x0020, 0x0020, CRC(463b2b07) SHA1(9ad275365eba4869f94749f39ff8705d92056a10) ) /* palette */
ROM_LOAD( "timeplt.e9", 0x0040, 0x0100, CRC(4bbb2150) SHA1(678433b21aae1daa938e32d3293eeed529a42ef9) ) /* sprite lookup table */
ROM_LOAD( "timeplt.e12", 0x0140, 0x0100, CRC(f7b7663e) SHA1(151bd2dff4e4ef76d6438c1ab2cae71f987b9dad) ) /* char lookup table */
ROM_END
ROM_START( spaceplta )
ROM_REGION( 0x10000, "maincpu", 0 )
ROM_LOAD( "1", 0x0000, 0x2000, CRC(c6672087) SHA1(1efaaf83dd11af18e947b428c3d9e70b075faf30) )
ROM_LOAD( "2", 0x2000, 0x2000, CRC(5b246c47) SHA1(a5e49eea9ac21b7a498ce5b2c2c30e0a45ce582e) )
ROM_LOAD( "3", 0x4000, 0x2000, CRC(cc9e745e) SHA1(387c748667399573f20d00467f2f6693e10588d3) )
ROM_REGION( 0x10000, "timeplt_audio:tpsound", 0 )
ROM_LOAD( "4", 0x0000, 0x1000, CRC(d66da813) SHA1(408fca4515e8af84211df3e204c8776b2f8adb23) )
ROM_REGION( 0x2000, "gfx1", 0 )
ROM_LOAD( "5", 0x0000, 0x2000, CRC(76caa8af) SHA1(f81bb73877d415a6587a32bddaad6db8a8fd4941) )
ROM_REGION( 0x4000, "gfx2", 0 )
ROM_LOAD( "6", 0x0000, 0x2000, CRC(86ab1ae7) SHA1(8e3f84aa6b2c21e7e1383ea1811fd99a4d940a23) ) // difference to spaceplt: erased Konami
ROM_LOAD( "7", 0x2000, 0x2000, CRC(e8ca87b9) SHA1(5dd30d3fb9fd8cf9e6a8e37e7ea858c7fd038a7e) )
ROM_REGION( 0x0240, "proms", 0 )
ROM_LOAD( "timeplt.b4", 0x0000, 0x0020, CRC(34c91839) SHA1(f62e279e21fce171231d3139be7adabe1f4b8c2e) ) /* palette */
ROM_LOAD( "timeplt.b5", 0x0020, 0x0020, CRC(463b2b07) SHA1(9ad275365eba4869f94749f39ff8705d92056a10) ) /* palette */
ROM_LOAD( "timeplt.e9", 0x0040, 0x0100, CRC(4bbb2150) SHA1(678433b21aae1daa938e32d3293eeed529a42ef9) ) /* sprite lookup table */
ROM_LOAD( "timeplt.e12", 0x0140, 0x0100, CRC(f7b7663e) SHA1(151bd2dff4e4ef76d6438c1ab2cae71f987b9dad) ) /* char lookup table */
ROM_END
ROM_START( psurge )
ROM_REGION( 0x10000, "maincpu", 0 )
ROM_LOAD( "p1", 0x0000, 0x2000, CRC(05f9ba12) SHA1(ad88838d1a0c64830281e425d4ad2498ba959098) )
ROM_LOAD( "p2", 0x2000, 0x2000, CRC(3ff41576) SHA1(9bdbad31c65dff76942967b5a334407b0326f752) )
ROM_LOAD( "p3", 0x4000, 0x2000, CRC(e8fe120a) SHA1(b6320c9cb1a67097692aa0de7d88b0dfb63dedd7) )
ROM_REGION( 0x10000, "timeplt_audio:tpsound", 0 )
ROM_LOAD( "p6", 0x0000, 0x1000, CRC(b52d01fa) SHA1(9b6cf9ea51d3a87c174f34d42a4b1b5f38b48723) )
ROM_LOAD( "p7", 0x1000, 0x1000, CRC(9db5c0ce) SHA1(b5bc1d89a7f7d7a0baae64390c37ee11f69a0e76) )
ROM_REGION( 0x2000, "gfx1", 0 )
ROM_LOAD( "p4", 0x0000, 0x2000, CRC(26fd7f81) SHA1(eb282313a37d7d611bf90f9b0b527adee9ae283f) )
ROM_REGION( 0x4000, "gfx2", 0 )
ROM_LOAD( "p5", 0x0000, 0x2000, CRC(6066ec8e) SHA1(7f1155cf8a2d63c0740a4b56f1e09e7dfc749302) )
ROM_LOAD( "tm5", 0x2000, 0x2000, CRC(e8ca87b9) SHA1(5dd30d3fb9fd8cf9e6a8e37e7ea858c7fd038a7e) )
ROM_REGION( 0x0240, "proms", 0 )
ROM_LOAD( "timeplt.b4", 0x0000, 0x0020, BAD_DUMP CRC(34c91839) SHA1(f62e279e21fce171231d3139be7adabe1f4b8c2e) ) /* palette */
ROM_LOAD( "timeplt.b5", 0x0020, 0x0020, BAD_DUMP CRC(463b2b07) SHA1(9ad275365eba4869f94749f39ff8705d92056a10) ) /* palette */
ROM_LOAD( "timeplt.e9", 0x0040, 0x0100, BAD_DUMP CRC(4bbb2150) SHA1(678433b21aae1daa938e32d3293eeed529a42ef9) ) /* sprite lookup table */
ROM_LOAD( "timeplt.e12", 0x0140, 0x0100, BAD_DUMP CRC(f7b7663e) SHA1(151bd2dff4e4ef76d6438c1ab2cae71f987b9dad) ) /* char lookup table */
ROM_END
ROM_START( chkun )
ROM_REGION( 0x12000, "maincpu", 0 )
ROM_LOAD( "n1.16a", 0x0000, 0x4000, CRC(c5879f9b) SHA1(68e3a87dfe6b3d1e0cdadd1ed8ad115a9d3055f9) )
ROM_LOAD( "12.14a", 0x4000, 0x2000, CRC(80cc55da) SHA1(68727721479624cd0d38d895b98dcef4edac13e9) )
ROM_REGION( 0x12000, "timeplt_audio:tpsound", 0 )
ROM_LOAD( "15.3l", 0x0000, 0x2000, CRC(1f1463ca) SHA1(870abbca35236fcce6a2f640a238e20b9e57f10f))
ROM_REGION( 0x4000, "gfx1", 0 )
ROM_LOAD( "13.4d", 0x0000, 0x4000, CRC(776427c0) SHA1(1e8387685f7e86aad31577f2186596b2a2dfc4de) )
ROM_REGION( 0x4000, "gfx2", 0 )
ROM_LOAD( "14.8h", 0x0000, 0x4000, CRC(0cb76a48) SHA1(0beebbc3d30eb978f6fe7b15c0a7b0c2152815b7) )
ROM_REGION( 0x20000, "tc8830f", 0 )
ROM_LOAD( "v1.8k", 0x00000, 0x10000, CRC(d5ca802d) SHA1(0c2867c86132745063e36d03f41e6c3e150fd3ad) )
ROM_LOAD( "v2.9k", 0x10000, 0x10000, CRC(70e902eb) SHA1(e1b2392446f2878f9e811a63bbbbdc56fd517a9c) )
ROM_REGION( 0x0240, "proms", 0 )
ROM_LOAD( "3.2j", 0x0000, 0x0020, CRC(34c91839) SHA1(f62e279e21fce171231d3139be7adabe1f4b8c2e) ) /* palette */
ROM_LOAD( "2.1h", 0x0020, 0x0020, CRC(463b2b07) SHA1(9ad275365eba4869f94749f39ff8705d92056a10) ) /* palette */
ROM_LOAD( "4.10h", 0x0040, 0x0100, CRC(4bbb2150) SHA1(678433b21aae1daa938e32d3293eeed529a42ef9) ) /* sprite lookup table */
ROM_LOAD( "mb7114e.2b", 0x0140, 0x0100, CRC(adfa399a) SHA1(3b18971ddaae7734f0aaa0fcc82d4ddccc282959) ) /* char lookup table */
ROM_REGION( 0x0200, "pld", 0 )
ROM_LOAD( "a.16c", 0x0000, 0x00eb, CRC(e0d54999) SHA1(9e1c749873572ade2b925ce1519d31a6e19f841f) )
ROM_LOAD( "b.9f", 0x0100, 0x00eb, CRC(e3857f83) SHA1(674e70dc960fc02a9fbda4a0ef0770eb8214c466) )
ROM_END
ROM_START( bikkuric )
ROM_REGION( 0x10000, "maincpu", 0 )
ROM_LOAD( "1.a16", 0x00000, 0x04000, CRC(e8d595ab) SHA1(01f6a5321274befcd03a0ec18ed9770aca4527b6) )
ROM_LOAD( "2.a14", 0x04000, 0x02000, CRC(63fd7d53) SHA1(b1ef666453c5c9e344bee544a0673068d60158fa) )
ROM_REGION( 0x10000, "timeplt_audio:tpsound", 0 )
ROM_LOAD( "5.l3", 0x00000, 0x02000, CRC(bc438531) SHA1(e19badc417b0538010cf535d3f733acc54b0cd96) )
ROM_REGION( 0x8000, "gfx1", 0 )
ROM_LOAD( "3.d4", 0x00000, 0x08000, CRC(74e8a64b) SHA1(b2542e1f6f4b54d8f7aec8f673cedcf5bff5e429) ) // 1st and 2nd identical, confirmed to be like this
ROM_REGION( 0x2000, "gfx2", 0 )
ROM_LOAD( "4.h8", 0x00000, 0x02000, CRC(d303942d) SHA1(688d43e6dbe505d44fc41fdde74858a02910080d) )
ROM_REGION( 0x0240, "proms", 0 ) // not dumped, roms taken from timeplt
ROM_LOAD( "3.2j", 0x0000, 0x0020, BAD_DUMP CRC(34c91839) SHA1(f62e279e21fce171231d3139be7adabe1f4b8c2e) ) /* palette */
ROM_LOAD( "2.1h", 0x0020, 0x0020, BAD_DUMP CRC(463b2b07) SHA1(9ad275365eba4869f94749f39ff8705d92056a10) ) /* palette */
ROM_LOAD( "4.10h", 0x0040, 0x0100, BAD_DUMP CRC(4bbb2150) SHA1(678433b21aae1daa938e32d3293eeed529a42ef9) ) /* sprite lookup table */
ROM_LOAD( "1.2b", 0x0140, 0x0100, BAD_DUMP CRC(f7b7663e) SHA1(151bd2dff4e4ef76d6438c1ab2cae71f987b9dad) ) /* char lookup table */
ROM_REGION( 0x0200, "pld", 0 )
ROM_LOAD( "a.16c", 0x0000, 0x00eb, NO_DUMP )
ROM_LOAD( "b.9f", 0x0100, 0x00eb, NO_DUMP )
ROM_END
/*************************************
*
* Game drivers
*
*************************************/
GAME( 1982, timeplt, 0, timeplt, timeplt, timeplt_state, empty_init, ROT90, "Konami", "Time Pilot", MACHINE_SUPPORTS_SAVE )
GAME( 1982, timepltc, timeplt, timeplt, timeplt, timeplt_state, empty_init, ROT90, "Konami (Centuri license)", "Time Pilot (Centuri)", MACHINE_SUPPORTS_SAVE )
GAME( 1982, timeplta, timeplt, timeplt, timeplt, timeplt_state, empty_init, ROT90, "Konami (Atari license)", "Time Pilot (Atari)", MACHINE_SUPPORTS_SAVE )
GAME( 1982, spaceplt, timeplt, timeplt, timeplt, timeplt_state, empty_init, ROT90, "bootleg", "Space Pilot (set 1)", MACHINE_SUPPORTS_SAVE )
GAME( 1982, spaceplta, timeplt, timeplt, timeplt, timeplt_state, empty_init, ROT90, "bootleg", "Space Pilot (set 2)", MACHINE_SUPPORTS_SAVE )
GAME( 1988, psurge, 0, psurge, psurge, timeplt_state, empty_init, ROT270, "Vision Electronics", "Power Surge", MACHINE_SUPPORTS_SAVE )
GAME( 1988, chkun, 0, chkun, chkun, timeplt_state, empty_init, ROT90, "Peni", "Chance Kun (Japan)", MACHINE_SUPPORTS_SAVE | MACHINE_IMPERFECT_SOUND )
GAME( 1987, bikkuric, 0, bikkuric, bikkuric, timeplt_state, empty_init, ROT90, "Peni", "Bikkuri Card (Japan)", MACHINE_SUPPORTS_SAVE )
|
.include "effect.h"
.include "symphony.h"
.bank 1
.org MMC1_PRG
palette:
.db $0f,$19,$2b,$39, $0f,$17,$16,$06, $0f,$39,$3a,$3b, $0f,$3d,$3e,$0f
.db $0f,$14,$27,$39, $0f,$27,$06,$2d, $0f,$0a,$29,$25, $0f,$02,$38,$3c
hello_string:
.db " Hello World!!!", $00
.org $fffa
reset_vectors:
.dw 0
.dw reset
.dw 0
.bank 2
.org $0000
tileset:
.incbin "tileset.chr"
|
;--------------------------------------------------------------------------------
; 291 - Moldorm Cave
; 286 - Northeast Dark Swamp Cave
;--------------------------------------------------------------------------------
!BIGRAM = "$7EC900";
;--------------------------------------------------------------------------------
!SPRITE_OAM = "$7EC025"
; A = Tile ID
macro UploadOAM(dest)
PHA : PHP
PHA
REP #$20 ; set 16-bit accumulator
LDA.w #$0000 : STA.l !SPRITE_OAM
STA.l !SPRITE_OAM+2
LDA.w #$0200 : STA.l !SPRITE_OAM+6
SEP #$20 ; set 8-bit accumulator
LDA.b <dest> : STA.l !SPRITE_OAM+4
LDA $01,s
JSL.l GetSpritePalette
STA !SPRITE_OAM+5 : STA !SPRITE_OAM+13
PLA
JSL.l IsNarrowSprite : BCS .narrow
BRA .done
.narrow
REP #$20 ; set 16-bit accumulator
LDA.w #$0000 : STA.l !SPRITE_OAM+7
STA.l !SPRITE_OAM+14
LDA.w #$0800 : STA.l !SPRITE_OAM+9
LDA.w #$3400 : STA.l !SPRITE_OAM+11
.done
PLP : PLA
endmacro
;--------------------------------------------------------------------------------
; $0A : Digit Offset
; $0C-$0D : Value to Display
; $0E-$0F : Base Coordinate
;--------------------------------------------------------------------------------
macro DrawDigit(value,offset)
STZ $0A ; clear digit buffer
LDA $0C ; load value
--
CMP.w <value> : !BLT ++
!SUB.w <value>
INC $0A
BRA --
++
STA $0C ; save value
CPY.b #$FF : BNE +
LDY.b <offset>
LDA $0E : !ADD.w .digit_offsets, Y : STA $0E
+
LDA $0E : STA !BIGRAM, X : INX : INX
LDA.w #56 : STA !BIGRAM, X : INX : INX
LDA $A0 : CMP.l #$109 : BNE + : LDA.w #$FFCA : STA !BIGRAM-2, X : +
LDY $0A : TYA : ASL : TAY : LDA.w .digit_properties, Y : STA !BIGRAM, X : INX : INX
LDA.w #$0000 : STA !BIGRAM, X : INX : INX
LDA $0E : !ADD.w #$0008 : STA $0E ; move offset 8px right
endmacro
;--------------------------------------------------------------------------------
!COLUMN_LOW = "$7F5022"
!COLUMN_HIGH = "$7F5023"
!SHOP_INVENTORY_PLAYER = "$7F5062"
!SHOP_INVENTORY = "$7F5052" ; $7F5056 - 5a - 5e
!SCRATCH_TEMP_X = "$7F506B"
DrawPrice:
STX $07
PHX : PHY : PHP
LDY.b #$FF
LDX #$00 ; clear bigram pointer
LDA $0C : CMP.w #1000 : !BLT + : BRL .len4 : +
CMP.w #100 : !BLT + : BRL .len3 : +
CMP.w #10 : !BLT + : BRL .len2 : +
CMP.w #1 : !BLT + : BRL .len1 : + JMP .len0
.len4
%DrawDigit(#1000,#6)
.len3
%DrawDigit(#100,#4)
.len2
%DrawDigit(#10,#2)
.len1
%DrawDigit(#1,#0)
.len0
; set up shop shuffle star
; i set it all up before then backtrack (dex #8) because i hate 16-bit 8-bit accumulator logic mixups
LDA $0E : STA !BIGRAM, X : INX : INX ; change this to a set distance from center
LDA.w #36 : STA !BIGRAM, X : INX : INX
LDA $A0 : CMP.l #$109 : BNE + : LDA.w #$FFAA : STA !BIGRAM-2, X : +
LDA.w #$0391 : STA !BIGRAM, X : INX : INX ; Yellow Star
LDA.w #$0000 : STA !BIGRAM, X : INX : INX : STX $06
SEP #$20 ; set 8-bit accumulator
LDX $07 : LDA.l !SHOP_INVENTORY+3, X : CMP.b #$40 : !BGE +++ ; do not render on base items
; LDA.b $07 : LSR #2 : TAX : LDA.l !SHOP_INVENTORY_PLAYER, X : BEQ ++ ; use a different icon if multiworld
; LDX $06 : LDA.b #$09 : STA !BIGRAM-3, X : LDA.b #$92 : STA !BIGRAM-4, X : BRA ++++ : ++
LDX $06 : BRA ++++
+++ : LDX $06 : DEX #8
++++
TXA : LSR #3 : STA $06 ; request 1-4 OAM slots
ASL #2
PHA
LDA $22 : CMP !COLUMN_LOW : !BLT .off
CMP !COLUMN_HIGH : !BGE .off
.on
PLA : JSL.l OAM_AllocateFromRegionB : BRA + ; request 4-16 bytes
.off
PLA : JSL.l OAM_AllocateFromRegionA ; request 4-16 bytes
+
TXA : LSR #3
PLP : PLY : PLX
RTS
;--------------------------------------------------------------------------------
!TILE_UPLOAD_OFFSET_OVERRIDE = "$7F5042"
!FREE_TILE_BUFFER = "#$1180"
!SHOP_ENABLE_COUNT = "$7F504F"
!SHOP_ID = "$7F5050"
!SHOP_TYPE = "$7F5051"
;!SHOP_INVENTORY = "$7F5052" ; $7F5056 - 5a - 5e
;!SHOP_INVENTORY_PLAYER = "$7F5062"
!SHOP_INVENTORY_DISGUISE = "$7F5065" ; was going to remove this, but this lets more than one bee trap exist with its own icon. that might be excessive, but seeing two items obviously reveals if there's one or more beetraps
!SHOP_STATE = "$7F5069"
!SHOP_CAPACITY = "$7F506A"
;!SCRATCH_TEMP_X = "$7F506B"
!SHOP_SRAM_INDEX = "$7F506C"
!SHOP_MERCHANT = "$7F506D"
!SHOP_DMA_TIMER = "$7F506E"
!SHOP_KEEP_REFILL = "$7F506F"
;--------------------------------------------------------------------------------
!NMI_AUX = "$7F5044"
;--------------------------------------------------------------------------------
.digit_properties
dw $0230, $0231, $0202, $0203, $0212, $0213, $0222, $0223, $0232, $0233
;--------------------------------------------------------------------------------
.digit_offsets
dw 4, 0, -4, -8
;--------------------------------------------------------------------------------
SpritePrep_ShopKeeper:
PHX : PHY : PHP
REP #$30 ; set 16-bit accumulator & index registers
LDX.w #$0000
-
LDA ShopTable+1, X : CMP $A0 : BNE +
;LDA ShopTable+3, X : CMP $010E : BNE +
LDA ShopTable+5, X : AND.w #$0040 : BNE ++
LDA $7F5099 : AND #$00FF : CMP ShopTable+3, X : BNE +
++
SEP #$20 ; set 8-bit accumulator
LDA ShopTable, X : STA !SHOP_ID
LDA ShopTable+5, X : STA !SHOP_TYPE
AND.b #$03 : ASL #2 : STA !SHOP_CAPACITY
LDA ShopTable+6, X : STA !SHOP_MERCHANT
LDA ShopTable+7, X : STA !SHOP_SRAM_INDEX
BRA .success
+
LDA ShopTable, X : AND.w #$00FF : CMP.w #$00FF : BEQ .fail
INX #8 ;; width of shop table
BRA -
.fail
SEP #$20 ; set 8-bit accumulator
LDA.b #$FF : STA !SHOP_TYPE ; $FF = error condition
BRL .done
.success
SEP #$20 ; set 8-bit accumulator
LDX.w #$0000
LDY.w #$0000
-
TYA : CMP !SHOP_CAPACITY : !BLT ++ : BRL .stop : ++
LDA.l ShopContentsTable+1, X : CMP.b #$FF : BNE ++ : BRL .stop : ++
LDA.l ShopContentsTable, X : CMP !SHOP_ID : BEQ ++ : BRL .next : ++
LDA.l ShopContentsTable+1, X : PHX : TYX : STA.l !SHOP_INVENTORY, X : PLX
LDA.l ShopContentsTable+2, X : PHX : TYX : STA.l !SHOP_INVENTORY+1, X : PLX
LDA.l ShopContentsTable+3, X : PHX : TYX : STA.l !SHOP_INVENTORY+2, X : PLX
LDA.l ShopContentsTable+8, X : PHX : PHA : STA.l !MULTIWORLD_SPRITEITEM_PLAYER_ID
LDA #0 : XBA : TYA : LSR #2 : TAX ; This will convert the value back to the slot number (in 8-bit accumulator mode)
PLA : STA.l !SHOP_INVENTORY_PLAYER, X : LDA #0 : STA.l !SHOP_INVENTORY_DISGUISE, X : PLX
PHY
PHX
LDA.b #$00 : XBA : TYA : LSR #2 : !ADD !SHOP_SRAM_INDEX : TAX
LDA !SHOP_PURCHASE_COUNTS, X : TYX : STA.l !SHOP_INVENTORY+3, X : TAY
PLX
LDA.l ShopContentsTable+4, X : BEQ +
TYA : CMP.l ShopContentsTable+4, X : !BLT ++
PLY
LDA.l ShopContentsTable+5, X : PHX : TYX : STA.l !SHOP_INVENTORY, X : PLX
LDA.l ShopContentsTable+6, X : PHX : TYX : STA.l !SHOP_INVENTORY+1, X : PLX
LDA.l ShopContentsTable+7, X : PHX : TYX : STA.l !SHOP_INVENTORY+2, X : PLX
LDA #$40 : PHX : TYX : STA.l !SHOP_INVENTORY+3, X : PLX
PHX : LDA #0 : XBA : TYA : LSR #2 : TAX ; This will convert the value back to the slot number (in 8-bit accumulator mode)
LDA #0 : STA.l !SHOP_INVENTORY_PLAYER, X : PLX
BRA +++
+ : PLY : LDA #$40 : PHX : TYX : STA.l !SHOP_INVENTORY+3, X : PLX : BRA +++
++ : PLY : +++
PHX : PHY
PHX : TYX : LDA.l !SHOP_INVENTORY, X : PLX
CMP #$5A : BEQ ++
CMP #$B0 : BNE + : ++
PHX : LDA #0 : XBA : TYA : LSR #2 : TAX ; This will convert the value back to the slot number (in 8-bit accumulator mode)
JSL GetRandomInt : AND #$3F : STA !BEE_TRAP_DISGUISE
BNE ++ : LDA #$49 : ++ : CMP #$26 : BNE ++ : LDA #$6A : ++ ; if 0 (fighter's sword + shield), set to just sword, if filled container (bugged palette), switch to triforce piece
STA.l !SHOP_INVENTORY_DISGUISE, X : PLX
+ : TAY
REP #$20 ; set 16-bit accumulator
LDA 1,s : TAX : LDA.l .tile_offsets, X : TAX
JSR LoadTile
PLY : PLX
INY #4 ; width of shop inventory item
.next
INX #9 ; width of shop contents table
BRL -
.stop
LDA #$01 : STA !NMI_AUX+2 : STA !NMI_AUX
.done
LDA.l !SHOP_TYPE : BIT.b #$20 : BEQ .notTakeAll ; Take-all
.takeAll
LDA.b #$00 : XBA : LDA !SHOP_SRAM_INDEX : TAX
LDA.l !SHOP_PURCHASE_COUNTS, X
BRA ++
.notTakeAll
LDA.b #$00
++
STA !SHOP_STATE
; If the item is $FF, make it not show (as if already taken)
LDA !SHOP_INVENTORY : CMP.b #$FF : BNE +
LDA !SHOP_STATE : ORA.l Shopkeeper_ItemMasks : STA !SHOP_STATE
+
LDA !SHOP_INVENTORY+4 : CMP.b #$FF : BNE +
LDA !SHOP_STATE : ORA.l Shopkeeper_ItemMasks+1 : STA !SHOP_STATE
+
LDA !SHOP_INVENTORY+8 : CMP.b #$FF : BNE +
LDA !SHOP_STATE : ORA.l Shopkeeper_ItemMasks+2 : STA !SHOP_STATE
+
PLP : PLY : PLX
LDA.l !SHOP_TYPE : CMP.b #$FF : BNE +
PLA : PLA : PLA
INC $0BA0, X
LDA $0E40, X
JML.l ShopkeeperFinishInit
+
RTL
.tile_offsets
dw $0000, $0000
dw $0080, $0000
dw $0100, $0000
;--------------------------------------------------------------------------------
QueueItemDMA:
LDA.b #Shopkeeper_UploadVRAMTilesLong>>0 : STA !NMI_AUX
LDA.b #Shopkeeper_UploadVRAMTilesLong>>8 : STA !NMI_AUX+1
LDA.b #Shopkeeper_UploadVRAMTilesLong>>16 : STA !NMI_AUX+2
RTS
;--------------------------------------------------------------------------------
; X - Tile Buffer Offset
; Y - Item ID
LoadTile:
TXA : !ADD.w !FREE_TILE_BUFFER : STA !TILE_UPLOAD_OFFSET_OVERRIDE ; load offset from X
SEP #$30 ; set 8-bit accumulator & index registers
TYA ; load item ID from Y
JSL.l GetSpriteID ; convert loot id to sprite id
JSL.l GetAnimatedSpriteTile_variable
REP #$10 ; set 16-bit index registers
RTS
;--------------------------------------------------------------------------------
;!SHOP_INVENTORY, X
;[id][$lo][$hi][purchase_counter]
;--------------------------------------------------------------------------------
;!SHOP_PURCHASE_COUNTS = "$7EF302"
;--------------------------------------------------------------------------------
Shopkeeper_UploadVRAMTilesLong:
JSR.w Shopkeeper_UploadVRAMTiles
RTL
Shopkeeper_UploadVRAMTiles:
LDA $4300 : PHA ; preserve DMA parameters
LDA $4301 : PHA ; preserve DMA parameters
LDA $4302 : PHA ; preserve DMA parameters
LDA $4303 : PHA ; preserve DMA parameters
LDA $4304 : PHA ; preserve DMA parameters
LDA $4305 : PHA ; preserve DMA parameters
LDA $4306 : PHA ; preserve DMA parameters
;--------------------------------------------------------------------------------
LDA #$01 : STA $4300 ; set DMA transfer direction A -> B, bus A auto increment, double-byte mode
LDA #$18 : STA $4301 ; set bus B destination to VRAM register
LDA #$80 : STA $2115 ; set VRAM to increment by 2 on high register write
LDA #$80 : STA $4302 ; set bus A source address to tile buffer
LDA #$A1 : STA $4303
LDA #$7E : STA $4304
LDA !SHOP_TYPE : AND.b #$10 : BNE .special
BRL .normal
.special
LDA #$40 : STA $4305 : STZ $4306 ; set transfer size to 0x40
LDA #$40 : STA $2116 ; set VRAM register destination address
LDA #$5A : STA $2117
LDA #$01 : STA $420B ; begin DMA transfer
LDA #$40 : STA $4305 : STZ $4306 ; set transfer size to 0x40
LDA #$40 : STA $2116 ; set VRAM register destination address
LDA #$5B : STA $2117
LDA #$01 : STA $420B ; begin DMA transfer
LDA #$40 : STA $4305 : STZ $4306 ; set transfer size to 0x40
LDA #$60 : STA $2116 ; set VRAM register destination address
LDA #$5A : STA $2117
LDA #$01 : STA $420B ; begin DMA transfer
LDA #$40 : STA $4305 : STZ $4306 ; set transfer size to 0x40
LDA #$60 : STA $2116 ; set VRAM register destination address
LDA #$5B : STA $2117
LDA #$01 : STA $420B ; begin DMA transfer
LDA #$40 : STA $4305 : STZ $4306 ; set transfer size to 0x40
LDA #$80 : STA $2116 ; set VRAM register destination address
LDA #$5A : STA $2117
LDA #$01 : STA $420B ; begin DMA transfer
LDA #$40 : STA $4305 : STZ $4306 ; set transfer size to 0x40
LDA #$80 : STA $2116 ; set VRAM register destination address
LDA #$5B : STA $2117
LDA #$01 : STA $420B ; begin DMA transfer
BRL .end
.normal
LDA #$40 : STA $4305 : STZ $4306 ; set transfer size to 0x40
LDA #$60 : STA $2116 ; set VRAM register destination address
LDA #$5C : STA $2117
LDA #$01 : STA $420B ; begin DMA transfer
LDA #$40 : STA $4305 : STZ $4306 ; set transfer size to 0x40
LDA #$60 : STA $2116 ; set VRAM register destination address
LDA #$5D : STA $2117
LDA #$01 : STA $420B ; begin DMA transfer
LDA #$40 : STA $4305 : STZ $4306 ; set transfer size to 0x40
LDA #$80 : STA $2116 ; set VRAM register destination address
LDA #$5C : STA $2117
LDA #$01 : STA $420B ; begin DMA transfer
LDA #$40 : STA $4305 : STZ $4306 ; set transfer size to 0x40
LDA #$80 : STA $2116 ; set VRAM register destination address
LDA #$5D : STA $2117
LDA #$01 : STA $420B ; begin DMA transfer
LDA #$40 : STA $4305 : STZ $4306 ; set transfer size to 0x40
LDA #$A0 : STA $2116 ; set VRAM register destination address
LDA #$5C : STA $2117
LDA #$01 : STA $420B ; begin DMA transfer
LDA #$40 : STA $4305 : STZ $4306 ; set transfer size to 0x40
LDA #$A0 : STA $2116 ; set VRAM register destination address
LDA #$5D : STA $2117
LDA #$01 : STA $420B ; begin DMA transfer
;--------------------------------------------------------------------------------
.end
PLA : STA $4306 ; restore DMA parameters
PLA : STA $4305 ; restore DMA parameters
PLA : STA $4304 ; restore DMA parameters
PLA : STA $4303 ; restore DMA parameters
PLA : STA $4302 ; restore DMA parameters
PLA : STA $4301 ; restore DMA parameters
PLA : STA $4300 ; restore DMA parameters
RTS
;--------------------------------------------------------------------------------
Shopkepeer_CallOriginal:
PLA : PLA : PLA
LDA.b #ShopkeeperJumpTable>>16 : PHA
LDA.b #ShopkeeperJumpTable>>8 : PHA
LDA.b #ShopkeeperJumpTable : PHA
LDA $0E80, X
JML.l UseImplicitRegIndexedLocalJumpTable
;--------------------------------------------------------------------------------
;!SHOP_TYPE = "$7F5051"
;!SHOP_CAPACITY = "$7F5020"
;!SCRATCH_TEMP_X = "$7F5021"
Sprite_ShopKeeperPotion:
PHB : PHK : PLB ;; we can just call the default shopkeeper but the potion shopkeeper refills your health
LDA $A0 : CMP.b #$09 : BNE +
JSR.w Shopkeeper_DrawItems
JSR.w Shopkeeper_SetupHitboxes
+
PLB
RTL
Sprite_ShopKeeper:
LDA.l !SHOP_TYPE : CMP.b #$FF : BNE + : JMP.w Shopkepeer_CallOriginal : +
PHB : PHK : PLB
JSL.l Sprite_PlayerCantPassThrough
; Draw Shopkeeper
JSR.w Shopkeeper_DrawMerchant
LDA.l !SHOP_TYPE : BIT.b #$80 : BEQ .normal ; Take-any
BIT.b #$20 : BNE + ; Not A Take-All
PHX
LDA !SHOP_SRAM_INDEX : TAX
LDA !SHOP_PURCHASE_COUNTS, X : BEQ ++ : PLX : BRA .done : ++
PLX
BRA .normal
+ ; Take-All
;PHX
; LDA !SHOP_SRAM_INDEX : TAX
; LDA.w !SHOP_PURCHASE_COUNTS, X : STA.l !SHOP_STATE
;PLX
.normal
; Draw Items
JSR.w Shopkeeper_DrawItems
; Set Up Hitboxes
JSR.w Shopkeeper_SetupHitboxes
; $22
; 0x48 - Left
; 0x60 - Midpoint 1
; 0x78 - Center
; 0x90 - Midpoint 2
; 0xA8 - Right
.done
PLB
RTL
;--------------------------------------------------------------------------------
macro DrawMerchant(head,body,speed)
PHX : LDX.b #$00
LDA $1A : AND <speed> : BEQ +
-
LDA.w .oam_shopkeeper_f1, X : STA !BIGRAM, X : INX
CPX.b #$10 : !BLT -
+
-
LDA.w .oam_shopkeeper_f2, X : STA !BIGRAM, X : INX
CPX.b #$10 : !BLT -
++
PLX
LDA !SHOP_MERCHANT : LSR #4 : AND.b #$0E : ORA !BIGRAM+5 : STA !BIGRAM+5
LDA !SHOP_MERCHANT : LSR #4 : AND.b #$0E : ORA !BIGRAM+13 : STA !BIGRAM+13
PHB
LDA.b #$02 : STA $06 ; request 2 OAM slots
LDA #$08 : JSL.l OAM_AllocateFromRegionA ; request 8 bytes
STZ $07
LDA.b #!BIGRAM : STA $08
LDA.b #!BIGRAM>>8 : STA $09
LDA.b #$7E : PHA : PLB ; set data bank to $7E
JSL.l Sprite_DrawMultiple_quantity_preset
LDA $90 : !ADD.b #$04*2 : STA $90 ; increment oam pointer
LDA $92 : INC #2 : STA $92
PLB
RTS
.oam_shopkeeper_f1
dw 0, -8 : db <head>, $00, $00, $02
dw 0, 0 : db <body>, $00, $00, $02
.oam_shopkeeper_f2
dw 0, -8 : db <head>, $00, $00, $02
dw 0, 0 : db <body>, $40, $00, $02
endmacro
;--------------------------------------------------------------------------------
Shopkeeper_DrawMerchant:
LDA.l !SHOP_MERCHANT : AND.b #$07
BEQ Shopkeeper_DrawMerchant_Type0
CMP.b #$01 : BNE + : BRL Shopkeeper_DrawMerchant_Type1 : +
CMP.b #$02 : BNE + : BRL Shopkeeper_DrawMerchant_Type2 : +
CMP.b #$03 : BNE + : BRL Shopkeeper_DrawMerchant_Type3 : +
CMP.b #$04 : BNE + : RTS : +
;--------------------------------------------------------------------------------
Shopkeeper_DrawMerchant_Type0:
%DrawMerchant(#$00, #$10, #$10)
;--------------------------------------------------------------------------------
Shopkeeper_DrawMerchant_Type1:
LDA.b #$01 : STA $06 ; request 1 OAM slot
LDA #$04 : JSL.l OAM_AllocateFromRegionA ; request 4 bytes
STZ $07
LDA $1A : AND #$08 : BEQ +
LDA.b #.oam_shopkeeper_f1 : STA $08
LDA.b #.oam_shopkeeper_f1>>8 : STA $09
BRA ++
+
LDA.b #.oam_shopkeeper_f2 : STA $08
LDA.b #.oam_shopkeeper_f2>>8 : STA $09
++
JSL.l Sprite_DrawMultiple_quantity_preset
LDA $90 : !ADD.b #$04 : STA $90 ; increment oam pointer
LDA $92 : INC : STA $92
RTS
.oam_shopkeeper_f1
dw 0, 0 : db $46, $0A, $00, $02
.oam_shopkeeper_f2
dw 0, 0 : db $46, $4A, $00, $02
;--------------------------------------------------------------------------------
Shopkeeper_DrawMerchant_Type2:
%DrawMerchant(#$84, #$10, #$40)
;--------------------------------------------------------------------------------
Shopkeeper_DrawMerchant_Type3:
%DrawMerchant(#$8E, #$10, #$40)
;--------------------------------------------------------------------------------
Shopkeeper_SetupHitboxes:
PHX : PHY : PHP
LDY.b #$00
-
PHY
TYA : LSR #2 : TAY
LDA.l !SHOP_STATE : AND.w Shopkeeper_ItemMasks, Y : BEQ +
PLY : BRA .no_interaction
+
PLY
LDA $00EE : CMP $0F20, X : BNE .no_interaction
JSR.w Setup_LinksHitbox
JSR.w Setup_ShopItemCollisionHitbox
JSL.l Utility_CheckIfHitBoxesOverlapLong
BCC .no_contact
JSR.w Sprite_HaltSpecialPlayerMovementCopied
.no_contact
JSR.w Setup_ShopItemInteractionHitbox
JSL.l Utility_CheckIfHitBoxesOverlapLong : BCC .no_interaction
LDA $02DA : BNE .no_interaction ; defer if link is buying a potion (this is faster than the potion buying speed before potion shop shuffle)
LDA $F6 : AND.b #$80 : BEQ .no_interaction ; check for A-press
LDA $10 : CMP.b #$0C : !BGE .no_interaction ; don't interact in other modes besides game action
JSR.w Shopkeeper_BuyItem
.no_interaction
INY #4
TYA : CMP !SHOP_CAPACITY : !BLT -
;CPY.b #$0C : !BLT -
PLP : PLY : PLX
RTS
!LOCK_STATS = "$7EF443"
!ITEM_TOTAL = "$7EF423"
;--------------------
;!SHOP_STATE
Shopkeeper_BuyItem:
PHX : PHY
TYX
LDA.l !SHOP_INVENTORY, X
CMP.b #$0E : BEQ .refill ; Bee Refill
CMP.b #$2E : BEQ .refill ; Red Potion Refill
CMP.b #$2F : BEQ .refill ; Green Potion Refill
CMP.b #$30 : BEQ .refill ; Blue Potion Refill
CMP.b #$B2 : BEQ .refill ; Good Bee Refill
BRA +
.refill
JSL.l Sprite_GetEmptyBottleIndex : BMI .full_bottles
LDA #$1 : STA !SHOP_KEEP_REFILL ; If this is on, don't toggle bit to remove from shop
+
LDA !SHOP_TYPE : AND.b #$80 : BNE .check_take_any ; don't charge if this is a take-any
REP #$20 : LDA $7EF360 : CMP.l !SHOP_INVENTORY+1, X : SEP #$20 : !BGE .buy
.cant_afford
LDA.b #$7A : LDY.b #$01 : JSL.l Sprite_ShowMessageUnconditional
LDA.b #$3C : STA $012E ; error sound
BRL .done
.full_bottles
LDA.b #$6B : LDY.b #$01 : JSL.l Sprite_ShowMessageUnconditional
LDA.b #$3C : STA $012E ; error sound
BRL .done
.check_take_any
LDA !SHOP_TYPE : AND.b #$08 : BEQ .buy
; old man sword cave -- check hearts
JSR CheckSwordCaveHearts : BCC .buy
; not enough hearts
CLC : LDA.b #$97 : LDY.b #$01 : JSL.l Sprite_ShowMessageUnconditional
LDA.b #$3C : STA $012E ; error sound
BRL .done
.buy
LDA !SHOP_TYPE : AND.b #$80 : BNE ++ ; don't charge if this is a take-any
REP #$20 : LDA $7EF360 : !SUB !SHOP_INVENTORY+1, X : STA $7EF360 : SEP #$20 ; Take price away
++
.buy_real
print "Shop Check: ", pc
PHX
LDA #0 : XBA : TXA : LSR #2 : TAX : LDA.l !SHOP_INVENTORY_PLAYER, X : STA !MULTIWORLD_ITEM_PLAYER_ID
LDA.l !SHOP_TYPE : BIT.b #$80 : BNE + ;Is the shop location a take-any cave
TXA : !ADD !SHOP_SRAM_INDEX : TAX : BRA ++ ;If so, explicitly load first SRAM Slot.
+ LDA.l !SHOP_SRAM_INDEX : TAX
++ LDA.l !SHOP_PURCHASE_COUNTS, X : BNE +++ ;Is this the first time buying this slot?
LDA.l EnableShopItemCount, X : STA.l !SHOP_ENABLE_COUNT ; If so, store the permission to count the item here.
+++
PLX
LDA.l !SHOP_INVENTORY, X : TAY : JSL.l Link_ReceiveItem
LDA.l !SHOP_INVENTORY+3, X : INC : STA.l !SHOP_INVENTORY+3, X
LDA.b #0 : STA.l !SHOP_ENABLE_COUNT
TXA : LSR #2 : TAX
LDA !SHOP_TYPE : BIT.b #$80 : BNE +
LDA !SHOP_KEEP_REFILL : BNE +++
LDA.l !SHOP_STATE : ORA.w Shopkeeper_ItemMasks, X : STA.l !SHOP_STATE
+++
PHX
TXA : !ADD !SHOP_SRAM_INDEX : TAX
LDA !SHOP_PURCHASE_COUNTS, X : INC : BEQ +++ : STA !SHOP_PURCHASE_COUNTS, X : +++
LDA.l RetroArrowShopBoughtMask, X : BEQ ++++ ; Confirm purchase was of a retro single arrow slot.
LDA.l RetroArrowShopList : PHX : TAX : LDA.l !SHOP_PURCHASE_COUNTS, X : BEQ +++ : PLX : BRA ++++ : +++ : PLX ; Check to see if all shop locationss already marked.
LDA.l RetroArrowShopBoughtMask, X : BEQ ++++ : ORA.l !SHOP_STATE : STA.l !SHOP_STATE ; Prevent purchase of other single arrows in same shop.
LDX #$00
- LDA.l RetroArrowShopList, X : BMI ++++ ; If end of list, stop here.
PHX : TAX
LDA !SHOP_PURCHASE_COUNTS, X : BNE +++
INC : STA !SHOP_PURCHASE_COUNTS, X
LDA !LOCK_STATS : BNE +++
LDA.l EnableShopItemCount, X : BEQ +++
REP #$20 : LDA !ITEM_TOTAL : INC : STA !ITEM_TOTAL : SEP #$20
+++
PLX
INX
BRA -
++++
PLX
BRA ++
+ ; Take-any
;STA $FFFFFF
BIT.b #$20 : BNE .takeAll
.takeAny
LDA.l !SHOP_STATE : ORA.b #$07 : STA.l !SHOP_STATE
PHX
LDA.l !SHOP_SRAM_INDEX : TAX : LDA.b #$01 : STA.l !SHOP_PURCHASE_COUNTS, X
PLX
BRA ++
.takeAll
LDA.l !SHOP_STATE : ORA.w Shopkeeper_ItemMasks, X : STA.l !SHOP_STATE
PHX
LDA.l !SHOP_SRAM_INDEX : TAX : LDA.l !SHOP_STATE : STA.l !SHOP_PURCHASE_COUNTS, X
PLX
++
; JSL SpritePrep_ShopKeeper ;; reloads entire shop again
.done
LDA #$0 : STA !SHOP_KEEP_REFILL
PLY : PLX
RTS
Shopkeeper_ItemMasks:
db #$01, #$02, #$04, #$08
;--------------------
;!SHOP_ID = "$7F5050"
;!SHOP_SRAM_INDEX = "$7F5062"
;!SHOP_PURCHASE_COUNTS = "$7EF302"
;--------------------
Setup_ShopItemCollisionHitbox:
;The complications with XBA are to handle the fact that nintendo likes to store
;high and low bytes of 16 bit postion values seperately :-(
REP #$20 ; set 16-bit accumulator
LDA $00 : PHA
SEP #$20 ; set 8-bit accumulator
; load shopkeeper X (16 bit)
LDA $0D30, X : XBA : LDA $0D10, X
REP #$20 ; set 16-bit accumulator
PHA : PHY
LDA !SHOP_TYPE : AND.w #$0003 : DEC : ASL : TAY
LDA $A0 : CMP.l #$109 : BNE + : INY #6 : +
LDA.w Shopkeeper_DrawNextItem_item_offsets_idx, Y : STA $00 ; get table from the table table
PLY : PLA
!ADD ($00), Y
!ADD.w #$0002 ; a small negative margin
; TODO: add 4 for a narrow item
SEP #$20 ; set 8-bit accumulator
; store hitbox X
STA $04 : XBA : STA $0A
;load shopkeeper Y (16 bit)
LDA $0D20, X : XBA : LDA $0D00, X
REP #$20 ; set 16-bit accumulator
PHY : INY #2
!ADD ($00), Y
PLY
PHA : LDA !SHOP_TYPE : AND.w #$0080 : BEQ + ; lower by 4 for Take-any
PLA : !ADD.w #$0004
BRA ++
+ : PLA : ++
SEP #$20 ; set 8-bit accumulator
; store hitbox Y Low: $05, High $0B
STA $05 : XBA : STA $0B
LDA.b #12 : STA $06 ; Hitbox width, always 12 for existing (wide) shop items
; TODO: for narrow sprite store make width 4 (i.e. 8 pixels smaller)
LDA.b #14 : STA $07 ; Hitbox height, always 14
REP #$20 ; set 16-bit accumulator
PLA : STA $00
SEP #$20 ; set 8-bit acc
RTS
;--------------------------------------------------------------------------------
; Adjusts the already set up collision hitbox to be a suitable interaction hitbox
Setup_ShopItemInteractionHitbox:
PHP
SEP #$20 ; set 8-bit accumulator
; collision hitbox has left margin of -2, we want margin of 8 so we subtract 10
LDA $04 : !SUB.b #$0A : STA $04
LDA $0A : SBC.b #$00 : STA $0A ; Apply borrow
; collision hitbox has 0 top margin, we want a margin of 8 so we subtract 8
LDA $05 : !SUB.b #$08 : STA $05
LDA $0B : SBC.b #$00 : STA $0B ; Apply borrow
; We want a width of 32 for wide or 24 for narrow, so we add 20
LDA $06 : !ADD.b #20 : STA $06 ; Hitbox width
LDA.b #40 : STA $07 ; Hitbox height, always 40
PLP
RTS
;--------------------------------------------------------------------------------
; Following is a copy of procedure $3770A (Bank06.asm Line 6273)
; because there is no long version available
Setup_LinksHitbox:
LDA.b #$08 : STA $02
STA $03
LDA $22 : !ADD.b #$04 : STA $00
LDA $23 : ADC.b #$00 : STA $08
LDA $20 : ADC.b #$08 : STA $01
LDA $21 : ADC.b #$00 : STA $09
RTS
;--------------------------------------------------------------------------------
; The following is a copy of procedure Sprite_HaltSpecialPlayerMovement (Bank1E.asm line 255)
; because there is no long version available
Sprite_HaltSpecialPlayerMovementCopied:
PHX
JSL Sprite_NullifyHookshotDrag
STZ $5E ; Set Link's speed to zero...
JSL Player_HaltDashAttackLong
PLX
RTS
;--------------------------------------------------------------------------------
;!SHOP_TYPE = "$7F5051"
;!SHOP_INVENTORY = "$7F5052"
!SPRITE_OAM = "$7EC025"
!REDRAW = "$7F5000"
Shopkeeper_DrawItems:
PHB : PHK : PLB
PHX : PHY
TXA : STA !SCRATCH_TEMP_X;
LDX.b #$00
LDY.b #$00
LDA !SHOP_TYPE : AND.b #$03
CMP.b #$03 : BNE +
JSR.w Shopkeeper_DrawNextItem : BRA ++
+ CMP.b #$02 : BNE + : ++
JSR.w Shopkeeper_DrawNextItem : BRA ++
+ CMP.b #$01 : BNE + : ++
JSR.w Shopkeeper_DrawNextItem
+
LDA $A0 : CMP.b #$09 : BNE + ; render powder slot if potion shop
LDA !REDRAW : BNE + ; if not redrawing
LDA $02DA : BNE + ; if not buying item
LDA $7F505E : BEQ + ; if potion slot filled
LDA $0ABF : BEQ + ; haven't left the room
LDA !NPC_FLAGS_2 : AND.b #$20 : BNE +
LDX.b #$0C : LDY.b #$03 : JSR.w Shopkeeper_DrawNextItem
+
PLY : PLX
PLB
RTS
;--------------------------------------------------------------------------------
Shopkeeper_DrawNextItem:
LDA.l !SHOP_STATE : AND.w Shopkeeper_ItemMasks, Y : BEQ + : BRL .next : +
PHY
LDA !SHOP_TYPE : AND.b #$03 : DEC : ASL : TAY
REP #$20 ; set 16-bit accumulator
LDA $A0 : CMP.l #$109 : BNE + : INY #6 : +
LDA.w .item_offsets_idx, Y : STA $00 ; get table from the table table
LDA 1,s : ASL #2 : TAY ; set Y to the item index
LDA ($00), Y : STA.l !SPRITE_OAM ; load X-coordinate
INY #2
LDA !SHOP_TYPE : AND.w #$0080 : BNE +
LDA ($00), Y : STA.l !SPRITE_OAM+2 : BRA ++ ; load Y-coordinate
+
LDA ($00), Y : !ADD.w #$0004 : STA.l !SPRITE_OAM+2 ; load Y-coordinate
++
SEP #$20 ; set 8-bit accumulator
PLY
PHX : LDA #0 : XBA : TXA : LSR #2 : TAX : LDA.l !SHOP_INVENTORY_DISGUISE, X : PLX : CMP #$0 : BNE ++
LDA.l !SHOP_INVENTORY, X ; get item palette
++
; Replace some items with graphics already loaded in VRAM
CMP.b #$2E : BNE + : LDA.b #$C0 : BRA .got_gfx : + ; Red Potion
CMP.b #$2F : BNE + : LDA.b #$E0 : BRA .got_gfx : + ; Green Potion
CMP.b #$30 : BNE + : LDA.b #$E2 : BRA .got_gfx : + ; Blue Potion
CMP.b #$B1 : BNE + : LDA.b #$EA : BRA .got_gfx : + ; Fairy
CMP.b #$B4 : BNE + : LDA.b #$E5 : BRA .got_gfx : + ; Apple (cleaner graphics in VRAM with a different palette)
; Use graphics we loaded for any others
LDA.w .tile_indices, Y ; get item gfx index
.got_gfx
XBA
LDA !SHOP_TYPE : AND.b #$10 : BEQ +
XBA : !SUB #$22 : XBA ; alt vram
+
XBA
STA.l !SPRITE_OAM+4
PHX : LDA #0 : XBA : TXA : LSR #2 : TAX : LDA.l !SHOP_INVENTORY_DISGUISE, X : PLX : CMP #$0 : BNE ++
LDA.l !SHOP_INVENTORY, X ; get item palette
++
; Same as above but with palettes
CMP.b #$B4 : BNE + : LDA.b #$02 : BRA .got_pal : + ; Apple (cleaner graphics in VRAM with a different palette)
JSL.l GetSpritePalette
.got_pal
STA.l !SPRITE_OAM+5
LDA.l !SPRITE_OAM+4 : CMP #$EA : BEQ .swap_sheet : CMP #$E4 : BEQ .swap_sheet : CMP #$62 : BEQ .swap_sheet : CMP #$E5 : BEQ .swap_sheet
AND #$FE : STA.l !SPRITE_OAM+4 ; if normal indices, strip last bit so it's even on the sprite sheet
LDA.w .tile_indices, Y : AND.b #$01 : BEQ +; get tile index sheet (swap sheet if we're using the upper tiles)
.swap_sheet
LDA.l !SPRITE_OAM+5
ORA.b #$1
STA.l !SPRITE_OAM+5
+
LDA.b #$00 : STA.l !SPRITE_OAM+6
PHX : LDA #0 : XBA : TXA : LSR #2 : TAX : LDA.l !SHOP_INVENTORY_DISGUISE, X : PLX : CMP #$0 : BNE ++
LDA.l !SHOP_INVENTORY, X ; get item id for narrowness
++
JSL.l IsNarrowSprite : BCS .narrow
.full
LDA.b #$02
STA.l !SPRITE_OAM+7
LDA.b #$01
BRL ++
.single
LDA.b #$00
STA.l !SPRITE_OAM+7
JSR.w PrepNarrowLower
LDA.b #$01
BRA ++
.narrow
LDA.b #$00
STA.l !SPRITE_OAM+7
JSR.w PrepNarrowLower
LDA.b #$02
++
PHX : PHA : LDA !SCRATCH_TEMP_X : TAX : PLA : JSR.w RequestItemOAM : PLX
LDA !SHOP_TYPE : AND.b #$80 : BNE +
CPX.b #12 : BEQ + ; don't render potion price
JSR.w Shopkeeper_DrawNextPrice
+
.next
INY
INX #4
RTS
;--------------------------------------------------------------------------------
.item_offsets_idx ; 112 60
dw #.item_offsets_1
dw #.item_offsets_2
dw #.item_offsets_3
.item_offsets_idx_Potion ; 160 176 - (112 64) = (48 112)
dw #.item_offsets_1p
dw #.item_offsets_2p
dw #.item_offsets_3p
.item_offsets_1
dw 8, 40
.item_offsets_2
dw -16, 40
dw 32, 40
.item_offsets_3
dw -40, 40
dw 8, 40
dw 56, 40
.item_offsets_1p
dw -40, -72
.item_offsets_2p
dw -64, -72
dw -16, -72
.item_offsets_3p
dw -88, -72
dw -40, -72
dw 8, -72
.potion_offset
dw -16, 0
.tile_indices
db $C6, $C8, $CA, $25 ; last bit is for sheet change
;--------------------------------------------------------------------------------
!COLUMN_LOW = "$7F5022"
!COLUMN_HIGH = "$7F5023"
Shopkeeper_DrawNextPrice:
PHB : PHK : PLB
PHX : PHY : PHP
REP #$20 ; set 16-bit accumulator
PHY
LDA !SHOP_TYPE : AND.w #$0003 : DEC : ASL : TAY
LDA $A0 : CMP.l #$109 : BNE + : INY #6 : +
LDA.w Shopkeeper_DrawNextItem_item_offsets_idx, Y : STA $00 ; get table from the table table
LDA.w .price_columns_idx, Y : STA $02 ; get table from the table table
PLY : PHY
TYA : ASL #2 : TAY
LDA ($00), Y : STA $0E ; set coordinate
TYA : LSR : TAY
LDA ($02), Y : STA !COLUMN_LOW
INY : LDA ($02), Y : STA !COLUMN_HIGH
PLY
LDA.l !SHOP_INVENTORY+1, X : STA $0C ; set value
JSR.w DrawPrice
SEP #$20 : STA $06 : STZ $07 ; set 8-bit accumulator & store result
PHA
LDA.b #!BIGRAM : STA $08
LDA.b #!BIGRAM>>8 : STA $09
LDA.b #$7E : PHA : PLB ; set data bank to $7E
PHX : PHA : LDA !SCRATCH_TEMP_X : TAX : PLA : JSL.l Sprite_DrawMultiple_quantity_preset : PLX
LDA 1,s
ASL #2 : !ADD $90 : STA $90 ; increment oam pointer
PLA
!ADD $92 : STA $92
PLP : PLY : PLX
PLB
RTS
.price_columns_idx
dw #.price_columns_1
dw #.price_columns_2
dw #.price_columns_3
.price_columns_1
db #$00, #$FF
.price_columns_2
db #$00, #$80, #$80, $FF
.price_columns_3
db #$00, #$60, #$60, #$90, #$90, $FF, $FF, $FF
;--------------------------------------------------------------------------------
RequestItemOAM:
PHX : PHY : PHA
STA $06 ; request A OAM slots
LDA $20 : CMP.b #$62 : !BGE .below
.above
LDA 1,s : ASL #2 : JSL.l OAM_AllocateFromRegionA ; request 4A bytes
BRA +
.below
LDA 1,s : ASL #2 : JSL.l OAM_AllocateFromRegionB ; request 4A bytes
+
LDA 1,s : STA $06 ; request 3 OAM slots
STZ $07
LDA.b #!SPRITE_OAM : STA $08
LDA.b #!SPRITE_OAM>>8 : STA $09
LDA #$7E : PHB : PHA : PLB
JSL Sprite_DrawMultiple_quantity_preset
PLB
LDA 1,s : ASL #2 : !ADD $90 : STA $90 ; increment oam pointer
LDA $92 : !ADD 1,s : STA $92
PLA : PLY : PLX
RTS
;--------------------------------------------------------------------------------
PrepNarrowLower:
PHX
LDX.b #$00
REP #$20 ; set 16-bit accumulator
LDA !SPRITE_OAM, X : !ADD.w #$0004 : STA !SPRITE_OAM, X : STA !SPRITE_OAM+8, X
LDA !SPRITE_OAM+2, X : !ADD.w #$0008 : STA !SPRITE_OAM+10, X
LDA !SPRITE_OAM+4, X : !ADD.w #$0010 : STA !SPRITE_OAM+12, X
LDA !SPRITE_OAM+6, X : STA !SPRITE_OAM+14, X
SEP #$20 ; set 8-bit accumulator
PLX
RTS
;--------------------------------------------------------------------------------
;.oam_items
;dw -40, 40 : db $C0, $08, $00, $02
;dw 8, 40 : db $C2, $04, $00, $02
;dw 56, 40 : db $C4, $02, $00, $02
;--------------------------------------------------------------------------------
;.oam_prices
;dw -48, 56 : db $30, $02, $00, $00
;dw -40, 56 : db $31, $02, $00, $00
;dw -32, 56 : db $02, $02, $00, $00
;dw -24, 56 : db $03, $02, $00, $00
;
;dw 0, 56 : db $12, $02, $00, $00
;dw 8, 56 : db $13, $02, $00, $00
;dw 16, 56 : db $22, $02, $00, $00
;dw 24, 56 : db $23, $02, $00, $00
;
;dw 48, 56 : db $32, $02, $00, $00
;dw 56, 56 : db $33, $02, $00, $00
;dw 64, 56 : db $30, $02, $00, $00
;dw 72, 56 : db $31, $02, $00, $00
;--------------------------------------------------------------------------------
; Returns heart requirement in A
GetSwordCaveHearts:
LDA.l !SHOP_INVENTORY, X
CMP.b #$5E : BNE + : LDA.l $7EF359 ; Progressive Sword -- load in current sword
+ : CMP.b #$50 : BNE + : LDA #$30 : RTS ; Master Sword (safe)
+ : CMP.b #$01 : BNE + : LDA #$30 : RTS ; Master Sword
+ : CMP.b #$02 : BNE + : LDA #$50 : RTS ; Tempered Sword
+ : CMP.b #$03 : BNE + : LDA #$80 : RTS ; Golden Sword
+ : LDA #$00 : RTS ; Fighter's Sword or something else
; Returns carry set on fail, clear on pass
CheckSwordCaveHearts:
LDA $00 : PHA ; Use $00 for our own purposes, we'll put it back after
JSR GetSwordCaveHearts : STA $00
LDA $7EF36C : CMP $00 : !BLT ++ ; Load in player max health and compare
CLC : BRA + ; Set enough hearts
++
SEC ; Set not enough hearts
+
PLA : STA $00 : RTS ; Restore $00 before returning
;--------------------------------------------------------------------------------
|
; A127230: a(n) = (2n)! - 1.
; 1,23,719,40319,3628799,479001599,87178291199,20922789887999,6402373705727999,2432902008176639999,1124000727777607679999,620448401733239439359999,403291461126605635583999999,304888344611713860501503999999,265252859812191058636308479999999
mul $0,2
add $0,2
seq $0,142 ; Factorial numbers: n! = 1*2*3*4*...*n (order of symmetric group S_n, number of permutations of n letters).
sub $0,1
|
/*
* RungeKutta4.hh
*
* created on: 22.04.2015
* author: rungger
*/
/** @file **/
#ifndef RUNGEKUTTA4_HH_
#define RUNGEKUTTA4_HH_
/** @namespace scots **/
namespace scots {
/**
*
* @brief Fixed step size ODE solver implementing a RungeKutta scheme of order 4
*
* @param rhs - lambda expression implementing the rhs of the ode
* \f[ \dot \xi(t) = rhs(\xi(t),u), \xi(0)=x \f]
* with signature
* \verbatim [] (state_type& xx, const state_type &x, const input_type &u) -> void \endverbatim
* @param x - state_type initial state x
* @param u - input_type constant input u
* @param dim - state space dimension
* @param tau - sampling time
* @param nint - number of intermediate steps (default = 10)
* @return the solution of IVP at time tau \f$ \xi(\tau) \f$ stored in x
**/
template<class RHS, class state_type, class input_type>
void runge_kutta_fixed4(RHS rhs, state_type &x, input_type &u, const int dim, const double tau, const int nint=10) noexcept {
state_type k[4];
state_type tmp;
double h=tau/(double)nint;
for(int t=0; t<nint; t++) {
rhs(k[0],x,u);
for(int i=0;i<dim;i++)
tmp[i]=x[i]+h/2*k[0][i];
rhs(k[1],tmp, u);
for(int i=0;i<dim;i++)
tmp[i]=x[i]+h/2*k[1][i];
rhs(k[2],tmp, u);
for(int i=0;i<dim;i++)
tmp[i]=x[i]+h*k[2][i];
rhs(k[3],tmp, u);
for(int i=0; i<dim; i++)
x[i] = x[i] + (h/6)*(k[0][i] + 2*k[1][i] + 2*k[2][i] + k[3][i]);
}
}
} /* close namespace */
#endif /* RUNGEKUTTA4_HH_ */
|
; A253946: a(n) = 6*binomial(n+1, 6).
; 6,42,168,504,1260,2772,5544,10296,18018,30030,48048,74256,111384,162792,232560,325584,447678,605682,807576,1062600,1381380,1776060,2260440,2850120,3562650,4417686,5437152,6645408,8069424,9738960,11686752,13948704,16564086,19575738,23030280,26978328,31474716,36578724,42354312,48870360,56200914,64425438,73629072,83902896,95344200,108056760,122151120,137744880,154962990,173938050,194810616,217729512,242852148,270344844,300383160,333152232,368847114,407673126,449846208,495593280,545152608,598774176
add $0,6
bin $0,6
mul $0,6
|
;******************************************************************************
;* Core video DSP functions
;* Copyright (c) 2012 Ronald S. Bultje <rsbultje@gmail.com>
;*
;* This file is part of FFmpeg.
;*
;* FFmpeg is free software; you can redistribute it and/or
;* modify it under the terms of the GNU Lesser General Public
;* License as published by the Free Software Foundation; either
;* version 2.1 of the License, or (at your option) any later version.
;*
;* FFmpeg is distributed in the hope that it will be useful,
;* but WITHOUT ANY WARRANTY; without even the implied warranty of
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************
%include "libavutil/x86/x86util.asm"
SECTION .text
; slow vertical extension loop function. Works with variable-width, and
; does per-line reading/writing of source data
%macro V_COPY_ROW 2 ; type (top/body/bottom), h
.%1_y_loop: ; do {
mov wq, r7mp ; initialize w (r7mp = wmp)
.%1_x_loop: ; do {
movu m0, [srcq+wq] ; m0 = read($mmsize)
movu [dstq+wq], m0 ; write(m0, $mmsize)
add wq, mmsize ; w -= $mmsize
cmp wq, -mmsize ; } while (w > $mmsize);
jl .%1_x_loop
movu m0, [srcq-mmsize] ; m0 = read($mmsize)
movu [dstq-mmsize], m0 ; write(m0, $mmsize)
%ifidn %1, body ; if ($type == body) {
add srcq, src_strideq ; src += src_stride
%endif ; }
add dstq, dst_strideq ; dst += dst_stride
dec %2 ; } while (--$h);
jnz .%1_y_loop
%endmacro
%macro vvar_fn 0
; .----. <- zero
; | | <- top is copied from first line in body of source
; |----| <- start_y
; | | <- body is copied verbatim (line-by-line) from source
; |----| <- end_y
; | | <- bottom is copied from last line in body of source
; '----' <- bh
%if ARCH_X86_64
cglobal emu_edge_vvar, 7, 8, 1, dst, dst_stride, src, src_stride, \
start_y, end_y, bh, w
%else ; x86-32
cglobal emu_edge_vvar, 1, 6, 1, dst, src, start_y, end_y, bh, w
%define src_strideq r3mp
%define dst_strideq r1mp
mov srcq, r2mp
mov start_yq, r4mp
mov end_yq, r5mp
mov bhq, r6mp
%endif
sub bhq, end_yq ; bh -= end_q
sub end_yq, start_yq ; end_q -= start_q
add srcq, r7mp ; (r7mp = wmp)
add dstq, r7mp ; (r7mp = wmp)
neg r7mp ; (r7mp = wmp)
test start_yq, start_yq ; if (start_q) {
jz .body
V_COPY_ROW top, start_yq ; v_copy_row(top, start_yq)
.body: ; }
V_COPY_ROW body, end_yq ; v_copy_row(body, end_yq)
test bhq, bhq ; if (bh) {
jz .end
sub srcq, src_strideq ; src -= src_stride
V_COPY_ROW bottom, bhq ; v_copy_row(bottom, bh)
.end: ; }
RET
%endmacro
%if ARCH_X86_32
INIT_MMX mmx
vvar_fn
%endif
INIT_XMM sse
vvar_fn
%macro hvar_fn 0
cglobal emu_edge_hvar, 5, 6, 1, dst, dst_stride, start_x, n_words, h, w
lea dstq, [dstq+n_wordsq*2]
neg n_wordsq
lea start_xq, [start_xq+n_wordsq*2]
.y_loop: ; do {
; FIXME also write a ssse3 version using pshufb
movzx wd, byte [dstq+start_xq] ; w = read(1)
imul wd, 0x01010101 ; w *= 0x01010101
movd m0, wd
mov wq, n_wordsq ; initialize w
%if cpuflag(sse2)
pshufd m0, m0, q0000 ; splat
%else ; mmx
punpckldq m0, m0 ; splat
%endif ; mmx/sse
.x_loop: ; do {
movu [dstq+wq*2], m0 ; write($reg, $mmsize)
add wq, mmsize/2 ; w -= $mmsize/2
cmp wq, -mmsize/2 ; } while (w > $mmsize/2)
jl .x_loop
movu [dstq-mmsize], m0 ; write($reg, $mmsize)
add dstq, dst_strideq ; dst += dst_stride
dec hq ; } while (h--)
jnz .y_loop
RET
%endmacro
%if ARCH_X86_32
INIT_MMX mmx
hvar_fn
%endif
INIT_XMM sse2
hvar_fn
; macro to read/write a horizontal number of pixels (%2) to/from registers
; on sse, - fills xmm0-15 for consecutive sets of 16 pixels
; - if (%2 & 8) fills 8 bytes into xmm$next
; - if (%2 & 4) fills 4 bytes into xmm$next
; - if (%2 & 3) fills 1, 2 or 4 bytes in eax
; on mmx, - fills mm0-7 for consecutive sets of 8 pixels
; - if (%2 & 4) fills 4 bytes into mm$next
; - if (%2 & 3) fills 1, 2 or 4 bytes in eax
; writing data out is in the same way
%macro READ_NUM_BYTES 2
%assign %%off 0 ; offset in source buffer
%assign %%mmx_idx 0 ; mmx register index
%assign %%xmm_idx 0 ; xmm register index
%rep %2/mmsize
%if mmsize == 16
movu xmm %+ %%xmm_idx, [srcq+%%off]
%assign %%xmm_idx %%xmm_idx+1
%else ; mmx
movu mm %+ %%mmx_idx, [srcq+%%off]
%assign %%mmx_idx %%mmx_idx+1
%endif
%assign %%off %%off+mmsize
%endrep ; %2/mmsize
%if mmsize == 16
%if (%2-%%off) >= 8
%if %2 > 16 && (%2-%%off) > 8
movu xmm %+ %%xmm_idx, [srcq+%2-16]
%assign %%xmm_idx %%xmm_idx+1
%assign %%off %2
%else
movq mm %+ %%mmx_idx, [srcq+%%off]
%assign %%mmx_idx %%mmx_idx+1
%assign %%off %%off+8
%endif
%endif ; (%2-%%off) >= 8
%endif
%if (%2-%%off) >= 4
%if %2 > 8 && (%2-%%off) > 4
movq mm %+ %%mmx_idx, [srcq+%2-8]
%assign %%off %2
%else
movd mm %+ %%mmx_idx, [srcq+%%off]
%assign %%off %%off+4
%endif
%assign %%mmx_idx %%mmx_idx+1
%endif ; (%2-%%off) >= 4
%if (%2-%%off) >= 1
%if %2 >= 4
movd mm %+ %%mmx_idx, [srcq+%2-4]
%elif (%2-%%off) == 1
mov valb, [srcq+%2-1]
%elif (%2-%%off) == 2
mov valw, [srcq+%2-2]
%elifidn %1, body
mov vald, [srcq+%2-3]
%else
movd mm %+ %%mmx_idx, [srcq+%2-3]
%endif
%endif ; (%2-%%off) >= 1
%endmacro ; READ_NUM_BYTES
%macro WRITE_NUM_BYTES 2
%assign %%off 0 ; offset in destination buffer
%assign %%mmx_idx 0 ; mmx register index
%assign %%xmm_idx 0 ; xmm register index
%rep %2/mmsize
%if mmsize == 16
movu [dstq+%%off], xmm %+ %%xmm_idx
%assign %%xmm_idx %%xmm_idx+1
%else ; mmx
movu [dstq+%%off], mm %+ %%mmx_idx
%assign %%mmx_idx %%mmx_idx+1
%endif
%assign %%off %%off+mmsize
%endrep ; %2/mmsize
%if mmsize == 16
%if (%2-%%off) >= 8
%if %2 > 16 && (%2-%%off) > 8
movu [dstq+%2-16], xmm %+ %%xmm_idx
%assign %%xmm_idx %%xmm_idx+1
%assign %%off %2
%else
movq [dstq+%%off], mm %+ %%mmx_idx
%assign %%mmx_idx %%mmx_idx+1
%assign %%off %%off+8
%endif
%endif ; (%2-%%off) >= 8
%endif
%if (%2-%%off) >= 4
%if %2 > 8 && (%2-%%off) > 4
movq [dstq+%2-8], mm %+ %%mmx_idx
%assign %%off %2
%else
movd [dstq+%%off], mm %+ %%mmx_idx
%assign %%off %%off+4
%endif
%assign %%mmx_idx %%mmx_idx+1
%endif ; (%2-%%off) >= 4
%if (%2-%%off) >= 1
%if %2 >= 4
movd [dstq+%2-4], mm %+ %%mmx_idx
%elif (%2-%%off) == 1
mov [dstq+%2-1], valb
%elif (%2-%%off) == 2
mov [dstq+%2-2], valw
%elifidn %1, body
mov [dstq+%2-3], valw
shr vald, 16
mov [dstq+%2-1], valb
%else
movd vald, mm %+ %%mmx_idx
mov [dstq+%2-3], valw
shr vald, 16
mov [dstq+%2-1], valb
%endif
%endif ; (%2-%%off) >= 1
%endmacro ; WRITE_NUM_BYTES
; vertical top/bottom extend and body copy fast loops
; these are function pointers to set-width line copy functions, i.e.
; they read a fixed number of pixels into set registers, and write
; those out into the destination buffer
%macro VERTICAL_EXTEND 2
%assign %%n %1
%rep 1+%2-%1
%if %%n <= 3
%if ARCH_X86_64
cglobal emu_edge_vfix %+ %%n, 6, 8, 0, dst, dst_stride, src, src_stride, \
start_y, end_y, val, bh
mov bhq, r6mp ; r6mp = bhmp
%else ; x86-32
cglobal emu_edge_vfix %+ %%n, 0, 6, 0, val, dst, src, start_y, end_y, bh
mov dstq, r0mp
mov srcq, r2mp
mov start_yq, r4mp
mov end_yq, r5mp
mov bhq, r6mp
%define dst_strideq r1mp
%define src_strideq r3mp
%endif ; x86-64/32
%else
%if ARCH_X86_64
cglobal emu_edge_vfix %+ %%n, 7, 7, 1, dst, dst_stride, src, src_stride, \
start_y, end_y, bh
%else ; x86-32
cglobal emu_edge_vfix %+ %%n, 1, 5, 1, dst, src, start_y, end_y, bh
mov srcq, r2mp
mov start_yq, r4mp
mov end_yq, r5mp
mov bhq, r6mp
%define dst_strideq r1mp
%define src_strideq r3mp
%endif ; x86-64/32
%endif
; FIXME move this to c wrapper?
sub bhq, end_yq ; bh -= end_y
sub end_yq, start_yq ; end_y -= start_y
; extend pixels above body
test start_yq, start_yq ; if (start_y) {
jz .body_loop
READ_NUM_BYTES top, %%n ; $variable_regs = read($n)
.top_loop: ; do {
WRITE_NUM_BYTES top, %%n ; write($variable_regs, $n)
add dstq, dst_strideq ; dst += linesize
dec start_yq ; } while (--start_y)
jnz .top_loop ; }
; copy body pixels
.body_loop: ; do {
READ_NUM_BYTES body, %%n ; $variable_regs = read($n)
WRITE_NUM_BYTES body, %%n ; write($variable_regs, $n)
add dstq, dst_strideq ; dst += dst_stride
add srcq, src_strideq ; src += src_stride
dec end_yq ; } while (--end_y)
jnz .body_loop
; copy bottom pixels
test bhq, bhq ; if (block_h) {
jz .end
sub srcq, src_strideq ; src -= linesize
READ_NUM_BYTES bottom, %%n ; $variable_regs = read($n)
.bottom_loop: ; do {
WRITE_NUM_BYTES bottom, %%n ; write($variable_regs, $n)
add dstq, dst_strideq ; dst += linesize
dec bhq ; } while (--bh)
jnz .bottom_loop ; }
.end:
RET
%assign %%n %%n+1
%endrep ; 1+%2-%1
%endmacro ; VERTICAL_EXTEND
INIT_MMX mmx
VERTICAL_EXTEND 1, 15
%if ARCH_X86_32
VERTICAL_EXTEND 16, 22
%endif
INIT_XMM sse
VERTICAL_EXTEND 16, 22
; left/right (horizontal) fast extend functions
; these are essentially identical to the vertical extend ones above,
; just left/right separated because number of pixels to extend is
; obviously not the same on both sides.
%macro READ_V_PIXEL 2
movzx vald, byte %2
imul vald, 0x01010101
%if %1 >= 8
movd m0, vald
%if mmsize == 16
pshufd m0, m0, q0000
%else
punpckldq m0, m0
%endif ; mmsize == 16
%endif ; %1 > 16
%endmacro ; READ_V_PIXEL
%macro WRITE_V_PIXEL 2
%assign %%off 0
%if %1 >= 8
%rep %1/mmsize
movu [%2+%%off], m0
%assign %%off %%off+mmsize
%endrep ; %1/mmsize
%if mmsize == 16
%if %1-%%off >= 8
%if %1 > 16 && %1-%%off > 8
movu [%2+%1-16], m0
%assign %%off %1
%else
movq [%2+%%off], m0
%assign %%off %%off+8
%endif
%endif ; %1-%%off >= 8
%endif ; mmsize == 16
%if %1-%%off >= 4
%if %1 > 8 && %1-%%off > 4
movq [%2+%1-8], m0
%assign %%off %1
%else
movd [%2+%%off], m0
%assign %%off %%off+4
%endif
%endif ; %1-%%off >= 4
%else ; %1 < 8
%rep %1/4
mov [%2+%%off], vald
%assign %%off %%off+4
%endrep ; %1/4
%endif ; %1 >=/< 8
%if %1-%%off == 2
mov [%2+%%off], valw
%endif ; (%1-%%off)/2
%endmacro ; WRITE_V_PIXEL
%macro H_EXTEND 2
%assign %%n %1
%rep 1+(%2-%1)/2
cglobal emu_edge_hfix %+ %%n, 4, 5, 1, dst, dst_stride, start_x, bh, val
.loop_y: ; do {
READ_V_PIXEL %%n, [dstq+start_xq] ; $variable_regs = read($n)
WRITE_V_PIXEL %%n, dstq ; write($variable_regs, $n)
add dstq, dst_strideq ; dst += dst_stride
dec bhq ; } while (--bh)
jnz .loop_y
RET
%assign %%n %%n+2
%endrep ; 1+(%2-%1)/2
%endmacro ; H_EXTEND
INIT_MMX mmx
H_EXTEND 2, 14
%if ARCH_X86_32
H_EXTEND 16, 22
%endif
INIT_XMM sse2
H_EXTEND 16, 22
%macro PREFETCH_FN 1
cglobal prefetch, 3, 3, 0, buf, stride, h
.loop:
%1 [bufq]
add bufq, strideq
dec hd
jg .loop
REP_RET
%endmacro
INIT_MMX mmxext
PREFETCH_FN prefetcht0
%if ARCH_X86_32
INIT_MMX 3dnow
PREFETCH_FN prefetch
%endif
|
#include "model_loader.hpp"
// use floats and med precision operations
#define GLM_PRECISION_MEDIUMP_FLOAT
#include <glm/vec3.hpp>
#include <glm/geometric.hpp>
#include <iostream>
namespace model_loader {
model obj(std::string const& name, model::attrib_flag_t import_attribs){
std::vector<tinyobj::shape_t> shapes;
std::vector<tinyobj::material_t> materials;
std::string err = tinyobj::LoadObj(shapes, materials, name.c_str());
if (!err.empty()) {
if (err[0] == 'W' && err[1] == 'A' && err[2] == 'R') {
std::cerr << "tinyobjloader: " << err << std::endl;
}
else {
throw std::logic_error("tinyobjloader: " + err);
}
}
model::attrib_flag_t attributes{model::POSITION | import_attribs};
if(import_attribs & model::TANGENT) {
// create tangents and bitangents?
throw std::invalid_argument("Attribute nr. " + std::to_string(model::TANGENT) + "not supported");
}
std::vector<float> vertex_data;
std::vector<unsigned> triangles;
GLuint vertex_offset = 0;
for (auto& shape : shapes) {
tinyobj::mesh_t& curr_mesh = shape.mesh;
// prevent MSVC warning due to Win BOOL implementation
bool has_normals = (import_attribs & model::NORMAL) != 0;
if(has_normals) {
// generate normals if necessary
if (curr_mesh.normals.empty()) {
generate_normals(curr_mesh);
}
}
bool has_uvs = (import_attribs & model::TEXCOORD) != 0;
if(has_uvs) {
if (curr_mesh.texcoords.empty()) {
has_uvs = false;
attributes ^= model::TEXCOORD;
std::cerr << "Shape has no texcoords" << std::endl;
}
}
// push back vertex attributes
for (unsigned i = 0; i < curr_mesh.positions.size() / 3; ++i) {
vertex_data.push_back(curr_mesh.positions[i * 3]);
vertex_data.push_back(curr_mesh.positions[i * 3 + 1]);
vertex_data.push_back(curr_mesh.positions[i * 3 + 2]);
if (has_normals) {
vertex_data.push_back(curr_mesh.normals[i * 3]);
vertex_data.push_back(curr_mesh.normals[i * 3 + 1]);
vertex_data.push_back(curr_mesh.normals[i * 3 + 2]);
}
if (has_uvs) {
vertex_data.push_back(curr_mesh.texcoords[i * 2]);
vertex_data.push_back(curr_mesh.texcoords[i * 2 + 1]);
}
}
// add triangles
for (unsigned i = 0; i < curr_mesh.indices.size(); ++i) {
triangles.push_back(vertex_offset + curr_mesh.indices[i]);
}
vertex_offset += GLuint(curr_mesh.positions.size() / 3);
}
return model{vertex_data, attributes, triangles};
}
void generate_normals(tinyobj::mesh_t& model) {
std::vector<glm::vec3> positions(model.positions.size() / 3);
for (unsigned i = 0; i < model.positions.size(); i+=3) {
positions[i / 3] = glm::vec3{model.positions[i], model.positions[i + 1], model.positions[i + 2]};
}
std::vector<glm::vec3> normals(model.positions.size() / 3, glm::vec3{0.0f});
for (unsigned i = 0; i < model.indices.size(); i+=3) {
glm::vec3 normal = glm::cross(positions[model.indices[i+1]] - positions[model.indices[i]], positions[model.indices[i+2]] - positions[model.indices[i]]);
normals[model.indices[i]] += normal;
normals[model.indices[i+1]] += normal;
normals[model.indices[i+2]] += normal;
}
model.normals.reserve(model.positions.size());
for (unsigned i = 0; i < normals.size(); ++i) {
glm::vec3 normal = glm::normalize(normals[i]);
model.normals[i * 3] = normal[0];
model.normals[i * 3 + 1] = normal[1];
model.normals[i * 3 + 2] = normal[2];
}
}
}; |
_kill: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "stat.h"
#include "user.h"
int
main(int argc, char **argv)
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 57 push %edi
4: 56 push %esi
5: 53 push %ebx
int i;
if(argc < 2){
6: bb 01 00 00 00 mov $0x1,%ebx
#include "stat.h"
#include "user.h"
int
main(int argc, char **argv)
{
b: 83 e4 f0 and $0xfffffff0,%esp
e: 83 ec 10 sub $0x10,%esp
11: 8b 75 08 mov 0x8(%ebp),%esi
14: 8b 7d 0c mov 0xc(%ebp),%edi
int i;
if(argc < 2){
17: 83 fe 01 cmp $0x1,%esi
1a: 7e 23 jle 3f <main+0x3f>
1c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
printf(2, "usage: kill pid...\n");
exit();
}
for(i=1; i<argc; i++)
kill(atoi(argv[i]));
20: 8b 04 9f mov (%edi,%ebx,4),%eax
if(argc < 2){
printf(2, "usage: kill pid...\n");
exit();
}
for(i=1; i<argc; i++)
23: 83 c3 01 add $0x1,%ebx
kill(atoi(argv[i]));
26: 89 04 24 mov %eax,(%esp)
29: e8 f2 01 00 00 call 220 <atoi>
2e: 89 04 24 mov %eax,(%esp)
31: e8 7c 02 00 00 call 2b2 <kill>
if(argc < 2){
printf(2, "usage: kill pid...\n");
exit();
}
for(i=1; i<argc; i++)
36: 39 f3 cmp %esi,%ebx
38: 75 e6 jne 20 <main+0x20>
kill(atoi(argv[i]));
exit();
3a: e8 43 02 00 00 call 282 <exit>
main(int argc, char **argv)
{
int i;
if(argc < 2){
printf(2, "usage: kill pid...\n");
3f: c7 44 24 04 36 07 00 movl $0x736,0x4(%esp)
46: 00
47: c7 04 24 02 00 00 00 movl $0x2,(%esp)
4e: e8 7d 03 00 00 call 3d0 <printf>
exit();
53: e8 2a 02 00 00 call 282 <exit>
58: 66 90 xchg %ax,%ax
5a: 66 90 xchg %ax,%ax
5c: 66 90 xchg %ax,%ax
5e: 66 90 xchg %ax,%ax
00000060 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
60: 55 push %ebp
61: 89 e5 mov %esp,%ebp
63: 8b 45 08 mov 0x8(%ebp),%eax
66: 8b 4d 0c mov 0xc(%ebp),%ecx
69: 53 push %ebx
char *os;
os = s;
while((*s++ = *t++) != 0)
6a: 89 c2 mov %eax,%edx
6c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
70: 83 c1 01 add $0x1,%ecx
73: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
77: 83 c2 01 add $0x1,%edx
7a: 84 db test %bl,%bl
7c: 88 5a ff mov %bl,-0x1(%edx)
7f: 75 ef jne 70 <strcpy+0x10>
;
return os;
}
81: 5b pop %ebx
82: 5d pop %ebp
83: c3 ret
84: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
8a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000090 <strcmp>:
int
strcmp(const char *p, const char *q)
{
90: 55 push %ebp
91: 89 e5 mov %esp,%ebp
93: 8b 55 08 mov 0x8(%ebp),%edx
96: 53 push %ebx
97: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
9a: 0f b6 02 movzbl (%edx),%eax
9d: 84 c0 test %al,%al
9f: 74 2d je ce <strcmp+0x3e>
a1: 0f b6 19 movzbl (%ecx),%ebx
a4: 38 d8 cmp %bl,%al
a6: 74 0e je b6 <strcmp+0x26>
a8: eb 2b jmp d5 <strcmp+0x45>
aa: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
b0: 38 c8 cmp %cl,%al
b2: 75 15 jne c9 <strcmp+0x39>
p++, q++;
b4: 89 d9 mov %ebx,%ecx
b6: 83 c2 01 add $0x1,%edx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
b9: 0f b6 02 movzbl (%edx),%eax
p++, q++;
bc: 8d 59 01 lea 0x1(%ecx),%ebx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
bf: 0f b6 49 01 movzbl 0x1(%ecx),%ecx
c3: 84 c0 test %al,%al
c5: 75 e9 jne b0 <strcmp+0x20>
c7: 31 c0 xor %eax,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
c9: 29 c8 sub %ecx,%eax
}
cb: 5b pop %ebx
cc: 5d pop %ebp
cd: c3 ret
ce: 0f b6 09 movzbl (%ecx),%ecx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
d1: 31 c0 xor %eax,%eax
d3: eb f4 jmp c9 <strcmp+0x39>
d5: 0f b6 cb movzbl %bl,%ecx
d8: eb ef jmp c9 <strcmp+0x39>
da: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
000000e0 <strlen>:
return (uchar)*p - (uchar)*q;
}
uint
strlen(char *s)
{
e0: 55 push %ebp
e1: 89 e5 mov %esp,%ebp
e3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
e6: 80 39 00 cmpb $0x0,(%ecx)
e9: 74 12 je fd <strlen+0x1d>
eb: 31 d2 xor %edx,%edx
ed: 8d 76 00 lea 0x0(%esi),%esi
f0: 83 c2 01 add $0x1,%edx
f3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
f7: 89 d0 mov %edx,%eax
f9: 75 f5 jne f0 <strlen+0x10>
;
return n;
}
fb: 5d pop %ebp
fc: c3 ret
uint
strlen(char *s)
{
int n;
for(n = 0; s[n]; n++)
fd: 31 c0 xor %eax,%eax
;
return n;
}
ff: 5d pop %ebp
100: c3 ret
101: eb 0d jmp 110 <memset>
103: 90 nop
104: 90 nop
105: 90 nop
106: 90 nop
107: 90 nop
108: 90 nop
109: 90 nop
10a: 90 nop
10b: 90 nop
10c: 90 nop
10d: 90 nop
10e: 90 nop
10f: 90 nop
00000110 <memset>:
void*
memset(void *dst, int c, uint n)
{
110: 55 push %ebp
111: 89 e5 mov %esp,%ebp
113: 8b 55 08 mov 0x8(%ebp),%edx
116: 57 push %edi
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
117: 8b 4d 10 mov 0x10(%ebp),%ecx
11a: 8b 45 0c mov 0xc(%ebp),%eax
11d: 89 d7 mov %edx,%edi
11f: fc cld
120: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
122: 89 d0 mov %edx,%eax
124: 5f pop %edi
125: 5d pop %ebp
126: c3 ret
127: 89 f6 mov %esi,%esi
129: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000130 <strchr>:
char*
strchr(const char *s, char c)
{
130: 55 push %ebp
131: 89 e5 mov %esp,%ebp
133: 8b 45 08 mov 0x8(%ebp),%eax
136: 53 push %ebx
137: 8b 55 0c mov 0xc(%ebp),%edx
for(; *s; s++)
13a: 0f b6 18 movzbl (%eax),%ebx
13d: 84 db test %bl,%bl
13f: 74 1d je 15e <strchr+0x2e>
if(*s == c)
141: 38 d3 cmp %dl,%bl
143: 89 d1 mov %edx,%ecx
145: 75 0d jne 154 <strchr+0x24>
147: eb 17 jmp 160 <strchr+0x30>
149: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
150: 38 ca cmp %cl,%dl
152: 74 0c je 160 <strchr+0x30>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
154: 83 c0 01 add $0x1,%eax
157: 0f b6 10 movzbl (%eax),%edx
15a: 84 d2 test %dl,%dl
15c: 75 f2 jne 150 <strchr+0x20>
if(*s == c)
return (char*)s;
return 0;
15e: 31 c0 xor %eax,%eax
}
160: 5b pop %ebx
161: 5d pop %ebp
162: c3 ret
163: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
169: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000170 <gets>:
char*
gets(char *buf, int max)
{
170: 55 push %ebp
171: 89 e5 mov %esp,%ebp
173: 57 push %edi
174: 56 push %esi
int i, cc;
char c;
for(i=0; i+1 < max; ){
175: 31 f6 xor %esi,%esi
return 0;
}
char*
gets(char *buf, int max)
{
177: 53 push %ebx
178: 83 ec 2c sub $0x2c,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
17b: 8d 7d e7 lea -0x19(%ebp),%edi
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
17e: eb 31 jmp 1b1 <gets+0x41>
cc = read(0, &c, 1);
180: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
187: 00
188: 89 7c 24 04 mov %edi,0x4(%esp)
18c: c7 04 24 00 00 00 00 movl $0x0,(%esp)
193: e8 02 01 00 00 call 29a <read>
if(cc < 1)
198: 85 c0 test %eax,%eax
19a: 7e 1d jle 1b9 <gets+0x49>
break;
buf[i++] = c;
19c: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
1a0: 89 de mov %ebx,%esi
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
1a2: 8b 55 08 mov 0x8(%ebp),%edx
if(c == '\n' || c == '\r')
1a5: 3c 0d cmp $0xd,%al
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
1a7: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
1ab: 74 0c je 1b9 <gets+0x49>
1ad: 3c 0a cmp $0xa,%al
1af: 74 08 je 1b9 <gets+0x49>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
1b1: 8d 5e 01 lea 0x1(%esi),%ebx
1b4: 3b 5d 0c cmp 0xc(%ebp),%ebx
1b7: 7c c7 jl 180 <gets+0x10>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
1b9: 8b 45 08 mov 0x8(%ebp),%eax
1bc: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
1c0: 83 c4 2c add $0x2c,%esp
1c3: 5b pop %ebx
1c4: 5e pop %esi
1c5: 5f pop %edi
1c6: 5d pop %ebp
1c7: c3 ret
1c8: 90 nop
1c9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000001d0 <stat>:
int
stat(char *n, struct stat *st)
{
1d0: 55 push %ebp
1d1: 89 e5 mov %esp,%ebp
1d3: 56 push %esi
1d4: 53 push %ebx
1d5: 83 ec 10 sub $0x10,%esp
int fd;
int r;
fd = open(n, O_RDONLY);
1d8: 8b 45 08 mov 0x8(%ebp),%eax
1db: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
1e2: 00
1e3: 89 04 24 mov %eax,(%esp)
1e6: e8 d7 00 00 00 call 2c2 <open>
if(fd < 0)
1eb: 85 c0 test %eax,%eax
stat(char *n, struct stat *st)
{
int fd;
int r;
fd = open(n, O_RDONLY);
1ed: 89 c3 mov %eax,%ebx
if(fd < 0)
1ef: 78 27 js 218 <stat+0x48>
return -1;
r = fstat(fd, st);
1f1: 8b 45 0c mov 0xc(%ebp),%eax
1f4: 89 1c 24 mov %ebx,(%esp)
1f7: 89 44 24 04 mov %eax,0x4(%esp)
1fb: e8 da 00 00 00 call 2da <fstat>
close(fd);
200: 89 1c 24 mov %ebx,(%esp)
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
r = fstat(fd, st);
203: 89 c6 mov %eax,%esi
close(fd);
205: e8 a0 00 00 00 call 2aa <close>
return r;
20a: 89 f0 mov %esi,%eax
}
20c: 83 c4 10 add $0x10,%esp
20f: 5b pop %ebx
210: 5e pop %esi
211: 5d pop %ebp
212: c3 ret
213: 90 nop
214: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
int fd;
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
218: b8 ff ff ff ff mov $0xffffffff,%eax
21d: eb ed jmp 20c <stat+0x3c>
21f: 90 nop
00000220 <atoi>:
return r;
}
int
atoi(const char *s)
{
220: 55 push %ebp
221: 89 e5 mov %esp,%ebp
223: 8b 4d 08 mov 0x8(%ebp),%ecx
226: 53 push %ebx
int n;
n = 0;
while('0' <= *s && *s <= '9')
227: 0f be 11 movsbl (%ecx),%edx
22a: 8d 42 d0 lea -0x30(%edx),%eax
22d: 3c 09 cmp $0x9,%al
int
atoi(const char *s)
{
int n;
n = 0;
22f: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
234: 77 17 ja 24d <atoi+0x2d>
236: 66 90 xchg %ax,%ax
n = n*10 + *s++ - '0';
238: 83 c1 01 add $0x1,%ecx
23b: 8d 04 80 lea (%eax,%eax,4),%eax
23e: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
242: 0f be 11 movsbl (%ecx),%edx
245: 8d 5a d0 lea -0x30(%edx),%ebx
248: 80 fb 09 cmp $0x9,%bl
24b: 76 eb jbe 238 <atoi+0x18>
n = n*10 + *s++ - '0';
return n;
}
24d: 5b pop %ebx
24e: 5d pop %ebp
24f: c3 ret
00000250 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
250: 55 push %ebp
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
251: 31 d2 xor %edx,%edx
return n;
}
void*
memmove(void *vdst, void *vsrc, int n)
{
253: 89 e5 mov %esp,%ebp
255: 56 push %esi
256: 8b 45 08 mov 0x8(%ebp),%eax
259: 53 push %ebx
25a: 8b 5d 10 mov 0x10(%ebp),%ebx
25d: 8b 75 0c mov 0xc(%ebp),%esi
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
260: 85 db test %ebx,%ebx
262: 7e 12 jle 276 <memmove+0x26>
264: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
268: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
26c: 88 0c 10 mov %cl,(%eax,%edx,1)
26f: 83 c2 01 add $0x1,%edx
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
272: 39 da cmp %ebx,%edx
274: 75 f2 jne 268 <memmove+0x18>
*dst++ = *src++;
return vdst;
}
276: 5b pop %ebx
277: 5e pop %esi
278: 5d pop %ebp
279: c3 ret
0000027a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
27a: b8 01 00 00 00 mov $0x1,%eax
27f: cd 40 int $0x40
281: c3 ret
00000282 <exit>:
SYSCALL(exit)
282: b8 02 00 00 00 mov $0x2,%eax
287: cd 40 int $0x40
289: c3 ret
0000028a <wait>:
SYSCALL(wait)
28a: b8 03 00 00 00 mov $0x3,%eax
28f: cd 40 int $0x40
291: c3 ret
00000292 <pipe>:
SYSCALL(pipe)
292: b8 04 00 00 00 mov $0x4,%eax
297: cd 40 int $0x40
299: c3 ret
0000029a <read>:
SYSCALL(read)
29a: b8 05 00 00 00 mov $0x5,%eax
29f: cd 40 int $0x40
2a1: c3 ret
000002a2 <write>:
SYSCALL(write)
2a2: b8 10 00 00 00 mov $0x10,%eax
2a7: cd 40 int $0x40
2a9: c3 ret
000002aa <close>:
SYSCALL(close)
2aa: b8 15 00 00 00 mov $0x15,%eax
2af: cd 40 int $0x40
2b1: c3 ret
000002b2 <kill>:
SYSCALL(kill)
2b2: b8 06 00 00 00 mov $0x6,%eax
2b7: cd 40 int $0x40
2b9: c3 ret
000002ba <exec>:
SYSCALL(exec)
2ba: b8 07 00 00 00 mov $0x7,%eax
2bf: cd 40 int $0x40
2c1: c3 ret
000002c2 <open>:
SYSCALL(open)
2c2: b8 0f 00 00 00 mov $0xf,%eax
2c7: cd 40 int $0x40
2c9: c3 ret
000002ca <mknod>:
SYSCALL(mknod)
2ca: b8 11 00 00 00 mov $0x11,%eax
2cf: cd 40 int $0x40
2d1: c3 ret
000002d2 <unlink>:
SYSCALL(unlink)
2d2: b8 12 00 00 00 mov $0x12,%eax
2d7: cd 40 int $0x40
2d9: c3 ret
000002da <fstat>:
SYSCALL(fstat)
2da: b8 08 00 00 00 mov $0x8,%eax
2df: cd 40 int $0x40
2e1: c3 ret
000002e2 <link>:
SYSCALL(link)
2e2: b8 13 00 00 00 mov $0x13,%eax
2e7: cd 40 int $0x40
2e9: c3 ret
000002ea <mkdir>:
SYSCALL(mkdir)
2ea: b8 14 00 00 00 mov $0x14,%eax
2ef: cd 40 int $0x40
2f1: c3 ret
000002f2 <chdir>:
SYSCALL(chdir)
2f2: b8 09 00 00 00 mov $0x9,%eax
2f7: cd 40 int $0x40
2f9: c3 ret
000002fa <dup>:
SYSCALL(dup)
2fa: b8 0a 00 00 00 mov $0xa,%eax
2ff: cd 40 int $0x40
301: c3 ret
00000302 <getpid>:
SYSCALL(getpid)
302: b8 0b 00 00 00 mov $0xb,%eax
307: cd 40 int $0x40
309: c3 ret
0000030a <sbrk>:
SYSCALL(sbrk)
30a: b8 0c 00 00 00 mov $0xc,%eax
30f: cd 40 int $0x40
311: c3 ret
00000312 <sleep>:
SYSCALL(sleep)
312: b8 0d 00 00 00 mov $0xd,%eax
317: cd 40 int $0x40
319: c3 ret
0000031a <uptime>:
SYSCALL(uptime)
31a: b8 0e 00 00 00 mov $0xe,%eax
31f: cd 40 int $0x40
321: c3 ret
322: 66 90 xchg %ax,%ax
324: 66 90 xchg %ax,%ax
326: 66 90 xchg %ax,%ax
328: 66 90 xchg %ax,%ax
32a: 66 90 xchg %ax,%ax
32c: 66 90 xchg %ax,%ax
32e: 66 90 xchg %ax,%ax
00000330 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
330: 55 push %ebp
331: 89 e5 mov %esp,%ebp
333: 57 push %edi
334: 56 push %esi
335: 89 c6 mov %eax,%esi
337: 53 push %ebx
338: 83 ec 4c sub $0x4c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
33b: 8b 5d 08 mov 0x8(%ebp),%ebx
33e: 85 db test %ebx,%ebx
340: 74 09 je 34b <printint+0x1b>
342: 89 d0 mov %edx,%eax
344: c1 e8 1f shr $0x1f,%eax
347: 84 c0 test %al,%al
349: 75 75 jne 3c0 <printint+0x90>
neg = 1;
x = -xx;
} else {
x = xx;
34b: 89 d0 mov %edx,%eax
static char digits[] = "0123456789ABCDEF";
char buf[16];
int i, neg;
uint x;
neg = 0;
34d: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
354: 89 75 c0 mov %esi,-0x40(%ebp)
x = -xx;
} else {
x = xx;
}
i = 0;
357: 31 ff xor %edi,%edi
359: 89 ce mov %ecx,%esi
35b: 8d 5d d7 lea -0x29(%ebp),%ebx
35e: eb 02 jmp 362 <printint+0x32>
do{
buf[i++] = digits[x % base];
360: 89 cf mov %ecx,%edi
362: 31 d2 xor %edx,%edx
364: f7 f6 div %esi
366: 8d 4f 01 lea 0x1(%edi),%ecx
369: 0f b6 92 51 07 00 00 movzbl 0x751(%edx),%edx
}while((x /= base) != 0);
370: 85 c0 test %eax,%eax
x = xx;
}
i = 0;
do{
buf[i++] = digits[x % base];
372: 88 14 0b mov %dl,(%ebx,%ecx,1)
}while((x /= base) != 0);
375: 75 e9 jne 360 <printint+0x30>
if(neg)
377: 8b 55 c4 mov -0x3c(%ebp),%edx
x = xx;
}
i = 0;
do{
buf[i++] = digits[x % base];
37a: 89 c8 mov %ecx,%eax
37c: 8b 75 c0 mov -0x40(%ebp),%esi
}while((x /= base) != 0);
if(neg)
37f: 85 d2 test %edx,%edx
381: 74 08 je 38b <printint+0x5b>
buf[i++] = '-';
383: 8d 4f 02 lea 0x2(%edi),%ecx
386: c6 44 05 d8 2d movb $0x2d,-0x28(%ebp,%eax,1)
while(--i >= 0)
38b: 8d 79 ff lea -0x1(%ecx),%edi
38e: 66 90 xchg %ax,%ax
390: 0f b6 44 3d d8 movzbl -0x28(%ebp,%edi,1),%eax
395: 83 ef 01 sub $0x1,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
398: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
39f: 00
3a0: 89 5c 24 04 mov %ebx,0x4(%esp)
3a4: 89 34 24 mov %esi,(%esp)
3a7: 88 45 d7 mov %al,-0x29(%ebp)
3aa: e8 f3 fe ff ff call 2a2 <write>
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
3af: 83 ff ff cmp $0xffffffff,%edi
3b2: 75 dc jne 390 <printint+0x60>
putc(fd, buf[i]);
}
3b4: 83 c4 4c add $0x4c,%esp
3b7: 5b pop %ebx
3b8: 5e pop %esi
3b9: 5f pop %edi
3ba: 5d pop %ebp
3bb: c3 ret
3bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
3c0: 89 d0 mov %edx,%eax
3c2: f7 d8 neg %eax
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
3c4: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
3cb: eb 87 jmp 354 <printint+0x24>
3cd: 8d 76 00 lea 0x0(%esi),%esi
000003d0 <printf>:
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
3d0: 55 push %ebp
3d1: 89 e5 mov %esp,%ebp
3d3: 57 push %edi
char *s;
int c, i, state;
uint *ap;
state = 0;
3d4: 31 ff xor %edi,%edi
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
3d6: 56 push %esi
3d7: 53 push %ebx
3d8: 83 ec 3c sub $0x3c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
3db: 8b 5d 0c mov 0xc(%ebp),%ebx
char *s;
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
3de: 8d 45 10 lea 0x10(%ebp),%eax
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
3e1: 8b 75 08 mov 0x8(%ebp),%esi
char *s;
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
3e4: 89 45 d4 mov %eax,-0x2c(%ebp)
for(i = 0; fmt[i]; i++){
3e7: 0f b6 13 movzbl (%ebx),%edx
3ea: 83 c3 01 add $0x1,%ebx
3ed: 84 d2 test %dl,%dl
3ef: 75 39 jne 42a <printf+0x5a>
3f1: e9 c2 00 00 00 jmp 4b8 <printf+0xe8>
3f6: 66 90 xchg %ax,%ax
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
3f8: 83 fa 25 cmp $0x25,%edx
3fb: 0f 84 bf 00 00 00 je 4c0 <printf+0xf0>
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
401: 8d 45 e2 lea -0x1e(%ebp),%eax
404: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
40b: 00
40c: 89 44 24 04 mov %eax,0x4(%esp)
410: 89 34 24 mov %esi,(%esp)
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
state = '%';
} else {
putc(fd, c);
413: 88 55 e2 mov %dl,-0x1e(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
416: e8 87 fe ff ff call 2a2 <write>
41b: 83 c3 01 add $0x1,%ebx
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
41e: 0f b6 53 ff movzbl -0x1(%ebx),%edx
422: 84 d2 test %dl,%dl
424: 0f 84 8e 00 00 00 je 4b8 <printf+0xe8>
c = fmt[i] & 0xff;
if(state == 0){
42a: 85 ff test %edi,%edi
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
42c: 0f be c2 movsbl %dl,%eax
if(state == 0){
42f: 74 c7 je 3f8 <printf+0x28>
if(c == '%'){
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
431: 83 ff 25 cmp $0x25,%edi
434: 75 e5 jne 41b <printf+0x4b>
if(c == 'd'){
436: 83 fa 64 cmp $0x64,%edx
439: 0f 84 31 01 00 00 je 570 <printf+0x1a0>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
43f: 25 f7 00 00 00 and $0xf7,%eax
444: 83 f8 70 cmp $0x70,%eax
447: 0f 84 83 00 00 00 je 4d0 <printf+0x100>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
44d: 83 fa 73 cmp $0x73,%edx
450: 0f 84 a2 00 00 00 je 4f8 <printf+0x128>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
456: 83 fa 63 cmp $0x63,%edx
459: 0f 84 35 01 00 00 je 594 <printf+0x1c4>
putc(fd, *ap);
ap++;
} else if(c == '%'){
45f: 83 fa 25 cmp $0x25,%edx
462: 0f 84 e0 00 00 00 je 548 <printf+0x178>
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
468: 8d 45 e6 lea -0x1a(%ebp),%eax
46b: 83 c3 01 add $0x1,%ebx
46e: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
475: 00
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
476: 31 ff xor %edi,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
478: 89 44 24 04 mov %eax,0x4(%esp)
47c: 89 34 24 mov %esi,(%esp)
47f: 89 55 d0 mov %edx,-0x30(%ebp)
482: c6 45 e6 25 movb $0x25,-0x1a(%ebp)
486: e8 17 fe ff ff call 2a2 <write>
} else if(c == '%'){
putc(fd, c);
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
48b: 8b 55 d0 mov -0x30(%ebp),%edx
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
48e: 8d 45 e7 lea -0x19(%ebp),%eax
491: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
498: 00
499: 89 44 24 04 mov %eax,0x4(%esp)
49d: 89 34 24 mov %esi,(%esp)
} else if(c == '%'){
putc(fd, c);
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
4a0: 88 55 e7 mov %dl,-0x19(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
4a3: e8 fa fd ff ff call 2a2 <write>
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
4a8: 0f b6 53 ff movzbl -0x1(%ebx),%edx
4ac: 84 d2 test %dl,%dl
4ae: 0f 85 76 ff ff ff jne 42a <printf+0x5a>
4b4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
putc(fd, c);
}
state = 0;
}
}
}
4b8: 83 c4 3c add $0x3c,%esp
4bb: 5b pop %ebx
4bc: 5e pop %esi
4bd: 5f pop %edi
4be: 5d pop %ebp
4bf: c3 ret
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
state = '%';
4c0: bf 25 00 00 00 mov $0x25,%edi
4c5: e9 51 ff ff ff jmp 41b <printf+0x4b>
4ca: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
4d0: 8b 45 d4 mov -0x2c(%ebp),%eax
4d3: b9 10 00 00 00 mov $0x10,%ecx
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
4d8: 31 ff xor %edi,%edi
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
4da: c7 04 24 00 00 00 00 movl $0x0,(%esp)
4e1: 8b 10 mov (%eax),%edx
4e3: 89 f0 mov %esi,%eax
4e5: e8 46 fe ff ff call 330 <printint>
ap++;
4ea: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
4ee: e9 28 ff ff ff jmp 41b <printf+0x4b>
4f3: 90 nop
4f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
} else if(c == 's'){
s = (char*)*ap;
4f8: 8b 45 d4 mov -0x2c(%ebp),%eax
ap++;
4fb: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
s = (char*)*ap;
4ff: 8b 38 mov (%eax),%edi
ap++;
if(s == 0)
s = "(null)";
501: b8 4a 07 00 00 mov $0x74a,%eax
506: 85 ff test %edi,%edi
508: 0f 44 f8 cmove %eax,%edi
while(*s != 0){
50b: 0f b6 07 movzbl (%edi),%eax
50e: 84 c0 test %al,%al
510: 74 2a je 53c <printf+0x16c>
512: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
518: 88 45 e3 mov %al,-0x1d(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
51b: 8d 45 e3 lea -0x1d(%ebp),%eax
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
51e: 83 c7 01 add $0x1,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
521: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
528: 00
529: 89 44 24 04 mov %eax,0x4(%esp)
52d: 89 34 24 mov %esi,(%esp)
530: e8 6d fd ff ff call 2a2 <write>
} else if(c == 's'){
s = (char*)*ap;
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
535: 0f b6 07 movzbl (%edi),%eax
538: 84 c0 test %al,%al
53a: 75 dc jne 518 <printf+0x148>
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
53c: 31 ff xor %edi,%edi
53e: e9 d8 fe ff ff jmp 41b <printf+0x4b>
543: 90 nop
544: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
548: 8d 45 e5 lea -0x1b(%ebp),%eax
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
54b: 31 ff xor %edi,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
54d: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
554: 00
555: 89 44 24 04 mov %eax,0x4(%esp)
559: 89 34 24 mov %esi,(%esp)
55c: c6 45 e5 25 movb $0x25,-0x1b(%ebp)
560: e8 3d fd ff ff call 2a2 <write>
565: e9 b1 fe ff ff jmp 41b <printf+0x4b>
56a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
} else {
putc(fd, c);
}
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
570: 8b 45 d4 mov -0x2c(%ebp),%eax
573: b9 0a 00 00 00 mov $0xa,%ecx
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
578: 66 31 ff xor %di,%di
} else {
putc(fd, c);
}
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
57b: c7 04 24 01 00 00 00 movl $0x1,(%esp)
582: 8b 10 mov (%eax),%edx
584: 89 f0 mov %esi,%eax
586: e8 a5 fd ff ff call 330 <printint>
ap++;
58b: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
58f: e9 87 fe ff ff jmp 41b <printf+0x4b>
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
putc(fd, *ap);
594: 8b 45 d4 mov -0x2c(%ebp),%eax
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
597: 31 ff xor %edi,%edi
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
putc(fd, *ap);
599: 8b 00 mov (%eax),%eax
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
59b: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
5a2: 00
5a3: 89 34 24 mov %esi,(%esp)
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
putc(fd, *ap);
5a6: 88 45 e4 mov %al,-0x1c(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
5a9: 8d 45 e4 lea -0x1c(%ebp),%eax
5ac: 89 44 24 04 mov %eax,0x4(%esp)
5b0: e8 ed fc ff ff call 2a2 <write>
putc(fd, *s);
s++;
}
} else if(c == 'c'){
putc(fd, *ap);
ap++;
5b5: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
5b9: e9 5d fe ff ff jmp 41b <printf+0x4b>
5be: 66 90 xchg %ax,%ax
000005c0 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
5c0: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5c1: a1 cc 09 00 00 mov 0x9cc,%eax
static Header base;
static Header *freep;
void
free(void *ap)
{
5c6: 89 e5 mov %esp,%ebp
5c8: 57 push %edi
5c9: 56 push %esi
5ca: 53 push %ebx
5cb: 8b 5d 08 mov 0x8(%ebp),%ebx
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5ce: 8b 08 mov (%eax),%ecx
void
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
5d0: 8d 53 f8 lea -0x8(%ebx),%edx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5d3: 39 d0 cmp %edx,%eax
5d5: 72 11 jb 5e8 <free+0x28>
5d7: 90 nop
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5d8: 39 c8 cmp %ecx,%eax
5da: 72 04 jb 5e0 <free+0x20>
5dc: 39 ca cmp %ecx,%edx
5de: 72 10 jb 5f0 <free+0x30>
5e0: 89 c8 mov %ecx,%eax
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5e2: 39 d0 cmp %edx,%eax
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5e4: 8b 08 mov (%eax),%ecx
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5e6: 73 f0 jae 5d8 <free+0x18>
5e8: 39 ca cmp %ecx,%edx
5ea: 72 04 jb 5f0 <free+0x30>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5ec: 39 c8 cmp %ecx,%eax
5ee: 72 f0 jb 5e0 <free+0x20>
break;
if(bp + bp->s.size == p->s.ptr){
5f0: 8b 73 fc mov -0x4(%ebx),%esi
5f3: 8d 3c f2 lea (%edx,%esi,8),%edi
5f6: 39 cf cmp %ecx,%edi
5f8: 74 1e je 618 <free+0x58>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
5fa: 89 4b f8 mov %ecx,-0x8(%ebx)
if(p + p->s.size == bp){
5fd: 8b 48 04 mov 0x4(%eax),%ecx
600: 8d 34 c8 lea (%eax,%ecx,8),%esi
603: 39 f2 cmp %esi,%edx
605: 74 28 je 62f <free+0x6f>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
607: 89 10 mov %edx,(%eax)
freep = p;
609: a3 cc 09 00 00 mov %eax,0x9cc
}
60e: 5b pop %ebx
60f: 5e pop %esi
610: 5f pop %edi
611: 5d pop %ebp
612: c3 ret
613: 90 nop
614: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
break;
if(bp + bp->s.size == p->s.ptr){
bp->s.size += p->s.ptr->s.size;
618: 03 71 04 add 0x4(%ecx),%esi
61b: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
61e: 8b 08 mov (%eax),%ecx
620: 8b 09 mov (%ecx),%ecx
622: 89 4b f8 mov %ecx,-0x8(%ebx)
} else
bp->s.ptr = p->s.ptr;
if(p + p->s.size == bp){
625: 8b 48 04 mov 0x4(%eax),%ecx
628: 8d 34 c8 lea (%eax,%ecx,8),%esi
62b: 39 f2 cmp %esi,%edx
62d: 75 d8 jne 607 <free+0x47>
p->s.size += bp->s.size;
62f: 03 4b fc add -0x4(%ebx),%ecx
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
freep = p;
632: a3 cc 09 00 00 mov %eax,0x9cc
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
if(p + p->s.size == bp){
p->s.size += bp->s.size;
637: 89 48 04 mov %ecx,0x4(%eax)
p->s.ptr = bp->s.ptr;
63a: 8b 53 f8 mov -0x8(%ebx),%edx
63d: 89 10 mov %edx,(%eax)
} else
p->s.ptr = bp;
freep = p;
}
63f: 5b pop %ebx
640: 5e pop %esi
641: 5f pop %edi
642: 5d pop %ebp
643: c3 ret
644: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
64a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000650 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
650: 55 push %ebp
651: 89 e5 mov %esp,%ebp
653: 57 push %edi
654: 56 push %esi
655: 53 push %ebx
656: 83 ec 1c sub $0x1c,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
659: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
65c: 8b 1d cc 09 00 00 mov 0x9cc,%ebx
malloc(uint nbytes)
{
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
662: 8d 48 07 lea 0x7(%eax),%ecx
665: c1 e9 03 shr $0x3,%ecx
if((prevp = freep) == 0){
668: 85 db test %ebx,%ebx
malloc(uint nbytes)
{
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
66a: 8d 71 01 lea 0x1(%ecx),%esi
if((prevp = freep) == 0){
66d: 0f 84 9b 00 00 00 je 70e <malloc+0xbe>
673: 8b 13 mov (%ebx),%edx
675: 8b 7a 04 mov 0x4(%edx),%edi
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
678: 39 fe cmp %edi,%esi
67a: 76 64 jbe 6e0 <malloc+0x90>
67c: 8d 04 f5 00 00 00 00 lea 0x0(,%esi,8),%eax
morecore(uint nu)
{
char *p;
Header *hp;
if(nu < 4096)
683: bb 00 80 00 00 mov $0x8000,%ebx
688: 89 45 e4 mov %eax,-0x1c(%ebp)
68b: eb 0e jmp 69b <malloc+0x4b>
68d: 8d 76 00 lea 0x0(%esi),%esi
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
690: 8b 02 mov (%edx),%eax
if(p->s.size >= nunits){
692: 8b 78 04 mov 0x4(%eax),%edi
695: 39 fe cmp %edi,%esi
697: 76 4f jbe 6e8 <malloc+0x98>
699: 89 c2 mov %eax,%edx
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
69b: 3b 15 cc 09 00 00 cmp 0x9cc,%edx
6a1: 75 ed jne 690 <malloc+0x40>
morecore(uint nu)
{
char *p;
Header *hp;
if(nu < 4096)
6a3: 8b 45 e4 mov -0x1c(%ebp),%eax
6a6: 81 fe 00 10 00 00 cmp $0x1000,%esi
6ac: bf 00 10 00 00 mov $0x1000,%edi
6b1: 0f 43 fe cmovae %esi,%edi
6b4: 0f 42 c3 cmovb %ebx,%eax
nu = 4096;
p = sbrk(nu * sizeof(Header));
6b7: 89 04 24 mov %eax,(%esp)
6ba: e8 4b fc ff ff call 30a <sbrk>
if(p == (char*)-1)
6bf: 83 f8 ff cmp $0xffffffff,%eax
6c2: 74 18 je 6dc <malloc+0x8c>
return 0;
hp = (Header*)p;
hp->s.size = nu;
6c4: 89 78 04 mov %edi,0x4(%eax)
free((void*)(hp + 1));
6c7: 83 c0 08 add $0x8,%eax
6ca: 89 04 24 mov %eax,(%esp)
6cd: e8 ee fe ff ff call 5c0 <free>
return freep;
6d2: 8b 15 cc 09 00 00 mov 0x9cc,%edx
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
if((p = morecore(nunits)) == 0)
6d8: 85 d2 test %edx,%edx
6da: 75 b4 jne 690 <malloc+0x40>
return 0;
6dc: 31 c0 xor %eax,%eax
6de: eb 20 jmp 700 <malloc+0xb0>
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
6e0: 89 d0 mov %edx,%eax
6e2: 89 da mov %ebx,%edx
6e4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
if(p->s.size == nunits)
6e8: 39 fe cmp %edi,%esi
6ea: 74 1c je 708 <malloc+0xb8>
prevp->s.ptr = p->s.ptr;
else {
p->s.size -= nunits;
6ec: 29 f7 sub %esi,%edi
6ee: 89 78 04 mov %edi,0x4(%eax)
p += p->s.size;
6f1: 8d 04 f8 lea (%eax,%edi,8),%eax
p->s.size = nunits;
6f4: 89 70 04 mov %esi,0x4(%eax)
}
freep = prevp;
6f7: 89 15 cc 09 00 00 mov %edx,0x9cc
return (void*)(p + 1);
6fd: 83 c0 08 add $0x8,%eax
}
if(p == freep)
if((p = morecore(nunits)) == 0)
return 0;
}
}
700: 83 c4 1c add $0x1c,%esp
703: 5b pop %ebx
704: 5e pop %esi
705: 5f pop %edi
706: 5d pop %ebp
707: c3 ret
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
if(p->s.size == nunits)
prevp->s.ptr = p->s.ptr;
708: 8b 08 mov (%eax),%ecx
70a: 89 0a mov %ecx,(%edx)
70c: eb e9 jmp 6f7 <malloc+0xa7>
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
70e: c7 05 cc 09 00 00 d0 movl $0x9d0,0x9cc
715: 09 00 00
base.s.size = 0;
718: ba d0 09 00 00 mov $0x9d0,%edx
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
71d: c7 05 d0 09 00 00 d0 movl $0x9d0,0x9d0
724: 09 00 00
base.s.size = 0;
727: c7 05 d4 09 00 00 00 movl $0x0,0x9d4
72e: 00 00 00
731: e9 46 ff ff ff jmp 67c <malloc+0x2c>
|
// Autogenerated from CppHeaderCreator
// Created by Sc2ad
// =========================================================================
#pragma once
// Begin includes
#include "beatsaber-hook/shared/utils/typedefs.h"
#include "beatsaber-hook/shared/utils/byref.hpp"
// Including type: System.Linq.Expressions.Interpreter.SubInstruction
#include "System/Linq/Expressions/Interpreter/SubInstruction.hpp"
// Including type: System.Linq.Expressions.Interpreter.Instruction
#include "System/Linq/Expressions/Interpreter/Instruction.hpp"
#include "beatsaber-hook/shared/utils/il2cpp-utils-methods.hpp"
#include "beatsaber-hook/shared/utils/il2cpp-utils-properties.hpp"
#include "beatsaber-hook/shared/utils/il2cpp-utils-fields.hpp"
#include "beatsaber-hook/shared/utils/utils.h"
// Completed includes
// Begin forward declares
// Forward declaring namespace: System::Linq::Expressions::Interpreter
namespace System::Linq::Expressions::Interpreter {
// Forward declaring type: InterpretedFrame
class InterpretedFrame;
}
// Completed forward declares
#include "beatsaber-hook/shared/utils/il2cpp-type-check.hpp"
NEED_NO_BOX(::System::Linq::Expressions::Interpreter::SubInstruction::SubDouble);
DEFINE_IL2CPP_ARG_TYPE(::System::Linq::Expressions::Interpreter::SubInstruction::SubDouble*, "System.Linq.Expressions.Interpreter", "SubInstruction/SubDouble");
// Type namespace: System.Linq.Expressions.Interpreter
namespace System::Linq::Expressions::Interpreter {
// Size: 0x10
#pragma pack(push, 1)
// Autogenerated type: System.Linq.Expressions.Interpreter.SubInstruction/System.Linq.Expressions.Interpreter.SubDouble
// [TokenAttribute] Offset: FFFFFFFF
class SubInstruction::SubDouble : public ::System::Linq::Expressions::Interpreter::SubInstruction {
public:
// public System.Void .ctor()
// Offset: 0x16B2728
// Implemented from: System.Linq.Expressions.Interpreter.SubInstruction
// Base method: System.Void SubInstruction::.ctor()
// Base method: System.Void Instruction::.ctor()
template<::il2cpp_utils::CreationType creationType = ::il2cpp_utils::CreationType::Temporary>
static SubInstruction::SubDouble* New_ctor() {
static auto ___internal__logger = ::Logger::get().WithContext("::System::Linq::Expressions::Interpreter::SubInstruction::SubDouble::.ctor");
return THROW_UNLESS((::il2cpp_utils::New<SubInstruction::SubDouble*, creationType>()));
}
// public override System.Int32 Run(System.Linq.Expressions.Interpreter.InterpretedFrame frame)
// Offset: 0x16B25C4
// Implemented from: System.Linq.Expressions.Interpreter.Instruction
// Base method: System.Int32 Instruction::Run(System.Linq.Expressions.Interpreter.InterpretedFrame frame)
int Run(::System::Linq::Expressions::Interpreter::InterpretedFrame* frame);
}; // System.Linq.Expressions.Interpreter.SubInstruction/System.Linq.Expressions.Interpreter.SubDouble
#pragma pack(pop)
}
#include "beatsaber-hook/shared/utils/il2cpp-utils-methods.hpp"
// Writing MetadataGetter for method: System::Linq::Expressions::Interpreter::SubInstruction::SubDouble::New_ctor
// Il2CppName: .ctor
// Cannot get method pointer of value based method overload from template for constructor!
// Try using FindMethod instead!
// Writing MetadataGetter for method: System::Linq::Expressions::Interpreter::SubInstruction::SubDouble::Run
// Il2CppName: Run
template<>
struct ::il2cpp_utils::il2cpp_type_check::MetadataGetter<static_cast<int (System::Linq::Expressions::Interpreter::SubInstruction::SubDouble::*)(::System::Linq::Expressions::Interpreter::InterpretedFrame*)>(&System::Linq::Expressions::Interpreter::SubInstruction::SubDouble::Run)> {
static const MethodInfo* get() {
static auto* frame = &::il2cpp_utils::GetClassFromName("System.Linq.Expressions.Interpreter", "InterpretedFrame")->byval_arg;
return ::il2cpp_utils::FindMethod(classof(System::Linq::Expressions::Interpreter::SubInstruction::SubDouble*), "Run", std::vector<Il2CppClass*>(), ::std::vector<const Il2CppType*>{frame});
}
};
|
/*
Copyright (c) 2003, Arvid Norberg
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.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <iterator>
#include "libtorrent/config.hpp"
#ifdef TORRENT_WINDOWS
#include <direct.h> // for _mkdir and _getcwd
#include <sys/types.h> // for _stat
#include <sys/stat.h>
#endif
#ifdef _MSC_VER
#pragma warning(push, 1)
#endif
#include <boost/bind.hpp>
#include <boost/unordered_set.hpp>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#include "libtorrent/extensions/ut_metadata.hpp"
#include "libtorrent/extensions/ut_pex.hpp"
#include "libtorrent/extensions/smart_ban.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/identify_client.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/ip_filter.hpp"
#include "libtorrent/magnet_uri.hpp"
#include "libtorrent/bitfield.hpp"
#include "libtorrent/peer_info.hpp"
#include "libtorrent/bdecode.hpp"
#include "libtorrent/add_torrent_params.hpp"
#include "libtorrent/time.hpp"
#include "libtorrent/create_torrent.hpp"
#include "torrent_view.hpp"
#include "session_view.hpp"
#include "print.hpp"
using boost::bind;
using libtorrent::total_milliseconds;
void sleep_ms(int milliseconds)
{
#if defined TORRENT_WINDOWS || defined TORRENT_CYGWIN
Sleep(milliseconds);
#elif defined TORRENT_BEOS
snooze_until(system_time() + boost::int64_t(milliseconds) * 1000, B_SYSTEM_TIMEBASE);
#else
usleep(milliseconds * 1000);
#endif
}
#ifdef _WIN32
#include <windows.h>
#include <conio.h>
bool sleep_and_input(int* c, int sleep)
{
for (int i = 0; i < 2; ++i)
{
if (_kbhit())
{
*c = _getch();
return true;
}
Sleep(sleep / 2);
}
return false;
};
#else
#include <stdio.h> // for snprintf
#include <stdlib.h> // for atoi
#include <termios.h>
#include <string.h>
#include <sys/ioctl.h>
#include <signal.h>
struct set_keypress
{
set_keypress()
{
termios new_settings;
tcgetattr(0,&stored_settings);
new_settings = stored_settings;
// Disable canonical mode, and set buffer size to 1 byte
new_settings.c_lflag &= (~ICANON);
new_settings.c_cc[VTIME] = 0;
new_settings.c_cc[VMIN] = 1;
tcsetattr(0,TCSANOW,&new_settings);
}
~set_keypress() { tcsetattr(0,TCSANOW,&stored_settings); }
termios stored_settings;
};
bool sleep_and_input(int* c, int sleep)
{
// sets the terminal to single-character mode
// and resets when destructed
set_keypress s;
libtorrent::time_point start = libtorrent::clock_type::now();
int ret = 0;
retry:
fd_set set;
FD_ZERO(&set);
FD_SET(0, &set);
timeval tv = {sleep/ 1000, (sleep % 1000) * 1000 };
ret = select(1, &set, 0, 0, &tv);
if (ret > 0)
{
*c = getc(stdin);
return true;
}
if (errno == EINTR)
{
if (total_milliseconds(libtorrent::clock_type::now() - start) < sleep)
goto retry;
return false;
}
if (ret < 0 && errno != 0 && errno != ETIMEDOUT)
{
fprintf(stderr, "select failed: %s\n", strerror(errno));
sleep_ms(500);
}
return false;
}
#endif
bool print_trackers = false;
bool print_peers = false;
bool print_log = false;
bool print_downloads = false;
bool print_file_progress = false;
bool show_pad_files = false;
bool show_dht_status = false;
bool sequential_download = false;
bool print_ip = true;
bool print_as = false;
bool print_timers = false;
bool print_block = false;
bool print_peer_rate = false;
bool print_fails = false;
bool print_send_bufs = true;
bool print_disk_stats = false;
// the number of times we've asked to save resume data
// without having received a response (successful or failure)
int num_outstanding_resume_data = 0;
#ifndef TORRENT_DISABLE_DHT
std::vector<libtorrent::dht_lookup> dht_active_requests;
std::vector<libtorrent::dht_routing_bucket> dht_routing_table;
#endif
torrent_view view;
session_view ses_view;
int load_file(std::string const& filename, std::vector<char>& v
, libtorrent::error_code& ec, int limit = 8000000)
{
ec.clear();
FILE* f = fopen(filename.c_str(), "rb");
if (f == NULL)
{
ec.assign(errno, boost::system::generic_category());
return -1;
}
int r = fseek(f, 0, SEEK_END);
if (r != 0)
{
ec.assign(errno, boost::system::generic_category());
fclose(f);
return -1;
}
long s = ftell(f);
if (s < 0)
{
ec.assign(errno, boost::system::generic_category());
fclose(f);
return -1;
}
if (s > limit)
{
fclose(f);
return -2;
}
r = fseek(f, 0, SEEK_SET);
if (r != 0)
{
ec.assign(errno, boost::system::generic_category());
fclose(f);
return -1;
}
v.resize(s);
if (s == 0)
{
fclose(f);
return 0;
}
r = fread(&v[0], 1, v.size(), f);
if (r < 0)
{
ec.assign(errno, boost::system::generic_category());
fclose(f);
return -1;
}
fclose(f);
if (r != s) return -3;
return 0;
}
bool is_absolute_path(std::string const& f)
{
if (f.empty()) return false;
#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2)
int i = 0;
// match the xx:\ or xx:/ form
while (f[i] && strchr("abcdefghijklmnopqrstuvxyz", f[i])) ++i;
if (i < int(f.size()-1) && f[i] == ':' && (f[i+1] == '\\' || f[i+1] == '/'))
return true;
// match the \\ form
if (int(f.size()) >= 2 && f[0] == '\\' && f[1] == '\\')
return true;
return false;
#else
if (f[0] == '/') return true;
return false;
#endif
}
std::string leaf_path(std::string f)
{
if (f.empty()) return "";
char const* first = f.c_str();
char const* sep = strrchr(first, '/');
#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2)
char const* altsep = strrchr(first, '\\');
if (sep == 0 || altsep > sep) sep = altsep;
#endif
if (sep == 0) return f;
if (sep - first == int(f.size()) - 1)
{
// if the last character is a / (or \)
// ignore it
int len = 0;
while (sep > first)
{
--sep;
if (*sep == '/'
#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2)
|| *sep == '\\'
#endif
)
return std::string(sep + 1, len);
++len;
}
return std::string(first, len);
}
return std::string(sep + 1);
}
std::string path_append(std::string const& lhs, std::string const& rhs)
{
if (lhs.empty() || lhs == ".") return rhs;
if (rhs.empty() || rhs == ".") return lhs;
#if defined(TORRENT_WINDOWS) || defined(TORRENT_OS2)
#define TORRENT_SEPARATOR "\\"
bool need_sep = lhs[lhs.size()-1] != '\\' && lhs[lhs.size()-1] != '/';
#else
#define TORRENT_SEPARATOR "/"
bool need_sep = lhs[lhs.size()-1] != '/';
#endif
return lhs + (need_sep?TORRENT_SEPARATOR:"") + rhs;
}
bool is_hex(char const *in, int len)
{
for (char const* end = in + len; in < end; ++in)
{
if (*in >= '0' && *in <= '9') continue;
if (*in >= 'A' && *in <= 'F') continue;
if (*in >= 'a' && *in <= 'f') continue;
return false;
}
return true;
}
std::string print_endpoint(libtorrent::tcp::endpoint const& ep)
{
using namespace libtorrent;
error_code ec;
char buf[200];
address const& addr = ep.address();
#if TORRENT_USE_IPV6
if (addr.is_v6())
snprintf(buf, sizeof(buf), "[%s]:%d", addr.to_string(ec).c_str(), ep.port());
else
#endif
snprintf(buf, sizeof(buf), "%s:%d", addr.to_string(ec).c_str(), ep.port());
return buf;
}
struct torrent_entry
{
torrent_entry(libtorrent::torrent_handle h) : handle(h) {}
libtorrent::torrent_handle handle;
libtorrent::torrent_status status;
};
// maps filenames to torrent_handles
typedef std::map<std::string, libtorrent::torrent_handle> handles_t;
typedef std::map<libtorrent::sha1_hash, std::string> files_t;
files_t hash_to_filename;
using libtorrent::torrent_status;
bool yes(libtorrent::torrent_status const&)
{ return true; }
FILE* g_log_file = 0;
std::string const& piece_bar(libtorrent::bitfield const& p, int width)
{
const int table_size = 18;
double piece_per_char = p.size() / double(width);
static std::string bar;
bar.clear();
bar.reserve(width * 6);
bar += "[";
if (p.size() == 0)
{
for (int i = 0; i < width; ++i) bar += ' ';
bar += "]";
return bar;
}
// the [piece, piece + pieces_per_char) range is the pieces that are represented by each character
double piece = 0;
for (int i = 0; i < width; ++i, piece += piece_per_char)
{
int num_pieces = 0;
int num_have = 0;
int end = (std::max)(int(piece + piece_per_char), int(piece) + 1);
for (int k = int(piece); k < end; ++k, ++num_pieces)
if (p[k]) ++num_have;
int color = int(std::ceil(num_have / float(num_pieces) * (table_size - 1)));
char buf[10];
snprintf(buf, 10, "48;5;%d", 232 + color);
bar += esc(buf);
bar += " ";
}
bar += esc("0");
bar += "]";
return bar;
}
int peer_index(libtorrent::tcp::endpoint addr, std::vector<libtorrent::peer_info> const& peers)
{
using namespace libtorrent;
std::vector<peer_info>::const_iterator i = std::find_if(peers.begin()
, peers.end(), boost::bind(&peer_info::ip, _1) == addr);
if (i == peers.end()) return -1;
return i - peers.begin();
}
// returns the number of lines printed
int print_peer_info(std::string& out
, std::vector<libtorrent::peer_info> const& peers, int max_lines)
{
using namespace libtorrent;
int pos = 0;
if (print_ip) out += "IP ";
out += "progress down (total | peak ) up (total | peak ) sent-req tmo bsy rcv flags dn up source ";
if (print_fails) out += "fail hshf ";
if (print_send_bufs) out += "rq sndb rcvb q-bytes ";
if (print_timers) out += "inactive wait timeout q-time ";
out += " v disk ^ rtt ";
if (print_block) out += "block-progress ";
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
out += "country ";
#endif
if (print_peer_rate) out += "peer-rate est.rec.rate ";
out += "client \x1b[K\n";
++pos;
char str[500];
for (std::vector<peer_info>::const_iterator i = peers.begin();
i != peers.end(); ++i)
{
if (i->flags & (peer_info::handshake | peer_info::connecting))
continue;
if (print_ip)
{
snprintf(str, sizeof(str), "%-30s ", (::print_endpoint(i->ip) +
(i->flags & peer_info::utp_socket ? " [uTP]" : "") +
(i->flags & peer_info::i2p_socket ? " [i2p]" : "")
).c_str());
out += str;
}
char temp[10];
snprintf(temp, sizeof(temp), "%d/%d"
, i->download_queue_length
, i->target_dl_queue_length);
temp[7] = 0;
char peer_progress[10];
snprintf(peer_progress, sizeof(peer_progress), "%.1f%%", i->progress_ppm / 10000.f);
snprintf(str, sizeof(str)
, "%s %s%s (%s|%s) %s%s (%s|%s) %s%7s %4d%4d%4d %s%s%s%s%s%s%s%s%s%s%s%s%s %s%s%s %s%s%s %s%s%s%s%s%s "
, progress_bar(i->progress_ppm / 1000, 15, col_green, '#', '-', peer_progress).c_str()
, esc("32"), add_suffix(i->down_speed, "/s").c_str()
, add_suffix(i->total_download).c_str(), add_suffix(i->download_rate_peak, "/s").c_str()
, esc("31"), add_suffix(i->up_speed, "/s").c_str(), add_suffix(i->total_upload).c_str()
, add_suffix(i->upload_rate_peak, "/s").c_str(), esc("0")
, temp // sent requests and target number of outstanding reqs.
, i->timed_out_requests
, i->busy_requests
, i->upload_queue_length
, color("I", (i->flags & peer_info::interesting)?col_white:col_blue).c_str()
, color("C", (i->flags & peer_info::choked)?col_white:col_blue).c_str()
, color("i", (i->flags & peer_info::remote_interested)?col_white:col_blue).c_str()
, color("c", (i->flags & peer_info::remote_choked)?col_white:col_blue).c_str()
, color("x", (i->flags & peer_info::supports_extensions)?col_white:col_blue).c_str()
, color("o", (i->flags & peer_info::local_connection)?col_white:col_blue).c_str()
, color("p", (i->flags & peer_info::on_parole)?col_white:col_blue).c_str()
, color("O", (i->flags & peer_info::optimistic_unchoke)?col_white:col_blue).c_str()
, color("S", (i->flags & peer_info::snubbed)?col_white:col_blue).c_str()
, color("U", (i->flags & peer_info::upload_only)?col_white:col_blue).c_str()
, color("e", (i->flags & peer_info::endgame_mode)?col_white:col_blue).c_str()
, color("E", (i->flags & peer_info::rc4_encrypted)?col_white:(i->flags & peer_info::plaintext_encrypted)?col_cyan:col_blue).c_str()
, color("h", (i->flags & peer_info::holepunched)?col_white:col_blue).c_str()
, color("d", (i->read_state & peer_info::bw_disk)?col_white:col_blue).c_str()
, color("l", (i->read_state & peer_info::bw_limit)?col_white:col_blue).c_str()
, color("n", (i->read_state & peer_info::bw_network)?col_white:col_blue).c_str()
, color("d", (i->write_state & peer_info::bw_disk)?col_white:col_blue).c_str()
, color("l", (i->write_state & peer_info::bw_limit)?col_white:col_blue).c_str()
, color("n", (i->write_state & peer_info::bw_network)?col_white:col_blue).c_str()
, color("t", (i->source & peer_info::tracker)?col_white:col_blue).c_str()
, color("p", (i->source & peer_info::pex)?col_white:col_blue).c_str()
, color("d", (i->source & peer_info::dht)?col_white:col_blue).c_str()
, color("l", (i->source & peer_info::lsd)?col_white:col_blue).c_str()
, color("r", (i->source & peer_info::resume_data)?col_white:col_blue).c_str()
, color("i", (i->source & peer_info::incoming)?col_white:col_blue).c_str());
out += str;
if (print_fails)
{
snprintf(str, sizeof(str), "%3d %3d "
, i->failcount, i->num_hashfails);
out += str;
}
if (print_send_bufs)
{
snprintf(str, sizeof(str), "%2d %6d %6d%5dkB "
, i->requests_in_buffer, i->used_send_buffer
, i->used_receive_buffer
, i->queue_bytes / 1000);
out += str;
}
if (print_timers)
{
char req_timeout[20] = "-";
// timeout is only meaningful if there is at least one outstanding
// request to the peer
if (i->download_queue_length > 0)
snprintf(req_timeout, sizeof(req_timeout), "%d", i->request_timeout);
snprintf(str, sizeof(str), "%8d %4d %7s %6d "
, int(total_seconds(i->last_active))
, int(total_seconds(i->last_request))
, req_timeout
, int(total_seconds(i->download_queue_time)));
out += str;
}
snprintf(str, sizeof(str), "%s|%s %5d "
, add_suffix(i->pending_disk_bytes).c_str()
, add_suffix(i->pending_disk_read_bytes).c_str()
, i->rtt);
out += str;
if (print_block)
{
if (i->downloading_piece_index >= 0)
{
char buf[50];
snprintf(buf, sizeof(buf), "%d:%d", i->downloading_piece_index, i->downloading_block_index);
out += progress_bar(
i->downloading_progress * 1000 / i->downloading_total, 14, col_green, '-', '#', buf);
}
else
{
out += progress_bar(0, 14);
}
}
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
if (i->country[0] == 0)
{
out += " ..";
}
else
{
snprintf(str, sizeof(str), " %c%c", i->country[0], i->country[1]);
out += str;
}
#endif
if (print_peer_rate)
{
bool unchoked = (i->flags & peer_info::choked) == 0;
snprintf(str, sizeof(str), " %s %s"
, add_suffix(i->remote_dl_rate, "/s").c_str()
, unchoked ? add_suffix(i->estimated_reciprocation_rate, "/s").c_str() : " ");
out += str;
}
out += " ";
if (i->flags & peer_info::handshake)
{
out += esc("31");
out += " waiting for handshake";
out += esc("0");
}
else if (i->flags & peer_info::connecting)
{
out += esc("31");
out += " connecting to peer";
out += esc("0");
}
else
{
out += " ";
out += i->client;
}
out += "\x1b[K\n";
++pos;
if (pos >= max_lines) break;
}
return pos;
}
int listen_port = 6881;
int allocation_mode = libtorrent::storage_mode_sparse;
std::string save_path(".");
int torrent_upload_limit = 0;
int torrent_download_limit = 0;
std::string monitor_dir;
std::string bind_to_interface = "";
int poll_interval = 5;
int max_connections_per_torrent = 50;
bool seed_mode = false;
bool share_mode = false;
bool disable_storage = false;
bool quit = false;
void signal_handler(int signo)
{
// make the main loop terminate
quit = true;
}
void load_torrent(libtorrent::sha1_hash const& ih, std::vector<char>& buf, libtorrent::error_code& ec)
{
files_t::iterator i = hash_to_filename.find(ih);
if (i == hash_to_filename.end())
{
// for magnet links and torrents downloaded via
// URL, the metadata is saved in the resume file
// TODO: pick up metadata from the resume file
ec.assign(boost::system::errc::no_such_file_or_directory, boost::system::generic_category());
return;
}
load_file(i->second.c_str(), buf, ec);
}
// if non-empty, a peer that will be added to all torrents
std::string peer;
using boost::bind;
std::string path_to_url(std::string f)
{
std::string ret = "file://"
#ifdef TORRENT_WINDOWS
"/"
#endif
;
static char const hex_chars[] = "0123456789abcdef";
static const char unreserved[] =
"/-_!.~*()ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
"0123456789";
// make sure the path is an absolute path
if (!is_absolute_path(f))
{
char cwd[TORRENT_MAX_PATH];
#if defined TORRENT_WINDOWS && !defined TORRENT_MINGW
_getcwd(cwd, sizeof(cwd));
#else
getcwd(cwd, sizeof(cwd));
#endif
f = path_append(cwd, f);
}
for (int i = 0; i < f.size(); ++i)
{
#ifdef TORRENT_WINDOWS
if (f[i] == '\\') ret.push_back('/');
else
#endif
if (std::strchr(unreserved, f[i]) != NULL) ret.push_back(f[i]);
else
{
ret.push_back('%');
ret.push_back(hex_chars[f[i] >> 4]);
ret.push_back(hex_chars[f[i] & 0xf]);
}
}
return ret;
}
// monitored_dir is true if this torrent is added because
// it was found in the directory that is monitored. If it
// is, it should be remembered so that it can be removed
// if it's no longer in that directory.
void add_torrent(libtorrent::session& ses
, handles_t& files
, std::set<libtorrent::torrent_handle>& non_files
, std::string torrent
, int allocation_mode
, std::string const& save_path
, bool monitored_dir
, int torrent_upload_limit
, int torrent_download_limit)
{
using namespace libtorrent;
static int counter = 0;
printf("[%d] %s\n", counter++, torrent.c_str());
add_torrent_params p;
if (seed_mode) p.flags |= add_torrent_params::flag_seed_mode;
if (disable_storage) p.storage = disabled_storage_constructor;
if (share_mode) p.flags |= add_torrent_params::flag_share_mode;
std::string filename = path_append(save_path, path_append(".resume"
, leaf_path(torrent) + ".resume"));
error_code ec;
load_file(filename.c_str(), p.resume_data, ec);
p.url = path_to_url(torrent);
p.save_path = save_path;
p.storage_mode = (storage_mode_t)allocation_mode;
p.flags |= add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_duplicate_is_error;
p.flags |= add_torrent_params::flag_auto_managed;
p.userdata = (void*)strdup(torrent.c_str());
ses.async_add_torrent(p);
files.insert(std::pair<const std::string, torrent_handle>(torrent, torrent_handle()));
}
std::vector<std::string> list_dir(std::string path
, bool (*filter_fun)(std::string const&)
, libtorrent::error_code& ec)
{
std::vector<std::string> ret;
#ifdef TORRENT_WINDOWS
if (!path.empty() && path[path.size()-1] != '\\') path += "\\*";
else path += "*";
WIN32_FIND_DATAA fd;
HANDLE handle = FindFirstFileA(path.c_str(), &fd);
if (handle == INVALID_HANDLE_VALUE)
{
ec.assign(GetLastError(), boost::system::system_category());
return ret;
}
do
{
std::string p = fd.cFileName;
if (filter_fun(p))
ret.push_back(p);
} while (FindNextFileA(handle, &fd));
FindClose(handle);
#else
if (!path.empty() && path[path.size()-1] == '/')
path.resize(path.size()-1);
DIR* handle = opendir(path.c_str());
if (handle == 0)
{
ec.assign(errno, boost::system::generic_category());
return ret;
}
struct dirent de;
dirent* dummy;
while (readdir_r(handle, &de, &dummy) == 0)
{
if (dummy == 0) break;
std::string p = de.d_name;
if (filter_fun(p))
ret.push_back(p);
}
closedir(handle);
#endif
return ret;
}
bool filter_fun(std::string const& p)
{
for (int i = p.size() - 1; i >= 0; --i)
{
if (p[i] == '/') break;
#ifdef TORRENT_WINDOWS
if (p[i] == '\\') break;
#endif
if (p[i] != '.') continue;
return p.compare(i, 8, ".torrent") == 0;
}
return false;
}
void scan_dir(std::string const& dir_path
, libtorrent::session& ses
, handles_t& files
, std::set<libtorrent::torrent_handle>& non_files
, int allocation_mode
, std::string const& save_path
, int torrent_upload_limit
, int torrent_download_limit)
{
std::set<std::string> valid;
using namespace libtorrent;
error_code ec;
std::vector<std::string> ents = list_dir(dir_path, filter_fun, ec);
if (ec)
{
fprintf(stderr, "failed to list directory: (%s : %d) %s\n"
, ec.category().name(), ec.value(), ec.message().c_str());
return;
}
for (std::vector<std::string>::iterator i = ents.begin()
, end(ents.end()); i != end; ++i)
{
std::string file = path_append(dir_path, *i);
handles_t::iterator k = files.find(file);
if (k != files.end())
{
valid.insert(file);
continue;
}
// the file has been added to the dir, start
// downloading it.
add_torrent(ses, files, non_files, file, allocation_mode
, save_path, true, torrent_upload_limit, torrent_download_limit);
valid.insert(file);
}
// remove the torrents that are no longer in the directory
for (handles_t::iterator i = files.begin(); !files.empty() && i != files.end();)
{
if (i->first.empty() || valid.find(i->first) != valid.end())
{
++i;
continue;
}
torrent_handle& h = i->second;
if (!h.is_valid())
{
files.erase(i++);
continue;
}
h.auto_managed(false);
h.pause();
// the alert handler for save_resume_data_alert
// will save it to disk
if (h.need_save_resume_data())
{
h.save_resume_data();
++num_outstanding_resume_data;
}
files.erase(i++);
}
}
char const* timestamp()
{
time_t t = std::time(0);
tm* timeinfo = std::localtime(&t);
static char str[200];
std::strftime(str, 200, "%b %d %X", timeinfo);
return str;
}
void print_alert(libtorrent::alert const* a, std::string& str)
{
using namespace libtorrent;
if (a->category() & alert::error_notification)
{
str += esc("31");
}
else if (a->category() & (alert::peer_notification | alert::storage_notification))
{
str += esc("33");
}
str += "[";
str += timestamp();
str += "] ";
str += a->message();
str += esc("0");
if (g_log_file)
fprintf(g_log_file, "[%s] %s\n", timestamp(), a->message().c_str());
}
int save_file(std::string const& filename, std::vector<char>& v)
{
FILE* f = fopen(filename.c_str(), "wb");
if (f == NULL)
return -1;
int w = fwrite(&v[0], 1, v.size(), f);
if (w < 0)
{
fclose(f);
return -1;
}
if (w != int(v.size())) return -3;
fclose(f);
return 0;
}
// returns true if the alert was handled (and should not be printed to the log)
// returns false if the alert was not handled
bool handle_alert(libtorrent::session& ses, libtorrent::alert* a
, handles_t& files, std::set<libtorrent::torrent_handle>& non_files)
{
using namespace libtorrent;
if (session_stats_alert* s = alert_cast<session_stats_alert>(a))
{
ses_view.update_counters(s->values, sizeof(s->values)/sizeof(s->values[0])
, duration_cast<microseconds>(s->timestamp().time_since_epoch()).count());
return true;
}
#ifndef TORRENT_DISABLE_DHT
if (dht_stats_alert* p = alert_cast<dht_stats_alert>(a))
{
dht_active_requests = p->active_requests;
dht_routing_table = p->routing_table;
return true;
}
#endif
#ifdef TORRENT_USE_OPENSSL
if (torrent_need_cert_alert* p = alert_cast<torrent_need_cert_alert>(a))
{
torrent_handle h = p->handle;
std::string base_name = path_append("certificates", to_hex(h.info_hash().to_string()));
std::string cert = base_name + ".pem";
std::string priv = base_name + "_key.pem";
#ifdef TORRENT_WINDOWS
struct ::_stat st;
int ret = ::_stat(cert.c_str(), &st);
if (ret < 0 || (st.st_mode & _S_IFREG) == 0)
#else
struct ::stat st;
int ret = ::stat(cert.c_str(), &st);
if (ret < 0 || (st.st_mode & S_IFREG) == 0)
#endif
{
char msg[256];
snprintf(msg, sizeof(msg), "ERROR. could not load certificate %s: %s\n", cert.c_str(), strerror(errno));
if (g_log_file) fprintf(g_log_file, "[%s] %s\n", timestamp(), msg);
return true;
}
#ifdef TORRENT_WINDOWS
ret = ::_stat(priv.c_str(), &st);
if (ret < 0 || (st.st_mode & _S_IFREG) == 0)
#else
ret = ::stat(priv.c_str(), &st);
if (ret < 0 || (st.st_mode & S_IFREG) == 0)
#endif
{
char msg[256];
snprintf(msg, sizeof(msg), "ERROR. could not load private key %s: %s\n", priv.c_str(), strerror(errno));
if (g_log_file) fprintf(g_log_file, "[%s] %s\n", timestamp(), msg);
return true;
}
char msg[256];
snprintf(msg, sizeof(msg), "loaded certificate %s and key %s\n", cert.c_str(), priv.c_str());
if (g_log_file) fprintf(g_log_file, "[%s] %s\n", timestamp(), msg);
h.set_ssl_certificate(cert, priv, "certificates/dhparams.pem", "1234");
h.resume();
}
#endif
// don't log every peer we try to connect to
if (alert_cast<peer_connect_alert>(a)) return true;
if (peer_disconnected_alert* pd = alert_cast<peer_disconnected_alert>(a))
{
// ignore failures to connect and peers not responding with a
// handshake. The peers that we successfully connect to and then
// disconnect is more interesting.
if (pd->operation == op_connect
|| pd->error == error_code(errors::timed_out_no_handshake
, get_libtorrent_category()))
return true;
}
if (metadata_received_alert* p = alert_cast<metadata_received_alert>(a))
{
// if we have a monitor dir, save the .torrent file we just received in it
// also, add it to the files map, and remove it from the non_files list
// to keep the scan dir logic in sync so it's not removed, or added twice
torrent_handle h = p->handle;
if (h.is_valid())
{
boost::shared_ptr<const torrent_info> ti = h.torrent_file();
create_torrent ct(*ti);
entry te = ct.generate();
std::vector<char> buffer;
bencode(std::back_inserter(buffer), te);
sha1_hash hash = ti->info_hash();
std::string filename = ti->name() + "." + to_hex(hash.to_string()) + ".torrent";
filename = path_append(monitor_dir, filename);
save_file(filename, buffer);
files.insert(std::pair<std::string, libtorrent::torrent_handle>(filename, h));
hash_to_filename.insert(std::make_pair(hash, filename));
non_files.erase(h);
}
}
else if (add_torrent_alert* p = alert_cast<add_torrent_alert>(a))
{
std::string filename;
if (p->params.userdata)
{
filename = (char*)p->params.userdata;
free(p->params.userdata);
}
if (p->error)
{
fprintf(stderr, "failed to add torrent: %s %s\n", filename.c_str()
, p->error.message().c_str());
}
else
{
torrent_handle h = p->handle;
if (!filename.empty())
files[filename] = h;
else
non_files.insert(h);
h.set_max_connections(max_connections_per_torrent);
h.set_max_uploads(-1);
h.set_upload_limit(torrent_upload_limit);
h.set_download_limit(torrent_download_limit);
#ifndef TORRENT_DISABLE_RESOLVE_COUNTRIES
h.resolve_countries(true);
#endif
// if we have a peer specified, connect to it
if (!peer.empty())
{
char* port = (char*) strrchr((char*)peer.c_str(), ':');
if (port > 0)
{
*port++ = 0;
char const* ip = peer.c_str();
int peer_port = atoi(port);
error_code ec;
if (peer_port > 0)
h.connect_peer(tcp::endpoint(address::from_string(ip, ec), peer_port));
}
}
sha1_hash info_hash;
if (p->params.ti)
{
info_hash = p->params.ti->info_hash();
}
else if (!p->params.info_hash.is_all_zeros())
{
info_hash = p->params.info_hash;
}
else
{
info_hash = h.info_hash();
}
hash_to_filename.insert(std::make_pair(info_hash, filename));
}
}
else if (torrent_finished_alert* p = alert_cast<torrent_finished_alert>(a))
{
p->handle.set_max_connections(max_connections_per_torrent / 2);
// write resume data for the finished torrent
// the alert handler for save_resume_data_alert
// will save it to disk
torrent_handle h = p->handle;
h.save_resume_data();
++num_outstanding_resume_data;
}
else if (save_resume_data_alert* p = alert_cast<save_resume_data_alert>(a))
{
--num_outstanding_resume_data;
torrent_handle h = p->handle;
TORRENT_ASSERT(p->resume_data);
if (p->resume_data)
{
std::vector<char> out;
bencode(std::back_inserter(out), *p->resume_data);
torrent_status st = h.status(torrent_handle::query_save_path);
save_file(path_append(st.save_path, path_append(".resume", leaf_path(
hash_to_filename[st.info_hash]) + ".resume")), out);
if (h.is_valid()
&& non_files.find(h) == non_files.end()
&& std::find_if(files.begin(), files.end()
, boost::bind(&handles_t::value_type::second, _1) == h) == files.end())
ses.remove_torrent(h);
}
}
else if (save_resume_data_failed_alert* p = alert_cast<save_resume_data_failed_alert>(a))
{
--num_outstanding_resume_data;
torrent_handle h = p->handle;
if (h.is_valid()
&& non_files.find(h) == non_files.end()
&& std::find_if(files.begin(), files.end()
, boost::bind(&handles_t::value_type::second, _1) == h) == files.end())
ses.remove_torrent(h);
}
else if (torrent_paused_alert* p = alert_cast<torrent_paused_alert>(a))
{
// write resume data for the finished torrent
// the alert handler for save_resume_data_alert
// will save it to disk
torrent_handle h = p->handle;
h.save_resume_data();
++num_outstanding_resume_data;
}
else if (state_update_alert* p = alert_cast<state_update_alert>(a))
{
view.update_torrents(p->status);
return true;
}
return false;
}
void print_piece(libtorrent::partial_piece_info* pp
, libtorrent::cached_piece_info* cs
, std::vector<libtorrent::peer_info> const& peers
, torrent_status const* ts
, std::string& out)
{
using namespace libtorrent;
char str[1024];
assert(pp == 0 || cs == 0 || cs->piece == pp->piece_index);
int piece = pp ? pp->piece_index : cs->piece;
int num_blocks = pp ? pp->blocks_in_piece : cs->blocks.size();
snprintf(str, sizeof(str), "%5d:[", piece);
out += str;
char const* last_color = 0;
for (int j = 0; j < num_blocks; ++j)
{
int index = pp ? peer_index(pp->blocks[j].peer(), peers) % 36 : -1;
char chr = '+';
if (index >= 0)
chr = (index < 10)?'0' + index:'A' + index - 10;
bool snubbed = index >= 0 ? peers[index].flags & peer_info::snubbed : false;
char const* color = "";
if (pp == 0)
{
color = cs->blocks[j] ? esc("34;7") : esc("0");
chr = ' ';
}
else
{
if (cs && cs->blocks[j] && pp->blocks[j].state != block_info::finished)
color = esc("36;7");
else if (pp->blocks[j].bytes_progress > 0
&& pp->blocks[j].state == block_info::requested)
{
if (pp->blocks[j].num_peers > 1) color = esc("1;7");
else color = snubbed ? esc("35;7") : esc("33;7");
chr = '0' + (pp->blocks[j].bytes_progress * 10 / pp->blocks[j].block_size);
}
else if (pp->blocks[j].state == block_info::finished) color = esc("32;7");
else if (pp->blocks[j].state == block_info::writing) color = esc("36;7");
else if (pp->blocks[j].state == block_info::requested) color = snubbed ? esc("35;7") : esc("0");
else { color = esc("0"); chr = ' '; }
}
if (last_color == 0 || strcmp(last_color, color) != 0)
snprintf(str, sizeof(str), "%s%c", color, chr);
else
out += chr;
out += str;
}
out += esc("0");
out += "]";
/*
char const* cache_kind_str[] = {"read", "write", "read-volatile"};
snprintf(str, sizeof(str), " %3d cache age: %-5.1f state: %s%s\n"
, cs ? cs->next_to_hash : 0
, cs ? (total_milliseconds(clock_type::now() - cs->last_use) / 1000.f) : 0.f
, cs ? cache_kind_str[cs->kind] : "N/A"
, ts && ts->pieces.size() ? (ts->pieces[piece] ? " have" : " dont-have") : "");
out += str;
*/
}
int main(int argc, char* argv[])
{
if (argc == 1)
{
fprintf(stderr, "usage: client_test [OPTIONS] [TORRENT|MAGNETURL|URL]\n\n"
"OPTIONS:\n"
"\n CLIENT OPTIONS\n"
" -f <log file> logs all events to the given file\n"
" -s <path> sets the save path for downloads\n"
" -m <path> sets the .torrent monitor directory\n"
" -t <seconds> sets the scan interval of the monitor dir\n"
" -F <milliseconds> sets the UI refresh rate. This is the number of\n"
" milliseconds between screen refreshes.\n"
" -k enable high performance settings. This overwrites any other\n"
" previous command line options, so be sure to specify this first\n"
" -G Add torrents in seed-mode (i.e. assume all pieces\n"
" are present and check hashes on-demand)\n"
" -E <num-threads> specify how many hashing threads to use\n"
"\n BITTORRENT OPTIONS\n"
" -c <limit> sets the max number of connections\n"
" -T <limit> sets the max number of connections per torrent\n"
" -U <rate> sets per-torrent upload rate\n"
" -D <rate> sets per-torrent download rate\n"
" -d <rate> limits the download rate\n"
" -u <rate> limits the upload rate\n"
" -S <limit> limits the upload slots\n"
" -A <num pieces> allowed pieces set size\n"
" -H Don't start DHT\n"
" -X Don't start local peer discovery\n"
" -n announce to trackers in all tiers\n"
" -W <num peers> Set the max number of peers to keep in the peer list\n"
" -B <seconds> sets the peer timeout\n"
" -Q enables share mode. Share mode attempts to maximize\n"
" share ratio rather than downloading\n"
" -K enable piece suggestions of read cache\n"
" -r <IP:port> connect to specified peer\n"
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
" -e force encrypted bittorrent connections\n"
#endif
"\n QUEING OPTIONS\n"
" -v <limit> Set the max number of active downloads\n"
" -^ <limit> Set the max number of active seeds\n"
"\n NETWORK OPTIONS\n"
" -p <port> sets the listen port\n"
#ifndef TORRENT_NO_DEPRECATE
" -o <limit> limits the number of simultaneous\n"
" half-open TCP connections to the\n"
" given number.\n"
#endif
" -w <seconds> sets the retry time for failed web seeds\n"
" -x <file> loads an emule IP-filter file\n"
" -P <host:port> Use the specified SOCKS5 proxy\n"
" -L <user:passwd> Use the specified username and password for the\n"
" proxy specified by -P\n"
" -h allow multiple connections from the same IP\n"
" -M Disable TCP/uTP bandwidth balancing\n"
" -N Do not attempt to use UPnP and NAT-PMP to forward ports\n"
" -Y Rate limit local peers\n"
" -y Disable TCP connections (disable outgoing TCP and reject\n"
" incoming TCP connections)\n"
" -J Disable uTP connections (disable outgoing uTP and reject\n"
" incoming uTP connections)\n"
" -b <IP> sets IP of the interface to bind the\n"
" listen socket to\n"
" -I <IP> sets the IP of the interface to bind\n"
" outgoing peer connections to\n"
#if TORRENT_USE_I2P
" -i <i2p-host> the hostname to an I2P SAM bridge to use\n"
#endif
" -l <limit> sets the listen socket queue size\n"
"\n DISK OPTIONS\n"
" -a <mode> sets the allocation mode. [sparse|allocate]\n"
" -R <num blocks> number of blocks per read cache line\n"
" -C <limit> sets the max cache size. Specified in 16kB blocks\n"
" -j disable disk read-ahead\n"
" -z disable piece hash checks (used for benchmarking)\n"
" -Z <file> mmap the disk cache to the specified file, should be an SSD\n"
" -0 disable disk I/O, read garbage and don't flush to disk\n"
"\n\n"
"TORRENT is a path to a .torrent file\n"
"MAGNETURL is a magnet link\n"
"URL is a url to a torrent file\n"
"\n"
"Example for running benchmark:\n\n"
" client_test -k -z -N -h -H -M -l 2000 -S 1000 -T 1000 -c 1000 test.torrent\n");
;
return 0;
}
using namespace libtorrent;
namespace lt = libtorrent;
settings_pack settings;
settings.set_int(settings_pack::active_loaded_limit, 20);
settings.set_int(settings_pack::choking_algorithm, settings_pack::rate_based_choker);
int refresh_delay = 500;
bool start_dht = true;
std::deque<std::string> events;
time_point next_dir_scan = clock_type::now();
// the string is the filename of the .torrent file, but only if
// it was added through the directory monitor. It is used to
// be able to remove torrents that were added via the directory
// monitor when they're not in the directory anymore.
handles_t files;
// torrents that were not added via the monitor dir
std::set<torrent_handle> non_files;
libtorrent::session ses(fingerprint("LT", LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0)
, lt::session::add_default_plugins | lt::session::start_default_features
, alert::all_categories
& ~(alert::dht_notification
+ alert::progress_notification
+ alert::stats_notification
+ alert::session_log_notification
+ alert::torrent_log_notification
+ alert::peer_log_notification
));
ses.set_load_function(&load_torrent);
std::vector<char> in;
error_code ec;
if (load_file(".ses_state", in, ec) == 0)
{
bdecode_node e;
if (bdecode(&in[0], &in[0] + in.size(), e, ec) == 0)
ses.load_state(e);
}
// load the torrents given on the commandline
std::vector<add_torrent_params> magnet_links;
std::vector<std::string> torrents;
for (int i = 1; i < argc; ++i)
{
if (argv[i][0] != '-')
{
// match it against the <hash>@<tracker> format
if (strlen(argv[i]) > 45
&& ::is_hex(argv[i], 40)
&& (strncmp(argv[i] + 40, "@http://", 8) == 0
|| strncmp(argv[i] + 40, "@udp://", 7) == 0))
{
sha1_hash info_hash;
from_hex(argv[i], 40, (char*)&info_hash[0]);
add_torrent_params p;
if (seed_mode) p.flags |= add_torrent_params::flag_seed_mode;
if (disable_storage) p.storage = disabled_storage_constructor;
if (share_mode) p.flags |= add_torrent_params::flag_share_mode;
p.trackers.push_back(argv[i] + 41);
p.info_hash = info_hash;
p.save_path = save_path;
p.storage_mode = (storage_mode_t)allocation_mode;
p.flags |= add_torrent_params::flag_paused;
p.flags &= ~add_torrent_params::flag_duplicate_is_error;
p.flags |= add_torrent_params::flag_auto_managed;
p.flags |= add_torrent_params::flag_pinned;
magnet_links.push_back(p);
continue;
}
torrents.push_back(argv[i]);
continue;
}
// if there's a flag but no argument following, ignore it
if (argc == i) continue;
char const* arg = argv[i+1];
if (arg == NULL) arg = "";
switch (argv[i][1])
{
case 'f': g_log_file = fopen(arg, "w+"); break;
#ifndef TORRENT_NO_DEPRECATE
case 'o': settings.set_int(settings_pack::half_open_limit, atoi(arg)); break;
#endif
case 'h': settings.set_bool(settings_pack::allow_multiple_connections_per_ip, true); --i; break;
case 'p': listen_port = atoi(arg); break;
case 'k': high_performance_seed(settings); --i; break;
case 'j': settings.set_bool(settings_pack::use_disk_read_ahead, false); --i; break;
case 'z': settings.set_bool(settings_pack::disable_hash_checks, true); --i; break;
case 'K': settings.set_int(settings_pack::suggest_mode, settings_pack::suggest_read_cache); --i; break;
case 'B': settings.set_int(settings_pack::peer_timeout, atoi(arg)); break;
case 'n': settings.set_bool(settings_pack::announce_to_all_tiers, true); --i; break;
case 'G': seed_mode = true; --i; break;
case 'E': settings.set_int(settings_pack::hashing_threads, atoi(arg)); break;
case 'd': settings.set_int(settings_pack::download_rate_limit, atoi(arg) * 1000); break;
case 'u': settings.set_int(settings_pack::upload_rate_limit, atoi(arg) * 1000); break;
case 'S':
settings.set_int(settings_pack::unchoke_slots_limit, atoi(arg));
settings.set_int(settings_pack::choking_algorithm, settings_pack::fixed_slots_choker);
break;
case 'a':
if (strcmp(arg, "allocate") == 0) allocation_mode = storage_mode_allocate;
else if (strcmp(arg, "full") == 0) allocation_mode = storage_mode_allocate;
else if (strcmp(arg, "sparse") == 0) allocation_mode = storage_mode_sparse;
break;
case 's': save_path = arg; break;
case 'U': torrent_upload_limit = atoi(arg) * 1000; break;
case 'D': torrent_download_limit = atoi(arg) * 1000; break;
case 'm': monitor_dir = arg; break;
case 'Q': share_mode = true; --i; break;
case 'b': bind_to_interface = arg; break;
case 'w': settings.set_int(settings_pack::urlseed_wait_retry, atoi(arg)); break;
case 't': poll_interval = atoi(arg); break;
case 'F': refresh_delay = atoi(arg); break;
case 'H':
start_dht = false;
settings.set_bool(settings_pack::enable_dht, false);
--i;
break;
case 'l': settings.set_int(settings_pack::listen_queue_size, atoi(arg)); break;
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
case 'e':
{
settings.set_int(settings_pack::out_enc_policy, settings_pack::pe_forced);
settings.set_int(settings_pack::in_enc_policy, settings_pack::pe_forced);
settings.set_int(settings_pack::allowed_enc_level, settings_pack::pe_rc4);
settings.set_bool(settings_pack::prefer_rc4, true);
--i;
break;
}
#endif
case 'W':
settings.set_int(settings_pack::max_peerlist_size, atoi(arg));
settings.set_int(settings_pack::max_paused_peerlist_size, atoi(arg) / 2);
break;
case 'x':
{
FILE* filter = fopen(arg, "r");
if (filter)
{
ip_filter fil;
unsigned int a,b,c,d,e,f,g,h, flags;
while (fscanf(filter, "%u.%u.%u.%u - %u.%u.%u.%u %u\n", &a, &b, &c, &d, &e, &f, &g, &h, &flags) == 9)
{
address_v4 start((a << 24) + (b << 16) + (c << 8) + d);
address_v4 last((e << 24) + (f << 16) + (g << 8) + h);
if (flags <= 127) flags = ip_filter::blocked;
else flags = 0;
fil.add_rule(start, last, flags);
}
ses.set_ip_filter(fil);
fclose(filter);
}
}
break;
case 'c': settings.set_int(settings_pack::connections_limit, atoi(arg)); break;
case 'T': max_connections_per_torrent = atoi(arg); break;
#if TORRENT_USE_I2P
case 'i':
{
settings.set_str(settings_pack::i2p_hostname, arg);
settings.set_int(settings_pack::i2p_port, 7650);
settings.set_int(settings_pack::proxy_type, settings_pack::i2p_proxy);
break;
}
#endif // TORRENT_USE_I2P
case 'C':
settings.set_int(settings_pack::cache_size, atoi(arg));
settings.set_bool(settings_pack::use_read_cache, atoi(arg) > 0);
settings.set_int(settings_pack::cache_buffer_chunk_size, atoi(arg) / 100);
break;
case 'A': settings.set_int(settings_pack::allowed_fast_set_size, atoi(arg)); break;
case 'R': settings.set_int(settings_pack::read_cache_line_size, atoi(arg)); break;
case 'M': settings.set_int(settings_pack::mixed_mode_algorithm, settings_pack::prefer_tcp); --i; break;
case 'y':
settings.set_bool(settings_pack::enable_outgoing_tcp, false);
settings.set_bool(settings_pack::enable_incoming_tcp, false);
--i;
break;
case 'J':
settings.set_bool(settings_pack::enable_outgoing_utp, false);
settings.set_bool(settings_pack::enable_incoming_utp, false);
--i;
break;
case 'r': peer = arg; break;
case 'P':
{
char* port = (char*) strrchr(arg, ':');
if (port == 0)
{
fprintf(stderr, "invalid proxy hostname, no port found\n");
break;
}
*port++ = 0;
settings.set_str(settings_pack::proxy_hostname, arg);
settings.set_int(settings_pack::proxy_port, atoi(port));
if (atoi(port) == 0) {
fprintf(stderr, "invalid proxy port\n");
break;
}
if (settings.get_int(settings_pack::proxy_type) == settings_pack::none)
settings.set_int(settings_pack::proxy_type, settings_pack::socks5);
}
break;
case 'L':
{
char* pw = (char*) strchr(arg, ':');
if (pw == 0)
{
fprintf(stderr, "invalid proxy username and password specified\n");
break;
}
*pw++ = 0;
settings.set_str(settings_pack::proxy_username, arg);
settings.set_str(settings_pack::proxy_password, pw);
settings.set_int(settings_pack::proxy_type, settings_pack::socks5_pw);
}
break;
case 'I': settings.set_str(settings_pack::outgoing_interfaces, arg); break;
case 'N':
settings.set_bool(settings_pack::enable_upnp, false);
settings.set_bool(settings_pack::enable_natpmp, false);
--i;
break;
case 'Y':
{
--i;
ip_filter pcf;
// 1 is the global peer class. This should be done properly in the future
pcf.add_rule(address_v4::from_string("0.0.0.0")
, address_v4::from_string("255.255.255.255"), 1);
#if TORRENT_USE_IPV6
pcf.add_rule(address_v6::from_string("::")
, address_v6::from_string("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"), 1);
#endif
ses.set_peer_class_filter(pcf);
break;
}
case 'X': settings.set_bool(settings_pack::enable_lsd, false); --i; break;
case 'Z':
settings.set_str(settings_pack::mmap_cache, arg);
settings.set_bool(settings_pack::contiguous_recv_buffer, false);
break;
case 'v': settings.set_int(settings_pack::active_downloads, atoi(arg));
settings.set_int(settings_pack::active_limit, atoi(arg) * 2);
break;
case '^':
settings.set_int(settings_pack::active_seeds, atoi(arg));
settings.set_int(settings_pack::active_limit, atoi(arg) * 2);
break;
case '0': disable_storage = true; --i;
}
++i; // skip the argument
}
// create directory for resume files
#ifdef TORRENT_WINDOWS
int ret = _mkdir(path_append(save_path, ".resume").c_str());
#else
int ret = mkdir(path_append(save_path, ".resume").c_str(), 0777);
#endif
if (ret < 0)
fprintf(stderr, "failed to create resume file directory: (%d) %s\n"
, errno, strerror(errno));
if (bind_to_interface.empty()) bind_to_interface = "0.0.0.0";
char iface_str[100];
snprintf(iface_str, sizeof(iface_str), "%s:%d", bind_to_interface.c_str()
, listen_port);
settings.set_str(settings_pack::listen_interfaces, iface_str);
#ifndef TORRENT_DISABLE_DHT
dht_settings dht;
dht.privacy_lookups = true;
ses.set_dht_settings(dht);
if (start_dht)
{
settings.set_bool(settings_pack::use_dht_as_fallback, false);
ses.add_dht_router(std::make_pair(
std::string("router.bittorrent.com"), 6881));
ses.add_dht_router(std::make_pair(
std::string("router.utorrent.com"), 6881));
ses.add_dht_router(std::make_pair(
std::string("router.bitcomet.com"), 6881));
}
#endif
settings.set_str(settings_pack::user_agent, "client_test/" LIBTORRENT_VERSION);
ses.apply_settings(settings);
for (std::vector<add_torrent_params>::iterator i = magnet_links.begin()
, end(magnet_links.end()); i != end; ++i)
{
ses.async_add_torrent(*i);
}
for (std::vector<std::string>::iterator i = torrents.begin()
, end(torrents.end()); i != end; ++i)
{
if (std::strstr(i->c_str(), "http://") == i->c_str()
|| std::strstr(i->c_str(), "https://") == i->c_str()
|| std::strstr(i->c_str(), "magnet:") == i->c_str())
{
add_torrent_params p;
if (seed_mode) p.flags |= add_torrent_params::flag_seed_mode;
if (disable_storage) p.storage = disabled_storage_constructor;
if (share_mode) p.flags |= add_torrent_params::flag_share_mode;
p.save_path = save_path;
p.storage_mode = (storage_mode_t)allocation_mode;
p.url = *i;
std::vector<char> buf;
if (std::strstr(i->c_str(), "magnet:") == i->c_str())
{
add_torrent_params tmp;
ec.clear();
parse_magnet_uri(*i, tmp, ec);
if (ec) continue;
std::string filename = path_append(save_path, path_append(".resume"
, to_hex(tmp.info_hash.to_string()) + ".resume"));
load_file(filename.c_str(), p.resume_data, ec);
}
printf("adding URL: %s\n", i->c_str());
ses.async_add_torrent(p);
continue;
}
// if it's a torrent file, open it as usual
add_torrent(ses, files, non_files, i->c_str()
, allocation_mode, save_path, false
, torrent_upload_limit, torrent_download_limit);
}
// main loop
std::vector<peer_info> peers;
std::vector<partial_piece_info> queue;
int tick = 0;
#ifndef WIN32
signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);
#endif
while (!quit)
{
++tick;
ses.post_torrent_updates();
ses.post_session_stats();
ses.post_dht_stats();
int terminal_width = 80;
int terminal_height = 50;
terminal_size(&terminal_width, &terminal_height);
view.set_size(terminal_width, terminal_height / 3);
ses_view.set_pos(terminal_height / 3);
int c = 0;
if (sleep_and_input(&c, refresh_delay))
{
#ifdef _WIN32
#define ESCAPE_SEQ 224
#define LEFT_ARROW 75
#define RIGHT_ARROW 77
#define UP_ARROW 72
#define DOWN_ARROW 80
#else
#define ESCAPE_SEQ 27
#define LEFT_ARROW 68
#define RIGHT_ARROW 67
#define UP_ARROW 65
#define DOWN_ARROW 66
#endif
torrent_handle h = view.get_active_handle();
if (c == EOF) { break; }
do
{
if (c == ESCAPE_SEQ)
{
// escape code, read another character
#ifdef WIN32
int c = _getch();
#else
int c = getc(stdin);
if (c == EOF) { break; }
if (c != '[') continue;
c = getc(stdin);
#endif
if (c == EOF) break;
if (c == LEFT_ARROW)
{
// arrow left
int filter = view.filter();
if (filter > 0)
{
--filter;
view.set_filter(filter);
h = view.get_active_handle();
}
}
else if (c == RIGHT_ARROW)
{
// arrow right
int filter = view.filter();
if (filter < torrent_view::torrents_max - 1)
{
++filter;
view.set_filter(filter);
h = view.get_active_handle();
}
}
else if (c == UP_ARROW)
{
// arrow up
view.arrow_up();
h = view.get_active_handle();
}
else if (c == DOWN_ARROW)
{
// arrow down
view.arrow_down();
h = view.get_active_handle();
}
}
if (c == ' ')
{
if (ses.is_paused()) ses.resume();
else ses.pause();
}
// add magnet link
if (c == 'm')
{
char url[4096];
puts("Enter magnet link:\n");
scanf("%4096s", url);
add_torrent_params p;
if (seed_mode) p.flags |= add_torrent_params::flag_seed_mode;
if (disable_storage) p.storage = disabled_storage_constructor;
if (share_mode) p.flags |= add_torrent_params::flag_share_mode;
p.save_path = save_path;
p.storage_mode = (storage_mode_t)allocation_mode;
p.url = url;
std::vector<char> buf;
if (std::strstr(url, "magnet:") == url)
{
add_torrent_params tmp;
parse_magnet_uri(url, tmp, ec);
if (ec) continue;
std::string filename = path_append(save_path, path_append(".resume"
, to_hex(tmp.info_hash.to_string()) + ".resume"));
load_file(filename.c_str(), p.resume_data, ec);
}
printf("adding URL: %s\n", url);
ses.async_add_torrent(p);
}
if (c == 'q') break;
if (c == 'W' && h.is_valid())
{
std::set<std::string> seeds = h.url_seeds();
for (std::set<std::string>::iterator i = seeds.begin()
, end(seeds.end()); i != end; ++i)
{
h.remove_url_seed(*i);
}
seeds = h.http_seeds();
for (std::set<std::string>::iterator i = seeds.begin()
, end(seeds.end()); i != end; ++i)
{
h.remove_http_seed(*i);
}
}
if (c == 'D' && h.is_valid())
{
torrent_status const& st = view.get_active_torrent();
printf("\n\nARE YOU SURE YOU WANT TO DELETE THE FILES FOR '%s'. THIS OPERATION CANNOT BE UNDONE. (y/N)"
, st.name.c_str());
char response = 'n';
scanf("%c", &response);
if (response == 'y')
{
// also delete the .torrent file from the torrent directory
handles_t::iterator i = std::find_if(files.begin(), files.end()
, boost::bind(&handles_t::value_type::second, _1) == st.handle);
if (i != files.end())
{
error_code ec;
std::string path;
if (is_absolute_path(i->first)) path = i->first;
else path = path_append(monitor_dir, i->first);
if (::remove(path.c_str()) < 0)
printf("failed to delete .torrent file: %s\n", ec.message().c_str());
files.erase(i);
}
if (st.handle.is_valid())
ses.remove_torrent(st.handle, lt::session::delete_files);
}
}
if (c == 'j' && h.is_valid())
{
h.force_recheck();
}
if (c == 'r' && h.is_valid())
{
h.force_reannounce();
}
if (c == 's' && h.is_valid())
{
torrent_status const& ts = view.get_active_torrent();
h.set_sequential_download(!ts.sequential_download);
}
if (c == 'R')
{
// save resume data for all torrents
std::vector<torrent_status> torrents;
ses.get_torrent_status(&torrents, &yes, 0);
for (std::vector<torrent_status>::iterator i = torrents.begin()
, end(torrents.end()); i != end; ++i)
{
if (i->need_save_resume)
{
i->handle.save_resume_data();
++num_outstanding_resume_data;
}
}
}
if (c == 'o' && h.is_valid())
{
torrent_status const& ts = view.get_active_torrent();
int num_pieces = ts.num_pieces;
if (num_pieces > 300) num_pieces = 300;
for (int i = 0; i < num_pieces; ++i)
{
h.set_piece_deadline(i, (i+5) * 1000, torrent_handle::alert_when_available);
}
}
if (c == 'v' && h.is_valid())
{
h.scrape_tracker();
}
if (c == 'p' && h.is_valid())
{
torrent_status const& ts = view.get_active_torrent();
if (!ts.auto_managed && ts.paused)
{
h.auto_managed(true);
}
else
{
h.auto_managed(false);
h.pause(torrent_handle::graceful_pause);
}
}
// toggle force-start
if (c == 'k' && h.is_valid())
{
torrent_status const& ts = view.get_active_torrent();
h.auto_managed(!ts.auto_managed);
if (ts.auto_managed && ts.paused) h.resume();
}
if (c == 'c' && h.is_valid())
{
h.clear_error();
}
// toggle displays
if (c == 't') print_trackers = !print_trackers;
if (c == 'i') print_peers = !print_peers;
if (c == 'l') print_log = !print_log;
if (c == 'd') print_downloads = !print_downloads;
if (c == 'f') print_file_progress = !print_file_progress;
if (c == 'P') show_pad_files = !show_pad_files;
if (c == 'g') show_dht_status = !show_dht_status;
if (c == 'u') ses_view.print_utp_stats(!ses_view.print_utp_stats());
if (c == 'x') print_disk_stats = !print_disk_stats;
// toggle columns
if (c == '1') print_ip = !print_ip;
if (c == '2') print_as = !print_as;
if (c == '3') print_timers = !print_timers;
if (c == '4') print_block = !print_block;
if (c == '5') print_peer_rate = !print_peer_rate;
if (c == '6') print_fails = !print_fails;
if (c == '7') print_send_bufs = !print_send_bufs;
if (c == 'h')
{
clear_screen();
set_cursor_pos(0,0);
print(
"HELP SCREEN (press any key to dismiss)\n\n"
"CLIENT OPTIONS\n"
"[q] quit client [m] add magnet link\n"
"\n"
"TORRENT ACTIONS\n"
"[p] pause/unpause selected torrent\n"
"[s] toggle sequential download [j] force recheck\n"
"[space] toggle session pause [c] clear error\n"
"[v] scrape [D] delete torrent and data\n"
"[r] force reannounce [R] save resume data for all torrents\n"
"[o] set piece deadlines (sequential dl) [P] toggle auto-managed\n"
"[k] toggle force-started [W] remove all web seeds\n"
"\n"
"DISPLAY OPTIONS\n"
"left/right arrow keys: select torrent filter\n"
"up/down arrow keys: select torrent\n"
"[i] toggle show peers [d] toggle show downloading pieces\n"
"[u] show uTP stats [f] toggle show files\n"
"[g] show DHT [x] toggle disk cache stats\n"
"[t] show trackers [l] show alert log\n"
"[P] show pad files (in file list)\n"
"\n"
"COLUMN OPTIONS\n"
"[1] toggle IP column [2] toggle AS column\n"
"[3] toggle timers column [4] toggle block progress column\n"
"[5] toggle peer rate column [6] toggle failures column\n"
"[7] toggle send buffers column\n"
);
int tmp;
while (sleep_and_input(&tmp, 500) == false);
}
} while (sleep_and_input(&c, 0));
if (c == 'q') break;
}
// loop through the alert queue to see if anything has happened.
std::vector<alert*> alerts;
ses.pop_alerts(&alerts);
std::string now = timestamp();
for (std::vector<alert*>::iterator i = alerts.begin()
, end(alerts.end()); i != end; ++i)
{
TORRENT_TRY
{
if (!::handle_alert(ses, *i, files, non_files))
{
// if we didn't handle the alert, print it to the log
std::string event_string;
print_alert(*i, event_string);
events.push_back(event_string);
if (events.size() >= 20) events.pop_front();
}
} TORRENT_CATCH(std::exception& e) {}
}
alerts.clear();
std::string out;
char str[500];
int pos = view.height() + ses_view.height();
set_cursor_pos(0, pos);
int cache_flags = print_downloads ? 0 : lt::session::disk_cache_no_pieces;
torrent_handle h = view.get_active_handle();
cache_status cs;
ses.get_cache_info(&cs, h, cache_flags);
#ifndef TORRENT_DISABLE_DHT
if (show_dht_status)
{
// TODO: 3 expose these counters as performance counters
/*
snprintf(str, sizeof(str), "DHT nodes: %d DHT cached nodes: %d "
"total DHT size: %" PRId64 " total observers: %d\n"
, sess_stat.dht_nodes, sess_stat.dht_node_cache, sess_stat.dht_global_nodes
, sess_stat.dht_total_allocations);
out += str;
*/
int bucket = 0;
for (std::vector<dht_routing_bucket>::iterator i = dht_routing_table.begin()
, end(dht_routing_table.end()); i != end; ++i, ++bucket)
{
char const* progress_bar =
"################################"
"################################"
"################################"
"################################";
char const* short_progress_bar = "--------";
snprintf(str, sizeof(str)
, "%3d [%3d, %d] %s%s\x1b[K\n"
, bucket, i->num_nodes, i->num_replacements
, progress_bar + (128 - i->num_nodes)
, short_progress_bar + (8 - (std::min)(8, i->num_replacements)));
out += str;
pos += 1;
}
for (std::vector<dht_lookup>::iterator i = dht_active_requests.begin()
, end(dht_active_requests.end()); i != end; ++i)
{
snprintf(str, sizeof(str)
, " %10s [limit: %2d] "
"in-flight: %-2d "
"left: %-3d "
"1st-timeout: %-2d "
"timeouts: %-2d "
"responses: %-2d "
"last_sent: %-2d\x1b[K\n"
, i->type
, i->branch_factor
, i->outstanding_requests
, i->nodes_left
, i->first_timeout
, i->timeouts
, i->responses
, i->last_sent);
out += str;
pos += 1;
}
}
#endif
if (h.is_valid())
{
torrent_status const& s = view.get_active_torrent();
print((piece_bar(s.pieces, 126) + "\x1b[K\n").c_str());
pos += 1;
if ((print_downloads && s.state != torrent_status::seeding)
|| print_peers)
h.get_peer_info(peers);
if (print_peers && !peers.empty())
pos += print_peer_info(out, peers, terminal_height - pos - 2);
if (print_trackers)
{
std::vector<announce_entry> tr = h.trackers();
time_point now = clock_type::now();
for (std::vector<announce_entry>::iterator i = tr.begin()
, end(tr.end()); i != end; ++i)
{
if (pos + 1 >= terminal_height) break;
snprintf(str, sizeof(str), "%2d %-55s fails: %-3d (%-3d) %s %s %5d \"%s\" %s\x1b[K\n"
, i->tier, i->url.c_str(), i->fails, i->fail_limit, i->verified?"OK ":"- "
, i->updating?"updating"
:to_string(int(total_seconds(i->next_announce - now)), 8).c_str()
, int(i->min_announce > now ? total_seconds(i->min_announce - now) : 0)
, i->last_error ? i->last_error.message().c_str() : ""
, i->message.c_str());
out += str;
pos += 1;
}
}
if (print_downloads)
{
h.get_download_queue(queue);
std::sort(queue.begin(), queue.end(), boost::bind(&partial_piece_info::piece_index, _1)
< boost::bind(&partial_piece_info::piece_index, _2));
std::sort(cs.pieces.begin(), cs.pieces.end(), boost::bind(&cached_piece_info::piece, _1)
> boost::bind(&cached_piece_info::piece, _2));
int p = 0; // this is horizontal position
for (std::vector<cached_piece_info>::iterator i = cs.pieces.begin();
i != cs.pieces.end(); ++i)
{
if (pos + 3 >= terminal_height) break;
partial_piece_info* pp = 0;
partial_piece_info tmp;
tmp.piece_index = i->piece;
std::vector<partial_piece_info>::iterator ppi
= std::lower_bound(queue.begin(), queue.end(), tmp
, boost::bind(&partial_piece_info::piece_index, _1)
< boost::bind(&partial_piece_info::piece_index, _2));
if (ppi != queue.end() && ppi->piece_index == i->piece) pp = &*ppi;
print_piece(pp, &*i, peers, &s, out);
int num_blocks = pp ? pp->blocks_in_piece : i->blocks.size();
p += num_blocks + 8;
bool continuous_mode = 8 + num_blocks > terminal_width;
if (continuous_mode)
{
while (p > terminal_width)
{
p -= terminal_width;
++pos;
}
}
else if (p + num_blocks + 8 > terminal_width)
{
out += "\x1b[K\n";
pos += 1;
p = 0;
}
if (pp) queue.erase(ppi);
}
for (std::vector<partial_piece_info>::iterator i = queue.begin()
, end(queue.end()); i != end; ++i)
{
if (pos + 3 >= terminal_height) break;
print_piece(&*i, 0, peers, &s, out);
int num_blocks = i->blocks_in_piece;
p += num_blocks + 8;
bool continuous_mode = 8 + num_blocks > terminal_width;
if (continuous_mode)
{
while (p > terminal_width)
{
p -= terminal_width;
++pos;
}
}
else if (p + num_blocks + 8 > terminal_width)
{
out += "\x1b[K\n";
pos += 1;
p = 0;
}
}
if (p != 0)
{
out += "\x1b[K\n";
pos += 1;
}
snprintf(str, sizeof(str), "%s %s read cache | %s %s downloading | %s %s cached | %s %s flushed | %s %s snubbed\x1b[K\n"
, esc("34;7"), esc("0") // read cache
, esc("33;7"), esc("0") // downloading
, esc("36;7"), esc("0") // cached
, esc("32;7"), esc("0") // flushed
, esc("35;7"), esc("0") // snubbed
);
out += str;
pos += 1;
}
if (print_file_progress && s.has_metadata)
{
std::vector<boost::int64_t> file_progress;
h.file_progress(file_progress);
std::vector<pool_file_status> file_status;
h.file_status(file_status);
std::vector<int> file_prio = h.file_priorities();
std::vector<pool_file_status>::iterator f = file_status.begin();
boost::shared_ptr<const torrent_info> ti = h.torrent_file();
int p = 0; // this is horizontal position
for (int i = 0; i < ti->num_files(); ++i)
{
if (pos + 1 >= terminal_height) break;
bool pad_file = ti->files().pad_file_at(i);
if (pad_file)
{
if (show_pad_files)
{
snprintf(str, sizeof(str), "\x1b[34m%-70s %s\x1b[0m\x1b[K\n"
, ti->files().file_name(i).c_str()
, add_suffix(ti->files().file_size(i)).c_str());
out += str;
pos += 1;
}
continue;
}
int progress = ti->files().file_size(i) > 0
?file_progress[i] * 1000 / ti->files().file_size(i):1000;
bool complete = file_progress[i] == ti->files().file_size(i);
std::string title = ti->files().file_name(i);
if (!complete)
{
snprintf(str, sizeof(str), " (%.1f%%)", progress / 10.f);
title += str;
}
if (f != file_status.end() && f->file_index == i)
{
title += " [ ";
if ((f->open_mode & file::rw_mask) == file::read_write) title += "read/write ";
else if ((f->open_mode & file::rw_mask) == file::read_only) title += "read ";
else if ((f->open_mode & file::rw_mask) == file::write_only) title += "write ";
if (f->open_mode & file::random_access) title += "random_access ";
if (f->open_mode & file::lock_file) title += "locked ";
if (f->open_mode & file::sparse) title += "sparse ";
title += "]";
++f;
}
const int file_progress_width = 65;
// do we need to line-break?
if (p + file_progress_width + 13 > terminal_width)
{
out += "\x1b[K\n";
pos += 1;
p = 0;
}
snprintf(str, sizeof(str), "%s %7s p: %d ",
progress_bar(progress, file_progress_width, complete ? col_green : col_yellow, '-', '#'
, title.c_str()).c_str()
, add_suffix(file_progress[i]).c_str()
, file_prio[i]);
p += file_progress_width + 13;
out += str;
}
if (p != 0)
{
out += "\x1b[K\n";
pos += 1;
}
}
}
if (print_log)
{
for (std::deque<std::string>::iterator i = events.begin();
i != events.end(); ++i)
{
if (pos + 1 >= terminal_height) break;
out += *i;
out += "\x1b[K\n";
pos += 1;
}
}
// clear rest of screen
out += "\x1b[J";
print(out.c_str());
fflush(stdout);
if (!monitor_dir.empty()
&& next_dir_scan < clock_type::now())
{
scan_dir(monitor_dir, ses, files, non_files
, allocation_mode, save_path, torrent_upload_limit
, torrent_download_limit);
next_dir_scan = clock_type::now() + seconds(poll_interval);
}
}
// keep track of the number of resume data
// alerts to wait for
int num_paused = 0;
int num_failed = 0;
ses.pause();
printf("saving resume data\n");
std::vector<torrent_status> temp;
ses.get_torrent_status(&temp, &yes, 0);
for (std::vector<torrent_status>::iterator i = temp.begin();
i != temp.end(); ++i)
{
torrent_status& st = *i;
if (!st.handle.is_valid())
{
printf(" skipping, invalid handle\n");
continue;
}
if (!st.has_metadata)
{
printf(" skipping %s, no metadata\n", st.name.c_str());
continue;
}
if (!st.need_save_resume)
{
printf(" skipping %s, resume file up-to-date\n", st.name.c_str());
continue;
}
// save_resume_data will generate an alert when it's done
st.handle.save_resume_data();
++num_outstanding_resume_data;
printf("\r%d ", num_outstanding_resume_data);
}
printf("\nwaiting for resume data [%d]\n", num_outstanding_resume_data);
while (num_outstanding_resume_data > 0)
{
alert const* a = ses.wait_for_alert(seconds(10));
if (a == 0) continue;
std::vector<alert*> alerts;
ses.pop_alerts(&alerts);
std::string now = timestamp();
for (std::vector<alert*>::iterator i = alerts.begin()
, end(alerts.end()); i != end; ++i)
{
torrent_paused_alert* tp = alert_cast<torrent_paused_alert>(*i);
if (tp)
{
++num_paused;
printf("\rleft: %d failed: %d pause: %d "
, num_outstanding_resume_data, num_failed, num_paused);
continue;
}
if (alert_cast<save_resume_data_failed_alert>(*i))
{
++num_failed;
--num_outstanding_resume_data;
printf("\rleft: %d failed: %d pause: %d "
, num_outstanding_resume_data, num_failed, num_paused);
continue;
}
save_resume_data_alert* rd = alert_cast<save_resume_data_alert>(*i);
if (!rd) continue;
--num_outstanding_resume_data;
printf("\rleft: %d failed: %d pause: %d "
, num_outstanding_resume_data, num_failed, num_paused);
if (!rd->resume_data) continue;
torrent_handle h = rd->handle;
torrent_status st = h.status(torrent_handle::query_save_path);
std::vector<char> out;
bencode(std::back_inserter(out), *rd->resume_data);
save_file(path_append(st.save_path, path_append(".resume"
, leaf_path(hash_to_filename[st.info_hash]) + ".resume")), out);
}
}
if (g_log_file) fclose(g_log_file);
printf("\nsaving session state\n");
{
entry session_state;
ses.save_state(session_state);
std::vector<char> out;
bencode(std::back_inserter(out), session_state);
save_file(".ses_state", out);
}
printf("closing session");
return 0;
}
|
Name: ys_rpro.asm
Type: file
Size: 119324
Last-Modified: '2016-05-13T04:50:37Z'
SHA-1: 9BC830D5CFABDA386CC53E8C1632FCD0DC07A58E
Description: null
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mash/browser/debug_view.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/gfx/canvas.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
namespace mash {
namespace browser {
DebugView::DebugView()
: interstitial_container_(new views::View),
interstitial_label_(
new views::Label(base::ASCIIToUTF16("Interstitial: "))),
interstitial_show_(
new views::LabelButton(this, base::ASCIIToUTF16("Show"))),
interstitial_hide_(
new views::LabelButton(this, base::ASCIIToUTF16("Hide"))),
interstitial_content_(new views::Textfield) {
AddChildView(interstitial_container_);
interstitial_container_->AddChildView(interstitial_label_);
interstitial_container_->AddChildView(interstitial_show_);
interstitial_container_->AddChildView(interstitial_hide_);
interstitial_container_->AddChildView(interstitial_content_);
views::BoxLayout* layout =
new views::BoxLayout(views::BoxLayout::kHorizontal, 5, 5, 5);
interstitial_container_->SetLayoutManager(layout);
layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
layout->set_cross_axis_alignment(
views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
layout->SetDefaultFlex(0);
layout->SetFlexForView(interstitial_content_, 1);
set_background(views::Background::CreateStandardPanelBackground());
SetLayoutManager(new views::FillLayout);
}
DebugView::~DebugView() {}
gfx::Size DebugView::GetPreferredSize() const {
return interstitial_container_->GetPreferredSize();
}
void DebugView::OnPaint(gfx::Canvas* canvas) {
gfx::Rect stroke_rect = GetLocalBounds();
stroke_rect.set_height(1);
canvas->FillRect(stroke_rect, SK_ColorGRAY);
}
void DebugView::ButtonPressed(views::Button* sender, const ui::Event& event) {
DCHECK(view_);
if (sender == interstitial_show_) {
view_->ShowInterstitial(base::UTF16ToUTF8(interstitial_content_->text()));
} else if (sender == interstitial_hide_) {
view_->HideInterstitial();
}
}
} // namespace browser
} // namespace mash
|
#include "terrain.h"
#include "engine/blob.h"
#include "engine/crc32.h"
#include "engine/geometry.h"
#include "engine/json_serializer.h"
#include "engine/lifo_allocator.h"
#include "engine/log.h"
#include "engine/math_utils.h"
#include "engine/profiler.h"
#include "engine/property_register.h"
#include "engine/resource_manager.h"
#include "engine/resource_manager_base.h"
#include "engine/engine.h"
#include "renderer/material.h"
#include "renderer/model.h"
#include "renderer/render_scene.h"
#include "renderer/shader.h"
#include "renderer/texture.h"
#include "engine/universe/universe.h"
#include <cfloat>
#include <cmath>
namespace Lumix
{
static const float GRASS_QUAD_SIZE = 10.0f;
static const float GRASS_QUAD_RADIUS = GRASS_QUAD_SIZE * 0.7072f;
static const int GRID_SIZE = 16;
static const int COPY_COUNT = 50;
static const ComponentType TERRAIN_HASH = PropertyRegister::getComponentType("terrain");
static const uint32 MORPH_CONST_HASH = crc32("morph_const");
static const uint32 QUAD_SIZE_HASH = crc32("quad_size");
static const uint32 QUAD_MIN_HASH = crc32("quad_min");
static const uint32 BRUSH_POSITION_HASH = crc32("brush_position");
static const uint32 BRUSH_SIZE_HASH = crc32("brush_size");
static const uint32 MAP_SIZE_HASH = crc32("map_size");
static const uint32 CAMERA_POS_HASH = crc32("camera_pos");
static const ResourceType MODEL_TYPE("model");
static const ResourceType MATERIAL_TYPE("material");
static const char* TEX_COLOR_UNIFORM = "u_texColor";
struct Sample
{
Vec3 pos;
float u, v;
};
struct TerrainQuad
{
enum ChildType
{
TOP_LEFT,
TOP_RIGHT,
BOTTOM_LEFT,
BOTTOM_RIGHT,
CHILD_COUNT
};
explicit TerrainQuad(IAllocator& allocator)
: m_allocator(allocator)
{
for (int i = 0; i < CHILD_COUNT; ++i)
{
m_children[i] = nullptr;
}
}
~TerrainQuad()
{
for (int i = 0; i < CHILD_COUNT; ++i)
{
LUMIX_DELETE(m_allocator, m_children[i]);
}
}
void createChildren()
{
if (m_lod < 16 && m_size > 16)
{
for (int i = 0; i < CHILD_COUNT; ++i)
{
m_children[i] = LUMIX_NEW(m_allocator, TerrainQuad)(m_allocator);
m_children[i]->m_lod = m_lod + 1;
m_children[i]->m_size = m_size / 2;
}
m_children[TOP_LEFT]->m_min = m_min;
m_children[TOP_RIGHT]->m_min.set(m_min.x + m_size / 2, 0, m_min.z);
m_children[BOTTOM_LEFT]->m_min.set(m_min.x, 0, m_min.z + m_size / 2);
m_children[BOTTOM_RIGHT]->m_min.set(m_min.x + m_size / 2, 0, m_min.z + m_size / 2);
for (int i = 0; i < CHILD_COUNT; ++i)
{
m_children[i]->createChildren();
}
}
}
float getSquaredDistance(const Vec3& camera_pos)
{
Vec3 _min = m_min;
Vec3 _max(_min.x + m_size, _min.y, _min.z + m_size);
float dist = 0;
if (camera_pos.x < _min.x)
{
float d = _min.x - camera_pos.x;
dist += d*d;
}
if (camera_pos.x > _max.x)
{
float d = _max.x - camera_pos.x;
dist += d*d;
}
if (camera_pos.z < _min.z)
{
float d = _min.z - camera_pos.z;
dist += d*d;
}
if (camera_pos.z > _max.z)
{
float d = _max.z - camera_pos.z;
dist += d*d;
}
return dist;
}
static float getRadiusInner(float size)
{
float lower_level_size = size * 0.5f;
float lower_level_diagonal = Math::SQRT2 * size * 0.5f;
return getRadiusOuter(lower_level_size) + lower_level_diagonal;
}
static float getRadiusOuter(float size)
{
return (size > 17 ? 2.25f : 1.25f) * Math::SQRT2 * size;
}
bool getInfos(Array<TerrainInfo>& infos, const Vec3& camera_pos, Terrain* terrain, const Matrix& world_matrix)
{
float squared_dist = getSquaredDistance(camera_pos);
float r = getRadiusOuter(m_size);
if (squared_dist > r * r && m_lod > 1) return false;
Vec3 morph_const(r, getRadiusInner(m_size), 0);
Shader& shader = *terrain->getMesh()->material->getShader();
for (int i = 0; i < CHILD_COUNT; ++i)
{
if (!m_children[i] || !m_children[i]->getInfos(infos, camera_pos, terrain, world_matrix))
{
TerrainInfo& data = infos.emplace();
data.m_morph_const = morph_const;
data.m_index = i;
data.m_terrain = terrain;
data.m_size = m_size;
data.m_min = m_min;
data.m_shader = &shader;
data.m_world_matrix = world_matrix;
}
}
return true;
}
IAllocator& m_allocator;
TerrainQuad* m_children[CHILD_COUNT];
Vec3 m_min;
float m_size;
int m_lod;
};
Terrain::Terrain(Renderer& renderer, Entity entity, RenderScene& scene, IAllocator& allocator)
: m_mesh(nullptr)
, m_material(nullptr)
, m_root(nullptr)
, m_detail_texture(nullptr)
, m_heightmap(nullptr)
, m_splatmap(nullptr)
, m_width(0)
, m_height(0)
, m_layer_mask(1)
, m_scale(1, 1, 1)
, m_entity(entity)
, m_scene(scene)
, m_allocator(allocator)
, m_grass_quads(m_allocator)
, m_last_camera_position(m_allocator)
, m_grass_types(m_allocator)
, m_renderer(renderer)
, m_vertices_handle(BGFX_INVALID_HANDLE)
, m_indices_handle(BGFX_INVALID_HANDLE)
, m_grass_distance(5)
, m_force_grass_update(false)
{
generateGeometry();
}
Terrain::GrassType::~GrassType()
{
if (m_grass_model)
{
m_grass_model->getResourceManager().unload(*m_grass_model);
m_grass_model->getObserverCb().unbind<GrassType, &GrassType::grassLoaded>(this);
}
}
Terrain::~Terrain()
{
bgfx::destroyIndexBuffer(m_indices_handle);
bgfx::destroyVertexBuffer(m_vertices_handle);
setMaterial(nullptr);
LUMIX_DELETE(m_allocator, m_mesh);
LUMIX_DELETE(m_allocator, m_root);
for(int i = 0; i < m_grass_types.size(); ++i)
{
LUMIX_DELETE(m_allocator, m_grass_types[i]);
}
for (int j = 0; j < m_grass_quads.size(); ++j)
{
Array<GrassQuad*>& quads = m_grass_quads.at(j);
for (int i = 0; i < quads.size(); ++i)
{
LUMIX_DELETE(m_allocator, quads[i]);
}
}
}
Terrain::GrassType::GrassType(Terrain& terrain)
: m_terrain(terrain)
{
m_grass_model = nullptr;
m_ground = 0;
m_density = 10;
m_distance = 50;
}
float Terrain::getRootSize() const
{
return m_root ? m_root->m_size : 0;
}
void Terrain::addGrassType(int index)
{
if(index < 0)
{
m_grass_types.push(LUMIX_NEW(m_allocator, GrassType)(*this));
}
else
{
m_grass_types.insert(index, LUMIX_NEW(m_allocator, GrassType)(*this));
}
}
void Terrain::removeGrassType(int index)
{
forceGrassUpdate();
LUMIX_DELETE(m_allocator, m_grass_types[index]);
m_grass_types.erase(index);
}
void Terrain::setGrassTypeDensity(int index, int density)
{
forceGrassUpdate();
GrassType& type = *m_grass_types[index];
type.m_density = Math::clamp(density, 0, 50);
}
int Terrain::getGrassTypeDensity(int index) const
{
GrassType& type = *m_grass_types[index];
return type.m_density;
}
void Terrain::setGrassTypeDistance(int index, float distance)
{
forceGrassUpdate();
GrassType& type = *m_grass_types[index];
type.m_distance = Math::clamp(distance, 1.0f, FLT_MAX);
m_grass_distance = 0;
for (auto* type : m_grass_types)
{
m_grass_distance = Math::maximum(m_grass_distance, int(type->m_distance / GRASS_QUAD_RADIUS + 0.99f));
}
}
float Terrain::getGrassTypeDistance(int index) const
{
GrassType& type = *m_grass_types[index];
return type.m_distance;
}
void Terrain::setGrassTypeGround(int index, int ground)
{
Lumix::Texture* tex = getMaterial()->getTextureByUniform(TEX_COLOR_UNIFORM);
if(tex) ground = Math::clamp(ground, 0, tex->layers - 1);
forceGrassUpdate();
GrassType& type = *m_grass_types[index];
type.m_ground = ground;
}
int Terrain::getGrassTypeGround(int index) const
{
GrassType& type = *m_grass_types[index];
return type.m_ground;
}
AABB Terrain::getAABB() const
{
Vec3 min(0, 0, 0);
Vec3 max(m_width * m_scale.x, 0, m_height * m_scale.z);
for (int j = 0; j < m_height; ++j)
{
for (int i = 0; i < m_width; ++i)
{
float height = getHeight(i, j);
if (height > max.y) max.y = height;
}
}
return AABB(min, max);
}
Path Terrain::getGrassTypePath(int index)
{
GrassType& type = *m_grass_types[index];
if (type.m_grass_model)
{
return type.m_grass_model->getPath();
}
return Path("");
}
void Terrain::setGrassTypePath(int index, const Path& path)
{
forceGrassUpdate();
GrassType& type = *m_grass_types[index];
if (type.m_grass_model)
{
type.m_grass_model->getResourceManager().unload(*type.m_grass_model);
type.m_grass_model->getObserverCb().unbind<GrassType, &GrassType::grassLoaded>(&type);
type.m_grass_model = nullptr;
}
if (path.isValid())
{
type.m_grass_model = static_cast<Model*>(m_scene.getEngine().getResourceManager().get(MODEL_TYPE)->load(path));
type.m_grass_model->onLoaded<GrassType, &GrassType::grassLoaded>(&type);
}
}
void Terrain::forceGrassUpdate()
{
m_force_grass_update = true;
for (int i = 0; i < m_grass_quads.size(); ++i)
{
Array<GrassQuad*>& quads = m_grass_quads.at(i);
for (GrassQuad* quad : quads)
{
LUMIX_DELETE(m_allocator, quad);
}
quads.clear();
}
}
Array<Terrain::GrassQuad*>& Terrain::getQuads(ComponentHandle camera)
{
int quads_index = m_grass_quads.find(camera);
if (quads_index < 0)
{
m_grass_quads.emplace(camera, m_allocator);
quads_index = m_grass_quads.find(camera);
}
return m_grass_quads.at(quads_index);
}
void Terrain::generateGrassTypeQuad(GrassPatch& patch, const Matrix& terrain_matrix, float quad_x, float quad_z)
{
ASSERT(quad_x >= 0);
ASSERT(quad_z >= 0);
ASSERT(!m_splatmap->data.empty());
ASSERT(m_splatmap->bytes_per_pixel == 4);
PROFILE_FUNCTION();
const float DIV255 = 1 / 255.0f;
Texture* splat_map = m_splatmap;
float step = GRASS_QUAD_SIZE / (float)patch.m_type->m_density;
float quad_width = Math::minimum(GRASS_QUAD_SIZE, splat_map->width - quad_x);
float quad_height = Math::minimum(GRASS_QUAD_SIZE, splat_map->height - quad_z);
float tx_step = splat_map->width / (m_width * m_scale.x);
float base_tx = tx_step * quad_x - tx_step * 0.5f;
struct { float x, y; void* type; } hashed_patch = { quad_x, quad_z, patch.m_type };
uint32 hash = crc32(&hashed_patch, sizeof(hashed_patch));
Math::seedRandom(hash);
for (float dz = 0; dz < quad_height; dz += step)
{
int y_offset = int(splat_map->height * (quad_z + dz) / (m_height * m_scale.x)) * splat_map->width;
uint32* splat_data = &((uint32*)&splat_map->data[0])[y_offset];
for (float dx = 0; dx < quad_width; dx += step)
{
int tx = int(base_tx + tx_step * dx);
uint32 pixel_value = splat_data[tx];
int ground_index = pixel_value & 0xff;
if (ground_index != patch.m_type->m_ground) continue;
float density = ((pixel_value >> 8) & 0xff) * DIV255;
if (density < 0.25f) continue;
Matrix tmp = Matrix::IDENTITY;
float x = quad_x + dx + step * Math::randFloat(-0.5f, 0.5f);
float z = quad_z + dz + step * Math::randFloat(-0.5f, 0.5f);
tmp.setTranslation(Vec3(x, getHeight(x, z), z));
Quat q(Vec3(0, 1, 0), Math::randFloat(0, Math::PI * 2));
tmp = terrain_matrix * tmp * q.toMatrix();
tmp.multiply3x3(density + Math::randFloat(-0.1f, 0.1f));
GrassPatch::InstanceData& instance_data = patch.instance_data.emplace();
instance_data.matrix = tmp;
instance_data.normal = Vec4(getNormal(x, z), 0);
}
}
}
void Terrain::updateGrass(ComponentHandle camera)
{
PROFILE_FUNCTION();
if (!m_splatmap) return;
Universe& universe = m_scene.getUniverse();
Entity camera_entity = m_scene.getCameraEntity(camera);
Vec3 camera_pos = universe.getPosition(camera_entity);
if ((m_last_camera_position[camera] - camera_pos).length() <= FLT_MIN && !m_force_grass_update) return;
m_last_camera_position[camera] = camera_pos;
m_force_grass_update = false;
Matrix terrain_mtx = universe.getMatrix(m_entity);
Matrix inv_mtx = terrain_mtx;
inv_mtx.fastInverse();
Vec3 local_camera_pos = inv_mtx.transform(camera_pos);
float cx = (int)(local_camera_pos.x / (GRASS_QUAD_SIZE)) * GRASS_QUAD_SIZE;
float cz = (int)(local_camera_pos.z / (GRASS_QUAD_SIZE)) * GRASS_QUAD_SIZE;
float from_quad_x = cx - m_grass_distance * GRASS_QUAD_SIZE;
float from_quad_z = cz - m_grass_distance * GRASS_QUAD_SIZE;
float to_quad_x = cx + m_grass_distance * GRASS_QUAD_SIZE;
float to_quad_z = cz + m_grass_distance * GRASS_QUAD_SIZE;
float old_bounds[4] = {FLT_MAX, -FLT_MAX, FLT_MAX, -FLT_MAX};
Array<GrassQuad*>& quads = getQuads(camera);
for (int i = quads.size() - 1; i >= 0; --i)
{
GrassQuad* quad = quads[i];
old_bounds[0] = Math::minimum(old_bounds[0], quad->pos.x);
old_bounds[1] = Math::maximum(old_bounds[1], quad->pos.x);
old_bounds[2] = Math::minimum(old_bounds[2], quad->pos.z);
old_bounds[3] = Math::maximum(old_bounds[3], quad->pos.z);
if (quad->pos.x < from_quad_x || quad->pos.x > to_quad_x || quad->pos.z < from_quad_z ||
quad->pos.z > to_quad_z)
{
LUMIX_DELETE(m_allocator, quads[i]);
quads.eraseFast(i);
}
}
from_quad_x = Math::maximum(0.0f, from_quad_x);
from_quad_z = Math::maximum(0.0f, from_quad_z);
int old_quad_size = quads.size();
for (float quad_z = from_quad_z; quad_z <= to_quad_z; quad_z += GRASS_QUAD_SIZE)
{
for (float quad_x = from_quad_x; quad_x <= to_quad_x; quad_x += GRASS_QUAD_SIZE)
{
if (quad_x >= old_bounds[0] && quad_x <= old_bounds[1] && quad_z >= old_bounds[2] &&
quad_z <= old_bounds[3])
continue;
PROFILE_BLOCK("generate quad");
GrassQuad* quad = LUMIX_NEW(m_allocator, GrassQuad)(m_allocator);
quads.push(quad);
quad->pos.x = quad_x;
quad->pos.z = quad_z;
quad->m_patches.reserve(m_grass_types.size());
float min_y = FLT_MAX;
float max_y = -FLT_MAX;
for (auto* grass_type : m_grass_types)
{
Model* model = grass_type->m_grass_model;
if (!model || !model->isReady()) continue;
GrassPatch& patch = quad->m_patches.emplace(m_allocator);
patch.m_type = grass_type;
generateGrassTypeQuad(patch, terrain_mtx, quad_x, quad_z);
for (auto instance_data : patch.instance_data)
{
min_y = Math::minimum(instance_data.matrix.getTranslation().y, min_y);
max_y = Math::maximum(instance_data.matrix.getTranslation().y, max_y);
}
}
quad->pos.y = (max_y + min_y) * 0.5f;
quad->radius = Math::maximum((max_y - min_y) * 0.5f, GRASS_QUAD_SIZE) * Math::SQRT2;
}
}
}
void Terrain::GrassType::grassLoaded(Resource::State, Resource::State, Resource&)
{
m_terrain.forceGrassUpdate();
}
void Terrain::getGrassInfos(const Frustum& frustum, Array<GrassInfo>& infos, ComponentHandle camera)
{
if (!m_material || !m_material->isReady()) return;
updateGrass(camera);
Array<GrassQuad*>& quads = getQuads(camera);
Universe& universe = m_scene.getUniverse();
Matrix mtx = universe.getMatrix(m_entity);
Vec3 frustum_position = frustum.position;
for (auto* quad : quads)
{
Vec3 quad_center(quad->pos.x + GRASS_QUAD_SIZE * 0.5f, quad->pos.y, quad->pos.z + GRASS_QUAD_SIZE * 0.5f);
quad_center = mtx.transform(quad_center);
if (frustum.isSphereInside(quad_center, quad->radius))
{
float dist2 = (quad_center - frustum_position).squaredLength();
for (int patch_idx = 0; patch_idx < quad->m_patches.size(); ++patch_idx)
{
const GrassPatch& patch = quad->m_patches[patch_idx];
if (patch.m_type->m_distance * patch.m_type->m_distance < dist2) continue;
if (!patch.instance_data.empty())
{
GrassInfo& info = infos.emplace();
info.instance_data = (GrassInfo::InstanceData*)&patch.instance_data[0];
info.instance_count = patch.instance_data.size();
info.model = patch.m_type->m_grass_model;
info.type_distance = patch.m_type->m_distance;
}
}
}
}
}
void Terrain::setMaterial(Material* material)
{
if (material != m_material)
{
if (m_material)
{
m_material->getResourceManager().unload(*m_material);
m_material->getObserverCb().unbind<Terrain, &Terrain::onMaterialLoaded>(this);
}
m_material = material;
m_splatmap = nullptr;
m_heightmap = nullptr;
if (m_mesh && m_material)
{
m_mesh->material = m_material;
m_material->onLoaded<Terrain, &Terrain::onMaterialLoaded>(this);
}
}
else if(material)
{
material->getResourceManager().unload(*material);
}
}
void Terrain::deserialize(InputBlob& serializer,
Universe& universe,
RenderScene& scene,
int version)
{
serializer.read(m_entity);
ComponentHandle cmp = {m_entity.index};
serializer.read(m_layer_mask);
char path[MAX_PATH_LENGTH];
serializer.readString(path, MAX_PATH_LENGTH);
setMaterial(static_cast<Material*>(scene.getEngine().getResourceManager().get(MATERIAL_TYPE)->load(Path(path))));
serializer.read(m_scale.x);
serializer.read(m_scale.y);
m_scale.z = m_scale.x;
int32 count;
serializer.read(m_grass_distance);
serializer.read(count);
while(m_grass_types.size() > count)
{
removeGrassType(m_grass_types.size() - 1);
}
while(m_grass_types.size() < count)
{
addGrassType(-1);
}
for(int i = 0; i < count; ++i)
{
serializer.readString(path, MAX_PATH_LENGTH);
serializer.read(m_grass_types[i]->m_ground);
serializer.read(m_grass_types[i]->m_density);
if (version > (int)RenderSceneVersion::GRASS_TYPE_DISTANCE)
{
serializer.read(m_grass_types[i]->m_distance);
}
setGrassTypePath(i, Path(path));
}
universe.addComponent(m_entity, TERRAIN_HASH, &scene, cmp);
}
void Terrain::serialize(OutputBlob& serializer)
{
serializer.write(m_entity);
serializer.write(m_layer_mask);
serializer.writeString(m_material ? m_material->getPath().c_str() : "");
serializer.write(m_scale.x);
serializer.write(m_scale.y);
serializer.write(m_grass_distance);
serializer.write((int32)m_grass_types.size());
for(int i = 0; i < m_grass_types.size(); ++i)
{
GrassType& type = *m_grass_types[i];
serializer.writeString(type.m_grass_model ? type.m_grass_model->getPath().c_str() : "");
serializer.write(type.m_ground);
serializer.write(type.m_density);
serializer.write(type.m_distance);
}
}
void Terrain::getInfos(Array<TerrainInfo>& infos, const Vec3& camera_pos)
{
if (!m_root) return;
if (!m_material || !m_material->isReady()) return;
Matrix matrix = m_scene.getUniverse().getMatrix(m_entity);
Matrix inv_matrix = matrix;
inv_matrix.fastInverse();
Vec3 local_camera_pos = inv_matrix.transform(camera_pos);
local_camera_pos.x /= m_scale.x;
local_camera_pos.z /= m_scale.z;
m_root->getInfos(infos, local_camera_pos, this, matrix);
}
Vec3 Terrain::getNormal(float x, float z)
{
int int_x = (int)(x / m_scale.x);
int int_z = (int)(z / m_scale.x);
float dec_x = (x - (int_x * m_scale.x)) / m_scale.x;
float dec_z = (z - (int_z * m_scale.x)) / m_scale.x;
if (dec_x > dec_z)
{
float h0 = getHeight(int_x, int_z);
float h1 = getHeight(int_x + 1, int_z);
float h2 = getHeight(int_x + 1, int_z + 1);
return crossProduct(Vec3(m_scale.x, h2 - h0, m_scale.x), Vec3(m_scale.x, h1 - h0, 0)).normalized();
}
else
{
float h0 = getHeight(int_x, int_z);
float h1 = getHeight(int_x + 1, int_z + 1);
float h2 = getHeight(int_x, int_z + 1);
return crossProduct(Vec3(0, h2 - h0, m_scale.x), Vec3(m_scale.x, h1 - h0, m_scale.x)).normalized();
}
}
float Terrain::getHeight(float x, float z) const
{
float inv_scale = 1.0f / m_scale.x;
int int_x = (int)(x * inv_scale);
int int_z = (int)(z * inv_scale);
float dec_x = (x - (int_x * m_scale.x)) * inv_scale;
float dec_z = (z - (int_z * m_scale.x)) * inv_scale;
if (dec_z == 0 && dec_x == 0)
{
return getHeight(int_x, int_z);
}
else if (dec_x > dec_z)
{
float h0 = getHeight(int_x, int_z);
float h1 = getHeight(int_x + 1, int_z);
float h2 = getHeight(int_x + 1, int_z + 1);
return h0 + (h1 - h0) * dec_x + (h2 - h1) * dec_z;
}
else
{
float h0 = getHeight(int_x, int_z);
float h1 = getHeight(int_x + 1, int_z + 1);
float h2 = getHeight(int_x, int_z + 1);
return h0 + (h2 - h0) * dec_z + (h1 - h2) * dec_x;
}
}
float Terrain::getHeight(int x, int z) const
{
const float DIV64K = 1.0f / 65535.0f;
const float DIV255 = 1.0f / 255.0f;
if (!m_heightmap) return 0;
Texture* t = m_heightmap;
ASSERT(t->bytes_per_pixel == 2);
int idx = Math::clamp(x, 0, m_width) + Math::clamp(z, 0, m_height) * m_width;
return m_scale.y * DIV64K * ((uint16*)t->getData())[idx];
}
void Terrain::setHeight(int x, int z, float h)
{
const float DIV64K = 1.0f / 65535.0f;
const float DIV255 = 1.0f / 255.0f;
if (!m_heightmap) return;
Texture* t = m_heightmap;
ASSERT(t->bytes_per_pixel == 2);
int idx = Math::clamp(x, 0, m_width) + Math::clamp(z, 0, m_height) * m_width;
((uint16*)t->getData())[idx] = (uint16)(h * (65535.0f / m_scale.y));
}
bool getRayTriangleIntersection(const Vec3& local_origin, const Vec3& local_dir, const Vec3& p0, const Vec3& p1, const Vec3& p2, float& out)
{
Vec3 normal = crossProduct(p1 - p0, p2 - p0);
float q = dotProduct(normal, local_dir);
if (q == 0)
{
return false;
}
float d = -dotProduct(normal, p0);
float t = -(dotProduct(normal, local_origin) + d) / q;
if (t < 0)
{
return false;
}
Vec3 hit_point = local_origin + local_dir * t;
Vec3 edge0 = p1 - p0;
Vec3 VP0 = hit_point - p0;
if (dotProduct(normal, crossProduct(edge0, VP0)) < 0)
{
return false;
}
Vec3 edge1 = p2 - p1;
Vec3 VP1 = hit_point - p1;
if (dotProduct(normal, crossProduct(edge1, VP1)) < 0)
{
return false;
}
Vec3 edge2 = p0 - p2;
Vec3 VP2 = hit_point - p2;
if (dotProduct(normal, crossProduct(edge2, VP2)) < 0)
{
return false;
}
out = t;
return true;
}
RayCastModelHit Terrain::castRay(const Vec3& origin, const Vec3& dir)
{
RayCastModelHit hit;
hit.m_is_hit = false;
if (m_root)
{
Matrix mtx = m_scene.getUniverse().getMatrix(m_entity);
mtx.fastInverse();
Vec3 rel_origin = mtx.transform(origin);
Vec3 rel_dir = mtx * Vec4(dir, 0);
Vec3 start;
Vec3 size(m_root->m_size * m_scale.x, m_scale.y * 65535.0f, m_root->m_size * m_scale.x);
if (Math::getRayAABBIntersection(rel_origin, rel_dir, m_root->m_min, size, start))
{
int hx = (int)(start.x / m_scale.x);
int hz = (int)(start.z / m_scale.x);
float next_x = fabs(rel_dir.x) < 0.01f ? hx : ((hx + (rel_dir.x < 0 ? 0 : 1)) * m_scale.x - rel_origin.x) / rel_dir.x;
float next_z = fabs(rel_dir.z) < 0.01f ? hz : ((hz + (rel_dir.z < 0 ? 0 : 1)) * m_scale.x - rel_origin.z) / rel_dir.z;
float delta_x = fabs(rel_dir.x) < 0.01f ? 0 : m_scale.x / Math::abs(rel_dir.x);
float delta_z = fabs(rel_dir.z) < 0.01f ? 0 : m_scale.x / Math::abs(rel_dir.z);
int step_x = (int)Math::signum(rel_dir.x);
int step_z = (int)Math::signum(rel_dir.z);
while (hx >= 0 && hz >= 0 && hx + step_x < m_width && hz + step_z < m_height)
{
float t;
float x = hx * m_scale.x;
float z = hz * m_scale.x;
Vec3 p0(x, getHeight(x, z), z);
Vec3 p1(x + m_scale.x, getHeight(x + m_scale.x, z), z);
Vec3 p2(x + m_scale.x, getHeight(x + m_scale.x, z + m_scale.x), z + m_scale.x);
Vec3 p3(x, getHeight(x, z + m_scale.x), z + m_scale.x);
if (getRayTriangleIntersection(rel_origin, rel_dir, p0, p1, p2, t))
{
hit.m_is_hit = true;
hit.m_origin = origin;
hit.m_dir = dir;
hit.m_t = t;
return hit;
}
if (getRayTriangleIntersection(rel_origin, rel_dir, p0, p2, p3, t))
{
hit.m_is_hit = true;
hit.m_origin = origin;
hit.m_dir = dir;
hit.m_t = t;
return hit;
}
if (next_x < next_z)
{
next_x += delta_x;
hx += step_x;
}
else
{
next_z += delta_z;
hz += step_z;
}
if (delta_x == 0 && delta_z == 0)
{
return hit;
}
}
}
}
return hit;
}
static void generateSubgrid(Array<Sample>& samples, Array<short>& indices, int& indices_offset, int start_x, int start_y)
{
for (int j = start_y; j < start_y + 8; ++j)
{
for (int i = start_x; i < start_x + 8; ++i)
{
short idx = short(4 * (i + j * GRID_SIZE));
samples[idx].pos.set((float)(i) / GRID_SIZE, 0, (float)(j) / GRID_SIZE);
samples[idx + 1].pos.set((float)(i + 1) / GRID_SIZE, 0, (float)(j) / GRID_SIZE);
samples[idx + 2].pos.set((float)(i + 1) / GRID_SIZE, 0, (float)(j + 1) / GRID_SIZE);
samples[idx + 3].pos.set((float)(i) / GRID_SIZE, 0, (float)(j + 1) / GRID_SIZE);
samples[idx].u = 0;
samples[idx].v = 0;
samples[idx + 1].u = 1;
samples[idx + 1].v = 0;
samples[idx + 2].u = 1;
samples[idx + 2].v = 1;
samples[idx + 3].u = 0;
samples[idx + 3].v = 1;
indices[indices_offset] = idx;
indices[indices_offset + 1] = idx + 3;
indices[indices_offset + 2] = idx + 2;
indices[indices_offset + 3] = idx;
indices[indices_offset + 4] = idx + 2;
indices[indices_offset + 5] = idx + 1;
indices_offset += 6;
}
}
}
void Terrain::generateGeometry()
{
LUMIX_DELETE(m_allocator, m_mesh);
m_mesh = nullptr;
Array<Sample> points(m_allocator);
points.resize(GRID_SIZE * GRID_SIZE * 4);
Array<short> indices(m_allocator);
indices.resize(GRID_SIZE * GRID_SIZE * 6);
int indices_offset = 0;
generateSubgrid(points, indices, indices_offset, 0, 0);
generateSubgrid(points, indices, indices_offset, 8, 0);
generateSubgrid(points, indices, indices_offset, 0, 8);
generateSubgrid(points, indices, indices_offset, 8, 8);
bgfx::VertexDecl vertex_def;
vertex_def.begin()
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
.end();
m_vertices_handle = bgfx::createVertexBuffer(bgfx::copy(&points[0], sizeof(points[0]) * points.size()), vertex_def);
auto* indices_mem = bgfx::copy(&indices[0], sizeof(indices[0]) * indices.size());
m_indices_handle = bgfx::createIndexBuffer(indices_mem);
m_mesh = LUMIX_NEW(m_allocator, Mesh)(
m_material, 0, int(points.size() * sizeof(points[0])), 0, int(indices.size()), "terrain", m_allocator);
}
TerrainQuad* Terrain::generateQuadTree(float size)
{
TerrainQuad* root = LUMIX_NEW(m_allocator, TerrainQuad)(m_allocator);
root->m_lod = 1;
root->m_min.set(0, 0, 0);
root->m_size = size;
root->createChildren();
return root;
}
void Terrain::onMaterialLoaded(Resource::State, Resource::State new_state, Resource&)
{
PROFILE_FUNCTION();
if (new_state == Resource::State::READY)
{
m_detail_texture = m_material->getTextureByUniform(TEX_COLOR_UNIFORM);
m_heightmap = m_material->getTextureByUniform("u_texHeightmap");
bool is_data_ready = true;
if (m_heightmap && m_heightmap->getData() == nullptr)
{
m_heightmap->addDataReference();
is_data_ready = false;
}
m_splatmap = m_material->getTextureByUniform("u_texSplatmap");
if (m_splatmap && m_splatmap->getData() == nullptr)
{
m_splatmap->addDataReference();
is_data_ready = false;
}
Texture* colormap = m_material->getTextureByUniform("u_texColormap");
if (colormap && colormap->getData() == nullptr)
{
colormap->addDataReference();
is_data_ready = false;
}
if (is_data_ready)
{
LUMIX_DELETE(m_allocator, m_root);
if (m_heightmap && m_splatmap)
{
m_width = m_heightmap->width;
m_height = m_heightmap->height;
m_root = generateQuadTree((float)m_width);
}
}
}
else
{
LUMIX_DELETE(m_allocator, m_root);
m_root = nullptr;
}
}
} // namespace Lumix |
// Copyright (c) 2011-2016, NVIDIA CORPORATION. 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.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <dp/DP.h>
#include <dp/sg/xbar/SceneTree.h>
#include <dp/sg/renderer/rix/gl/inc/ResourceTexture.h>
#include <dp/sg/renderer/rix/gl/inc/ResourceManager.h>
#include <dp/sg/renderer/rix/gl/inc/Utility.h>
#include <dp/rix/gl/inc/DataTypeConversionGL.h>
#include <dp/rix/gl/RiXGL.h>
#include <dp/sg/gl/TextureGL.h>
#include <dp/sg/core/Buffer.h>
#include <dp/sg/core/TextureHost.h>
#include <dp/sg/core/TextureFile.h>
#include <dp/sg/io/IO.h>
namespace dp
{
namespace sg
{
namespace renderer
{
namespace rix
{
namespace gl
{
ResourceTextureSharedPtr ResourceTexture::get( const dp::sg::core::TextureSharedPtr& texture, const ResourceManagerSharedPtr& resourceManager )
{
DP_ASSERT( texture );
DP_ASSERT( !!resourceManager );
ResourceTextureSharedPtr resourceTexture = resourceManager->getResource<ResourceTexture>( reinterpret_cast<size_t>(texture.operator->()) ); // Big Hack !!
if ( !resourceTexture )
{
resourceTexture = std::shared_ptr<ResourceTexture>( new ResourceTexture( texture, resourceManager ) );
}
return resourceTexture;
}
inline dp::PixelFormat getRiXPixelFormat( dp::sg::core::Image::PixelFormat pixelFormat )
{
switch ( pixelFormat )
{
case dp::sg::core::Image::PixelFormat::RGB:
return dp::PixelFormat::RGB;
case dp::sg::core::Image::PixelFormat::RGBA:
return dp::PixelFormat::RGBA;
case dp::sg::core::Image::PixelFormat::BGR:
return dp::PixelFormat::BGR;
case dp::sg::core::Image::PixelFormat::BGRA:
return dp::PixelFormat::BGRA;
case dp::sg::core::Image::PixelFormat::LUMINANCE:
return dp::PixelFormat::LUMINANCE;
case dp::sg::core::Image::PixelFormat::ALPHA:
return dp::PixelFormat::ALPHA;
case dp::sg::core::Image::PixelFormat::LUMINANCE_ALPHA:
return dp::PixelFormat::LUMINANCE_ALPHA;
default:
DP_ASSERT( !"unknown pixel format, assuming PixelFormat::RGB");
return dp::PixelFormat::RGB;
}
}
dp::rix::core::TextureType getRiXTextureType( dp::sg::core::TextureSharedPtr const& texture )
{
dp::rix::core::TextureType tt;
switch ( texture->getTextureTarget() )
{
case dp::sg::core::TextureTarget::TEXTURE_1D:
tt = dp::rix::core::TextureType::_1D;
break;
case dp::sg::core::TextureTarget::TEXTURE_1D_ARRAY:
tt =dp::rix::core::TextureType::_1D_ARRAY;
break;
case dp::sg::core::TextureTarget::TEXTURE_2D:
tt =dp::rix::core::TextureType::_2D;
break;
case dp::sg::core::TextureTarget::TEXTURE_RECTANGLE:
tt =dp::rix::core::TextureType::_2D_RECTANGLE;
break;
case dp::sg::core::TextureTarget::TEXTURE_2D_ARRAY:
tt =dp::rix::core::TextureType::_2D_ARRAY;
break;
case dp::sg::core::TextureTarget::TEXTURE_3D:
tt =dp::rix::core::TextureType::_3D;
break;
case dp::sg::core::TextureTarget::TEXTURE_CUBE:
tt =dp::rix::core::TextureType::CUBEMAP;
break;
case dp::sg::core::TextureTarget::TEXTURE_CUBE_ARRAY:
tt =dp::rix::core::TextureType::CUBEMAP_ARRAY;
break;
case dp::sg::core::TextureTarget::TEXTURE_BUFFER:
DP_ASSERT( !"texture type not yet supported" );
return dp::rix::core::TextureType::NUM_TEXTURETYPES;
default:
DP_ASSERT( !"unknwon texture type");
return dp::rix::core::TextureType::NUM_TEXTURETYPES;
}
return tt;
}
dp::rix::core::TextureSharedHandle ResourceTexture::getRiXTexture( dp::sg::core::TextureHostSharedPtr const& texture )
{
dp::rix::core::Renderer *renderer = m_resourceManager->getRenderer();
// TODO assumes that all images have the same datatype
dp::rix::core::TextureType tt;
size_t width = 0;
size_t height = 0;
size_t depth = 0;
size_t layers = 0;
switch( texture->getTextureTarget() )
{
case dp::sg::core::TextureTarget::TEXTURE_1D:
tt = dp::rix::core::TextureType::_1D;
width = texture->getWidth();
break;
case dp::sg::core::TextureTarget::TEXTURE_1D_ARRAY:
tt = dp::rix::core::TextureType::_1D_ARRAY;
width = texture->getWidth();
layers = texture->getNumberOfImages();
break;
case dp::sg::core::TextureTarget::TEXTURE_2D:
tt = dp::rix::core::TextureType::_2D;
width = texture->getWidth();
height = texture->getHeight();
break;
case dp::sg::core::TextureTarget::TEXTURE_RECTANGLE:
tt = dp::rix::core::TextureType::_2D_RECTANGLE;
width = texture->getWidth();
height = texture->getHeight();
break;
case dp::sg::core::TextureTarget::TEXTURE_2D_ARRAY:
tt = dp::rix::core::TextureType::_2D_ARRAY;
width = texture->getWidth();
height = texture->getHeight();
layers = texture->getNumberOfImages();
break;
case dp::sg::core::TextureTarget::TEXTURE_3D:
tt = dp::rix::core::TextureType::_3D;
width = texture->getWidth();
height = texture->getHeight();
depth = texture->getDepth();
break;
case dp::sg::core::TextureTarget::TEXTURE_CUBE:
tt = dp::rix::core::TextureType::CUBEMAP;
width = texture->getWidth();
height = texture->getHeight();
break;
case dp::sg::core::TextureTarget::TEXTURE_CUBE_ARRAY:
tt = dp::rix::core::TextureType::CUBEMAP_ARRAY;
width = texture->getWidth();
height = texture->getHeight();
layers = texture->getNumberOfImages() / 6; // !
break;
case dp::sg::core::TextureTarget::TEXTURE_BUFFER:
DP_ASSERT( !"texture type not yet supported" );
return nullptr;
default:
DP_ASSERT( !"unknwon texture type");
return nullptr;
}
// use SceniX capability to determine the best internal GL format and pass it in as GL format
dp::sg::gl::GLTexImageFmt texFormat;
// get the user-provided requested GPU format
dp::sg::core::TextureHost::TextureGPUFormat gpuFormat = texture->getTextureGPUFormat();
// receive the GL texture format description here
if ( !dp::sg::gl::TextureGL::getTexImageFmt(texFormat, texture->getFormat(), texture->getType(), gpuFormat) )
{
DP_ASSERT( !"ERROR: could not fetch valid texture format!\n");
return nullptr;
}
bool mipMaps = texture->isMipmapRequired();
dp::rix::gl::TextureDescriptionGL td( tt, dp::rix::core::InternalTextureFormat::NATIVE, getRiXPixelFormat( texture->getFormat() ), getRiXDataType( texture->getType() ), width, height, depth, layers, mipMaps );
td.m_internalFormatGL = texFormat.intFmt;
return renderer->textureCreate( td );
}
void ResourceTexture::updateRiXTexture( const dp::rix::core::TextureSharedHandle& rixTexture, dp::sg::core::TextureHostSharedPtr const& texture )
{
std::vector<dp::sg::core::Buffer::DataReadLock> buffers; // Keep these locks until textureSetData() is done with the input pointers.
std::vector<void const *> data;
dp::PixelFormat pixelFormat = getRiXPixelFormat( texture->getFormat() );
dp::DataType pixelDataType = getRiXDataType( texture->getType() );
for ( unsigned int img = 0; img < texture->getNumberOfImages(); ++img )
{
for ( unsigned int lod = 0; lod < texture->getNumberOfMipmaps() + 1; ++lod ) // + 1 for LOD 0.
{
buffers.push_back( dp::sg::core::Buffer::DataReadLock( texture->getPixels(img, lod) ) );
data.push_back( buffers.back().getPtr() );
}
}
// getNumberOfMipmaps() does NOT include LOD 0 in SceniX!
// RiX generates mipmaps when numMipMapLevels == 0 and the Texture
unsigned int numMipMapLevels = texture->getNumberOfMipmaps();
// If mipmaps are provided include the LOD 0 in the count for RiX.
if (numMipMapLevels)
{
numMipMapLevels++;
}
dp::rix::core::TextureDataPtr dataPtr( &data[0], numMipMapLevels, texture->getNumberOfImages(), pixelFormat, pixelDataType );
m_resourceManager->getRenderer()->textureSetData( m_textureHandle, dataPtr );
}
ResourceTexture::ResourceTexture( const dp::sg::core::TextureSharedPtr& texture, const ResourceManagerSharedPtr& resourceManager )
: ResourceManager::Resource( reinterpret_cast<size_t>( texture.operator->() ), resourceManager ) // Big Hack !!
, m_texture( texture )
, m_isNativeTexture( false )
{
resourceManager->subscribe( this );
update();
}
ResourceTexture::~ResourceTexture()
{
if ( m_resourceManager )
{
m_resourceManager->unsubscribe( this );
}
}
dp::sg::core::HandledObjectSharedPtr ResourceTexture::getHandledObject() const
{
return std::static_pointer_cast<dp::sg::core::HandledObject>(m_texture);
}
void ResourceTexture::update()
{
if( m_isNativeTexture )
{
return;
}
dp::rix::core::Renderer *renderer = m_resourceManager->getRenderer();
if ( std::dynamic_pointer_cast<dp::sg::core::TextureFile>(m_texture) )
{
// It's a file texture. Generate a TextureHost out of the TextureFile and upload it.
dp::sg::core::TextureFileSharedPtr const& textureFile = std::static_pointer_cast<dp::sg::core::TextureFile>(m_texture);
dp::sg::core::TextureHostSharedPtr textureHost = dp::sg::io::loadTextureHost(textureFile->getFilename(), dp::util::FileFinder{ dp::home() });
if ( textureHost )
{
textureHost->setTextureTarget( textureFile->getTextureTarget() );
// If TextureFile required mipmaps increase the mipmap count of the loaded TextureHost so that it
// requires mipmaps too.
if ( textureFile->isMipmapRequired() )
{
textureHost->incrementMipmapUseCount();
}
m_textureHandle = getRiXTexture( textureHost );
updateRiXTexture( m_textureHandle, textureHost );
}
}
// TODO buffers are not being observed
else if ( std::dynamic_pointer_cast<dp::sg::core::TextureHost>(m_texture) )
{
dp::sg::core::TextureHostSharedPtr const& textureHost = std::static_pointer_cast<dp::sg::core::TextureHost>(m_texture);
m_textureHandle = getRiXTexture( textureHost );
updateRiXTexture( m_textureHandle, textureHost );
}
else if ( std::dynamic_pointer_cast<dp::sg::gl::TextureGL>(m_texture) )
{
dp::sg::gl::TextureGLSharedPtr const& textureGL = std::static_pointer_cast<dp::sg::gl::TextureGL>(m_texture);
dp::rix::gl::TextureDescriptionGL td( getRiXTextureType(m_texture), dp::rix::core::InternalTextureFormat::NATIVE, dp::rix::gl::getDPPixelFormat( textureGL->getTexture()->getFormat() )
, dp::rix::gl::getDPDataType( textureGL->getTexture()->getType() ) );
m_textureHandle = renderer->textureCreate( td );
renderer->textureSetData( m_textureHandle, dp::rix::gl::TextureDataGLTexture( textureGL->getTexture() ) );
}
else
{
DP_ASSERT( 0 && "unknown texture type");
}
// TODO: extend for TextureSharedPtr support
}
} // namespace gl
} // namespace rix
} // namespace renderer
} // namespace sg
} // namespace dp
|
; This table contains the pointers to each dialogue and the text macro pointers
dl Message0000,Message0001,Message0002,Message0003
dl Message0004,Message0005,Message0006,Message0007
dl Message0008,Message0009,Message000A,Message000B
dl Message000C,Message000D,Message000E,Message000F
dl Message0010,Message0011,Message0012,Message0013
dl Message0014,Message0015,Message0016,Message0017
dl Message0018,Message0019,Message001A,Message001B
dl Message001C,Message001D,Message001E,Message001F
dl Message0020,Message0021,Message0022,Message0023
dl Message0024,Message0025,Message0026,Message0027
dl Message0028,Message0029,Message002A,Message002B
dl Message002C,Message002D,Message002E,Message002F
dl Message0030,Message0031,Message0032,Message0033
dl Message0034,Message0035,Message0036,Message0037
dl Message0038,Message0039,Message003A,Message003B
dl Message003C,Message003D,Message003E,Message003F
dl Message0040,Message0041,Message0042,Message0043
dl Message0044,Message0045,Message0046,Message0047
dl Message0048,Message0049,Message004A,Message004B
dl Message004C,Message004D,Message004E,Message004F
dl Message0050,Message0051,Message0052,Message0053
dl Message0054,Message0055,Message0056,Message0057
dl Message0058,Message0059,Message005A,Message005B
dl Message005C,Message005D,Message005E,Message005F
dl Message0060,Message0061,Message0062,Message0063
dl Message0064,Message0065,Message0066,Message0067
dl Message0068,Message0069,Message006A,Message006B
dl Message006C,Message006D,Message006E,Message006F
dl Message0070,Message0071,Message0072,Message0073
dl Message0074,Message0075,Message0076,Message0077
dl Message0078,Message0079,Message007A,Message007B
dl Message007C,Message007D,Message007E,Message007F
dl Message0080,Message0081,Message0082,Message0083
dl Message0084,Message0085,Message0086,Message0087
dl Message0088,Message0089,Message008A,Message008B
dl Message008C,Message008D,Message008E,Message008F
dl Message0090,Message0091,Message0092,Message0093
dl Message0094,Message0095,Message0096,Message0097
dl Message0098,Message0099,Message009A,Message009B
dl Message009C,Message009D,Message009E,Message009F
dl Message00A0,Message00A1,Message00A2,Message00A3
dl Message00A4,Message00A5,Message00A6,Message00A7
dl Message00A8,Message00A9,Message00AA,Message00AB
dl Message00AC,Message00AD,Message00AE,Message00AF
dl Message00B0,Message00B1,Message00B2,Message00B3
dl Message00B4,Message00B5,Message00B6,Message00B7
dl Message00B8,Message00B9,Message00BA,Message00BB
dl Message00BC,Message00BD,Message00BE,Message00BF
dl Message00C0,Message00C1,Message00C2,Message00C3
dl Message00C4,Message00C5,Message00C6,Message00C7
dl Message00C8,Message00C9,Message00CA,Message00CB
dl Message00CC,Message00CD,Message00CE,Message00CF
dl Message00D0,Message00D1,Message00D2,Message00D3
dl Message00D4,Message00D5,Message00D6,Message00D7
dl Message00D8,Message00D9,Message00DA,Message00DB
dl Message00DC,Message00DD,Message00DE,Message00DF
dl Message00E0,Message00E1,Message00E2,Message00E3
dl Message00E4,Message00E5,Message00E6,Message00E7
dl Message00E8,Message00E9,Message00EA,Message00EB
dl Message00EC,Message00ED,Message00EE,Message00EF
dl Message00F0,Message00F1,Message00F2,Message00F3
dl Message00F4,Message00F5,Message00F6,Message00F7
dl Message00F8,Message00F9,Message00FA,Message00FB
dl Message00FC,Message00FD,Message00FE,Message00FF
TextMacroPointers:
dw TextMacros_TM0000,TextMacros_TM0001,TextMacros_TM0002,TextMacros_TM0003
dw TextMacros_TM0004,TextMacros_TM0005,TextMacros_TM0006,TextMacros_TM0007
dw TextMacros_TM0008,TextMacros_TM0009,TextMacros_TM000A,TextMacros_TM000B
dw TextMacros_TM000C,TextMacros_TM000D,TextMacros_TM000E,TextMacros_TM000F
dw TextMacros_TM0010,TextMacros_TM0011,TextMacros_TM0012,TextMacros_TM0013
dw TextMacros_TM0014,TextMacros_TM0015,TextMacros_TM0016,TextMacros_TM0017
dw TextMacros_TM0018,TextMacros_TM0019,TextMacros_TM001A,TextMacros_TM001B
dw TextMacros_TM001C,TextMacros_TM001D,TextMacros_TM001E,TextMacros_TM001F
dw TextMacros_TM0020,TextMacros_TM0021,TextMacros_TM0022,TextMacros_TM0023
dw TextMacros_TM0024,TextMacros_TM0025,TextMacros_TM0026,TextMacros_TM0027
dw TextMacros_TM0028,TextMacros_TM0029,TextMacros_TM002A,TextMacros_TM002B
dw TextMacros_TM002C,TextMacros_TM002D,TextMacros_TM002E,TextMacros_TM002F
dw TextMacros_TM0030,TextMacros_TM0031,TextMacros_TM0032,TextMacros_TM0033
dw TextMacros_TM0034,TextMacros_TM0035,TextMacros_TM0036,TextMacros_TM0037
dw TextMacros_TM0038,TextMacros_TM0039,TextMacros_TM003A,TextMacros_TM003B
dw TextMacros_TM003C,TextMacros_TM003D,TextMacros_TM003E,TextMacros_TM003F
dw TextMacros_TM0040,TextMacros_TM0041,TextMacros_TM0042,TextMacros_TM0043
dw TextMacros_TM0044,TextMacros_TM0045,TextMacros_TM0046,TextMacros_TM0047
dw TextMacros_TM0048,TextMacros_TM0049,TextMacros_TM004A,TextMacros_TM004B
dw TextMacros_TM004C,TextMacros_TM004D,TextMacros_TM004E,TextMacros_TM004F
dw TextMacros_TM0050,TextMacros_TM0051,TextMacros_TM0052,TextMacros_TM0053
dw TextMacros_TM0054,TextMacros_TM0055,TextMacros_TM0056,TextMacros_TM0057
dw TextMacros_TM0058,TextMacros_TM0059,TextMacros_TM005A,TextMacros_TM005B
dw TextMacros_TM005C,TextMacros_TM005D,TextMacros_TM005E,TextMacros_TM005F
dw TextMacros_TM0060,TextMacros_TM0061,TextMacros_TM0062,TextMacros_TM0063
dw TextMacros_TM0064,TextMacros_TM0065,TextMacros_TM0066,TextMacros_TM0067
dw TextMacros_TM0068,TextMacros_TM0069,TextMacros_TM006A,TextMacros_TM006B
dw TextMacros_TM006C,TextMacros_TM006D,TextMacros_TM006E,TextMacros_TM006F
dw TextMacros_TM0070,TextMacros_TM0071,TextMacros_TM0072,TextMacros_TM0073
dw TextMacros_TM0074,TextMacros_TM0075,TextMacros_TM0076,TextMacros_TM0077
dw TextMacros_TM0078,TextMacros_TM0079,TextMacros_TM007A,TextMacros_TM007B
dw TextMacros_TM007C,TextMacros_TM007D,TextMacros_TM007E,TextMacros_TM007F
dw TextMacros_TM0080,TextMacros_TM0081,TextMacros_TM0082,TextMacros_TM0083
dw TextMacros_TM0084,TextMacros_TM0085,TextMacros_TM0086,TextMacros_TM0087
dw TextMacros_TM0088,TextMacros_TM0089,TextMacros_TM008A,TextMacros_TM008B
dw TextMacros_TM008C,TextMacros_TM008D,TextMacros_TM008E,TextMacros_TM008F
dw TextMacros_TM0090,TextMacros_TM0091,TextMacros_TM0092,TextMacros_TM0093
dw TextMacros_TM0094,TextMacros_TM0095,TextMacros_TM0096,TextMacros_TM0097
dw TextMacros_TM0098,TextMacros_TM0099,TextMacros_TM009A,TextMacros_TM009B
dw TextMacros_TM009C,TextMacros_TM009D,TextMacros_TM009E,TextMacros_TM009F
dw TextMacros_TM00A0,TextMacros_TM00A1,TextMacros_TM00A2,TextMacros_TM00A3
dw TextMacros_TM00A4,TextMacros_TM00A5,TextMacros_TM00A6,TextMacros_TM00A7
dw TextMacros_TM00A8,TextMacros_TM00A9,TextMacros_TM00AA,TextMacros_TM00AB
dw TextMacros_TM00AC,TextMacros_TM00AD,TextMacros_TM00AE,TextMacros_TM00AF
dw TextMacros_TM00B0,TextMacros_TM00B1,TextMacros_TM00B2,TextMacros_TM00B3
dw TextMacros_TM00B4,TextMacros_TM00B5,TextMacros_TM00B6,TextMacros_TM00B7
dw TextMacros_TM00B8,TextMacros_TM00B9,TextMacros_TM00BA,TextMacros_TM00BB
dw TextMacros_TM00BC,TextMacros_TM00BD,TextMacros_TM00BE,TextMacros_TM00BF
dw TextMacros_TM00C0,TextMacros_TM00C1,TextMacros_TM00C2,TextMacros_TM00C3
dw TextMacros_TM00C4,TextMacros_TM00C5,TextMacros_TM00C6,TextMacros_TM00C7
dw TextMacros_TM00C8,TextMacros_TM00C9,TextMacros_TM00CA,TextMacros_TM00CB
dw TextMacros_TM00CC,TextMacros_TM00CD,TextMacros_TM00CE,TextMacros_TM00CF
dw TextMacros_TM00D0,TextMacros_TM00D1,TextMacros_TM00D2,TextMacros_TM00D3
dw TextMacros_TM00D4,TextMacros_TM00D5,TextMacros_TM00D6,TextMacros_TM00D7
dw TextMacros_TM00D8,TextMacros_TM00D9,TextMacros_TM00DA,TextMacros_TM00DB
dw TextMacros_TM00DC,TextMacros_TM00DD,TextMacros_TM00DE,TextMacros_TM00DF
dw TextMacros_TM00E0,TextMacros_TM00E1,TextMacros_TM00E2,TextMacros_TM00E3
dw TextMacros_TM00E4,TextMacros_TM00E5,TextMacros_TM00E6,TextMacros_TM00E7
dw TextMacros_TM00E8,TextMacros_TM00E9,TextMacros_TM00EA,TextMacros_TM00EB
dw TextMacros_TM00EC,TextMacros_TM00ED,TextMacros_TM00EE,TextMacros_TM00EF
dw TextMacros_TM00F0,TextMacros_TM00F1,TextMacros_TM00F2,TextMacros_TM00F3
dw TextMacros_TM00F4,TextMacros_TM00F5,TextMacros_TM00F6,TextMacros_TM00F7
dw TextMacros_TM00F8,TextMacros_TM00F9,TextMacros_TM00FA,TextMacros_TM00FB
dw TextMacros_TM00FC,TextMacros_TM00FD,TextMacros_TM00FE,TextMacros_TM00FF
|
/**
* Copyright (C) 2016 MongoDB Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the copyright holders give permission to link the
* code of portions of this program with the OpenSSL library under certain
* conditions as described in each individual source file and distribute
* linked combinations including the program with the OpenSSL library. You
* must comply with the GNU Affero General Public License in all respects for
* all of the code used other than as permitted herein. If you modify file(s)
* with this exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do so,
* delete this exception statement from your version. If you delete this
* exception statement from all source files in the program, then also delete
* it in the license file.
*/
#include "mongo/platform/basic.h"
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/s/request_types/merge_chunk_request_type.h"
#include "mongo/unittest/unittest.h"
namespace mongo {
namespace {
using unittest::assertGet;
TEST(MergeChunkRequest, BasicValidConfigCommand) {
auto request = assertGet(MergeChunkRequest::parseFromConfigCommand(
BSON("_configsvrCommitChunkMerge"
<< "TestDB.TestColl"
<< "collEpoch"
<< OID("7fffffff0000000000000001")
<< "chunkBoundaries"
<< BSON_ARRAY(BSON("a" << 1) << BSON("a" << 5) << BSON("a" << 10))
<< "shard"
<< "shard0000")));
ASSERT_EQ(NamespaceString("TestDB", "TestColl"), request.getNamespace());
ASSERT_EQ(OID("7fffffff0000000000000001"), request.getEpoch());
ASSERT_BSONOBJ_EQ(BSON("a" << 1), request.getChunkBoundaries().at(0));
ASSERT_BSONOBJ_EQ(BSON("a" << 5), request.getChunkBoundaries().at(1));
ASSERT_BSONOBJ_EQ(BSON("a" << 10), request.getChunkBoundaries().at(2));
ASSERT_EQ("shard0000", request.getShardName());
}
TEST(MergeChunkRequest, ConfigCommandtoBSON) {
BSONObj serializedRequest =
BSON("_configsvrCommitChunkMerge"
<< "TestDB.TestColl"
<< "collEpoch"
<< OID("7fffffff0000000000000001")
<< "chunkBoundaries"
<< BSON_ARRAY(BSON("a" << 1) << BSON("a" << 5) << BSON("a" << 10))
<< "shard"
<< "shard0000");
BSONObj writeConcernObj = BSON("writeConcern" << BSON("w"
<< "majority"));
BSONObjBuilder cmdBuilder;
{
cmdBuilder.appendElements(serializedRequest);
cmdBuilder.appendElements(writeConcernObj);
}
auto request = assertGet(MergeChunkRequest::parseFromConfigCommand(serializedRequest));
auto requestToBSON = request.toConfigCommandBSON(writeConcernObj);
ASSERT_BSONOBJ_EQ(cmdBuilder.obj(), requestToBSON);
}
TEST(MergeChunkRequest, MissingNameSpaceErrors) {
auto request = MergeChunkRequest::parseFromConfigCommand(
BSON("collEpoch" << OID("7fffffff0000000000000001") << "chunkBoundaries"
<< BSON_ARRAY(BSON("a" << 1) << BSON("a" << 5) << BSON("a" << 10))
<< "shard"
<< "shard0000"));
ASSERT_EQ(ErrorCodes::NoSuchKey, request.getStatus());
}
TEST(MergeChunkRequest, MissingCollEpochErrors) {
auto request = MergeChunkRequest::parseFromConfigCommand(
BSON("_configsvrCommitChunkMerge"
<< "TestDB.TestColl"
<< "chunkBoundaries"
<< BSON_ARRAY(BSON("a" << 1) << BSON("a" << 5) << BSON("a" << 10))
<< "shard"
<< "shard0000"));
ASSERT_EQ(ErrorCodes::NoSuchKey, request.getStatus());
}
TEST(MergeChunkRequest, MissingChunkBoundariesErrors) {
auto request = MergeChunkRequest::parseFromConfigCommand(BSON("_configsvrCommitChunkMerge"
<< "TestDB.TestColl"
<< "collEpoch"
<< OID("7fffffff0000000000000001")
<< "shard"
<< "shard0000"));
ASSERT_EQ(ErrorCodes::NoSuchKey, request.getStatus());
}
TEST(MergeChunkRequest, MissingShardNameErrors) {
auto request = MergeChunkRequest::parseFromConfigCommand(
BSON("_configsvrCommitChunkMerge"
<< "TestDB.TestColl"
<< "collEpoch"
<< OID("7fffffff0000000000000001")
<< "chunkBoundaries"
<< BSON_ARRAY(BSON("a" << 1) << BSON("a" << 5) << BSON("a" << 10))));
ASSERT_EQ(ErrorCodes::NoSuchKey, request.getStatus());
}
TEST(MergeChunkRequest, WrongNamespaceTypeErrors) {
auto request = MergeChunkRequest::parseFromConfigCommand(
BSON("_configsvrCommitChunkMerge" << 1234 << "collEpoch" << OID("7fffffff0000000000000001")
<< "chunkBoundaries"
<< BSON_ARRAY(BSON("a" << 1) << BSON("a" << 5)
<< BSON("a" << 10))
<< "shard"
<< "shard0000"));
ASSERT_EQ(ErrorCodes::TypeMismatch, request.getStatus());
}
TEST(MergeChunkRequest, WrongCollEpochTypeErrors) {
auto request = MergeChunkRequest::parseFromConfigCommand(
BSON("_configsvrCommitChunkMerge"
<< "TestDB.TestColl"
<< "collEpoch"
<< 1234
<< "chunkBoundaries"
<< BSON_ARRAY(BSON("a" << 1) << BSON("a" << 5) << BSON("a" << 10))
<< "shard"
<< "shard0000"));
ASSERT_EQ(ErrorCodes::TypeMismatch, request.getStatus());
}
TEST(MergeChunkRequest, WrongChunkBoundariesTypeErrors) {
auto request = MergeChunkRequest::parseFromConfigCommand(BSON("_configsvrCommitChunkMerge"
<< "TestDB.TestColl"
<< "collEpoch"
<< OID("7fffffff0000000000000001")
<< "chunkBoundaries"
<< 1234
<< "shard"
<< "shard0000"));
ASSERT_EQ(ErrorCodes::TypeMismatch, request.getStatus());
}
TEST(MergeChunkRequest, WrongShardNameTypeErrors) {
auto request = MergeChunkRequest::parseFromConfigCommand(
BSON("_configsvrCommitChunkMerge"
<< "TestDB.TestColl"
<< "collEpoch"
<< OID("7fffffff0000000000000001")
<< "chunkBoundaries"
<< BSON_ARRAY(BSON("a" << 1) << BSON("a" << 5) << BSON("a" << 10))
<< "shard"
<< 1234));
ASSERT_EQ(ErrorCodes::TypeMismatch, request.getStatus());
}
TEST(MergeChunkRequest, InvalidNamespaceErrors) {
auto request = MergeChunkRequest::parseFromConfigCommand(
BSON("_configsvrCommitChunkMerge"
<< ""
<< "collEpoch"
<< OID("7fffffff0000000000000001")
<< "chunkBoundaries"
<< BSON_ARRAY(BSON("a" << 1) << BSON("a" << 5) << BSON("a" << 10))
<< "shard"
<< "shard0000"));
ASSERT_EQ(ErrorCodes::InvalidNamespace, request.getStatus());
}
TEST(MergeChunkRequest, EmptyChunkBoundariesErrors) {
auto request = MergeChunkRequest::parseFromConfigCommand(BSON("_configsvrCommitChunkMerge"
<< "TestDB.TestColl"
<< "collEpoch"
<< OID("7fffffff0000000000000001")
<< "chunkBoundaries"
<< BSONArray()
<< "shard"
<< "shard0000"));
ASSERT_EQ(ErrorCodes::InvalidOptions, request.getStatus());
}
TEST(MergeChunkRequest, TooFewChunkBoundariesErrors) {
auto request = MergeChunkRequest::parseFromConfigCommand(
BSON("_configsvrCommitChunkMerge"
<< "TestDB.TestColl"
<< "collEpoch"
<< OID("7fffffff0000000000000001")
<< "chunkBoundaries"
<< BSON_ARRAY(BSON("a" << 1) << BSON("a" << 10))
<< "shard"
<< "shard0000"));
ASSERT_EQ(ErrorCodes::InvalidOptions, request.getStatus());
}
}
} // namespace mongo
|
main:
PUSH %14
MOV %15,%14
SUBS %15,$1,%15
MOV $1,-1(%14)
SUBS %15,$1,%15
MOV $0,-2(%14)
AND -1(%14),-2(%14),%0
XOR %0,$1,%0
SUBS %15,$1,%15
MOV %0,-3(%14)
@main_body:
MOV -3(%14),%13
JMP @main_exit
@main_exit:
MOV %14,%15
POP %14
RET |
r1: db 0
r2: db 1
ld a , r1 / r2
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.