text stringlengths 1 1.05M |
|---|
;
; ANSI Video handling for the PC6001
;
; BEL - chr(7) Beep it out
;
;
; Stefano Bodrato - Jan 2013
;
;
; $Id: f_ansi_bel.asm,v 1.3 2016-06-12 16:06:43 dom Exp $
;
SECTION code_clib
PUBLIC ansi_BEL
.ansi_BEL
ld a,7
jp $26c7
|
SECTION code_fp_math32
PUBLIC _atanh
EXTERN cm32_sdcc_atanh
defc _atanh = cm32_sdcc_atanh
|
#This TM solution dedups consecutive strings of a's,b's and c's respectively.
#So, 'aabcccbbba' becomes 'abcba'
alpha "abc&-"
#Begin: If we read empty, halt. Otherwise, put an & just to the left of the
#string. We'll need that later.
!0
cmp ''
brae !0_e
cmp 'a'
brae !0_*
cmp 'b'
brae !0_*
cmp 'c'
brae !0_*
fail
!0_e
halt
!0_*
left 1
draw '&'
right 1
#Part 1: Traverse left to right deleting strings of consecutive chars.
#Leave the final char in the sequence alone.
!1
cmp ''
brae !1_e
cmp 'a'
brae !1_a
cmp 'b'
brae !1_b
cmp 'c'
brae !1_c
fail
!1_a
erase
right 1
cmp 'a'
brane !1_a_*
brae !1_a
!1_a_*
left 1
draw 'a'
right 1
bra !1
!1_b
erase
right 1
cmp 'b'
brane !1_b_*
brae !1_b
!1_b_*
left 1
draw 'b'
right 1
bra !1
!1_c
erase
right 1
cmp 'c'
brane !1_c_*
brae !1_c
!1_c_*
left 1
draw 'c'
right 1
bra !1
!1_e
left 1
#Part 2: traverse the string right, to left.
#Move each [abc] to the left of the '&'
!2
cmp ''
brae !2_e
cmp 'a'
brae !2_a
cmp 'b'
brae !2_b
cmp 'c'
brae !2_c
cmp '&'
brae !2_&
fail
!2_e
left 1
bra !2
!2_a
draw '-'
left 1
!2_a_1
cmp '&'
brae !2_a_1_&
left 1
brane !2_a_1
!2_a_1_&
left 1
!2_a_2
cmp ''
brae !2_a_2_e
left 1
brane !2_a_2
!2_a_2_e
draw 'a'
right 1
!2_a_3
cmp '-'
brae !2_a_3_-
right 1
brane !2_a_3
!2_a_3_-
erase
left 1
bra !2
!2_b
draw '-'
left 1
!2_b_1
cmp '&'
brae !2_b_1_&
left 1
brane !2_b_1
!2_b_1_&
left 1
!2_b_2
cmp ''
brae !2_b_2_e
left 1
brane !2_b_2
!2_b_2_e
draw 'b'
right 1
!2_b_3
cmp '-'
brae !2_b_3_-
right 1
brane !2_b_3
!2_b_3_-
erase
left 1
bra !2
!2_c
draw '-'
left 1
!2_c_1
cmp '&'
brae !2_c_1_&
left 1
brane !2_c_1
!2_c_1_&
left 1
!2_c_2
cmp ''
brae !2_c_2_e
left 1
brane !2_c_2
!2_c_2_e
draw 'c'
right 1
!2_c_3
cmp '-'
brae !2_c_3_-
right 1
brane !2_c_3
!2_c_3_-
erase
left 1
bra !2
!2_&
erase
left 1
#Part 3: Reset the head
!3
cmp ''
brae !3_e
left 1
brane !3
!3_e
right 1
HALT
|
/*
** EPITECH PROJECT, 2018
** Project description
** File description:
** Description here
*/
#include "AI.hpp"
bool zappy::AI::startIncantation()
{
look();
std::cout << "Starting elevation incantation\n";
_cli.sendRequest("Incantation\n");
if (_cli.getAnswer() != "ko\n") {
levelUp();
look();
_mode = zappy::GATHERING;
return (true);
} else
return (false);
}
bool zappy::AI::readyToCall(zappy::Inventory &inv)
{
auto lvl = _reqRef.find(_lvl + 1);
if (lvl != _reqRef.end()) {
if (inv.enoughMats(lvl->second) == true)
return (true);
}
return (false);
}
bool zappy::AI::lvlRequirementsMet(zappy::Inventory &inv)
{
auto lvl = _reqRef.find(_lvl + 1);
if (lvl != _reqRef.end()) {
if (inv >= lvl->second)
return (true);
}
return (false);
}
bool zappy::AI::prepareTileForRitual()
{
zappy::Inventory tile = _vision.getHere();
PickupAllOf("linemate", tile);
PickupAllOf("deraumere", tile);
PickupAllOf("sibur", tile);
PickupAllOf("mendiane", tile);
PickupAllOf("phiras", tile);
PickupAllOf("thystame", tile);
PickupAllFood();
look();
if (_vision.getHere().isEmpty() == true)
std::cout << "Current tile emptied for ritual !" << std::endl;
else {
std::cout << "Current tile emptied for ritual !" << std::endl;
return (false);
}
return (setRequirementsDown());
}
bool zappy::AI::setRequirementsDown()
{
setDownAllOf("linemate");
setDownAllOf("deraumere");
setDownAllOf("sibur");
setDownAllOf("mendiane");
setDownAllOf("phiras");
setDownAllOf("thystame");
look();
if (_vision.getHere() == _reqRef[_lvl + 1])
return (true);
else
return (false);
}
void zappy::AI::levelUp()
{
this->_lvl += 1;
std::cout << "Leveled up! New level: " << std::to_string(_lvl) << std::endl;
}
|
; Copyright © 2021, VideoLAN and dav1d authors
; Copyright © 2021, 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
sgr_lshuf3: db 0, 1, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
sgr_lshuf5: db 0, 1, 0, 1, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
wiener_shufA: db 2, 3, 4, 5, 4, 5, 6, 7, 6, 7, 8, 9, 8, 9, 10, 11
wiener_shufB: db 6, 7, 4, 5, 8, 9, 6, 7, 10, 11, 8, 9, 12, 13, 10, 11
wiener_shufC: db 6, 7, 8, 9, 8, 9, 10, 11, 10, 11, 12, 13, 12, 13, 14, 15
wiener_shufD: db 2, 3, -1, -1, 4, 5, -1, -1, 6, 7, -1, -1, 8, 9, -1, -1
wiener_shufE: db 0, 1, 8, 9, 2, 3, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15
wiener_lshuf5: db 4, 5, 4, 5, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
wiener_lshuf7: db 8, 9, 8, 9, 8, 9, 8, 9, 8, 9, 10, 11, 12, 13, 14, 15
pb_0to31: db 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
db 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
wiener_hshift: dw 4, 4, 1, 1
wiener_vshift: dw 1024, 1024, 4096, 4096
wiener_round: dd 1049600, 1048832
pb_m10_m9: times 2 db -10, -9
pb_m6_m5: times 2 db -6, -5
pb_m2_m1: times 2 db -2, -1
pb_2_3: times 2 db 2, 3
pb_6_7: times 2 db 6, 7
pw_1023: times 2 dw 1023
pd_8: dd 8
pd_25: dd 25
pd_4096: dd 4096
pd_34816: dd 34816
pd_m262128: dd -262128
pd_0xf00800a4: dd 0xf00800a4
pd_0xf00801c7: dd 0xf00801c7
%define pw_256 sgr_lshuf5
cextern sgr_x_by_x_avx2
SECTION .text
%macro REPX 2-*
%xdefine %%f(x) %1
%rep %0 - 1
%rotate 1
%%f(%1)
%endrep
%endmacro
DECLARE_REG_TMP 4, 9, 7, 11, 12, 13, 14 ; wiener ring buffer pointers
INIT_YMM avx2
cglobal wiener_filter7_16bpc, 5, 15, 16, -384*12-16, dst, dst_stride, left, lpf, \
lpf_stride, w, edge, flt, h
%define base t4-wiener_hshift
mov fltq, fltmp
mov edged, r8m
movifnidn wd, wm
mov hd, r6m
mov t3d, r9m ; pixel_max
vbroadcasti128 m6, [wiener_shufA]
vpbroadcastd m12, [fltq+ 0] ; x0 x1
lea t4, [wiener_hshift]
vbroadcasti128 m7, [wiener_shufB]
add wd, wd
vpbroadcastd m13, [fltq+ 4] ; x2 x3
shr t3d, 11
vbroadcasti128 m8, [wiener_shufC]
add lpfq, wq
vbroadcasti128 m9, [wiener_shufD]
lea t1, [rsp+wq+16]
vpbroadcastd m14, [fltq+16] ; y0 y1
add dstq, wq
vpbroadcastd m15, [fltq+20] ; y2 y3
neg wq
vpbroadcastd m0, [base+wiener_hshift+t3*4]
vpbroadcastd m10, [base+wiener_round+t3*4]
vpbroadcastd m11, [base+wiener_vshift+t3*4]
pmullw m12, m0 ; upshift filter coefs to make the
pmullw m13, m0 ; horizontal downshift constant
test edgeb, 4 ; LR_HAVE_TOP
jz .no_top
call .h_top
add lpfq, lpf_strideq
mov t6, t1
mov t5, t1
add t1, 384*2
call .h_top
lea r7, [lpfq+lpf_strideq*4]
mov lpfq, dstq
mov t4, t1
add t1, 384*2
mov [rsp+8*1], lpf_strideq
add r7, lpf_strideq
mov [rsp+8*0], r7 ; below
call .h
mov t3, t1
mov t2, t1
dec hd
jz .v1
add lpfq, dst_strideq
add t1, 384*2
call .h
mov t2, t1
dec hd
jz .v2
add lpfq, dst_strideq
add t1, 384*2
call .h
dec hd
jz .v3
.main:
lea t0, [t1+384*2]
.main_loop:
call .hv
dec hd
jnz .main_loop
test edgeb, 8 ; LR_HAVE_BOTTOM
jz .v3
mov lpfq, [rsp+8*0]
call .hv_bottom
add lpfq, [rsp+8*1]
call .hv_bottom
.v1:
call .v
RET
.no_top:
lea r7, [lpfq+lpf_strideq*4]
mov lpfq, dstq
mov [rsp+8*1], lpf_strideq
lea r7, [r7+lpf_strideq*2]
mov [rsp+8*0], r7
call .h
mov t6, t1
mov t5, t1
mov t4, t1
mov t3, t1
mov t2, t1
dec hd
jz .v1
add lpfq, dst_strideq
add t1, 384*2
call .h
mov t2, t1
dec hd
jz .v2
add lpfq, dst_strideq
add t1, 384*2
call .h
dec hd
jz .v3
lea t0, [t1+384*2]
call .hv
dec hd
jz .v3
add t0, 384*8
call .hv
dec hd
jnz .main
.v3:
call .v
.v2:
call .v
jmp .v1
.extend_right:
movd xm1, r10d
vpbroadcastd m0, [pb_6_7]
movu m2, [pb_0to31]
vpbroadcastb m1, xm1
psubb m0, m1
pminub m0, m2
pshufb m3, m0
vpbroadcastd m0, [pb_m2_m1]
psubb m0, m1
pminub m0, m2
pshufb m4, m0
vpbroadcastd m0, [pb_m10_m9]
psubb m0, m1
pminub m0, m2
pshufb m5, m0
ret
.h:
mov r10, wq
test edgeb, 1 ; LR_HAVE_LEFT
jz .h_extend_left
movq xm3, [leftq]
vpblendd m3, [lpfq+r10-8], 0xfc
add leftq, 8
jmp .h_main
.h_extend_left:
vbroadcasti128 m3, [lpfq+r10] ; avoid accessing memory located
mova m4, [lpfq+r10] ; before the start of the buffer
shufpd m3, m4, 0x05
pshufb m3, [wiener_lshuf7]
jmp .h_main2
.h_top:
mov r10, wq
test edgeb, 1 ; LR_HAVE_LEFT
jz .h_extend_left
.h_loop:
movu m3, [lpfq+r10-8]
.h_main:
mova m4, [lpfq+r10+0]
.h_main2:
movu m5, [lpfq+r10+8]
test edgeb, 2 ; LR_HAVE_RIGHT
jnz .h_have_right
cmp r10d, -36
jl .h_have_right
call .extend_right
.h_have_right:
pshufb m0, m3, m6
pshufb m1, m4, m7
paddw m0, m1
pshufb m3, m8
pmaddwd m0, m12
pshufb m1, m4, m9
paddw m3, m1
pshufb m1, m4, m6
pmaddwd m3, m13
pshufb m2, m5, m7
paddw m1, m2
vpbroadcastd m2, [pd_m262128] ; (1 << 4) - (1 << 18)
pshufb m4, m8
pmaddwd m1, m12
pshufb m5, m9
paddw m4, m5
pmaddwd m4, m13
paddd m0, m2
paddd m1, m2
paddd m0, m3
paddd m1, m4
psrad m0, 4
psrad m1, 4
packssdw m0, m1
psraw m0, 1
mova [t1+r10], m0
add r10, 32
jl .h_loop
ret
ALIGN function_align
.hv:
add lpfq, dst_strideq
mov r10, wq
test edgeb, 1 ; LR_HAVE_LEFT
jz .hv_extend_left
movq xm3, [leftq]
vpblendd m3, [lpfq+r10-8], 0xfc
add leftq, 8
jmp .hv_main
.hv_extend_left:
movu m3, [lpfq+r10-8]
pshufb m3, [wiener_lshuf7]
jmp .hv_main
.hv_bottom:
mov r10, wq
test edgeb, 1 ; LR_HAVE_LEFT
jz .hv_extend_left
.hv_loop:
movu m3, [lpfq+r10-8]
.hv_main:
mova m4, [lpfq+r10+0]
movu m5, [lpfq+r10+8]
test edgeb, 2 ; LR_HAVE_RIGHT
jnz .hv_have_right
cmp r10d, -36
jl .hv_have_right
call .extend_right
.hv_have_right:
pshufb m0, m3, m6
pshufb m1, m4, m7
paddw m0, m1
pshufb m3, m8
pmaddwd m0, m12
pshufb m1, m4, m9
paddw m3, m1
pshufb m1, m4, m6
pmaddwd m3, m13
pshufb m2, m5, m7
paddw m1, m2
vpbroadcastd m2, [pd_m262128]
pshufb m4, m8
pmaddwd m1, m12
pshufb m5, m9
paddw m4, m5
pmaddwd m4, m13
paddd m0, m2
paddd m1, m2
mova m2, [t4+r10]
paddw m2, [t2+r10]
mova m5, [t3+r10]
paddd m0, m3
paddd m1, m4
psrad m0, 4
psrad m1, 4
packssdw m0, m1
mova m4, [t5+r10]
paddw m4, [t1+r10]
psraw m0, 1
paddw m3, m0, [t6+r10]
mova [t0+r10], m0
punpcklwd m0, m2, m5
pmaddwd m0, m15
punpckhwd m2, m5
pmaddwd m2, m15
punpcklwd m1, m3, m4
pmaddwd m1, m14
punpckhwd m3, m4
pmaddwd m3, m14
paddd m0, m10
paddd m2, m10
paddd m0, m1
paddd m2, m3
psrad m0, 5
psrad m2, 5
packusdw m0, m2
pmulhuw m0, m11
mova [dstq+r10], m0
add r10, 32
jl .hv_loop
mov t6, t5
mov t5, t4
mov t4, t3
mov t3, t2
mov t2, t1
mov t1, t0
mov t0, t6
add dstq, dst_strideq
ret
.v:
mov r10, wq
.v_loop:
mova m1, [t4+r10]
paddw m1, [t2+r10]
mova m2, [t3+r10]
mova m4, [t1+r10]
paddw m3, m4, [t6+r10]
paddw m4, [t5+r10]
punpcklwd m0, m1, m2
pmaddwd m0, m15
punpckhwd m1, m2
pmaddwd m1, m15
punpcklwd m2, m3, m4
pmaddwd m2, m14
punpckhwd m3, m4
pmaddwd m3, m14
paddd m0, m10
paddd m1, m10
paddd m0, m2
paddd m1, m3
psrad m0, 5
psrad m1, 5
packusdw m0, m1
pmulhuw m0, m11
mova [dstq+r10], m0
add r10, 32
jl .v_loop
mov t6, t5
mov t5, t4
mov t4, t3
mov t3, t2
mov t2, t1
add dstq, dst_strideq
ret
cglobal wiener_filter5_16bpc, 5, 13, 16, 384*8+16, dst, dst_stride, left, lpf, \
lpf_stride, w, edge, flt, h
%define base t4-wiener_hshift
mov fltq, fltmp
mov edged, r8m
movifnidn wd, wm
mov hd, r6m
mov t3d, r9m ; pixel_max
vbroadcasti128 m5, [wiener_shufE]
vpbroadcastw m11, [fltq+ 2] ; x1
vbroadcasti128 m6, [wiener_shufB]
lea t4, [wiener_hshift]
vbroadcasti128 m7, [wiener_shufD]
add wd, wd
vpbroadcastd m12, [fltq+ 4] ; x2 x3
shr t3d, 11
vpbroadcastd m8, [pd_m262128] ; (1 << 4) - (1 << 18)
add lpfq, wq
lea t1, [rsp+wq+16]
vpbroadcastw m13, [fltq+18] ; y1
add dstq, wq
vpbroadcastd m14, [fltq+20] ; y2 y3
neg wq
vpbroadcastd m0, [base+wiener_hshift+t3*4]
vpbroadcastd m9, [base+wiener_round+t3*4]
vpbroadcastd m10, [base+wiener_vshift+t3*4]
movu xm15, [wiener_lshuf5]
pmullw m11, m0
vinserti128 m15, [pb_0to31], 1
pmullw m12, m0
test edgeb, 4 ; LR_HAVE_TOP
jz .no_top
call .h_top
add lpfq, lpf_strideq
mov t4, t1
add t1, 384*2
call .h_top
lea r7, [lpfq+lpf_strideq*4]
mov lpfq, dstq
mov t3, t1
add t1, 384*2
mov [rsp+8*1], lpf_strideq
add r7, lpf_strideq
mov [rsp+8*0], r7 ; below
call .h
mov t2, t1
dec hd
jz .v1
add lpfq, dst_strideq
add t1, 384*2
call .h
dec hd
jz .v2
.main:
mov t0, t4
.main_loop:
call .hv
dec hd
jnz .main_loop
test edgeb, 8 ; LR_HAVE_BOTTOM
jz .v2
mov lpfq, [rsp+8*0]
call .hv_bottom
add lpfq, [rsp+8*1]
call .hv_bottom
.end:
RET
.no_top:
lea r7, [lpfq+lpf_strideq*4]
mov lpfq, dstq
mov [rsp+8*1], lpf_strideq
lea r7, [r7+lpf_strideq*2]
mov [rsp+8*0], r7
call .h
mov t4, t1
mov t3, t1
mov t2, t1
dec hd
jz .v1
add lpfq, dst_strideq
add t1, 384*2
call .h
dec hd
jz .v2
lea t0, [t1+384*2]
call .hv
dec hd
jz .v2
add t0, 384*6
call .hv
dec hd
jnz .main
.v2:
call .v
mov t4, t3
mov t3, t2
mov t2, t1
add dstq, dst_strideq
.v1:
call .v
jmp .end
.extend_right:
movd xm2, r10d
vpbroadcastd m0, [pb_2_3]
vpbroadcastd m1, [pb_m6_m5]
vpbroadcastb m2, xm2
psubb m0, m2
psubb m1, m2
movu m2, [pb_0to31]
pminub m0, m2
pminub m1, m2
pshufb m3, m0
pshufb m4, m1
ret
.h:
mov r10, wq
test edgeb, 1 ; LR_HAVE_LEFT
jz .h_extend_left
movd xm3, [leftq+4]
vpblendd m3, [lpfq+r10-4], 0xfe
add leftq, 8
jmp .h_main
.h_extend_left:
vbroadcasti128 m4, [lpfq+r10] ; avoid accessing memory located
mova m3, [lpfq+r10] ; before the start of the buffer
palignr m3, m4, 12
pshufb m3, m15
jmp .h_main
.h_top:
mov r10, wq
test edgeb, 1 ; LR_HAVE_LEFT
jz .h_extend_left
.h_loop:
movu m3, [lpfq+r10-4]
.h_main:
movu m4, [lpfq+r10+4]
test edgeb, 2 ; LR_HAVE_RIGHT
jnz .h_have_right
cmp r10d, -34
jl .h_have_right
call .extend_right
.h_have_right:
pshufb m0, m3, m5
pmaddwd m0, m11
pshufb m1, m4, m5
pmaddwd m1, m11
pshufb m2, m3, m6
pshufb m3, m7
paddw m2, m3
pshufb m3, m4, m6
pmaddwd m2, m12
pshufb m4, m7
paddw m3, m4
pmaddwd m3, m12
paddd m0, m8
paddd m1, m8
paddd m0, m2
paddd m1, m3
psrad m0, 4
psrad m1, 4
packssdw m0, m1
psraw m0, 1
mova [t1+r10], m0
add r10, 32
jl .h_loop
ret
ALIGN function_align
.hv:
add lpfq, dst_strideq
mov r10, wq
test edgeb, 1 ; LR_HAVE_LEFT
jz .hv_extend_left
movd xm3, [leftq+4]
vpblendd m3, [lpfq+r10-4], 0xfe
add leftq, 8
jmp .hv_main
.hv_extend_left:
movu m3, [lpfq+r10-4]
pshufb m3, m15
jmp .hv_main
.hv_bottom:
mov r10, wq
test edgeb, 1 ; LR_HAVE_LEFT
jz .hv_extend_left
.hv_loop:
movu m3, [lpfq+r10-4]
.hv_main:
movu m4, [lpfq+r10+4]
test edgeb, 2 ; LR_HAVE_RIGHT
jnz .hv_have_right
cmp r10d, -34
jl .hv_have_right
call .extend_right
.hv_have_right:
pshufb m0, m3, m5
pmaddwd m0, m11
pshufb m1, m4, m5
pmaddwd m1, m11
pshufb m2, m3, m6
pshufb m3, m7
paddw m2, m3
pshufb m3, m4, m6
pmaddwd m2, m12
pshufb m4, m7
paddw m3, m4
pmaddwd m3, m12
paddd m0, m8
paddd m1, m8
paddd m0, m2
mova m2, [t3+r10]
paddw m2, [t1+r10]
paddd m1, m3
mova m4, [t2+r10]
punpckhwd m3, m2, m4
pmaddwd m3, m14
punpcklwd m2, m4
mova m4, [t4+r10]
psrad m0, 4
psrad m1, 4
packssdw m0, m1
pmaddwd m2, m14
psraw m0, 1
mova [t0+r10], m0
punpckhwd m1, m0, m4
pmaddwd m1, m13
punpcklwd m0, m4
pmaddwd m0, m13
paddd m3, m9
paddd m2, m9
paddd m1, m3
paddd m0, m2
psrad m1, 5
psrad m0, 5
packusdw m0, m1
pmulhuw m0, m10
mova [dstq+r10], m0
add r10, 32
jl .hv_loop
mov t4, t3
mov t3, t2
mov t2, t1
mov t1, t0
mov t0, t4
add dstq, dst_strideq
ret
.v:
mov r10, wq
.v_loop:
mova m0, [t1+r10]
paddw m2, m0, [t3+r10]
mova m1, [t2+r10]
mova m4, [t4+r10]
punpckhwd m3, m2, m1
pmaddwd m3, m14
punpcklwd m2, m1
pmaddwd m2, m14
punpckhwd m1, m0, m4
pmaddwd m1, m13
punpcklwd m0, m4
pmaddwd m0, m13
paddd m3, m9
paddd m2, m9
paddd m1, m3
paddd m0, m2
psrad m1, 5
psrad m0, 5
packusdw m0, m1
pmulhuw m0, m10
mova [dstq+r10], m0
add r10, 32
jl .v_loop
ret
cglobal sgr_filter_5x5_16bpc, 5, 14, 16, 400*24+16, dst, dst_stride, left, lpf, \
lpf_stride, w, edge, params, h
movifnidn wd, wm
mov paramsq, paramsmp
lea r13, [sgr_x_by_x_avx2+256*4]
mov edged, r8m
mov hd, r6m
add wd, wd
vpbroadcastw m7, [paramsq+8] ; w0
add lpfq, wq
vpbroadcastd m8, [pd_8]
lea t1, [rsp+wq+20]
vpbroadcastd m9, [pd_25]
add dstq, wq
vpbroadcastd m10, [paramsq+0] ; s0
lea t3, [rsp+wq*2+400*12+16]
vpbroadcastd m11, [pd_0xf00800a4]
lea t4, [rsp+wq+400*20+16]
vpbroadcastd m12, [pw_256]
neg wq
vpbroadcastd m13, [pd_34816] ; (1 << 11) + (1 << 15)
pxor m6, m6
vpbroadcastd m14, [pw_1023]
psllw m7, 4
mova xm15, [sgr_lshuf5]
test edgeb, 4 ; LR_HAVE_TOP
jz .no_top
call .h_top
add lpfq, lpf_strideq
mov t2, t1
call .top_fixup
add t1, 400*6
call .h_top
lea r10, [lpfq+lpf_strideq*4]
mov lpfq, dstq
mov [rsp+8*1], lpf_strideq
add r10, lpf_strideq
mov [rsp+8*0], r10 ; below
mov t0, t2
dec hd
jz .height1
or edged, 16
call .h
.main:
add lpfq, dst_strideq
call .hv
call .prep_n
sub hd, 2
jl .extend_bottom
.main_loop:
add lpfq, dst_strideq
test hd, hd
jz .odd_height
call .h
add lpfq, dst_strideq
call .hv
call .n0
call .n1
sub hd, 2
jge .main_loop
test edgeb, 8 ; LR_HAVE_BOTTOM
jz .extend_bottom
mov lpfq, [rsp+8*0]
call .h_top
add lpfq, [rsp+8*1]
call .hv_bottom
.end:
call .n0
call .n1
.end2:
RET
.height1:
call .hv
call .prep_n
jmp .odd_height_end
.odd_height:
call .hv
call .n0
call .n1
.odd_height_end:
call .v
call .n0
jmp .end2
.extend_bottom:
call .v
jmp .end
.no_top:
lea r10, [lpfq+lpf_strideq*4]
mov lpfq, dstq
mov [rsp+8*1], lpf_strideq
lea r10, [r10+lpf_strideq*2]
mov [rsp+8*0], r10
call .h
lea t2, [t1+400*6]
call .top_fixup
dec hd
jz .no_top_height1
or edged, 16
mov t0, t1
mov t1, t2
jmp .main
.no_top_height1:
call .v
call .prep_n
jmp .odd_height_end
.extend_right:
vpbroadcastw m0, [lpfq-2]
movu m1, [r13+r10+ 0]
movu m2, [r13+r10+16]
vpblendvb m4, m0, m1
vpblendvb m5, m0, m2
ret
.h: ; horizontal boxsum
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .h_extend_left
vpbroadcastq xm5, [leftq]
vinserti128 m5, [lpfq+wq], 1
mova m4, [lpfq+wq]
add leftq, 8
palignr m4, m5, 10
jmp .h_main
.h_extend_left:
mova xm4, [lpfq+wq]
pshufb xm4, xm15
vinserti128 m4, [lpfq+wq+10], 1
jmp .h_main
.h_top:
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .h_extend_left
.h_loop:
movu m4, [lpfq+r10- 2]
.h_main:
movu m5, [lpfq+r10+14]
test edgeb, 2 ; LR_HAVE_RIGHT
jnz .h_have_right
cmp r10d, -36
jl .h_have_right
call .extend_right
.h_have_right:
palignr m2, m5, m4, 2
paddw m0, m4, m2
palignr m3, m5, m4, 6
paddw m0, m3
punpcklwd m1, m2, m3
pmaddwd m1, m1
punpckhwd m2, m3
pmaddwd m2, m2
shufpd m5, m4, m5, 0x05
paddw m0, m5
punpcklwd m3, m4, m5
pmaddwd m3, m3
paddd m1, m3
punpckhwd m3, m4, m5
pmaddwd m3, m3
shufps m4, m5, q2121
paddw m0, m4 ; sum
punpcklwd m5, m4, m6
pmaddwd m5, m5
punpckhwd m4, m6
pmaddwd m4, m4
paddd m2, m3
test edgeb, 16 ; y > 0
jz .h_loop_end
paddw m0, [t1+r10+400*0]
paddd m1, [t1+r10+400*2]
paddd m2, [t1+r10+400*4]
.h_loop_end:
paddd m1, m5 ; sumsq
paddd m2, m4
mova [t1+r10+400*0], m0
mova [t1+r10+400*2], m1
mova [t1+r10+400*4], m2
add r10, 32
jl .h_loop
ret
.top_fixup:
lea r10, [wq-4]
.top_fixup_loop: ; the sums of the first row needs to be doubled
mova m0, [t1+r10+400*0]
mova m1, [t1+r10+400*2]
mova m2, [t1+r10+400*4]
paddw m0, m0
paddd m1, m1
paddd m2, m2
mova [t2+r10+400*0], m0
mova [t2+r10+400*2], m1
mova [t2+r10+400*4], m2
add r10, 32
jl .top_fixup_loop
ret
ALIGN function_align
.hv: ; horizontal boxsum + vertical boxsum + ab
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .hv_extend_left
vpbroadcastq xm5, [leftq]
vinserti128 m5, [lpfq+wq], 1
mova m4, [lpfq+wq]
add leftq, 8
palignr m4, m5, 10
jmp .hv_main
.hv_extend_left:
mova xm4, [lpfq+wq]
pshufb xm4, xm15
vinserti128 m4, [lpfq+wq+10], 1
jmp .hv_main
.hv_bottom:
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .hv_extend_left
.hv_loop:
movu m4, [lpfq+r10- 2]
.hv_main:
movu m5, [lpfq+r10+14]
test edgeb, 2 ; LR_HAVE_RIGHT
jnz .hv_have_right
cmp r10d, -36
jl .hv_have_right
call .extend_right
.hv_have_right:
palignr m3, m5, m4, 2
paddw m0, m4, m3
palignr m1, m5, m4, 6
paddw m0, m1
punpcklwd m2, m3, m1
pmaddwd m2, m2
punpckhwd m3, m1
pmaddwd m3, m3
shufpd m5, m4, m5, 0x05
paddw m0, m5
punpcklwd m1, m4, m5
pmaddwd m1, m1
paddd m2, m1
punpckhwd m1, m4, m5
pmaddwd m1, m1
shufps m4, m5, q2121
paddw m0, m4 ; h sum
punpcklwd m5, m4, m6
pmaddwd m5, m5
punpckhwd m4, m6
pmaddwd m4, m4
paddd m3, m1
paddd m2, m5 ; h sumsq
paddd m3, m4
paddw m1, m0, [t1+r10+400*0]
paddd m4, m2, [t1+r10+400*2]
paddd m5, m3, [t1+r10+400*4]
test hd, hd
jz .hv_last_row
.hv_main2:
paddw m1, [t2+r10+400*0] ; hv sum
paddd m4, [t2+r10+400*2] ; hv sumsq
paddd m5, [t2+r10+400*4]
mova [t0+r10+400*0], m0
mova [t0+r10+400*2], m2
mova [t0+r10+400*4], m3
psrlw m3, m1, 1
paddd m4, m8
pavgw m3, m6 ; (b + 2) >> 2
paddd m5, m8
psrld m4, 4 ; (a + 8) >> 4
punpcklwd m2, m3, m6
psrld m5, 4
punpckhwd m3, m6
pmulld m4, m9 ; a * 25
pmulld m5, m9
pmaddwd m2, m2 ; b * b
pmaddwd m3, m3
punpcklwd m0, m1, m6 ; b
punpckhwd m1, m6
pmaxud m4, m2
pmaxud m5, m3
psubd m4, m2 ; p
psubd m5, m3
pmulld m4, m10 ; p * s
pmulld m5, m10
pmaddwd m0, m11 ; b * 164
pmaddwd m1, m11
paddusw m4, m11
paddusw m5, m11
psrad m3, m4, 20 ; min(z, 255) - 256
vpgatherdd m2, [r13+m3*4], m4
psrad m4, m5, 20
vpgatherdd m3, [r13+m4*4], m5
pmulld m0, m2
pmulld m1, m3
packssdw m2, m3
psubw m2, m12, m2 ; a
paddd m0, m13 ; x * b * 164 + (1 << 11) + (1 << 15)
paddd m1, m13
mova [t4+r10+4], m2
psrld m0, 12 ; b
psrld m1, 12
mova [t3+r10*2+ 8], xm0
vextracti128 [t3+r10*2+40], m0, 1
mova [t3+r10*2+24], xm1
vextracti128 [t3+r10*2+56], m1, 1
add r10, 32
jl .hv_loop
mov t2, t1
mov t1, t0
mov t0, t2
ret
.hv_last_row: ; esoteric edge case for odd heights
mova [t1+r10+400*0], m1
paddw m1, m0
mova [t1+r10+400*2], m4
paddd m4, m2
mova [t1+r10+400*4], m5
paddd m5, m3
jmp .hv_main2
.v: ; vertical boxsum + ab
lea r10, [wq-4]
.v_loop:
mova m0, [t1+r10+400*0]
mova m2, [t1+r10+400*2]
mova m3, [t1+r10+400*4]
paddw m1, m0, [t2+r10+400*0]
paddd m4, m2, [t2+r10+400*2]
paddd m5, m3, [t2+r10+400*4]
paddw m0, m0
paddd m2, m2
paddd m3, m3
paddw m1, m0 ; hv sum
paddd m4, m2 ; hv sumsq
paddd m5, m3
psrlw m3, m1, 1
paddd m4, m8
pavgw m3, m6 ; (b + 2) >> 2
paddd m5, m8
psrld m4, 4 ; (a + 8) >> 4
punpcklwd m2, m3, m6
psrld m5, 4
punpckhwd m3, m6
pmulld m4, m9 ; a * 25
pmulld m5, m9
pmaddwd m2, m2 ; b * b
pmaddwd m3, m3
punpcklwd m0, m1, m6 ; b
punpckhwd m1, m6
pmaxud m4, m2
pmaxud m5, m3
psubd m4, m2 ; p
psubd m5, m3
pmulld m4, m10 ; p * s
pmulld m5, m10
pmaddwd m0, m11 ; b * 164
pmaddwd m1, m11
paddusw m4, m11
paddusw m5, m11
psrad m3, m4, 20 ; min(z, 255) - 256
vpgatherdd m2, [r13+m3*4], m4
psrad m4, m5, 20
vpgatherdd m3, [r13+m4*4], m5
pmulld m0, m2
pmulld m1, m3
packssdw m2, m3
psubw m2, m12, m2 ; a
paddd m0, m13 ; x * b * 164 + (1 << 11) + (1 << 15)
paddd m1, m13
mova [t4+r10+4], m2
psrld m0, 12 ; b
psrld m1, 12
mova [t3+r10*2+ 8], xm0
vextracti128 [t3+r10*2+40], m0, 1
mova [t3+r10*2+24], xm1
vextracti128 [t3+r10*2+56], m1, 1
add r10, 32
jl .v_loop
ret
.prep_n: ; initial neighbor setup
mov r10, wq
.prep_n_loop:
movu m0, [t4+r10*1+ 2]
movu m1, [t3+r10*2+ 4]
movu m2, [t3+r10*2+36]
paddw m3, m0, [t4+r10*1+ 0]
paddd m4, m1, [t3+r10*2+ 0]
paddd m5, m2, [t3+r10*2+32]
paddw m3, [t4+r10*1+ 4]
paddd m4, [t3+r10*2+ 8]
paddd m5, [t3+r10*2+40]
paddw m0, m3
psllw m3, 2
paddd m1, m4
pslld m4, 2
paddd m2, m5
pslld m5, 2
paddw m0, m3 ; a 565
paddd m1, m4 ; b 565
paddd m2, m5
mova [t4+r10*1+400*2+ 0], m0
mova [t3+r10*2+400*4+ 0], m1
mova [t3+r10*2+400*4+32], m2
add r10, 32
jl .prep_n_loop
ret
ALIGN function_align
.n0: ; neighbor + output (even rows)
mov r10, wq
.n0_loop:
movu m0, [t4+r10*1+ 2]
movu m1, [t3+r10*2+ 4]
movu m2, [t3+r10*2+36]
paddw m3, m0, [t4+r10*1+ 0]
paddd m4, m1, [t3+r10*2+ 0]
paddd m5, m2, [t3+r10*2+32]
paddw m3, [t4+r10*1+ 4]
paddd m4, [t3+r10*2+ 8]
paddd m5, [t3+r10*2+40]
paddw m0, m3
psllw m3, 2
paddd m1, m4
pslld m4, 2
paddd m2, m5
pslld m5, 2
paddw m0, m3 ; a 565
paddd m1, m4 ; b 565
paddd m2, m5
paddw m3, m0, [t4+r10*1+400*2+ 0]
paddd m4, m1, [t3+r10*2+400*4+ 0]
paddd m5, m2, [t3+r10*2+400*4+32]
mova [t4+r10*1+400*2+ 0], m0
mova [t3+r10*2+400*4+ 0], m1
mova [t3+r10*2+400*4+32], m2
mova m0, [dstq+r10]
punpcklwd m1, m0, m6 ; src
punpcklwd m2, m3, m6 ; a
pmaddwd m2, m1 ; a * src
punpckhwd m1, m0, m6
punpckhwd m3, m6
pmaddwd m3, m1
vinserti128 m1, m4, xm5, 1
vperm2i128 m4, m5, 0x31
paddd m2, m1 ; a * src + b + (1 << 8)
paddd m3, m4
psrld m2, 9
psrld m3, 9
packssdw m2, m3
psllw m1, m0, 4
psubw m2, m1
pmulhrsw m2, m7
paddw m0, m2
pmaxsw m0, m6
pminsw m0, m14
mova [dstq+r10], m0
add r10, 32
jl .n0_loop
add dstq, dst_strideq
ret
ALIGN function_align
.n1: ; neighbor + output (odd rows)
mov r10, wq
.n1_loop:
mova m0, [dstq+r10]
mova m3, [t4+r10*1+400*2+ 0]
mova m4, [t3+r10*2+400*4+ 0]
mova m5, [t3+r10*2+400*4+32]
punpcklwd m1, m0, m6 ; src
punpcklwd m2, m3, m6 ; a
pmaddwd m2, m1
punpckhwd m1, m0, m6
punpckhwd m3, m6
pmaddwd m3, m1
vinserti128 m1, m4, xm5, 1
vperm2i128 m4, m5, 0x31
paddd m2, m1 ; a * src + b + (1 <<7)
paddd m3, m4
psrld m2, 8
psrld m3, 8
packssdw m2, m3
psllw m1, m0, 4
psubw m2, m1
pmulhrsw m2, m7
paddw m0, m2
pmaxsw m0, m6
pminsw m0, m14
mova [dstq+r10], m0
add r10, 32
jl .n1_loop
add dstq, dst_strideq
ret
cglobal sgr_filter_3x3_16bpc, 5, 14, 15, 400*42+8, dst, dst_stride, left, lpf, \
lpf_stride, w, edge, params, h
movifnidn wd, wm
mov paramsq, paramsmp
lea r13, [sgr_x_by_x_avx2+256*4]
mov edged, r8m
add wd, wd
mov hd, r6m
add lpfq, wq
vpbroadcastw m7, [paramsq+10] ; w1
lea t1, [rsp+wq+12]
vpbroadcastd m8, [pd_8]
add dstq, wq
vpbroadcastd m9, [paramsq+ 4] ; s1
lea t3, [rsp+wq*2+400*12+8]
vpbroadcastd m10, [pd_0xf00801c7]
lea t4, [rsp+wq+400*32+8]
vpbroadcastd m11, [pd_34816]
neg wq
vpbroadcastd m12, [pw_256]
pxor m6, m6
vpbroadcastd m13, [pw_1023]
psllw m7, 4
mova xm14, [sgr_lshuf3]
test edgeb, 4 ; LR_HAVE_TOP
jz .no_top
call .h_top
add lpfq, lpf_strideq
mov t2, t1
add t1, 400*6
call .h_top
lea r10, [lpfq+lpf_strideq*4]
mov lpfq, dstq
add r10, lpf_strideq
mov [rsp], r10 ; below
call .hv0
.main:
dec hd
jz .height1
add lpfq, dst_strideq
call .hv1
call .prep_n
sub hd, 2
jl .extend_bottom
.main_loop:
add lpfq, dst_strideq
call .hv0
test hd, hd
jz .odd_height
add lpfq, dst_strideq
call .hv1
call .n0
call .n1
sub hd, 2
jge .main_loop
test edgeb, 8 ; LR_HAVE_BOTTOM
jz .extend_bottom
mov lpfq, [rsp]
call .hv0_bottom
add lpfq, lpf_strideq
call .hv1_bottom
.end:
call .n0
call .n1
.end2:
RET
.height1:
call .v1
call .prep_n
jmp .odd_height_end
.odd_height:
call .v1
call .n0
call .n1
.odd_height_end:
call .v0
call .v1
call .n0
jmp .end2
.extend_bottom:
call .v0
call .v1
jmp .end
.no_top:
lea r10, [lpfq+lpf_strideq*4]
mov lpfq, dstq
lea r10, [r10+lpf_strideq*2]
mov [rsp], r10
call .h
lea r10, [wq-4]
lea t2, [t1+400*6]
.top_fixup_loop:
mova m0, [t1+r10+400*0]
mova m1, [t1+r10+400*2]
mova m2, [t1+r10+400*4]
mova [t2+r10+400*0], m0
mova [t2+r10+400*2], m1
mova [t2+r10+400*4], m2
add r10, 32
jl .top_fixup_loop
call .v0
jmp .main
.extend_right:
vpbroadcastw m0, [lpfq-2]
movu m1, [r13+r10+ 2]
movu m2, [r13+r10+18]
vpblendvb m4, m0, m1
vpblendvb m5, m0, m2
ret
.h: ; horizontal boxsum
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .h_extend_left
vpbroadcastq xm5, [leftq]
vinserti128 m5, [lpfq+wq], 1
mova m4, [lpfq+wq]
add leftq, 8
palignr m4, m5, 12
jmp .h_main
.h_extend_left:
mova xm4, [lpfq+wq]
pshufb xm4, xm14
vinserti128 m4, [lpfq+wq+12], 1
jmp .h_main
.h_top:
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .h_extend_left
.h_loop:
movu m4, [lpfq+r10+ 0]
.h_main:
movu m5, [lpfq+r10+16]
test edgeb, 2 ; LR_HAVE_RIGHT
jnz .h_have_right
cmp r10d, -34
jl .h_have_right
call .extend_right
.h_have_right:
palignr m0, m5, m4, 2
paddw m1, m4, m0
punpcklwd m2, m4, m0
pmaddwd m2, m2
punpckhwd m3, m4, m0
pmaddwd m3, m3
palignr m5, m4, 4
paddw m1, m5 ; sum
punpcklwd m4, m5, m6
pmaddwd m4, m4
punpckhwd m5, m6
pmaddwd m5, m5
paddd m2, m4 ; sumsq
paddd m3, m5
mova [t1+r10+400*0], m1
mova [t1+r10+400*2], m2
mova [t1+r10+400*4], m3
add r10, 32
jl .h_loop
ret
ALIGN function_align
.hv0: ; horizontal boxsum + vertical boxsum + ab (even rows)
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .hv0_extend_left
vpbroadcastq xm5, [leftq]
vinserti128 m5, [lpfq+wq], 1
mova m4, [lpfq+wq]
add leftq, 8
palignr m4, m5, 12
jmp .hv0_main
.hv0_extend_left:
mova xm4, [lpfq+wq]
pshufb xm4, xm14
vinserti128 m4, [lpfq+wq+12], 1
jmp .hv0_main
.hv0_bottom:
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .hv0_extend_left
.hv0_loop:
movu m4, [lpfq+r10+ 0]
.hv0_main:
movu m5, [lpfq+r10+16]
test edgeb, 2 ; LR_HAVE_RIGHT
jnz .hv0_have_right
cmp r10d, -34
jl .hv0_have_right
call .extend_right
.hv0_have_right:
palignr m0, m5, m4, 2
paddw m1, m4, m0
punpcklwd m2, m4, m0
pmaddwd m2, m2
punpckhwd m3, m4, m0
pmaddwd m3, m3
palignr m5, m4, 4
paddw m1, m5 ; sum
punpcklwd m4, m5, m6
pmaddwd m4, m4
punpckhwd m5, m6
pmaddwd m5, m5
paddd m2, m4 ; sumsq
paddd m3, m5
paddw m0, m1, [t1+r10+400*0]
paddd m4, m2, [t1+r10+400*2]
paddd m5, m3, [t1+r10+400*4]
mova [t1+r10+400*0], m1
mova [t1+r10+400*2], m2
mova [t1+r10+400*4], m3
paddw m1, m0, [t2+r10+400*0]
paddd m2, m4, [t2+r10+400*2]
paddd m3, m5, [t2+r10+400*4]
mova [t2+r10+400*0], m0
mova [t2+r10+400*2], m4
mova [t2+r10+400*4], m5
paddd m2, m8
paddd m3, m8
psrld m2, 4 ; (a + 8) >> 4
psrld m3, 4
pslld m4, m2, 3
pslld m5, m3, 3
paddd m4, m2 ; ((a + 8) >> 4) * 9
paddd m5, m3
psrlw m3, m1, 1
pavgw m3, m6 ; (b + 2) >> 2
punpcklwd m2, m3, m6
pmaddwd m2, m2
punpckhwd m3, m6
pmaddwd m3, m3
punpcklwd m0, m1, m6 ; b
punpckhwd m1, m6
pmaxud m4, m2
psubd m4, m2 ; p
pmaxud m5, m3
psubd m5, m3
pmulld m4, m9 ; p * s
pmulld m5, m9
pmaddwd m0, m10 ; b * 455
pmaddwd m1, m10
paddusw m4, m10
paddusw m5, m10
psrad m3, m4, 20 ; min(z, 255) - 256
vpgatherdd m2, [r13+m3*4], m4
psrad m4, m5, 20
vpgatherdd m3, [r13+m4*4], m5
pmulld m0, m2
pmulld m1, m3
packssdw m2, m3
paddd m0, m11 ; x * b * 455 + (1 << 11) + (1 << 15)
paddd m1, m11
psubw m2, m12, m2
psrld m0, 12
psrld m1, 12
mova [t4+r10*1+400*0+ 4], m2
mova [t3+r10*2+400*0+ 8], xm0
vextracti128 [t3+r10*2+400*0+40], m0, 1
mova [t3+r10*2+400*0+24], xm1
vextracti128 [t3+r10*2+400*0+56], m1, 1
add r10, 32
jl .hv0_loop
ret
ALIGN function_align
.hv1: ; horizontal boxsums + vertical boxsums + ab (odd rows)
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .hv1_extend_left
vpbroadcastq xm5, [leftq]
vinserti128 m5, [lpfq+wq], 1
mova m4, [lpfq+wq]
add leftq, 8
palignr m4, m5, 12
jmp .hv1_main
.hv1_extend_left:
mova xm4, [lpfq+wq]
pshufb xm4, xm14
vinserti128 m4, [lpfq+wq+12], 1
jmp .hv1_main
.hv1_bottom:
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .hv1_extend_left
.hv1_loop:
movu m4, [lpfq+r10+ 0]
.hv1_main:
movu m5, [lpfq+r10+16]
test edgeb, 2 ; LR_HAVE_RIGHT
jnz .hv1_have_right
cmp r10d, -34
jl .hv1_have_right
call .extend_right
.hv1_have_right:
palignr m1, m5, m4, 2
paddw m0, m4, m1
punpcklwd m2, m4, m1
pmaddwd m2, m2
punpckhwd m3, m4, m1
pmaddwd m3, m3
palignr m5, m4, 4
paddw m0, m5 ; h sum
punpcklwd m1, m5, m6
pmaddwd m1, m1
punpckhwd m5, m6
pmaddwd m5, m5
paddd m2, m1 ; h sumsq
paddd m3, m5
paddw m1, m0, [t2+r10+400*0]
paddd m4, m2, [t2+r10+400*2]
paddd m5, m3, [t2+r10+400*4]
mova [t2+r10+400*0], m0
mova [t2+r10+400*2], m2
mova [t2+r10+400*4], m3
paddd m4, m8
paddd m5, m8
psrld m4, 4 ; (a + 8) >> 4
psrld m5, 4
pslld m2, m4, 3
pslld m3, m5, 3
paddd m4, m2 ; ((a + 8) >> 4) * 9
paddd m5, m3
psrlw m3, m1, 1
pavgw m3, m6 ; (b + 2) >> 2
punpcklwd m2, m3, m6
pmaddwd m2, m2
punpckhwd m3, m6
pmaddwd m3, m3
punpcklwd m0, m1, m6 ; b
punpckhwd m1, m6
pmaxud m4, m2
psubd m4, m2 ; p
pmaxud m5, m3
psubd m5, m3
pmulld m4, m9 ; p * s
pmulld m5, m9
pmaddwd m0, m10 ; b * 455
pmaddwd m1, m10
paddusw m4, m10
paddusw m5, m10
psrad m3, m4, 20 ; min(z, 255) - 256
vpgatherdd m2, [r13+m3*4], m4
psrad m4, m5, 20
vpgatherdd m3, [r13+m4*4], m5
pmulld m0, m2
pmulld m1, m3
packssdw m2, m3
paddd m0, m11 ; x * b * 455 + (1 << 11) + (1 << 15)
paddd m1, m11
psubw m2, m12, m2
psrld m0, 12
psrld m1, 12
mova [t4+r10*1+400*2 +4], m2
mova [t3+r10*2+400*4+ 8], xm0
vextracti128 [t3+r10*2+400*4+40], m0, 1
mova [t3+r10*2+400*4+24], xm1
vextracti128 [t3+r10*2+400*4+56], m1, 1
add r10, 32
jl .hv1_loop
mov r10, t2
mov t2, t1
mov t1, r10
ret
.v0: ; vertical boxsums + ab (even rows)
lea r10, [wq-4]
.v0_loop:
mova m0, [t1+r10+400*0]
mova m4, [t1+r10+400*2]
mova m5, [t1+r10+400*4]
paddw m0, m0
paddd m4, m4
paddd m5, m5
paddw m1, m0, [t2+r10+400*0]
paddd m2, m4, [t2+r10+400*2]
paddd m3, m5, [t2+r10+400*4]
mova [t2+r10+400*0], m0
mova [t2+r10+400*2], m4
mova [t2+r10+400*4], m5
paddd m2, m8
paddd m3, m8
psrld m2, 4 ; (a + 8) >> 4
psrld m3, 4
pslld m4, m2, 3
pslld m5, m3, 3
paddd m4, m2 ; ((a + 8) >> 4) * 9
paddd m5, m3
psrlw m3, m1, 1
pavgw m3, m6 ; (b + 2) >> 2
punpcklwd m2, m3, m6
pmaddwd m2, m2
punpckhwd m3, m6
pmaddwd m3, m3
punpcklwd m0, m1, m6 ; b
punpckhwd m1, m6
pmaxud m4, m2
psubd m4, m2 ; p
pmaxud m5, m3
psubd m5, m3
pmulld m4, m9 ; p * s
pmulld m5, m9
pmaddwd m0, m10 ; b * 455
pmaddwd m1, m10
paddusw m4, m10
paddusw m5, m10
psrad m3, m4, 20 ; min(z, 255) - 256
vpgatherdd m2, [r13+m3*4], m4
psrad m4, m5, 20
vpgatherdd m3, [r13+m4*4], m5
pmulld m0, m2
pmulld m1, m3
packssdw m2, m3
paddd m0, m11 ; x * b * 455 + (1 << 11) + (1 << 15)
paddd m1, m11
psubw m2, m12, m2
psrld m0, 12
psrld m1, 12
mova [t4+r10*1+400*0+ 4], m2
mova [t3+r10*2+400*0+ 8], xm0
vextracti128 [t3+r10*2+400*0+40], m0, 1
mova [t3+r10*2+400*0+24], xm1
vextracti128 [t3+r10*2+400*0+56], m1, 1
add r10, 32
jl .v0_loop
ret
.v1: ; vertical boxsums + ab (odd rows)
lea r10, [wq-4]
.v1_loop:
mova m0, [t1+r10+400*0]
mova m4, [t1+r10+400*2]
mova m5, [t1+r10+400*4]
paddw m1, m0, [t2+r10+400*0]
paddd m2, m4, [t2+r10+400*2]
paddd m3, m5, [t2+r10+400*4]
mova [t2+r10+400*0], m0
mova [t2+r10+400*2], m4
mova [t2+r10+400*4], m5
paddd m2, m8
paddd m3, m8
psrld m2, 4 ; (a + 8) >> 4
psrld m3, 4
pslld m4, m2, 3
pslld m5, m3, 3
paddd m4, m2 ; ((a + 8) >> 4) * 9
paddd m5, m3
psrlw m3, m1, 1
pavgw m3, m6 ; (b + 2) >> 2
punpcklwd m2, m3, m6
pmaddwd m2, m2
punpckhwd m3, m6
pmaddwd m3, m3
punpcklwd m0, m1, m6 ; b
punpckhwd m1, m6
pmaxud m4, m2
psubd m4, m2 ; p
pmaxud m5, m3
psubd m5, m3
pmulld m4, m9 ; p * s
pmulld m5, m9
pmaddwd m0, m10 ; b * 455
pmaddwd m1, m10
paddusw m4, m10
paddusw m5, m10
psrad m3, m4, 20 ; min(z, 255) - 256
vpgatherdd m2, [r13+m3*4], m4
psrad m4, m5, 20
vpgatherdd m3, [r13+m4*4], m5
pmulld m0, m2
pmulld m1, m3
packssdw m2, m3
paddd m0, m11 ; x * b * 455 + (1 << 11) + (1 << 15)
paddd m1, m11
psubw m2, m12, m2
psrld m0, 12
psrld m1, 12
mova [t4+r10*1+400*2+ 4], m2
mova [t3+r10*2+400*4+ 8], xm0
vextracti128 [t3+r10*2+400*4+40], m0, 1
mova [t3+r10*2+400*4+24], xm1
vextracti128 [t3+r10*2+400*4+56], m1, 1
add r10, 32
jl .v1_loop
mov r10, t2
mov t2, t1
mov t1, r10
ret
.prep_n: ; initial neighbor setup
mov r10, wq
.prep_n_loop:
mova xm0, [t4+r10*1+400*0+0]
paddw xm0, [t4+r10*1+400*0+4]
paddw xm2, xm0, [t4+r10*1+400*0+2]
mova m1, [t3+r10*2+400*0+0]
paddd m1, [t3+r10*2+400*0+8]
paddd m3, m1, [t3+r10*2+400*0+4]
psllw xm2, 2 ; a[-1] 444
pslld m3, 2 ; b[-1] 444
psubw xm2, xm0 ; a[-1] 343
psubd m3, m1 ; b[-1] 343
mova [t4+r10*1+400* 4], xm2
mova [t3+r10*2+400* 8], m3
mova xm0, [t4+r10*1+400*2+0]
paddw xm0, [t4+r10*1+400*2+4]
paddw xm2, xm0, [t4+r10*1+400*2+2]
mova m1, [t3+r10*2+400*4+0]
paddd m1, [t3+r10*2+400*4+8]
paddd m3, m1, [t3+r10*2+400*4+4]
psllw xm2, 2 ; a[ 0] 444
pslld m3, 2 ; b[ 0] 444
mova [t4+r10*1+400* 6], xm2
mova [t3+r10*2+400*12], m3
psubw xm2, xm0 ; a[ 0] 343
psubd m3, m1 ; b[ 0] 343
mova [t4+r10*1+400* 8], xm2
mova [t3+r10*2+400*16], m3
add r10, 16
jl .prep_n_loop
ret
ALIGN function_align
.n0: ; neighbor + output (even rows)
mov r10, wq
.n0_loop:
mova m3, [t4+r10*1+400*0+0]
paddw m3, [t4+r10*1+400*0+4]
paddw m1, m3, [t4+r10*1+400*0+2]
psllw m1, 2 ; a[ 1] 444
psubw m2, m1, m3 ; a[ 1] 343
paddw m3, m2, [t4+r10*1+400*4]
paddw m3, [t4+r10*1+400*6]
mova [t4+r10*1+400*4], m2
mova [t4+r10*1+400*6], m1
mova m4, [t3+r10*2+400*0+0]
paddd m4, [t3+r10*2+400*0+8]
paddd m1, m4, [t3+r10*2+400*0+4]
pslld m1, 2 ; b[ 1] 444
psubd m2, m1, m4 ; b[ 1] 343
paddd m4, m2, [t3+r10*2+400* 8+ 0]
paddd m4, [t3+r10*2+400*12+ 0]
mova [t3+r10*2+400* 8+ 0], m2
mova [t3+r10*2+400*12+ 0], m1
mova m5, [t3+r10*2+400*0+32]
paddd m5, [t3+r10*2+400*0+40]
paddd m1, m5, [t3+r10*2+400*0+36]
pslld m1, 2
psubd m2, m1, m5
paddd m5, m2, [t3+r10*2+400* 8+32]
paddd m5, [t3+r10*2+400*12+32]
mova [t3+r10*2+400* 8+32], m2
mova [t3+r10*2+400*12+32], m1
mova m0, [dstq+r10]
punpcklwd m1, m0, m6
punpcklwd m2, m3, m6
pmaddwd m2, m1 ; a * src
punpckhwd m1, m0, m6
punpckhwd m3, m6
pmaddwd m3, m1
vinserti128 m1, m4, xm5, 1
vperm2i128 m4, m5, 0x31
paddd m2, m1 ; a * src + b + (1 << 8)
paddd m3, m4
psrld m2, 9
psrld m3, 9
packssdw m2, m3
psllw m1, m0, 4
psubw m2, m1
pmulhrsw m2, m7
paddw m0, m2
pmaxsw m0, m6
pminsw m0, m13
mova [dstq+r10], m0
add r10, 32
jl .n0_loop
add dstq, dst_strideq
ret
ALIGN function_align
.n1: ; neighbor + output (odd rows)
mov r10, wq
.n1_loop:
mova m3, [t4+r10*1+400*2+0]
paddw m3, [t4+r10*1+400*2+4]
paddw m1, m3, [t4+r10*1+400*2+2]
psllw m1, 2 ; a[ 1] 444
psubw m2, m1, m3 ; a[ 1] 343
paddw m3, m2, [t4+r10*1+400*6]
paddw m3, [t4+r10*1+400*8]
mova [t4+r10*1+400*6], m1
mova [t4+r10*1+400*8], m2
mova m4, [t3+r10*2+400*4+0]
paddd m4, [t3+r10*2+400*4+8]
paddd m1, m4, [t3+r10*2+400*4+4]
pslld m1, 2 ; b[ 1] 444
psubd m2, m1, m4 ; b[ 1] 343
paddd m4, m2, [t3+r10*2+400*12+ 0]
paddd m4, [t3+r10*2+400*16+ 0]
mova [t3+r10*2+400*12+ 0], m1
mova [t3+r10*2+400*16+ 0], m2
mova m5, [t3+r10*2+400*4+32]
paddd m5, [t3+r10*2+400*4+40]
paddd m1, m5, [t3+r10*2+400*4+36]
pslld m1, 2
psubd m2, m1, m5
paddd m5, m2, [t3+r10*2+400*12+32]
paddd m5, [t3+r10*2+400*16+32]
mova [t3+r10*2+400*12+32], m1
mova [t3+r10*2+400*16+32], m2
mova m0, [dstq+r10]
punpcklwd m1, m0, m6
punpcklwd m2, m3, m6
pmaddwd m2, m1 ; a * src
punpckhwd m1, m0, m6
punpckhwd m3, m6
pmaddwd m3, m1
vinserti128 m1, m4, xm5, 1
vperm2i128 m4, m5, 0x31
paddd m2, m1 ; a * src + b + (1 << 8)
paddd m3, m4
psrld m2, 9
psrld m3, 9
packssdw m2, m3
psllw m1, m0, 4
psubw m2, m1
pmulhrsw m2, m7
paddw m0, m2
pmaxsw m0, m6
pminsw m0, m13
mova [dstq+r10], m0
add r10, 32
jl .n1_loop
add dstq, dst_strideq
ret
cglobal sgr_filter_mix_16bpc, 5, 14, 16, 400*66+8, dst, dst_stride, left, lpf, \
lpf_stride, w, edge, params, h
movifnidn wd, wm
mov paramsq, paramsmp
lea r13, [sgr_x_by_x_avx2+256*4]
mov edged, r8m
add wd, wd
mov hd, r6m
add lpfq, wq
vpbroadcastd m9, [pd_8]
lea t1, [rsp+wq+12]
vpbroadcastd m10, [pd_34816]
add dstq, wq
vpbroadcastd m11, [pw_256]
lea t3, [rsp+wq*2+400*24+8]
vpbroadcastd m12, [pd_0xf00801c7]
lea t4, [rsp+wq+400*52+8]
vpbroadcastd m15, [paramsq+8] ; w0 w1
neg wq
vpbroadcastd m13, [paramsq+0] ; s0
pxor m7, m7
vpbroadcastd m14, [paramsq+4] ; s1
psllw m15, 2
test edgeb, 4 ; LR_HAVE_TOP
jz .no_top
call .h_top
add lpfq, lpf_strideq
mov t2, t1
call mangle(private_prefix %+ _sgr_filter_5x5_16bpc_avx2).top_fixup
add t1, 400*12
call .h_top
lea r10, [lpfq+lpf_strideq*4]
mov lpfq, dstq
add r10, lpf_strideq
mov [rsp], r10 ; below
call .hv0
.main:
dec hd
jz .height1
add lpfq, dst_strideq
call .hv1
call .prep_n
sub hd, 2
jl .extend_bottom
.main_loop:
add lpfq, dst_strideq
call .hv0
test hd, hd
jz .odd_height
add lpfq, dst_strideq
call .hv1
call .n0
call .n1
sub hd, 2
jge .main_loop
test edgeb, 8 ; LR_HAVE_BOTTOM
jz .extend_bottom
mov lpfq, [rsp]
call .hv0_bottom
add lpfq, lpf_strideq
call .hv1_bottom
.end:
call .n0
call .n1
.end2:
RET
.height1:
call .v1
call .prep_n
jmp .odd_height_end
.odd_height:
call .v1
call .n0
call .n1
.odd_height_end:
call .v0
call .v1
call .n0
jmp .end2
.extend_bottom:
call .v0
call .v1
jmp .end
.no_top:
lea r10, [lpfq+lpf_strideq*4]
mov lpfq, dstq
lea r10, [r10+lpf_strideq*2]
mov [rsp], r10
call .h
lea r10, [wq-4]
lea t2, [t1+400*12]
.top_fixup_loop:
mova m0, [t1+r10+400* 0]
mova m1, [t1+r10+400* 2]
mova m2, [t1+r10+400* 4]
paddw m0, m0
mova m3, [t1+r10+400* 6]
paddd m1, m1
mova m4, [t1+r10+400* 8]
paddd m2, m2
mova m5, [t1+r10+400*10]
mova [t2+r10+400* 0], m0
mova [t2+r10+400* 2], m1
mova [t2+r10+400* 4], m2
mova [t2+r10+400* 6], m3
mova [t2+r10+400* 8], m4
mova [t2+r10+400*10], m5
add r10, 32
jl .top_fixup_loop
call .v0
jmp .main
.h: ; horizontal boxsum
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .h_extend_left
vpbroadcastq xm5, [leftq]
vinserti128 m5, [lpfq+wq], 1
mova m4, [lpfq+wq]
add leftq, 8
palignr m4, m5, 10
jmp .h_main
.h_extend_left:
mova xm4, [lpfq+wq]
pshufb xm4, [sgr_lshuf5]
vinserti128 m4, [lpfq+wq+10], 1
jmp .h_main
.h_top:
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .h_extend_left
.h_loop:
movu m4, [lpfq+r10- 2]
.h_main:
movu m5, [lpfq+r10+14]
test edgeb, 2 ; LR_HAVE_RIGHT
jnz .h_have_right
cmp r10d, -36
jl .h_have_right
call mangle(private_prefix %+ _sgr_filter_5x5_16bpc_avx2).extend_right
.h_have_right:
palignr m3, m5, m4, 2
palignr m0, m5, m4, 4
paddw m1, m3, m0
punpcklwd m2, m3, m0
pmaddwd m2, m2
punpckhwd m3, m0
pmaddwd m3, m3
palignr m0, m5, m4, 6
paddw m1, m0 ; sum3
punpcklwd m6, m0, m7
pmaddwd m6, m6
punpckhwd m0, m7
pmaddwd m0, m0
paddd m2, m6 ; sumsq3
shufpd m6, m4, m5, 0x05
punpcklwd m5, m6, m4
paddw m8, m4, m6
pmaddwd m5, m5
punpckhwd m6, m4
pmaddwd m6, m6
paddd m3, m0
mova [t1+r10+400* 6], m1
mova [t1+r10+400* 8], m2
mova [t1+r10+400*10], m3
paddw m8, m1 ; sum5
paddd m5, m2 ; sumsq5
paddd m6, m3
mova [t1+r10+400* 0], m8
mova [t1+r10+400* 2], m5
mova [t1+r10+400* 4], m6
add r10, 32
jl .h_loop
ret
ALIGN function_align
.hv0: ; horizontal boxsum + vertical boxsum + ab3 (even rows)
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .hv0_extend_left
vpbroadcastq xm5, [leftq]
vinserti128 m5, [lpfq+wq], 1
mova m4, [lpfq+wq]
add leftq, 8
palignr m4, m5, 10
jmp .hv0_main
.hv0_extend_left:
mova xm4, [lpfq+wq]
pshufb xm4, [sgr_lshuf5]
vinserti128 m4, [lpfq+wq+10], 1
jmp .hv0_main
.hv0_bottom:
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .hv0_extend_left
.hv0_loop:
movu m4, [lpfq+r10- 2]
.hv0_main:
movu m5, [lpfq+r10+14]
test edgeb, 2 ; LR_HAVE_RIGHT
jnz .hv0_have_right
cmp r10d, -36
jl .hv0_have_right
call mangle(private_prefix %+ _sgr_filter_5x5_16bpc_avx2).extend_right
.hv0_have_right:
palignr m3, m5, m4, 2
palignr m0, m5, m4, 4
paddw m1, m3, m0
punpcklwd m2, m3, m0
pmaddwd m2, m2
punpckhwd m3, m0
pmaddwd m3, m3
palignr m0, m5, m4, 6
paddw m1, m0 ; h sum3
punpcklwd m6, m0, m7
pmaddwd m6, m6
punpckhwd m0, m7
pmaddwd m0, m0
paddd m2, m6 ; h sumsq3
shufpd m6, m4, m5, 0x05
punpcklwd m5, m6, m4
paddw m8, m4, m6
pmaddwd m5, m5
punpckhwd m6, m4
pmaddwd m6, m6
paddd m3, m0
paddw m8, m1 ; h sum5
paddd m5, m2 ; h sumsq5
paddd m6, m3
mova [t3+r10*2+400*8+ 8], m8 ; we need a clean copy of the last row TODO: t4?
mova [t3+r10*2+400*0+ 8], m5 ; in case height is odd
mova [t3+r10*2+400*0+40], m6
paddw m8, [t1+r10+400* 0]
paddd m5, [t1+r10+400* 2]
paddd m6, [t1+r10+400* 4]
mova [t1+r10+400* 0], m8
mova [t1+r10+400* 2], m5
mova [t1+r10+400* 4], m6
paddw m0, m1, [t1+r10+400* 6]
paddd m4, m2, [t1+r10+400* 8]
paddd m5, m3, [t1+r10+400*10]
mova [t1+r10+400* 6], m1
mova [t1+r10+400* 8], m2
mova [t1+r10+400*10], m3
paddw m1, m0, [t2+r10+400* 6]
paddd m2, m4, [t2+r10+400* 8]
paddd m3, m5, [t2+r10+400*10]
mova [t2+r10+400* 6], m0
mova [t2+r10+400* 8], m4
mova [t2+r10+400*10], m5
paddd m2, m9
paddd m3, m9
psrld m2, 4 ; (a3 + 8) >> 4
psrld m3, 4
pslld m4, m2, 3
pslld m5, m3, 3
paddd m4, m2 ; ((a3 + 8) >> 4) * 9
paddd m5, m3
psrlw m3, m1, 1
pavgw m3, m7 ; (b3 + 2) >> 2
punpcklwd m2, m3, m7
pmaddwd m2, m2
punpckhwd m3, m7
pmaddwd m3, m3
punpcklwd m0, m1, m7 ; b3
punpckhwd m1, m7
pmaxud m4, m2
psubd m4, m2 ; p3
pmaxud m5, m3
psubd m5, m3
pmulld m4, m14 ; p3 * s1
pmulld m5, m14
pmaddwd m0, m12 ; b3 * 455
pmaddwd m1, m12
paddusw m4, m12
paddusw m5, m12
psrad m3, m4, 20 ; min(z3, 255) - 256
vpgatherdd m2, [r13+m3*4], m4
psrad m4, m5, 20
vpgatherdd m3, [r13+m4*4], m5
pmulld m0, m2
pmulld m1, m3
packssdw m2, m3
paddd m0, m10 ; x3 * b3 * 455 + (1 << 11) + (1 << 15)
paddd m1, m10
psubw m2, m11, m2
psrld m0, 12
psrld m1, 12
mova [t4+r10*1+400*2+ 4], m2
mova [t3+r10*2+400*4+ 8], xm0
vextracti128 [t3+r10*2+400*4+40], m0, 1
mova [t3+r10*2+400*4+24], xm1
vextracti128 [t3+r10*2+400*4+56], m1, 1
add r10, 32
jl .hv0_loop
ret
ALIGN function_align
.hv1: ; horizontal boxsums + vertical boxsums + ab (odd rows)
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .hv1_extend_left
vpbroadcastq xm5, [leftq]
vinserti128 m5, [lpfq+wq], 1
mova m4, [lpfq+wq]
add leftq, 8
palignr m4, m5, 10
jmp .hv1_main
.hv1_extend_left:
mova xm4, [lpfq+wq]
pshufb xm4, [sgr_lshuf5]
vinserti128 m4, [lpfq+wq+10], 1
jmp .hv1_main
.hv1_bottom:
lea r10, [wq-4]
test edgeb, 1 ; LR_HAVE_LEFT
jz .hv1_extend_left
.hv1_loop:
movu m4, [lpfq+r10- 2]
.hv1_main:
movu m5, [lpfq+r10+14]
test edgeb, 2 ; LR_HAVE_RIGHT
jnz .hv1_have_right
cmp r10d, -36
jl .hv1_have_right
call mangle(private_prefix %+ _sgr_filter_5x5_16bpc_avx2).extend_right
.hv1_have_right:
palignr m6, m5, m4, 2
palignr m3, m5, m4, 4
paddw m2, m6, m3
punpcklwd m0, m6, m3
pmaddwd m0, m0
punpckhwd m6, m3
pmaddwd m6, m6
palignr m3, m5, m4, 6
paddw m2, m3 ; h sum3
punpcklwd m1, m3, m7
pmaddwd m1, m1
punpckhwd m3, m7
pmaddwd m3, m3
paddd m0, m1 ; h sumsq3
shufpd m1, m4, m5, 0x05
punpckhwd m5, m4, m1
paddw m8, m4, m1
pmaddwd m5, m5
punpcklwd m4, m1
pmaddwd m4, m4
paddd m6, m3
paddw m1, m2, [t2+r10+400* 6]
mova [t2+r10+400* 6], m2
paddw m8, m2 ; h sum5
paddd m2, m0, [t2+r10+400* 8]
paddd m3, m6, [t2+r10+400*10]
mova [t2+r10+400* 8], m0
mova [t2+r10+400*10], m6
paddd m4, m0 ; h sumsq5
paddd m5, m6
paddd m2, m9
paddd m3, m9
psrld m2, 4 ; (a3 + 8) >> 4
psrld m3, 4
pslld m0, m2, 3
pslld m6, m3, 3
paddd m2, m0 ; ((a3 + 8) >> 4) * 9
paddd m3, m6
psrlw m6, m1, 1
pavgw m6, m7 ; (b3 + 2) >> 2
punpcklwd m0, m6, m7
pmaddwd m0, m0
punpckhwd m6, m7
pmaddwd m6, m6
pmaxud m2, m0
psubd m2, m0 ; p3
pmaxud m3, m6
psubd m3, m6
punpcklwd m0, m1, m7 ; b3
punpckhwd m1, m7
pmulld m2, m14 ; p3 * s1
pmulld m3, m14
pmaddwd m0, m12 ; b3 * 455
pmaddwd m1, m12
paddusw m2, m12
paddusw m3, m12
psrad m7, m2, 20 ; min(z3, 255) - 256
vpgatherdd m6, [r13+m7*4], m2
psrad m2, m3, 20
vpgatherdd m7, [r13+m2*4], m3
pmulld m0, m6
packssdw m6, m7
pmulld m7, m1
paddd m0, m10 ; x3 * b3 * 455 + (1 << 11) + (1 << 15)
paddd m7, m10
psubw m6, m11, m6
psrld m0, 12
psrld m7, 12
paddw m1, m8, [t2+r10+400*0]
paddd m2, m4, [t2+r10+400*2]
paddd m3, m5, [t2+r10+400*4]
paddw m1, [t1+r10+400*0]
paddd m2, [t1+r10+400*2]
paddd m3, [t1+r10+400*4]
mova [t2+r10+400*0], m8
mova [t2+r10+400*2], m4
mova [t2+r10+400*4], m5
mova [t4+r10*1+400*4 +4], m6
mova [t3+r10*2+400*8+ 8], xm0
vextracti128 [t3+r10*2+400*8+40], m0, 1
mova [t3+r10*2+400*8+24], xm7
vextracti128 [t3+r10*2+400*8+56], m7, 1
vpbroadcastd m4, [pd_25]
pxor m7, m7
paddd m2, m9
paddd m3, m9
psrld m2, 4 ; (a5 + 8) >> 4
psrld m3, 4
pmulld m2, m4 ; ((a5 + 8) >> 4) * 25
pmulld m3, m4
psrlw m5, m1, 1
pavgw m5, m7 ; (b5 + 2) >> 2
punpcklwd m4, m5, m7
pmaddwd m4, m4
punpckhwd m5, m7
pmaddwd m5, m5
punpcklwd m0, m1, m7 ; b5
punpckhwd m1, m7
pmaxud m2, m4
psubd m2, m4 ; p5
vpbroadcastd m4, [pd_0xf00800a4]
pmaxud m3, m5
psubd m3, m5
pmulld m2, m13 ; p5 * s0
pmulld m3, m13
pmaddwd m0, m4 ; b5 * 164
pmaddwd m1, m4
paddusw m2, m4
paddusw m3, m4
psrad m5, m2, 20 ; min(z5, 255) - 256
vpgatherdd m4, [r13+m5*4], m2
psrad m2, m3, 20
vpgatherdd m5, [r13+m2*4], m3
pmulld m0, m4
pmulld m1, m5
packssdw m4, m5
paddd m0, m10 ; x5 * b5 * 164 + (1 << 11) + (1 << 15)
paddd m1, m10
psubw m4, m11, m4
psrld m0, 12
psrld m1, 12
mova [t4+r10*1+400*0+ 4], m4
mova [t3+r10*2+400*0+ 8], xm0
vextracti128 [t3+r10*2+400*0+40], m0, 1
mova [t3+r10*2+400*0+24], xm1
vextracti128 [t3+r10*2+400*0+56], m1, 1
add r10, 32
jl .hv1_loop
mov r10, t2
mov t2, t1
mov t1, r10
ret
.v0: ; vertical boxsums + ab3 (even rows)
lea r10, [wq-4]
.v0_loop:
mova m0, [t1+r10+400* 6]
mova m4, [t1+r10+400* 8]
mova m5, [t1+r10+400*10]
paddw m0, m0
paddd m4, m4
paddd m5, m5
paddw m1, m0, [t2+r10+400* 6]
paddd m2, m4, [t2+r10+400* 8]
paddd m3, m5, [t2+r10+400*10]
mova [t2+r10+400* 6], m0
mova [t2+r10+400* 8], m4
mova [t2+r10+400*10], m5
paddd m2, m9
paddd m3, m9
psrld m2, 4 ; (a3 + 8) >> 4
psrld m3, 4
pslld m4, m2, 3
pslld m5, m3, 3
paddd m4, m2 ; ((a3 + 8) >> 4) * 9
paddd m5, m3
psrlw m3, m1, 1
pavgw m3, m7 ; (b3 + 2) >> 2
punpcklwd m2, m3, m7
pmaddwd m2, m2
punpckhwd m3, m7
pmaddwd m3, m3
punpcklwd m0, m1, m7 ; b3
punpckhwd m1, m7
pmaxud m4, m2
psubd m4, m2 ; p3
pmaxud m5, m3
psubd m5, m3
pmulld m4, m14 ; p3 * s1
pmulld m5, m14
pmaddwd m0, m12 ; b3 * 455
pmaddwd m1, m12
paddusw m4, m12
paddusw m5, m12
psrad m3, m4, 20 ; min(z3, 255) - 256
vpgatherdd m2, [r13+m3*4], m4
psrad m4, m5, 20
vpgatherdd m3, [r13+m4*4], m5
pmulld m0, m2
pmulld m1, m3
packssdw m2, m3
paddd m0, m10 ; x3 * b3 * 455 + (1 << 11) + (1 << 15)
paddd m1, m10
psubw m2, m11, m2
psrld m0, 12
psrld m1, 12
mova m3, [t1+r10+400*0]
mova m4, [t1+r10+400*2]
mova m5, [t1+r10+400*4]
mova [t3+r10*2+400*8+ 8], m3
mova [t3+r10*2+400*0+ 8], m4
mova [t3+r10*2+400*0+40], m5
paddw m3, m3 ; cc5
paddd m4, m4
paddd m5, m5
mova [t1+r10+400*0], m3
mova [t1+r10+400*2], m4
mova [t1+r10+400*4], m5
mova [t4+r10*1+400*2+ 4], m2
mova [t3+r10*2+400*4+ 8], xm0
vextracti128 [t3+r10*2+400*4+40], m0, 1
mova [t3+r10*2+400*4+24], xm1
vextracti128 [t3+r10*2+400*4+56], m1, 1
add r10, 32
jl .v0_loop
ret
.v1: ; vertical boxsums + ab (odd rows)
lea r10, [wq-4]
.v1_loop:
mova m4, [t1+r10+400* 6]
mova m5, [t1+r10+400* 8]
mova m6, [t1+r10+400*10]
paddw m1, m4, [t2+r10+400* 6]
paddd m2, m5, [t2+r10+400* 8]
paddd m3, m6, [t2+r10+400*10]
mova [t2+r10+400* 6], m4
mova [t2+r10+400* 8], m5
mova [t2+r10+400*10], m6
paddd m2, m9
paddd m3, m9
psrld m2, 4 ; (a3 + 8) >> 4
psrld m3, 4
pslld m4, m2, 3
pslld m5, m3, 3
paddd m4, m2 ; ((a3 + 8) >> 4) * 9
paddd m5, m3
psrlw m3, m1, 1
pavgw m3, m7 ; (b3 + 2) >> 2
punpcklwd m2, m3, m7
pmaddwd m2, m2
punpckhwd m3, m7
pmaddwd m3, m3
punpcklwd m0, m1, m7 ; b3
punpckhwd m1, m7
pmaxud m4, m2
psubd m4, m2 ; p3
pmaxud m5, m3
psubd m5, m3
pmulld m4, m14 ; p3 * s1
pmulld m5, m14
pmaddwd m0, m12 ; b3 * 455
pmaddwd m1, m12
paddusw m4, m12
paddusw m5, m12
psrad m3, m4, 20 ; min(z3, 255) - 256
vpgatherdd m2, [r13+m3*4], m4
psrad m4, m5, 20
vpgatherdd m3, [r13+m4*4], m5
pmulld m0, m2
pmulld m1, m3
packssdw m2, m3
paddd m0, m10 ; x3 * b3 * 455 + (1 << 11) + (1 << 15)
paddd m1, m10
psubw m2, m11, m2
psrld m0, 12
psrld m8, m1, 12
mova [t4+r10*1+400*4+4], m2
mova m4, [t3+r10*2+400*8+ 8]
mova m5, [t3+r10*2+400*0+ 8]
mova m6, [t3+r10*2+400*0+40]
paddw m1, m4, [t2+r10+400*0]
paddd m2, m5, [t2+r10+400*2]
paddd m3, m6, [t2+r10+400*4]
paddw m1, [t1+r10+400*0]
paddd m2, [t1+r10+400*2]
paddd m3, [t1+r10+400*4]
mova [t2+r10+400*0], m4
mova [t2+r10+400*2], m5
mova [t2+r10+400*4], m6
vpbroadcastd m4, [pd_25]
mova [t3+r10*2+400*8+ 8], xm0
vextracti128 [t3+r10*2+400*8+40], m0, 1
mova [t3+r10*2+400*8+24], xm8
vextracti128 [t3+r10*2+400*8+56], m8, 1
paddd m2, m9
paddd m3, m9
psrld m2, 4 ; (a5 + 8) >> 4
psrld m3, 4
pmulld m2, m4 ; ((a5 + 8) >> 4) * 25
pmulld m3, m4
psrlw m5, m1, 1
pavgw m5, m7 ; (b5 + 2) >> 2
punpcklwd m4, m5, m7
pmaddwd m4, m4
punpckhwd m5, m7
pmaddwd m5, m5
punpcklwd m0, m1, m7 ; b5
punpckhwd m1, m7
pmaxud m2, m4
psubd m2, m4 ; p5
vpbroadcastd m4, [pd_0xf00800a4]
pmaxud m3, m5
psubd m3, m5
pmulld m2, m13 ; p5 * s0
pmulld m3, m13
pmaddwd m0, m4 ; b5 * 164
pmaddwd m1, m4
paddusw m2, m4
paddusw m3, m4
psrad m5, m2, 20 ; min(z5, 255) - 256
vpgatherdd m4, [r13+m5*4], m2
psrad m2, m3, 20
vpgatherdd m5, [r13+m2*4], m3
pmulld m0, m4
pmulld m1, m5
packssdw m4, m5
paddd m0, m10 ; x5 * b5 * 164 + (1 << 11) + (1 << 15)
paddd m1, m10
psubw m4, m11, m4
psrld m0, 12
psrld m1, 12
mova [t4+r10*1+400*0+ 4], m4
mova [t3+r10*2+400*0+ 8], xm0
vextracti128 [t3+r10*2+400*0+40], m0, 1
mova [t3+r10*2+400*0+24], xm1
vextracti128 [t3+r10*2+400*0+56], m1, 1
add r10, 32
jl .v1_loop
mov r10, t2
mov t2, t1
mov t1, r10
ret
.prep_n: ; initial neighbor setup
mov r10, wq
.prep_n_loop:
movu xm0, [t4+r10*1+400*0+2]
paddw xm2, xm0, [t4+r10*1+400*0+0]
paddw xm2, [t4+r10*1+400*0+4]
movu m1, [t3+r10*2+400*0+4]
paddd m3, m1, [t3+r10*2+400*0+0]
paddd m3, [t3+r10*2+400*0+8]
paddw xm0, xm2
paddd m1, m3
psllw xm2, 2
pslld m3, 2
paddw xm0, xm2 ; a5 565
paddd m1, m3 ; b5 565
mova [t4+r10*1+400* 6], xm0
mova [t3+r10*2+400*12], m1
mova xm0, [t4+r10*1+400*2+0]
paddw xm0, [t4+r10*1+400*2+4]
paddw xm2, xm0, [t4+r10*1+400*2+2]
mova m1, [t3+r10*2+400*4+0]
paddd m1, [t3+r10*2+400*4+8]
paddd m3, m1, [t3+r10*2+400*4+4]
psllw xm2, 2 ; a3[-1] 444
pslld m3, 2 ; b3[-1] 444
psubw xm2, xm0 ; a3[-1] 343
psubd m3, m1 ; b3[-1] 343
mova [t4+r10*1+400* 8], xm2
mova [t3+r10*2+400*16], m3
mova xm0, [t4+r10*1+400*4+0]
paddw xm0, [t4+r10*1+400*4+4]
paddw xm2, xm0, [t4+r10*1+400*4+2]
mova m1, [t3+r10*2+400*8+0]
paddd m1, [t3+r10*2+400*8+8]
paddd m3, m1, [t3+r10*2+400*8+4]
psllw xm2, 2 ; a3[ 0] 444
pslld m3, 2 ; b3[ 0] 444
mova [t4+r10*1+400*10], xm2
mova [t3+r10*2+400*20], m3
psubw xm2, xm0 ; a3[ 0] 343
psubd m3, m1 ; b3[ 0] 343
mova [t4+r10*1+400*12], xm2
mova [t3+r10*2+400*24], m3
add r10, 16
jl .prep_n_loop
ret
ALIGN function_align
.n0: ; neighbor + output (even rows)
mov r10, wq
.n0_loop:
movu xm2, [t4+r10*1+2]
paddw xm0, xm2, [t4+r10*1+0]
paddw xm0, [t4+r10*1+4]
paddw xm2, xm0
psllw xm0, 2
paddw xm0, xm2 ; a5
movu m1, [t3+r10*2+4]
paddd m4, m1, [t3+r10*2+0]
paddd m4, [t3+r10*2+8]
paddd m1, m4
pslld m4, 2
paddd m4, m1 ; b5
paddw xm2, xm0, [t4+r10*1+400* 6]
mova [t4+r10*1+400* 6], xm0
paddd m0, m4, [t3+r10*2+400*12]
mova [t3+r10*2+400*12], m4
mova xm3, [t4+r10*1+400*2+0]
paddw xm3, [t4+r10*1+400*2+4]
paddw xm5, xm3, [t4+r10*1+400*2+2]
psllw xm5, 2 ; a3[ 1] 444
psubw xm4, xm5, xm3 ; a3[ 1] 343
paddw xm3, xm4, [t4+r10*1+400* 8]
paddw xm3, [t4+r10*1+400*10]
mova [t4+r10*1+400* 8], xm4
mova [t4+r10*1+400*10], xm5
mova m1, [t3+r10*2+400*4+0]
paddd m1, [t3+r10*2+400*4+8]
paddd m5, m1, [t3+r10*2+400*4+4]
pslld m5, 2 ; b3[ 1] 444
psubd m4, m5, m1 ; b3[ 1] 343
paddd m1, m4, [t3+r10*2+400*16]
paddd m1, [t3+r10*2+400*20]
mova [t3+r10*2+400*16], m4
mova [t3+r10*2+400*20], m5
pmovzxwd m4, [dstq+r10]
pmovzxwd m2, xm2 ; a5
pmovzxwd m3, xm3 ; a3
pmaddwd m2, m4 ; a5 * src
pmaddwd m3, m4 ; a3 * src
pslld m4, 13
psubd m0, m4
psubd m1, m4
paddd m0, m2 ; a5 * src + b5 + (1 << 8) - (src << 13)
paddd m1, m3 ; a3 * src + b3 + (1 << 8) - (src << 13)
psrld m0, 9
pslld m1, 7
pblendw m0, m1, 0xaa
pmaddwd m0, m15
vpbroadcastd m1, [pd_4096]
paddd m4, m1
paddd m0, m4
psrad m0, 7
vextracti128 xm1, m0, 1
packusdw xm0, xm1 ; clip
psrlw xm0, 6
mova [dstq+r10], xm0
add r10, 16
jl .n0_loop
add dstq, dst_strideq
ret
ALIGN function_align
.n1: ; neighbor + output (odd rows)
mov r10, wq
.n1_loop:
mova xm3, [t4+r10*1+400*4+0]
paddw xm3, [t4+r10*1+400*4+4]
paddw xm5, xm3, [t4+r10*1+400*4+2]
psllw xm5, 2 ; a3[ 1] 444
psubw xm4, xm5, xm3 ; a3[ 1] 343
paddw xm3, xm4, [t4+r10*1+400*12]
paddw xm3, [t4+r10*1+400*10]
mova [t4+r10*1+400*10], xm5
mova [t4+r10*1+400*12], xm4
mova m1, [t3+r10*2+400*8+0]
paddd m1, [t3+r10*2+400*8+8]
paddd m5, m1, [t3+r10*2+400*8+4]
pslld m5, 2 ; b3[ 1] 444
psubd m4, m5, m1 ; b3[ 1] 343
paddd m1, m4, [t3+r10*2+400*24]
paddd m1, [t3+r10*2+400*20]
mova [t3+r10*2+400*20], m5
mova [t3+r10*2+400*24], m4
pmovzxwd m4, [dstq+r10]
pmovzxwd m0, [t4+r10*1+400* 6]
pmovzxwd m3, xm3
pmaddwd m0, m4 ; a5 * src
pmaddwd m3, m4 ; a3 * src
pslld m4, 12
psubd m2, m4, [t3+r10*2+400*12]
paddd m4, m4
psubd m1, m4
psubd m0, m2 ; a5 * src + b5 + (1 << 8) - (src << 13)
paddd m1, m3 ; a3 * src + b3 + (1 << 8) - (src << 13)
psrld m0, 8
pslld m1, 7
pblendw m0, m1, 0xaa
pmaddwd m0, m15
vpbroadcastd m1, [pd_4096]
paddd m4, m1
paddd m0, m4
psrad m0, 7
vextracti128 xm1, m0, 1
packusdw xm0, xm1 ; clip
psrlw xm0, 6
mova [dstq+r10], xm0
add r10, 16
jl .n1_loop
add dstq, dst_strideq
ret
%endif ; ARCH_X86_64
|
; A158481: 49n^2 + 7.
; 56,203,448,791,1232,1771,2408,3143,3976,4907,5936,7063,8288,9611,11032,12551,14168,15883,17696,19607,21616,23723,25928,28231,30632,33131,35728,38423,41216,44107,47096,50183,53368,56651,60032,63511,67088,70763,74536,78407,82376,86443,90608,94871,99232,103691,108248,112903,117656,122507,127456,132503,137648,142891,148232,153671,159208,164843,170576,176407,182336,188363,194488,200711,207032,213451,219968,226583,233296,240107,247016,254023,261128,268331,275632,283031,290528,298123,305816,313607,321496,329483,337568,345751,354032,362411,370888,379463,388136,396907,405776,414743,423808,432971,442232,451591,461048,470603,480256,490007,499856,509803,519848,529991,540232,550571,561008,571543,582176,592907,603736,614663,625688,636811,648032,659351,670768,682283,693896,705607,717416,729323,741328,753431,765632,777931,790328,802823,815416,828107,840896,853783,866768,879851,893032,906311,919688,933163,946736,960407,974176,988043,1002008,1016071,1030232,1044491,1058848,1073303,1087856,1102507,1117256,1132103,1147048,1162091,1177232,1192471,1207808,1223243,1238776,1254407,1270136,1285963,1301888,1317911,1334032,1350251,1366568,1382983,1399496,1416107,1432816,1449623,1466528,1483531,1500632,1517831,1535128,1552523,1570016,1587607,1605296,1623083,1640968,1658951,1677032,1695211,1713488,1731863,1750336,1768907,1787576,1806343,1825208,1844171,1863232,1882391,1901648,1921003,1940456,1960007,1979656,1999403,2019248,2039191,2059232,2079371,2099608,2119943,2140376,2160907,2181536,2202263,2223088,2244011,2265032,2286151,2307368,2328683,2350096,2371607,2393216,2414923,2436728,2458631,2480632,2502731,2524928,2547223,2569616,2592107,2614696,2637383,2660168,2683051,2706032,2729111,2752288,2775563,2798936,2822407,2845976,2869643,2893408,2917271,2941232,2965291,2989448,3013703,3038056,3062507
mov $1,2
add $1,$0
mul $1,$0
mul $1,49
add $1,56
|
#include <jni.h>
#include <android/log.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <Eigen/Geometry>
#include <g2o/core/hyper_graph_action.h>
#include <g2o/core/sparse_optimizer.h>
#include <g2o/core/base_binary_edge.h>
#include <g2o/types/slam3d/vertex_se3.h>
#include <g2o/types/slam3d/parameter_se3_offset.h>
#include <g2o/core/block_solver.h>
#include <g2o/core/optimization_algorithm_levenberg.h>
#include <g2o/solvers/pcg/linear_solver_pcg.h>
#include <g2o/core/hyper_dijkstra.h>
using namespace std;
#define LOG_TAG "G2O"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
/**
* Stop iterating based on the gain which is (oldChi - currentChi) / currentChi.
*
* If the gain is larger than zero and below the threshold, then the optimizer is stopped.
* Typically usage of this action includes adding it as a postIteration action, by calling
* addPostIterationAction on a sparse optimizer.
*/
class ConvergenceCheckAction : public g2o::HyperGraphAction
{
public:
ConvergenceCheckAction(g2o::SparseOptimizer* opt, double error_th = 1e-8)
: m_optimizer(opt), m_gain_th(error_th), m_last_chi2(0.), m_stop_flag(false)
{}
void reset(g2o::SparseOptimizer* opt = NULL, double error_th = -1.)
{
if(opt != NULL)
m_optimizer = opt;
if(error_th >= 0)
m_gain_th = error_th;
m_last_chi2 = 0.;
m_stop_flag = false;
}
virtual g2o::HyperGraphAction* operator()(const g2o::HyperGraph* graph, g2o::HyperGraphAction::Parameters* = 0)
{
m_optimizer->computeActiveErrors();
const double current_chi2 = m_optimizer->activeChi2();
const double gain = m_last_chi2/current_chi2 - 1.0;
if((gain >= 0 && gain < m_gain_th) || current_chi2 == 0.0)
{
// tell the optimizer to stop
if(m_optimizer->forceStopFlag() != NULL)
*(m_optimizer->forceStopFlag()) = true;
else
{
m_stop_flag = true;
m_optimizer->setForceStopFlag(&m_stop_flag);
}
}
m_last_chi2 = current_chi2;
return this;
}
private:
g2o::SparseOptimizer* m_optimizer;
double m_gain_th, m_last_chi2;
bool m_stop_flag;
};
/** col-0 = point-0; col-1 = point-1 */
typedef Eigen::Matrix<double,3,2> XYZPairMeasurement;
class EdgeSE3XYZPair : public g2o::BaseBinaryEdge<3, XYZPairMeasurement, g2o::VertexSE3, g2o::VertexSE3>
{
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
EdgeSE3XYZPair()
: offset0_(NULL), offset1_(NULL), cache0_(NULL), cache1_(NULL), weight_(1)
{
jac_buffer_.setZero();
resizeParameters(2);
installParameter(offset0_, 0);
installParameter(offset1_, 1);
}
inline void setWeight(double w)
{
weight_ = w;
}
inline void setPointPointMetric()
{
plane_plane_metric_ = false;
_information.setIdentity();
}
inline void setPointPlaneMetric(const Eigen::Vector3d& normal0, double e = 1e-3)
{
plane_plane_metric_ = false;
Eigen::Matrix3d info;
info << e, 0, 0,
0, e, 0,
0, 0, 1;
Eigen::Matrix3d rot0 = computeRotation(normal0);
_information = rot0.transpose()*info*rot0;
}
inline void setPlanePlaneMetric(const Eigen::Vector3d& normal0, const Eigen::Vector3d& normal1, double e = 1e-3)
{
plane_plane_metric_ = true;
Eigen::Matrix3d info;
info << 1, 0, 0,
0, 1, 0,
0, 0, e;
Eigen::Matrix3d rot = computeRotation(normal0);
cov0_ = rot.transpose()*info*rot;
rot = computeRotation(normal1);
cov1_ = rot.transpose()*info*rot;
}
double weight() const
{
return weight_;
}
const Eigen::Matrix3d& cov0() const
{
return cov0_;
}
const Eigen::Matrix3d& cov1() const
{
return cov1_;
}
//TODO meglio spostare poi il tutto in un altro file!
virtual bool read(std::istream& is)
{
int pid0, pid1;
is >> pid0 >> pid1;
if(!setParameterId(0, pid0))
return false;
if(!setParameterId(1, pid1))
return false;
if(!is.good())
return false;
is >> _measurement(0,0) >> _measurement(1,0) >> _measurement(2,0)
>> _measurement(0,1) >> _measurement(1,1) >> _measurement(2,1);
if(!is.good())
return false;
for (unsigned i = 0; i < 3; ++i)
for (unsigned j = 0; j < 3; ++j)
is >> _information(i,j);
if(!is.good())
return false;
int plpl;
is >> weight_ >> plpl;
plane_plane_metric_ = (plpl == 1 ? true : false);
if(!is.good())
return false;
for (unsigned i = 0; i < 3; ++i)
for (unsigned j = 0; j < 3; ++j)
is >> cov0_(i,j);
if(!is.good())
return false;
for (unsigned i = 0; i < 3; ++i)
for (unsigned j = 0; j < 3; ++j)
is >> cov1_(i,j);
return true;
}
virtual bool write(std::ostream& os) const
{
os << offset0_->id() << " " << offset1_->id() << " ";
os << _measurement(0,0) << " " << _measurement(1,0) << " " << _measurement(2,0) << " "
<< _measurement(0,1) << " " << _measurement(1,1) << " " << _measurement(2,1) << " ";
for (unsigned i = 0; i < 3; ++i)
for (unsigned j = 0; j < 3; ++j)
os << _information(i,j) << " ";
os << weight_ << " " << (plane_plane_metric_ ? 1 : 0) << " ";
for (unsigned i = 0; i < 3; ++i)
for (unsigned j = 0; j < 3; ++j)
os << cov0_(i,j) << " ";
for (unsigned i = 0; i < 3; ++i)
for (unsigned j = 0; j < 3; ++j)
os << cov1_(i,j) << " ";
return os.good();
}
virtual void computeError()
{
if(plane_plane_metric_)
{
const Eigen::Isometry3d n2n = cache0_->w2n() * cache1_->n2w();
_error = weight_ * ((n2n * _measurement.col(1)) - _measurement.col(0));
_information = (cov0_ + n2n.rotation() * cov1_ * n2n.rotation().transpose()).inverse();
}
else
_error = weight_ * ((cache0_->w2n() * (cache1_->n2w() * _measurement.col(1))) - _measurement.col(0));
}
virtual bool setMeasurementData(const double* d)
{
_measurement = Eigen::Map<const XYZPairMeasurement>(d);
return true;
}
virtual bool getMeasurementData(double* d) const
{
Eigen::Map<XYZPairMeasurement> v(d);
v = _measurement;
return true;
}
virtual void linearizeOplus()
{
const g2o::VertexSE3* vp0 = static_cast<const g2o::VertexSE3*>(_vertices[0]);
const g2o::VertexSE3* vp1 = static_cast<const g2o::VertexSE3*>(_vertices[1]);
if (!vp0->fixed())
{
const Eigen::Vector3d p1t = cache0_->w2l() * (cache1_->n2w() * _measurement.col(1));
jac_buffer_(1,0) = 2.0*p1t[2];
jac_buffer_(2,0) = -2.0*p1t[1];
jac_buffer_(0,1) = -2.0*p1t[2];
jac_buffer_(2,1) = 2.0*p1t[0];
jac_buffer_(0,2) = 2.0*p1t[1];
jac_buffer_(1,2) = -2.0*p1t[0];
_jacobianOplusXi.block<3,3>(0,0) = -1. * offset0_->inverseOffset().rotation();
_jacobianOplusXi.block<3,3>(0,3) = offset0_->inverseOffset().rotation() * jac_buffer_;
}
if (!vp1->fixed())
{
const Eigen::Vector3d p1o = offset1_->offset() * _measurement.col(1);
jac_buffer_(1,0) = -2.0*p1o[2];
jac_buffer_(2,0) = 2.0*p1o[1];
jac_buffer_(0,1) = 2.0*p1o[2];
jac_buffer_(2,1) = -2.0*p1o[0];
jac_buffer_(0,2) = -2.0*p1o[1];
jac_buffer_(1,2) = 2.0*p1o[0];
_jacobianOplusXj.block<3,3>(0,0) = cache0_->w2n().rotation() * vp1->estimate().rotation();
_jacobianOplusXj.block<3,3>(0,3) = _jacobianOplusXj.block<3,3>(0,0) * jac_buffer_;
}
}
virtual int measurementDimension() const
{
return 6;
}
private:
inline Eigen::Matrix3d computeRotation(const Eigen::Vector3d& normal) const
{
Eigen::Matrix3d rot;
rot.row(2) = normal;
rot.row(1) = (Eigen::Vector3d::UnitY() - normal(1)*normal).normalized();
rot.row(0) = normal.cross(rot.row(1));
return rot;
}
virtual bool resolveCaches()
{
assert(offset0_ && offset1_);
g2o::ParameterVector pv(2);
pv[0] = offset0_;
resolveCache(cache0_, (g2o::OptimizableGraph::Vertex*)_vertices[0], "CACHE_SE3_OFFSET", pv);
pv[1] = offset1_;
resolveCache(cache1_, (g2o::OptimizableGraph::Vertex*)_vertices[1], "CACHE_SE3_OFFSET", pv);
return (cache0_ && cache1_);
}
g2o::ParameterSE3Offset *offset0_, *offset1_;
g2o::CacheSE3Offset *cache0_, *cache1_;
double weight_;
bool plane_plane_metric_;
Eigen::Matrix3d cov0_, cov1_;
Eigen::Matrix3d jac_buffer_;
};
extern "C"
{
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_initNativeGraph(JNIEnv *env, jobject obj);
JNIEXPORT jdouble JNICALL Java_it_unibo_slam_graph_GraphBackend_getChi2Native(JNIEnv *env, jobject obj);
JNIEXPORT jdouble JNICALL Java_it_unibo_slam_graph_GraphBackend_getWeightedMeanChi2Native(JNIEnv *env, jobject obj);
JNIEXPORT jint JNICALL Java_it_unibo_slam_graph_GraphBackend_getNumberOfEdgesNative(JNIEnv *env, jobject obj);
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_clearNative(JNIEnv *env, jobject obj);
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_setFixedViewNative(JNIEnv *env, jobject obj,
jint viewId, jboolean fixed);
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_addVertexWithEstimateNative(JNIEnv *env, jobject obj,
jint poseId, jdoubleArray estimate);
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_setVertexEstimateNative(JNIEnv *env, jobject obj,
jint poseId, jdoubleArray estimate);
JNIEXPORT jdoubleArray JNICALL Java_it_unibo_slam_graph_GraphBackend_getVertexEstimateNative(JNIEnv *env, jobject obj,
jint poseId);
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_removeVertexNative(JNIEnv *env, jobject obj,
jint poseId);
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_addEdgeNative(JNIEnv *env, jobject obj,
jint referenceId, jint matchingId, jdoubleArray referenceVx, jdoubleArray matchingVx, jdouble score);
JNIEXPORT jint JNICALL Java_it_unibo_slam_graph_GraphBackend_optimizeNative(JNIEnv *env, jobject obj,
jint maximumNumberOfIterations);
JNIEXPORT jint JNICALL Java_it_unibo_slam_graph_GraphBackend_relativeOptimizeNative(JNIEnv *env, jobject obj,
jintArray vSet, jint size, jint maximumNumberOfIterations);
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_createRBASubsetNative(JNIEnv *env, jobject obj,
jint originId, jint ring, jobject vSet, jobject fSet);
}
// Global variables accessible only within this source file
namespace
{
g2o::SparseOptimizer optimizer;
ConvergenceCheckAction action = ConvergenceCheckAction(&optimizer, 1E-10);
double edgeWeights = 0.0;
}
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_initNativeGraph(JNIEnv *env, jobject obj)
{
action = ConvergenceCheckAction(&optimizer, 1E-10);
edgeWeights = 0.0;
typedef g2o::BlockSolver< g2o::BlockSolverTraits<6, 0> > BlockSolver_6_0;
BlockSolver_6_0::LinearSolverType* linearSolver = new g2o::LinearSolverPCG<BlockSolver_6_0::PoseMatrixType>();
BlockSolver_6_0* solverPointer = new BlockSolver_6_0(linearSolver);
g2o::OptimizationAlgorithmLevenberg* optimizationAlgorithm = new g2o::OptimizationAlgorithmLevenberg(solverPointer);
// Set the algorithm and the termination action
optimizer.setAlgorithm(optimizationAlgorithm);
optimizer.addPostIterationAction(&action);
g2o::ParameterSE3Offset* offset = new g2o::ParameterSE3Offset();
offset->setId(0);
optimizer.addParameter(offset);
}
JNIEXPORT jdouble JNICALL Java_it_unibo_slam_graph_GraphBackend_getChi2Native(JNIEnv *env, jobject obj)
{
return optimizer.activeChi2();
}
JNIEXPORT jdouble JNICALL Java_it_unibo_slam_graph_GraphBackend_getWeightedMeanChi2Native(JNIEnv *env, jobject obj)
{
assert(edgeWeights > 0);
return optimizer.activeChi2() / edgeWeights;
}
JNIEXPORT jint JNICALL Java_it_unibo_slam_graph_GraphBackend_getNumberOfEdgesNative(JNIEnv *env, jobject obj)
{
return optimizer.edges().size();
}
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_clearNative(JNIEnv *env, jobject obj)
{
optimizer.clear();
edgeWeights = 0.0;
}
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_setFixedViewNative(JNIEnv *env, jobject obj,
jint viewId, jboolean fixed)
{
g2o::SparseOptimizer::Vertex* v = optimizer.vertex(viewId);
if (v != NULL)
v->setFixed(fixed);
}
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_addVertexWithEstimateNative(JNIEnv *env, jobject obj,
jint poseId, jdoubleArray estimate)
{
double tempEstimate[16];
env->GetDoubleArrayRegion(estimate, 0, 16, tempEstimate);
Eigen::Isometry3d estimateEigen(Eigen::Matrix4d::Map(tempEstimate));
g2o::VertexSE3* vx = new g2o::VertexSE3();
vx->setId(poseId);
vx->setEstimate(estimateEigen);
optimizer.addVertex(vx);
}
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_setVertexEstimateNative(JNIEnv *env, jobject obj,
jint poseId, jdoubleArray estimate)
{
double tempEstimate[16];
env->GetDoubleArrayRegion(estimate, 0, 16, tempEstimate);
Eigen::Isometry3d estimateEigen(Eigen::Matrix4d::Map(tempEstimate));
static_cast<g2o::VertexSE3*>(optimizer.vertex(poseId))->setEstimate(estimateEigen);
}
JNIEXPORT jdoubleArray JNICALL Java_it_unibo_slam_graph_GraphBackend_getVertexEstimateNative(JNIEnv *env, jobject obj,
jint poseId)
{
jdoubleArray vertexEstimateArray;
vertexEstimateArray = env->NewDoubleArray(16);
double *tempVertexEstimateArray;
Eigen::Isometry3d vertexEstimate = static_cast<g2o::VertexSE3*>(optimizer.vertex(poseId))->estimate();
tempVertexEstimateArray = vertexEstimate.data();
env->SetDoubleArrayRegion(vertexEstimateArray, 0, 16, tempVertexEstimateArray);
return vertexEstimateArray;
}
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_removeVertexNative(JNIEnv *env, jobject obj,
jint poseId)
{
g2o::SparseOptimizer::Vertex* vx = optimizer.vertex(poseId);
for(g2o::HyperGraph::EdgeSet::const_iterator it = vx->edges().begin(); it != vx->edges().end(); ++it)
edgeWeights -= static_cast<const EdgeSE3XYZPair*>(*it)->weight();
optimizer.removeVertex(vx);
}
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_addEdgeNative(JNIEnv *env, jobject obj,
jint referenceId, jint matchingId, jdoubleArray referenceVx, jdoubleArray matchingVx, jdouble score)
{
double tempReferenceVx[3];
double tempMatchingVx[3];
env->GetDoubleArrayRegion(referenceVx, 0, 3, tempReferenceVx);
env->GetDoubleArrayRegion(matchingVx, 0, 3, tempMatchingVx);
Eigen::Vector3d referenceVxEigen(tempReferenceVx[0], tempReferenceVx[1], tempReferenceVx[2]);
Eigen::Vector3d matchingVxEigen(tempMatchingVx[0], tempMatchingVx[1], tempMatchingVx[2]);
g2o::SparseOptimizer::Vertex* referenceVertex = optimizer.vertex(referenceId);
g2o::SparseOptimizer::Vertex* matchingVertex = optimizer.vertex(matchingId);
EdgeSE3XYZPair* edge = new EdgeSE3XYZPair();
edge->setParameterId(0, 0);
edge->setParameterId(1, 0);
edge->vertices()[0] = referenceVertex;
edge->vertices()[1] = matchingVertex;
XYZPairMeasurement measurement;
measurement.col(0) = referenceVxEigen;
measurement.col(1) = matchingVxEigen;
edge->setMeasurement(measurement);
if (score > 0)
edge->setWeight(score);
edge->setPointPointMetric();
optimizer.addEdge(edge);
edgeWeights += edge->weight();
}
JNIEXPORT jint JNICALL Java_it_unibo_slam_graph_GraphBackend_optimizeNative(JNIEnv *env, jobject obj,
jint maximumNumberOfIterations)
{
action.reset();
optimizer.initializeOptimization(-1);
return optimizer.optimize(maximumNumberOfIterations);
}
JNIEXPORT jint JNICALL Java_it_unibo_slam_graph_GraphBackend_relativeOptimizeNative(JNIEnv *env, jobject obj,
jintArray vSet, jint size, jint maximumNumberOfIterations)
{
int vSetArray[size];
env->GetIntArrayRegion(vSet, 0, size, vSetArray);
g2o::HyperGraph::VertexSet vSetG2O;
for (int i = 0; i < size; i++)
vSetG2O.insert(optimizer.vertex(vSetArray[i]));
action.reset();
optimizer.initializeOptimization(vSetG2O, -1);
return optimizer.optimize(maximumNumberOfIterations);
}
JNIEXPORT void JNICALL Java_it_unibo_slam_graph_GraphBackend_createRBASubsetNative(JNIEnv *env, jobject obj,
jint originId, jint ring, jobject vSet, jobject fSet)
{
//TODO verificare se i metodi sono corretti
jclass vSetClass = env->GetObjectClass(vSet);
jmethodID vSetMethod = env->GetMethodID(vSetClass, "add", "(Ljava/lang/Object;)Z");
if (vSetMethod == 0)
{
LOGE("VSET METHOD NOT FOUND");
return;
}
jclass fSetClass = env->GetObjectClass(fSet);
jmethodID fSetMethod = env->GetMethodID(fSetClass, "add", "(Ljava/lang/Object;)Z");
if (fSetMethod == 0)
{
LOGE("FSET METHOD NOT FOUND");
return;
}
g2o::HyperGraph::Vertex* origin = optimizer.vertex(originId);
g2o::HyperGraph::VertexSet vSetG2O;
g2o::HyperGraph::VertexSet fSetG2O;
vSetG2O.insert(origin);
g2o::HyperGraph::VertexSet localSets[2];
localSets[0] = vSetG2O;
g2o::HyperGraph::VertexSet* lastRing = &localSets[0];
g2o::HyperGraph::VertexSet* nextRing = &localSets[1];
for (unsigned cr = 0; cr <= ring; ++cr)
{
for (g2o::HyperGraph::VertexSet::const_iterator vit = lastRing->begin(); vit != lastRing->end(); ++vit)
{
// Collect next ring
for (g2o::HyperGraph::EdgeSet::iterator eit = (*vit)->edges().begin(); eit != (*vit)->edges().end(); ++eit)
{
for (unsigned i = 0; i < (*eit)->vertices().size(); ++i)
{
g2o::HyperGraph::Vertex* vi = (*eit)->vertex(i);
if (!vSetG2O.count(vi))
{
if (cr == ring)
{
vSetG2O.insert(vi);
fSetG2O.insert(vi);
static_cast<g2o::SparseOptimizer::Vertex*>(vi)->setFixed(true);
}
else
nextRing->insert(vi);
}
} // For every vx attached to the periphery
} // For every peripheral edge
} // For every peripheral vx
if (nextRing->empty())
break;
vSetG2O.insert(nextRing->begin(), nextRing->end());
std::swap(lastRing, nextRing);
nextRing->clear();
} // For every ring
jclass integerClass = env->FindClass("java/lang/Integer");
jmethodID integerInitMethod = env->GetMethodID(integerClass, "<init>", "(I)V");
//TODO verificare funzionamento - passaggio da int a Integer
for (g2o::HyperGraph::VertexSet::const_iterator vit = vSetG2O.begin(); vit != vSetG2O.end(); ++vit)
env->CallBooleanMethod(vSet, vSetMethod, env->NewObject(integerClass, integerInitMethod, (*vit)->id()));
for (g2o::HyperGraph::VertexSet::const_iterator fit = fSetG2O.begin(); fit != fSetG2O.end(); ++fit)
env->CallBooleanMethod(fSet, fSetMethod, env->NewObject(integerClass, integerInitMethod, (*fit)->id()));
}
extern "C"
{
JNIEXPORT void JNICALL Java_it_unibo_slam_main_SlamDunk_initDijkstraNative(JNIEnv *env, jobject obj);
JNIEXPORT jboolean JNICALL Java_it_unibo_slam_main_SlamDunk_loopClosureCheck(JNIEnv *env, jobject obj,
jintArray trackedKeyframes, jint size, jint rbaRings);
JNIEXPORT void JNICALL Java_it_unibo_slam_main_SlamDunk_updateAdjacencyMap(JNIEnv *env, jobject obj,
jint id);
}
g2o::HyperDijkstra dijkstra = g2o::HyperDijkstra(&optimizer);
JNIEXPORT void JNICALL Java_it_unibo_slam_main_SlamDunk_initDijkstraNative(JNIEnv *env, jobject obj)
{
dijkstra = g2o::HyperDijkstra(&optimizer);
}
JNIEXPORT jboolean JNICALL Java_it_unibo_slam_main_SlamDunk_loopClosureCheck(JNIEnv *env, jobject obj,
jintArray trackedKeyframes, jint size, jint rbaRings)
{
int trackedKeyframesArray[size];
env->GetIntArrayRegion(trackedKeyframes, 0, size, trackedKeyframesArray);
std::vector<g2o::HyperGraph::Vertex*> trackedVertices(size);
for (unsigned k = 0; k < trackedVertices.size(); k++)
trackedVertices[k] = optimizer.vertex(trackedKeyframesArray[k]);
g2o::UniformCostFunction edgeCost;
bool isKeyframe = false;
for (unsigned k = 0; k < trackedVertices.size() && !isKeyframe; ++k)
{
g2o::HyperGraph::Vertex* vx = trackedVertices[k];
dijkstra.shortestPaths(vx, &edgeCost, rbaRings);
const g2o::HyperGraph::VertexSet& visited = dijkstra.visited();
for (unsigned k2 = k; k2 < trackedVertices.size() && !isKeyframe; ++k2)
isKeyframe = (visited.count(trackedVertices[k2]) == 0);
}
return isKeyframe;
}
JNIEXPORT void JNICALL Java_it_unibo_slam_main_SlamDunk_updateAdjacencyMap(JNIEnv *env, jobject obj,
jint id)
{
g2o::HyperGraph::Vertex* vx = optimizer.vertex(id);
g2o::HyperDijkstra::AdjacencyMapEntry entry(vx, 0, 0, std::numeric_limits< double >::max());
dijkstra.adjacencyMap().insert(std::make_pair(entry.child(), entry));
}
|
%ifdef CONFIG
{
"RegData": {
"RAX": "0x1",
"RBX": "0x0"
},
"MemoryRegions": {
"0x100000000": "4096"
}
}
%endif
mov r15, 0xe0000000
mov r10, 0x1
mov r11, 0x0
mov r12, 0x2
cmp r10d, r12d
mov rax, 0
mov rbx, 0
jle .tgt_1
jnle .tgt_2
jmp .end
.tgt_1:
mov rax, 1
jmp .end
.tgt_2:
mov rbx, 1
jmp .end
.end:
hlt
|
/*
Copyright 2020 VMware, Inc.
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 "eliminateSwitch.h"
#include "frontends/p4/coreLibrary.h"
namespace P4 {
const IR::Node* DoEliminateSwitch::postorder(IR::P4Control* control) {
for (auto a : toInsert)
control->controlLocals.push_back(a);
toInsert.clear();
return control;
}
const IR::Node* DoEliminateSwitch::postorder(IR::SwitchStatement* statement) {
auto type = typeMap->getType(statement->expression);
if (type->is<IR::Type_ActionEnum>())
// Classic switch; no changes needed
return statement;
auto src = statement->srcInfo;
IR::IndexedVector<IR::StatOrDecl> contents;
cstring prefix = refMap->newName("switch");
// Compute key for new switch statement
cstring key = refMap->newName(prefix + "_key");
auto decl = new IR::Declaration_Variable(key, type->getP4Type());
toInsert.push_back(decl);
auto assign = new IR::AssignmentStatement(
src, new IR::PathExpression(key), statement->expression);
contents.push_back(assign);
auto hidden = new IR::Annotations();
hidden->add(new IR::Annotation(IR::Annotation::hiddenAnnotation, {}));
auto tableKeyEl = new IR::KeyElement(
src, new IR::PathExpression(key),
new IR::PathExpression(P4CoreLibrary::instance.exactMatch.Id()));
IR::IndexedVector<IR::ActionListElement> actionsList;
IR::IndexedVector<IR::Property> properties;
IR::Vector<IR::SwitchCase> cases;
IR::Vector<IR::Entry> entries;
properties.push_back(new IR::Property(src, "key", new IR::Key({tableKeyEl}), false));
IR::ID defaultAction = P4CoreLibrary::instance.noAction.Id();
// Add Default switch Expression if not present
bool isDefaultPresent = false;
for (auto sc : statement->cases) {
if (sc->label->is<IR::DefaultExpression>()) {
isDefaultPresent = true;
break;
}
}
if (!isDefaultPresent) {
statement->cases.push_back(
new IR::SwitchCase(new IR::DefaultExpression(IR::Type_Dontcare::get()),
new IR::BlockStatement));
}
// Create actions
IR::Vector<IR::Expression> pendingLabels; // switch labels with no statement
for (auto sc : statement->cases) {
auto scSrc = sc->srcInfo;
pendingLabels.push_back(sc->label);
if (sc->statement != nullptr) {
cstring actionName = refMap->newName(prefix + "_case");
auto action = new IR::P4Action(
src, actionName, hidden, new IR::ParameterList(),
new IR::BlockStatement());
auto actionCall = new IR::MethodCallExpression(
scSrc, new IR::PathExpression(actionName));
toInsert.push_back(action);
auto ale = new IR::ActionListElement(scSrc, actionCall);
actionsList.push_back(ale);
auto c = new IR::SwitchCase(scSrc, new IR::PathExpression(actionName), sc->statement);
cases.push_back(c);
if (sc->label->is<IR::DefaultExpression>()) {
defaultAction = IR::ID(actionName);
}
for (auto lab : pendingLabels) {
if (!lab->is<IR::DefaultExpression>()) {
auto entry = new IR::Entry(scSrc, new IR::ListExpression({lab}), actionCall);
entries.push_back(entry);
}
}
pendingLabels.clear();
}
}
properties.push_back(new IR::Property(src, "actions", new IR::ActionList(actionsList), false));
properties.push_back(new IR::Property(
src, "default_action", new IR::ExpressionValue(
src, new IR::MethodCallExpression(new IR::PathExpression(defaultAction))), true));
properties.push_back(new IR::Property(src, "entries", new IR::EntriesList(entries), true));
cstring tableName = refMap->newName(prefix + "_table");
auto table = new IR::P4Table(src, tableName, hidden, new IR::TableProperties(properties));
toInsert.push_back(table);
auto apply = new IR::Member(
src,
new IR::MethodCallExpression(
src, new IR::Member(src, new IR::PathExpression(tableName),
IR::IApply::applyMethodName)),
IR::Type_Table::action_run);
auto stat = new IR::SwitchStatement(src, apply, cases);
contents.push_back(stat);
return new IR::BlockStatement(src, contents);
}
} // namespace P4
|
object_const_def ; object_event constants
const ROUTE30_YOUNGSTER1
const ROUTE30_YOUNGSTER2
const ROUTE30_YOUNGSTER3
const ROUTE30_BUG_CATCHER
const ROUTE30_YOUNGSTER4
const ROUTE30_MONSTER1
const ROUTE30_MONSTER2
const ROUTE30_FRUIT_TREE1
const ROUTE30_FRUIT_TREE2
const ROUTE30_COOLTRAINER_F
const ROUTE30_POKE_BALL
Route30_MapScripts:
db 0 ; scene scripts
db 0 ; callbacks
YoungsterJoey_ImportantBattleScript:
waitsfx
playmusic MUSIC_JOHTO_TRAINER_BATTLE
opentext
writetext Text_UseTackle
pause 30
closetext
playsound SFX_TACKLE
applymovement ROUTE30_MONSTER2, Route30_JoeysRattataAttacksMovement
opentext
faceplayer
writetext Text_ThisIsABigBattle
waitbutton
turnobject ROUTE30_YOUNGSTER1, UP
closetext
playsound SFX_TACKLE
applymovement ROUTE30_MONSTER1, Route30_MikeysRattataAttacksMovement
special RestartMapMusic
end
TrainerYoungsterJoey:
trainer YOUNGSTER, JOEY1, EVENT_BEAT_YOUNGSTER_JOEY, YoungsterJoey1SeenText, YoungsterJoey1BeatenText, 0, .Script
.Script:
loadvar VAR_CALLERID, PHONE_YOUNGSTER_JOEY
endifjustbattled
opentext
checkflag ENGINE_JOEY
iftrue .Rematch
checkcellnum PHONE_YOUNGSTER_JOEY
iftrue .NumberAccepted
checkevent EVENT_JOEY_ASKED_FOR_PHONE_NUMBER
iftrue .AskAgain
writetext YoungsterJoey1AfterText
buttonsound
setevent EVENT_JOEY_ASKED_FOR_PHONE_NUMBER
scall .AskNumber1
sjump .RequestNumber
.AskAgain:
scall .AskNumber2
.RequestNumber:
askforphonenumber PHONE_YOUNGSTER_JOEY
ifequal PHONE_CONTACTS_FULL, .PhoneFull
ifequal PHONE_CONTACT_REFUSED, .NumberDeclined
gettrainername STRING_BUFFER_3, YOUNGSTER, JOEY1
scall .RegisteredNumber
sjump .NumberAccepted
.Rematch:
scall .RematchStd
winlosstext YoungsterJoey1BeatenText, 0
readmem wJoeyFightCount
ifequal 4, .Fight4
ifequal 3, .Fight3
ifequal 2, .Fight2
ifequal 1, .Fight1
ifequal 0, .LoadFight0
.Fight4:
checkevent EVENT_BEAT_ELITE_FOUR
iftrue .LoadFight4
.Fight3:
; checkevent EVENT_CLEARED_RADIO_TOWER
; iftrue .LoadFight3
.Fight2:
checkflag ENGINE_FLYPOINT_OLIVINE
iftrue .LoadFight2
.Fight1:
checkflag ENGINE_FLYPOINT_GOLDENROD
iftrue .LoadFight1
.LoadFight0:
loadtrainer YOUNGSTER, JOEY1
startbattle
reloadmapafterbattle
loadmem wJoeyFightCount, 1
clearflag ENGINE_JOEY
end
.LoadFight1:
loadtrainer YOUNGSTER, JOEY2
startbattle
reloadmapafterbattle
loadmem wJoeyFightCount, 2
clearflag ENGINE_JOEY
end
.LoadFight2:
loadtrainer YOUNGSTER, JOEY3
startbattle
reloadmapafterbattle
loadmem wJoeyFightCount, 3
clearflag ENGINE_JOEY
end
.LoadFight3:
loadtrainer YOUNGSTER, JOEY4
startbattle
reloadmapafterbattle
loadmem wJoeyFightCount, 4
clearflag ENGINE_JOEY
end
.LoadFight4:
loadtrainer YOUNGSTER, JOEY5
startbattle
reloadmapafterbattle
clearflag ENGINE_JOEY
checkevent EVENT_JOEY_HP_UP
iftrue .GiveHPUp
checkevent EVENT_GOT_HP_UP_FROM_JOEY
iftrue .done
scall .RematchGift
verbosegiveitem HP_UP
iffalse .PackFull
setevent EVENT_GOT_HP_UP_FROM_JOEY
sjump .NumberAccepted
.done
end
.GiveHPUp:
opentext
writetext YoungsterJoeyText_GiveHPUpAfterBattle
waitbutton
verbosegiveitem HP_UP
iffalse .PackFull
clearevent EVENT_JOEY_HP_UP
setevent EVENT_GOT_HP_UP_FROM_JOEY
sjump .NumberAccepted
.AskNumber1:
jumpstd asknumber1m
end
.AskNumber2:
jumpstd asknumber2m
end
.RegisteredNumber:
jumpstd registerednumberm
end
.NumberAccepted:
jumpstd numberacceptedm
end
.NumberDeclined:
jumpstd numberdeclinedm
end
.PhoneFull:
jumpstd phonefullm
end
.RematchStd:
jumpstd rematchm
end
.PackFull:
setevent EVENT_JOEY_HP_UP
jumpstd packfullm
end
.RematchGift:
jumpstd rematchgiftm
end
TrainerYoungsterMikey:
trainer YOUNGSTER, MIKEY, EVENT_BEAT_YOUNGSTER_MIKEY, YoungsterMikeySeenText, YoungsterMikeyBeatenText, 0, .Script
.Script:
endifjustbattled
opentext
writetext YoungsterMikeyAfterText
waitbutton
closetext
end
TrainerBugCatcherDon:
trainer BUG_CATCHER, DON, EVENT_BEAT_BUG_CATCHER_DON, BugCatcherDonSeenText, BugCatcherDonBeatenText, 0, .Script
.Script:
endifjustbattled
opentext
writetext BugCatcherDonAfterText
waitbutton
closetext
end
Route30YoungsterScript:
faceplayer
opentext
; checkevent EVENT_GAVE_MYSTERY_EGG_TO_ELM
; iftrue .CompletedEggQuest
writetext Route30YoungsterText_DirectionsToMrPokemonsHouse
waitbutton
closetext
end
.CompletedEggQuest:
writetext Route30YoungsterText_EveryoneIsBattling
waitbutton
closetext
end
Route30CooltrainerFScript:
jumptextfaceplayer Route30CooltrainerFText
Route30Sign:
jumptext Route30SignText
MrPokemonsHouseDirectionsSign:
jumptext MrPokemonsHouseDirectionsSignText
MrPokemonsHouseSign:
jumptext MrPokemonsHouseSignText
Route30TrainerTips:
jumptext Route30TrainerTipsText
Route30Antidote:
itemball ANTIDOTE
Route30FruitTree1:
fruittree FRUITTREE_ROUTE_30_1
Route30FruitTree2:
fruittree FRUITTREE_ROUTE_30_2
Route30HiddenPotion:
hiddenitem POTION, EVENT_ROUTE_30_HIDDEN_POTION
Route30_JoeysRattataAttacksMovement:
fix_facing
big_step UP
big_step DOWN
step_end
Route30_MikeysRattataAttacksMovement:
fix_facing
big_step DOWN
big_step UP
step_end
Text_UseTackle:
text "Go, RATTATA!"
para "TACKLE!"
done
Text_ThisIsABigBattle:
text "What? This is a"
line "big battle!"
cont "Leave me alone!"
done
YoungsterJoey1SeenText:
text "I just lost, so"
line "I'm trying to find"
cont "more #MON."
para "Wait! You look"
line "weak! Come on,"
cont "let's battle!"
done
YoungsterJoey1BeatenText:
text "Ack! I lost again!"
line "Doggone it!"
done
YoungsterJoey1AfterText:
text "Do I have to have"
line "more #MON in"
para "order to battle"
line "better?"
para "No! I'm sticking"
line "with this one no"
cont "matter what!"
done
YoungsterMikeySeenText:
text "You're a #MON"
line "trainer, right?"
para "Then you have to"
line "battle!"
done
YoungsterMikeyBeatenText:
text "That's strange."
line "I won before."
done
YoungsterMikeyAfterText:
text "Becoming a good"
line "trainer is really"
cont "tough."
para "I'm going to bat-"
line "tle other people"
cont "to get better."
done
BugCatcherDonSeenText:
text "Instead of a bug"
line "#MON, I found"
cont "a trainer!"
done
BugCatcherDonBeatenText:
text "Argh! You're too"
line "strong!"
done
BugCatcherDonAfterText:
text "I ran out of #"
line "BALLS while I was"
cont "catching #MON."
para "I should've bought"
line "some more…"
done
Route30YoungsterText_DirectionsToMrPokemonsHouse:
text "MR.#MON's"
line "house? It's a bit"
cont "farther ahead."
done
Route30YoungsterText_EveryoneIsBattling:
text "Everyone's having"
line "fun battling!"
cont "You should too!"
done
Route30CooltrainerFText:
text "I'm not a trainer."
para "But if you look"
line "one in the eyes,"
cont "prepare to battle."
done
Route30SignText:
text "ROUTE 30"
para "VIOLET CITY -"
line "CHERRYGROVE CITY"
done
MrPokemonsHouseDirectionsSignText:
text "MR.#MON'S HOUSE"
line "STRAIGHT AHEAD!"
done
MrPokemonsHouseSignText:
text "MR.#MON'S HOUSE"
done
Route30TrainerTipsText:
text "TRAINER TIPS"
para "No stealing other"
line "people's #MON!"
para "# BALLS are to"
line "be thrown only at"
cont "wild #MON!"
done
YoungsterJoeyText_GiveHPUpAfterBattle:
text "I lost again…"
line "Gee, you're tough!"
para "Oh yeah, I almost"
line "forgot that I had"
cont "to give you this."
para "Use it to get even"
line "tougher, OK?"
para "I'm going to get"
line "tougher too."
done
Route30_MapEvents:
db 0, 0 ; filler
db 2 ; warp events
warp_event 7, 39, ROUTE_30_BERRY_HOUSE, 1
warp_event 17, 5, MR_POKEMONS_HOUSE, 1
db 0 ; coord events
db 5 ; bg events
bg_event 9, 43, BGEVENT_READ, Route30Sign
bg_event 13, 29, BGEVENT_READ, MrPokemonsHouseDirectionsSign
bg_event 15, 5, BGEVENT_READ, MrPokemonsHouseSign
bg_event 3, 21, BGEVENT_READ, Route30TrainerTips
bg_event 14, 9, BGEVENT_ITEM, Route30HiddenPotion
db 11 ; object events
object_event 5, 26, SPRITE_YOUNGSTER, SPRITEMOVEDATA_STANDING_UP, 0, 0, -1, -1, PAL_NPC_BLUE, OBJECTTYPE_SCRIPT, 0, YoungsterJoey_ImportantBattleScript, EVENT_ROUTE_30_BATTLE
object_event 2, 28, SPRITE_YOUNGSTER, SPRITEMOVEDATA_STANDING_RIGHT, 0, 0, -1, -1, PAL_NPC_BLUE, OBJECTTYPE_TRAINER, 3, TrainerYoungsterJoey, EVENT_ROUTE_30_YOUNGSTER_JOEY
object_event 5, 23, SPRITE_YOUNGSTER, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_BLUE, OBJECTTYPE_TRAINER, 1, TrainerYoungsterMikey, -1
object_event 1, 7, SPRITE_BUG_CATCHER, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_BROWN, OBJECTTYPE_TRAINER, 3, TrainerBugCatcherDon, -1
object_event 7, 30, SPRITE_YOUNGSTER, SPRITEMOVEDATA_WALK_LEFT_RIGHT, 1, 0, -1, -1, PAL_NPC_RED, OBJECTTYPE_SCRIPT, 0, Route30YoungsterScript, -1
object_event 5, 24, SPRITE_MONSTER, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_RED, OBJECTTYPE_SCRIPT, 0, ObjectEvent, EVENT_ROUTE_30_BATTLE
object_event 5, 25, SPRITE_MONSTER, SPRITEMOVEDATA_STANDING_UP, 0, 0, -1, -1, PAL_NPC_BLUE, OBJECTTYPE_SCRIPT, 0, ObjectEvent, EVENT_ROUTE_30_BATTLE
object_event 5, 39, SPRITE_FRUIT_TREE, SPRITEMOVEDATA_STILL, 0, 0, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, Route30FruitTree1, -1
object_event 11, 5, SPRITE_FRUIT_TREE, SPRITEMOVEDATA_STILL, 0, 0, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, Route30FruitTree2, -1
object_event 2, 13, SPRITE_COOLTRAINER_F, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, Route30CooltrainerFScript, -1
object_event 8, 35, SPRITE_POKE_BALL, SPRITEMOVEDATA_STILL, 0, 0, -1, -1, 0, OBJECTTYPE_ITEMBALL, 0, Route30Antidote, EVENT_ROUTE_30_ANTIDOTE
|
; A267576: Triangle read by rows giving successive states of cellular automaton generated by "Rule 167" initiated with a single ON (black) cell.
; 1,1,1,0,1,1,0,1,0,1,1,0,1,1,1,0,1,1,0,1,0,1,0,1,0,1,1,0,1,1,1,1,1,1,1,0,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
trn $0,2
seq $0,267605 ; Triangle read by rows giving successive states of cellular automaton generated by "Rule 181" initiated with a single ON (black) cell.
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Dolphin Smalltalk
;
; Implement Constant Object Space
;
.586
OPTION CASEMAP:NONE
OPTION NOLJMP
OPTION PROC:PRIVATE
INCLUDE IstAsm.Inc
.LISTALL
;.LALL
.data
PUBLIC ?_Pointers@@3UVMPointers@@A
VM$CNST SEGMENT PUBLIC 'DATA'
?_Pointers@@3UVMPointers@@A VMPointers <>
_emptyStringObj SBYTE 4 DUP (?) ; ... String has null terminator so must pad to 4 bytes
_delimStringObj SBYTE 4 DUP (?) ; ... String 2+1 bytes, padded to 4
_charObjs Character 256 DUP (<>)
; Pad out to fill one page
?_vmConstSegFiller@@3PAEA BYTE 2464 DUP (?)
VM$CNST ENDS
END |
//
// Copyright (c) 2003 L.M.Witek
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from
// the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
#include <iostream>
#include "CondensedTraceOutput.h"
using namespace std;
void CondensedTraceOutput::startTrace (net::InetAddress& target, bool noRDNS, DWORD maxHops, bool noPort)
{
m_target = target;
m_noRDNS = noRDNS;
}
void CondensedTraceOutput::startHop (int hopNumber)
{
cout << "["<< m_target.getIPAddressAsString() << ":" << m_target.getPortNumber() << "] " << hopNumber << "\t";
m_goodPings = 0;
}
void CondensedTraceOutput::pingResultGood (net::InetAddress& respFrom, DWORD pingTime)
{
cout << pingTime << " ms" << "\t";
m_goodPings++;
m_lastGoodResp = respFrom;
}
void CondensedTraceOutput::pingResultBad (net::InetAddress& respFrom, string message)
{
cout << "\t" << respFrom.getIPAddressAsString() << " reports: " << message << endl;
}
void CondensedTraceOutput::pingResultTimeout ()
{
cout << "*\t";
}
void CondensedTraceOutput::destinationReached (net::InetAddress& respFrom, DWORD pingTime, bool portOpen)
{
cout << "Dest. in " << pingTime << " ms. ";
if (portOpen)
cout << "Port OPEN on " << respFrom.getIPAddressAsString();
else
cout << "Port CLOSED on " << respFrom.getIPAddressAsString();
cout << endl;
}
void CondensedTraceOutput::endHop ()
{
if (m_goodPings)
{
cout << m_lastGoodResp.getIPAddressAsString() << "\t";
if (!m_noRDNS)
{
try
{
string name = m_lastGoodResp.lookupHostName();
cout << "[" << name << "]";
}
catch (net::SocketException&) {}
}
cout << endl;
}
else
{
cout << "Request timed out." << endl;
}
}
void CondensedTraceOutput::endTrace ()
{
}
|
ivnentory_page_marker DB "Inventory PG52"
inventory_boiler_text DW $0248,INM_inventory
DW $0B08,INM_fuel
DW $1308,INM_cash
INM_inventory DB "INVENTORY",0
INM_fuel DB "Fuel:",0
INM_cash DB "Cash:",0
txt_inventory_amount DB "00000",0
inventory_cursor DW $0000
inv_fuel_position equ $0B30
inv_cash_position equ $1330
inventory_position equ $2008
inventory_amount equ $80
inventory_uom equ $B0
inv_selected_row DB 0
INM_cash_amount DS 10
INM_cash_UoM DB " Cr",0
INM_DispAtoDE: ld h,0
ld l,a
ld bc,-10000
call .Num1
ld bc,-1000
call .Num1
ld bc,-100
call .Num1
ld c,-10
call .Num1
ld c,-1
.Num1: ld a,'0'-1
.Num2: inc a
add hl,bc
jr c,.Num2
sbc hl,bc
ld (de),a
inc de
ret
INM_print_boiler_text: INCLUDE "Menus/print_boiler_text_inlineInclude.asm"
INM_DispDEIXtoIY: ld (.inmclcn32z),ix
ld (.inmclcn32zIX),de
ld ix,.inmclcn32t+36
ld b,9
ld c,0
.inmclcn321: ld a,'0'
or a
.inmclcn322: ld e,(ix+0)
ld d,(ix+1)
ld hl,(.inmclcn32z)
sbc hl,de
ld (.inmclcn32z),hl
ld e,(ix+2)
ld d,(ix+3)
ld hl,(.inmclcn32zIX)
sbc hl,de
ld (.inmclcn32zIX),hl
jr c,.inmclcn325
inc c
inc a
jr .inmclcn322
.inmclcn325: ld e,(ix+0)
ld d,(ix+1)
ld hl,(.inmclcn32z)
add hl,de
ld (.inmclcn32z),hl
ld e,(ix+2)
ld d,(ix+3)
ld hl,(.inmclcn32zIX)
adc hl,de
ld (.inmclcn32zIX),hl
ld de,-4
add ix,de
inc c
dec c
jr z,.inmclcn323
ld (iy+0),a
inc iy
.inmclcn323: djnz .inmclcn321
ld a,(.inmclcn32z)
add A,'0'
ld (iy+0),a
ld (iy+2),0
ld a,(IY+0)
ld (IY+1),a
ld a,"."
ld (IY+0),a
inc IY
inc IY
ret
.inmclcn32t dw 1,0, 10,0, 100,0, 1000,0, 10000,0
dw $86a0,1, $4240,$0f, $9680,$98, $e100,$05f5, $ca00,$3b9a
.inmclcn32z ds 2
.inmclcn32zIX ds 2
INM_GetFuelLevel: INCLUDE "Menus/get_fuel_level_inlineinclude.asm"
; "A = stock item number"
;----------------------------------------------------------------------------------------------------------------------------------
PrintInvItem: ld b,a
ld hl,CargoTonnes
add hl,a
ld a,(hl)
ld c,a
cp 0
ret z
ld a,b
push bc ; push item nbr + quantity
MMUSelectStockTable
ld hl, StockItemTable
call getTableText
.ItemItemName ld a,(hl)
ld hl, WordIdx
call getTableText
ld de,(inventory_cursor)
MMUSelectLayer1
call l1_print_at
.ItemAmount: pop bc ; b = item number, c = quantity
push bc
ld a,c
ld de,txt_inventory_amount
call INM_DispAtoDE
ld hl,txt_inventory_amount
push hl
.ZeroLoop: ld a,(hl)
cp '0'
jr nz,.NotZero
.ZeroDigit: ld (hl),' '
inc hl
jr .ZeroLoop
.NotZero: ld de,(inventory_cursor)
pop hl
ld e,inventory_amount
MMUSelectLayer1
call l1_print_at
.ItemMeasure: MMUSelectStockTable
ld hl, StockItemTable
pop bc
ld a,b
call getTableText
add hl,7
ld a,(hl)
ld hl,WordIdx
call getTableText
ld de,(inventory_cursor)
ld e,inventory_uom
MMUSelectLayer1
call l1_print_at
ld a,(inventory_cursor+1)
add a,8
ld (inventory_cursor+1),a
ret
;----------------------------------------------------------------------------------------------------------------------------------
INM_GetCash: ld hl,(Cash+2)
ex de,hl
ld ix,(Cash)
ld iy,INM_cash_amount
call INM_DispDEIXtoIY
push IY
pop de
ld hl,INM_cash_UoM
ld bc,4
ldir
ret
;----------------------------------------------------------------------------------------------------------------------------------
draw_inventory_menu: INCLUDE "Menus/clear_screen_inline_no_double_buffer.asm"
ld a,$08
ld (MenuIdMax),a
MMUSelectSpriteBank
call sprite_cls_cursors
.Drawbox: ld bc,$0101
ld de,$BEFD
ld a,$C0
MMUSelectLayer2
call l2_draw_box
ld bc,$0A01
ld de,$FEC0
call l2_draw_horz_line
.StaticText: ld b,3
ld hl,inventory_boiler_text
call INM_print_boiler_text
.DisplayFuel: call INM_GetFuelLevel
ld hl, txt_fuel_level
ld a,(hl)
cp '0'
jr nz,.PrintFuel
.SkipLeadingZero: inc hl
.PrintFuel: ld e,txt_status_colour
ld bc,inv_fuel_position
MMUSelectLayer2
call l2_print_at
.DisplayCash: call INM_GetCash
ld hl,INM_cash_amount
ld e,txt_status_colour
ld bc,inv_cash_position
MMUSelectLayer2
call l2_print_at ; now we have the correct integer
ld bc,inv_cash_position
ld hl,INM_cash_amount
.DisplayInventory: ld a,0
ld hl,inventory_position
ld (inventory_cursor),hl
.InvLoop: push af
call PrintInvItem
pop af
inc a
cp 17
jr c,.InvLoop
ret
|
; vasmm68k_mot[_<HOST>] -Fbin -o icon_36_279/def_tool.info def_tool-icon_36_279.asm
;
; Default "ENV:def_tool.info" data included in "icon 36.279 (20.4.90)".
;
include deficon.inc
ifne DEFICON_MEM
align 1
endif
defIconTool:
dc.w $E310 ; do_Magic = WB_DISKMAGIC
dc.w $0001 ; do_Version = WB_DISKVERSION
dc.l 0 ; do_Gadget+gg_NextGadget
dc.w 36,53 ; do_Gadget+gg_LeftEdge/gg_TopEdge
dc.w 54,23 ; do_Gadget+gg_Width/gg_Height
dc.w $0004 ; do_Gadget+gg_Flags =
; GFLG_GADGIMAGE
dc.w $0001 ; do_Gadget+gg_Activation =
; GACT_RELVERIFY
dc.w $0001 ; do_Gadget+gg_GadgetType =
; GTYP_BOOLGADGET
DEFICON_PTR .GadgetRender ; do_Gadget+gg_GadgetRender
dc.l 0 ; do_Gadget+gg_SelectRender
dc.l 0 ; do_Gadget+gg_GadgetText
dc.l 0 ; do_Gadget+gg_MutualExclude
dc.l 0 ; do_Gadget+gg_SpecialInfo
dc.w 0 ; do_Gadget+gg_GadgetID
dc.l 0 ; do_Gadget+gg_UserData
dc.b 3 ; do_Type = WBTOOL
dc.b 0 ; do_PAD_BYTE
dc.l 0 ; do_DefaultTool
dc.l 0 ; do_ToolTypes
dc.l $80000000 ; do_CurrentX = NO_ICON_POSITION
dc.l $80000000 ; do_CurrentY = NO_ICON_POSITION
dc.l 0 ; do_DrawerData
dc.l 0 ; do_ToolWindow
dc.l 0 ; do_StackSize
.GadgetRender:
dc.w 0,0 ; ig_LeftEdge/ig_TopEdge
dc.w 54,23 ; ig_Width/ig_Height
dc.w 2 ; ig_Depth
DEFICON_PTR .GadgetImage ; ig_ImageData
dc.b (1<<2)-1,0 ; ig_PlanePick/ig_PlaneOnOff
dc.l 0 ; ig_NextImage
.GadgetImage:
dc.w %0000000000000000,%0000000000000000,%0000000000000100,%0000000000000000
dc.w %0000000000000000,%0000000000000000,%0000000000000001,%0000000000000000
dc.w %0000000000000000,%0000000000000000,%0000000000000000,%0100000000000000
dc.w %0000000000000000,%0000000000000000,%0000000000000000,%0001000000000000
dc.w %0000000011111111,%1111100000000000,%0000000000000000,%0000100000000000
dc.w %0000000100000000,%0000010000000000,%0000000000000000,%0000110000000000
dc.w %0000001000000000,%0000001111111111,%1111111111111111,%1000110000000000
dc.w %0000010000000000,%0000000000000000,%0000000000000000,%0100110000000000
dc.w %0000010000000000,%0000000000000000,%0000000000000000,%0100110000000000
dc.w %0000010111111111,%1111111111111111,%1111111111111111,%0100110000000000
dc.w %0000011000000000,%0000000000000000,%0000000000000000,%1100110000000000
dc.w %0000010000000000,%0000000000000000,%0000000000000000,%0100110000000000
dc.w %0000010000000000,%0000000000000000,%0000000000000000,%0100110000000000
dc.w %0000010000000000,%0000000000000000,%0000000000000000,%0100110000000000
dc.w %0000010000000000,%0000000000000000,%0000000000000000,%0100110000000000
dc.w %0000010000000000,%0000000000000000,%0000000000000000,%0100110000000000
dc.w %0000010000000000,%0000000000000000,%0000000000000000,%0100110000000000
dc.w %0000010000000000,%0000000000000000,%0000000000000000,%0100110000000000
dc.w %0000010000000000,%0000000000000000,%0000000000000000,%0100110000000000
dc.w %0000010000000000,%0000000000000000,%0000000000000000,%0100110000000000
dc.w %0000010000000000,%0000000000000000,%0000000000000000,%0100110000000000
dc.w %0111111111111111,%1111111111111111,%1111111111111111,%1111110000000000
dc.w %0000000000000000,%0000000000000000,%0000000000000000,%0000000000000000
dc.w %1111111111111111,%1111111111111111,%1111111111111000,%0000000000000000
dc.w %1101010101010101,%0101010101010101,%0101010101010110,%0000000000000000
dc.w %1101010101010101,%0101010101010101,%0101010101010101,%1000000000000000
dc.w %1101010101010101,%0101010101010101,%0101010101010101,%0110000000000000
dc.w %1101010100000000,%0000010101010101,%0101010101010101,%0101000000000000
dc.w %1101010000000000,%0000000101010101,%0101010101010101,%0101000000000000
dc.w %1101010000000000,%0000000000000000,%0000000000000000,%0101000000000000
dc.w %1101000000000000,%0000000000000000,%0000000000000000,%0001000000000000
dc.w %1101000011111111,%1111111111111111,%1111111111111100,%0001000000000000
dc.w %1101000000000000,%0000000000000000,%0000000000000000,%0001000000000000
dc.w %1101000000000000,%0000000000000000,%0000000000000000,%0001000000000000
dc.w %1101000000000000,%0000000000000000,%0000000000000000,%0001000000000000
dc.w %1101000000000000,%0000000000000000,%0000000000000000,%0001000000000000
dc.w %1101000000000000,%0000000000000000,%0000000000000000,%0001000000000000
dc.w %1101000000000000,%0000000000000000,%0000000000000000,%0001000000000000
dc.w %1101000000000000,%0000000000000000,%0000000000000000,%0001000000000000
dc.w %1101000000000000,%0000000000000000,%0000000000000000,%0001000000000000
dc.w %1101000000000000,%0000000000000000,%0000000000000000,%0001000000000000
dc.w %1101000000000000,%0000000000000000,%0000000000000000,%0001000000000000
dc.w %1101000000000000,%0000000000000000,%0000000000000000,%0001000000000000
dc.w %1101000000000000,%0000000000000000,%0000000000000000,%0001000000000000
dc.w %1000000000000000,%0000000000000000,%0000000000000000,%0000000000000000
dc.w %0000000000000000,%0000000000000000,%0000000000000000,%0000000000000000
|
; void __CALLEE__ *HeapCalloc_callee(void *heap, unsigned int nobj, unsigned int size)
; 12.2006 aralbrec
SECTION code_clib
PUBLIC HeapCalloc_callee
PUBLIC _HeapCalloc_callee
PUBLIC ASMDISP_HEAPCALLOC_CALLEE
EXTERN l_mult, HeapAlloc_callee
EXTERN ASMDISP_HEAPALLOC_CALLEE
.HeapCalloc_callee
._HeapCalloc_callee
pop af
pop de
pop hl
pop bc
push af
.asmentry
; Allocate memory from the indicated heap and clear it to zeroes
;
; enter : hl = number of objects
; de = size of each object
; bc = & heap pointer
; exit : hl = address of memory block and carry set if successful
; else 0 and no carry if failed
; uses : af, bc, de, hl
.MAHeapCalloc
push bc
call l_mult ; hl = hl*de = total size of request
ld c,l
ld b,h
pop hl
push bc
call HeapAlloc_callee + ASMDISP_HEAPALLOC_CALLEE
pop bc
ret nc ; ret if fail
ld a,b
or c
jr z, out
ld (hl),0
dec bc
ld a,b
or c
jr z, out
push hl ; zero memory block
ld e,l
ld d,h
inc de
IF __CPU_INTEL__
ldir_loop:
ld a,(hl)
ld (de),a
inc hl
inc de
dec bc
ld a,b
or c
jp nz,ldir_loop
ELSE
ldir
ENDIF
pop hl
.out
scf
ret
DEFC ASMDISP_HEAPCALLOC_CALLEE = asmentry - HeapCalloc_callee
|
; A267595: Binary representation of the n-th iteration of the "Rule 173" elementary cellular automaton starting with a single ON (black) cell.
; Submitted by Simon Strandgaard
; 1,10,1111,111111,11111111,1111111111,111111111111,11111111111111,1111111111111111,111111111111111111,11111111111111111111,1111111111111111111111,111111111111111111111111,11111111111111111111111111,1111111111111111111111111111,111111111111111111111111111111,11111111111111111111111111111111,1111111111111111111111111111111111,111111111111111111111111111111111111,11111111111111111111111111111111111111,1111111111111111111111111111111111111111,111111111111111111111111111111111111111111
mul $0,2
mov $1,10
pow $1,$0
cmp $0,2
div $1,18
mul $1,10
sub $1,$0
mov $0,$1
div $0,5
add $0,1
|
#include <stdlib.h>
#include "iwstring.h"
#if (__GNUC_MINOR__ == 95)
#include <strstream>
IWString &
IWString::operator = (ostrstream & zstream)
{
int nchars = zstream.pcount ();
char * c = zstream.str ();
IWString::strncpy (c, nchars);
#ifdef __GNUG__
zstream.freeze (0); // allow zstream to delete the buffer, we have a copy
#else
delete c;
#endif
return * this;
}
/*
Append the text in ZEXTRA
*/
IWString &
operator << (IWString & s, ostrstream & zextra)
{
assert (s.ok ());
int nchars = zextra.pcount ();
char * c = zextra.str ();
s.strncat (c, nchars);
#ifdef __GNUG__
zextra.freeze (0);
#else
delete c;
#endif
return s;
}
#else
#include <sstream>
/*IWString &
IWString::operator = (ostringstream & zstream)
{
std::string c = zstream.str ();
IWString::operator = (c);
return *this;
}
IWString &
operator << (IWString & s, ostringstream & zextra)
{
assert (s.ok ());
string c = zextra.str ();
s.strncat (c.data (), c.length ());
return s;
}*/
#endif
|
; Game Code (NES-specific)
;==============================================================================;
;-- Defines/Constants --;
PADDLE_DEFAULT_Y_POS = (240/2)-16
PADDLE_MIN_Y_POS = 44
PADDLE_MAX_Y_POS = 240-64
BALL_DEFAULT_X = (256/2)-3 ; screen center x - 3 (7/2, rounded down)
BALL_DEFAULT_Y = (240/2)-3 ; screen center y - 3 (7/2, rounded down)
WALL_TOP = 30 ; top wall: ballY = 0x1E (30)
WALL_BOT = 204 ; bot wall: ballY = 0xCC (204)
WALL_LEFT = 0 ; left wall (P1)
WALL_RIGHT = 250 ; right wall (P2)
BALL_PADDLEX_P1 = 30 ; P1 paddle surface X = 0x1E (30)
BALL_PADDLEX_P2 = 219 ; P2 paddle surface X = 0xDB (219)
PADDLE_WIDTH_P1 = 17
PADDLE_WIDTH_P2 = 12
;------------------------------------------------------------------------------;
; Platform-specific routine aliases
HANDLE_GAME_INPUT = game_InputsGame_nes
RENDER_BALL = game_renderBall_nes
RENDER_PADDLE = game_renderPaddle_nes
DRAW_FIELD = game_drawField_nes
UPDATE_SCORE_DISP = game_updateScoreDisplay_nes
INPUT_DEBUG = game_InputsGame_Debug_nes
INPUT_ATTRACT = game_InputsAttract_nes
;==============================================================================;
; Platform-specific data
; Paddle attributes for player 1 and 2
tbl_PaddleAttrib_nes: .byte $00,$01
; Starting sprite number for player 1 and 2
tbl_PaddleSpriteNum_nes: .byte $01,$0A
; Sprite tile indexes for paddle
tbl_PaddleTiles_nes:
.byte $00,$01 ; top
.byte $02,$03 ; middle 1/2
.byte $02,$03 ; middle 2/2
.byte $04,$05 ; bottom
; Starting paddle X positions for player 1 and 2
tbl_PaddleXPos: .byte 16,256-32
;==============================================================================;
; NES sprite map (using 8x8 mode, because it's less painful to deal with)
;-------------------------;-----;
; $00 - ball
;-------------------------;-----;
; $01 - paddle 1 top | 1/2 ;
; $02 - paddle 1 top | 2/2 ;
; $03 - paddle 1 middle 1 | 1/2 ;
; $04 - paddle 1 middle 1 | 2/2 ;
; $05 - paddle 1 middle 2 | 1/2 ;
; $06 - paddle 1 middle 2 | 2/2 ;
; $07 - paddle 1 bottom | 1/2 ;
; $08 - paddle 1 bottom | 2/2 ;
;-------------------------;-----;
; $09 - paddle 2 top | 1/2 ;
; $0A - paddle 2 top | 2/2 ;
; $0B - paddle 2 middle 1 | 1/2 ;
; $0C - paddle 2 middle 1 | 2/2 ;
; $0D - paddle 2 middle 2 | 1/2 ;
; $0E - paddle 2 middle 2 | 2/2 ;
; $0F - paddle 2 bottom | 1/2 ;
; $10 - paddle 2 bottom | 2/2 ;
;-------------------------;-----;
;==============================================================================;
; game_InputsAttract_nes
; Handle controller inputs in attract mode.
game_InputsAttract_nes:
; check for Start button on the first controller
lda nes_padTrigger
sta tmp00
and #PAD_START
beq @game_InputsAttract_nes_CheckLeft
; pressed start, begin game
lda #1
sta inGame
; don't allow left/right input after pressing Start
bne @game_InputsAttract_nes_end ; branch always
; handle left/right for changing maximum score
@game_InputsAttract_nes_CheckLeft:
lda tmp00
and #PAD_LEFT
beq @game_InputsAttract_nes_CheckRight
; pressed left; decrement score or wrap around to max
lda maxScore
cmp #GAME_MIN_SCORE
bne @game_InputsAttract_nes_NormalLeft
; wrap around
lda #GAME_MAX_SCORE
sta maxScore
bne @game_InputsAttract_nes_end ; branch always
@game_InputsAttract_nes_NormalLeft:
dec maxScore
bne @game_InputsAttract_nes_end ; branch always
@game_InputsAttract_nes_CheckRight:
lda tmp00
and #INPUT_RIGHT
beq @game_InputsAttract_nes_end
; pressed right; increment score or wrap around to min
lda maxScore
cmp #GAME_MAX_SCORE
bne @game_InputsAttract_nes_NormalRight
; wrap around
lda #GAME_MIN_SCORE
sta maxScore
bne @game_InputsAttract_nes_end ; branch always
@game_InputsAttract_nes_NormalRight:
inc maxScore
@game_InputsAttract_nes_end:
rts
;==============================================================================;
; game_InputsGame_nes
; NES controller input handler
; (Params)
; X - player number (0=p1, 1=p2)
game_InputsGame_nes:
; save copies of inputs for operation later
lda nes_padTrigger,x
sta tmp01
lda nes_padState,x
sta tmp00
; check if paused
lda gamePaused
beq @game_InputsGame_nes_Normal
; if paused, only check for start
lda tmp01
and #INPUT_START
bne @game_InputsGame_nes_Unpause
rts
@game_InputsGame_nes_Unpause:
lda #0
sta gamePaused
rts
@game_InputsGame_nes_Normal:
; check for up
lda tmp00
and #PAD_UP
beq @game_InputsGame_nes_CheckDown
; pressed up
lda player1Y,x
cmp #PADDLE_MIN_Y_POS
bcc @game_InputsGame_nes_ForceMin
dec player1Y,x
lda player1Y,x
cmp #PADDLE_MIN_Y_POS
bcc @game_InputsGame_nes_ForceMin
dec player1Y,x
lda player1Y,x
cmp #PADDLE_MIN_Y_POS
bcc @game_InputsGame_nes_ForceMin
; don't allow up+down
jmp @game_InputsGame_nes_Start
@game_InputsGame_nes_ForceMin:
lda #PADDLE_MIN_Y_POS
sta player1Y,x
; don't allow up+down
jmp @game_InputsGame_nes_Start
@game_InputsGame_nes_CheckDown:
; check for down
lda tmp00
and #PAD_DOWN
beq @game_InputsGame_nes_Start
; pressed down
lda player1Y,x
cmp #PADDLE_MAX_Y_POS
bcs @game_InputsGame_nes_ForceMax
inc player1Y,x
lda player1Y,x
cmp #PADDLE_MAX_Y_POS
bcs @game_InputsGame_nes_ForceMax
inc player1Y,x
lda player1Y,x
cmp #PADDLE_MAX_Y_POS
bcs @game_InputsGame_nes_ForceMax
jmp @game_InputsGame_nes_Start
@game_InputsGame_nes_ForceMax:
lda #PADDLE_MAX_Y_POS
sta player1Y,x
@game_InputsGame_nes_Start:
lda tmp01
and #INPUT_START
beq @game_InputsGame_nes_Debug
lda #1
sta gamePaused
@game_InputsGame_nes_Debug:
.ifdef __DEBUGMODE__
; select = debug
lda tmp01
and #PAD_SELECT
beq @game_InputsGame_nes_end
; debugger's high, a contra story
lda #1
sta p1Debug
lda ballDir
sta lastBallDir
lda #0
sta ballDir
.endif
@game_InputsGame_nes_end:
rts
;==============================================================================;
; game_InputsGame_Debug_nes
; debugger input mode: move the ball!
game_InputsGame_Debug_nes:
.ifdef __DEBUGMODE__
lda nes_padTrigger
sta tmp01
lda nes_padState
sta tmp00
lda gamePaused
beq @game_InputsGame_Debug_nes_Normal
lda tmp01
and #INPUT_START
bne @game_InputsGame_Debug_nes_Unpause
rts
@game_InputsGame_Debug_nes_Unpause:
lda #0
sta gamePaused
rts
@game_InputsGame_Debug_nes_Normal:
; input up: ball goes up
lda tmp00
and #PAD_UP
beq @game_InputsGame_Debug_nes_down
dec ballY
@game_InputsGame_Debug_nes_down:
; input down: ball goes down
lda tmp00
and #PAD_DOWN
beq @game_InputsGame_Debug_nes_left
inc ballY
@game_InputsGame_Debug_nes_left:
; input left: ball goes left
lda tmp00
and #PAD_LEFT
beq @game_InputsGame_Debug_nes_right
dec ballX
@game_InputsGame_Debug_nes_right:
; input right: ball goes right
lda tmp00
and #INPUT_RIGHT
beq @game_InputsGame_Debug_nes_start
inc ballX
@game_InputsGame_Debug_nes_start:
; input start: pause
lda tmp01
and #INPUT_START
beq @game_InputsGame_Debug_nes_select
lda #1
sta gamePaused
@game_InputsGame_Debug_nes_select:
; input select: no more debuggery
lda tmp01
and #INPUT_SELECT
beq @game_InputsGame_Debug_nes_end
lda #0
sta p1Debug
lda lastBallDir
sta ballDir
@game_InputsGame_Debug_nes_end:
.endif
rts
;==============================================================================;
; game_renderBall_nes
; NES version of ball renderer.
game_renderBall_nes:
; using sprite 0
; Y position
lda ballY
; subtract 1 from Y position for correct display location
sec
sbc #1
sta OAM_BUF
; tile number
lda #$06
sta OAM_BUF+1
; attributes
lda #2
.ifdef __DEBUGMODE__
clc
adc p1Debug
.endif
sta OAM_BUF+2
; X position
lda ballX
sta OAM_BUF+3
rts
;==============================================================================;
; game_renderPaddle_nes
; NES version of paddle renderer.
; (Params)
; X - Player number (0=p1, 1=p2)
game_renderPaddle_nes:
; set up a counter for indexing into tables and sprite counting
lda #0
sta tmp02
; get starting sprite number
lda tbl_PaddleSpriteNum_nes,x
asl
asl
tay
; store base Y position
lda player1Y,x
sta tmp00
; store base X position
lda tbl_PaddleXPos,x
sta tmp01
@game_renderPaddle_nes_loop:
;-- Y position --;
lda tmp00
sta OAM_BUF,y
iny
;-- tile index --;
; load proper tile from table
tya
pha
ldy tmp02
lda tbl_PaddleTiles_nes,y
sta tmp03
pla
tay
lda tmp03
sta OAM_BUF,y
iny
;-- attributes --;
lda tbl_PaddleAttrib_nes,x
sta OAM_BUF,y
iny
;-- X position --;
lda tmp01
sta OAM_BUF,y
iny
; set up next X position
lda tmp01
eor #8
sta tmp01
; check for even/odd
inc tmp02
lda tmp02
and #$01
bne @game_renderPaddle_nes_loopLogic
; set next row's Y position
lda tmp00
clc
adc #8
sta tmp00
@game_renderPaddle_nes_loopLogic:
;-- check loop logic --;
lda tmp02
cmp #8
bne @game_renderPaddle_nes_loop
rts
;==============================================================================;
; game_drawField_nes
; Handles drawing the game field on NES.
game_drawField_nes:
;-- horizontal top line ($2060) --;
ldx #>$2060
ldy #<$2060
stx PPU_ADDR
sty PPU_ADDR
; tiles $48,$49,$4A,$4B
lda #$48
sta PPU_DATA
lda #$49
sta PPU_DATA
lda #$4A
sta PPU_DATA
lda #$4B
sta PPU_DATA
; tile $03 x24
lda #$03
ldx #24
@game_drawField_nes_top:
sta PPU_DATA
dex
bne @game_drawField_nes_top
; tiles $4C,$4D,$4E,$4F
lda #$4C
sta PPU_DATA
lda #$4D
sta PPU_DATA
lda #$4E
sta PPU_DATA
lda #$4F
sta PPU_DATA
;-- horizontal bottom line ($2340) --;
; tile $03 x32
ldx #>$2340
ldy #<$2340
stx PPU_ADDR
sty PPU_ADDR
; tiles $48,$49,$4A,$4B
lda #$48
sta PPU_DATA
lda #$49
sta PPU_DATA
lda #$4A
sta PPU_DATA
lda #$4B
sta PPU_DATA
; tile $03 x24
lda #$03
ldx #24
@game_drawField_nes_bottom:
sta PPU_DATA
dex
bne @game_drawField_nes_bottom
; tiles $4C,$4D,$4E,$4F
lda #$4C
sta PPU_DATA
lda #$4D
sta PPU_DATA
lda #$4E
sta PPU_DATA
lda #$4F
sta PPU_DATA
; set increment for vertical tiles
lda int_ppuCtrl
and #%11111011
ora #%00000100
sta int_ppuCtrl
sta PPU_CTRL
;-- vertical middle line 1/2 ($206F) --;
ldx #>$206F
ldy #<$206F
stx PPU_ADDR
sty PPU_ADDR
; tiles $04,$08,$0A x1 each
lda #$04
sta PPU_DATA
lda #$08
sta PPU_DATA
lda #$0A
sta PPU_DATA
; tile $0C x17
lda #$0C
ldx #17
@game_drawField_nes_mid1:
sta PPU_DATA
dex
bne @game_drawField_nes_mid1
; tiles $0E,$44,$46,$06 x1 each
lda #$0E
sta PPU_DATA
lda #$44
sta PPU_DATA
lda #$46
sta PPU_DATA
lda #$06
sta PPU_DATA
;-- vertical middle line 2/2 ($2070) --;
ldx #>$2070
ldy #<$2070
stx PPU_ADDR
sty PPU_ADDR
; tiles $05,$09,$0B x1 each
lda #$05
sta PPU_DATA
lda #$09
sta PPU_DATA
lda #$0B
sta PPU_DATA
; tile $0D x17
lda #$0D
ldx #17
@game_drawField_nes_mid2:
sta PPU_DATA
dex
bne @game_drawField_nes_mid2
; tiles $0F,$45,$47,$07 x1 each
lda #$0F
sta PPU_DATA
lda #$45
sta PPU_DATA
lda #$47
sta PPU_DATA
lda #$07
sta PPU_DATA
; reset increment for horizontal tiles
lda int_ppuCtrl
and #%11111011
sta int_ppuCtrl
sta PPU_CTRL
;-- write attributes --;
; $23CA = $44
; $23CB = $99
; $23CC = $66
ldx #>$23CA
ldy #<$23CA
stx PPU_ADDR
sty PPU_ADDR
lda #$44
sta PPU_DATA
lda #$99
sta PPU_DATA
lda #$66
sta PPU_DATA
;------------;
; $23D3 = $88
; $23D4 = $22
ldx #>$23D3
ldy #<$23D3
stx PPU_ADDR
sty PPU_ADDR
lda #$88
sta PPU_DATA
lda #$22
sta PPU_DATA
;------------;
; $23DB = $88
; $23DC = $22
ldx #>$23DB
ldy #<$23DB
stx PPU_ADDR
sty PPU_ADDR
lda #$88
sta PPU_DATA
lda #$22
sta PPU_DATA
;------------;
; $23E3 = $88
; $23E4 = $22
ldx #>$23E3
ldy #<$23E3
stx PPU_ADDR
sty PPU_ADDR
lda #$88
sta PPU_DATA
lda #$22
sta PPU_DATA
;------------;
; $23EB = $88
; $23EC = $22
ldx #>$23EB
ldy #<$23EB
stx PPU_ADDR
sty PPU_ADDR
lda #$88
sta PPU_DATA
lda #$22
sta PPU_DATA
;------------;
; $23F3 = $08
; $23F4 = $02
ldx #>$23F3
ldy #<$23F3
stx PPU_ADDR
sty PPU_ADDR
lda #$08
sta PPU_DATA
lda #$02
sta PPU_DATA
rts
;==============================================================================;
; game_updateScoreDisplay_nes
; Update score display (NES version)
; needs to go into VRAM buffer with specified commands.
game_updateScoreDisplay_nes:
;-- update player 1 score display --;
; (digit 1: $20AC,$20CC)
ldx #>$20AC
ldy #<$20AC
lda #$82
stx nes_vramBuf
sty nes_vramBuf+1
sta nes_vramBuf+2
; get digit
lda scoreP1
and #$F0
lsr
lsr
lsr
lsr
tay
lda tbl_scoreTiles_Top,y
sta nes_vramBuf+3
lda tbl_scoreTiles_Bot,y
sta nes_vramBuf+4
; (digit 2: $20AD,$20CD)
ldx #>$20AD
ldy #<$20AD
lda #$82
stx nes_vramBuf+5
sty nes_vramBuf+6
sta nes_vramBuf+7
; get digit
lda scoreP1
and #$0F
tay
lda tbl_scoreTiles_Top,y
sta nes_vramBuf+8
lda tbl_scoreTiles_Bot,y
sta nes_vramBuf+9
; update player 2 score display
; (digit 1: $20B2,$20D2)
ldx #>$20B2
ldy #<$20B2
lda #$82
stx nes_vramBuf+10
sty nes_vramBuf+11
sta nes_vramBuf+12
; get digit
lda scoreP2
and #$F0
lsr
lsr
lsr
lsr
tay
lda tbl_scoreTiles_Top,y
sta nes_vramBuf+13
lda tbl_scoreTiles_Bot,y
sta nes_vramBuf+14
; (digit 2: $20B3,$20D3)
ldx #>$20B3
ldy #<$20B3
lda #$82
stx nes_vramBuf+15
sty nes_vramBuf+16
sta nes_vramBuf+17
; get digit
lda scoreP2
and #$0F
tay
lda tbl_scoreTiles_Top,y
sta nes_vramBuf+18
lda tbl_scoreTiles_Bot,y
sta nes_vramBuf+19
lda #1
sta nes_ntUpdate
rts
|
; A190998: Digital root of concatenation of all divisors of n (A037278).
; 1,3,4,7,6,3,8,6,4,9,3,1,5,6,6,4,9,3,2,6,5,9,6,6,4,6,4,2,3,9,5,9,3,9,3,1,2,6,2,9,6,6,8,3,6,9,3,7,3,3,9,8,9,3,9,3,8,9,6,6,8,6,5,1,3,9,5,9,6,9,9,6,2,6,7,5,6,6,8,6,4,9,3,8,9,6,3,9,9,9,4,6,2,9,3,9,8,9,3,1
seq $0,203 ; a(n) = sigma(n), the sum of the divisors of n. Also called sigma_1(n).
sub $0,1
mod $0,9
add $0,1
|
; Demonstrate runtime information informing analysis.
;
; The switch statement has 4 legitimate cases and 4 secret cases.
; Analysis will statically find the 4 legitimate.
; Analysis will learn the other 4 while stepping through the table dispatch at runtime.
default rel
%ifdef OS_IS_LINUX
global _start
section .text
_start:
%endif
%ifdef OS_IS_MACOS
global start
section .text
start:
%endif
%ifdef OS_IS_WINDOWS
global WinMain
extern ExitProcess, GetStdHandle, WriteConsoleA
section .text
WinMain:
%endif
start:
; get pointer past switch constraint (which binja static analyzed)
lea rbx, [function_with_switch]
mov edi, 14
call mapper ; returns 7
add rbx, rax ; skip over switch constraint
; call secret cases
mov rcx, 4
call rbx
mov rcx, 5
call rbx
mov rcx, 6
call rbx
mov rcx, 7
call rbx
; call legit cases
mov rdi, 0
call function_with_switch
mov rdi, 1
call function_with_switch
mov rdi, 2
call function_with_switch
mov rdi, 3
call function_with_switch
%ifdef OS_IS_LINUX
mov rdi, 0 ; arg0: status
mov rax, 60 ; __NR_exit
syscall
%endif
%ifdef OS_IS_MACOS
mov rax, 0x2000001 ; exit
mov rdi, 0
syscall
%endif
%ifdef OS_IS_WINDOWS
mov rcx, 0
call ExitProcess
%endif
; exit (so Binja knows end-of-function)
ret
function_with_switch:
; 00000000: 0x48, 0x89, 0xf9
mov rcx, rdi ; arg0: 0,1,2,3
; 00000003: 0x48, 0x83, 0xe1, 0x03
and rcx, 0x3
; 00000007: <--- jumping here bypasses the constraint
lea rax, [.jump_table]
movsx rdx, dword[rax+rcx*4]
add rdx, rax
jmp rdx
.case0:
mov rax, 0
jmp .switch_end
.case1:
mov rax, 1
jmp .switch_end
.case2:
mov rax, 2
jmp .switch_end
.case3:
mov rax, 3
jmp .switch_end
.case4:
mov rax, 4
jmp .switch_end
.case5:
mov rax, 5
jmp .switch_end
.case6:
mov rax, 6
jmp .switch_end
.case7:
mov rax, 7
jmp .switch_end
.switch_end:
ret
.jump_table:
dd function_with_switch.case0 - .jump_table
dd function_with_switch.case1 - .jump_table
dd function_with_switch.case2 - .jump_table
dd function_with_switch.case3 - .jump_table
; these entries should be invisible/illegal to binja because of the "and 3" constraint
dd function_with_switch.case4 - .jump_table
dd function_with_switch.case5 - .jump_table
dd function_with_switch.case6 - .jump_table
dd function_with_switch.case7 - .jump_table
; evade data flow: return given number integer divided by 2
mapper:
mov rax, rdi
shr rax, 1
ret
|
; A140649: Triangle whose rows are decreasing powers of 2, followed by 0.
; 1,0,2,1,0,4,2,1,0,8,4,2,1,0,16,8,4,2,1,0,32,16,8,4,2,1,0,64,32,16,8,4,2,1,0,128,64,32,16,8,4,2,1,0,256,128,64,32,16,8,4,2,1,0,512,256,128,64,32,16,8,4,2,1,0,1024,512,256,128,64,32,16,8,4,2,1,0,2048,1024,512,256,128,64,32,16,8,4,2,1,0,4096
add $0,1
seq $0,25676 ; Exponent of 8 (value of i) in n-th number of form 8^i*9^j.
sub $0,1
mov $1,2
pow $1,$0
mov $0,$1
|
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "low_precision_transformations/mvn_transformation.hpp"
#include <memory>
#include <tuple>
#include <vector>
#include <string>
#include <ie_core.hpp>
#include "common_test_utils/common_utils.hpp"
#include "functional_test_utils/plugin_cache.hpp"
#include "shared_test_classes/base/layer_test_utils.hpp"
#include "functional_test_utils/blob_utils.hpp"
#include "ngraph_functions/pass/convert_prc.hpp"
#include "lpt_ngraph_functions/mvn_function.hpp"
namespace LayerTestsDefinitions {
std::string MVNTransformation::getTestCaseName(const testing::TestParamInfo<MVNTransformationParams>& obj) {
std::string targetDevice;
ngraph::PartialShape shape;
ngraph::element::Type precision;
auto params = LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParamsU8I8();
ngraph::AxisSet reductionAxes;
bool normalizeVariance;
std::tie(precision, shape, targetDevice, reductionAxes, normalizeVariance) = obj.param;
std::ostringstream result;
result << getTestCaseNameByParams(precision, shape, targetDevice, params) <<
"_" << reductionAxes << "_" << normalizeVariance;
return result.str();
}
void MVNTransformation::SetUp() {
ngraph::PartialShape shape;
ngraph::element::Type precision;
ngraph::AxisSet reductionAxes;
bool normalizeVariance;
std::tie(precision, shape, targetDevice, reductionAxes, normalizeVariance) = this->GetParam();
function = ngraph::builder::subgraph::MVNFunction::getOriginal(
precision,
shape,
reductionAxes,
normalizeVariance);
}
TEST_P(MVNTransformation, CompareWithRefImpl) {
Run();
};
} // namespace LayerTestsDefinitions
|
/*
* fam_invalidkey_test.cpp
* Copyright (c) 2019 Hewlett Packard Enterprise Development, LP. 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.
*
* See https://spdx.org/licenses/BSD-3-Clause
*
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <fam/fam.h>
#include "common/fam_libfabric.h"
#include "common/fam_ops_libfabric.h"
#include "common/fam_test_config.h"
using namespace std;
using namespace openfam;
int main() {
fam *my_fam = new fam();
Fam_Options fam_opts;
Fam_Region_Descriptor *desc;
Fam_Descriptor *item;
Fam_Global_Descriptor global;
memset((void *)&fam_opts, 0, sizeof(Fam_Options));
Fam_Ops_Libfabric *famOps = new Fam_Ops_Libfabric;
int ret = 0;
char *buff = (char *)malloc(1024);
memset(buff, 0, 1024);
// Initialize the libfabric ops
char *message = strdup("This is the datapath test");
init_fam_options(&fam_opts);
ret = famOps->initialize(name, service, false, provider);
if (ret < 0) {
cout << "famOps initialization failed" << endl;
exit(1);
}
// Initialize openFAM API
fam_opts.memoryServer = strdup(TEST_MEMORY_SERVER);
fam_opts.grpcPort = strdup(TEST_GRPC_PORT);
try {
my_fam->fam_initialize("default", &fam_opts);
} catch (Fam_Exception &e) {
cout << "fam initialization failed" << endl;
exit(1);
}
// Create Region
desc = my_fam->fam_create_region("test", 8192, 0777, RAID1);
if (desc == NULL) {
cout << "fam create region failed" << endl;
exit(1);
} else {
global = desc->get_global_descriptor();
cout << " Fam_Region_Descriptor { Region ID : 0x" << hex << uppercase
<< global.regionId << ", Offset : 0x" << global.offset << " }"
<< endl;
}
// Allocating data items in the created region
item = my_fam->fam_allocate("first", 1024, 0777, desc);
if (item == NULL) {
cout << "fam allocation of dataitem 'first' failed" << endl;
} else {
global = item->get_global_descriptor();
cout << " Fam_Descriptor { Region ID : 0x" << hex << uppercase
<< global.regionId << ", Offset : 0x" << global.offset
<< ", Key : 0x" << item->get_key() << " }" << endl;
}
// Write with valid key
ret =
fabric_write(item->get_key(), message, 25, 0,
(*famOps->get_fiAddrs())[0], famOps->get_defaultCtx(item));
if (ret < 0) {
cout << "fabric write failed" << endl;
exit(1);
}
// Read with valid key
ret = fabric_read(item->get_key(), buff, 25, 0, (*famOps->get_fiAddrs())[0],
famOps->get_defaultCtx(item));
if (ret < 0) {
cout << "fabric read failed" << endl;
exit(1);
}
cout << "With valid key : " << endl;
cout << "key = " << item->get_key() << endl;
cout << "buffer = " << buff << endl;
uint64_t invalidKey = -1;
// Write with invalid key
ret = fabric_write(invalidKey, message, 25, 0, (*famOps->get_fiAddrs())[0],
famOps->get_defaultCtx(item));
if (ret < 0) {
cout << "fabric write failed" << endl;
exit(1);
}
// Read with invalid key
ret = fabric_read(invalidKey, buff, 25, 0, (*famOps->get_fiAddrs())[0],
famOps->get_defaultCtx(item));
if (ret < 0) {
cout << "fabric read failed" << endl;
exit(1);
}
cout << "With invalid key : " << endl;
cout << "key = " << item->get_key() << endl;
cout << "buffer = " << buff << endl;
// Deallocating data items
if (item != NULL)
my_fam->fam_deallocate(item);
// Destroying the regioin
if (desc != NULL)
my_fam->fam_destroy_region(desc);
famOps->finalize();
my_fam->fam_finalize("default");
cout << "fam finalize successful" << endl;
}
|
// Copyright 2016-2022 by Martin Moene
//
// This version targets C++11 and later.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// status_value is based on:
// A Class for Status and Optional Value, P0262r0
// by Lawrence Crowl and Chris Mysen
#include nsstv_STATUS_VALUE_HEADER
#ifdef __clang__
# pragma clang diagnostic ignored "-Wstring-conversion"
# pragma clang diagnostic ignored "-Wunused-parameter"
# pragma clang diagnostic ignored "-Wunused-template"
# pragma clang diagnostic ignored "-Wunused-function"
# pragma clang diagnostic ignored "-Wunused-member-function"
#elif defined __GNUC__
# pragma GCC diagnostic ignored "-Wunused-parameter"
# pragma GCC diagnostic ignored "-Wunused-function"
#endif
#include "lest.hpp"
#ifndef nsstsv_CONFIG_CONFIRMS_COMPILATION_ERRORS
#define nsstsv_CONFIG_CONFIRMS_COMPILATION_ERRORS 0
#endif
#define CASE( name ) lest_CASE( specification, name )
static lest::tests specification;
using namespace nonstd;
template< typename T >
void use( T const & ) {}
struct not_default_constructible
{
not_default_constructible() = delete;
};
struct move_constructible
{
int x;
move_constructible( int x_ ) : x(x_) {}
move_constructible( move_constructible && other ) : x( std::move( other.x ) ) {}
move_constructible( move_constructible const & other ) = delete;
};
struct copy_constructible
{
int x;
copy_constructible( int x_ ) : x(x_) {}
copy_constructible( copy_constructible && other ) = delete;
copy_constructible( copy_constructible const & other ) : x( other.x ) {}
};
// -----------------------------------------------------------------------
// status_value<>
CASE( "status_value<>: Disallows default construction" )
{
#if nsstsv_CONFIG_CONFIRMS_COMPILATION_ERRORS
status_value<int, int> sv;
#endif
EXPECT( !!"Avoid warning" );
}
CASE( "status_value<>: Allows construction from only status" )
{
status_value<int, int> sv( 7 );
EXPECT( sv.status() == 7 );
}
CASE( "status_value<>: Allows construction from status and non-default-constructible value" )
{
#if nsstsv_CONFIG_CONFIRMS_COMPILATION_ERRORS
not_default_constructible x;
#endif
status_value<int, not_default_constructible> sv( 7 );
EXPECT( sv.status() == 7 );
}
CASE( "status_value<>: Allows construction from copied status and moved value" )
{
status_value<int, move_constructible> sv( 7, move_constructible( 42 ) );
EXPECT( sv.status() == 7 );
EXPECT( sv.value().x == 42 );
}
CASE( "status_value<>: Allows construction from copied status and copied value" )
{
copy_constructible x( 42 );
status_value<int, copy_constructible> sv( 7, x );
EXPECT( sv.status() == 7 );
EXPECT( sv.value().x == 42 );
}
// A status_value may be moved.
// A copy operation would make the type unusable for non-copyable
// contained objects, so we do not provide a copy operation.
CASE( "status_value<>: Disallows copy-construction from other status_value of the same type" )
{
#if nsstsv_CONFIG_CONFIRMS_COMPILATION_ERRORS
status_value<int, copy_constructible> sv1( 7, copy_constructible( 42 ) );
status_value<int, copy_constructible> sv2( sv1 );
#endif
EXPECT( !!"Avoid warning" );
}
CASE( "status_value<>: Allows move-construction from other status_value of the same type" )
{
status_value<int, move_constructible> sv1( 7, move_constructible( 42 ) );
status_value<int, move_constructible> sv2( std::move( sv1 ) );
EXPECT( ! sv1 );
EXPECT( sv2.status() == 7 );
EXPECT( sv2.value().x == 42 );
}
// They may be queried for status. The design assumes that inlining
// will remove the cost of returning a reference for cheap copyable types.
CASE( "status_value<>: Allows to observe its status" )
{
status_value<int, int> sv( 7 );
EXPECT( sv.status() == 7 );
}
// They may be queried for whether or not they have a value.
CASE( "status_value<>: Allows to observe the presence of a value (has_value())" )
{
status_value<int, int> sv1( 7 );
status_value<int, int> sv2( 7, 42 );
EXPECT( ! sv1.has_value() );
EXPECT( !! sv2.has_value() );
}
CASE( "status_value<>: Allows to observe the presence of a value (operator bool)" )
{
status_value<int, int> sv1( 7 );
status_value<int, int> sv2( 7, 42 );
EXPECT( ! sv1 );
EXPECT( !! sv2 );
}
// They may provide access to their value.
// If they have no value, an exception of type Status,
// with the status value passed to the constructor, is thrown.
CASE( "status_value<>: Allows to observe its value (value())" )
{
status_value<int, int> sv( 7, 42 );
status_value<int, int> const csv( 7, 42 );
EXPECT( sv.value() == 42 );
EXPECT( csv.value() == 42 );
EXPECT( std::move( sv ).value() == 42 );
EXPECT( std::move( csv ).value() == 42 );
}
CASE( "status_value<>: Allows to observe its value (operator*)" )
{
status_value<int, int> sv( 7, 42 );
status_value<int, int> const csv( 7, 42 );
EXPECT( *sv == 42 );
EXPECT( *csv == 42 );
EXPECT( *std::move( sv ) == 42 );
EXPECT( *std::move( csv ) == 42 );
}
CASE( "status_value<>: Allows to observe its value (operator->)" )
{
struct V { int i = 42; } v;
status_value<int, V> sv( 7, v );
status_value<int, V> const csv( 7, v );
EXPECT( sv->i == 42 );
EXPECT( csv->i == 42 );
EXPECT( std::move( sv )->i == 42 );
EXPECT( std::move( csv )->i == 42 );
}
CASE( "status_value<>: Throws when observing non-engaged (value())" )
{
#if ! nsstsv_CONFIG_NO_EXCEPTIONS
SETUP("") {
status_value<int, int> sv( 7 );
status_value<int, int> const csv( 7 );
SECTION("for l-value reference")
{
EXPECT_THROWS( sv.value() );
EXPECT_THROWS( csv.value() );
EXPECT_THROWS_AS( sv.value(), std::logic_error );
EXPECT_THROWS_AS( csv.value(), std::logic_error );
EXPECT_THROWS_AS( sv.value(), bad_status_value_access<int> );
EXPECT_THROWS_AS( csv.value(), bad_status_value_access<const int> );
}
SECTION("for r-value reference (throws)")
{
EXPECT_THROWS( std::move( sv ).value() );
EXPECT_THROWS( std::move( csv ).value() );
}
SECTION("for r-value reference (throws-as)")
{
EXPECT_THROWS_AS( std::move( sv ).value(), bad_status_value_access<int> );
EXPECT_THROWS_AS( std::move( csv ).value(), bad_status_value_access<const int> );
}
SECTION("throw with expected status value")
{
try { sv.value(); } catch ( bad_status_value_access< int> const & e ) { EXPECT( e.status() == 7 ); }
try { csv.value(); } catch ( bad_status_value_access<const int> const & e ) { EXPECT( e.status() == 7 ); }
}}
#else
EXPECT( !!"status_value: exceptions not available (nsstsv_CONFIG_NO_EXCEPTIONS)" );
#endif
}
CASE( "status_value<>: Throws when observing non-engaged (operator*())" )
{
#if ! nsstsv_CONFIG_NO_EXCEPTIONS
SETUP("") {
status_value<int, int> sv( 7 );
status_value<int, int> const csv( 7 );
SECTION("for l-value reference")
{
EXPECT_THROWS( *sv );
EXPECT_THROWS( *csv );
EXPECT_THROWS_AS( *sv, std::logic_error );
EXPECT_THROWS_AS( *csv, std::logic_error );
EXPECT_THROWS_AS( *sv, bad_status_value_access<int> );
EXPECT_THROWS_AS( *csv, bad_status_value_access<const int> );
}
SECTION("for r-value reference (throws)")
{
EXPECT_THROWS( *std::move( sv ) );
EXPECT_THROWS( *std::move( csv ) );
}
SECTION("for r-value reference (throws-as)")
{
EXPECT_THROWS_AS( *std::move( sv ), bad_status_value_access<int> );
EXPECT_THROWS_AS( *std::move( csv ), bad_status_value_access<const int> );
}
SECTION("throw with expected status value")
{
try { *sv; } catch ( bad_status_value_access< int> const & e ) { EXPECT( e.status() == 7 ); }
try { *csv; } catch ( bad_status_value_access<const int> const & e ) { EXPECT( e.status() == 7 ); }
}}
#else
EXPECT( !!"status_value: exceptions not available (nsstsv_CONFIG_NO_EXCEPTIONS)" );
#endif
}
CASE( "status_value<>: Throws when observing non-engaged (operator->())" )
{
#if ! nsstsv_CONFIG_NO_EXCEPTIONS
SETUP("") {
struct V { int i = 42; };
status_value<int, V> sv( 7 );
status_value<int, V> const csv( 7 );
SECTION("for l-value reference")
{
EXPECT_THROWS( sv->i );
EXPECT_THROWS( csv->i );
EXPECT_THROWS_AS( sv->i, std::logic_error );
EXPECT_THROWS_AS( csv->i, std::logic_error );
EXPECT_THROWS_AS( sv->i, bad_status_value_access<int> );
EXPECT_THROWS_AS( csv->i, bad_status_value_access<const int> );
// EXPECT_THROWS_WITH( sv->i, 7 );
// EXPECT_THROWS_WITH( csv->i, 7 );
}
SECTION("for r-value reference (throws)")
{
EXPECT_THROWS( std::move( sv )->i );
EXPECT_THROWS( std::move( csv )->i );
// EXPECT_THROWS_WITH( std::move( sv )->i, 7 );
// EXPECT_THROWS_WITH( std::move( csv )->i, 7 );
}
SECTION("for r-value reference (throws-as)")
{
EXPECT_THROWS_AS( std::move( sv )->i, bad_status_value_access<int> );
EXPECT_THROWS_AS( std::move( csv )->i, bad_status_value_access<const int> );
// EXPECT_THROWS_WITH( std::move( sv )->i, 7 );
// EXPECT_THROWS_WITH( std::move( csv )->i, 7 );
}
SECTION("throw with expected status value")
{
try { use( sv->i ); } catch ( bad_status_value_access< int> const & e ) { EXPECT( e.status() == 7 ); }
try { use( csv->i ); } catch ( bad_status_value_access<const int> const & e ) { EXPECT( e.status() == 7 ); }
}}
#else
EXPECT( !!"status_value: exceptions not available (nsstsv_CONFIG_NO_EXCEPTIONS)" );
#endif
}
CASE( "tweak header: reads tweak header if supported " "[tweak]" )
{
#if nsstsv_HAVE_TWEAK_HEADER
EXPECT( NSSTSV_TWEAK_VALUE == 42 );
#else
EXPECT( !!"Tweak header is not available (nsstsv_HAVE_TWEAK_HEADER: 0)." );
#endif
}
// -----------------------------------------------------------------------
// test driver:
int main( int argc, char * argv[] )
{
return lest::run( specification, argc, argv );
}
#if 0
//
cl -nologo -W3 -wd4814 -EHsc -Dnsstsv_CONFIG_CONFIRMS_COMPILATION_ERRORS=0 -Dlest_FEATURE_AUTO_REGISTER=1 -I../include status_value.t.cpp && status_value.t --pass
cl -nologo -Wall -wd4814 -EHsc -Dnsstsv_CONFIG_CONFIRMS_COMPILATION_ERRORS=0 -Dlest_FEATURE_AUTO_REGISTER=1 -I../include status_value.t.cpp && status_value.t --pass
g++ -Wall -Wextra -std=c++03 -Wno-unused-parameter -Dlest_FEATURE_AUTO_REGISTER=1 -I../include -o status_value.t.exe status_value.t.cpp && status_value.t --pass
g++ -Wall -Wextra -std=c++11 -Wno-unused-parameter -Dlest_FEATURE_AUTO_REGISTER=1 -I../include -o status_value.t.exe status_value.t.cpp && status_value.t --pass
g++ -Wall -Wextra -std=c++14 -Wno-unused-parameter -Dlest_FEATURE_AUTO_REGISTER=1 -I../include -o status_value.t.exe status_value.t.cpp && status_value.t --pass
g++ -Wall -Wextra -std=c++1y -Wno-unused-parameter -Dlest_FEATURE_AUTO_REGISTER=1 -I../include -o status_value.t.exe status_value.t.cpp && status_value.t --pass
#endif // 0
|
//
// Created by Mingkai Chen on 2017-09-02.
//
#include <vector>
#include <boost/python.hpp>
namespace bp = boost::python;
#pragma once
#ifndef ROCBOOST_EMBEDDING_HPP
#define ROCBOOST_EMBEDDING_HPP
bp::tuple pickle (std::string data_path);
void mnist_imageout (std::vector<std::vector<double> >& imgdata,
std::vector<size_t> inner_dims, size_t n_chains, size_t n_samples);
#endif /* ROCBOOST_EMBEDDING_HPP */
|
_ln: 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: 83 e4 f0 and $0xfffffff0,%esp
6: 83 ec 10 sub $0x10,%esp
if(argc != 3){
9: 83 7d 08 03 cmpl $0x3,0x8(%ebp)
d: 74 19 je 28 <main+0x28>
printf(2, "Usage: ln old new\n");
f: c7 44 24 04 f8 0b 00 movl $0xbf8,0x4(%esp)
16: 00
17: c7 04 24 02 00 00 00 movl $0x2,(%esp)
1e: e8 66 04 00 00 call 489 <printf>
exit();
23: e8 b9 02 00 00 call 2e1 <exit>
}
if(link(argv[1], argv[2]) < 0)
28: 8b 45 0c mov 0xc(%ebp),%eax
2b: 83 c0 08 add $0x8,%eax
2e: 8b 10 mov (%eax),%edx
30: 8b 45 0c mov 0xc(%ebp),%eax
33: 83 c0 04 add $0x4,%eax
36: 8b 00 mov (%eax),%eax
38: 89 54 24 04 mov %edx,0x4(%esp)
3c: 89 04 24 mov %eax,(%esp)
3f: e8 fd 02 00 00 call 341 <link>
44: 85 c0 test %eax,%eax
46: 79 2c jns 74 <main+0x74>
printf(2, "link %s %s: failed\n", argv[1], argv[2]);
48: 8b 45 0c mov 0xc(%ebp),%eax
4b: 83 c0 08 add $0x8,%eax
4e: 8b 10 mov (%eax),%edx
50: 8b 45 0c mov 0xc(%ebp),%eax
53: 83 c0 04 add $0x4,%eax
56: 8b 00 mov (%eax),%eax
58: 89 54 24 0c mov %edx,0xc(%esp)
5c: 89 44 24 08 mov %eax,0x8(%esp)
60: c7 44 24 04 0b 0c 00 movl $0xc0b,0x4(%esp)
67: 00
68: c7 04 24 02 00 00 00 movl $0x2,(%esp)
6f: e8 15 04 00 00 call 489 <printf>
exit();
74: e8 68 02 00 00 call 2e1 <exit>
00000079 <stosb>:
"cc");
}
static inline void
stosb(void *addr, int data, int cnt)
{
79: 55 push %ebp
7a: 89 e5 mov %esp,%ebp
7c: 57 push %edi
7d: 53 push %ebx
asm volatile("cld; rep stosb" :
7e: 8b 4d 08 mov 0x8(%ebp),%ecx
81: 8b 55 10 mov 0x10(%ebp),%edx
84: 8b 45 0c mov 0xc(%ebp),%eax
87: 89 cb mov %ecx,%ebx
89: 89 df mov %ebx,%edi
8b: 89 d1 mov %edx,%ecx
8d: fc cld
8e: f3 aa rep stos %al,%es:(%edi)
90: 89 ca mov %ecx,%edx
92: 89 fb mov %edi,%ebx
94: 89 5d 08 mov %ebx,0x8(%ebp)
97: 89 55 10 mov %edx,0x10(%ebp)
"=D" (addr), "=c" (cnt) :
"0" (addr), "1" (cnt), "a" (data) :
"memory", "cc");
}
9a: 5b pop %ebx
9b: 5f pop %edi
9c: 5d pop %ebp
9d: c3 ret
0000009e <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
9e: 55 push %ebp
9f: 89 e5 mov %esp,%ebp
a1: 83 ec 10 sub $0x10,%esp
char *os;
os = s;
a4: 8b 45 08 mov 0x8(%ebp),%eax
a7: 89 45 fc mov %eax,-0x4(%ebp)
while((*s++ = *t++) != 0)
aa: 90 nop
ab: 8b 45 08 mov 0x8(%ebp),%eax
ae: 8d 50 01 lea 0x1(%eax),%edx
b1: 89 55 08 mov %edx,0x8(%ebp)
b4: 8b 55 0c mov 0xc(%ebp),%edx
b7: 8d 4a 01 lea 0x1(%edx),%ecx
ba: 89 4d 0c mov %ecx,0xc(%ebp)
bd: 0f b6 12 movzbl (%edx),%edx
c0: 88 10 mov %dl,(%eax)
c2: 0f b6 00 movzbl (%eax),%eax
c5: 84 c0 test %al,%al
c7: 75 e2 jne ab <strcpy+0xd>
;
return os;
c9: 8b 45 fc mov -0x4(%ebp),%eax
}
cc: c9 leave
cd: c3 ret
000000ce <strcmp>:
int
strcmp(const char *p, const char *q)
{
ce: 55 push %ebp
cf: 89 e5 mov %esp,%ebp
while(*p && *p == *q)
d1: eb 08 jmp db <strcmp+0xd>
p++, q++;
d3: 83 45 08 01 addl $0x1,0x8(%ebp)
d7: 83 45 0c 01 addl $0x1,0xc(%ebp)
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
db: 8b 45 08 mov 0x8(%ebp),%eax
de: 0f b6 00 movzbl (%eax),%eax
e1: 84 c0 test %al,%al
e3: 74 10 je f5 <strcmp+0x27>
e5: 8b 45 08 mov 0x8(%ebp),%eax
e8: 0f b6 10 movzbl (%eax),%edx
eb: 8b 45 0c mov 0xc(%ebp),%eax
ee: 0f b6 00 movzbl (%eax),%eax
f1: 38 c2 cmp %al,%dl
f3: 74 de je d3 <strcmp+0x5>
p++, q++;
return (uchar)*p - (uchar)*q;
f5: 8b 45 08 mov 0x8(%ebp),%eax
f8: 0f b6 00 movzbl (%eax),%eax
fb: 0f b6 d0 movzbl %al,%edx
fe: 8b 45 0c mov 0xc(%ebp),%eax
101: 0f b6 00 movzbl (%eax),%eax
104: 0f b6 c0 movzbl %al,%eax
107: 29 c2 sub %eax,%edx
109: 89 d0 mov %edx,%eax
}
10b: 5d pop %ebp
10c: c3 ret
0000010d <strlen>:
uint
strlen(char *s)
{
10d: 55 push %ebp
10e: 89 e5 mov %esp,%ebp
110: 83 ec 10 sub $0x10,%esp
int n;
for(n = 0; s[n]; n++)
113: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
11a: eb 04 jmp 120 <strlen+0x13>
11c: 83 45 fc 01 addl $0x1,-0x4(%ebp)
120: 8b 55 fc mov -0x4(%ebp),%edx
123: 8b 45 08 mov 0x8(%ebp),%eax
126: 01 d0 add %edx,%eax
128: 0f b6 00 movzbl (%eax),%eax
12b: 84 c0 test %al,%al
12d: 75 ed jne 11c <strlen+0xf>
;
return n;
12f: 8b 45 fc mov -0x4(%ebp),%eax
}
132: c9 leave
133: c3 ret
00000134 <memset>:
void*
memset(void *dst, int c, uint n)
{
134: 55 push %ebp
135: 89 e5 mov %esp,%ebp
137: 83 ec 0c sub $0xc,%esp
stosb(dst, c, n);
13a: 8b 45 10 mov 0x10(%ebp),%eax
13d: 89 44 24 08 mov %eax,0x8(%esp)
141: 8b 45 0c mov 0xc(%ebp),%eax
144: 89 44 24 04 mov %eax,0x4(%esp)
148: 8b 45 08 mov 0x8(%ebp),%eax
14b: 89 04 24 mov %eax,(%esp)
14e: e8 26 ff ff ff call 79 <stosb>
return dst;
153: 8b 45 08 mov 0x8(%ebp),%eax
}
156: c9 leave
157: c3 ret
00000158 <strchr>:
char*
strchr(const char *s, char c)
{
158: 55 push %ebp
159: 89 e5 mov %esp,%ebp
15b: 83 ec 04 sub $0x4,%esp
15e: 8b 45 0c mov 0xc(%ebp),%eax
161: 88 45 fc mov %al,-0x4(%ebp)
for(; *s; s++)
164: eb 14 jmp 17a <strchr+0x22>
if(*s == c)
166: 8b 45 08 mov 0x8(%ebp),%eax
169: 0f b6 00 movzbl (%eax),%eax
16c: 3a 45 fc cmp -0x4(%ebp),%al
16f: 75 05 jne 176 <strchr+0x1e>
return (char*)s;
171: 8b 45 08 mov 0x8(%ebp),%eax
174: eb 13 jmp 189 <strchr+0x31>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
176: 83 45 08 01 addl $0x1,0x8(%ebp)
17a: 8b 45 08 mov 0x8(%ebp),%eax
17d: 0f b6 00 movzbl (%eax),%eax
180: 84 c0 test %al,%al
182: 75 e2 jne 166 <strchr+0xe>
if(*s == c)
return (char*)s;
return 0;
184: b8 00 00 00 00 mov $0x0,%eax
}
189: c9 leave
18a: c3 ret
0000018b <gets>:
char*
gets(char *buf, int max)
{
18b: 55 push %ebp
18c: 89 e5 mov %esp,%ebp
18e: 83 ec 28 sub $0x28,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
191: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
198: eb 4c jmp 1e6 <gets+0x5b>
cc = read(0, &c, 1);
19a: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
1a1: 00
1a2: 8d 45 ef lea -0x11(%ebp),%eax
1a5: 89 44 24 04 mov %eax,0x4(%esp)
1a9: c7 04 24 00 00 00 00 movl $0x0,(%esp)
1b0: e8 44 01 00 00 call 2f9 <read>
1b5: 89 45 f0 mov %eax,-0x10(%ebp)
if(cc < 1)
1b8: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
1bc: 7f 02 jg 1c0 <gets+0x35>
break;
1be: eb 31 jmp 1f1 <gets+0x66>
buf[i++] = c;
1c0: 8b 45 f4 mov -0xc(%ebp),%eax
1c3: 8d 50 01 lea 0x1(%eax),%edx
1c6: 89 55 f4 mov %edx,-0xc(%ebp)
1c9: 89 c2 mov %eax,%edx
1cb: 8b 45 08 mov 0x8(%ebp),%eax
1ce: 01 c2 add %eax,%edx
1d0: 0f b6 45 ef movzbl -0x11(%ebp),%eax
1d4: 88 02 mov %al,(%edx)
if(c == '\n' || c == '\r')
1d6: 0f b6 45 ef movzbl -0x11(%ebp),%eax
1da: 3c 0a cmp $0xa,%al
1dc: 74 13 je 1f1 <gets+0x66>
1de: 0f b6 45 ef movzbl -0x11(%ebp),%eax
1e2: 3c 0d cmp $0xd,%al
1e4: 74 0b je 1f1 <gets+0x66>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
1e6: 8b 45 f4 mov -0xc(%ebp),%eax
1e9: 83 c0 01 add $0x1,%eax
1ec: 3b 45 0c cmp 0xc(%ebp),%eax
1ef: 7c a9 jl 19a <gets+0xf>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
1f1: 8b 55 f4 mov -0xc(%ebp),%edx
1f4: 8b 45 08 mov 0x8(%ebp),%eax
1f7: 01 d0 add %edx,%eax
1f9: c6 00 00 movb $0x0,(%eax)
return buf;
1fc: 8b 45 08 mov 0x8(%ebp),%eax
}
1ff: c9 leave
200: c3 ret
00000201 <stat>:
int
stat(char *n, struct stat *st)
{
201: 55 push %ebp
202: 89 e5 mov %esp,%ebp
204: 83 ec 28 sub $0x28,%esp
int fd;
int r;
fd = open(n, O_RDONLY);
207: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
20e: 00
20f: 8b 45 08 mov 0x8(%ebp),%eax
212: 89 04 24 mov %eax,(%esp)
215: e8 07 01 00 00 call 321 <open>
21a: 89 45 f4 mov %eax,-0xc(%ebp)
if(fd < 0)
21d: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
221: 79 07 jns 22a <stat+0x29>
return -1;
223: b8 ff ff ff ff mov $0xffffffff,%eax
228: eb 23 jmp 24d <stat+0x4c>
r = fstat(fd, st);
22a: 8b 45 0c mov 0xc(%ebp),%eax
22d: 89 44 24 04 mov %eax,0x4(%esp)
231: 8b 45 f4 mov -0xc(%ebp),%eax
234: 89 04 24 mov %eax,(%esp)
237: e8 fd 00 00 00 call 339 <fstat>
23c: 89 45 f0 mov %eax,-0x10(%ebp)
close(fd);
23f: 8b 45 f4 mov -0xc(%ebp),%eax
242: 89 04 24 mov %eax,(%esp)
245: e8 bf 00 00 00 call 309 <close>
return r;
24a: 8b 45 f0 mov -0x10(%ebp),%eax
}
24d: c9 leave
24e: c3 ret
0000024f <atoi>:
int
atoi(const char *s)
{
24f: 55 push %ebp
250: 89 e5 mov %esp,%ebp
252: 83 ec 10 sub $0x10,%esp
int n;
n = 0;
255: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
while('0' <= *s && *s <= '9')
25c: eb 25 jmp 283 <atoi+0x34>
n = n*10 + *s++ - '0';
25e: 8b 55 fc mov -0x4(%ebp),%edx
261: 89 d0 mov %edx,%eax
263: c1 e0 02 shl $0x2,%eax
266: 01 d0 add %edx,%eax
268: 01 c0 add %eax,%eax
26a: 89 c1 mov %eax,%ecx
26c: 8b 45 08 mov 0x8(%ebp),%eax
26f: 8d 50 01 lea 0x1(%eax),%edx
272: 89 55 08 mov %edx,0x8(%ebp)
275: 0f b6 00 movzbl (%eax),%eax
278: 0f be c0 movsbl %al,%eax
27b: 01 c8 add %ecx,%eax
27d: 83 e8 30 sub $0x30,%eax
280: 89 45 fc mov %eax,-0x4(%ebp)
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
283: 8b 45 08 mov 0x8(%ebp),%eax
286: 0f b6 00 movzbl (%eax),%eax
289: 3c 2f cmp $0x2f,%al
28b: 7e 0a jle 297 <atoi+0x48>
28d: 8b 45 08 mov 0x8(%ebp),%eax
290: 0f b6 00 movzbl (%eax),%eax
293: 3c 39 cmp $0x39,%al
295: 7e c7 jle 25e <atoi+0xf>
n = n*10 + *s++ - '0';
return n;
297: 8b 45 fc mov -0x4(%ebp),%eax
}
29a: c9 leave
29b: c3 ret
0000029c <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
29c: 55 push %ebp
29d: 89 e5 mov %esp,%ebp
29f: 83 ec 10 sub $0x10,%esp
char *dst, *src;
dst = vdst;
2a2: 8b 45 08 mov 0x8(%ebp),%eax
2a5: 89 45 fc mov %eax,-0x4(%ebp)
src = vsrc;
2a8: 8b 45 0c mov 0xc(%ebp),%eax
2ab: 89 45 f8 mov %eax,-0x8(%ebp)
while(n-- > 0)
2ae: eb 17 jmp 2c7 <memmove+0x2b>
*dst++ = *src++;
2b0: 8b 45 fc mov -0x4(%ebp),%eax
2b3: 8d 50 01 lea 0x1(%eax),%edx
2b6: 89 55 fc mov %edx,-0x4(%ebp)
2b9: 8b 55 f8 mov -0x8(%ebp),%edx
2bc: 8d 4a 01 lea 0x1(%edx),%ecx
2bf: 89 4d f8 mov %ecx,-0x8(%ebp)
2c2: 0f b6 12 movzbl (%edx),%edx
2c5: 88 10 mov %dl,(%eax)
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
2c7: 8b 45 10 mov 0x10(%ebp),%eax
2ca: 8d 50 ff lea -0x1(%eax),%edx
2cd: 89 55 10 mov %edx,0x10(%ebp)
2d0: 85 c0 test %eax,%eax
2d2: 7f dc jg 2b0 <memmove+0x14>
*dst++ = *src++;
return vdst;
2d4: 8b 45 08 mov 0x8(%ebp),%eax
}
2d7: c9 leave
2d8: c3 ret
000002d9 <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
2d9: b8 01 00 00 00 mov $0x1,%eax
2de: cd 40 int $0x40
2e0: c3 ret
000002e1 <exit>:
SYSCALL(exit)
2e1: b8 02 00 00 00 mov $0x2,%eax
2e6: cd 40 int $0x40
2e8: c3 ret
000002e9 <wait>:
SYSCALL(wait)
2e9: b8 03 00 00 00 mov $0x3,%eax
2ee: cd 40 int $0x40
2f0: c3 ret
000002f1 <pipe>:
SYSCALL(pipe)
2f1: b8 04 00 00 00 mov $0x4,%eax
2f6: cd 40 int $0x40
2f8: c3 ret
000002f9 <read>:
SYSCALL(read)
2f9: b8 05 00 00 00 mov $0x5,%eax
2fe: cd 40 int $0x40
300: c3 ret
00000301 <write>:
SYSCALL(write)
301: b8 10 00 00 00 mov $0x10,%eax
306: cd 40 int $0x40
308: c3 ret
00000309 <close>:
SYSCALL(close)
309: b8 15 00 00 00 mov $0x15,%eax
30e: cd 40 int $0x40
310: c3 ret
00000311 <kill>:
SYSCALL(kill)
311: b8 06 00 00 00 mov $0x6,%eax
316: cd 40 int $0x40
318: c3 ret
00000319 <exec>:
SYSCALL(exec)
319: b8 07 00 00 00 mov $0x7,%eax
31e: cd 40 int $0x40
320: c3 ret
00000321 <open>:
SYSCALL(open)
321: b8 0f 00 00 00 mov $0xf,%eax
326: cd 40 int $0x40
328: c3 ret
00000329 <mknod>:
SYSCALL(mknod)
329: b8 11 00 00 00 mov $0x11,%eax
32e: cd 40 int $0x40
330: c3 ret
00000331 <unlink>:
SYSCALL(unlink)
331: b8 12 00 00 00 mov $0x12,%eax
336: cd 40 int $0x40
338: c3 ret
00000339 <fstat>:
SYSCALL(fstat)
339: b8 08 00 00 00 mov $0x8,%eax
33e: cd 40 int $0x40
340: c3 ret
00000341 <link>:
SYSCALL(link)
341: b8 13 00 00 00 mov $0x13,%eax
346: cd 40 int $0x40
348: c3 ret
00000349 <mkdir>:
SYSCALL(mkdir)
349: b8 14 00 00 00 mov $0x14,%eax
34e: cd 40 int $0x40
350: c3 ret
00000351 <chdir>:
SYSCALL(chdir)
351: b8 09 00 00 00 mov $0x9,%eax
356: cd 40 int $0x40
358: c3 ret
00000359 <dup>:
SYSCALL(dup)
359: b8 0a 00 00 00 mov $0xa,%eax
35e: cd 40 int $0x40
360: c3 ret
00000361 <getpid>:
SYSCALL(getpid)
361: b8 0b 00 00 00 mov $0xb,%eax
366: cd 40 int $0x40
368: c3 ret
00000369 <sbrk>:
SYSCALL(sbrk)
369: b8 0c 00 00 00 mov $0xc,%eax
36e: cd 40 int $0x40
370: c3 ret
00000371 <sleep>:
SYSCALL(sleep)
371: b8 0d 00 00 00 mov $0xd,%eax
376: cd 40 int $0x40
378: c3 ret
00000379 <uptime>:
SYSCALL(uptime)
379: b8 0e 00 00 00 mov $0xe,%eax
37e: cd 40 int $0x40
380: c3 ret
00000381 <clone>:
SYSCALL(clone)
381: b8 16 00 00 00 mov $0x16,%eax
386: cd 40 int $0x40
388: c3 ret
00000389 <texit>:
SYSCALL(texit)
389: b8 17 00 00 00 mov $0x17,%eax
38e: cd 40 int $0x40
390: c3 ret
00000391 <tsleep>:
SYSCALL(tsleep)
391: b8 18 00 00 00 mov $0x18,%eax
396: cd 40 int $0x40
398: c3 ret
00000399 <twakeup>:
SYSCALL(twakeup)
399: b8 19 00 00 00 mov $0x19,%eax
39e: cd 40 int $0x40
3a0: c3 ret
000003a1 <test>:
SYSCALL(test)
3a1: b8 1a 00 00 00 mov $0x1a,%eax
3a6: cd 40 int $0x40
3a8: c3 ret
000003a9 <putc>:
#include "stat.h"
#include "user.h"
static void
putc(int fd, char c)
{
3a9: 55 push %ebp
3aa: 89 e5 mov %esp,%ebp
3ac: 83 ec 18 sub $0x18,%esp
3af: 8b 45 0c mov 0xc(%ebp),%eax
3b2: 88 45 f4 mov %al,-0xc(%ebp)
write(fd, &c, 1);
3b5: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
3bc: 00
3bd: 8d 45 f4 lea -0xc(%ebp),%eax
3c0: 89 44 24 04 mov %eax,0x4(%esp)
3c4: 8b 45 08 mov 0x8(%ebp),%eax
3c7: 89 04 24 mov %eax,(%esp)
3ca: e8 32 ff ff ff call 301 <write>
}
3cf: c9 leave
3d0: c3 ret
000003d1 <printint>:
static void
printint(int fd, int xx, int base, int sgn)
{
3d1: 55 push %ebp
3d2: 89 e5 mov %esp,%ebp
3d4: 56 push %esi
3d5: 53 push %ebx
3d6: 83 ec 30 sub $0x30,%esp
static char digits[] = "0123456789ABCDEF";
char buf[16];
int i, neg;
uint x;
neg = 0;
3d9: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
if(sgn && xx < 0){
3e0: 83 7d 14 00 cmpl $0x0,0x14(%ebp)
3e4: 74 17 je 3fd <printint+0x2c>
3e6: 83 7d 0c 00 cmpl $0x0,0xc(%ebp)
3ea: 79 11 jns 3fd <printint+0x2c>
neg = 1;
3ec: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp)
x = -xx;
3f3: 8b 45 0c mov 0xc(%ebp),%eax
3f6: f7 d8 neg %eax
3f8: 89 45 ec mov %eax,-0x14(%ebp)
3fb: eb 06 jmp 403 <printint+0x32>
} else {
x = xx;
3fd: 8b 45 0c mov 0xc(%ebp),%eax
400: 89 45 ec mov %eax,-0x14(%ebp)
}
i = 0;
403: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
do{
buf[i++] = digits[x % base];
40a: 8b 4d f4 mov -0xc(%ebp),%ecx
40d: 8d 41 01 lea 0x1(%ecx),%eax
410: 89 45 f4 mov %eax,-0xc(%ebp)
413: 8b 5d 10 mov 0x10(%ebp),%ebx
416: 8b 45 ec mov -0x14(%ebp),%eax
419: ba 00 00 00 00 mov $0x0,%edx
41e: f7 f3 div %ebx
420: 89 d0 mov %edx,%eax
422: 0f b6 80 58 10 00 00 movzbl 0x1058(%eax),%eax
429: 88 44 0d dc mov %al,-0x24(%ebp,%ecx,1)
}while((x /= base) != 0);
42d: 8b 75 10 mov 0x10(%ebp),%esi
430: 8b 45 ec mov -0x14(%ebp),%eax
433: ba 00 00 00 00 mov $0x0,%edx
438: f7 f6 div %esi
43a: 89 45 ec mov %eax,-0x14(%ebp)
43d: 83 7d ec 00 cmpl $0x0,-0x14(%ebp)
441: 75 c7 jne 40a <printint+0x39>
if(neg)
443: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
447: 74 10 je 459 <printint+0x88>
buf[i++] = '-';
449: 8b 45 f4 mov -0xc(%ebp),%eax
44c: 8d 50 01 lea 0x1(%eax),%edx
44f: 89 55 f4 mov %edx,-0xc(%ebp)
452: c6 44 05 dc 2d movb $0x2d,-0x24(%ebp,%eax,1)
while(--i >= 0)
457: eb 1f jmp 478 <printint+0xa7>
459: eb 1d jmp 478 <printint+0xa7>
putc(fd, buf[i]);
45b: 8d 55 dc lea -0x24(%ebp),%edx
45e: 8b 45 f4 mov -0xc(%ebp),%eax
461: 01 d0 add %edx,%eax
463: 0f b6 00 movzbl (%eax),%eax
466: 0f be c0 movsbl %al,%eax
469: 89 44 24 04 mov %eax,0x4(%esp)
46d: 8b 45 08 mov 0x8(%ebp),%eax
470: 89 04 24 mov %eax,(%esp)
473: e8 31 ff ff ff call 3a9 <putc>
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
478: 83 6d f4 01 subl $0x1,-0xc(%ebp)
47c: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
480: 79 d9 jns 45b <printint+0x8a>
putc(fd, buf[i]);
}
482: 83 c4 30 add $0x30,%esp
485: 5b pop %ebx
486: 5e pop %esi
487: 5d pop %ebp
488: c3 ret
00000489 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
489: 55 push %ebp
48a: 89 e5 mov %esp,%ebp
48c: 83 ec 38 sub $0x38,%esp
char *s;
int c, i, state;
uint *ap;
state = 0;
48f: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp)
ap = (uint*)(void*)&fmt + 1;
496: 8d 45 0c lea 0xc(%ebp),%eax
499: 83 c0 04 add $0x4,%eax
49c: 89 45 e8 mov %eax,-0x18(%ebp)
for(i = 0; fmt[i]; i++){
49f: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
4a6: e9 7c 01 00 00 jmp 627 <printf+0x19e>
c = fmt[i] & 0xff;
4ab: 8b 55 0c mov 0xc(%ebp),%edx
4ae: 8b 45 f0 mov -0x10(%ebp),%eax
4b1: 01 d0 add %edx,%eax
4b3: 0f b6 00 movzbl (%eax),%eax
4b6: 0f be c0 movsbl %al,%eax
4b9: 25 ff 00 00 00 and $0xff,%eax
4be: 89 45 e4 mov %eax,-0x1c(%ebp)
if(state == 0){
4c1: 83 7d ec 00 cmpl $0x0,-0x14(%ebp)
4c5: 75 2c jne 4f3 <printf+0x6a>
if(c == '%'){
4c7: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp)
4cb: 75 0c jne 4d9 <printf+0x50>
state = '%';
4cd: c7 45 ec 25 00 00 00 movl $0x25,-0x14(%ebp)
4d4: e9 4a 01 00 00 jmp 623 <printf+0x19a>
} else {
putc(fd, c);
4d9: 8b 45 e4 mov -0x1c(%ebp),%eax
4dc: 0f be c0 movsbl %al,%eax
4df: 89 44 24 04 mov %eax,0x4(%esp)
4e3: 8b 45 08 mov 0x8(%ebp),%eax
4e6: 89 04 24 mov %eax,(%esp)
4e9: e8 bb fe ff ff call 3a9 <putc>
4ee: e9 30 01 00 00 jmp 623 <printf+0x19a>
}
} else if(state == '%'){
4f3: 83 7d ec 25 cmpl $0x25,-0x14(%ebp)
4f7: 0f 85 26 01 00 00 jne 623 <printf+0x19a>
if(c == 'd'){
4fd: 83 7d e4 64 cmpl $0x64,-0x1c(%ebp)
501: 75 2d jne 530 <printf+0xa7>
printint(fd, *ap, 10, 1);
503: 8b 45 e8 mov -0x18(%ebp),%eax
506: 8b 00 mov (%eax),%eax
508: c7 44 24 0c 01 00 00 movl $0x1,0xc(%esp)
50f: 00
510: c7 44 24 08 0a 00 00 movl $0xa,0x8(%esp)
517: 00
518: 89 44 24 04 mov %eax,0x4(%esp)
51c: 8b 45 08 mov 0x8(%ebp),%eax
51f: 89 04 24 mov %eax,(%esp)
522: e8 aa fe ff ff call 3d1 <printint>
ap++;
527: 83 45 e8 04 addl $0x4,-0x18(%ebp)
52b: e9 ec 00 00 00 jmp 61c <printf+0x193>
} else if(c == 'x' || c == 'p'){
530: 83 7d e4 78 cmpl $0x78,-0x1c(%ebp)
534: 74 06 je 53c <printf+0xb3>
536: 83 7d e4 70 cmpl $0x70,-0x1c(%ebp)
53a: 75 2d jne 569 <printf+0xe0>
printint(fd, *ap, 16, 0);
53c: 8b 45 e8 mov -0x18(%ebp),%eax
53f: 8b 00 mov (%eax),%eax
541: c7 44 24 0c 00 00 00 movl $0x0,0xc(%esp)
548: 00
549: c7 44 24 08 10 00 00 movl $0x10,0x8(%esp)
550: 00
551: 89 44 24 04 mov %eax,0x4(%esp)
555: 8b 45 08 mov 0x8(%ebp),%eax
558: 89 04 24 mov %eax,(%esp)
55b: e8 71 fe ff ff call 3d1 <printint>
ap++;
560: 83 45 e8 04 addl $0x4,-0x18(%ebp)
564: e9 b3 00 00 00 jmp 61c <printf+0x193>
} else if(c == 's'){
569: 83 7d e4 73 cmpl $0x73,-0x1c(%ebp)
56d: 75 45 jne 5b4 <printf+0x12b>
s = (char*)*ap;
56f: 8b 45 e8 mov -0x18(%ebp),%eax
572: 8b 00 mov (%eax),%eax
574: 89 45 f4 mov %eax,-0xc(%ebp)
ap++;
577: 83 45 e8 04 addl $0x4,-0x18(%ebp)
if(s == 0)
57b: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
57f: 75 09 jne 58a <printf+0x101>
s = "(null)";
581: c7 45 f4 1f 0c 00 00 movl $0xc1f,-0xc(%ebp)
while(*s != 0){
588: eb 1e jmp 5a8 <printf+0x11f>
58a: eb 1c jmp 5a8 <printf+0x11f>
putc(fd, *s);
58c: 8b 45 f4 mov -0xc(%ebp),%eax
58f: 0f b6 00 movzbl (%eax),%eax
592: 0f be c0 movsbl %al,%eax
595: 89 44 24 04 mov %eax,0x4(%esp)
599: 8b 45 08 mov 0x8(%ebp),%eax
59c: 89 04 24 mov %eax,(%esp)
59f: e8 05 fe ff ff call 3a9 <putc>
s++;
5a4: 83 45 f4 01 addl $0x1,-0xc(%ebp)
} else if(c == 's'){
s = (char*)*ap;
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
5a8: 8b 45 f4 mov -0xc(%ebp),%eax
5ab: 0f b6 00 movzbl (%eax),%eax
5ae: 84 c0 test %al,%al
5b0: 75 da jne 58c <printf+0x103>
5b2: eb 68 jmp 61c <printf+0x193>
putc(fd, *s);
s++;
}
} else if(c == 'c'){
5b4: 83 7d e4 63 cmpl $0x63,-0x1c(%ebp)
5b8: 75 1d jne 5d7 <printf+0x14e>
putc(fd, *ap);
5ba: 8b 45 e8 mov -0x18(%ebp),%eax
5bd: 8b 00 mov (%eax),%eax
5bf: 0f be c0 movsbl %al,%eax
5c2: 89 44 24 04 mov %eax,0x4(%esp)
5c6: 8b 45 08 mov 0x8(%ebp),%eax
5c9: 89 04 24 mov %eax,(%esp)
5cc: e8 d8 fd ff ff call 3a9 <putc>
ap++;
5d1: 83 45 e8 04 addl $0x4,-0x18(%ebp)
5d5: eb 45 jmp 61c <printf+0x193>
} else if(c == '%'){
5d7: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp)
5db: 75 17 jne 5f4 <printf+0x16b>
putc(fd, c);
5dd: 8b 45 e4 mov -0x1c(%ebp),%eax
5e0: 0f be c0 movsbl %al,%eax
5e3: 89 44 24 04 mov %eax,0x4(%esp)
5e7: 8b 45 08 mov 0x8(%ebp),%eax
5ea: 89 04 24 mov %eax,(%esp)
5ed: e8 b7 fd ff ff call 3a9 <putc>
5f2: eb 28 jmp 61c <printf+0x193>
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
5f4: c7 44 24 04 25 00 00 movl $0x25,0x4(%esp)
5fb: 00
5fc: 8b 45 08 mov 0x8(%ebp),%eax
5ff: 89 04 24 mov %eax,(%esp)
602: e8 a2 fd ff ff call 3a9 <putc>
putc(fd, c);
607: 8b 45 e4 mov -0x1c(%ebp),%eax
60a: 0f be c0 movsbl %al,%eax
60d: 89 44 24 04 mov %eax,0x4(%esp)
611: 8b 45 08 mov 0x8(%ebp),%eax
614: 89 04 24 mov %eax,(%esp)
617: e8 8d fd ff ff call 3a9 <putc>
}
state = 0;
61c: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp)
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
623: 83 45 f0 01 addl $0x1,-0x10(%ebp)
627: 8b 55 0c mov 0xc(%ebp),%edx
62a: 8b 45 f0 mov -0x10(%ebp),%eax
62d: 01 d0 add %edx,%eax
62f: 0f b6 00 movzbl (%eax),%eax
632: 84 c0 test %al,%al
634: 0f 85 71 fe ff ff jne 4ab <printf+0x22>
putc(fd, c);
}
state = 0;
}
}
}
63a: c9 leave
63b: c3 ret
0000063c <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
63c: 55 push %ebp
63d: 89 e5 mov %esp,%ebp
63f: 83 ec 10 sub $0x10,%esp
Header *bp, *p;
bp = (Header*)ap - 1;
642: 8b 45 08 mov 0x8(%ebp),%eax
645: 83 e8 08 sub $0x8,%eax
648: 89 45 f8 mov %eax,-0x8(%ebp)
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
64b: a1 78 10 00 00 mov 0x1078,%eax
650: 89 45 fc mov %eax,-0x4(%ebp)
653: eb 24 jmp 679 <free+0x3d>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
655: 8b 45 fc mov -0x4(%ebp),%eax
658: 8b 00 mov (%eax),%eax
65a: 3b 45 fc cmp -0x4(%ebp),%eax
65d: 77 12 ja 671 <free+0x35>
65f: 8b 45 f8 mov -0x8(%ebp),%eax
662: 3b 45 fc cmp -0x4(%ebp),%eax
665: 77 24 ja 68b <free+0x4f>
667: 8b 45 fc mov -0x4(%ebp),%eax
66a: 8b 00 mov (%eax),%eax
66c: 3b 45 f8 cmp -0x8(%ebp),%eax
66f: 77 1a ja 68b <free+0x4f>
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
671: 8b 45 fc mov -0x4(%ebp),%eax
674: 8b 00 mov (%eax),%eax
676: 89 45 fc mov %eax,-0x4(%ebp)
679: 8b 45 f8 mov -0x8(%ebp),%eax
67c: 3b 45 fc cmp -0x4(%ebp),%eax
67f: 76 d4 jbe 655 <free+0x19>
681: 8b 45 fc mov -0x4(%ebp),%eax
684: 8b 00 mov (%eax),%eax
686: 3b 45 f8 cmp -0x8(%ebp),%eax
689: 76 ca jbe 655 <free+0x19>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
break;
if(bp + bp->s.size == p->s.ptr){
68b: 8b 45 f8 mov -0x8(%ebp),%eax
68e: 8b 40 04 mov 0x4(%eax),%eax
691: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx
698: 8b 45 f8 mov -0x8(%ebp),%eax
69b: 01 c2 add %eax,%edx
69d: 8b 45 fc mov -0x4(%ebp),%eax
6a0: 8b 00 mov (%eax),%eax
6a2: 39 c2 cmp %eax,%edx
6a4: 75 24 jne 6ca <free+0x8e>
bp->s.size += p->s.ptr->s.size;
6a6: 8b 45 f8 mov -0x8(%ebp),%eax
6a9: 8b 50 04 mov 0x4(%eax),%edx
6ac: 8b 45 fc mov -0x4(%ebp),%eax
6af: 8b 00 mov (%eax),%eax
6b1: 8b 40 04 mov 0x4(%eax),%eax
6b4: 01 c2 add %eax,%edx
6b6: 8b 45 f8 mov -0x8(%ebp),%eax
6b9: 89 50 04 mov %edx,0x4(%eax)
bp->s.ptr = p->s.ptr->s.ptr;
6bc: 8b 45 fc mov -0x4(%ebp),%eax
6bf: 8b 00 mov (%eax),%eax
6c1: 8b 10 mov (%eax),%edx
6c3: 8b 45 f8 mov -0x8(%ebp),%eax
6c6: 89 10 mov %edx,(%eax)
6c8: eb 0a jmp 6d4 <free+0x98>
} else
bp->s.ptr = p->s.ptr;
6ca: 8b 45 fc mov -0x4(%ebp),%eax
6cd: 8b 10 mov (%eax),%edx
6cf: 8b 45 f8 mov -0x8(%ebp),%eax
6d2: 89 10 mov %edx,(%eax)
if(p + p->s.size == bp){
6d4: 8b 45 fc mov -0x4(%ebp),%eax
6d7: 8b 40 04 mov 0x4(%eax),%eax
6da: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx
6e1: 8b 45 fc mov -0x4(%ebp),%eax
6e4: 01 d0 add %edx,%eax
6e6: 3b 45 f8 cmp -0x8(%ebp),%eax
6e9: 75 20 jne 70b <free+0xcf>
p->s.size += bp->s.size;
6eb: 8b 45 fc mov -0x4(%ebp),%eax
6ee: 8b 50 04 mov 0x4(%eax),%edx
6f1: 8b 45 f8 mov -0x8(%ebp),%eax
6f4: 8b 40 04 mov 0x4(%eax),%eax
6f7: 01 c2 add %eax,%edx
6f9: 8b 45 fc mov -0x4(%ebp),%eax
6fc: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
6ff: 8b 45 f8 mov -0x8(%ebp),%eax
702: 8b 10 mov (%eax),%edx
704: 8b 45 fc mov -0x4(%ebp),%eax
707: 89 10 mov %edx,(%eax)
709: eb 08 jmp 713 <free+0xd7>
} else
p->s.ptr = bp;
70b: 8b 45 fc mov -0x4(%ebp),%eax
70e: 8b 55 f8 mov -0x8(%ebp),%edx
711: 89 10 mov %edx,(%eax)
freep = p;
713: 8b 45 fc mov -0x4(%ebp),%eax
716: a3 78 10 00 00 mov %eax,0x1078
}
71b: c9 leave
71c: c3 ret
0000071d <morecore>:
static Header*
morecore(uint nu)
{
71d: 55 push %ebp
71e: 89 e5 mov %esp,%ebp
720: 83 ec 28 sub $0x28,%esp
char *p;
Header *hp;
if(nu < 4096)
723: 81 7d 08 ff 0f 00 00 cmpl $0xfff,0x8(%ebp)
72a: 77 07 ja 733 <morecore+0x16>
nu = 4096;
72c: c7 45 08 00 10 00 00 movl $0x1000,0x8(%ebp)
p = sbrk(nu * sizeof(Header));
733: 8b 45 08 mov 0x8(%ebp),%eax
736: c1 e0 03 shl $0x3,%eax
739: 89 04 24 mov %eax,(%esp)
73c: e8 28 fc ff ff call 369 <sbrk>
741: 89 45 f4 mov %eax,-0xc(%ebp)
if(p == (char*)-1)
744: 83 7d f4 ff cmpl $0xffffffff,-0xc(%ebp)
748: 75 07 jne 751 <morecore+0x34>
return 0;
74a: b8 00 00 00 00 mov $0x0,%eax
74f: eb 22 jmp 773 <morecore+0x56>
hp = (Header*)p;
751: 8b 45 f4 mov -0xc(%ebp),%eax
754: 89 45 f0 mov %eax,-0x10(%ebp)
hp->s.size = nu;
757: 8b 45 f0 mov -0x10(%ebp),%eax
75a: 8b 55 08 mov 0x8(%ebp),%edx
75d: 89 50 04 mov %edx,0x4(%eax)
free((void*)(hp + 1));
760: 8b 45 f0 mov -0x10(%ebp),%eax
763: 83 c0 08 add $0x8,%eax
766: 89 04 24 mov %eax,(%esp)
769: e8 ce fe ff ff call 63c <free>
return freep;
76e: a1 78 10 00 00 mov 0x1078,%eax
}
773: c9 leave
774: c3 ret
00000775 <malloc>:
void*
malloc(uint nbytes)
{
775: 55 push %ebp
776: 89 e5 mov %esp,%ebp
778: 83 ec 28 sub $0x28,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
77b: 8b 45 08 mov 0x8(%ebp),%eax
77e: 83 c0 07 add $0x7,%eax
781: c1 e8 03 shr $0x3,%eax
784: 83 c0 01 add $0x1,%eax
787: 89 45 ec mov %eax,-0x14(%ebp)
if((prevp = freep) == 0){
78a: a1 78 10 00 00 mov 0x1078,%eax
78f: 89 45 f0 mov %eax,-0x10(%ebp)
792: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
796: 75 23 jne 7bb <malloc+0x46>
base.s.ptr = freep = prevp = &base;
798: c7 45 f0 70 10 00 00 movl $0x1070,-0x10(%ebp)
79f: 8b 45 f0 mov -0x10(%ebp),%eax
7a2: a3 78 10 00 00 mov %eax,0x1078
7a7: a1 78 10 00 00 mov 0x1078,%eax
7ac: a3 70 10 00 00 mov %eax,0x1070
base.s.size = 0;
7b1: c7 05 74 10 00 00 00 movl $0x0,0x1074
7b8: 00 00 00
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
7bb: 8b 45 f0 mov -0x10(%ebp),%eax
7be: 8b 00 mov (%eax),%eax
7c0: 89 45 f4 mov %eax,-0xc(%ebp)
if(p->s.size >= nunits){
7c3: 8b 45 f4 mov -0xc(%ebp),%eax
7c6: 8b 40 04 mov 0x4(%eax),%eax
7c9: 3b 45 ec cmp -0x14(%ebp),%eax
7cc: 72 4d jb 81b <malloc+0xa6>
if(p->s.size == nunits)
7ce: 8b 45 f4 mov -0xc(%ebp),%eax
7d1: 8b 40 04 mov 0x4(%eax),%eax
7d4: 3b 45 ec cmp -0x14(%ebp),%eax
7d7: 75 0c jne 7e5 <malloc+0x70>
prevp->s.ptr = p->s.ptr;
7d9: 8b 45 f4 mov -0xc(%ebp),%eax
7dc: 8b 10 mov (%eax),%edx
7de: 8b 45 f0 mov -0x10(%ebp),%eax
7e1: 89 10 mov %edx,(%eax)
7e3: eb 26 jmp 80b <malloc+0x96>
else {
p->s.size -= nunits;
7e5: 8b 45 f4 mov -0xc(%ebp),%eax
7e8: 8b 40 04 mov 0x4(%eax),%eax
7eb: 2b 45 ec sub -0x14(%ebp),%eax
7ee: 89 c2 mov %eax,%edx
7f0: 8b 45 f4 mov -0xc(%ebp),%eax
7f3: 89 50 04 mov %edx,0x4(%eax)
p += p->s.size;
7f6: 8b 45 f4 mov -0xc(%ebp),%eax
7f9: 8b 40 04 mov 0x4(%eax),%eax
7fc: c1 e0 03 shl $0x3,%eax
7ff: 01 45 f4 add %eax,-0xc(%ebp)
p->s.size = nunits;
802: 8b 45 f4 mov -0xc(%ebp),%eax
805: 8b 55 ec mov -0x14(%ebp),%edx
808: 89 50 04 mov %edx,0x4(%eax)
}
freep = prevp;
80b: 8b 45 f0 mov -0x10(%ebp),%eax
80e: a3 78 10 00 00 mov %eax,0x1078
return (void*)(p + 1);
813: 8b 45 f4 mov -0xc(%ebp),%eax
816: 83 c0 08 add $0x8,%eax
819: eb 38 jmp 853 <malloc+0xde>
}
if(p == freep)
81b: a1 78 10 00 00 mov 0x1078,%eax
820: 39 45 f4 cmp %eax,-0xc(%ebp)
823: 75 1b jne 840 <malloc+0xcb>
if((p = morecore(nunits)) == 0)
825: 8b 45 ec mov -0x14(%ebp),%eax
828: 89 04 24 mov %eax,(%esp)
82b: e8 ed fe ff ff call 71d <morecore>
830: 89 45 f4 mov %eax,-0xc(%ebp)
833: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
837: 75 07 jne 840 <malloc+0xcb>
return 0;
839: b8 00 00 00 00 mov $0x0,%eax
83e: eb 13 jmp 853 <malloc+0xde>
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
840: 8b 45 f4 mov -0xc(%ebp),%eax
843: 89 45 f0 mov %eax,-0x10(%ebp)
846: 8b 45 f4 mov -0xc(%ebp),%eax
849: 8b 00 mov (%eax),%eax
84b: 89 45 f4 mov %eax,-0xc(%ebp)
return (void*)(p + 1);
}
if(p == freep)
if((p = morecore(nunits)) == 0)
return 0;
}
84e: e9 70 ff ff ff jmp 7c3 <malloc+0x4e>
}
853: c9 leave
854: c3 ret
00000855 <xchg>:
asm volatile("sti");
}
static inline uint
xchg(volatile uint *addr, uint newval)
{
855: 55 push %ebp
856: 89 e5 mov %esp,%ebp
858: 83 ec 10 sub $0x10,%esp
uint result;
// The + in "+m" denotes a read-modify-write operand.
asm volatile("lock; xchgl %0, %1" :
85b: 8b 55 08 mov 0x8(%ebp),%edx
85e: 8b 45 0c mov 0xc(%ebp),%eax
861: 8b 4d 08 mov 0x8(%ebp),%ecx
864: f0 87 02 lock xchg %eax,(%edx)
867: 89 45 fc mov %eax,-0x4(%ebp)
"+m" (*addr), "=a" (result) :
"1" (newval) :
"cc");
return result;
86a: 8b 45 fc mov -0x4(%ebp),%eax
}
86d: c9 leave
86e: c3 ret
0000086f <lock_init>:
#include "mmu.h"
#include "spinlock.h"
#include "x86.h"
#include "proc.h"
void lock_init(lock_t *lock){
86f: 55 push %ebp
870: 89 e5 mov %esp,%ebp
lock->locked = 0;
872: 8b 45 08 mov 0x8(%ebp),%eax
875: c7 00 00 00 00 00 movl $0x0,(%eax)
}
87b: 5d pop %ebp
87c: c3 ret
0000087d <lock_acquire>:
void lock_acquire(lock_t *lock){
87d: 55 push %ebp
87e: 89 e5 mov %esp,%ebp
880: 83 ec 08 sub $0x8,%esp
while(xchg(&lock->locked,1) != 0);
883: 90 nop
884: 8b 45 08 mov 0x8(%ebp),%eax
887: c7 44 24 04 01 00 00 movl $0x1,0x4(%esp)
88e: 00
88f: 89 04 24 mov %eax,(%esp)
892: e8 be ff ff ff call 855 <xchg>
897: 85 c0 test %eax,%eax
899: 75 e9 jne 884 <lock_acquire+0x7>
}
89b: c9 leave
89c: c3 ret
0000089d <lock_release>:
void lock_release(lock_t *lock){
89d: 55 push %ebp
89e: 89 e5 mov %esp,%ebp
8a0: 83 ec 08 sub $0x8,%esp
xchg(&lock->locked,0);
8a3: 8b 45 08 mov 0x8(%ebp),%eax
8a6: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
8ad: 00
8ae: 89 04 24 mov %eax,(%esp)
8b1: e8 9f ff ff ff call 855 <xchg>
}
8b6: c9 leave
8b7: c3 ret
000008b8 <thread_create>:
void *thread_create(void(*start_routine)(void*), void *arg){
8b8: 55 push %ebp
8b9: 89 e5 mov %esp,%ebp
8bb: 83 ec 28 sub $0x28,%esp
int tid;
void * stack = malloc(2 * 4096);
8be: c7 04 24 00 20 00 00 movl $0x2000,(%esp)
8c5: e8 ab fe ff ff call 775 <malloc>
8ca: 89 45 f4 mov %eax,-0xc(%ebp)
void *garbage_stack = stack;
8cd: 8b 45 f4 mov -0xc(%ebp),%eax
8d0: 89 45 f0 mov %eax,-0x10(%ebp)
// printf(1,"start routine addr : %d\n",(uint)start_routine);
if((uint)stack % 4096){
8d3: 8b 45 f4 mov -0xc(%ebp),%eax
8d6: 25 ff 0f 00 00 and $0xfff,%eax
8db: 85 c0 test %eax,%eax
8dd: 74 14 je 8f3 <thread_create+0x3b>
stack = stack + (4096 - (uint)stack % 4096);
8df: 8b 45 f4 mov -0xc(%ebp),%eax
8e2: 25 ff 0f 00 00 and $0xfff,%eax
8e7: 89 c2 mov %eax,%edx
8e9: b8 00 10 00 00 mov $0x1000,%eax
8ee: 29 d0 sub %edx,%eax
8f0: 01 45 f4 add %eax,-0xc(%ebp)
}
if (stack == 0){
8f3: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
8f7: 75 1b jne 914 <thread_create+0x5c>
printf(1,"malloc fail \n");
8f9: c7 44 24 04 26 0c 00 movl $0xc26,0x4(%esp)
900: 00
901: c7 04 24 01 00 00 00 movl $0x1,(%esp)
908: e8 7c fb ff ff call 489 <printf>
return 0;
90d: b8 00 00 00 00 mov $0x0,%eax
912: eb 6f jmp 983 <thread_create+0xcb>
}
tid = clone((uint)stack,PSIZE,(uint)start_routine,(int)arg);
914: 8b 4d 0c mov 0xc(%ebp),%ecx
917: 8b 55 08 mov 0x8(%ebp),%edx
91a: 8b 45 f4 mov -0xc(%ebp),%eax
91d: 89 4c 24 0c mov %ecx,0xc(%esp)
921: 89 54 24 08 mov %edx,0x8(%esp)
925: c7 44 24 04 00 10 00 movl $0x1000,0x4(%esp)
92c: 00
92d: 89 04 24 mov %eax,(%esp)
930: e8 4c fa ff ff call 381 <clone>
935: 89 45 ec mov %eax,-0x14(%ebp)
if(tid < 0){
938: 83 7d ec 00 cmpl $0x0,-0x14(%ebp)
93c: 79 1b jns 959 <thread_create+0xa1>
printf(1,"clone fails\n");
93e: c7 44 24 04 34 0c 00 movl $0xc34,0x4(%esp)
945: 00
946: c7 04 24 01 00 00 00 movl $0x1,(%esp)
94d: e8 37 fb ff ff call 489 <printf>
return 0;
952: b8 00 00 00 00 mov $0x0,%eax
957: eb 2a jmp 983 <thread_create+0xcb>
}
if(tid > 0){
959: 83 7d ec 00 cmpl $0x0,-0x14(%ebp)
95d: 7e 05 jle 964 <thread_create+0xac>
//store threads on thread table
return garbage_stack;
95f: 8b 45 f0 mov -0x10(%ebp),%eax
962: eb 1f jmp 983 <thread_create+0xcb>
}
if(tid == 0){
964: 83 7d ec 00 cmpl $0x0,-0x14(%ebp)
968: 75 14 jne 97e <thread_create+0xc6>
printf(1,"tid = 0 return \n");
96a: c7 44 24 04 41 0c 00 movl $0xc41,0x4(%esp)
971: 00
972: c7 04 24 01 00 00 00 movl $0x1,(%esp)
979: e8 0b fb ff ff call 489 <printf>
}
// wait();
// free(garbage_stack);
return 0;
97e: b8 00 00 00 00 mov $0x0,%eax
}
983: c9 leave
984: c3 ret
00000985 <random>:
unsigned long rands = 1;
// generate 0 -> max random number exclude max.
int random(int max){
985: 55 push %ebp
986: 89 e5 mov %esp,%ebp
rands = rands * 1664525 + 1013904233;
988: a1 6c 10 00 00 mov 0x106c,%eax
98d: 69 c0 0d 66 19 00 imul $0x19660d,%eax,%eax
993: 05 69 f3 6e 3c add $0x3c6ef369,%eax
998: a3 6c 10 00 00 mov %eax,0x106c
return (int)(rands % max);
99d: a1 6c 10 00 00 mov 0x106c,%eax
9a2: 8b 4d 08 mov 0x8(%ebp),%ecx
9a5: ba 00 00 00 00 mov $0x0,%edx
9aa: f7 f1 div %ecx
9ac: 89 d0 mov %edx,%eax
9ae: 5d pop %ebp
9af: c3 ret
000009b0 <init_q>:
#include "queue.h"
#include "types.h"
#include "user.h"
void init_q(struct queue *q){
9b0: 55 push %ebp
9b1: 89 e5 mov %esp,%ebp
q->size = 0;
9b3: 8b 45 08 mov 0x8(%ebp),%eax
9b6: c7 00 00 00 00 00 movl $0x0,(%eax)
q->head = 0;
9bc: 8b 45 08 mov 0x8(%ebp),%eax
9bf: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax)
q->tail = 0;
9c6: 8b 45 08 mov 0x8(%ebp),%eax
9c9: c7 40 08 00 00 00 00 movl $0x0,0x8(%eax)
}
9d0: 5d pop %ebp
9d1: c3 ret
000009d2 <add_q>:
void add_q(struct queue *q, int v){
9d2: 55 push %ebp
9d3: 89 e5 mov %esp,%ebp
9d5: 83 ec 28 sub $0x28,%esp
struct node * n = malloc(sizeof(struct node));
9d8: c7 04 24 08 00 00 00 movl $0x8,(%esp)
9df: e8 91 fd ff ff call 775 <malloc>
9e4: 89 45 f4 mov %eax,-0xc(%ebp)
n->next = 0;
9e7: 8b 45 f4 mov -0xc(%ebp),%eax
9ea: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax)
n->value = v;
9f1: 8b 45 f4 mov -0xc(%ebp),%eax
9f4: 8b 55 0c mov 0xc(%ebp),%edx
9f7: 89 10 mov %edx,(%eax)
if(q->head == 0){
9f9: 8b 45 08 mov 0x8(%ebp),%eax
9fc: 8b 40 04 mov 0x4(%eax),%eax
9ff: 85 c0 test %eax,%eax
a01: 75 0b jne a0e <add_q+0x3c>
q->head = n;
a03: 8b 45 08 mov 0x8(%ebp),%eax
a06: 8b 55 f4 mov -0xc(%ebp),%edx
a09: 89 50 04 mov %edx,0x4(%eax)
a0c: eb 0c jmp a1a <add_q+0x48>
}else{
q->tail->next = n;
a0e: 8b 45 08 mov 0x8(%ebp),%eax
a11: 8b 40 08 mov 0x8(%eax),%eax
a14: 8b 55 f4 mov -0xc(%ebp),%edx
a17: 89 50 04 mov %edx,0x4(%eax)
}
q->tail = n;
a1a: 8b 45 08 mov 0x8(%ebp),%eax
a1d: 8b 55 f4 mov -0xc(%ebp),%edx
a20: 89 50 08 mov %edx,0x8(%eax)
q->size++;
a23: 8b 45 08 mov 0x8(%ebp),%eax
a26: 8b 00 mov (%eax),%eax
a28: 8d 50 01 lea 0x1(%eax),%edx
a2b: 8b 45 08 mov 0x8(%ebp),%eax
a2e: 89 10 mov %edx,(%eax)
}
a30: c9 leave
a31: c3 ret
00000a32 <empty_q>:
int empty_q(struct queue *q){
a32: 55 push %ebp
a33: 89 e5 mov %esp,%ebp
if(q->size == 0)
a35: 8b 45 08 mov 0x8(%ebp),%eax
a38: 8b 00 mov (%eax),%eax
a3a: 85 c0 test %eax,%eax
a3c: 75 07 jne a45 <empty_q+0x13>
return 1;
a3e: b8 01 00 00 00 mov $0x1,%eax
a43: eb 05 jmp a4a <empty_q+0x18>
else
return 0;
a45: b8 00 00 00 00 mov $0x0,%eax
}
a4a: 5d pop %ebp
a4b: c3 ret
00000a4c <pop_q>:
int pop_q(struct queue *q){
a4c: 55 push %ebp
a4d: 89 e5 mov %esp,%ebp
a4f: 83 ec 28 sub $0x28,%esp
int val;
struct node *destroy;
if(!empty_q(q)){
a52: 8b 45 08 mov 0x8(%ebp),%eax
a55: 89 04 24 mov %eax,(%esp)
a58: e8 d5 ff ff ff call a32 <empty_q>
a5d: 85 c0 test %eax,%eax
a5f: 75 5d jne abe <pop_q+0x72>
val = q->head->value;
a61: 8b 45 08 mov 0x8(%ebp),%eax
a64: 8b 40 04 mov 0x4(%eax),%eax
a67: 8b 00 mov (%eax),%eax
a69: 89 45 f4 mov %eax,-0xc(%ebp)
destroy = q->head;
a6c: 8b 45 08 mov 0x8(%ebp),%eax
a6f: 8b 40 04 mov 0x4(%eax),%eax
a72: 89 45 f0 mov %eax,-0x10(%ebp)
q->head = q->head->next;
a75: 8b 45 08 mov 0x8(%ebp),%eax
a78: 8b 40 04 mov 0x4(%eax),%eax
a7b: 8b 50 04 mov 0x4(%eax),%edx
a7e: 8b 45 08 mov 0x8(%ebp),%eax
a81: 89 50 04 mov %edx,0x4(%eax)
free(destroy);
a84: 8b 45 f0 mov -0x10(%ebp),%eax
a87: 89 04 24 mov %eax,(%esp)
a8a: e8 ad fb ff ff call 63c <free>
q->size--;
a8f: 8b 45 08 mov 0x8(%ebp),%eax
a92: 8b 00 mov (%eax),%eax
a94: 8d 50 ff lea -0x1(%eax),%edx
a97: 8b 45 08 mov 0x8(%ebp),%eax
a9a: 89 10 mov %edx,(%eax)
if(q->size == 0){
a9c: 8b 45 08 mov 0x8(%ebp),%eax
a9f: 8b 00 mov (%eax),%eax
aa1: 85 c0 test %eax,%eax
aa3: 75 14 jne ab9 <pop_q+0x6d>
q->head = 0;
aa5: 8b 45 08 mov 0x8(%ebp),%eax
aa8: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax)
q->tail = 0;
aaf: 8b 45 08 mov 0x8(%ebp),%eax
ab2: c7 40 08 00 00 00 00 movl $0x0,0x8(%eax)
}
return val;
ab9: 8b 45 f4 mov -0xc(%ebp),%eax
abc: eb 05 jmp ac3 <pop_q+0x77>
}
return -1;
abe: b8 ff ff ff ff mov $0xffffffff,%eax
}
ac3: c9 leave
ac4: c3 ret
00000ac5 <sem_init>:
#include "types.h"
#include "user.h"
#include "semaphore.h"
void
sem_init(struct semaphore *s, int size){
ac5: 55 push %ebp
ac6: 89 e5 mov %esp,%ebp
ac8: 83 ec 18 sub $0x18,%esp
s->size = size;
acb: 8b 45 08 mov 0x8(%ebp),%eax
ace: 8b 55 0c mov 0xc(%ebp),%edx
ad1: 89 50 08 mov %edx,0x8(%eax)
s->count = size;
ad4: 8b 45 08 mov 0x8(%ebp),%eax
ad7: 8b 55 0c mov 0xc(%ebp),%edx
ada: 89 50 04 mov %edx,0x4(%eax)
lock_init(&s->lock);
add: 8b 45 08 mov 0x8(%ebp),%eax
ae0: 89 04 24 mov %eax,(%esp)
ae3: e8 87 fd ff ff call 86f <lock_init>
}
ae8: c9 leave
ae9: c3 ret
00000aea <sem_init_full>:
void
sem_init_full(struct semaphore *s, int size){
aea: 55 push %ebp
aeb: 89 e5 mov %esp,%ebp
aed: 83 ec 18 sub $0x18,%esp
s->size = size;
af0: 8b 45 08 mov 0x8(%ebp),%eax
af3: 8b 55 0c mov 0xc(%ebp),%edx
af6: 89 50 08 mov %edx,0x8(%eax)
s->count= 0;
af9: 8b 45 08 mov 0x8(%ebp),%eax
afc: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax)
lock_init(&s->lock);
b03: 8b 45 08 mov 0x8(%ebp),%eax
b06: 89 04 24 mov %eax,(%esp)
b09: e8 61 fd ff ff call 86f <lock_init>
}
b0e: c9 leave
b0f: c3 ret
00000b10 <sem_aquire>:
//Attempts to aquire a lock. If count is not
//full then we will add the process to the list of
//processes holding the lock.
void
sem_aquire(struct semaphore * s){
b10: 55 push %ebp
b11: 89 e5 mov %esp,%ebp
b13: 83 ec 28 sub $0x28,%esp
//Disable interrupts? nah
//We need to only get a hold of waiters?
//If count is full then place proccess on waiters list
//Else add to the holding list
lock_acquire(&s->lock);
b16: 8b 45 08 mov 0x8(%ebp),%eax
b19: 89 04 24 mov %eax,(%esp)
b1c: e8 5c fd ff ff call 87d <lock_acquire>
if(s->count == 0){
b21: 8b 45 08 mov 0x8(%ebp),%eax
b24: 8b 40 04 mov 0x4(%eax),%eax
b27: 85 c0 test %eax,%eax
b29: 75 2f jne b5a <sem_aquire+0x4a>
//printf(1, "Sem F\n");
//add proc to waiters list
int tid = getpid();
b2b: e8 31 f8 ff ff call 361 <getpid>
b30: 89 45 f4 mov %eax,-0xc(%ebp)
//place requesting process to sleep
add_q(&s->waiters, tid); //Add process to queue
b33: 8b 45 08 mov 0x8(%ebp),%eax
b36: 8d 50 0c lea 0xc(%eax),%edx
b39: 8b 45 f4 mov -0xc(%ebp),%eax
b3c: 89 44 24 04 mov %eax,0x4(%esp)
b40: 89 14 24 mov %edx,(%esp)
b43: e8 8a fe ff ff call 9d2 <add_q>
//printf(1, " Added to waiters semaphore with size: %d\n", s->size);
lock_release(&s->lock);
b48: 8b 45 08 mov 0x8(%ebp),%eax
b4b: 89 04 24 mov %eax,(%esp)
b4e: e8 4a fd ff ff call 89d <lock_release>
tsleep();
b53: e8 39 f8 ff ff call 391 <tsleep>
b58: eb 1a jmp b74 <sem_aquire+0x64>
}
else{
//printf(1, "Sem A\n");
s->count--;
b5a: 8b 45 08 mov 0x8(%ebp),%eax
b5d: 8b 40 04 mov 0x4(%eax),%eax
b60: 8d 50 ff lea -0x1(%eax),%edx
b63: 8b 45 08 mov 0x8(%ebp),%eax
b66: 89 50 04 mov %edx,0x4(%eax)
lock_release(&s->lock);
b69: 8b 45 08 mov 0x8(%ebp),%eax
b6c: 89 04 24 mov %eax,(%esp)
b6f: e8 29 fd ff ff call 89d <lock_release>
}
}
b74: c9 leave
b75: c3 ret
00000b76 <sem_signal>:
//Removes a process from a lock and decreases count
//to indicate that more process can hold the lock.
void
sem_signal(struct semaphore * s){
b76: 55 push %ebp
b77: 89 e5 mov %esp,%ebp
b79: 83 ec 28 sub $0x28,%esp
//printf(1, "Sem R\n");
//If count is full then place proccess on waiters list
lock_acquire(&s->lock);
b7c: 8b 45 08 mov 0x8(%ebp),%eax
b7f: 89 04 24 mov %eax,(%esp)
b82: e8 f6 fc ff ff call 87d <lock_acquire>
if(s->count < s->size){
b87: 8b 45 08 mov 0x8(%ebp),%eax
b8a: 8b 50 04 mov 0x4(%eax),%edx
b8d: 8b 45 08 mov 0x8(%ebp),%eax
b90: 8b 40 08 mov 0x8(%eax),%eax
b93: 39 c2 cmp %eax,%edx
b95: 7d 0f jge ba6 <sem_signal+0x30>
s->count++;
b97: 8b 45 08 mov 0x8(%ebp),%eax
b9a: 8b 40 04 mov 0x4(%eax),%eax
b9d: 8d 50 01 lea 0x1(%eax),%edx
ba0: 8b 45 08 mov 0x8(%ebp),%eax
ba3: 89 50 04 mov %edx,0x4(%eax)
}
int tid;
tid = pop_q(&s->waiters);
ba6: 8b 45 08 mov 0x8(%ebp),%eax
ba9: 83 c0 0c add $0xc,%eax
bac: 89 04 24 mov %eax,(%esp)
baf: e8 98 fe ff ff call a4c <pop_q>
bb4: 89 45 f4 mov %eax,-0xc(%ebp)
if(tid != -1){
bb7: 83 7d f4 ff cmpl $0xffffffff,-0xc(%ebp)
bbb: 74 2e je beb <sem_signal+0x75>
//printf(1, "Sem A\n");
twakeup(tid);
bbd: 8b 45 f4 mov -0xc(%ebp),%eax
bc0: 89 04 24 mov %eax,(%esp)
bc3: e8 d1 f7 ff ff call 399 <twakeup>
s->count--;
bc8: 8b 45 08 mov 0x8(%ebp),%eax
bcb: 8b 40 04 mov 0x4(%eax),%eax
bce: 8d 50 ff lea -0x1(%eax),%edx
bd1: 8b 45 08 mov 0x8(%ebp),%eax
bd4: 89 50 04 mov %edx,0x4(%eax)
if(s->count < 0) s->count = 0;
bd7: 8b 45 08 mov 0x8(%ebp),%eax
bda: 8b 40 04 mov 0x4(%eax),%eax
bdd: 85 c0 test %eax,%eax
bdf: 79 0a jns beb <sem_signal+0x75>
be1: 8b 45 08 mov 0x8(%ebp),%eax
be4: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax)
}
lock_release(&s->lock);
beb: 8b 45 08 mov 0x8(%ebp),%eax
bee: 89 04 24 mov %eax,(%esp)
bf1: e8 a7 fc ff ff call 89d <lock_release>
bf6: c9 leave
bf7: c3 ret
|
; ==========================================================
; COMMODORE 64 - Examples in 6502 Assembly language
; © Digitsensitive; digit.sensitivee@gmail.com
; How to print a text
; ==========================================================
; ----------------------------------------------------------
; Main Loop
; ----------------------------------------------------------
*=$02a7 ; sys 679
init ldx #$01
stx $d020 ; Border color register
ldx #$00
stx $d021 ; Background color
clear lda #$20 ; spacebar screen code
sta $0400,x ; fill four areas of screen with 256 spacebar characters
sta $0500,x
sta $0600,x
sta $06e8,x
lda #$01 ; set foreground to white in Color Ram
sta $d800,x
sta $d900,x
sta $da00,x
sta $dae8,x
inx
bne clear ; bne = branch on not equal
; did x turn to zero already?
; if yes -> stop loop
; if no -> continue loop
ldx #$00
text lda hello,x ; take byte by byte
and #$3f ; convert to uppercase
sta $05BF,x ; store byte to screen area
inx
cpx #26 ; check for end of the string data table
bne text
loop jmp loop ; endless stupid loop
; ----------------------------------------------------------
; Data
; ----------------------------------------------------------
; .text is a pseudo-ops and one standard way to make a string data table
; It takes a quoted string and converts it into a span of bytes
; Characters are converted from ASCII to PETSCII
hello .text "Hello wonderful C64 world!" |
; A001880: Coefficients of Bessel polynomials y_n (x).
; Submitted by Jon Maiga
; 1,15,210,3150,51975,945945,18918900,413513100,9820936125,252070693875,6957151150950,205552193096250,6474894082531875,216659917377028125,7675951358500425000,287080580807915895000,11303797869311688365625,467445288360359818884375,20255962495615592151656250,917914932038159202240843750,43417376285404930265991909375,2139856402637814420252458390625,109716273735247939365671502937500,5843584144594727205345547439062500,322858023988858678095341496008203125,18480393293122270734177347231509546875
add $0,1
mov $2,$0
seq $0,1879 ; a(n) = (2n+2)!/(n!*2^(n+1)).
mul $2,$0
mov $0,$2
div $0,6
|
// Copyright (c) 2020 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <policy/fees.h>
#include <primitives/transaction.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <txmempool.h>
#include <cstdint>
#include <optional>
#include <string>
#include <vector>
void initialize_policy_estimator()
{
static const auto testing_setup = MakeFuzzingContext<>();
}
FUZZ_TARGET_INIT(policy_estimator, initialize_policy_estimator)
{
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
CBlockPolicyEstimator block_policy_estimator;
while (fuzzed_data_provider.ConsumeBool()) {
CallOneOf(
fuzzed_data_provider,
[&] {
const std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
if (!mtx) {
return;
}
const CTransaction tx{*mtx};
block_policy_estimator.processTransaction(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx), fuzzed_data_provider.ConsumeBool());
if (fuzzed_data_provider.ConsumeBool()) {
(void)block_policy_estimator.removeTx(tx.GetHash(), /* inBlock */ fuzzed_data_provider.ConsumeBool());
}
},
[&] {
std::vector<CTxMemPoolEntry> mempool_entries;
while (fuzzed_data_provider.ConsumeBool()) {
const std::optional<CMutableTransaction> mtx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
if (!mtx) {
break;
}
const CTransaction tx{*mtx};
mempool_entries.push_back(ConsumeTxMemPoolEntry(fuzzed_data_provider, tx));
}
std::vector<const CTxMemPoolEntry*> ptrs;
ptrs.reserve(mempool_entries.size());
for (const CTxMemPoolEntry& mempool_entry : mempool_entries) {
ptrs.push_back(&mempool_entry);
}
block_policy_estimator.processBlock(fuzzed_data_provider.ConsumeIntegral<unsigned int>(), ptrs);
},
[&] {
(void)block_policy_estimator.removeTx(ConsumeUInt256(fuzzed_data_provider), /* inBlock */ fuzzed_data_provider.ConsumeBool());
},
[&] {
block_policy_estimator.FlushUnconfirmed();
});
(void)block_policy_estimator.estimateFee(fuzzed_data_provider.ConsumeIntegral<int>());
EstimationResult result;
(void)block_policy_estimator.estimateRawFee(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeFloatingPoint<double>(), fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS), fuzzed_data_provider.ConsumeBool() ? &result : nullptr);
FeeCalculation fee_calculation;
(void)block_policy_estimator.estimateSmartFee(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeBool() ? &fee_calculation : nullptr, fuzzed_data_provider.ConsumeBool());
(void)block_policy_estimator.HighestTargetTracked(fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS));
}
{
FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider);
CAutoFile fuzzed_auto_file = fuzzed_auto_file_provider.open();
block_policy_estimator.Write(fuzzed_auto_file);
block_policy_estimator.Read(fuzzed_auto_file);
}
}
|
// Copyright (c) 2003-2020 Xsens Technologies B.V. or subsidiaries worldwide.
// 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 names of the copyright holders nor the names of their 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 HOLDERS 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.THE LAWS OF THE NETHERLANDS
// SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
// OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
// ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
//
// Copyright (c) 2003-2020 Xsens Technologies B.V. or subsidiaries worldwide.
// 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 names of the copyright holders nor the names of their 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 HOLDERS 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.THE LAWS OF THE NETHERLANDS
// SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
// OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
// ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
//
#include "mtibasedevice.h"
#include "xsdef.h"
#include "synclinemk4.h"
#include "synclinegmt.h"
#include <xstypes/xsoutputconfigurationarray.h>
#include <xstypes/xssyncsettingarray.h>
#include <xstypes/xsportinfo.h>
#include "xsicccommand.h"
#include <xstypes/xsmatrix.h>
#include "xsiccrepmotionresult.h"
#include <xstypes/xsquaternion.h>
#include <xstypes/xsvector.h>
#include <set>
#include <xstypes/xsstatusflag.h>
using namespace xsens;
/*! \brief Constructs a device
\param comm The communicator to construct with
*/
MtiBaseDevice::MtiBaseDevice(Communicator* comm)
: MtDeviceEx(comm)
{
}
/*! \brief Constructs a child device for a master device
\param master The master device to construct for
*/
MtiBaseDevice::MtiBaseDevice(XsDevice* master)
: MtDeviceEx(master, XsDeviceId())
{
}
MtiBaseDevice::~MtiBaseDevice()
{
}
/*! \copybrief XsDevice::setHeadingOffset
*/
bool MtiBaseDevice::setHeadingOffset(double)
{
return false;
}
/*! \copybrief XsDevice::outputConfiguration
*/
XsOutputConfigurationArray MtiBaseDevice::outputConfiguration() const
{
XsMessage snd(XMID_ReqOutputConfiguration), rcv;
if (!doTransaction(snd, rcv))
return XsOutputConfigurationArray();
XsOutputConfigurationArray rv;
XsSize count = rcv.getDataSize() >> 2;
for (XsSize row = 0; row < count; row++)
{
uint16_t dataId, freq;
dataId = rcv.getDataShort(row * 4);
freq = rcv.getDataShort(2 + row * 4);
rv.push_back(XsOutputConfiguration((XsDataIdentifier)dataId, freq));
}
return rv;
}
/*! \brief Set the output configuration for this device
\param config The desired output configuration
\returns true if the output configuration was successfully updated
*/
bool MtiBaseDevice::setOutputConfiguration(XsOutputConfigurationArray& config)
{
if (!deviceId().isMti6X0())
setStringOutputMode(0, 0, 0);
return MtDeviceEx::setOutputConfiguration(config);
}
/*! \copybrief XsDevice::setAlignmentRotationMatrix
*/
bool MtiBaseDevice::setAlignmentRotationQuaternion(XsAlignmentFrame frame, const XsQuaternion& quat)
{
XsMessage snd(XMID_SetAlignmentRotation, 1 + XS_LEN_ALIGNMENTROTATION);
snd.setBusId(busId());
snd.setDataByte((uint8_t)frame);
for (XsSize i = 0; i < 4; ++i)
snd.setDataFloat((float)quat[i], (uint16_t) (1 + i * sizeof(float)));
return doTransaction(snd);
}
/*! \copybrief XsDevice::alignmentRotationQuaternion
*/
XsQuaternion MtiBaseDevice::alignmentRotationQuaternion(XsAlignmentFrame frame) const
{
XsQuaternion quat;
XsMessage snd(XMID_ReqAlignmentRotation), rcv;
snd.setDataByte(frame);
if (doTransaction(snd, rcv))
{
for (XsSize i = 0; i < 4; ++i)
quat[i] = rcv.getDataFloat(1 + i * 4);
}
return quat;
}
/*! \copybrief XsDevice::setAlignmentRotationMatrix
*/
bool MtiBaseDevice::setAlignmentRotationMatrix(XsAlignmentFrame frame, const XsMatrix& matrix)
{
return setAlignmentRotationQuaternion(frame, XsQuaternion(matrix).normalized());
}
/*! \copybrief XsDevice::alignmentRotationMatrix
*/
XsMatrix MtiBaseDevice::alignmentRotationMatrix(XsAlignmentFrame frame) const
{
XsMatrix matrix;
matrix.fromQuaternion(alignmentRotationQuaternion(frame));
return matrix;
}
/*! \copybrief XsDevice::setSyncSettings
*/
bool MtiBaseDevice::setSyncSettings(const XsSyncSettingArray &s)
{
/* Mk4 sync lines:
* XSL_ClockIn => 0 external clock sync (SMCU)
* XSL_GnssClockIn => 1 GNSS clock sync (DSP?)
* XSL_In1 => 2 send data line (IMCU)
* XSL_Bi1In => 3 SMCU
* XSL_Bi1Out => 4 SMCU
*/
unsigned int timeResolution = XsDevice::syncSettingsTimeResolutionInMicroSeconds(deviceId());
if (s.size() > 10)
return false;
//if no item, create the length of 1 item with zero values
XsMessage snd(XMID_SetSyncConfiguration, (s.size() == 0) ? 12 : s.size()*12);
snd.setBusId(busId());
/* create message but abort if we encounter anything out of the ordinary
each sync setting is:
0: event / action (function)
1: line
2: polarity
3: triggerOnce
4-5: skipFirst
6-7: skipFactor
8-9: pulse width
10-11: delay/offset/clock frequency
*/
for (size_t i = 0; i < s.size(); ++i)
{
const XsSyncSetting& setting = s[i];
XsSize offset = i*12;
snd.setDataByte(setting.m_function, offset);
const uint8_t line = syncLine(setting);
snd.setDataByte(line, offset+1);
assert(setting.m_polarity != XSP_None);
snd.setDataByte(setting.m_polarity, offset+2);
snd.setDataByte(setting.m_triggerOnce?1:0, offset+3);
snd.setDataShort(setting.m_skipFirst, offset+4);
snd.setDataShort(setting.m_skipFactor, offset+6);
snd.setDataShort((uint16_t) (setting.m_pulseWidth / timeResolution), offset+8);
uint16_t value = 0;
if (setting.m_function == XSF_ClockBiasEstimation || setting.m_function == XSF_SampleAndSend)
{
snd.setDataShort(setting.m_clockPeriod, offset+10);
}
else
{
value = (uint16_t) (int16_t) (setting.m_offset / (int) timeResolution);
snd.setDataShort(value, offset+10);
}
}
return doTransaction(snd);
}
/*! \copybrief XsDevice::syncSettings
*/
XsSyncSettingArray MtiBaseDevice::syncSettings() const
{
XsMessage snd(XMID_SyncConfiguration), rcv;
if (!doTransaction(snd, rcv))
return XsSyncSettingArray();
const uint8_t* emtsBuffer = rcv.getDataBuffer();
return syncSettingsFromBuffer(emtsBuffer);
}
/*! \brief Create an XsSyncSttingsArray from the given buffer of sync configuration data */
XsSyncSettingArray MtiBaseDevice::syncSettingsFromBuffer(const uint8_t* buffer) const
{
unsigned int timeResolution = XsDevice::syncSettingsTimeResolutionInMicroSeconds(deviceId());
XsSyncSettingArray rv;
for (XsSize i = 0; i < 10; ++i)
{
XsSize offset = i*12;
XsSyncSetting ss;
ss.m_function = (XsSyncFunction) buffer[offset];
ss.m_polarity = (XsSyncPolarity) buffer[offset+2];
if (ss.m_polarity == XSP_None)
break;
ss.m_line = syncSettingsLine(buffer, offset);
ss.m_triggerOnce = buffer[offset+3];
memcpy((void*) &ss.m_skipFirst, (void const*) &buffer[offset+4], sizeof(uint16_t));
memcpy((void*) &ss.m_skipFactor, (void const*) &buffer[offset+6], sizeof(uint16_t));
memcpy((void*) &ss.m_pulseWidth, (void const*) &buffer[offset+8], sizeof(int32_t));
ss.m_pulseWidth *= (uint32_t) timeResolution;
if (ss.m_function == XSF_ClockBiasEstimation || ss.m_function == XSF_SampleAndSend)
memcpy((void*) &ss.m_clockPeriod, (void const*) &buffer[offset+10], sizeof(uint16_t));
else
{
memcpy((void*) &ss.m_offset, (void const*) &buffer[offset+10], sizeof(int32_t));
ss.m_offset *= (int32_t) timeResolution;
}
rv.push_back(ss);
}
return rv;
}
/*! \returns the update rate for the specified XsDataIdentifier in the configuration list or 0 if no such data available
\param dataType The data identifier for which the update rate is requested
\param configurations The configuration list in which the specified dataType must be looked up
*/
int MtiBaseDevice::calculateUpdateRateImp(XsDataIdentifier dataType, const XsOutputConfigurationArray& configurations) const
{
int matchLevel = 0;
int result = 0;
bool groupCheck = ((dataType & XDI_TypeMask) == dataType);
for (XsOutputConfigurationArray::const_iterator i = configurations.begin(); i != configurations.end(); ++i)
{
int ml = 0;
if ((dataType & XDI_FullTypeMask) == (i->m_dataIdentifier & XDI_FullTypeMask))
{
if (dataType == i->m_dataIdentifier)
ml = 3;
else
ml = 2;
}
else if (groupCheck && (dataType == (i->m_dataIdentifier & XDI_TypeMask)))
ml = 1;
if (ml > matchLevel)
{
result = i->m_frequency;
if (ml == 3)
break;
matchLevel = ml;
}
}
return result;
}
/*! \returns the update rate for the specified XsDataIdentifier or 0 if no such data available
\details This function only looks at the output configuration configured in the device, not XDA calculated data
\param dataType The data identifier to use
\sa calculateUpdateRateImp
*/
int MtiBaseDevice::calculateUpdateRate(XsDataIdentifier dataType) const
{
return calculateUpdateRateImp(dataType, outputConfiguration());
}
/*! \returns the base update rate (Hz) corresponding to the dataType. Returns 0 if no update rate is available
\param dataType The data identifier to use
*/
int MtiBaseDevice::getBaseFrequency(XsDataIdentifier dataType) const
{
return getBaseFrequencyInternal(dataType).m_frequency;
}
/*! \copybrief XsDevice::supportedUpdateRates
*/
std::vector<int> MtiBaseDevice::supportedUpdateRates(XsDataIdentifier dataType) const
{
std::vector<int> updateRates;
auto baseFreq = getBaseFrequencyInternal(dataType);
if (baseFreq.m_frequency == 0)
return updateRates;
if (!baseFreq.m_divedable)
{
updateRates.push_back(baseFreq.m_frequency);
return updateRates;
}
std::set<int> unsupportedUpdateRates;
unsupportedUpdateRates.insert(500);
unsupportedUpdateRates.insert(250);
unsupportedUpdateRates.insert(125);
for (int skip = 0; skip <= baseFreq.m_frequency; ++skip)
{
int freq = calcFrequency(baseFreq.m_frequency, (uint16_t) skip);
if (freq * (skip+1) == baseFreq.m_frequency)
{
if (unsupportedUpdateRates.count(freq) == 0)
updateRates.push_back(freq);
}
}
return updateRates;
}
/*! \copybrief XsDevice::setNoRotation
*/
bool MtiBaseDevice::setNoRotation(uint16_t duration)
{
return MtDeviceEx::setNoRotation(duration);
}
/*! \copybrief XsDevice::setInitialPositionLLA
*/
bool MtiBaseDevice::setInitialPositionLLA(const XsVector& lla)
{
uint8_t bid = (uint8_t) busId();
if (bid == XS_BID_INVALID || bid == XS_BID_BROADCAST || lla.size() != 3)
return false;
XsMessage snd(XMID_SetLatLonAlt, 3*sizeof(double));
snd.setDataDouble(lla[0], 0);
snd.setDataDouble(lla[1], 8);
snd.setDataDouble(lla[2], 16);
snd.setBusId(bid);
return doTransaction(snd);
}
/*! \copybrief XsDevice::utcTime
*/
XsTimeInfo MtiBaseDevice::utcTime() const
{
uint8_t bid = (uint8_t) busId();
if (bid == XS_BID_INVALID || bid == XS_BID_BROADCAST)
return XsTimeInfo();
XsMessage snd(XMID_ReqUtcTime, 0), rcv;
snd.setBusId(bid);
if (!doTransaction(snd, rcv))
return XsTimeInfo();
XsTimeInfo time;
time.m_nano = rcv.getDataLong(0);
time.m_year = rcv.getDataShort(4);
time.m_month = rcv.getDataByte(6);
time.m_day = rcv.getDataByte(7);
time.m_hour = rcv.getDataByte(8);
time.m_minute = rcv.getDataByte(9);
time.m_second = rcv.getDataByte(10);
time.m_valid = rcv.getDataByte(11);
time.m_utcOffset = 0;
return time;
}
/*! \copybrief XsDevice::setUtcTime
*/
bool MtiBaseDevice::setUtcTime(const XsTimeInfo& time)
{
uint8_t bid = (uint8_t) busId();
if (bid == XS_BID_INVALID || bid == XS_BID_BROADCAST)
return false;
XsMessage snd(XMID_SetUtcTime, XS_LEN_UTCTIME);
snd.setDataLong(time.m_nano, 0);
snd.setDataShort(time.m_year, 4);
snd.setDataByte(time.m_month, 6);
snd.setDataByte(time.m_day, 7);
snd.setDataByte(time.m_hour, 8);
snd.setDataByte(time.m_minute, 9);
snd.setDataByte(time.m_second, 10);
snd.setDataByte(time.m_valid, 11);
snd.setBusId(bid);
if (!doTransaction(snd))
return false;
return true;
}
/*! \copybrief XsDevice::setErrorMode
*/
bool MtiBaseDevice::setErrorMode(XsErrorMode em)
{
if (em == XEM_IncreasePacketCounterAndSendError)
return true;
return false;
}
/*! \copybrief XsDevice::errorMode
*/
XsErrorMode MtiBaseDevice::errorMode() const
{
return XEM_IncreasePacketCounterAndSendError;
}
/*! \copybrief XsDevice::rs485TransmissionDelay
*/
uint16_t MtiBaseDevice::rs485TransmissionDelay() const
{
XsMessage snd(XMID_ReqTransmitDelay), rcv;
if (!doTransaction(snd, rcv))
return 0;
return rcv.getDataShort();
}
/*! \copybrief XsDevice::setRs485TransmissionDelay
*/
bool MtiBaseDevice::setRs485TransmissionDelay(uint16_t delay)
{
return delay == 0;
}
/*! \copybrief XsDevice::resetRemovesPort
*/
bool MtiBaseDevice::resetRemovesPort() const
{
Communicator* comm = communicator();
if (!comm)
return false;
bool removesPort = false;
uint16_t vid, pid;
comm->portInfo().getVidPid(vid, pid);
// Direct connection, COM port will be removed
if (vid == XSENS_VENDOR_ID && pid < 0x00FF)
removesPort = true;
return removesPort;
}
/*! \brief Returns the sync settings line for a generic mti device
*/
XsSyncLine MtiBaseDevice::syncSettingsLine(const uint8_t* buff, XsSize offset) const
{
if (deviceId().isMtMark4() || deviceId().isMtMark5())
return xsl4ToXsl((SyncLineMk4) buff[offset + 1]);
else
return xslgmtToXsl((SyncLineGmt) buff[offset + 1]);
}
/*! \brief Returns the sync line for a generic mti device
*/
uint8_t MtiBaseDevice::syncLine(const XsSyncSetting& setting) const
{
if (deviceId().isMtMark4() || deviceId().isMtMark5())
{
SyncLineMk4 mk4Line = xslToXsl4(setting.m_line);
assert(mk4Line != XSL4_Invalid);
if (mk4Line == XSL4_ClockIn || mk4Line == XSL4_GnssClockIn)
{
assert(setting.m_function == XSF_ClockBiasEstimation);
}
return static_cast<uint8_t>(mk4Line);
}
else
{
SyncLineGmt gmtLine = xslToXslgmt(setting.m_line);
assert(gmtLine != XSLGMT_Invalid);
if (gmtLine == XSLGMT_ClockIn)
{
assert(setting.m_function == XSF_SampleAndSend);
}
return static_cast<uint8_t>(gmtLine);
}
}
bool MtiBaseDevice::messageLooksSane(const XsMessage &msg) const
{
(void)msg;
return true;
}
/*! \returns True if device uses on board filtering */
bool MtiBaseDevice::deviceUsesOnBoardFiltering()
{
return updateRateForDataIdentifier(XDI_OrientationGroup) > 0;
}
/*! \brief Starts the representative motion
\returns True if successful
*/
bool MtiBaseDevice::startRepresentativeMotion()
{
if (!hasIccSupport())
return false;
if (!deviceUsesOnBoardFiltering())
return false;
XsMessage snd(XMID_IccCommand, 1);
snd.setBusId(busId());
snd.setDataByte(XIC_StartRepMotion);
if (!doTransaction(snd))
return false;
return true;
}
/*! \returns True if the representative motion is running */
bool MtiBaseDevice::representativeMotionState()
{
if (!hasIccSupport())
return false;
if (!deviceUsesOnBoardFiltering())
return false;
bool enabled = false;
XsMessage snd(XMID_IccCommand, 1);
snd.setBusId(busId());
snd.setDataByte(XIC_RepMotionState);
XsMessage rcv;
if (doTransaction(snd, rcv))
enabled = (rcv.getDataByte(1) != 0);
return enabled;
}
/*! \brief Stops the representative motion
\returns The results of the representative motion
*/
XsIccRepMotionResult MtiBaseDevice::stopRepresentativeMotion()
{
XsIccRepMotionResult result;
if (!hasIccSupport())
return result;
if (!deviceUsesOnBoardFiltering())
return result;
XsMessage snd(XMID_IccCommand, 1), rcv;
snd.setBusId(busId());
snd.setDataByte(XIC_StopRepMotion);
if (doTransaction(snd, rcv, 3500))
{
result.m_ddtAccuracy = rcv.getDataFloat(1);
result.m_dimension = rcv.getDataByte(5);
result.m_status = rcv.getDataByte(6);
}
return result;
}
/*! \brief Stores the ICC results
\returns True if successful
*/
bool MtiBaseDevice::storeIccResults()
{
if (!deviceUsesOnBoardFiltering())
return false;
XsMessage snd(XMID_IccCommand, 1);
snd.setBusId(busId());
snd.setDataByte(XIC_StoreResults);
return doTransaction(snd, 2000);
}
/*! \returns True if this device has an ICC support
*/
bool MtiBaseDevice::hasIccSupport() const
{
return (firmwareVersion() >= XsVersion(1, 5, 0));
}
void MtiBaseDevice::fetchAvailableHardwareScenarios()
{
if (deviceId().isImu()) // If we are a 100 type device,
m_hardwareFilterProfiles.clear(); // there are no filter profiles in the firmware.
else // For other device types,
MtDeviceEx::fetchAvailableHardwareScenarios(); // fetch the scenarios.
}
|
; vim: set syntax=z80:
.module font_file
.area _CODE
#data _INITIALIZED
ds 96*8
#code _INITIALIZER
_g_font:
; space
db 3
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
; !
db 2
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 00000000b
db 10000000b
db 00000000b
; "
db 4
db 10100000b
db 10100000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
; #
db 6
db 00000000b
db 01010000b
db 11111000b
db 01010000b
db 11111000b
db 01010000b
db 00000000b
; $
db 6
db 00100000b
db 01111000b
db 10100000b
db 01110000b
db 00101000b
db 11110000b
db 00100000b
; %
db 6
db 00000000b
db 00000000b
db 10010000b
db 00100000b
db 01000000b
db 10010000b
db 00000000b
; &
db 5
db 01000000b
db 10100000b
db 10000000b
db 01010000b
db 10100000b
db 01010000b
db 00000000b
; '
db 2
db 10000000b
db 10000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
; (
db 3
db 01000000b
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 01000000b
; )
db 3
db 10000000b
db 01000000b
db 01000000b
db 01000000b
db 01000000b
db 01000000b
db 10000000b
; *
db 4
db 00000000b
db 10100000b
db 01000000b
db 10100000b
db 00000000b
db 00000000b
db 00000000b
; +
db 4
db 00000000b
db 00000000b
db 01000000b
db 11100000b
db 01000000b
db 00000000b
db 00000000b
; ,
db 2
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 10000000b
db 10000000b
; -
db 4
db 00000000b
db 00000000b
db 00000000b
db 11100000b
db 00000000b
db 00000000b
db 00000000b
; .
db 2
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 10000000b
db 00000000b
; /
db 4
db 00100000b
db 00100000b
db 01000000b
db 01000000b
db 10000000b
db 10000000b
db 00000000b
; 0
db 4
db 01000000b
db 10100000b
db 10100000b
db 10100000b
db 10100000b
db 01000000b
db 00000000b
; 1
db 4
db 01000000b
db 11000000b
db 01000000b
db 01000000b
db 01000000b
db 11100000b
db 00000000b
; 2
db 4
db 01000000b
db 10100000b
db 00100000b
db 01000000b
db 10000000b
db 11100000b
db 00000000b
; 3
db 4
db 11000000b
db 00100000b
db 01000000b
db 00100000b
db 00100000b
db 11000000b
db 00000000b
; 4
db 4
db 10100000b
db 10100000b
db 11100000b
db 00100000b
db 00100000b
db 00100000b
db 00000000b
; 5
db 4
db 11100000b
db 10000000b
db 11000000b
db 00100000b
db 00100000b
db 11000000b
db 00000000b
; 6
db 4
db 01100000b
db 10000000b
db 11000000b
db 10100000b
db 10100000b
db 01000000b
db 00000000b
; 7
db 4
db 11100000b
db 00100000b
db 01000000b
db 01000000b
db 01000000b
db 01000000b
db 00000000b
; 8
db 4
db 01000000b
db 10100000b
db 01000000b
db 10100000b
db 10100000b
db 01000000b
db 00000000b
; 9
db 4
db 01000000b
db 10100000b
db 01100000b
db 00100000b
db 10100000b
db 01000000b
db 00000000b
; :
db 2
db 00000000b
db 10000000b
db 00000000b
db 00000000b
db 00000000b
db 10000000b
db 00000000b
; ;
db 2
db 00000000b
db 10000000b
db 00000000b
db 00000000b
db 00000000b
db 10000000b
db 10000000b
; <
db 4
db 00000000b
db 00100000b
db 01000000b
db 10000000b
db 01000000b
db 00100000b
db 00000000b
; =
db 4
db 00000000b
db 00000000b
db 11100000b
db 00000000b
db 11100000b
db 00000000b
db 00000000b
; >
db 4
db 00000000b
db 10000000b
db 01000000b
db 00100000b
db 01000000b
db 10000000b
db 00000000b
; ?
db 4
db 01000000b
db 10100000b
db 00100000b
db 01000000b
db 00000000b
db 01000000b
db 00000000b
; @
db 5
db 00000000b
db 01100000b
db 10110000b
db 10110000b
db 10000000b
db 01100000b
db 00000000b
; A
db 4
db 01000000b
db 10100000b
db 11100000b
db 10100000b
db 10100000b
db 10100000b
db 00000000b
; B
db 4
db 11000000b
db 10100000b
db 11000000b
db 10100000b
db 10100000b
db 11000000b
db 00000000b
; C
db 4
db 01100000b
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 01100000b
db 00000000b
; D
db 4
db 11000000b
db 10100000b
db 10100000b
db 10100000b
db 10100000b
db 11000000b
db 00000000b
; E
db 4
db 11100000b
db 10000000b
db 11000000b
db 10000000b
db 10000000b
db 11100000b
db 00000000b
; F
db 4
db 11100000b
db 10000000b
db 11000000b
db 10000000b
db 10000000b
db 10000000b
db 00000000b
; G
db 4
db 01100000b
db 10000000b
db 10000000b
db 10100000b
db 10100000b
db 01100000b
db 00000000b
; H
db 4
db 10100000b
db 10100000b
db 11100000b
db 10100000b
db 10100000b
db 10100000b
db 00000000b
; I
db 4
db 11100000b
db 01000000b
db 01000000b
db 01000000b
db 01000000b
db 11100000b
db 00000000b
; J
db 4
db 11100000b
db 00100000b
db 00100000b
db 00100000b
db 00100000b
db 11000000b
db 00000000b
; K
db 4
db 10100000b
db 10100000b
db 11000000b
db 11000000b
db 10100000b
db 10100000b
db 00000000b
; L
db 4
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 11100000b
db 00000000b
; M
db 6
db 10001000b
db 11011000b
db 10101000b
db 10001000b
db 10001000b
db 10001000b
db 00000000b
; N
db 5
db 10010000b
db 11010000b
db 10110000b
db 10010000b
db 10010000b
db 10010000b
db 00000000b
; O
db 5
db 01100000b
db 10010000b
db 10010000b
db 10010000b
db 10010000b
db 01100000b
db 00000000b
; P
db 4
db 11000000b
db 10100000b
db 11000000b
db 10000000b
db 10000000b
db 10000000b
db 00000000b
; Q
db 5
db 01100000b
db 10010000b
db 10010000b
db 10010000b
db 10110000b
db 01110000b
db 00000000b
; R
db 4
db 11000000b
db 10100000b
db 11000000b
db 11000000b
db 10100000b
db 10100000b
db 00000000b
; S
db 4
db 01100000b
db 10000000b
db 01000000b
db 00100000b
db 00100000b
db 11000000b
db 00000000b
; T
db 4
db 11100000b
db 01000000b
db 01000000b
db 01000000b
db 01000000b
db 01000000b
db 00000000b
; U
db 4
db 10100000b
db 10100000b
db 10100000b
db 10100000b
db 10100000b
db 01100000b
db 00000000b
; V
db 4
db 10100000b
db 10100000b
db 10100000b
db 10100000b
db 01000000b
db 01000000b
db 00000000b
; W
db 6
db 10001000b
db 10001000b
db 10001000b
db 10101000b
db 01010000b
db 01010000b
db 00000000b
; X
db 4
db 10100000b
db 10100000b
db 01000000b
db 10100000b
db 10100000b
db 10100000b
db 00000000b
; Y
db 4
db 10100000b
db 10100000b
db 01000000b
db 01000000b
db 01000000b
db 01000000b
db 00000000b
; Z
db 4
db 11100000b
db 00100000b
db 01000000b
db 01000000b
db 10000000b
db 11100000b
db 00000000b
; [
db 3
db 11000000b
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 11000000b
; \
db 4
db 10000000b
db 10000000b
db 01000000b
db 01000000b
db 00100000b
db 00100000b
db 00000000b
; ]
db 3
db 11000000b
db 01000000b
db 01000000b
db 01000000b
db 01000000b
db 01000000b
db 11000000b
; ^
db 4
db 01000000b
db 10100000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
; _
db 4
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 00000000b
db 11100000b
; £
db 5
db 01100000b
db 10010000b
db 01000000b
db 11100000b
db 01000000b
db 11110000b
db 00000000b
; a
db 4
db 00000000b
db 00000000b
db 01100000b
db 10100000b
db 10100000b
db 01100000b
db 00000000b
; b
db 4
db 10000000b
db 10000000b
db 11000000b
db 10100000b
db 10100000b
db 11000000b
db 00000000b
; c
db 3
db 00000000b
db 00000000b
db 01000000b
db 10000000b
db 10000000b
db 01000000b
db 00000000b
; d
db 4
db 00100000b
db 00100000b
db 01100000b
db 10100000b
db 10100000b
db 01100000b
db 00000000b
; e
db 4
db 00000000b
db 00000000b
db 01000000b
db 10100000b
db 11000000b
db 01100000b
db 00000000b
; f
db 3
db 01000000b
db 10000000b
db 10000000b
db 11000000b
db 10000000b
db 10000000b
db 00000000b
; g
db 4
db 00000000b
db 00000000b
db 01100000b
db 10100000b
db 01100000b
db 00100000b
db 11000000b
; h
db 4
db 10000000b
db 10000000b
db 11000000b
db 10100000b
db 10100000b
db 10100000b
db 00000000b
; i
db 2
db 10000000b
db 00000000b
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 00000000b
; j
db 3
db 01000000b
db 00000000b
db 01000000b
db 01000000b
db 01000000b
db 01000000b
db 10000000b
; k
db 4
db 10000000b
db 10000000b
db 10100000b
db 11000000b
db 10100000b
db 10100000b
db 00000000b
; l
db 2
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 00000000b
; m
db 6
db 00000000b
db 00000000b
db 11010000b
db 10101000b
db 10101000b
db 10101000b
db 00000000b
; n
db 4
db 00000000b
db 00000000b
db 11000000b
db 10100000b
db 10100000b
db 10100000b
db 00000000b
; o
db 4
db 00000000b
db 00000000b
db 01000000b
db 10100000b
db 10100000b
db 01000000b
db 00000000b
; p
db 4
db 00000000b
db 00000000b
db 11000000b
db 10100000b
db 10100000b
db 11000000b
db 10000000b
; q
db 4
db 00000000b
db 00000000b
db 01100000b
db 10100000b
db 10100000b
db 01100000b
db 00100000b
; r
db 3
db 00000000b
db 00000000b
db 11000000b
db 10000000b
db 10000000b
db 10000000b
db 00000000b
; s
db 4
db 00000000b
db 00000000b
db 01100000b
db 10000000b
db 01100000b
db 11000000b
db 00000000b
; t
db 3
db 10000000b
db 10000000b
db 11000000b
db 10000000b
db 10000000b
db 01000000b
db 00000000b
; u
db 4
db 00000000b
db 00000000b
db 10100000b
db 10100000b
db 10100000b
db 01100000b
db 00000000b
; v
db 4
db 00000000b
db 00000000b
db 10100000b
db 10100000b
db 10100000b
db 01000000b
db 00000000b
; w
db 6
db 00000000b
db 00000000b
db 10001000b
db 10001000b
db 10101000b
db 01010000b
db 00000000b
; x
db 4
db 00000000b
db 00000000b
db 10100000b
db 01000000b
db 01000000b
db 10100000b
db 00000000b
; y
db 4
db 00000000b
db 00000000b
db 10100000b
db 10100000b
db 01100000b
db 00100000b
db 11000000b
; z
db 4
db 00000000b
db 00000000b
db 11100000b
db 00100000b
db 01000000b
db 11100000b
db 00000000b
; {
db 4
db 00100000b
db 01000000b
db 01000000b
db 11000000b
db 01000000b
db 01000000b
db 00100000b
; |
db 2
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 10000000b
db 10000000b
; }
db 4
db 10000000b
db 01000000b
db 01000000b
db 01100000b
db 01000000b
db 01000000b
db 10000000b
; ~
db 5
db 00000000b
db 00000000b
db 01010000b
db 10100000b
db 00000000b
db 00000000b
db 00000000b
; copyright
db 8
db 00111000b
db 01000100b
db 10011010b
db 10100010b
db 10011010b
db 01000100b
db 00111000b
|
; O3 project lab
; loop
; Hudson Schumaker
extern _o3prtInt, _o3prt
section .data
x dd 0
y dd 1000
fmtstr: db "%s", 0xA, 0x0 ; format for printing a string, "\n" and end the "string"
section .text
global _main
_main:
push rbp
mov rbp, rsp
mov rdi, x
movsx r12, dword [rdi]
mov rdi, y
movsx r13, dword [rdi]
jmp _L2
jmp _exit
_L3:
mov rdi, r12
mov rax, 0
call _o3prtInt
inc r12
_L2:
cmp r12, r13
jne _L3
_exit:
mov rax, 0x02000001 ; exit system call
xor rdi, rdi ; out error code 0 to exit successfully
syscall
|
global _print_newline
_print_newline:
push bp
mov bp, sp
call os_print_newline
pop bp
ret
|
#include "Window.h"
#include <cstdio>
#include <Imgui/imgui.h>
#include <Imgui/imgui_impl_sdl.h>
#include <Imgui/imgui_impl_opengl3.h>
#include "Util/Util.h"
#include "../CUDA_Source/Common.h"
static void GLAPIENTRY gl_message_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar * message, const void * user_param) {
fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "", type, severity, message);
}
void Window::init(const char * title) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL);
context = SDL_GL_CreateContext(window);
SDL_SetWindowResizable(window, SDL_TRUE);
SDL_GL_SetSwapInterval(0);
GLenum status = glewInit();
if (status != GLEW_OK) {
printf("Glew failed to initialize!\n");
abort();
}
puts("OpenGL Info:");
printf("Version: %s\n", glGetString(GL_VERSION));
printf("GLSL: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
printf("Vendor: %s\n", glGetString(GL_VENDOR));
printf("Renderer: %s\n", glGetString(GL_RENDERER));
puts("");
#if false
glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(gl_message_callback, nullptr);
#endif
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
//glEnable(GL_CULL_FACE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
width = SCREEN_WIDTH;
height = SCREEN_HEIGHT;
glGenTextures(1, &frame_buffer_handle);
glBindTexture(GL_TEXTURE_2D, frame_buffer_handle);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, nullptr);
shader = Shader::load("Shaders/screen_vertex.glsl", "Shaders/screen_fragment.glsl");
shader.bind();
glUniform1i(shader.get_uniform("screen"), 0);
IMGUI_CHECKVERSION();
ImGui::CreateContext();
// Setup Platform/Renderer bindings
ImGui_ImplSDL2_InitForOpenGL(window, context);
ImGui_ImplOpenGL3_Init("#version 450");
ImGui::StyleColorsDark();
}
void Window::free() {
SDL_GL_DeleteContext(context);
SDL_DestroyWindow(window);
SDL_Quit();
}
void Window::render_framebuffer() const {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader.bind();
glBindTexture(GL_TEXTURE_2D, frame_buffer_handle);
// Draws a single Triangle, without any buffers
// The Vertex Shader makes sure positions + uvs work out
glDrawArrays(GL_TRIANGLES, 0, 3);
shader.unbind();
}
void Window::gui_begin() const {
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL2_NewFrame(window);
ImGui::NewFrame();
}
void Window::gui_end() const {
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
void Window::swap() {
SDL_GL_SwapWindow(window);
SDL_Event event;
while (SDL_PollEvent(&event)) {
ImGui_ImplSDL2_ProcessEvent(&event);
switch (event.type) {
case SDL_WINDOWEVENT: {
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
width = event.window.data1;
height = event.window.data2;
glDeleteTextures(1, &frame_buffer_handle);
glGenTextures (1, &frame_buffer_handle);
glBindTexture(GL_TEXTURE_2D, frame_buffer_handle);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, nullptr);
glViewport(0, 0, width, height);
if (resize_handler) resize_handler(frame_buffer_handle, width, height);
}
break;
}
case SDL_QUIT: is_closed = true; break;
}
}
}
void Window::read_frame_buffer(unsigned char * data) const {
glMemoryBarrier(GL_PIXEL_BUFFER_BARRIER_BIT);
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
}
|
;
; CPC Maths Routines
;
; August 2003 **_|warp6|_** <kbaccam /at/ free.fr>
;
; $Id: stkequ.asm,v 1.4 2016-06-22 19:50:49 dom Exp $
;
SECTION smc_fp
INCLUDE "target/cpc/def/cpcfp.def"
PUBLIC stkequ
EXTERN fa
.stkequ
ld de,fa+1 ; (fa+1)<-(sp+3)
ld hl,3
add hl,sp
ld bc,5
ldir
pop hl ;ret to program
pop bc ;get rid of fp number
pop bc
pop bc
jp (hl) ;outa here back to program
|
; A344568: Decimal expansion of 2*(1+sqrt(82))/9.
; Submitted by Christian Krause
; 2,2,3,4,5,3,0,0,3,0,6,9,7,2,0,3,6,9,4,7,9,4,1,7,9,5,9,2,6,6,3,1,2,5,8,6,9,5,6,7,1,3,8,7,6,9,7,9,9,3,2,0,0,6,1,4,6,2,6,0,9,1,6,2,2,2,6,3,6,8,4,4,0,1,7,0,2,3,5,3,8,5,1,9,6,6,5,7,9,2,8,5,7
mov $1,1
mov $2,1
mov $3,$0
mul $3,4
lpb $3
mul $1,$3
mul $2,$3
add $1,$2
cmp $6,0
add $5,$6
div $1,$5
div $2,$5
add $2,$1
mul $1,2
mul $2,9
sub $3,1
lpe
mul $1,2
mov $4,10
pow $4,$0
div $2,$4
div $1,$2
mov $0,$1
mod $0,10
|
; A118425: Number of binary sequences of length n containing exactly one subsequence 001.
; 0,0,0,1,4,12,30,68,144,291,568,1080,2012,3688,6672,11941,21180,37284,65210,113420,196320,338375,581040,994416,1696824,2887632,4902240,8304073,14038324,23688636,39905238,67118420,112726512,189072363
mov $30,$0
mov $32,$0
lpb $32
clr $0,30
mov $0,$30
sub $32,1
sub $0,$32
mov $27,$0
mov $29,$0
lpb $29
mov $0,$27
sub $29,1
sub $0,$29
sub $0,1
cal $0,1629 ; Self-convolution of Fibonacci numbers.
add $28,$0
lpe
add $31,$28
lpe
mov $1,$31
|
; A016770: a(n) = (3*n)^6.
; 0,729,46656,531441,2985984,11390625,34012224,85766121,191102976,387420489,729000000,1291467969,2176782336,3518743761,5489031744,8303765625,12230590464,17596287801,24794911296,34296447249,46656000000,62523502209,82653950016,107918163081,139314069504,177978515625,225199600704,282429536481,351298031616,433626201009,531441000000,646990183449,782757789696,941480149401,1126162419264,1340095640625,1586874322944,1870414552161,2194972623936,2565164201769,2985984000000,3462825991689,4001504141376
pow $0,6
mul $0,729
|
/*###############################################################################
#
# Copyright (c) 2020 NVIDIA Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
###############################################################################*/
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <chrono>
#include <string>
#include <iostream>
#include <cuda_runtime_api.h>
#include "nvCVOpenCV.h"
#include "nvVideoEffects.h"
#include "opencv2/opencv.hpp"
#ifdef _MSC_VER
#define strcasecmp _stricmp
#include <Windows.h>
#else // !_MSC_VER
#include <sys/stat.h>
#endif // _MSC_VER
#define BAIL_IF_ERR(err) do { if (0 != (err)) { goto bail; } } while(0)
#define BAIL_IF_NULL(x, err, code) do { if ((void*)(x) == NULL) { err = code; goto bail; } } while(0)
#define NVCV_ERR_HELP 411
#ifdef _WIN32
#define DEFAULT_CODEC "avc1"
#else // !_WIN32
#define DEFAULT_CODEC "H264"
#endif // _WIN32
bool FLAG_debug = false,
FLAG_verbose = false,
FLAG_show = false,
FLAG_progress = false,
FLAG_webcam = false;
float FLAG_strength = 0.f;
std::string FLAG_codec = DEFAULT_CODEC,
FLAG_camRes = "1280x720",
FLAG_inFile,
FLAG_outFile,
FLAG_outDir,
FLAG_modelDir;
// Set this when using OTA Updates
// This path is used by nvVideoEffectsProxy.cpp to load the SDK dll
// when using OTA Updates
char *g_nvVFXSDKPath = NULL;
static bool GetFlagArgVal(const char *flag, const char *arg, const char **val) {
if (*arg != '-')
return false;
while (*++arg == '-')
continue;
const char *s = strchr(arg, '=');
if (s == NULL) {
if (strcmp(flag, arg) != 0)
return false;
*val = NULL;
return true;
}
size_t n = s - arg;
if ((strlen(flag) != n) || (strncmp(flag, arg, n) != 0))
return false;
*val = s + 1;
return true;
}
static bool GetFlagArgVal(const char *flag, const char *arg, std::string *val) {
const char *valStr;
if (!GetFlagArgVal(flag, arg, &valStr))
return false;
val->assign(valStr ? valStr : "");
return true;
}
static bool GetFlagArgVal(const char *flag, const char *arg, bool *val) {
const char *valStr;
bool success = GetFlagArgVal(flag, arg, &valStr);
if (success) {
*val = (valStr == NULL ||
strcasecmp(valStr, "true") == 0 ||
strcasecmp(valStr, "on") == 0 ||
strcasecmp(valStr, "yes") == 0 ||
strcasecmp(valStr, "1") == 0
);
}
return success;
}
static bool GetFlagArgVal(const char *flag, const char *arg, float *val) {
const char *valStr;
bool success = GetFlagArgVal(flag, arg, &valStr);
if (success)
*val = strtof(valStr, NULL);
return success;
}
static bool GetFlagArgVal(const char *flag, const char *arg, long *val) {
const char *valStr;
bool success = GetFlagArgVal(flag, arg, &valStr);
if (success)
*val = strtol(valStr, NULL, 10);
return success;
}
static bool GetFlagArgVal(const char *flag, const char *arg, int *val) {
long longVal;
bool success = GetFlagArgVal(flag, arg, &longVal);
if (success)
*val = (int)longVal;
return success;
}
static void Usage() {
printf(
"DenoiseEffectApp [args ...]\n"
" where args is:\n"
" --in_file=<path> input file to be processed (can be an image but the best denoising performance is observed on videos)\n"
" --webcam use a webcam as the input\n"
" --out_file=<path> output file to be written\n"
" --show display the results in a window (for webcam, it is always true)\n"
" --strength=<value> strength of an effect [0-1]\n"
" --model_dir=<path> the path to the directory that contains the models\n"
" --codec=<fourcc> the fourcc code for the desired codec (default " DEFAULT_CODEC ")\n"
" --progress show progress\n"
" --verbose verbose output\n"
" --debug print extra debugging information\n"
);
}
static int ParseMyArgs(int argc, char **argv) {
int errs = 0;
for (--argc, ++argv; argc--; ++argv) {
bool help;
const char *arg = *argv;
if (arg[0] != '-') {
continue;
} else if ((arg[1] == '-') &&
( GetFlagArgVal("verbose", arg, &FLAG_verbose) ||
GetFlagArgVal("in", arg, &FLAG_inFile) ||
GetFlagArgVal("in_file", arg, &FLAG_inFile) ||
GetFlagArgVal("out", arg, &FLAG_outFile) ||
GetFlagArgVal("out_file", arg, &FLAG_outFile) ||
GetFlagArgVal("show", arg, &FLAG_show) ||
GetFlagArgVal("webcam", arg, &FLAG_webcam) ||
GetFlagArgVal("cam_res", arg, &FLAG_camRes) ||
GetFlagArgVal("strength", arg, &FLAG_strength) ||
GetFlagArgVal("model_dir", arg, &FLAG_modelDir) ||
GetFlagArgVal("codec", arg, &FLAG_codec) ||
GetFlagArgVal("progress", arg, &FLAG_progress) ||
GetFlagArgVal("debug", arg, &FLAG_debug)
)) {
continue;
} else if (GetFlagArgVal("help", arg, &help)) {
return NVCV_ERR_HELP;
} else if (arg[1] != '-') {
for (++arg; *arg; ++arg) {
if (*arg == 'v') {
FLAG_verbose = true;
} else {
printf("Unknown flag ignored: \"-%c\"\n", *arg);
}
}
continue;
} else {
printf("Unknown flag ignored: \"%s\"\n", arg);
}
}
return errs;
}
static bool HasSuffix(const char *str, const char *suf) {
size_t strSize = strlen(str),
sufSize = strlen(suf);
if (strSize < sufSize)
return false;
return (0 == strcasecmp(suf, str + strSize - sufSize));
}
static bool HasOneOfTheseSuffixes(const char *str, ...) {
bool matches = false;
const char *suf;
va_list ap;
va_start(ap, str);
while (nullptr != (suf = va_arg(ap, const char*))) {
if (HasSuffix(str, suf)) {
matches = true;
break;
}
}
va_end(ap);
return matches;
}
static bool IsImageFile(const char *str) {
return HasOneOfTheseSuffixes(str, ".bmp", ".jpg", ".jpeg", ".png", nullptr);
}
static const char* DurationString(double sc) {
static char buf[16];
int hr, mn;
hr = (int)(sc / 3600.);
sc -= hr * 3600.;
mn = (int)(sc / 60.);
sc -= mn * 60.;
snprintf(buf, sizeof(buf), "%02d:%02d:%06.3f", hr, mn, sc);
return buf;
}
struct VideoInfo {
int codec;
int width;
int height;
double frameRate;
long long frameCount;
};
static void GetVideoInfo(cv::VideoCapture& reader, const char *fileName, VideoInfo *info) {
info->codec = (int)reader.get(cv::CAP_PROP_FOURCC);
info->width = (int)reader.get(cv::CAP_PROP_FRAME_WIDTH);
info->height = (int)reader.get(cv::CAP_PROP_FRAME_HEIGHT);
info->frameRate = (double)reader.get(cv::CAP_PROP_FPS);
info->frameCount = (long long)reader.get(cv::CAP_PROP_FRAME_COUNT);
if (FLAG_verbose)
printf(
" file \"%s\"\n"
" codec %.4s\n"
" width %4d\n"
" height %4d\n"
" frame rate %.3f\n"
"frame count %4lld\n"
" duration %s\n",
fileName, (char*)&info->codec, info->width, info->height, info->frameRate, info->frameCount,
DurationString(info->frameCount / info->frameRate)
);
}
static int StringToFourcc(const std::string& str) {
union chint { int i; char c[4]; };
chint x = { 0 };
for (int n = (str.size() < 4) ? (int)str.size() : 4; n--;)
x.c[n] = str[n];
return x.i;
}
struct FXApp {
enum Err {
errQuit = +1, // Application errors
errFlag = +2,
errRead = +3,
errWrite = +4,
errNone = NVCV_SUCCESS, // Video Effects SDK errors
errGeneral = NVCV_ERR_GENERAL,
errUnimplemented = NVCV_ERR_UNIMPLEMENTED,
errMemory = NVCV_ERR_MEMORY,
errEffect = NVCV_ERR_EFFECT,
errSelector = NVCV_ERR_SELECTOR,
errBuffer = NVCV_ERR_BUFFER,
errParameter = NVCV_ERR_PARAMETER,
errMismatch = NVCV_ERR_MISMATCH,
errPixelFormat = NVCV_ERR_PIXELFORMAT,
errModel = NVCV_ERR_MODEL,
errLibrary = NVCV_ERR_LIBRARY,
errInitialization = NVCV_ERR_INITIALIZATION,
errFileNotFound = NVCV_ERR_FILE,
errFeatureNotFound = NVCV_ERR_FEATURENOTFOUND,
errMissingInput = NVCV_ERR_MISSINGINPUT,
errResolution = NVCV_ERR_RESOLUTION,
errUnsupportedGPU = NVCV_ERR_UNSUPPORTEDGPU,
errWrongGPU = NVCV_ERR_WRONGGPU,
errUnsupportedDriver = NVCV_ERR_UNSUPPORTEDDRIVER,
errCudaMemory = NVCV_ERR_CUDA_MEMORY, // CUDA errors
errCudaValue = NVCV_ERR_CUDA_VALUE,
errCudaPitch = NVCV_ERR_CUDA_PITCH,
errCudaInit = NVCV_ERR_CUDA_INIT,
errCudaLaunch = NVCV_ERR_CUDA_LAUNCH,
errCudaKernel = NVCV_ERR_CUDA_KERNEL,
errCudaDriver = NVCV_ERR_CUDA_DRIVER,
errCudaUnsupported = NVCV_ERR_CUDA_UNSUPPORTED,
errCudaIllegalAddress = NVCV_ERR_CUDA_ILLEGAL_ADDRESS,
errCuda = NVCV_ERR_CUDA,
};
FXApp() { _eff = nullptr; _effectName = nullptr; _inited = false; _showFPS = false; _progress = false;
_show = false; _enableEffect = true, _drawVisualization = true, _framePeriod = 0.f; }
~FXApp() { NvVFX_DestroyEffect(_eff); }
void setShow(bool show) { _show = show; }
Err createEffect(const char *effectSelector, const char *modelDir);
void destroyEffect();
NvCV_Status allocBuffers(unsigned width, unsigned height);
NvCV_Status allocTempBuffers();
Err processImage(const char *inFile, const char *outFile);
Err processMovie(const char *inFile, const char *outFile);
Err initCamera(cv::VideoCapture& cap);
Err processKey(int key);
void drawFrameRate(cv::Mat& img);
void drawEffectStatus(cv::Mat& img);
Err appErrFromVfxStatus(NvCV_Status status) { return (Err)status; }
const char* errorStringFromCode(Err code);
NvVFX_Handle _eff;
cv::Mat _srcImg;
cv::Mat _dstImg;
NvCVImage _srcGpuBuf;
NvCVImage _dstGpuBuf;
NvCVImage _srcVFX;
NvCVImage _dstVFX;
NvCVImage _tmpVFX; // We use the same temporary buffer for source and dst, since it auto-shapes as needed
bool _show;
bool _inited;
bool _showFPS;
bool _progress;
bool _enableEffect;
bool _drawVisualization;
const char* _effectName;
float _framePeriod;
std::chrono::high_resolution_clock::time_point _lastTime;
};
const char* FXApp::errorStringFromCode(Err code) {
struct LutEntry { Err code; const char *str; };
static const LutEntry lut[] = {
{ errRead, "There was a problem reading a file" },
{ errWrite, "There was a problem writing a file" },
{ errQuit, "The user chose to quit the application" },
{ errFlag, "There was a problem with the command-line arguments" },
};
if ((int)code <= 0) return NvCV_GetErrorStringFromCode((NvCV_Status)code);
for (const LutEntry *p = lut; p != &lut[sizeof(lut) / sizeof(lut[0])]; ++p)
if (p->code == code) return p->str;
return "UNKNOWN ERROR";
}
void FXApp::drawFrameRate(cv::Mat &img) {
const float timeConstant = 16.f;
std::chrono::high_resolution_clock::time_point now = std::chrono::high_resolution_clock::now();
std::chrono::duration<float> dur = std::chrono::duration_cast<std::chrono::duration<float>>(now - _lastTime);
float t = dur.count();
if (0.f < t && t < 100.f) {
if (_framePeriod)
_framePeriod += (t - _framePeriod) * (1.f / timeConstant); // 1 pole IIR filter
else
_framePeriod = t;
if (_showFPS) {
char buf[32];
snprintf(buf, sizeof(buf), "%.1f", 1. / _framePeriod);
cv::putText(img, buf, cv::Point(10, img.rows - 10), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(255, 255, 255), 1);
}
} else { // Ludicrous time interval; reset
_framePeriod = 0.f; // WAKE UP
}
_lastTime = now;
}
FXApp::Err FXApp::processKey(int key) {
static const int ESC_KEY = 27;
switch (key) {
case 'Q': case 'q': case ESC_KEY:
return errQuit;
case 'f': case 'F':
_showFPS = !_showFPS;
break;
case 'p': case 'P': case '%':
_progress = !_progress;
case 'e': case 'E':
_enableEffect = !_enableEffect;
break;
case 'd': case'D':
if (FLAG_webcam)
_drawVisualization = !_drawVisualization;
break;
default:
break;
}
return errNone;
}
FXApp::Err FXApp::initCamera(cv::VideoCapture& cap) {
const int camIndex = 0;
cap.open(camIndex);
if (!FLAG_camRes.empty()) {
int camWidth, camHeight, n;
n = sscanf(FLAG_camRes.c_str(), "%d%*[xX]%d", &camWidth, &camHeight);
switch (n) {
case 2:
break; // We have read both width and height
case 1:
camHeight = camWidth;
camWidth = (int)(camHeight * (16. / 9.) + .5);
break;
default:
camHeight = 0;
camWidth = 0;
break;
}
if (camWidth) cap.set(cv::CAP_PROP_FRAME_WIDTH, camWidth);
if (camHeight) cap.set(cv::CAP_PROP_FRAME_HEIGHT, camHeight);
int actualCamWidth = cap.get(cv::CAP_PROP_FRAME_WIDTH);
int actualCamHeight = cap.get(cv::CAP_PROP_FRAME_HEIGHT);
if (camWidth != actualCamWidth || camHeight != actualCamHeight) {
printf("The requested resolution of %d x %d is not available and has been subsituted by %d x %d.\n", camWidth, camHeight, actualCamWidth, actualCamHeight);
}
}
return errNone;
}
void FXApp::drawEffectStatus(cv::Mat& img) {
char buf[32];
snprintf(buf, sizeof(buf), "Effect: %s", _enableEffect ? "on" : "off");
cv::putText(img, buf, cv::Point(10, img.rows - 40), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(255, 255, 255), 1);
}
FXApp::Err FXApp::createEffect(const char *effectSelector, const char *modelDir) {
NvCV_Status vfxErr;
BAIL_IF_ERR(vfxErr = NvVFX_CreateEffect(effectSelector, &_eff));
_effectName = effectSelector;
if (modelDir[0] != '\0'){
BAIL_IF_ERR(vfxErr = NvVFX_SetString(_eff, NVVFX_MODEL_DIRECTORY, modelDir));
}
bail:
return appErrFromVfxStatus(vfxErr);
}
void FXApp::destroyEffect() {
NvVFX_DestroyEffect(_eff);
_eff = nullptr;
}
// Allocate one temp buffer to be used for input and output. Reshaping of the temp buffer in NvCVImage_Transfer() is done automatically,
// and is very low overhead. We expect the destination to be largest, so we allocate that first to minimize reallocs probablistically.
// Then we Realloc for the source to get the union of the two.
// This could alternately be done at runtime by feeding in an empty temp NvCVImage, but there are advantages to allocating all memory at load time.
NvCV_Status FXApp::allocTempBuffers() {
NvCV_Status vfxErr;
BAIL_IF_ERR(vfxErr = NvCVImage_Alloc( &_tmpVFX, _dstVFX.width, _dstVFX.height, _dstVFX.pixelFormat, _dstVFX.componentType, _dstVFX.planar, NVCV_GPU, 0));
BAIL_IF_ERR(vfxErr = NvCVImage_Realloc(&_tmpVFX, _srcVFX.width, _srcVFX.height, _srcVFX.pixelFormat, _srcVFX.componentType, _srcVFX.planar, NVCV_GPU, 0));
bail:
return vfxErr;
}
NvCV_Status FXApp::allocBuffers(unsigned width, unsigned height) {
NvCV_Status vfxErr = NVCV_SUCCESS;
if (_inited)
return NVCV_SUCCESS;
if (!_srcImg.data) {
_srcImg.create(height, width, CV_8UC3); // src CPU
BAIL_IF_NULL(_srcImg.data, vfxErr, NVCV_ERR_MEMORY);
}
_dstImg.create(_srcImg.rows, _srcImg.cols, _srcImg.type()); //
BAIL_IF_NULL(_dstImg.data, vfxErr, NVCV_ERR_MEMORY); //
BAIL_IF_ERR(vfxErr = NvCVImage_Alloc(&_srcGpuBuf, _srcImg.cols, _srcImg.rows, NVCV_BGR, NVCV_F32, NVCV_PLANAR, NVCV_GPU, 1)); // src GPU
BAIL_IF_ERR(vfxErr = NvCVImage_Alloc(&_dstGpuBuf, _srcImg.cols, _srcImg.rows, NVCV_BGR, NVCV_F32, NVCV_PLANAR, NVCV_GPU, 1)); //dst GPU
NVWrapperForCVMat(&_srcImg, &_srcVFX); // _srcVFX is an alias for _srcImg
NVWrapperForCVMat(&_dstImg, &_dstVFX); // _dstVFX is an alias for _dstImg
//#define ALLOC_TEMP_BUFFERS_AT_RUN_TIME // Deferring temp buffer allocation is easier
#ifndef ALLOC_TEMP_BUFFERS_AT_RUN_TIME // Allocating temp buffers at load time avoids run time hiccups
BAIL_IF_ERR(vfxErr = allocTempBuffers()); // This uses _srcVFX and _dstVFX and allocates one buffer to be a temporary for src and dst
#endif // ALLOC_TEMP_BUFFERS_AT_RUN_TIME
_inited = true;
bail:
return vfxErr;
}
FXApp::Err FXApp::processImage(const char *inFile, const char *outFile) {
CUstream stream = 0;
NvCV_Status vfxErr;
void* state = nullptr;
void* stateArray[1];
if (!_eff)
return errEffect;
_srcImg = cv::imread(inFile);
if (!_srcImg.data)
return errRead;
BAIL_IF_ERR(vfxErr = allocBuffers(_srcImg.cols, _srcImg.rows));
BAIL_IF_ERR(vfxErr = NvCVImage_Transfer(&_srcVFX, &_srcGpuBuf, 1.f / 255.f, stream, &_tmpVFX)); // _srcVFX--> _tmpVFX --> _srcGpuBuf
BAIL_IF_ERR(vfxErr = NvVFX_SetImage(_eff, NVVFX_INPUT_IMAGE, &_srcGpuBuf));
BAIL_IF_ERR(vfxErr = NvVFX_SetImage(_eff, NVVFX_OUTPUT_IMAGE, &_dstGpuBuf));
BAIL_IF_ERR(vfxErr = NvVFX_SetF32(_eff, NVVFX_STRENGTH, FLAG_strength));
unsigned int stateSizeInBytes;
BAIL_IF_ERR(vfxErr = NvVFX_GetU32(_eff, NVVFX_STATE_SIZE, &stateSizeInBytes));
cudaMalloc(&state, stateSizeInBytes);
cudaMemsetAsync(state, 0, stateSizeInBytes, stream);
stateArray[0] = state;
BAIL_IF_ERR(vfxErr = NvVFX_SetObject(_eff, NVVFX_STATE, (void*)stateArray));
BAIL_IF_ERR(vfxErr = NvVFX_Load(_eff));
BAIL_IF_ERR(vfxErr = NvVFX_Run(_eff, 0));
BAIL_IF_ERR(vfxErr = NvCVImage_Transfer(&_dstGpuBuf, &_dstVFX, 255.f, stream, &_tmpVFX));
if (outFile && outFile[0]) {
if (!cv::imwrite(outFile, _dstImg)) {
printf("Error writing: \"%s\"\n", outFile);
return errWrite;
}
}
if (_show) {
cv::imshow("Output", _dstImg);
cv::waitKey(3000);
}
bail:
if (state) cudaFree(state); // release state memory
return appErrFromVfxStatus(vfxErr);
}
FXApp::Err FXApp::processMovie(const char *inFile, const char *outFile) {
const int fourcc_h264 = cv::VideoWriter::fourcc('H','2','6','4');
CUstream stream = 0;
FXApp::Err appErr = errNone;
bool ok;
cv::VideoCapture reader;
cv::VideoWriter writer;
NvCV_Status vfxErr;
unsigned frameNum;
VideoInfo info;
void* state = nullptr;
void* stateArray[1];
if (inFile && !inFile[0]) inFile = nullptr; // Set file paths to NULL if zero length
if (!FLAG_webcam && inFile) {
reader.open(inFile);
} else {
appErr = initCamera(reader);
if (appErr != errNone)
return appErr;
}
if (!reader.isOpened()) {
if (!FLAG_webcam) printf("Error: Could not open video: \"%s\"\n", inFile);
else printf("Error: Webcam not found\n");
return errRead;
}
GetVideoInfo(reader, (inFile ? inFile : "webcam"), &info);
if (!(fourcc_h264 == info.codec || cv::VideoWriter::fourcc('a', 'v', 'c', '1') == info.codec)) // avc1 is alias for h264
printf("Filters only target H264 videos, not %.4s\n", (char*)&info.codec);
BAIL_IF_ERR(vfxErr = allocBuffers(info.width, info.height));
if (outFile && !outFile[0]) outFile = nullptr;
if (outFile) {
ok = writer.open(outFile, StringToFourcc(FLAG_codec), info.frameRate, cv::Size(_dstVFX.width, _dstVFX.height));
if (!ok) {
printf("Cannot open \"%s\" for video writing\n", outFile);
outFile = nullptr;
if (!_show)
return errWrite;
}
}
BAIL_IF_ERR(vfxErr = NvVFX_SetImage(_eff, NVVFX_INPUT_IMAGE, &_srcGpuBuf));
BAIL_IF_ERR(vfxErr = NvVFX_SetImage(_eff, NVVFX_OUTPUT_IMAGE, &_dstGpuBuf));
BAIL_IF_ERR(vfxErr = NvVFX_SetF32(_eff, NVVFX_STRENGTH, FLAG_strength));
unsigned int stateSizeInBytes;
BAIL_IF_ERR(vfxErr = NvVFX_GetU32(_eff, NVVFX_STATE_SIZE, &stateSizeInBytes));
cudaMalloc(&state, stateSizeInBytes);
cudaMemsetAsync(state, 0, stateSizeInBytes, stream);
stateArray[0] = state;
BAIL_IF_ERR(vfxErr = NvVFX_SetObject(_eff, NVVFX_STATE, (void*)stateArray));
BAIL_IF_ERR(vfxErr = NvVFX_Load(_eff));
for (frameNum = 0; reader.read(_srcImg); frameNum++) {
if (_enableEffect) {
BAIL_IF_ERR(vfxErr = NvCVImage_Transfer(&_srcVFX, &_srcGpuBuf, 1.f / 255.f, stream, &_tmpVFX));
BAIL_IF_ERR(vfxErr = NvVFX_Run(_eff, 0));
BAIL_IF_ERR(vfxErr = NvCVImage_Transfer(&_dstGpuBuf, &_dstVFX, 255.f, stream, &_tmpVFX));
} else {
BAIL_IF_ERR(vfxErr = NvCVImage_Transfer(&_srcVFX, &_dstVFX, 1.f, stream, &_tmpVFX));
cudaMemsetAsync(state, 0, stateSizeInBytes, stream);// reset state by setting to 0
}
if (outFile)
writer.write(_dstImg);
if (_show) {
if (_drawVisualization) drawEffectStatus(_dstImg);
drawFrameRate(_dstImg);
cv::imshow("Output", _dstImg);
int key= cv::waitKey(1);
if (key > 0) {
appErr = processKey(key);
if (errQuit == appErr)
break;
}
}
if (_progress)
fprintf(stderr, "\b\b\b\b%3.0f%%", 100.f * frameNum / info.frameCount);
}
if (_progress) fprintf(stderr, "\n");
reader.release();
if (outFile)
writer.release();
bail:
if (state) cudaFree(state); // release state memory
return appErrFromVfxStatus(vfxErr);
}
int main(int argc, char **argv) {
FXApp::Err fxErr = FXApp::errNone;
int nErrs;
FXApp app;
nErrs = ParseMyArgs(argc, argv);
if (nErrs)
std::cerr << nErrs << " command line syntax problems\n";
if (FLAG_webcam) {
// If webcam is on, enable showing the results and turn off displaying the progress
if (FLAG_progress) FLAG_progress = !FLAG_progress;
if (!FLAG_show) FLAG_show = !FLAG_show;
}
if (FLAG_inFile.empty() && !FLAG_webcam) {
std::cerr << "Please specify --in_file=XXX or --webcam=true\n";
++nErrs;
}
if (FLAG_outFile.empty() && !FLAG_show) {
std::cerr << "Please specify --out_file=XXX or --show\n";
++nErrs;
}
app._progress = FLAG_progress;
app.setShow(FLAG_show);
if (nErrs) {
Usage();
fxErr = FXApp::errFlag;
}
else {
fxErr = app.createEffect(NVVFX_FX_DENOISING, FLAG_modelDir.c_str());
if (FXApp::errNone != fxErr) {
std::cerr << "Error creating effect\n";
}
else {
if (IsImageFile(FLAG_inFile.c_str()))
fxErr = app.processImage(FLAG_inFile.c_str(), FLAG_outFile.c_str());
else
fxErr = app.processMovie(FLAG_inFile.c_str(), FLAG_outFile.c_str());
}
}
if (fxErr)
std::cerr << "Error: " << app.errorStringFromCode(fxErr) << std::endl;
return (int)fxErr;
}
|
; A313685: Coordination sequence Gal.4.43.3 where G.u.t.v denotes the coordination sequence for a vertex of type v in tiling number t in the Galebach list of u-uniform tilings.
; 1,5,10,15,19,23,28,33,38,43,48,53,57,61,66,71,76,81,86,91,95,99,104,109,114,119,124,129,133,137,142,147,152,157,162,167,171,175,180,185,190,195,200,205,209,213,218,223,228,233
mov $2,$0
add $0,1
mov $1,$0
lpb $0
sub $0,3
trn $0,1
add $1,1
mov $3,$1
mov $1,2
trn $1,$0
trn $0,4
trn $3,3
add $1,$3
lpe
lpb $2
add $1,4
sub $2,1
lpe
sub $1,1
|
; A071281: Numerators of Peirce sequence of order 3.
; 0,0,0,1,1,2,2,3,1,4,3,5,4,6,2,7,5,8,6,9,3,10,7,11,8,12,4,13,9,14,10,15,5,16,11,17,12,18,6,19,13,20,14,21,7,22,15,23,16,24,8,25,17,26,18,27,9,28,19,29,20,30,10,31,21,32,22,33,11,34,23,35,24,36,12,37,25,38
mov $2,-2
bin $2,$0
div $2,2
mov $5,3
lpb $5
sub $0,$2
mov $3,$5
cmp $3,0
add $5,$3
div $0,$5
sub $0,$2
dif $0,2
add $4,15
add $4,$0
add $2,$4
trn $5,7
lpe
mov $0,$2
sub $0,15
|
SECTION code_clib
SECTION code_fp_math48
PUBLIC mm48__acpi
mm48__acpi:
; set AC = pi
ld bc,$490F
ld de,$DAA2
ld hl,$2182
ret
|
; A153491: Triangle T(n,m)= 11*binomial(n,k) - 8 read by rows, 0<=k<=n.
; 3,3,3,3,14,3,3,25,25,3,3,36,58,36,3,3,47,102,102,47,3,3,58,157,212,157,58,3,3,69,223,377,377,223,69,3,3,80,300,608,762,608,300,80,3,3,91,388,916,1378,1378,916,388,91,3,3,102,487,1312,2302,2764,2302,1312,487,102,3,3,113,597,1807,3622,5074,5074,3622,1807,597,113,3,3,124,718,2412,5437,8704,10156,8704,5437,2412,718,124,3,3,135,850,3138,7857,14149,18868,18868,14149
lpb $0
add $1,1
sub $0,$1
lpe
bin $1,$0
sub $1,1
mul $1,11
add $1,3
mov $0,$1
|
.size 8000
.text@48
ei
jp lstatint
.text@100
jp lbegin
.text@150
lbegin:
ld c, 41
ld b, 03
lbegin_waitm3:
ldff a, (c)
and a, b
cmp a, b
jrnz lbegin_waitm3
ld a, 20
ldff(c), a
ld a, 02
ldff(ff), a
xor a, a
ldff(0f), a
ei
ld c, 47
ld a, 03
ldff(43), a
ld a, ff
ldff(c), a
inc a
.text@1000
lstatint:
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
ldff(c), a
dec a
.text@1034
ldff(c), a
inc a
pop hl
|
/*
* Copyright (c) 2013, Google Inc. 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 Google Inc. 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 "config.h"
#include "core/animation/animatable/AnimatableDouble.h"
#include <gtest/gtest.h>
using namespace blink;
namespace {
TEST(AnimationAnimatableDoubleTest, Create)
{
EXPECT_TRUE(static_cast<bool>(AnimatableDouble::create(5).get()));
EXPECT_TRUE(static_cast<bool>(AnimatableDouble::create(10).get()));
}
TEST(AnimationAnimatableDoubleTest, Equal)
{
EXPECT_TRUE(AnimatableDouble::create(10)->equals(AnimatableDouble::create(10).get()));
EXPECT_FALSE(AnimatableDouble::create(5)->equals(AnimatableDouble::create(10).get()));
}
TEST(AnimationAnimatableDoubleTest, ToDouble)
{
EXPECT_EQ(5.9, AnimatableDouble::create(5.9)->toDouble());
EXPECT_EQ(-10, AnimatableDouble::create(-10)->toDouble());
}
TEST(AnimationAnimatableDoubleTest, Interpolate)
{
RefPtrWillBeRawPtr<AnimatableDouble> from10 = AnimatableDouble::create(10);
RefPtrWillBeRawPtr<AnimatableDouble> to20 = AnimatableDouble::create(20);
EXPECT_EQ(5, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), to20.get(), -0.5).get())->toDouble());
EXPECT_EQ(10, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), to20.get(), 0).get())->toDouble());
EXPECT_EQ(14, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), to20.get(), 0.4).get())->toDouble());
EXPECT_EQ(15, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), to20.get(), 0.5).get())->toDouble());
EXPECT_EQ(16, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), to20.get(), 0.6).get())->toDouble());
EXPECT_EQ(20, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), to20.get(), 1).get())->toDouble());
EXPECT_EQ(25, toAnimatableDouble(AnimatableValue::interpolate(from10.get(), to20.get(), 1.5).get())->toDouble());
}
}
|
global _start
section .text
_start:
call love
mov rax, 60
xor rdi, rdi
syscall ; exiting program with code 0
;------------------------------------------------------------------------------
; Standard potter-tongue function, that reads decimal number from STDIN.
;
; Expects: [RBP + 16] = precision
; [RBP + 24] = i/o buffer address
;
; Returns: RAX = read number
;
; Changes: RAX, RBX, RCX, RDI, RSI, R12
;------------------------------------------------------------------------------
accio_bombarda:
push rbp
mov rbp, rsp
mov rax, 0x00 ; read(int fd, void *buf, size_t count)
mov rdi, 0x00 ; fd = STDIN
mov rsi, [rbp + 24] ; buf = IO_BUFFER
mov rdx, 512 ; count = IO_BUFFER_SIZE
syscall
xor rax, rax
mov rsi, [rbp + 24]
mov rbx, 10
xor rcx, rcx
xor r12, r12 ; r12 = is number negative
cmp byte [rsi], '-'
jne .NOT_NEGATIVE
mov r12, 1
inc rsi
.NOT_NEGATIVE:
; Parsing until '.'
.UNTIL_DECIMAL_POINT:
mov cl, byte [rsi]
cmp cl, 0xa ; new line character
je .DECIMAL_POINT_REACHED
cmp cl, '.'
je .DECIMAL_POINT_REACHED
imul rax, rbx
add rax, rcx
sub rax, '0'
inc rsi
jmp .UNTIL_DECIMAL_POINT
.DECIMAL_POINT_REACHED:
; Parsing after '.' (maximum precision times)
mov rdi, qword [rbp + 16] ; rdi = precision
cmp cl, '.'
jne .NOT_SKIP_POINT
inc rsi
.NOT_SKIP_POINT:
.PARSE_PRECISION_TIMES:
test rdi, rdi
jz .END_PARSE_PRECISION_TIMES
mov cl, byte [rsi]
cmp cl, 0xa ; new line character
je .END_PARSE_PRECISION_TIMES
imul rax, rbx
add rax, rcx
sub rax, '0'
inc rsi
dec rdi
jmp .PARSE_PRECISION_TIMES
.END_PARSE_PRECISION_TIMES:
; Finish multiplying by 10 in case rdi isn't 0 at this point
.REMAINING_DIGITS:
test rdi, rdi
jz .END_REMAINING_DIGITS
imul rax, rbx
dec rdi
jmp .REMAINING_DIGITS
.END_REMAINING_DIGITS:
test r12, r12
jz .SKIP_NEGATIVE_SIGN
neg rax
.SKIP_NEGATIVE_SIGN:
mov rsp, rbp
pop rbp
ret
;------------------------------------------------------------------------------
; Standard potter-tongue function, that reads decimal number from STDIN.
;
; Expects: [RBP + 16] = i/o buffer address
;
; Returns: RAX = read number
;
; Changes: RAX, RBX, RCX, RDI, RSI, R12
;------------------------------------------------------------------------------
accio:
push rbp
mov rbp, rsp
mov rax, 0x00 ; read(int fd, void *buf, size_t count)
mov rdi, 0x00 ; fd = STDIN
mov rsi, [rbp + 16] ; buf = IO_BUFFER
mov rdx, 512 ; count = IO_BUFFER_SIZE
syscall
xor rax, rax
mov rsi, [rbp + 16]
mov rbx, 10
xor rcx, rcx
xor r12, r12 ; r12 = is number negative
cmp byte [rsi], '-'
jne .NOT_NEGATIVE
mov r12, 1
inc rsi
.NOT_NEGATIVE:
.WHILE_DIGITS_LEFT:
mov cl, byte [rsi]
cmp cl, 0xa ; new line character
je .END_WHILE
imul rax, rbx
add rax, rcx
sub rax, '0'
inc rsi
jmp .WHILE_DIGITS_LEFT
.END_WHILE:
test r12, r12
jz .SKIP_NEGATIVE_SIGN
neg rax
.SKIP_NEGATIVE_SIGN:
mov rsp, rbp
pop rbp
ret
;------------------------------------------------------------------------------
; Standard potter-tongue function, that prints decimal number to STDOUT and
; puts a decimal point '.' after precision number of least-significant digits.
;
; Expects: [RBP + 16] = precision
; [RBP + 24] = number
; [RBP + 32] = i/o buffer address
;
; Returns: (none)
;
; Changes: RAX, RBX, RCX, RDX, RDI, RSI, R12, R13
;------------------------------------------------------------------------------
flagrate_bombarda:
push rbp
mov rbp, rsp
mov r13, [rbp + 32]
add r13, 512 - 1
mov rax, qword [rbp + 24] ; rax = number
mov rbx, 10
mov rdi, r13
xor r12, r12 ; is number negative
cmp rax, 0
jge .NOT_NEGATIVE
mov r12, 1
neg rax
.NOT_NEGATIVE:
mov rcx, qword [rbp + 16] ; rcx = precision
.PRECISION_DIGITS:
xor rdx, rdx
div rbx ; rax = quotient; rdx = last digit
add dl, '0'
mov byte [rdi], dl
dec rdi
dec rcx
test rcx, rcx
jnz .PRECISION_DIGITS
; Putting '.'
mov byte [rdi], '.'
dec rdi
.WHILE_DIGITS_LEFT:
xor rdx, rdx
div rbx ; rax = quotient; rdx = last digit
add dl, '0'
mov byte [rdi], dl
dec rdi
test rax, rax
jnz .WHILE_DIGITS_LEFT
test r12, r12
jz .SKIP_NEGATIVE_SIGN
mov byte [rdi], '-'
dec rdi
.SKIP_NEGATIVE_SIGN:
; Writing the number to STDOUT
mov rax, 0x01 ; write(rdi=fd, rsi=buf, rdx=cnt)
mov rsi, rdi
inc rsi
mov rdx, r13
sub rdx, rdi
mov rdi, 0x01 ; STDOUT
syscall
mov rsp, rbp
pop rbp
ret
;------------------------------------------------------------------------------
; Standard potter-tongue function, that prints a string to STDOUT.
;
; Expects: [RBP + 16] = string address
;
; Returns: (none)
;
; Changes: RAX, RCX, RDX, RDI, RSI
;------------------------------------------------------------------------------
flagrate_s:
push rbp
mov rbp, rsp
; ==== strlen() ====
mov rsi, qword [rbp + 16] ; rsi = string
xor rdx, rdx ; rdx = string's length
.LOOP_STRLEN:
mov cl, byte [rsi] ; cl = current char
test cl, cl
jz .END_STRLEN
inc rdx
inc rsi
jmp .LOOP_STRLEN
.END_STRLEN:
; ==== strlen() ====
; Writing the string to STDOUT
mov rax, 0x01 ; write(rdi=fd, rsi=buf, rdx=cnt)
mov rsi, qword [rbp + 16]
mov rdi, 0x01 ; STDOUT
syscall
mov rsp, rbp
pop rbp
ret
;------------------------------------------------------------------------------
; Standard potter-tongue function, that prints decimal number to STDOUT.
;
; Expects: [RBP + 16] = number
; [RBP + 24] = i/o buffer address
;
; Returns: (none)
;
; Changes: RAX, RBX, RDX, RDI, RSI, R12
;------------------------------------------------------------------------------
flagrate:
push rbp
mov rbp, rsp
mov r13, [rbp + 24]
add r13, 512 - 1
mov rax, qword [rbp + 16] ; rax = number
mov rbx, 10
mov rdi, r13
xor r12, r12 ; is number negative
cmp rax, 0
jge .NOT_NEGATIVE
mov r12, 1
neg rax
.NOT_NEGATIVE:
.WHILE_DIGITS_LEFT:
xor rdx, rdx
div rbx ; rax = quotient; rdx = last digit
add dl, '0'
mov byte [rdi], dl
dec rdi
test rax, rax
jnz .WHILE_DIGITS_LEFT
.END_WHILE:
test r12, r12
jz .SKIP_NEGATIVE_SIGN
mov byte [rdi], '-'
dec rdi
.SKIP_NEGATIVE_SIGN:
; Writing the number to STDOUT
mov rax, 0x01 ; write(rdi=fd, rsi=buf, rdx=cnt)
mov rsi, rdi
inc rsi
mov rdx, r13
sub rdx, rdi
mov rdi, 0x01 ; STDOUT
syscall
mov rsp, rbp
pop rbp
ret
;------------------------------------------------------------------------------
; Standard potter-tongue function, that calculates the square root of number.
;
; Expects: [RBP + 16] = number
;
; Returns: RAX = sqrt(number)
;
; Changes: RAX, XMM0, XMM1
;------------------------------------------------------------------------------
crucio:
push rbp
mov rbp, rsp
mov rax, [rbp + 16]
cvtsi2ss xmm0, rax
sqrtss xmm1, xmm0
cvttss2si rax, xmm1
mov rsp, rbp
pop rbp
ret
; ==================================================
; love
;
; params:
; vars: n, i
; ==================================================
love:
push rbp
mov rbp, rsp
sub rsp, 16
; --- assignment to n ---
; evaluating expression
mov rax, 0
mov [rbp - 8], rax
; --- assignment to i ---
; evaluating expression
mov rax, 0
mov [rbp - 16], rax
; ==== while ====
.WHILE_0:
; exit condition
mov rax, [rbp - 16]
mov rbx, 10000000
cmp rax, rbx
jg .END_WHILE_0
; loop body
; --- assignment to n ---
; evaluating expression
mov rax, [rbp - 8]
push rax ; save rax
mov rax, 3
mov rbx, [rbp - 8]
imul rax, rbx
push rax ; save rax
mov rax, 2
mov rbx, rax
pop rax ; restore rax
sub rax, rbx
push rax ; save rax
mov rax, 2
mov rbx, rax
pop rax ; restore rax
cqo
idiv rbx
mov rbx, rax
pop rax ; restore rax
add rax, rbx
push rax ; save rax
mov rax, 4
mov rbx, rax
pop rax ; restore rax
add rax, rbx
mov [rbp - 8], rax
; --- assignment to i ---
; evaluating expression
mov rax, [rbp - 16]
mov rbx, 1
add rax, rbx
mov [rbp - 16], rax
jmp .WHILE_0
.END_WHILE_0:
mov rax, [rbp - 8]
mov rax, 0
jmp .RETURN
.RETURN:
mov rsp, rbp
pop rbp
ret
section .bss
IO_BUFFER:
resb 512
section .data
|
//
// Created by ww on 2020/12/25.
//
#include <gtest/gtest.h>
#include "warm_wind/cv/visualization.h"
class VisualizationTests : public testing::Test {
};
TEST_F(VisualizationTests, DrawPointsOnImage) {
// TODO Test DrawPointsOnImage
}
TEST_F(VisualizationTests, DrawBoundingBox3DOnImage) {
// TODO Test DrawBoundingBox3DOnImage
} |
//===- AggressiveAntiDepBreaker.cpp - Anti-dep breaker --------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the AggressiveAntiDepBreaker class, which
// implements register anti-dependence breaking during post-RA
// scheduling. It attempts to break all anti-dependencies within a
// block.
//
//===----------------------------------------------------------------------===//
#include "AggressiveAntiDepBreaker.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/MachineValueType.h"
#include "llvm/CodeGen/RegisterClassInfo.h"
#include "llvm/CodeGen/ScheduleDAG.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <map>
#include <set>
#include <utility>
#include <vector>
using namespace llvm;
#define DEBUG_TYPE "post-RA-sched"
// If DebugDiv > 0 then only break antidep with (ID % DebugDiv) == DebugMod
static cl::opt<int>
DebugDiv("agg-antidep-debugdiv",
cl::desc("Debug control for aggressive anti-dep breaker"),
cl::init(0), cl::Hidden);
static cl::opt<int>
DebugMod("agg-antidep-debugmod",
cl::desc("Debug control for aggressive anti-dep breaker"),
cl::init(0), cl::Hidden);
AggressiveAntiDepState::AggressiveAntiDepState(const unsigned TargetRegs,
MachineBasicBlock *BB)
: NumTargetRegs(TargetRegs), GroupNodes(TargetRegs, 0),
GroupNodeIndices(TargetRegs, 0), KillIndices(TargetRegs, 0),
DefIndices(TargetRegs, 0) {
const unsigned BBSize = BB->size();
for (unsigned i = 0; i < NumTargetRegs; ++i) {
// Initialize all registers to be in their own group. Initially we
// assign the register to the same-indexed GroupNode.
GroupNodeIndices[i] = i;
// Initialize the indices to indicate that no registers are live.
KillIndices[i] = ~0u;
DefIndices[i] = BBSize;
}
}
unsigned AggressiveAntiDepState::GetGroup(unsigned Reg) {
unsigned Node = GroupNodeIndices[Reg];
while (GroupNodes[Node] != Node)
Node = GroupNodes[Node];
return Node;
}
void AggressiveAntiDepState::GetGroupRegs(
unsigned Group,
std::vector<unsigned> &Regs,
std::multimap<unsigned, AggressiveAntiDepState::RegisterReference> *RegRefs)
{
for (unsigned Reg = 0; Reg != NumTargetRegs; ++Reg) {
if ((GetGroup(Reg) == Group) && (RegRefs->count(Reg) > 0))
Regs.push_back(Reg);
}
}
unsigned AggressiveAntiDepState::UnionGroups(unsigned Reg1, unsigned Reg2) {
assert(GroupNodes[0] == 0 && "GroupNode 0 not parent!");
assert(GroupNodeIndices[0] == 0 && "Reg 0 not in Group 0!");
// find group for each register
unsigned Group1 = GetGroup(Reg1);
unsigned Group2 = GetGroup(Reg2);
// if either group is 0, then that must become the parent
unsigned Parent = (Group1 == 0) ? Group1 : Group2;
unsigned Other = (Parent == Group1) ? Group2 : Group1;
GroupNodes.at(Other) = Parent;
return Parent;
}
unsigned AggressiveAntiDepState::LeaveGroup(unsigned Reg) {
// Create a new GroupNode for Reg. Reg's existing GroupNode must
// stay as is because there could be other GroupNodes referring to
// it.
unsigned idx = GroupNodes.size();
GroupNodes.push_back(idx);
GroupNodeIndices[Reg] = idx;
return idx;
}
bool AggressiveAntiDepState::IsLive(unsigned Reg) {
// KillIndex must be defined and DefIndex not defined for a register
// to be live.
return((KillIndices[Reg] != ~0u) && (DefIndices[Reg] == ~0u));
}
AggressiveAntiDepBreaker::AggressiveAntiDepBreaker(
MachineFunction &MFi, const RegisterClassInfo &RCI,
TargetSubtargetInfo::RegClassVector &CriticalPathRCs)
: AntiDepBreaker(), MF(MFi), MRI(MF.getRegInfo()),
TII(MF.getSubtarget().getInstrInfo()),
TRI(MF.getSubtarget().getRegisterInfo()), RegClassInfo(RCI) {
/* Collect a bitset of all registers that are only broken if they
are on the critical path. */
for (unsigned i = 0, e = CriticalPathRCs.size(); i < e; ++i) {
BitVector CPSet = TRI->getAllocatableSet(MF, CriticalPathRCs[i]);
if (CriticalPathSet.none())
CriticalPathSet = CPSet;
else
CriticalPathSet |= CPSet;
}
DEBUG(dbgs() << "AntiDep Critical-Path Registers:");
DEBUG(for (unsigned r : CriticalPathSet.set_bits())
dbgs() << " " << printReg(r, TRI));
DEBUG(dbgs() << '\n');
}
AggressiveAntiDepBreaker::~AggressiveAntiDepBreaker() {
delete State;
}
void AggressiveAntiDepBreaker::StartBlock(MachineBasicBlock *BB) {
assert(!State);
State = new AggressiveAntiDepState(TRI->getNumRegs(), BB);
bool IsReturnBlock = BB->isReturnBlock();
std::vector<unsigned> &KillIndices = State->GetKillIndices();
std::vector<unsigned> &DefIndices = State->GetDefIndices();
// Examine the live-in regs of all successors.
for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(),
SE = BB->succ_end(); SI != SE; ++SI)
for (const auto &LI : (*SI)->liveins()) {
for (MCRegAliasIterator AI(LI.PhysReg, TRI, true); AI.isValid(); ++AI) {
unsigned Reg = *AI;
State->UnionGroups(Reg, 0);
KillIndices[Reg] = BB->size();
DefIndices[Reg] = ~0u;
}
}
// Mark live-out callee-saved registers. In a return block this is
// all callee-saved registers. In non-return this is any
// callee-saved register that is not saved in the prolog.
const MachineFrameInfo &MFI = MF.getFrameInfo();
BitVector Pristine = MFI.getPristineRegs(MF);
for (const MCPhysReg *I = MF.getRegInfo().getCalleeSavedRegs(); *I;
++I) {
unsigned Reg = *I;
if (!IsReturnBlock && !Pristine.test(Reg))
continue;
for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI) {
unsigned AliasReg = *AI;
State->UnionGroups(AliasReg, 0);
KillIndices[AliasReg] = BB->size();
DefIndices[AliasReg] = ~0u;
}
}
}
void AggressiveAntiDepBreaker::FinishBlock() {
delete State;
State = nullptr;
}
void AggressiveAntiDepBreaker::Observe(MachineInstr &MI, unsigned Count,
unsigned InsertPosIndex) {
assert(Count < InsertPosIndex && "Instruction index out of expected range!");
std::set<unsigned> PassthruRegs;
GetPassthruRegs(MI, PassthruRegs);
PrescanInstruction(MI, Count, PassthruRegs);
ScanInstruction(MI, Count);
DEBUG(dbgs() << "Observe: ");
DEBUG(MI.dump());
DEBUG(dbgs() << "\tRegs:");
std::vector<unsigned> &DefIndices = State->GetDefIndices();
for (unsigned Reg = 0; Reg != TRI->getNumRegs(); ++Reg) {
// If Reg is current live, then mark that it can't be renamed as
// we don't know the extent of its live-range anymore (now that it
// has been scheduled). If it is not live but was defined in the
// previous schedule region, then set its def index to the most
// conservative location (i.e. the beginning of the previous
// schedule region).
if (State->IsLive(Reg)) {
DEBUG(if (State->GetGroup(Reg) != 0)
dbgs() << " " << printReg(Reg, TRI) << "=g" <<
State->GetGroup(Reg) << "->g0(region live-out)");
State->UnionGroups(Reg, 0);
} else if ((DefIndices[Reg] < InsertPosIndex)
&& (DefIndices[Reg] >= Count)) {
DefIndices[Reg] = Count;
}
}
DEBUG(dbgs() << '\n');
}
bool AggressiveAntiDepBreaker::IsImplicitDefUse(MachineInstr &MI,
MachineOperand &MO) {
if (!MO.isReg() || !MO.isImplicit())
return false;
unsigned Reg = MO.getReg();
if (Reg == 0)
return false;
MachineOperand *Op = nullptr;
if (MO.isDef())
Op = MI.findRegisterUseOperand(Reg, true);
else
Op = MI.findRegisterDefOperand(Reg);
return(Op && Op->isImplicit());
}
void AggressiveAntiDepBreaker::GetPassthruRegs(
MachineInstr &MI, std::set<unsigned> &PassthruRegs) {
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI.getOperand(i);
if (!MO.isReg()) continue;
if ((MO.isDef() && MI.isRegTiedToUseOperand(i)) ||
IsImplicitDefUse(MI, MO)) {
const unsigned Reg = MO.getReg();
for (MCSubRegIterator SubRegs(Reg, TRI, /*IncludeSelf=*/true);
SubRegs.isValid(); ++SubRegs)
PassthruRegs.insert(*SubRegs);
}
}
}
/// AntiDepEdges - Return in Edges the anti- and output- dependencies
/// in SU that we want to consider for breaking.
static void AntiDepEdges(const SUnit *SU, std::vector<const SDep *> &Edges) {
SmallSet<unsigned, 4> RegSet;
for (SUnit::const_pred_iterator P = SU->Preds.begin(), PE = SU->Preds.end();
P != PE; ++P) {
if ((P->getKind() == SDep::Anti) || (P->getKind() == SDep::Output)) {
if (RegSet.insert(P->getReg()).second)
Edges.push_back(&*P);
}
}
}
/// CriticalPathStep - Return the next SUnit after SU on the bottom-up
/// critical path.
static const SUnit *CriticalPathStep(const SUnit *SU) {
const SDep *Next = nullptr;
unsigned NextDepth = 0;
// Find the predecessor edge with the greatest depth.
if (SU) {
for (SUnit::const_pred_iterator P = SU->Preds.begin(), PE = SU->Preds.end();
P != PE; ++P) {
const SUnit *PredSU = P->getSUnit();
unsigned PredLatency = P->getLatency();
unsigned PredTotalLatency = PredSU->getDepth() + PredLatency;
// In the case of a latency tie, prefer an anti-dependency edge over
// other types of edges.
if (NextDepth < PredTotalLatency ||
(NextDepth == PredTotalLatency && P->getKind() == SDep::Anti)) {
NextDepth = PredTotalLatency;
Next = &*P;
}
}
}
return (Next) ? Next->getSUnit() : nullptr;
}
void AggressiveAntiDepBreaker::HandleLastUse(unsigned Reg, unsigned KillIdx,
const char *tag,
const char *header,
const char *footer) {
std::vector<unsigned> &KillIndices = State->GetKillIndices();
std::vector<unsigned> &DefIndices = State->GetDefIndices();
std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>&
RegRefs = State->GetRegRefs();
// FIXME: We must leave subregisters of live super registers as live, so that
// we don't clear out the register tracking information for subregisters of
// super registers we're still tracking (and with which we're unioning
// subregister definitions).
for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI)
if (TRI->isSuperRegister(Reg, *AI) && State->IsLive(*AI)) {
DEBUG(if (!header && footer) dbgs() << footer);
return;
}
if (!State->IsLive(Reg)) {
KillIndices[Reg] = KillIdx;
DefIndices[Reg] = ~0u;
RegRefs.erase(Reg);
State->LeaveGroup(Reg);
DEBUG(if (header) {
dbgs() << header << printReg(Reg, TRI); header = nullptr; });
DEBUG(dbgs() << "->g" << State->GetGroup(Reg) << tag);
// Repeat for subregisters. Note that we only do this if the superregister
// was not live because otherwise, regardless whether we have an explicit
// use of the subregister, the subregister's contents are needed for the
// uses of the superregister.
for (MCSubRegIterator SubRegs(Reg, TRI); SubRegs.isValid(); ++SubRegs) {
unsigned SubregReg = *SubRegs;
if (!State->IsLive(SubregReg)) {
KillIndices[SubregReg] = KillIdx;
DefIndices[SubregReg] = ~0u;
RegRefs.erase(SubregReg);
State->LeaveGroup(SubregReg);
DEBUG(if (header) {
dbgs() << header << printReg(Reg, TRI); header = nullptr; });
DEBUG(dbgs() << " " << printReg(SubregReg, TRI) << "->g" <<
State->GetGroup(SubregReg) << tag);
}
}
}
DEBUG(if (!header && footer) dbgs() << footer);
}
void AggressiveAntiDepBreaker::PrescanInstruction(
MachineInstr &MI, unsigned Count, std::set<unsigned> &PassthruRegs) {
std::vector<unsigned> &DefIndices = State->GetDefIndices();
std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>&
RegRefs = State->GetRegRefs();
// Handle dead defs by simulating a last-use of the register just
// after the def. A dead def can occur because the def is truly
// dead, or because only a subregister is live at the def. If we
// don't do this the dead def will be incorrectly merged into the
// previous def.
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI.getOperand(i);
if (!MO.isReg() || !MO.isDef()) continue;
unsigned Reg = MO.getReg();
if (Reg == 0) continue;
HandleLastUse(Reg, Count + 1, "", "\tDead Def: ", "\n");
}
DEBUG(dbgs() << "\tDef Groups:");
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI.getOperand(i);
if (!MO.isReg() || !MO.isDef()) continue;
unsigned Reg = MO.getReg();
if (Reg == 0) continue;
DEBUG(dbgs() << " " << printReg(Reg, TRI) << "=g" << State->GetGroup(Reg));
// If MI's defs have a special allocation requirement, don't allow
// any def registers to be changed. Also assume all registers
// defined in a call must not be changed (ABI). Inline assembly may
// reference either system calls or the register directly. Skip it until we
// can tell user specified registers from compiler-specified.
if (MI.isCall() || MI.hasExtraDefRegAllocReq() || TII->isPredicated(MI) ||
MI.isInlineAsm()) {
DEBUG(if (State->GetGroup(Reg) != 0) dbgs() << "->g0(alloc-req)");
State->UnionGroups(Reg, 0);
}
// Any aliased that are live at this point are completely or
// partially defined here, so group those aliases with Reg.
for (MCRegAliasIterator AI(Reg, TRI, false); AI.isValid(); ++AI) {
unsigned AliasReg = *AI;
if (State->IsLive(AliasReg)) {
State->UnionGroups(Reg, AliasReg);
DEBUG(dbgs() << "->g" << State->GetGroup(Reg) << "(via "
<< printReg(AliasReg, TRI) << ")");
}
}
// Note register reference...
const TargetRegisterClass *RC = nullptr;
if (i < MI.getDesc().getNumOperands())
RC = TII->getRegClass(MI.getDesc(), i, TRI, MF);
AggressiveAntiDepState::RegisterReference RR = { &MO, RC };
RegRefs.insert(std::make_pair(Reg, RR));
}
DEBUG(dbgs() << '\n');
// Scan the register defs for this instruction and update
// live-ranges.
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI.getOperand(i);
if (!MO.isReg() || !MO.isDef()) continue;
unsigned Reg = MO.getReg();
if (Reg == 0) continue;
// Ignore KILLs and passthru registers for liveness...
if (MI.isKill() || (PassthruRegs.count(Reg) != 0))
continue;
// Update def for Reg and aliases.
for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI) {
// We need to be careful here not to define already-live super registers.
// If the super register is already live, then this definition is not
// a definition of the whole super register (just a partial insertion
// into it). Earlier subregister definitions (which we've not yet visited
// because we're iterating bottom-up) need to be linked to the same group
// as this definition.
if (TRI->isSuperRegister(Reg, *AI) && State->IsLive(*AI))
continue;
DefIndices[*AI] = Count;
}
}
}
void AggressiveAntiDepBreaker::ScanInstruction(MachineInstr &MI,
unsigned Count) {
DEBUG(dbgs() << "\tUse Groups:");
std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>&
RegRefs = State->GetRegRefs();
// If MI's uses have special allocation requirement, don't allow
// any use registers to be changed. Also assume all registers
// used in a call must not be changed (ABI).
// Inline Assembly register uses also cannot be safely changed.
// FIXME: The issue with predicated instruction is more complex. We are being
// conservatively here because the kill markers cannot be trusted after
// if-conversion:
// %r6 = LDR %sp, %reg0, 92, pred:14, pred:%reg0; mem:LD4[FixedStack14]
// ...
// STR %r0, killed %r6, %reg0, 0, pred:0, pred:%cpsr; mem:ST4[%395]
// %r6 = LDR %sp, %reg0, 100, pred:0, pred:%cpsr; mem:LD4[FixedStack12]
// STR %r0, killed %r6, %reg0, 0, pred:14, pred:%reg0; mem:ST4[%396](align=8)
//
// The first R6 kill is not really a kill since it's killed by a predicated
// instruction which may not be executed. The second R6 def may or may not
// re-define R6 so it's not safe to change it since the last R6 use cannot be
// changed.
bool Special = MI.isCall() || MI.hasExtraSrcRegAllocReq() ||
TII->isPredicated(MI) || MI.isInlineAsm();
// Scan the register uses for this instruction and update
// live-ranges, groups and RegRefs.
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI.getOperand(i);
if (!MO.isReg() || !MO.isUse()) continue;
unsigned Reg = MO.getReg();
if (Reg == 0) continue;
DEBUG(dbgs() << " " << printReg(Reg, TRI) << "=g" << State->GetGroup(Reg));
// It wasn't previously live but now it is, this is a kill. Forget
// the previous live-range information and start a new live-range
// for the register.
HandleLastUse(Reg, Count, "(last-use)");
if (Special) {
DEBUG(if (State->GetGroup(Reg) != 0) dbgs() << "->g0(alloc-req)");
State->UnionGroups(Reg, 0);
}
// Note register reference...
const TargetRegisterClass *RC = nullptr;
if (i < MI.getDesc().getNumOperands())
RC = TII->getRegClass(MI.getDesc(), i, TRI, MF);
AggressiveAntiDepState::RegisterReference RR = { &MO, RC };
RegRefs.insert(std::make_pair(Reg, RR));
}
DEBUG(dbgs() << '\n');
// Form a group of all defs and uses of a KILL instruction to ensure
// that all registers are renamed as a group.
if (MI.isKill()) {
DEBUG(dbgs() << "\tKill Group:");
unsigned FirstReg = 0;
for (unsigned i = 0, e = MI.getNumOperands(); i != e; ++i) {
MachineOperand &MO = MI.getOperand(i);
if (!MO.isReg()) continue;
unsigned Reg = MO.getReg();
if (Reg == 0) continue;
if (FirstReg != 0) {
DEBUG(dbgs() << "=" << printReg(Reg, TRI));
State->UnionGroups(FirstReg, Reg);
} else {
DEBUG(dbgs() << " " << printReg(Reg, TRI));
FirstReg = Reg;
}
}
DEBUG(dbgs() << "->g" << State->GetGroup(FirstReg) << '\n');
}
}
BitVector AggressiveAntiDepBreaker::GetRenameRegisters(unsigned Reg) {
BitVector BV(TRI->getNumRegs(), false);
bool first = true;
// Check all references that need rewriting for Reg. For each, use
// the corresponding register class to narrow the set of registers
// that are appropriate for renaming.
for (const auto &Q : make_range(State->GetRegRefs().equal_range(Reg))) {
const TargetRegisterClass *RC = Q.second.RC;
if (!RC) continue;
BitVector RCBV = TRI->getAllocatableSet(MF, RC);
if (first) {
BV |= RCBV;
first = false;
} else {
BV &= RCBV;
}
DEBUG(dbgs() << " " << TRI->getRegClassName(RC));
}
return BV;
}
bool AggressiveAntiDepBreaker::FindSuitableFreeRegisters(
unsigned AntiDepGroupIndex,
RenameOrderType& RenameOrder,
std::map<unsigned, unsigned> &RenameMap) {
std::vector<unsigned> &KillIndices = State->GetKillIndices();
std::vector<unsigned> &DefIndices = State->GetDefIndices();
std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>&
RegRefs = State->GetRegRefs();
// Collect all referenced registers in the same group as
// AntiDepReg. These all need to be renamed together if we are to
// break the anti-dependence.
std::vector<unsigned> Regs;
State->GetGroupRegs(AntiDepGroupIndex, Regs, &RegRefs);
assert(!Regs.empty() && "Empty register group!");
if (Regs.empty())
return false;
// Find the "superest" register in the group. At the same time,
// collect the BitVector of registers that can be used to rename
// each register.
DEBUG(dbgs() << "\tRename Candidates for Group g" << AntiDepGroupIndex
<< ":\n");
std::map<unsigned, BitVector> RenameRegisterMap;
unsigned SuperReg = 0;
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
unsigned Reg = Regs[i];
if ((SuperReg == 0) || TRI->isSuperRegister(SuperReg, Reg))
SuperReg = Reg;
// If Reg has any references, then collect possible rename regs
if (RegRefs.count(Reg) > 0) {
DEBUG(dbgs() << "\t\t" << printReg(Reg, TRI) << ":");
BitVector &BV = RenameRegisterMap[Reg];
assert(BV.empty());
BV = GetRenameRegisters(Reg);
DEBUG({
dbgs() << " ::";
for (unsigned r : BV.set_bits())
dbgs() << " " << printReg(r, TRI);
dbgs() << "\n";
});
}
}
// All group registers should be a subreg of SuperReg.
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
unsigned Reg = Regs[i];
if (Reg == SuperReg) continue;
bool IsSub = TRI->isSubRegister(SuperReg, Reg);
// FIXME: remove this once PR18663 has been properly fixed. For now,
// return a conservative answer:
// assert(IsSub && "Expecting group subregister");
if (!IsSub)
return false;
}
#ifndef NDEBUG
// If DebugDiv > 0 then only rename (renamecnt % DebugDiv) == DebugMod
if (DebugDiv > 0) {
static int renamecnt = 0;
if (renamecnt++ % DebugDiv != DebugMod)
return false;
dbgs() << "*** Performing rename " << printReg(SuperReg, TRI)
<< " for debug ***\n";
}
#endif
// Check each possible rename register for SuperReg in round-robin
// order. If that register is available, and the corresponding
// registers are available for the other group subregisters, then we
// can use those registers to rename.
// FIXME: Using getMinimalPhysRegClass is very conservative. We should
// check every use of the register and find the largest register class
// that can be used in all of them.
const TargetRegisterClass *SuperRC =
TRI->getMinimalPhysRegClass(SuperReg, MVT::Other);
ArrayRef<MCPhysReg> Order = RegClassInfo.getOrder(SuperRC);
if (Order.empty()) {
DEBUG(dbgs() << "\tEmpty Super Regclass!!\n");
return false;
}
DEBUG(dbgs() << "\tFind Registers:");
RenameOrder.insert(RenameOrderType::value_type(SuperRC, Order.size()));
unsigned OrigR = RenameOrder[SuperRC];
unsigned EndR = ((OrigR == Order.size()) ? 0 : OrigR);
unsigned R = OrigR;
do {
if (R == 0) R = Order.size();
--R;
const unsigned NewSuperReg = Order[R];
// Don't consider non-allocatable registers
if (!MRI.isAllocatable(NewSuperReg)) continue;
// Don't replace a register with itself.
if (NewSuperReg == SuperReg) continue;
DEBUG(dbgs() << " [" << printReg(NewSuperReg, TRI) << ':');
RenameMap.clear();
// For each referenced group register (which must be a SuperReg or
// a subregister of SuperReg), find the corresponding subregister
// of NewSuperReg and make sure it is free to be renamed.
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
unsigned Reg = Regs[i];
unsigned NewReg = 0;
if (Reg == SuperReg) {
NewReg = NewSuperReg;
} else {
unsigned NewSubRegIdx = TRI->getSubRegIndex(SuperReg, Reg);
if (NewSubRegIdx != 0)
NewReg = TRI->getSubReg(NewSuperReg, NewSubRegIdx);
}
DEBUG(dbgs() << " " << printReg(NewReg, TRI));
// Check if Reg can be renamed to NewReg.
if (!RenameRegisterMap[Reg].test(NewReg)) {
DEBUG(dbgs() << "(no rename)");
goto next_super_reg;
}
// If NewReg is dead and NewReg's most recent def is not before
// Regs's kill, it's safe to replace Reg with NewReg. We
// must also check all aliases of NewReg, because we can't define a
// register when any sub or super is already live.
if (State->IsLive(NewReg) || (KillIndices[Reg] > DefIndices[NewReg])) {
DEBUG(dbgs() << "(live)");
goto next_super_reg;
} else {
bool found = false;
for (MCRegAliasIterator AI(NewReg, TRI, false); AI.isValid(); ++AI) {
unsigned AliasReg = *AI;
if (State->IsLive(AliasReg) ||
(KillIndices[Reg] > DefIndices[AliasReg])) {
DEBUG(dbgs() << "(alias " << printReg(AliasReg, TRI) << " live)");
found = true;
break;
}
}
if (found)
goto next_super_reg;
}
// We cannot rename 'Reg' to 'NewReg' if one of the uses of 'Reg' also
// defines 'NewReg' via an early-clobber operand.
for (const auto &Q : make_range(RegRefs.equal_range(Reg))) {
MachineInstr *UseMI = Q.second.Operand->getParent();
int Idx = UseMI->findRegisterDefOperandIdx(NewReg, false, true, TRI);
if (Idx == -1)
continue;
if (UseMI->getOperand(Idx).isEarlyClobber()) {
DEBUG(dbgs() << "(ec)");
goto next_super_reg;
}
}
// Also, we cannot rename 'Reg' to 'NewReg' if the instruction defining
// 'Reg' is an early-clobber define and that instruction also uses
// 'NewReg'.
for (const auto &Q : make_range(RegRefs.equal_range(Reg))) {
if (!Q.second.Operand->isDef() || !Q.second.Operand->isEarlyClobber())
continue;
MachineInstr *DefMI = Q.second.Operand->getParent();
if (DefMI->readsRegister(NewReg, TRI)) {
DEBUG(dbgs() << "(ec)");
goto next_super_reg;
}
}
// Record that 'Reg' can be renamed to 'NewReg'.
RenameMap.insert(std::pair<unsigned, unsigned>(Reg, NewReg));
}
// If we fall-out here, then every register in the group can be
// renamed, as recorded in RenameMap.
RenameOrder.erase(SuperRC);
RenameOrder.insert(RenameOrderType::value_type(SuperRC, R));
DEBUG(dbgs() << "]\n");
return true;
next_super_reg:
DEBUG(dbgs() << ']');
} while (R != EndR);
DEBUG(dbgs() << '\n');
// No registers are free and available!
return false;
}
/// BreakAntiDependencies - Identifiy anti-dependencies within the
/// ScheduleDAG and break them by renaming registers.
unsigned AggressiveAntiDepBreaker::BreakAntiDependencies(
const std::vector<SUnit> &SUnits,
MachineBasicBlock::iterator Begin,
MachineBasicBlock::iterator End,
unsigned InsertPosIndex,
DbgValueVector &DbgValues) {
std::vector<unsigned> &KillIndices = State->GetKillIndices();
std::vector<unsigned> &DefIndices = State->GetDefIndices();
std::multimap<unsigned, AggressiveAntiDepState::RegisterReference>&
RegRefs = State->GetRegRefs();
// The code below assumes that there is at least one instruction,
// so just duck out immediately if the block is empty.
if (SUnits.empty()) return 0;
// For each regclass the next register to use for renaming.
RenameOrderType RenameOrder;
// ...need a map from MI to SUnit.
std::map<MachineInstr *, const SUnit *> MISUnitMap;
for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
const SUnit *SU = &SUnits[i];
MISUnitMap.insert(std::pair<MachineInstr *, const SUnit *>(SU->getInstr(),
SU));
}
// Track progress along the critical path through the SUnit graph as
// we walk the instructions. This is needed for regclasses that only
// break critical-path anti-dependencies.
const SUnit *CriticalPathSU = nullptr;
MachineInstr *CriticalPathMI = nullptr;
if (CriticalPathSet.any()) {
for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
const SUnit *SU = &SUnits[i];
if (!CriticalPathSU ||
((SU->getDepth() + SU->Latency) >
(CriticalPathSU->getDepth() + CriticalPathSU->Latency))) {
CriticalPathSU = SU;
}
}
CriticalPathMI = CriticalPathSU->getInstr();
}
#ifndef NDEBUG
DEBUG(dbgs() << "\n===== Aggressive anti-dependency breaking\n");
DEBUG(dbgs() << "Available regs:");
for (unsigned Reg = 0; Reg < TRI->getNumRegs(); ++Reg) {
if (!State->IsLive(Reg))
DEBUG(dbgs() << " " << printReg(Reg, TRI));
}
DEBUG(dbgs() << '\n');
#endif
BitVector RegAliases(TRI->getNumRegs());
// Attempt to break anti-dependence edges. Walk the instructions
// from the bottom up, tracking information about liveness as we go
// to help determine which registers are available.
unsigned Broken = 0;
unsigned Count = InsertPosIndex - 1;
for (MachineBasicBlock::iterator I = End, E = Begin;
I != E; --Count) {
MachineInstr &MI = *--I;
if (MI.isDebugValue())
continue;
DEBUG(dbgs() << "Anti: ");
DEBUG(MI.dump());
std::set<unsigned> PassthruRegs;
GetPassthruRegs(MI, PassthruRegs);
// Process the defs in MI...
PrescanInstruction(MI, Count, PassthruRegs);
// The dependence edges that represent anti- and output-
// dependencies that are candidates for breaking.
std::vector<const SDep *> Edges;
const SUnit *PathSU = MISUnitMap[&MI];
AntiDepEdges(PathSU, Edges);
// If MI is not on the critical path, then we don't rename
// registers in the CriticalPathSet.
BitVector *ExcludeRegs = nullptr;
if (&MI == CriticalPathMI) {
CriticalPathSU = CriticalPathStep(CriticalPathSU);
CriticalPathMI = (CriticalPathSU) ? CriticalPathSU->getInstr() : nullptr;
} else if (CriticalPathSet.any()) {
ExcludeRegs = &CriticalPathSet;
}
// Ignore KILL instructions (they form a group in ScanInstruction
// but don't cause any anti-dependence breaking themselves)
if (!MI.isKill()) {
// Attempt to break each anti-dependency...
for (unsigned i = 0, e = Edges.size(); i != e; ++i) {
const SDep *Edge = Edges[i];
SUnit *NextSU = Edge->getSUnit();
if ((Edge->getKind() != SDep::Anti) &&
(Edge->getKind() != SDep::Output)) continue;
unsigned AntiDepReg = Edge->getReg();
DEBUG(dbgs() << "\tAntidep reg: " << printReg(AntiDepReg, TRI));
assert(AntiDepReg != 0 && "Anti-dependence on reg0?");
if (!MRI.isAllocatable(AntiDepReg)) {
// Don't break anti-dependencies on non-allocatable registers.
DEBUG(dbgs() << " (non-allocatable)\n");
continue;
} else if (ExcludeRegs && ExcludeRegs->test(AntiDepReg)) {
// Don't break anti-dependencies for critical path registers
// if not on the critical path
DEBUG(dbgs() << " (not critical-path)\n");
continue;
} else if (PassthruRegs.count(AntiDepReg) != 0) {
// If the anti-dep register liveness "passes-thru", then
// don't try to change it. It will be changed along with
// the use if required to break an earlier antidep.
DEBUG(dbgs() << " (passthru)\n");
continue;
} else {
// No anti-dep breaking for implicit deps
MachineOperand *AntiDepOp = MI.findRegisterDefOperand(AntiDepReg);
assert(AntiDepOp && "Can't find index for defined register operand");
if (!AntiDepOp || AntiDepOp->isImplicit()) {
DEBUG(dbgs() << " (implicit)\n");
continue;
}
// If the SUnit has other dependencies on the SUnit that
// it anti-depends on, don't bother breaking the
// anti-dependency since those edges would prevent such
// units from being scheduled past each other
// regardless.
//
// Also, if there are dependencies on other SUnits with the
// same register as the anti-dependency, don't attempt to
// break it.
for (SUnit::const_pred_iterator P = PathSU->Preds.begin(),
PE = PathSU->Preds.end(); P != PE; ++P) {
if (P->getSUnit() == NextSU ?
(P->getKind() != SDep::Anti || P->getReg() != AntiDepReg) :
(P->getKind() == SDep::Data && P->getReg() == AntiDepReg)) {
AntiDepReg = 0;
break;
}
}
for (SUnit::const_pred_iterator P = PathSU->Preds.begin(),
PE = PathSU->Preds.end(); P != PE; ++P) {
if ((P->getSUnit() == NextSU) && (P->getKind() != SDep::Anti) &&
(P->getKind() != SDep::Output)) {
DEBUG(dbgs() << " (real dependency)\n");
AntiDepReg = 0;
break;
} else if ((P->getSUnit() != NextSU) &&
(P->getKind() == SDep::Data) &&
(P->getReg() == AntiDepReg)) {
DEBUG(dbgs() << " (other dependency)\n");
AntiDepReg = 0;
break;
}
}
if (AntiDepReg == 0) continue;
// If the definition of the anti-dependency register does not start
// a new live range, bail out. This can happen if the anti-dep
// register is a sub-register of another register whose live range
// spans over PathSU. In such case, PathSU defines only a part of
// the larger register.
RegAliases.reset();
for (MCRegAliasIterator AI(AntiDepReg, TRI, true); AI.isValid(); ++AI)
RegAliases.set(*AI);
for (SDep S : PathSU->Succs) {
SDep::Kind K = S.getKind();
if (K != SDep::Data && K != SDep::Output && K != SDep::Anti)
continue;
unsigned R = S.getReg();
if (!RegAliases[R])
continue;
if (R == AntiDepReg || TRI->isSubRegister(AntiDepReg, R))
continue;
AntiDepReg = 0;
break;
}
if (AntiDepReg == 0) continue;
}
assert(AntiDepReg != 0);
if (AntiDepReg == 0) continue;
// Determine AntiDepReg's register group.
const unsigned GroupIndex = State->GetGroup(AntiDepReg);
if (GroupIndex == 0) {
DEBUG(dbgs() << " (zero group)\n");
continue;
}
DEBUG(dbgs() << '\n');
// Look for a suitable register to use to break the anti-dependence.
std::map<unsigned, unsigned> RenameMap;
if (FindSuitableFreeRegisters(GroupIndex, RenameOrder, RenameMap)) {
DEBUG(dbgs() << "\tBreaking anti-dependence edge on "
<< printReg(AntiDepReg, TRI) << ":");
// Handle each group register...
for (std::map<unsigned, unsigned>::iterator
S = RenameMap.begin(), E = RenameMap.end(); S != E; ++S) {
unsigned CurrReg = S->first;
unsigned NewReg = S->second;
DEBUG(dbgs() << " " << printReg(CurrReg, TRI) << "->"
<< printReg(NewReg, TRI) << "("
<< RegRefs.count(CurrReg) << " refs)");
// Update the references to the old register CurrReg to
// refer to the new register NewReg.
for (const auto &Q : make_range(RegRefs.equal_range(CurrReg))) {
Q.second.Operand->setReg(NewReg);
// If the SU for the instruction being updated has debug
// information related to the anti-dependency register, make
// sure to update that as well.
const SUnit *SU = MISUnitMap[Q.second.Operand->getParent()];
if (!SU) continue;
UpdateDbgValues(DbgValues, Q.second.Operand->getParent(),
AntiDepReg, NewReg);
}
// We just went back in time and modified history; the
// liveness information for CurrReg is now inconsistent. Set
// the state as if it were dead.
State->UnionGroups(NewReg, 0);
RegRefs.erase(NewReg);
DefIndices[NewReg] = DefIndices[CurrReg];
KillIndices[NewReg] = KillIndices[CurrReg];
State->UnionGroups(CurrReg, 0);
RegRefs.erase(CurrReg);
DefIndices[CurrReg] = KillIndices[CurrReg];
KillIndices[CurrReg] = ~0u;
assert(((KillIndices[CurrReg] == ~0u) !=
(DefIndices[CurrReg] == ~0u)) &&
"Kill and Def maps aren't consistent for AntiDepReg!");
}
++Broken;
DEBUG(dbgs() << '\n');
}
}
}
ScanInstruction(MI, Count);
}
return Broken;
}
|
hello_world:
lda #$00
sta PPU_01_CTRL2
ldx #0
lda PPU_02_STATUS
lda #$20
sta VRAM_06_ADDR2
stx VRAM_06_ADDR2
.hello_world_top_blank:
sta VRAM_07_IO
inx
bne .hello_world_top_blank
.hello_world_print:
lda hello_string,x
sta VRAM_07_IO
inx
cpx #$10
bne .hello_world_print
ldx #$50
ldy #3
lda #$20
.hello_world_bottom_blank:
sta VRAM_07_IO
inx
bne .hello_world_bottom_blank
dey
bne .hello_world_bottom_blank
ldx #$40
lda #0
.hello_world_attribute_table:
sta VRAM_07_IO
dex
bne .hello_world_attribute_table
sta VRAM_05_ADDR1
sta VRAM_05_ADDR1
lda #%001000
sta PPU_01_CTRL2
|
/*
* Copyright (c) 2017, Intel Corporation
*
* 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.
*/
L0:
(W&~f0.1)jmpi L1552
L16:
mov (8|M0) acc0.0<1>:f r25.2<0;1,0>:f
mac (1|M0) r23.3<1>:f r25.4<0;1,0>:f 7.0:f
mov (4|M0) r10.0<1>:f 0x48403000:vf
mov (4|M0) r10.4<1>:f 0x5C585450:vf
mov (8|M0) r13.0<1>:ud r0.0<8;8,1>:ud
mov (2|M0) r13.0<1>:ud 0x0:ud
mov (1|M0) r13.2<1>:ud 0xE000:ud
add (1|M0) a0.0<1>:ud r23.5<0;1,0>:ud 0xA2C0100:ud
mov (8|M0) acc0.0<1>:f r25.3<0;1,0>:f
mac (8|M0) r16.0<1>:f r25.5<0;1,0>:f r10.0<8;8,1>:f
mac (8|M0) r17.0<1>:f r25.5<0;1,0>:f r10.0<8;8,1>:f
mov (8|M0) acc0.0<1>:f r23.3<0;1,0>:f
mac (8|M0) r14.0<1>:f r25.4<0;1,0>:f r10.0<0;1,0>:f
mul (8|M0) acc0.0<1>:f r25.4<0;1,0>:f -1.0:f
add (8|M0) r15.0<1>:f acc0.0<8;8,1>:f r14.0<8;8,1>:f
send (16|M0) r104:uw r13:ub 0x2 a0.0
add (1|M0) a0.0<1>:ud r23.5<0;1,0>:ud 0xA4C0201:ud
mov (1|M0) r13.2<1>:ud 0xC000:ud
send (16|M0) r108:uw r13:ub 0x2 a0.0
mul (8|M0) acc0.0<1>:f r25.4<0;1,0>:f -2.0:f
add (8|M0) r14.0<1>:f acc0.0<8;8,1>:f r14.0<8;8,1>:f
add (8|M0) r15.0<1>:f acc0.0<8;8,1>:f r15.0<8;8,1>:f
mul (16|M0) acc0.0<1>:f r104.0<8;8,1>:f 65472.0:f
mov (16|M0) (sat)r96.0<1>:ud acc0.0<8;8,1>:f
mul (16|M0) acc0.0<1>:f r108.0<8;8,1>:f 65472.0:f
mov (16|M0) (sat)r100.0<1>:ud acc0.0<8;8,1>:f
mul (16|M0) acc0.0<1>:f r110.0<8;8,1>:f 65472.0:f
mov (16|M0) (sat)r102.0<1>:ud acc0.0<8;8,1>:f
mov (16|M0) r96.0<1>:uw r96.0<16;8,2>:uw
mov (16|M0) r100.0<1>:uw r100.0<16;8,2>:uw
mov (16|M0) r102.0<1>:uw r102.0<16;8,2>:uw
add (1|M0) a0.0<1>:ud r23.5<0;1,0>:ud 0xA2C0100:ud
mov (1|M0) r13.2<1>:ud 0xE000:ud
send (16|M0) r104:uw r13:ub 0x2 a0.0
add (1|M0) a0.0<1>:ud r23.5<0;1,0>:ud 0xA4C0201:ud
mov (1|M0) r13.2<1>:ud 0xC000:ud
send (16|M0) r106:uw r13:ub 0x2 a0.0
mul (8|M0) acc0.0<1>:f r25.5<0;1,0>:f 8.0:f
add (8|M0) r16.0<1>:f acc0.0<8;8,1>:f r16.0<8;8,1>:f
add (8|M0) r17.0<1>:f acc0.0<8;8,1>:f r17.0<8;8,1>:f
mul (8|M0) acc0.0<1>:f r25.4<0;1,0>:f 2.0:f
add (8|M0) r14.0<1>:f acc0.0<8;8,1>:f r14.0<8;8,1>:f
add (8|M0) r15.0<1>:f acc0.0<8;8,1>:f r15.0<8;8,1>:f
mul (16|M0) acc0.0<1>:f r104.0<8;8,1>:f 65472.0:f
mov (16|M0) (sat)r104.0<1>:ud acc0.0<8;8,1>:f
mul (16|M0) acc0.0<1>:f r106.0<8;8,1>:f 65472.0:f
mov (16|M0) (sat)r106.0<1>:ud acc0.0<8;8,1>:f
mul (16|M0) acc0.0<1>:f r108.0<8;8,1>:f 65472.0:f
mov (16|M0) (sat)r108.0<1>:ud acc0.0<8;8,1>:f
mov (16|M0) r97.0<1>:uw r104.0<16;8,2>:uw
mov (16|M0) r101.0<1>:uw r106.0<16;8,2>:uw
mov (16|M0) r103.0<1>:uw r108.0<16;8,2>:uw
add (1|M0) a0.0<1>:ud r23.5<0;1,0>:ud 0xA2C0100:ud
mov (1|M0) r13.2<1>:ud 0xE000:ud
send (16|M0) r104:uw r13:ub 0x2 a0.0
add (1|M0) a0.0<1>:ud r23.5<0;1,0>:ud 0xA4C0201:ud
mov (1|M0) r13.2<1>:ud 0xC000:ud
send (16|M0) r108:uw r13:ub 0x2 a0.0
mul (8|M0) acc0.0<1>:f r25.4<0;1,0>:f -2.0:f
add (8|M0) r14.0<1>:f acc0.0<8;8,1>:f r14.0<8;8,1>:f
add (8|M0) r15.0<1>:f acc0.0<8;8,1>:f r15.0<8;8,1>:f
mul (16|M0) acc0.0<1>:f r104.0<8;8,1>:f 65472.0:f
mov (16|M0) (sat)r104.0<1>:ud acc0.0<8;8,1>:f
mul (16|M0) acc0.0<1>:f r108.0<8;8,1>:f 65472.0:f
mov (16|M0) (sat)r108.0<1>:ud acc0.0<8;8,1>:f
mul (16|M0) acc0.0<1>:f r110.0<8;8,1>:f 65472.0:f
mov (16|M0) (sat)r110.0<1>:ud acc0.0<8;8,1>:f
mov (16|M0) r10.0<1>:uw r104.0<16;8,2>:uw
mov (16|M0) r11.0<1>:uw r108.0<16;8,2>:uw
mov (16|M0) r12.0<1>:uw r110.0<16;8,2>:uw
add (1|M0) a0.0<1>:ud r23.5<0;1,0>:ud 0xA2C0100:ud
mov (1|M0) r13.2<1>:ud 0xE000:ud
send (16|M0) r104:uw r13:ub 0x2 a0.0
add (1|M0) a0.0<1>:ud r23.5<0;1,0>:ud 0xA4C0201:ud
mov (1|M0) r13.2<1>:ud 0xC000:ud
send (16|M0) r108:uw r13:ub 0x2 a0.0
mul (16|M0) acc0.0<1>:f r104.0<8;8,1>:f 65472.0:f
mov (16|M0) (sat)r104.0<1>:ud acc0.0<8;8,1>:f
mul (16|M0) acc0.0<1>:f r108.0<8;8,1>:f 65472.0:f
mov (16|M0) (sat)r108.0<1>:ud acc0.0<8;8,1>:f
mul (16|M0) acc0.0<1>:f r110.0<8;8,1>:f 65472.0:f
mov (16|M0) (sat)r110.0<1>:ud acc0.0<8;8,1>:f
mov (16|M0) r105.0<1>:uw r104.0<16;8,2>:uw
mov (16|M0) r109.0<1>:uw r108.0<16;8,2>:uw
mov (16|M0) r111.0<1>:uw r110.0<16;8,2>:uw
mov (16|M0) r104.0<1>:uw r10.0<16;16,1>:uw
mov (16|M0) r108.0<1>:uw r11.0<16;16,1>:uw
mov (16|M0) r110.0<1>:uw r12.0<16;16,1>:uw
mov (16|M0) r98.0<1>:uw 0xFFFF:uw
mov (16|M0) r99.0<1>:uw 0xFFFF:uw
mov (16|M0) r106.0<1>:uw 0xFFFF:uw
mov (16|M0) r107.0<1>:uw 0xFFFF:uw
mov (1|M0) a0.8<1>:uw 0xC00:uw
mov (1|M0) a0.9<1>:uw 0xC80:uw
mov (1|M0) a0.10<1>:uw 0xCC0:uw
add (4|M0) a0.12<1>:uw a0.8<4;4,1>:uw 0x100:uw
L1552:
nop
|
;------------------------------------------------------------------------------
; lcmnd.asm
; Intel hex data load command
;
; Copyright (c) 2021 4sun5bu
;------------------------------------------------------------------------------
.z280p
.area CODE
.globl lcmnd
lcmnd:
ldw (ldad), 0x0000
call skipsp
or a, a
jr z, lcmnd1 ; without load address
call strhex16
jr c, lerr
ld (ldad), de
ld (jmpad), de
lcmnd1:
ld hl, linebuf
call gets
ld hl, linebuf
lcmnd2:
ld a, (hl)
cp a, ':
jr nz, herr
inc hl
lcmnd3:
call strhex8 ; Byte count
jr c, herr
ld b, e
ld c, e
call strhex16 ; Address
jr c, herr
ld ixh, d
ld ixl, e
ld a, c
add a, d
add a, e
ld c, a
call strhex8 ; Type
jr c, herr
ld a, e
cp a, 0x01
jp z, loop
or a, a
jr nz, herr
add a, c
ld c, a
lcmnd4:
call strhex8
jr c, herr
ld (ix), e
ld a, e
add a, c
ld c, a
inc ix
djnz lcmnd4
call strhex8
ld a, c
neg
cp a, e
jr nz, herr
jr lcmnd1
lerr:
ld hl, lerrmsg
jp cmnderr
herr:
ld hl, herrmsg
jp cmnderr
;------------------------------------------------------------------------------
.area DATA
lerrmsg:
.ascii "Error! l [xxxx]"
.db 0x00
herrmsg:
.ascii "Illegal HEX File"
.db 0x00
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r13
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_UC_ht+0x3b9b, %r10
nop
xor %r11, %r11
movb $0x61, (%r10)
nop
nop
nop
nop
nop
dec %rcx
lea addresses_WC_ht+0x1e17b, %rsi
lea addresses_D_ht+0x138bb, %rdi
nop
nop
cmp %r13, %r13
mov $91, %rcx
rep movsq
nop
nop
nop
nop
and $33410, %rdi
lea addresses_normal_ht+0x12b6b, %r13
nop
nop
xor $51107, %r10
mov (%r13), %r11
nop
nop
cmp $1380, %rdi
lea addresses_normal_ht+0x10a7b, %rsi
nop
nop
nop
xor %rdx, %rdx
mov (%rsi), %rdi
nop
dec %r13
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %r13
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r14
push %r8
push %r9
push %rbx
push %rdx
push %rsi
// Store
lea addresses_RW+0x1053b, %r9
xor %r8, %r8
movb $0x51, (%r9)
nop
nop
nop
dec %rdx
// Store
lea addresses_US+0x1f97b, %r14
nop
nop
sub $12431, %rbx
mov $0x5152535455565758, %rdx
movq %rdx, %xmm2
movups %xmm2, (%r14)
nop
xor %rsi, %rsi
// Load
lea addresses_US+0x1dc9f, %rsi
nop
nop
nop
nop
nop
and %r13, %r13
mov (%rsi), %r14d
nop
nop
nop
add $53688, %rsi
// Load
mov $0x3db, %r8
nop
xor %r9, %r9
movb (%r8), %r13b
sub %r9, %r9
// Faulty Load
lea addresses_US+0x1f97b, %r9
nop
nop
nop
nop
add $50043, %rsi
mov (%r9), %r8
lea oracles, %r13
and $0xff, %r8
shlq $12, %r8
mov (%r13,%r8,1), %r8
pop %rsi
pop %rdx
pop %rbx
pop %r9
pop %r8
pop %r14
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_US', 'size': 2, 'AVXalign': False}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 6, 'NT': False, 'type': 'addresses_RW', 'size': 1, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_US', 'size': 16, 'AVXalign': False}}
{'src': {'same': False, 'congruent': 1, 'NT': False, 'type': 'addresses_US', 'size': 4, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 5, 'NT': False, 'type': 'addresses_P', 'size': 1, 'AVXalign': False}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_US', 'size': 8, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 3, 'NT': False, 'type': 'addresses_UC_ht', 'size': 1, 'AVXalign': False}}
{'src': {'type': 'addresses_WC_ht', 'congruent': 11, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_D_ht', 'congruent': 1, 'same': False}}
{'src': {'same': False, 'congruent': 4, 'NT': False, 'type': 'addresses_normal_ht', 'size': 8, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 7, 'NT': False, 'type': 'addresses_normal_ht', 'size': 8, 'AVXalign': False}, 'OP': 'LOAD'}
{'58': 21829}
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
*/
|
; ----- Colour palette (ULA)
BLACK equ 0
BLUE equ 1
RED equ 2
MAGENTA equ 3
GREEN equ 4
CYAN equ 5
YELLOW equ 6
WHITE equ 7
P_BLACK equ 0
P_BLUE equ 1<<3
P_RED equ 2<<3
P_MAGENTA equ 3<<3
P_GREEN equ 4<<3
P_CYAN equ 5<<3
P_YELLOW equ 6<<3
P_WHITE equ 7<<3
; ----- Attribs
A_FLASH equ 128
A_BRIGHT equ 64
;----------------------------------------------
BIT_UP equ 4 ; 16
BIT_DOWN equ 5 ; 32
BIT_LEFT equ 6 ; 64
BIT_RIGHT equ 7 ; 128
DIR_NONE equ %00000000
DIR_UP equ %00010000
DIR_DOWN equ %00100000
DIR_LEFT equ %01000000
DIR_RIGHT equ %10000000
DIR_UP_I equ %11101111
DIR_DOWN_I equ %11011111
DIR_LEFT_I equ %10111111
DIR_RIGHT_I equ %01111111
;-----------------------------------------------------------------------------
;-- I/O ports - ZX Spectrum classic (48, 128, Timex, Pentagon, ...) ports
ULA_P_FE equ $FE ; BORDER + MIC + BEEP + read Keyboard
TIMEX_P_FF equ $FF ; Timex video control port
ZX128_MEMORY_P_7FFD equ $7FFD ; ZX Spectrum 128 ports
ZX128_MEMORY_P_DFFD equ $DFFD
ZX128P3_MEMORY_P_1FFD equ $1FFD
AY_REG_P_FFFD equ $FFFD
AY_DATA_P_BFFD equ $BFFD
Z80_DMA_PORT_DATAGEAR equ $6B ; on ZXN the zxnDMA handles this
Z80_DMA_PORT_MB02 equ $0B ; only in Zilog DMA mode zxnDMA handles this
DIVMMC_CONTROL_P_E3 equ $E3
SPI_CS_P_E7 equ $E7
SPI_DATA_P_EB equ $EB
KEMPSTON_MOUSE_X_P_FBDF equ $FBDF
KEMPSTON_MOUSE_Y_P_FFDF equ $FFDF
KEMPSTON_MOUSE_B_P_FADF equ $FADF ; kempston mouse wheel+buttons
KEMPSTON_JOY1_P_1F equ $1F
KEMPSTON_JOY2_P_37 equ $37
;-----------------------------------------------------------------------------
;-- I/O ports - ZX Spectrum NEXT specific ports
TBBLUE_REGISTER_SELECT_P_243B equ $243B
; -- port $243B = 9275 Read+Write (detection bitmask: %0010_0100_0011_1011)
; -- selects NextREG mapped at port TBBLUE_REGISTER_ACCESS_P_253B
TBBLUE_REGISTER_ACCESS_P_253B equ $253B
; -- port $253B = 9531 Read?+Write? (detection bitmask: %0010_0101_0011_1011)
; -- data for selected NextREG (read/write depends on the register selected)
I2C_SCL_P_103B equ $103B ; i2c bus port (clock) (write only?)
I2C_SDA_P_113B equ $113B ; i2c bus port (data) (read+write)
UART_TX_P_133B equ $133B ; UART tx port (read+write)
UART_RX_P_143B equ $143B ; UART rx port (read+write)
ZXN_DMA_P_6B equ $6B
; -- port $6B = 107 Read+Write (detection bitmask: %xxxx_xxxx_0110_1011)
; - The zxnDMA is mostly compatible with Zilog DMA chip (Z8410) (at least
; as far as old ZX apps are concerned), but has many modifications.
; - core3.0 update - specific behaviour details can be selected (PERIPHERAL_2_NR_06)
LAYER2_ACCESS_P_123B equ $123B
; -- port $123B = 4667 Read+Write (detection bitmask: %0001_0010_0011_1011)
; -- bit 7-6 = write-Layer2-over-ROM bank selection (00, 01 or 10) (11 is 48kiB mode)
; -- bit 3 = shadow banks "over ROM" (nextreg $13 banks instead of $12 banks)
; -- bit 2 = read-Layer2-over-ROM (1 = read at $0000..$3FFF reads from Layer2)
; -- bit 1 = Layer2 visibility (1 = visible, 0 = disabled) (always nextreg $12)
; -- bit 0 = write-Layer2-over-ROM (1 = write at $0000..$3FFF writes into Layer2)
LAYER2_ACCESS_WRITE_OVER_ROM equ $01 ; map Layer2 bank into ROM area (0000..3FFF) for WRITE-only (reads as ROM)
LAYER2_ACCESS_L2_ENABLED equ $02 ; enable Layer2 (make banks form nextreg $12 visible)
LAYER2_ACCESS_READ_OVER_ROM equ $04 ; map Layer2 bank into ROM area (0000..3FFF) for READ-only
LAYER2_ACCESS_SHADOW_OVER_ROM equ $08 ; bank selected by bits 6-7 is from "shadow Layer 2" banks range (nextreg $13)
LAYER2_ACCESS_OVER_ROM_BANK_M equ $C0 ; (mask of) value 0..3 selecting bank mapped for R/W (Nextreg $12 or $13)
LAYER2_ACCESS_OVER_ROM_BANK_0 equ $00 ; screen lines 0..63
LAYER2_ACCESS_OVER_ROM_BANK_1 equ $40 ; screen lines 64..127
LAYER2_ACCESS_OVER_ROM_BANK_2 equ $80 ; screen lines 128..191
LAYER2_ACCESS_OVER_ROM_48K equ $C0 ; maps all 0..191 lines into $0000..$BFFF region
SPRITE_STATUS_SLOT_SELECT_P_303B equ $303B
; -- port $303B = 12347 Read+Write (detection bitmask: %0011_0000_0011_1011)
; -- write:
; - sets both "sprite slot" (0..63) and "pattern slot" (0..63 +128)
; - once the sprite/pattern slots are set, they act independently and
; each port ($xx57 and $xx5B) will auto-increment its own slot index
; (to resync one can write to this port again).
; - the +128 flag will make the pattern upload start at byte 128 of pattern
; slot (second half of slot)
; - The sprite-slot (sprite-attributes) may be optionally interlinked with
; NextReg $34 (feature controlled by NextReg $34)
; - auto-increments of slot position from value 63 are officially
; "undefined behaviour", wrap to 0 is not guaranteed. (only setting slots
; explicitly back to valid 0..63 will make your code future-proof)
; -- read (will also reset both collision and max-sprites flags):
; - bit 1 = maximum sprites per line hit (set when sprite renderer ran
; out of time when preparing next scanline)
; - bit 0 = collision flag (set when any sprites draw non-transparent
; pixel at the same location)
; Both flags contain values for current scanline already at the beginning
; of scanline (sprite engine renders one line ahead into buffer and updates
; flags progressively as it renders the sprites)
SPRITE_STATUS_MAXIMUM_SPRITES equ $02
SPRITE_STATUS_COLLISION equ $01
SPRITE_SLOT_SELECT_PATTERN_HALF equ 128 ; add it to 0..63 index to make pattern upload start at second half of pattern
SPRITE_ATTRIBUTE_P_57 equ $57
; -- port $xx57 = 87 write-only (detection bitmask: %xxxx_xxxx_0101_0111)
; - writing 4 or 5 bytes long structures to control particular sprite
; - after 4/5 bytes block the sprite slot index is auto-incremented
; - for detailed documentation check official docs or wiki (too long)
SPRITE_PATTERN_P_5B equ $5B
; -- port $xx5B = 91 write-only (detection bitmask: %xxxx_xxxx_0101_1011)
; - each pattern slot is 256 bytes long = one 16x16 pattern of 8-bit pixels
; or two 16x16 patterns of 4-bit pixels.
; - Patterns are uploaded in "English" order (left to right, top to bottom),
; one byte encodes single pixel in 8 bit mode and two pixels in 4 bit
; mode (bits 7-4 are "left" pixel, 3-0 are "right" pixel)
; - pixels are offset (index) into active sprite palette
TURBO_SOUND_CONTROL_P_FFFD equ $FFFD ; write with bit 7 = 1 (port shared with AY)
;-----------------------------------------------------------------------------
;-- NEXT HW Registers (NextReg)
MACHINE_ID_NR_00 equ $00
NEXT_VERSION_NR_01 equ $01
NEXT_RESET_NR_02 equ $02
MACHINE_TYPE_NR_03 equ $03
ROM_MAPPING_NR_04 equ $04 ;In config mode, allows RAM to be mapped to ROM area.
PERIPHERAL_1_NR_05 equ $05 ;Sets joystick mode, video frequency and Scandoubler.
PERIPHERAL_2_NR_06 equ $06 ;Enables Acceleration, DivMMC, Multiface, Mouse and AY audio
TURBO_CONTROL_NR_07 equ $07
PERIPHERAL_3_NR_08 equ $08 ;ABC/ACB Stereo, Internal Speaker, SpecDrum, Timex Video Modes, Turbo Sound Next, RAM contention and [un]lock 128k paging.
PERIPHERAL_4_NR_09 equ $09 ;Sets scanlines, AY mono output, Sprite-id lockstep, disables Kempston and divMMC ports.
NEXT_VERSION_MINOR_NR_0E equ $0E
ANTI_BRICK_NR_10 equ $10
VIDEO_TIMING_NR_11 equ $11
LAYER2_RAM_BANK_NR_12 equ $12 ;bank number where visible Layer 2 video memory begins.
LAYER2_RAM_SHADOW_BANK_NR_13 equ $13 ;bank number for Layer2 "shadow" write-over-rom
GLOBAL_TRANSPARENCY_NR_14 equ $14 ;Sets the color treated as transparent for ULA/Layer2/LoRes
SPRITE_CONTROL_NR_15 equ $15 ;LoRes mode, Sprites configuration, layers priority
; bit 7: enable LoRes mode
; bit 6: sprite rendering (1=sprite 0 on top of other, 0=sprite 0 at bottom)
; bit 5: If 1, the clipping works even in "over border" mode
; 4-2: layers priority: 000=SLU, 001=LSU, 010=SUL, 011=LUS, 100=USL, 101=ULS, 110=S,mix(U+L), 111=S,mix(U+L-5)
; bit 1: enable sprites over border, bit 0: show sprites
LAYER2_XOFFSET_NR_16 equ $16
LAYER2_YOFFSET_NR_17 equ $17
CLIP_LAYER2_NR_18 equ $18
CLIP_SPRITE_NR_19 equ $19
CLIP_ULA_LORES_NR_1A equ $1A
CLIP_TILEMAP_NR_1B equ $1B
CLIP_WINDOW_CONTROL_NR_1C equ $1C ;set to 15 to reset all clip-window indices to 0
RASTER_LINE_MSB_NR_1E equ $1E
RASTER_LINE_LSB_NR_1F equ $1F
RASTER_INTERUPT_CONTROL_NR_22 equ $22 ;Controls the timing of raster interrupts and the ULA frame interrupt.
RASTER_INTERUPT_VALUE_NR_23 equ $23
ULA_XOFFSET_NR_26 equ $26 ;since core 3.0
ULA_YOFFSET_NR_27 equ $27 ;since core 3.0
HIGH_ADRESS_KEYMAP_NR_28 equ $28
LOW_ADRESS_KEYMAP_NR_29 equ $29
HIGH_DATA_TO_KEYMAP_NR_2A equ $2A
LOW_DATA_TO_KEYMAP_NR_2B equ $2B
DAC_B_MIRROR_NR_2C equ $2C
DAC_AD_MIRROR_NR_2D equ $2D ;another alias for $2D
SOUNDDRIVE_DF_MIRROR_NR_2D equ $2D ;Nextreg port-mirror of port 0xDF
DAC_C_MIRROR_NR_2E equ $2E
TILEMAP_XOFFSET_MSB_NR_2F equ $2F
TILEMAP_XOFFSET_LSB_NR_30 equ $30
TILEMAP_YOFFSET_NR_31 equ $31
LORES_XOFFSET_NR_32 equ $32
LORES_YOFFSET_NR_33 equ $33
SPRITE_ATTR_SLOT_SEL_NR_34 equ $34 ;Sprite-attribute slot index for $35-$39/$75-$79 port $57 mirrors
SPRITE_ATTR0_NR_35 equ $35 ;port $57 mirror in nextreg space (accessible to copper)
SPRITE_ATTR1_NR_36 equ $36
SPRITE_ATTR2_NR_37 equ $37
SPRITE_ATTR3_NR_38 equ $38
SPRITE_ATTR4_NR_39 equ $39
PALETTE_INDEX_NR_40 equ $40 ;Chooses a ULANext palette number to configure.
PALETTE_VALUE_NR_41 equ $41 ;Used to upload 8-bit colors to the ULANext palette.
PALETTE_FORMAT_NR_42 equ $42 ;ink-mask for ULANext modes
PALETTE_CONTROL_NR_43 equ $43 ;Enables or disables ULANext interpretation of attribute values and toggles active palette.
PALETTE_VALUE_9BIT_NR_44 equ $44 ;Holds the additional blue color bit for RGB333 color selection.
TRANSPARENCY_FALLBACK_COL_NR_4A equ $4A ;8-bit colour to be drawn when all layers are transparent
SPRITE_TRANSPARENCY_I_NR_4B equ $4B ;index of transparent colour in sprite palette (only bottom 4 bits for 4-bit patterns)
TILEMAP_TRANSPARENCY_I_NR_4C equ $4C ;index of transparent colour in tilemap graphics (only bottom 4 bits)
MMU0_0000_NR_50 equ $50 ;Set a Spectrum RAM page at position 0x0000 to 0x1FFF
MMU1_2000_NR_51 equ $51 ;Set a Spectrum RAM page at position 0x2000 to 0x3FFF
MMU2_4000_NR_52 equ $52 ;Set a Spectrum RAM page at position 0x4000 to 0x5FFF
MMU3_6000_NR_53 equ $53 ;Set a Spectrum RAM page at position 0x6000 to 0x7FFF
MMU4_8000_NR_54 equ $54 ;Set a Spectrum RAM page at position 0x8000 to 0x9FFF
MMU5_A000_NR_55 equ $55 ;Set a Spectrum RAM page at position 0xA000 to 0xBFFF
MMU6_C000_NR_56 equ $56 ;Set a Spectrum RAM page at position 0xC000 to 0xDFFF
MMU7_E000_NR_57 equ $57 ;Set a Spectrum RAM page at position 0xE000 to 0xFFFF
COPPER_DATA_NR_60 equ $60
COPPER_CONTROL_LO_NR_61 equ $61
COPPER_CONTROL_HI_NR_62 equ $62
COPPER_DATA_16B_NR_63 equ $63 ; same as $60, but waits for full 16b before write
ULA_CONTROL_NR_68 equ $68
DISPLAY_CONTROL_NR_69 equ $69
LORES_CONTROL_NR_6A equ $6A
TILEMAP_CONTROL_NR_6B equ $6B
TILEMAP_DEFAULT_ATTR_NR_6C equ $6C
TILEMAP_BASE_ADR_NR_6E equ $6E ;Tilemap base address of map
TILEMAP_GFX_ADR_NR_6F equ $6F ;Tilemap definitions (graphics of tiles)
LAYER2_CONTROL_NR_70 equ $70
SPRITE_ATTR0_INC_NR_75 equ $75 ;port $57 mirror in nextreg space (accessible to copper) (slot index++)
SPRITE_ATTR1_INC_NR_76 equ $76
SPRITE_ATTR2_INC_NR_77 equ $77
SPRITE_ATTR3_INC_NR_78 equ $78
SPRITE_ATTR4_INC_NR_79 equ $79
USER_STORAGE_0_NR_7F equ $7F
EXPANSION_BUS_CONTROL_NR_80 equ $80
INTERNAL_PORT_DECODING_0_NR_82 equ $82 ;bits 0-7
INTERNAL_PORT_DECODING_1_NR_83 equ $83 ;bits 8-15
INTERNAL_PORT_DECODING_2_NR_84 equ $84 ;bits 16-23
INTERNAL_PORT_DECODING_3_NR_85 equ $85 ;bits 24-31
EXPANSION_BUS_DECODING_0_NR_86 equ $86 ;bits 0-7 mask
EXPANSION_BUS_DECODING_1_NR_87 equ $87 ;bits 8-15 mask
EXPANSION_BUS_DECODING_2_NR_88 equ $88 ;bits 16-23 mask
EXPANSION_BUS_DECODING_3_NR_89 equ $89 ;bits 24-31 mask
EXPANSION_BUS_PROPAGATE_NR_8A equ $8A ;Monitoring internal I/O or adding external keyboard
PI_GPIO_OUT_ENABLE_0_NR_90 equ $90 ;pins 0-7
PI_GPIO_OUT_ENABLE_1_NR_91 equ $91 ;pins 8-15
PI_GPIO_OUT_ENABLE_2_NR_92 equ $92 ;pins 16-23
PI_GPIO_OUT_ENABLE_3_NR_93 equ $93 ;pins 24-27
PI_GPIO_0_NR_98 equ $98 ;pins 0-7
PI_GPIO_1_NR_99 equ $99 ;pins 8-15
PI_GPIO_2_NR_9A equ $9A ;pins 16-23
PI_GPIO_3_NR_9B equ $9B ;pins 24-27
PI_PERIPHERALS_ENABLE_NR_A0 equ $A0
PI_I2S_AUDIO_CONTROL_NR_A2 equ $A2
PI_I2S_CLOCK_DIVIDE_NR_A3 equ $A3
DEBUG_LED_CONTROL_NR_FF equ $FF ;Turns debug LEDs on and off on TBBlue implementations that have them.
;-----------------------------------------------------------------------------
;-- common memory addresses
MEM_ROM_CHARS_3C00 equ $3C00 ; actual chars start at $3D00 with space
MEM_ZX_SCREEN_4000 equ $4000
MEM_ZX_ATTRIB_5800 equ $5800
MEM_LORES0_4000 equ $4000
MEM_LORES1_6000 equ $6000
MEM_TIMEX_SCR0_4000 equ $4000
MEM_TIMEX_SCR1_6000 equ $6000
;-----------------------------------------------------------------------------
;-- Copper commands
COPPER_NOOP equ %00000000
COPPER_WAIT_H equ %1'000000'0
COPPER_HALT_B equ $FF ; 2x $FF = wait for (511,63) = infinite wait
;-----------------------------------------------------------------------------
; DMA (Register 6)
DMA_RESET equ $C3
DMA_RESET_PORT_A_TIMING equ $C7
DMA_RESET_PORT_B_TIMING equ $CB
DMA_LOAD equ $CF
DMA_CONTINUE equ $D3
DMA_DISABLE_INTERUPTS equ $AF
DMA_ENABLE_INTERUPTS equ $AB
DMA_RESET_DISABLE_INTERUPTS equ $A3
DMA_ENABLE_AFTER_RETI equ $B7
DMA_READ_STATUS_BYTE equ $BF
DMA_REINIT_STATUS_BYTE equ $8B
DMA_START_READ_SEQUENCE equ $A7
DMA_FORCE_READY equ $B3
DMA_DISABLE equ $83
DMA_ENABLE equ $87
DMA_READ_MASK_FOLLOWS equ $BB
; About UART<->ESP baund rate from AA:
;
; It's very easy to compute the prescalar.
; 1. Read nextreg 0x11 to find out the video timing the system is using 0-7
; 2. Take the associated actual system clock from this table:define(__CLK_28_0', 28000000)
; define(CLK_28_1', 28571429)
; define(`CLK_28_2', 29464286)
; define(__CLK_28_3', 30000000)
; define(CLK_28_4', 31000000)
; define(`CLK_28_5', 32000000)
; define(__CLK_28_6', 33000000)
; define(__CLK_28_7', 27000000)
; 3. Divide the clock by the baud rate you want to find the 14-bit prescalar value.
; That's it.
|
; A024174: a(n) is floor((4th elementary symmetric function of 1,2,..,n)/(3rd elementary symmetric function of 1,2,...,n)).
; 0,0,1,2,3,4,6,8,10,13,16,19,22,25,29,33,37,42,47,52,57,62,68,74,80,87,94,101,108,115,123,131,139,148,157,166,175,184,194,204,214,225,236,247,258,269,281,293,305,318,331,344,357,370,384,398,412,427,442,457,472,487,503,519,535,552,569,586,603,620,638,656,674,693,712,731,750,769,789,809,829,850,871,892,913,934,956,978,1000,1023,1046,1069,1092,1115,1139,1163,1187,1212,1237,1262,1287,1312,1338,1364,1390,1417,1444,1471,1498,1525,1553,1581,1609,1638,1667,1696,1725,1754,1784,1814,1844,1875,1906,1937,1968,1999,2031,2063,2095,2128,2161,2194,2227,2260,2294,2328,2362,2397,2432,2467,2502,2537,2573,2609,2645,2682,2719,2756,2793,2830,2868,2906,2944,2983,3022,3061,3100,3139,3179,3219,3259,3300,3341,3382,3423,3464,3506,3548,3590,3633,3676,3719,3762,3805,3849,3893,3937,3982,4027,4072,4117,4162,4208,4254,4300,4347,4394,4441,4488,4535,4583,4631,4679,4728,4777,4826,4875,4924,4974,5024,5074,5125,5176,5227,5278,5329,5381,5433,5485,5538,5591,5644,5697,5750,5804,5858,5912,5967,6022,6077,6132,6187,6243,6299,6355,6412,6469,6526,6583,6640,6698,6756,6814,6873,6932,6991,7050,7109,7169,7229,7289,7350,7411,7472,7533,7594,7656,7718,7780,7843
mov $3,$0
mov $0,9
add $3,1
mov $4,$3
pow $3,2
add $4,$3
lpb $0,1
mov $0,2
add $1,1
mov $2,8
sub $4,5
add $1,$4
lpe
div $1,$2
|
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <bitset>
#include <limits>
#include <numeric>
#include <iomanip>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
using namespace std;
typedef unsigned int ui;
typedef long long int ll;
typedef unsigned long long int ull;
#define $1 first
#define $2 second
#define pb push_back
#define INF 0x5A5B5C5D
#define INF2 0x77777777
#define INT_MAX 0x7FFFFFFF
#define UINT_MAX (ui)0xFFFFFFFF
#define LL_MAX (ll)0x7FFFFFFFFFFFFFFF
#define ULL_MAX (ull)0xFFFFFFFFFFFFFFFF
#define PI 3.1415926535897932
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define REP(i,n) for(ull i=0;i<(n);i++)
#define ALL(list) (list).begin(),(list).end()
#define PRESENT(list,x) (find(ALL(list),x)!=(list).end())
#define INPUT(cin_a) cin>>(cin_a)
#define INPUT2(cin_a,cin_b) cin>>(cin_a)>>(cin_b)
#define INPUT3(cin_a,cin_b,cin_c) cin>>(cin_a)>>(cin_b)>>(cin_c)
#define DINPUT(int_a) int (int_a);scanf("%d",&(int_a))
#define DINPUT2(int_a,int_b) int (int_a),(int_b);scanf("%d%d",&(int_a),&(int_b))
#define DINPUT3(int_a,int_b,int_c) int (int_a),(int_b),(int_c);scanf("%d%d%d",&(int_a),&(int_b),&(int_c))
#define TESTCASE(T) DINPUT(i_i__ai);for(int (T)=1;(T)<=i_i__ai;(T)++)
#define INIT(arr) memset((arr),0,sizeof(arr))
#define FILL(a,x) for(auto& acm_icpc:(a))acm_icpc=(x);
#define BETWEEN(x,low,high) ((x)>=(low)&&(x)<=(high))
#define ctoi(ch) ((ch)-'0')
#define countof(arr) (sizeof(arr)/sizeof((arr)[0]))
#define endl '\n'
#define PRINT(cout_x) cout<<(cout_x)<<endl
#define DEBUG(cout_x) cout<<">> "<<#cout_x<<" = "<<(cout_x)<<endl
#ifndef ONLINE_JUDGE
#define READTXT freopen(TXTPATH,"r",stdin)
#else
#define READTXT
#endif
#define TXTPATH "_input.txt"
inline ull GCD(ull a, ull b) { while (b != 0) { ull t = a % b; a = b; b = t; } return a; }
inline ull LCM(ull a, ull b) { return a * b / GCD(a, b); }
int main() {
READTXT;
double temp, temp2;
INPUT(temp);
while (cin >> temp2) {
if (temp2 == 999) break;
printf("%.2lf\n", temp2 - temp);
temp = temp2;
}
return 0;
} |
#include <iostream>
#include <seqan/file.h>
#include <seqan/modifier.h>
using namespace std;
using namespace seqan;
struct ConvertCT : public ::std::unary_function<Dna, Dna>
{
inline Dna operator()(Dna x) const
{
if (x == 'C') return 'T';
return x;
}
};
int main()
{
typedef String<Dna> TSequence;
TSequence seq1 = "CCCGGCATCATCC";
TSequence seq2 = "CTTGGCATTATTC";
std::cout << seq1 << std::endl;
std::cout << seq2 << std::endl;
std::cout << std::endl;
typedef ModifiedString< TSequence, ModView<ConvertCT> > TModCT;
TModCT modCT1(seq1);
TModCT modCT2(seq2);
std::cout << modCT1 << std::endl;
std::cout << modCT2 << std::endl;
return 0;
}
|
/* TEMPLATE GENERATED TESTCASE FILE
Filename: CWE127_Buffer_Underread__new_char_memmove_62b.cpp
Label Definition File: CWE127_Buffer_Underread__new.label.xml
Template File: sources-sink-62b.tmpl.cpp
*/
/*
* @description
* CWE: 127 Buffer Under-read
* BadSource: Set data pointer to before the allocated memory buffer
* GoodSource: Set data pointer to the allocated memory buffer
* Sinks: memmove
* BadSink : Copy data to string using memmove
* Flow Variant: 62 Data flow: data flows using a C++ reference from one function to another in different source files
*
* */
#include "std_testcase.h"
#include <wchar.h>
namespace CWE127_Buffer_Underread__new_char_memmove_62
{
#ifndef OMITBAD
void badSource(char * &data)
{
{
char * dataBuffer = new char[100];
memset(dataBuffer, 'A', 100-1);
dataBuffer[100-1] = '\0';
/* FLAW: Set data pointer to before the allocated memory buffer */
data = dataBuffer - 8;
}
}
#endif /* OMITBAD */
#ifndef OMITGOOD
/* goodG2B() uses the GoodSource with the BadSink */
void goodG2BSource(char * &data)
{
{
char * dataBuffer = new char[100];
memset(dataBuffer, 'A', 100-1);
dataBuffer[100-1] = '\0';
/* FIX: Set data pointer to the allocated memory buffer */
data = dataBuffer;
}
}
#endif /* OMITGOOD */
} /* close namespace */
|
;=======================================================================================================================
; ;
; Name: socOS (System On Chip Operation System) ;
; Year: 2020 ;
; License: MIT License ;
; ;
;=======================================================================================================================
; Require:
;.include "m8def.inc"
;.include "kernel/kernel_def.asm"
;.include "kernel/drivers/device_def.asm"
; Analog-Digital Convertor
; st_adc size
.equ SZ_ST_ADC = SZ_ST_DEVICE + 0x07
; st_adc:st_device
.equ ST_ADC_INPUT_NEGATIVE = SZ_ST_DEVICE + 0x00
.equ ST_ADC_INPUT_POSITIVE = SZ_ST_DEVICE + 0x01
.equ ST_ADC_FREQUENCY = SZ_ST_DEVICE + 0x02
.equ ST_ADC_OUTPUT_VALUE_ORDER = SZ_ST_DEVICE + 0x03
.equ ST_ADC_CONTINUOUS_MEASUREMENT = SZ_ST_DEVICE + 0x04
.equ ST_ADC_ON_COMPLETED_HANDLER_OFFSET = SZ_ST_DEVICE + 0x05
; enum ADC_INPUT_NEGATIVE(ADMUX: REFS1-REFS0)
.equ ADC_INPUT_NEGATIVE_AREF = 0x00 ; AREF pin (PIN24)
.equ ADC_INPUT_NEGATIVE_AVCC = 0x01 ; Vcc
;.equ ADC_INPUT_NEGATIVE_FORBIDDEN = 0x02 ;
.equ ADC_INPUT_NEGATIVE_REG_2_56V = 0x03 ; 2.56 V
; enum ADC_INPUT_POSITIVE (ADMUX: MUX3-MUX2-MUX1-MUX0)
.equ ADC_INPUT_POSITIVE_PINC0 = 0x00 ; DDRC as IN, PINC unpull-up;
.equ ADC_INPUT_POSITIVE_PINC1 = 0x01 ; DDRC as IN, PINC unpull-up
.equ ADC_INPUT_POSITIVE_PINC2 = 0x02 ; DDRC as IN, PINC unpull-up
.equ ADC_INPUT_POSITIVE_PINC3 = 0x03 ; DDRC as IN, PINC unpull-up
.equ ADC_INPUT_POSITIVE_PINC4 = 0x04 ; DDRC as IN, PINC unpull-up
.equ ADC_INPUT_POSITIVE_PINC5 = 0x05 ; DDRC as IN, PINC unpull-up
.equ ADC_INPUT_POSITIVE_PINC6 = 0x06 ; DDRC as IN, PINC unpull-up
.equ ADC_INPUT_POSITIVE_PINC7 = 0x07 ; DDRC as IN, PINC unpull-up
.equ ADC_INPUT_VREF_1_23V = 0x0E ; For calibration (to detect ADC error)
.equ ADC_INPUT_VREF_GND = 0x0F ; For calibration (to detect AFC error)
; enum ADC_FREQUENCY (ADCSRA: ADSP2-1-0)
.equ ADC_FREQUNCY_X1 = 0x00
.equ ADC_FREQUNCY_X2 = 0x01
.equ ADC_FREQUNCY_X4 = 0x02
.equ ADC_FREQUNCY_X8 = 0x03
.equ ADC_FREQUNCY_X16 = 0x04
.equ ADC_FREQUNCY_X32 = 0x05
.equ ADC_FREQUNCY_X64 = 0x06
.equ ADC_FREQUNCY_X128 = 0x07
; enum ADC_CONTINUOUS_MEASUREMENT (ADCSRA: ADFR)
.equ ADC_CONTINUOUS_MEASUREMENT_TRUE = TRUE
.equ ADC_CONTINUOUS_MEASUREMENT_FALSE = FALSE
; enum ADC_OUTPUT_VALUE_ORDER
.equ ADC_OUTPUT_VALUE_ORDER_LOW_FULL = 0x00
.equ ADC_OUTPUT_VALUE_ORDER_HIGH_FULL = 0x01
; enum ADC_CONVERSION_COMPLETED
.equ ADC_CONVERSION_COMPLETED_TRUE = TRUE
.equ ADC_CONVERSION_COMPLETED_FALSE = FALSE
;ADCSRA:
; ADEN - enable/disable
; ADFR - continuous measure
; ADSC - start convertion (single measure)
; ADIE - interrupt enable
;ADMUX
; ADLAR - if 0 then all low at ADCL, 2 high at ADCH. if 1 then all high at ADCH, 2 low at ADCL |
; A018910: Pisot sequence L(4,5).
; 4,5,7,10,15,23,36,57,91,146,235,379,612,989,1599,2586,4183,6767,10948,17713,28659,46370,75027,121395,196420,317813,514231,832042,1346271,2178311,3524580,5702889,9227467,14930354,24157819,39088171,63245988,102334157,165580143,267914298,433494439,701408735,1134903172,1836311905,2971215075,4807526978,7778742051,12586269027,20365011076,32951280101,53316291175,86267571274,139583862447,225851433719,365435296164,591286729881,956722026043,1548008755922,2504730781963,4052739537883,6557470319844,10610209857725,17167680177567,27777890035290,44945570212855,72723460248143,117669030460996,190392490709137,308061521170131,498454011879266,806515533049395,1304969544928659,2111485077978052,3416454622906709,5527939700884759,8944394323791466
mov $1,2
mov $2,1
lpb $0
sub $0,1
mov $3,$2
mov $2,$1
add $1,$3
lpe
add $1,2
|
;/*!
; @file
;
; @ingroup fapi
;
; @brief BksStringIn DOS wrapper
;
; (c) osFree Project 2018, <http://www.osFree.org>
; for licence see licence.txt in root directory, or project website
;
; This is Family API implementation for DOS, used with BIND tools
; to link required API
;
; @author Yuri Prokushev (yuri.prokushev@gmail.com)
;
;*/
.8086
; Helpers
INCLUDE helpers.inc
INCLUDE BSEERR.INC
INCL_KBD EQU 1
INCLUDE BSESUB.INC
_TEXT SEGMENT BYTE PUBLIC 'CODE' USE16
@BKSPROLOG BKSSTRINGIN
KBDHANDLE DW ?
IOWAIT DW ?
BLENGTH DD ?
CHARBUFFER DD ?
@BKSSTART BKSSTRINGIN
;buff db 26 ;MAX NUMBER OF CHARACTERS ALLOWED (25).
; db ? ;NUMBER OF CHARACTERS ENTERED BY USER.
; db 26 dup(0) ;CHARACTERS ENTERED BY USER.
; Prepare Buffer
;CAPTURE STRING FROM KEYBOARD.
; MOV AH, 0AH
; MOV DX, OFFSET BUFF
; INT 21H
@BKSEPILOG BKSSTRINGIN
_TEXT ENDS
END
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %r13
push %r15
push %r9
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x1c89c, %rsi
lea addresses_WC_ht+0x90cc, %rdi
clflush (%rdi)
nop
nop
nop
xor $45958, %r15
mov $15, %rcx
rep movsw
nop
add %rsi, %rsi
lea addresses_D_ht+0x198cc, %r9
clflush (%r9)
nop
add %rcx, %rcx
mov (%r9), %r12d
nop
sub $5208, %rdi
lea addresses_A_ht+0x1bf0b, %rsi
lea addresses_D_ht+0x1d94c, %rdi
nop
cmp $15149, %r13
mov $11, %rcx
rep movsq
nop
nop
nop
inc %r9
lea addresses_A_ht+0x384c, %rsi
lea addresses_WT_ht+0x170cc, %rdi
clflush (%rsi)
xor %r11, %r11
mov $92, %rcx
rep movsw
nop
nop
xor $49562, %r9
lea addresses_WT_ht+0xfb3c, %rsi
nop
nop
dec %r15
mov (%rsi), %r13d
nop
nop
nop
nop
nop
sub %rcx, %rcx
lea addresses_A_ht+0x14c, %rsi
nop
add $59131, %rcx
mov $0x6162636465666768, %r9
movq %r9, (%rsi)
nop
nop
nop
nop
xor $21164, %rcx
lea addresses_WT_ht+0x17bb4, %rsi
lea addresses_A_ht+0xa74c, %rdi
nop
nop
nop
nop
sub %r13, %r13
mov $58, %rcx
rep movsw
nop
nop
nop
nop
nop
cmp $49323, %r15
lea addresses_normal_ht+0x66cc, %r15
nop
nop
nop
xor $62679, %rsi
vmovups (%r15), %ymm7
vextracti128 $0, %ymm7, %xmm7
vpextrq $0, %xmm7, %rdi
dec %r15
lea addresses_WC_ht+0x12c6c, %rdi
nop
xor %r13, %r13
vmovups (%rdi), %ymm6
vextracti128 $0, %ymm6, %xmm6
vpextrq $0, %xmm6, %r9
nop
nop
nop
nop
nop
dec %rsi
pop %rsi
pop %rdi
pop %rcx
pop %r9
pop %r15
pop %r13
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r13
push %r9
push %rax
push %rbx
push %rcx
push %rdi
// Load
lea addresses_RW+0x172cc, %rax
nop
nop
sub %r10, %r10
mov (%rax), %di
nop
and %rcx, %rcx
// Store
lea addresses_RW+0x1f11, %rdi
nop
nop
nop
dec %r9
movb $0x51, (%rdi)
and %r10, %r10
// Store
lea addresses_RW+0x38cc, %r9
nop
nop
nop
sub $22469, %r13
mov $0x5152535455565758, %rbx
movq %rbx, %xmm0
movups %xmm0, (%r9)
cmp $57329, %rbx
// Faulty Load
lea addresses_RW+0x38cc, %rbx
nop
and %rax, %rax
mov (%rbx), %r10d
lea oracles, %rdi
and $0xff, %r10
shlq $12, %r10
mov (%rdi,%r10,1), %r10
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r9
pop %r13
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': True, 'same': True, 'congruent': 0, 'type': 'addresses_RW', 'AVXalign': False, 'size': 8}, 'OP': 'LOAD'}
{'src': {'NT': False, 'same': False, 'congruent': 5, 'type': 'addresses_RW', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_RW', 'AVXalign': False, 'size': 1}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_RW', 'AVXalign': False, 'size': 16}}
[Faulty Load]
{'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_RW', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'same': False, 'congruent': 4, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 11, 'type': 'addresses_WC_ht'}}
{'src': {'NT': False, 'same': False, 'congruent': 11, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 0, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'same': True, 'congruent': 5, 'type': 'addresses_D_ht'}}
{'src': {'same': True, 'congruent': 7, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 11, 'type': 'addresses_WT_ht'}}
{'src': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_WT_ht', 'AVXalign': True, 'size': 4}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': True, 'same': False, 'congruent': 7, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 8}}
{'src': {'same': False, 'congruent': 3, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 5, 'type': 'addresses_A_ht'}}
{'src': {'NT': False, 'same': False, 'congruent': 8, 'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'}
{'src': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'}
{'58': 21829}
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
*/
|
; A329502: G.f. = (1+x)*(1+2*x)/(1-x).
; 1,4,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6
mul $0,3
mov $1,$0
trn $1,5
sub $0,$1
add $0,1
|
;----[ ds3231rtc.asm ]------------------
;DS3231 RTC over i2c6502 for C64
;Copyright (c) 2020 Greg Nacu
*= $0801
.word end ;next line ptr
.word 64 ;basic line #64
.byte $9e ;sys
.null "2061" ;$080d
end .word $00 ;end of basic
doset = 0
i2cbase = $2000
init_ = 0
reset_ = 3
prep_rw_ = 6
readreg_ = 9
writreg_ = 12
ds3231addr = $68
dssecsreg = $00
chrout = $ffd2
;-----------------------
;--[ main ]-------------
;-----------------------
jsr i2cbase+init_
.ifne doset
beq settime
.endif
.ifeq doset
beq gettime
.endif
ldx #<errmsg_init
ldy #>errmsg_init
jmp msg_out
.ifne doset
settime ldx #<dss_secs
ldy #>dss_secs
lda #dss_size
jsr i2cbase+prep_rw_
lda #ds3231addr
ldy #dssecsreg
jsr i2cbase+writreg_
beq showsetmsg
ldx #<errmsg_sett
ldy #>errmsg_sett
jmp msg_out
showsetmsg
ldx #<msg_settime
ldy #>msg_settime
jmp msg_out
.endif
.ifeq doset
gettime ldx #<dss_secs
ldy #>dss_secs
lda #dss_size
jsr i2cbase+prep_rw_
lda #ds3231addr
ldy #dssecsreg
clc ;don't skip reg write
jsr i2cbase+readreg_
beq showtime
ldx #<errmsg_time
ldy #>errmsg_time
jmp msg_out
showtime
ldx #<msg_curt
ldy #>msg_curt
jsr msg_out
lda dss_date
jsr bcd_out
lda #"/"
jsr chrout
lda dss_mon
jsr bcd_out
lda #"/"
jsr chrout
lda dss_year
jsr bcd_out
lda #" "
jsr chrout
lda dss_hrs
jsr bcd_out
lda #":"
jsr chrout
lda dss_mins
jsr bcd_out
lda #":"
jsr chrout
lda dss_secs
jsr bcd_out
lda #" "
jsr chrout
ldx #<msg_wd
ldy #>msg_wd
jsr msg_out
lda dss_dow
jmp bcd_out
.endif
;-----------------------
;--[ print msgs ]-------
;-----------------------
bcd_out ;A -> number in bcd
pha
lsr a
lsr a
lsr a
lsr a
clc
adc #$30;convert to petscii
jsr chrout
pla
and #$0f
clc
adc #$30;convert to petscii
jmp chrout
msg_out
.block
;RegPtr -> message
stx $fb
sty $fc
ldy #0
loop lda ($fb),y
beq done
jsr chrout
iny
bne loop
done rts
.bend
msg_curt .null "current time: "
msg_wd .null "wd: "
msg_settime
.null "rtc time has been set"
errmsg_init
.null "failed to init i2c bus"
errmsg_time
.null "failed to get rtc time"
errmsg_sett
.null "failed to set rtc time"
;----------------------
;--[ data structure ]---
;-----------------------
;ds seconds register struct
.ifne doset
;Set values must be in BCD
dss_secs .byte $00
dss_mins .byte $01
dss_hrs .byte $02
dss_dow .byte $03
dss_date .byte $25
dss_mon .byte $06
dss_year .byte $81
.endif
.ifeq doset
dss_secs .byte 0
dss_mins .byte 0
dss_hrs .byte 0
dss_dow .byte 0
dss_date .byte 0
dss_mon .byte 0
dss_year .byte 0
.endif
dss_size = 7
|
; int ungetc(int c, FILE *stream)
INCLUDE "clib_cfg.asm"
SECTION code_clib
SECTION code_stdio
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IF __CLIB_OPT_MULTITHREAD & $02
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC _ungetc
EXTERN l0_ungetc_callee
_ungetc:
pop af
pop hl
pop bc
push bc
push hl
push af
jp l0_ungetc_callee
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ELSE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC _ungetc
EXTERN _ungetc_unlocked
defc _ungetc = _ungetc_unlocked
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ENDIF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
SECTION code_fp_math48
PUBLIC _ceil_fastcall
EXTERN cm48_sdcciy_ceil_fastcall
defc _ceil_fastcall = cm48_sdcciy_ceil_fastcall
|
; Substitute for 'sbc hl, sp' instruction
; CPU Min T Max T
; 8080 156 156
; 8085 154 154
; gbz80 232 232
; r2k 111 111
; z180 146 146
; z80 151 151
; z80n 151 151
SECTION code_crt0_sccz80
PUBLIC __z80asm__sub_hl_sp
__z80asm__sub_hl_sp:
push bc
ld b, a
push de
ex de, hl ; subtrahed to de
IF __CPU_GBZ80__
ld hl, sp+6 ; minuend to hl, compensate for return address, DE and BC in stack
ELSE
push af
ld hl, 8 ; minuend to hl, compensate for return address, DE, BC and AF in stack
add hl, sp
pop af
ENDIF
ld a, e
sub a, l
ld e, a
ld a, d
sbc a, h
ld d, a
ex de, hl
pop de
ld a, b
pop bc
ret
|
;
; >>> START OF FILE
;
; telephony
; (__TEXT, __text)
;
;
;
start:
; [ MODULE ENTRY POINT ]
;
+00000 00001b50 00009DE4 ldr r0,[sp]
+00004 00001b54 04108DE2 add r1,sp,#0x4
+00008 00001b58 014080E2 add r4,r0,#0x1
+0000c 00001b5c 042181E0 add r2,r1,r4,lsl #2
+00010 00001b60 07D0CDE3 bic sp,sp,#0x7
+00014 00001b64 0A0000EB bl _start
+00018 00001b68 700020E1 bkpt 0x0000
;
;
dyld_stub_binding_helper:
;
+00000 00001b6c 04C02DE5 str ip,[sp,#-0x4]!
+00004 00001b70 08C09FE5 ldr ip,[pc,#0x8] ; -> 0x1b80 _mh_execute_header
+00008 00001b74 04C02DE5 str ip,[sp,#-0x4]!
+0000c 00001b78 04C09FE5 ldr ip,[pc,#0x4] ; -> 0x1b84 dyld_content_lazy_binder
+00010 00001b7c 00F09CE4 ldr pc,[ip] ; call -> ?
+00014 00001b80 00100000
+00018 00001b84 04200000
;
;
_dyld_func_lookup:
;
; X-REFS:
;
; _start
;
+00000 00001b88 00C09FE5 ldr ip,[pc,#0x0] ; -> 0x1b90 dyld_func_lookup_pointer "\x08\x10\xe0\x8fl\x1b"
+00004 00001b8c 00F09CE4 ldr pc,[ip] ; call -> ?
+00008 00001b90 08200000
;
;
_start:
;
; X-REFS:
;
; start
;
+00000 00001b94 80402DE9 stmdb sp!,{r7,lr}
+00004 00001b98 0D70A0E1 mov r7,sp
+00008 00001b9c 1CD04DE2 sub sp,sp,#0x1c
+0000c 00001ba0 18008DE5 str r0,[sp,#0x18]
+00010 00001ba4 14108DE5 str r1,[sp,#0x14]
+00014 00001ba8 10208DE5 str r2,[sp,#0x10]
+00018 00001bac 30319FE5 ldr r3,[pc,#0x130] ; -> 0x1ce4 NXArgc
+0001c 00001bb0 18209DE5 ldr r2,[sp,#0x18]
+00020 00001bb4 002083E4 str r2,[r3]
+00024 00001bb8 28319FE5 ldr r3,[pc,#0x128] ; -> 0x1ce8 NXArgv
+00028 00001bbc 14209DE5 ldr r2,[sp,#0x14]
+0002c 00001bc0 002083E4 str r2,[r3]
+00030 00001bc4 20319FE5 ldr r3,[pc,#0x120] ; -> 0x1cec environ
+00034 00001bc8 10209DE5 ldr r2,[sp,#0x10]
+00038 00001bcc 002083E4 str r2,[r3]
+0003c 00001bd0 14309DE5 ldr r3,[sp,#0x14]
+00040 00001bd4 003093E4 ldr r3,[r3]
+00044 00001bd8 000053E3 cmp r3,#0x0
+00048 00001bdc 3B00001A bne loc_00013c
+0004c 00001be0 08319FE5 ldr r3,[pc,#0x108] ; -> 0x1cf0 .str
+00050 00001be4 0C308DE5 str r3,[sp,#0xc]
+00054 00001be8 0C309DE5 loc_000054: ldr r3,[sp,#0xc] ; .str
+00058 00001bec 00219FE5 ldr r2,[pc,#0x100] ; -> 0x1cf4 __progname
+0005c 00001bf0 003082E4 str r3,[r2]
+00060 00001bf4 10309DE5 ldr r3,[sp,#0x10]
+00064 00001bf8 08308DE5 str r3,[sp,#0x8]
+00068 00001bfc 020000EA b loc_000078
+0006c 00001c00 08309DE5 loc_00006c: ldr r3,[sp,#0x8]
+00070 00001c04 043083E2 add r3,r3,#0x4
+00074 00001c08 08308DE5 str r3,[sp,#0x8]
+00078 00001c0c 08309DE5 loc_000078: ldr r3,[sp,#0x8]
+0007c 00001c10 003093E4 ldr r3,[r3]
+00080 00001c14 000053E3 cmp r3,#0x0
+00084 00001c18 F8FFFF1A bne loc_00006c
+00088 00001c1c 08309DE5 ldr r3,[sp,#0x8]
+0008c 00001c20 043083E2 add r3,r3,#0x4
+00090 00001c24 08308DE5 str r3,[sp,#0x8]
+00094 00001c28 C8309FE5 ldr r3,[pc,#0xc8] ; -> 0x1cf8 mach_init_routine
+00098 00001c2c 003093E4 ldr r3,[r3]
+0009c 00001c30 003093E4 ldr r3,[r3]
+000a0 00001c34 000053E3 cmp r3,#0x0
+000a4 00001c38 0300000A beq loc_0000b8
+000a8 00001c3c B4309FE5 ldr r3,[pc,#0xb4] ; -> 0x1cf8 mach_init_routine
+000ac 00001c40 003093E4 ldr r3,[r3]
+000b0 00001c44 003093E4 ldr r3,[r3]
+000b4 00001c48 33FF2FE1 blx r3 ; call -> ?
+000b8 00001c4c A8309FE5 loc_0000b8: ldr r3,[pc,#0xa8] ; -> 0x1cfc _cthread_init_routine
+000bc 00001c50 003093E4 ldr r3,[r3]
+000c0 00001c54 003093E4 ldr r3,[r3]
+000c4 00001c58 000053E3 cmp r3,#0x0
+000c8 00001c5c 0300000A beq loc_0000dc
+000cc 00001c60 94309FE5 ldr r3,[pc,#0x94] ; -> 0x1cfc _cthread_init_routine
+000d0 00001c64 003093E4 ldr r3,[r3]
+000d4 00001c68 003093E4 ldr r3,[r3]
+000d8 00001c6c 33FF2FE1 blx r3 ; call -> ?
+000dc 00001c70 C40000EB loc_0000dc: bl __keymgr_dwarf2_register_sections (stub)
+000e0 00001c74 0D10A0E1 mov r1,sp
+000e4 00001c78 80009FE5 ldr r0,[pc,#0x80] ; -> 0x1d00 .str1 "__dyld_make_delayed_module_initializer_calls"
+000e8 00001c7c C1FFFFEB bl _dyld_func_lookup
+000ec 00001c80 00309DE4 ldr r3,[sp]
+000f0 00001c84 33FF2FE1 blx r3 ; call -> ?
+000f4 00001c88 04108DE2 add r1,sp,#0x4
+000f8 00001c8c 70009FE5 ldr r0,[pc,#0x70] ; -> 0x1d04 .str2 "__dyld_mod_term_funcs"
+000fc 00001c90 BCFFFFEB bl _dyld_func_lookup
+00100 00001c94 04309DE5 ldr r3,[sp,#0x4]
+00104 00001c98 000053E3 cmp r3,#0x0
+00108 00001c9c 0100000A beq loc_000114
+0010c 00001ca0 04009DE5 ldr r0,[sp,#0x4]
+00110 00001ca4 BA0000EB bl atexit (stub)
+00114 00001ca8 58309FE5 loc_000114: ldr r3,[pc,#0x58] ; -> 0x1d08 errno
+00118 00001cac 003093E4 ldr r3,[r3]
+0011c 00001cb0 0020A0E3 mov r2,#0x0
+00120 00001cb4 002083E4 str r2,[r3]
+00124 00001cb8 08309DE5 ldr r3,[sp,#0x8]
+00128 00001cbc 14109DE5 ldr r1,[sp,#0x14]
+0012c 00001cc0 10209DE5 ldr r2,[sp,#0x10]
+00130 00001cc4 18009DE5 ldr r0,[sp,#0x18]
+00134 00001cc8 4E0000EB bl main
+00138 00001ccc B30000EB bl exit (stub)
+0013c 00001cd0 14309DE5 loc_00013c: ldr r3,[sp,#0x14]
+00140 00001cd4 000093E4 ldr r0,[r3]
+00144 00001cd8 0B0000EB bl crt_basename
+00148 00001cdc 0C008DE5 str r0,[sp,#0xc]
+0014c 00001ce0 C0FFFFEA b loc_000054
+00150 00001ce4 00300000
+00154 00001ce8 04300000
+00158 00001cec 08300000
+0015c 00001cf0 3C200000
+00160 00001cf4 0C300000
+00164 00001cf8 34200000
+00168 00001cfc 2C200000
+0016c 00001d00 101F0000
+00170 00001d04 3D1F0000
+00174 00001d08 30200000
;
;
crt_basename:
;
; X-REFS:
;
; _start
;
+00000 00001d0c 14D04DE2 sub sp,sp,#0x14
+00004 00001d10 10008DE5 str r0,[sp,#0x10]
+00008 00001d14 00008DE4 str r0,[sp]
+0000c 00001d18 10309DE5 ldr r3,[sp,#0x10]
+00010 00001d1c 04308DE5 str r3,[sp,#0x4]
+00014 00001d20 090000EA b loc_000040
+00018 00001d24 04309DE5 loc_000018: ldr r3,[sp,#0x4]
+0001c 00001d28 0030D3E4 ldrb r3,[r3]
+00020 00001d2c 2F0053E3 cmp r3,#0x2f
+00024 00001d30 0200001A bne loc_000034
+00028 00001d34 04309DE5 ldr r3,[sp,#0x4]
+0002c 00001d38 013083E2 add r3,r3,#0x1
+00030 00001d3c 00308DE4 str r3,[sp]
+00034 00001d40 04309DE5 loc_000034: ldr r3,[sp,#0x4]
+00038 00001d44 013083E2 add r3,r3,#0x1
+0003c 00001d48 04308DE5 str r3,[sp,#0x4]
+00040 00001d4c 04309DE5 loc_000040: ldr r3,[sp,#0x4]
+00044 00001d50 0030D3E4 ldrb r3,[r3]
+00048 00001d54 000053E3 cmp r3,#0x0
+0004c 00001d58 F1FFFF1A bne loc_000018
+00050 00001d5c 00309DE4 ldr r3,[sp]
+00054 00001d60 08308DE5 str r3,[sp,#0x8]
+00058 00001d64 0C308DE5 str r3,[sp,#0xc]
+0005c 00001d68 0C009DE5 ldr r0,[sp,#0xc]
+00060 00001d6c 14D08DE2 add sp,sp,#0x14
+00064 00001d70 1EFF2FE1 bx lr ; return
;
;
DumpInt:
; [ EXTERNAL ]
;
+00000 00001d74 08D04DE2 sub sp,sp,#0x8
+00004 00001d78 04E08DE5 str lr,[sp,#0x4]
+00008 00001d7c 00708DE4 str r7,[sp]
+0000c 00001d80 0D70A0E1 mov r7,sp
+00010 00001d84 08D04DE2 sub sp,sp,#0x8
+00014 00001d88 0010A0E1 mov r1,r0
+00018 00001d8c 041007E5 str r1,[r7,#-0x4]
+0001c 00001d90 2C309FE5 ldr r3,[pc,#0x2c] ; -> 0x1dc4
+00020 00001d94 081007E5 str r1,[r7,#-0x8]
+00024 00001d98 03008FE0 add r0,pc,r3 ; .str "int = %d\n"
+00028 00001d9c 8A0000EB bl printf (stub)
+0002c 00001da0 081017E5 ldr r1,[r7,#-0x8]
+00030 00001da4 1C309FE5 ldr r3,[pc,#0x1c] ; -> 0x1dc8
+00034 00001da8 03008FE0 add r0,pc,r3 ; .str1 " = 0x%08x\n"
+00038 00001dac 860000EB bl printf (stub)
+0003c 00001db0 07D0A0E1 mov sp,r7
+00040 00001db4 00709DE4 ldr r7,[sp]
+00044 00001db8 04E09DE5 ldr lr,[sp,#0x4]
+00048 00001dbc 08D08DE2 add sp,sp,#0x8
+0004c 00001dc0 1EFF2FE1 bx lr ; return
+00050 00001dc4 B3010000
+00054 00001dc8 AD010000
;
;
CreateCallback:
; [ EXTERNAL ]
;
+00000 00001dcc 08D04DE2 sub sp,sp,#0x8
+00004 00001dd0 04E08DE5 str lr,[sp,#0x4]
+00008 00001dd4 00708DE4 str r7,[sp]
+0000c 00001dd8 0D70A0E1 mov r7,sp
+00010 00001ddc 04D04DE2 sub sp,sp,#0x4
+00014 00001de0 1C309FE5 ldr r3,[pc,#0x1c] ; -> 0x1e04
+00018 00001de4 040007E5 str r0,[r7,#-0x4]
+0001c 00001de8 03008FE0 add r0,pc,r3 ; .str2 "Foo! called"
+00020 00001dec 7E0000EB bl puts (stub)
+00024 00001df0 07D0A0E1 mov sp,r7
+00028 00001df4 00709DE4 ldr r7,[sp]
+0002c 00001df8 04E09DE5 ldr lr,[sp,#0x4]
+00030 00001dfc 08D08DE2 add sp,sp,#0x8
+00034 00001e00 1EFF2FE1 bx lr ; return
+00038 00001e04 7B010000
;
;
main:
; [ EXTERNAL ]
;
; X-REFS:
;
; _start
;
+00000 00001e08 14D04DE2 sub sp,sp,#0x14
+00004 00001e0c 10E08DE5 str lr,[sp,#0x10]
+00008 00001e10 0C708DE5 str r7,[sp,#0xc]
+0000c 00001e14 08608DE5 str r6,[sp,#0x8]
+00010 00001e18 04508DE5 str r5,[sp,#0x4]
+00014 00001e1c 00408DE4 str r4,[sp]
+00018 00001e20 0C708DE2 add r7,sp,#0xc
+0001c 00001e24 43DF4DE2 sub sp,sp,#0x10c
+00020 00001e28 C8309FE5 ldr r3,[pc,#0xc8] ; -> 0x1ef8
+00024 00001e2c 03008FE0 add r0,pc,r3 ; .str3 "Create"
+00028 00001e30 6D0000EB bl puts (stub)
+0002c 00001e34 FF20A0E3 mov r2,#0xff
+00030 00001e38 0040A0E3 mov r4,#0x0
+00034 00001e3c 115E47E2 sub r5,r7,#0x110
+00038 00001e40 B4609FE5 ldr r6,[pc,#0xb4] ; -> 0x1efc
+0003c 00001e44 0500A0E1 mov r0,r5
+00040 00001e48 0410A0E1 mov r1,r4
+00044 00001e4c 5A0000EB bl memset (stub)
+00048 00001e50 06309FE7 ldr r3,[pc,r6] ; -> kCFAllocatorDefault
+0004c 00001e54 A4209FE5 ldr r2,[pc,#0xa4] ; -> 0x1f00
+00050 00001e58 000093E4 ldr r0,[r3]
+00054 00001e5c 02108FE0 add r1,pc,r2 ; CreateCallback
+00058 00001e60 0520A0E1 mov r2,r5
+0005c 00001e64 500000EB bl _CTServerConnectionCreate (stub)
+00060 00001e68 140107E5 str r0,[r7,#-0x114]
+00064 00001e6c 184107E5 str r4,[r7,#-0x118]
+00068 00001e70 080000EA b loc_000090
+0006c 00001e74 183117E5 loc_00006c: ldr r3,[r7,#-0x118]
+00070 00001e78 112E47E2 sub r2,r7,#0x110
+00074 00001e7c D31092E1 ldrsb r1,[r2,r3]
+00078 00001e80 7C309FE5 ldr r3,[pc,#0x7c] ; -> 0x1f04
+0007c 00001e84 03008FE0 add r0,pc,r3 ; .str4 " %x "
+00080 00001e88 4F0000EB bl printf (stub)
+00084 00001e8c 183117E5 ldr r3,[r7,#-0x118]
+00088 00001e90 013083E2 add r3,r3,#0x1
+0008c 00001e94 183107E5 str r3,[r7,#-0x118]
+00090 00001e98 183117E5 loc_000090: ldr r3,[r7,#-0x118]
+00094 00001e9c FF0053E3 cmp r3,#0xff
+00098 00001ea0 F3FFFFBA blt loc_00006c
+0009c 00001ea4 0A00A0E3 mov r0,#0xa
+000a0 00001ea8 4B0000EB bl putchar (stub)
+000a4 00001eac 143117E5 ldr r3,[r7,#-0x114]
+000a8 00001eb0 000053E3 cmp r3,#0x0
+000ac 00001eb4 0300000A beq loc_0000c0
+000b0 00001eb8 48309FE5 ldr r3,[pc,#0x48] ; -> 0x1f08
+000b4 00001ebc 03008FE0 add r0,pc,r3 ; .str5 "z"
+000b8 00001ec0 490000EB bl puts (stub)
+000bc 00001ec4 020000EA b loc_0000cc
+000c0 00001ec8 3C309FE5 loc_0000c0: ldr r3,[pc,#0x3c] ; -> 0x1f0c
+000c4 00001ecc 03008FE0 add r0,pc,r3 ; .str6 "nz"
+000c8 00001ed0 450000EB bl puts (stub)
+000cc 00001ed4 100017E5 loc_0000cc: ldr r0,[r7,#-0x10]
+000d0 00001ed8 0CD047E2 sub sp,r7,#0xc
+000d4 00001edc 00409DE4 ldr r4,[sp]
+000d8 00001ee0 04509DE5 ldr r5,[sp,#0x4]
+000dc 00001ee4 08609DE5 ldr r6,[sp,#0x8]
+000e0 00001ee8 0C709DE5 ldr r7,[sp,#0xc]
+000e4 00001eec 10E09DE5 ldr lr,[sp,#0x10]
+000e8 00001ef0 14D08DE2 add sp,sp,#0x14
+000ec 00001ef4 1EFF2FE1 bx lr ; return
+000f0 00001ef8 43010000
+000f4 00001efc E0010000
+000f8 00001f00 68FFFFFF
+000fc 00001f04 F2000000
+00100 00001f08 BF000000
+00104 00001f0c B1000000
;
;
; STUBS X-REFS:
;
; _CTServerConnectionCreate (fe000000) -> CoreTelephony
; _CTServerConnectionCreate (00001fac) -> CoreTelephony
; main
; __keymgr_dwarf2_register_sections (00001f88) -> libSystem.B.dylib
; _start
; __keymgr_dwarf2_register_sections (fe000008) -> libSystem.B.dylib
; _cthread_init_routine (fe000010) -> libSystem.B.dylib
; atexit (fe000018) -> libSystem.B.dylib
; atexit (00001f94) -> libSystem.B.dylib
; _start
; errno (fe000020) -> libSystem.B.dylib
; exit (00001fa0) -> libSystem.B.dylib
; _start
; exit (fe000028) -> libSystem.B.dylib
; kCFAllocatorDefault (fe000030) -> CoreFoundation
; mach_init_routine (fe000038) -> libSystem.B.dylib
; memset (fe000040) -> libSystem.B.dylib
; memset (00001fbc) -> libSystem.B.dylib
; main
; printf (fe000048) -> libSystem.B.dylib
; printf (00001fcc) -> libSystem.B.dylib
; DumpInt
; main
; putchar (fe000050) -> libSystem.B.dylib
; putchar (00001fdc) -> libSystem.B.dylib
; main
; puts (fe000058) -> libSystem.B.dylib
; puts (00001fec) -> libSystem.B.dylib
; CreateCallback
; main
;
; >>> END OF FILE
;
|
; ************************************************************************* ;
; Organizacion del Computador II ;
; ;
; Implementacion de la funcion HSL 2 ;
; ;
; ************************************************************************* ;
extern malloc
extern free
%define PIXEL_SIZE 4h
%define OFFSET_A 0h
%define OFFSET_R 1h
%define OFFSET_G 2h
%define OFFSET_B 3h
lemask: dd 0.0, 360.0, 1.0, 1.0 ; 1 | 1 | 360 | 0
absmask: dd 0x7FFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,0xFFFFFFFF
shuf: db 0x00,0x04,0x08,0x0C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
divS: dd 255.0001, 0.0, 0.0, 0.0 ; 0 | 0 | 0 | 255.0001
divL: dd 510.0, 0.0, 0.0, 0.0
one: dd 1.0 , 0.0, 0.0, 0.0
cEscala: dd 0.0 , 255.0, 255.0, 255.0
cRGB: dd 120.0, 0.0, 0.0, 0.0
cmod2: dd 2.0, 0.0, 0.0, 0.0
c060: dd 60.0, 0.0, 0.0, 0.0
; void ASM_hsl2(uint32_t w, uint32_t h, uint8_t* data, float hh, float ss, float ll)
global ASM_hsl2
ASM_hsl2:
push rbp
mov rbp, rsp
push rbx
push r12
push r13
push r14
push r15
sub rbp, 8
mov edi, edi ;limpio parte alta
mov esi, esi
xor r15, r15
movq xmm8, xmm2 ;xmm8 = ll
pslldq xmm8, 4 ;xmm8 = 0 | 0 | ll | 0
addps xmm8, xmm1 ;xmm8 = 0 | 0 | ll | ss
pslldq xmm8, 4 ;xmm8 = 0 | ll | ss | 0
addps xmm8, xmm0 ;xmm8 = 0 | ll | ss | hh
pslldq xmm8, 4 ;xmm8 = ll | ss | hh | 0
movdqu xmm9, [lemask] ;xmm9 = 1 | 1 | 360 | 0
movdqu xmm6, xmm9 ;xmm6 = 1 | 1 | 360 | 0
movdqu xmm7, xmm6
pslldq xmm7, 8 ;xmm7 = 360 | 0 | 0 | 0
psrldq xmm7, 8 ;xmm7 = 0 | 0 | 360 | 0
psubd xmm6, xmm7 ;xmm6 = 1 | 1 | 0 | 0
mov rbx, rdi ;rbx = w
mov r12, rsi ;r12 = h
mov r13, rdx ;r13 = data
mov rax, r12 ;rax = h
mul rbx ;rax = w * h
mov r9, 4
mul r9
mov r14, rax ;r14 = w * h * 4
mov rdi, 16d
call malloc
mov r12, rax ;r12 = *dst
.ciclo:
mov rsi, r12
lea rdi, [r13 + r15]
call rgbTOhsl3 ;rsi = pixel en hsl ;pixel en registro = l s h a
;call rgbTOhsl
movdqu xmm11, [r12] ;xmm11 = l | s | h | a
;el ultimo "else" se toma como implicito y se buscan las modificaciones hacia los otros casos de ser necesarias,
;primer if
pxor xmm5 , xmm5
pxor xmm15, xmm15
addps xmm11, xmm8 ;xmm11 = l+ll | s+ss | h+hh | a
movdqu xmm4, xmm11 ;xmm4 = l+ll | s+ss | h+hh | a
movdqu xmm13, xmm9 ;xmm13 = 1 | 1 | 360 | 0
cmpleps xmm13, xmm11 ;xmm13 = 1 <= l+ll | 1 <= s+ss | 360 <= h+hh | 0
;h+hh >= 360
movdqu xmm5, xmm13 ;xmm5 = 1 <= l+ll | 1 <= s+ss | 360 <= h+hh | 0
pand xmm5, xmm7 ;xmm7 = 0 | 0 | 360 o 0 | 0
subps xmm11, xmm5 ;xmm11 = l+ll | s+ss | h+hh o h+hh-360| 0
;s+ss >= 1 | l+ll >= 1
movdqu xmm5, xmm4 ;xmm5 = l+ll | s+ss | h+hh | 0
subps xmm5, xmm6 ;xmm5 = l+ll-1 | s+ss-1 | h+hh | 0
pand xmm5, xmm13 ;xmm5 = l+ll-1 o 0 | s+ss-1 o 0 | h+hh o 0 | 0
psrldq xmm5, 8 ;xmm5 = | 0 | 0 | l+ll-1 o 0 | s+ss+1 o 0
pslldq xmm5, 8 ;xmm5 = l+ll-1 o 0 | s+ss-1 o 0 | 0 | 0 |
subps xmm11, xmm5 ;xmm11 = l+ll o 1 | s+ss o 1 | h+hh o h+hh-360 | 0
;segundo if
movdqu xmm14, xmm4 ;xmm14 = l+ll | s+ss | h+hh | 0
cmpltps xmm14, xmm15 ;xmm14 = l+ll < 0 | s+ss < 0 | h+hh < 0 | 0
;h+hh < 360
movdqu xmm5, xmm14 ;xmm5 = l+ll < 0 | s+ss < 0 | h+hh < 0 | 0
pand xmm5, xmm7 ;xmm5 = 0 | 0 | 360 o 0 | 0
addps xmm11, xmm5 ;xmm11 = l+ll o 1 | s+ss o 1 | h+hh o h+hh-360 o h+hh+360| 0
;s+ss < 0 | l+ll < 0
movdqu xmm5, xmm4 ;xmm5 = l+ll | s+ss | h+hh | 0
pand xmm5, xmm14 ;xmm5 = l+ll o 0 | s+ss o 0 | h+hh o 0 | 0 |
psrldq xmm5, 8 ;xmm5 = | 0 | 0 | l+ll o 0 | s+ss o 0
pslldq xmm5, 8 ;xmm5 = l+ll o 0 | s+ss o 0 | 0 | 0 |
subps xmm11, xmm5 ;xmm11 = l+ll o 1 o 0 | s+ss o 1 o 0 | h+hh o h+hh-360 o h+hh+360 | 0
movdqu [r12], xmm11
mov rdi, r12
lea rsi, [r13 + r15]
call hslTOrgb3
add r15, PIXEL_SIZE
cmp r15, r14
jl .ciclo
add rbp, 8
pop r15
pop r14
pop r13
pop r12
pop rbx
pop rbp
ret
rgbTOhsl3:
push rbp
mov rbp, rsp
push rbx
push r12
push r13
push r14
push r15
sub rbp, 8
xor r14, r14
xor r15, r15
xor rcx, rcx
xor rbx, rbx
xor rax, rax
xor rdx, rdx
mov r12, rdi ;r12 = *dato
mov r13, rsi ;r13 = *dst
mov eax, [r12] ;rax = r-g-b-a
mov r8 , rax ;r8 = r-g-b-a
;repartimos valores
mov dl, al ;rdx = a
shrd rax, r14, 8 ;rbx = r-g-b
mov bl, al ;rbx = b
shrd rax, r14, 8 ;rax = r-g
mov cl, al ;rcx = g
shrd rax, r14, 8 ;rax = r
.calcMax:
mov r15, rbx ;r15 = b (max actual)
cmp r15, rcx ;maxactual < g
jl .maxg
.max2:
cmp r15, rax ;maxactual < r
jl .maxr
jge .calcMin
.maxg:
mov r15, rcx ;maxactual = g
jmp .max2
.maxr:
mov r15, rax ;maxactual = r
jmp .calcMin
.calcMin:
mov r14, rbx ;r14 = b (min actual)
cmp r14, rcx ;minactual > g
jg .ming
.min2:
cmp r14, rax ;minactual > r
jg .minr
jle .calcD
.ming:
mov r14, rcx ;minactual = g
jmp .min2
.minr:
mov r14, rax ;minactual = r
jmp .calcD
.calcD:
xor r8, r8
xor r9, r9
mov r8, rax ;r8 = r
mov r9, rbx ;r9 = b
mov r10, rcx ;r10 = g
mov rcx, r14 ;rcx = minimo
mov rbx, r15 ;rbx = maximo
sub r15, r14 ;r15 = maximo - minimo
.calcH:
xor r11 , r11
pxor xmm0, xmm0
pxor xmm1, xmm1
pxor xmm2, xmm2
pxor xmm4, xmm4
cmp r15, 0 ;if(max == min)
je .Hcaso0
cmp rbx, r8 ;if(max == r)
je .Hcaso1
cmp rbx, r10 ;if(max == g)
je .Hcaso2
cmp rbx, r9 ;if(max == b)
je .Hcaso3
jmp .calcL
.Hcaso0:
xorps xmm0, xmm0
jmp .calcL
.Hcaso1:
movq xmm0, r10 ;xmm0 = g
movq xmm1, r9 ;xmm1 = b
movq xmm2, r15 ;xmm2 = d
mov r11 , 60
movq xmm3, r11 ;xmm3 = 60
mov r11 , 6
movq xmm4, r11 ;xmm4 = 6
cvtdq2ps xmm0, xmm0 ;xmm0 = (float) g
cvtdq2ps xmm1, xmm1 ;xmm0 = (float) b
cvtdq2ps xmm2, xmm2 ;xmm2 = (float) d
cvtdq2ps xmm3, xmm3 ;xmm3 = (float) 60
cvtdq2ps xmm4, xmm4 ;xmm4 = (float) 6
jmp .Hoperar
.Hcaso2:
movq xmm0, r9 ;xmm0 = b
movq xmm1, r8 ;xmm1 = r
movq xmm2, r15 ;xmm2 = d
mov r11 , 60
movq xmm3, r11 ;xmm3 = 60
mov r11 , 2
movq xmm4, r11 ;xmm4 = 2
cvtdq2ps xmm0, xmm0 ;xmm0 = (float) b
cvtdq2ps xmm1, xmm1 ;xmm1 = (float) r
cvtdq2ps xmm2, xmm2 ;xmm2 = (float) d
cvtdq2ps xmm3, xmm3 ;xmm3 = (float) 60
cvtdq2ps xmm4, xmm4 ;xmm4 = (float) 2
jmp .Hoperar
.Hcaso3:
movq xmm0, r8 ;xmm0 = r
movq xmm1, r10 ;xmm1 = g
movq xmm2, r15 ;xmm2 = d
mov r11 , 60
movq xmm3, r11 ;xmm3 = 60
mov r11 , 4
movq xmm4, r11 ;xmm4 = 4
cvtdq2ps xmm0, xmm0 ;xmm0 = (float) r
cvtdq2ps xmm1, xmm1 ;xmm0 = (float) g
cvtdq2ps xmm2, xmm2 ;xmm2 = (float) d
cvtdq2ps xmm3, xmm3 ;xmm3 = (float) 60
cvtdq2ps xmm4, xmm4 ;xmm4 = (float) 4
jmp .Hoperar
.Hoperar: ;(los comentarios de esta funcion son un mero ejemplo del caso 3, es analogo para los otros 2)
subps xmm0, xmm1 ;xmm0 = g-b
divps xmm0, xmm2 ;xmm0 = (g-b)/d
addps xmm0, xmm4 ;xmm0 = ((d-b)/d) + 4
mulps xmm0, xmm3 ;xmm0 = 60 * ( (d-b)/d + 4 )
;ultimo if
mov r8, 360
pxor xmm1, xmm1
pxor xmm2, xmm2
movq xmm1, r8 ;xmm1 = 360
cvtdq2ps xmm1, xmm1
movdqu xmm2, xmm1 ;xmm2 = 360
cmpleps xmm1, xmm0 ;xmm1 = 360 <= h
pand xmm2, xmm1 ;xmm2 = 360 o 0
subps xmm0, xmm2 ;xmm0 = h o h-360
pslldq xmm0, 12
psrldq xmm0, 12
jmp .calcL
.calcL:
pxor xmm1, xmm1
pxor xmm2, xmm2
mov r8, rbx ;r8 = max
add r8, r14 ;r8 = max + min
movq xmm1, r8 ;xmm1 = max + min
cvtdq2ps xmm1, xmm1
divps xmm1, [divL] ;xmm1 = ( max + min ) / 510
pslldq xmm1, 12
psrldq xmm1, 12
.calcS:
pxor xmm2, xmm2 ;xmm2 = 0
pxor xmm11, xmm11 ;xmm11 = 0
cmp rbx, r14
je .terminar
;else
movq xmm2, r15 ;xmm2 = d
cvtdq2ps xmm2, xmm2
mov r8, 1
movq xmm4, r8
cvtdq2ps xmm4, xmm4 ;xmm4 = 1.0
movdqu xmm3, xmm4 ;xmm3 = 1.0
addps xmm3, xmm3 ;xmm3 = 2.0
mulps xmm3, xmm1 ;xmm3 = 2*l
subps xmm3, xmm4 ;xmm3 = 2*l - 1
movdqu xmm12, [absmask]
pand xmm3, xmm12 ; abs(2*l - 1)
subps xmm4, xmm3 ;xmm4 = 1 - abs( 2*l - 1 )
divps xmm2, xmm4 ;xmm4 = d / ( 1 - fabs( 2*l - 1 ) )
divps xmm2, [divS] ;xmm2 = d / ( 1 - fabs( 2*l - 1 ) ) / 255.0001
pslldq xmm2, 12
psrldq xmm2, 12
.terminar:
movq xmm10, rdx
cvtdq2ps xmm10, xmm10
punpckldq xmm0, xmm1 ;xmm1 = 0 | 0 | l | h
punpckldq xmm10, xmm2 ;xmm2 = 0 | 0 | s | a
punpckldq xmm10, xmm0 ;xmm10 = l | s | h | a
movdqu [r13], xmm10
add rbp, 8
pop r15
pop r14
pop r13
pop r12
pop rbx
pop rbp
ret
hslTOrgb3: ; rdi = float *src rsi = uint8_t *dst
push rbp
mov rbp, rsp
push rbx
push r12
push r13
push r14
push r15
sub rbp, 8
mov r12, rdi ; r12 = *src
mov r13, rsi ; r13 = *dst
;separacion de elementos
pxor xmm1, xmm1
pxor xmm2, xmm2
movdqu xmm0, [r12] ;xmm0 = l | s | h | a
punpckldq xmm2, xmm0 ;xmm2 = h | 0 | a | 0
punpckhdq xmm1, xmm0 ;xmm1 = l | 0 | s | 0
;l
psrldq xmm0, 12 ;xmm0 = 0 | 0 | 0 | l
;s
pslldq xmm1, 4 ;xmm1 = 0 | s | 0 | 0
psrldq xmm1, 8 ;xmm1 = 0 | 0 | 0 | s
;h
movdqu xmm3, xmm2 ;xmm3 = h | 0 | a | 0
psrldq xmm2, 12 ;xmm2 = 0 | 0 | 0 | h
;a
pslldq xmm3, 4 ;xmm3 = 0 | a | 0 | 0
psrldq xmm3, 8 ;xmm3 = 0 | 0 | 0 | a
;Cálculo de c, x y m
.calcC:
movdqu xmm15, [one] ;xmm15 = 1
movdqu xmm4 , xmm15 ;xmm4 = 1
movdqu xmm5 , xmm4 ;xmm5 = 1
movdqu xmm10, xmm4 ;xmm5 = 1
addss xmm5, xmm5 ;xmm5 = 2
mulss xmm5, xmm0 ;xmm5 = 2*l
subss xmm5, xmm4 ;xmm5 = 2*l - 1
movdqu xmm11, [absmask] ;xmm11 = 0 yo todos 1s
pand xmm5 , xmm11 ;xmm5 = abs(2*l - 1)
subss xmm4, xmm5 ;xmm4 = 1 - abs(2*l - 1)
mulss xmm4, xmm1 ;xmm4 = ( 1 - abs(2*l - 1) ) * s
.calcX:
mov r8, 60
movq xmm10, r8
cvtdq2ps xmm10, xmm10 ;xmm10 = 60
movdqu xmm11, xmm2 ;xmm11 = h
divss xmm11, xmm10 ;xmm11 = h/60
movdqu xmm5 , xmm15 ;xmm5 = 1
movdqu xmm13, xmm5 ;xmm13 = 1
movdqu xmm12, [cmod2];xmm12 = 2.0
comiss xmm11, xmm12
jb .finloop
.modresta:
subss xmm11, xmm12 ;xmm11 = xmm11 - 60.0
comiss xmm12, xmm11
jbe .modresta
.finloop:
subss xmm11, xmm13 ;xmm11 = mod(h/60 , 2) - 1
movdqu xmm12, [absmask]
pand xmm11, xmm12 ;xmm11 = abs( mod(h/60 , 2) - 1 )
subss xmm13, xmm11 ;xmm13 = 1 - ( abs( mod(h/60 , 2) - 1 ) )
mulss xmm13, xmm4 ;xmm13 = c * ( 1 - ( abs( mod(h/60 , 2) - 1 ) ) )
movdqu xmm5 , xmm13 ;xmm5 = c * ( 1 - ( abs( mod(h/60 , 2) - 1 ) ) )
.calcM:
movdqu xmm10, xmm0 ;xmm10 = l
movdqu xmm11, xmm15 ;xmm11 = 1
addss xmm11, xmm11 ;xmm11 = 2
movdqu xmm12, xmm4 ;xmm12 = c
divss xmm12, xmm11 ;xmm12 = c/2
subss xmm10, xmm12 ;xmm10 = l - c/2
;Cálculo de RGB
.calcRGB:
pxor xmm12, xmm12
movdqu xmm11, [c060]
addss xmm12, xmm11 ;xmm12 = 60
movd r10d, xmm5 ;r10 = x
.mayig0:
comiss xmm2, xmm12
jb .men60
addss xmm12, xmm11 ;xmm12 = 120
comiss xmm2, xmm12
jb .men120
addss xmm12, xmm11 ;xmm12 = 180
comiss xmm2, xmm12
jb .men180
addss xmm12, xmm11 ;xmm12 = 240
comiss xmm2, xmm12
jb .men240
addss xmm12, xmm11 ;xmm12 = 300
comiss xmm2, xmm12
jb .men300
addss xmm12, xmm11 ;xmm12 = 360
comiss xmm2, xmm12
jb .men360
.men60:
pslldq xmm4, 12 ;xmm4 = c | 0 | 0 | 0
pinsrd xmm4, r10d, 2 ;xmm4 = c | x | 0 | 0
jmp .calcEscala
.men120:
pslldq xmm4, 8 ;xmm4 = 0 | c | 0 | 0
pinsrd xmm4, r10d, 3 ;xmm4 = x | c | 0 | 0
jmp .calcEscala
.men180:
pslldq xmm4, 8 ;xmm4 = 0 | c | 0 | 0
pinsrd xmm4, r10d, 1 ;xmm4 = 0 | c | x | 0
jmp .calcEscala
.men240:
pslldq xmm4, 4 ;xmm4 = 0 | 0 | c | 0
pinsrd xmm4, r10d, 2 ;xmm4 = 0 | x | c | 0
jmp .calcEscala
.men300:
pslldq xmm4, 4 ;xmm4 = 0 | 0 | c | 0
pinsrd xmm4, r10d, 3 ;xmm4 = x | 0 | c | 0
jmp .calcEscala
.men360:
pslldq xmm4, 12 ;xmm4 = c | 0 | 0 | 0
pinsrd xmm4, r10d, 1 ;xmm4 = c | 0 | x | 0
jmp .calcEscala
;Cálculo de escala
.calcEscala:
movdqu xmm12, xmm10 ;xmm12 = 0 | 0 | 0 | m
pslldq xmm12, 4 ;xmm12 = 0 | 0 | m | 0
addps xmm12, xmm10 ;xmm12 = 0 | 0 | m | m
pslldq xmm12, 4 ;xmm12 = 0 | m | m | 0
addps xmm12, xmm10 ;xmm12 = 0 | m | m | m
pslldq xmm12, 4 ;xmm12 = m | m | m | 0
movdqu xmm13, [cEscala] ;xmm13 = 255 | 255 | 255 | 0
addps xmm4, xmm12 ;xmm4 = r+m | g+m | b+m | X
mulps xmm4, xmm13 ;xmm4 = (r+m)*255 | (g+m)*255 | (b+m)*255 | 0
movd r10d, xmm3
pinsrd xmm4, r10d, 0 ;xmm4 = (r+m)*255 | (g+m)*255 | (b+m)*255 | a
cvttps2dq xmm4, xmm4
movdqu xmm10, [shuf] ; Shuffle para pasar dword int a byte int
pshufb xmm4 , xmm10 ; xmm4 = | 0 | 0 | 0 |R|G|B|A|
PEXTRD [r13], xmm4, 00b ; grabo a memoria
.terminar:
add rbp, 8
pop r15
pop r14
pop r13
pop r12
pop rbx
pop rbp
ret
|
/********************************************************************************
* Copyright 2017 The Robotics Group, The Maersk Mc-Kinney Moller Institute,
* Faculty of Engineering, University of Southern Denmark
*
* 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 <gtest/gtest.h>
#include "../TestEnvironment.hpp"
#include <rw/kinematics/FixedFrame.hpp>
#include <rw/loaders/WorkCellLoader.hpp>
#include <rw/models/ParallelDevice.hpp>
#include <rw/models/ParallelLeg.hpp>
#include <rw/models/RevoluteJoint.hpp>
#include <rw/models/PrismaticJoint.hpp>
#include <rw/models/WorkCell.hpp>
using namespace rw::kinematics;
using rw::loaders::WorkCellLoader;
using namespace rw::math;
using namespace rw::models;
// Joint structure to test:
//
// Fixed
// |
// A
// |
// |-Ga------------Gb---H
// | |
// | __| |
// | _Fb |
// | _/ |
// | Fa |
// | |
// |-B---------------D
// | |
// Ca |
// | |
// | |
// Cb ---E
//
// Where all are revolute joints, except Fb which is prismatic
// Goal is that Fb/Gb remains connected, as well as D/H and Cb/E.
//
// Kinematic structure:
// ________
// /-------------------------|-Ca--Cb |
// / ___ | |
// /-- B -----------------|-D-|----|-E |
// / \ ________ | | |________|
// / \---|-Fa--Fb | | |
// / | | | |
// A -----------|-Ga--Gb-|----|-H-|
// |________| |___|
//
namespace {
ParallelLeg* makeLeg(Frame* A, Frame* B, Frame* C = NULL, Frame* D = NULL, Frame* E = NULL, Frame* F = NULL) {
std::vector<Frame*> chain(C==NULL?2:D==NULL?3:E==NULL?4:F==NULL?5:6);
chain[0] = A;
chain[1] = B;
if (C != NULL)
chain[2] = C;
if (D != NULL)
chain[3] = D;
if (E != NULL)
chain[4] = E;
if (F != NULL)
chain[5] = F;
return new ParallelLeg(chain);
}
}
TEST(ParallelDevice, Junctions) {
static const double lAB = 0.055;
static const double lGaGb = 0.055;
static const double lBFa = 0.015;
static const double lFaFb = 0.020;
static const double lFaD = lGaGb-lBFa;
static const double angleFb = std::atan2(lAB,lFaD);
static const double lFbFend = std::sqrt(lAB*lAB+lFaD*lFaD)-lFaFb;
Frame* const base = new FixedFrame("Fixed",Transform3D<>::identity());
Joint* const A = new RevoluteJoint("A",Transform3D<>(Vector3D<>::zero(),RPY<>(0,0,Pi/2)));
Frame* const Aend = new FixedFrame("Aend",Transform3D<>::identity());
Joint* const B = new RevoluteJoint("B",Transform3D<>(Vector3D<>(0,0,lAB),RPY<>(0,0,-Pi/2)));
Frame* const Bend = new FixedFrame("Bend",Transform3D<>::identity());
Joint* const Ca = new RevoluteJoint("Ca",Transform3D<>(Vector3D<>(0.030,0,0)));
Joint* const Cb = new RevoluteJoint("Cb",Transform3D<>(Vector3D<>(0,-0.045,0)));
Joint* const D = new RevoluteJoint("D",Transform3D<>(Vector3D<>(lGaGb,0,0)));
Joint* const E = new RevoluteJoint("E",Transform3D<>(Vector3D<>(0,-0.045,0)));
Frame* const Eend = new FixedFrame("Eend",Transform3D<>(Vector3D<>(-0.025,0,0)));
Joint* const Fa = new RevoluteJoint("Fa",Transform3D<>(Vector3D<>(lBFa,0,0),RPY<>(angleFb,0,0)));
Joint* const Fb = new PrismaticJoint("Fb",Transform3D<>(Vector3D<>(lFaFb,0,0),RPY<>(0,Pi/2,0)));
Frame* const Fbend = new FixedFrame("Fbend",Transform3D<>(Vector3D<>(0,0,lFbFend),RPY<>(0,-Pi/2,0)));
Joint* const Ga = new RevoluteJoint("Ga",Transform3D<>(Vector3D<>::zero(),RPY<>(0,0,-Pi/2)));
Joint* const Gb = new RevoluteJoint("Gb",Transform3D<>(Vector3D<>(lGaGb,0,0),RPY<>(angleFb,0,0)));
Joint* const H = new RevoluteJoint("H",Transform3D<>(Vector3D<>::zero(),RPY<>(-angleFb,0,0)));
Frame* const Hend = new FixedFrame("Hend",Transform3D<>(Vector3D<>(0,-lAB,0)));
A->setActive(true);
B->setActive(false);
Ca->setActive(false);
Cb->setActive(false);
D->setActive(false);
E->setActive(false);
Fa->setActive(false);
Fb->setActive(true);
Ga->setActive(false);
Gb->setActive(false);
H->setActive(false);
StateStructure sstruct;
sstruct.addData(base);
sstruct.addFrame(A,base);
sstruct.addFrame(Aend,A);
sstruct.addFrame(Ga,Aend);
sstruct.addFrame(Gb,Ga);
sstruct.addFrame(H,Gb);
sstruct.addFrame(Hend,H);
sstruct.addFrame(B,Aend);
sstruct.addFrame(Bend,B);
sstruct.addFrame(D,Bend);
sstruct.addFrame(E,D);
sstruct.addFrame(Eend,E);
sstruct.addFrame(Ca,Bend);
sstruct.addFrame(Cb,Ca);
sstruct.addFrame(Fa,Bend);
sstruct.addFrame(Fb,Fa);
sstruct.addFrame(Fbend,Fb);
State state = sstruct.getDefaultState();
std::vector<ParallelDevice::Legs> junctions(3);
junctions[0].push_back(makeLeg(Aend,Ga,Gb));
junctions[0].push_back(makeLeg(Aend,B,Bend,Fa,Fb,Fbend));
junctions[1].push_back(makeLeg(Aend,Ga,Gb,H,Hend));
junctions[1].push_back(makeLeg(Aend,B,Bend,D));
junctions[2].push_back(makeLeg(Bend,Ca,Cb));
junctions[2].push_back(makeLeg(Bend,D,E,Eend));
ASSERT_TRUE(junctions[0][1]->baseTend(state).equal(junctions[0][0]->baseTend(state)));
ASSERT_TRUE(junctions[1][1]->baseTend(state).equal(junctions[1][0]->baseTend(state)));
ASSERT_TRUE(junctions[2][1]->baseTend(state).equal(junctions[2][0]->baseTend(state)));
std::vector<Joint*> joints(11);
joints[0] = A;
joints[1] = B;
joints[2] = Ca;
joints[3] = Cb;
joints[4] = D;
joints[5] = E;
joints[6] = Fa;
joints[7] = Fb;
joints[8] = Ga;
joints[9] = Gb;
joints[10] = H;
const ParallelDevice* const device = new ParallelDevice("TestDevice", base, E, joints, state, junctions);
const JointDevice* const jdevice = device;
const Device* const ddevice = jdevice;
// Generic Device functions
EXPECT_EQ("TestDevice", ddevice->getName());
EXPECT_TRUE(ddevice->baseTend(state).equal(Transform3D<>(Vector3D<>(lGaGb,-lAB-0.045,0))));
EXPECT_TRUE(ddevice->baseTframe(H,state).equal(Transform3D<>(Vector3D<>(lGaGb,0,0))));
EXPECT_TRUE(ddevice->worldTbase(state).equal(Transform3D<>::identity()));
// Generic JointDevice functions
EXPECT_EQ(base, jdevice->getBase());
EXPECT_EQ(E, jdevice->getEnd());
EXPECT_EQ(2u, jdevice->getJoints().size());
ASSERT_GE(2u, jdevice->getJoints().size());
EXPECT_EQ(A, jdevice->getJoints()[0]);
EXPECT_EQ(Fb, jdevice->getJoints()[1]);
EXPECT_EQ(2u, jdevice->getDOF());
EXPECT_EQ(2u, jdevice->getBounds().first.size());
EXPECT_EQ(2u, jdevice->getBounds().second.size());
EXPECT_EQ(2u, jdevice->getVelocityLimits().size());
EXPECT_EQ(2u, jdevice->getAccelerationLimits().size());
// ParallelDevice functions
EXPECT_EQ(0u, device->getLegs().size()); // There should be no legs when using the junction concept.
EXPECT_EQ(2u, device->getActiveJoints().size());
ASSERT_GE(2u, device->getActiveJoints().size());
EXPECT_EQ(A, device->getActiveJoints()[0]);
EXPECT_EQ(Fb, device->getActiveJoints()[1]);
EXPECT_EQ(11u, device->getAllJoints().size());
EXPECT_EQ(11u, device->getFullDOF());
EXPECT_EQ(11u, device->getAllBounds().first.size());
EXPECT_EQ(11u, device->getAllBounds().second.size());
// Set full Q
EXPECT_EQ(11u, device->getFullQ(state).size());
double vals[11] = {0,1,2,3,4,5,6,7,8,9,10};
device->setFullQ(Q(11,vals),state);
for (std::size_t i = 0; i <= 10; i++)
EXPECT_EQ(i, device->getFullQ(state)[i]);
device->setFullQ(Q(11,0.),state);
// Set Q
EXPECT_EQ(2u, device->getQ(state).size());
device->setQ(Q(2,0.,0.015),state);
const Q qTest = device->getFullQ(state); // save for later comparison
{
static const double lFaFend = lFaFb+lFbFend+0.015;
static const double angleFaRef = std::acos((lFaD*lFaD+lFaFend*lFaFend-lAB*lAB)/(lFaD*lFaFend*2));
static const double angleDRef = std::acos((lFaD*lFaD+lAB*lAB-lFaFend*lFaFend)/(lFaD*lAB*2));
// Check full Q vector {A,B,Ca,Cb,D,E,Fa,Fb,Ga,Gb,H}
static const double eps = 1e-4;
EXPECT_NEAR(0,device->getFullQ(state)[0],eps); // A (controlled)
EXPECT_NEAR(angleDRef-Pi/2,device->getFullQ(state)[1],eps); // B
EXPECT_NEAR(-(angleDRef-Pi/2),device->getFullQ(state)[2],eps); // Ca
EXPECT_NEAR(angleDRef-Pi/2,device->getFullQ(state)[3],eps); // CB
EXPECT_NEAR(-(angleDRef-Pi/2),device->getFullQ(state)[4],eps); // D
EXPECT_NEAR(angleDRef-Pi/2,device->getFullQ(state)[5],eps); // E
EXPECT_NEAR(angleFaRef-angleFb,device->getFullQ(state)[6],eps); // Fa
EXPECT_NEAR(0.015,device->getFullQ(state)[7],eps); // Fb (controlled)
EXPECT_NEAR(angleDRef-Pi/2,device->getFullQ(state)[8],eps); // Ga
EXPECT_NEAR(angleFaRef-angleFb,device->getFullQ(state)[9],eps); // Gb
EXPECT_NEAR(-(angleDRef-Pi/2+angleFaRef-angleFb),device->getFullQ(state)[10],eps); // H
EXPECT_TRUE(junctions[0][1]->baseTend(state).equal(junctions[0][0]->baseTend(state),1e-6));
EXPECT_TRUE(junctions[1][1]->baseTend(state).equal(junctions[1][0]->baseTend(state),1e-6));
EXPECT_TRUE(junctions[2][1]->baseTend(state).equal(junctions[2][0]->baseTend(state),1e-6));
}
device->setQ(Q(2,0.,-0.015),state);
{
static const double lFaFend = lFaFb+lFbFend-0.015;
static const double angleFaRef = std::acos((lFaD*lFaD+lFaFend*lFaFend-lAB*lAB)/(lFaD*lFaFend*2));
static const double angleDRef = std::acos((lFaD*lFaD+lAB*lAB-lFaFend*lFaFend)/(lFaD*lAB*2));
// Check full Q vector {A,B,Ca,Cb,D,E,Fa,Fb,Ga,Gb,H}
static const double eps = 1e-4;
EXPECT_NEAR(0,device->getFullQ(state)[0],eps); // A (controlled)
EXPECT_NEAR(angleDRef-Pi/2,device->getFullQ(state)[1],eps); // B
EXPECT_NEAR(-(angleDRef-Pi/2),device->getFullQ(state)[2],eps); // Ca
EXPECT_NEAR(angleDRef-Pi/2,device->getFullQ(state)[3],eps); // CB
EXPECT_NEAR(-(angleDRef-Pi/2),device->getFullQ(state)[4],eps); // D
EXPECT_NEAR(angleDRef-Pi/2,device->getFullQ(state)[5],eps); // E
EXPECT_NEAR(angleFaRef-angleFb,device->getFullQ(state)[6],eps); // Fa
EXPECT_NEAR(-0.015,device->getFullQ(state)[7],eps); // Fb (controlled)
EXPECT_NEAR(angleDRef-Pi/2,device->getFullQ(state)[8],eps); // Ga
EXPECT_NEAR(angleFaRef-angleFb,device->getFullQ(state)[9],eps); // Gb
EXPECT_NEAR(-(angleDRef-Pi/2+angleFaRef-angleFb),device->getFullQ(state)[10],eps); // H
EXPECT_TRUE(junctions[0][1]->baseTend(state).equal(junctions[0][0]->baseTend(state),1e-6));
EXPECT_TRUE(junctions[1][1]->baseTend(state).equal(junctions[1][0]->baseTend(state),1e-6));
EXPECT_TRUE(junctions[2][1]->baseTend(state).equal(junctions[2][0]->baseTend(state),1e-6));
}
delete device;
// Test that we get same result with extra active joint, that is then disabled when setting setQ
B->setActive(true);
state = sstruct.getDefaultState();
const ParallelDevice* const devExtraJoint = new ParallelDevice("TestDevice", base, E, joints, state, junctions);
std::vector<bool> enabled(3,true);
enabled[1] = false;
devExtraJoint->setQ(Q(3,0.,0.2,0.015),enabled,state);
EXPECT_TRUE((devExtraJoint->getFullQ(state).e()-qTest.e()).isZero(std::numeric_limits<double>::epsilon()));
// Then test that we can control the other active joint instead
enabled[1] = true;
enabled[2] = false;
devExtraJoint->setQ(Q(3,0.,0.2,0.015),enabled,state);
{
static const double lFaFendRef = std::sqrt(lFaD*lFaD+lAB*lAB+lFaD*lAB*2*std::sin(0.2));
static const double angleFaRef = std::acos((lFaD+lAB*std::sin(0.2))/lFaFendRef);
// Check full Q vector {A,B,Ca,Cb,D,E,Fa,Fb,Ga,Gb,H}
static const double eps = 1e-4;
EXPECT_NEAR(0,devExtraJoint->getFullQ(state)[0],eps); // A (controlled)
EXPECT_NEAR(0.2,devExtraJoint->getFullQ(state)[1],eps); // B (controlled)
EXPECT_NEAR(-0.2,devExtraJoint->getFullQ(state)[2],eps); // Ca
EXPECT_NEAR(0.2,devExtraJoint->getFullQ(state)[3],eps); // CB
EXPECT_NEAR(-0.2,devExtraJoint->getFullQ(state)[4],eps); // D
EXPECT_NEAR(0.2,devExtraJoint->getFullQ(state)[5],eps); // E
EXPECT_NEAR(angleFaRef-angleFb,devExtraJoint->getFullQ(state)[6],eps); // Fa
EXPECT_NEAR(lFaFendRef-lFaFb-lFbFend,devExtraJoint->getFullQ(state)[7],eps); // Fb
EXPECT_NEAR(0.2,devExtraJoint->getFullQ(state)[8],eps); // Ga
EXPECT_NEAR(angleFaRef-angleFb,devExtraJoint->getFullQ(state)[9],eps); // Gb
EXPECT_NEAR(-(0.2+angleFaRef-angleFb),devExtraJoint->getFullQ(state)[10],eps); // H
EXPECT_TRUE(junctions[0][1]->baseTend(state).equal(junctions[0][0]->baseTend(state),1e-6));
EXPECT_TRUE(junctions[1][1]->baseTend(state).equal(junctions[1][0]->baseTend(state),1e-6));
EXPECT_TRUE(junctions[2][1]->baseTend(state).equal(junctions[2][0]->baseTend(state),1e-6));
}
delete devExtraJoint;
for (std::size_t i = 0; i < junctions.size(); i++) {
for (std::size_t j = 0; j < junctions[i].size(); j++) {
delete junctions[i][j];
}
}
}
namespace {
std::vector<Frame*> ParallelLegHEXAPOD(Frame* base, const std::string& scope, const Transform3D<double>& legBase, const Transform3D<double>& tool, double yaw, double pitch) {
Joint* const joint1 = new RevoluteJoint(scope+".joint1",Transform3D<>::craigDH( 0, 0, 0, yaw));
Joint* const joint2 = new RevoluteJoint(scope+".joint2",Transform3D<>::craigDH( Pi/2.0, 0, 0, Pi/2.0+pitch));
Joint* const joint3 = new PrismaticJoint(scope+".joint3",Transform3D<>::craigDH( Pi/2.0, 0, 0, 0));
Joint* const joint4 = new RevoluteJoint(scope+".joint4",Transform3D<>::craigDH( -Pi/2.0, 0, 0, Pi/2.0));
Joint* const joint5 = new RevoluteJoint(scope+".joint5",Transform3D<>::craigDH( Pi/2.0, 0, 0, -Pi/2.0));
Joint* const joint6 = new RevoluteJoint(scope+".joint6",Transform3D<>::craigDH( Pi/2.0, 0, 0, Pi/2.0));
joint1->setActive(false);
joint2->setActive(false);
joint3->setActive(true);
joint4->setActive(false);
joint5->setActive(false);
joint6->setActive(false);
std::vector<Frame*> serialChain;
serialChain.push_back(base);
serialChain.push_back(new FixedFrame(scope+".legOffset",legBase));
serialChain.push_back(joint1);
serialChain.push_back(joint2);
serialChain.push_back(joint3);
serialChain.push_back(joint4);
serialChain.push_back(joint5);
serialChain.push_back(joint6);
serialChain.push_back(new FixedFrame(scope+".Tool",tool));
serialChain.push_back(new FixedFrame(scope+".End",Transform3D<>::identity()));
return serialChain;
}
}
TEST(ParallelDevice, SerialChains) {
Frame* const world = new FixedFrame("World", Transform3D<>::identity());
const EAA<> R(normalize(Vector3D<>(1,0,1)),Pi);
std::vector<std::vector<Frame*> > legChains(6);
// Leg A
const Transform3D<> baseTA(Vector3D<>(-60.206416539249155, -11.580306882912305, 0), R);
const Transform3D<> toolTA(Vector3D<>(14.533675867691082, -8.586935664729255, 5.486283046170201), RPY<>(0,-0.5058297976189102, 0.2554802362083838));
legChains[0] = ParallelLegHEXAPOD(world, "LegA", baseTA, toolTA,-0.2554802362083838, 0.5058297976189102);
// Leg B
const Transform3D<> baseTB(Vector3D<>(-40.132048213846446, -46.350132752361176,0), R);
const Transform3D<> toolTB(Vector3D<>(-2.6407792002537804, 16.673016630261774, 5.486283046154413), RPY<>(0,-0.4486102166464917, 0.3501394675976276));
legChains[1] = ParallelLegHEXAPOD(world, "LegB", baseTB, toolTB, -0.3501394675976276, 0.4486102166464917);
// Leg C
const Transform3D<> baseTC(Vector3D<>(40.13204821384643, -46.35013275236119,0), R);
const Transform3D<> toolTC(Vector3D<>(2.6407792002537804, 16.673016630261774, 5.486283046154413), RPY<>(0,0.4486102166464917, 0.3501394675976276));
legChains[2] = ParallelLegHEXAPOD(world, "LegC", baseTC, toolTC,-0.3501394675976276,-0.4486102166464917);
// Leg D
const Transform3D<> baseTD(Vector3D<>(60.20641653924915, -11.580306882912327, 0), R);
const Transform3D<> toolTD(Vector3D<> (-14.533675867691082, -8.586935664729255, 5.486283046170201), RPY<>(0,0.5058297976189102, 0.2554802362083838));
legChains[3] = ParallelLegHEXAPOD(world, "LegD", baseTD, toolTD,-0.2554802362083838, -0.5058297976189102);
// Leg E
const Transform3D<> baseTE(Vector3D<> (20.074368325402705, 57.930439635273515, 0), R);
const Transform3D<> toolTE(Vector3D<> (-15.112667091527895, -7.521335766866318, 5.486283046171359), RPY<>(0,0.05084170375926413, -0.5595869360340129));
legChains[4] = ParallelLegHEXAPOD(world, "LegE", baseTE, toolTE,0.5595869360340129, -0.05084170375926413);
// Leg F
const Transform3D<> baseTF(Vector3D<> (-20.0743683254027, 57.93043963527352, 0), R);
const Transform3D<> toolTF(Vector3D<> (15.112667091527895, -7.521335766866318, 5.486283046171359), RPY<>(0,-0.05084170375926413, -0.5595869360340129));
legChains[5] = ParallelLegHEXAPOD(world, "LegF", baseTF, toolTF,0.5595869360340129, 0.05084170375926413);
StateStructure sstruct;
sstruct.addData(world);
for (std::size_t i = 0; i < legChains.size(); i++) {
for (std::size_t j = 1; j < legChains[i].size(); j++) {
sstruct.addFrame(legChains[i][j],legChains[i][j-1]);
}
}
State state = sstruct.getDefaultState();
const Q qh(6,0.,0.,92.6865,0.,0.,0.);
std::vector<ParallelLeg*> legs(legChains.size());
for (std::size_t i = 0; i < legChains.size(); i++) {
legs[i] = new ParallelLeg(legChains[i]);
legs[i]->setQ(qh,state);
}
const ParallelDevice hexapod(legs,"Hexapod",state);
Q q = hexapod.getQ(state);
hexapod.setQ(q,state);
q = hexapod.getQ(state);
EXPECT_NEAR(0,hexapod.baseTend(state).P()[0],5e-12);
EXPECT_NEAR(0,hexapod.baseTend(state).P()[1],5e-12);
EXPECT_NEAR(78.5,hexapod.baseTend(state).P()[2],1e-4);
EXPECT_TRUE(hexapod.baseTend(state).R().equal(Rotation3D<>::identity(),1e-13));
for (std::size_t i = 0; i < legs.size(); i++) {
EXPECT_TRUE(legs[i]->baseTend(state).R().equal(hexapod.baseTend(state).R(),1e-12));
EXPECT_NEAR(0,(legs[i]->baseTend(state).P()-hexapod.baseTend(state).P()).normInf(),1e-10);
}
q[0] += 1;
hexapod.setQ(q,state);
for (std::size_t i = 0; i < legs.size(); i++) {
EXPECT_TRUE(legs[i]->baseTend(state).R().equal(hexapod.baseTend(state).R(),1e-12));
EXPECT_NEAR(0,(legs[i]->baseTend(state).P()-hexapod.baseTend(state).P()).normInf(),1e-10);
}
q[1] += 2;
q[2] += 1;
q[3] += 3;
hexapod.setQ(q,state);
for (std::size_t i = 0; i < legs.size(); i++) {
EXPECT_TRUE(legs[i]->baseTend(state).R().equal(hexapod.baseTend(state).R(),5e-10));
EXPECT_NEAR(0,(legs[i]->baseTend(state).P()-hexapod.baseTend(state).P()).normInf(),5e-9);
}
q[1] += 2;
q[2] += 1;
q[3] += 3;
q[4] += 20;
q[5] += 3;
hexapod.setQ(q,state);
for (std::size_t i = 0; i < legs.size(); i++) {
EXPECT_TRUE(legs[i]->baseTend(state).R().equal(hexapod.baseTend(state).R(),1e-11));
EXPECT_NEAR(0,(legs[i]->baseTend(state).P()-hexapod.baseTend(state).P()).normInf(),1e-9);
}
EXPECT_EQ(6u, q.size());
ASSERT_GE(6u, q.size());
EXPECT_EQ(93.6865, q[0]);
EXPECT_EQ(96.6865, q[1]);
EXPECT_EQ(94.6865, q[2]);
EXPECT_EQ(98.6865, q[3]);
EXPECT_EQ(112.6865, q[4]);
EXPECT_EQ(95.6865, q[5]);
const Q qFull = hexapod.getFullQ(state);
EXPECT_EQ(36u, qFull.size());
ASSERT_GE(36u, qFull.size());
EXPECT_EQ(93.6865, qFull[2]);
EXPECT_EQ(96.6865, qFull[8]);
EXPECT_EQ(94.6865, qFull[14]);
EXPECT_EQ(98.6865, qFull[20]);
EXPECT_EQ(112.6865, qFull[26]);
EXPECT_EQ(95.6865, qFull[32]);
}
TEST(ParallelDevice, Robotiq) {
const WorkCell::Ptr wc = WorkCellLoader::Factory::load(TestEnvironment::testfilesDir()+"devices/Robotiq-2-finger-85/robotiq.wc.xml");
ASSERT_FALSE(wc.isNull());
const ParallelDevice::Ptr robotiqDist = wc->findDevice<ParallelDevice>("RobotiqDistanceControl");
const ParallelDevice::Ptr robotiqFinger = wc->findDevice<ParallelDevice>("RobotiqFingerControl");
ASSERT_FALSE(robotiqDist.isNull());
ASSERT_FALSE(robotiqFinger.isNull());
State state = wc->getDefaultState();
// Generic Device functions
EXPECT_EQ("RobotiqDistanceControl", robotiqDist->getName());
EXPECT_EQ("RobotiqFingerControl", robotiqFinger->getName());
EXPECT_TRUE(robotiqDist->baseTend(state).equal(Transform3D<>(Vector3D<>(-0.0425,0.119008,0),RPY<>(0,Pi/2,0)),1e-6));
EXPECT_TRUE(robotiqFinger->baseTend(state).equal(Transform3D<>(Vector3D<>(-0.0425,0.119008,0),RPY<>(0,Pi/2,0)),1e-4));
// Generic JointDevice functions
EXPECT_EQ("RobotiqDistanceControl.Base", robotiqDist->getBase()->getName());
EXPECT_EQ("RobotiqDistanceControl.LeftMotorEnd", robotiqDist->getEnd()->getName());
EXPECT_EQ("RobotiqFingerControl.Base", robotiqFinger->getBase()->getName());
EXPECT_EQ("RobotiqFingerControl.LeftMotorEnd", robotiqFinger->getEnd()->getName());
EXPECT_EQ(3u, robotiqDist->getJoints().size());
EXPECT_EQ(3u, robotiqDist->getDOF());
EXPECT_EQ(3u, robotiqDist->getBounds().first.size());
EXPECT_EQ(3u, robotiqDist->getBounds().second.size());
EXPECT_EQ(3u, robotiqDist->getVelocityLimits().size());
EXPECT_EQ(3u, robotiqDist->getAccelerationLimits().size());
EXPECT_EQ(4u, robotiqFinger->getJoints().size()); // two motor joints maps to one DOF (dependent joints)
EXPECT_EQ(3u, robotiqFinger->getDOF());
EXPECT_EQ(3u, robotiqFinger->getBounds().first.size());
EXPECT_EQ(3u, robotiqFinger->getBounds().second.size());
EXPECT_EQ(3u, robotiqFinger->getVelocityLimits().size());
EXPECT_EQ(3u, robotiqFinger->getAccelerationLimits().size());
// ParallelDevice functions
EXPECT_EQ(0u, robotiqDist->getLegs().size()); // There should be no legs when using the junction concept.
EXPECT_EQ(3u, robotiqDist->getJunctions().size());
ASSERT_GE(robotiqDist->getJunctions().size(), 3u);
ASSERT_EQ(2u, robotiqDist->getJunctions()[0].size());
ASSERT_EQ(2u, robotiqDist->getJunctions()[1].size());
ASSERT_EQ(2u, robotiqDist->getJunctions()[2].size());
EXPECT_EQ(3u, robotiqDist->getActiveJoints().size());
EXPECT_EQ(13u, robotiqDist->getAllJoints().size());
EXPECT_EQ(12u, robotiqDist->getFullDOF());
EXPECT_EQ(12u, robotiqDist->getAllBounds().first.size());
EXPECT_EQ(12u, robotiqDist->getAllBounds().second.size());
EXPECT_EQ(0u, robotiqFinger->getLegs().size()); // There should be no legs when using the junction concept.
EXPECT_EQ(2u, robotiqFinger->getJunctions().size());
ASSERT_GE(robotiqFinger->getJunctions().size(), 2u);
ASSERT_EQ(2u, robotiqFinger->getJunctions()[0].size());
ASSERT_EQ(2u, robotiqFinger->getJunctions()[1].size());
EXPECT_EQ(4u, robotiqFinger->getActiveJoints().size());
EXPECT_EQ(10u, robotiqFinger->getAllJoints().size());
EXPECT_EQ(9u, robotiqFinger->getFullDOF());
EXPECT_EQ(9u, robotiqFinger->getAllBounds().first.size());
EXPECT_EQ(9u, robotiqFinger->getAllBounds().second.size());
ASSERT_EQ(3u, robotiqDist->getQ(state).size());
ASSERT_EQ(12u, robotiqDist->getFullQ(state).size());
ASSERT_EQ(3u, robotiqFinger->getQ(state).size());
ASSERT_EQ(9u, robotiqFinger->getFullQ(state).size());
// Set Q
robotiqDist->setQ(Q(3,0.,0.04,0.),state);
{
static const double eps = 1e-4;
EXPECT_NEAR(0.4506,robotiqDist->getFullQ(state)[0],eps);
EXPECT_NEAR(0.0008,robotiqDist->getFullQ(state)[1],eps);
EXPECT_NEAR(-0.4514,robotiqDist->getFullQ(state)[2],eps);
EXPECT_NEAR(0.4511,robotiqDist->getFullQ(state)[3],eps);
EXPECT_NEAR(-0.4511,robotiqDist->getFullQ(state)[4],eps);
EXPECT_NEAR(0.0008,robotiqDist->getFullQ(state)[5],eps);
EXPECT_NEAR(-0.4514,robotiqDist->getFullQ(state)[6],eps);
EXPECT_NEAR(0.4511,robotiqDist->getFullQ(state)[7],eps);
EXPECT_NEAR(-0.4511,robotiqDist->getFullQ(state)[8],eps);
EXPECT_EQ(0,robotiqDist->getFullQ(state)[9]);
EXPECT_EQ(0.04,robotiqDist->getFullQ(state)[10]);
EXPECT_EQ(0,robotiqDist->getFullQ(state)[11]);
EXPECT_TRUE(robotiqDist->getJunctions()[0][0]->baseTend(state).equal(robotiqDist->getJunctions()[0][1]->baseTend(state),1e-6));
EXPECT_TRUE(robotiqDist->getJunctions()[1][0]->baseTend(state).equal(robotiqDist->getJunctions()[1][1]->baseTend(state),1e-6));
EXPECT_TRUE(robotiqDist->getJunctions()[2][0]->baseTend(state).equal(robotiqDist->getJunctions()[2][1]->baseTend(state),1e-6));
}
robotiqDist->setQ(Q(3,-0.35,0.04,0.35),state);
{
static const double eps = 1e-4;
EXPECT_NEAR(0.4858,robotiqDist->getFullQ(state)[0],eps);
EXPECT_NEAR(-0.2596,robotiqDist->getFullQ(state)[1],eps);
EXPECT_NEAR(0.1237,robotiqDist->getFullQ(state)[2],eps);
EXPECT_NEAR(0.2841,robotiqDist->getFullQ(state)[3],eps);
EXPECT_NEAR(0.0659,robotiqDist->getFullQ(state)[4],eps);
EXPECT_NEAR(-0.2596,robotiqDist->getFullQ(state)[5],eps);
EXPECT_NEAR(0.1237,robotiqDist->getFullQ(state)[6],eps);
EXPECT_NEAR(0.2841,robotiqDist->getFullQ(state)[7],eps);
EXPECT_NEAR(0.0658,robotiqDist->getFullQ(state)[8],eps);
EXPECT_EQ(-0.35,robotiqDist->getFullQ(state)[9]);
EXPECT_EQ(0.04,robotiqDist->getFullQ(state)[10]);
EXPECT_EQ(0.35,robotiqDist->getFullQ(state)[11]);
EXPECT_TRUE(robotiqDist->getJunctions()[0][0]->baseTend(state).equal(robotiqDist->getJunctions()[0][1]->baseTend(state),1e-6));
EXPECT_TRUE(robotiqDist->getJunctions()[1][0]->baseTend(state).equal(robotiqDist->getJunctions()[1][1]->baseTend(state),1e-6));
EXPECT_TRUE(robotiqDist->getJunctions()[2][0]->baseTend(state).equal(robotiqDist->getJunctions()[2][1]->baseTend(state),1e-6));
}
robotiqFinger->setQ(Q(3,0.35,0.25,0.25),state);
{
static const double eps = 1e-4;
EXPECT_EQ(0.35,robotiqFinger->getFullQ(state)[0]);
EXPECT_NEAR(-0.1294,robotiqFinger->getFullQ(state)[1],eps);
EXPECT_NEAR(-0.0422,robotiqFinger->getFullQ(state)[2],eps);
EXPECT_EQ(0.25,robotiqFinger->getFullQ(state)[3]);
EXPECT_NEAR(-0.0716,robotiqFinger->getFullQ(state)[4],eps);
EXPECT_NEAR(-0.1294,robotiqFinger->getFullQ(state)[5],eps);
EXPECT_NEAR(-0.0422,robotiqFinger->getFullQ(state)[6],eps);
EXPECT_EQ(0.25,robotiqFinger->getFullQ(state)[7]);
EXPECT_NEAR(-0.0716,robotiqFinger->getFullQ(state)[8],eps);
EXPECT_TRUE(robotiqFinger->getJunctions()[0][0]->baseTend(state).equal(robotiqFinger->getJunctions()[0][1]->baseTend(state),1e-6));
EXPECT_TRUE(robotiqFinger->getJunctions()[1][0]->baseTend(state).equal(robotiqFinger->getJunctions()[1][1]->baseTend(state),1e-6));
}
robotiqFinger->setQ(Q(3,0.5,0.52,0.2),state);
{
static const double eps = 1e-4;
EXPECT_EQ(0.5,robotiqFinger->getFullQ(state)[0]);
EXPECT_NEAR(0.0327,robotiqFinger->getFullQ(state)[1],eps);
EXPECT_NEAR(-0.5776,robotiqFinger->getFullQ(state)[2],eps);
EXPECT_EQ(0.52,robotiqFinger->getFullQ(state)[3]);
EXPECT_NEAR(-0.5650,robotiqFinger->getFullQ(state)[4],eps);
EXPECT_NEAR(-0.3623,robotiqFinger->getFullQ(state)[5],eps);
EXPECT_NEAR(0.3618,robotiqFinger->getFullQ(state)[6],eps);
EXPECT_EQ(0.2,robotiqFinger->getFullQ(state)[7]);
EXPECT_NEAR(0.2995,robotiqFinger->getFullQ(state)[8],eps);
EXPECT_TRUE(robotiqFinger->getJunctions()[0][0]->baseTend(state).equal(robotiqFinger->getJunctions()[0][1]->baseTend(state),1e-6));
EXPECT_TRUE(robotiqFinger->getJunctions()[1][0]->baseTend(state).equal(robotiqFinger->getJunctions()[1][1]->baseTend(state),1e-6));
}
}
|
; learning data types correctly
; Mohit Agarwal
; 17-05-2021
section .data
;define constants
EXIT_SUCCESS equ 0 ;successful operation
SYS_EXIT equ 60 ;sysexit syscall
;define variables
bvar1 db 8
bvar2 db 16
bres db 0
section .text
global _start
_start:
;byte addition
loop:
mov al, byte [bvar1]
add al, byte [bvar2]
mov byte [bres], al
;end program
last:
mov rax, SYS_EXIT
mov rdi, EXIT_SUCCESS
syscall
|
; A327706: The minimal size of a partition lambda of n such that every partition of n with at most 6 parts can be obtained by coalescing the parts of lambda.
; 1,2,3,4,5,6,6,7,7,8,8,9,9,9,10,10,10,11,11,11,11,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18
add $0,1
lpb $0
mul $0,5
div $0,6
add $1,4
lpe
div $1,4
mov $0,$1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r12
push %r14
push %rbp
push %rcx
push %rsi
lea addresses_WT_ht+0x15812, %r14
nop
nop
nop
nop
nop
cmp $60052, %rcx
mov (%r14), %r12
sub $42484, %rsi
lea addresses_WT_ht+0x13800, %r10
nop
nop
nop
inc %rsi
movb (%r10), %r14b
nop
nop
add %r14, %r14
lea addresses_D_ht+0xa7e2, %r14
nop
sub %r10, %r10
mov (%r14), %r12
nop
nop
nop
nop
nop
add $54174, %rcx
pop %rsi
pop %rcx
pop %rbp
pop %r14
pop %r12
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r14
push %r15
push %rbx
push %rdi
push %rdx
// Faulty Load
lea addresses_normal+0x16b62, %rbx
nop
nop
nop
nop
xor $8612, %r14
movups (%rbx), %xmm1
vpextrq $1, %xmm1, %rdi
lea oracles, %r15
and $0xff, %rdi
shlq $12, %rdi
mov (%r15,%rdi,1), %rdi
pop %rdx
pop %rdi
pop %rbx
pop %r15
pop %r14
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 2, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 1, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 5, 'size': 8, 'same': False, 'NT': False}}
{'34': 21829}
34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34
*/
|
<%
from pwnlib.shellcraft.powerpc.linux import syscall
%>
<%page args="fd, mode, offset, length"/>
<%docstring>
Invokes the syscall fallocate. See 'man 2 fallocate' for more information.
Arguments:
fd(int): fd
mode(int): mode
offset(off_t): offset
len(off_t): len
</%docstring>
${syscall('SYS_fallocate', fd, mode, offset, length)}
|
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QInputDialog>
#include <QPushButton>
#include <QEasingCurve>
#include "qanimatedgridlayout.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
statusBar()->hide();
// Setup animated grid
animatedLayout = new QAnimatedGridLayout(centralWidget());
animatedLayout->setAnimationDuration(350);
animatedLayout->setContentsMargins(10,20,10,20);
ui->actionDuration->setText(
QString("Duration:%1").arg(animatedLayout->animationDuration()));
// See QEasingCurve doc for detailed explanation
QEasingCurve easing(QEasingCurve::OutElastic);
easing.setAmplitude(0.7);
easing.setPeriod(1.0);
animatedLayout->setEasingCurve(easing);
QPushButton * button = NULL;
int rowMax = 3;
int colMax = 4;
for (int row = 0; row < rowMax; ++row)
{
for (int col = 0; col < colMax; ++col)
{
// Add a button to each cell in the matrix
button = new QPushButton(
QString("(%1,%2)").arg(row).arg(col),
centralWidget());
// Set size policy to fill the cell properly
button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
animatedLayout->addWidget(button,row, col);
connect(button, SIGNAL(clicked()), SLOT(buttonClicked()));
}
}
// Lets add a button to a row
button = new QPushButton(
QString("(%1,%2) to (%3,%4)")
.arg(rowMax)
.arg(0)
.arg(rowMax)
.arg(colMax-1)
,
centralWidget());
button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
animatedLayout->addWidget(button,rowMax, 0, 1, colMax);
connect(button, SIGNAL(clicked()), SLOT(buttonClicked()));
centralWidget()->setLayout(animatedLayout);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::buttonClicked()
{
// On each click, switch the view
if (animatedLayout->isZoomed())
animatedLayout->showAll();
else
animatedLayout->zoomTo(qobject_cast<QPushButton*>(sender()));
}
void MainWindow::on_actionDuration_triggered()
{
bool ok = false;
int i = QInputDialog::getInt(this,
"Duration",
"Please enter a duration as miliseconds (1000ms = 1s):",
animatedLayout->animationDuration(),
50, 10000, 1, &ok);
if (ok) {
animatedLayout->setAnimationDuration(i);
ui->actionDuration->setText(
QString("Duration:%1").arg(animatedLayout->animationDuration()));
}
}
|
.global s_prepare_buffers
s_prepare_buffers:
push %r13
push %r14
push %r8
push %r9
push %rax
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0x6211, %r13
nop
nop
sub %r8, %r8
mov (%r13), %eax
nop
nop
nop
nop
nop
inc %r9
lea addresses_D_ht+0xfff1, %r13
and $14502, %rsi
movl $0x61626364, (%r13)
nop
nop
nop
dec %rax
lea addresses_WC_ht+0x1e381, %rsi
lea addresses_normal_ht+0x16231, %rdi
nop
nop
nop
nop
nop
and %r14, %r14
mov $67, %rcx
rep movsq
nop
nop
nop
lfence
lea addresses_A_ht+0x15141, %rax
nop
dec %rcx
movb (%rax), %r14b
nop
nop
nop
add $39062, %r9
lea addresses_WC_ht+0x119d1, %rsi
lea addresses_normal_ht+0x1aa39, %rdi
nop
add %r13, %r13
mov $30, %rcx
rep movsq
nop
nop
nop
nop
nop
add %rsi, %rsi
lea addresses_normal_ht+0xbb1, %rsi
lea addresses_WT_ht+0x10af1, %rdi
nop
nop
cmp $65343, %r9
mov $116, %rcx
rep movsb
nop
nop
nop
nop
nop
dec %rdi
lea addresses_A_ht+0x6df1, %rsi
lea addresses_WC_ht+0x1cc5d, %rdi
nop
add %r13, %r13
mov $119, %rcx
rep movsq
nop
nop
nop
nop
sub $21093, %r9
lea addresses_A_ht+0xc0f1, %r13
nop
nop
dec %r8
mov $0x6162636465666768, %rax
movq %rax, %xmm4
movups %xmm4, (%r13)
nop
nop
sub %r14, %r14
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r9
pop %r8
pop %r14
pop %r13
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r14
push %r15
push %r9
// Faulty Load
mov $0x7643b700000005f1, %r9
nop
nop
add %r10, %r10
mov (%r9), %r11
lea oracles, %r15
and $0xff, %r11
shlq $12, %r11
mov (%r15,%r11,1), %r11
pop %r9
pop %r15
pop %r14
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_NC', 'same': False, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'type': 'addresses_NC', 'same': True, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_D_ht', 'same': True, 'size': 4, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_D_ht', 'same': False, 'size': 4, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_WC_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_A_ht', 'same': False, 'size': 1, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WC_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 2, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_normal_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_A_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 2, 'same': True}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_A_ht', 'same': False, 'size': 16, 'congruent': 8, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
#include "avcodec.hpp"
#ifdef __cplusplus
extern "C" {
#endif
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
#ifdef __cplusplus
}
#endif
extern AVInputFormat ff_mov_demuxer;
extern AVInputFormat ff_matroska_demuxer;
extern AVInputFormat ff_mp3_demuxer;
extern AVInputFormat ff_flac_demuxer;
extern AVInputFormat ff_wav_demuxer;
extern AVInputFormat ff_aac_demuxer;
extern AVInputFormat ff_ogg_demuxer;
extern AVCodec ff_h264_decoder;
extern AVCodec ff_mpeg4_decoder;
extern AVCodec ff_vp9_decoder;
extern AVCodec ff_vp8_decoder;
extern AVCodec ff_mp3_decoder;
extern AVCodec ff_flac_decoder;
extern AVCodec ff_aac_decoder;
extern AVCodec ff_vorbis_decoder;
void avcodec_init()
{
av_register_input_format(&ff_mov_demuxer);
av_register_input_format(&ff_matroska_demuxer);
av_register_input_format(&ff_mp3_demuxer);
av_register_input_format(&ff_flac_demuxer);
av_register_input_format(&ff_wav_demuxer);
av_register_input_format(&ff_aac_demuxer);
av_register_input_format(&ff_ogg_demuxer);
avcodec_register(&ff_h264_decoder);
avcodec_register(&ff_mpeg4_decoder);
avcodec_register(&ff_vp9_decoder);
avcodec_register(&ff_vp8_decoder);
avcodec_register(&ff_mp3_decoder);
avcodec_register(&ff_flac_decoder);
avcodec_register(&ff_aac_decoder);
avcodec_register(&ff_vorbis_decoder);
av_log_set_level(AV_LOG_ERROR);
}
struct avcodec_decoder_struct {
const cv::Mat* mat;
ptrdiff_t read_index;
AVFormatContext* container;
AVCodecContext* codec;
AVIOContext* avio;
int video_stream_index;
};
static int avcodec_decoder_read_callback(void* d_void, uint8_t* buf, int buf_size)
{
avcodec_decoder d = static_cast<avcodec_decoder>(d_void);
size_t buf_len = d->mat->total() - d->read_index;
size_t read_len = (buf_len > buf_size) ? buf_size : buf_len;
memmove(buf, d->mat->data + d->read_index, read_len);
d->read_index += read_len;
return read_len;
}
static int64_t avcodec_decoder_seek_callback(void* d_void, int64_t offset, int whence)
{
avcodec_decoder d = static_cast<avcodec_decoder>(d_void);
uint8_t* to;
switch (whence) {
case SEEK_SET:
to = d->mat->data + offset;
break;
case SEEK_CUR:
to = d->mat->data + d->read_index + offset;
break;
case SEEK_END:
to = d->mat->data + d->mat->total() + offset;
break;
case AVSEEK_SIZE:
return d->mat->total();
default:
return -1;
}
if (to < d->mat->data) {
return -1;
}
if (to >= (d->mat->data + d->mat->total())) {
return -1;
}
d->read_index = (to - d->mat->data);
return 0;
}
static bool avcodec_decoder_is_audio(const avcodec_decoder d)
{
if (!d->container) {
return false;
}
if (d->container->iformat == &ff_mp3_demuxer) {
return true;
}
if (d->container->iformat == &ff_flac_demuxer) {
return true;
}
if (d->container->iformat == &ff_wav_demuxer) {
return true;
}
if (d->container->iformat == &ff_aac_demuxer) {
return true;
}
if (d->container->iformat == &ff_ogg_demuxer) {
return true;
}
return false;
}
avcodec_decoder avcodec_decoder_create(const opencv_mat buf)
{
avcodec_decoder d = new struct avcodec_decoder_struct();
memset(d, 0, sizeof(struct avcodec_decoder_struct));
d->mat = static_cast<const cv::Mat*>(buf);
d->container = avformat_alloc_context();
if (!d->container) {
avcodec_decoder_release(d);
return NULL;
}
d->avio = avio_alloc_context(
NULL, 0, 0, d, avcodec_decoder_read_callback, NULL, avcodec_decoder_seek_callback);
if (!d->avio) {
avcodec_decoder_release(d);
return NULL;
}
d->container->pb = d->avio;
int res = avformat_open_input(&d->container, NULL, NULL, NULL);
if (res < 0) {
avformat_free_context(d->container);
d->container = NULL;
avcodec_decoder_release(d);
return NULL;
}
res = avformat_find_stream_info(d->container, NULL);
if (res < 0) {
avcodec_decoder_release(d);
return NULL;
}
if (avcodec_decoder_is_audio(d)) {
// in this case, quit out fast since we won't be decoding this anyway
// (audio is metadata-only)
return d;
}
AVCodecParameters* codec_params = NULL;
for (int i = 0; i < d->container->nb_streams; i++) {
if (d->container->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
codec_params = d->container->streams[i]->codecpar;
d->video_stream_index = i;
break;
}
}
if (!codec_params) {
avcodec_decoder_release(d);
return NULL;
}
AVCodec* codec = avcodec_find_decoder(codec_params->codec_id);
if (!codec) {
avcodec_decoder_release(d);
return NULL;
}
d->codec = avcodec_alloc_context3(codec);
res = avcodec_parameters_to_context(d->codec, codec_params);
if (res < 0) {
avcodec_decoder_release(d);
return NULL;
}
res = avcodec_open2(d->codec, codec, NULL);
if (res < 0) {
avcodec_decoder_release(d);
return NULL;
}
return d;
}
int avcodec_decoder_get_width(const avcodec_decoder d)
{
if (d->codec) {
return d->codec->width;
}
return 0;
}
int avcodec_decoder_get_height(const avcodec_decoder d)
{
if (d->codec) {
return d->codec->height;
}
return 0;
}
int avcodec_decoder_get_orientation(const avcodec_decoder d)
{
if (!d->container) {
return CV_IMAGE_ORIENTATION_TL;
}
if (!d->codec) {
return CV_IMAGE_ORIENTATION_TL;
}
CVImageOrientation orientation = CV_IMAGE_ORIENTATION_TL;
AVDictionaryEntry* tag =
av_dict_get(d->container->streams[d->video_stream_index]->metadata, "rotate", NULL, 0);
if (!tag) {
return orientation;
}
int rotation = atoi(tag->value);
switch (rotation) {
case 90:
orientation = CV_IMAGE_ORIENTATION_RT;
break;
case 180:
orientation = CV_IMAGE_ORIENTATION_BR;
break;
case 270:
orientation = CV_IMAGE_ORIENTATION_LB;
break;
}
return orientation;
}
float avcodec_decoder_get_duration(const avcodec_decoder d)
{
if (d->container) {
return d->container->duration / (float)(AV_TIME_BASE);
}
return 0;
}
const char* avcodec_decoder_get_description(const avcodec_decoder d)
{
if (d->container) {
if (d->container->iformat == &ff_mov_demuxer) {
return "MOV";
}
if (d->container->iformat == &ff_matroska_demuxer) {
return "WEBM";
}
if (d->container->iformat == &ff_mp3_demuxer) {
return "MP3";
}
if (d->container->iformat == &ff_flac_demuxer) {
return "FLAC";
}
if (d->container->iformat == &ff_wav_demuxer) {
return "WAV";
}
if (d->container->iformat == &ff_aac_demuxer) {
return "AAC";
}
if (d->container->iformat == &ff_ogg_demuxer) {
return "OGG";
}
}
return "";
}
static int avcodec_decoder_copy_frame(const avcodec_decoder d, opencv_mat mat, AVFrame* frame)
{
auto cvMat = static_cast<cv::Mat*>(mat);
int res = avcodec_receive_frame(d->codec, frame);
if (res >= 0) {
if (frame->width != cvMat->cols || frame->height != cvMat->rows) {
return -1;
}
int stepSize = 4 * frame->width;
if (frame->width % 32 != 0) {
int width = frame->width + 32 - (frame->width % 32);
stepSize = 4 * width;
}
if (!opencv_mat_set_row_stride(mat, stepSize)) {
return -1;
}
struct SwsContext* sws = sws_getContext(frame->width,
frame->height,
(AVPixelFormat)(frame->format),
frame->width,
frame->height,
AV_PIX_FMT_BGRA,
0,
NULL,
NULL,
NULL);
int linesizes[] = {stepSize, 0, 0, 0};
uint8_t* data_ptrs[] = {cvMat->data, NULL, NULL, NULL};
sws_scale(sws, frame->data, frame->linesize, 0, frame->height, data_ptrs, linesizes);
sws_freeContext(sws);
}
return res;
}
static int avcodec_decoder_decode_packet(const avcodec_decoder d, opencv_mat mat, AVPacket* packet)
{
int res = avcodec_send_packet(d->codec, packet);
if (res < 0) {
return res;
}
AVFrame* frame = av_frame_alloc();
if (!frame) {
return -1;
}
res = avcodec_decoder_copy_frame(d, mat, frame);
av_frame_free(&frame);
return res;
}
bool avcodec_decoder_decode(const avcodec_decoder d, opencv_mat mat)
{
if (!d) {
return false;
}
if (!d->container) {
return false;
}
if (!d->codec) {
return false;
}
AVPacket packet;
bool done = false;
bool success = false;
while (!done) {
int res = av_read_frame(d->container, &packet);
if (res < 0) {
return false;
}
if (packet.stream_index == d->video_stream_index) {
res = avcodec_decoder_decode_packet(d, mat, &packet);
if (res >= 0) {
success = true;
done = true;
}
else if (res != AVERROR(EAGAIN)) {
done = true;
}
}
av_packet_unref(&packet);
}
return success;
}
void avcodec_decoder_release(avcodec_decoder d)
{
if (d->codec) {
avcodec_free_context(&d->codec);
}
if (d->container) {
avformat_close_input(&d->container);
}
if (d->avio) {
avio_flush(d->avio);
av_free(d->avio->buffer);
av_free(d->avio);
}
delete d;
}
|
; ***********************************************************
; * *
; * Copyright, (C) Honeywell Bull Inc., 1987 *
; * *
; * Copyright, (C) Honeywell Information Systems Inc., 1986 *
; * *
; ***********************************************************
; HISTORY COMMENTS:
; 1) change(86-01-03,Flegel), approve(87-07-13,MCR7580),
; audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
; Created.
; 2) change(86-04-13,Flegel), approve(87-07-13,MCR7580),
; audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
; Extracted send_message module.
; 3) change(86-05-07,Lee), approve(87-07-13,MCR7580), audit(87-07-13,Leskiw),
; install(87-08-07,MR12.1-1072):
; Added CREATE_INST, DESTROY_INST, FINDCAPNUM,
; and FINDCAPNAME handlers.
; 4) change(86-05-21,Westcott), approve(87-07-13,MCR7580),
; audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
; Support parameter copying.
; 5) change(86-08-12,Flegel), approve(87-07-13,MCR7580),
; audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
; Installed FG_BREAK and DISCONNECT.
; 6) change(86-08-27,Flegel), approve(87-07-13,MCR7580),
; audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
; Modifications to DISCONNECT.
; 7) change(86-09-02,Flegel), approve(87-07-13,MCR7580),
; audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
; Installed checks for packet mode mincaps.
; 8) chnage(86-09-27,ASmith): Installed SUSPEND handler.
; 9) change(86-10-18,ASmith), approve(87-07-13,MCR7580),
; audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
; Installed connect by name handler.
; 10) change(87-02-10,Flegel), approve(87-07-13,MCR7580),
; audit(87-07-13,Leskiw), install(87-08-07,MR12.1-1072):
; Changed tests for MOWSE active to check
; packetize_flag instead of packet_mode
; END HISTORY COMMENTS
page 55,132
.xlist
; /* : PROCEDURE FUNCTION (user_interrupt_handler):
;
; This is the MOWSE user interrupt handler. This deals with MOWSE requested
; functions.
; */
; /* : NOTES:
;
; Syntax:
; #include <dos.h> mov ah,<MOWSE FUNCTION>
; union REGS *inregs,outregs; int USERINTRPT
; inregs->h.al = <MOWSE FUNCTION>;
; int86(USERINTRPT,in,out);
;
; Input Arguments:
; ah - register determines MOWSE FUNCTION (input)
; si - address of parameter structure
; cx - length of parameter structure
;
; */
;
;/* : RETURNS:
; ax - return code appropriate to command called
;
; If data is required to be passed back, it would be preferrable for the
; generating interrupt to pass addresses as determined by the interrupt handler
; requested and to return only an error code in the AX register.
; */
; /* : NOTES
;
; Each case in this massive switch is primarily concerned with setting up
; the argument list to each of the handlers for that specific case. This may
; include moving data into and out of parameter structures.
; */
include dos.mac
include ws.mac
include ws_stack.mac
include ws_dcls.mac
include ws_error.mac
include wsmincap.mac
page
;**************************************************************
; MAIN
;**************************************************************
dseg
; Public Declarations
public user_interrupt_handler
; Data Declarations
endds
page
;**************************************************************
; MAIN
;**************************************************************
PGROUP GROUP PROG
PROG SEGMENT WORD PUBLIC 'PROG'
ASSUME CS:PGROUP
;--------- External Procedures -----------------------------------------------
extrn packetize_flag:word
extrn bgcount:word
extrn IN_SOFT:word
extrn setup_stack:near
extrn reset_stack:near
extrn send_terminal_data:near
extrn terminal_buffer_check:near
extrn snddat:near
extrn i_execom:near
extrn i_creins:near
extrn i_desins:near
extrn i_fndcnu:near
extrn i_fndcna:near
extrn i_execap:near
extrn i_getbgm:near
extrn i_putbgm:near
extrn i_sendbg:near
extrn i_reset:near
extrn i_sleep:near
extrn i_suspnd:near
extrn i_connect:near
extrn terminate_mowse:near
extrn toggle_debug_switches:near
extrn snddis:near
extrn sndbrk:near
extrn line_break:near
;------ publics --------------------------------------------------------------
public uisystem
user_interrupt_handler proc near
jmp arounds ; provide a signiture for MOWSE
even
uisystem db 0
db 'MOWSE',0
; /* : call setup_stack () */
arounds:
inc CS:IN_SOFT
call setup_stack ;Set up user interrupt stack frame
push bp
; /* : copy parameters from caller's address space into MOWSE address space */
or cx,cx
jbe nocopy ; if no parameter to copy
push ds
pop es
mov si,sireg[bp]
lea di,wsparm[bp]
mov ds,dsreg[bp]
rep movsb ; copy string into this address space
push es
pop ds
; /* : switch (user call type) */
nocopy:
xor cx,cx ; requested MOWSE function:
mov cl,ah ; switch (ah)
sal cx,1
mov di,cx
cmp di,MAXJMP ; ensure request is valid
jbe do_jump ; if request not valid
jmp end_int
do_jump:
mov cx,CS:JMPTBL[di]
jmp cx
; /* : -- case SENDMESSAGE: not used */
SENDMESS:
jmp end_int
; /* : SENDTERM: Not used */
SENDTERM:
jmp end_int
; /* : -- case EXECUTCOM: */
EXECUTCOM:
push bp ; save bp
lea di,wsparm[bp] ; di -> the parameter structure
mov bp,sp ; save SP so we can put it back after the C
push di ; put the parameter pointer on the stack (arg)
call i_execom ; call the procedure
mov sp,bp ; restore the stack position
pop bp ; restore BP
jmp copy_back ; copy resutls back into callers space
; /* : -- case 3: EXECAP */
EXECAP:
push bp
lea di,wsparm[bp]
mov cx,cxreg[bp]
mov bp,sp
push cx
push di
call i_execap
mov sp,bp
pop bp
jmp copy_back
; /* : -- case 4: CREATE_INSTANCE */
CREATE_INST:
push bp
lea di,wsparm[bp]
mov ax,bp
mov bp,sp
push di ; push address of copy of caller's mcb
push ax ; push address of stack
call i_creins
mov sp,bp
pop bp
jmp copy_back
; /* : -- case 5: DESTROY_INSTANCE */
DESTROY_INST:
push bp
lea di,wsparm[bp]
mov bp,sp
push di
call i_desins
mov sp,bp
pop bp
jmp copy_back
; /* : -- case 6: FINDCAPNAME */
FINDCAPNAME:
push bp
lea di,wsparm[bp]
mov bp,sp
push di
call i_fndcna
mov sp,bp
pop bp
jmp copy_back
; /* : -- case 7: FINDCAPNUM */
FINDCAPNUM:
push bp
lea di,wsparm[bp]
mov bp,sp
push di
call i_fndcnu
mov sp,bp
pop bp
jmp copy_back
; /* : -- case 8: Debug packet switches - undocumented */
L08:
mov ax,wsparm[bp]
push bp
push ax
call toggle_debug_switches
pop bp
jmp copy_back
; /* : -- case GETTDATA: Get data from terminal buffer */
GETTDATA:
lea bx,wsparm[bp]
mov cx,bgcount ; see if background messages are pending
mov gbpflag[bx],cx
mov di,getlbp[bx] ;di = address of caller's buffer
mov cx,getlbs[bx] ;cx = size of caller's buffer
push es
mov es,dsreg[bp]
push bp ;check for foreground data
call terminal_buffer_check
pop bp
pop es
cmp cx,0 ;if no data then check the mode flag
jne data_ready
test packetize_flag,1 ;if clear, then set minor cap to mowse_detached
jne set_attached ;else set minor to mowse_attached
mov ax,MOWSE_DETACHED
jmp data_ready
set_attached:
mov ax,MOWSE_ATTACHED
data_ready:
mov gmincap[bx],ax
mov ax,cx ;return number of chars obtained to caller
mov cx,gettlen
jmp copy_back
; /* : -- case PUTTDATA : Send data over foreground channel */
PUTDATA:
lea bx,wsparm[bp]
test packetize_flag,1
jz nopkt
; /* : --- if in packet mode create send packet structure for snddat */
mov ax,minor_cap[bx]
lea si,pkthdr[bp]
mov [si],al ; insert minor cap in packet header
mov datap[bp],si ; insert pointer to packet header
mov datal[bp],1 ; insert length of packet header
lea si,puttstr[bx]
mov datap+2[bp],si ; insert pointer to data string
mov ax,putstrl[bx]
mov datal+2[bp],ax ; insert length of data string
mov datac[bp],2 ; insert count of packet pieces
mov chan[bp],FG ; insert channel id (foreground)
lea bx,chan[bp]
; /* : --- give the packet to the protocol to send */
jmp send_pkt ; give data to protocol
; /* : -- else, just transmit the data */
nopkt:
push bp
mov cx,putstrl[bx]
lea si,puttstr[bx]
mov bp,sp
call send_terminal_data
mov sp,bp
pop bp
jmp end_int
; /* : -- case GETBGMES: */
GETBGMES:
push bp
lea di,wsparm[bp]
mov bp,sp
push di ; push address of parameter structure
call i_getbgm ; get background message
mov sp,bp
pop bp
jmp copy_back
; /* : -- case PUTBGMES: */
PUTBGMES:
push bp
lea di,wsparm[bp]
mov bp,sp
push di ; push address of parameter structure
call i_putbgm ; put background message
mov sp,bp
pop bp
jmp copy_back
; /* : -- case SENDBG: */
SENDBG:
push bp
lea di,wsparm[bp]
mov cx,cxreg[bp]
mov bp,sp
push cx ; push length of message
push di ; push address of message
call i_sendbg
mov sp,bp
pop bp
jmp copy_back
; /* : -- case L14: Nothing */
L14:
mov bx,wsparm[bp]
mov ax,[bx]
jmp end_int
; /* : -- case RESET: */
RESET:
push bp
lea di,wsparm[bp]
mov cx,cxreg[bp]
mov bp,sp
push cx ; push length of message
push di
call i_reset
mov sp,bp
pop bp
jmp copy_back
; /* : -- case SLEEP */
SLEEP:
push bp
lea di,wsparm[bp]
mov bp,sp
push di
call i_sleep
mov sp,bp
pop bp
jmp copy_back
SUSPEND:
push bp
lea di,wsparm[bp]
mov bp,sp
push di
call i_suspnd
mov sp,bp
pop bp
jmp copy_back
CONNECT:
push bp
lea di,wsparm[bp]
mov bp,sp
push di
call i_connect
mov sp,bp
pop bp
jmp copy_back
; /* : -- case DISCONNECT */
DISCONNECT:
test wsparm[bp],1 ; but if force is requested, continue
jne discon_ok
test packetize_flag,1 ; if in packet mode then fail
je discon_ok
push bp
mov bp,sp
call snddis ; establish disconnection attempt
mov sp,bp
pop bp
jmp copy_back
discon_ok:
push bp
mov bp,sp
call terminate_mowse ; remove mowse from the PC
mov sp,bp
pop bp
jmp copy_back
; /* : -- case FOREBREAK: */
FOREBREAK:
xor ax,ax
test packetize_flag,1 ; Packet mode ?
jne soft_brk ; YES - Protocol break
call line_break ; NO - Line break
jmp copy_back
soft_brk:
push bp
mov bp,sp
call sndbrk ; call to send break to Multics
mov sp,bp
pop bp
jmp copy_back
; /* : send_pkt : give a packet structure to the mowse protocol for packetizing
; and subsequent trasmission */
send_pkt:
push bp
lea si,datap[bp]
lea di,datal[bp]
mov ax,chan[bp]
mov cx,datac[bp]
mov bp,sp
push di
push si
push cx
push ax
call snddat ; send the packet to the protocol
mov sp,bp
pop bp
cmp ax,1
je send_pkt ; if window full, try again
mov axreg[bp],ax ; save return code
jmp end_int
; /* : COPY_BACK: copy parameter structure back to user's address space before
; returning from interrupt. */
copy_back:
mov axreg[bp],ax ; save return code
mov cx,cxreg[bp]
or cx,cx
jbe end_int ; if no parameter to copy
mov di,sireg[bp]
lea si,wsparm[bp]
mov es,dsreg[bp]
rep movsb ; copy string into this address space
; /* : End of interrupt: call reset_stack(), return from interrupt */
end_int:
pop bp ; Put the stack to where it was
call reset_stack ; before the interrupt
dec CS:IN_SOFT
iret
; Switching Table
JMPTBL dw pgroup:SENDMESS
dw pgroup:SENDTERM
dw pgroup:EXECUTCOM
dw pgroup:EXECAP
dw pgroup:CREATE_INST
dw pgroup:DESTROY_INST
dw pgroup:FINDCAPNAME
dw pgroup:FINDCAPNUM
dw pgroup:L08
dw pgroup:GETTDATA
dw pgroup:PUTDATA
dw pgroup:GETBGMES
dw pgroup:PUTBGMES
dw pgroup:SENDBG
dw pgroup:L14
dw pgroup:RESET
dw pgroup:SLEEP
dw pgroup:DISCONNECT
dw pgroup:FOREBREAK
dw pgroup:SUSPEND
dw pgroup:CONNECT
JMP_END dw 0
MAXJMP = JMP_END - JMPTBL
; /* : END user_interrupt_handler */
user_interrupt_handler endp
endps
end
|
; wrapper for function pointers
PUBLIC vfscanf
EXTERN vfscanf_callee
EXTERN ASMDISP_VFSCANF_CALLEE
.vfscanf
pop hl
pop bc
pop de
pop ix
push hl
push de
push bc
push hl
jp vfscanf_callee + ASMDISP_VFSCANF_CALLEE
|
//------------------------------------------------------------------------------------------
// File: D3DDevicesManager.cpp
//
// Author: Gabriel Clavero
//------------------------------------------------------------------------------------------
#include "D3DDevicesManager.h"
namespace DTFramework
{
D3DDevicesManager::D3DDevicesManager()
: m_device11(0), m_deviceContext(0), m_swapChain(0), m_device10(0), m_renderTargetView(0), m_depthStencilView(0),
m_vsync(0), m_MSsampleCount(1), m_MSqualityLevel(0), m_font(0), m_ready(false)
{
}
D3DDevicesManager::~D3DDevicesManager()
{
SAFE_RELEASE(m_font);
SAFE_RELEASE(m_renderTargetView);
SAFE_RELEASE(m_depthStencilView);
SAFE_RELEASE(m_swapChain);
SAFE_RELEASE(m_deviceContext);
//descomentar para testear memory leaks de interfaces COM
//no olvidar setear los flags de creación del device con D3D11_CREATE_DEVICE_DEBUG
/*ID3D11Debug *debugDevice = nullptr;
HRESULT result = m_device11->QueryInterface(__uuidof(ID3D11Debug), reinterpret_cast<void **>(&debugDevice));
result = debugDevice->ReportLiveDeviceObjects(D3D11_RLDO_DETAIL);
SAFE_RELEASE(debugDevice);*/
SAFE_RELEASE(m_device11);
SAFE_RELEASE(m_device10);
}
HRESULT D3DDevicesManager::Init(const DXGI_MODE_DESC &mode, const bool windowed, const bool vsync, const bool aa,
const HWND window, const UINT totalBackBuffers)
{
_ASSERT(!m_ready);
if(m_ready) {
MiscErrorWarning(INVALID_FUNCTION_CALL, L"D3DDevicesManager::Init");
return E_FAIL;
}
HRESULT hr;
//vsync
m_vsync = vsync;
//d3d devices y swapchain
if(FAILED( hr = PrepareDevicesAndSwapChain(mode, windowed, aa, window, totalBackBuffers) ))
return hr;
//obtener un render target view del backbuffer
ID3D11Texture2D *backBuffer = NULL;
if(FAILED(hr = m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID *)&backBuffer)))
{
DXGI_D3D_ErrorWarning(hr, L"D3DDevicesManager::Init-->GetBuffer");
return hr;
}
if(FAILED(hr = m_device11->CreateRenderTargetView(backBuffer, NULL, &m_renderTargetView)))
{
SAFE_RELEASE(backBuffer);
DXGI_D3D_ErrorWarning(hr, L"D3DDevicesManager::Init-->CreateRenderTargetView");
return hr;
}
//la llamada a GetBuffer incrementa en 1 las referencias al back buffer.
SAFE_RELEASE(backBuffer);
//depth stencil buffer
if(FAILED( hr = PrepareDepthStencilBuffer() )) return hr;
//bindear las views al Output Merger Stage del pipeline
m_deviceContext->OMSetRenderTargets(1, &m_renderTargetView, m_depthStencilView);
//view port
if(FAILED( hr = PrepareViewPort() )) return hr;
//font
IFW1Factory *FW1factory;
if(FAILED(hr = FW1CreateFactory(FW1_VERSION, &FW1factory))) return hr;
if(FAILED(hr = FW1factory->CreateFontWrapper(m_device11, L"Arial", &m_font))) {
SAFE_RELEASE(FW1factory);
return hr;
}
SAFE_RELEASE(FW1factory);
m_ready = true;
return hr;
}
//creamos el ID3D10Device, ID3D11Device, ID3D11DeviceContext, y IDXGISwapChain. Utilizamos las opciones que escogió el usuario en el SettingsDialog y en el EngineConfig
HRESULT D3DDevicesManager::PrepareDevicesAndSwapChain(const DXGI_MODE_DESC &mode, const bool windowed, const bool aa, const HWND window, const UINT totalBackBuffers)
{
HRESULT hr;
DXGI_SWAP_CHAIN_DESC sd;
//copiamos los parametros elegidos en el SettingsDialog
if(memcpy_s(&(sd.BufferDesc), sizeof(DXGI_MODE_DESC), &mode, sizeof(DXGI_MODE_DESC)) != 0) {
MiscErrorWarning(MEMCPY);
return E_FAIL;
}
//no multisampling
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = totalBackBuffers;
sd.OutputWindow = window;
sd.Windowed = windowed;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
//refresh rate. vsync activado => 60 cuadros por segundo. Desactivado => se dibujará tantas veces por segundo como se pueda
if(m_vsync) {
sd.BufferDesc.RefreshRate.Numerator = 0;
sd.BufferDesc.RefreshRate.Denominator = 1;
}
//feature level
D3D_FEATURE_LEVEL featureLevel[1] = {D3D_FEATURE_LEVEL_11_0};
//flags
UINT createDeviceFlags = D3D11_CREATE_DEVICE_SINGLETHREADED; // | D3D11_CREATE_DEVICE_DEBUG;
#if defined(DEBUG)
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
// multisampling o antialiasing.
if(aa)
{
//creamos un device temporal para ver si el antialiasing requerido está disponible
ID3D11Device *device;
ID3D11DeviceContext *context;
hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevel, 1, D3D11_SDK_VERSION, &device, NULL, &context);
if(FAILED(hr)) {
DXGI_D3D_ErrorWarning(hr, L"D3DDevicesManager::PrepareDevicesAndSwapChain-->D3D11CreateDevice");
return hr;
}
UINT qualityLevels;
//chequeamos que esté disponible en la pc actual y recordar que el depthbuffer debe tener los mismos valores
if(FAILED( hr = device->CheckMultisampleQualityLevels(sd.BufferDesc.Format, SAMPLE_COUNT, &qualityLevels) ) ) {
DXGI_D3D_ErrorWarning(hr, L"D3DDevicesManager::PrepareDevicesAndSwapChain-->ID3D11Device::CheckMultisampleQualityLevels");
device->Release();
context->Release();
return hr;
}
//si devolvió al menos un quality level usamos el SAMPLE_COUNT, sino 1. Ver DXGI_SAMPLE_DESC en la documentación de directx
sd.SampleDesc.Count = qualityLevels == 0 ? 1 : SAMPLE_COUNT;
sd.SampleDesc.Quality = 0;
//guardar estos valores para que el depth buffer utilice los mismos que el back buffer
m_MSsampleCount = sd.SampleDesc.Count;
m_MSqualityLevel = sd.SampleDesc.Quality;
device->Release();
context->Release();
}
//crear el swap chain, device y device context de direct3d11.
hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevel, 1,
D3D11_SDK_VERSION, &sd, &m_swapChain, &m_device11, NULL, &m_deviceContext);
if(FAILED(hr)) {
DXGI_D3D_ErrorWarning(hr, L"D3DDevicesManager::PrepareDevicesAndSwapChain-->D3D11CreateDeviceAndSwapChain");
return hr;
}
//en algunas partes también necesitaremos un ID3D10Device. Aquí lo creamos.
createDeviceFlags = D3D10_CREATE_DEVICE_SINGLETHREADED;
#if defined(DEBUG)
createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG;
#endif
hr = D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, D3D10_SDK_VERSION, &m_device10);
if(FAILED(hr))
DXGI_D3D_ErrorWarning(hr, L"D3DDevicesManager::PrepareDevicesAndSwapChain-->D3D10CreateDevice");
return hr;
}
HRESULT D3DDevicesManager::PrepareDepthStencilBuffer()
{
//crear el depth stencil buffer usando un texture resource
HRESULT hr;
DXGI_SWAP_CHAIN_DESC sd;
if(FAILED( hr = m_swapChain->GetDesc(&sd) )) {
DXGI_D3D_ErrorWarning(hr, L"PrepareDepthStencilBufferAndView --> IDXGISwapChain::GetDesc");
return hr;
}
D3D11_TEXTURE2D_DESC descDepth;
descDepth.Width = sd.BufferDesc.Width;
descDepth.Height = sd.BufferDesc.Height;
descDepth.MipLevels = 1; //para el depth buffer con un mip map level nos basta
descDepth.ArraySize = 1;
descDepth.Format = DXGI_FORMAT_D32_FLOAT; //no stencil buffer
descDepth.SampleDesc.Count = m_MSsampleCount;
descDepth.SampleDesc.Quality = m_MSqualityLevel;
descDepth.Usage = D3D11_USAGE_DEFAULT;
descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL;
descDepth.CPUAccessFlags = 0;
descDepth.MiscFlags = 0;
ID3D11Texture2D *depthStencilBuffer;
if(FAILED(hr = m_device11->CreateTexture2D( &descDepth, NULL, &depthStencilBuffer ))) {
DXGI_D3D_ErrorWarning(hr, L"PrepareDepthStencilBufferAndView --> ID3D11Device::CreateTexture2D");
return hr;
}
//crear la view del depthstencil texture
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
dsvDesc.Format = DXGI_FORMAT_D32_FLOAT;
dsvDesc.ViewDimension = descDepth.SampleDesc.Count > 1 ? D3D11_DSV_DIMENSION_TEXTURE2DMS : D3D11_DSV_DIMENSION_TEXTURE2D;;
dsvDesc.Texture2D.MipSlice = 0;
dsvDesc.Flags = 0;
if( FAILED(hr = m_device11->CreateDepthStencilView(depthStencilBuffer, &dsvDesc, &m_depthStencilView)) )
DXGI_D3D_ErrorWarning(hr, L"PrepareDepthStencilBufferAndView --> ID3D11Device::CreateDepthStencilView");
depthStencilBuffer->Release(); //la view guarda una referencia a la textura, asi que podemos quitar esta
return hr;
}
HRESULT D3DDevicesManager::PrepareViewPort()
{
HRESULT hr;
DXGI_SWAP_CHAIN_DESC sd;
if(FAILED( hr = m_swapChain->GetDesc(&sd) )) {
DXGI_D3D_ErrorWarning(hr, L"PrepareViewPort --> IDXGISwapChain::GetDesc");
return hr;
}
m_vp.TopLeftX = 0;
m_vp.TopLeftY = 0;
m_vp.Width = static_cast<float>(sd.BufferDesc.Width);
m_vp.Height = static_cast<float>(sd.BufferDesc.Height);
m_vp.MinDepth = 0.0f;
m_vp.MaxDepth = 1.0f;
m_deviceContext->RSSetViewports(1, &m_vp);
return hr;
}
} |
#pragma once
#include <utility>
NS_HWM_BEGIN
namespace ArrayRefDetail {
template<class T>
struct DummyArray
{
static T value;
static T * GetAddress() { return &value; }
};
template<class T>
T DummyArray<T>::value = {};
} // ::ArrayRefDetail
//! 配列やvectorクラスなど、メモリ上にオブジェクトを連続して配置するクラスへのアクセスを抽象化する。
template<class T>
struct ArrayRef
{
typedef ArrayRef<T> this_type;
typedef T value_type;
typedef size_t size_type;
typedef T * iterator;
typedef T const * const_iterator;
//! デフォルトコンストラクタ
/*!
@post arr_ != nullptr
@post length == 0
*/
ArrayRef()
: arr_(ArrayRefDetail::DummyArray<T>::GetAddress())
, length_(0)
{}
//! Iteratorのペアから構築するコンストラクタ
/*!
@tparam ContigousInputIterator std::vectorやstd::string(C++11以降)のイテレータなど、\n
データがメモリ上で連続していることが保証されているクラスのイテレータ。\n
この要件を満たすイテレータは`Contigous Iterator`と呼ばれたりする。\n
@note ランダムアクセスイテレータであっても、リングバッファのようなクラスのイテレータは\n
メモリ上でデータが連続していないため、このクラスでは使用してはいけない。\n
テンプレート引数ContiguousInputIteratorが`Contiguous Iterator`要件を満たすかどうかを\n
型レベルでチェックする仕組みが現在無いため、実行時アサーションでメモリの連続性をチェックしている。
*/
template<class ContigousInputIterator>
ArrayRef(ContigousInputIterator begin, ContigousInputIterator end)
: arr_(nullptr)
, length_(0)
{
if(begin == end) {
arr_ = ArrayRefDetail::DummyArray<T>::GetAddress();
length_ = 0;
} else {
arr_ = &*begin;
length_ = end - begin;
assert(((&*(end - 1)) - &*begin == length_ - 1) &&
"Iterator must be a Contiguous Iterator"
);
}
}
template<class Container>
ArrayRef(Container &c)
: ArrayRef(std::begin(c), std::end(c))
{}
void swap(this_type &rhs)
{
std::swap(arr_, rhs.arr_);
std::swap(length_, rhs.length_);
}
size_type size() const { return length_; }
bool empty() const { return length_ == 0; }
T * data() { return arr_; }
T const * data() const { return arr_; }
T & operator[](size_type index) { return arr_[index]; }
T const & operator[](size_type index) const { return arr_[index]; }
T & front() { assert(length_ > 0); return arr_[0]; }
T const & front() const { assert(length_ > 0); return arr_[0]; }
T & back() { assert(length_ > 0); return arr_[length_ - 1]; }
T const & back() const { assert(length_ > 0); return arr_[length_ - 1]; }
T * begin() { return arr_; }
T const * begin() const { return arr_; }
T const * cbegin() const { return arr_; }
T * end() { return arr_ + length_; }
T const * end() const { return arr_ + length_; }
T const * cend() const { return arr_ + length_; }
private:
T * arr_;
size_type length_;
};
NS_HWM_END
|
OPTION DOTNAME
.text$ SEGMENT ALIGN(64) 'CODE'
PUBLIC aesni_encrypt
ALIGN 16
aesni_encrypt PROC PUBLIC
movups xmm2,XMMWORD PTR[rcx]
mov eax,DWORD PTR[240+r8]
movups xmm0,XMMWORD PTR[r8]
movups xmm1,XMMWORD PTR[16+r8]
lea r8,QWORD PTR[32+r8]
xorps xmm2,xmm0
$L$oop_enc1_1::
DB 102,15,56,220,209
dec eax
movups xmm1,XMMWORD PTR[r8]
lea r8,QWORD PTR[16+r8]
jnz $L$oop_enc1_1
DB 102,15,56,221,209
movups XMMWORD PTR[rdx],xmm2
DB 0F3h,0C3h ;repret
aesni_encrypt ENDP
PUBLIC aesni_decrypt
ALIGN 16
aesni_decrypt PROC PUBLIC
movups xmm2,XMMWORD PTR[rcx]
mov eax,DWORD PTR[240+r8]
movups xmm0,XMMWORD PTR[r8]
movups xmm1,XMMWORD PTR[16+r8]
lea r8,QWORD PTR[32+r8]
xorps xmm2,xmm0
$L$oop_dec1_2::
DB 102,15,56,222,209
dec eax
movups xmm1,XMMWORD PTR[r8]
lea r8,QWORD PTR[16+r8]
jnz $L$oop_dec1_2
DB 102,15,56,223,209
movups XMMWORD PTR[rdx],xmm2
DB 0F3h,0C3h ;repret
aesni_decrypt ENDP
ALIGN 16
_aesni_encrypt3 PROC PRIVATE
movups xmm0,XMMWORD PTR[rcx]
shr eax,1
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
xorps xmm3,xmm0
xorps xmm4,xmm0
movups xmm0,XMMWORD PTR[rcx]
$L$enc_loop3::
DB 102,15,56,220,209
DB 102,15,56,220,217
dec eax
DB 102,15,56,220,225
movups xmm1,XMMWORD PTR[16+rcx]
DB 102,15,56,220,208
DB 102,15,56,220,216
lea rcx,QWORD PTR[32+rcx]
DB 102,15,56,220,224
movups xmm0,XMMWORD PTR[rcx]
jnz $L$enc_loop3
DB 102,15,56,220,209
DB 102,15,56,220,217
DB 102,15,56,220,225
DB 102,15,56,221,208
DB 102,15,56,221,216
DB 102,15,56,221,224
DB 0F3h,0C3h ;repret
_aesni_encrypt3 ENDP
ALIGN 16
_aesni_decrypt3 PROC PRIVATE
movups xmm0,XMMWORD PTR[rcx]
shr eax,1
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
xorps xmm3,xmm0
xorps xmm4,xmm0
movups xmm0,XMMWORD PTR[rcx]
$L$dec_loop3::
DB 102,15,56,222,209
DB 102,15,56,222,217
dec eax
DB 102,15,56,222,225
movups xmm1,XMMWORD PTR[16+rcx]
DB 102,15,56,222,208
DB 102,15,56,222,216
lea rcx,QWORD PTR[32+rcx]
DB 102,15,56,222,224
movups xmm0,XMMWORD PTR[rcx]
jnz $L$dec_loop3
DB 102,15,56,222,209
DB 102,15,56,222,217
DB 102,15,56,222,225
DB 102,15,56,223,208
DB 102,15,56,223,216
DB 102,15,56,223,224
DB 0F3h,0C3h ;repret
_aesni_decrypt3 ENDP
ALIGN 16
_aesni_encrypt4 PROC PRIVATE
movups xmm0,XMMWORD PTR[rcx]
shr eax,1
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
xorps xmm3,xmm0
xorps xmm4,xmm0
xorps xmm5,xmm0
movups xmm0,XMMWORD PTR[rcx]
$L$enc_loop4::
DB 102,15,56,220,209
DB 102,15,56,220,217
dec eax
DB 102,15,56,220,225
DB 102,15,56,220,233
movups xmm1,XMMWORD PTR[16+rcx]
DB 102,15,56,220,208
DB 102,15,56,220,216
lea rcx,QWORD PTR[32+rcx]
DB 102,15,56,220,224
DB 102,15,56,220,232
movups xmm0,XMMWORD PTR[rcx]
jnz $L$enc_loop4
DB 102,15,56,220,209
DB 102,15,56,220,217
DB 102,15,56,220,225
DB 102,15,56,220,233
DB 102,15,56,221,208
DB 102,15,56,221,216
DB 102,15,56,221,224
DB 102,15,56,221,232
DB 0F3h,0C3h ;repret
_aesni_encrypt4 ENDP
ALIGN 16
_aesni_decrypt4 PROC PRIVATE
movups xmm0,XMMWORD PTR[rcx]
shr eax,1
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
xorps xmm3,xmm0
xorps xmm4,xmm0
xorps xmm5,xmm0
movups xmm0,XMMWORD PTR[rcx]
$L$dec_loop4::
DB 102,15,56,222,209
DB 102,15,56,222,217
dec eax
DB 102,15,56,222,225
DB 102,15,56,222,233
movups xmm1,XMMWORD PTR[16+rcx]
DB 102,15,56,222,208
DB 102,15,56,222,216
lea rcx,QWORD PTR[32+rcx]
DB 102,15,56,222,224
DB 102,15,56,222,232
movups xmm0,XMMWORD PTR[rcx]
jnz $L$dec_loop4
DB 102,15,56,222,209
DB 102,15,56,222,217
DB 102,15,56,222,225
DB 102,15,56,222,233
DB 102,15,56,223,208
DB 102,15,56,223,216
DB 102,15,56,223,224
DB 102,15,56,223,232
DB 0F3h,0C3h ;repret
_aesni_decrypt4 ENDP
ALIGN 16
_aesni_encrypt6 PROC PRIVATE
movups xmm0,XMMWORD PTR[rcx]
shr eax,1
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
pxor xmm3,xmm0
DB 102,15,56,220,209
pxor xmm4,xmm0
DB 102,15,56,220,217
pxor xmm5,xmm0
DB 102,15,56,220,225
pxor xmm6,xmm0
DB 102,15,56,220,233
pxor xmm7,xmm0
dec eax
DB 102,15,56,220,241
movups xmm0,XMMWORD PTR[rcx]
DB 102,15,56,220,249
jmp $L$enc_loop6_enter
ALIGN 16
$L$enc_loop6::
DB 102,15,56,220,209
DB 102,15,56,220,217
dec eax
DB 102,15,56,220,225
DB 102,15,56,220,233
DB 102,15,56,220,241
DB 102,15,56,220,249
$L$enc_loop6_enter::
movups xmm1,XMMWORD PTR[16+rcx]
DB 102,15,56,220,208
DB 102,15,56,220,216
lea rcx,QWORD PTR[32+rcx]
DB 102,15,56,220,224
DB 102,15,56,220,232
DB 102,15,56,220,240
DB 102,15,56,220,248
movups xmm0,XMMWORD PTR[rcx]
jnz $L$enc_loop6
DB 102,15,56,220,209
DB 102,15,56,220,217
DB 102,15,56,220,225
DB 102,15,56,220,233
DB 102,15,56,220,241
DB 102,15,56,220,249
DB 102,15,56,221,208
DB 102,15,56,221,216
DB 102,15,56,221,224
DB 102,15,56,221,232
DB 102,15,56,221,240
DB 102,15,56,221,248
DB 0F3h,0C3h ;repret
_aesni_encrypt6 ENDP
ALIGN 16
_aesni_decrypt6 PROC PRIVATE
movups xmm0,XMMWORD PTR[rcx]
shr eax,1
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
pxor xmm3,xmm0
DB 102,15,56,222,209
pxor xmm4,xmm0
DB 102,15,56,222,217
pxor xmm5,xmm0
DB 102,15,56,222,225
pxor xmm6,xmm0
DB 102,15,56,222,233
pxor xmm7,xmm0
dec eax
DB 102,15,56,222,241
movups xmm0,XMMWORD PTR[rcx]
DB 102,15,56,222,249
jmp $L$dec_loop6_enter
ALIGN 16
$L$dec_loop6::
DB 102,15,56,222,209
DB 102,15,56,222,217
dec eax
DB 102,15,56,222,225
DB 102,15,56,222,233
DB 102,15,56,222,241
DB 102,15,56,222,249
$L$dec_loop6_enter::
movups xmm1,XMMWORD PTR[16+rcx]
DB 102,15,56,222,208
DB 102,15,56,222,216
lea rcx,QWORD PTR[32+rcx]
DB 102,15,56,222,224
DB 102,15,56,222,232
DB 102,15,56,222,240
DB 102,15,56,222,248
movups xmm0,XMMWORD PTR[rcx]
jnz $L$dec_loop6
DB 102,15,56,222,209
DB 102,15,56,222,217
DB 102,15,56,222,225
DB 102,15,56,222,233
DB 102,15,56,222,241
DB 102,15,56,222,249
DB 102,15,56,223,208
DB 102,15,56,223,216
DB 102,15,56,223,224
DB 102,15,56,223,232
DB 102,15,56,223,240
DB 102,15,56,223,248
DB 0F3h,0C3h ;repret
_aesni_decrypt6 ENDP
ALIGN 16
_aesni_encrypt8 PROC PRIVATE
movups xmm0,XMMWORD PTR[rcx]
shr eax,1
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
xorps xmm3,xmm0
DB 102,15,56,220,209
pxor xmm4,xmm0
DB 102,15,56,220,217
pxor xmm5,xmm0
DB 102,15,56,220,225
pxor xmm6,xmm0
DB 102,15,56,220,233
pxor xmm7,xmm0
dec eax
DB 102,15,56,220,241
pxor xmm8,xmm0
DB 102,15,56,220,249
pxor xmm9,xmm0
movups xmm0,XMMWORD PTR[rcx]
DB 102,68,15,56,220,193
DB 102,68,15,56,220,201
movups xmm1,XMMWORD PTR[16+rcx]
jmp $L$enc_loop8_enter
ALIGN 16
$L$enc_loop8::
DB 102,15,56,220,209
DB 102,15,56,220,217
dec eax
DB 102,15,56,220,225
DB 102,15,56,220,233
DB 102,15,56,220,241
DB 102,15,56,220,249
DB 102,68,15,56,220,193
DB 102,68,15,56,220,201
movups xmm1,XMMWORD PTR[16+rcx]
$L$enc_loop8_enter::
DB 102,15,56,220,208
DB 102,15,56,220,216
lea rcx,QWORD PTR[32+rcx]
DB 102,15,56,220,224
DB 102,15,56,220,232
DB 102,15,56,220,240
DB 102,15,56,220,248
DB 102,68,15,56,220,192
DB 102,68,15,56,220,200
movups xmm0,XMMWORD PTR[rcx]
jnz $L$enc_loop8
DB 102,15,56,220,209
DB 102,15,56,220,217
DB 102,15,56,220,225
DB 102,15,56,220,233
DB 102,15,56,220,241
DB 102,15,56,220,249
DB 102,68,15,56,220,193
DB 102,68,15,56,220,201
DB 102,15,56,221,208
DB 102,15,56,221,216
DB 102,15,56,221,224
DB 102,15,56,221,232
DB 102,15,56,221,240
DB 102,15,56,221,248
DB 102,68,15,56,221,192
DB 102,68,15,56,221,200
DB 0F3h,0C3h ;repret
_aesni_encrypt8 ENDP
ALIGN 16
_aesni_decrypt8 PROC PRIVATE
movups xmm0,XMMWORD PTR[rcx]
shr eax,1
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
xorps xmm3,xmm0
DB 102,15,56,222,209
pxor xmm4,xmm0
DB 102,15,56,222,217
pxor xmm5,xmm0
DB 102,15,56,222,225
pxor xmm6,xmm0
DB 102,15,56,222,233
pxor xmm7,xmm0
dec eax
DB 102,15,56,222,241
pxor xmm8,xmm0
DB 102,15,56,222,249
pxor xmm9,xmm0
movups xmm0,XMMWORD PTR[rcx]
DB 102,68,15,56,222,193
DB 102,68,15,56,222,201
movups xmm1,XMMWORD PTR[16+rcx]
jmp $L$dec_loop8_enter
ALIGN 16
$L$dec_loop8::
DB 102,15,56,222,209
DB 102,15,56,222,217
dec eax
DB 102,15,56,222,225
DB 102,15,56,222,233
DB 102,15,56,222,241
DB 102,15,56,222,249
DB 102,68,15,56,222,193
DB 102,68,15,56,222,201
movups xmm1,XMMWORD PTR[16+rcx]
$L$dec_loop8_enter::
DB 102,15,56,222,208
DB 102,15,56,222,216
lea rcx,QWORD PTR[32+rcx]
DB 102,15,56,222,224
DB 102,15,56,222,232
DB 102,15,56,222,240
DB 102,15,56,222,248
DB 102,68,15,56,222,192
DB 102,68,15,56,222,200
movups xmm0,XMMWORD PTR[rcx]
jnz $L$dec_loop8
DB 102,15,56,222,209
DB 102,15,56,222,217
DB 102,15,56,222,225
DB 102,15,56,222,233
DB 102,15,56,222,241
DB 102,15,56,222,249
DB 102,68,15,56,222,193
DB 102,68,15,56,222,201
DB 102,15,56,223,208
DB 102,15,56,223,216
DB 102,15,56,223,224
DB 102,15,56,223,232
DB 102,15,56,223,240
DB 102,15,56,223,248
DB 102,68,15,56,223,192
DB 102,68,15,56,223,200
DB 0F3h,0C3h ;repret
_aesni_decrypt8 ENDP
PUBLIC aesni_ecb_encrypt
ALIGN 16
aesni_ecb_encrypt PROC PUBLIC
mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
mov QWORD PTR[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_aesni_ecb_encrypt::
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD PTR[40+rsp]
lea rsp,QWORD PTR[((-88))+rsp]
movaps XMMWORD PTR[rsp],xmm6
movaps XMMWORD PTR[16+rsp],xmm7
movaps XMMWORD PTR[32+rsp],xmm8
movaps XMMWORD PTR[48+rsp],xmm9
$L$ecb_enc_body::
and rdx,-16
jz $L$ecb_ret
mov eax,DWORD PTR[240+rcx]
movups xmm0,XMMWORD PTR[rcx]
mov r11,rcx
mov r10d,eax
test r8d,r8d
jz $L$ecb_decrypt
cmp rdx,080h
jb $L$ecb_enc_tail
movdqu xmm2,XMMWORD PTR[rdi]
movdqu xmm3,XMMWORD PTR[16+rdi]
movdqu xmm4,XMMWORD PTR[32+rdi]
movdqu xmm5,XMMWORD PTR[48+rdi]
movdqu xmm6,XMMWORD PTR[64+rdi]
movdqu xmm7,XMMWORD PTR[80+rdi]
movdqu xmm8,XMMWORD PTR[96+rdi]
movdqu xmm9,XMMWORD PTR[112+rdi]
lea rdi,QWORD PTR[128+rdi]
sub rdx,080h
jmp $L$ecb_enc_loop8_enter
ALIGN 16
$L$ecb_enc_loop8::
movups XMMWORD PTR[rsi],xmm2
mov rcx,r11
movdqu xmm2,XMMWORD PTR[rdi]
mov eax,r10d
movups XMMWORD PTR[16+rsi],xmm3
movdqu xmm3,XMMWORD PTR[16+rdi]
movups XMMWORD PTR[32+rsi],xmm4
movdqu xmm4,XMMWORD PTR[32+rdi]
movups XMMWORD PTR[48+rsi],xmm5
movdqu xmm5,XMMWORD PTR[48+rdi]
movups XMMWORD PTR[64+rsi],xmm6
movdqu xmm6,XMMWORD PTR[64+rdi]
movups XMMWORD PTR[80+rsi],xmm7
movdqu xmm7,XMMWORD PTR[80+rdi]
movups XMMWORD PTR[96+rsi],xmm8
movdqu xmm8,XMMWORD PTR[96+rdi]
movups XMMWORD PTR[112+rsi],xmm9
lea rsi,QWORD PTR[128+rsi]
movdqu xmm9,XMMWORD PTR[112+rdi]
lea rdi,QWORD PTR[128+rdi]
$L$ecb_enc_loop8_enter::
call _aesni_encrypt8
sub rdx,080h
jnc $L$ecb_enc_loop8
movups XMMWORD PTR[rsi],xmm2
mov rcx,r11
movups XMMWORD PTR[16+rsi],xmm3
mov eax,r10d
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
movups XMMWORD PTR[64+rsi],xmm6
movups XMMWORD PTR[80+rsi],xmm7
movups XMMWORD PTR[96+rsi],xmm8
movups XMMWORD PTR[112+rsi],xmm9
lea rsi,QWORD PTR[128+rsi]
add rdx,080h
jz $L$ecb_ret
$L$ecb_enc_tail::
movups xmm2,XMMWORD PTR[rdi]
cmp rdx,020h
jb $L$ecb_enc_one
movups xmm3,XMMWORD PTR[16+rdi]
je $L$ecb_enc_two
movups xmm4,XMMWORD PTR[32+rdi]
cmp rdx,040h
jb $L$ecb_enc_three
movups xmm5,XMMWORD PTR[48+rdi]
je $L$ecb_enc_four
movups xmm6,XMMWORD PTR[64+rdi]
cmp rdx,060h
jb $L$ecb_enc_five
movups xmm7,XMMWORD PTR[80+rdi]
je $L$ecb_enc_six
movdqu xmm8,XMMWORD PTR[96+rdi]
call _aesni_encrypt8
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
movups XMMWORD PTR[64+rsi],xmm6
movups XMMWORD PTR[80+rsi],xmm7
movups XMMWORD PTR[96+rsi],xmm8
jmp $L$ecb_ret
ALIGN 16
$L$ecb_enc_one::
movups xmm0,XMMWORD PTR[rcx]
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
$L$oop_enc1_3::
DB 102,15,56,220,209
dec eax
movups xmm1,XMMWORD PTR[rcx]
lea rcx,QWORD PTR[16+rcx]
jnz $L$oop_enc1_3
DB 102,15,56,221,209
movups XMMWORD PTR[rsi],xmm2
jmp $L$ecb_ret
ALIGN 16
$L$ecb_enc_two::
xorps xmm4,xmm4
call _aesni_encrypt3
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
jmp $L$ecb_ret
ALIGN 16
$L$ecb_enc_three::
call _aesni_encrypt3
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
jmp $L$ecb_ret
ALIGN 16
$L$ecb_enc_four::
call _aesni_encrypt4
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
jmp $L$ecb_ret
ALIGN 16
$L$ecb_enc_five::
xorps xmm7,xmm7
call _aesni_encrypt6
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
movups XMMWORD PTR[64+rsi],xmm6
jmp $L$ecb_ret
ALIGN 16
$L$ecb_enc_six::
call _aesni_encrypt6
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
movups XMMWORD PTR[64+rsi],xmm6
movups XMMWORD PTR[80+rsi],xmm7
jmp $L$ecb_ret
ALIGN 16
$L$ecb_decrypt::
cmp rdx,080h
jb $L$ecb_dec_tail
movdqu xmm2,XMMWORD PTR[rdi]
movdqu xmm3,XMMWORD PTR[16+rdi]
movdqu xmm4,XMMWORD PTR[32+rdi]
movdqu xmm5,XMMWORD PTR[48+rdi]
movdqu xmm6,XMMWORD PTR[64+rdi]
movdqu xmm7,XMMWORD PTR[80+rdi]
movdqu xmm8,XMMWORD PTR[96+rdi]
movdqu xmm9,XMMWORD PTR[112+rdi]
lea rdi,QWORD PTR[128+rdi]
sub rdx,080h
jmp $L$ecb_dec_loop8_enter
ALIGN 16
$L$ecb_dec_loop8::
movups XMMWORD PTR[rsi],xmm2
mov rcx,r11
movdqu xmm2,XMMWORD PTR[rdi]
mov eax,r10d
movups XMMWORD PTR[16+rsi],xmm3
movdqu xmm3,XMMWORD PTR[16+rdi]
movups XMMWORD PTR[32+rsi],xmm4
movdqu xmm4,XMMWORD PTR[32+rdi]
movups XMMWORD PTR[48+rsi],xmm5
movdqu xmm5,XMMWORD PTR[48+rdi]
movups XMMWORD PTR[64+rsi],xmm6
movdqu xmm6,XMMWORD PTR[64+rdi]
movups XMMWORD PTR[80+rsi],xmm7
movdqu xmm7,XMMWORD PTR[80+rdi]
movups XMMWORD PTR[96+rsi],xmm8
movdqu xmm8,XMMWORD PTR[96+rdi]
movups XMMWORD PTR[112+rsi],xmm9
lea rsi,QWORD PTR[128+rsi]
movdqu xmm9,XMMWORD PTR[112+rdi]
lea rdi,QWORD PTR[128+rdi]
$L$ecb_dec_loop8_enter::
call _aesni_decrypt8
movups xmm0,XMMWORD PTR[r11]
sub rdx,080h
jnc $L$ecb_dec_loop8
movups XMMWORD PTR[rsi],xmm2
mov rcx,r11
movups XMMWORD PTR[16+rsi],xmm3
mov eax,r10d
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
movups XMMWORD PTR[64+rsi],xmm6
movups XMMWORD PTR[80+rsi],xmm7
movups XMMWORD PTR[96+rsi],xmm8
movups XMMWORD PTR[112+rsi],xmm9
lea rsi,QWORD PTR[128+rsi]
add rdx,080h
jz $L$ecb_ret
$L$ecb_dec_tail::
movups xmm2,XMMWORD PTR[rdi]
cmp rdx,020h
jb $L$ecb_dec_one
movups xmm3,XMMWORD PTR[16+rdi]
je $L$ecb_dec_two
movups xmm4,XMMWORD PTR[32+rdi]
cmp rdx,040h
jb $L$ecb_dec_three
movups xmm5,XMMWORD PTR[48+rdi]
je $L$ecb_dec_four
movups xmm6,XMMWORD PTR[64+rdi]
cmp rdx,060h
jb $L$ecb_dec_five
movups xmm7,XMMWORD PTR[80+rdi]
je $L$ecb_dec_six
movups xmm8,XMMWORD PTR[96+rdi]
movups xmm0,XMMWORD PTR[rcx]
call _aesni_decrypt8
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
movups XMMWORD PTR[64+rsi],xmm6
movups XMMWORD PTR[80+rsi],xmm7
movups XMMWORD PTR[96+rsi],xmm8
jmp $L$ecb_ret
ALIGN 16
$L$ecb_dec_one::
movups xmm0,XMMWORD PTR[rcx]
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
$L$oop_dec1_4::
DB 102,15,56,222,209
dec eax
movups xmm1,XMMWORD PTR[rcx]
lea rcx,QWORD PTR[16+rcx]
jnz $L$oop_dec1_4
DB 102,15,56,223,209
movups XMMWORD PTR[rsi],xmm2
jmp $L$ecb_ret
ALIGN 16
$L$ecb_dec_two::
xorps xmm4,xmm4
call _aesni_decrypt3
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
jmp $L$ecb_ret
ALIGN 16
$L$ecb_dec_three::
call _aesni_decrypt3
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
jmp $L$ecb_ret
ALIGN 16
$L$ecb_dec_four::
call _aesni_decrypt4
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
jmp $L$ecb_ret
ALIGN 16
$L$ecb_dec_five::
xorps xmm7,xmm7
call _aesni_decrypt6
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
movups XMMWORD PTR[64+rsi],xmm6
jmp $L$ecb_ret
ALIGN 16
$L$ecb_dec_six::
call _aesni_decrypt6
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
movups XMMWORD PTR[64+rsi],xmm6
movups XMMWORD PTR[80+rsi],xmm7
$L$ecb_ret::
movaps xmm6,XMMWORD PTR[rsp]
movaps xmm7,XMMWORD PTR[16+rsp]
movaps xmm8,XMMWORD PTR[32+rsp]
movaps xmm9,XMMWORD PTR[48+rsp]
lea rsp,QWORD PTR[88+rsp]
$L$ecb_enc_ret::
mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
mov rsi,QWORD PTR[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_aesni_ecb_encrypt::
aesni_ecb_encrypt ENDP
PUBLIC aesni_ccm64_encrypt_blocks
ALIGN 16
aesni_ccm64_encrypt_blocks PROC PUBLIC
mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
mov QWORD PTR[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_aesni_ccm64_encrypt_blocks::
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD PTR[40+rsp]
mov r9,QWORD PTR[48+rsp]
lea rsp,QWORD PTR[((-88))+rsp]
movaps XMMWORD PTR[rsp],xmm6
movaps XMMWORD PTR[16+rsp],xmm7
movaps XMMWORD PTR[32+rsp],xmm8
movaps XMMWORD PTR[48+rsp],xmm9
$L$ccm64_enc_body::
mov eax,DWORD PTR[240+rcx]
movdqu xmm9,XMMWORD PTR[r8]
movdqa xmm6,XMMWORD PTR[$L$increment64]
movdqa xmm7,XMMWORD PTR[$L$bswap_mask]
shr eax,1
lea r11,QWORD PTR[rcx]
movdqu xmm3,XMMWORD PTR[r9]
movdqa xmm2,xmm9
mov r10d,eax
DB 102,68,15,56,0,207
jmp $L$ccm64_enc_outer
ALIGN 16
$L$ccm64_enc_outer::
movups xmm0,XMMWORD PTR[r11]
mov eax,r10d
movups xmm8,XMMWORD PTR[rdi]
xorps xmm2,xmm0
movups xmm1,XMMWORD PTR[16+r11]
xorps xmm0,xmm8
lea rcx,QWORD PTR[32+r11]
xorps xmm3,xmm0
movups xmm0,XMMWORD PTR[rcx]
$L$ccm64_enc2_loop::
DB 102,15,56,220,209
dec eax
DB 102,15,56,220,217
movups xmm1,XMMWORD PTR[16+rcx]
DB 102,15,56,220,208
lea rcx,QWORD PTR[32+rcx]
DB 102,15,56,220,216
movups xmm0,XMMWORD PTR[rcx]
jnz $L$ccm64_enc2_loop
DB 102,15,56,220,209
DB 102,15,56,220,217
paddq xmm9,xmm6
DB 102,15,56,221,208
DB 102,15,56,221,216
dec rdx
lea rdi,QWORD PTR[16+rdi]
xorps xmm8,xmm2
movdqa xmm2,xmm9
movups XMMWORD PTR[rsi],xmm8
lea rsi,QWORD PTR[16+rsi]
DB 102,15,56,0,215
jnz $L$ccm64_enc_outer
movups XMMWORD PTR[r9],xmm3
movaps xmm6,XMMWORD PTR[rsp]
movaps xmm7,XMMWORD PTR[16+rsp]
movaps xmm8,XMMWORD PTR[32+rsp]
movaps xmm9,XMMWORD PTR[48+rsp]
lea rsp,QWORD PTR[88+rsp]
$L$ccm64_enc_ret::
mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
mov rsi,QWORD PTR[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_aesni_ccm64_encrypt_blocks::
aesni_ccm64_encrypt_blocks ENDP
PUBLIC aesni_ccm64_decrypt_blocks
ALIGN 16
aesni_ccm64_decrypt_blocks PROC PUBLIC
mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
mov QWORD PTR[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_aesni_ccm64_decrypt_blocks::
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD PTR[40+rsp]
mov r9,QWORD PTR[48+rsp]
lea rsp,QWORD PTR[((-88))+rsp]
movaps XMMWORD PTR[rsp],xmm6
movaps XMMWORD PTR[16+rsp],xmm7
movaps XMMWORD PTR[32+rsp],xmm8
movaps XMMWORD PTR[48+rsp],xmm9
$L$ccm64_dec_body::
mov eax,DWORD PTR[240+rcx]
movups xmm9,XMMWORD PTR[r8]
movdqu xmm3,XMMWORD PTR[r9]
movdqa xmm6,XMMWORD PTR[$L$increment64]
movdqa xmm7,XMMWORD PTR[$L$bswap_mask]
movaps xmm2,xmm9
mov r10d,eax
mov r11,rcx
DB 102,68,15,56,0,207
movups xmm0,XMMWORD PTR[rcx]
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
$L$oop_enc1_5::
DB 102,15,56,220,209
dec eax
movups xmm1,XMMWORD PTR[rcx]
lea rcx,QWORD PTR[16+rcx]
jnz $L$oop_enc1_5
DB 102,15,56,221,209
movups xmm8,XMMWORD PTR[rdi]
paddq xmm9,xmm6
lea rdi,QWORD PTR[16+rdi]
jmp $L$ccm64_dec_outer
ALIGN 16
$L$ccm64_dec_outer::
xorps xmm8,xmm2
movdqa xmm2,xmm9
mov eax,r10d
movups XMMWORD PTR[rsi],xmm8
lea rsi,QWORD PTR[16+rsi]
DB 102,15,56,0,215
sub rdx,1
jz $L$ccm64_dec_break
movups xmm0,XMMWORD PTR[r11]
shr eax,1
movups xmm1,XMMWORD PTR[16+r11]
xorps xmm8,xmm0
lea rcx,QWORD PTR[32+r11]
xorps xmm2,xmm0
xorps xmm3,xmm8
movups xmm0,XMMWORD PTR[rcx]
$L$ccm64_dec2_loop::
DB 102,15,56,220,209
dec eax
DB 102,15,56,220,217
movups xmm1,XMMWORD PTR[16+rcx]
DB 102,15,56,220,208
lea rcx,QWORD PTR[32+rcx]
DB 102,15,56,220,216
movups xmm0,XMMWORD PTR[rcx]
jnz $L$ccm64_dec2_loop
movups xmm8,XMMWORD PTR[rdi]
paddq xmm9,xmm6
DB 102,15,56,220,209
DB 102,15,56,220,217
lea rdi,QWORD PTR[16+rdi]
DB 102,15,56,221,208
DB 102,15,56,221,216
jmp $L$ccm64_dec_outer
ALIGN 16
$L$ccm64_dec_break::
movups xmm0,XMMWORD PTR[r11]
movups xmm1,XMMWORD PTR[16+r11]
xorps xmm8,xmm0
lea r11,QWORD PTR[32+r11]
xorps xmm3,xmm8
$L$oop_enc1_6::
DB 102,15,56,220,217
dec eax
movups xmm1,XMMWORD PTR[r11]
lea r11,QWORD PTR[16+r11]
jnz $L$oop_enc1_6
DB 102,15,56,221,217
movups XMMWORD PTR[r9],xmm3
movaps xmm6,XMMWORD PTR[rsp]
movaps xmm7,XMMWORD PTR[16+rsp]
movaps xmm8,XMMWORD PTR[32+rsp]
movaps xmm9,XMMWORD PTR[48+rsp]
lea rsp,QWORD PTR[88+rsp]
$L$ccm64_dec_ret::
mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
mov rsi,QWORD PTR[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_aesni_ccm64_decrypt_blocks::
aesni_ccm64_decrypt_blocks ENDP
PUBLIC aesni_ctr32_encrypt_blocks
ALIGN 16
aesni_ctr32_encrypt_blocks PROC PUBLIC
mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
mov QWORD PTR[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_aesni_ctr32_encrypt_blocks::
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD PTR[40+rsp]
lea rsp,QWORD PTR[((-200))+rsp]
movaps XMMWORD PTR[32+rsp],xmm6
movaps XMMWORD PTR[48+rsp],xmm7
movaps XMMWORD PTR[64+rsp],xmm8
movaps XMMWORD PTR[80+rsp],xmm9
movaps XMMWORD PTR[96+rsp],xmm10
movaps XMMWORD PTR[112+rsp],xmm11
movaps XMMWORD PTR[128+rsp],xmm12
movaps XMMWORD PTR[144+rsp],xmm13
movaps XMMWORD PTR[160+rsp],xmm14
movaps XMMWORD PTR[176+rsp],xmm15
$L$ctr32_body::
cmp rdx,1
je $L$ctr32_one_shortcut
movdqu xmm14,XMMWORD PTR[r8]
movdqa xmm15,XMMWORD PTR[$L$bswap_mask]
xor eax,eax
DB 102,69,15,58,22,242,3
DB 102,68,15,58,34,240,3
mov eax,DWORD PTR[240+rcx]
bswap r10d
pxor xmm12,xmm12
pxor xmm13,xmm13
DB 102,69,15,58,34,226,0
lea r11,QWORD PTR[3+r10]
DB 102,69,15,58,34,235,0
inc r10d
DB 102,69,15,58,34,226,1
inc r11
DB 102,69,15,58,34,235,1
inc r10d
DB 102,69,15,58,34,226,2
inc r11
DB 102,69,15,58,34,235,2
movdqa XMMWORD PTR[rsp],xmm12
DB 102,69,15,56,0,231
movdqa XMMWORD PTR[16+rsp],xmm13
DB 102,69,15,56,0,239
pshufd xmm2,xmm12,192
pshufd xmm3,xmm12,128
pshufd xmm4,xmm12,64
cmp rdx,6
jb $L$ctr32_tail
shr eax,1
mov r11,rcx
mov r10d,eax
sub rdx,6
jmp $L$ctr32_loop6
ALIGN 16
$L$ctr32_loop6::
pshufd xmm5,xmm13,192
por xmm2,xmm14
movups xmm0,XMMWORD PTR[r11]
pshufd xmm6,xmm13,128
por xmm3,xmm14
movups xmm1,XMMWORD PTR[16+r11]
pshufd xmm7,xmm13,64
por xmm4,xmm14
por xmm5,xmm14
xorps xmm2,xmm0
por xmm6,xmm14
por xmm7,xmm14
pxor xmm3,xmm0
DB 102,15,56,220,209
lea rcx,QWORD PTR[32+r11]
pxor xmm4,xmm0
DB 102,15,56,220,217
movdqa xmm13,XMMWORD PTR[$L$increment32]
pxor xmm5,xmm0
DB 102,15,56,220,225
movdqa xmm12,XMMWORD PTR[rsp]
pxor xmm6,xmm0
DB 102,15,56,220,233
pxor xmm7,xmm0
movups xmm0,XMMWORD PTR[rcx]
dec eax
DB 102,15,56,220,241
DB 102,15,56,220,249
jmp $L$ctr32_enc_loop6_enter
ALIGN 16
$L$ctr32_enc_loop6::
DB 102,15,56,220,209
DB 102,15,56,220,217
dec eax
DB 102,15,56,220,225
DB 102,15,56,220,233
DB 102,15,56,220,241
DB 102,15,56,220,249
$L$ctr32_enc_loop6_enter::
movups xmm1,XMMWORD PTR[16+rcx]
DB 102,15,56,220,208
DB 102,15,56,220,216
lea rcx,QWORD PTR[32+rcx]
DB 102,15,56,220,224
DB 102,15,56,220,232
DB 102,15,56,220,240
DB 102,15,56,220,248
movups xmm0,XMMWORD PTR[rcx]
jnz $L$ctr32_enc_loop6
DB 102,15,56,220,209
paddd xmm12,xmm13
DB 102,15,56,220,217
paddd xmm13,XMMWORD PTR[16+rsp]
DB 102,15,56,220,225
movdqa XMMWORD PTR[rsp],xmm12
DB 102,15,56,220,233
movdqa XMMWORD PTR[16+rsp],xmm13
DB 102,15,56,220,241
DB 102,69,15,56,0,231
DB 102,15,56,220,249
DB 102,69,15,56,0,239
DB 102,15,56,221,208
movups xmm8,XMMWORD PTR[rdi]
DB 102,15,56,221,216
movups xmm9,XMMWORD PTR[16+rdi]
DB 102,15,56,221,224
movups xmm10,XMMWORD PTR[32+rdi]
DB 102,15,56,221,232
movups xmm11,XMMWORD PTR[48+rdi]
DB 102,15,56,221,240
movups xmm1,XMMWORD PTR[64+rdi]
DB 102,15,56,221,248
movups xmm0,XMMWORD PTR[80+rdi]
lea rdi,QWORD PTR[96+rdi]
xorps xmm8,xmm2
pshufd xmm2,xmm12,192
xorps xmm9,xmm3
pshufd xmm3,xmm12,128
movups XMMWORD PTR[rsi],xmm8
xorps xmm10,xmm4
pshufd xmm4,xmm12,64
movups XMMWORD PTR[16+rsi],xmm9
xorps xmm11,xmm5
movups XMMWORD PTR[32+rsi],xmm10
xorps xmm1,xmm6
movups XMMWORD PTR[48+rsi],xmm11
xorps xmm0,xmm7
movups XMMWORD PTR[64+rsi],xmm1
movups XMMWORD PTR[80+rsi],xmm0
lea rsi,QWORD PTR[96+rsi]
mov eax,r10d
sub rdx,6
jnc $L$ctr32_loop6
add rdx,6
jz $L$ctr32_done
mov rcx,r11
lea eax,DWORD PTR[1+rax*1+rax]
$L$ctr32_tail::
por xmm2,xmm14
movups xmm8,XMMWORD PTR[rdi]
cmp rdx,2
jb $L$ctr32_one
por xmm3,xmm14
movups xmm9,XMMWORD PTR[16+rdi]
je $L$ctr32_two
pshufd xmm5,xmm13,192
por xmm4,xmm14
movups xmm10,XMMWORD PTR[32+rdi]
cmp rdx,4
jb $L$ctr32_three
pshufd xmm6,xmm13,128
por xmm5,xmm14
movups xmm11,XMMWORD PTR[48+rdi]
je $L$ctr32_four
por xmm6,xmm14
xorps xmm7,xmm7
call _aesni_encrypt6
movups xmm1,XMMWORD PTR[64+rdi]
xorps xmm8,xmm2
xorps xmm9,xmm3
movups XMMWORD PTR[rsi],xmm8
xorps xmm10,xmm4
movups XMMWORD PTR[16+rsi],xmm9
xorps xmm11,xmm5
movups XMMWORD PTR[32+rsi],xmm10
xorps xmm1,xmm6
movups XMMWORD PTR[48+rsi],xmm11
movups XMMWORD PTR[64+rsi],xmm1
jmp $L$ctr32_done
ALIGN 16
$L$ctr32_one_shortcut::
movups xmm2,XMMWORD PTR[r8]
movups xmm8,XMMWORD PTR[rdi]
mov eax,DWORD PTR[240+rcx]
$L$ctr32_one::
movups xmm0,XMMWORD PTR[rcx]
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
$L$oop_enc1_7::
DB 102,15,56,220,209
dec eax
movups xmm1,XMMWORD PTR[rcx]
lea rcx,QWORD PTR[16+rcx]
jnz $L$oop_enc1_7
DB 102,15,56,221,209
xorps xmm8,xmm2
movups XMMWORD PTR[rsi],xmm8
jmp $L$ctr32_done
ALIGN 16
$L$ctr32_two::
xorps xmm4,xmm4
call _aesni_encrypt3
xorps xmm8,xmm2
xorps xmm9,xmm3
movups XMMWORD PTR[rsi],xmm8
movups XMMWORD PTR[16+rsi],xmm9
jmp $L$ctr32_done
ALIGN 16
$L$ctr32_three::
call _aesni_encrypt3
xorps xmm8,xmm2
xorps xmm9,xmm3
movups XMMWORD PTR[rsi],xmm8
xorps xmm10,xmm4
movups XMMWORD PTR[16+rsi],xmm9
movups XMMWORD PTR[32+rsi],xmm10
jmp $L$ctr32_done
ALIGN 16
$L$ctr32_four::
call _aesni_encrypt4
xorps xmm8,xmm2
xorps xmm9,xmm3
movups XMMWORD PTR[rsi],xmm8
xorps xmm10,xmm4
movups XMMWORD PTR[16+rsi],xmm9
xorps xmm11,xmm5
movups XMMWORD PTR[32+rsi],xmm10
movups XMMWORD PTR[48+rsi],xmm11
$L$ctr32_done::
movaps xmm6,XMMWORD PTR[32+rsp]
movaps xmm7,XMMWORD PTR[48+rsp]
movaps xmm8,XMMWORD PTR[64+rsp]
movaps xmm9,XMMWORD PTR[80+rsp]
movaps xmm10,XMMWORD PTR[96+rsp]
movaps xmm11,XMMWORD PTR[112+rsp]
movaps xmm12,XMMWORD PTR[128+rsp]
movaps xmm13,XMMWORD PTR[144+rsp]
movaps xmm14,XMMWORD PTR[160+rsp]
movaps xmm15,XMMWORD PTR[176+rsp]
lea rsp,QWORD PTR[200+rsp]
$L$ctr32_ret::
mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
mov rsi,QWORD PTR[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_aesni_ctr32_encrypt_blocks::
aesni_ctr32_encrypt_blocks ENDP
PUBLIC aesni_xts_encrypt
ALIGN 16
aesni_xts_encrypt PROC PUBLIC
mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
mov QWORD PTR[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_aesni_xts_encrypt::
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD PTR[40+rsp]
mov r9,QWORD PTR[48+rsp]
lea rsp,QWORD PTR[((-264))+rsp]
movaps XMMWORD PTR[96+rsp],xmm6
movaps XMMWORD PTR[112+rsp],xmm7
movaps XMMWORD PTR[128+rsp],xmm8
movaps XMMWORD PTR[144+rsp],xmm9
movaps XMMWORD PTR[160+rsp],xmm10
movaps XMMWORD PTR[176+rsp],xmm11
movaps XMMWORD PTR[192+rsp],xmm12
movaps XMMWORD PTR[208+rsp],xmm13
movaps XMMWORD PTR[224+rsp],xmm14
movaps XMMWORD PTR[240+rsp],xmm15
$L$xts_enc_body::
movups xmm15,XMMWORD PTR[r9]
mov eax,DWORD PTR[240+r8]
mov r10d,DWORD PTR[240+rcx]
movups xmm0,XMMWORD PTR[r8]
movups xmm1,XMMWORD PTR[16+r8]
lea r8,QWORD PTR[32+r8]
xorps xmm15,xmm0
$L$oop_enc1_8::
DB 102,68,15,56,220,249
dec eax
movups xmm1,XMMWORD PTR[r8]
lea r8,QWORD PTR[16+r8]
jnz $L$oop_enc1_8
DB 102,68,15,56,221,249
mov r11,rcx
mov eax,r10d
mov r9,rdx
and rdx,-16
movdqa xmm8,XMMWORD PTR[$L$xts_magic]
pxor xmm14,xmm14
pcmpgtd xmm14,xmm15
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm10,xmm15
paddq xmm15,xmm15
pand xmm9,xmm8
pcmpgtd xmm14,xmm15
pxor xmm15,xmm9
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm11,xmm15
paddq xmm15,xmm15
pand xmm9,xmm8
pcmpgtd xmm14,xmm15
pxor xmm15,xmm9
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm12,xmm15
paddq xmm15,xmm15
pand xmm9,xmm8
pcmpgtd xmm14,xmm15
pxor xmm15,xmm9
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm13,xmm15
paddq xmm15,xmm15
pand xmm9,xmm8
pcmpgtd xmm14,xmm15
pxor xmm15,xmm9
sub rdx,16*6
jc $L$xts_enc_short
shr eax,1
sub eax,1
mov r10d,eax
jmp $L$xts_enc_grandloop
ALIGN 16
$L$xts_enc_grandloop::
pshufd xmm9,xmm14,013h
movdqa xmm14,xmm15
paddq xmm15,xmm15
movdqu xmm2,XMMWORD PTR[rdi]
pand xmm9,xmm8
movdqu xmm3,XMMWORD PTR[16+rdi]
pxor xmm15,xmm9
movdqu xmm4,XMMWORD PTR[32+rdi]
pxor xmm2,xmm10
movdqu xmm5,XMMWORD PTR[48+rdi]
pxor xmm3,xmm11
movdqu xmm6,XMMWORD PTR[64+rdi]
pxor xmm4,xmm12
movdqu xmm7,XMMWORD PTR[80+rdi]
lea rdi,QWORD PTR[96+rdi]
pxor xmm5,xmm13
movups xmm0,XMMWORD PTR[r11]
pxor xmm6,xmm14
pxor xmm7,xmm15
movups xmm1,XMMWORD PTR[16+r11]
pxor xmm2,xmm0
pxor xmm3,xmm0
movdqa XMMWORD PTR[rsp],xmm10
DB 102,15,56,220,209
lea rcx,QWORD PTR[32+r11]
pxor xmm4,xmm0
movdqa XMMWORD PTR[16+rsp],xmm11
DB 102,15,56,220,217
pxor xmm5,xmm0
movdqa XMMWORD PTR[32+rsp],xmm12
DB 102,15,56,220,225
pxor xmm6,xmm0
movdqa XMMWORD PTR[48+rsp],xmm13
DB 102,15,56,220,233
pxor xmm7,xmm0
movups xmm0,XMMWORD PTR[rcx]
dec eax
movdqa XMMWORD PTR[64+rsp],xmm14
DB 102,15,56,220,241
movdqa XMMWORD PTR[80+rsp],xmm15
DB 102,15,56,220,249
pxor xmm14,xmm14
pcmpgtd xmm14,xmm15
jmp $L$xts_enc_loop6_enter
ALIGN 16
$L$xts_enc_loop6::
DB 102,15,56,220,209
DB 102,15,56,220,217
dec eax
DB 102,15,56,220,225
DB 102,15,56,220,233
DB 102,15,56,220,241
DB 102,15,56,220,249
$L$xts_enc_loop6_enter::
movups xmm1,XMMWORD PTR[16+rcx]
DB 102,15,56,220,208
DB 102,15,56,220,216
lea rcx,QWORD PTR[32+rcx]
DB 102,15,56,220,224
DB 102,15,56,220,232
DB 102,15,56,220,240
DB 102,15,56,220,248
movups xmm0,XMMWORD PTR[rcx]
jnz $L$xts_enc_loop6
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
paddq xmm15,xmm15
DB 102,15,56,220,209
pand xmm9,xmm8
DB 102,15,56,220,217
pcmpgtd xmm14,xmm15
DB 102,15,56,220,225
pxor xmm15,xmm9
DB 102,15,56,220,233
DB 102,15,56,220,241
DB 102,15,56,220,249
movups xmm1,XMMWORD PTR[16+rcx]
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm10,xmm15
paddq xmm15,xmm15
DB 102,15,56,220,208
pand xmm9,xmm8
DB 102,15,56,220,216
pcmpgtd xmm14,xmm15
DB 102,15,56,220,224
pxor xmm15,xmm9
DB 102,15,56,220,232
DB 102,15,56,220,240
DB 102,15,56,220,248
movups xmm0,XMMWORD PTR[32+rcx]
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm11,xmm15
paddq xmm15,xmm15
DB 102,15,56,220,209
pand xmm9,xmm8
DB 102,15,56,220,217
pcmpgtd xmm14,xmm15
DB 102,15,56,220,225
pxor xmm15,xmm9
DB 102,15,56,220,233
DB 102,15,56,220,241
DB 102,15,56,220,249
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm12,xmm15
paddq xmm15,xmm15
DB 102,15,56,221,208
pand xmm9,xmm8
DB 102,15,56,221,216
pcmpgtd xmm14,xmm15
DB 102,15,56,221,224
pxor xmm15,xmm9
DB 102,15,56,221,232
DB 102,15,56,221,240
DB 102,15,56,221,248
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm13,xmm15
paddq xmm15,xmm15
xorps xmm2,XMMWORD PTR[rsp]
pand xmm9,xmm8
xorps xmm3,XMMWORD PTR[16+rsp]
pcmpgtd xmm14,xmm15
pxor xmm15,xmm9
xorps xmm4,XMMWORD PTR[32+rsp]
movups XMMWORD PTR[rsi],xmm2
xorps xmm5,XMMWORD PTR[48+rsp]
movups XMMWORD PTR[16+rsi],xmm3
xorps xmm6,XMMWORD PTR[64+rsp]
movups XMMWORD PTR[32+rsi],xmm4
xorps xmm7,XMMWORD PTR[80+rsp]
movups XMMWORD PTR[48+rsi],xmm5
mov eax,r10d
movups XMMWORD PTR[64+rsi],xmm6
movups XMMWORD PTR[80+rsi],xmm7
lea rsi,QWORD PTR[96+rsi]
sub rdx,16*6
jnc $L$xts_enc_grandloop
lea eax,DWORD PTR[3+rax*1+rax]
mov rcx,r11
mov r10d,eax
$L$xts_enc_short::
add rdx,16*6
jz $L$xts_enc_done
cmp rdx,020h
jb $L$xts_enc_one
je $L$xts_enc_two
cmp rdx,040h
jb $L$xts_enc_three
je $L$xts_enc_four
pshufd xmm9,xmm14,013h
movdqa xmm14,xmm15
paddq xmm15,xmm15
movdqu xmm2,XMMWORD PTR[rdi]
pand xmm9,xmm8
movdqu xmm3,XMMWORD PTR[16+rdi]
pxor xmm15,xmm9
movdqu xmm4,XMMWORD PTR[32+rdi]
pxor xmm2,xmm10
movdqu xmm5,XMMWORD PTR[48+rdi]
pxor xmm3,xmm11
movdqu xmm6,XMMWORD PTR[64+rdi]
lea rdi,QWORD PTR[80+rdi]
pxor xmm4,xmm12
pxor xmm5,xmm13
pxor xmm6,xmm14
call _aesni_encrypt6
xorps xmm2,xmm10
movdqa xmm10,xmm15
xorps xmm3,xmm11
xorps xmm4,xmm12
movdqu XMMWORD PTR[rsi],xmm2
xorps xmm5,xmm13
movdqu XMMWORD PTR[16+rsi],xmm3
xorps xmm6,xmm14
movdqu XMMWORD PTR[32+rsi],xmm4
movdqu XMMWORD PTR[48+rsi],xmm5
movdqu XMMWORD PTR[64+rsi],xmm6
lea rsi,QWORD PTR[80+rsi]
jmp $L$xts_enc_done
ALIGN 16
$L$xts_enc_one::
movups xmm2,XMMWORD PTR[rdi]
lea rdi,QWORD PTR[16+rdi]
xorps xmm2,xmm10
movups xmm0,XMMWORD PTR[rcx]
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
$L$oop_enc1_9::
DB 102,15,56,220,209
dec eax
movups xmm1,XMMWORD PTR[rcx]
lea rcx,QWORD PTR[16+rcx]
jnz $L$oop_enc1_9
DB 102,15,56,221,209
xorps xmm2,xmm10
movdqa xmm10,xmm11
movups XMMWORD PTR[rsi],xmm2
lea rsi,QWORD PTR[16+rsi]
jmp $L$xts_enc_done
ALIGN 16
$L$xts_enc_two::
movups xmm2,XMMWORD PTR[rdi]
movups xmm3,XMMWORD PTR[16+rdi]
lea rdi,QWORD PTR[32+rdi]
xorps xmm2,xmm10
xorps xmm3,xmm11
call _aesni_encrypt3
xorps xmm2,xmm10
movdqa xmm10,xmm12
xorps xmm3,xmm11
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
lea rsi,QWORD PTR[32+rsi]
jmp $L$xts_enc_done
ALIGN 16
$L$xts_enc_three::
movups xmm2,XMMWORD PTR[rdi]
movups xmm3,XMMWORD PTR[16+rdi]
movups xmm4,XMMWORD PTR[32+rdi]
lea rdi,QWORD PTR[48+rdi]
xorps xmm2,xmm10
xorps xmm3,xmm11
xorps xmm4,xmm12
call _aesni_encrypt3
xorps xmm2,xmm10
movdqa xmm10,xmm13
xorps xmm3,xmm11
xorps xmm4,xmm12
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
lea rsi,QWORD PTR[48+rsi]
jmp $L$xts_enc_done
ALIGN 16
$L$xts_enc_four::
movups xmm2,XMMWORD PTR[rdi]
movups xmm3,XMMWORD PTR[16+rdi]
movups xmm4,XMMWORD PTR[32+rdi]
xorps xmm2,xmm10
movups xmm5,XMMWORD PTR[48+rdi]
lea rdi,QWORD PTR[64+rdi]
xorps xmm3,xmm11
xorps xmm4,xmm12
xorps xmm5,xmm13
call _aesni_encrypt4
xorps xmm2,xmm10
movdqa xmm10,xmm15
xorps xmm3,xmm11
xorps xmm4,xmm12
movups XMMWORD PTR[rsi],xmm2
xorps xmm5,xmm13
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
lea rsi,QWORD PTR[64+rsi]
jmp $L$xts_enc_done
ALIGN 16
$L$xts_enc_done::
and r9,15
jz $L$xts_enc_ret
mov rdx,r9
$L$xts_enc_steal::
movzx eax,BYTE PTR[rdi]
movzx ecx,BYTE PTR[((-16))+rsi]
lea rdi,QWORD PTR[1+rdi]
mov BYTE PTR[((-16))+rsi],al
mov BYTE PTR[rsi],cl
lea rsi,QWORD PTR[1+rsi]
sub rdx,1
jnz $L$xts_enc_steal
sub rsi,r9
mov rcx,r11
mov eax,r10d
movups xmm2,XMMWORD PTR[((-16))+rsi]
xorps xmm2,xmm10
movups xmm0,XMMWORD PTR[rcx]
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
$L$oop_enc1_10::
DB 102,15,56,220,209
dec eax
movups xmm1,XMMWORD PTR[rcx]
lea rcx,QWORD PTR[16+rcx]
jnz $L$oop_enc1_10
DB 102,15,56,221,209
xorps xmm2,xmm10
movups XMMWORD PTR[(-16)+rsi],xmm2
$L$xts_enc_ret::
movaps xmm6,XMMWORD PTR[96+rsp]
movaps xmm7,XMMWORD PTR[112+rsp]
movaps xmm8,XMMWORD PTR[128+rsp]
movaps xmm9,XMMWORD PTR[144+rsp]
movaps xmm10,XMMWORD PTR[160+rsp]
movaps xmm11,XMMWORD PTR[176+rsp]
movaps xmm12,XMMWORD PTR[192+rsp]
movaps xmm13,XMMWORD PTR[208+rsp]
movaps xmm14,XMMWORD PTR[224+rsp]
movaps xmm15,XMMWORD PTR[240+rsp]
lea rsp,QWORD PTR[264+rsp]
$L$xts_enc_epilogue::
mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
mov rsi,QWORD PTR[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_aesni_xts_encrypt::
aesni_xts_encrypt ENDP
PUBLIC aesni_xts_decrypt
ALIGN 16
aesni_xts_decrypt PROC PUBLIC
mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
mov QWORD PTR[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_aesni_xts_decrypt::
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD PTR[40+rsp]
mov r9,QWORD PTR[48+rsp]
lea rsp,QWORD PTR[((-264))+rsp]
movaps XMMWORD PTR[96+rsp],xmm6
movaps XMMWORD PTR[112+rsp],xmm7
movaps XMMWORD PTR[128+rsp],xmm8
movaps XMMWORD PTR[144+rsp],xmm9
movaps XMMWORD PTR[160+rsp],xmm10
movaps XMMWORD PTR[176+rsp],xmm11
movaps XMMWORD PTR[192+rsp],xmm12
movaps XMMWORD PTR[208+rsp],xmm13
movaps XMMWORD PTR[224+rsp],xmm14
movaps XMMWORD PTR[240+rsp],xmm15
$L$xts_dec_body::
movups xmm15,XMMWORD PTR[r9]
mov eax,DWORD PTR[240+r8]
mov r10d,DWORD PTR[240+rcx]
movups xmm0,XMMWORD PTR[r8]
movups xmm1,XMMWORD PTR[16+r8]
lea r8,QWORD PTR[32+r8]
xorps xmm15,xmm0
$L$oop_enc1_11::
DB 102,68,15,56,220,249
dec eax
movups xmm1,XMMWORD PTR[r8]
lea r8,QWORD PTR[16+r8]
jnz $L$oop_enc1_11
DB 102,68,15,56,221,249
xor eax,eax
test rdx,15
setnz al
shl rax,4
sub rdx,rax
mov r11,rcx
mov eax,r10d
mov r9,rdx
and rdx,-16
movdqa xmm8,XMMWORD PTR[$L$xts_magic]
pxor xmm14,xmm14
pcmpgtd xmm14,xmm15
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm10,xmm15
paddq xmm15,xmm15
pand xmm9,xmm8
pcmpgtd xmm14,xmm15
pxor xmm15,xmm9
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm11,xmm15
paddq xmm15,xmm15
pand xmm9,xmm8
pcmpgtd xmm14,xmm15
pxor xmm15,xmm9
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm12,xmm15
paddq xmm15,xmm15
pand xmm9,xmm8
pcmpgtd xmm14,xmm15
pxor xmm15,xmm9
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm13,xmm15
paddq xmm15,xmm15
pand xmm9,xmm8
pcmpgtd xmm14,xmm15
pxor xmm15,xmm9
sub rdx,16*6
jc $L$xts_dec_short
shr eax,1
sub eax,1
mov r10d,eax
jmp $L$xts_dec_grandloop
ALIGN 16
$L$xts_dec_grandloop::
pshufd xmm9,xmm14,013h
movdqa xmm14,xmm15
paddq xmm15,xmm15
movdqu xmm2,XMMWORD PTR[rdi]
pand xmm9,xmm8
movdqu xmm3,XMMWORD PTR[16+rdi]
pxor xmm15,xmm9
movdqu xmm4,XMMWORD PTR[32+rdi]
pxor xmm2,xmm10
movdqu xmm5,XMMWORD PTR[48+rdi]
pxor xmm3,xmm11
movdqu xmm6,XMMWORD PTR[64+rdi]
pxor xmm4,xmm12
movdqu xmm7,XMMWORD PTR[80+rdi]
lea rdi,QWORD PTR[96+rdi]
pxor xmm5,xmm13
movups xmm0,XMMWORD PTR[r11]
pxor xmm6,xmm14
pxor xmm7,xmm15
movups xmm1,XMMWORD PTR[16+r11]
pxor xmm2,xmm0
pxor xmm3,xmm0
movdqa XMMWORD PTR[rsp],xmm10
DB 102,15,56,222,209
lea rcx,QWORD PTR[32+r11]
pxor xmm4,xmm0
movdqa XMMWORD PTR[16+rsp],xmm11
DB 102,15,56,222,217
pxor xmm5,xmm0
movdqa XMMWORD PTR[32+rsp],xmm12
DB 102,15,56,222,225
pxor xmm6,xmm0
movdqa XMMWORD PTR[48+rsp],xmm13
DB 102,15,56,222,233
pxor xmm7,xmm0
movups xmm0,XMMWORD PTR[rcx]
dec eax
movdqa XMMWORD PTR[64+rsp],xmm14
DB 102,15,56,222,241
movdqa XMMWORD PTR[80+rsp],xmm15
DB 102,15,56,222,249
pxor xmm14,xmm14
pcmpgtd xmm14,xmm15
jmp $L$xts_dec_loop6_enter
ALIGN 16
$L$xts_dec_loop6::
DB 102,15,56,222,209
DB 102,15,56,222,217
dec eax
DB 102,15,56,222,225
DB 102,15,56,222,233
DB 102,15,56,222,241
DB 102,15,56,222,249
$L$xts_dec_loop6_enter::
movups xmm1,XMMWORD PTR[16+rcx]
DB 102,15,56,222,208
DB 102,15,56,222,216
lea rcx,QWORD PTR[32+rcx]
DB 102,15,56,222,224
DB 102,15,56,222,232
DB 102,15,56,222,240
DB 102,15,56,222,248
movups xmm0,XMMWORD PTR[rcx]
jnz $L$xts_dec_loop6
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
paddq xmm15,xmm15
DB 102,15,56,222,209
pand xmm9,xmm8
DB 102,15,56,222,217
pcmpgtd xmm14,xmm15
DB 102,15,56,222,225
pxor xmm15,xmm9
DB 102,15,56,222,233
DB 102,15,56,222,241
DB 102,15,56,222,249
movups xmm1,XMMWORD PTR[16+rcx]
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm10,xmm15
paddq xmm15,xmm15
DB 102,15,56,222,208
pand xmm9,xmm8
DB 102,15,56,222,216
pcmpgtd xmm14,xmm15
DB 102,15,56,222,224
pxor xmm15,xmm9
DB 102,15,56,222,232
DB 102,15,56,222,240
DB 102,15,56,222,248
movups xmm0,XMMWORD PTR[32+rcx]
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm11,xmm15
paddq xmm15,xmm15
DB 102,15,56,222,209
pand xmm9,xmm8
DB 102,15,56,222,217
pcmpgtd xmm14,xmm15
DB 102,15,56,222,225
pxor xmm15,xmm9
DB 102,15,56,222,233
DB 102,15,56,222,241
DB 102,15,56,222,249
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm12,xmm15
paddq xmm15,xmm15
DB 102,15,56,223,208
pand xmm9,xmm8
DB 102,15,56,223,216
pcmpgtd xmm14,xmm15
DB 102,15,56,223,224
pxor xmm15,xmm9
DB 102,15,56,223,232
DB 102,15,56,223,240
DB 102,15,56,223,248
pshufd xmm9,xmm14,013h
pxor xmm14,xmm14
movdqa xmm13,xmm15
paddq xmm15,xmm15
xorps xmm2,XMMWORD PTR[rsp]
pand xmm9,xmm8
xorps xmm3,XMMWORD PTR[16+rsp]
pcmpgtd xmm14,xmm15
pxor xmm15,xmm9
xorps xmm4,XMMWORD PTR[32+rsp]
movups XMMWORD PTR[rsi],xmm2
xorps xmm5,XMMWORD PTR[48+rsp]
movups XMMWORD PTR[16+rsi],xmm3
xorps xmm6,XMMWORD PTR[64+rsp]
movups XMMWORD PTR[32+rsi],xmm4
xorps xmm7,XMMWORD PTR[80+rsp]
movups XMMWORD PTR[48+rsi],xmm5
mov eax,r10d
movups XMMWORD PTR[64+rsi],xmm6
movups XMMWORD PTR[80+rsi],xmm7
lea rsi,QWORD PTR[96+rsi]
sub rdx,16*6
jnc $L$xts_dec_grandloop
lea eax,DWORD PTR[3+rax*1+rax]
mov rcx,r11
mov r10d,eax
$L$xts_dec_short::
add rdx,16*6
jz $L$xts_dec_done
cmp rdx,020h
jb $L$xts_dec_one
je $L$xts_dec_two
cmp rdx,040h
jb $L$xts_dec_three
je $L$xts_dec_four
pshufd xmm9,xmm14,013h
movdqa xmm14,xmm15
paddq xmm15,xmm15
movdqu xmm2,XMMWORD PTR[rdi]
pand xmm9,xmm8
movdqu xmm3,XMMWORD PTR[16+rdi]
pxor xmm15,xmm9
movdqu xmm4,XMMWORD PTR[32+rdi]
pxor xmm2,xmm10
movdqu xmm5,XMMWORD PTR[48+rdi]
pxor xmm3,xmm11
movdqu xmm6,XMMWORD PTR[64+rdi]
lea rdi,QWORD PTR[80+rdi]
pxor xmm4,xmm12
pxor xmm5,xmm13
pxor xmm6,xmm14
call _aesni_decrypt6
xorps xmm2,xmm10
xorps xmm3,xmm11
xorps xmm4,xmm12
movdqu XMMWORD PTR[rsi],xmm2
xorps xmm5,xmm13
movdqu XMMWORD PTR[16+rsi],xmm3
xorps xmm6,xmm14
movdqu XMMWORD PTR[32+rsi],xmm4
pxor xmm14,xmm14
movdqu XMMWORD PTR[48+rsi],xmm5
pcmpgtd xmm14,xmm15
movdqu XMMWORD PTR[64+rsi],xmm6
lea rsi,QWORD PTR[80+rsi]
pshufd xmm11,xmm14,013h
and r9,15
jz $L$xts_dec_ret
movdqa xmm10,xmm15
paddq xmm15,xmm15
pand xmm11,xmm8
pxor xmm11,xmm15
jmp $L$xts_dec_done2
ALIGN 16
$L$xts_dec_one::
movups xmm2,XMMWORD PTR[rdi]
lea rdi,QWORD PTR[16+rdi]
xorps xmm2,xmm10
movups xmm0,XMMWORD PTR[rcx]
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
$L$oop_dec1_12::
DB 102,15,56,222,209
dec eax
movups xmm1,XMMWORD PTR[rcx]
lea rcx,QWORD PTR[16+rcx]
jnz $L$oop_dec1_12
DB 102,15,56,223,209
xorps xmm2,xmm10
movdqa xmm10,xmm11
movups XMMWORD PTR[rsi],xmm2
movdqa xmm11,xmm12
lea rsi,QWORD PTR[16+rsi]
jmp $L$xts_dec_done
ALIGN 16
$L$xts_dec_two::
movups xmm2,XMMWORD PTR[rdi]
movups xmm3,XMMWORD PTR[16+rdi]
lea rdi,QWORD PTR[32+rdi]
xorps xmm2,xmm10
xorps xmm3,xmm11
call _aesni_decrypt3
xorps xmm2,xmm10
movdqa xmm10,xmm12
xorps xmm3,xmm11
movdqa xmm11,xmm13
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
lea rsi,QWORD PTR[32+rsi]
jmp $L$xts_dec_done
ALIGN 16
$L$xts_dec_three::
movups xmm2,XMMWORD PTR[rdi]
movups xmm3,XMMWORD PTR[16+rdi]
movups xmm4,XMMWORD PTR[32+rdi]
lea rdi,QWORD PTR[48+rdi]
xorps xmm2,xmm10
xorps xmm3,xmm11
xorps xmm4,xmm12
call _aesni_decrypt3
xorps xmm2,xmm10
movdqa xmm10,xmm13
xorps xmm3,xmm11
movdqa xmm11,xmm15
xorps xmm4,xmm12
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
lea rsi,QWORD PTR[48+rsi]
jmp $L$xts_dec_done
ALIGN 16
$L$xts_dec_four::
pshufd xmm9,xmm14,013h
movdqa xmm14,xmm15
paddq xmm15,xmm15
movups xmm2,XMMWORD PTR[rdi]
pand xmm9,xmm8
movups xmm3,XMMWORD PTR[16+rdi]
pxor xmm15,xmm9
movups xmm4,XMMWORD PTR[32+rdi]
xorps xmm2,xmm10
movups xmm5,XMMWORD PTR[48+rdi]
lea rdi,QWORD PTR[64+rdi]
xorps xmm3,xmm11
xorps xmm4,xmm12
xorps xmm5,xmm13
call _aesni_decrypt4
xorps xmm2,xmm10
movdqa xmm10,xmm14
xorps xmm3,xmm11
movdqa xmm11,xmm15
xorps xmm4,xmm12
movups XMMWORD PTR[rsi],xmm2
xorps xmm5,xmm13
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
lea rsi,QWORD PTR[64+rsi]
jmp $L$xts_dec_done
ALIGN 16
$L$xts_dec_done::
and r9,15
jz $L$xts_dec_ret
$L$xts_dec_done2::
mov rdx,r9
mov rcx,r11
mov eax,r10d
movups xmm2,XMMWORD PTR[rdi]
xorps xmm2,xmm11
movups xmm0,XMMWORD PTR[rcx]
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
$L$oop_dec1_13::
DB 102,15,56,222,209
dec eax
movups xmm1,XMMWORD PTR[rcx]
lea rcx,QWORD PTR[16+rcx]
jnz $L$oop_dec1_13
DB 102,15,56,223,209
xorps xmm2,xmm11
movups XMMWORD PTR[rsi],xmm2
$L$xts_dec_steal::
movzx eax,BYTE PTR[16+rdi]
movzx ecx,BYTE PTR[rsi]
lea rdi,QWORD PTR[1+rdi]
mov BYTE PTR[rsi],al
mov BYTE PTR[16+rsi],cl
lea rsi,QWORD PTR[1+rsi]
sub rdx,1
jnz $L$xts_dec_steal
sub rsi,r9
mov rcx,r11
mov eax,r10d
movups xmm2,XMMWORD PTR[rsi]
xorps xmm2,xmm10
movups xmm0,XMMWORD PTR[rcx]
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
$L$oop_dec1_14::
DB 102,15,56,222,209
dec eax
movups xmm1,XMMWORD PTR[rcx]
lea rcx,QWORD PTR[16+rcx]
jnz $L$oop_dec1_14
DB 102,15,56,223,209
xorps xmm2,xmm10
movups XMMWORD PTR[rsi],xmm2
$L$xts_dec_ret::
movaps xmm6,XMMWORD PTR[96+rsp]
movaps xmm7,XMMWORD PTR[112+rsp]
movaps xmm8,XMMWORD PTR[128+rsp]
movaps xmm9,XMMWORD PTR[144+rsp]
movaps xmm10,XMMWORD PTR[160+rsp]
movaps xmm11,XMMWORD PTR[176+rsp]
movaps xmm12,XMMWORD PTR[192+rsp]
movaps xmm13,XMMWORD PTR[208+rsp]
movaps xmm14,XMMWORD PTR[224+rsp]
movaps xmm15,XMMWORD PTR[240+rsp]
lea rsp,QWORD PTR[264+rsp]
$L$xts_dec_epilogue::
mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
mov rsi,QWORD PTR[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_aesni_xts_decrypt::
aesni_xts_decrypt ENDP
PUBLIC aesni_cbc_encrypt
ALIGN 16
aesni_cbc_encrypt PROC PUBLIC
mov QWORD PTR[8+rsp],rdi ;WIN64 prologue
mov QWORD PTR[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_aesni_cbc_encrypt::
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD PTR[40+rsp]
mov r9,QWORD PTR[48+rsp]
test rdx,rdx
jz $L$cbc_ret
mov r10d,DWORD PTR[240+rcx]
mov r11,rcx
test r9d,r9d
jz $L$cbc_decrypt
movups xmm2,XMMWORD PTR[r8]
mov eax,r10d
cmp rdx,16
jb $L$cbc_enc_tail
sub rdx,16
jmp $L$cbc_enc_loop
ALIGN 16
$L$cbc_enc_loop::
movups xmm3,XMMWORD PTR[rdi]
lea rdi,QWORD PTR[16+rdi]
movups xmm0,XMMWORD PTR[rcx]
movups xmm1,XMMWORD PTR[16+rcx]
xorps xmm3,xmm0
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm3
$L$oop_enc1_15::
DB 102,15,56,220,209
dec eax
movups xmm1,XMMWORD PTR[rcx]
lea rcx,QWORD PTR[16+rcx]
jnz $L$oop_enc1_15
DB 102,15,56,221,209
mov eax,r10d
mov rcx,r11
movups XMMWORD PTR[rsi],xmm2
lea rsi,QWORD PTR[16+rsi]
sub rdx,16
jnc $L$cbc_enc_loop
add rdx,16
jnz $L$cbc_enc_tail
movups XMMWORD PTR[r8],xmm2
jmp $L$cbc_ret
$L$cbc_enc_tail::
mov rcx,rdx
xchg rsi,rdi
DD 09066A4F3h
mov ecx,16
sub rcx,rdx
xor eax,eax
DD 09066AAF3h
lea rdi,QWORD PTR[((-16))+rdi]
mov eax,r10d
mov rsi,rdi
mov rcx,r11
xor rdx,rdx
jmp $L$cbc_enc_loop
ALIGN 16
$L$cbc_decrypt::
lea rsp,QWORD PTR[((-88))+rsp]
movaps XMMWORD PTR[rsp],xmm6
movaps XMMWORD PTR[16+rsp],xmm7
movaps XMMWORD PTR[32+rsp],xmm8
movaps XMMWORD PTR[48+rsp],xmm9
$L$cbc_decrypt_body::
movups xmm9,XMMWORD PTR[r8]
mov eax,r10d
cmp rdx,070h
jbe $L$cbc_dec_tail
shr r10d,1
sub rdx,070h
mov eax,r10d
movaps XMMWORD PTR[64+rsp],xmm9
jmp $L$cbc_dec_loop8_enter
ALIGN 16
$L$cbc_dec_loop8::
movaps XMMWORD PTR[64+rsp],xmm0
movups XMMWORD PTR[rsi],xmm9
lea rsi,QWORD PTR[16+rsi]
$L$cbc_dec_loop8_enter::
movups xmm0,XMMWORD PTR[rcx]
movups xmm2,XMMWORD PTR[rdi]
movups xmm3,XMMWORD PTR[16+rdi]
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
movdqu xmm4,XMMWORD PTR[32+rdi]
xorps xmm2,xmm0
movdqu xmm5,XMMWORD PTR[48+rdi]
xorps xmm3,xmm0
movdqu xmm6,XMMWORD PTR[64+rdi]
DB 102,15,56,222,209
pxor xmm4,xmm0
movdqu xmm7,XMMWORD PTR[80+rdi]
DB 102,15,56,222,217
pxor xmm5,xmm0
movdqu xmm8,XMMWORD PTR[96+rdi]
DB 102,15,56,222,225
pxor xmm6,xmm0
movdqu xmm9,XMMWORD PTR[112+rdi]
DB 102,15,56,222,233
pxor xmm7,xmm0
dec eax
DB 102,15,56,222,241
pxor xmm8,xmm0
DB 102,15,56,222,249
pxor xmm9,xmm0
movups xmm0,XMMWORD PTR[rcx]
DB 102,68,15,56,222,193
DB 102,68,15,56,222,201
movups xmm1,XMMWORD PTR[16+rcx]
call $L$dec_loop8_enter
movups xmm1,XMMWORD PTR[rdi]
movups xmm0,XMMWORD PTR[16+rdi]
xorps xmm2,XMMWORD PTR[64+rsp]
xorps xmm3,xmm1
movups xmm1,XMMWORD PTR[32+rdi]
xorps xmm4,xmm0
movups xmm0,XMMWORD PTR[48+rdi]
xorps xmm5,xmm1
movups xmm1,XMMWORD PTR[64+rdi]
xorps xmm6,xmm0
movups xmm0,XMMWORD PTR[80+rdi]
xorps xmm7,xmm1
movups xmm1,XMMWORD PTR[96+rdi]
xorps xmm8,xmm0
movups xmm0,XMMWORD PTR[112+rdi]
xorps xmm9,xmm1
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
mov eax,r10d
movups XMMWORD PTR[64+rsi],xmm6
mov rcx,r11
movups XMMWORD PTR[80+rsi],xmm7
lea rdi,QWORD PTR[128+rdi]
movups XMMWORD PTR[96+rsi],xmm8
lea rsi,QWORD PTR[112+rsi]
sub rdx,080h
ja $L$cbc_dec_loop8
movaps xmm2,xmm9
movaps xmm9,xmm0
add rdx,070h
jle $L$cbc_dec_tail_collected
movups XMMWORD PTR[rsi],xmm2
lea eax,DWORD PTR[1+r10*1+r10]
lea rsi,QWORD PTR[16+rsi]
$L$cbc_dec_tail::
movups xmm2,XMMWORD PTR[rdi]
movaps xmm8,xmm2
cmp rdx,010h
jbe $L$cbc_dec_one
movups xmm3,XMMWORD PTR[16+rdi]
movaps xmm7,xmm3
cmp rdx,020h
jbe $L$cbc_dec_two
movups xmm4,XMMWORD PTR[32+rdi]
movaps xmm6,xmm4
cmp rdx,030h
jbe $L$cbc_dec_three
movups xmm5,XMMWORD PTR[48+rdi]
cmp rdx,040h
jbe $L$cbc_dec_four
movups xmm6,XMMWORD PTR[64+rdi]
cmp rdx,050h
jbe $L$cbc_dec_five
movups xmm7,XMMWORD PTR[80+rdi]
cmp rdx,060h
jbe $L$cbc_dec_six
movups xmm8,XMMWORD PTR[96+rdi]
movaps XMMWORD PTR[64+rsp],xmm9
call _aesni_decrypt8
movups xmm1,XMMWORD PTR[rdi]
movups xmm0,XMMWORD PTR[16+rdi]
xorps xmm2,XMMWORD PTR[64+rsp]
xorps xmm3,xmm1
movups xmm1,XMMWORD PTR[32+rdi]
xorps xmm4,xmm0
movups xmm0,XMMWORD PTR[48+rdi]
xorps xmm5,xmm1
movups xmm1,XMMWORD PTR[64+rdi]
xorps xmm6,xmm0
movups xmm0,XMMWORD PTR[80+rdi]
xorps xmm7,xmm1
movups xmm9,XMMWORD PTR[96+rdi]
xorps xmm8,xmm0
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
movups XMMWORD PTR[64+rsi],xmm6
movups XMMWORD PTR[80+rsi],xmm7
lea rsi,QWORD PTR[96+rsi]
movaps xmm2,xmm8
sub rdx,070h
jmp $L$cbc_dec_tail_collected
ALIGN 16
$L$cbc_dec_one::
movups xmm0,XMMWORD PTR[rcx]
movups xmm1,XMMWORD PTR[16+rcx]
lea rcx,QWORD PTR[32+rcx]
xorps xmm2,xmm0
$L$oop_dec1_16::
DB 102,15,56,222,209
dec eax
movups xmm1,XMMWORD PTR[rcx]
lea rcx,QWORD PTR[16+rcx]
jnz $L$oop_dec1_16
DB 102,15,56,223,209
xorps xmm2,xmm9
movaps xmm9,xmm8
sub rdx,010h
jmp $L$cbc_dec_tail_collected
ALIGN 16
$L$cbc_dec_two::
xorps xmm4,xmm4
call _aesni_decrypt3
xorps xmm2,xmm9
xorps xmm3,xmm8
movups XMMWORD PTR[rsi],xmm2
movaps xmm9,xmm7
movaps xmm2,xmm3
lea rsi,QWORD PTR[16+rsi]
sub rdx,020h
jmp $L$cbc_dec_tail_collected
ALIGN 16
$L$cbc_dec_three::
call _aesni_decrypt3
xorps xmm2,xmm9
xorps xmm3,xmm8
movups XMMWORD PTR[rsi],xmm2
xorps xmm4,xmm7
movups XMMWORD PTR[16+rsi],xmm3
movaps xmm9,xmm6
movaps xmm2,xmm4
lea rsi,QWORD PTR[32+rsi]
sub rdx,030h
jmp $L$cbc_dec_tail_collected
ALIGN 16
$L$cbc_dec_four::
call _aesni_decrypt4
xorps xmm2,xmm9
movups xmm9,XMMWORD PTR[48+rdi]
xorps xmm3,xmm8
movups XMMWORD PTR[rsi],xmm2
xorps xmm4,xmm7
movups XMMWORD PTR[16+rsi],xmm3
xorps xmm5,xmm6
movups XMMWORD PTR[32+rsi],xmm4
movaps xmm2,xmm5
lea rsi,QWORD PTR[48+rsi]
sub rdx,040h
jmp $L$cbc_dec_tail_collected
ALIGN 16
$L$cbc_dec_five::
xorps xmm7,xmm7
call _aesni_decrypt6
movups xmm1,XMMWORD PTR[16+rdi]
movups xmm0,XMMWORD PTR[32+rdi]
xorps xmm2,xmm9
xorps xmm3,xmm8
xorps xmm4,xmm1
movups xmm1,XMMWORD PTR[48+rdi]
xorps xmm5,xmm0
movups xmm9,XMMWORD PTR[64+rdi]
xorps xmm6,xmm1
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
lea rsi,QWORD PTR[64+rsi]
movaps xmm2,xmm6
sub rdx,050h
jmp $L$cbc_dec_tail_collected
ALIGN 16
$L$cbc_dec_six::
call _aesni_decrypt6
movups xmm1,XMMWORD PTR[16+rdi]
movups xmm0,XMMWORD PTR[32+rdi]
xorps xmm2,xmm9
xorps xmm3,xmm8
xorps xmm4,xmm1
movups xmm1,XMMWORD PTR[48+rdi]
xorps xmm5,xmm0
movups xmm0,XMMWORD PTR[64+rdi]
xorps xmm6,xmm1
movups xmm9,XMMWORD PTR[80+rdi]
xorps xmm7,xmm0
movups XMMWORD PTR[rsi],xmm2
movups XMMWORD PTR[16+rsi],xmm3
movups XMMWORD PTR[32+rsi],xmm4
movups XMMWORD PTR[48+rsi],xmm5
movups XMMWORD PTR[64+rsi],xmm6
lea rsi,QWORD PTR[80+rsi]
movaps xmm2,xmm7
sub rdx,060h
jmp $L$cbc_dec_tail_collected
ALIGN 16
$L$cbc_dec_tail_collected::
and rdx,15
movups XMMWORD PTR[r8],xmm9
jnz $L$cbc_dec_tail_partial
movups XMMWORD PTR[rsi],xmm2
jmp $L$cbc_dec_ret
ALIGN 16
$L$cbc_dec_tail_partial::
movaps XMMWORD PTR[64+rsp],xmm2
mov rcx,16
mov rdi,rsi
sub rcx,rdx
lea rsi,QWORD PTR[64+rsp]
DD 09066A4F3h
$L$cbc_dec_ret::
movaps xmm6,XMMWORD PTR[rsp]
movaps xmm7,XMMWORD PTR[16+rsp]
movaps xmm8,XMMWORD PTR[32+rsp]
movaps xmm9,XMMWORD PTR[48+rsp]
lea rsp,QWORD PTR[88+rsp]
$L$cbc_ret::
mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue
mov rsi,QWORD PTR[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_aesni_cbc_encrypt::
aesni_cbc_encrypt ENDP
PUBLIC aesni_set_decrypt_key
ALIGN 16
aesni_set_decrypt_key PROC PUBLIC
DB 048h,083h,0ECh,008h
call __aesni_set_encrypt_key
shl edx,4
test eax,eax
jnz $L$dec_key_ret
lea rcx,QWORD PTR[16+rdx*1+r8]
movups xmm0,XMMWORD PTR[r8]
movups xmm1,XMMWORD PTR[rcx]
movups XMMWORD PTR[rcx],xmm0
movups XMMWORD PTR[r8],xmm1
lea r8,QWORD PTR[16+r8]
lea rcx,QWORD PTR[((-16))+rcx]
$L$dec_key_inverse::
movups xmm0,XMMWORD PTR[r8]
movups xmm1,XMMWORD PTR[rcx]
DB 102,15,56,219,192
DB 102,15,56,219,201
lea r8,QWORD PTR[16+r8]
lea rcx,QWORD PTR[((-16))+rcx]
movups XMMWORD PTR[16+rcx],xmm0
movups XMMWORD PTR[(-16)+r8],xmm1
cmp rcx,r8
ja $L$dec_key_inverse
movups xmm0,XMMWORD PTR[r8]
DB 102,15,56,219,192
movups XMMWORD PTR[rcx],xmm0
$L$dec_key_ret::
add rsp,8
DB 0F3h,0C3h ;repret
$L$SEH_end_set_decrypt_key::
aesni_set_decrypt_key ENDP
PUBLIC aesni_set_encrypt_key
ALIGN 16
aesni_set_encrypt_key PROC PUBLIC
__aesni_set_encrypt_key::
DB 048h,083h,0ECh,008h
mov rax,-1
test rcx,rcx
jz $L$enc_key_ret
test r8,r8
jz $L$enc_key_ret
movups xmm0,XMMWORD PTR[rcx]
xorps xmm4,xmm4
lea rax,QWORD PTR[16+r8]
cmp edx,256
je $L$14rounds
cmp edx,192
je $L$12rounds
cmp edx,128
jne $L$bad_keybits
$L$10rounds::
mov edx,9
movups XMMWORD PTR[r8],xmm0
DB 102,15,58,223,200,1
call $L$key_expansion_128_cold
DB 102,15,58,223,200,2
call $L$key_expansion_128
DB 102,15,58,223,200,4
call $L$key_expansion_128
DB 102,15,58,223,200,8
call $L$key_expansion_128
DB 102,15,58,223,200,16
call $L$key_expansion_128
DB 102,15,58,223,200,32
call $L$key_expansion_128
DB 102,15,58,223,200,64
call $L$key_expansion_128
DB 102,15,58,223,200,128
call $L$key_expansion_128
DB 102,15,58,223,200,27
call $L$key_expansion_128
DB 102,15,58,223,200,54
call $L$key_expansion_128
movups XMMWORD PTR[rax],xmm0
mov DWORD PTR[80+rax],edx
xor eax,eax
jmp $L$enc_key_ret
ALIGN 16
$L$12rounds::
movq xmm2,QWORD PTR[16+rcx]
mov edx,11
movups XMMWORD PTR[r8],xmm0
DB 102,15,58,223,202,1
call $L$key_expansion_192a_cold
DB 102,15,58,223,202,2
call $L$key_expansion_192b
DB 102,15,58,223,202,4
call $L$key_expansion_192a
DB 102,15,58,223,202,8
call $L$key_expansion_192b
DB 102,15,58,223,202,16
call $L$key_expansion_192a
DB 102,15,58,223,202,32
call $L$key_expansion_192b
DB 102,15,58,223,202,64
call $L$key_expansion_192a
DB 102,15,58,223,202,128
call $L$key_expansion_192b
movups XMMWORD PTR[rax],xmm0
mov DWORD PTR[48+rax],edx
xor rax,rax
jmp $L$enc_key_ret
ALIGN 16
$L$14rounds::
movups xmm2,XMMWORD PTR[16+rcx]
mov edx,13
lea rax,QWORD PTR[16+rax]
movups XMMWORD PTR[r8],xmm0
movups XMMWORD PTR[16+r8],xmm2
DB 102,15,58,223,202,1
call $L$key_expansion_256a_cold
DB 102,15,58,223,200,1
call $L$key_expansion_256b
DB 102,15,58,223,202,2
call $L$key_expansion_256a
DB 102,15,58,223,200,2
call $L$key_expansion_256b
DB 102,15,58,223,202,4
call $L$key_expansion_256a
DB 102,15,58,223,200,4
call $L$key_expansion_256b
DB 102,15,58,223,202,8
call $L$key_expansion_256a
DB 102,15,58,223,200,8
call $L$key_expansion_256b
DB 102,15,58,223,202,16
call $L$key_expansion_256a
DB 102,15,58,223,200,16
call $L$key_expansion_256b
DB 102,15,58,223,202,32
call $L$key_expansion_256a
DB 102,15,58,223,200,32
call $L$key_expansion_256b
DB 102,15,58,223,202,64
call $L$key_expansion_256a
movups XMMWORD PTR[rax],xmm0
mov DWORD PTR[16+rax],edx
xor rax,rax
jmp $L$enc_key_ret
ALIGN 16
$L$bad_keybits::
mov rax,-2
$L$enc_key_ret::
add rsp,8
DB 0F3h,0C3h ;repret
$L$SEH_end_set_encrypt_key::
ALIGN 16
$L$key_expansion_128::
movups XMMWORD PTR[rax],xmm0
lea rax,QWORD PTR[16+rax]
$L$key_expansion_128_cold::
shufps xmm4,xmm0,16
xorps xmm0,xmm4
shufps xmm4,xmm0,140
xorps xmm0,xmm4
shufps xmm1,xmm1,255
xorps xmm0,xmm1
DB 0F3h,0C3h ;repret
ALIGN 16
$L$key_expansion_192a::
movups XMMWORD PTR[rax],xmm0
lea rax,QWORD PTR[16+rax]
$L$key_expansion_192a_cold::
movaps xmm5,xmm2
$L$key_expansion_192b_warm::
shufps xmm4,xmm0,16
movdqa xmm3,xmm2
xorps xmm0,xmm4
shufps xmm4,xmm0,140
pslldq xmm3,4
xorps xmm0,xmm4
pshufd xmm1,xmm1,85
pxor xmm2,xmm3
pxor xmm0,xmm1
pshufd xmm3,xmm0,255
pxor xmm2,xmm3
DB 0F3h,0C3h ;repret
ALIGN 16
$L$key_expansion_192b::
movaps xmm3,xmm0
shufps xmm5,xmm0,68
movups XMMWORD PTR[rax],xmm5
shufps xmm3,xmm2,78
movups XMMWORD PTR[16+rax],xmm3
lea rax,QWORD PTR[32+rax]
jmp $L$key_expansion_192b_warm
ALIGN 16
$L$key_expansion_256a::
movups XMMWORD PTR[rax],xmm2
lea rax,QWORD PTR[16+rax]
$L$key_expansion_256a_cold::
shufps xmm4,xmm0,16
xorps xmm0,xmm4
shufps xmm4,xmm0,140
xorps xmm0,xmm4
shufps xmm1,xmm1,255
xorps xmm0,xmm1
DB 0F3h,0C3h ;repret
ALIGN 16
$L$key_expansion_256b::
movups XMMWORD PTR[rax],xmm0
lea rax,QWORD PTR[16+rax]
shufps xmm4,xmm2,16
xorps xmm2,xmm4
shufps xmm4,xmm2,140
xorps xmm2,xmm4
shufps xmm1,xmm1,170
xorps xmm2,xmm1
DB 0F3h,0C3h ;repret
aesni_set_encrypt_key ENDP
ALIGN 64
$L$bswap_mask::
DB 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
$L$increment32::
DD 6,6,6,0
$L$increment64::
DD 1,0,0,0
$L$xts_magic::
DD 087h,0,1,0
DB 65,69,83,32,102,111,114,32,73,110,116,101,108,32,65,69
DB 83,45,78,73,44,32,67,82,89,80,84,79,71,65,77,83
DB 32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115
DB 115,108,46,111,114,103,62,0
ALIGN 64
EXTERN __imp_RtlVirtualUnwind:NEAR
ALIGN 16
ecb_ccm64_se_handler PROC PRIVATE
push rsi
push rdi
push rbx
push rbp
push r12
push r13
push r14
push r15
pushfq
sub rsp,64
mov rax,QWORD PTR[120+r8]
mov rbx,QWORD PTR[248+r8]
mov rsi,QWORD PTR[8+r9]
mov r11,QWORD PTR[56+r9]
mov r10d,DWORD PTR[r11]
lea r10,QWORD PTR[r10*1+rsi]
cmp rbx,r10
jb $L$common_seh_tail
mov rax,QWORD PTR[152+r8]
mov r10d,DWORD PTR[4+r11]
lea r10,QWORD PTR[r10*1+rsi]
cmp rbx,r10
jae $L$common_seh_tail
lea rsi,QWORD PTR[rax]
lea rdi,QWORD PTR[512+r8]
mov ecx,8
DD 0a548f3fch
lea rax,QWORD PTR[88+rax]
jmp $L$common_seh_tail
ecb_ccm64_se_handler ENDP
ALIGN 16
ctr32_se_handler PROC PRIVATE
push rsi
push rdi
push rbx
push rbp
push r12
push r13
push r14
push r15
pushfq
sub rsp,64
mov rax,QWORD PTR[120+r8]
mov rbx,QWORD PTR[248+r8]
lea r10,QWORD PTR[$L$ctr32_body]
cmp rbx,r10
jb $L$common_seh_tail
mov rax,QWORD PTR[152+r8]
lea r10,QWORD PTR[$L$ctr32_ret]
cmp rbx,r10
jae $L$common_seh_tail
lea rsi,QWORD PTR[32+rax]
lea rdi,QWORD PTR[512+r8]
mov ecx,20
DD 0a548f3fch
lea rax,QWORD PTR[200+rax]
jmp $L$common_seh_tail
ctr32_se_handler ENDP
ALIGN 16
xts_se_handler PROC PRIVATE
push rsi
push rdi
push rbx
push rbp
push r12
push r13
push r14
push r15
pushfq
sub rsp,64
mov rax,QWORD PTR[120+r8]
mov rbx,QWORD PTR[248+r8]
mov rsi,QWORD PTR[8+r9]
mov r11,QWORD PTR[56+r9]
mov r10d,DWORD PTR[r11]
lea r10,QWORD PTR[r10*1+rsi]
cmp rbx,r10
jb $L$common_seh_tail
mov rax,QWORD PTR[152+r8]
mov r10d,DWORD PTR[4+r11]
lea r10,QWORD PTR[r10*1+rsi]
cmp rbx,r10
jae $L$common_seh_tail
lea rsi,QWORD PTR[96+rax]
lea rdi,QWORD PTR[512+r8]
mov ecx,20
DD 0a548f3fch
lea rax,QWORD PTR[((104+160))+rax]
jmp $L$common_seh_tail
xts_se_handler ENDP
ALIGN 16
cbc_se_handler PROC PRIVATE
push rsi
push rdi
push rbx
push rbp
push r12
push r13
push r14
push r15
pushfq
sub rsp,64
mov rax,QWORD PTR[152+r8]
mov rbx,QWORD PTR[248+r8]
lea r10,QWORD PTR[$L$cbc_decrypt]
cmp rbx,r10
jb $L$common_seh_tail
lea r10,QWORD PTR[$L$cbc_decrypt_body]
cmp rbx,r10
jb $L$restore_cbc_rax
lea r10,QWORD PTR[$L$cbc_ret]
cmp rbx,r10
jae $L$common_seh_tail
lea rsi,QWORD PTR[rax]
lea rdi,QWORD PTR[512+r8]
mov ecx,8
DD 0a548f3fch
lea rax,QWORD PTR[88+rax]
jmp $L$common_seh_tail
$L$restore_cbc_rax::
mov rax,QWORD PTR[120+r8]
$L$common_seh_tail::
mov rdi,QWORD PTR[8+rax]
mov rsi,QWORD PTR[16+rax]
mov QWORD PTR[152+r8],rax
mov QWORD PTR[168+r8],rsi
mov QWORD PTR[176+r8],rdi
mov rdi,QWORD PTR[40+r9]
mov rsi,r8
mov ecx,154
DD 0a548f3fch
mov rsi,r9
xor rcx,rcx
mov rdx,QWORD PTR[8+rsi]
mov r8,QWORD PTR[rsi]
mov r9,QWORD PTR[16+rsi]
mov r10,QWORD PTR[40+rsi]
lea r11,QWORD PTR[56+rsi]
lea r12,QWORD PTR[24+rsi]
mov QWORD PTR[32+rsp],r10
mov QWORD PTR[40+rsp],r11
mov QWORD PTR[48+rsp],r12
mov QWORD PTR[56+rsp],rcx
call QWORD PTR[__imp_RtlVirtualUnwind]
mov eax,1
add rsp,64
popfq
pop r15
pop r14
pop r13
pop r12
pop rbp
pop rbx
pop rdi
pop rsi
DB 0F3h,0C3h ;repret
cbc_se_handler ENDP
.text$ ENDS
.pdata SEGMENT READONLY ALIGN(4)
ALIGN 4
DD imagerel $L$SEH_begin_aesni_ecb_encrypt
DD imagerel $L$SEH_end_aesni_ecb_encrypt
DD imagerel $L$SEH_info_ecb
DD imagerel $L$SEH_begin_aesni_ccm64_encrypt_blocks
DD imagerel $L$SEH_end_aesni_ccm64_encrypt_blocks
DD imagerel $L$SEH_info_ccm64_enc
DD imagerel $L$SEH_begin_aesni_ccm64_decrypt_blocks
DD imagerel $L$SEH_end_aesni_ccm64_decrypt_blocks
DD imagerel $L$SEH_info_ccm64_dec
DD imagerel $L$SEH_begin_aesni_ctr32_encrypt_blocks
DD imagerel $L$SEH_end_aesni_ctr32_encrypt_blocks
DD imagerel $L$SEH_info_ctr32
DD imagerel $L$SEH_begin_aesni_xts_encrypt
DD imagerel $L$SEH_end_aesni_xts_encrypt
DD imagerel $L$SEH_info_xts_enc
DD imagerel $L$SEH_begin_aesni_xts_decrypt
DD imagerel $L$SEH_end_aesni_xts_decrypt
DD imagerel $L$SEH_info_xts_dec
DD imagerel $L$SEH_begin_aesni_cbc_encrypt
DD imagerel $L$SEH_end_aesni_cbc_encrypt
DD imagerel $L$SEH_info_cbc
DD imagerel aesni_set_decrypt_key
DD imagerel $L$SEH_end_set_decrypt_key
DD imagerel $L$SEH_info_key
DD imagerel aesni_set_encrypt_key
DD imagerel $L$SEH_end_set_encrypt_key
DD imagerel $L$SEH_info_key
.pdata ENDS
.xdata SEGMENT READONLY ALIGN(8)
ALIGN 8
$L$SEH_info_ecb::
DB 9,0,0,0
DD imagerel ecb_ccm64_se_handler
DD imagerel $L$ecb_enc_body,imagerel $L$ecb_enc_ret
$L$SEH_info_ccm64_enc::
DB 9,0,0,0
DD imagerel ecb_ccm64_se_handler
DD imagerel $L$ccm64_enc_body,imagerel $L$ccm64_enc_ret
$L$SEH_info_ccm64_dec::
DB 9,0,0,0
DD imagerel ecb_ccm64_se_handler
DD imagerel $L$ccm64_dec_body,imagerel $L$ccm64_dec_ret
$L$SEH_info_ctr32::
DB 9,0,0,0
DD imagerel ctr32_se_handler
$L$SEH_info_xts_enc::
DB 9,0,0,0
DD imagerel xts_se_handler
DD imagerel $L$xts_enc_body,imagerel $L$xts_enc_epilogue
$L$SEH_info_xts_dec::
DB 9,0,0,0
DD imagerel xts_se_handler
DD imagerel $L$xts_dec_body,imagerel $L$xts_dec_epilogue
$L$SEH_info_cbc::
DB 9,0,0,0
DD imagerel cbc_se_handler
$L$SEH_info_key::
DB 001h,004h,001h,000h
DB 004h,002h,000h,000h
.xdata ENDS
END
|
; PC-G8xx / PC-E2xx Program boot
;
; Stefano Bodrato 2017
;
; $Id: g800_crt0.asm - Stefano Exp $
;
MODULE g800_crt0
;--------
; Include zcc_opt.def to find out some info
;--------
defc crt0 = 1
INCLUDE "zcc_opt.def"
;--------
; Some scope definitions
;--------
EXTERN _main ;main() is always external to crt0 code
PUBLIC cleanup ;jp'd to by exit()
PUBLIC l_dcal ;jp(hl)
;--------
; Set an origin for the application (-zorg=) default to $100
;--------
IF !DEFINED_CRT_ORG_CODE
defc CRT_ORG_CODE = $100
ENDIF
org CRT_ORG_CODE
start:
ld (start1+1),sp ;Save entry stack
IF STACKPTR
ld sp,STACKPTR
ELSE
; ld sp, $77df-64
ld hl,-64
add hl,sp
ld sp,hl
ENDIF
call crt0_init_bss
ld (exitsp),sp
; Optional definition for auto MALLOC init
; it assumes we have free space between the end of
; the compiled program and the stack pointer
IF DEFINED_USING_amalloc
INCLUDE "amalloc.def"
ENDIF
call _main ;Call user program
cleanup:
;
; Deallocate memory which has been allocated here!
;
IF !DEFINED_nostreams
EXTERN closeall
call closeall
ENDIF
cleanup_exit:
start1: ld sp,0 ;Restore stack to entry value
ret
l_dcal: jp (hl) ;Used for function pointer calls
defm "Small C+ G8xx" ;Unnecessary file signature
defb 0
INCLUDE "crt0_runtime_selection.asm"
INCLUDE "crt0_section.asm"
SECTION code_crt_init
; ld hl,??
; ld (base_graphics),hl
|
; A134025: Numbers for which the balanced ternary representation is the same length as the ternary representation.
; 0,1,3,4,9,10,11,12,13,27,28,29,30,31,32,33,34,35,36,37,38,39,40,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278
mov $1,$0
lpb $1
trn $2,$1
add $0,$2
sub $1,$2
trn $1,1
mov $2,$0
lpe
|
_cat: file format elf32-i386
Disassembly of section .text:
00001000 <main>:
}
}
int
main(int argc, char *argv[])
{
1000: f3 0f 1e fb endbr32
1004: 8d 4c 24 04 lea 0x4(%esp),%ecx
1008: 83 e4 f0 and $0xfffffff0,%esp
100b: ff 71 fc pushl -0x4(%ecx)
100e: 55 push %ebp
100f: 89 e5 mov %esp,%ebp
1011: 57 push %edi
1012: 56 push %esi
1013: be 01 00 00 00 mov $0x1,%esi
1018: 53 push %ebx
1019: 51 push %ecx
101a: 83 ec 18 sub $0x18,%esp
101d: 8b 01 mov (%ecx),%eax
101f: 8b 59 04 mov 0x4(%ecx),%ebx
1022: 89 45 e4 mov %eax,-0x1c(%ebp)
1025: 83 c3 04 add $0x4,%ebx
int fd, i;
if(argc <= 1){
1028: 83 f8 01 cmp $0x1,%eax
102b: 7e 50 jle 107d <main+0x7d>
102d: 8d 76 00 lea 0x0(%esi),%esi
cat(0);
exit();
}
for(i = 1; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
1030: 83 ec 08 sub $0x8,%esp
1033: 6a 00 push $0x0
1035: ff 33 pushl (%ebx)
1037: e8 77 03 00 00 call 13b3 <open>
103c: 83 c4 10 add $0x10,%esp
103f: 89 c7 mov %eax,%edi
1041: 85 c0 test %eax,%eax
1043: 78 24 js 1069 <main+0x69>
printf(1, "cat: cannot open %s\n", argv[i]);
exit();
}
cat(fd);
1045: 83 ec 0c sub $0xc,%esp
for(i = 1; i < argc; i++){
1048: 83 c6 01 add $0x1,%esi
104b: 83 c3 04 add $0x4,%ebx
cat(fd);
104e: 50 push %eax
104f: e8 3c 00 00 00 call 1090 <cat>
close(fd);
1054: 89 3c 24 mov %edi,(%esp)
1057: e8 3f 03 00 00 call 139b <close>
for(i = 1; i < argc; i++){
105c: 83 c4 10 add $0x10,%esp
105f: 39 75 e4 cmp %esi,-0x1c(%ebp)
1062: 75 cc jne 1030 <main+0x30>
}
exit();
1064: e8 0a 03 00 00 call 1373 <exit>
printf(1, "cat: cannot open %s\n", argv[i]);
1069: 50 push %eax
106a: ff 33 pushl (%ebx)
106c: 68 ab 18 00 00 push $0x18ab
1071: 6a 01 push $0x1
1073: e8 68 04 00 00 call 14e0 <printf>
exit();
1078: e8 f6 02 00 00 call 1373 <exit>
cat(0);
107d: 83 ec 0c sub $0xc,%esp
1080: 6a 00 push $0x0
1082: e8 09 00 00 00 call 1090 <cat>
exit();
1087: e8 e7 02 00 00 call 1373 <exit>
108c: 66 90 xchg %ax,%ax
108e: 66 90 xchg %ax,%ax
00001090 <cat>:
{
1090: f3 0f 1e fb endbr32
1094: 55 push %ebp
1095: 89 e5 mov %esp,%ebp
1097: 56 push %esi
1098: 8b 75 08 mov 0x8(%ebp),%esi
109b: 53 push %ebx
while((n = read(fd, buf, sizeof(buf))) > 0) {
109c: eb 19 jmp 10b7 <cat+0x27>
109e: 66 90 xchg %ax,%ax
if (write(1, buf, n) != n) {
10a0: 83 ec 04 sub $0x4,%esp
10a3: 53 push %ebx
10a4: 68 20 1c 00 00 push $0x1c20
10a9: 6a 01 push $0x1
10ab: e8 e3 02 00 00 call 1393 <write>
10b0: 83 c4 10 add $0x10,%esp
10b3: 39 d8 cmp %ebx,%eax
10b5: 75 25 jne 10dc <cat+0x4c>
while((n = read(fd, buf, sizeof(buf))) > 0) {
10b7: 83 ec 04 sub $0x4,%esp
10ba: 68 00 02 00 00 push $0x200
10bf: 68 20 1c 00 00 push $0x1c20
10c4: 56 push %esi
10c5: e8 c1 02 00 00 call 138b <read>
10ca: 83 c4 10 add $0x10,%esp
10cd: 89 c3 mov %eax,%ebx
10cf: 85 c0 test %eax,%eax
10d1: 7f cd jg 10a0 <cat+0x10>
if(n < 0){
10d3: 75 1b jne 10f0 <cat+0x60>
}
10d5: 8d 65 f8 lea -0x8(%ebp),%esp
10d8: 5b pop %ebx
10d9: 5e pop %esi
10da: 5d pop %ebp
10db: c3 ret
printf(1, "cat: write error\n");
10dc: 83 ec 08 sub $0x8,%esp
10df: 68 88 18 00 00 push $0x1888
10e4: 6a 01 push $0x1
10e6: e8 f5 03 00 00 call 14e0 <printf>
exit();
10eb: e8 83 02 00 00 call 1373 <exit>
printf(1, "cat: read error\n");
10f0: 50 push %eax
10f1: 50 push %eax
10f2: 68 9a 18 00 00 push $0x189a
10f7: 6a 01 push $0x1
10f9: e8 e2 03 00 00 call 14e0 <printf>
exit();
10fe: e8 70 02 00 00 call 1373 <exit>
1103: 66 90 xchg %ax,%ax
1105: 66 90 xchg %ax,%ax
1107: 66 90 xchg %ax,%ax
1109: 66 90 xchg %ax,%ax
110b: 66 90 xchg %ax,%ax
110d: 66 90 xchg %ax,%ax
110f: 90 nop
00001110 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
1110: f3 0f 1e fb endbr32
1114: 55 push %ebp
char *os;
os = s;
while((*s++ = *t++) != 0)
1115: 31 c0 xor %eax,%eax
{
1117: 89 e5 mov %esp,%ebp
1119: 53 push %ebx
111a: 8b 4d 08 mov 0x8(%ebp),%ecx
111d: 8b 5d 0c mov 0xc(%ebp),%ebx
while((*s++ = *t++) != 0)
1120: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx
1124: 88 14 01 mov %dl,(%ecx,%eax,1)
1127: 83 c0 01 add $0x1,%eax
112a: 84 d2 test %dl,%dl
112c: 75 f2 jne 1120 <strcpy+0x10>
;
return os;
}
112e: 89 c8 mov %ecx,%eax
1130: 5b pop %ebx
1131: 5d pop %ebp
1132: c3 ret
1133: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
113a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
00001140 <strcmp>:
int
strcmp(const char *p, const char *q)
{
1140: f3 0f 1e fb endbr32
1144: 55 push %ebp
1145: 89 e5 mov %esp,%ebp
1147: 53 push %ebx
1148: 8b 4d 08 mov 0x8(%ebp),%ecx
114b: 8b 55 0c mov 0xc(%ebp),%edx
while(*p && *p == *q)
114e: 0f b6 01 movzbl (%ecx),%eax
1151: 0f b6 1a movzbl (%edx),%ebx
1154: 84 c0 test %al,%al
1156: 75 19 jne 1171 <strcmp+0x31>
1158: eb 26 jmp 1180 <strcmp+0x40>
115a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
1160: 0f b6 41 01 movzbl 0x1(%ecx),%eax
p++, q++;
1164: 83 c1 01 add $0x1,%ecx
1167: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
116a: 0f b6 1a movzbl (%edx),%ebx
116d: 84 c0 test %al,%al
116f: 74 0f je 1180 <strcmp+0x40>
1171: 38 d8 cmp %bl,%al
1173: 74 eb je 1160 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
1175: 29 d8 sub %ebx,%eax
}
1177: 5b pop %ebx
1178: 5d pop %ebp
1179: c3 ret
117a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
1180: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
1182: 29 d8 sub %ebx,%eax
}
1184: 5b pop %ebx
1185: 5d pop %ebp
1186: c3 ret
1187: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
118e: 66 90 xchg %ax,%ax
00001190 <strlen>:
uint
strlen(char *s)
{
1190: f3 0f 1e fb endbr32
1194: 55 push %ebp
1195: 89 e5 mov %esp,%ebp
1197: 8b 55 08 mov 0x8(%ebp),%edx
int n;
for(n = 0; s[n]; n++)
119a: 80 3a 00 cmpb $0x0,(%edx)
119d: 74 21 je 11c0 <strlen+0x30>
119f: 31 c0 xor %eax,%eax
11a1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
11a8: 83 c0 01 add $0x1,%eax
11ab: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1)
11af: 89 c1 mov %eax,%ecx
11b1: 75 f5 jne 11a8 <strlen+0x18>
;
return n;
}
11b3: 89 c8 mov %ecx,%eax
11b5: 5d pop %ebp
11b6: c3 ret
11b7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
11be: 66 90 xchg %ax,%ax
for(n = 0; s[n]; n++)
11c0: 31 c9 xor %ecx,%ecx
}
11c2: 5d pop %ebp
11c3: 89 c8 mov %ecx,%eax
11c5: c3 ret
11c6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
11cd: 8d 76 00 lea 0x0(%esi),%esi
000011d0 <memset>:
void*
memset(void *dst, int c, uint n)
{
11d0: f3 0f 1e fb endbr32
11d4: 55 push %ebp
11d5: 89 e5 mov %esp,%ebp
11d7: 57 push %edi
11d8: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
11db: 8b 4d 10 mov 0x10(%ebp),%ecx
11de: 8b 45 0c mov 0xc(%ebp),%eax
11e1: 89 d7 mov %edx,%edi
11e3: fc cld
11e4: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
11e6: 89 d0 mov %edx,%eax
11e8: 5f pop %edi
11e9: 5d pop %ebp
11ea: c3 ret
11eb: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
11ef: 90 nop
000011f0 <strchr>:
char*
strchr(const char *s, char c)
{
11f0: f3 0f 1e fb endbr32
11f4: 55 push %ebp
11f5: 89 e5 mov %esp,%ebp
11f7: 8b 45 08 mov 0x8(%ebp),%eax
11fa: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx
for(; *s; s++)
11fe: 0f b6 10 movzbl (%eax),%edx
1201: 84 d2 test %dl,%dl
1203: 75 16 jne 121b <strchr+0x2b>
1205: eb 21 jmp 1228 <strchr+0x38>
1207: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
120e: 66 90 xchg %ax,%ax
1210: 0f b6 50 01 movzbl 0x1(%eax),%edx
1214: 83 c0 01 add $0x1,%eax
1217: 84 d2 test %dl,%dl
1219: 74 0d je 1228 <strchr+0x38>
if(*s == c)
121b: 38 d1 cmp %dl,%cl
121d: 75 f1 jne 1210 <strchr+0x20>
return (char*)s;
return 0;
}
121f: 5d pop %ebp
1220: c3 ret
1221: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
return 0;
1228: 31 c0 xor %eax,%eax
}
122a: 5d pop %ebp
122b: c3 ret
122c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00001230 <gets>:
char*
gets(char *buf, int max)
{
1230: f3 0f 1e fb endbr32
1234: 55 push %ebp
1235: 89 e5 mov %esp,%ebp
1237: 57 push %edi
1238: 56 push %esi
int i, cc;
char c;
for(i=0; i+1 < max; ){
1239: 31 f6 xor %esi,%esi
{
123b: 53 push %ebx
123c: 89 f3 mov %esi,%ebx
123e: 83 ec 1c sub $0x1c,%esp
1241: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
1244: eb 33 jmp 1279 <gets+0x49>
1246: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
124d: 8d 76 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
1250: 83 ec 04 sub $0x4,%esp
1253: 8d 45 e7 lea -0x19(%ebp),%eax
1256: 6a 01 push $0x1
1258: 50 push %eax
1259: 6a 00 push $0x0
125b: e8 2b 01 00 00 call 138b <read>
if(cc < 1)
1260: 83 c4 10 add $0x10,%esp
1263: 85 c0 test %eax,%eax
1265: 7e 1c jle 1283 <gets+0x53>
break;
buf[i++] = c;
1267: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
126b: 83 c7 01 add $0x1,%edi
126e: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
1271: 3c 0a cmp $0xa,%al
1273: 74 23 je 1298 <gets+0x68>
1275: 3c 0d cmp $0xd,%al
1277: 74 1f je 1298 <gets+0x68>
for(i=0; i+1 < max; ){
1279: 83 c3 01 add $0x1,%ebx
127c: 89 fe mov %edi,%esi
127e: 3b 5d 0c cmp 0xc(%ebp),%ebx
1281: 7c cd jl 1250 <gets+0x20>
1283: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
1285: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
1288: c6 03 00 movb $0x0,(%ebx)
}
128b: 8d 65 f4 lea -0xc(%ebp),%esp
128e: 5b pop %ebx
128f: 5e pop %esi
1290: 5f pop %edi
1291: 5d pop %ebp
1292: c3 ret
1293: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
1297: 90 nop
1298: 8b 75 08 mov 0x8(%ebp),%esi
129b: 8b 45 08 mov 0x8(%ebp),%eax
129e: 01 de add %ebx,%esi
12a0: 89 f3 mov %esi,%ebx
buf[i] = '\0';
12a2: c6 03 00 movb $0x0,(%ebx)
}
12a5: 8d 65 f4 lea -0xc(%ebp),%esp
12a8: 5b pop %ebx
12a9: 5e pop %esi
12aa: 5f pop %edi
12ab: 5d pop %ebp
12ac: c3 ret
12ad: 8d 76 00 lea 0x0(%esi),%esi
000012b0 <stat>:
int
stat(char *n, struct stat *st)
{
12b0: f3 0f 1e fb endbr32
12b4: 55 push %ebp
12b5: 89 e5 mov %esp,%ebp
12b7: 56 push %esi
12b8: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
12b9: 83 ec 08 sub $0x8,%esp
12bc: 6a 00 push $0x0
12be: ff 75 08 pushl 0x8(%ebp)
12c1: e8 ed 00 00 00 call 13b3 <open>
if(fd < 0)
12c6: 83 c4 10 add $0x10,%esp
12c9: 85 c0 test %eax,%eax
12cb: 78 2b js 12f8 <stat+0x48>
return -1;
r = fstat(fd, st);
12cd: 83 ec 08 sub $0x8,%esp
12d0: ff 75 0c pushl 0xc(%ebp)
12d3: 89 c3 mov %eax,%ebx
12d5: 50 push %eax
12d6: e8 f0 00 00 00 call 13cb <fstat>
close(fd);
12db: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
12de: 89 c6 mov %eax,%esi
close(fd);
12e0: e8 b6 00 00 00 call 139b <close>
return r;
12e5: 83 c4 10 add $0x10,%esp
}
12e8: 8d 65 f8 lea -0x8(%ebp),%esp
12eb: 89 f0 mov %esi,%eax
12ed: 5b pop %ebx
12ee: 5e pop %esi
12ef: 5d pop %ebp
12f0: c3 ret
12f1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
return -1;
12f8: be ff ff ff ff mov $0xffffffff,%esi
12fd: eb e9 jmp 12e8 <stat+0x38>
12ff: 90 nop
00001300 <atoi>:
int
atoi(const char *s)
{
1300: f3 0f 1e fb endbr32
1304: 55 push %ebp
1305: 89 e5 mov %esp,%ebp
1307: 53 push %ebx
1308: 8b 55 08 mov 0x8(%ebp),%edx
int n;
n = 0;
while('0' <= *s && *s <= '9')
130b: 0f be 02 movsbl (%edx),%eax
130e: 8d 48 d0 lea -0x30(%eax),%ecx
1311: 80 f9 09 cmp $0x9,%cl
n = 0;
1314: b9 00 00 00 00 mov $0x0,%ecx
while('0' <= *s && *s <= '9')
1319: 77 1a ja 1335 <atoi+0x35>
131b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
131f: 90 nop
n = n*10 + *s++ - '0';
1320: 83 c2 01 add $0x1,%edx
1323: 8d 0c 89 lea (%ecx,%ecx,4),%ecx
1326: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx
while('0' <= *s && *s <= '9')
132a: 0f be 02 movsbl (%edx),%eax
132d: 8d 58 d0 lea -0x30(%eax),%ebx
1330: 80 fb 09 cmp $0x9,%bl
1333: 76 eb jbe 1320 <atoi+0x20>
return n;
}
1335: 89 c8 mov %ecx,%eax
1337: 5b pop %ebx
1338: 5d pop %ebp
1339: c3 ret
133a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
00001340 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
1340: f3 0f 1e fb endbr32
1344: 55 push %ebp
1345: 89 e5 mov %esp,%ebp
1347: 57 push %edi
1348: 8b 45 10 mov 0x10(%ebp),%eax
134b: 8b 55 08 mov 0x8(%ebp),%edx
134e: 56 push %esi
134f: 8b 75 0c mov 0xc(%ebp),%esi
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
1352: 85 c0 test %eax,%eax
1354: 7e 0f jle 1365 <memmove+0x25>
1356: 01 d0 add %edx,%eax
dst = vdst;
1358: 89 d7 mov %edx,%edi
135a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
*dst++ = *src++;
1360: a4 movsb %ds:(%esi),%es:(%edi)
while(n-- > 0)
1361: 39 f8 cmp %edi,%eax
1363: 75 fb jne 1360 <memmove+0x20>
return vdst;
}
1365: 5e pop %esi
1366: 89 d0 mov %edx,%eax
1368: 5f pop %edi
1369: 5d pop %ebp
136a: c3 ret
0000136b <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
136b: b8 01 00 00 00 mov $0x1,%eax
1370: cd 40 int $0x40
1372: c3 ret
00001373 <exit>:
SYSCALL(exit)
1373: b8 02 00 00 00 mov $0x2,%eax
1378: cd 40 int $0x40
137a: c3 ret
0000137b <wait>:
SYSCALL(wait)
137b: b8 03 00 00 00 mov $0x3,%eax
1380: cd 40 int $0x40
1382: c3 ret
00001383 <pipe>:
SYSCALL(pipe)
1383: b8 04 00 00 00 mov $0x4,%eax
1388: cd 40 int $0x40
138a: c3 ret
0000138b <read>:
SYSCALL(read)
138b: b8 05 00 00 00 mov $0x5,%eax
1390: cd 40 int $0x40
1392: c3 ret
00001393 <write>:
SYSCALL(write)
1393: b8 10 00 00 00 mov $0x10,%eax
1398: cd 40 int $0x40
139a: c3 ret
0000139b <close>:
SYSCALL(close)
139b: b8 15 00 00 00 mov $0x15,%eax
13a0: cd 40 int $0x40
13a2: c3 ret
000013a3 <kill>:
SYSCALL(kill)
13a3: b8 06 00 00 00 mov $0x6,%eax
13a8: cd 40 int $0x40
13aa: c3 ret
000013ab <exec>:
SYSCALL(exec)
13ab: b8 07 00 00 00 mov $0x7,%eax
13b0: cd 40 int $0x40
13b2: c3 ret
000013b3 <open>:
SYSCALL(open)
13b3: b8 0f 00 00 00 mov $0xf,%eax
13b8: cd 40 int $0x40
13ba: c3 ret
000013bb <mknod>:
SYSCALL(mknod)
13bb: b8 11 00 00 00 mov $0x11,%eax
13c0: cd 40 int $0x40
13c2: c3 ret
000013c3 <unlink>:
SYSCALL(unlink)
13c3: b8 12 00 00 00 mov $0x12,%eax
13c8: cd 40 int $0x40
13ca: c3 ret
000013cb <fstat>:
SYSCALL(fstat)
13cb: b8 08 00 00 00 mov $0x8,%eax
13d0: cd 40 int $0x40
13d2: c3 ret
000013d3 <link>:
SYSCALL(link)
13d3: b8 13 00 00 00 mov $0x13,%eax
13d8: cd 40 int $0x40
13da: c3 ret
000013db <mkdir>:
SYSCALL(mkdir)
13db: b8 14 00 00 00 mov $0x14,%eax
13e0: cd 40 int $0x40
13e2: c3 ret
000013e3 <chdir>:
SYSCALL(chdir)
13e3: b8 09 00 00 00 mov $0x9,%eax
13e8: cd 40 int $0x40
13ea: c3 ret
000013eb <dup>:
SYSCALL(dup)
13eb: b8 0a 00 00 00 mov $0xa,%eax
13f0: cd 40 int $0x40
13f2: c3 ret
000013f3 <getpid>:
SYSCALL(getpid)
13f3: b8 0b 00 00 00 mov $0xb,%eax
13f8: cd 40 int $0x40
13fa: c3 ret
000013fb <sbrk>:
SYSCALL(sbrk)
13fb: b8 0c 00 00 00 mov $0xc,%eax
1400: cd 40 int $0x40
1402: c3 ret
00001403 <sleep>:
SYSCALL(sleep)
1403: b8 0d 00 00 00 mov $0xd,%eax
1408: cd 40 int $0x40
140a: c3 ret
0000140b <uptime>:
SYSCALL(uptime)
140b: b8 0e 00 00 00 mov $0xe,%eax
1410: cd 40 int $0x40
1412: c3 ret
00001413 <shm_open>:
SYSCALL(shm_open)
1413: b8 16 00 00 00 mov $0x16,%eax
1418: cd 40 int $0x40
141a: c3 ret
0000141b <shm_close>:
SYSCALL(shm_close)
141b: b8 17 00 00 00 mov $0x17,%eax
1420: cd 40 int $0x40
1422: c3 ret
1423: 66 90 xchg %ax,%ax
1425: 66 90 xchg %ax,%ax
1427: 66 90 xchg %ax,%ax
1429: 66 90 xchg %ax,%ax
142b: 66 90 xchg %ax,%ax
142d: 66 90 xchg %ax,%ax
142f: 90 nop
00001430 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
1430: 55 push %ebp
1431: 89 e5 mov %esp,%ebp
1433: 57 push %edi
1434: 56 push %esi
1435: 53 push %ebx
1436: 83 ec 3c sub $0x3c,%esp
1439: 89 4d c4 mov %ecx,-0x3c(%ebp)
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
143c: 89 d1 mov %edx,%ecx
{
143e: 89 45 b8 mov %eax,-0x48(%ebp)
if(sgn && xx < 0){
1441: 85 d2 test %edx,%edx
1443: 0f 89 7f 00 00 00 jns 14c8 <printint+0x98>
1449: f6 45 08 01 testb $0x1,0x8(%ebp)
144d: 74 79 je 14c8 <printint+0x98>
neg = 1;
144f: c7 45 bc 01 00 00 00 movl $0x1,-0x44(%ebp)
x = -xx;
1456: f7 d9 neg %ecx
} else {
x = xx;
}
i = 0;
1458: 31 db xor %ebx,%ebx
145a: 8d 75 d7 lea -0x29(%ebp),%esi
145d: 8d 76 00 lea 0x0(%esi),%esi
do{
buf[i++] = digits[x % base];
1460: 89 c8 mov %ecx,%eax
1462: 31 d2 xor %edx,%edx
1464: 89 cf mov %ecx,%edi
1466: f7 75 c4 divl -0x3c(%ebp)
1469: 0f b6 92 c8 18 00 00 movzbl 0x18c8(%edx),%edx
1470: 89 45 c0 mov %eax,-0x40(%ebp)
1473: 89 d8 mov %ebx,%eax
1475: 8d 5b 01 lea 0x1(%ebx),%ebx
}while((x /= base) != 0);
1478: 8b 4d c0 mov -0x40(%ebp),%ecx
buf[i++] = digits[x % base];
147b: 88 14 1e mov %dl,(%esi,%ebx,1)
}while((x /= base) != 0);
147e: 39 7d c4 cmp %edi,-0x3c(%ebp)
1481: 76 dd jbe 1460 <printint+0x30>
if(neg)
1483: 8b 4d bc mov -0x44(%ebp),%ecx
1486: 85 c9 test %ecx,%ecx
1488: 74 0c je 1496 <printint+0x66>
buf[i++] = '-';
148a: c6 44 1d d8 2d movb $0x2d,-0x28(%ebp,%ebx,1)
buf[i++] = digits[x % base];
148f: 89 d8 mov %ebx,%eax
buf[i++] = '-';
1491: ba 2d 00 00 00 mov $0x2d,%edx
while(--i >= 0)
1496: 8b 7d b8 mov -0x48(%ebp),%edi
1499: 8d 5c 05 d7 lea -0x29(%ebp,%eax,1),%ebx
149d: eb 07 jmp 14a6 <printint+0x76>
149f: 90 nop
14a0: 0f b6 13 movzbl (%ebx),%edx
14a3: 83 eb 01 sub $0x1,%ebx
write(fd, &c, 1);
14a6: 83 ec 04 sub $0x4,%esp
14a9: 88 55 d7 mov %dl,-0x29(%ebp)
14ac: 6a 01 push $0x1
14ae: 56 push %esi
14af: 57 push %edi
14b0: e8 de fe ff ff call 1393 <write>
while(--i >= 0)
14b5: 83 c4 10 add $0x10,%esp
14b8: 39 de cmp %ebx,%esi
14ba: 75 e4 jne 14a0 <printint+0x70>
putc(fd, buf[i]);
}
14bc: 8d 65 f4 lea -0xc(%ebp),%esp
14bf: 5b pop %ebx
14c0: 5e pop %esi
14c1: 5f pop %edi
14c2: 5d pop %ebp
14c3: c3 ret
14c4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
14c8: c7 45 bc 00 00 00 00 movl $0x0,-0x44(%ebp)
14cf: eb 87 jmp 1458 <printint+0x28>
14d1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
14d8: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
14df: 90 nop
000014e0 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
14e0: f3 0f 1e fb endbr32
14e4: 55 push %ebp
14e5: 89 e5 mov %esp,%ebp
14e7: 57 push %edi
14e8: 56 push %esi
14e9: 53 push %ebx
14ea: 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++){
14ed: 8b 75 0c mov 0xc(%ebp),%esi
14f0: 0f b6 1e movzbl (%esi),%ebx
14f3: 84 db test %bl,%bl
14f5: 0f 84 b4 00 00 00 je 15af <printf+0xcf>
ap = (uint*)(void*)&fmt + 1;
14fb: 8d 45 10 lea 0x10(%ebp),%eax
14fe: 83 c6 01 add $0x1,%esi
write(fd, &c, 1);
1501: 8d 7d e7 lea -0x19(%ebp),%edi
state = 0;
1504: 31 d2 xor %edx,%edx
ap = (uint*)(void*)&fmt + 1;
1506: 89 45 d0 mov %eax,-0x30(%ebp)
1509: eb 33 jmp 153e <printf+0x5e>
150b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
150f: 90 nop
1510: 89 55 d4 mov %edx,-0x2c(%ebp)
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
state = '%';
1513: ba 25 00 00 00 mov $0x25,%edx
if(c == '%'){
1518: 83 f8 25 cmp $0x25,%eax
151b: 74 17 je 1534 <printf+0x54>
write(fd, &c, 1);
151d: 83 ec 04 sub $0x4,%esp
1520: 88 5d e7 mov %bl,-0x19(%ebp)
1523: 6a 01 push $0x1
1525: 57 push %edi
1526: ff 75 08 pushl 0x8(%ebp)
1529: e8 65 fe ff ff call 1393 <write>
152e: 8b 55 d4 mov -0x2c(%ebp),%edx
} else {
putc(fd, c);
1531: 83 c4 10 add $0x10,%esp
for(i = 0; fmt[i]; i++){
1534: 0f b6 1e movzbl (%esi),%ebx
1537: 83 c6 01 add $0x1,%esi
153a: 84 db test %bl,%bl
153c: 74 71 je 15af <printf+0xcf>
c = fmt[i] & 0xff;
153e: 0f be cb movsbl %bl,%ecx
1541: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
1544: 85 d2 test %edx,%edx
1546: 74 c8 je 1510 <printf+0x30>
}
} else if(state == '%'){
1548: 83 fa 25 cmp $0x25,%edx
154b: 75 e7 jne 1534 <printf+0x54>
if(c == 'd'){
154d: 83 f8 64 cmp $0x64,%eax
1550: 0f 84 9a 00 00 00 je 15f0 <printf+0x110>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
1556: 81 e1 f7 00 00 00 and $0xf7,%ecx
155c: 83 f9 70 cmp $0x70,%ecx
155f: 74 5f je 15c0 <printf+0xe0>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
1561: 83 f8 73 cmp $0x73,%eax
1564: 0f 84 d6 00 00 00 je 1640 <printf+0x160>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
156a: 83 f8 63 cmp $0x63,%eax
156d: 0f 84 8d 00 00 00 je 1600 <printf+0x120>
putc(fd, *ap);
ap++;
} else if(c == '%'){
1573: 83 f8 25 cmp $0x25,%eax
1576: 0f 84 b4 00 00 00 je 1630 <printf+0x150>
write(fd, &c, 1);
157c: 83 ec 04 sub $0x4,%esp
157f: c6 45 e7 25 movb $0x25,-0x19(%ebp)
1583: 6a 01 push $0x1
1585: 57 push %edi
1586: ff 75 08 pushl 0x8(%ebp)
1589: e8 05 fe ff ff call 1393 <write>
putc(fd, c);
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
158e: 88 5d e7 mov %bl,-0x19(%ebp)
write(fd, &c, 1);
1591: 83 c4 0c add $0xc,%esp
1594: 6a 01 push $0x1
1596: 83 c6 01 add $0x1,%esi
1599: 57 push %edi
159a: ff 75 08 pushl 0x8(%ebp)
159d: e8 f1 fd ff ff call 1393 <write>
for(i = 0; fmt[i]; i++){
15a2: 0f b6 5e ff movzbl -0x1(%esi),%ebx
putc(fd, c);
15a6: 83 c4 10 add $0x10,%esp
}
state = 0;
15a9: 31 d2 xor %edx,%edx
for(i = 0; fmt[i]; i++){
15ab: 84 db test %bl,%bl
15ad: 75 8f jne 153e <printf+0x5e>
}
}
}
15af: 8d 65 f4 lea -0xc(%ebp),%esp
15b2: 5b pop %ebx
15b3: 5e pop %esi
15b4: 5f pop %edi
15b5: 5d pop %ebp
15b6: c3 ret
15b7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
15be: 66 90 xchg %ax,%ax
printint(fd, *ap, 16, 0);
15c0: 83 ec 0c sub $0xc,%esp
15c3: b9 10 00 00 00 mov $0x10,%ecx
15c8: 6a 00 push $0x0
15ca: 8b 5d d0 mov -0x30(%ebp),%ebx
15cd: 8b 45 08 mov 0x8(%ebp),%eax
15d0: 8b 13 mov (%ebx),%edx
15d2: e8 59 fe ff ff call 1430 <printint>
ap++;
15d7: 89 d8 mov %ebx,%eax
15d9: 83 c4 10 add $0x10,%esp
state = 0;
15dc: 31 d2 xor %edx,%edx
ap++;
15de: 83 c0 04 add $0x4,%eax
15e1: 89 45 d0 mov %eax,-0x30(%ebp)
15e4: e9 4b ff ff ff jmp 1534 <printf+0x54>
15e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
printint(fd, *ap, 10, 1);
15f0: 83 ec 0c sub $0xc,%esp
15f3: b9 0a 00 00 00 mov $0xa,%ecx
15f8: 6a 01 push $0x1
15fa: eb ce jmp 15ca <printf+0xea>
15fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
putc(fd, *ap);
1600: 8b 5d d0 mov -0x30(%ebp),%ebx
write(fd, &c, 1);
1603: 83 ec 04 sub $0x4,%esp
putc(fd, *ap);
1606: 8b 03 mov (%ebx),%eax
write(fd, &c, 1);
1608: 6a 01 push $0x1
ap++;
160a: 83 c3 04 add $0x4,%ebx
write(fd, &c, 1);
160d: 57 push %edi
160e: ff 75 08 pushl 0x8(%ebp)
putc(fd, *ap);
1611: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
1614: e8 7a fd ff ff call 1393 <write>
ap++;
1619: 89 5d d0 mov %ebx,-0x30(%ebp)
161c: 83 c4 10 add $0x10,%esp
state = 0;
161f: 31 d2 xor %edx,%edx
1621: e9 0e ff ff ff jmp 1534 <printf+0x54>
1626: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
162d: 8d 76 00 lea 0x0(%esi),%esi
putc(fd, c);
1630: 88 5d e7 mov %bl,-0x19(%ebp)
write(fd, &c, 1);
1633: 83 ec 04 sub $0x4,%esp
1636: e9 59 ff ff ff jmp 1594 <printf+0xb4>
163b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
163f: 90 nop
s = (char*)*ap;
1640: 8b 45 d0 mov -0x30(%ebp),%eax
1643: 8b 18 mov (%eax),%ebx
ap++;
1645: 83 c0 04 add $0x4,%eax
1648: 89 45 d0 mov %eax,-0x30(%ebp)
if(s == 0)
164b: 85 db test %ebx,%ebx
164d: 74 17 je 1666 <printf+0x186>
while(*s != 0){
164f: 0f b6 03 movzbl (%ebx),%eax
state = 0;
1652: 31 d2 xor %edx,%edx
while(*s != 0){
1654: 84 c0 test %al,%al
1656: 0f 84 d8 fe ff ff je 1534 <printf+0x54>
165c: 89 75 d4 mov %esi,-0x2c(%ebp)
165f: 89 de mov %ebx,%esi
1661: 8b 5d 08 mov 0x8(%ebp),%ebx
1664: eb 1a jmp 1680 <printf+0x1a0>
s = "(null)";
1666: bb c0 18 00 00 mov $0x18c0,%ebx
while(*s != 0){
166b: 89 75 d4 mov %esi,-0x2c(%ebp)
166e: b8 28 00 00 00 mov $0x28,%eax
1673: 89 de mov %ebx,%esi
1675: 8b 5d 08 mov 0x8(%ebp),%ebx
1678: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
167f: 90 nop
write(fd, &c, 1);
1680: 83 ec 04 sub $0x4,%esp
s++;
1683: 83 c6 01 add $0x1,%esi
1686: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
1689: 6a 01 push $0x1
168b: 57 push %edi
168c: 53 push %ebx
168d: e8 01 fd ff ff call 1393 <write>
while(*s != 0){
1692: 0f b6 06 movzbl (%esi),%eax
1695: 83 c4 10 add $0x10,%esp
1698: 84 c0 test %al,%al
169a: 75 e4 jne 1680 <printf+0x1a0>
169c: 8b 75 d4 mov -0x2c(%ebp),%esi
state = 0;
169f: 31 d2 xor %edx,%edx
16a1: e9 8e fe ff ff jmp 1534 <printf+0x54>
16a6: 66 90 xchg %ax,%ax
16a8: 66 90 xchg %ax,%ax
16aa: 66 90 xchg %ax,%ax
16ac: 66 90 xchg %ax,%ax
16ae: 66 90 xchg %ax,%ax
000016b0 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
16b0: f3 0f 1e fb endbr32
16b4: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
16b5: a1 00 1c 00 00 mov 0x1c00,%eax
{
16ba: 89 e5 mov %esp,%ebp
16bc: 57 push %edi
16bd: 56 push %esi
16be: 53 push %ebx
16bf: 8b 5d 08 mov 0x8(%ebp),%ebx
16c2: 8b 10 mov (%eax),%edx
bp = (Header*)ap - 1;
16c4: 8d 4b f8 lea -0x8(%ebx),%ecx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
16c7: 39 c8 cmp %ecx,%eax
16c9: 73 15 jae 16e0 <free+0x30>
16cb: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
16cf: 90 nop
16d0: 39 d1 cmp %edx,%ecx
16d2: 72 14 jb 16e8 <free+0x38>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
16d4: 39 d0 cmp %edx,%eax
16d6: 73 10 jae 16e8 <free+0x38>
{
16d8: 89 d0 mov %edx,%eax
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
16da: 8b 10 mov (%eax),%edx
16dc: 39 c8 cmp %ecx,%eax
16de: 72 f0 jb 16d0 <free+0x20>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
16e0: 39 d0 cmp %edx,%eax
16e2: 72 f4 jb 16d8 <free+0x28>
16e4: 39 d1 cmp %edx,%ecx
16e6: 73 f0 jae 16d8 <free+0x28>
break;
if(bp + bp->s.size == p->s.ptr){
16e8: 8b 73 fc mov -0x4(%ebx),%esi
16eb: 8d 3c f1 lea (%ecx,%esi,8),%edi
16ee: 39 fa cmp %edi,%edx
16f0: 74 1e je 1710 <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;
16f2: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
16f5: 8b 50 04 mov 0x4(%eax),%edx
16f8: 8d 34 d0 lea (%eax,%edx,8),%esi
16fb: 39 f1 cmp %esi,%ecx
16fd: 74 28 je 1727 <free+0x77>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
16ff: 89 08 mov %ecx,(%eax)
freep = p;
}
1701: 5b pop %ebx
freep = p;
1702: a3 00 1c 00 00 mov %eax,0x1c00
}
1707: 5e pop %esi
1708: 5f pop %edi
1709: 5d pop %ebp
170a: c3 ret
170b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
170f: 90 nop
bp->s.size += p->s.ptr->s.size;
1710: 03 72 04 add 0x4(%edx),%esi
1713: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
1716: 8b 10 mov (%eax),%edx
1718: 8b 12 mov (%edx),%edx
171a: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
171d: 8b 50 04 mov 0x4(%eax),%edx
1720: 8d 34 d0 lea (%eax,%edx,8),%esi
1723: 39 f1 cmp %esi,%ecx
1725: 75 d8 jne 16ff <free+0x4f>
p->s.size += bp->s.size;
1727: 03 53 fc add -0x4(%ebx),%edx
freep = p;
172a: a3 00 1c 00 00 mov %eax,0x1c00
p->s.size += bp->s.size;
172f: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
1732: 8b 53 f8 mov -0x8(%ebx),%edx
1735: 89 10 mov %edx,(%eax)
}
1737: 5b pop %ebx
1738: 5e pop %esi
1739: 5f pop %edi
173a: 5d pop %ebp
173b: c3 ret
173c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00001740 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
1740: f3 0f 1e fb endbr32
1744: 55 push %ebp
1745: 89 e5 mov %esp,%ebp
1747: 57 push %edi
1748: 56 push %esi
1749: 53 push %ebx
174a: 83 ec 1c sub $0x1c,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
174d: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
1750: 8b 3d 00 1c 00 00 mov 0x1c00,%edi
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
1756: 8d 70 07 lea 0x7(%eax),%esi
1759: c1 ee 03 shr $0x3,%esi
175c: 83 c6 01 add $0x1,%esi
if((prevp = freep) == 0){
175f: 85 ff test %edi,%edi
1761: 0f 84 a9 00 00 00 je 1810 <malloc+0xd0>
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
1767: 8b 07 mov (%edi),%eax
if(p->s.size >= nunits){
1769: 8b 48 04 mov 0x4(%eax),%ecx
176c: 39 f1 cmp %esi,%ecx
176e: 73 6d jae 17dd <malloc+0x9d>
1770: 81 fe 00 10 00 00 cmp $0x1000,%esi
1776: bb 00 10 00 00 mov $0x1000,%ebx
177b: 0f 43 de cmovae %esi,%ebx
p = sbrk(nu * sizeof(Header));
177e: 8d 0c dd 00 00 00 00 lea 0x0(,%ebx,8),%ecx
1785: 89 4d e4 mov %ecx,-0x1c(%ebp)
1788: eb 17 jmp 17a1 <malloc+0x61>
178a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
1790: 8b 10 mov (%eax),%edx
if(p->s.size >= nunits){
1792: 8b 4a 04 mov 0x4(%edx),%ecx
1795: 39 f1 cmp %esi,%ecx
1797: 73 4f jae 17e8 <malloc+0xa8>
1799: 8b 3d 00 1c 00 00 mov 0x1c00,%edi
179f: 89 d0 mov %edx,%eax
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
17a1: 39 c7 cmp %eax,%edi
17a3: 75 eb jne 1790 <malloc+0x50>
p = sbrk(nu * sizeof(Header));
17a5: 83 ec 0c sub $0xc,%esp
17a8: ff 75 e4 pushl -0x1c(%ebp)
17ab: e8 4b fc ff ff call 13fb <sbrk>
if(p == (char*)-1)
17b0: 83 c4 10 add $0x10,%esp
17b3: 83 f8 ff cmp $0xffffffff,%eax
17b6: 74 1b je 17d3 <malloc+0x93>
hp->s.size = nu;
17b8: 89 58 04 mov %ebx,0x4(%eax)
free((void*)(hp + 1));
17bb: 83 ec 0c sub $0xc,%esp
17be: 83 c0 08 add $0x8,%eax
17c1: 50 push %eax
17c2: e8 e9 fe ff ff call 16b0 <free>
return freep;
17c7: a1 00 1c 00 00 mov 0x1c00,%eax
if((p = morecore(nunits)) == 0)
17cc: 83 c4 10 add $0x10,%esp
17cf: 85 c0 test %eax,%eax
17d1: 75 bd jne 1790 <malloc+0x50>
return 0;
}
}
17d3: 8d 65 f4 lea -0xc(%ebp),%esp
return 0;
17d6: 31 c0 xor %eax,%eax
}
17d8: 5b pop %ebx
17d9: 5e pop %esi
17da: 5f pop %edi
17db: 5d pop %ebp
17dc: c3 ret
if(p->s.size >= nunits){
17dd: 89 c2 mov %eax,%edx
17df: 89 f8 mov %edi,%eax
17e1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
if(p->s.size == nunits)
17e8: 39 ce cmp %ecx,%esi
17ea: 74 54 je 1840 <malloc+0x100>
p->s.size -= nunits;
17ec: 29 f1 sub %esi,%ecx
17ee: 89 4a 04 mov %ecx,0x4(%edx)
p += p->s.size;
17f1: 8d 14 ca lea (%edx,%ecx,8),%edx
p->s.size = nunits;
17f4: 89 72 04 mov %esi,0x4(%edx)
freep = prevp;
17f7: a3 00 1c 00 00 mov %eax,0x1c00
}
17fc: 8d 65 f4 lea -0xc(%ebp),%esp
return (void*)(p + 1);
17ff: 8d 42 08 lea 0x8(%edx),%eax
}
1802: 5b pop %ebx
1803: 5e pop %esi
1804: 5f pop %edi
1805: 5d pop %ebp
1806: c3 ret
1807: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
180e: 66 90 xchg %ax,%ax
base.s.ptr = freep = prevp = &base;
1810: c7 05 00 1c 00 00 04 movl $0x1c04,0x1c00
1817: 1c 00 00
base.s.size = 0;
181a: bf 04 1c 00 00 mov $0x1c04,%edi
base.s.ptr = freep = prevp = &base;
181f: c7 05 04 1c 00 00 04 movl $0x1c04,0x1c04
1826: 1c 00 00
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
1829: 89 f8 mov %edi,%eax
base.s.size = 0;
182b: c7 05 08 1c 00 00 00 movl $0x0,0x1c08
1832: 00 00 00
if(p->s.size >= nunits){
1835: e9 36 ff ff ff jmp 1770 <malloc+0x30>
183a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
prevp->s.ptr = p->s.ptr;
1840: 8b 0a mov (%edx),%ecx
1842: 89 08 mov %ecx,(%eax)
1844: eb b1 jmp 17f7 <malloc+0xb7>
1846: 66 90 xchg %ax,%ax
1848: 66 90 xchg %ax,%ax
184a: 66 90 xchg %ax,%ax
184c: 66 90 xchg %ax,%ax
184e: 66 90 xchg %ax,%ax
00001850 <uacquire>:
#include "uspinlock.h"
#include "x86.h"
void
uacquire(struct uspinlock *lk)
{
1850: f3 0f 1e fb endbr32
1854: 55 push %ebp
xchg(volatile uint *addr, uint newval)
{
uint result;
// The + in "+m" denotes a read-modify-write operand.
asm volatile("lock; xchgl %0, %1" :
1855: b9 01 00 00 00 mov $0x1,%ecx
185a: 89 e5 mov %esp,%ebp
185c: 8b 55 08 mov 0x8(%ebp),%edx
185f: 90 nop
1860: 89 c8 mov %ecx,%eax
1862: f0 87 02 lock xchg %eax,(%edx)
// The xchg is atomic.
while(xchg(&lk->locked, 1) != 0)
1865: 85 c0 test %eax,%eax
1867: 75 f7 jne 1860 <uacquire+0x10>
;
// Tell the C compiler and the processor to not move loads or stores
// past this point, to ensure that the critical section's memory
// references happen after the lock is acquired.
__sync_synchronize();
1869: f0 83 0c 24 00 lock orl $0x0,(%esp)
}
186e: 5d pop %ebp
186f: c3 ret
00001870 <urelease>:
void urelease (struct uspinlock *lk) {
1870: f3 0f 1e fb endbr32
1874: 55 push %ebp
1875: 89 e5 mov %esp,%ebp
1877: 8b 45 08 mov 0x8(%ebp),%eax
__sync_synchronize();
187a: f0 83 0c 24 00 lock orl $0x0,(%esp)
// Release the lock, equivalent to lk->locked = 0.
// This code can't use a C assignment, since it might
// not be atomic. A real OS would use C atomics here.
asm volatile("movl $0, %0" : "+m" (lk->locked) : );
187f: c7 00 00 00 00 00 movl $0x0,(%eax)
}
1885: 5d pop %ebp
1886: c3 ret
|
// seed 3
lbi r0, 18 // icount 0
slbi r0, 25 // icount 1
lbi r1, 81 // icount 2
slbi r1, 89 // icount 3
lbi r2, 151 // icount 4
slbi r2, 171 // icount 5
lbi r3, 121 // icount 6
slbi r3, 62 // icount 7
lbi r4, 92 // icount 8
slbi r4, 247 // icount 9
lbi r5, 120 // icount 10
slbi r5, 213 // icount 11
lbi r6, 90 // icount 12
slbi r6, 162 // icount 13
lbi r7, 189 // icount 14
slbi r7, 176 // icount 15
ror r1, r0, r5 // icount 16
ror r6, r6, r5 // icount 17
ror r2, r1, r6 // icount 18
ror r4, r4, r5 // icount 19
ror r0, r2, r6 // icount 20
ror r1, r1, r3 // icount 21
ror r2, r3, r3 // icount 22
ror r2, r6, r4 // icount 23
ror r7, r1, r1 // icount 24
ror r4, r6, r1 // icount 25
ror r5, r5, r5 // icount 26
ror r1, r4, r2 // icount 27
ror r6, r6, r7 // icount 28
ror r1, r0, r7 // icount 29
ror r6, r1, r5 // icount 30
ror r2, r6, r0 // icount 31
halt // icount 32
|
;---------------------00 - NULL
mov edi, GDTTableLoc
mov dword [edi], 0
add edi, 4
mov dword [edi], 0
add edi, 4
;---------------------08 - Stack
;500 - 1500
mov ax, 0x14ff
mov [edi], ax
add edi, 2
push ax
mov ax, 0x500
mov [edi], ax
pop ax
add edi, 2
xor ecx, ecx
mov ch, 01010000b
shl ecx, 8
mov ch, 10010010b
mov [edi], ecx
add edi, 4
;---------------------10 - TSS
;1500 - 1564
add ax, 0x65
mov word [edi], 0x64
add edi, 2
push ax
sub ax, 0x64
mov [edi], ax
pop ax
add edi, 2
xor ecx, ecx
mov ch, 0x40
shl ecx, 8
mov ch, 0x89
mov [edi], ecx
add edi, 4
;----------------------18 - Kernel Data
;1565 - 145ff
add ax, 0x4600-0x64-0x1500-1
mov [edi], ax
add edi, 2
push ax
sub ax, 0x4600-0x64-0x1500-2
mov [edi], ax
pop ax
add edi, 2
xor ecx, ecx
mov ch, 01010001b
shl ecx, 8
mov ch, 10010010b
mov [edi], ecx
add edi, 4
inc ax
mov bx, ax ;---------------------20 - Kernel Code
;14600 - 159ff
add ax, 0x13FF
mov [edi], ax
add edi, 2
mov [edi], bx
add edi, 2
xor ecx, ecx
mov ch, 01010001b
shl ecx, 8
mov ch, 10011010b
mov cl, 1
mov [edi], ecx
add edi, 4 ;---------------------28 - Screen
;b8000 - bffff
mov bx, 0x8000
mov ax, 0xFFFF
mov [edi], ax
add edi, 2
mov [edi], bx
add edi, 2
xor ecx, ecx
mov ch, 01011011b
shl ecx, 8
mov ch, 10010010b
mov cl, 0xB
mov [edi], ecx
add edi, 4 ;---------------------30 - Hookpoints
;14300 - 145ff
mov bx, 0x4300
mov ax, 0x45ff
mov [edi], ax
add edi, 2
mov [edi], bx
add edi, 2
xor ecx, ecx
mov ch, 01010001b
shl ecx, 8
mov ch, 10010010b
mov cl, 0x1
mov [edi], ecx
add edi, 4 ;---------------------38 - VidBuffer Pointers
;15a00 - 15fff
mov bx, 0x5A00
mov ax, 0x5FFF
mov [edi], ax
add edi, 2
mov [edi], bx
add edi, 2
xor ecx, ecx
mov ch, 01010001b
shl ecx, 8
mov ch, 10010010b
mov cl, 0x1
mov [edi], ecx
add edi, 4 ;---------------------40 - USER Data
;100000 - ffffffff
mov bx, 0x0000
mov ax, 0xFFFF
mov [edi], ax
add edi, 2
mov [edi], bx
add edi, 2
xor ecx, ecx
mov ch, 11011111b
shl ecx, 8
mov ch, 10010010b
mov cl, 0x10
mov [edi], ecx
add edi, 4 ;---------------------48 - USER Code
;100000 - ffffffff
mov bx, 0x0000
mov ax, 0xFFFF
mov [edi], ax
add edi, 2
mov [edi], bx
add edi, 2
xor ecx, ecx
mov ch, 11011111b
shl ecx, 8
mov ch, 10011010b
mov cl, 0x10
mov [edi], ecx
add edi, 4 ;---------------------
mov esi, edi
sub esi, GDTTableLoc
dec esi
mov [edi], si
mov eax, edi
add edi, 2
mov dword [edi], GDTTableLoc
xchg bx, bx
lgdt [eax]
jmp 0x20:ReloadGDT
ReloadGDT:
|
.setcpu "65816"
.autoimport on
.include "utility-macros.inc"
.include "GlobalVarsAndConsts.inc"
.segment "STARTUP"
; Reset int. (Entry Point) -------------------
.proc Reset ; int handler
sei
clc
xce ; Native Mode On
phk
plb ; PB -stack-> DB (=0)
rep #$30 ; A,I 16bit
.a16
.i16
; Initialize stack
ldx #$1fff
txs
jsr initRegs
jsr initSystemGenericStatuses
jsr initVideoForGame
jsr disableNMI
; Read QL header
lda f:SongMetadataHeader+2
sta gQuickLoadSize
; Load initial sound
stz gSelectedIndex
; jsr selectSoundAssetAddress
; jsr spcSetup
jsr setupMainScreen
jsr enableNMI
ldsta $40,#$3412
begin_loop:
lda gSPCResetReq
beq no_spc_reset
jsr spcRequestReset
stz gSPCResetReq
no_spc_reset:
lda gSPCLoadReq
beq skip_spc_load
jsr disableNMI
jsr selectSoundAssetAddress
jsr shouldDoQuickLoad
bcs qmode
jsr spcSetup
jmp endif_q
qmode:
jsr spcQuickReload
endif_q:
stz gSPCLoadReq
stz gLoaderBusy
jsr spcUpdateProgressHandler
jsr enableNMI
ldsta gQuickLoadOK,#$FF
skip_spc_load:
jsr processSETriggers
nop
jmp begin_loop
rti
.endproc
.proc VBlank ; int handler
save_pax
set_a16
.a16
.i16
ldx kTickerY*32
ldy #0
jsr tbTransferDMA
ldx kTickerY*32
ldy #1
jsr tbTransferDMA
jsr startTextLayerHDMA
jsr moveCursorSprite
jsr processMainInput
jsr updatePadState
; out_scanpos gBenchmarkOut2
restore_pax
rti
.endproc
.proc updatePadState
set_a8
.a8
; Wait until auto-read is finished
: lda $4212
and #$01
bne :-
set_a16
.a16
; Store Pad Status
lda $4218
sta gPadState
rts
.endproc
.macro set_sndimage_pair part1, part2
ldsta gBlobSrcAddrLo, #.LOWORD(part1)
ldsta gBlobSrcAddrHi, #.HIWORD(part1)
ldsta gBlobSrcAddrLoNext, #.LOWORD(part2)
ldsta gBlobSrcAddrHiNext, #.HIWORD(part2)
.endmacro
; A16, I16
.proc shouldDoQuickLoad
.a16
.i16
pha
lda f:SongMetadataHeader
and gQuickLoadOK
bne return_yes
return_no:
pla
clc
rts
return_yes:
pla
sec
rts
.endproc
; A16, I16
.proc selectSoundAssetAddress
.a16
.i16
pha
lda gSelectedIndex
cmp #3
bne not_4th
set_sndimage_pair SndDrv4LoImageBase, SndDrv4HiImageBase
bra end_sw
not_4th:
cmp #1
bcc case_0
beq case_1
set_sndimage_pair SndDrv3LoImageBase, SndDrv3HiImageBase
bra end_sw
case_1:
set_sndimage_pair SndDrv2LoImageBase, SndDrv2HiImageBase
bra end_sw
case_0:
set_sndimage_pair SndDrvImageBase, SndDrvImageBaseHigh
end_sw:
pla
rts
.endproc
; ===================================================
; Metadata and Assets
; ===================================================
; Cartridge metadata - - -
.segment "CARTINFO"
; ||||++++||||++++||||+ 21 bytes
.byte "QSPC2PLAYER " ; Game Title
.byte $00 ; 0x01:HiRom, 0x30:FastRom(3.57MHz)
.byte $00 ; ROM only
.byte $09 ; ROM Size
.byte $00 ; RAM Size (8KByte * N)
.byte $00 ; NTSC
.byte $01 ; Licensee
.byte $00 ; Version
; Embed information (must be replaced with checksum)
.word $1C1C
.word $E3E3
.byte $ff, $ff, $ff, $ff ; unknown
.word $0000 ; Native:COP
.word $0000 ; Native:BRK
.word $0000 ; Native:ABORT
.word VBlank ; Native:NMI
.word $0000 ;
.word $0000 ; Native:IRQ
.word $0000 ;
.word $0000 ;
.word $0000 ; Emulation:COP
.word $0000 ;
.word $0000 ; Emulation:ABORT
.word $0000 ; Emulation:NMI
.word Reset ; Emulation:RESET
.word $0000 ; Emulation:IRQ/BRK
; assets -----------------------------------------------------
.export SndDrvImageBase:far
.export SndDrvImageBaseHigh:far
.export AssetBGGraphic:far
.export AssetSpGraphic:far
.export AssetFont:far
.export PaletteBase:far
.export SongMetadataList:far
.export BGMapAsset:far
.export StrTitleDisp:far
.export StrSingleMode:far
.export StrSongListCaption:far
.export StrBy:far
.export StrLoading:far
.export StrEmpty:far
.export WStrInstruction:far
; - - -
.segment "VISASSET1":far
AssetBGGraphic:
.incbin "assets/bg-ptn.bin"
AssetSpGraphic:
.incbin "assets/sp-ptn.bin"
AssetFont:
.incbin "assets/font-ptn.bin"
.byte $FF,$FF,$4D ; adjust checksum
.segment "VISASSET2": far
PaletteBase:
.incbin "assets/main.pal"
.incbin "assets/sub.pal"
.incbin "assets/sprite.pal"
.segment "MISCASSET": far
SongMetadataHeader:
; header
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
SongMetadataList:
; 0123456789ABCDEF
.byte "Dummy 01"
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
; 0123456789ABCDEF
.byte "Yuji Ninomiya"
.byte $00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
; 0123456789ABCDEF
.byte "Dummy 02"
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
; 0123456789ABCDEF
.byte "Yuji Ninomiya"
.byte $00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
; 0123456789ABCDEF
.byte "Dummy 03"
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
; 0123456789ABCDEF
.byte "Yuji Ninomiya"
.byte $00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
; 0123456789ABCDEF
.byte $00,$00 ; DISABLED
.byte "rrying You"
.byte $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
; 0123456789ABCDEF
.byte $00,$00 ; DISABLED
.byte "xxxxxxxxxx"
.byte $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
; terminate
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
.byte $00,$00,$00,$00, $00,$00,$00,$00
BGMapAsset:
.incbin "assets/q-bgmap.bin"
; STRING ASSETS
StrTitleDisp:
.byte " qSPC Player Version 2.1"
.byte $00
StrSingleMode:
.byte "SINGLE MODE"
.byte $00
StrSongListCaption:
.byte "SONG LIST"
.byte $00
StrBy:
.byte " by "
.byte $00
StrLoading:
.byte " Loading... "
.byte $00
StrEmpty:
.byte "- - - - - - - -"
.byte $00
WStrInstruction:
.word $0080,$007F,$0050,$006C,$0061,$0079
.word $0020
.word $0020
.word $1081,$007F,$0053,$0074,$006F,$0070
.word $0000
; ||||----||||----||||----
.byte "_EMBED_DRIVER_AFTER_HERE"
.segment "SDRVROM1": far
SndDrvImageBase:
.incbin "assets/demo-lo.bin"
.segment "SDRVROM2": far
SndDrvImageBaseHigh:
.incbin "assets/demo-hi.bin"
.segment "SDRVROM3": far
SndDrv2LoImageBase:
.incbin "assets/demo-lo.bin"
.segment "SDRVROM4": far
SndDrv2HiImageBase:
.incbin "assets/demo-hi.bin"
.segment "SDRVROM5": far
SndDrv3LoImageBase:
; .incbin "assets/demo-lo.bin"
.incbin "../n-driver/split_drv_00" ;TEST
.segment "SDRVROM6": far
SndDrv3HiImageBase:
; .incbin "assets/demo-hi.bin"
.incbin "../n-driver/split_drv_01" ;TEST
; - - - -
.segment "SDRVROM7": far
SndDrv4LoImageBase:
.incbin "assets/demo-lo.bin"
.segment "SDRVROM8": far
SndDrv4HiImageBase:
.incbin "assets/demo-hi.bin"
; - - - -
.segment "DONTUSE"
.byte "NO-DATA"
|
; A170657: Number of reduced words of length n in Coxeter group on 24 generators S_i with relations (S_i)^2 = (S_i S_j)^49 = I.
; 1,24,552,12696,292008,6716184,154472232,3552861336,81715810728,1879463646744,43227663875112,994236269127576,22867434189934248,525950986368487704,12096872686475217192,278228071788929995416
add $0,1
mov $3,1
lpb $0
sub $0,1
add $2,$3
div $3,$2
mul $2,23
lpe
mov $0,$2
div $0,23
|
SECTION rodata_font_fzx
PUBLIC _ff_utz_Notez
_ff_utz_Notez:
BINARY "font/fzx/fonts/utz/Notez/notez.fzx"
|
; A290745: Maximum number of distinct Lyndon factors that can appear in words of length n over an alphabet of size 10.
; 10,11,13,16,20,25,31,38,46,55,64,74,85,97,110,124,139,155,172,190,208,227,247,268,290,313,337,362,388,415,442,470,499,529,560,592,625,659,694,730,766,803,841,880,920,961,1003,1046,1090,1135,1180,1226,1273,1321,1370,1420,1471,1523,1576,1630,1684,1739,1795,1852,1910,1969,2029,2090,2152,2215,2278,2342,2407,2473,2540,2608,2677,2747,2818,2890,2962,3035,3109,3184,3260,3337,3415,3494,3574,3655,3736,3818,3901,3985,4070,4156,4243,4331,4420,4510,4600,4691,4783,4876,4970,5065,5161,5258,5356,5455,5554,5654,5755,5857,5960,6064,6169,6275,6382,6490,6598,6707,6817,6928,7040,7153,7267,7382,7498,7615,7732,7850,7969,8089,8210,8332,8455,8579,8704,8830,8956,9083,9211,9340,9470,9601,9733,9866,10000,10135,10270,10406,10543,10681,10820,10960,11101,11243,11386,11530,11674,11819,11965,12112,12260,12409,12559,12710,12862,13015,13168,13322,13477,13633,13790,13948,14107,14267,14428,14590,14752,14915,15079,15244,15410,15577,15745,15914,16084,16255,16426,16598,16771,16945,17120,17296,17473,17651,17830,18010,18190,18371,18553,18736,18920,19105,19291,19478,19666,19855,20044,20234,20425,20617,20810,21004,21199,21395,21592,21790,21988,22187,22387,22588,22790,22993,23197,23402,23608,23815,24022,24230,24439,24649,24860,25072,25285,25499,25714,25930,26146,26363,26581,26800,27020,27241,27463,27686,27910,28135
mov $1,10
mov $2,$0
mov $3,$0
add $3,1
lpb $2
add $1,$2
sub $2,1
sub $3,5
trn $3,5
sub $1,$3
lpe
|
; A052996: G.f.: (1+x^2-x^3)/((1-x)(1-2*x)).
; 1,3,8,17,35,71,143,287,575,1151,2303,4607,9215,18431,36863,73727,147455,294911,589823,1179647,2359295,4718591,9437183,18874367,37748735,75497471,150994943,301989887,603979775,1207959551,2415919103,4831838207,9663676415,19327352831,38654705663,77309411327,154618822655,309237645311,618475290623,1236950581247,2473901162495,4947802324991,9895604649983,19791209299967,39582418599935,79164837199871,158329674399743,316659348799487,633318697598975,1266637395197951,2533274790395903,5066549580791807
mov $1,2
pow $1,$0
mul $1,9
div $1,4
sub $1,1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r12
push %rbp
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WT_ht+0x1176b, %rdx
nop
nop
nop
nop
nop
xor $26709, %rbx
movw $0x6162, (%rdx)
nop
cmp $47481, %rbp
lea addresses_D_ht+0x17578, %rsi
lea addresses_A_ht+0x8711, %rdi
nop
nop
nop
nop
nop
xor $54360, %r12
mov $53, %rcx
rep movsb
add $15525, %rsi
lea addresses_WT_ht+0xcf04, %r10
nop
nop
nop
nop
nop
cmp $64908, %rdi
movw $0x6162, (%r10)
nop
nop
nop
and $41992, %r10
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r12
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r14
push %r15
push %rbx
push %rdi
push %rsi
// Store
lea addresses_US+0xe36b, %r12
nop
nop
and %r15, %r15
mov $0x5152535455565758, %rsi
movq %rsi, %xmm7
movups %xmm7, (%r12)
nop
nop
nop
nop
nop
add %r14, %r14
// Faulty Load
lea addresses_US+0xe36b, %rbx
nop
nop
nop
nop
add %r11, %r11
mov (%rbx), %r12
lea oracles, %rdi
and $0xff, %r12
shlq $12, %r12
mov (%rdi,%r12,1), %r12
pop %rsi
pop %rdi
pop %rbx
pop %r15
pop %r14
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': True, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 0, 'size': 8, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 10, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 1, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': True, 'NT': False}}
{'58': 21829}
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
*/
|
; Pack.Jumptable and BattlePack.Jumptable indexes
const_def
const PACKSTATE_INITGFX ; 0
const PACKSTATE_INITITEMSPOCKET ; 1
const PACKSTATE_ITEMSPOCKETMENU ; 2
const PACKSTATE_INITBALLSPOCKET ; 3
const PACKSTATE_BALLSPOCKETMENU ; 4
const PACKSTATE_INITKEYITEMSPOCKET ; 5
const PACKSTATE_KEYITEMSPOCKETMENU ; 6
const PACKSTATE_INITTMHMPOCKET ; 7
const PACKSTATE_TMHMPOCKETMENU ; 8
const PACKSTATE_QUITNOSCRIPT ; 9
const PACKSTATE_QUITRUNSCRIPT ; 10
Pack:
ld hl, wOptions
set NO_TEXT_SCROLL, [hl]
call InitPackBuffers
.loop
call JoyTextDelay
ld a, [wJumptableIndex]
bit 7, a
jr nz, .done
call .RunJumptable
call DelayFrame
jr .loop
.done
ld a, [wCurPocket]
ld [wLastPocket], a
ld hl, wOptions
res NO_TEXT_SCROLL, [hl]
ret
.RunJumptable:
ld a, [wJumptableIndex]
ld hl, .Jumptable
call Pack_GetJumptablePointer
jp hl
.Jumptable:
; entries correspond to PACKSTATE_* constants
dw .InitGFX ; 0
dw .InitItemsPocket ; 1
dw .ItemsPocketMenu ; 2
dw .InitBallsPocket ; 3
dw .BallsPocketMenu ; 4
dw .InitKeyItemsPocket ; 5
dw .KeyItemsPocketMenu ; 6
dw .InitTMHMPocket ; 7
dw .TMHMPocketMenu ; 8
dw Pack_QuitNoScript ; 9
dw Pack_QuitRunScript ; 10
.InitGFX:
xor a
ldh [hBGMapMode], a
call Pack_InitGFX
ld a, [wPackJumptableIndex]
ld [wJumptableIndex], a
call Pack_InitColors
ret
.InitItemsPocket:
xor a ; ITEM_POCKET
ld [wCurPocket], a
call ClearPocketList
call DrawPocketName
call WaitBGMap_DrawPackGFX
call Pack_JumptableNext
ret
.ItemsPocketMenu:
ld hl, ItemsPocketMenuHeader
call CopyMenuHeader
ld a, [wItemsPocketCursor]
ld [wMenuCursorBuffer], a
ld a, [wItemsPocketScrollPosition]
ld [wMenuScrollPosition], a
call ScrollingMenu
ld a, [wMenuScrollPosition]
ld [wItemsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wItemsPocketCursor], a
ld b, PACKSTATE_INITTMHMPOCKET ; left
ld c, PACKSTATE_INITBALLSPOCKET ; right
call Pack_InterpretJoypad
ret c
call .ItemBallsKey_LoadSubmenu
ret
.InitKeyItemsPocket:
ld a, KEY_ITEM_POCKET
ld [wCurPocket], a
call ClearPocketList
call DrawPocketName
call WaitBGMap_DrawPackGFX
call Pack_JumptableNext
ret
.KeyItemsPocketMenu:
ld hl, KeyItemsPocketMenuHeader
call CopyMenuHeader
ld a, [wKeyItemsPocketCursor]
ld [wMenuCursorBuffer], a
ld a, [wKeyItemsPocketScrollPosition]
ld [wMenuScrollPosition], a
call ScrollingMenu
ld a, [wMenuScrollPosition]
ld [wKeyItemsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wKeyItemsPocketCursor], a
ld b, PACKSTATE_INITBALLSPOCKET ; left
ld c, PACKSTATE_INITTMHMPOCKET ; right
call Pack_InterpretJoypad
ret c
call .ItemBallsKey_LoadSubmenu
ret
.InitTMHMPocket:
ld a, TM_HM_POCKET
ld [wCurPocket], a
call ClearPocketList
call DrawPocketName
xor a
ldh [hBGMapMode], a
call WaitBGMap_DrawPackGFX
call Pack_JumptableNext
ret
.TMHMPocketMenu:
farcall TMHMPocket
ld b, PACKSTATE_INITKEYITEMSPOCKET ; left
ld c, PACKSTATE_INITITEMSPOCKET ; right
call Pack_InterpretJoypad
ret c
farcall _CheckTossableItem
ld a, [wItemAttributeParamBuffer]
and a
jr nz, .use_quit
ld hl, .MenuHeader2
ld de, .Jumptable2
jr .load_jump
.use_quit
ld hl, .MenuHeader1
ld de, .Jumptable1
.load_jump
push de
call LoadMenuHeader
call VerticalMenu
call ExitMenu
pop hl
ret c
ld a, [wMenuCursorY]
dec a
call Pack_GetJumptablePointer
jp hl
.MenuHeader1:
db MENU_BACKUP_TILES ; flags
menu_coords 13, 7, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .MenuData_1
db 1 ; default option
.MenuData_1:
db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
db 2 ; items
db "USE@"
db "QUIT@"
.Jumptable1:
dw .UseItem
dw QuitItemSubmenu
.MenuHeader2:
db MENU_BACKUP_TILES ; flags
menu_coords 13, 5, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .MenuData_2
db 1 ; default option
.MenuData_2:
db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
db 3 ; items
db "USE@"
db "GIVE@"
db "QUIT@"
.Jumptable2:
dw .UseItem
dw GiveItem
dw QuitItemSubmenu
.UseItem:
farcall AskTeachTMHM
ret c
farcall ChooseMonToLearnTMHM
jr c, .declined
ld hl, wOptions
ld a, [hl]
push af
res NO_TEXT_SCROLL, [hl]
farcall TeachTMHM
pop af
ld [wOptions], a
.declined
xor a
ldh [hBGMapMode], a
call Pack_InitGFX
call WaitBGMap_DrawPackGFX
call Pack_InitColors
ret
.InitBallsPocket:
ld a, BALL_POCKET
ld [wCurPocket], a
call ClearPocketList
call DrawPocketName
call WaitBGMap_DrawPackGFX
call Pack_JumptableNext
ret
.BallsPocketMenu:
ld hl, BallsPocketMenuHeader
call CopyMenuHeader
ld a, [wBallsPocketCursor]
ld [wMenuCursorBuffer], a
ld a, [wBallsPocketScrollPosition]
ld [wMenuScrollPosition], a
call ScrollingMenu
ld a, [wMenuScrollPosition]
ld [wBallsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wBallsPocketCursor], a
ld b, PACKSTATE_INITITEMSPOCKET ; left
ld c, PACKSTATE_INITKEYITEMSPOCKET ; right
call Pack_InterpretJoypad
ret c
call .ItemBallsKey_LoadSubmenu
ret
.ItemBallsKey_LoadSubmenu:
farcall _CheckTossableItem
ld a, [wItemAttributeParamBuffer]
and a
jr nz, .tossable
farcall CheckSelectableItem
ld a, [wItemAttributeParamBuffer]
and a
jr nz, .selectable
farcall CheckItemMenu
ld a, [wItemAttributeParamBuffer]
and a
jr nz, .usable
jr .unusable
.selectable
farcall CheckItemMenu
ld a, [wItemAttributeParamBuffer]
and a
jr nz, .selectable_usable
jr .selectable_unusable
.tossable
farcall CheckSelectableItem
ld a, [wItemAttributeParamBuffer]
and a
jr nz, .tossable_selectable
jr .tossable_unselectable
.usable
ld hl, MenuHeader_UsableKeyItem
ld de, Jumptable_UseGiveTossRegisterQuit
jr .build_menu
.selectable_usable
ld hl, MenuHeader_UsableItem
ld de, Jumptable_UseGiveTossQuit
jr .build_menu
.tossable_selectable
ld hl, MenuHeader_UnusableItem
ld de, Jumptable_UseQuit
jr .build_menu
.tossable_unselectable
ld hl, MenuHeader_UnusableKeyItem
ld de, Jumptable_UseRegisterQuit
jr .build_menu
.unusable
ld hl, MenuHeader_HoldableKeyItem
ld de, Jumptable_GiveTossRegisterQuit
jr .build_menu
.selectable_unusable
ld hl, MenuHeader_HoldableItem
ld de, Jumptable_GiveTossQuit
.build_menu
push de
call LoadMenuHeader
call VerticalMenu
call ExitMenu
pop hl
ret c
ld a, [wMenuCursorY]
dec a
call Pack_GetJumptablePointer
jp hl
MenuHeader_UsableKeyItem:
db MENU_BACKUP_TILES ; flags
menu_coords 13, 1, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
db 5 ; items
db "USE@"
db "GIVE@"
db "TOSS@"
db "SEL@"
db "QUIT@"
Jumptable_UseGiveTossRegisterQuit:
dw UseItem
dw GiveItem
dw TossMenu
dw RegisterItem
dw QuitItemSubmenu
MenuHeader_UsableItem:
db MENU_BACKUP_TILES ; flags
menu_coords 13, 3, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
db 4 ; items
db "USE@"
db "GIVE@"
db "TOSS@"
db "QUIT@"
Jumptable_UseGiveTossQuit:
dw UseItem
dw GiveItem
dw TossMenu
dw QuitItemSubmenu
MenuHeader_UnusableItem:
db MENU_BACKUP_TILES ; flags
menu_coords 13, 7, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
db 2 ; items
db "USE@"
db "QUIT@"
Jumptable_UseQuit:
dw UseItem
dw QuitItemSubmenu
MenuHeader_UnusableKeyItem:
db MENU_BACKUP_TILES ; flags
menu_coords 13, 5, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
db 3 ; items
db "USE@"
db "SEL@"
db "QUIT@"
Jumptable_UseRegisterQuit:
dw UseItem
dw RegisterItem
dw QuitItemSubmenu
MenuHeader_HoldableKeyItem:
db MENU_BACKUP_TILES ; flags
menu_coords 13, 3, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
db 4 ; items
db "GIVE@"
db "TOSS@"
db "SEL@"
db "QUIT@"
Jumptable_GiveTossRegisterQuit:
dw GiveItem
dw TossMenu
dw RegisterItem
dw QuitItemSubmenu
MenuHeader_HoldableItem:
db MENU_BACKUP_TILES ; flags
menu_coords 13, 5, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
db 3 ; items
db "GIVE@"
db "TOSS@"
db "QUIT@"
Jumptable_GiveTossQuit:
dw GiveItem
dw TossMenu
dw QuitItemSubmenu
UseItem:
farcall CheckItemMenu
ld a, [wItemAttributeParamBuffer]
ld hl, .dw
rst JumpTable
ret
.dw
; entries correspond to ITEMMENU_* constants
dw .Oak ; ITEMMENU_NOUSE
dw .Oak
dw .Oak
dw .Oak
dw .Current ; ITEMMENU_CURRENT
dw .Party ; ITEMMENU_PARTY
dw .Field ; ITEMMENU_CLOSE
.Oak:
ld hl, Text_ThisIsntTheTime
call Pack_PrintTextNoScroll
ret
.Current:
call DoItemEffect
ret
.Party:
ld a, [wPartyCount]
and a
jr z, .NoPokemon
call DoItemEffect
xor a
ldh [hBGMapMode], a
call Pack_InitGFX
call WaitBGMap_DrawPackGFX
call Pack_InitColors
ret
.NoPokemon:
ld hl, TextJump_YouDontHaveAMon
call Pack_PrintTextNoScroll
ret
.Field:
call DoItemEffect
ld a, [wItemEffectSucceeded]
and a
jr z, .Oak
ld a, PACKSTATE_QUITRUNSCRIPT
ld [wJumptableIndex], a
ret
TossMenu:
ld hl, Text_ThrowAwayHowMany
call Pack_PrintTextNoScroll
farcall SelectQuantityToToss
push af
call ExitMenu
pop af
jr c, .finish
call Pack_GetItemName
ld hl, Text_ConfirmThrowAway
call MenuTextbox
call YesNoBox
push af
call ExitMenu
pop af
jr c, .finish
ld hl, wNumItems
ld a, [wCurItemQuantity]
call TossItem
call Pack_GetItemName
ld hl, Text_ThrewAway
call Pack_PrintTextNoScroll
.finish
ret
Unreferenced_ResetPocketCursorPositions:
ld a, [wCurPocket]
and a ; ITEM_POCKET
jr z, .items
dec a ; BALL_POCKET
jr z, .balls
dec a ; KEY_ITEM_POCKET
jr z, .key
ret
.balls
xor a
ld [wBallsPocketCursor], a
ld [wBallsPocketScrollPosition], a
ret
.items
xor a
ld [wItemsPocketCursor], a
ld [wItemsPocketScrollPosition], a
ret
.key
xor a
ld [wKeyItemsPocketCursor], a
ld [wKeyItemsPocketScrollPosition], a
ret
RegisterItem:
farcall CheckSelectableItem
ld a, [wItemAttributeParamBuffer]
and a
jr nz, .cant_register
ld a, [wCurPocket]
rrca
rrca
and REGISTERED_POCKET
ld b, a
ld a, [wCurItemQuantity]
inc a
and REGISTERED_NUMBER
or b
ld [wWhichRegisteredItem], a
ld a, [wCurItem]
ld [wRegisteredItem], a
call Pack_GetItemName
ld de, SFX_FULL_HEAL
call WaitPlaySFX
ld hl, Text_RegisteredItem
call Pack_PrintTextNoScroll
ret
.cant_register
ld hl, Text_CantRegister
call Pack_PrintTextNoScroll
ret
GiveItem:
ld a, [wPartyCount]
and a
jp z, .NoPokemon
ld a, [wOptions]
push af
res NO_TEXT_SCROLL, a
ld [wOptions], a
ld a, PARTYMENUACTION_GIVE_ITEM
ld [wPartyMenuActionText], a
call ClearBGPalettes
farcall LoadPartyMenuGFX
farcall InitPartyMenuWithCancel
farcall InitPartyMenuGFX
.loop
farcall WritePartyMenuTilemap
farcall PrintPartyMenuText
call WaitBGMap
call SetPalettes
call DelayFrame
farcall PartyMenuSelect
jr c, .finish
ld a, [wCurPartySpecies]
cp EGG
jr nz, .give
ld hl, .Egg
call PrintText
jr .loop
.give
ld a, [wJumptableIndex]
push af
ld a, [wPackJumptableIndex]
push af
call GetCurNick
ld hl, wStringBuffer1
ld de, wMonOrItemNameBuffer
ld bc, MON_NAME_LENGTH
call CopyBytes
call TryGiveItemToPartymon
pop af
ld [wPackJumptableIndex], a
pop af
ld [wJumptableIndex], a
.finish
pop af
ld [wOptions], a
xor a
ldh [hBGMapMode], a
call Pack_InitGFX
call WaitBGMap_DrawPackGFX
call Pack_InitColors
ret
.NoPokemon:
ld hl, TextJump_YouDontHaveAMon
call Pack_PrintTextNoScroll
ret
.Egg:
; An EGG can't hold an item.
text_far Text_AnEGGCantHoldAnItem
text_end
QuitItemSubmenu:
ret
BattlePack:
ld hl, wOptions
set NO_TEXT_SCROLL, [hl]
call InitPackBuffers
.loop
call JoyTextDelay
ld a, [wJumptableIndex]
bit 7, a
jr nz, .end
call .RunJumptable
call DelayFrame
jr .loop
.end
ld a, [wCurPocket]
ld [wLastPocket], a
ld hl, wOptions
res NO_TEXT_SCROLL, [hl]
ret
.RunJumptable:
ld a, [wJumptableIndex]
ld hl, .Jumptable
call Pack_GetJumptablePointer
jp hl
.Jumptable:
; entries correspond to PACKSTATE_* constants
dw .InitGFX ; 0
dw .InitItemsPocket ; 1
dw .ItemsPocketMenu ; 2
dw .InitBallsPocket ; 3
dw .BallsPocketMenu ; 4
dw .InitKeyItemsPocket ; 5
dw .KeyItemsPocketMenu ; 6
dw .InitTMHMPocket ; 7
dw .TMHMPocketMenu ; 8
dw Pack_QuitNoScript ; 9
dw Pack_QuitRunScript ; 10
.InitGFX:
xor a
ldh [hBGMapMode], a
call Pack_InitGFX
ld a, [wPackJumptableIndex]
ld [wJumptableIndex], a
call Pack_InitColors
ret
.InitItemsPocket:
xor a ; ITEM_POCKET
ld [wCurPocket], a
call ClearPocketList
call DrawPocketName
call WaitBGMap_DrawPackGFX
call Pack_JumptableNext
ret
.ItemsPocketMenu:
ld hl, ItemsPocketMenuHeader
call CopyMenuHeader
ld a, [wItemsPocketCursor]
ld [wMenuCursorBuffer], a
ld a, [wItemsPocketScrollPosition]
ld [wMenuScrollPosition], a
call ScrollingMenu
ld a, [wMenuScrollPosition]
ld [wItemsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wItemsPocketCursor], a
ld b, PACKSTATE_INITTMHMPOCKET ; left
ld c, PACKSTATE_INITBALLSPOCKET ; right
call Pack_InterpretJoypad
ret c
call ItemSubmenu
ret
.InitKeyItemsPocket:
ld a, KEY_ITEM_POCKET
ld [wCurPocket], a
call ClearPocketList
call DrawPocketName
call WaitBGMap_DrawPackGFX
call Pack_JumptableNext
ret
.KeyItemsPocketMenu:
ld hl, KeyItemsPocketMenuHeader
call CopyMenuHeader
ld a, [wKeyItemsPocketCursor]
ld [wMenuCursorBuffer], a
ld a, [wKeyItemsPocketScrollPosition]
ld [wMenuScrollPosition], a
call ScrollingMenu
ld a, [wMenuScrollPosition]
ld [wKeyItemsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wKeyItemsPocketCursor], a
ld b, PACKSTATE_INITBALLSPOCKET ; left
ld c, PACKSTATE_INITTMHMPOCKET ; right
call Pack_InterpretJoypad
ret c
call ItemSubmenu
ret
.InitTMHMPocket:
ld a, TM_HM_POCKET
ld [wCurPocket], a
call ClearPocketList
call DrawPocketName
xor a
ldh [hBGMapMode], a
call WaitBGMap_DrawPackGFX
ld hl, Text_PackEmptyString
call Pack_PrintTextNoScroll
call Pack_JumptableNext
ret
.TMHMPocketMenu:
farcall TMHMPocket
ld b, PACKSTATE_INITKEYITEMSPOCKET ; left
ld c, PACKSTATE_INITITEMSPOCKET ; right
call Pack_InterpretJoypad
ret c
xor a
call TMHMSubmenu
ret
.InitBallsPocket:
ld a, BALL_POCKET
ld [wCurPocket], a
call ClearPocketList
call DrawPocketName
call WaitBGMap_DrawPackGFX
call Pack_JumptableNext
ret
.BallsPocketMenu:
ld hl, BallsPocketMenuHeader
call CopyMenuHeader
ld a, [wBallsPocketCursor]
ld [wMenuCursorBuffer], a
ld a, [wBallsPocketScrollPosition]
ld [wMenuScrollPosition], a
call ScrollingMenu
ld a, [wMenuScrollPosition]
ld [wBallsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wBallsPocketCursor], a
ld b, PACKSTATE_INITITEMSPOCKET ; left
ld c, PACKSTATE_INITKEYITEMSPOCKET ; right
call Pack_InterpretJoypad
ret c
call ItemSubmenu
ret
ItemSubmenu:
farcall CheckItemContext
ld a, [wItemAttributeParamBuffer]
TMHMSubmenu:
and a
jr z, .NoUse
ld hl, .UsableMenuHeader
ld de, .UsableJumptable
jr .proceed
.NoUse:
ld hl, .UnusableMenuHeader
ld de, .UnusableJumptable
.proceed
push de
call LoadMenuHeader
call VerticalMenu
call ExitMenu
pop hl
ret c
ld a, [wMenuCursorY]
dec a
call Pack_GetJumptablePointer
jp hl
.UsableMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 13, 7, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .UsableMenuData
db 1 ; default option
.UsableMenuData:
db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
db 2 ; items
db "USE@"
db "QUIT@"
.UsableJumptable:
dw .Use
dw .Quit
.UnusableMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 13, 9, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .UnusableMenuData
db 1 ; default option
.UnusableMenuData:
db STATICMENU_CURSOR | STATICMENU_NO_TOP_SPACING ; flags
db 1 ; items
db "QUIT@"
.UnusableJumptable:
dw .Quit
.Use:
farcall CheckItemContext
ld a, [wItemAttributeParamBuffer]
ld hl, .ItemFunctionJumptable
rst JumpTable
ret
.ItemFunctionJumptable:
; entries correspond to ITEMMENU_* constants
dw .Oak ; ITEMMENU_NOUSE
dw .Oak
dw .Oak
dw .Oak
dw .Unused ; ITEMMENU_CURRENT
dw .BattleField ; ITEMMENU_PARTY
dw .BattleOnly ; ITEMMENU_CLOSE
.Oak:
ld hl, Text_ThisIsntTheTime
call Pack_PrintTextNoScroll
ret
.Unused:
call DoItemEffect
ld a, [wItemEffectSucceeded]
and a
jr nz, .ReturnToBattle
ret
.BattleField:
call DoItemEffect
ld a, [wItemEffectSucceeded]
and a
jr nz, .quit_run_script
xor a
ldh [hBGMapMode], a
call Pack_InitGFX
call WaitBGMap_DrawPackGFX
call Pack_InitColors
ret
.ReturnToBattle:
call ClearBGPalettes
jr .quit_run_script
.BattleOnly:
call DoItemEffect
ld a, [wItemEffectSucceeded]
and a
jr z, .Oak
cp $2
jr z, .didnt_use_item
.quit_run_script
ld a, PACKSTATE_QUITRUNSCRIPT
ld [wJumptableIndex], a
ret
.didnt_use_item
xor a
ld [wItemEffectSucceeded], a
ret
.Quit:
ret
InitPackBuffers:
xor a
ld [wJumptableIndex], a
; pocket id -> jumptable index
ld a, [wLastPocket]
maskbits NUM_POCKETS
ld [wCurPocket], a
inc a
add a
dec a
ld [wPackJumptableIndex], a
xor a ; FALSE
ld [wPackUsedItem], a
xor a
ld [wSwitchItem], a
ret
DepositSellInitPackBuffers:
xor a
ldh [hBGMapMode], a
ld [wJumptableIndex], a ; PACKSTATE_INITGFX
ld [wPackJumptableIndex], a ; PACKSTATE_INITGFX
ld [wCurPocket], a ; ITEM_POCKET
ld [wPackUsedItem], a
ld [wSwitchItem], a
call Pack_InitGFX
call Pack_InitColors
ret
DepositSellPack:
.loop
call .RunJumptable
call DepositSellTutorial_InterpretJoypad
jr c, .loop
ret
.RunJumptable:
ld a, [wJumptableIndex]
ld hl, .Jumptable
call Pack_GetJumptablePointer
jp hl
.Jumptable:
; entries correspond to *_POCKET constants
dw .ItemsPocket
dw .BallsPocket
dw .KeyItemsPocket
dw .TMHMPocket
.ItemsPocket:
xor a ; ITEM_POCKET
call InitPocket
ld hl, PC_Mart_ItemsPocketMenuHeader
call CopyMenuHeader
ld a, [wItemsPocketCursor]
ld [wMenuCursorBuffer], a
ld a, [wItemsPocketScrollPosition]
ld [wMenuScrollPosition], a
call ScrollingMenu
ld a, [wMenuScrollPosition]
ld [wItemsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wItemsPocketCursor], a
ret
.KeyItemsPocket:
ld a, KEY_ITEM_POCKET
call InitPocket
ld hl, PC_Mart_KeyItemsPocketMenuHeader
call CopyMenuHeader
ld a, [wKeyItemsPocketCursor]
ld [wMenuCursorBuffer], a
ld a, [wKeyItemsPocketScrollPosition]
ld [wMenuScrollPosition], a
call ScrollingMenu
ld a, [wMenuScrollPosition]
ld [wKeyItemsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wKeyItemsPocketCursor], a
ret
.TMHMPocket:
ld a, TM_HM_POCKET
call InitPocket
call WaitBGMap_DrawPackGFX
farcall TMHMPocket
ld a, [wCurItem]
ld [wCurItem], a
ret
.BallsPocket:
ld a, BALL_POCKET
call InitPocket
ld hl, PC_Mart_BallsPocketMenuHeader
call CopyMenuHeader
ld a, [wBallsPocketCursor]
ld [wMenuCursorBuffer], a
ld a, [wBallsPocketScrollPosition]
ld [wMenuScrollPosition], a
call ScrollingMenu
ld a, [wMenuScrollPosition]
ld [wBallsPocketScrollPosition], a
ld a, [wMenuCursorY]
ld [wBallsPocketCursor], a
ret
InitPocket:
ld [wCurPocket], a
call ClearPocketList
call DrawPocketName
call WaitBGMap_DrawPackGFX
ret
DepositSellTutorial_InterpretJoypad:
ld hl, wMenuJoypad
ld a, [hl]
and A_BUTTON
jr nz, .a_button
ld a, [hl]
and B_BUTTON
jr nz, .b_button
ld a, [hl]
and D_LEFT
jr nz, .d_left
ld a, [hl]
and D_RIGHT
jr nz, .d_right
scf
ret
.a_button
ld a, TRUE
ld [wPackUsedItem], a
and a
ret
.b_button
xor a ; FALSE
ld [wPackUsedItem], a
and a
ret
.d_left
ld a, [wJumptableIndex]
dec a
maskbits NUM_POCKETS
ld [wJumptableIndex], a
push de
ld de, SFX_SWITCH_POCKETS
call PlaySFX
pop de
scf
ret
.d_right
ld a, [wJumptableIndex]
inc a
maskbits NUM_POCKETS
ld [wJumptableIndex], a
push de
ld de, SFX_SWITCH_POCKETS
call PlaySFX
pop de
scf
ret
TutorialPack:
call DepositSellInitPackBuffers
ld a, [wInputType]
or a
jr z, .loop
farcall _DudeAutoInput_RightA
.loop
call .RunJumptable
call DepositSellTutorial_InterpretJoypad
jr c, .loop
xor a ; FALSE
ld [wPackUsedItem], a
ret
.RunJumptable:
ld a, [wJumptableIndex]
ld hl, .dw
call Pack_GetJumptablePointer
jp hl
.dw
; entries correspond to *_POCKET constants
dw .Items
dw .Balls
dw .KeyItems
dw .TMHM
.Items:
xor a ; ITEM_POCKET
ld hl, .ItemsMenuHeader
jr .DisplayPocket
.ItemsMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 7, 1, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .ItemsMenuData
db 1 ; default option
.ItemsMenuData:
db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP | STATICMENU_CURSOR ; flags
db 5, 8 ; rows, columns
db 2 ; horizontal spacing
dbw 0, wDudeNumItems
dba PlaceMenuItemName
dba PlaceMenuItemQuantity
dba UpdateItemDescription
.KeyItems:
ld a, KEY_ITEM_POCKET
ld hl, .KeyItemsMenuHeader
jr .DisplayPocket
.KeyItemsMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 7, 1, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .KeyItemsMenuData
db 1 ; default option
.KeyItemsMenuData:
db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP | STATICMENU_CURSOR ; flags
db 5, 8 ; rows, columns
db 1 ; horizontal spacing
dbw 0, wDudeNumKeyItems
dba PlaceMenuItemName
dba PlaceMenuItemQuantity
dba UpdateItemDescription
.TMHM:
ld a, TM_HM_POCKET
call InitPocket
call WaitBGMap_DrawPackGFX
farcall TMHMPocket
ld a, [wCurItem]
ld [wCurItem], a
ret
.Balls:
ld a, BALL_POCKET
ld hl, .BallsMenuHeader
jr .DisplayPocket
.BallsMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 7, 1, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .BallsMenuData
db 1 ; default option
.BallsMenuData:
db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP | STATICMENU_CURSOR ; flags
db 5, 8 ; rows, columns
db 2 ; horizontal spacing
dbw 0, wDudeNumBalls
dba PlaceMenuItemName
dba PlaceMenuItemQuantity
dba UpdateItemDescription
.DisplayPocket:
push hl
call InitPocket
pop hl
call CopyMenuHeader
call ScrollingMenu
ret
Pack_JumptableNext:
ld hl, wJumptableIndex
inc [hl]
ret
Pack_GetJumptablePointer:
ld e, a
ld d, 0
add hl, de
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ret
Pack_QuitNoScript:
ld hl, wJumptableIndex
set 7, [hl]
xor a ; FALSE
ld [wPackUsedItem], a
ret
Pack_QuitRunScript:
ld hl, wJumptableIndex
set 7, [hl]
ld a, TRUE
ld [wPackUsedItem], a
ret
Pack_PrintTextNoScroll:
ld a, [wOptions]
push af
set NO_TEXT_SCROLL, a
ld [wOptions], a
call PrintText
pop af
ld [wOptions], a
ret
WaitBGMap_DrawPackGFX:
call WaitBGMap
DrawPackGFX:
ld a, [wCurPocket]
maskbits NUM_POCKETS
ld e, a
ld d, 0
ld a, [wBattleType]
cp BATTLETYPE_TUTORIAL
jr z, .male_dude
ld a, [wPlayerGender]
bit PLAYERGENDER_FEMALE_F, a
jr nz, .female
.male_dude
ld hl, PackGFXPointers
add hl, de
add hl, de
ld a, [hli]
ld e, a
ld d, [hl]
ld hl, vTiles2 tile $50
lb bc, BANK(PackGFX), 15
call Request2bpp
ret
.female
farcall DrawKrisPackGFX
ret
PackGFXPointers:
dw PackGFX + (15 tiles) * 1 ; ITEM_POCKET
dw PackGFX + (15 tiles) * 3 ; BALL_POCKET
dw PackGFX + (15 tiles) * 0 ; KEY_ITEM_POCKET
dw PackGFX + (15 tiles) * 2 ; TM_HM_POCKET
Pack_InterpretJoypad:
ld hl, wMenuJoypad
ld a, [wSwitchItem]
and a
jr nz, .switching_item
ld a, [hl]
and A_BUTTON
jr nz, .a_button
ld a, [hl]
and B_BUTTON
jr nz, .b_button
ld a, [hl]
and D_LEFT
jr nz, .d_left
ld a, [hl]
and D_RIGHT
jr nz, .d_right
ld a, [hl]
and SELECT
jr nz, .select
scf
ret
.a_button
and a
ret
.b_button
ld a, PACKSTATE_QUITNOSCRIPT
ld [wJumptableIndex], a
scf
ret
.d_left
ld a, b
ld [wJumptableIndex], a
ld [wPackJumptableIndex], a
push de
ld de, SFX_SWITCH_POCKETS
call PlaySFX
pop de
scf
ret
.d_right
ld a, c
ld [wJumptableIndex], a
ld [wPackJumptableIndex], a
push de
ld de, SFX_SWITCH_POCKETS
call PlaySFX
pop de
scf
ret
.select
farcall SwitchItemsInBag
ld hl, Text_MoveItemWhere
call Pack_PrintTextNoScroll
scf
ret
.switching_item
ld a, [hl]
and A_BUTTON | SELECT
jr nz, .place_insert
ld a, [hl]
and B_BUTTON
jr nz, .end_switch
scf
ret
.place_insert
farcall SwitchItemsInBag
ld de, SFX_SWITCH_POKEMON
call WaitPlaySFX
ld de, SFX_SWITCH_POKEMON
call WaitPlaySFX
.end_switch
xor a
ld [wSwitchItem], a
scf
ret
Pack_InitGFX:
call ClearBGPalettes
call ClearTileMap
call ClearSprites
call DisableLCD
ld hl, PackMenuGFX
ld de, vTiles2
ld bc, $60 tiles
ld a, BANK(PackMenuGFX)
call FarCopyBytes
; Background (blue if male, pink if female)
hlcoord 0, 1
ld bc, 11 * SCREEN_WIDTH
ld a, $24
call ByteFill
; This is where the items themselves will be listed.
hlcoord 5, 1
lb bc, 11, 15
call ClearBox
; ◀▶ POCKET ▼▲ ITEMS
hlcoord 0, 0
ld a, $28
ld c, SCREEN_WIDTH
.loop
ld [hli], a
inc a
dec c
jr nz, .loop
call DrawPocketName
call PlacePackGFX
; Place the textbox for displaying the item description
hlcoord 0, SCREEN_HEIGHT - 4 - 2
lb bc, 4, SCREEN_WIDTH - 2
call Textbox
call EnableLCD
call DrawPackGFX
ret
PlacePackGFX:
hlcoord 0, 3
ld a, $50
ld de, SCREEN_WIDTH - 5
ld b, 3
.row
ld c, 5
.column
ld [hli], a
inc a
dec c
jr nz, .column
add hl, de
dec b
jr nz, .row
ret
DrawPocketName:
ld a, [wCurPocket]
; * 15
ld d, a
swap a
sub d
ld d, 0
ld e, a
ld hl, .tilemap
add hl, de
ld d, h
ld e, l
hlcoord 0, 7
ld c, 3
.row
ld b, 5
.col
ld a, [de]
inc de
ld [hli], a
dec b
jr nz, .col
ld a, c
ld c, SCREEN_WIDTH - 5
add hl, bc
ld c, a
dec c
jr nz, .row
ret
.tilemap
; ITEM_POCKET
db $00, $04, $04, $04, $01 ; top border
db $06, $07, $08, $09, $0a ; Items
db $02, $05, $05, $05, $03 ; bottom border
; BALL_POCKET
db $00, $04, $04, $04, $01 ; top border
db $15, $16, $17, $18, $19 ; Balls
db $02, $05, $05, $05, $03 ; bottom border
; KEY_ITEM_POCKET
db $00, $04, $04, $04, $01 ; top border
db $0b, $0c, $0d, $0e, $0f ; Key Items
db $02, $05, $05, $05, $03 ; bottom border
; TM_HM_POCKET
db $00, $04, $04, $04, $01 ; top border
db $10, $11, $12, $13, $14 ; TM/HM
db $02, $05, $05, $05, $03 ; bottom border
Pack_GetItemName:
ld a, [wCurItem]
ld [wNamedObjectIndexBuffer], a
call GetItemName
call CopyName1
ret
Unreferenced_Pack_ClearTilemap:
hlcoord 0, 0
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
ld a, " "
call ByteFill
ret
ClearPocketList:
hlcoord 5, 2
lb bc, 10, SCREEN_WIDTH - 5
call ClearBox
ret
Pack_InitColors:
call WaitBGMap
ld b, SCGB_PACKPALS
call GetSGBLayout
call SetPalettes
call DelayFrame
ret
ItemsPocketMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 7, 1, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP | STATICMENU_CURSOR ; flags
db 5, 8 ; rows, columns
db SCROLLINGMENU_ITEMS_QUANTITY ; item format
dbw 0, wNumItems
dba PlaceMenuItemName
dba PlaceMenuItemQuantity
dba UpdateItemDescription
PC_Mart_ItemsPocketMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 7, 1, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP ; flags
db 5, 8 ; rows, columns
db SCROLLINGMENU_ITEMS_QUANTITY ; item format
dbw 0, wNumItems
dba PlaceMenuItemName
dba PlaceMenuItemQuantity
dba UpdateItemDescription
KeyItemsPocketMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 7, 1, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP | STATICMENU_CURSOR ; flags
db 5, 8 ; rows, columns
db SCROLLINGMENU_ITEMS_NORMAL ; item format
dbw 0, wNumKeyItems
dba PlaceMenuItemName
dba PlaceMenuItemQuantity
dba UpdateItemDescription
PC_Mart_KeyItemsPocketMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 7, 1, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP ; flags
db 5, 8 ; rows, columns
db SCROLLINGMENU_ITEMS_NORMAL ; item format
dbw 0, wNumKeyItems
dba PlaceMenuItemName
dba PlaceMenuItemQuantity
dba UpdateItemDescription
BallsPocketMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 7, 1, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP | STATICMENU_CURSOR ; flags
db 5, 8 ; rows, columns
db SCROLLINGMENU_ITEMS_QUANTITY ; item format
dbw 0, wNumBalls
dba PlaceMenuItemName
dba PlaceMenuItemQuantity
dba UpdateItemDescription
PC_Mart_BallsPocketMenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 7, 1, SCREEN_WIDTH - 1, TEXTBOX_Y - 1
dw .MenuData
db 1 ; default option
.MenuData:
db STATICMENU_ENABLE_SELECT | STATICMENU_ENABLE_LEFT_RIGHT | STATICMENU_ENABLE_START | STATICMENU_WRAP ; flags
db 5, 8 ; rows, columns
db SCROLLINGMENU_ITEMS_QUANTITY ; item format
dbw 0, wNumBalls
dba PlaceMenuItemName
dba PlaceMenuItemQuantity
dba UpdateItemDescription
Text_PackNoItems:
; No items.
text_far UnknownText_0x1c0b9a
text_end
Text_ThrowAwayHowMany:
; Throw away how many?
text_far UnknownText_0x1c0ba5
text_end
Text_ConfirmThrowAway:
; Throw away @ @ (S)?
text_far UnknownText_0x1c0bbb
text_end
Text_ThrewAway:
; Threw away @ (S).
text_far UnknownText_0x1c0bd8
text_end
Text_ThisIsntTheTime:
; OAK: ! This isn't the time to use that!
text_far UnknownText_0x1c0bee
text_end
TextJump_YouDontHaveAMon:
; You don't have a #MON!
text_far Text_YouDontHaveAMon
text_end
Text_RegisteredItem:
; Registered the @ .
text_far UnknownText_0x1c0c2e
text_end
Text_CantRegister:
; You can't register that item.
text_far UnknownText_0x1c0c45
text_end
Text_MoveItemWhere:
; Where should this be moved to?
text_far UnknownText_0x1c0c63
text_end
Text_PackEmptyString:
;
text_far UnknownText_0x1c0c83
text_end
TextJump_YouCantUseItInABattle:
; Doesn't seem to be used anywhere
; "You can't use it in a battle."
text_far Text_YouCantUseItInABattle
text_end
PackMenuGFX:
INCBIN "gfx/pack/pack_menu.2bpp"
PackGFX:
INCBIN "gfx/pack/pack.2bpp"
|
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef LIBP2P_BASIC_ASIO_SCHEDULER_BACKEND_HPP
#define LIBP2P_BASIC_ASIO_SCHEDULER_BACKEND_HPP
#include <boost/asio/io_context.hpp>
#include <boost/asio/steady_timer.hpp>
#include <libp2p/basic/scheduler.hpp>
namespace libp2p::basic {
/**
* Boost.Asio scheduler backend implementation, uses steady timer.
* Injected into SchedulerImpl. Has only 1 timer, which is rescheduled as per
* higher level logic
*/
class AsioSchedulerBackend : public SchedulerBackend {
public:
/**
* Ctor.
* @param io_context Asio io context
*/
explicit AsioSchedulerBackend(
std::shared_ptr<boost::asio::io_context> io_context);
/**
* @return Milliseconds since steady clock's epoch
*/
std::chrono::milliseconds now() noexcept override;
/**
* Sets the timer. Called by Scheduler implementation
* @param abs_time Abs time: milliseconds since clock's epoch
* @param scheduler Weak ref to owner
*/
void setTimer(
std::chrono::milliseconds abs_time,
std::weak_ptr<SchedulerBackendFeedback> scheduler) override;
private:
/**
* Non-virtual now() implementation
*/
static std::chrono::milliseconds nowImpl();
/// Boost.Asio context
std::shared_ptr<boost::asio::io_context> io_context_;
/// Boost.Asio steady timer
boost::asio::steady_timer timer_;
};
} // namespace libp2p::basic
#endif // LIBP2P_BASIC_ASIO_SCHEDULER_BACKEND_HPP
|
// Copyright (c) 2019-2023 The PIVXL developers
// Copyright (c) 2014 The Bitcoin Core developers
// Copyright (c) 2017-2019 The PIVX developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "main.h"
#include "util.h"
#include "test/test_pivxl.h"
#include <vector>
#include <boost/test/unit_test.hpp>
#define SKIPLIST_LENGTH 300000
BOOST_FIXTURE_TEST_SUITE(skiplist_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(skiplist_test)
{
std::vector<CBlockIndex> vIndex(SKIPLIST_LENGTH);
for (int i=0; i<SKIPLIST_LENGTH; i++) {
vIndex[i].nHeight = i;
vIndex[i].pprev = (i == 0) ? NULL : &vIndex[i - 1];
vIndex[i].BuildSkip();
}
for (int i=0; i<SKIPLIST_LENGTH; i++) {
if (i > 0) {
BOOST_CHECK(vIndex[i].pskip == &vIndex[vIndex[i].pskip->nHeight]);
BOOST_CHECK(vIndex[i].pskip->nHeight < i);
} else {
BOOST_CHECK(vIndex[i].pskip == NULL);
}
}
for (int i=0; i < 1000; i++) {
int from = InsecureRandRange(SKIPLIST_LENGTH - 1);
int to = InsecureRandRange(from + 1);
BOOST_CHECK(vIndex[SKIPLIST_LENGTH - 1].GetAncestor(from) == &vIndex[from]);
BOOST_CHECK(vIndex[from].GetAncestor(to) == &vIndex[to]);
BOOST_CHECK(vIndex[from].GetAncestor(0) == &vIndex[0]);
}
}
BOOST_AUTO_TEST_CASE(getlocator_test)
{
// Build a main chain 100000 blocks long.
std::vector<uint256> vHashMain(100000);
std::vector<CBlockIndex> vBlocksMain(100000);
for (unsigned int i=0; i<vBlocksMain.size(); i++) {
vHashMain[i] = i; // Set the hash equal to the height, so we can quickly check the distances.
vBlocksMain[i].nHeight = i;
vBlocksMain[i].pprev = i ? &vBlocksMain[i - 1] : NULL;
vBlocksMain[i].phashBlock = &vHashMain[i];
vBlocksMain[i].BuildSkip();
BOOST_CHECK_EQUAL((int)vBlocksMain[i].GetBlockHash().GetLow64(), vBlocksMain[i].nHeight);
BOOST_CHECK(vBlocksMain[i].pprev == NULL || vBlocksMain[i].nHeight == vBlocksMain[i].pprev->nHeight + 1);
}
// Build a branch that splits off at block 49999, 50000 blocks long.
std::vector<uint256> vHashSide(50000);
std::vector<CBlockIndex> vBlocksSide(50000);
for (unsigned int i=0; i<vBlocksSide.size(); i++) {
vHashSide[i] = i + 50000 + (uint256(1) << 128); // Add 1<<128 to the hashes, so GetLow64() still returns the height.
vBlocksSide[i].nHeight = i + 50000;
vBlocksSide[i].pprev = i ? &vBlocksSide[i - 1] : &vBlocksMain[49999];
vBlocksSide[i].phashBlock = &vHashSide[i];
vBlocksSide[i].BuildSkip();
BOOST_CHECK_EQUAL((int)vBlocksSide[i].GetBlockHash().GetLow64(), vBlocksSide[i].nHeight);
BOOST_CHECK(vBlocksSide[i].pprev == NULL || vBlocksSide[i].nHeight == vBlocksSide[i].pprev->nHeight + 1);
}
// Build a CChain for the main branch.
CChain chain;
chain.SetTip(&vBlocksMain.back());
// Test 100 random starting points for locators.
for (int n=0; n<100; n++) {
int r = InsecureRandRange(150000);
CBlockIndex* tip = (r < 100000) ? &vBlocksMain[r] : &vBlocksSide[r - 100000];
CBlockLocator locator = chain.GetLocator(tip);
// The first result must be the block itself, the last one must be genesis.
BOOST_CHECK(locator.vHave.front() == tip->GetBlockHash());
BOOST_CHECK(locator.vHave.back() == vBlocksMain[0].GetBlockHash());
// Entries 1 through 11 (inclusive) go back one step each.
for (unsigned int i = 1; i < 12 && i < locator.vHave.size() - 1; i++) {
BOOST_CHECK_EQUAL(locator.vHave[i].GetLow64(), tip->nHeight - i);
}
// The further ones (excluding the last one) go back with exponential steps.
unsigned int dist = 2;
for (unsigned int i = 12; i < locator.vHave.size() - 1; i++) {
BOOST_CHECK_EQUAL(locator.vHave[i - 1].GetLow64() - locator.vHave[i].GetLow64(), dist);
dist *= 2;
}
}
}
BOOST_AUTO_TEST_SUITE_END()
|
; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.50727.1
include listing.inc
INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES
CONST SEGMENT
$SG3424 DB 'Ethernet Protocol Received ->> ARP type', 0aH, 00H
ORG $+7
$SG3426 DB 'Ethernet Protocol Received packet ->> IP Packet', 0aH, 00H
CONST ENDS
PUBLIC ?ethernet_send_packet@@YAHPEAE0HG@Z ; ethernet_send_packet
PUBLIC ?ethernet_handle_packet@@YAXPEAU_ethernet_frame_@@H@Z ; ethernet_handle_packet
EXTRN memcpy:PROC
EXTRN ?printf@@YAXPEBDZZ:PROC ; printf
EXTRN ?malloc@@YAPEAX_K@Z:PROC ; malloc
EXTRN ?free@@YAXPEAX@Z:PROC ; free
EXTRN ?nethw_get_mac@@YAXPEAE@Z:PROC ; nethw_get_mac
EXTRN ?htons@@YAGG@Z:PROC ; htons
EXTRN ?ntohs@@YAGG@Z:PROC ; ntohs
EXTRN ?e1000_send_packet@@YAXPEAX_K@Z:PROC ; e1000_send_packet
pdata SEGMENT
$pdata$?ethernet_send_packet@@YAHPEAE0HG@Z DD imagerel $LN3
DD imagerel $LN3+205
DD imagerel $unwind$?ethernet_send_packet@@YAHPEAE0HG@Z
$pdata$?ethernet_handle_packet@@YAXPEAU_ethernet_frame_@@H@Z DD imagerel $LN5
DD imagerel $LN5+119
DD imagerel $unwind$?ethernet_handle_packet@@YAXPEAU_ethernet_frame_@@H@Z
pdata ENDS
xdata SEGMENT
$unwind$?ethernet_send_packet@@YAHPEAE0HG@Z DD 011901H
DD 08219H
$unwind$?ethernet_handle_packet@@YAXPEAU_ethernet_frame_@@H@Z DD 010d01H
DD 0620dH
xdata ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\net\ethernet.cpp
_TEXT SEGMENT
data_len$ = 32
data$ = 40
packet$ = 64
len$ = 72
?ethernet_handle_packet@@YAXPEAU_ethernet_frame_@@H@Z PROC ; ethernet_handle_packet
; 46 : void ethernet_handle_packet (ethernet_frame_t * packet, int len) {
$LN5:
mov DWORD PTR [rsp+16], edx
mov QWORD PTR [rsp+8], rcx
sub rsp, 56 ; 00000038H
; 47 : void* data = (void*)(packet + sizeof(ethernet_frame_t));
mov rax, QWORD PTR packet$[rsp]
add rax, 196 ; 000000c4H
mov QWORD PTR data$[rsp], rax
; 48 : int data_len = len - sizeof(ethernet_frame_t);
movsxd rax, DWORD PTR len$[rsp]
sub rax, 14
mov DWORD PTR data_len$[rsp], eax
; 49 : if(ntohs(packet->type) == ETHERNET_TYPE_ARP) {
mov rax, QWORD PTR packet$[rsp]
movzx ecx, WORD PTR [rax+12]
call ?ntohs@@YAGG@Z ; ntohs
movzx eax, ax
cmp eax, 2054 ; 00000806H
jne SHORT $LN2@ethernet_h
; 50 : printf ("Ethernet Protocol Received ->> ARP type\n");
lea rcx, OFFSET FLAT:$SG3424
call ?printf@@YAXPEBDZZ ; printf
$LN2@ethernet_h:
; 51 : //arp_handle_packet
; 52 : }
; 53 :
; 54 : //!IP packets (TCP, UDP, or others)
; 55 : if (ntohs(packet->type) == ETHERNET_TYPE_IP) {
mov rax, QWORD PTR packet$[rsp]
movzx ecx, WORD PTR [rax+12]
call ?ntohs@@YAGG@Z ; ntohs
movzx eax, ax
cmp eax, 2048 ; 00000800H
jne SHORT $LN1@ethernet_h
; 56 : printf ("Ethernet Protocol Received packet ->> IP Packet\n");
lea rcx, OFFSET FLAT:$SG3426
call ?printf@@YAXPEBDZZ ; printf
$LN1@ethernet_h:
; 57 : }
; 58 : }
add rsp, 56 ; 00000038H
ret 0
?ethernet_handle_packet@@YAXPEAU_ethernet_frame_@@H@Z ENDP ; ethernet_handle_packet
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\net\ethernet.cpp
_TEXT SEGMENT
src_mac_addr$ = 32
frame$ = 40
frame_data$ = 48
dst_mac_addr$ = 80
data$ = 88
len$ = 96
protocol$ = 104
?ethernet_send_packet@@YAHPEAE0HG@Z PROC ; ethernet_send_packet
; 20 : int ethernet_send_packet (uint8_t* dst_mac_addr, uint8_t *data, int len, uint16_t protocol) {
$LN3:
mov WORD PTR [rsp+32], r9w
mov DWORD PTR [rsp+24], r8d
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+8], rcx
sub rsp, 72 ; 00000048H
; 21 :
; 22 : uint8_t src_mac_addr[6];
; 23 : ethernet_frame_t *frame = (ethernet_frame_t*)malloc (sizeof(ethernet_frame_t) + len);
movsxd rax, DWORD PTR len$[rsp]
add rax, 14
mov rcx, rax
call ?malloc@@YAPEAX_K@Z ; malloc
mov QWORD PTR frame$[rsp], rax
; 24 : void *frame_data = (void*)(frame + sizeof(ethernet_frame_t));
mov rax, QWORD PTR frame$[rsp]
add rax, 196 ; 000000c4H
mov QWORD PTR frame_data$[rsp], rax
; 25 :
; 26 : //! get the src mac address
; 27 : nethw_get_mac (src_mac_addr);
lea rcx, QWORD PTR src_mac_addr$[rsp]
call ?nethw_get_mac@@YAXPEAE@Z ; nethw_get_mac
; 28 :
; 29 : //! fill in source and destination mac address
; 30 : memcpy (frame->src_mac_addr, src_mac_addr, 6);
mov rax, QWORD PTR frame$[rsp]
add rax, 6
mov r8d, 6
lea rdx, QWORD PTR src_mac_addr$[rsp]
mov rcx, rax
call memcpy
; 31 : memcpy (frame->dst_mac_addr, dst_mac_addr, 6);
mov rax, QWORD PTR frame$[rsp]
mov r8d, 6
mov rdx, QWORD PTR dst_mac_addr$[rsp]
mov rcx, rax
call memcpy
; 32 :
; 33 : //!fill in data
; 34 : memcpy (frame_data,data, len);
mov r8d, DWORD PTR len$[rsp]
mov rdx, QWORD PTR data$[rsp]
mov rcx, QWORD PTR frame_data$[rsp]
call memcpy
; 35 :
; 36 : //!fill in type
; 37 : frame->type = htons(protocol);
movzx ecx, WORD PTR protocol$[rsp]
call ?htons@@YAGG@Z ; htons
mov rcx, QWORD PTR frame$[rsp]
mov WORD PTR [rcx+12], ax
; 38 :
; 39 : //!Send packet
; 40 : e1000_send_packet (frame, sizeof(ethernet_frame_t) + len);
movsxd rax, DWORD PTR len$[rsp]
add rax, 14
mov rdx, rax
mov rcx, QWORD PTR frame$[rsp]
call ?e1000_send_packet@@YAXPEAX_K@Z ; e1000_send_packet
; 41 : free (frame);
mov rcx, QWORD PTR frame$[rsp]
call ?free@@YAXPEAX@Z ; free
; 42 : return len;
mov eax, DWORD PTR len$[rsp]
; 43 : }
add rsp, 72 ; 00000048H
ret 0
?ethernet_send_packet@@YAHPEAE0HG@Z ENDP ; ethernet_send_packet
_TEXT ENDS
END
|
; A105186: Replace odd-positioned digits with 0 in ternary representation of n.
; Submitted by Jamie Morken(w1)
; 0,1,2,0,1,2,0,1,2,9,10,11,9,10,11,9,10,11,18,19,20,18,19,20,18,19,20,0,1,2,0,1,2,0,1,2,9,10,11,9,10,11,9,10,11,18,19,20,18,19,20,18,19,20,0,1,2,0,1,2,0,1,2,9,10,11,9,10,11,9,10,11,18,19,20,18,19,20,18,19,20,81,82,83,81,82,83,81,82,83,90,91,92,90,91,92,90,91,92,99
mov $3,1
lpb $0
mov $2,$0
div $0,9
mod $2,3
mul $2,$3
add $1,$2
mul $3,9
lpe
mov $0,$1
|
SECTION code_clib
SECTION code_l
PUBLIC l_small_asr_dehl
EXTERN error_lznc, error_lmnc
l_small_asr_dehl:
; arithmetic shift right 32-bit signed long
;
; enter : dehl = 32-bit number
; a = shift amount
;
; exit : dehl = dehl >> a
;
; uses : af, b, de, hl
or a
ret z
cp 32
jr nc, shift_infinite
ld b,a
ld a,e
shift_loop:
sra d
rra
rr h
rr l
djnz shift_loop
ld e,a
ret
shift_infinite:
bit 7,d
jp z, error_lznc
jp error_lmnc
|
; A102591: a(n)=sum k=0..n, C(2n+1,2k)3^(n-k).
; 1,6,44,328,2448,18272,136384,1017984,7598336,56714752,423324672,3159738368,23584608256,176037912576,1313964867584,9807567290368,73204678852608,546407161659392,4078438577864704,30441879976280064
mul $0,2
mov $1,1
mov $2,2
lpb $0
sub $0,1
sub $1,1
mov $3,$1
add $1,$2
sub $1,1
mul $1,2
add $3,3
mov $2,$3
lpe
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.