text
stringlengths
1
1.05M
; A122639: n_{2n+1}. ; 0,1,2,3,4,5,6,7,8,9,21,24,27,30,33,36,39,42,45,48,82,87,92,97,102,107,112,117,122,127,183,190,197,204,211,218,225,232,239,246,324,333,342,351,360,369,378,387,396,405,505,516,527,538,549,560,571,582,593,604,726,739 mov $3,$0 lpb $0 mov $1,$0 mov $0,1 mov $2,$1 sub $1,3 lpe mul $1,2 sub $1,3 div $2,10 mul $1,$2 add $1,$3
; BUFFER handling routines ; 2006.10.01 1.01 buffer test added (at buff_test) (BC) ; ; ax buffer length / buffer free ; al byte in / out ; bx base of buffer ; buf_stt = 0 ; start of buffer buf_end = 2 ; end of buffer buf_put = 4 ; put pointer buf_get = 6 ; get pointer buf_start = 8 ; start of buffer ASSUME ds:DGROUP ASSUME es:DGROUP buff_set: push cx mov cx,buff_start add cx,bx ; start of buffer mov [bx+buff_stt],cx mov [bx+buff_put],cx mov [bx+buff_get],cx add cx,ax ; end of buffer mov [bx+buff_end],cx dec ax ; free space is one less pop cx retn ; BUFF_PBYTE returns EQ/Z if failed! buff_pbyte: push di mov di,[bx+buff_put] ; put pointer mov [di],al ; put inc di cmp di,[bx+buff_end] ; at end? jb bufp_chk ; ... no mov di,[bx+buff_stt] ; ... yes, reset to start bufp_chk: cmp di,[bx+buff_get] ; full? je bufp_ov ; ... yes mov [bx+buff_put],di ; ... no, move pointer on pop di retn bufp_ov: xor ax,ax pop di retn ; ; BUFF_PBROOM Put byte and check room returns S if failed, Z/EQ if full ; buff_pbroom: push di mov di,[bx+buff_put] ; put pointer mov [di],al ; put inc di cmp di,[bx+buff_end] ; at end? jb bufpr_chk ; ... no mov di,[bx+buff_stt] ; ... yes, reset to start bufpr_chk: mov ax,[bx+buff_get] ; get pointer sub ax,di ; total room in middle je bufpr_ov ; ... out of room mov [bx+buff_put],di ; move pointer on dec ax jns bufpr_exit add ax,[bx+buff_end] ; overlap, we need to add the length sub ax,[bx+buff_stt] bufpr_exit: pop di retn bufpr_ov: mov ax,-1 test ax,ax pop di retn ; ; BUFF_ROOM ; ;buff_room: ; mov ax,[bx+buff_get] ; get pointer ; sub ax,[bx+buff_put] ; total room in middle ; dec ax ; jns bufr_exit ; add ax,[bx+buff_end] ; overlap, we need to add the length ; sub ax,[bx+buff_stt] ;bufr_exit: ; retn ; ; BUFF_GBYTE returns EQ if failed! ; buff_gbyte: push si mov si,[bx+buff_get] ; get pointer cmp si,[bx+buff_put] ; anything to get? jz bufg_exit lodsb ; get cmp si,[bx+buff_end] ; at end? jb bufg_ok ; ... no mov si,[bx+buff_stt] ; ... yes, reset to start test si,si ; set nz bufg_ok: mov [bx+buff_get],si ; move pointer on bufg_exit: pop si retn ; ; BUFF_TEST returns EQ if empty ; buff_test: push si mov si,[bx+buff_get] ; get pointer cmp si,[bx+buff_put] ; anything to get? pop si retn
; int ungetc(int c, FILE *stream) INCLUDE "config_private.inc" 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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; A135528: 1, then repeat 1,0. ; Submitted by Christian Krause ; 1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1 trn $0,1 add $0,1 mod $0,2
; Test program used during MEGA65 keyboard development ; ; Prints the keyboard status register and the data register and additionally ; echos normal keys. "SPECIAL" in the text area, when a special key is pressed. ; ; Press CTRL+E to exit back to the monitor ; ; done by sy2002 in April 2020 .ORG 0x8000 #include "../../dist_kit/sysdef.asm" #include "../../dist_kit/monitor.def" SYSCALL(vga_cls, 1) MOVE STR_HEADER, R8 ; print header and make space in line 0 SYSCALL(puts, 1) XOR R11, R11 ; R11 = SPECIAL, ASCII MAIN_LOOP MOVE _VGA$X, R0 ; current x, y coordinates MOVE @R0, R1 MOVE _VGA$Y, R2 MOVE @R2, R3 XOR R4, R4 MOVE R4, @R0 MOVE 2, R4 MOVE R4, @R2 MOVE STR_STATUS, R8 ; print "STATUS = " SYSCALL(puts, 1) MOVE IO$KBD_STATE, R8 ; read and print status register MOVE @R8, R8 SYSCALL(puthex, 1) MOVE STR_ASCII, R8 ; print " SPECIAL, ASCII = " SYSCALL(puts, 1) MOVE R11, R8 ; print the SPECIAL and ASCII value SYSCALL(puthex, 1) MOVE R1, @R0 ; restore the cursor position MOVE R3, @R2 MOVE IO$KBD_STATE, R4 ; read keyboard state MOVE @R4, R4 AND KBD$NEW_ASCII, R4 ; new ASCII character? RBRA _NO_NEW_ASCII, Z ; no, skip MOVE IO$KBD_DATA, R4 ; read char and check if CTRL+E MOVE @R4, R8 CMP KBD$CTRL_E, R8 RBRA EXIT, Z ; yes: exit CMP KBD$ENTER, R8 ; ENTER? RBRA _BS, !Z ; no? check BS MOVE _VGA$X, R0 ; x=0 XOR @R0, @R0 MOVE _VGA$Y, R0 ; y++ ADD 1, @R0 RBRA _CONT, 1 _BS CMP KBD$BACKSPACE, R8 ; BACKSPACE? RBRA _PRINT, !Z ; no? print MOVE _VGA$X, R0 ; x-- SUB 1, @R0 RBRA _CONT, 1 _PRINT SYSCALL(putc, 1) _CONT MOVE R8, R11 ; remember it for printing _NO_NEW_ASCII MOVE IO$KBD_STATE, R4 MOVE @R4, R4 AND KBD$NEW_SPECIAL, R4 ; new special key? RBRA _NO_NEW_SPECIAL, Z ; no, skip MOVE IO$KBD_DATA, R4 ; read special char MOVE @R4, R11 ; remember it for printing MOVE STR_SPECIAL, R8 SYSCALL(puts, 1) _NO_NEW_SPECIAL RBRA MAIN_LOOP, 1 EXIT SYSCALL(exit, 1) STR_HEADER .ASCII_W "MEGA65 Keyboard Development Testbed, done by sy2002 in April 2020\n\n\n\n" STR_STATUS .ASCII_W "STATUS = " STR_ASCII .ASCII_W " SPECIAL, ASCII = " STR_SPECIAL .ASCII_W "SPECIAL" _VGA$X .EQU 0xFEEC _VGA$Y .EQU 0xFEED
#include "stl_implement_text_class.h" void Text::AddStringEnd(const std::string & add_string_end) { text_.push_back(add_string_end); return; } void Text::InsertString(const std::string & insert_string) { text_[GetRowNum_()].insert(GetColumeNum_(), insert_string); return; } void Text::DeleteForward() { if (GetColumeNum_() == 0) { DeleteEntireLine(); } else { text_[GetColumeNum_()].erase(GetRowNum_(), 1); MoveLeft(); } return; } void Text::DeleteBackward() { if (GetColumeNum_() == text_[GetRowNum_()].length()) { MoveRight(); const std::string temp_next_line = text_[GetRowNum_()]; DeleteEntireLine(); MoveLeft(); text_[GetRowNum_()] += temp_next_line; } else { text_[GetColumeNum_()].erase(GetRowNum_() + 1, 1); } return; } void Text::DeleteEntireLine() { text_.erase(text_.begin() + GetRowNum_()); return; } void Text::MoveUp() { if (GetRowNum_() != 0) { --screen_info_.screen_y; } return; } void Text::MoveDown() { if (GetRowNum_() != GetNumOfLines()) { ++screen_info_.screen_y; } return; } void Text::MoveRight() { if (GetColumeNum_() == text_[GetRowNum_()].length() && GetRowNum_() != GetNumOfLines()) { ++screen_info_.cursor_y; screen_info_.cursor_x = 0; } else { ++screen_info_.cursor_x; } return; } void Text::MoveLeft() { if (GetColumeNum_() == 0 && GetRowNum_() != 0) { --screen_info_.cursor_y; screen_info_.cursor_x = static_cast<int>(text_[GetRowNum_()].length()); } else { --screen_info_.cursor_x; } } bool Text::SearchWord(const std::string & search_word) { //search the word from the current position auto temp_search_position = text_[GetRowNum_()].find(search_word, GetColumeNum_()); if (temp_search_position != std::string::npos) { screen_info_.cursor_x = static_cast<int>(temp_search_position) - screen_info_.screen_x; return true; } //search the word from next line for (auto i = text_.begin() + GetRowNum_(); i != text_.end(); ++i) { temp_search_position = i->find(search_word); if (temp_search_position != std::string::npos) { screen_info_.cursor_x = static_cast<int>(temp_search_position) - screen_info_.screen_x; screen_info_.cursor_y = static_cast<int>(i - text_.begin()) - screen_info_.screen_y; return true; } } return false; } void Text::TakePlaceString(const std::string & search_word, const std::string & take_place) { SearchWord(search_word); take_place_ = take_place; return; } void Text::ConfirmTakePlace(bool confirm_take_place) { if (confirm_take_place) { InsertString(take_place_); } take_place_.clear(); return; } void Text::RefreshScreenPosition() { if (screen_info_.cursor_x > COLUME_NUMBER) { screen_info_.screen_x += screen_info_.cursor_x - COLUME_NUMBER ; screen_info_.cursor_x = COLUME_NUMBER; } if (screen_info_.cursor_x <= 0) { screen_info_.screen_x += screen_info_.cursor_x; screen_info_.cursor_x = 0; } if (screen_info_.cursor_y > ROW_NUMBER) { screen_info_.screen_x += screen_info_.cursor_y - ROW_NUMBER; screen_info_.cursor_y = ROW_NUMBER; } if (screen_info_.cursor_y <= 0) { screen_info_.screen_y += screen_info_.cursor_y; screen_info_.cursor_y = 0; } return; } int Text::GetNumOfLines() { return static_cast<int>(text_.end() - text_.begin()); } std::string Text::GetIthString(int i) { return text_[i]; } ScreenInfo Text::GetPosition() { return screen_info_; } void Text::RefreshScreenCache() { cache_.clear(); for (int i = 0; i <= ROW_NUMBER; ++i) { if (i + screen_info_.cursor_y < GetNumOfLines()) { cache_.push_back(GetIthString(i + screen_info_.cursor_y).substr(GetColumeNum_(), COLUME_NUMBER)); } else { cache_.push_back(std::string()); } } } std::string Text::GetIthCacheString(int i) { return cache_[i]; } int Text::GetColumeNum_() { return screen_info_.screen_x + screen_info_.cursor_x; } int Text::GetRowNum_() { return screen_info_.screen_y + screen_info_.cursor_y; }
; A028162: Expansion of 1/((1-4x)(1-9x)(1-10x)(1-12x)). ; Submitted by Christian Krause ; 1,35,783,14287,231959,3494127,49989031,689059679,9238060887,121247325199,1565149220999,19940086389951,251372353802935,3141956721674351,38999543432154087,481325752085244703,5912556766920852503,72347177535344895183,882401264035644410695,10733598037414698673535,130272888935792734703991,1578168746274594607701295,19088738333355809956333223,230587947069435545621806047,2782429815122197999456131799,33544194500733035128152486287,404092331148860018016855064071,4864832614713547241581148171839 mov $1,1 mov $2,$0 mov $3,$0 lpb $2 mov $0,$3 sub $2,1 sub $0,$2 seq $0,19722 ; Expansion of 1/((1-4x)(1-9x)(1-12x)). add $0,$1 mul $1,9 add $1,$0 lpe mov $0,$1
// Copyright 2019 The Fuchsia Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "as370-gpio.h" #include <fbl/algorithm.h> #include <lib/mock-function/mock-function.h> #include <mock-mmio-reg/mock-mmio-reg.h> #include <zxtest/zxtest.h> namespace gpio { class As370GpioTest : public As370Gpio { public: As370GpioTest() : As370Gpio(nullptr, ddk::MmioBuffer({}), ddk::MmioBuffer({}), ddk::MmioBuffer({})), mock_pinmux_regs_(pinmux_reg_array_, sizeof(uint32_t), fbl::count_of(pinmux_reg_array_)), mock_gpio1_regs_(gpio1_reg_array_, sizeof(uint32_t), fbl::count_of(gpio1_reg_array_)), mock_gpio2_regs_(gpio2_reg_array_, sizeof(uint32_t), fbl::count_of(gpio2_reg_array_)) { pinmux_mmio_ = ddk::MmioBuffer(mock_pinmux_regs_.GetMmioBuffer()); gpio1_mmio_ = ddk::MmioBuffer(mock_gpio1_regs_.GetMmioBuffer()); gpio2_mmio_ = ddk::MmioBuffer(mock_gpio2_regs_.GetMmioBuffer()); } void VerifyAll() { mock_pinmux_regs_.VerifyAll(); mock_gpio1_regs_.VerifyAll(); mock_gpio2_regs_.VerifyAll(); mock_gpio_impl_write_.VerifyAndClear(); } ddk_mock::MockMmioRegRegion& mock_pinmux_regs() { return mock_pinmux_regs_; } ddk_mock::MockMmioRegRegion& mock_gpio1_regs() { return mock_gpio1_regs_; } ddk_mock::MockMmioRegRegion& mock_gpio2_regs() { return mock_gpio2_regs_; } auto& mock_GpioImplWrite() { return mock_gpio_impl_write_; } zx_status_t GpioImplWrite(uint32_t index, uint8_t value) override { if (mock_gpio_impl_write_.HasExpectations()) { return mock_gpio_impl_write_.Call(index, value); } else { return As370Gpio::GpioImplWrite(index, value); } } private: ddk_mock::MockMmioReg pinmux_reg_array_[64]; ddk_mock::MockMmioReg gpio1_reg_array_[128]; ddk_mock::MockMmioReg gpio2_reg_array_[128]; ddk_mock::MockMmioRegRegion mock_pinmux_regs_; ddk_mock::MockMmioRegRegion mock_gpio1_regs_; ddk_mock::MockMmioRegRegion mock_gpio2_regs_; mock_function::MockFunction<zx_status_t, uint32_t, uint8_t> mock_gpio_impl_write_; }; TEST(As370GpioTest, ConfigIn) { As370GpioTest dut; dut.mock_gpio1_regs()[0x04] .ExpectRead(0xdeadbeef) .ExpectWrite(0xdeadbeee) .ExpectRead(0xabcd1234) .ExpectWrite(0xabcd0234) .ExpectRead(0xfedc1234) .ExpectWrite(0x7edc1234); dut.mock_gpio2_regs()[0x04] .ExpectRead(0xabcd4321) .ExpectWrite(0xabcd4320) .ExpectRead(0xcc7a2c98) .ExpectWrite(0xc47a2c98) .ExpectRead(0x89ab0123) .ExpectWrite(0x09ab0123); EXPECT_OK(dut.GpioImplConfigIn(0, GPIO_NO_PULL)); EXPECT_OK(dut.GpioImplConfigIn(12, GPIO_NO_PULL)); EXPECT_OK(dut.GpioImplConfigIn(31, GPIO_NO_PULL)); EXPECT_OK(dut.GpioImplConfigIn(32, GPIO_NO_PULL)); EXPECT_OK(dut.GpioImplConfigIn(59, GPIO_NO_PULL)); EXPECT_OK(dut.GpioImplConfigIn(63, GPIO_NO_PULL)); EXPECT_NE(ZX_OK, dut.GpioImplConfigIn(64, GPIO_NO_PULL)); dut.VerifyAll(); } TEST(As370GpioTest, ConfigOut) { As370GpioTest dut; dut.mock_GpioImplWrite() .ExpectCall(ZX_OK, 0, 0) .ExpectCall(ZX_OK, 20, 1) .ExpectCall(ZX_OK, 31, 0) .ExpectCall(ZX_OK, 32, 1) .ExpectCall(ZX_OK, 39, 0) .ExpectCall(ZX_OK, 63, 1); dut.mock_gpio1_regs()[0x04] .ExpectRead(0xc8e4dc3c) .ExpectWrite(0xc8e4dc3d) .ExpectRead(0x89226125) .ExpectWrite(0x89326125) .ExpectRead(0x19b21f13) .ExpectWrite(0x99b21f13); dut.mock_gpio2_regs()[0x04] .ExpectRead(0x9f5f0d82) .ExpectWrite(0x9f5f0d83) .ExpectRead(0x4b012478) .ExpectWrite(0x4b0124f8) .ExpectRead(0x468529a9) .ExpectWrite(0xc68529a9); EXPECT_OK(dut.GpioImplConfigOut(0, 0)); EXPECT_OK(dut.GpioImplConfigOut(20, 1)); EXPECT_OK(dut.GpioImplConfigOut(31, 0)); EXPECT_OK(dut.GpioImplConfigOut(32, 1)); EXPECT_OK(dut.GpioImplConfigOut(39, 0)); EXPECT_OK(dut.GpioImplConfigOut(63, 1)); EXPECT_NE(ZX_OK, dut.GpioImplConfigOut(64, 0)); dut.VerifyAll(); } TEST(As370GpioTest, SetAltFunction) { As370GpioTest dut; dut.mock_pinmux_regs()[0x40].ExpectRead(0x7a695363).ExpectWrite(0x7a695367); dut.mock_pinmux_regs()[0x44].ExpectRead(0x647b8955).ExpectWrite(0x649b8955); dut.mock_pinmux_regs()[0x48].ExpectRead(0xac20b39d).ExpectWrite(0xac2cb39d); dut.mock_pinmux_regs()[0x54].ExpectRead(0x2bfc508b).ExpectWrite(0x2b1c508b); dut.mock_pinmux_regs()[0x48].ExpectRead(0x833d4afc).ExpectWrite(0x833d4b7c); dut.mock_pinmux_regs()[0x48].ExpectRead(0xcd0f533b).ExpectWrite(0xcd0cd33b); EXPECT_OK(dut.GpioImplSetAltFunction(0, 7)); EXPECT_OK(dut.GpioImplSetAltFunction(17, 4)); EXPECT_OK(dut.GpioImplSetAltFunction(18, 3)); EXPECT_OK(dut.GpioImplSetAltFunction(49, 0)); EXPECT_OK(dut.GpioImplSetAltFunction(68, 5)); EXPECT_OK(dut.GpioImplSetAltFunction(71, 1)); EXPECT_NE(ZX_OK, dut.GpioImplSetAltFunction(72, 0)); EXPECT_NE(ZX_OK, dut.GpioImplSetAltFunction(0, 8)); dut.VerifyAll(); } TEST(As370GpioTest, Read) { As370GpioTest dut; dut.mock_gpio1_regs()[0x50] .ExpectRead(0x833d4b7c) .ExpectRead(0xa66346fe) .ExpectRead(0x2962e9ab); dut.mock_gpio2_regs()[0x50] .ExpectRead(0x7054a9e7) .ExpectRead(0xe5770561) .ExpectRead(0xbd4bfdec); uint8_t value; EXPECT_OK(dut.GpioImplRead(0, &value)); EXPECT_EQ(0, value); EXPECT_OK(dut.GpioImplRead(17, &value)); EXPECT_EQ(1, value); EXPECT_OK(dut.GpioImplRead(31, &value)); EXPECT_EQ(0, value); EXPECT_OK(dut.GpioImplRead(32, &value)); EXPECT_EQ(1, value); EXPECT_OK(dut.GpioImplRead(55, &value)); EXPECT_EQ(0, value); EXPECT_OK(dut.GpioImplRead(63, &value)); EXPECT_EQ(1, value); EXPECT_NE(ZX_OK, dut.GpioImplRead(64, &value)); dut.VerifyAll(); } TEST(As370GpioTest, Write) { As370GpioTest dut; dut.mock_gpio1_regs()[0x00] .ExpectRead(0xfff6b928) .ExpectWrite(0xfff6b929) .ExpectRead(0x6a246060) .ExpectWrite(0x6a246060) .ExpectRead(0xaab6b6b7) .ExpectWrite(0xaab6b6b7); dut.mock_gpio2_regs()[0x00] .ExpectRead(0x8a22ff3b) .ExpectWrite(0x8a22ff3a) .ExpectRead(0x07e37cb7) .ExpectWrite(0x07e37db7) .ExpectRead(0x833d4b7c) .ExpectWrite(0x033d4b7c); EXPECT_OK(dut.GpioImplWrite(0, 0x9c)); EXPECT_OK(dut.GpioImplWrite(12, 0x00)); EXPECT_OK(dut.GpioImplWrite(31, 0x1e)); EXPECT_OK(dut.GpioImplWrite(32, 0x00)); EXPECT_OK(dut.GpioImplWrite(40, 0xba)); EXPECT_OK(dut.GpioImplWrite(63, 0x00)); EXPECT_NE(ZX_OK, dut.GpioImplWrite(64, 0)); dut.VerifyAll(); } } // namespace gpio
TITLE BdMgr.asm - Buffer Descriptor Management Routines COMMENT \ --------- --- ---- -- ---------- ---- COPYRIGHT (C) 1985 BY MICROSOFT, INC. --------- --- ---- -- ---------- ---- \ ;============================================================================ ; Module: BdMgr.asm - Buffer Descriptor Management Routines ; This is a layer of routines which depends on the BASCOM Runtime Heap ; Management routines in source file (strutl.asm). ; It manages entries in the Interpreter and Far heap. ; System: Quick BASIC Interpreter ;============================================================================ .xlist include version.inc BDMGR_ASM = ON includeOnce architec includeOnce context includeOnce heap includeOnce parser includeOnce txtmgr includeOnce util .list ; .sall assumes DS,DATA assumes ES,DATA assumes SS,DATA sBegin DATA ; HMEM_ constants used by SBMGR allocation routines HMEM_FIXED EQU 0000H HMEM_MOVEABLE EQU 0002H HMEM_NOCOMPACT EQU 0010H HMEM_ZEROINIT EQU 0040H HMEM_DISCARDABLE EQU 0F00H externW b$fVarHeapActive ;non-0 when variable heap is active DbOMCnt MACRO label ENDM sEnd DATA EXTRN AdjustCommon:FAR EXTRN AdjustVarTable:FAR sBegin RT assumes CS,RT EXTRN B$ILHALC:NEAR EXTRN B$LHREALC:NEAR EXTRN B$LHDALC:NEAR EXTRN B$LHChgBakPtr:NEAR EXTRN B$ILHADJ:NEAR EXTRN B$LHForEachEntry:NEAR EXTRN B$NHCPCT:NEAR EXTRN B$TglHeapSpt:FAR EXTRN B$IFHAlloc:NEAR EXTRN B$FHDealloc:NEAR EXTRN B$FHRealloc:NEAR EXTRN B$FHAdjDesc:NEAR EXTRN B$FHAdjOneDesc:NEAR CBBUFBLOCK equ 512 ;Never grow a near heap by less than this ; number of bytes to reduce heap thrashing. VAR_EXTRA equ 30 ;we want to keep up to this much free space beyond ; cbLogical in IT_VAR (variable) tables when compressing ; other bd's all the way back to cbLogical. This is to ; help the user's chances of edit and CONTinuing. ;------------------------------------------------------------ ;--- Interpreter Buffer Descriptor Management Routines --- ;------------------------------------------------------------ ;*** ;B$IHeapEntryMoved - handle movement of Interpreter-specific Heap entry ;Purpose: ; This routine is called by the Runtime Heap management ; code just before it moves an Interpreter-specific Heap entry. ; This routine performs any updating necessary due to ; the movement of an Interpreter-specific Heap entry ; it does not need to update entry pointer in the bd[p] for ; the entry being moved; it just dispatches based on the ; heap entry type to a routine which finds all string/heap ; owners within the heap entry being moved, and calls the heap ; management code to update the backpointers. Note that each ; such routine will be located in it's own component; these ; routines will call the runtime heap manager directly, but ; will do so via a macro to keep runtime heap interface knowledge ; confined to this module and associated header files. ;Entry: ; AX = number of bytes the heap entry has moved. ; A positive number indicates the entry has moved ; to a higher address. ; BX = pointer to the bd[p].pb field of the buffer descriptor for ; the heap entry being moved. ; CL = type constant for the heap type being moved (IT_MRS, ... etc.) ; ;Exit: ; none. ;Modifies: ; May modify BX, CX, or PSW - no others ;*************************************************************************** cProc B$IHeapEntryMoved,<PUBLIC,NEAR,NODATA>,<AX,DX,ES,SI,DI> cBegin mov si,bx cmp cl,IT_NO_OWNERS_BDP ;a bdp entry being moved? jnz Not_Bdp ;brif not add [bx.BDP_pbCur-2],ax ;adjust the pbCur field jmp short Entry_Moved_Exit ;that's all, folks Not_Bdp: mov di,ax ;communicate adjustment factor in DI mov ax,[bx-2] ;put cbLogical (table end offset) in ax mov bx,[bx] push ax ;save until Entry_Moved_Cont push bx ;save until Entry_Moved_Cont push cx ;save until Entry_Moved_Cont cmp cl,IT_COMMON_VALUE jae Update_Stack_Ptrs ;brif we have to update stack ptrs, or ;var or common table cmp cl,IT_PRS ; no bd's in prs tables jz Entry_Moved_Cont ; brif prs table cCall AdjustITable,<bx,ax,cx> ;adjust the table, whatever it is. Entry_Moved_Cont: pop cx ;restore type constant pop bx ;restore start of range pop dx FHD_TBL EQU NOT IT_M_INTERP AND (IT_MRS OR IT_PRS OR IT_COMMON_VALUE OR IT_VAR) test cl,FHD_TBL jz Entry_Moved_Exit ;brif entry can't contain far heap desc. ;prs and mrs tables contain bdl's - - - get far heap to update these add dx,bx ;dx is now end of range mov ax,di ;adjustment factor call B$FHAdjDesc Entry_Moved_Exit: cEnd Update_Stack_Ptrs: jnz Upd_Stk_Ptrs_Cont ;brif cl != IT_COMMON_VALUE call AdjustCommon ;update backpointers to any string ;descriptors or string array descriptors ;in given IT_COMMON_VALUE heap entry jmp short Entry_Moved_Cont Upd_Stk_Ptrs_Cont: DbAssertRelB cl,z,IT_VAR,RT,<B$IHeapEntryMoved: cl == IT_VAR expected> call AdjustVarTable ;update backpointers to any string ;descriptors or string array descriptors ;in given IT_VAR heap entry jmp short Entry_Moved_Cont ;*** ;BdCompress - Compress a Runtime Heap entry ;Purpose: ; Call B$LhRealloc to reduce cbPhysical to cbLogical for a Bd whose ; pb field is at a given location. ; Called via B$LHForEachEntry by BdCompressAll. ; ; Note that variable tables are handled specially - - they're trimmed ; back so that they keep up to VAR_EXTRA free space at the end of the ; table to maximize the change of CONTinuing after variables are added. ;Entry: ; BX = pointer to owner of a local heap entry - - - for interpreter ; buffers, that amounts to a pointer to the 'pb' field of the ; owning bd. ; DL = heap entry type. ;Exit: ; none. ;Preserves: ; CX,SI ;Exceptions: ; none. ; ;*************************************************************************** cProc BdCompress,<NEAR,NODATA> cBegin BdCompress DbChk Heaps ;ife RELEASE & checking enabled, check ; Local & Far Heaps for problems test dl,IT_M_INTERP ;is this an interpreter buffer? jz BdCompress_Exit dec bx ;turn bx into a real pBd (for cmp below) dec bx mov ax,[bx.BD_cbLogical] cmp dl,IT_VAR ;is this a variable table? jnz BdCompress_Cont ; brif not add ax,VAR_EXTRA ;want to have up to VAR_EXTRA bytes ; left in each var table to improve ; chances of user adding a few ; variables and still CONTinuing cmp ax,[bx.BD_cbPhysical] jae BdCompress_Exit ;brif cbPhysical <= size we want buffer ; to be - - - leave buffer alone BdCompress_Cont: lea dx,[ps.PS_bdpDst.BDP_cbLogical] cmp bx,dx ;brif not special parser buffer that jnz BdCompress_Cont1 ; must always have a minimal amount cmp ax,CB_PCODE_MIN ;never trim below this minimum ja BdCompress_Cont1 ;brif cbLogical > Minimum required DbAssertRel [bx.BD_cbPhysical],ae,CB_PCODE_MIN,RT,<BdCompress:Parser buffer is too small> mov ax,CB_PCODE_MIN BdCompress_Cont1: push cx ;preserve for caller push si ;preserve for caller mov [bx.BD_cbPhysical],ax ;set new desired cbPhysical mov si,[bx.BD_pb] ;pointer to start of data in buffer call B$LHREALC ;reduce entry to cbLogical size ; MUST succeed and CANNOT cause ; heap movement, because it is either ; reducing entry size or doing nothing pop si pop cx BdCompress_Exit: cEnd BdCompress ;*** ;BdCompressHeap - Compress all Runtime Heap entries in currently active heap ;Purpose: ; Same as BdCompressAll (below), but only crunches bd's in the currently ; active heap (either the local heap or the variable heap). ;Input: ; none. ;Output: ; none. ;Modifies: ; no permanent registers. ;Exceptions: ; Chance of string space corrupt. ;*************************************************************************** cProc BdCompressHeap,<NEAR,NODATA> cBegin mov cx,RTOFFSET BdCompress call B$LHForEachEntry ;compress all bd's down to cbLogical ; (effect is to create free blocks ; out of extraneous space in bd's) cmp [b$fVarHeapActive],FALSE jnz BdCompressHeap_Exit ;don't compact the variable heap ; only runtime init. does that - - ; B$NHCPCT assumes local heap active. call B$NHCPCT ;compact Local Heap and String Space BdCompressHeap_Exit: DbChk Heaps cEnd ;*** ;BdCompressAll - Compress all Runtime Heap entries ;Purpose: ; To increase the speed of BdGrow, we keep a little free ; space at the end of each heap entry. When the program ; begins execution, this routine is called to ; release all this space and compact interpreter-specific entries ; to the top of the Runtime Heap. ; Note that this routine is ONLY called by interpreter code, ; and never by the shared-runtime code. ; ; NOTE: after this operation is complete, the 'pbCurrent' field in ; bdp's will still be correct and useable, assuming that ; such pointers weren't pointing beyond cbLogical ... ;Input: ; none. ;Output: ; none. ;Modifies: ; no permanent registers. ;Exceptions: ; Chance of string space corrupt. ; ;*************************************************************************** cProc BdCompressAll,<PUBLIC,FAR,NODATA> cBegin call BdCompressHeap ;compress the active heap call B$TglHeapSpt ;activate the other heap call BdCompressHeap ;compress the active heap call B$TglHeapSpt ;reactivate the originally active heap cEnd ;*** ;BdAdjust(pBd) ; This routine takes a pointer to a bd as a parameter and assumes ; that an adjustment factor (the bd is being moved) is in DI. ; It calls a heap manager routine which updates the entry backpointer, ; if the bd is an owner (i.e., if the pb field is not NULL). ;Entry: ; pBd - pointer to a bd that's being moved ; DI contains adjustment factor it's being moved by ;Exit: ; none. ;Modifies: ; none. (no permanent registers) ;Exceptions: ; if anything wrong with heap entry for this bd, can end up calling ; the non-trapable "String Space Corrupt" error. ;*************************************************************************** cProc BdAdjust,<PUBLIC,FAR,NODATA> parmW pBd cBegin BdAdjust mov bx,[pBd] mov ax,[bx.BD_pb] cmp ax,NULL jz BdAdjust_Done call B$ILHADJ ;get heap manager to do adjustment BdAdjust_Done: cEnd BdAdjust page ;*** ;BdAllocVar - Allocate a Runtime Heap entry in the variable heap ;Purpose: ; Allocate an Interpreter-specific Heap entry from the variable heap. ; Uses the same interface and BdAlloc (see below). ;Entry, Exit, Modifies: ; Same as BdAlloc (see below). ;Note: Shares and exits via BdAlloc, below ;*************************************************************************** cProc BdAllocVar,<PUBLIC,FAR,NODATA> cBegin <nogen> DbAssertRel grs.GRS_otxCONT,z,UNDEFINED,RT,<BdAllocVar: CAN continue> call B$TglHeapSpt ;make variable heap the active one cEnd <nogen> ;fall into BdAlloc, below ;*** ;BdAlloc - Allocate a Runtime Heap entry ;Purpose: ; Allocate an Interpreter-specific Heap entry from the Runtime ; Heap. ; Note that this routine should ask for only the amount of space asked ; for; growing a buffer will increase requests to some minimal block size, ; but many buffers need to be initially allocated to some minimal ; (possibly zero) size. ; NOTE: current heap manager interface demands that the owner-to-be ; should not be subject to heap movement (i.e., not in heap, or ; heap locked). ;Entry: ; parm: bd *pbdOwner - points to owner-to-be of new heap entry ; parm: ushort cbSize - number of bytes needed ;if NOT FV_LMEM ; parm: char interpType - type of interp. table (IT_VALUE etc) ;endif ;Exit: ; if entry was successfully allocated: ; pbdOwner->cbLogical = cbSize ;if FV_LMEM ; pbdOwner->ppb = ptr to ptr to new heap entry (and is now owner) ;else ; pbdOwner->pb = pointer to new heap entry (and is now a heap owner) ; pbdOwner->cbPhysical = cbSize ;endif ; [AX] = TRUE (non-zero) ; else ; [AX] = FALSE (0) (Out of memory) ;Modifies: ; none (NOTE: DOES modify ES) ; ;*************************************************************************** cProc BdAlloc,<PUBLIC,FAR,NODATA>,<SI> parmW pbdOwner parmW cbSize parmB interpType cBegin DbShiftLH ;ife RELEASE cause some heap movement DbChk Heaps mov dl,[interpType] mov cx,[cbSize] mov bx,[pbdOwner] DbChk BdNotOwner,bx ;ensure that given bd isn't an owner now mov [bx.BD_pb],NULL ;in case allocation fails and caller ; blindly calls BdFree with this bd DbOMCnt BD_END xchg bx,cx ;input order required by B$ILHALC inc cx ;'owner' to heap manager is the actual inc cx ; pointer to the heap entry, not a pbd call B$ILHALC ;call heap manager to allocate memory jc BD_Crunch_BDs ;brif OM return; trim bd's, try again BdAlloc_Success: mov bx,[pbdOwner] ;assumes bdOwner not moved by allocation mov [bx.BD_pb],si ;SI is data ptr returned from B$ILHALC mov ax,[cbSize] ;save requested size as both logical mov [bx.BD_cbLogical],ax ; and physical size, and return it as mov [bx.BD_cbPhysical],ax ; our non-zero (i.e., 'TRUE') result mov al,TRUE ;in case input size was zero BD_END: cmp [b$fVarHeapActive],FALSE jz BdAlloc_Exit ;brif variable heap not active call B$TglHeapSpt ;reactivate the local heap BdAlloc_Exit: cEnd BD_Crunch_BDs: push dx push cx call far ptr BdCompressAll ;trim bd's, compress heap space pop cx pop dx call B$ILHALC ;try allocation again jnc BdAlloc_Success ; brif it worked this time xor ax,ax ;OM error return jmp short BD_END ;*** ;BdFree(pbdOwner) - Release a Heap entry ;Purpose: ; Release a Runtime Heap entry. If pbdOwner.BD_pb is NULL, ; just return (as input wasn't really an owner). ;Entry: ; parm: bd *pbdOwner - points to owner of new heap entry ; ;*************************************************************************** cProc BdFree,<PUBLIC,FAR,NODATA>,<SI> parmW pbdOwner cBegin mov bx,[pbdOwner] mov si,[bx.BD_pb] cmp si,NULL jz BdFree_Exit ;brif bd isn't an owner mov [bx.BD_pb],NULL call B$LHDALC BdFree_Exit: cEnd ;*** ;BdChgContents(pbd, psdNew) - Change contents of a buffer ;Purpose: ; Change the contents of a given buffer. Note that the buffer may or ; may not be an owner already; if it is an owner, it will be Free'd. ; The buffer will then be allocated, and the input sd contents copied in. ; ; NOTE: psdNew must not point into a heap entry! ;Entry: ; parm: bd *pbd - points to current owner of heap entry ; parm: bd *psdNew - points to sd, contents of which are to be put ; in the input bd. ;Exit: ; if operation successful ; [AX] = TRUE (non-zero) ; else ; [AX] = FALSE (0) (Out of memory), and the original contents ; of the bd are lost. ;*************************************************************************** cProc BdChgContents,<PUBLIC,FAR,NODATA>,<SI,DI> parmW pbd parmW psdNew cBegin mov si,[pbd] cCall BdFree,<si> ;free original contents if any mov di,[psdNew] DbChk PtrNotInHeap,di mov cx,[di.SD_cb] push cx ;save across call push si push cx PUSHI dx,IT_NO_OWNERS call BdAlloc ;alloc to size of desired contents pop cx or ax,ax jz BdChgContents_Exit ;brif OM error on allocation mov ax,[si.BD_pb] mov bx,[di.SD_pb] cCall CopyBlk,<bx,ax,cx> ;copy sd contents into bd BdChgContents_Exit: cEnd ;*** ;BdChgOwner(pbdOwner, pbdNew) - Change the owner of a Heap entry ;BdChgOwner_NoCopy(pbdOwner, pbdNew) - Change the owner of a Heap entry ;Purpose: ; Change the owner of an Interpreter-specific Heap entry. If ; pbdOwner.BD_pb is NULL, just return (as it wasn't really an owner to ; begin with). ; BdChgOwner copies the bd contents to the new bd. ; BdChgOwner_NoCopy is provided as a speed improvement, and should be ; called in cases where the bd has already been copied BEFORE ; this routine is called. ; ; NOTE: This routine is guaranteed not to cause heap movement to occur. ; ; NOTE: This routine must be called AFTER a block containing the bd is ; moved if such movement is to take place, because this routine ; changes the contents of bdOwner to indicate that it's no longer ; an owner. ;Entry: ; parm: bd *pbdOwner - points to current owner of heap entry ; parm: bd *pbdNew - points to new owner of heap entry ; ;*************************************************************************** PUBLIC BdChgOwner BdChgOwner: mov cx,SIZE BD ;non-zero - - - do the copy SKIP2_PSW ;skip to start of common code PUBLIC BdChgOwner_NoCopy BdChgOwner_NoCopy: xor cx,cx cProc Chg_The_Owner,<FAR,NODATA>,<SI> parmW pbdOwner parmW pbdNew cBegin mov si,[pbdOwner] cmp [si.BD_pb],NULL jz BdChg_Exit DbChk BdOwner,si ;ensure that given bd is an owner jcxz BdChg_CopyDone ;brif caller already did this copy push si push pbdNew push cx ;set to SIZE BD for BdChgOwner call CopyBlk BdChg_CopyDone: mov cx,[pbdNew] inc cx ;to heap manager, 'owner' is the actual inc cx ; pointer to heap data, not a pbd push si ;si is an input to B$LHChgBakPtr mov si,[si.BD_pb] call B$LHChgBakPtr pop si ;so we can set bd.pb to NULL mov [si.BD_pb],NULL ;mark that this is no longer an owner BdChg_Exit: cEnd ;*** ;EnsPhysicalSize - ensure physical size of near heap >= ax ;Purpose: ; Change physical size of an Interpreter-specific Heap entry if necessary. ; This is used by BdGrow and BdCheckFree. ; Note that this is not an external entry point, only for use ; within this module, and can thus use register calling conventions. ; ; NOTE: current heap manager interface demands that the owner ; should not be subject to heap movement. ;Entry: ; [di] - points to owner of heap entry ; [ax] = new total size requested for the buffer (i.e., new minimum ; cbPhysical desired). ;Exit: ; if enough memory is available: ; [ax] = TRUE (non-zero) ; [bx] = new value for cbLogical (i.e., [ax] exit = entry) ; otherwise, ; [ax] = 0 ; ;*************************************************************************** EnsPhysicalSize PROC NEAR DbChk BdOwner,di ;ensure that given bd is an owner DbChk Heaps push ax ;save input requested size DbOMCnt Ens_End2 cmp ax,[di.BD_cbPhysical] jbe NoChange ;branch if already big enough push si ;save caller's si push ax ;in case initial try fails sub ax,[di.BD_cbPhysical] ;ax=amount to grow cmp ax,CBBUFBLOCK jae Big_Enough ;branch if growing by significant amount mov ax,CBBUFBLOCK ;never grow by less than this amount Big_Enough: add ax,[di.BD_cbPhysical] ;ax=(hopefully) new cbPhysical push ax ;save (hopefully) new cbPhysical mov si,[di.BD_pb] call B$LHREALC ;call heap manager to realloc pop bx ;size we realloced to or ax,ax ;test result jz Ens_Crunch_BDs ;brif realloc failed pop cx ;clean stack Ens_Phy_Success: mov [di.BD_cbPhysical],bx mov [di.BD_pb],si ;in case realloc moved the entry Ens_End1: pop si ;restore caller's si Ens_End2: pop bx ;restore input size for retval ret NoChange: mov al,TRUE ;ensure TRUE return, even if passed ax=0 jmp short Ens_End2 EnsPhysicalSize ENDP Ens_Crunch_BDs: call far ptr BdCompressAll ;trim all bd's, compress heaps pop ax ;input to B$LHREALC push ax ;save for return mov si,[di.BD_pb] ;may be trashed on error return call B$LHREALC pop bx ;cb we tried to realloc to or ax,ax ;did we succeed this time? jz Ens_End1 ; brif not jmp short Ens_Phy_Success ;succeeded this time - - go wrap up ;*** ;BdGrowVar - Grow a Runtime Heap entry in the variable heap ;Purpose: ; Same as BdGrow (below), but for an entry in the variable heap. ; Uses the same interface and BdGrow (see below). ;Entry, Exit, Modifies: ; Same as BdGrow (see below). ;Note: Shares and exits via BdGrow, below ;*************************************************************************** cProc BdGrowVar,<PUBLIC,FAR,NODATA> cBegin <nogen> DbAssertRel grs.GRS_otxCONT,z,UNDEFINED,RT,<BdlGrowVar: CAN continue> call B$TglHeapSpt ;make variable heap the active one cEnd <nogen> ;fall into BdGrow, below ;*** ;BdGrow - Increase the logical size of a Heap entry ;Purpose: ; Change logical size of an Interpreter-specific Heap entry. This can ; result in the movement of this and other heap entries as well ; as strings. ; When this routine actually needs to grow the physical size ; of the heap, it grows more than needed for this request, to ; reduce heap thrashing. ; ; NOTE: current heap manager interface demands that the owner ; should not be subject to heap movement. ;Entry: ; parm: bd *pbdOwner - points to owner of heap entry ; parm: ushort cbGrow - number of bytes needed ;Exit: ; if enough memory is available: ; pbdOwner->cbLogical += cbGrow, ; pbdOwner->cbPhysical >= pbdOwner->cbLogical ; [AX] = TRUE (non-zero) ; else ; [AX] = FALSE (0) (Out of memory) ; ;*************************************************************************** cProc BdGrow,<PUBLIC,FAR,NODATA>,<di> parmW pbdOwner parmW cbGrow cBegin mov di,[pbdOwner] ;di points to bd descriptor mov ax,[cbGrow] ;[AX] == increase desired add ax,[di.BD_cbLogical] ;[AX] == new logical size jc GrowOmErr ;branch if overflow (can't grow > 64k) ;***************************** ;NOTE: BdRealloc jumps in here ;***************************** BdRealloc1: call EnsPhysicalSize ;change physical size (inputs ax & di) or ax,ax ;test boolean result jz BdGrow_End ;brif out-of-memory case mov [di.BD_cbLogical],bx ;new cbLogical - successful return BdGrow_End: cmp [b$fVarHeapActive],FALSE jz BdGrow_Exit ;brif variable heap not active call B$TglHeapSpt ;reactivate the local heap BdGrow_Exit: cEnd GrowOmErr: xor ax,ax jmp short BdGrow_End ;*** ;BdRealloc - Change the logical size of a Heap entry ;Purpose: ; Change logical size of an Interpreter-specific Heap entry. This can ; result in the movement of this and other heap entries as well ; as strings. ; When this routine actually needs to grow the physical size ; of the heap, it grows more than needed for this request, to ; reduce heap thrashing. ; ; NOTE: current heap manager interface demands that the owner ; should not be subject to heap movement. ;Entry: ; parm: bd *pbdOwner - points to owner of heap entry ; parm: ushort cbLogicalNew - new size of heap entry ;Exit: ; if enough memory is available: ; pbdOwner->cbLogical = cbLogicalNew, ; pbdOwner->cbPhysical >= pbdOwner->cbLogical ; [AX] = TRUE (non-zero) ; else ; pbdOwner->cbLogical is unchanged ; [AX] = FALSE (0) (Out of memory) ; ;*************************************************************************** cProc BdRealloc,<PUBLIC,FAR,NODATA>,<di> parmW pbdOwner parmW cbNew cBegin mov di,[pbdOwner] ;di points to bd descriptor mov ax,[cbNew] ;[AX] == increase desired jmp SHORT BdRealloc1 cEnd <nogen> ;*** ;BdCheckFree - Make sure buffer has some free space ;Purpose: ; This is identical to BdGrow, but it does not alter the ; descriptor's cbLogical field. Some typical cases when it is ; called include: ; 1- Before calling BdAppend to copy from one bd to another. ; By calling this first, we know BdAppend won't have to ; grow the heap entry, causing movement, which could invalidate ; BdAppend's pb argument. ; 2- When the caller is about to do an operation which will ; append information to a bd, but the caller doesn't know ; exactly how many bytes will be added, but an upper limit is known. ; ; NOTE: current heap manager interface demands that the owner ; should not be subject to heap movement. ;Entry: ; parm: bd *pbdOwner - points to owner of heap entry ; parm: ushort cbFree - number of free bytes needed ;Exit: ; pbdOwner->cbLogical is ALWAYS UNCHANGED ; If enough memory is available: ; pbdOwner->cbPhysical >= pbdOwner->cbLogical + cbFree ; [AX] = TRUE (non-zero) ; else ; [AX] = FALSE (0) (Out of memory) ; ;*************************************************************************** cProc BdCheckFree,<PUBLIC,FAR,NODATA>,<DI> parmW pbdOwner parmW cbFree cBegin mov di,[pbdOwner] ;di points to bd descriptor mov ax,[cbFree] ;[AX] == increase desired add ax,[di.BD_cbLogical] ;[AX] == resulting size jc CheckOmErr ;branch if overflow (can't grow > 64k) call EnsPhysicalSize ;change physical size (inputs ax & di) BdCheck_End: cEnd CheckOmErr: xor ax,ax jmp short BdCheck_End ;*** ; boolean BdShiftRight(pbd, obStart, cb) ; ; Purpose: ; Grow the buffer descriptor, and shift its contents right ; (copying content to higher addresses) starting at offset ; obStart until the end of the buffer. ; ; NOTE: current heap manager interface demands that the owner ; should not be subject to heap movement. ; ; Entry: ; parmW pbd points to the buffer descriptor ; parmW obStart = byte offset for 1st byte to be shifted right ; parmW cb = number of bytes each byte is to be shifted ; ; Exit: ; If not enough memory can be obtained, ; [AX] = FALSE ; else ; pbdDst->cbLogical is updated ; [AX] = TRUE ; ; Before BdShiftRight(pbd, 2, 2): ; high memory ; pbd->cbLogical------->+-----+ ; | E | ; | D | ; | C | ; | B | ; | A | ; low memory +-----+ ; ; After: ; high memory ; pbd->cbLogical------->+-----+ ; | E | ; | D | ; | C | ; | D | ; | C | ; | B | ; | A | ; low memory +-----+ ; ;*************************************************************************** cProc BdShiftRight,<PUBLIC,FAR,NODATA>,<SI,DI> parmW pbd parmW obStart parmW cb cBegin push pbd push cb call BdCheckFree ;1st grow the buffer or ax,ax je BdShiftExit ;branch if out-of-memory, return 0 mov bx,pbd ;bx -> descriptor mov cx,[bx.BD_cbLogical] ;[CX] = current size of buffer mov si,[bx.BD_pb] ;si points to start of buffer add si,cx ;si points beyond end of current content dec si ;si points to 1st byte to copy mov di,si mov ax,cb add di,ax ;di points to dst for 1st byte to copy add [bx.BD_cbLogical],ax ;update size of buffer sub cx,obStart ;[CX] = number of bytes to copy jcxz Copy0Bytes push ds pop es ;es=ds std ;copy from high to low address rep movsb ;do the block copy cld Copy0Bytes: mov ax,TRUE BdShiftExit: cEnd ;*** ; boolean BdShiftLeft(pbd, obStart, cb) ; ; Purpose: ; Shrink the buffer descriptor, and shift its contents left ; (copying content to lower addresses) starting at offset ; obStart until the end of the buffer. ; ; Entry: ; parmW pbd points to the buffer descriptor ; parmW obStart = byte offset for 1st byte to be deleted ; parmW cb = number of bytes to be deleted ; ; Exit: ; pbdDst->cbLogical is updated ; no return value ; ; Before BdShiftLeft(pbd, 2, 2): ; high memory ; pbd->cbLogical------->+-----+ ; | E | ; | D | ; | C | ; | B | ; | A | ; low memory +-----+ ; ; After: ; high memory ; pbd->cbLogical------->+-----+ ; | E | ; | B | ; | A | ; low memory +-----+ ; ;*************************************************************************** cProc BdShiftLeft,<PUBLIC,FAR,NODATA>,<SI,DI> parmW pbd parmW obStart parmW cb cBegin mov bx,pbd ;bx -> descriptor mov di,[bx.BD_pb] ;di points to start of buffer add di,obStart ;di points to 1st byte to delete mov si,di add si,cb ;si points beyond last byte to delete mov cx,[bx.BD_cbLogical] ;[CX] = current size of buffer sub cx,cb ;cx = new size of buffer mov [bx.BD_cbLogical],cx ;update descriptor sub cx,obStart ;cx = # bytes to copy jcxz LeftExit ;brif 0 bytes to copy push ds pop es ;es=ds rep movsb ;do the block copy LeftExit: cEnd ;*** ; boolean BdAppend(pbdDst, pbSrc, cb) ; ; Purpose: ; Append a string of bytes to a Buffer Descriptor. ; If this is preceeded by a call to BdCheckFree(pbdDst, cb) ; then pbSrc can point within another heap entry with no ; fear of movement before the copy is complete. Otherwise, ; pbSrc had better not point within a heap entry. ; ; NOTE: current heap manager interface demands that the owner ; should not be subject to heap movement. ; ; Entry: ; parmW pbdDst points to the destination buffer descriptor ; parmW pbSrc points to 1st byte to be copied into buffer ; parmW cb = number of bytes to be copied ; ; Exit: ; If not enough memory can be obtained, ; [AX] = FALSE ; else ; pbdDst->cbLogical is updated ; [AX] = TRUE ; ;*************************************************************************** cProc BdAppend,<PUBLIC,FAR,NODATA>,<SI,DI> parmW pbdDst parmW pbSrc parmW cb localW pbDst localW cbTemp cBegin push pbdDst push cb call BdCheckFree or ax,ax je BdAppendExit ;branch if out-of-memory, return 0 mov cx,cb ;[CX] = # bytes to copy mov di,pbdDst ;di -> destination descriptor mov ax,[di.BD_cbLogical] ;ax = current size of buffer add [di.BD_cbLogical],cx ;update size of buffer mov di,[di.BD_pb] ;di points to start of dest buffer add di,ax ;add new bytes at end of buffer mov si,pbSrc ;si = source byte ptr push ds pop es ;es=ds rep movsb ;do the block copy mov ax,TRUE BdAppendExit: cEnd ;----------------------------------------------------------------- ;--- Large Far Heap Buffer Descriptor Management Routines --- ;----------------------------------------------------------------- FAR_EXTRA = 512 ;never grow a far heap entry by less than 512 bytes ;*** ;AllocBdl - Allocate a Far Heap entry (workhorse for BdlAlloc) ;AllocBdl_Sb - same, but allocates a given sb for this ;Purpose: ; Allocate a Heap entry from the Far Heap. This can cause ; movement of Runtime and String heap entries. ; Note that this routine should ask for only the amount of space asked ; for; growing a buffer will increase requests to some minimal block size, ; but many buffers need to be initially allocated to some minimal ; (possibly zero) size. ;Entry: ; di = pbdlOwner - points to owner of new heap entry ; si = cbSize - number of bytes needed ; For EB versions, bx = type constant for type of bdl buffer ; For AllocBdl_Sb, cx = sb to use ;Exit: ; if entry was successfully allocated: ; pbdlOwner->cbLogical = cbSize ; pbdlOwner->cbPhysical = cbSize ; [AX] = TRUE (non-zero) ; pbdlOwner->status != NOT_OWNER ; else ; [AX] = FALSE (0) (Out of memory) ; PSW.Z is set on exit based on an 'OR AX,AX' instruction ; ;*************************************************************************** cProc AllocBdl,<NEAR,NODATA> cBegin <nogen> mov cx,0 ; use any sb that's free cEnd <nogen> cProc AllocBdl_Sb,<NEAR,NODATA> cBegin mov ax,si DbAssertRel ax,be,0FFF0H,RT,<BdlAlloc: caller asked for more than FFF0H> ;The above assertion is based on the problem where a request to ; B$IFHAlloc for greater than 0FFF0H bytes will be rounded UP to past ; 64k, with no error reported. xor dx,dx ;DX:AX is input size to B$IFHAlloc mov bx,di DbChk BdlNotOwner,di mov [bx.BDL_cbLogical],ax call B$IFHAlloc ;allocate a far heap entry (0 if can't) or ax,ax ;set zero flag for caller cEnd AllocBdl ;*** ;BdlAlloc - Allocate a Far Heap entry ;Purpose: ; Allocate a Heap entry from the Far Heap. This can cause ; movement of Runtime and String heap entries. ; Note that this routine should ask for only the amount of space asked ; for; growing a buffer will increase requests to some minimal block size, ; but many buffers need to be initially allocated to some minimal ; (possibly zero) size. ; ; [5] Note that at least some callers depend on the new block being zero- ; [5] filled (EB varmgr code, for one). ;Entry: ; parm: bdl *pbdlOwner - points to owner of new heap entry ; parm: ushort cbSize - number of bytes needed ;Exit: ; if entry was successfully allocated: ; pbdlOwner->cbLogical = cbSize ; pbdlOwner->cbPhysical = cbSize ; [AX] = TRUE (non-zero) ; pbdlOwner->status != NOT_OWNER ; else ; [AX] = FALSE (0) (Out of memory) ; ;*************************************************************************** cProc BdlAlloc,<PUBLIC,FAR,NODATA>,<si,di> parmW pbdlOwner parmW cbSize cBegin DbOMCnt BdlAlloc_Exit mov di,[pbdlOwner] mov si,[cbSize] cCall AllocBdl jnz BdlAlloc_Exit ;brif success call far ptr BdCompressAll ;trim bd's, compress heap space cCall AllocBdl BdlAlloc_Exit: cEnd ;*** ;BdlAllocSb - Allocate a Far Heap entry, given a desired sb ;Purpose: ; Same as BdlAlloc, but accepts as a third parm the sb value that ; is to be used. ; Added as revision [13]. ;Entry: ; parm: bdl *pbdlOwner - points to owner of new heap entry ; parm: ushort cbSize - number of bytes needed ; parm: ushort sbInput - sb we must use for this allocation ; (caller guarantees this is unallocated). ;Exit: ; if entry was successfully allocated: ; pbdlOwner->cbLogical = cbSize ; pbdlOwner->cbPhysical = cbSize ; [AX] = TRUE (non-zero) ; pbdlOwner->status != NOT_OWNER ; else ; [AX] = FALSE (0) (Out of memory) ; ;*************************************************************************** cProc BdlAllocSb,<PUBLIC,FAR,NODATA>,<si,di> parmW pbdlOwner parmW cbSize parmW sbInput cBegin DbOMCnt BdlAllocSb_Exit mov di,[pbdlOwner] mov si,[cbSize] mov cx,[sbInput] cCall AllocBdl_Sb BdlAllocSb_Exit: cEnd ;*** ;BdlFree - Release a far Heap entry ;Purpose: ; Release a far Heap entry. If bdl is not an owner, this routine just ; returns, with no error. ;Entry: ; parm: bdl *pbdlOwner - points to owner of new heap entry ;Exit: ; bdl is released; pbdlOwner->status = NOT_OWNER ; ;*************************************************************************** cProc BdlFree,<PUBLIC,FAR,NODATA> parmW pbdlOwner cBegin mov bx,[pbdlOwner] cmp [bx.BDL_status],NOT_OWNER jz BdlFree_Exit ;brif bdl already free DbChk BdlOwner,bx ;ensure that given bdl is an owner push bx call B$FHDealloc ;free an allocated far heap entry pop bx mov [bx.BDL_status],NOT_OWNER ;indicate that bdl is not an owner BdlFree_Exit: cEnd ;*** ;BdlChgOwner(pbdlOwner, pbdlNew) - Change the owner of a Far Heap entry ;Purpose: ; Change the owner of a Far Heap entry. If pbdlOwner.BDL_status is ; NOT_OWNER, just return (as it wasn't really an owner to begin with). ; ; NOTE: This routine is guaranteed not to cause heap movement to occur. ; ; NOTE: This routine must be called AFTER a block containing the bdl is ; copied, as the far heap manager modifies the FHD according to ; its original location. This copy MUST be done by the caller ; prior to this routine being called. ; Note also that it is NOT safe to block copy a range containing ; multiple bdl's and then call this routine once per bdl - - - ; Since the far heap code chains all bdl's together, a call to ; BdlChgOwner can cause another bdl to be modified (in the ; 'status' a.k.a. 'pNext' field). ;Entry: ; parm: bdl *pbdlOwner - points to current owner of far heap entry ; parm: bdl *pbdlNew - points to new owner of far heap entry ;Exit: ; none. ; ;*************************************************************************** cProc BdlChgOwner,<PUBLIC,FAR,NODATA>,<SI> parmW pbdlOwner parmW pbdlNew cBegin mov si,[pbdlOwner] cmp [si.BDL_status],NOT_OWNER jz BdlChg_Exit ;brif bdl wasn't an owner DbChk BdlOwner,si ;ensure that bdlOwner is an owner mov dx,si ;pFHD for FHD that's being moved mov cx,[pbdlNew] sub cx,si ;cx = pNew - pOld (adjustment factor) call B$FHAdjOneDesc mov [si.BDL_status],NOT_OWNER BdlChg_Exit: cEnd ;*** ;BdlRealloc - reallocate a Far Heap entry ;Purpose: ; reallocate a Heap entry from the Far Heap. This can cause ; movement of String and Runtime heap entries. ; ; [5] Note that at least some callers depend on additional space being ; [5] zero-filled (EB varmgr code, for one). ;Entry: ; parm: bdl *pbdlOwner - points to owner of heap entry ; parm: ushort cbNew - new buffer size desired ;Exit: ; if entry was successfully reallocated: ; pbdlOwner->cbLogical = cbNew ; pbdlOwner->cbPhysical >= cbNew ; [AX] = TRUE (non-zero) ; else ; [AX] = FALSE (0) (Out of memory) ; ;*************************************************************************** cProc BdlRealloc,<PUBLIC,FAR,NODATA>,<di> parmW pbdlOwner parmW cbNew localB fTryAgain cBegin mov [fTryAgain],TRUE DbOMCnt BdlRealloc_Exit mov di,[pbdlOwner] mov bx,[di.BDL_cPhysical] SHIFT H,L,bx,4 ;shift left to convert cPara to cbytes mov ax,[cbNew] cmp bx,ax jae Change_cbLogical ;brif physical size is big enough cmp ax,0FFE0H ;if ask far heap for > FFE0H, it will ; round request up to para boundary ... jbe BdlRealloc_Cont ;brif request not too large xor ax,ax ;Out of Memory return jmp short BdlRealloc_Exit BdlRealloc_Crunch: cmp [fTryAgain],FALSE jz BdlRealloc_Exit ;brif we've already tried this - give up mov [fTryAgain],FALSE ;remember this is the 2nd attempt call far ptr BdCompressAll ;trim all bd's, compress heaps, mov ax,[cbNew] ;and try again w/o blocking factor jmp short BdlRealloc_Cont1 BdlRealloc_Cont: add ax,FAR_EXTRA ;ax = ax + FAR_EXTRA to reduce thrashing ;Under DOS 3, we know the heap manager actually allocates in 16-byte ; (paragraph) quantities, so to ensure we don't waste an average of ; 8 bytes per bdl, pay a few bytes of code here to round up jc RealcForMax ;brif this puts us over 64k BdlRealloc_Cont1: add ax,000FH ;constant for rounding up to paragraph jnc TryToRealloc ;brif still under 64k RealcForMax: mov ax,0FFE0H ; try for maximum - - - note that ;'maximum' can't be FFFFH, because ;the far heap code will round this ;up to the nearest paragraph boundary TryToRealloc: and al,0F0H ;[9] finish rounding size up to para mov dx,0FFE0H cmp ax,dx ; is result > legal max? jbe ReallocAttempt ; brif not xchg ax,dx ReallocAttempt: DbChk BdlOwner,di ;ensure that bdlOwner is an owner xor dx,dx mov bx,di call B$FHRealloc or ax,ax jz BdlRealloc_Crunch ;brif insufficient memory mov ax,[cbNew] ;requested size Change_cbLogical: mov [di.BDL_cbLogical],ax ;save new logical size mov ax,sp ;signal success (cbNew could be zero ..) BdlRealloc_Exit: cEnd ;*** ;BdlCheckFree - Make sure far heap entry has some free space ;Purpose: ; Change size of a far Heap entry if necessary to ; ensure that there is a certain number of free bytes at the ; end of the entry. This can result in the movement of this ; and other heap entries. ; This routine does not work with HUGE heap entries (i.e. > 64k) ;Entry: ; parm: bdl *pbdlOwner - points to owner of heap entry ; parm: ushort cbFree - number of free bytes needed ;Exit: ; If enough memory is available: ; pbdlOwner->cbLogical is unchanged ; pbdlOwner->cbPhysical >= pbdlOwner->cbLogical + cbFree ; [AX] = TRUE (non-zero) (successful return) ; else ; [AX] = FALSE (0) (Out of memory) ; ;*************************************************************************** cProc BdlCheckFree,<PUBLIC,FAR,NODATA>,<di> parmW pbdlOwner parmW cbFree cBegin DbOMCnt BdlCheckFreeExit mov di,[pbdlOwner] mov ax,[di.BDL_cPhysical] ;ax = current physical size SHIFT H,L,ax,4 ;shift left to convert cPara to cbytes push ax sub ax,[di.BDL_cbLogical] ;ax = current free size sub ax,cbFree ;ax = new free size jnc SizeIsOk ;brif we're already big enough neg ax pop bx add ax,bx ;ax = minimum new free size jc BdlCheckDenied ;error if attempting to grow > 64k push [di.BDL_cbLogical] ;save this across call to BdlRealloc cCall BdlRealloc,<di,ax> pop [di.BDL_cbLogical] BdlCheckFreeExit: cEnd BdlCheckDenied: xor ax,ax ;return ERROR result (zero) SKIP1_PSW ;this 'eats' the next instruction SizeIsOk: pop ax ;cPhysical known to be non-zero jmp short BdlCheckFreeExit ;*** ;BdlGrow - Increase the logical size of a Heap entry ;Purpose: ; Change logical size of a bdl. This can result in the movement of this ; and other heap entries. ; When this routine actually needs to grow the physical size ; of the bdl, it grows more than needed for this request, to ; reduce heap thrashing. ; ; Added as part of revision [9]. ;Entry: ; parm: bd *pbdlOwner ; parm: ushort cbGrow - number of additional bytes needed ;Exit: ; if enough memory is available: ; pbdlOwner->cbLogical += cbGrow, ; pbdlOwner->cPhysical increased to account for >= cbLogical bytes ; [AX] = TRUE (non-zero) ; else ; [AX] = FALSE (0) (Out of memory) ; ;*************************************************************************** cProc BdlGrow,<PUBLIC,FAR> parmW pbdlOwner parmW cbGrow cBegin mov bx,[pbdlOwner] mov ax,[cbGrow] add ax,[bx.BDL_cbLogical] cCall BdlRealloc,<bx,ax> cEnd ;*** ;BdlCopyFrom - Copy data from a far Heap entry to DS ;Purpose: ; Copy data from a far Heap entry to DS ; Does not work with HUGE heap entries (i.e. > 64k) ;Entry: ; parm: bdl *pbdlOwner - points to owner of new heap entry ; parm: ushort oSrc - 16 bit offset into bdl to source ; parm: char *pbDst - points to 1st byte of destination ; parm: ushort cb - number of bytes to copy ; ;*************************************************************************** cProc BdlCopyFrom,<PUBLIC,FAR,NODATA>,<si,di> parmW pbdlOwner parmW oSrc parmW pbDst parmW cb cBegin mov si,[oSrc] ;si = source offset mov di,[pbDst] ;di = destination offset mov bx,[pbdlOwner] DbChk BdlOwner,bx ;ensure that bdlOwner is an owner GETSEG ax,[bx.BDL_seg],,<SIZE,LOAD> ;[4] seg of far heap entry mov bx,ds ;bx -> DGROUP mov ds,ax ;set up source seg (heap entry) mov es,bx ;set up destination seg (DGROUP) CopyCommon: mov cx,cb ;cx = byte count shr cx,1 ;convert to word count rep movsw ;transfer from ds:si to es:di jnc CopyFrom_Even ;no carry if count was even movsb ;move the last (odd) byte CopyFrom_Even: mov ds,bx ;restore ds->DGROUP cEnd ;*** ;BdlCopyTo - Copy data from DS into a far Heap entry ;Purpose: ; Copy data from DS into a far Heap entry ; Does not work with HUGE heap entries (i.e. > 64k) ;Entry: ; parm: bdl *pbdlOwner - points to owner of new heap entry ; parm: ushort oDst - 16 bit offset into bdl to destination ; parm: char *pbSrc - points to 1st byte of source ; parm: ushort cb - number of bytes to copy ; ;*************************************************************************** cProc BdlCopyTo,<PUBLIC,FAR,NODATA>,<si,di> parmW pbdlOwner parmW oDst parmW pbSrc parmW cb cBegin mov si,[pbSrc] ;si = source offset mov di,[oDst] ;di = destination offset mov bx,[pbdlOwner] DbChk BdlOwner,bx ;ensure that bdlOwner is an owner GETSEG ax,[bx.BDL_seg],,<SIZE,LOAD> ;[4] seg of far heap entry mov es,ax ;set up destination seg mov bx,ds jmp short CopyCommon cEnd nogen ;*** ;BdlCopyFromTo - Copy data from one bdl to another ;Purpose: ; Copy data from one far heap entry into another. ; Does not work with HUGE heap entries (i.e. > 64k) ; ; Added as part of revison [7] ;Entry: ; parm: bdl *pbdlSrc - points to source bdl ; parm: ushort oSrc - 16 bit offset into bdl to source ; parm: bdl *pbdlDst - points to destination bdl ; parm: ushort oDst - 16 bit offset into bdl to destination ; parm: ushort cb - number of bytes to copy ;Exit: ; none. ;*************************************************************************** cProc BdlCopyFromTo,<PUBLIC,FAR,NODATA>,<si,di,ds> parmW pbdlSrc parmW oSrc parmW pbdlDst parmW oDst parmW cb cBegin mov si,[pbdlDst] DbChk BdlOwner,si ;ensure that bdlDst is an owner GETSEG dx,[si.BDL_seg],,<SIZE,LOAD> ; dx = seg of far heap entry (dst) mov bx,[pbdlSrc] DbChk BdlOwner,bx ;ensure that bdlSrc is an owner GETSEG ds,[bx.BDL_seg],,<SIZE,LOAD,NOFLUSH> ; ds = seg of far heap entry (src) assumes DS,NOTHING mov es,dx mov si,[oSrc] ;si = source offset mov di,[oDst] ;di = destination offset mov cx,[cb] shr cx,1 ;convert to word count rep movsw ;transfer from ds:si to es:di jnc CopyFrom_Even2 ;no carry if count was even movsb ;move the last (odd) byte CopyFrom_Even2: cEnd assumes DS,DATA ;*** ;BdlTrim - trim given bdl down to cbLogical ;Purpose: ; Releases excess space in a given bdl ;Entry: ; parm: bdl *pbdl ; ;*************************************************************************** cProc BdlTrim,<PUBLIC,FAR,NODATA>,<si,di> parmW pbdl cBegin mov bx,[pbdl] DbChk BdlOwner,bx ;ensure that bdlOwner is an owner mov ax,[bx.BDL_cbLogical] ;size to realloc to xor dx,dx call B$FHRealloc ;must succeed; we're either reducing ; or asking for existing entry size cEnd ;seg_rt = segment address for the RT segment ;It can be referenced from any module as follows: ; EXTRN seg_rt:abs ; mov ax,SEG seg_rt PUBLIC seg_rt seg_rt EQU SEG BdlTrim sEnd RT ;------------------------------------------------------------ ;--- Interpreter Buffer Descriptor Management Routines --- ;------------------------------------------------------------ sBegin DATA staticB bdGrabSpace,NULL,<SIZE BD> sEnd DATA sBegin CODE assumes CS,CODE CBNEAR_GRAB equ 2 * CBBUFBLOCK ;*** ;GrabSpace - grab some heap space ;Purpose: ; Allocates CBNEAR_GRAB bytes via BdAlloc. ; Called to lock up a chunk of heap space so we ensure that ; enough space exists to do simple things like CLEAR for more memory! ; ; NOTE: It's important that grabspace just grab space from the near ; heap, not the far heap; if we grabbed far space instead, ; this could allow the user to tie up all of DGROUP with ; variable tables with plenty of DGROUP space free. ;Entry: ; none. ;Exit: ; ax = 0 if insufficient memory, else ax != 0 ;*************************************************************************** cProc GrabSpace,<PUBLIC,FAR,NODATA> cBegin mov ax,[bdGrabSpace.BD_pb] or ax,ax jnz GotSpace ;return ax<>0 if already have space PUSHI ax,<dataOFFSET bdGrabSpace> PUSHI ax,CBNEAR_GRAB PUSHI ax,IT_NO_OWNERS call BdAlloc or ax,ax GotSpace: cEnd ;*** ;ReleaseSpace - Release the space grabbed by GrabSpace ;Purpose: ; Deallocates the bd allocated by GrabSpace if it is currently allocated. ; Note that it's perfectly o.k. to call this even when no space has ; been grabbed. ;Entry: ; none. ;Exit: ; ax = 0. ;*************************************************************************** cProc ReleaseSpace,<PUBLIC,FAR,NODATA> cBegin PUSHI ax,<dataOFFSET bdGrabSpace> call BdFree ;deallocate bd if couldn't allocate bdl cEnd sEnd CODE end
ViridianHouseObject: db $a ; border block db $2 ; warps db $7, $2, $3, $ff db $7, $3, $3, $ff db $0 ; signs db $4 ; objects object SPRITE_BALDING_GUY, $5, $3, STAY, NONE, $1 ; person object SPRITE_LITTLE_GIRL, $1, $4, WALK, $1, $2 ; person object SPRITE_BIRD, $5, $5, WALK, $2, $3 ; person object SPRITE_CLIPBOARD, $4, $0, STAY, NONE, $4 ; person ; warp-to EVENT_DISP VIRIDIAN_HOUSE_WIDTH, $7, $2 EVENT_DISP VIRIDIAN_HOUSE_WIDTH, $7, $3
; A035289: Number of ways to place a non-attacking white and black knight on n X n chessboard. ; Submitted by Jamie Morken(s3) ; 0,12,56,192,504,1100,2112,3696,6032,9324,13800,19712,27336,36972,48944,63600,81312,102476,127512,156864,191000,230412,275616,327152,385584,451500,525512,608256,700392,802604,915600,1040112,1176896,1326732,1490424,1668800,1862712,2073036,2300672,2546544,2811600,3096812,3403176,3731712,4083464,4459500,4860912,5288816,5744352,6228684,6743000,7288512,7866456,8478092,9124704,9807600,10528112,11287596,12087432,12929024,13813800,14743212,15718736,16741872,17814144,18937100,20112312,21341376,22625912 mov $1,$0 mul $0,3 bin $1,2 add $0,$1 mov $2,$1 add $2,1 mul $0,$2 mul $0,4
lda {m1} sta $fe lda {m1}+1 sta $ff lda ($fe),y cmp #<{c1} iny lda ($fe),y sbc #>{c1} bvc !+ eor #$80 !: bmi {la1}
; A216779: Number of derangements on n elements with an odd number of cycles. ; 0,0,1,2,6,24,135,930,7420,66752,667485,7342290,88107426,1145396472,16035550531,240533257874,3848532125880,65425046139840,1177650830516985,22375365779822562 mov $1,$0 cal $0,166 ; Subfactorial or rencontres numbers, or derangements: number of permutations of n elements with no fixed points. add $1,$0 div $1,2
/** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ #include <aws/dms/model/ResourceAlreadyExistsFault.h> #include <aws/core/utils/json/JsonSerializer.h> #include <utility> using namespace Aws::Utils::Json; using namespace Aws::Utils; namespace Aws { namespace DatabaseMigrationService { namespace Model { ResourceAlreadyExistsFault::ResourceAlreadyExistsFault() : m_messageHasBeenSet(false), m_resourceArnHasBeenSet(false) { } ResourceAlreadyExistsFault::ResourceAlreadyExistsFault(JsonView jsonValue) : m_messageHasBeenSet(false), m_resourceArnHasBeenSet(false) { *this = jsonValue; } ResourceAlreadyExistsFault& ResourceAlreadyExistsFault::operator =(JsonView jsonValue) { if(jsonValue.ValueExists("message")) { m_message = jsonValue.GetString("message"); m_messageHasBeenSet = true; } if(jsonValue.ValueExists("resourceArn")) { m_resourceArn = jsonValue.GetString("resourceArn"); m_resourceArnHasBeenSet = true; } return *this; } JsonValue ResourceAlreadyExistsFault::Jsonize() const { JsonValue payload; if(m_messageHasBeenSet) { payload.WithString("message", m_message); } if(m_resourceArnHasBeenSet) { payload.WithString("resourceArn", m_resourceArn); } return payload; } } // namespace Model } // namespace DatabaseMigrationService } // namespace Aws
#include <mutex> #include <Common/ThreadStatus.h> #include <Processors/Transforms/buildPushingToViewsChain.h> #include <Interpreters/Context.h> #include <Interpreters/OpenTelemetrySpanLog.h> #include <Interpreters/ProcessList.h> #include <Interpreters/QueryThreadLog.h> #include <Interpreters/QueryViewsLog.h> #include <Parsers/formatAST.h> #include <Common/CurrentThread.h> #include <Common/Exception.h> #include <Common/ProfileEvents.h> #include <Common/QueryProfiler.h> #include <Common/SensitiveDataMasker.h> #include <Common/ThreadProfileEvents.h> #include <Common/TraceCollector.h> #include <base/errnoToString.h> #if defined(OS_LINUX) # include <Common/hasLinuxCapability.h> # include <sys/time.h> # include <sys/resource.h> #endif namespace ProfileEvents { extern const Event SelectedRows; extern const Event SelectedBytes; extern const Event InsertedRows; extern const Event InsertedBytes; } /// Implement some methods of ThreadStatus and CurrentThread here to avoid extra linking dependencies in clickhouse_common_io /// TODO It doesn't make sense. namespace DB { namespace ErrorCodes { extern const int LOGICAL_ERROR; extern const int CANNOT_SET_THREAD_PRIORITY; } void ThreadStatus::applyQuerySettings() { auto query_context_ptr = query_context.lock(); assert(query_context_ptr); const Settings & settings = query_context_ptr->getSettingsRef(); query_id = query_context_ptr->getCurrentQueryId(); initQueryProfiler(); untracked_memory_limit = settings.max_untracked_memory; if (settings.memory_profiler_step && settings.memory_profiler_step < UInt64(untracked_memory_limit)) untracked_memory_limit = settings.memory_profiler_step; #if defined(OS_LINUX) /// Set "nice" value if required. Int32 new_os_thread_priority = settings.os_thread_priority; if (new_os_thread_priority && hasLinuxCapability(CAP_SYS_NICE)) { LOG_TRACE(log, "Setting nice to {}", new_os_thread_priority); if (0 != setpriority(PRIO_PROCESS, thread_id, new_os_thread_priority)) throwFromErrno("Cannot 'setpriority'", ErrorCodes::CANNOT_SET_THREAD_PRIORITY); os_thread_priority = new_os_thread_priority; } #endif } void ThreadStatus::attachQueryContext(ContextPtr query_context_) { query_context = query_context_; if (global_context.expired()) global_context = query_context_->getGlobalContext(); if (thread_group) { std::lock_guard lock(thread_group->mutex); thread_group->query_context = query_context; if (thread_group->global_context.expired()) thread_group->global_context = global_context; } // Generate new span for thread manually here, because we can't depend // on OpenTelemetrySpanHolder due to link order issues. // FIXME why and how is this different from setupState()? thread_trace_context = query_context_->query_trace_context; if (thread_trace_context.trace_id != UUID()) { thread_trace_context.span_id = thread_local_rng(); } applyQuerySettings(); } void CurrentThread::defaultThreadDeleter() { if (unlikely(!current_thread)) return; current_thread->detachQuery(true, true); } void ThreadStatus::setupState(const ThreadGroupStatusPtr & thread_group_) { assertState({ThreadState::DetachedFromQuery}, __PRETTY_FUNCTION__); /// Attach or init current thread to thread group and copy useful information from it thread_group = thread_group_; performance_counters.setParent(&thread_group->performance_counters); memory_tracker.setParent(&thread_group->memory_tracker); { std::lock_guard lock(thread_group->mutex); /// NOTE: thread may be attached multiple times if it is reused from a thread pool. thread_group->thread_ids.emplace_back(thread_id); thread_group->threads.insert(this); logs_queue_ptr = thread_group->logs_queue_ptr; fatal_error_callback = thread_group->fatal_error_callback; query_context = thread_group->query_context; profile_queue_ptr = thread_group->profile_queue_ptr; if (global_context.expired()) global_context = thread_group->global_context; } if (auto query_context_ptr = query_context.lock()) { applyQuerySettings(); // Generate new span for thread manually here, because we can't depend // on OpenTelemetrySpanHolder due to link order issues. thread_trace_context = query_context_ptr->query_trace_context; if (thread_trace_context.trace_id != UUID()) { thread_trace_context.span_id = thread_local_rng(); } } else { thread_trace_context.trace_id = 0; } initPerformanceCounters(); thread_state = ThreadState::AttachedToQuery; } void ThreadStatus::initializeQuery() { setupState(std::make_shared<ThreadGroupStatus>()); /// No need to lock on mutex here thread_group->memory_tracker.setDescription("(for query)"); thread_group->master_thread_id = thread_id; } void ThreadStatus::attachQuery(const ThreadGroupStatusPtr & thread_group_, bool check_detached) { if (thread_state == ThreadState::AttachedToQuery) { if (check_detached) throw Exception("Can't attach query to the thread, it is already attached", ErrorCodes::LOGICAL_ERROR); return; } if (!thread_group_) throw Exception("Attempt to attach to nullptr thread group", ErrorCodes::LOGICAL_ERROR); setupState(thread_group_); } inline UInt64 time_in_nanoseconds(std::chrono::time_point<std::chrono::system_clock> timepoint) { return std::chrono::duration_cast<std::chrono::nanoseconds>(timepoint.time_since_epoch()).count(); } inline UInt64 time_in_microseconds(std::chrono::time_point<std::chrono::system_clock> timepoint) { return std::chrono::duration_cast<std::chrono::microseconds>(timepoint.time_since_epoch()).count(); } inline UInt64 time_in_seconds(std::chrono::time_point<std::chrono::system_clock> timepoint) { return std::chrono::duration_cast<std::chrono::seconds>(timepoint.time_since_epoch()).count(); } void ThreadStatus::initPerformanceCounters() { performance_counters_finalized = false; /// Clear stats from previous query if a new query is started /// TODO: make separate query_thread_performance_counters and thread_performance_counters performance_counters.resetCounters(); memory_tracker.resetCounters(); memory_tracker.setDescription("(for thread)"); // query_start_time_{microseconds, nanoseconds} are all constructed from the same time point // to ensure that they are all equal up to the precision of a second. const auto now = std::chrono::system_clock::now(); query_start_time_nanoseconds = time_in_nanoseconds(now); query_start_time = time_in_seconds(now); query_start_time_microseconds = time_in_microseconds(now); ++queries_started; // query_start_time_nanoseconds cannot be used here since RUsageCounters expect CLOCK_MONOTONIC *last_rusage = RUsageCounters::current(); if (auto query_context_ptr = query_context.lock()) { const Settings & settings = query_context_ptr->getSettingsRef(); if (settings.metrics_perf_events_enabled) { try { current_thread_counters.initializeProfileEvents( settings.metrics_perf_events_list); } catch (...) { tryLogCurrentException(__PRETTY_FUNCTION__); } } } if (!taskstats) { try { taskstats = TasksStatsCounters::create(thread_id); } catch (...) { tryLogCurrentException(log); } } if (taskstats) taskstats->reset(); } void ThreadStatus::finalizePerformanceCounters() { if (performance_counters_finalized) return; performance_counters_finalized = true; updatePerformanceCounters(); // We want to close perf file descriptors if the perf events were enabled for // one query. What this code does in practice is less clear -- e.g., if I run // 'select 1 settings metrics_perf_events_enabled = 1', I still get // query_context->getSettingsRef().metrics_perf_events_enabled == 0 *shrug*. bool close_perf_descriptors = true; if (auto query_context_ptr = query_context.lock()) close_perf_descriptors = !query_context_ptr->getSettingsRef().metrics_perf_events_enabled; try { current_thread_counters.finalizeProfileEvents(performance_counters); if (close_perf_descriptors) current_thread_counters.closeEventDescriptors(); } catch (...) { tryLogCurrentException(log); } try { auto global_context_ptr = global_context.lock(); auto query_context_ptr = query_context.lock(); if (global_context_ptr && query_context_ptr) { const auto & settings = query_context_ptr->getSettingsRef(); if (settings.log_queries && settings.log_query_threads) { const auto now = std::chrono::system_clock::now(); Int64 query_duration_ms = (time_in_microseconds(now) - query_start_time_microseconds) / 1000; if (query_duration_ms >= settings.log_queries_min_query_duration_ms.totalMilliseconds()) { if (auto thread_log = global_context_ptr->getQueryThreadLog()) logToQueryThreadLog(*thread_log, query_context_ptr->getCurrentDatabase(), now); } } } } catch (...) { tryLogCurrentException(log); } } void ThreadStatus::resetPerformanceCountersLastUsage() { *last_rusage = RUsageCounters::current(); if (taskstats) taskstats->reset(); } void ThreadStatus::initQueryProfiler() { if (!query_profiled_enabled) return; /// query profilers are useless without trace collector auto global_context_ptr = global_context.lock(); if (!global_context_ptr || !global_context_ptr->hasTraceCollector()) return; auto query_context_ptr = query_context.lock(); assert(query_context_ptr); const auto & settings = query_context_ptr->getSettingsRef(); try { if (settings.query_profiler_real_time_period_ns > 0) query_profiler_real = std::make_unique<QueryProfilerReal>(thread_id, /* period */ static_cast<UInt32>(settings.query_profiler_real_time_period_ns)); if (settings.query_profiler_cpu_time_period_ns > 0) query_profiler_cpu = std::make_unique<QueryProfilerCPU>(thread_id, /* period */ static_cast<UInt32>(settings.query_profiler_cpu_time_period_ns)); } catch (...) { /// QueryProfiler is optional. tryLogCurrentException("ThreadStatus", "Cannot initialize QueryProfiler"); } } void ThreadStatus::finalizeQueryProfiler() { query_profiler_real.reset(); query_profiler_cpu.reset(); } void ThreadStatus::detachQuery(bool exit_if_already_detached, bool thread_exits) { MemoryTracker::LockExceptionInThread lock(VariableContext::Global); if (exit_if_already_detached && thread_state == ThreadState::DetachedFromQuery) { thread_state = thread_exits ? ThreadState::Died : ThreadState::DetachedFromQuery; return; } assertState({ThreadState::AttachedToQuery}, __PRETTY_FUNCTION__); std::shared_ptr<OpenTelemetrySpanLog> opentelemetry_span_log; auto query_context_ptr = query_context.lock(); if (thread_trace_context.trace_id != UUID() && query_context_ptr) { opentelemetry_span_log = query_context_ptr->getOpenTelemetrySpanLog(); } if (opentelemetry_span_log) { // Log the current thread span. // We do this manually, because we can't use OpenTelemetrySpanHolder as a // ThreadStatus member, because of linking issues. This file is linked // separately, so we can reference OpenTelemetrySpanLog here, but if we had // the span holder as a field, we would have to reference it in the // destructor, which is in another library. OpenTelemetrySpanLogElement span; span.trace_id = thread_trace_context.trace_id; // All child span holders should be finished by the time we detach this // thread, so the current span id should be the thread span id. If not, // an assertion for a proper parent span in ~OpenTelemetrySpanHolder() // is going to fail, because we're going to reset it to zero later in // this function. span.span_id = thread_trace_context.span_id; assert(query_context_ptr); span.parent_span_id = query_context_ptr->query_trace_context.span_id; span.operation_name = getThreadName(); span.start_time_us = query_start_time_microseconds; span.finish_time_us = std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::system_clock::now().time_since_epoch()).count(); span.attribute_names.push_back("clickhouse.thread_id"); span.attribute_values.push_back(thread_id); opentelemetry_span_log->add(span); } finalizeQueryProfiler(); finalizePerformanceCounters(); /// Detach from thread group { std::lock_guard guard(thread_group->mutex); thread_group->threads.erase(this); } performance_counters.setParent(&ProfileEvents::global_counters); memory_tracker.reset(); /// Must reset pointer to thread_group's memory_tracker, because it will be destroyed two lines below (will reset to its parent). memory_tracker.setParent(thread_group->memory_tracker.getParent()); query_id.clear(); query_context.reset(); thread_trace_context.trace_id = 0; thread_trace_context.span_id = 0; thread_group.reset(); thread_state = thread_exits ? ThreadState::Died : ThreadState::DetachedFromQuery; #if defined(__linux__) if (os_thread_priority) { LOG_TRACE(log, "Resetting nice"); if (0 != setpriority(PRIO_PROCESS, thread_id, 0)) LOG_ERROR(log, "Cannot 'setpriority' back to zero: {}", errnoToString(ErrorCodes::CANNOT_SET_THREAD_PRIORITY, errno)); os_thread_priority = 0; } #endif } void ThreadStatus::logToQueryThreadLog(QueryThreadLog & thread_log, const String & current_database, std::chrono::time_point<std::chrono::system_clock> now) { QueryThreadLogElement elem; // construct current_time and current_time_microseconds using the same time point // so that the two times will always be equal up to a precision of a second. auto current_time = time_in_seconds(now); auto current_time_microseconds = time_in_microseconds(now); elem.event_time = current_time; elem.event_time_microseconds = current_time_microseconds; elem.query_start_time = query_start_time; elem.query_start_time_microseconds = query_start_time_microseconds; elem.query_duration_ms = (time_in_nanoseconds(now) - query_start_time_nanoseconds) / 1000000U; elem.read_rows = progress_in.read_rows.load(std::memory_order_relaxed); elem.read_bytes = progress_in.read_bytes.load(std::memory_order_relaxed); /// TODO: Use written_rows and written_bytes when run time progress is implemented elem.written_rows = progress_out.read_rows.load(std::memory_order_relaxed); elem.written_bytes = progress_out.read_bytes.load(std::memory_order_relaxed); elem.memory_usage = memory_tracker.get(); elem.peak_memory_usage = memory_tracker.getPeak(); elem.thread_name = getThreadName(); elem.thread_id = thread_id; elem.current_database = current_database; if (thread_group) { { std::lock_guard lock(thread_group->mutex); elem.master_thread_id = thread_group->master_thread_id; elem.query = thread_group->query; elem.normalized_query_hash = thread_group->normalized_query_hash; } } auto query_context_ptr = query_context.lock(); if (query_context_ptr) { elem.client_info = query_context_ptr->getClientInfo(); if (query_context_ptr->getSettingsRef().log_profile_events != 0) { /// NOTE: Here we are in the same thread, so we can make memcpy() elem.profile_counters = std::make_shared<ProfileEvents::Counters::Snapshot>(performance_counters.getPartiallyAtomicSnapshot()); } } thread_log.add(elem); } static String getCleanQueryAst(const ASTPtr q, ContextPtr context) { String res = serializeAST(*q, true); if (auto * masker = SensitiveDataMasker::getInstance()) masker->wipeSensitiveData(res); res = res.substr(0, context->getSettingsRef().log_queries_cut_to_length); return res; } void ThreadStatus::logToQueryViewsLog(const ViewRuntimeData & vinfo) { auto query_context_ptr = query_context.lock(); if (!query_context_ptr) return; auto views_log = query_context_ptr->getQueryViewsLog(); if (!views_log) return; QueryViewsLogElement element; element.event_time = time_in_seconds(vinfo.runtime_stats->event_time); element.event_time_microseconds = time_in_microseconds(vinfo.runtime_stats->event_time); element.view_duration_ms = vinfo.runtime_stats->elapsed_ms; element.initial_query_id = query_id; element.view_name = vinfo.table_id.getFullTableName(); element.view_uuid = vinfo.table_id.uuid; element.view_type = vinfo.runtime_stats->type; if (vinfo.query) element.view_query = getCleanQueryAst(vinfo.query, query_context_ptr); element.view_target = vinfo.runtime_stats->target_name; auto events = std::make_shared<ProfileEvents::Counters::Snapshot>(performance_counters.getPartiallyAtomicSnapshot()); element.read_rows = progress_in.read_rows.load(std::memory_order_relaxed); element.read_bytes = progress_in.read_bytes.load(std::memory_order_relaxed); element.written_rows = (*events)[ProfileEvents::InsertedRows]; element.written_bytes = (*events)[ProfileEvents::InsertedBytes]; element.peak_memory_usage = memory_tracker.getPeak() > 0 ? memory_tracker.getPeak() : 0; if (query_context_ptr->getSettingsRef().log_profile_events != 0) { element.profile_counters = events; } element.status = vinfo.runtime_stats->event_status; element.exception_code = 0; if (vinfo.exception) { element.exception_code = getExceptionErrorCode(vinfo.exception); element.exception = getExceptionMessage(vinfo.exception, false); if (query_context_ptr->getSettingsRef().calculate_text_stack_trace) element.stack_trace = getExceptionStackTraceString(vinfo.exception); } views_log->add(element); } void CurrentThread::initializeQuery() { if (unlikely(!current_thread)) return; current_thread->initializeQuery(); current_thread->deleter = CurrentThread::defaultThreadDeleter; } void CurrentThread::attachTo(const ThreadGroupStatusPtr & thread_group) { if (unlikely(!current_thread)) return; current_thread->attachQuery(thread_group, true); current_thread->deleter = CurrentThread::defaultThreadDeleter; } void CurrentThread::attachToIfDetached(const ThreadGroupStatusPtr & thread_group) { if (unlikely(!current_thread)) return; current_thread->attachQuery(thread_group, false); current_thread->deleter = CurrentThread::defaultThreadDeleter; } void CurrentThread::attachQueryContext(ContextPtr query_context) { if (unlikely(!current_thread)) return; current_thread->attachQueryContext(query_context); } void CurrentThread::finalizePerformanceCounters() { if (unlikely(!current_thread)) return; current_thread->finalizePerformanceCounters(); } void CurrentThread::detachQuery() { if (unlikely(!current_thread)) return; current_thread->detachQuery(false); } void CurrentThread::detachQueryIfNotDetached() { if (unlikely(!current_thread)) return; current_thread->detachQuery(true); } CurrentThread::QueryScope::QueryScope(ContextMutablePtr query_context) { CurrentThread::initializeQuery(); CurrentThread::attachQueryContext(query_context); if (!query_context->hasQueryContext()) query_context->makeQueryContext(); } void CurrentThread::QueryScope::logPeakMemoryUsage() { auto group = CurrentThread::getGroup(); if (!group) return; log_peak_memory_usage_in_destructor = false; group->memory_tracker.logPeakMemoryUsage(); } CurrentThread::QueryScope::~QueryScope() { try { if (log_peak_memory_usage_in_destructor) logPeakMemoryUsage(); CurrentThread::detachQueryIfNotDetached(); } catch (...) { tryLogCurrentException("CurrentThread", __PRETTY_FUNCTION__); } } }
; gpfix.asm - pointer validation routines include gpfix.inc include kernel.inc include tdb.inc include newexe.inc sBegin GPFIX0 __GP label word ;gpbeg dw 0, 0, 0, 0 ; for use in handler public __GP sEnd GPFIX0 sBegin GPFIX1 gpend dw 0 sEnd GPFIX1 sBegin DATA ;this segment is page locked and will be accessible during a GP fault ;has the names of modules that are allowed to use our funky GP fault handling ; mechanism. Format: length byte, module name. The table is zero-terminated. gp_valid_modules label byte db 3, "GDI" db 4, "USER" db 6, "KERNEL" db 6, "PENWIN" db 7, "DISPLAY" db 8, "MMSYSTEM" db 0 ;end of table sEnd DATA ifdef DISABLE sBegin DATA ;ExternW wErrorOpts sEnd DATA endif ;public gpbeg, gpend sBegin CODE assumes CS,CODE externA __AHINCR externNP GetOwner externNP EntProcAddress externFP GetExePtr externFP SetSelectorLimit ;=============================================================== ; ; cProc IsBadReadPtr,<PUBLIC,FAR,NONWIN> ParmD lp ParmW cb cBegin beg_fault_trap BadRead1 les bx,lp ; check selector mov cx,cb jcxz ReadDone1 dec cx add bx,cx jc BadRead ; check 16 bit overflow mov al,es:[bx] ; check read permission, limit end_fault_trap ReadDone1: xor ax,ax ReadDone: cEnd BadRead1: fault_fix_stack BadRead: mov ax,1 jmp short ReadDone ;=============================================================== ; ; cProc IsBadWritePtr,<PUBLIC,FAR,NONWIN> ParmD lp ParmW cb cBegin beg_fault_trap BadWrite1 les bx,lp ; check selector mov cx,cb jcxz WriteDone1 dec cx add bx,cx jc BadWrite ; check 16 bit overflow or es:byte ptr [bx],0 ; check write permission, limit end_fault_trap WriteDone1: xor ax, ax WriteDone: cEnd BadWrite1: fault_fix_stack BadWrite: mov ax,1 jmp short WriteDone ;=============================================================== ; BOOL IsBadFlatReadWritePtr(VOID HUGE*lp, DWORD cb, WORD fWrite) ; This will validate a Flat pointer plus a special hack for Fox Pro ; to detect their poorly tiled selector (ie. all n selector with ; limit of 64K) (Our tiling is such that you can access up to end of ; the block using any one of the intermediate selectors flat) ; if we detect such a case we will fix up the limit on the first sel ; so GDI can access all of the memory as a 1st_sel:32-bit offset cProc IsBadFlatReadWritePtr,<PUBLIC,FAR,NONWIN> ParmD lp ParmD cb ParmW fWrite cBegin beg_fault_trap frp_trap les bx,lp ; check selector .386p mov eax,cb movzx ebx, bx test eax,eax ; cb == 0, all done. jz frp_ok add ebx,eax dec ebx cmp fWrite, 0 jne frp_write mov al,es:[ebx] ; read last byte jmp frp_ok frp_write: or byte ptr es:[ebx], 0 ; write last byte frp_ok: xor ax,ax end_fault_trap frp_exit: cEnd frp_trap: fault_fix_stack frp_bad: push ebx mov ecx, ebx ; get cb shr ecx, 16 ; get high word jecxz frp_bade ; if < 64K then bad ptr mov ax, es lsl eax, eax ; get limit on 1st sel jnz frp_bade ; bad sel? cmp ax, 0ffffh ; 1st of poorly tiled sels? jne frp_bade ; N: return bad ptr ; now we have to confirm that this is indeed the first of a bunch ; of poorly tiled sels and fix up the limit correctly of the first sel movzx ebx, ax ; ebx = lim total of tiled sels inc ebx ; make it 10000 mov dx, es frp_loop: add dx,__AHINCR ; next sel in array lsl eax, edx jnz frp_bade cmp ecx, 1 ; last sel? je @f ; if its not the last sel, then its limit has to be ffffh ; otherwise it probably is not a poorly tiled sel. cmp eax, 0ffffh jne frp_bade @@: add ebx, eax ; upd total limit inc ebx ; add 1 for middle sels loop frp_loop dec ebx ; take exact limit of last sel pop edx ; get cb cmp edx, ebx jg frp_bade_cleaned ; set limit of 1st sel to be ebx push es push ebx call SetSelectorLimit if KDEBUG mov ax, es krDebugOut DEB_WARN, "Fixing poorly tiled selector #AX for flat access" endif jmp frp_ok frp_bade: pop ebx frp_bade_cleaned: .286p mov ax,1 jmp frp_exit ;=============================================================== ; BOOL IsBadHugeReadPtr(VOID HUGE*lp, DWORD cb) ; cProc IsBadHugeReadPtr,<PUBLIC,FAR,NONWIN> ParmD lp ParmD cb cBegin beg_fault_trap hrp_trap les bx,lp ; check selector mov ax,off_cb mov cx,seg_cb mov dx,ax ; if cb == 0, then all done. or dx,cx jz hrp_ok sub ax,1 ; decrement the count sbb cx,0 add bx,ax ; adjust cx:bx by pointer offset adc cx,0 jc hrp_bad ; (bug #10446, pass in -1L as count) jcxz hrplast ; deal with leftover hrploop: mov al,es:[0ffffh] ; touch complete segments. mov dx,es add dx,__AHINCR mov es,dx loop hrploop hrplast: mov al,es:[bx] hrp_ok: xor ax,ax end_fault_trap hrp_exit: cEnd hrp_trap: fault_fix_stack hrp_bad: mov ax,1 jmp hrp_exit ;=============================================================== ; BOOL IsBadHugeWritePtr(VOID HUGE*lp, DWORD cb) ; cProc IsBadHugeWritePtr,<PUBLIC,FAR,NONWIN> ParmD lp ParmD cb cBegin beg_fault_trap hwp_trap les bx,lp ; check selector mov ax,off_cb mov cx,seg_cb mov dx,ax ; if cb == 0, then all done. or dx,cx jz hwp_ok sub ax,1 ; decrement the count sbb cx,0 add bx,ax ; adjust cx:bx by pointer offset adc cx,0 jc hwp_bad ; (bug #10446, pass in -1L as count) jcxz hwplast ; deal with leftover hwploop: or byte ptr es:[0ffffh],0 ; touch complete segments. mov dx,es add dx,__AHINCR mov es,dx loop hwploop hwplast: or byte ptr es:[bx],0 hwp_ok: xor ax,ax end_fault_trap hwp_exit: cEnd hwp_trap: fault_fix_stack hwp_bad: mov ax,1 jmp hwp_exit ;=============================================================== ; ; cProc IsBadCodePtr,<PUBLIC,FAR,NONWIN> ParmD lpfn cBegin beg_fault_trap BadCode1 mov cx,seg_lpfn lar ax,cx jnz BadCode ; Oh no, this isn't a selector! test ah, 8 jz BadCode ; Oh no, this isn't code! mov es,cx ; Validate the pointer mov bx,off_lpfn mov al,es:[bx] end_fault_trap xor ax, ax CodeDone: cEnd BadCode1: fault_fix_stack BadCode: mov ax,1 jmp short CodeDone ;======================================================== ; ; BOOL IsBadStringPtr(LPSTR lpsz, UINT cch); ; cProc IsBadStringPtr,<PUBLIC,FAR,NONWIN>,<DI> ParmD lpsz ParmW cchMax cBegin beg_fault_trap BadStr1 les di,lpsz ; Scan the string. xor ax,ax mov cx,-1 cld repnz scasb end_fault_trap neg cx ; cx = string length + 1 dec cx cmp cx,cchMax ja BadStr ; if string length > cchMax, then bad string. bspexit: cEnd BadStr1: fault_fix_stack BadStr: mov ax,1 jmp bspexit ;-----------------------------------------------------------------------; ; HasGPHandler ; ; ; ; See if GP fault handler is registered for faulting address. ; ; ; ; This scheme can only be used by registered modules. You register ; ; a module by adding an entry containing a length byte followed by ; ; the module name in the gp_valid_modules table defined above. ; ; ; ; Arguments: ; ; parmD lpFaultAdr ; ; ; ; Returns: ; ; AX = New IP of handler ; ; AX = 0 if no handler registered ; ; ; ; Error Returns: ; ; ; ; Registers Preserved: ; ; DI,SI,DS ; ; ; ; Registers Destroyed: ; ; AX,BX,CX,DX,ES ; ; ; ; Calls: ; ; GetOwner ; ; EntProcAddress ; ; ; ; The __GP table has the format of 4 words per entry, plus a ; ; zero word to terminate the table. The 'seg' value should be ; ; the actual selector (it must be fixed up by the linker), ; ; and the offset values should be relative to the start of the ; ; segment or group. The handler must be in the same code segment ; ; as the fault range (this ensures that the handler is present ; ; at GP fault time). ; ; ; ; __GP label word ; ; public __GP ; ; seg, offset begin, offset end, handler ; ; ... ; ; 0 ; ; ; ; The symbol '__GP' needs to be in the resident name table, so ; ; it should be added to the DEF file like this (with an ; ; appropriate ordinal value): ; ; ; ; EXPORTS ; ; __GP @??? RESIDENTNAME ; ; ; ; ; ; History: ; ; ?? Jun 91 Don Corbitt [donc] Wrote it ; ; 30 Jul 91 Don Corbitt [donc] Added support for __GP table ; ;-----------------------------------------------------------------------; cProc HasGPHandler,<PUBLIC,FAR,NONWIN>,<ds,si,di> ParmD lpfn cBegin cCall GetOwner, <SEG_lpfn> ; find owner of faulting code or ax, ax jz to_fail ;HH_fail lar bx, ax ; make sure segment is present jnz to_fail ;HH_fail test bx, 8000h jz to_fail ;HH_fail mov es, ax cmp es:[ne_magic], NEMAGIC jz @f to_fail: jmp HH_fail @@: ; check if the faulting module is allowed to use this scheme SetKernelDS mov di, es:[ne_restab] mov bx, di inc bx ; save ptr to module name xor cx,cx xor ax,ax mov si, offset gp_valid_modules mov al, es:[di] cld friend_or_fiend: mov cl, [si] jcxz HH_fail cmp al,cl jnz next_friend mov di, bx ; need to keep restoring di inc si ; skip len byte repe cmpsb jz we_know_this_chap dec si ; point to the mismatch next_friend: add si, cx inc si jmp short friend_or_fiend we_know_this_chap: xor cx, cx mov si, es:[ne_restab] ; restore si jmp short @F ; start in middle of code HH_nextSym: add si, cx ; skip name add si, 3 ; and entry point @@: mov cl, es:[si] ; get length of symbol jcxz HH_fail ; end of table - not found cmp cl, 4 ; name length jnz HH_nextSym cmp es:[si+1], '__' ; look for '__GP' jnz HH_nextSym cmp es:[si+3], 'PG' jnz HH_nextSym mov ax, es:[si+5] ; get ordinal for '__GP' if KDEBUG cCall EntProcAddress,<es,ax,1> else cCall EntProcAddress,<es,ax> ; I hate conditional assembly.... endif mov cx, ax or cx, dx jz HH_fail ; This shouldn't ever fail, but... lar bx, dx ; make sure segment is present jnz HH_fail test bx, 8000h jz HH_fail mov ds, dx mov si, ax mov ax, SEG_lpfn mov dx, OFF_lpfn next_fault_val: mov cx, [si] jcxz HH_fail cmp cx, ax ; does segment match? jnz gp_mismatch cmp [si+2], dx ; block start ja gp_mismatch cmp [si+4], dx ; block end jbe gp_mismatch mov ax, [si+6] ; get new IP jmp short HH_done gp_mismatch: add si, 8 jmp short next_fault_val HH_fail: xor ax, ax HH_done: cEnd ;======================================================================== ; ; BOOL IsSharedSelector(HGLOBAL h); ; ; Makes sure the given selector is shareable. Currently, we just check ; if it is owned by a DLL. We also need to check GMEM_SHARE bit but ; this isn't saved... ; cProc IsSharedSelector,<PUBLIC,FAR,NOWIN> ParmW sharedsel cBegin push sharedsel call GetExePtr or ax,ax ; bogus handle: exit. jz ISS_Done mov es,ax xor ax,ax test es:[ne_flags],NENOTP jz ISS_Done ; Not a DLL inc ax ; Yup a DLL ISS_Done: cEnd sEnd CODE end
; A031343: a(n) = prime(10*n). ; Submitted by Simon Strandgaard ; 29,71,113,173,229,281,349,409,463,541,601,659,733,809,863,941,1013,1069,1151,1223,1291,1373,1451,1511,1583,1657,1733,1811,1889,1987,2053,2129,2213,2287,2357,2423,2531,2617,2687,2741,2819,2903,2999,3079,3181,3257,3331,3413,3511,3571,3643,3727,3821,3907,3989,4057,4139,4231,4297,4409,4493,4583,4657,4751,4831,4937,5003,5087,5179,5279,5387,5443,5521,5639,5693,5791,5857,5939,6053,6133,6221,6301,6367,6473,6571,6673,6761,6833,6917,6997,7103,7207,7297,7411,7499,7561,7643,7723,7829,7919 mul $0,10 add $0,7 seq $0,173064 ; a(n) = prime(n) - 5. add $0,5
############################################################################### # Copyright 2019 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # You may not use this file except in compliance with the License. You may # obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # limitations under the License. ############################################################################### .text .p2align 5, 0x90 .globl _cpSub_BNU _cpSub_BNU: movslq %ecx, %rcx xor %rax, %rax cmp $(2), %rcx jge .LSUB_GE2gas_1 add %rax, %rax movq (%rsi), %r8 sbbq (%rdx), %r8 movq %r8, (%rdi) sbb %rax, %rax jmp .LFINALgas_1 .LSUB_GE2gas_1: jg .LSUB_GT2gas_1 add %rax, %rax movq (%rsi), %r8 sbbq (%rdx), %r8 movq (8)(%rsi), %r9 sbbq (8)(%rdx), %r9 movq %r8, (%rdi) movq %r9, (8)(%rdi) sbb %rax, %rax jmp .LFINALgas_1 .LSUB_GT2gas_1: cmp $(4), %rcx jge .LSUB_GE4gas_1 add %rax, %rax movq (%rsi), %r8 sbbq (%rdx), %r8 movq (8)(%rsi), %r9 sbbq (8)(%rdx), %r9 movq (16)(%rsi), %r10 sbbq (16)(%rdx), %r10 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) sbb %rax, %rax jmp .LFINALgas_1 .LSUB_GE4gas_1: jg .LSUB_GT4gas_1 add %rax, %rax movq (%rsi), %r8 sbbq (%rdx), %r8 movq (8)(%rsi), %r9 sbbq (8)(%rdx), %r9 movq (16)(%rsi), %r10 sbbq (16)(%rdx), %r10 movq (24)(%rsi), %r11 sbbq (24)(%rdx), %r11 movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) sbb %rax, %rax jmp .LFINALgas_1 .LSUB_GT4gas_1: cmp $(6), %rcx jge .LSUB_GE6gas_1 add %rax, %rax movq (%rsi), %r8 sbbq (%rdx), %r8 movq (8)(%rsi), %r9 sbbq (8)(%rdx), %r9 movq (16)(%rsi), %r10 sbbq (16)(%rdx), %r10 movq (24)(%rsi), %r11 sbbq (24)(%rdx), %r11 movq (32)(%rsi), %rcx sbbq (32)(%rdx), %rcx movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %rcx, (32)(%rdi) sbb %rax, %rax jmp .LFINALgas_1 .LSUB_GE6gas_1: jg .LSUB_GT6gas_1 add %rax, %rax movq (%rsi), %r8 sbbq (%rdx), %r8 movq (8)(%rsi), %r9 sbbq (8)(%rdx), %r9 movq (16)(%rsi), %r10 sbbq (16)(%rdx), %r10 movq (24)(%rsi), %r11 sbbq (24)(%rdx), %r11 movq (32)(%rsi), %rcx sbbq (32)(%rdx), %rcx movq (40)(%rsi), %rsi sbbq (40)(%rdx), %rsi movq %r8, (%rdi) movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %rcx, (32)(%rdi) movq %rsi, (40)(%rdi) sbb %rax, %rax jmp .LFINALgas_1 .LSUB_GT6gas_1: cmp $(8), %rcx jge .LSUB_GE8gas_1 .LSUB_EQ7gas_1: add %rax, %rax movq (%rsi), %r8 sbbq (%rdx), %r8 movq (8)(%rsi), %r9 sbbq (8)(%rdx), %r9 movq (16)(%rsi), %r10 sbbq (16)(%rdx), %r10 movq (24)(%rsi), %r11 sbbq (24)(%rdx), %r11 movq (32)(%rsi), %rcx sbbq (32)(%rdx), %rcx movq %r8, (%rdi) movq (40)(%rsi), %r8 sbbq (40)(%rdx), %r8 movq (48)(%rsi), %rsi sbbq (48)(%rdx), %rsi movq %r9, (8)(%rdi) movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %rcx, (32)(%rdi) movq %r8, (40)(%rdi) movq %rsi, (48)(%rdi) sbb %rax, %rax jmp .LFINALgas_1 .LSUB_GE8gas_1: jg .LSUB_GT8gas_1 add %rax, %rax movq (%rsi), %r8 sbbq (%rdx), %r8 movq (8)(%rsi), %r9 sbbq (8)(%rdx), %r9 movq (16)(%rsi), %r10 sbbq (16)(%rdx), %r10 movq (24)(%rsi), %r11 sbbq (24)(%rdx), %r11 movq (32)(%rsi), %rcx sbbq (32)(%rdx), %rcx movq %r8, (%rdi) movq (40)(%rsi), %r8 sbbq (40)(%rdx), %r8 movq %r9, (8)(%rdi) movq (48)(%rsi), %r9 sbbq (48)(%rdx), %r9 movq (56)(%rsi), %rsi sbbq (56)(%rdx), %rsi movq %r10, (16)(%rdi) movq %r11, (24)(%rdi) movq %rcx, (32)(%rdi) movq %r8, (40)(%rdi) movq %r9, (48)(%rdi) movq %rsi, (56)(%rdi) sbb %rax, %rax jmp .LFINALgas_1 .LSUB_GT8gas_1: mov %rax, %r8 mov %rcx, %rax and $(3), %rcx xor %rax, %rcx lea (%rsi,%rcx,8), %rsi lea (%rdx,%rcx,8), %rdx lea (%rdi,%rcx,8), %rdi neg %rcx add %r8, %r8 jmp .LSUB_GLOOPgas_1 .p2align 5, 0x90 .LSUB_GLOOPgas_1: movq (%rsi,%rcx,8), %r8 movq (8)(%rsi,%rcx,8), %r9 movq (16)(%rsi,%rcx,8), %r10 movq (24)(%rsi,%rcx,8), %r11 sbbq (%rdx,%rcx,8), %r8 sbbq (8)(%rdx,%rcx,8), %r9 sbbq (16)(%rdx,%rcx,8), %r10 sbbq (24)(%rdx,%rcx,8), %r11 movq %r8, (%rdi,%rcx,8) movq %r9, (8)(%rdi,%rcx,8) movq %r10, (16)(%rdi,%rcx,8) movq %r11, (24)(%rdi,%rcx,8) lea (4)(%rcx), %rcx jrcxz .LSUB_LLAST0gas_1 jmp .LSUB_GLOOPgas_1 .LSUB_LLAST0gas_1: sbb %rcx, %rcx and $(3), %rax jz .LFIN0gas_1 .LSUB_LLOOPgas_1: test $(2), %rax jz .LSUB_LLAST1gas_1 add %rcx, %rcx movq (%rsi), %r8 movq (8)(%rsi), %r9 sbbq (%rdx), %r8 sbbq (8)(%rdx), %r9 movq %r8, (%rdi) movq %r9, (8)(%rdi) sbb %rcx, %rcx test $(1), %rax jz .LFIN0gas_1 add $(16), %rsi add $(16), %rdx add $(16), %rdi .LSUB_LLAST1gas_1: add %rcx, %rcx movq (%rsi), %r8 sbbq (%rdx), %r8 movq %r8, (%rdi) sbb %rcx, %rcx .LFIN0gas_1: mov %rcx, %rax .LFINALgas_1: neg %rax vzeroupper ret
; ; as per the System-V ABI, registers are allocated in the order: ; rdi, rsi, rdx, rcx, r8, r9 ; ; just some stuff its nice to have globally global sdl_rect_a global sdl_rect_b global screen global screen_format global draw_rect_a global draw_rect_b global draw_tree global draw_stage extern ticks extern linearmap extern SDL_FillRect extern SDL_GetTicks extern filledPolygonColor ; part of the SDL_gfxPrimitives extern filledTrigonColor ; ... extern filledCircleColor ; ... extern lineColor ; ... extern color_lut_begin extern green extern brown extern gray extern yellow extern white extern silver extern gold extern black %define rect_a_X(v) mov [sdl_rect_a + 0], word v %define rect_a_Y(v) mov [sdl_rect_a + 2], word v %define rect_a_W(v) mov [sdl_rect_a + 4], word v %define rect_a_H(v) mov [sdl_rect_a + 6], word v %define rect_b_X(v) mov [sdl_rect_b + 0], word v %define rect_b_Y(v) mov [sdl_rect_b + 2], word v %define rect_b_W(v) mov [sdl_rect_b + 4], word v %define rect_b_H(v) mov [sdl_rect_b + 6], word v section .bss ; a single SDL_Rect is 8 bytes. save space for a few sdl_rect_a: resb 8 sdl_rect_b: resb 8 ; SDL_Surface ptr screen: resq 1 screen_format: resq 1 section .data align 16 ; tree data : x y x y x y t1: dw 0, 30, -4, 20, 4, 20 t2: dw -2, 20, 2, 20, -7, 10 t3: dw 2, 20, -7, 10, 7, 10 t4: dw -5, 10, 5, 10, -10, 0 t5: dw 5, 10, -10, 0, 10, 0 t_none: ; road data : x y x y x y road1: dw 350, 300, 450, 300, 300, 600 road2: dw 450, 300, 300, 600, 500, 600 r_none: _320: dd 320.0 _550: dd 550.0 _615: dd 615.0 _250: dd 250.0 _185: dd 185.0 align 16 draw_tree: push rbp mov rbp, rsp ; rdi : x ; rsi : y ; edx : color ; need some space for locals sub rsp, 64 ; store our arguments where we can get them easily mov qword [rsp + 16], rdi ; X mov qword [rsp + 24], rsi ; Y mov qword [rsp + 32], rdx ; color ; ; filledTrigonColor ; rdi : SDL_Surface ptr ; rsi : x1 ; rdx : y1 ; rcx : x2 ; r8 : y2 ; r9 : x3 ; push : y3 ; push : color ; (no padding needed) ; remove stack args after subroutine returns ; ; preserve that which needs preservation mov qword [rsp + 40], r14 mov qword [rsp + 48], r13 mov r14, qword t1 ; point to first triangle coord array draw_tree_loop: movsx rsi, word [r14 + 0] ; x1 movsx rdx, word [r14 + 2] ; y1 movsx rcx, word [r14 + 4] ; x2 movsx r8, word [r14 + 6] ; y2 movsx r9, word [r14 + 8] ; x3 <- last register arg to filledTrigonColor movsx r13, word [r14 + 10] ; y3 <- needs to be placed on the stack add r14, 12 ; advance to next triangle ; r14 is callee preserved ; y coords need to be negated neg rdx neg r8 neg r13 ; multiply everything by 2 shl rsi, 1 shl rdx, 1 shl rcx, 1 shl r8, 1 shl r9, 1 shl r13, 1 ; optimization... now thats a word I havent heard in a long time ; fetch the offset from its local storage mov r10, qword [rsp + 16] ; tmp Xoffset mov r11, qword [rsp + 24] ; tmp Yoffset add rsi, r10 ; x1 + Xoff add rdx, r11 ; y1 + Yoff add rcx, r10 ; x2 + Xoff add r8, r11 ; y2 + Yoff add r9, r10 ; x3 + Xoff add r13, r11 ; y3 + Yoff mov rdi, [screen] ; SDL_Surface ptr ; remaining arguments are passed on the stack in right-to-left ; order (so last arg is pushed first) push qword [rsp + 32] ; fetch and push the color (last argument) push r13 ; y3, needs to be on the stack (penultimate argument) call filledTrigonColor add rsp, 16 ; destroy temorary arguments to filledTrigonColor (y3 and color) cmp r14, t_none ; end of triangles jne draw_tree_loop ; loop through all triangles ; need to draw brown trunk of tree mov r10, qword [rsp + 16] ; X mov r11, qword [rsp + 24] ; Y sub r10, 4 ; apply small x offset to base inc r11 ; apply small y offset to base ; SDL_Rect describing the tree trunk rect_a_X(r10w) rect_a_Y(r11w) rect_a_H(10) rect_a_W(8) mov edi, dword [brown + 0] call draw_rect_a ; restore certain registers mov r14, qword [rsp + 40] mov r13, qword [rsp + 48] mov rsp, rbp pop rbp ret align 16 draw_stage: sub rsp, 24 ; set the background rect_b_X(0) rect_b_Y(0) rect_b_H(600) rect_b_W(800) mov edi, dword [gray] call draw_rect_b ; rdi, rsi, rdx, rcx, r8, r9 ; draw the sunrise mov rdi, [screen] mov si, 400 mov dx, 375 mov cx, 150 mov r8d, dword [gold + 4] call filledCircleColor ; draw the foreground rect_b_X(0) rect_b_Y(300) rect_b_H(300) rect_b_W(800) mov edi, dword [silver] call draw_rect_b ; draw the road in the center mov rdi, [screen] movsx rsi, word [road1 + 0] ; x1 movsx rdx, word [road1 + 2] ; y1 movsx rcx, word [road1 + 4] ; x2 movsx r8, word [road1 + 6] ; y2 movsx r9, word [road1 + 8] ; x3 <- last register arg to filledTrigonColor movsx r13, word [road1 + 10] ; y3 <- needs to be placed on the stack push qword [black + 4] ; color push r13 ; y3 call filledTrigonColor add rsp, 16 ; readjust stack ; second triangle for road mov rdi, [screen] movsx rsi, word [road2 + 0] ; x1 movsx rdx, word [road2 + 2] ; y1 movsx rcx, word [road2 + 4] ; x2 movsx r8, word [road2 + 6] ; y2 movsx r9, word [road2 + 8] ; x3 <- last register arg to filledTrigonColor movsx r13, word [road2 + 10] ; y3 <- needs to be placed on the stack push qword [black + 4] ; color push r13 ; y3 call filledTrigonColor add rsp, 16 ; readjust stack ; draw lines on the side of the road ; ; lineColor() ; rdi : SDL_Surface ptr ; rsi : x1 ; rdx : y1 ; rcx : x2 ; r8 : y2 ; r9 : color ; ; left hand line mov rdi, [screen] mov si, 360 ; x1 mov dx, 300 ; y1 (centerline) mov cx, 320 ; x2 mov r8w, 600 ; y2 (bottom) mov r9d, [white + 4] call lineColor ; right hand line mov rdi, [screen] mov si, 440 ; x1 mov dx, 300 ; y1 (centerline) mov cx, 480 ; x2 mov r8w, 600 ; y2 (bottom) mov r9d, [white + 4] call lineColor ; calculate the offset used to draw the center lines in the road mov eax, [ticks] shr eax, 3 ; divide by 8 xor edx, edx ; yeah...division on AMD64 is not pretty mov ebx, 80 ; setup the divisor (because there is no div imm) div ebx ; eax=quotient, edx=remainder mov eax, edx ; overwrite the quotient with le remainder add eax, 300 ; start in the center ; draw a bunch of lines in the center of the road mov qword [rsp], rax add rax, 400 ; enough for 4 lines mov qword [rsp + 8], rax ; used for loop termination later mov rax, [rsp] ; get correct offset value center_line_loop: rect_b_X(398) rect_b_Y(ax) rect_b_H(50) rect_b_W(4) mov edi, [white] call draw_rect_b mov rax, qword [rsp] ; restore rax add rax, 80 ; go to next iteration mov qword [rsp], rax ; update stored loop value cmp rax, qword [rsp + 8] ; test against termination value jne center_line_loop ; repeat until termination ; draw some trees! xor rdi, rdi ; offset=0 xor rsi, rsi ; left=0 call draw_tree_w_offset mov rdi, 160 ; offset=160 xor rsi, rsi ; left=0 call draw_tree_w_offset mov rdi, 80 ; offset=80 mov rsi, 1 ; right=1 call draw_tree_w_offset mov rdi, 240 ; offset=240 mov rsi, 1 ; right=1 call draw_tree_w_offset add rsp, 24 ret align 16 draw_tree_w_offset: sub rsp, 8 ; ; rdi : local offset ; rsi : 0=left, 1=right ; mov eax, [ticks] shr eax, 3 add eax, edi ; given deg offset from 'normal' xor edx, edx ; need to zero this register mov ebx, 320 ; divisor div ebx ; eax=quotient, edx=remainder mov eax, edx ; get the remainder cmp rsi, 0 jne map_right_side ; use linearmap to place trees at correct places cvtsi2ss xmm0, eax ; x xorps xmm1, xmm1 ; x_begin, place 0.0f in xmm1 movss xmm2, [_320] ; x_end, 300 movss xmm3, [_250] ; y_begin movss xmm4, [_185] ; y_end call linearmap jmp mapping_done map_right_side: cvtsi2ss xmm0, eax ; x xorps xmm1, xmm1 ; x_begin, place 0.0f in xmm1 movss xmm2, [_320] ; x_end, 300 movss xmm3, [_550] ; y_begin movss xmm4, [_615] ; y_end call linearmap mapping_done: ; place x,y,color and call draw_tree cvttss2si edi, xmm0 ; mapped value is in xmm0 mov esi, eax ; y add esi, 300 ; y+300 to put in bottom half of screen mov edx, [green + 4] ; this is useless but i dont want to rewrite draw_tree call draw_tree add rsp, 8 ret align 16 draw_rect_a: ; quick way to align stack sub rsp, 8 ; ; rdi : color of rectangle ; mov rdx, rdi mov rdi, [screen] mov rsi, sdl_rect_a call SDL_FillRect add rsp, 8 ret align 16 draw_rect_b: sub rsp, 8 mov rdx, rdi mov rdi, [screen] mov rsi, sdl_rect_b call SDL_FillRect add rsp, 8 ret
; WMAN colours basic procedures V1.04  2002 Marcel Kilgus ; ; 2003-05-27 1.01 Changed routines to always use sys_clnk to get WMAN vec (MK) ; Added WM_MOVEMODE (WL/MK) ; 2003-09-05 1.02 Fixed WM_BLOCK (GG/MK) ; 2013-04-28 1.03 Added WM_MOVEALPHA (wl) ; 2018-04-08 1.04 Mini-optimisations (mk) section wm_ext xdef wm_paper xdef wm_ink xdef wm_strip xdef wm_block xdef wm_border xdef wm_movemode xdef wm_movealpha xdef sp_reset xdef sp_set xdef sp_get xdef sp_getcount xdef sp_jobpal xdef sp_jobownpal xref ut_chan1 xref ut_rtint xref ut_gtint xref ut_gtin1 xref ut_gtlin xref ut_gxli1 xref ut_gxli2 xref ut_gtnm1 xref ut_fjob include 'dev8_keys_wman_data' include 'dev8_keys_qdos_sms' include 'dev8_keys_qdos_io' include 'dev8_keys_con' include 'dev8_keys_wman' include 'dev8_keys_sys' include 'dev8_keys_err' include 'dev8_keys_sbasic' ;+++ ; WM_PAPER (#ch,) colour ;--- wm_paper bsr wm_getwman jsr ut_chan1 ; get a channel id bne.s wm_rts jsr ut_gxli1 bne.s wm_rts moveq #iow.spap,d0 move.l (a6,a1.l),d1 move.l d1,d7 moveq #-1,d3 jsr wm.trap3(a2) bne.s wm_rts moveq #iow.sstr,d0 move.l d7,d1 jmp wm.trap3(a2) ;+++ ; WM_INK (#ch,) colour ;--- wm_ink moveq #iow.sink,d7 bra.s wm_setcolour ;+++ ; WM_STRIP (#ch,) colour ;--- wm_strip moveq #iow.sstr,d7 wm_setcolour bsr wm_getwman jsr ut_chan1 ; get a channel id bne.s wm_rts jsr ut_gxli1 bne.s wm_rts move.l d7,d0 move.l (a6,a1.l),d1 moveq #-1,d3 jsr wm.trap3(a2) wm_rts rts ;+++ ; WM_BLOCK (#ch,) xs, ys, xo, yo, col ;--- wm_block bsr wm_getwman jsr ut_chan1 ; get a channel id bne.s wm_rts subq.l #8,a5 cmpa.l a3,a5 ble wm_ipar jsr ut_gtint cmp.w #4,d3 bne wm_ipar lea 4*8(a3),a3 addq.l #8,a5 jsr ut_gxli1 bne.s wm_rts moveq #iow.blok,d0 move.l (a6,a1.l),d1 moveq #-1,d3 lea 4(a6,a1.l),a1 jmp wm.trap3(a2) ;+++ ; WM_BORDER (#ch,) width, colour ;--- wm_border bsr wm_getwman jsr ut_chan1 ; get a channel id bne.s wm_rts jsr ut_gxli2 bne.s wm_rts moveq #iow.defb,d0 move.l 4(a6,a1.l),d1 move.l (a6,a1.l),d2 moveq #-1,d3 jmp wm.trap3(a2) ;+++ ; WM_MOVEMODE move_type% (0..3) ;--- wm_movemode bsr wm_getwdata jsr ut_gtin1 ; get one int bne.s wm_rts move.w (a6,a1.l),d0 blt.s wm_ipar ; and it must be between 0... cmp.w #3,d0 ; ... and 2 bgt.s wm_ipar move.b d0,wd_movemd(a2) clr.l d0 rts ;+++ ; WM_MOVEALPHA move_alpha% (0..255) ;--- wm_movealpha bsr wm_getwdata jsr ut_gtin1 ; get one int bne.s alp_rts move.w (a6,a1.l),d0 move.b d0,wd_alpha(a2) clr.l d0 alp_rts rts ;+++ ; SP_RESET (no) ;--- sp_reset bsr wm_getwman ; get WMAN vector moveq #0,d4 ; default to palette 0 jsr ut_gtint cmp.w #1,d3 ; max 1 parameter bhi.s wm_ipar tst.w d3 beq.s spr_nonum move.w (a6,a1.l),d4 ; palette number spr_nonum move.l d4,d3 moveq #0,d1 moveq #-1,d2 suba.l a1,a1 jsr wm.getsp(a2) jmp wm.setsp(a2) wm_ipar moveq #err.ipar,d0 sp_rts rts ;+++ ; SP_GETCOUNT ;--- sp_getcount bsr wm_getwman cmpa.l a3,a5 bne.s wm_ipar moveq #-1,d2 jsr wm.getsp(a2) move.w d2,d1 jmp ut_rtint ;+++ ; SP_GET (no,) adr, first, count ;--- sp_get bsr.s wm_getwman moveq #0,d4 ; default to palette 0 jsr ut_gtlin cmp.w #3,d3 beq.s spg_nonum cmp.w #4,d3 bne.s wm_ipar move.l (a6,a1.l),d4 ; given palette number addq.l #4,a1 spg_nonum move.l d4,d3 move.l 4(a6,a1.l),d1 move.l 8(a6,a1.l),d2 move.l (a6,a1.l),a1 jmp wm.getsp(a2) ;+++ ; SP_SET (no,) adr, first, count ;--- sp_set bsr.s wm_getwman moveq #0,d4 ; default to palette 0 jsr ut_gtlin cmp.w #3,d3 beq.s sps_nonum cmp.w #4,d3 bne.s wm_ipar move.l (a6,a1.l),d4 ; given palette number addq.l #4,a1 sps_nonum move.l d4,d3 move.l 4(a6,a1.l),d1 move.l 8(a6,a1.l),d2 move.l (a6,a1.l),a1 jmp wm.setsp(a2) ;+++ ; SP_JOBPAL job id / job name, no ;--- sp_jobpal bsr.s wm_getwman bsr.s job_proc bne.s wm_rts2 move.l d2,d3 suba.l a1,a1 jmp wm.jbpal(a2) ;+++ ; SP_JOBOWNPAL job id / job name, ptr to palette ;--- sp_jobownpal bsr.s wm_getwman bsr.s job_proc bne.s wm_rts2 move.l d2,a1 moveq #-1,d3 jmp wm.jbpal(a2) ;+++ ; Get WMAN vector in a2 ;--- wm_getwman movem.l d1-d3/a0,-(sp) moveq #sms.info,d0 trap #1 move.l sys_clnk(a0),a2 move.l pt_wman(a2),a2 movem.l (sp)+,d1-d3/a0 wm_rts2 rts ;+++ ; Get WMAN data ptr in a2 ;--- wm_getwdata movem.l d1-d3/a0,-(sp) moveq #sms.info,d0 trap #1 move.l sys_clnk(a0),a2 move.l pt_wdata(a2),a2 movem.l (sp)+,d1-d3/a0 rts ;+++ ; Get job ID from supplied parameter(s) ;--- job_proc moveq #8,d5 get 2 parameters (8 bytes) * cmp.l a3,a5 must be some parameters beq.s job_bp tst.b (a6,a3.l) is it unused name? beq.s job_gtnm ... yes, get name moveq #$f,d0 and.b 1(a6,a3.l),d0 get variable type subq.b #1,d0 is it string? beq.s job_gtnm ... yes tst.w 2(a6,a3.l) any name? bmi.s job_gtln ... no, get long integers tst.w 4(a6,a3.l) any value? bpl.s job_gtln ... yes, get it job_gtnm move.l d5,d6 save number of parms bsr.l ut_gtnm1 get name bne.s job_rts ... oops addq.l #8,a3 move parameter pointer on * bsr.l ut_fjob find job bne.s job_rts ... oops * subq.l #8,a0 backspace a0 to base of job move.l d4,d1 set Job ID moveq #0,d2 no additional information cmp.l a3,a5 any more params? beq.s job_rts ... no subq.l #4,d6 was another param needed? beq.s job_bp ... no, bad bsr.l ut_gxli1 ... yes, one long integer bne.s job_rts addq.l #4,sb_arthp(a6) restore RI stack move.l d4,d1 reset job ID subq.l #4,a1 move RI stack pointer to ... bra.s job_parm ... set parameter * job_gtln bsr.l ut_gtlin get long integers bne.s job_rts ext.l d3 lsl.w #2,d3 make d3 number of bytes add.l d3,sb_arthp(a6) and restore RI stack pointer sub.w d5,d3 did we get the right number? blt.s job_bp too few beq.s job_id1 combined id subq.w #4,d3 was it number/tag? job_bp bne.l wm_ipar ... no move.l 6(a6,a1.l),d1 get tag in msw of d1 move.w 2(a6,a1.l),d1 and number in lsw addq.l #4,a1 move up a bit bra.s job_parm job_id1 move.l (a6,a1.l),d1 get job id job_parm move.l 4(a6,a1.l),d2 set parameter tst.l d0 job_rts rts end
; A240115: Schoenheim lower bound L(n,4,2). ; Submitted by Jamie Morken(s3) ; 1,3,3,4,6,7,8,11,12,13,18,19,20,26,27,29,35,37,39,46,48,50,59,61,63,73,75,78,88,91,94,105,108,111,124,127,130,144,147,151,165,169,173,188,192,196,213,217,221,239,243,248,266,271,276,295,300,305,326,331,336,358,363,369,391,397,403,426,432,438,463,469,475,501,507,514,540,547,554,581,588,595,624,631,638,668,675,683,713,721,729,760,768,776,809,817,825,859,867,876 mov $1,$0 add $0,5 div $0,3 add $1,4 mul $1,$0 add $1,27 div $1,4 mov $0,$1 sub $0,6
retornaCursor: CLR RS CLR P1.7 CLR P1.6 CLR P1.5 CLR P1.4 SETB EN CLR EN CLR P1.7 CLR P1.6 SETB P1.5 SETB P1.4 SETB EN CLR EN CALL delay RET
; A332757: Number of involutions (plus identity) in the n-fold iterated wreath product of C_2. ; Submitted by Christian Krause ; 1,2,6,44,2064,4292864,18430828806144,339695459704759501186924544,115393005344028056118476170527365821430429589033713664,13315545682326887517994506072805639054664915214679444711916992466809542959290217586307654871548759705124864 mul $0,2 mov $2,1 mov $3,1 lpb $0 sub $0,2 pow $2,2 add $2,$3 pow $3,2 mul $3,2 lpe mov $0,$2
; A005430: Apéry numbers: n*C(2*n,n). ; 0,2,12,60,280,1260,5544,24024,102960,437580,1847560,7759752,32449872,135207800,561632400,2326762800,9617286240,39671305740,163352435400,671560012200,2756930576400,11303415363240,46290177201840,189368906734800,773942488394400,3160265160943800,12893881856650704,52567364492499024,214163336821292320,871950728486690160,3547937446945842720,14428278950913093728,58643972510162897088,238241138322536769420,967403410158179609160,3926519723583199590120,15930451449966124051344,64606830880418169763784 mov $1,$0 mul $0,2 bin $0,$1 mul $0,$1
!ifndef is_main !eof .lvl1_start: ; insert player !byte CHOR_OP_MUS, <m_seeking, >m_seeking !byte CHOR_OP_SBG, t_square_id !pet CHOR_OP_CHR, 4, 4, "l" !pet CHOR_OP_SLP, $08 !pet CHOR_OP_CHR, 5, 4, "e" !pet CHOR_OP_SLP, $08 !pet CHOR_OP_CHR, 6, 4, "v" !pet CHOR_OP_SLP, $08 !pet CHOR_OP_CHR, 7, 4, "e" !pet CHOR_OP_SLP, $08 !pet CHOR_OP_CHR, 8, 4, "l" !pet CHOR_OP_SLP, $08 !pet CHOR_OP_CHR, 10, 4, "1" !pet CHOR_OP_SLP, $10 !pet CHOR_OP_CHR, 15, 5, "f" !pet CHOR_OP_SLP, $08 !pet CHOR_OP_CHR, 16, 5, "i" !pet CHOR_OP_SLP, $08 !pet CHOR_OP_CHR, 17, 5, "l" !pet CHOR_OP_SLP, $08 !pet CHOR_OP_CHR, 18, 5, "e" !pet CHOR_OP_SLP, $08 !pet CHOR_OP_CHR, 19, 5, "s" !pet CHOR_OP_SLP, $08 !pet CHOR_OP_CHR, 20, 5, "y" !pet CHOR_OP_SLP, $08 !pet CHOR_OP_CHR, 21, 5, "s" !pet CHOR_OP_SLP, $08 !pet CHOR_OP_CHR, 22, 5, "t" !pet CHOR_OP_SLP, $08 !pet CHOR_OP_CHR, 23, 5, "e" !pet CHOR_OP_SLP, $08 !pet CHOR_OP_CHR, 24, 5, "m" !byte CHOR_OP_SOT, $01 !byte CHOR_OP_SCR, $03 !byte CHOR_OP_SLP, $10 !byte CHOR_OP_SCR, $02 !byte CHOR_OP_SLP, $10 !byte CHOR_OP_SCR, $01 !byte CHOR_OP_SLP, $10 !byte CHOR_OP_SCR, $04 !byte CHOR_OP_SLP, $10 !byte CHOR_OP_SLP, $3C ; ; initial throw ; .lvl1_s1: !byte CHOR_OP_LDA, $06 !byte CHOR_OP_SPS, $18, $01 .lvl1_s1_lp: !byte CHOR_OP_INS, id_mov_incr, $02 !byte CHOR_OP_MPS, $10, $00 !byte CHOR_OP_INS, id_mov_incr, $03 !byte CHOR_OP_DEA !byte CHOR_OP_MPS, $10, $00 !byte CHOR_OP_SLP, $08 !byte CHOR_OP_JAN, <.lvl1_s1_lp, >.lvl1_s1_lp !pet CHOR_OP_PRD, 2,4, " ", PET_NULL !pet CHOR_OP_PRD, 15,5," ", PET_NULL !byte CHOR_OP_SLP, $78 ; ; spawn bullets making a static diagonal ; .lvl1_s2: !byte CHOR_OP_SPS, $20, $20 !byte CHOR_OP_LDA, $0B .lvl1_s2_lp: !byte CHOR_OP_BIS, 3 !byte id_mov_incr, $02 !byte id_mov_incr, $12 !byte id_mov_dcic, $12 !byte CHOR_OP_MPS, $10, $00 !byte CHOR_OP_DEA !byte CHOR_OP_SLP, $10 !byte CHOR_OP_JAN, <.lvl1_s2_lp, >.lvl1_s2_lp ; ; cut the screen with diagonals ; .lvl1_s3: !byte CHOR_OP_SPS, $02, $02 !byte CHOR_OP_LDA, $18 .lvl1_s3_lp: !byte CHOR_OP_BIS, 2 !byte id_mov_incr, $12 !byte id_mov_incr, $22 !byte CHOR_OP_JNH, <.lvl1_s3_md, >.lvl1_s3_md !byte CHOR_OP_SPS, $E6, $02 !byte CHOR_OP_BIS, 2 !byte id_mov_dcic, $12 !byte id_mov_dcic, $22 !byte CHOR_OP_SPS, $02, $02 .lvl1_s3_md: !byte CHOR_OP_DEA !byte CHOR_OP_SLP, $10 !byte CHOR_OP_JAN, <.lvl1_s3_lp, >.lvl1_s3_lp ; ; "explosions" in the center ; .lvl1_s4: !byte CHOR_OP_SPS, $6F, $20 !byte CHOR_OP_LDA, $08 !byte CHOR_OP_JNH, <.lvl1_s4_lp, >.lvl1_s4_lp ; \_ hard mode: double number of explosions !byte CHOR_OP_LDA, $10 ; / .lvl1_s4_lp: !byte CHOR_OP_JNH, <.lvl1_s4_exp, >.lvl1_s4_exp ; \ !byte CHOR_OP_JRN, <.lvl1_s4_h_plus, >.lvl1_s4_h_plus ; |- hard mode ; .lvl1_s4_h_minus: ; | !byte CHOR_OP_MPS, $F1, $00 ; |> x-15 !byte CHOR_OP_JMP, <.lvl1_s4_exp, >.lvl1_s4_exp ; | .lvl1_s4_h_plus: ; | !byte CHOR_OP_FPS, $F0 ; |> x+15 ; / .lvl1_s4_exp: !byte CHOR_OP_BIS, 6 !byte id_mov_dcic, $40 !byte id_mov_dcic, $31 !byte id_mov_dcic, $22 !byte id_mov_dcic, $13 !byte id_mov_dcic, $04 !byte id_mov_incr, $13 !byte CHOR_OP_BIS, 6 !byte id_mov_incr, $22 !byte id_mov_incr, $31 !byte id_mov_incr, $40 !byte id_mov_decr, $40 !byte id_mov_decr, $31 !byte id_mov_decr, $22 !byte CHOR_OP_BIS, 6 !byte id_mov_decr, $13 !byte id_mov_decr, $04 !byte id_mov_icdc, $13 !byte id_mov_icdc, $22 !byte id_mov_icdc, $31 !byte id_mov_icdc, $40 !byte CHOR_OP_DEA !byte CHOR_OP_SLP, $10 !byte CHOR_OP_JHM, <.lvl1_s4_endlp, >.lvl1_s4_endlp ; \ !byte CHOR_OP_SLP, $10 ; |- hard mode: sleep half time .lvl1_s4_endlp: ; / !byte CHOR_OP_JAN, <.lvl1_s4_lp, >.lvl1_s4_lp !byte CHOR_OP_SLP, $30 !byte CHOR_OP_LDA, $08 .lvl1_s4_blk: !pet CHOR_OP_PRD, 2,4, "virus located", PET_NULL !byte CHOR_OP_SLP, $10 !pet CHOR_OP_PRD, 2,4, " ", PET_NULL !byte CHOR_OP_SLP, $10 !byte CHOR_OP_DEA !byte CHOR_OP_JAN, <.lvl1_s4_blk, >.lvl1_s4_blk !byte CHOR_OP_SCR, $07 ; ; flying, slow ; .lvl1_s5: !byte CHOR_OP_SPS, $00, $01 !byte CHOR_OP_LDA, $20 !byte CHOR_OP_JNH, <.lvl1_s5_lp, >.lvl1_s5_lp ; \_ hard mode: double number of explosions !byte CHOR_OP_LDA, $40 ; / .lvl1_s5_lp: !byte CHOR_OP_SRX !byte CHOR_OP_INS, id_mov_incr, $04 !byte CHOR_OP_DEA !byte CHOR_OP_SLP, $08 !byte CHOR_OP_JHM, <.lvl1_s5_endlp, >.lvl1_s5_endlp ; \ !byte CHOR_OP_SLP, $08 ; |- hard mode: sleep half time .lvl1_s5_endlp: ; / !byte CHOR_OP_JAN, <.lvl1_s5_lp, >.lvl1_s5_lp !byte CHOR_OP_SCR, $06 !byte CHOR_OP_SLP, $08 !byte CHOR_OP_SCR, $05 !byte CHOR_OP_SLP, $08 !byte CHOR_OP_CMO, $02, $7D, id_mov_incr, $05 !byte CHOR_OP_SCR, $08 ; ; flying, faster ; .lvl1_s6: !byte CHOR_OP_SPS, $00, $01 !byte CHOR_OP_LDA, $20 .lvl1_s6_lp: !byte CHOR_OP_SRX !byte CHOR_OP_INS, id_mov_incr, $05 !byte CHOR_OP_DEA !byte CHOR_OP_SLP, $0B !byte CHOR_OP_JAN, <.lvl1_s6_lp, >.lvl1_s6_lp !byte CHOR_OP_SCR, $0B !byte CHOR_OP_SLP, $08 !byte CHOR_OP_SCR, $0A !byte CHOR_OP_SLP, $08 !byte CHOR_OP_SCR, $09 !byte CHOR_OP_SLP, $08 !byte CHOR_OP_CMO, $02, $7D, id_mov_incr, $07 !byte CHOR_OP_SCR, $0C ; ; flying, fastest ; .lvl1_s7: !byte CHOR_OP_SPS, $00, $01 !byte CHOR_OP_LDA, $20 !byte CHOR_OP_JNH, <.lvl1_s7_lp, >.lvl1_s7_lp ; \_ hard mode: double number of explosions !byte CHOR_OP_LDA, $40 ; / .lvl1_s7_lp: !byte CHOR_OP_SRX !byte CHOR_OP_INS, id_mov_incr, $07 !byte CHOR_OP_DEA !byte CHOR_OP_SLP, $04 !byte CHOR_OP_JHM, <.lvl1_s7_endlp, >.lvl1_s7_endlp ; \ !byte CHOR_OP_SLP, $04 ; |- hard mode: sleep half time .lvl1_s7_endlp: ; / !byte CHOR_OP_JAN, <.lvl1_s7_lp, >.lvl1_s7_lp !byte CHOR_OP_SCR, $0F !byte CHOR_OP_SLP, $08 !byte CHOR_OP_SCR, $0E !byte CHOR_OP_SLP, $08 !byte CHOR_OP_SCR, $0D !byte CHOR_OP_SLP, $08 !byte CHOR_OP_CMO, $02, $7D, id_mov_incr, $0B !byte CHOR_OP_SCR, $10 ; ; flying, max speed ; .lvl1_s8: !byte CHOR_OP_SPS, $00, $01 !byte CHOR_OP_LDA, $30 .lvl1_s8_lp: !byte CHOR_OP_SRX !byte CHOR_OP_INS, id_mov_incr, $0B !byte CHOR_OP_DEA !byte CHOR_OP_SLP, $04 !byte CHOR_OP_JAN, <.lvl1_s8_lp, >.lvl1_s8_lp !byte CHOR_OP_SLP, $7C ; ; boss ; .lvl1_boss1: !pet CHOR_OP_PRT, 2,4, <lvl1_str_warning, >lvl1_str_warning !byte CHOR_OP_SCR, $0D !byte CHOR_OP_SLP, $10 !byte CHOR_OP_SCR, $0E !byte CHOR_OP_SLP, $10 !byte CHOR_OP_SCR, $0F !byte CHOR_OP_SLP, $10 !byte CHOR_OP_SCR, $08 !byte CHOR_OP_SLP, $10 !pet CHOR_OP_PRT, 2,4, <lvl1_str_clr_warning, >lvl1_str_clr_warning !byte CHOR_OP_SCR, $05 !byte CHOR_OP_SLP, $10 !byte CHOR_OP_SCR, $06 !byte CHOR_OP_SLP, $10 !byte CHOR_OP_SCR, $07 !byte CHOR_OP_SLP, $10 !byte CHOR_OP_SCR, $04 !byte CHOR_OP_SLP, $10 !pet CHOR_OP_PRT, 2,4, <lvl1_str_warning, >lvl1_str_warning !byte CHOR_OP_SCR, $01 !byte CHOR_OP_SLP, $10 !byte CHOR_OP_SCR, $02 !byte CHOR_OP_SLP, $10 !byte CHOR_OP_SCR, $03 !byte CHOR_OP_SLP, $10 !byte CHOR_OP_SCR, $00 !byte CHOR_OP_SLP, $10 !byte CHOR_OP_MOJ, $01, $6D, $00 !byte CHOR_OP_COJ, $01, id_mov_incr, $01 !byte CHOR_OP_MUS, <m_cowardmenace, >m_cowardmenace !pet CHOR_OP_PRT, 2,4, <lvl1_str_clr_warning, >lvl1_str_clr_warning !byte CHOR_OP_SLP, $40 !byte CHOR_OP_COJ, $01, id_mov_incr, $00 !pet CHOR_OP_PRT, 2,4, <lvl1_str_warning, >lvl1_str_warning !byte CHOR_OP_SLP, $40 !pet CHOR_OP_PRT, 2,4, <lvl1_str_clr_warning, >lvl1_str_clr_warning !byte CHOR_OP_SLP, $20 !byte CHOR_OP_COJ, $01, id_mov_bcir, $00 !byte CHOR_OP_SLP, $3C !byte CHOR_OP_LDA, $02 !byte CHOR_OP_LDC, $0D .lvl1_boss1_lp: !byte CHOR_OP_SPR, $02, $7D, bullet_glitch1_spid !byte CHOR_OP_SPS, $08, $10 !byte CHOR_OP_BIS, 3 !byte id_mov_incr, $22 !byte id_mov_incr, $31 !byte id_mov_incr, $13 !byte CHOR_OP_SPS, $D9, $10 !byte CHOR_OP_BIS, 3 !byte id_mov_dcic, $22 !byte id_mov_dcic, $31 !byte id_mov_dcic, $13 !byte CHOR_OP_SPS, $08, $60 !byte CHOR_OP_BIS, 2 !byte id_mov_incr, $22 !byte id_mov_icdc, $22 !byte CHOR_OP_SPS, $D9, $60 !byte CHOR_OP_BIS, 2 !byte id_mov_dcic, $22 !byte id_mov_decr, $22 !byte CHOR_OP_SPS, $08, $D0 !byte CHOR_OP_BIS, 3 !byte id_mov_icdc, $22 !byte id_mov_icdc, $31 !byte id_mov_icdc, $13 !byte CHOR_OP_SPS, $D9, $D0 !byte CHOR_OP_BIS, 3 !byte id_mov_decr, $22 !byte id_mov_decr, $31 !byte id_mov_decr, $13 !byte CHOR_OP_JNH, <.lvl1_boss1_skip_exp, >.lvl1_boss1_skip_exp !byte CHOR_OP_SEK, $01 !byte CHOR_OP_BIS, 6 !byte id_mov_dcic, $40 !byte id_mov_dcic, $31 !byte id_mov_dcic, $22 !byte id_mov_dcic, $13 !byte id_mov_dcic, $04 !byte id_mov_incr, $13 !byte CHOR_OP_BIS, 6 !byte id_mov_incr, $22 !byte id_mov_incr, $31 !byte id_mov_incr, $40 !byte id_mov_decr, $40 !byte id_mov_decr, $31 !byte id_mov_decr, $22 !byte CHOR_OP_BIS, 6 !byte id_mov_decr, $13 !byte id_mov_decr, $04 !byte id_mov_icdc, $13 !byte id_mov_icdc, $22 !byte id_mov_icdc, $31 !byte id_mov_icdc, $40 .lvl1_boss1_skip_exp: !byte CHOR_OP_LDB, $04 !byte CHOR_OP_SPS, $00, $02 .lvl1_boss1_lp2: !byte CHOR_OP_SLP, $20 !byte CHOR_OP_SPR, $02, $7D, bullet_glitch2_spid !byte CHOR_OP_SRX !byte CHOR_OP_DEA !byte CHOR_OP_DEB !byte CHOR_OP_JAZ, <.lvl1_boss1_diag, >.lvl1_boss1_diag !byte CHOR_OP_DEC !byte CHOR_OP_JCZ, <.lvl1_boss1_end, >.lvl1_boss1_end !byte CHOR_OP_INS, id_mov_incr, $02 !byte CHOR_OP_JBN, <.lvl1_boss1_lp2, >.lvl1_boss1_lp2 !byte CHOR_OP_JMP, <.lvl1_boss1_lp, >.lvl1_boss1_lp ; ;; ; !byte CHOR_OP_JMP, <.lvl1_s2, >.lvl1_s2 .lvl1_boss1_diag: !byte CHOR_OP_INS, id_mov_incr, $13 !byte CHOR_OP_INS, id_mov_dcic, $13 !byte CHOR_OP_LDA, $02 !byte CHOR_OP_JBN, <.lvl1_boss1_lp2, >.lvl1_boss1_lp2 !byte CHOR_OP_JMP, <.lvl1_boss1_lp, >.lvl1_boss1_lp .lvl1_boss1_end: !byte CHOR_OP_SOT, $00 !byte CHOR_OP_COJ, $01, id_mov_incr, $02 !byte CHOR_OP_SLP, $20 !byte CHOR_OP_COJ, $01, id_mov_rng, $00 !byte CHOR_OP_SLP, $90 !byte CHOR_OP_SPR, $01, $01, virus2_spid !byte CHOR_OP_SLP, $10 !byte CHOR_OP_COJ, $01, id_mov_incr, $00 !byte CHOR_OP_SLP, $3C !byte CHOR_OP_COJ, $01, id_mov_decr, $02 !byte CHOR_OP_SLP, $3C !pet CHOR_OP_PRD, 2,4,"level cleared!", PET_NULL !byte CHOR_OP_SLP, $3C !pet CHOR_OP_PRD, 2,5,"bonus: 1000 pts", PET_NULL !byte CHOR_OP_SLP, $18 !pet CHOR_OP_PRD, 2,6," +1 life!", PET_NULL !byte CHOR_OP_LIF !byte CHOR_OP_SCO, $00, $10, $00 !byte CHOR_OP_SLP, $72 !pet CHOR_OP_PRD, 2,7,"remaining: 80%", PET_NULL !byte CHOR_OP_SLP, $72 !pet CHOR_OP_PRT, 2,4, <lvl1_str_clr_ending, >lvl1_str_clr_ending !pet CHOR_OP_PRT, 2,5, <lvl1_str_clr_ending, >lvl1_str_clr_ending !pet CHOR_OP_PRT, 2,6, <lvl1_str_clr_ending, >lvl1_str_clr_ending !pet CHOR_OP_PRT, 2,7, <lvl1_str_clr_ending, >lvl1_str_clr_ending ; --- end of lvl1
; CRT0 stub for the Old School Computer Architecture (FLOS) ; ; Stefano Bodrato - Jul. 2011 ; ; ; EXTRA OPTIONS: ; ; At C source level: ; #pragma output osca_bank=(0..14) set the memory bank for locations > 32768 before loading program ; #pragma output osca_stack=<value> put the stack in a differen place, i.e. 32767 ; #pragma output nostreams - No stdio disc files ; #pragma output noredir - do not insert the file redirection option while parsing the ; command line arguments (useless if "nostreams" is set) ; #pragma output osca_notimer - Save very few bytes and excludes the clock handling, ; thus disabling those functions connected to time.h ; #pragma output osca_restoretxt - works only with FLOS > v547, restores the text mode on program exit ; ; At compile time: ; -zorg=<location> parameter permits to specify the program position ; ; $Id: osca_crt0.asm,v 1.38 2016/07/15 21:38:08 dom Exp $ ; MODULE osca_crt0 ; ; Initially include the zcc_opt.def file to find out lots of lovely ; information about what we should do.. ; defc crt0 = 1 INCLUDE "zcc_opt.def" ; No matter what set up we have, main is always, always external to ; this file EXTERN _main ; ; Some variables which are needed for both app and basic startup ; PUBLIC cleanup PUBLIC l_dcal ; FLOS system variables PUBLIC sector_lba0 ; keep this byte order PUBLIC sector_lba1 PUBLIC sector_lba2 PUBLIC sector_lba3 PUBLIC a_store1 PUBLIC bc_store1 PUBLIC de_store1 PUBLIC hl_store1 PUBLIC a_store2 PUBLIC bc_store2 PUBLIC de_store2 PUBLIC hl_store2 PUBLIC storeix PUBLIC storeiy PUBLIC storesp PUBLIC storepc PUBLIC storef PUBLIC store_registers PUBLIC com_start_addr PUBLIC cursor_y ;keep this byte order PUBLIC cursor_x ;(allows read as word with y=LSB) PUBLIC current_scancode PUBLIC current_asciicode ;-------- ; OSCA / FLOS specific definitions ;-------- INCLUDE "flos.def" INCLUDE "osca.def" ; Now, getting to the real stuff now! ;-------- ; Set an origin for the application (-zorg=) default to $5000 ;-------- IF !DEFINED_CRT_ORG_CODE defc CRT_ORG_CODE = $5000 ENDIF IF ((CRT_ORG_CODE = $5000) | (!DEFINED_osca_bank)) org CRT_ORG_CODE ELSE ; optional Program Location File Header org CRT_ORG_CODE defb $ed defb $00 jr start defw CRT_ORG_CODE IF DEFINED_osca_bank defb osca_bank ELSE defb 0 ENDIF defb $00 ; control byte: 1=truncate basing on next 3 bytes ;defw 0 ; Load length 15:0 only needed if truncate flag is set ;defb 0 ; Load length ..bits 23:16, only needed if truncate flag is set ENDIF start: di ld b,h ld c,l ld hl,0 add hl,sp ld (start1+1),hl IF (!DEFINED_osca_stack) ld sp,-64 ELSE ld sp,osca_stack ENDIF ;ld sp,$7FFF push bc call crt0_init_bss pop bc ld (exitsp),sp push bc ; keep ptr to arg list ; 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 IF (!DEFINED_osca_notimer) ld hl,(FLOS_irq_vector) ; The label "irq_vector" = $A01 (contained in equates file) ld (original_irq_vector),hl ; Store the original FLOS vecotr for restoration later. ld hl,my_custom_irq_handler ld (FLOS_irq_vector),hl ld a,@10000111 ; Enable keyboard, mouse and timer interrupts out (sys_irq_enable),a ld a,250 neg out (sys_timer),a ld a,@00000100 out (sys_clear_irq_flags),a ; Clear the timer IRQ flag ELSE ld b,255 .v_srand_loop ld hl,FLOSvarsaddr add (hl) ld (FRAMES),a inc hl djnz v_srand_loop ENDIF ei ; Push pointers to argv[n] onto the stack now ; We must start from the end pop hl ; command line back again ld bc,0 ld a,(hl) and a jr z,argv_done dec hl find_end: inc hl inc c ld a,(hl) and a jr nz,find_end dec hl INCLUDE "crt0_command_line.asm" IF DEFINED_Z88DK_USES_SDCC push hl ;argv push bc ;argc ELSE push bc ;argc push hl ;argv ENDIF call _main ;Call user code pop bc ;kill argv pop bc ;kill argc cleanup: ; ; Deallocate memory which has been allocated here! ; push hl ;save exit value IF !DEFINED_nostreams EXTERN closeall call closeall ENDIF ; kjt_flos_display restores the text mode but makes the screen flicker ; if it is in text mode already ; IF (DEFINED_osca_restoretxt) call $10c4 ; kjt_flos_display (added in v547) ENDIF IF (!DEFINED_osca_notimer) di ld hl,(original_irq_vector) ld (FLOS_irq_vector),hl ld a,@10000011 ; Enable keyboard and mouse interrupts only out (sys_irq_enable),a ei ENDIF pop hl ; restore exit value start1: ld sp,0 xor a or h ; ATM we are not mamaging the 'spawn' exception jr nz,cmdok ld l,a cmdok: ld a,l ; return code (lowest byte only) and a ; set Z flag to set the eventual error condition ;xor a ; (set A and flags for RESULT=OK) ret l_dcal: jp (hl) IF (!DEFINED_osca_notimer) ; ---------------------------------- ; Custom Interrupt handlers ; ---------------------------------- my_custom_irq_handler: push af in a,(sys_irq_ps2_flags) bit 0,a call nz,kjt_keyboard_irq_code ; Kernal keyboard irq handler bit 1,a call nz,kjt_mouse_irq_code ; Kernal mouse irq handler bit 2,a call nz,my_timer_irq_code ; User's timer irq handler pop af ei reti my_timer_irq_code: push af ; (do whatever, push/pop registers!) push hl ; ld hl,(frames_pre) ; inc (hl) ; ld a,(hl) ; bit 4,a ; jr nz,timer_irq_count_done ld hl,(FRAMES) inc hl ld (FRAMES),hl ;;ld (palette),hl ; testing purposes ld a,h or l jr nz,timer_irq_count_done ld hl,(FRAMES+2) inc hl ld (FRAMES+2),hl timer_irq_count_done: ld a,@00000100 out (sys_clear_irq_flags),a ; Clear the timer IRQ flag pop hl pop af ret ENDIF SECTION bss_crt PUBLIC FRAMES original_irq_vector: defw 0 FRAMES: defw 0 defw 0 defm "Small C+ OSCA" end: defb 0 ;-------------------------------------------------------------------------------------------- ; ; OS_variables location as defined in system_equates.asm ; FLOSv582 sets it to $B00, hopefully it won't change much ; but we keep the option for making it dynamic ; ;-------------------------------------------------------------------------------------------- IF !DEFINED_FLOSvarsaddr defc FLOSvarsaddr = $B00 ENDIF ;-------------------------------------------------------------------------------------------- DEFVARS FLOSvarsaddr { sector_lba0 ds.b 1 ; keep this byte order sector_lba1 ds.b 1 sector_lba2 ds.b 1 sector_lba3 ds.b 1 a_store1 ds.b 1 bc_store1 ds.b 2 de_store1 ds.b 2 hl_store1 ds.b 2 a_store2 ds.b 1 bc_store2 ds.b 2 de_store2 ds.b 2 hl_store2 ds.b 2 storeix ds.b 2 storeiy ds.b 2 storesp ds.b 2 storepc ds.b 2 storef ds.b 1 store_registers ds.b 1 com_start_addr ds.w 1 cursor_y ds.b 1 ;keep this byte order cursor_x ds.b 1 ;(allows read as word with y=LSB) current_scancode ds.b 1 current_asciicode ds.b 1 ; The other variable positions depend on the FLOS version ; .. } ;-------------------------------------------------------------------------------------------- INCLUDE "crt0_runtime_selection.asm" INCLUDE "crt0_section.asm" SECTION code_crt_init ld hl,$2000 ld (base_graphics),hl SECTION rodata_clib IF !DEFINED_noredir IF !DEFINED_nostreams redir_fopen_flag: defb 'w',0 redir_fopen_flagr: defb 'r',0 ENDIF ENDIF ; SD CARD interface IF DEFINED_NEED_SDCARD SECTION bss_crt PUBLIC card_select PUBLIC sd_card_info PUBLIC sector_buffer_loc ; Keep the following 2 bytes in the right order (1-card_select, 2-sd_card_info) !!! card_select: defb 0 ; Currently selected MMC/SD slot sd_card_info: defb 0 ; Card type flags.. sector_buffer_loc: defw 0 sector_buffer: defs 513 SECTION code_crt_init ld hl,sector_buffer ld (sector_buffer_loc),hl ENDIF
; A266395: Number of orbits of Aut(Z^7) as function of the infinity norm n of the representative lattice point of the orbit, when the cardinality of the orbit is equal to 161280. ; 0,0,0,0,15,75,225,525,1050,1890,3150,4950,7425,10725,15015,20475,27300,35700,45900,58140,72675,89775,109725,132825,159390,189750,224250,263250,307125,356265,411075,471975,539400,613800,695640,785400,883575,990675,1107225,1233765,1370850,1519050,1678950,1851150,2036265,2234925,2447775,2675475,2918700,3178140,3454500,3748500,4060875,4392375,4743765,5115825,5509350,5925150,6364050,6826890,7314525,7827825,8367675,8934975,9530640,10155600,10810800,11497200,12215775,12967515,13753425,14574525 bin $0,4 mul $0,15
lui $1,63234 ori $1,$1,53640 lui $2,40971 ori $2,$2,36928 lui $3,49388 ori $3,$3,28895 lui $4,27626 ori $4,$4,38375 lui $5,51700 ori $5,$5,31638 lui $6,18285 ori $6,$6,58539 mthi $1 mtlo $2 sec0: nop nop nop nor $0,$6,$6 sec1: nop nop slt $6,$4,$1 nor $4,$6,$6 sec2: nop nop lui $6,14615 nor $4,$6,$6 sec3: nop nop mfhi $6 nor $1,$6,$6 sec4: nop nop lh $6,10($0) nor $3,$6,$6 sec5: nop nor $6,$3,$2 nop nor $5,$6,$6 sec6: nop slt $6,$2,$3 slt $6,$5,$3 nor $4,$6,$6 sec7: nop subu $6,$5,$3 lui $6,20076 nor $3,$6,$6 sec8: nop slt $6,$4,$1 mfhi $6 nor $3,$6,$6 sec9: nop or $6,$5,$2 lh $6,6($0) nor $0,$6,$6 sec10: nop xori $6,$4,16851 nop nor $3,$6,$6 sec11: nop sltiu $6,$3,4864 addu $6,$6,$3 nor $1,$6,$6 sec12: nop andi $6,$3,63225 ori $6,$5,51934 nor $2,$6,$6 sec13: nop slti $6,$2,-27343 mflo $6 nor $1,$6,$6 sec14: nop andi $6,$4,64962 lb $6,3($0) nor $3,$6,$6 sec15: nop mfhi $6 nop nor $6,$6,$6 sec16: nop mfhi $6 slt $6,$5,$0 nor $3,$6,$6 sec17: nop mfhi $6 slti $6,$5,-2314 nor $2,$6,$6 sec18: nop mfhi $6 mflo $6 nor $5,$6,$6 sec19: nop mflo $6 lh $6,16($0) nor $1,$6,$6 sec20: nop lbu $6,9($0) nop nor $1,$6,$6 sec21: nop lhu $6,10($0) xor $6,$1,$6 nor $6,$6,$6 sec22: nop lw $6,0($0) xori $6,$2,19397 nor $6,$6,$6 sec23: nop lw $6,16($0) mflo $6 nor $2,$6,$6 sec24: nop lh $6,8($0) lb $6,13($0) nor $3,$6,$6 sec25: nor $6,$6,$5 nop nop nor $6,$6,$6 sec26: addu $6,$1,$3 nop xor $6,$3,$3 nor $4,$6,$6 sec27: subu $6,$2,$5 nop xori $6,$3,4622 nor $5,$6,$6 sec28: xor $6,$3,$3 nop mflo $6 nor $3,$6,$6 sec29: or $6,$2,$3 nop lhu $6,6($0) nor $2,$6,$6 sec30: or $6,$4,$3 slt $6,$3,$2 nop nor $4,$6,$6 sec31: xor $6,$2,$3 sltu $6,$1,$3 subu $6,$5,$3 nor $2,$6,$6 sec32: and $6,$4,$3 slt $6,$3,$4 sltiu $6,$2,31331 nor $4,$6,$6 sec33: addu $6,$6,$2 or $6,$4,$4 mflo $6 nor $3,$6,$6 sec34: xor $6,$3,$4 nor $6,$2,$3 lbu $6,16($0) nor $4,$6,$6 sec35: and $6,$1,$2 sltiu $6,$1,-10011 nop nor $4,$6,$6 sec36: subu $6,$5,$1 andi $6,$4,35207 or $6,$3,$4 nor $5,$6,$6 sec37: xor $6,$3,$1 slti $6,$1,-28276 ori $6,$2,23156 nor $3,$6,$6 sec38: subu $6,$4,$4 ori $6,$4,34419 mflo $6 nor $4,$6,$6 sec39: xor $6,$5,$4 lui $6,4958 lhu $6,4($0) nor $1,$6,$6 sec40: nor $6,$1,$4 mflo $6 nop nor $4,$6,$6 sec41: xor $6,$0,$2 mflo $6 xor $6,$1,$2 nor $1,$6,$6 sec42: sltu $6,$2,$3 mfhi $6 andi $6,$3,15520 nor $1,$6,$6 sec43: xor $6,$4,$3 mfhi $6 mfhi $6 nor $2,$6,$6 sec44: sltu $6,$1,$3 mflo $6 lh $6,14($0) nor $2,$6,$6 sec45: nor $6,$4,$3 lbu $6,8($0) nop nor $3,$6,$6 sec46: subu $6,$4,$5 lh $6,8($0) nor $6,$2,$2 nor $3,$6,$6 sec47: slt $6,$3,$3 lhu $6,6($0) lui $6,62233 nor $5,$6,$6 sec48: subu $6,$5,$0 lw $6,8($0) mfhi $6 nor $6,$6,$6 sec49: or $6,$6,$6 lh $6,6($0) lw $6,0($0) nor $4,$6,$6 sec50: lui $6,21792 nop nop nor $4,$6,$6 sec51: lui $6,59959 nop subu $6,$2,$4 nor $5,$6,$6 sec52: ori $6,$3,391 nop slti $6,$2,1310 nor $1,$6,$6 sec53: sltiu $6,$4,-26009 nop mflo $6 nor $3,$6,$6 sec54: addiu $6,$3,19143 nop lh $6,10($0) nor $2,$6,$6 sec55: xori $6,$1,58880 nor $6,$2,$3 nop nor $6,$6,$6 sec56: lui $6,56375 subu $6,$2,$1 and $6,$4,$2 nor $1,$6,$6 sec57: lui $6,14677 nor $6,$2,$3 slti $6,$3,18427 nor $1,$6,$6 sec58: lui $6,39740 subu $6,$0,$2 mflo $6 nor $3,$6,$6 sec59: sltiu $6,$4,-23833 and $6,$0,$3 lb $6,10($0) nor $6,$6,$6 sec60: xori $6,$2,822 addiu $6,$3,-7806 nop nor $2,$6,$6 sec61: ori $6,$6,5003 sltiu $6,$2,26329 slt $6,$4,$3 nor $2,$6,$6 sec62: sltiu $6,$2,10159 slti $6,$1,-23923 slti $6,$1,22609 nor $2,$6,$6 sec63: xori $6,$3,34567 andi $6,$1,53135 mfhi $6 nor $4,$6,$6 sec64: andi $6,$2,49507 xori $6,$1,22485 lhu $6,16($0) nor $2,$6,$6 sec65: slti $6,$3,26565 mfhi $6 nop nor $1,$6,$6 sec66: ori $6,$4,63037 mflo $6 addu $6,$0,$2 nor $6,$6,$6 sec67: slti $6,$1,-22108 mflo $6 addiu $6,$3,-24732 nor $1,$6,$6 sec68: xori $6,$3,60236 mfhi $6 mfhi $6 nor $2,$6,$6 sec69: ori $6,$0,21496 mflo $6 lhu $6,4($0) nor $2,$6,$6 sec70: sltiu $6,$5,-8357 lhu $6,8($0) nop nor $4,$6,$6 sec71: slti $6,$0,16400 lhu $6,12($0) addu $6,$2,$4 nor $3,$6,$6 sec72: lui $6,12159 lb $6,9($0) ori $6,$6,38247 nor $1,$6,$6 sec73: andi $6,$4,32460 lhu $6,12($0) mfhi $6 nor $0,$6,$6 sec74: lui $6,22633 lb $6,10($0) lhu $6,10($0) nor $5,$6,$6 sec75: mfhi $6 nop nop nor $1,$6,$6 sec76: mflo $6 nop xor $6,$3,$3 nor $3,$6,$6 sec77: mflo $6 nop lui $6,26867 nor $0,$6,$6 sec78: mfhi $6 nop mflo $6 nor $4,$6,$6 sec79: mflo $6 nop lh $6,14($0) nor $1,$6,$6 sec80: mfhi $6 or $6,$3,$4 nop nor $6,$6,$6 sec81: mfhi $6 sltu $6,$3,$2 subu $6,$3,$2 nor $1,$6,$6 sec82: mfhi $6 slt $6,$0,$3 lui $6,47926 nor $3,$6,$6 sec83: mflo $6 addu $6,$3,$2 mflo $6 nor $3,$6,$6 sec84: mflo $6 nor $6,$4,$0 lb $6,15($0) nor $1,$6,$6 sec85: mfhi $6 xori $6,$1,50112 nop nor $2,$6,$6 sec86: mflo $6 andi $6,$3,60397 sltu $6,$4,$5 nor $1,$6,$6 sec87: mfhi $6 andi $6,$3,39369 lui $6,20887 nor $5,$6,$6 sec88: mflo $6 sltiu $6,$4,29382 mflo $6 nor $4,$6,$6 sec89: mfhi $6 xori $6,$3,13072 lb $6,16($0) nor $3,$6,$6 sec90: mfhi $6 mflo $6 nop nor $1,$6,$6 sec91: mflo $6 mflo $6 xor $6,$6,$3 nor $4,$6,$6 sec92: mflo $6 mfhi $6 xori $6,$3,35030 nor $1,$6,$6 sec93: mfhi $6 mfhi $6 mflo $6 nor $5,$6,$6 sec94: mfhi $6 mfhi $6 lh $6,6($0) nor $2,$6,$6 sec95: mfhi $6 lhu $6,6($0) nop nor $2,$6,$6 sec96: mfhi $6 lb $6,6($0) nor $6,$1,$4 nor $3,$6,$6 sec97: mfhi $6 lh $6,8($0) xori $6,$4,10865 nor $3,$6,$6 sec98: mflo $6 lbu $6,12($0) mflo $6 nor $6,$6,$6 sec99: mfhi $6 lh $6,4($0) lhu $6,14($0) nor $2,$6,$6 sec100: lb $6,12($0) nop nop nor $2,$6,$6 sec101: lw $6,8($0) nop sltu $6,$3,$0 nor $1,$6,$6 sec102: lh $6,10($0) nop ori $6,$3,23697 nor $4,$6,$6 sec103: lb $6,6($0) nop mfhi $6 nor $6,$6,$6 sec104: lbu $6,12($0) nop lhu $6,16($0) nor $3,$6,$6 sec105: lhu $6,6($0) and $6,$3,$1 nop nor $2,$6,$6 sec106: lb $6,14($0) addu $6,$3,$2 or $6,$2,$5 nor $2,$6,$6 sec107: lh $6,6($0) or $6,$0,$5 lui $6,59619 nor $2,$6,$6 sec108: lbu $6,6($0) subu $6,$0,$5 mflo $6 nor $1,$6,$6 sec109: lb $6,7($0) xor $6,$1,$5 lb $6,11($0) nor $3,$6,$6 sec110: lb $6,6($0) addiu $6,$5,-4407 nop nor $5,$6,$6 sec111: lbu $6,15($0) sltiu $6,$4,8228 nor $6,$3,$3 nor $4,$6,$6 sec112: lhu $6,2($0) slti $6,$6,-10997 slti $6,$2,-15196 nor $5,$6,$6 sec113: lh $6,0($0) lui $6,51403 mfhi $6 nor $0,$6,$6 sec114: lhu $6,6($0) sltiu $6,$3,-29486 lb $6,16($0) nor $5,$6,$6 sec115: lb $6,13($0) mfhi $6 nop nor $4,$6,$6 sec116: lhu $6,8($0) mflo $6 addu $6,$2,$5 nor $1,$6,$6 sec117: lh $6,0($0) mfhi $6 addiu $6,$3,28514 nor $3,$6,$6 sec118: lh $6,10($0) mfhi $6 mfhi $6 nor $1,$6,$6 sec119: lbu $6,9($0) mflo $6 lb $6,2($0) nor $1,$6,$6 sec120: lb $6,8($0) lh $6,14($0) nop nor $1,$6,$6 sec121: lbu $6,13($0) lhu $6,10($0) or $6,$4,$4 nor $2,$6,$6 sec122: lh $6,4($0) lw $6,16($0) lui $6,58652 nor $4,$6,$6 sec123: lh $6,6($0) lbu $6,12($0) mflo $6 nor $2,$6,$6 sec124: lb $6,12($0) lhu $6,10($0) lbu $6,13($0) nor $1,$6,$6
; A207436: Number of n X 2 0..1 arrays avoiding 0 0 1 and 0 1 0 horizontally and 0 0 1 and 1 0 0 vertically. ; 4,16,36,81,196,484,1225,3136,8100,21025,54756,142884,373321,976144,2553604,6682225,17489124,45778756,119836809,313714944,821280964,2150084161,5628900676,14736503236,38580423561,101004467344,264432492900,692292225681,1812442912900,4745034456100,12422657127241,32522931540544,85146128781156,222915440704609,583600170521124,1527885033948900,4000054871604169,10472279484232336,27416783424740164,71778070537004209,187917427776935844,491974212131482756,1288005207545855241,3372041408772105216 seq $0,71679 ; Least k such that the maximum number of elements among the continued fractions for k/1, k/2, k/3, k/4 ...., k/k equals n. add $0,1 pow $0,2
/* * Copyright (c) 2021, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <cudf/column/column_view.hpp> #include <rmm/cuda_stream_view.hpp> namespace cudf { namespace detail { /** * @brief Return validity of a row * * Retrieves the validity (NULL or non-NULL) of the specified row from device memory. * * @note Synchronizes `stream`. * * @throw cudf::logic_error if `element_index < 0 or >= col_view.size()` * * @param col_view The column to retrieve the validity from. * @param element_index The index of the row to retrieve. * @param stream The stream to use for copying the validity to the host. * @return Host boolean that indicates the validity of the row. */ bool is_element_valid_sync(column_view const& col_view, size_type element_index, rmm::cuda_stream_view stream = rmm::cuda_stream_default); } // namespace detail } // namespace cudf
; A203150: (n-1)-st elementary symmetric function of the first n terms of (1,2,1,2,1,2,1,2,1,2,...)=A000034. ; 1,3,5,12,16,36,44,96,112,240,272,576,640,1344,1472,3072,3328,6912,7424,15360,16384,33792,35840,73728,77824,159744,167936,344064,360448,737280,770048,1572864,1638400,3342336,3473408,7077888,7340032,14942208,15466496,31457280,32505856,66060288,68157440,138412032,142606336,289406976,297795584,603979776,620756992,1258291200,1291845632,2617245696,2684354560,5435817984,5570035712,11274289152,11542724608,23353884672,23890755584,48318382080,49392123904,99857989632,102005473280,206158430208,210453397504,425201762304,433791696896,876173328384,893353197568,1803886264320,1838246002688,3710851743744,3779571220480,7627861917696,7765300871168,15668040695808,15942918602752,32160715112448,32710470926336,65970697666560,67070209294336,135239930216448,137438953472000,277076930199552,281474976710656,567347999932416,576144092954624,1161084278931456,1178676464975872,2374945115996160,2410129488084992,4855443348258816,4925812092436480 mov $1,$0 mul $0,2 add $1,1 mov $2,2 lpb $0,1 sub $0,2 trn $0,2 mul $1,2 sub $1,$2 add $1,1 mul $2,2 sub $2,1 lpe
// Copyright (C) 2002-2012 Nikolaus Gebhardt // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h #include "IrrCompileConfig.h" #include "CSoftwareDriver.h" #ifdef _IRR_COMPILE_WITH_SOFTWARE_ #include "CSoftwareTexture.h" #include "CBlit.h" #include "os.h" #include "S3DVertex.h" namespace irr { namespace video { //! constructor CSoftwareDriver::CSoftwareDriver(const core::dimension2d<u32>& windowSize, bool fullscreen, io::IFileSystem* io, video::IImagePresenter* presenter) : CNullDriver(io, windowSize), BackBuffer(0), Presenter(presenter), WindowId(0), SceneSourceRect(0), RenderTargetTexture(0), RenderTargetSurface(0), CurrentTriangleRenderer(0), ZBuffer(0), Texture(0) { #ifdef _DEBUG setDebugName("CSoftwareDriver"); #endif // create backbuffer BackBuffer = new CImage(ECF_A1R5G5B5, windowSize); if (BackBuffer) { BackBuffer->fill(SColor(0)); // create z buffer ZBuffer = video::createZBuffer(BackBuffer->getDimension()); } DriverAttributes->setAttribute("MaxTextures", 1); DriverAttributes->setAttribute("MaxIndices", 1<<16); DriverAttributes->setAttribute("MaxTextureSize", 1024); DriverAttributes->setAttribute("Version", 1); // create triangle renderers TriangleRenderers[ETR_FLAT] = createTriangleRendererFlat(ZBuffer); TriangleRenderers[ETR_FLAT_WIRE] = createTriangleRendererFlatWire(ZBuffer); TriangleRenderers[ETR_GOURAUD] = createTriangleRendererGouraud(ZBuffer); TriangleRenderers[ETR_GOURAUD_WIRE] = createTriangleRendererGouraudWire(ZBuffer); TriangleRenderers[ETR_TEXTURE_FLAT] = createTriangleRendererTextureFlat(ZBuffer); TriangleRenderers[ETR_TEXTURE_FLAT_WIRE] = createTriangleRendererTextureFlatWire(ZBuffer); TriangleRenderers[ETR_TEXTURE_GOURAUD] = createTriangleRendererTextureGouraud(ZBuffer); TriangleRenderers[ETR_TEXTURE_GOURAUD_WIRE] = createTriangleRendererTextureGouraudWire(ZBuffer); TriangleRenderers[ETR_TEXTURE_GOURAUD_NOZ] = createTriangleRendererTextureGouraudNoZ(); TriangleRenderers[ETR_TEXTURE_GOURAUD_ADD] = createTriangleRendererTextureGouraudAdd(ZBuffer); // select render target setRenderTargetImage(BackBuffer); // select the right renderer selectRightTriangleRenderer(); } //! destructor CSoftwareDriver::~CSoftwareDriver() { // delete Backbuffer if (BackBuffer) BackBuffer->drop(); // delete triangle renderers for (s32 i=0; i<ETR_COUNT; ++i) if (TriangleRenderers[i]) TriangleRenderers[i]->drop(); // delete zbuffer if (ZBuffer) ZBuffer->drop(); // delete current texture if (Texture) Texture->drop(); if (RenderTargetTexture) RenderTargetTexture->drop(); if (RenderTargetSurface) RenderTargetSurface->drop(); } //! switches to a triangle renderer void CSoftwareDriver::switchToTriangleRenderer(ETriangleRenderer renderer) { video::IImage* s = 0; if (Texture) s = ((CSoftwareTexture*)Texture)->getTexture(); CurrentTriangleRenderer = TriangleRenderers[renderer]; CurrentTriangleRenderer->setBackfaceCulling(Material.BackfaceCulling == true); CurrentTriangleRenderer->setTexture(s); CurrentTriangleRenderer->setRenderTarget(RenderTargetSurface, ViewPort); } //! void selects the right triangle renderer based on the render states. void CSoftwareDriver::selectRightTriangleRenderer() { ETriangleRenderer renderer = ETR_FLAT; if (Texture) { if (!Material.GouraudShading) renderer = (!Material.Wireframe) ? ETR_TEXTURE_FLAT : ETR_TEXTURE_FLAT_WIRE; else { if (Material.Wireframe) renderer = ETR_TEXTURE_GOURAUD_WIRE; else { if (Material.MaterialType == EMT_TRANSPARENT_ADD_COLOR || Material.MaterialType == EMT_TRANSPARENT_ALPHA_CHANNEL || Material.MaterialType == EMT_TRANSPARENT_VERTEX_ALPHA) { // simply draw all transparent stuff with the same renderer. at // least it is transparent then. renderer = ETR_TEXTURE_GOURAUD_ADD; } else if ((Material.ZBuffer==ECFN_DISABLED) && !Material.ZWriteEnable) renderer = ETR_TEXTURE_GOURAUD_NOZ; else { renderer = ETR_TEXTURE_GOURAUD; } } } } else { if (!Material.GouraudShading) renderer = (!Material.Wireframe) ? ETR_FLAT : ETR_FLAT_WIRE; else renderer = (!Material.Wireframe) ? ETR_GOURAUD : ETR_GOURAUD_WIRE; } switchToTriangleRenderer(renderer); } //! queries the features of the driver, returns true if feature is available bool CSoftwareDriver::queryFeature(E_VIDEO_DRIVER_FEATURE feature) const { switch (feature) { case EVDF_RENDER_TO_TARGET: case EVDF_TEXTURE_NSQUARE: return FeatureEnabled[feature]; default: return false; }; } //! Create render target. IRenderTarget* CSoftwareDriver::addRenderTarget() { CSoftwareRenderTarget* renderTarget = new CSoftwareRenderTarget(this); RenderTargets.push_back(renderTarget); return renderTarget; } //! sets transformation void CSoftwareDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat) { TransformationMatrix[state] = mat; } //! sets the current Texture bool CSoftwareDriver::setActiveTexture(u32 stage, video::ITexture* texture) { if (texture && texture->getDriverType() != EDT_SOFTWARE) { os::Printer::log("Fatal Error: Tried to set a texture not owned by this driver.", ELL_ERROR); return false; } if (Texture) Texture->drop(); Texture = texture; if (Texture) Texture->grab(); selectRightTriangleRenderer(); return true; } //! sets a material void CSoftwareDriver::setMaterial(const SMaterial& material) { Material = material; OverrideMaterial.apply(Material); for (u32 i = 0; i < 1; ++i) { setActiveTexture(i, Material.getTexture(i)); setTransform ((E_TRANSFORMATION_STATE) ( ETS_TEXTURE_0 + i ), material.getTextureMatrix(i)); } } bool CSoftwareDriver::beginScene(u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil, const SExposedVideoData& videoData, core::rect<s32>* sourceRect) { CNullDriver::beginScene(clearFlag, clearColor, clearDepth, clearStencil, videoData, sourceRect); WindowId=videoData.D3D9.HWnd; SceneSourceRect = sourceRect; clearBuffers(clearFlag, clearColor, clearDepth, clearStencil); return true; } bool CSoftwareDriver::endScene() { CNullDriver::endScene(); return Presenter->present(BackBuffer, WindowId, SceneSourceRect); } ITexture* CSoftwareDriver::createDeviceDependentTexture(const io::path& name, IImage* image) { CSoftwareTexture* texture = new CSoftwareTexture(image, name, false); return texture; } bool CSoftwareDriver::setRenderTargetEx(IRenderTarget* target, u16 clearFlag, SColor clearColor, f32 clearDepth, u8 clearStencil) { if (target && target->getDriverType() != EDT_SOFTWARE) { os::Printer::log("Fatal Error: Tried to set a render target not owned by this driver.", ELL_ERROR); return false; } if (RenderTargetTexture) RenderTargetTexture->drop(); CSoftwareRenderTarget* renderTarget = static_cast<CSoftwareRenderTarget*>(target); RenderTargetTexture = (renderTarget) ? renderTarget->getTexture() : 0; if (RenderTargetTexture) { RenderTargetTexture->grab(); setRenderTargetImage(((CSoftwareTexture*)RenderTargetTexture)->getTexture()); } else { setRenderTargetImage(BackBuffer); } clearBuffers(clearFlag, clearColor, clearDepth, clearStencil); return true; } //! sets a render target void CSoftwareDriver::setRenderTargetImage(video::CImage* image) { if (RenderTargetSurface) RenderTargetSurface->drop(); RenderTargetSurface = image; RenderTargetSize.Width = 0; RenderTargetSize.Height = 0; Render2DTranslation.X = 0; Render2DTranslation.Y = 0; if (RenderTargetSurface) { RenderTargetSurface->grab(); RenderTargetSize = RenderTargetSurface->getDimension(); } setViewPort(core::rect<s32>(0,0,RenderTargetSize.Width,RenderTargetSize.Height)); if (ZBuffer) ZBuffer->setSize(RenderTargetSize); } //! sets a viewport void CSoftwareDriver::setViewPort(const core::rect<s32>& area) { ViewPort = area; //TODO: the clipping is not correct, because the projection is affected. // to correct this, ViewPortSize and Render2DTranslation will have to be corrected. core::rect<s32> rendert(0,0,RenderTargetSize.Width,RenderTargetSize.Height); ViewPort.clipAgainst(rendert); ViewPortSize = core::dimension2du(ViewPort.getSize()); Render2DTranslation.X = (ViewPortSize.Width / 2) + ViewPort.UpperLeftCorner.X; Render2DTranslation.Y = ViewPort.UpperLeftCorner.Y + ViewPortSize.Height - (ViewPortSize.Height / 2);// + ViewPort.UpperLeftCorner.Y; if (CurrentTriangleRenderer) CurrentTriangleRenderer->setRenderTarget(RenderTargetSurface, ViewPort); } void CSoftwareDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCount, const void* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType) { switch (iType) { case (EIT_16BIT): { drawVertexPrimitiveList16(vertices, vertexCount, (const u16*)indexList, primitiveCount, vType, pType); break; } case (EIT_32BIT): { os::Printer::log("Software driver can not render 32bit buffers", ELL_ERROR); break; } } } //! draws a vertex primitive list void CSoftwareDriver::drawVertexPrimitiveList16(const void* vertices, u32 vertexCount, const u16* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType) { const u16* indexPointer=0; core::array<u16> newBuffer; switch (pType) { case scene::EPT_LINE_STRIP: { switch (vType) { case EVT_STANDARD: { for (u32 i=0; i < primitiveCount-1; ++i) draw3DLine(((S3DVertex*)vertices)[indexList[i]].Pos, ((S3DVertex*)vertices)[indexList[i+1]].Pos, ((S3DVertex*)vertices)[indexList[i]].Color); } break; case EVT_2TCOORDS: { for (u32 i=0; i < primitiveCount-1; ++i) draw3DLine(((S3DVertex2TCoords*)vertices)[indexList[i]].Pos, ((S3DVertex2TCoords*)vertices)[indexList[i+1]].Pos, ((S3DVertex2TCoords*)vertices)[indexList[i]].Color); } break; case EVT_TANGENTS: { for (u32 i=0; i < primitiveCount-1; ++i) draw3DLine(((S3DVertexTangents*)vertices)[indexList[i]].Pos, ((S3DVertexTangents*)vertices)[indexList[i+1]].Pos, ((S3DVertexTangents*)vertices)[indexList[i]].Color); } break; } } return; case scene::EPT_LINE_LOOP: drawVertexPrimitiveList16(vertices, vertexCount, indexList, primitiveCount-1, vType, scene::EPT_LINE_STRIP); switch (vType) { case EVT_STANDARD: draw3DLine(((S3DVertex*)vertices)[indexList[primitiveCount-1]].Pos, ((S3DVertex*)vertices)[indexList[0]].Pos, ((S3DVertex*)vertices)[indexList[primitiveCount-1]].Color); break; case EVT_2TCOORDS: draw3DLine(((S3DVertex2TCoords*)vertices)[indexList[primitiveCount-1]].Pos, ((S3DVertex2TCoords*)vertices)[indexList[0]].Pos, ((S3DVertex2TCoords*)vertices)[indexList[primitiveCount-1]].Color); break; case EVT_TANGENTS: draw3DLine(((S3DVertexTangents*)vertices)[indexList[primitiveCount-1]].Pos, ((S3DVertexTangents*)vertices)[indexList[0]].Pos, ((S3DVertexTangents*)vertices)[indexList[primitiveCount-1]].Color); break; } return; case scene::EPT_LINES: { switch (vType) { case EVT_STANDARD: { for (u32 i=0; i < 2*primitiveCount; i+=2) draw3DLine(((S3DVertex*)vertices)[indexList[i]].Pos, ((S3DVertex*)vertices)[indexList[i+1]].Pos, ((S3DVertex*)vertices)[indexList[i]].Color); } break; case EVT_2TCOORDS: { for (u32 i=0; i < 2*primitiveCount; i+=2) draw3DLine(((S3DVertex2TCoords*)vertices)[indexList[i]].Pos, ((S3DVertex2TCoords*)vertices)[indexList[i+1]].Pos, ((S3DVertex2TCoords*)vertices)[indexList[i]].Color); } break; case EVT_TANGENTS: { for (u32 i=0; i < 2*primitiveCount; i+=2) draw3DLine(((S3DVertexTangents*)vertices)[indexList[i]].Pos, ((S3DVertexTangents*)vertices)[indexList[i+1]].Pos, ((S3DVertexTangents*)vertices)[indexList[i]].Color); } break; } } return; case scene::EPT_TRIANGLE_FAN: { // TODO: don't convert fan to list newBuffer.reallocate(primitiveCount*3); for( u32 t=0; t<primitiveCount; ++t ) { newBuffer.push_back(indexList[0]); newBuffer.push_back(indexList[t+1]); newBuffer.push_back(indexList[t+2]); } indexPointer = newBuffer.pointer(); } break; case scene::EPT_TRIANGLES: indexPointer=indexList; break; default: return; } switch (vType) { case EVT_STANDARD: drawClippedIndexedTriangleListT((S3DVertex*)vertices, vertexCount, indexPointer, primitiveCount); break; case EVT_2TCOORDS: drawClippedIndexedTriangleListT((S3DVertex2TCoords*)vertices, vertexCount, indexPointer, primitiveCount); break; case EVT_TANGENTS: drawClippedIndexedTriangleListT((S3DVertexTangents*)vertices, vertexCount, indexPointer, primitiveCount); break; } } template<class VERTEXTYPE> void CSoftwareDriver::drawClippedIndexedTriangleListT(const VERTEXTYPE* vertices, s32 vertexCount, const u16* indexList, s32 triangleCount) { if (!RenderTargetSurface || !ZBuffer || !triangleCount) return; if (!checkPrimitiveCount(triangleCount)) return; // arrays for storing clipped vertices core::array<VERTEXTYPE> clippedVertices; core::array<u16> clippedIndices; // calculate inverse world transformation core::matrix4 worldinv(TransformationMatrix[ETS_WORLD]); worldinv.makeInverse(); // calculate view frustum planes scene::SViewFrustum frustum(TransformationMatrix[ETS_PROJECTION] * TransformationMatrix[ETS_VIEW]); // copy and transform clipping planes ignoring far plane core::plane3df planes[5]; // ordered by near, left, right, bottom, top for (int p=0; p<5; ++p) worldinv.transformPlane(frustum.planes[p+1], planes[p]); core::EIntersectionRelation3D inout[3]; // is point in front or back of plane? // temporary buffer for vertices to be clipped by all planes core::array<VERTEXTYPE> tClpBuf; int t; int i; for (i=0; i<triangleCount; ++i) // for all input triangles { // add next triangle to tempClipBuffer for (t=0; t<3; ++t) tClpBuf.push_back(vertices[indexList[(i*3)+t]]); for (int p=0; p<5; ++p) // for all clip planes for (int v=0; v<(int)tClpBuf.size(); v+=3) // for all vertices in temp clip buffer { int inside = 0; int outside = 0; // test intersection relation of the current vertices for (t=0; t<3; ++t) { inout[t] = planes[p].classifyPointRelation(tClpBuf[v+t].Pos); if (inout[t] != core::ISREL3D_FRONT) ++inside; else if (inout[t] == core::ISREL3D_FRONT) ++outside; } if (!outside) { // add all vertices to new buffer, this triangle needs no clipping. // so simply don't change this part of the temporary triangle buffer continue; } if (!inside) { // all vertices are outside, don't add this triangle, so erase this // triangle from the tClpBuf tClpBuf.erase(v,3); v -= 3; continue; } // this vertex has to be clipped by this clipping plane. // The following lines represent my try to implement some real clipping. // There is a bug somewhere, and after some time I've given up. // So now it is commented out, resulting that triangles which would need clipping // are simply taken out (in the next two lines). #ifndef __SOFTWARE_CLIPPING_PROBLEM__ tClpBuf.erase(v,3); v -= 3; #endif /* // my idea is the following: // current vertex to next vertex relation: // out - out : add nothing // out - in : add middle point // in - out : add first and middle point // in - in : add both // now based on the number of intersections, create new vertices // into tClpBuf (at the front for not letting them be clipped again) int added = 0; int prev = v+2; for (int index=v; index<v+3; ++index) { if (inout[prev] == core::ISREL3D_BACK) { if (inout[index] != core::ISREL3D_BACK) { VERTEXTYPE& vt1 = tClpBuf[prev]; VERTEXTYPE& vt2 = tClpBuf[index]; f32 fact = planes[p].getKnownIntersectionWithLine(vt1.Pos, vt2.Pos); VERTEXTYPE nvt; nvt.Pos = vt1.Pos.getInterpolated(vt2.Pos, fact); nvt.Color = vt1.Color.getInterpolated(vt2.Color, fact); nvt.TCoords = vt1.TCoords.getInterpolated(vt2.TCoords, fact); tClpBuf.push_front(nvt); ++index; ++prev; ++v; ++added; } } else { if (inout[index] != core::ISREL3D_BACK) { VERTEXTYPE vt1 = tClpBuf[index]; VERTEXTYPE vt2 = tClpBuf[prev]; tClpBuf.push_front(vt1); ++index; ++prev; ++v; tClpBuf.push_front(vt2); ++index; ++prev; ++v; added+= 2; } else { // same as above, but other way round. VERTEXTYPE vt1 = tClpBuf[index]; VERTEXTYPE vt2 = tClpBuf[prev]; f32 fact = planes[p].getKnownIntersectionWithLine(vt1.Pos, vt2.Pos); VERTEXTYPE nvt; nvt.Pos = vt1.Pos.getInterpolated(vt2.Pos, fact); nvt.Color = vt1.Color.getInterpolated(vt2.Color, fact); nvt.TCoords = vt1.TCoords.getInterpolated(vt2.TCoords, fact); tClpBuf.push_front(vt2); ++index; ++prev; ++v; tClpBuf.push_front(nvt); ++index; ++prev; ++v; added += 2; } } prev = index; } // erase original vertices tClpBuf.erase(v,3); v -= 3; */ } // end for all clip planes // now add all remaining triangles in tempClipBuffer to clippedIndices // and clippedVertices array. if (clippedIndices.size() + tClpBuf.size() < 65535) for (t=0; t<(int)tClpBuf.size(); ++t) { clippedIndices.push_back(clippedVertices.size()); clippedVertices.push_back(tClpBuf[t]); } tClpBuf.clear(); } // end for all input triangles // draw newly created triangles. // ----------------------------------------------------------- // here all triangles are being drawn. I put this in a separate // method, but the visual studio 6 compiler has great problems // with templates and didn't accept two template methods in this // class. // draw triangles CNullDriver::drawVertexPrimitiveList(clippedVertices.pointer(), clippedVertices.size(), clippedIndices.pointer(), clippedIndices.size()/3, EVT_STANDARD, scene::EPT_TRIANGLES, EIT_16BIT); if (TransformedPoints.size() < clippedVertices.size()) TransformedPoints.set_used(clippedVertices.size()); if (TransformedPoints.empty()) return; const VERTEXTYPE* currentVertex = clippedVertices.pointer(); S2DVertex* tp = &TransformedPoints[0]; core::dimension2d<u32> textureSize(0,0); f32 zDiv; if (Texture) textureSize = ((CSoftwareTexture*)Texture)->getTexture()->getDimension(); f32 transformedPos[4]; // transform all points in the list core::matrix4 matrix(TransformationMatrix[ETS_PROJECTION]); matrix *= TransformationMatrix[ETS_VIEW]; matrix *= TransformationMatrix[ETS_WORLD]; s32 ViewTransformWidth = (ViewPortSize.Width>>1); s32 ViewTransformHeight = (ViewPortSize.Height>>1); for (i=0; i<(int)clippedVertices.size(); ++i) { transformedPos[0] = currentVertex->Pos.X; transformedPos[1] = currentVertex->Pos.Y; transformedPos[2] = currentVertex->Pos.Z; transformedPos[3] = 1.0f; matrix.multiplyWith1x4Matrix(transformedPos); zDiv = transformedPos[3] == 0.0f ? 1.0f : (1.0f / transformedPos[3]); tp->Pos.X = (s32)(ViewTransformWidth * (transformedPos[0] * zDiv) + (Render2DTranslation.X)); tp->Pos.Y = (Render2DTranslation.Y - (s32)(ViewTransformHeight * (transformedPos[1] * zDiv))); tp->Color = currentVertex->Color.toA1R5G5B5(); tp->ZValue = (TZBufferType)(32767.0f * zDiv); tp->TCoords.X = (s32)(currentVertex->TCoords.X * textureSize.Width); tp->TCoords.X <<= 8; tp->TCoords.Y = (s32)(currentVertex->TCoords.Y * textureSize.Height); tp->TCoords.Y <<= 8; ++currentVertex; ++tp; } // draw all transformed points from the index list CurrentTriangleRenderer->drawIndexedTriangleList(&TransformedPoints[0], clippedVertices.size(), clippedIndices.pointer(), clippedIndices.size()/3); } //! Draws a 3d line. void CSoftwareDriver::draw3DLine(const core::vector3df& start, const core::vector3df& end, SColor color) { core::vector3df vect = start.crossProduct(end); vect.normalize(); vect *= Material.Thickness*0.3f; S3DVertex vtx[4]; vtx[0].Color = color; vtx[1].Color = color; vtx[2].Color = color; vtx[3].Color = color; vtx[0].Pos = start; vtx[1].Pos = end; vtx[2].Pos = start + vect; vtx[3].Pos = end + vect; u16 idx[12] = {0,1,2, 0,2,1, 0,1,3, 0,3,1}; drawIndexedTriangleList(vtx, 4, idx, 4); } //! clips a triangle against the viewing frustum void CSoftwareDriver::clipTriangle(f32* transformedPos) { } //! Only used by the internal engine. Used to notify the driver that //! the window was resized. void CSoftwareDriver::OnResize(const core::dimension2d<u32>& size) { // make sure width and height are multiples of 2 core::dimension2d<u32> realSize(size); if (realSize.Width % 2) realSize.Width += 1; if (realSize.Height % 2) realSize.Height += 1; if (ScreenSize != realSize) { if (ViewPort.getWidth() == (s32)ScreenSize.Width && ViewPort.getHeight() == (s32)ScreenSize.Height) { ViewPort = core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(realSize)); } ScreenSize = realSize; bool resetRT = (RenderTargetSurface == BackBuffer); if (BackBuffer) BackBuffer->drop(); BackBuffer = new CImage(ECF_A1R5G5B5, realSize); if (resetRT) setRenderTargetImage(BackBuffer); } } //! returns the current render target size const core::dimension2d<u32>& CSoftwareDriver::getCurrentRenderTargetSize() const { return RenderTargetSize; } //! draws an 2d image, using a color (if color is other then Color(255,255,255,255)) and the alpha channel of the texture if wanted. void CSoftwareDriver::draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos, const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect, SColor color, bool useAlphaChannelOfTexture) { if (texture) { if (texture->getDriverType() != EDT_SOFTWARE) { os::Printer::log("Fatal Error: Tried to copy from a surface not owned by this driver.", ELL_ERROR); return; } if (useAlphaChannelOfTexture) ((CSoftwareTexture*)texture)->getImage()->copyToWithAlpha( RenderTargetSurface, destPos, sourceRect, color, clipRect); else ((CSoftwareTexture*)texture)->getImage()->copyTo( RenderTargetSurface, destPos, sourceRect, clipRect); } } //! Draws a 2d line. void CSoftwareDriver::draw2DLine(const core::position2d<s32>& start, const core::position2d<s32>& end, SColor color) { drawLine(RenderTargetSurface, start, end, color ); } //! Draws a pixel void CSoftwareDriver::drawPixel(u32 x, u32 y, const SColor & color) { BackBuffer->setPixel(x, y, color, true); } //! draw a 2d rectangle void CSoftwareDriver::draw2DRectangle(SColor color, const core::rect<s32>& pos, const core::rect<s32>* clip) { if (clip) { core::rect<s32> p(pos); p.clipAgainst(*clip); if(!p.isValid()) return; drawRectangle(RenderTargetSurface, p, color); } else { if(!pos.isValid()) return; drawRectangle(RenderTargetSurface, pos, color); } } //!Draws an 2d rectangle with a gradient. void CSoftwareDriver::draw2DRectangle(const core::rect<s32>& pos, SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown, const core::rect<s32>* clip) { // TODO: implement draw2DRectangle(colorLeftUp, pos, clip); } //! \return Returns the name of the video driver. Example: In case of the Direct3D8 //! driver, it would return "Direct3D8.1". const wchar_t* CSoftwareDriver::getName() const { return L"Irrlicht Software Driver 1.0"; } //! Returns type of video driver E_DRIVER_TYPE CSoftwareDriver::getDriverType() const { return EDT_SOFTWARE; } //! returns color format ECOLOR_FORMAT CSoftwareDriver::getColorFormat() const { if (BackBuffer) return BackBuffer->getColorFormat(); else return CNullDriver::getColorFormat(); } //! Returns the transformation set by setTransform const core::matrix4& CSoftwareDriver::getTransform(E_TRANSFORMATION_STATE state) const { return TransformationMatrix[state]; } //! Creates a render target texture. ITexture* CSoftwareDriver::addRenderTargetTexture(const core::dimension2d<u32>& size, const io::path& name, const ECOLOR_FORMAT format) { IImage* img = createImage(video::ECF_A1R5G5B5, size); ITexture* tex = new CSoftwareTexture(img, name, true); img->drop(); addTexture(tex); tex->drop(); return tex; } void CSoftwareDriver::clearBuffers(u16 flag, SColor color, f32 depth, u8 stencil) { if ((flag & ECBF_COLOR) && RenderTargetSurface) RenderTargetSurface->fill(color); if ((flag & ECBF_DEPTH) && ZBuffer) ZBuffer->clear(); } //! Returns an image created from the last rendered frame. IImage* CSoftwareDriver::createScreenShot(video::ECOLOR_FORMAT format, video::E_RENDER_TARGET target) { if (target != video::ERT_FRAME_BUFFER) return 0; if (BackBuffer) { IImage* tmp = createImage(BackBuffer->getColorFormat(), BackBuffer->getDimension()); BackBuffer->copyTo(tmp); return tmp; } else return 0; } //! Returns the maximum amount of primitives (mostly vertices) which //! the device is able to render with one drawIndexedTriangleList //! call. u32 CSoftwareDriver::getMaximalPrimitiveCount() const { return 0x00800000; } bool CSoftwareDriver::queryTextureFormat(ECOLOR_FORMAT format) const { return format == ECF_A1R5G5B5; } } // end namespace video } // end namespace irr #endif // _IRR_COMPILE_WITH_SOFTWARE_ namespace irr { namespace video { //! creates a video driver IVideoDriver* createSoftwareDriver(const core::dimension2d<u32>& windowSize, bool fullscreen, io::IFileSystem* io, video::IImagePresenter* presenter) { #ifdef _IRR_COMPILE_WITH_SOFTWARE_ return new CSoftwareDriver(windowSize, fullscreen, io, presenter); #else return 0; #endif } } // end namespace video } // end namespace irr
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- /* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* * AP_MotorsY6.cpp - ArduCopter motors library * Code by RandyMackay. DIYDrones.com * */ #include "AP_MotorsY6.h" // setup_motors - configures the motors for a hexa void AP_MotorsY6::setup_motors() { // call parent AP_MotorsMatrix::setup_motors(); if (_flags.frame_orientation >= AP_MOTORS_NEW_PLUS_FRAME) { // Y6 motor definition with all top motors spinning clockwise, all bottom motors counter clockwise add_motor_raw(AP_MOTORS_MOT_1, -1.0f, 0.500f, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 1); add_motor_raw(AP_MOTORS_MOT_2, -1.0f, 0.500f, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 2); add_motor_raw(AP_MOTORS_MOT_3, 0.0f, -1.000f, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 3); add_motor_raw(AP_MOTORS_MOT_4, 0.0f, -1.000f, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 4); add_motor_raw(AP_MOTORS_MOT_5, 1.0f, 0.500f, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 5); add_motor_raw(AP_MOTORS_MOT_6, 1.0f, 0.500f, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 6); }else{ // original Y6 motor definition add_motor_raw(AP_MOTORS_MOT_1, -1.0f, 0.666f, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 2); add_motor_raw(AP_MOTORS_MOT_2, 1.0f, 0.666f, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 5); add_motor_raw(AP_MOTORS_MOT_3, 1.0f, 0.666f, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 6); add_motor_raw(AP_MOTORS_MOT_4, 0.0f, -1.333f, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 4); add_motor_raw(AP_MOTORS_MOT_5, -1.0f, 0.666f, AP_MOTORS_MATRIX_YAW_FACTOR_CW, 1); add_motor_raw(AP_MOTORS_MOT_6, 0.0f, -1.333f, AP_MOTORS_MATRIX_YAW_FACTOR_CCW, 3); } }
/** * Copyright 2017 National Chiao Tung University, Intelligent System and Control Integration Laboratory * Author: Cheng-Hei Wu * Maintainer : Howard Chen * * 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. */ #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET #include "VotingSchemePoseEstimation_Class.h" VotingSchemePoseEstimationClass::VotingSchemePoseEstimationClass() { pcl::PointCloud<pcl::PointXYZ>::Ptr sceneCloud (new pcl::PointCloud<pcl::PointXYZ>); SceneCloud = sceneCloud; pcl::PointCloud<pcl::PointXYZ>::Ptr downsampling_SceneCloud (new pcl::PointCloud<pcl::PointXYZ>); Downsampling_SceneCloud = downsampling_SceneCloud; pcl::PointCloud<pcl::Normal>::Ptr sceneNormal (new pcl::PointCloud<pcl::Normal>); SceneNormal = sceneNormal; pcl::PointCloud<pcl::Normal>::Ptr downsampling_SceneNormal (new pcl::PointCloud<pcl::Normal>); Downsampling_SceneNormal = downsampling_SceneNormal; pcl::PointCloud<pcl::Boundary>::Ptr sceneBoundaryInf (new pcl::PointCloud<pcl::Boundary>); SceneBoundaryInf = sceneBoundaryInf; pcl::PointCloud<pcl::PointXYZ>::Ptr sceneBoundaryCloud (new pcl::PointCloud<pcl::PointXYZ>); SceneBoundaryCloud = sceneBoundaryCloud; pcl::PointCloud<pcl::PointXYZ>::Ptr sceneReferenceCloud (new pcl::PointCloud<pcl::PointXYZ>); SceneReferenceCloud = sceneReferenceCloud; pcl::PointCloud<pcl::PointXYZ>::Ptr sceneSegmentationCloud (new pcl::PointCloud<pcl::PointXYZ>); SceneSegmentationCloud = sceneSegmentationCloud; } pcl::PointCloud<pcl::PointXYZ>::Ptr VotingSchemePoseEstimationClass::getSceneSegmentationCloud() { return SceneSegmentationCloud; } pcl::PointCloud<pcl::PointXYZ>::Ptr VotingSchemePoseEstimationClass::getSceneCloud() { return SceneCloud; } pcl::PointCloud<pcl::PointXYZ>::Ptr VotingSchemePoseEstimationClass::getDownsampling_SceneCloud() { return Downsampling_SceneCloud; } pcl::PointCloud<pcl::Normal>::Ptr VotingSchemePoseEstimationClass::getSceneNormal() { return SceneNormal; } pcl::PointCloud<pcl::PointXYZ>::Ptr VotingSchemePoseEstimationClass::getSceneBoundaryCloud() { return SceneBoundaryCloud; } pcl::PointCloud<pcl::Boundary>::Ptr VotingSchemePoseEstimationClass::getSceneBoundaryInf() { return SceneBoundaryInf; } pcl::PointCloud<pcl::Normal>::Ptr VotingSchemePoseEstimationClass::getDownsampling_SceneNormal() { return Downsampling_SceneNormal; } pcl::PointCloud<pcl::PointXYZ>::Ptr VotingSchemePoseEstimationClass::getSceneReferenceCloud() { return SceneReferenceCloud; } Eigen::Matrix4f VotingSchemePoseEstimationClass::getPickObject_Mat() { return PickObject_Mat; }
; A087627: Count ...n,2n,2n... ; 1,2,2,2,4,4,3,6,6,4,8,8,5,10,10,6,12,12,7,14,14,8,16,16,9,18,18,10,20,20,11,22,22,12,24,24,13,26,26,14,28,28,15,30,30,16,32,32,17,34,34,18,36,36,19,38,38,20,40,40,21,42,42,22,44,44,23,46,46,24,48,48,25,50,50 mul $0,2 add $0,1 div $0,3 dif $0,2 add $0,1
// Copyright 2016 PDFium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "core/fpdfapi/page/cpdf_streamcontentparser.h" #include "testing/gtest/include/gtest/gtest.h" TEST(cpdf_streamcontentparser, PDF_FindKeyAbbreviation) { CPDF_StreamContentParser parser(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, 0); EXPECT_EQ(CFX_ByteStringC("BitsPerComponent"), parser.FindKeyAbbreviationForTesting(CFX_ByteStringC("BPC"))); EXPECT_EQ(CFX_ByteStringC("Width"), parser.FindKeyAbbreviationForTesting(CFX_ByteStringC("W"))); EXPECT_EQ(CFX_ByteStringC(""), parser.FindKeyAbbreviationForTesting(CFX_ByteStringC(""))); EXPECT_EQ(CFX_ByteStringC(""), parser.FindKeyAbbreviationForTesting(CFX_ByteStringC("NoInList"))); // Prefix should not match. EXPECT_EQ(CFX_ByteStringC(""), parser.FindKeyAbbreviationForTesting(CFX_ByteStringC("WW"))); } TEST(cpdf_streamcontentparser, PDF_FindValueAbbreviation) { CPDF_StreamContentParser parser(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, 0); EXPECT_EQ(CFX_ByteStringC("DeviceGray"), parser.FindValueAbbreviationForTesting(CFX_ByteStringC("G"))); EXPECT_EQ(CFX_ByteStringC("DCTDecode"), parser.FindValueAbbreviationForTesting(CFX_ByteStringC("DCT"))); EXPECT_EQ(CFX_ByteStringC(""), parser.FindValueAbbreviationForTesting(CFX_ByteStringC(""))); EXPECT_EQ(CFX_ByteStringC(""), parser.FindValueAbbreviationForTesting( CFX_ByteStringC("NoInList"))); // Prefix should not match. EXPECT_EQ(CFX_ByteStringC(""), parser.FindValueAbbreviationForTesting(CFX_ByteStringC("II"))); }
; void *tshc_cxy2aaddr(uchar x, uchar y) SECTION code_clib SECTION code_arch PUBLIC tshc_cxy2aaddr_callee EXTERN asm_tshc_cxy2aaddr tshc_cxy2aaddr_callee: pop hl ex (sp),hl jp asm_tshc_cxy2aaddr ; SDCC bridge for Classic IF __CLASSIC PUBLIC _tshc_cxy2aaddr_callee defc _tshc_cxy2aaddr_callee = tshc_cxy2aaddr_callee ENDIF
/** * MIT License * * Copyright (c) 2019 Arjun Gupta * * 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. */ /** *@file walkerAlgorithm.cpp *@author Arjun Gupta *@copyright MIT License *@brief define and implement walkerAlgorithm class functions */ #include <iostream> #include "../include/turtlebot_walker/walkerAlgorithm.hpp" walkerAlgorithm::walkerAlgorithm() { // Default value for linearVelocity and angularVelocity linearVelocity = 0.3; angularVelocity = -1.0; collision = false; ROS_INFO_STREAM("Default parameters parameters initialized"); // Publish on the topic publishVelocity = nh.advertise<geometry_msgs::Twist>(\ "cmd_vel_mux/input/navi", 1000); // Subscribe to the topic subscribeVelocity = nh.subscribe<sensor_msgs::LaserScan>(\ "/scan", 1000, &walkerAlgorithm::laserScanCallback, this); // Initialize initial linear and angular velocities msg.linear.x = 0.0; msg.linear.y = 0.0; msg.linear.z = 0.0; msg.angular.x = 0.0; msg.angular.y = 0.0; msg.angular.z = 0.0; publishVelocity.publish(msg); } walkerAlgorithm::~walkerAlgorithm() { ROS_WARN_STREAM("Stopping the bot"); // Setting the velocity to zero to stop the bot msg.linear.x = 0.0; msg.linear.y = 0.0; msg.linear.z = 0.0; msg.angular.x = 0.0; msg.angular.y = 0.0; msg.angular.z = 0.0; publishVelocity.publish(msg); } void walkerAlgorithm::laserScanCallback(\ const sensor_msgs::LaserScan::ConstPtr& msg) { for (auto msgs_ : msg->ranges) { // check if any object is witihin 0.7 range if (msgs_ < 0.7) { collision = true; return; } } collision = false; } bool walkerAlgorithm::checkObstacle() { // return the collision value return collision; } void walkerAlgorithm::moveRobot() { // Set the ros loop rate ros::Rate loop_rate(5); // Run until ros runs while (ros::ok()) { // Check if the obstacle is detected or not if (checkObstacle()) { ROS_WARN_STREAM("Obstacle ahead within the range of 0.7"); // Setting the linear velocity to be 0 msg.linear.x = 0.0; // Changing the angular velocity for turning msg.angular.z = angularVelocity; } else { ROS_INFO_STREAM("No obstacle detected moving forward"); // Stop the angular movement msg.angular.z = 0; // Set the linear velocity to the default value msg.linear.x = linearVelocity; } // Publish the current velocities publishVelocity.publish(msg); ros::spinOnce(); loop_rate.sleep(); } }
i2c_init: cli cbi DDRC, 4 cbi DDRC, 5 sbi PORTC, 4 sbi PORTC, 5 lds r16, PRR andi r16, 0b01101111 sts PRR, r16 call delay1msec ; set TWSR(Two Wire Status Register) to 0 to put it in an idle state and 1* divisor ldi r16, 0x0 sts TWSR, r16 ; set TWBR(Two Wire Bit Rate) reg to 0 as this sets the clock to 100kHz ldi r16, 0xc1 ; 16000000 / (16 + 2 * 193 * 1) sts TWBR, r16 ; enable TW and clear the interupt ldi r16, (1<<TWINT)|(1<<TWEN) sts TWCR, r16 ; _i2c_init_wait: ; lds r16, TWCR ; sbrs r16, TWINT ; if TWINT is set continue, else loop back to _wait ; rjmp _i2c_init_wait sei ret i2c_start: ; TWCR => Control Register ; TWINT => Clear interupt flag ; TWSTA => put TW into start mode(As in send the start of frame) ; TWEN => Enable TWI/I2C ldi r16, (1<<TWINT)|(1<<TWSTA)|(1<<TWEN) sts TWCR, r16 _i2c_start_wait: lds r16, TWCR sbrs r16, TWINT ; if TWINT is set continue, else loop back to _wait rjmp _i2c_start_wait lds r16, TWSR andi r16, 0b11111000 cpi r16, (1<<4) ; 0x08 breq end ; error if 0x08 is not in the status register ret i2c_stop: ; TWCR => Control Register ; TWINT => Clear interupt flag ; TWSTA => put TW into STOP mode(As in send the end of frame) ; TWEN => Enable TWI/I2C ldi r16, (1<<TWINT)|(1<<TWSTO)|(1<<TWEN) sts TWCR, r16 rcall delay1msec ret i2c_write_SLA: rcall i2c_write_byte lds r16,TWSR andi r16,0xf8 ; mask out cpi r16,0x18 ; TWSR = SLA+W sent, ACK received (0x18) ret i2c_write_byte: sts TWDR, r16 ldi r16, (1<<TWINT) | (1<<TWEN) sts TWCR, r16 rcall i2c_tansmit_wait ret i2c_tansmit_wait: lds r16, TWCR sbrs r16, TWINT rjmp i2c_tansmit_wait ret
#include "glfw_window.hpp" #include <bnb/effect_player/utility.hpp> #include <bnb/utils/defs.hpp> #include <glad/glad.h> using namespace bnb; glfw_window::glfw_window(const std::string& title, GLFWwindow* share) { init(); try { create_window(title, share); glfwMakeContextCurrent(m_window); load_glad_functions(); glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); glfwMakeContextCurrent(nullptr); } catch (...) { glfwTerminate(); throw; } } glfw_window::~glfw_window() { glfwMakeContextCurrent(nullptr); glfwDestroyWindow(m_window); glfwTerminate(); } void glfw_window::set_resize_callback(std::function<void(int32_t w, int32_t h, int32_t w_glfw_buffer, int32_t h_glfw_buffer)> surface_changed) { surface_changed_callback = surface_changed; } void glfw_window::show(uint32_t width_hint, uint32_t height_hint) { window_width = width_hint; window_height = height_hint; async::spawn( m_scheduler, [this, width_hint, height_hint]() { glfwSetWindowSize(m_window, width_hint, height_hint); glfwSetWindowPos(m_window, 100, 100); glfwShowWindow(m_window); }); glfwPostEmptyEvent(); } void glfw_window::run_main_loop() { while (!glfwWindowShouldClose(m_window)) { glfwWaitEvents(); m_scheduler.run_all_tasks(); if (surface_changed_callback && resized) { int32_t buffer_width, buffer_height; glfwGetFramebufferSize(m_window, &buffer_width, &buffer_height); surface_changed_callback(window_width, window_height, buffer_width, buffer_height); resized = false; } } } void glfw_window::init() { if (GLFW_TRUE != glfwInit()) { throw std::runtime_error("glfwInit error"); } } void glfw_window::create_window(const std::string& title, GLFWwindow* share) { // // Choose OpenGL context // glfwWindowHint(GLFW_DEPTH_BITS, 0); glfwWindowHint(GLFW_STENCIL_BITS, 0); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); #if BNB_OS_WINDOWS glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); #elif BNB_OS_MACOS || BNB_OS_LINUX glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); #endif // // Create window // // The new window is hidden until is shown, so // initial width and height are just dummy values auto initial_window_width = 1; auto initial_window_height = 1; m_window = glfwCreateWindow( initial_window_width, initial_window_height, title.c_str(), nullptr, share); if (nullptr == m_window) { throw std::runtime_error("glfwCreateWindow error"); } glfwSetWindowSizeCallback(m_window, [](GLFWwindow*, int w, int h) { glViewport(0, 0, w, h); window_width = w; window_height = h; resized = true; }); } void glfw_window::load_glad_functions() { #if BNB_OS_WINDOWS || BNB_OS_MACOS // it's only need for use while working with dynamic libs utility::load_gl_functions(); #endif if (0 == gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)) { throw std::runtime_error("gladLoadGLLoader error"); } }
cCOMMENT @---------------------------------------------------------------------- Copyright (c) GeoWorks 1988 -- All Rights Reserved PROJECT: PC GEOS MODULE: CommonUI/CSpec FILE: cspecTextDisplay.asm ROUTINES: Name Description ---- ----------- GLB OLBuildTextDisplay Convert a text display to the OL equivalent REVISION HISTORY: Name Date Description ---- ---- ----------- Doug 6/89 Initial version DESCRIPTION: $Id: cspecTextDisplay.asm,v 1.1 97/04/07 10:50:41 newdeal Exp $ ------------------------------------------------------------------------------@ Nuked. 7/ 7/92 cbh
; A345980: a(n) = spum of a path P_n. ; Submitted by Christian Krause ; 5,7,9,12,15,19,22,23,26,27,30 lpb $0 sub $0,1 mov $1,10 sub $1,$4 add $3,$2 add $1,$3 sub $3,$2 add $1,$3 mod $1,3 mov $2,$3 add $4,1 mov $5,$4 add $4,$1 div $5,3 add $5,$4 mov $3,$5 lpe mov $0,$3 add $0,5
/* * 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: mov (1|M0) r22.5<1>:ud 0x1200120:ud mov (1|M0) f0.0<1>:uw r24.0<0;1,0>:ub (W&~f0.0)jmpi L752 L48: mov (8|M0) r17.0<1>:ud r26.0<8;8,1>:ud mov (1|M0) r16.2<1>:ud 0xE000:ud cmp (1|M0) (eq)f1.0 null.0<1>:w r24.2<0;1,0>:ub 0x1:uw add (1|M0) a0.0<1>:ud r24.5<0;1,0>:ud 0x43EA100:ud (~f1.0) mov (1|M0) r17.2<1>:f r9.1<0;1,0>:f (~f1.0) mov (1|M0) r17.3<1>:f r9.4<0;1,0>:f (f1.0) mov (1|M0) r17.2<1>:f r9.1<0;1,0>:f (f1.0) mov (1|M0) r17.3<1>:f r9.7<0;1,0>:f send (1|M0) r46:uw r16:ub 0x2 a0.0 (~f1.0) mov (1|M0) r17.2<1>:f r9.6<0;1,0>:f (~f1.0) mov (1|M0) r17.3<1>:f r9.4<0;1,0>:f (f1.0) mov (1|M0) r17.2<1>:f r9.6<0;1,0>:f (f1.0) mov (1|M0) r17.3<1>:f r9.7<0;1,0>:f send (1|M0) r55:uw r16:ub 0x2 a0.0 add (1|M0) a0.0<1>:ud r24.5<0;1,0>:ud 0x43EA201:ud (~f1.0) mov (1|M0) r17.2<1>:f r9.1<0;1,0>:f (~f1.0) mov (1|M0) r17.3<1>:f r9.4<0;1,0>:f (f1.0) mov (1|M0) r17.2<1>:f r9.1<0;1,0>:f (f1.0) mov (1|M0) r17.3<1>:f r9.7<0;1,0>:f send (1|M0) r50:uw r16:ub 0x2 a0.0 (~f1.0) mov (1|M0) r17.2<1>:f r9.6<0;1,0>:f (~f1.0) mov (1|M0) r17.3<1>:f r9.4<0;1,0>:f (f1.0) mov (1|M0) r17.2<1>:f r9.6<0;1,0>:f (f1.0) mov (1|M0) r17.3<1>:f r9.7<0;1,0>:f send (1|M0) r59:uw r16:ub 0x2 a0.0 add (1|M0) a0.0<1>:ud r24.5<0;1,0>:ud 0x43EA302:ud (~f1.0) mov (1|M0) r17.2<1>:f r9.1<0;1,0>:f (~f1.0) mov (1|M0) r17.3<1>:f r9.4<0;1,0>:f (f1.0) mov (1|M0) r17.2<1>:f r9.1<0;1,0>:f (f1.0) mov (1|M0) r17.3<1>:f r9.7<0;1,0>:f send (1|M0) r52:uw r16:ub 0x2 a0.0 (~f1.0) mov (1|M0) r17.2<1>:f r9.6<0;1,0>:f (~f1.0) mov (1|M0) r17.3<1>:f r9.4<0;1,0>:f (f1.0) mov (1|M0) r17.2<1>:f r9.6<0;1,0>:f (f1.0) mov (1|M0) r17.3<1>:f r9.7<0;1,0>:f send (1|M0) r61:uw r16:ub 0x2 a0.0 mov (16|M0) r48.0<1>:uw 0xFFFF:uw mov (16|M0) r49.0<1>:uw 0xFFFF:uw mov (16|M0) r57.0<1>:uw 0xFFFF:uw mov (16|M0) r58.0<1>:uw 0xFFFF:uw mov (1|M0) a0.8<1>:uw 0x5C0:uw mov (1|M0) a0.9<1>:uw 0x640:uw mov (1|M0) a0.10<1>:uw 0x680:uw add (4|M0) a0.12<1>:uw a0.8<4;4,1>:uw 0x120:uw L752: nop
.size 8000 .text@48 jp lstatint .text@100 jp lbegin .data@143 c0 .text@150 lbegin: ld a, 00 ldff(ff), a ld a, 30 ldff(00), a ld a, 01 ldff(4d), a stop, 00 ld a, ff ldff(45), a ld b, 8c call lwaitly_b ld a, 40 ldff(41), a ld a, 02 ldff(ff), a ld a, b inc a inc a ldff(45), a ld c, 0f xor a, a ldff(0f), a ei .text@1000 lstatint: ld a, 10 ldff(41), a .text@11b0 xor a, a ldff(0f), a nop nop nop nop nop nop nop xor a, a ldff(41), a nop nop nop ldff a, (c) and a, 03 jp lprint_a .text@7000 lprint_a: push af ld b, 91 call lwaitly_b xor a, a ldff(40), a pop af ld(9800), a ld bc, 7a00 ld hl, 8000 ld d, a0 lprint_copytiles: ld a, (bc) inc bc ld(hl++), a dec d jrnz lprint_copytiles ld a, c0 ldff(47), a ld a, 80 ldff(68), a ld a, ff ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a xor a, a ldff(69), a ldff(69), a ldff(43), a ld a, 91 ldff(40), a lprint_limbo: jr lprint_limbo .text@7400 lwaitly_b: ld c, 44 lwaitly_b_loop: ldff a, (c) cmp a, b jrnz lwaitly_b_loop ret .data@7a00 00 00 7f 7f 41 41 41 41 41 41 41 41 41 41 7f 7f 00 00 08 08 08 08 08 08 08 08 08 08 08 08 08 08 00 00 7f 7f 01 01 01 01 7f 7f 40 40 40 40 7f 7f 00 00 7f 7f 01 01 01 01 3f 3f 01 01 01 01 7f 7f 00 00 41 41 41 41 41 41 7f 7f 01 01 01 01 01 01 00 00 7f 7f 40 40 40 40 7e 7e 01 01 01 01 7e 7e 00 00 7f 7f 40 40 40 40 7f 7f 41 41 41 41 7f 7f 00 00 7f 7f 01 01 02 02 04 04 08 08 10 10 10 10 00 00 3e 3e 41 41 41 41 3e 3e 41 41 41 41 3e 3e 00 00 7f 7f 41 41 41 41 7f 7f 01 01 01 01 7f 7f
; A195460: 2^(2*n+1) - 3*2^n - 1. ; 1,19,103,463,1951,7999,32383,130303,522751,2094079,8382463,33542143,134193151,536821759,2147385343,8589737983,34359345151,137438167039,549754241023,2199020109823,8796086730751,35184359505919,140737463189503,562949903089663,2251799713021951,9007199053414399 mov $1,2 pow $1,$0 mov $0,2 sub $1,1 mul $1,2 mov $3,$1 mul $3,2 add $0,$3 mul $1,2 mov $2,$1 mov $4,1 mul $4,$1 add $0,$4 add $2,3 mul $2,$1 mov $1,$0 add $1,$2 div $1,12 mul $1,6 add $1,1
; A204257: Matrix given by f(i,j)=1+[(i+2j) mod 3], by antidiagonals. ; 1,3,2,2,1,3,1,3,2,1,3,2,1,3,2,2,1,3,2,1,3,1,3,2,1,3,2,1,3,2,1,3,2,1,3,2,2,1,3,2,1,3,2,1,3,1,3,2,1,3,2,1,3,2,1,3,2,1,3,2,1,3,2,1,3,2,2,1,3,2,1,3,2,1,3,2,1,3,1,3,2,1,3,2,1,3,2,1,3,2,1,3,2,1,3,2,1,3,2 cal $0,294317 ; Triangle read by rows: T(n, k) = 2*n-k, k <= n. mod $0,3 add $0,56 mov $1,$0 sub $1,55
// Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "flutter/shell/platform/fuchsia/flutter/platform_view.h" #include <fuchsia/ui/gfx/cpp/fidl.h> #include <fuchsia/ui/scenic/cpp/fidl.h> #include <fuchsia/ui/views/cpp/fidl.h> #include <lib/async-loop/cpp/loop.h> #include <lib/async-loop/default.h> #include <lib/async/default.h> #include <lib/fidl/cpp/binding_set.h> #include <lib/sys/cpp/testing/service_directory_provider.h> #include <lib/ui/scenic/cpp/view_ref_pair.h> #include <memory> #include <ostream> #include <string> #include <vector> #include "flutter/flow/embedded_views.h" #include "flutter/lib/ui/window/platform_message.h" #include "flutter/lib/ui/window/viewport_metrics.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "surface.h" #include "task_runner_adapter.h" namespace flutter_runner::testing { namespace { class MockExternalViewEmbedder : public flutter::ExternalViewEmbedder { public: SkCanvas* GetRootCanvas() override { return nullptr; } std::vector<SkCanvas*> GetCurrentCanvases() override { return std::vector<SkCanvas*>(); } void CancelFrame() override {} void BeginFrame( SkISize frame_size, GrDirectContext* context, double device_pixel_ratio, fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) override {} void SubmitFrame(GrDirectContext* context, std::unique_ptr<flutter::SurfaceFrame> frame, const std::shared_ptr<const fml::SyncSwitch>& gpu_disable_sync_switch) override { return; } void PrerollCompositeEmbeddedView( int view_id, std::unique_ptr<flutter::EmbeddedViewParams> params) override {} SkCanvas* CompositeEmbeddedView(int view_id) override { return nullptr; } }; class MockPlatformViewDelegate : public flutter::PlatformView::Delegate { public: void Reset() { message_ = nullptr; metrics_ = flutter::ViewportMetrics{}; semantics_features_ = 0; semantics_enabled_ = false; } // |flutter::PlatformView::Delegate| void OnPlatformViewCreated(std::unique_ptr<flutter::Surface> surface) { ASSERT_EQ(surface_.get(), nullptr); surface_ = std::move(surface); } // |flutter::PlatformView::Delegate| void OnPlatformViewDestroyed() {} // |flutter::PlatformView::Delegate| void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) {} // |flutter::PlatformView::Delegate| void OnPlatformViewSetViewportMetrics( const flutter::ViewportMetrics& metrics) { metrics_ = metrics; } // |flutter::PlatformView::Delegate| void OnPlatformViewDispatchPlatformMessage( std::unique_ptr<flutter::PlatformMessage> message) { message_ = std::move(message); } // |flutter::PlatformView::Delegate| void OnPlatformViewDispatchPointerDataPacket( std::unique_ptr<flutter::PointerDataPacket> packet) {} // |flutter::PlatformView::Delegate| void OnPlatformViewDispatchKeyDataPacket( std::unique_ptr<flutter::KeyDataPacket> packet, std::function<void(bool)> callback) {} // |flutter::PlatformView::Delegate| void OnPlatformViewDispatchSemanticsAction(int32_t id, flutter::SemanticsAction action, std::vector<uint8_t> args) {} // |flutter::PlatformView::Delegate| void OnPlatformViewSetSemanticsEnabled(bool enabled) { semantics_enabled_ = enabled; } // |flutter::PlatformView::Delegate| void OnPlatformViewSetAccessibilityFeatures(int32_t flags) { semantics_features_ = flags; } // |flutter::PlatformView::Delegate| void OnPlatformViewRegisterTexture( std::shared_ptr<flutter::Texture> texture) {} // |flutter::PlatformView::Delegate| void OnPlatformViewUnregisterTexture(int64_t texture_id) {} // |flutter::PlatformView::Delegate| void OnPlatformViewMarkTextureFrameAvailable(int64_t texture_id) {} // |flutter::PlatformView::Delegate| std::unique_ptr<std::vector<std::string>> ComputePlatformViewResolvedLocale( const std::vector<std::string>& supported_locale_data) { return nullptr; } // |flutter::PlatformView::Delegate| void LoadDartDeferredLibrary( intptr_t loading_unit_id, std::unique_ptr<const fml::Mapping> snapshot_data, std::unique_ptr<const fml::Mapping> snapshot_instructions) {} // |flutter::PlatformView::Delegate| void LoadDartDeferredLibraryError(intptr_t loading_unit_id, const std::string error_message, bool transient) {} // |flutter::PlatformView::Delegate| void UpdateAssetResolverByType( std::unique_ptr<flutter::AssetResolver> updated_asset_resolver, flutter::AssetResolver::AssetResolverType type) {} flutter::Surface* surface() const { return surface_.get(); } flutter::PlatformMessage* message() const { return message_.get(); } const flutter::ViewportMetrics& metrics() const { return metrics_; } int32_t semantics_features() const { return semantics_features_; } bool semantics_enabled() const { return semantics_enabled_; } private: std::unique_ptr<flutter::Surface> surface_; std::unique_ptr<flutter::PlatformMessage> message_; flutter::ViewportMetrics metrics_; int32_t semantics_features_ = 0; bool semantics_enabled_ = false; }; class MockFocuser : public fuchsia::ui::views::Focuser { public: MockFocuser(bool fail_request_focus = false) : fail_request_focus_(fail_request_focus) {} bool request_focus_called() const { return request_focus_called_; } private: void RequestFocus(fuchsia::ui::views::ViewRef view_ref, RequestFocusCallback callback) override { request_focus_called_ = true; auto result = fail_request_focus_ ? fuchsia::ui::views::Focuser_RequestFocus_Result::WithErr( fuchsia::ui::views::Error::DENIED) : fuchsia::ui::views::Focuser_RequestFocus_Result::WithResponse( fuchsia::ui::views::Focuser_RequestFocus_Response()); callback(std::move(result)); } bool request_focus_called_ = false; bool fail_request_focus_ = false; }; class MockResponse : public flutter::PlatformMessageResponse { public: MOCK_METHOD1(Complete, void(std::unique_ptr<fml::Mapping> data)); MOCK_METHOD0(CompleteEmpty, void()); }; // Used to construct partial instances of PlatformView for testing. The // PlatformView constructor has many parameters, not all of which need to // be filled out for each test. The builder allows you to initialize only // those that matter to your specific test. Not all builder methods are // provided: if you find some that are missing, feel free to add them. class PlatformViewBuilder { public: PlatformViewBuilder(flutter::PlatformView::Delegate& delegate, flutter::TaskRunners task_runners, std::shared_ptr<sys::ServiceDirectory> runner_services) : delegate_(delegate), debug_label_("test_platform_view"), view_ref_(fuchsia::ui::views::ViewRef()), task_runners_(task_runners), runner_services_(runner_services) {} // Add builder methods as required. PlatformViewBuilder& SetServiceProvider( fidl::InterfaceHandle<fuchsia::sys::ServiceProvider> service_provider) { parent_environment_service_provider_ = std::move(service_provider); return *this; } PlatformViewBuilder& SetFocuser( fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser) { focuser_ = std::move(focuser); return *this; } PlatformViewBuilder& SetDestroyViewCallback(OnDestroyView callback) { on_destroy_view_callback_ = std::move(callback); return *this; } PlatformViewBuilder& SetUpdateViewCallback(OnUpdateView callback) { on_update_view_callback_ = std::move(callback); return *this; } PlatformViewBuilder& SetEnableWireframeCallback(OnEnableWireframe callback) { wireframe_enabled_callback_ = std::move(callback); return *this; } PlatformViewBuilder& SetCreateViewCallback(OnCreateView callback) { on_create_view_callback_ = std::move(callback); return *this; } PlatformViewBuilder& SetSessionListenerRequest( fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener> request) { session_listener_request_ = std::move(request); return *this; } PlatformViewBuilder& SetCreateSurfaceCallback(OnCreateSurface callback) { on_create_surface_callback_ = std::move(callback); return *this; } PlatformViewBuilder& SetViewEmbedder( std::shared_ptr<flutter::ExternalViewEmbedder> embedder) { view_embedder_ = embedder; return *this; } PlatformViewBuilder& SetKeyboardListener( fidl::InterfaceRequest<fuchsia::ui::input3::KeyboardListener> listener) { keyboard_listener_ = std::move(listener); return *this; } // Once Build is called, the instance is no longer usable. PlatformView Build() { EXPECT_EQ(false, built_) << "Build() was already called, this buider is good for one use only."; built_ = true; return PlatformView(delegate_, debug_label_, std::move(view_ref_), task_runners_, runner_services_, std::move(parent_environment_service_provider_), std::move(session_listener_request_), std::move(focuser_), std::move(keyboard_listener_), std::move(on_session_listener_error_callback_), std::move(wireframe_enabled_callback_), std::move(on_create_view_callback_), std::move(on_update_view_callback_), std::move(on_destroy_view_callback_), std::move(on_create_surface_callback_), view_embedder_, std::move(vsync_offset_), vsync_event_handle_); } private: PlatformViewBuilder() = delete; bool built_{false}; // Required elements. Make sure to initialize them. flutter::PlatformView::Delegate& delegate_; std::string debug_label_; fuchsia::ui::views::ViewRef view_ref_; flutter::TaskRunners task_runners_; std::shared_ptr<sys::ServiceDirectory> runner_services_{nullptr}; fidl::InterfaceHandle<fuchsia::sys::ServiceProvider> parent_environment_service_provider_{nullptr}; // Optional elements. fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener> session_listener_request_{nullptr}; fidl::InterfaceHandle<fuchsia::ui::views::Focuser> focuser_{nullptr}; fidl::InterfaceRequest<fuchsia::ui::input3::KeyboardListener> keyboard_listener_{nullptr}; fit::closure on_session_listener_error_callback_{nullptr}; OnEnableWireframe wireframe_enabled_callback_{nullptr}; OnCreateView on_create_view_callback_{nullptr}; OnUpdateView on_update_view_callback_{nullptr}; OnDestroyView on_destroy_view_callback_{nullptr}; OnCreateSurface on_create_surface_callback_{nullptr}; std::shared_ptr<flutter::ExternalViewEmbedder> view_embedder_{nullptr}; fml::TimeDelta vsync_offset_{fml::TimeDelta::Zero()}; zx_handle_t vsync_event_handle_{ZX_HANDLE_INVALID}; }; } // namespace class PlatformViewTests : public ::testing::Test { protected: PlatformViewTests() : loop_(&kAsyncLoopConfigAttachToCurrentThread) {} async_dispatcher_t* dispatcher() { return loop_.dispatcher(); } void RunLoopUntilIdle() { loop_.RunUntilIdle(); loop_.ResetQuit(); } fuchsia::ui::input3::KeyEvent MakeEvent( fuchsia::ui::input3::KeyEventType event_type, std::optional<fuchsia::ui::input3::Modifiers> modifiers, fuchsia::input::Key key) { fuchsia::ui::input3::KeyEvent event; event.set_timestamp(++event_timestamp_); event.set_type(event_type); if (modifiers.has_value()) { event.set_modifiers(modifiers.value()); } event.set_key(key); return event; } private: async::Loop loop_; uint64_t event_timestamp_{42}; FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewTests); }; // This test makes sure that the PlatformView correctly returns a Surface // instance that can surface the provided gr_context and view_embedder. TEST_F(PlatformViewTests, CreateSurfaceTest) { sys::testing::ServiceDirectoryProvider services_provider(dispatcher()); MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", // label nullptr, // platform flutter_runner::CreateFMLTaskRunner( async_get_default_dispatcher()), // raster nullptr, // ui nullptr // io ); // Test create surface callback function. sk_sp<GrDirectContext> gr_context = GrDirectContext::MakeMock(nullptr, GrContextOptions()); std::shared_ptr<MockExternalViewEmbedder> view_embedder = std::make_shared<MockExternalViewEmbedder>(); auto CreateSurfaceCallback = [&view_embedder, gr_context]() { return std::make_unique<flutter_runner::Surface>( "PlatformViewTest", view_embedder, gr_context.get()); }; flutter_runner::PlatformView platform_view = PlatformViewBuilder(delegate, std::move(task_runners), services_provider.service_directory()) .SetCreateSurfaceCallback(CreateSurfaceCallback) .SetViewEmbedder(view_embedder) .Build(); platform_view.NotifyCreated(); RunLoopUntilIdle(); EXPECT_EQ(gr_context.get(), delegate.surface()->GetContext()); EXPECT_EQ(view_embedder.get(), platform_view.CreateExternalViewEmbedder().get()); } // This test makes sure that the PlatformView correctly registers Scenic // MetricsEvents sent to it via FIDL, correctly parses the metrics it receives, // and calls the SetViewportMetrics callback with the appropriate parameters. TEST_F(PlatformViewTests, SetViewportMetrics) { constexpr float invalid_pixel_ratio = -0.75f; constexpr float valid_pixel_ratio = 0.75f; constexpr float invalid_max_bound = -0.75f; constexpr float valid_max_bound = 0.75f; MockPlatformViewDelegate delegate; EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics()); fuchsia::ui::scenic::SessionListenerPtr session_listener; std::vector<fuchsia::ui::scenic::Event> events; sys::testing::ServiceDirectoryProvider services_provider(dispatcher()); flutter::TaskRunners task_runners("test_runners", nullptr, nullptr, nullptr, nullptr); flutter_runner::PlatformView platform_view = PlatformViewBuilder(delegate, std::move(task_runners), services_provider.service_directory()) .SetSessionListenerRequest(session_listener.NewRequest()) .Build(); RunLoopUntilIdle(); EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics()); // Test updating with an invalid pixel ratio. The final metrics should be // unchanged. events.clear(); events.emplace_back(fuchsia::ui::scenic::Event::WithGfx( fuchsia::ui::gfx::Event::WithMetrics(fuchsia::ui::gfx::MetricsEvent{ .node_id = 0, .metrics = fuchsia::ui::gfx::Metrics{ .scale_x = invalid_pixel_ratio, .scale_y = 1.f, .scale_z = 1.f, }, }))); session_listener->OnScenicEvent(std::move(events)); RunLoopUntilIdle(); EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics()); // Test updating with an invalid size. The final metrics should be unchanged. events.clear(); events.emplace_back( fuchsia::ui::scenic::Event::WithGfx( fuchsia::ui::gfx::Event::WithViewPropertiesChanged( fuchsia::ui::gfx::ViewPropertiesChangedEvent{ .view_id = 0, .properties = fuchsia::ui::gfx::ViewProperties{ .bounding_box = fuchsia::ui::gfx::BoundingBox{ .min = fuchsia::ui::gfx::vec3{ .x = 0.f, .y = 0.f, .z = 0.f, }, .max = fuchsia::ui::gfx::vec3{ .x = invalid_max_bound, .y = invalid_max_bound, .z = invalid_max_bound, }, }, }, }))); session_listener->OnScenicEvent(std::move(events)); RunLoopUntilIdle(); EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics()); // Test updating the size only. The final metrics should be unchanged until // both pixel ratio and size are updated. events.clear(); events.emplace_back( fuchsia::ui::scenic::Event::WithGfx( fuchsia::ui::gfx::Event::WithViewPropertiesChanged( fuchsia::ui::gfx::ViewPropertiesChangedEvent{ .view_id = 0, .properties = fuchsia::ui::gfx::ViewProperties{ .bounding_box = fuchsia::ui::gfx::BoundingBox{ .min = fuchsia::ui::gfx::vec3{ .x = 0.f, .y = 0.f, .z = 0.f, }, .max = fuchsia::ui::gfx::vec3{ .x = valid_max_bound, .y = valid_max_bound, .z = valid_max_bound, }, }, }, }))); session_listener->OnScenicEvent(std::move(events)); RunLoopUntilIdle(); EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics()); // Test updating the pixel ratio only. The final metrics should change now. events.clear(); events.emplace_back(fuchsia::ui::scenic::Event::WithGfx( fuchsia::ui::gfx::Event::WithMetrics(fuchsia::ui::gfx::MetricsEvent{ .node_id = 0, .metrics = fuchsia::ui::gfx::Metrics{ .scale_x = valid_pixel_ratio, .scale_y = 1.f, .scale_z = 1.f, }, }))); session_listener->OnScenicEvent(std::move(events)); RunLoopUntilIdle(); EXPECT_EQ(delegate.metrics(), flutter::ViewportMetrics(valid_pixel_ratio, valid_pixel_ratio * valid_max_bound, valid_pixel_ratio * valid_max_bound)); } // This test makes sure that the PlatformView correctly registers semantics // settings changes applied to it and calls the SetSemanticsEnabled / // SetAccessibilityFeatures callbacks with the appropriate parameters. TEST_F(PlatformViewTests, ChangesAccessibilitySettings) { sys::testing::ServiceDirectoryProvider services_provider(dispatcher()); MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr); EXPECT_FALSE(delegate.semantics_enabled()); EXPECT_EQ(delegate.semantics_features(), 0); flutter_runner::PlatformView platform_view = PlatformViewBuilder( delegate, // delegate std::move(task_runners), // task_runners services_provider.service_directory() // runner_services ) .Build(); RunLoopUntilIdle(); platform_view.SetSemanticsEnabled(true); EXPECT_TRUE(delegate.semantics_enabled()); EXPECT_EQ(delegate.semantics_features(), static_cast<int32_t>( flutter::AccessibilityFeatureFlag::kAccessibleNavigation)); platform_view.SetSemanticsEnabled(false); EXPECT_FALSE(delegate.semantics_enabled()); EXPECT_EQ(delegate.semantics_features(), 0); } // This test makes sure that the PlatformView forwards messages on the // "flutter/platform_views" channel for EnableWireframe. TEST_F(PlatformViewTests, EnableWireframeTest) { sys::testing::ServiceDirectoryProvider services_provider(dispatcher()); MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr); // Test wireframe callback function. If the message sent to the platform // view was properly handled and parsed, this function should be called, // setting |wireframe_enabled| to true. bool wireframe_enabled = false; auto EnableWireframeCallback = [&wireframe_enabled](bool should_enable) { wireframe_enabled = should_enable; }; flutter_runner::PlatformView platform_view = PlatformViewBuilder(delegate, std::move(task_runners), services_provider.service_directory()) .SetEnableWireframeCallback(EnableWireframeCallback) .Build(); // Cast platform_view to its base view so we can have access to the public // "HandlePlatformMessage" function. auto base_view = static_cast<flutter::PlatformView*>(&platform_view); EXPECT_TRUE(base_view); // JSON for the message to be passed into the PlatformView. const uint8_t txt[] = "{" " \"method\":\"View.enableWireframe\"," " \"args\": {" " \"enable\":true" " }" "}"; std::unique_ptr<flutter::PlatformMessage> message = std::make_unique<flutter::PlatformMessage>( "flutter/platform_views", std::vector<uint8_t>(txt, txt + sizeof(txt)), fml::RefPtr<flutter::PlatformMessageResponse>()); base_view->HandlePlatformMessage(std::move(message)); RunLoopUntilIdle(); EXPECT_TRUE(wireframe_enabled); } // This test makes sure that the PlatformView forwards messages on the // "flutter/platform_views" channel for Createview. TEST_F(PlatformViewTests, CreateViewTest) { sys::testing::ServiceDirectoryProvider services_provider(dispatcher()); MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", // label flutter_runner::CreateFMLTaskRunner( async_get_default_dispatcher()), // platform nullptr, // raster nullptr, // ui nullptr // io ); // Test wireframe callback function. If the message sent to the platform // view was properly handled and parsed, this function should be called, // setting |wireframe_enabled| to true. bool create_view_called = false; auto CreateViewCallback = [&create_view_called]( int64_t view_id, flutter_runner::ViewIdCallback on_view_bound, bool hit_testable, bool focusable) { create_view_called = true; on_view_bound(0); }; flutter_runner::PlatformView platform_view = PlatformViewBuilder(delegate, std::move(task_runners), services_provider.service_directory()) .SetCreateViewCallback(CreateViewCallback) .Build(); // Cast platform_view to its base view so we can have access to the public // "HandlePlatformMessage" function. auto base_view = static_cast<flutter::PlatformView*>(&platform_view); EXPECT_TRUE(base_view); // JSON for the message to be passed into the PlatformView. const uint8_t txt[] = "{" " \"method\":\"View.create\"," " \"args\": {" " \"viewId\":42," " \"hitTestable\":true," " \"focusable\":true" " }" "}"; std::unique_ptr<flutter::PlatformMessage> message = std::make_unique<flutter::PlatformMessage>( "flutter/platform_views", std::vector<uint8_t>(txt, txt + sizeof(txt)), fml::RefPtr<flutter::PlatformMessageResponse>()); base_view->HandlePlatformMessage(std::move(message)); RunLoopUntilIdle(); EXPECT_TRUE(create_view_called); } // This test makes sure that the PlatformView forwards messages on the // "flutter/platform_views" channel for UpdateView. TEST_F(PlatformViewTests, UpdateViewTest) { sys::testing::ServiceDirectoryProvider services_provider(dispatcher()); MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr); // Test wireframe callback function. If the message sent to the platform // view was properly handled and parsed, this function should be called, // setting |wireframe_enabled| to true. bool update_view_called = false; auto UpdateViewCallback = [&update_view_called]( int64_t view_id, SkRect occlusion_hint, bool hit_testable, bool focusable) { update_view_called = true; }; flutter_runner::PlatformView platform_view = PlatformViewBuilder(delegate, std::move(task_runners), services_provider.service_directory()) .SetUpdateViewCallback(UpdateViewCallback) .Build(); // Cast platform_view to its base view so we can have access to the public // "HandlePlatformMessage" function. auto base_view = static_cast<flutter::PlatformView*>(&platform_view); EXPECT_TRUE(base_view); // JSON for the message to be passed into the PlatformView. const uint8_t txt[] = "{" " \"method\":\"View.update\"," " \"args\": {" " \"viewId\":42," " \"hitTestable\":true," " \"focusable\":true" " }" "}"; std::unique_ptr<flutter::PlatformMessage> message = std::make_unique<flutter::PlatformMessage>( "flutter/platform_views", std::vector<uint8_t>(txt, txt + sizeof(txt)), fml::RefPtr<flutter::PlatformMessageResponse>()); base_view->HandlePlatformMessage(std::move(message)); RunLoopUntilIdle(); EXPECT_TRUE(update_view_called); } // This test makes sure that the PlatformView forwards messages on the // "flutter/platform_views" channel for DestroyView. TEST_F(PlatformViewTests, DestroyViewTest) { sys::testing::ServiceDirectoryProvider services_provider(dispatcher()); MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", // label flutter_runner::CreateFMLTaskRunner( async_get_default_dispatcher()), // platform nullptr, // raster nullptr, // ui nullptr // io ); // Test wireframe callback function. If the message sent to the platform // view was properly handled and parsed, this function should be called, // setting |wireframe_enabled| to true. bool destroy_view_called = false; auto DestroyViewCallback = [&destroy_view_called](int64_t view_id, flutter_runner::ViewIdCallback on_view_unbound) { destroy_view_called = true; on_view_unbound(0); }; flutter_runner::PlatformView platform_view = PlatformViewBuilder(delegate, std::move(task_runners), services_provider.service_directory()) .SetDestroyViewCallback(DestroyViewCallback) .Build(); // Cast platform_view to its base view so we can have access to the public // "HandlePlatformMessage" function. auto base_view = static_cast<flutter::PlatformView*>(&platform_view); EXPECT_TRUE(base_view); // JSON for the message to be passed into the PlatformView. const uint8_t txt[] = "{" " \"method\":\"View.dispose\"," " \"args\": {" " \"viewId\":42" " }" "}"; std::unique_ptr<flutter::PlatformMessage> message = std::make_unique<flutter::PlatformMessage>( "flutter/platform_views", std::vector<uint8_t>(txt, txt + sizeof(txt)), fml::RefPtr<flutter::PlatformMessageResponse>()); base_view->HandlePlatformMessage(std::move(message)); RunLoopUntilIdle(); EXPECT_TRUE(destroy_view_called); } // This test makes sure that the PlatformView forwards messages on the // "flutter/platform_views" channel for ViewConnected, ViewDisconnected, and // ViewStateChanged events. TEST_F(PlatformViewTests, ViewEventsTest) { constexpr int64_t kViewId = 33; constexpr scenic::ResourceId kViewHolderId = 42; MockPlatformViewDelegate delegate; fuchsia::ui::scenic::SessionListenerPtr session_listener; std::vector<fuchsia::ui::scenic::Event> events; sys::testing::ServiceDirectoryProvider services_provider(dispatcher()); flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", // label flutter_runner::CreateFMLTaskRunner( async_get_default_dispatcher()), // platform flutter_runner::CreateFMLTaskRunner( async_get_default_dispatcher()), // raster flutter_runner::CreateFMLTaskRunner( async_get_default_dispatcher()), // ui nullptr // io ); auto on_create_view = [kViewId](int64_t view_id, flutter_runner::ViewIdCallback on_view_bound, bool hit_testable, bool focusable) { ASSERT_EQ(view_id, kViewId); on_view_bound(kViewHolderId); }; flutter_runner::PlatformView platform_view = PlatformViewBuilder(delegate, std::move(task_runners), services_provider.service_directory()) .SetSessionListenerRequest(session_listener.NewRequest()) .SetCreateViewCallback(on_create_view) .Build(); RunLoopUntilIdle(); ASSERT_EQ(delegate.message(), nullptr); // Create initial view for testing. std::ostringstream create_view_message; create_view_message << "{" << " \"method\":\"View.create\"," << " \"args\":{" << " \"viewId\":" << kViewId << "," << " \"hitTestable\":true," << " \"focusable\":true" << " }" << "}"; std::string create_view_call = create_view_message.str(); static_cast<flutter::PlatformView*>(&platform_view) ->HandlePlatformMessage(std::make_unique<flutter::PlatformMessage>( "flutter/platform_views", std::vector<uint8_t>(create_view_call.begin(), create_view_call.end()), fml::RefPtr<flutter::PlatformMessageResponse>())); RunLoopUntilIdle(); // ViewConnected event. delegate.Reset(); events.clear(); events.emplace_back(fuchsia::ui::scenic::Event::WithGfx( fuchsia::ui::gfx::Event::WithViewConnected( fuchsia::ui::gfx::ViewConnectedEvent{ .view_holder_id = kViewHolderId, }))); session_listener->OnScenicEvent(std::move(events)); RunLoopUntilIdle(); flutter::PlatformMessage* view_connected_msg = delegate.message(); ASSERT_NE(view_connected_msg, nullptr); std::ostringstream view_connected_expected_out; view_connected_expected_out << "{" << "\"method\":\"View.viewConnected\"," << "\"args\":{" << " \"viewId\":" << kViewId // ViewHolderToken handle << " }" << "}"; EXPECT_EQ(view_connected_expected_out.str(), std::string(view_connected_msg->data().begin(), view_connected_msg->data().end())); // ViewDisconnected event. delegate.Reset(); events.clear(); events.emplace_back(fuchsia::ui::scenic::Event::WithGfx( fuchsia::ui::gfx::Event::WithViewDisconnected( fuchsia::ui::gfx::ViewDisconnectedEvent{ .view_holder_id = kViewHolderId, }))); session_listener->OnScenicEvent(std::move(events)); RunLoopUntilIdle(); flutter::PlatformMessage* view_disconnected_msg = delegate.message(); ASSERT_NE(view_disconnected_msg, nullptr); std::ostringstream view_disconnected_expected_out; view_disconnected_expected_out << "{" << "\"method\":\"View.viewDisconnected\"," << "\"args\":{" << " \"viewId\":" << kViewId // ViewHolderToken handle << " }" << "}"; EXPECT_EQ(view_disconnected_expected_out.str(), std::string(view_disconnected_msg->data().begin(), view_disconnected_msg->data().end())); // ViewStateChanged event. delegate.Reset(); events.clear(); events.emplace_back(fuchsia::ui::scenic::Event::WithGfx( fuchsia::ui::gfx::Event::WithViewStateChanged( fuchsia::ui::gfx::ViewStateChangedEvent{ .view_holder_id = kViewHolderId, .state = fuchsia::ui::gfx::ViewState{ .is_rendering = true, }, }))); session_listener->OnScenicEvent(std::move(events)); RunLoopUntilIdle(); flutter::PlatformMessage* view_state_changed_msg = delegate.message(); ASSERT_NE(view_state_changed_msg, nullptr); std::ostringstream view_state_changed_expected_out; view_state_changed_expected_out << "{" << "\"method\":\"View.viewStateChanged\"," << "\"args\":{" << " \"viewId\":" << kViewId << "," // ViewHolderToken << " \"is_rendering\":true," // IsViewRendering << " \"state\":true" // IsViewRendering << " }" << "}"; EXPECT_EQ(view_state_changed_expected_out.str(), std::string(view_state_changed_msg->data().begin(), view_state_changed_msg->data().end())); } // This test makes sure that the PlatformView forwards messages on the // "flutter/platform_views" channel for RequestFocus. TEST_F(PlatformViewTests, RequestFocusTest) { sys::testing::ServiceDirectoryProvider services_provider(dispatcher()); MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr); MockFocuser mock_focuser; fidl::BindingSet<fuchsia::ui::views::Focuser> focuser_bindings; auto focuser_handle = focuser_bindings.AddBinding(&mock_focuser); flutter_runner::PlatformView platform_view = PlatformViewBuilder(delegate, std::move(task_runners), services_provider.service_directory()) .SetFocuser(std::move(focuser_handle)) .Build(); // Cast platform_view to its base view so we can have access to the public // "HandlePlatformMessage" function. auto base_view = static_cast<flutter::PlatformView*>(&platform_view); EXPECT_TRUE(base_view); // This "Mock" ViewRef serves as the target for the RequestFocus operation. auto mock_view_ref_pair = scenic::ViewRefPair::New(); // JSON for the message to be passed into the PlatformView. char buff[254]; snprintf(buff, sizeof(buff), "{" " \"method\":\"View.requestFocus\"," " \"args\": {" " \"viewRef\":%u" " }" "}", mock_view_ref_pair.view_ref.reference.get()); // Define a custom gmock matcher to capture the response to platform message. struct DataArg { void Complete(std::unique_ptr<fml::Mapping> data) { this->data = std::move(data); } std::unique_ptr<fml::Mapping> data; }; DataArg data_arg; fml::RefPtr<MockResponse> response = fml::MakeRefCounted<MockResponse>(); EXPECT_CALL(*response, Complete(::testing::_)) .WillOnce(::testing::Invoke(&data_arg, &DataArg::Complete)); std::unique_ptr<flutter::PlatformMessage> message = std::make_unique<flutter::PlatformMessage>( "flutter/platform_views", std::vector<uint8_t>(buff, buff + sizeof(buff)), response); base_view->HandlePlatformMessage(std::move(message)); RunLoopUntilIdle(); EXPECT_TRUE(mock_focuser.request_focus_called()); auto result = std::string((const char*)data_arg.data->GetMapping(), data_arg.data->GetSize()); EXPECT_EQ(std::string("[0]"), result); } // This test makes sure that the PlatformView correctly replies with an error // response when a RequestFocus call fails. TEST_F(PlatformViewTests, RequestFocusFailTest) { sys::testing::ServiceDirectoryProvider services_provider(dispatcher()); MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr); MockFocuser mock_focuser(true /*fail_request_focus*/); fidl::BindingSet<fuchsia::ui::views::Focuser> focuser_bindings; auto focuser_handle = focuser_bindings.AddBinding(&mock_focuser); flutter_runner::PlatformView platform_view = PlatformViewBuilder(delegate, std::move(task_runners), services_provider.service_directory()) .SetFocuser(std::move(focuser_handle)) .Build(); // Cast platform_view to its base view so we can have access to the public // "HandlePlatformMessage" function. auto base_view = static_cast<flutter::PlatformView*>(&platform_view); EXPECT_TRUE(base_view); // This "Mock" ViewRef serves as the target for the RequestFocus operation. auto mock_view_ref_pair = scenic::ViewRefPair::New(); // JSON for the message to be passed into the PlatformView. char buff[254]; snprintf(buff, sizeof(buff), "{" " \"method\":\"View.requestFocus\"," " \"args\": {" " \"viewRef\":%u" " }" "}", mock_view_ref_pair.view_ref.reference.get()); // Define a custom gmock matcher to capture the response to platform message. struct DataArg { void Complete(std::unique_ptr<fml::Mapping> data) { this->data = std::move(data); } std::unique_ptr<fml::Mapping> data; }; DataArg data_arg; fml::RefPtr<MockResponse> response = fml::MakeRefCounted<MockResponse>(); EXPECT_CALL(*response, Complete(::testing::_)) .WillOnce(::testing::Invoke(&data_arg, &DataArg::Complete)); std::unique_ptr<flutter::PlatformMessage> message = std::make_unique<flutter::PlatformMessage>( "flutter/platform_views", std::vector<uint8_t>(buff, buff + sizeof(buff)), response); base_view->HandlePlatformMessage(std::move(message)); RunLoopUntilIdle(); EXPECT_TRUE(mock_focuser.request_focus_called()); auto result = std::string((const char*)data_arg.data->GetMapping(), data_arg.data->GetSize()); std::ostringstream out; out << "[" << static_cast<std::underlying_type_t<fuchsia::ui::views::Error>>( fuchsia::ui::views::Error::DENIED) << "]"; EXPECT_EQ(out.str(), result); } struct EventFlow { fuchsia::ui::input3::KeyEvent event; fuchsia::ui::input3::KeyEventStatus expected_key_event_status; std::string expected_platform_message; }; // Makes sure that OnKeyEvent is dispatched as a platform message. TEST_F(PlatformViewTests, OnKeyEvent) { sys::testing::ServiceDirectoryProvider services_provider(dispatcher()); MockPlatformViewDelegate delegate; flutter::TaskRunners task_runners = flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr); fidl::InterfacePtr<fuchsia::ui::input3::KeyboardListener> keyboard_listener; flutter_runner::PlatformView platform_view = PlatformViewBuilder(delegate, std::move(task_runners), services_provider.service_directory()) .SetKeyboardListener(keyboard_listener.NewRequest(dispatcher())) .Build(); using fuchsia::input::Key; using fuchsia::ui::input3::KeyEvent; using fuchsia::ui::input3::KeyEventStatus; using fuchsia::ui::input3::KeyEventType; using fuchsia::ui::input3::Modifiers; std::vector<EventFlow> events; // Press A. Get 'a'. events.emplace_back(EventFlow{ MakeEvent(KeyEventType::PRESSED, std::nullopt, Key::A), KeyEventStatus::HANDLED, R"({"type":"keydown","keymap":"fuchsia","hidUsage":4,"codePoint":97,"modifiers":0})", }); // Release A. Get 'a' release. events.emplace_back(EventFlow{ MakeEvent(KeyEventType::RELEASED, std::nullopt, Key::A), KeyEventStatus::HANDLED, R"({"type":"keyup","keymap":"fuchsia","hidUsage":4,"codePoint":97,"modifiers":0})", }); // Press CAPS_LOCK. Modifier now active. events.emplace_back(EventFlow{ MakeEvent(KeyEventType::PRESSED, Modifiers::CAPS_LOCK, Key::CAPS_LOCK), KeyEventStatus::HANDLED, R"({"type":"keydown","keymap":"fuchsia","hidUsage":57,"codePoint":0,"modifiers":1})", }); // Pres A. Get 'A'. events.emplace_back(EventFlow{ MakeEvent(KeyEventType::PRESSED, std::nullopt, Key::A), KeyEventStatus::HANDLED, R"({"type":"keydown","keymap":"fuchsia","hidUsage":4,"codePoint":65,"modifiers":1})", }); // Release CAPS_LOCK. events.emplace_back(EventFlow{ MakeEvent(KeyEventType::RELEASED, Modifiers::CAPS_LOCK, Key::CAPS_LOCK), KeyEventStatus::HANDLED, R"({"type":"keyup","keymap":"fuchsia","hidUsage":57,"codePoint":0,"modifiers":1})", }); // Press A again. This time get 'A'. // CAPS_LOCK is latched active even if it was just released. events.emplace_back(EventFlow{ MakeEvent(KeyEventType::PRESSED, std::nullopt, Key::A), KeyEventStatus::HANDLED, R"({"type":"keydown","keymap":"fuchsia","hidUsage":4,"codePoint":65,"modifiers":1})", }); for (const auto& event : events) { KeyEvent e; event.event.Clone(&e); fuchsia::ui::input3::KeyEventStatus key_event_status; keyboard_listener->OnKeyEvent( std::move(e), [&key_event_status](fuchsia::ui::input3::KeyEventStatus status) { key_event_status = status; }); RunLoopUntilIdle(); const std::vector<uint8_t> data = delegate.message()->data(); const std::string message = std::string(data.begin(), data.end()); EXPECT_EQ(event.expected_platform_message, message); EXPECT_EQ(key_event_status, event.expected_key_event_status); } } } // namespace flutter_runner::testing
BillsHouse_Script: call EnableAutoTextBoxDrawing ld a, [wBillsHouseCurScript] ld hl, BillsHouse_ScriptPointers jp CallFunctionInTable BillsHouse_ScriptPointers: dw BillsHouseScript0 dw BillsHouseScript1 dw BillsHouseScript2 dw BillsHouseScript3 dw BillsHouseScript4 dw BillsHouseScript5 BillsHouseScript0: ret BillsHouseScript1: ld a, [wSpritePlayerStateData1FacingDirection] and a ; cp SPRITE_FACING_DOWN ld de, MovementData_1e79c jr nz, .notDown ld de, MovementData_1e7a0 .notDown ld a, $1 ldh [hSpriteIndex], a call MoveSprite ld a, $2 ld [wBillsHouseCurScript], a ret MovementData_1e79c: db NPC_MOVEMENT_UP db NPC_MOVEMENT_UP db NPC_MOVEMENT_UP db -1 ; end ; make Bill walk around the player MovementData_1e7a0: db NPC_MOVEMENT_RIGHT db NPC_MOVEMENT_UP db NPC_MOVEMENT_UP db NPC_MOVEMENT_LEFT db NPC_MOVEMENT_UP db -1 ; end BillsHouseScript2: ld a, [wd730] bit 0, a ret nz ld a, HS_BILL_POKEMON ld [wMissableObjectIndex], a predef HideObject SetEvent EVENT_BILL_SAID_USE_CELL_SEPARATOR xor a ld [wJoyIgnore], a ld a, $3 ld [wBillsHouseCurScript], a ret BillsHouseScript3: CheckEvent EVENT_USED_CELL_SEPARATOR_ON_BILL ret z ld a, $f0 ld [wJoyIgnore], a ld a, $2 ld [wSpriteIndex], a ld a, $c ldh [hSpriteScreenYCoord], a ld a, $40 ldh [hSpriteScreenXCoord], a ld a, 6 ldh [hSpriteMapYCoord], a ld a, 5 ldh [hSpriteMapXCoord], a call SetSpritePosition1 ld a, HS_BILL_1 ld [wMissableObjectIndex], a predef ShowObject ld c, 8 call DelayFrames ld a, $2 ldh [hSpriteIndex], a ld de, MovementData_1e807 call MoveSprite ld a, $4 ld [wBillsHouseCurScript], a ret MovementData_1e807: db NPC_MOVEMENT_DOWN db NPC_MOVEMENT_RIGHT db NPC_MOVEMENT_RIGHT db NPC_MOVEMENT_RIGHT db NPC_MOVEMENT_DOWN db -1 ; end BillsHouseScript4: ld a, [wd730] bit 0, a ret nz xor a ld [wJoyIgnore], a SetEvent EVENT_MET_BILL_2 ; this event seems redundant SetEvent EVENT_MET_BILL ld a, $0 ld [wBillsHouseCurScript], a ret BillsHouseScript5: ld a, $4 ldh [hSpriteIndexOrTextID], a call DisplayTextID ld a, $0 ld [wBillsHouseCurScript], a ret BillsHouse_TextPointers: dw BillsHouseText1 dw BillsHouseText2 dw BillsHouseText3 dw BillsHouseText4 BillsHouseText4: script_bills_pc BillsHouseText1: text_asm ld hl, BillsHouseText_1e865 call PrintText call YesNoChoice ld a, [wCurrentMenuItem] and a jr nz, .asm_1e85a .asm_1e84d ld hl, BillsHouseText_1e86a call PrintText ld a, $1 ld [wBillsHouseCurScript], a jr .asm_1e862 .asm_1e85a ld hl, BillsHouseText_1e86f call PrintText jr .asm_1e84d .asm_1e862 jp TextScriptEnd BillsHouseText_1e865: text_far _BillsHouseText_1e865 text_end BillsHouseText_1e86a: text_far _BillsHouseText_1e86a text_end BillsHouseText_1e86f: text_far _BillsHouseText_1e86f text_end BillsHouseText2: text_asm CheckEvent EVENT_GOT_SS_TICKET jr nz, .asm_1e8a9 ld hl, BillThankYouText call PrintText lb bc, S_S_TICKET, 1 call GiveItem jr nc, .BagFull ld hl, SSTicketReceivedText call PrintText SetEvent EVENT_GOT_SS_TICKET ld a, HS_CERULEAN_GUARD_1 ld [wMissableObjectIndex], a predef ShowObject ld a, HS_CERULEAN_GUARD_2 ld [wMissableObjectIndex], a predef HideObject .asm_1e8a9 ld hl, BillsHouseText_1e8cb call PrintText jr .asm_1e8b7 .BagFull ld hl, SSTicketNoRoomText call PrintText .asm_1e8b7 jp TextScriptEnd BillThankYouText: text_far _BillThankYouText text_end SSTicketReceivedText: text_far _SSTicketReceivedText sound_get_key_item text_promptbutton text_end SSTicketNoRoomText: text_far _SSTicketNoRoomText text_end BillsHouseText_1e8cb: text_far _BillsHouseText_1e8cb text_end BillsHouseText3: text_asm ld hl, BillsHouseText_1e8da call PrintText jp TextScriptEnd BillsHouseText_1e8da: text_far _BillsHouseText_1e8da text_end
_lseek_test: file format elf32-i386 Disassembly of section .text: 00000000 <main>: #include "types.h" #include "stat.h" #include "user.h" #include "fcntl.h" int main(int argc, char *argv[]) { 0: 8d 4c 24 04 lea 0x4(%esp),%ecx 4: 83 e4 f0 and $0xfffffff0,%esp 7: ff 71 fc pushl -0x4(%ecx) a: 55 push %ebp b: 89 e5 mov %esp,%ebp d: 57 push %edi e: 56 push %esi f: 53 push %ebx 10: 51 push %ecx 11: 81 ec 94 00 00 00 sub $0x94,%esp 17: 8b 59 04 mov 0x4(%ecx),%ebx char *file_name = argv[1]; 1a: 8b 53 04 mov 0x4(%ebx),%edx int offset = atoi(argv[2]); 1d: ff 73 08 pushl 0x8(%ebx) char *file_name = argv[1]; 20: 89 95 70 ff ff ff mov %edx,-0x90(%ebp) int offset = atoi(argv[2]); 26: e8 c5 02 00 00 call 2f0 <atoi> 2b: 89 c6 mov %eax,%esi int len = atoi(argv[3]); 2d: 58 pop %eax 2e: ff 73 0c pushl 0xc(%ebx) 31: e8 ba 02 00 00 call 2f0 <atoi> char *string = argv[4]; 36: 8b 7b 10 mov 0x10(%ebx),%edi int len = atoi(argv[3]); 39: 89 85 74 ff ff ff mov %eax,-0x8c(%ebp) int fd = open(file_name, O_RDWR); 3f: 58 pop %eax 40: 5a pop %edx 41: 8b 95 70 ff ff ff mov -0x90(%ebp),%edx 47: 6a 02 push $0x2 49: 52 push %edx 4a: e8 54 03 00 00 call 3a3 <open> if (fd != -1) 4f: 83 c4 10 add $0x10,%esp int fd = open(file_name, O_RDWR); 52: 89 c3 mov %eax,%ebx if (fd != -1) 54: 83 f8 ff cmp $0xffffffff,%eax 57: 74 11 je 6a <main+0x6a> printf(1, "File opened successfully\n"); 59: 50 push %eax 5a: 50 push %eax 5b: 68 38 08 00 00 push $0x838 60: 6a 01 push $0x1 62: e8 69 04 00 00 call 4d0 <printf> 67: 83 c4 10 add $0x10,%esp if (lseek(fd, offset, SEEK_SET) == -1) { 6a: 83 ec 04 sub $0x4,%esp 6d: 6a 00 push $0x0 6f: 56 push %esi 70: 53 push %ebx 71: e8 95 03 00 00 call 40b <lseek> 76: 83 c4 10 add $0x10,%esp 79: 83 f8 ff cmp $0xffffffff,%eax 7c: 74 7a je f8 <main+0xf8> } char content[100]; int ret_read = read(fd, content, len); 7e: 83 ec 04 sub $0x4,%esp 81: 8d 75 84 lea -0x7c(%ebp),%esi 84: ff b5 74 ff ff ff pushl -0x8c(%ebp) 8a: 56 push %esi 8b: 53 push %ebx 8c: e8 ea 02 00 00 call 37b <read> content[ret_read] = '\0'; printf(1, "The expected string is : %s\n", string); 91: 83 c4 0c add $0xc,%esp 94: 57 push %edi 95: 68 60 08 00 00 push $0x860 9a: 6a 01 push $0x1 content[ret_read] = '\0'; 9c: c6 44 05 84 00 movb $0x0,-0x7c(%ebp,%eax,1) printf(1, "The expected string is : %s\n", string); a1: e8 2a 04 00 00 call 4d0 <printf> printf(1, "The string got by read is : %s\n", content); a6: 83 c4 0c add $0xc,%esp a9: 56 push %esi aa: 68 b0 08 00 00 push $0x8b0 af: 6a 01 push $0x1 b1: e8 1a 04 00 00 call 4d0 <printf> if (!strcmp(string, content)) { b6: 59 pop %ecx b7: 58 pop %eax b8: 56 push %esi b9: 57 push %edi ba: e8 81 00 00 00 call 140 <strcmp> bf: 83 c4 10 add $0x10,%esp c2: 85 c0 test %eax,%eax c4: 75 1f jne e5 <main+0xe5> printf(1, "Content verified\n"); c6: 52 push %edx c7: 52 push %edx c8: 68 7d 08 00 00 push $0x87d cd: 6a 01 push $0x1 cf: e8 fc 03 00 00 call 4d0 <printf> d4: 83 c4 10 add $0x10,%esp printf(1, "Content unable to be verified"); } close(fd); d7: 83 ec 0c sub $0xc,%esp da: 53 push %ebx db: e8 ab 02 00 00 call 38b <close> exit(); e0: e8 7e 02 00 00 call 363 <exit> printf(1, "Content unable to be verified"); e5: 50 push %eax e6: 50 push %eax e7: 68 8f 08 00 00 push $0x88f ec: 6a 01 push $0x1 ee: e8 dd 03 00 00 call 4d0 <printf> f3: 83 c4 10 add $0x10,%esp f6: eb df jmp d7 <main+0xd7> printf(1, "Lseek failed\n"); f8: 50 push %eax f9: 50 push %eax fa: 68 52 08 00 00 push $0x852 ff: 6a 01 push $0x1 101: e8 ca 03 00 00 call 4d0 <printf> 106: 83 c4 10 add $0x10,%esp 109: e9 70 ff ff ff jmp 7e <main+0x7e> 10e: 66 90 xchg %ax,%ax 00000110 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { 110: 55 push %ebp char *os; os = s; while((*s++ = *t++) != 0) 111: 31 c0 xor %eax,%eax { 113: 89 e5 mov %esp,%ebp 115: 53 push %ebx 116: 8b 4d 08 mov 0x8(%ebp),%ecx 119: 8b 5d 0c mov 0xc(%ebp),%ebx 11c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi while((*s++ = *t++) != 0) 120: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx 124: 88 14 01 mov %dl,(%ecx,%eax,1) 127: 83 c0 01 add $0x1,%eax 12a: 84 d2 test %dl,%dl 12c: 75 f2 jne 120 <strcpy+0x10> ; return os; } 12e: 8b 5d fc mov -0x4(%ebp),%ebx 131: 89 c8 mov %ecx,%eax 133: c9 leave 134: c3 ret 135: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 13c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000140 <strcmp>: int strcmp(const char *p, const char *q) { 140: 55 push %ebp 141: 89 e5 mov %esp,%ebp 143: 53 push %ebx 144: 8b 4d 08 mov 0x8(%ebp),%ecx 147: 8b 55 0c mov 0xc(%ebp),%edx while(*p && *p == *q) 14a: 0f b6 01 movzbl (%ecx),%eax 14d: 0f b6 1a movzbl (%edx),%ebx 150: 84 c0 test %al,%al 152: 75 1d jne 171 <strcmp+0x31> 154: eb 2a jmp 180 <strcmp+0x40> 156: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 15d: 8d 76 00 lea 0x0(%esi),%esi 160: 0f b6 41 01 movzbl 0x1(%ecx),%eax p++, q++; 164: 83 c1 01 add $0x1,%ecx 167: 83 c2 01 add $0x1,%edx return (uchar)*p - (uchar)*q; 16a: 0f b6 1a movzbl (%edx),%ebx while(*p && *p == *q) 16d: 84 c0 test %al,%al 16f: 74 0f je 180 <strcmp+0x40> 171: 38 d8 cmp %bl,%al 173: 74 eb je 160 <strcmp+0x20> return (uchar)*p - (uchar)*q; 175: 29 d8 sub %ebx,%eax } 177: 8b 5d fc mov -0x4(%ebp),%ebx 17a: c9 leave 17b: c3 ret 17c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 180: 31 c0 xor %eax,%eax return (uchar)*p - (uchar)*q; 182: 29 d8 sub %ebx,%eax } 184: 8b 5d fc mov -0x4(%ebp),%ebx 187: c9 leave 188: c3 ret 189: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000190 <strlen>: uint strlen(const char *s) { 190: 55 push %ebp 191: 89 e5 mov %esp,%ebp 193: 8b 55 08 mov 0x8(%ebp),%edx int n; for(n = 0; s[n]; n++) 196: 80 3a 00 cmpb $0x0,(%edx) 199: 74 15 je 1b0 <strlen+0x20> 19b: 31 c0 xor %eax,%eax 19d: 8d 76 00 lea 0x0(%esi),%esi 1a0: 83 c0 01 add $0x1,%eax 1a3: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1) 1a7: 89 c1 mov %eax,%ecx 1a9: 75 f5 jne 1a0 <strlen+0x10> ; return n; } 1ab: 89 c8 mov %ecx,%eax 1ad: 5d pop %ebp 1ae: c3 ret 1af: 90 nop for(n = 0; s[n]; n++) 1b0: 31 c9 xor %ecx,%ecx } 1b2: 5d pop %ebp 1b3: 89 c8 mov %ecx,%eax 1b5: c3 ret 1b6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1bd: 8d 76 00 lea 0x0(%esi),%esi 000001c0 <memset>: void* memset(void *dst, int c, uint n) { 1c0: 55 push %ebp 1c1: 89 e5 mov %esp,%ebp 1c3: 57 push %edi 1c4: 8b 55 08 mov 0x8(%ebp),%edx } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : 1c7: 8b 4d 10 mov 0x10(%ebp),%ecx 1ca: 8b 45 0c mov 0xc(%ebp),%eax 1cd: 89 d7 mov %edx,%edi 1cf: fc cld 1d0: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 1d2: 8b 7d fc mov -0x4(%ebp),%edi 1d5: 89 d0 mov %edx,%eax 1d7: c9 leave 1d8: c3 ret 1d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 000001e0 <strchr>: char* strchr(const char *s, char c) { 1e0: 55 push %ebp 1e1: 89 e5 mov %esp,%ebp 1e3: 8b 45 08 mov 0x8(%ebp),%eax 1e6: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx for(; *s; s++) 1ea: 0f b6 10 movzbl (%eax),%edx 1ed: 84 d2 test %dl,%dl 1ef: 75 12 jne 203 <strchr+0x23> 1f1: eb 1d jmp 210 <strchr+0x30> 1f3: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 1f7: 90 nop 1f8: 0f b6 50 01 movzbl 0x1(%eax),%edx 1fc: 83 c0 01 add $0x1,%eax 1ff: 84 d2 test %dl,%dl 201: 74 0d je 210 <strchr+0x30> if(*s == c) 203: 38 d1 cmp %dl,%cl 205: 75 f1 jne 1f8 <strchr+0x18> return (char*)s; return 0; } 207: 5d pop %ebp 208: c3 ret 209: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi return 0; 210: 31 c0 xor %eax,%eax } 212: 5d pop %ebp 213: c3 ret 214: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 21b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 21f: 90 nop 00000220 <gets>: char* gets(char *buf, int max) { 220: 55 push %ebp 221: 89 e5 mov %esp,%ebp 223: 57 push %edi 224: 56 push %esi int i, cc; char c; for(i=0; i+1 < max; ){ 225: 31 f6 xor %esi,%esi { 227: 53 push %ebx 228: 89 f3 mov %esi,%ebx 22a: 83 ec 1c sub $0x1c,%esp 22d: 8b 7d 08 mov 0x8(%ebp),%edi for(i=0; i+1 < max; ){ 230: eb 2f jmp 261 <gets+0x41> 232: 8d b6 00 00 00 00 lea 0x0(%esi),%esi cc = read(0, &c, 1); 238: 83 ec 04 sub $0x4,%esp 23b: 8d 45 e7 lea -0x19(%ebp),%eax 23e: 6a 01 push $0x1 240: 50 push %eax 241: 6a 00 push $0x0 243: e8 33 01 00 00 call 37b <read> if(cc < 1) 248: 83 c4 10 add $0x10,%esp 24b: 85 c0 test %eax,%eax 24d: 7e 1c jle 26b <gets+0x4b> break; buf[i++] = c; 24f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax if(c == '\n' || c == '\r') 253: 83 c7 01 add $0x1,%edi buf[i++] = c; 256: 88 47 ff mov %al,-0x1(%edi) if(c == '\n' || c == '\r') 259: 3c 0a cmp $0xa,%al 25b: 74 23 je 280 <gets+0x60> 25d: 3c 0d cmp $0xd,%al 25f: 74 1f je 280 <gets+0x60> for(i=0; i+1 < max; ){ 261: 83 c3 01 add $0x1,%ebx buf[i++] = c; 264: 89 fe mov %edi,%esi for(i=0; i+1 < max; ){ 266: 3b 5d 0c cmp 0xc(%ebp),%ebx 269: 7c cd jl 238 <gets+0x18> 26b: 89 f3 mov %esi,%ebx break; } buf[i] = '\0'; return buf; } 26d: 8b 45 08 mov 0x8(%ebp),%eax buf[i] = '\0'; 270: c6 03 00 movb $0x0,(%ebx) } 273: 8d 65 f4 lea -0xc(%ebp),%esp 276: 5b pop %ebx 277: 5e pop %esi 278: 5f pop %edi 279: 5d pop %ebp 27a: c3 ret 27b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 27f: 90 nop buf[i] = '\0'; 280: 8b 75 08 mov 0x8(%ebp),%esi } 283: 8b 45 08 mov 0x8(%ebp),%eax buf[i] = '\0'; 286: 01 de add %ebx,%esi 288: 89 f3 mov %esi,%ebx 28a: c6 03 00 movb $0x0,(%ebx) } 28d: 8d 65 f4 lea -0xc(%ebp),%esp 290: 5b pop %ebx 291: 5e pop %esi 292: 5f pop %edi 293: 5d pop %ebp 294: c3 ret 295: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 29c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 000002a0 <stat>: int stat(const char *n, struct stat *st) { 2a0: 55 push %ebp 2a1: 89 e5 mov %esp,%ebp 2a3: 56 push %esi 2a4: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); 2a5: 83 ec 08 sub $0x8,%esp 2a8: 6a 00 push $0x0 2aa: ff 75 08 pushl 0x8(%ebp) 2ad: e8 f1 00 00 00 call 3a3 <open> if(fd < 0) 2b2: 83 c4 10 add $0x10,%esp 2b5: 85 c0 test %eax,%eax 2b7: 78 27 js 2e0 <stat+0x40> return -1; r = fstat(fd, st); 2b9: 83 ec 08 sub $0x8,%esp 2bc: ff 75 0c pushl 0xc(%ebp) 2bf: 89 c3 mov %eax,%ebx 2c1: 50 push %eax 2c2: e8 f4 00 00 00 call 3bb <fstat> close(fd); 2c7: 89 1c 24 mov %ebx,(%esp) r = fstat(fd, st); 2ca: 89 c6 mov %eax,%esi close(fd); 2cc: e8 ba 00 00 00 call 38b <close> return r; 2d1: 83 c4 10 add $0x10,%esp } 2d4: 8d 65 f8 lea -0x8(%ebp),%esp 2d7: 89 f0 mov %esi,%eax 2d9: 5b pop %ebx 2da: 5e pop %esi 2db: 5d pop %ebp 2dc: c3 ret 2dd: 8d 76 00 lea 0x0(%esi),%esi return -1; 2e0: be ff ff ff ff mov $0xffffffff,%esi 2e5: eb ed jmp 2d4 <stat+0x34> 2e7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 2ee: 66 90 xchg %ax,%ax 000002f0 <atoi>: int atoi(const char *s) { 2f0: 55 push %ebp 2f1: 89 e5 mov %esp,%ebp 2f3: 53 push %ebx 2f4: 8b 55 08 mov 0x8(%ebp),%edx int n; n = 0; while('0' <= *s && *s <= '9') 2f7: 0f be 02 movsbl (%edx),%eax 2fa: 8d 48 d0 lea -0x30(%eax),%ecx 2fd: 80 f9 09 cmp $0x9,%cl n = 0; 300: b9 00 00 00 00 mov $0x0,%ecx while('0' <= *s && *s <= '9') 305: 77 1e ja 325 <atoi+0x35> 307: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 30e: 66 90 xchg %ax,%ax n = n*10 + *s++ - '0'; 310: 83 c2 01 add $0x1,%edx 313: 8d 0c 89 lea (%ecx,%ecx,4),%ecx 316: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx while('0' <= *s && *s <= '9') 31a: 0f be 02 movsbl (%edx),%eax 31d: 8d 58 d0 lea -0x30(%eax),%ebx 320: 80 fb 09 cmp $0x9,%bl 323: 76 eb jbe 310 <atoi+0x20> return n; } 325: 8b 5d fc mov -0x4(%ebp),%ebx 328: 89 c8 mov %ecx,%eax 32a: c9 leave 32b: c3 ret 32c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000330 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { 330: 55 push %ebp 331: 89 e5 mov %esp,%ebp 333: 57 push %edi 334: 8b 45 10 mov 0x10(%ebp),%eax 337: 8b 55 08 mov 0x8(%ebp),%edx 33a: 56 push %esi 33b: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 33e: 85 c0 test %eax,%eax 340: 7e 13 jle 355 <memmove+0x25> 342: 01 d0 add %edx,%eax dst = vdst; 344: 89 d7 mov %edx,%edi 346: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 34d: 8d 76 00 lea 0x0(%esi),%esi *dst++ = *src++; 350: a4 movsb %ds:(%esi),%es:(%edi) while(n-- > 0) 351: 39 f8 cmp %edi,%eax 353: 75 fb jne 350 <memmove+0x20> return vdst; } 355: 5e pop %esi 356: 89 d0 mov %edx,%eax 358: 5f pop %edi 359: 5d pop %ebp 35a: c3 ret 0000035b <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 35b: b8 01 00 00 00 mov $0x1,%eax 360: cd 40 int $0x40 362: c3 ret 00000363 <exit>: SYSCALL(exit) 363: b8 02 00 00 00 mov $0x2,%eax 368: cd 40 int $0x40 36a: c3 ret 0000036b <wait>: SYSCALL(wait) 36b: b8 03 00 00 00 mov $0x3,%eax 370: cd 40 int $0x40 372: c3 ret 00000373 <pipe>: SYSCALL(pipe) 373: b8 04 00 00 00 mov $0x4,%eax 378: cd 40 int $0x40 37a: c3 ret 0000037b <read>: SYSCALL(read) 37b: b8 05 00 00 00 mov $0x5,%eax 380: cd 40 int $0x40 382: c3 ret 00000383 <write>: SYSCALL(write) 383: b8 10 00 00 00 mov $0x10,%eax 388: cd 40 int $0x40 38a: c3 ret 0000038b <close>: SYSCALL(close) 38b: b8 15 00 00 00 mov $0x15,%eax 390: cd 40 int $0x40 392: c3 ret 00000393 <kill>: SYSCALL(kill) 393: b8 06 00 00 00 mov $0x6,%eax 398: cd 40 int $0x40 39a: c3 ret 0000039b <exec>: SYSCALL(exec) 39b: b8 07 00 00 00 mov $0x7,%eax 3a0: cd 40 int $0x40 3a2: c3 ret 000003a3 <open>: SYSCALL(open) 3a3: b8 0f 00 00 00 mov $0xf,%eax 3a8: cd 40 int $0x40 3aa: c3 ret 000003ab <mknod>: SYSCALL(mknod) 3ab: b8 11 00 00 00 mov $0x11,%eax 3b0: cd 40 int $0x40 3b2: c3 ret 000003b3 <unlink>: SYSCALL(unlink) 3b3: b8 12 00 00 00 mov $0x12,%eax 3b8: cd 40 int $0x40 3ba: c3 ret 000003bb <fstat>: SYSCALL(fstat) 3bb: b8 08 00 00 00 mov $0x8,%eax 3c0: cd 40 int $0x40 3c2: c3 ret 000003c3 <link>: SYSCALL(link) 3c3: b8 13 00 00 00 mov $0x13,%eax 3c8: cd 40 int $0x40 3ca: c3 ret 000003cb <mkdir>: SYSCALL(mkdir) 3cb: b8 14 00 00 00 mov $0x14,%eax 3d0: cd 40 int $0x40 3d2: c3 ret 000003d3 <chdir>: SYSCALL(chdir) 3d3: b8 09 00 00 00 mov $0x9,%eax 3d8: cd 40 int $0x40 3da: c3 ret 000003db <dup>: SYSCALL(dup) 3db: b8 0a 00 00 00 mov $0xa,%eax 3e0: cd 40 int $0x40 3e2: c3 ret 000003e3 <getpid>: SYSCALL(getpid) 3e3: b8 0b 00 00 00 mov $0xb,%eax 3e8: cd 40 int $0x40 3ea: c3 ret 000003eb <sbrk>: SYSCALL(sbrk) 3eb: b8 0c 00 00 00 mov $0xc,%eax 3f0: cd 40 int $0x40 3f2: c3 ret 000003f3 <sleep>: SYSCALL(sleep) 3f3: b8 0d 00 00 00 mov $0xd,%eax 3f8: cd 40 int $0x40 3fa: c3 ret 000003fb <uptime>: SYSCALL(uptime) 3fb: b8 0e 00 00 00 mov $0xe,%eax 400: cd 40 int $0x40 402: c3 ret 00000403 <getyear>: SYSCALL(getyear) 403: b8 16 00 00 00 mov $0x16,%eax 408: cd 40 int $0x40 40a: c3 ret 0000040b <lseek>: 40b: b8 17 00 00 00 mov $0x17,%eax 410: cd 40 int $0x40 412: c3 ret 413: 66 90 xchg %ax,%ax 415: 66 90 xchg %ax,%ax 417: 66 90 xchg %ax,%ax 419: 66 90 xchg %ax,%ax 41b: 66 90 xchg %ax,%ax 41d: 66 90 xchg %ax,%ax 41f: 90 nop 00000420 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 420: 55 push %ebp 421: 89 e5 mov %esp,%ebp 423: 57 push %edi 424: 56 push %esi 425: 53 push %ebx 426: 83 ec 3c sub $0x3c,%esp 429: 89 4d c4 mov %ecx,-0x3c(%ebp) uint x; neg = 0; if(sgn && xx < 0){ neg = 1; x = -xx; 42c: 89 d1 mov %edx,%ecx { 42e: 89 45 b8 mov %eax,-0x48(%ebp) if(sgn && xx < 0){ 431: 85 d2 test %edx,%edx 433: 0f 89 7f 00 00 00 jns 4b8 <printint+0x98> 439: f6 45 08 01 testb $0x1,0x8(%ebp) 43d: 74 79 je 4b8 <printint+0x98> neg = 1; 43f: c7 45 bc 01 00 00 00 movl $0x1,-0x44(%ebp) x = -xx; 446: f7 d9 neg %ecx } else { x = xx; } i = 0; 448: 31 db xor %ebx,%ebx 44a: 8d 75 d7 lea -0x29(%ebp),%esi 44d: 8d 76 00 lea 0x0(%esi),%esi do{ buf[i++] = digits[x % base]; 450: 89 c8 mov %ecx,%eax 452: 31 d2 xor %edx,%edx 454: 89 cf mov %ecx,%edi 456: f7 75 c4 divl -0x3c(%ebp) 459: 0f b6 92 d8 08 00 00 movzbl 0x8d8(%edx),%edx 460: 89 45 c0 mov %eax,-0x40(%ebp) 463: 89 d8 mov %ebx,%eax 465: 8d 5b 01 lea 0x1(%ebx),%ebx }while((x /= base) != 0); 468: 8b 4d c0 mov -0x40(%ebp),%ecx buf[i++] = digits[x % base]; 46b: 88 14 1e mov %dl,(%esi,%ebx,1) }while((x /= base) != 0); 46e: 39 7d c4 cmp %edi,-0x3c(%ebp) 471: 76 dd jbe 450 <printint+0x30> if(neg) 473: 8b 4d bc mov -0x44(%ebp),%ecx 476: 85 c9 test %ecx,%ecx 478: 74 0c je 486 <printint+0x66> buf[i++] = '-'; 47a: c6 44 1d d8 2d movb $0x2d,-0x28(%ebp,%ebx,1) buf[i++] = digits[x % base]; 47f: 89 d8 mov %ebx,%eax buf[i++] = '-'; 481: ba 2d 00 00 00 mov $0x2d,%edx while(--i >= 0) 486: 8b 7d b8 mov -0x48(%ebp),%edi 489: 8d 5c 05 d7 lea -0x29(%ebp,%eax,1),%ebx 48d: eb 07 jmp 496 <printint+0x76> 48f: 90 nop putc(fd, buf[i]); 490: 0f b6 13 movzbl (%ebx),%edx 493: 83 eb 01 sub $0x1,%ebx write(fd, &c, 1); 496: 83 ec 04 sub $0x4,%esp 499: 88 55 d7 mov %dl,-0x29(%ebp) 49c: 6a 01 push $0x1 49e: 56 push %esi 49f: 57 push %edi 4a0: e8 de fe ff ff call 383 <write> while(--i >= 0) 4a5: 83 c4 10 add $0x10,%esp 4a8: 39 de cmp %ebx,%esi 4aa: 75 e4 jne 490 <printint+0x70> } 4ac: 8d 65 f4 lea -0xc(%ebp),%esp 4af: 5b pop %ebx 4b0: 5e pop %esi 4b1: 5f pop %edi 4b2: 5d pop %ebp 4b3: c3 ret 4b4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; 4b8: c7 45 bc 00 00 00 00 movl $0x0,-0x44(%ebp) 4bf: eb 87 jmp 448 <printint+0x28> 4c1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 4c8: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 4cf: 90 nop 000004d0 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 4d0: 55 push %ebp 4d1: 89 e5 mov %esp,%ebp 4d3: 57 push %edi 4d4: 56 push %esi 4d5: 53 push %ebx 4d6: 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++){ 4d9: 8b 75 0c mov 0xc(%ebp),%esi 4dc: 0f b6 1e movzbl (%esi),%ebx 4df: 84 db test %bl,%bl 4e1: 0f 84 b8 00 00 00 je 59f <printf+0xcf> ap = (uint*)(void*)&fmt + 1; 4e7: 8d 45 10 lea 0x10(%ebp),%eax 4ea: 83 c6 01 add $0x1,%esi write(fd, &c, 1); 4ed: 8d 7d e7 lea -0x19(%ebp),%edi state = 0; 4f0: 31 d2 xor %edx,%edx ap = (uint*)(void*)&fmt + 1; 4f2: 89 45 d0 mov %eax,-0x30(%ebp) 4f5: eb 37 jmp 52e <printf+0x5e> 4f7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 4fe: 66 90 xchg %ax,%ax 500: 89 55 d4 mov %edx,-0x2c(%ebp) c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ state = '%'; 503: ba 25 00 00 00 mov $0x25,%edx if(c == '%'){ 508: 83 f8 25 cmp $0x25,%eax 50b: 74 17 je 524 <printf+0x54> write(fd, &c, 1); 50d: 83 ec 04 sub $0x4,%esp 510: 88 5d e7 mov %bl,-0x19(%ebp) 513: 6a 01 push $0x1 515: 57 push %edi 516: ff 75 08 pushl 0x8(%ebp) 519: e8 65 fe ff ff call 383 <write> 51e: 8b 55 d4 mov -0x2c(%ebp),%edx } else { putc(fd, c); 521: 83 c4 10 add $0x10,%esp for(i = 0; fmt[i]; i++){ 524: 0f b6 1e movzbl (%esi),%ebx 527: 83 c6 01 add $0x1,%esi 52a: 84 db test %bl,%bl 52c: 74 71 je 59f <printf+0xcf> c = fmt[i] & 0xff; 52e: 0f be cb movsbl %bl,%ecx 531: 0f b6 c3 movzbl %bl,%eax if(state == 0){ 534: 85 d2 test %edx,%edx 536: 74 c8 je 500 <printf+0x30> } } else if(state == '%'){ 538: 83 fa 25 cmp $0x25,%edx 53b: 75 e7 jne 524 <printf+0x54> if(c == 'd'){ 53d: 83 f8 64 cmp $0x64,%eax 540: 0f 84 9a 00 00 00 je 5e0 <printf+0x110> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 546: 81 e1 f7 00 00 00 and $0xf7,%ecx 54c: 83 f9 70 cmp $0x70,%ecx 54f: 74 5f je 5b0 <printf+0xe0> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 551: 83 f8 73 cmp $0x73,%eax 554: 0f 84 d6 00 00 00 je 630 <printf+0x160> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 55a: 83 f8 63 cmp $0x63,%eax 55d: 0f 84 8d 00 00 00 je 5f0 <printf+0x120> putc(fd, *ap); ap++; } else if(c == '%'){ 563: 83 f8 25 cmp $0x25,%eax 566: 0f 84 b4 00 00 00 je 620 <printf+0x150> write(fd, &c, 1); 56c: 83 ec 04 sub $0x4,%esp 56f: c6 45 e7 25 movb $0x25,-0x19(%ebp) 573: 6a 01 push $0x1 575: 57 push %edi 576: ff 75 08 pushl 0x8(%ebp) 579: e8 05 fe ff ff call 383 <write> putc(fd, c); } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); 57e: 88 5d e7 mov %bl,-0x19(%ebp) write(fd, &c, 1); 581: 83 c4 0c add $0xc,%esp 584: 6a 01 push $0x1 for(i = 0; fmt[i]; i++){ 586: 83 c6 01 add $0x1,%esi write(fd, &c, 1); 589: 57 push %edi 58a: ff 75 08 pushl 0x8(%ebp) 58d: e8 f1 fd ff ff call 383 <write> for(i = 0; fmt[i]; i++){ 592: 0f b6 5e ff movzbl -0x1(%esi),%ebx putc(fd, c); 596: 83 c4 10 add $0x10,%esp } state = 0; 599: 31 d2 xor %edx,%edx for(i = 0; fmt[i]; i++){ 59b: 84 db test %bl,%bl 59d: 75 8f jne 52e <printf+0x5e> } } } 59f: 8d 65 f4 lea -0xc(%ebp),%esp 5a2: 5b pop %ebx 5a3: 5e pop %esi 5a4: 5f pop %edi 5a5: 5d pop %ebp 5a6: c3 ret 5a7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 5ae: 66 90 xchg %ax,%ax printint(fd, *ap, 16, 0); 5b0: 83 ec 0c sub $0xc,%esp 5b3: b9 10 00 00 00 mov $0x10,%ecx 5b8: 6a 00 push $0x0 5ba: 8b 5d d0 mov -0x30(%ebp),%ebx 5bd: 8b 45 08 mov 0x8(%ebp),%eax 5c0: 8b 13 mov (%ebx),%edx 5c2: e8 59 fe ff ff call 420 <printint> ap++; 5c7: 89 d8 mov %ebx,%eax 5c9: 83 c4 10 add $0x10,%esp state = 0; 5cc: 31 d2 xor %edx,%edx ap++; 5ce: 83 c0 04 add $0x4,%eax 5d1: 89 45 d0 mov %eax,-0x30(%ebp) 5d4: e9 4b ff ff ff jmp 524 <printf+0x54> 5d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi printint(fd, *ap, 10, 1); 5e0: 83 ec 0c sub $0xc,%esp 5e3: b9 0a 00 00 00 mov $0xa,%ecx 5e8: 6a 01 push $0x1 5ea: eb ce jmp 5ba <printf+0xea> 5ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi putc(fd, *ap); 5f0: 8b 5d d0 mov -0x30(%ebp),%ebx write(fd, &c, 1); 5f3: 83 ec 04 sub $0x4,%esp putc(fd, *ap); 5f6: 8b 03 mov (%ebx),%eax write(fd, &c, 1); 5f8: 6a 01 push $0x1 ap++; 5fa: 83 c3 04 add $0x4,%ebx write(fd, &c, 1); 5fd: 57 push %edi 5fe: ff 75 08 pushl 0x8(%ebp) putc(fd, *ap); 601: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 604: e8 7a fd ff ff call 383 <write> ap++; 609: 89 5d d0 mov %ebx,-0x30(%ebp) 60c: 83 c4 10 add $0x10,%esp state = 0; 60f: 31 d2 xor %edx,%edx 611: e9 0e ff ff ff jmp 524 <printf+0x54> 616: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 61d: 8d 76 00 lea 0x0(%esi),%esi putc(fd, c); 620: 88 5d e7 mov %bl,-0x19(%ebp) write(fd, &c, 1); 623: 83 ec 04 sub $0x4,%esp 626: e9 59 ff ff ff jmp 584 <printf+0xb4> 62b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 62f: 90 nop s = (char*)*ap; 630: 8b 45 d0 mov -0x30(%ebp),%eax 633: 8b 18 mov (%eax),%ebx ap++; 635: 83 c0 04 add $0x4,%eax 638: 89 45 d0 mov %eax,-0x30(%ebp) if(s == 0) 63b: 85 db test %ebx,%ebx 63d: 74 17 je 656 <printf+0x186> while(*s != 0){ 63f: 0f b6 03 movzbl (%ebx),%eax state = 0; 642: 31 d2 xor %edx,%edx while(*s != 0){ 644: 84 c0 test %al,%al 646: 0f 84 d8 fe ff ff je 524 <printf+0x54> 64c: 89 75 d4 mov %esi,-0x2c(%ebp) 64f: 89 de mov %ebx,%esi 651: 8b 5d 08 mov 0x8(%ebp),%ebx 654: eb 1a jmp 670 <printf+0x1a0> s = "(null)"; 656: bb d0 08 00 00 mov $0x8d0,%ebx while(*s != 0){ 65b: 89 75 d4 mov %esi,-0x2c(%ebp) 65e: b8 28 00 00 00 mov $0x28,%eax 663: 89 de mov %ebx,%esi 665: 8b 5d 08 mov 0x8(%ebp),%ebx 668: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 66f: 90 nop write(fd, &c, 1); 670: 83 ec 04 sub $0x4,%esp s++; 673: 83 c6 01 add $0x1,%esi 676: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 679: 6a 01 push $0x1 67b: 57 push %edi 67c: 53 push %ebx 67d: e8 01 fd ff ff call 383 <write> while(*s != 0){ 682: 0f b6 06 movzbl (%esi),%eax 685: 83 c4 10 add $0x10,%esp 688: 84 c0 test %al,%al 68a: 75 e4 jne 670 <printf+0x1a0> state = 0; 68c: 8b 75 d4 mov -0x2c(%ebp),%esi 68f: 31 d2 xor %edx,%edx 691: e9 8e fe ff ff jmp 524 <printf+0x54> 696: 66 90 xchg %ax,%ax 698: 66 90 xchg %ax,%ax 69a: 66 90 xchg %ax,%ax 69c: 66 90 xchg %ax,%ax 69e: 66 90 xchg %ax,%ax 000006a0 <free>: static Header base; static Header *freep; void free(void *ap) { 6a0: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 6a1: a1 88 0b 00 00 mov 0xb88,%eax { 6a6: 89 e5 mov %esp,%ebp 6a8: 57 push %edi 6a9: 56 push %esi 6aa: 53 push %ebx 6ab: 8b 5d 08 mov 0x8(%ebp),%ebx bp = (Header*)ap - 1; 6ae: 8d 4b f8 lea -0x8(%ebx),%ecx for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 6b1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 6b8: 89 c2 mov %eax,%edx 6ba: 8b 00 mov (%eax),%eax 6bc: 39 ca cmp %ecx,%edx 6be: 73 30 jae 6f0 <free+0x50> 6c0: 39 c1 cmp %eax,%ecx 6c2: 72 04 jb 6c8 <free+0x28> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 6c4: 39 c2 cmp %eax,%edx 6c6: 72 f0 jb 6b8 <free+0x18> break; if(bp + bp->s.size == p->s.ptr){ 6c8: 8b 73 fc mov -0x4(%ebx),%esi 6cb: 8d 3c f1 lea (%ecx,%esi,8),%edi 6ce: 39 f8 cmp %edi,%eax 6d0: 74 30 je 702 <free+0x62> bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; 6d2: 89 43 f8 mov %eax,-0x8(%ebx) if(p + p->s.size == bp){ 6d5: 8b 42 04 mov 0x4(%edx),%eax 6d8: 8d 34 c2 lea (%edx,%eax,8),%esi 6db: 39 f1 cmp %esi,%ecx 6dd: 74 3a je 719 <free+0x79> p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; 6df: 89 0a mov %ecx,(%edx) freep = p; } 6e1: 5b pop %ebx freep = p; 6e2: 89 15 88 0b 00 00 mov %edx,0xb88 } 6e8: 5e pop %esi 6e9: 5f pop %edi 6ea: 5d pop %ebp 6eb: c3 ret 6ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 6f0: 39 c2 cmp %eax,%edx 6f2: 72 c4 jb 6b8 <free+0x18> 6f4: 39 c1 cmp %eax,%ecx 6f6: 73 c0 jae 6b8 <free+0x18> if(bp + bp->s.size == p->s.ptr){ 6f8: 8b 73 fc mov -0x4(%ebx),%esi 6fb: 8d 3c f1 lea (%ecx,%esi,8),%edi 6fe: 39 f8 cmp %edi,%eax 700: 75 d0 jne 6d2 <free+0x32> bp->s.size += p->s.ptr->s.size; 702: 03 70 04 add 0x4(%eax),%esi 705: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 708: 8b 02 mov (%edx),%eax 70a: 8b 00 mov (%eax),%eax 70c: 89 43 f8 mov %eax,-0x8(%ebx) if(p + p->s.size == bp){ 70f: 8b 42 04 mov 0x4(%edx),%eax 712: 8d 34 c2 lea (%edx,%eax,8),%esi 715: 39 f1 cmp %esi,%ecx 717: 75 c6 jne 6df <free+0x3f> p->s.size += bp->s.size; 719: 03 43 fc add -0x4(%ebx),%eax freep = p; 71c: 89 15 88 0b 00 00 mov %edx,0xb88 p->s.size += bp->s.size; 722: 89 42 04 mov %eax,0x4(%edx) p->s.ptr = bp->s.ptr; 725: 8b 43 f8 mov -0x8(%ebx),%eax 728: 89 02 mov %eax,(%edx) } 72a: 5b pop %ebx 72b: 5e pop %esi 72c: 5f pop %edi 72d: 5d pop %ebp 72e: c3 ret 72f: 90 nop 00000730 <malloc>: return freep; } void* malloc(uint nbytes) { 730: 55 push %ebp 731: 89 e5 mov %esp,%ebp 733: 57 push %edi 734: 56 push %esi 735: 53 push %ebx 736: 83 ec 1c sub $0x1c,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 739: 8b 45 08 mov 0x8(%ebp),%eax if((prevp = freep) == 0){ 73c: 8b 3d 88 0b 00 00 mov 0xb88,%edi nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 742: 8d 70 07 lea 0x7(%eax),%esi 745: c1 ee 03 shr $0x3,%esi 748: 83 c6 01 add $0x1,%esi if((prevp = freep) == 0){ 74b: 85 ff test %edi,%edi 74d: 0f 84 ad 00 00 00 je 800 <malloc+0xd0> base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 753: 8b 07 mov (%edi),%eax if(p->s.size >= nunits){ 755: 8b 48 04 mov 0x4(%eax),%ecx 758: 39 f1 cmp %esi,%ecx 75a: 73 71 jae 7cd <malloc+0x9d> 75c: 81 fe 00 10 00 00 cmp $0x1000,%esi 762: bb 00 10 00 00 mov $0x1000,%ebx 767: 0f 43 de cmovae %esi,%ebx p = sbrk(nu * sizeof(Header)); 76a: 8d 0c dd 00 00 00 00 lea 0x0(,%ebx,8),%ecx 771: 89 4d e4 mov %ecx,-0x1c(%ebp) 774: eb 1b jmp 791 <malloc+0x61> 776: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 77d: 8d 76 00 lea 0x0(%esi),%esi for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 780: 8b 10 mov (%eax),%edx if(p->s.size >= nunits){ 782: 8b 4a 04 mov 0x4(%edx),%ecx 785: 39 f1 cmp %esi,%ecx 787: 73 4f jae 7d8 <malloc+0xa8> p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) 789: 8b 3d 88 0b 00 00 mov 0xb88,%edi 78f: 89 d0 mov %edx,%eax 791: 39 c7 cmp %eax,%edi 793: 75 eb jne 780 <malloc+0x50> p = sbrk(nu * sizeof(Header)); 795: 83 ec 0c sub $0xc,%esp 798: ff 75 e4 pushl -0x1c(%ebp) 79b: e8 4b fc ff ff call 3eb <sbrk> if(p == (char*)-1) 7a0: 83 c4 10 add $0x10,%esp 7a3: 83 f8 ff cmp $0xffffffff,%eax 7a6: 74 1b je 7c3 <malloc+0x93> hp->s.size = nu; 7a8: 89 58 04 mov %ebx,0x4(%eax) free((void*)(hp + 1)); 7ab: 83 ec 0c sub $0xc,%esp 7ae: 83 c0 08 add $0x8,%eax 7b1: 50 push %eax 7b2: e8 e9 fe ff ff call 6a0 <free> return freep; 7b7: a1 88 0b 00 00 mov 0xb88,%eax if((p = morecore(nunits)) == 0) 7bc: 83 c4 10 add $0x10,%esp 7bf: 85 c0 test %eax,%eax 7c1: 75 bd jne 780 <malloc+0x50> return 0; } } 7c3: 8d 65 f4 lea -0xc(%ebp),%esp return 0; 7c6: 31 c0 xor %eax,%eax } 7c8: 5b pop %ebx 7c9: 5e pop %esi 7ca: 5f pop %edi 7cb: 5d pop %ebp 7cc: c3 ret if(p->s.size >= nunits){ 7cd: 89 c2 mov %eax,%edx 7cf: 89 f8 mov %edi,%eax 7d1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi if(p->s.size == nunits) 7d8: 39 ce cmp %ecx,%esi 7da: 74 54 je 830 <malloc+0x100> p->s.size -= nunits; 7dc: 29 f1 sub %esi,%ecx 7de: 89 4a 04 mov %ecx,0x4(%edx) p += p->s.size; 7e1: 8d 14 ca lea (%edx,%ecx,8),%edx p->s.size = nunits; 7e4: 89 72 04 mov %esi,0x4(%edx) freep = prevp; 7e7: a3 88 0b 00 00 mov %eax,0xb88 } 7ec: 8d 65 f4 lea -0xc(%ebp),%esp return (void*)(p + 1); 7ef: 8d 42 08 lea 0x8(%edx),%eax } 7f2: 5b pop %ebx 7f3: 5e pop %esi 7f4: 5f pop %edi 7f5: 5d pop %ebp 7f6: c3 ret 7f7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 7fe: 66 90 xchg %ax,%ax base.s.ptr = freep = prevp = &base; 800: c7 05 88 0b 00 00 8c movl $0xb8c,0xb88 807: 0b 00 00 base.s.size = 0; 80a: bf 8c 0b 00 00 mov $0xb8c,%edi base.s.ptr = freep = prevp = &base; 80f: c7 05 8c 0b 00 00 8c movl $0xb8c,0xb8c 816: 0b 00 00 for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 819: 89 f8 mov %edi,%eax base.s.size = 0; 81b: c7 05 90 0b 00 00 00 movl $0x0,0xb90 822: 00 00 00 if(p->s.size >= nunits){ 825: e9 32 ff ff ff jmp 75c <malloc+0x2c> 82a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi prevp->s.ptr = p->s.ptr; 830: 8b 0a mov (%edx),%ecx 832: 89 08 mov %ecx,(%eax) 834: eb b1 jmp 7e7 <malloc+0xb7>
; size_t p_forward_list_alt_size(p_forward_list_alt_t *list) SECTION code_clib SECTION code_adt_p_forward_list_alt PUBLIC p_forward_list_alt_size EXTERN asm_p_forward_list_alt_size defc p_forward_list_alt_size = asm_p_forward_list_alt_size ; SDCC bridge for Classic IF __CLASSIC PUBLIC _p_forward_list_alt_size defc _p_forward_list_alt_size = p_forward_list_alt_size ENDIF
//===--- Types.cpp - Driver input & temporary type information ------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "clang/Driver/Types.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Driver/Options.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Option/Arg.h" #include <cassert> #include <cstring> using namespace clang::driver; using namespace clang::driver::types; struct TypeInfo { const char *Name; const char *TempSuffix; ID PreprocessedType; const llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> Phases; }; static const TypeInfo TypeInfos[] = { #define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, ...) \ { NAME, TEMP_SUFFIX, TY_##PP_TYPE, { __VA_ARGS__ }, }, #include "clang/Driver/Types.def" #undef TYPE }; static const unsigned numTypes = llvm::array_lengthof(TypeInfos); static const TypeInfo &getInfo(unsigned id) { assert(id > 0 && id - 1 < numTypes && "Invalid Type ID."); return TypeInfos[id - 1]; } const char *types::getTypeName(ID Id) { return getInfo(Id).Name; } types::ID types::getPreprocessedType(ID Id) { ID PPT = getInfo(Id).PreprocessedType; assert((llvm::is_contained(getInfo(Id).Phases, phases::Preprocess) != (PPT == TY_INVALID)) && "Unexpected Preprocess Type."); return PPT; } static bool isPrepeocessedModuleType(ID Id) { return Id == TY_CXXModule || Id == TY_PP_CXXModule; } types::ID types::getPrecompiledType(ID Id) { if (isPrepeocessedModuleType(Id)) return TY_ModuleFile; if (onlyPrecompileType(Id)) return TY_PCH; return TY_INVALID; } const char *types::getTypeTempSuffix(ID Id, bool CLMode) { if (CLMode) { switch (Id) { case TY_Object: case TY_LTO_BC: return "obj"; case TY_Image: return "exe"; case TY_PP_Asm: return "asm"; default: break; } } return getInfo(Id).TempSuffix; } bool types::onlyAssembleType(ID Id) { return llvm::is_contained(getInfo(Id).Phases, phases::Assemble) && !llvm::is_contained(getInfo(Id).Phases, phases::Compile) && !llvm::is_contained(getInfo(Id).Phases, phases::Backend); } bool types::onlyPrecompileType(ID Id) { return llvm::is_contained(getInfo(Id).Phases, phases::Precompile) && !isPrepeocessedModuleType(Id); } bool types::canTypeBeUserSpecified(ID Id) { static const clang::driver::types::ID kStaticLangageTypes[] = { TY_CUDA_DEVICE, TY_HIP_DEVICE, TY_PP_CHeader, TY_PP_ObjCHeader, TY_PP_CXXHeader, TY_PP_ObjCXXHeader, TY_PP_CXXModule, TY_LTO_IR, TY_LTO_BC, TY_Plist, TY_RewrittenObjC, TY_RewrittenLegacyObjC, TY_Remap, TY_PCH, TY_Object, TY_Image, TY_dSYM, TY_Dependencies, TY_CUDA_FATBIN, TY_HIP_FATBIN}; return !llvm::is_contained(kStaticLangageTypes, Id); } bool types::appendSuffixForType(ID Id) { return Id == TY_PCH || Id == TY_dSYM || Id == TY_CUDA_FATBIN || Id == TY_HIP_FATBIN; } bool types::canLipoType(ID Id) { return (Id == TY_Nothing || Id == TY_Image || Id == TY_Object || Id == TY_LTO_BC); } bool types::isAcceptedByClang(ID Id) { switch (Id) { default: return false; case TY_Asm: case TY_C: case TY_PP_C: case TY_CL: case TY_CUDA: case TY_PP_CUDA: case TY_CUDA_DEVICE: case TY_HIP: case TY_PP_HIP: case TY_HIP_DEVICE: case TY_ObjC: case TY_PP_ObjC: case TY_PP_ObjC_Alias: case TY_CXX: case TY_PP_CXX: case TY_ObjCXX: case TY_PP_ObjCXX: case TY_PP_ObjCXX_Alias: case TY_CHeader: case TY_PP_CHeader: case TY_CLHeader: case TY_ObjCHeader: case TY_PP_ObjCHeader: case TY_CXXHeader: case TY_PP_CXXHeader: case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader: case TY_CXXModule: case TY_PP_CXXModule: case TY_AST: case TY_ModuleFile: case TY_LLVM_IR: case TY_LLVM_BC: // @mulle-objc@ AAM: .aam filename extension support case TY_ObjCAAM: return true; } } bool types::isObjC(ID Id) { switch (Id) { default: return false; case TY_ObjC: case TY_PP_ObjC: case TY_PP_ObjC_Alias: case TY_ObjCXX: case TY_PP_ObjCXX: case TY_ObjCHeader: case TY_PP_ObjCHeader: case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader: case TY_PP_ObjCXX_Alias: // @mulle-objc@ AAM: .aam filename extension support case TY_ObjCAAM: return true; } } bool types::isCXX(ID Id) { switch (Id) { default: return false; case TY_CXX: case TY_PP_CXX: case TY_ObjCXX: case TY_PP_ObjCXX: case TY_PP_ObjCXX_Alias: case TY_CXXHeader: case TY_PP_CXXHeader: case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader: case TY_CXXModule: case TY_PP_CXXModule: case TY_CUDA: case TY_PP_CUDA: case TY_CUDA_DEVICE: case TY_HIP: case TY_PP_HIP: case TY_HIP_DEVICE: return true; } } bool types::isLLVMIR(ID Id) { switch (Id) { default: return false; case TY_LLVM_IR: case TY_LLVM_BC: case TY_LTO_IR: case TY_LTO_BC: return true; } } bool types::isCuda(ID Id) { switch (Id) { default: return false; case TY_CUDA: case TY_PP_CUDA: case TY_CUDA_DEVICE: return true; } } bool types::isHIP(ID Id) { switch (Id) { default: return false; case TY_HIP: case TY_PP_HIP: case TY_HIP_DEVICE: return true; } } bool types::isFortran(ID Id) { switch (Id) { default: return false; case TY_Fortran: case TY_PP_Fortran: return true; } } bool types::isSrcFile(ID Id) { return Id != TY_Object && getPreprocessedType(Id) != TY_INVALID; } types::ID types::lookupTypeForExtension(llvm::StringRef Ext) { return llvm::StringSwitch<types::ID>(Ext) .Case("c", TY_C) .Case("C", TY_CXX) .Case("F", TY_Fortran) .Case("f", TY_PP_Fortran) .Case("h", TY_CHeader) .Case("H", TY_CXXHeader) .Case("i", TY_PP_C) // @mulle-objc@ AAM: .aam filename extension support .Case("m", TY_ObjC) .Case("aam", TY_ObjCAAM) .Case("M", TY_ObjCXX) .Case("o", TY_Object) .Case("S", TY_Asm) .Case("s", TY_PP_Asm) .Case("bc", TY_LLVM_BC) .Case("cc", TY_CXX) .Case("CC", TY_CXX) .Case("cl", TY_CL) .Case("cp", TY_CXX) .Case("cu", TY_CUDA) .Case("hh", TY_CXXHeader) .Case("ii", TY_PP_CXX) .Case("ll", TY_LLVM_IR) .Case("mi", TY_PP_ObjC) .Case("mm", TY_ObjCXX) .Case("rs", TY_RenderScript) .Case("adb", TY_Ada) .Case("ads", TY_Ada) .Case("asm", TY_PP_Asm) .Case("ast", TY_AST) .Case("ccm", TY_CXXModule) .Case("cpp", TY_CXX) .Case("CPP", TY_CXX) .Case("c++", TY_CXX) .Case("C++", TY_CXX) .Case("cui", TY_PP_CUDA) .Case("cxx", TY_CXX) .Case("CXX", TY_CXX) .Case("F90", TY_Fortran) .Case("f90", TY_PP_Fortran) .Case("F95", TY_Fortran) .Case("f95", TY_PP_Fortran) .Case("for", TY_PP_Fortran) .Case("FOR", TY_PP_Fortran) .Case("fpp", TY_Fortran) .Case("FPP", TY_Fortran) .Case("gch", TY_PCH) .Case("hip", TY_HIP) .Case("hpp", TY_CXXHeader) .Case("iim", TY_PP_CXXModule) .Case("lib", TY_Object) .Case("mii", TY_PP_ObjCXX) .Case("obj", TY_Object) .Case("ifs", TY_IFS) .Case("pch", TY_PCH) .Case("pcm", TY_ModuleFile) .Case("c++m", TY_CXXModule) .Case("cppm", TY_CXXModule) .Case("cxxm", TY_CXXModule) .Default(TY_INVALID); } types::ID types::lookupTypeForTypeSpecifier(const char *Name) { for (unsigned i=0; i<numTypes; ++i) { types::ID Id = (types::ID) (i + 1); if (canTypeBeUserSpecified(Id) && strcmp(Name, getInfo(Id).Name) == 0) return Id; } return TY_INVALID; } // FIXME: Why don't we just put this list in the defs file, eh. // FIXME: The list is now in Types.def but for now this function will verify // the old behavior and a subsequent change will delete most of the body. void types::getCompilationPhases(ID Id, llvm::SmallVectorImpl<phases::ID> &P) { P = getInfo(Id).Phases; assert(0 < P.size() && "Not enough phases in list"); assert(P.size() <= phases::MaxNumberOfPhases && "Too many phases in list"); } void types::getCompilationPhases(const clang::driver::Driver &Driver, llvm::opt::DerivedArgList &DAL, ID Id, llvm::SmallVectorImpl<phases::ID> &P) { llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PhaseList; types::getCompilationPhases(Id, PhaseList); // Filter to compiler mode. When the compiler is run as a preprocessor then // compilation is not an option. // -S runs the compiler in Assembly listing mode. if (Driver.CCCIsCPP() || DAL.getLastArg(options::OPT_E) || DAL.getLastArg(options::OPT__SLASH_EP) || DAL.getLastArg(options::OPT_M, options::OPT_MM) || DAL.getLastArg(options::OPT__SLASH_P)) llvm::copy_if(PhaseList, std::back_inserter(P), [](phases::ID Phase) { return Phase <= phases::Preprocess; }); // --precompile only runs up to precompilation. // This is a clang extension and is not compatible with GCC. else if (DAL.getLastArg(options::OPT__precompile)) llvm::copy_if(PhaseList, std::back_inserter(P), [](phases::ID Phase) { return Phase <= phases::Precompile; }); // -{fsyntax-only,-analyze,emit-ast} only run up to the compiler. else if (DAL.getLastArg(options::OPT_fsyntax_only) || DAL.getLastArg(options::OPT_print_supported_cpus) || DAL.getLastArg(options::OPT_module_file_info) || DAL.getLastArg(options::OPT_verify_pch) || DAL.getLastArg(options::OPT_rewrite_objc) || DAL.getLastArg(options::OPT_rewrite_legacy_objc) || DAL.getLastArg(options::OPT__migrate) || DAL.getLastArg(options::OPT__analyze) || DAL.getLastArg(options::OPT_emit_ast)) llvm::copy_if(PhaseList, std::back_inserter(P), [](phases::ID Phase) { return Phase <= phases::Compile; }); else if (DAL.getLastArg(options::OPT_S) || DAL.getLastArg(options::OPT_emit_llvm)) llvm::copy_if(PhaseList, std::back_inserter(P), [](phases::ID Phase) { return Phase <= phases::Backend; }); else if (DAL.getLastArg(options::OPT_c)) llvm::copy_if(PhaseList, std::back_inserter(P), [](phases::ID Phase) { return Phase <= phases::Assemble; }); // Generally means, do every phase until Link. else P = PhaseList; } ID types::lookupCXXTypeForCType(ID Id) { switch (Id) { default: return Id; case types::TY_C: return types::TY_CXX; case types::TY_PP_C: return types::TY_PP_CXX; case types::TY_CHeader: return types::TY_CXXHeader; case types::TY_PP_CHeader: return types::TY_PP_CXXHeader; } } ID types::lookupHeaderTypeForSourceType(ID Id) { switch (Id) { default: return Id; // FIXME: Handle preprocessed input types. case types::TY_C: return types::TY_CHeader; case types::TY_CXX: case types::TY_CXXModule: return types::TY_CXXHeader; case types::TY_ObjC: return types::TY_ObjCHeader; case types::TY_ObjCXX: return types::TY_ObjCXXHeader; case types::TY_CL: return types::TY_CLHeader; } }
dc.w word_2DC5C-Map_Results dc.w word_2DC5E-Map_Results dc.w word_2DC66-Map_Results dc.w word_2DC6E-Map_Results dc.w word_2DC76-Map_Results dc.w word_2DC7E-Map_Results dc.w word_2DC86-Map_Results dc.w word_2DC8E-Map_Results dc.w word_2DC96-Map_Results dc.w word_2DC9E-Map_Results dc.w word_2DCA6-Map_Results dc.w word_2DCAE-Map_Results dc.w word_2DCC2-Map_Results dc.w word_2DCD6-Map_Results dc.w word_2DCDE-Map_Results dc.w word_2DCE6-Map_Results dc.w word_2DCF4-Map_Results dc.w word_2DD1A-Map_Results dc.w word_2DD2E-Map_Results dc.w word_2DD42-Map_Results dc.w word_2DD56-Map_Results dc.w word_2DD6A-Map_Results dc.w word_2DD78-Map_Results dc.w word_2DD92-Map_Results dc.w word_2DDB2-Map_Results dc.w word_2DDCC-Map_Results dc.w word_2DDE0-Map_Results dc.w word_2DDF4-Map_Results dc.w word_2DDFC-Map_Results dc.w word_2DE04-Map_Results dc.w word_2DE0C-Map_Results dc.w word_2DE14-Map_Results dc.w word_2DE1C-Map_Results dc.w word_2DE24-Map_Results dc.w word_2DE2C-Map_Results dc.w word_2DE76-Map_Results dc.w word_2DE90-Map_Results dc.w word_2DEDA-Map_Results dc.w word_2DEE8-Map_Results dc.w word_2DEF0-Map_Results dc.w word_2DF16-Map_Results dc.w word_2DF24-Map_Results dc.w word_2DF2C-Map_Results dc.w word_2DF34-Map_Results word_2DC5C: dc.w 0 word_2DC5E: dc.w 1 dc.b 0, 1, $A5, $20, 0, 0 word_2DC66: dc.w 1 dc.b 0, 1, $A5, $22, 0, 0 word_2DC6E: dc.w 1 dc.b 0, 1, $A5, $24, 0, 0 word_2DC76: dc.w 1 dc.b 0, 1, $A5, $26, 0, 0 word_2DC7E: dc.w 1 dc.b 0, 1, $A5, $28, 0, 0 word_2DC86: dc.w 1 dc.b 0, 1, $A5, $2A, 0, 0 word_2DC8E: dc.w 1 dc.b 0, 1, $A5, $2C, 0, 0 word_2DC96: dc.w 1 dc.b 0, 1, $A5, $2E, 0, 0 word_2DC9E: dc.w 1 dc.b 0, 1, $A5, $30, 0, 0 word_2DCA6: dc.w 1 dc.b 0, 1, $A5, $32, 0, 0 word_2DCAE: dc.w 3 dc.b 0, 1, $A5, $44, 0, 0 dc.b 0, $D, $A5, $42, 0, 8 dc.b $F6, 6, $85, $34, 0, $24 word_2DCC2: dc.w 3 dc.b 0, $D, $A5, $3A, 0, 0 dc.b 0, 1, $A6, $CA, 0, $20 dc.b $F6, 6, $85, $34, 0, $24 word_2DCD6: dc.w 1 dc.b 0, $D, $A6, $D2, 0, 0 word_2DCDE: dc.w 1 dc.b 0, $D, $A6, $DA, 0, 0 word_2DCE6: dc.w 2 dc.b $10, 9, $85, $4A, 0, 0 dc.b 0, $F, $85, $70, 0, $11 word_2DCF4: dc.w 6 dc.b 0, 5, $85, $60, 0, 0 dc.b 0, 5, $85, $54, 0, $10 dc.b 0, 5, $85, $5C, 0, $20 dc.b 0, 5, $85, $58, 0, $30 dc.b 0, 5, $85, $64, 0, $40 dc.b 0, $D, $85, $50, 0, $50 word_2DD1A: dc.w 3 dc.b 0, 5, $85, $50, 0, 0 dc.b 0, 5, $85, $58, 0, $10 dc.b 0, 5, $85, $60, 0, $1E word_2DD2E: dc.w 3 dc.b 0, $D, $85, $80, 0, 0 dc.b 0, $D, $85, $88, 0, $20 dc.b 0, 5, $85, $90, 0, $40 word_2DD42: dc.w 3 dc.b 0, $D, $85, $94, 0, 1 dc.b 0, $D, $85, $9C, 0, $21 dc.b 0, 1, $85, $A4, 0, $41 word_2DD56: dc.w 3 dc.b 0, $D, $85, $80, 0, 6 dc.b 0, $D, $85, $88, 0, $26 dc.b 0, 1, $85, $90, 0, $46 word_2DD6A: dc.w 2 dc.b 0, $D, $85, $80, 0, 1 dc.b 0, $D, $85, $88, 0, $21 word_2DD78: dc.w 4 dc.b 0, $D, $85, $80, 0, 4 dc.b 0, $D, $85, $88, 0, $24 dc.b 0, $D, $85, $90, 0, $44 dc.b 0, 9, $85, $98, 0, $64 word_2DD92: dc.w 5 dc.b 0, $D, $66, $CA, $FF, $A0 dc.b 0, 1, $66, $E2, $FF, $C0 dc.b 0, 9, $26, $E4, 0, $28 dc.b 0, $D, $26, $EA, 0, $40 dc.b $F6, 6, 5, $34, $FF, $C4 word_2DDB2: dc.w 4 dc.b 0, $D, $66, $D2, 0, 0 dc.b 0, $D, $65, $3A, 0, $28 dc.b 0, 1, $66, $CA, 0, $48 dc.b $F6, 6, 5, $34, 0, $4C word_2DDCC: dc.w 3 dc.b 0, $D, $60, $59, 0, 0 dc.b 0, 9, $60, $61, 0, $20 dc.b $F6, 6, 5, $34, 0, $34 word_2DDE0: dc.w 3 dc.b 0, $D, $60, $67, 0, 0 dc.b 0, $D, $60, $6F, 0, $20 dc.b $F6, 6, 5, $34, 0, $3C word_2DDF4: dc.w 1 dc.b $F8, 5, $40, $49, $FF, $F8 word_2DDFC: dc.w 1 dc.b $F8, 5, $40, $45, $FF, $F8 word_2DE04: dc.w 1 dc.b $F8, 5, $40, $4D, $FF, $F8 word_2DE0C: dc.w 1 dc.b $F8, 5, $20, $45, $FF, $F8 word_2DE14: dc.w 1 dc.b $F8, 5, 0, $55, $FF, $F8 word_2DE1C: dc.w 1 dc.b $F8, 5, 0, $51, $FF, $F8 word_2DE24: dc.w 1 dc.b $F8, 5, $20, $49, $FF, $F8 word_2DE2C: dc.w $C dc.b 0, 5, $60, $37, $FF, $A0 dc.b 0, 5, $60, $2F, $FF, $B0 dc.b 0, 5, $60, $11, $FF, $C0 dc.b 0, 5, $60, 9, $FF, $D0 dc.b 0, 1, $60, $1D, $FF, $E0 dc.b 0, 5, $60, 1, $FF, $E8 dc.b 0, 5, $60, $1F, $FF, $F8 dc.b 0, 5, $60, $37, 0, $10 dc.b 0, 5, $60, $3B, 0, $20 dc.b 0, 5, $60, 1, 0, $30 dc.b 0, 5, $60, $15, 0, $40 dc.b 0, 5, $60, $11, 0, $50 word_2DE76: dc.w 4 dc.b 0, 5, $60, $15, 0, 0 dc.b 0, 5, $60, $2B, 0, $10 dc.b 0, 5, $60, $3B, 0, $20 dc.b 0, 5, $60, 1, 0, $38 word_2DE90: dc.w $C dc.b 0, 5, $60, 9, $FF, $9C dc.b 0, 5, $60, $19, $FF, $AC dc.b 0, 5, $60, 1, $FF, $BC dc.b 0, 5, $60, $2B, $FF, $CC dc.b 0, 5, $60, $37, $FF, $DC dc.b 0, 5, $60, $11, $FF, $F4 dc.b 0, 5, $60, $23, 0, 4 dc.b 0, 5, $60, $11, 0, $14 dc.b 0, 5, $60, $33, 0, $24 dc.b 0, 5, $60, 1, 0, $34 dc.b 0, 5, $60, $1F, 0, $44 dc.b 0, 5, $60, $D, 0, $54 word_2DEDA: dc.w 2 dc.b 0, 5, $60, $1F, 0, $48 dc.b 0, 5, $60, $1F, 0, $58 word_2DEE8: dc.w 1 dc.b 0, 5, $60, $37, 0, $64 word_2DEF0: dc.w 6 dc.b 0, 5, $60, $27, $FF, $A0 dc.b 0, 5, $60, $2B, $FF, $B0 dc.b 0, 9, $60, $3F, $FF, $C0 dc.b 0, 5, $60, 9, 0, $30 dc.b 0, 5, $60, 1, 0, $40 dc.b 0, 5, $60, $27, 0, $50 word_2DF16: dc.w 2 dc.b 0, 5, $60, 5, 0, 0 dc.b 0, 5, $60, $11, 0, $10 word_2DF24: dc.w 1 dc.b $E8, $A, 0, $77, $FF, $F4 word_2DF2C: dc.w 1 dc.b $E8, $A, 0, $80, $FF, $F4 word_2DF34: dc.w 1 dc.b $E8, $A, 0, $89, $FF, $F4
// Initialize stack pointer to start at 256 (i.e. RAM[0] contains 256) @256 D=A @SP M=D // push constant 69 @69 D=A @SP A=M M=D @SP M=M+1 // not: // 69: 0000000001000101 // !69: 1111111110111010 (-70) @SP M=M-1 A=M M=!M @SP M=M+1
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r13 push %r14 push %rbp push %rbx push %rcx push %rdi push %rsi lea addresses_A_ht+0xa224, %r13 nop inc %rbx mov $0x6162636465666768, %r10 movq %r10, %xmm6 movups %xmm6, (%r13) and %rbp, %rbp lea addresses_WC_ht+0xa7cb, %rsi lea addresses_UC_ht+0x9a4, %rdi nop nop add %r14, %r14 mov $38, %rcx rep movsq xor $59965, %rbx lea addresses_normal_ht+0x15bf4, %rsi lea addresses_D_ht+0x8c64, %rdi nop nop nop nop add $63852, %r13 mov $78, %rcx rep movsw nop add %r10, %r10 lea addresses_A_ht+0x15f64, %rsi lea addresses_A_ht+0x14e24, %rdi nop add $7887, %r13 mov $94, %rcx rep movsb nop nop nop xor $14940, %r13 lea addresses_WT_ht+0x1b584, %rsi nop nop nop xor %r10, %r10 movb $0x61, (%rsi) nop add %rsi, %rsi lea addresses_D_ht+0x3ff3, %rbp nop nop nop nop nop cmp $28306, %rbx mov (%rbp), %ecx nop nop cmp %rcx, %rcx lea addresses_UC_ht+0x5554, %rsi nop nop nop nop cmp $1300, %rdi mov (%rsi), %ecx nop nop nop nop lfence lea addresses_normal_ht+0x17044, %rsi lea addresses_UC_ht+0xbe24, %rdi nop nop nop nop xor $17106, %r14 mov $99, %rcx rep movsl nop nop nop nop xor $22497, %rbp lea addresses_WC_ht+0xb02, %rsi lea addresses_normal_ht+0xcba4, %rdi nop nop and $52575, %r13 mov $32, %rcx rep movsw nop nop cmp %rbp, %rbp lea addresses_normal_ht+0x1ef14, %r10 nop nop nop and %rsi, %rsi movb (%r10), %bl nop nop nop add $33275, %rbx lea addresses_UC_ht+0x19664, %rsi lea addresses_A_ht+0x1d224, %rdi clflush (%rsi) nop nop nop nop nop sub $27257, %rbx mov $95, %rcx rep movsl sub %rsi, %rsi lea addresses_D_ht+0x5554, %rsi lea addresses_A_ht+0x4624, %rdi nop nop nop nop and %r14, %r14 mov $82, %rcx rep movsq nop nop add %rdi, %rdi lea addresses_UC_ht+0x7e24, %rsi lea addresses_WT_ht+0x190c, %rdi nop nop add $64725, %r14 mov $49, %rcx rep movsq nop nop nop and $20398, %rbx lea addresses_WC_ht+0x3e70, %rsi lea addresses_WT_ht+0x1e854, %rdi nop nop sub %rbp, %rbp mov $95, %rcx rep movsw nop nop nop xor %rbp, %rbp lea addresses_A_ht+0x1624, %r14 nop nop xor %rcx, %rcx movups (%r14), %xmm1 vpextrq $0, %xmm1, %rbp nop nop nop xor %r13, %r13 pop %rsi pop %rdi pop %rcx pop %rbx pop %rbp pop %r14 pop %r13 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %rbp push %rcx push %rdi push %rdx push %rsi // Faulty Load lea addresses_UC+0xde24, %rsi nop nop nop nop dec %rdi mov (%rsi), %r10w lea oracles, %rcx and $0xff, %r10 shlq $12, %r10 mov (%rcx,%r10,1), %r10 pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 0, 'size': 32, 'same': True, 'NT': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_UC', 'AVXalign': True, 'congruent': 0, 'size': 2, 'same': True, 'NT': True}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 8, 'size': 16, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 6, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 5, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 7, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 4, 'size': 1, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': True, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 3, 'size': 4, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 10, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 7, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 0, 'size': 1, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 8, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 11, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 0, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': True}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 4, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 7, 'size': 16, 'same': False, 'NT': False}} {'00': 21829} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
#include <sirius.h> #include <thread> #ifdef __PAPI #include <papi.h> #endif #include "kiss_fft.h" using namespace sirius; #define NOW std::chrono::high_resolution_clock::now() #ifdef __PAPI unsigned long int static thread_id(void) { return omp_get_thread_num(); } #endif void kernel_fractal(int size, double_complex* in, double_complex* out) { for (int i = 0; i < size; i++) { out[i] = double_complex(0, 0); for (int j = 0; j < 100; j++) { out[i] = std::pow(out[i], 2) + in[i]; } } } void kernel_v2(int size, double_complex* in, double_complex* out) { for (int i = 0; i < size; i++) { out[i] = double_complex(0, 0); } for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { out[(i + j) % size] = out[i] + in[(i + j) % size]; } } } void kernel_fft(int size, double_complex* buf) { int depth = int(log2(size) + 1e-10); if (size != std::pow(2, depth)) { printf("wrong FFT size"); exit(0); } for (int i = 0; i < size / 2; i++) { int j = 0; for (int k = 0; k < depth; k++) { if (i & (1 << (depth - k - 1))) j += (1 << k); } if (i != j) std::swap(buf[i], buf[j]); } int nb = size / 2; for (int s = 0; s < depth; s++) { int bs = 1 << (s + 1); for (int ib = 0; ib < nb; ib++) { for (int k = 0; k < (1 << s); k++) { double_complex w = std::exp(-double_complex(0, twopi * k / size)); auto z1 = buf[ib * bs + k]; auto z2 = buf[ib * bs + k + (1<<s)]; buf[ib * bs + k] = z1 + w * z2; buf[ib * bs + k + (1<<s)] = z1 - w * z2; } } nb >>= 1; } } void kernel_zgemm(int size, double_complex* in, double_complex* out) { linalg<device_t::CPU>::gemm(0, 0, size, size, size, double_complex(1, 0), in, size, in, size, double_complex(0, 0), out, size); } void kernel_memcpy(int size, double_complex* in, double_complex* out) { memcpy(out, in, size * sizeof(double_complex)); } template <int kernel_id> void test_fft_1d(int size, int num_tasks, int repeat) { int num_threads = omp_get_max_threads(); std::vector<double_complex*> in_buf(num_threads); std::vector<double_complex*> out_buf(num_threads); int N = (kernel_id == 5) ? size * size : size; for (int i = 0; i < num_threads; i++) { in_buf[i] = (double_complex*)fftw_malloc(N * sizeof(double_complex)); out_buf[i] = (double_complex*)fftw_malloc(N * sizeof(double_complex)); } kiss_fft_cfg cfg; if (kernel_id == 1) cfg = kiss_fft_alloc(size, false, 0, 0); std::vector<fftw_plan> plan(num_threads); fftw_plan_with_nthreads(1); if (kernel_id == 0) { for (int i = 0; i < num_threads; i++) { plan[i] = fftw_plan_dft_1d(size, (fftw_complex*)in_buf[i], (fftw_complex*)in_buf[i], FFTW_BACKWARD, FFTW_ESTIMATE); } } int M = (kernel_id == 0 || kernel_id == 1 || kernel_id == 2) ? num_tasks : num_threads; mdarray<double_complex, 2> A(N, M); for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) A(j, i) = type_wrapper<double_complex>::random(); } mdarray<double, 2> times(num_threads, repeat); times.zero(); mdarray<int, 2> counts(num_threads, repeat); counts.zero(); #ifdef __PAPI mdarray<long long, 2> values(2, num_threads); values.zero(); mdarray<long long, 2> tmp_values(2, num_threads); int Events[2] = {PAPI_TOT_CYC, PAPI_TOT_INS}; int num_hwcntrs = 0; int retval; /* Initialize the library */ retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT && retval > 0) { TERMINATE("PAPI library version mismatch!\n"); } if (PAPI_thread_init(thread_id) != PAPI_OK) { TERMINATE("PAPI_thread_init error"); } /* Initialize the PAPI library and get the number of counters available */ if ((num_hwcntrs = PAPI_num_counters()) <= PAPI_OK) { TERMINATE("PAPI error"); } printf("number of available counters: %i\n", num_hwcntrs); if (num_hwcntrs > 2) num_hwcntrs = 2; #pragma omp parallel num_threads(num_fft_workers) { /* Start counting events */ if (PAPI_start_counters(Events, num_hwcntrs) != PAPI_OK) { TERMINATE("PAPI error"); } } #endif auto t0 = NOW; for (int i = 0; i < repeat; i++) { #pragma omp parallel { int tid = omp_get_thread_num(); #pragma omp for schedule(static) for (int j = 0; j < num_tasks; j++) { if (kernel_id == 0 || kernel_id == 1 || kernel_id == 2) { memcpy(in_buf[tid], &A(0, j), N * sizeof(double_complex)); } else { memcpy(in_buf[tid], &A(0, tid), N * sizeof(double_complex)); } auto tt = NOW; #ifdef __PAPI PAPI_read_counters(&tmp_values(0, tid), num_hwcntrs); #endif if (kernel_id == 0) fftw_execute(plan[tid]); if (kernel_id == 1) kiss_fft(cfg, (kiss_fft_cpx*)in_buf[tid], (kiss_fft_cpx*)out_buf[tid]); if (kernel_id == 2) kernel_fft(size, in_buf[tid]); if (kernel_id == 3) kernel_memcpy(size, in_buf[tid], out_buf[tid]); if (kernel_id == 4) kernel_fractal(size, in_buf[tid], out_buf[tid]); if (kernel_id == 5) kernel_zgemm(size, in_buf[tid], out_buf[tid]); #ifdef __PAPI PAPI_accum_counters(&values(0, tid), num_hwcntrs); #endif times(tid, i) += std::chrono::duration_cast< std::chrono::duration<double> >(NOW - tt).count(); counts(tid, i)++; } } } double tot_time = std::chrono::duration_cast< std::chrono::duration<double> >(NOW - t0).count(); #ifdef __PAPI #pragma omp parallel num_threads(num_fft_workers) { int tid = omp_get_thread_num(); /* Stop counting events */ if (PAPI_stop_counters(&tmp_values(0, tid), num_hwcntrs) != PAPI_OK) { TERMINATE("PAPI error"); } } #endif double avg_thread_perf = 0; runtime::pstdout pout(mpi_comm_world()); pout.printf("\n"); pout.printf("rank: %2i\n", mpi_comm_world().rank()); pout.printf("---------\n"); for (int tid = 0; tid < num_threads; tid++) { std::vector<double> x(repeat); double avg = 0; double tot_time_thread = 0; for (int i = 0; i < repeat; i++) { x[i] = (counts(tid, i) == 0) ? 0 : counts(tid, i) / times(tid, i); avg += x[i]; tot_time_thread += times(tid, i); } avg /= repeat; avg_thread_perf += avg; double variance = 0; for (int i = 0; i < repeat; i++) variance += std::pow(x[i] - avg, 2); variance /= repeat; double sigma = std::sqrt(variance); pout.printf(" tid : %i\n", tid); pout.printf(" average performance : %.4f\n", avg); pout.printf(" sigma : %.4f\n", sigma); pout.printf(" coefficient of variation : %.2f%%\n", 100 * (sigma / avg)); pout.printf(" kernel time : %.2f%%\n", 100 * tot_time_thread / tot_time); #ifdef __PAPI pout.printf(" total cycles : %lld\n", values(0, tid)); pout.printf(" instructions completed : %lld\n", values(1, tid)); pout.printf(" completed instructions / cycle : %f\n", double(values(1, tid)) / values(0, tid)); #endif pout.printf(" -------\n"); } double perf = repeat * num_tasks / tot_time; pout.printf("---------\n"); pout.printf("average thread performance: %.4f kernels/sec./thread\n", avg_thread_perf / num_threads); pout.printf("MPI rank effective performance: %.4f kernels/sec./rank\n", perf); pout.printf("---------\n"); pout.flush(); mpi_comm_world().allreduce(&perf, 1); mpi_comm_world().allreduce(&avg_thread_perf, 1); if (mpi_comm_world().rank() == 0) { printf("\n"); printf("Average MPI rank performance: %.4f kernels/sec.\n", avg_thread_perf / mpi_comm_world().size()); printf("Aggregate effective performance: %.4f kernels/sec.\n", perf); printf("\n"); } for (int i = 0; i < num_threads; i++) { fftw_free(in_buf[i]); fftw_free(out_buf[i]); if (kernel_id == 0) fftw_destroy_plan(plan[i]); } } int main(int argn, char** argv) { cmd_args args; args.register_key("--size=", "{int} kernel size (length of FFT buffer or matrix size of a zgemm kernel("); args.register_key("--num_tasks=", "{int} number of kernels inside one measurment"); args.register_key("--repeat=", "{int} number of measurments"); args.register_key("--kernel=", "{int} 0: fftw, 1: kiss_fft, 2: custom_fft, 3: memcpy, 4: fractal progression, 5: zgemm"); args.parse_args(argn, argv); if (argn == 1) { printf("Usage: %s [options]\n", argv[0]); args.print_help(); exit(0); } int size = args.value<int>("size", 128); int num_tasks = args.value<int>("num_tasks", 64); int repeat = args.value<int>("repeat", 100); int kernel_id = args.value<int>("kernel", 0); sirius::initialize(1); if (kernel_id == 0) test_fft_1d<0>(size, num_tasks, repeat); if (kernel_id == 1) test_fft_1d<1>(size, num_tasks, repeat); if (kernel_id == 2) test_fft_1d<2>(size, num_tasks, repeat); if (kernel_id == 3) test_fft_1d<3>(size, num_tasks, repeat); if (kernel_id == 4) test_fft_1d<4>(size, num_tasks, repeat); if (kernel_id == 5) test_fft_1d<5>(size, num_tasks, repeat); sirius::finalize(); }
_cat: file format elf32-i386 Disassembly of section .text: 00000000 <main>: } } int main(int argc, char *argv[]) { 0: 8d 4c 24 04 lea 0x4(%esp),%ecx 4: 83 e4 f0 and $0xfffffff0,%esp 7: ff 71 fc pushl -0x4(%ecx) a: 55 push %ebp b: 89 e5 mov %esp,%ebp d: 57 push %edi e: 56 push %esi f: 53 push %ebx 10: 51 push %ecx 11: be 01 00 00 00 mov $0x1,%esi 16: 83 ec 18 sub $0x18,%esp 19: 8b 01 mov (%ecx),%eax 1b: 8b 59 04 mov 0x4(%ecx),%ebx 1e: 83 c3 04 add $0x4,%ebx int fd, i; if(argc <= 1){ 21: 83 f8 01 cmp $0x1,%eax { 24: 89 45 e4 mov %eax,-0x1c(%ebp) if(argc <= 1){ 27: 7e 54 jle 7d <main+0x7d> 29: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi cat(0); exit(); } for(i = 1; i < argc; i++){ if((fd = open(argv[i], 0)) < 0){ 30: 83 ec 08 sub $0x8,%esp 33: 6a 00 push $0x0 35: ff 33 pushl (%ebx) 37: e8 66 03 00 00 call 3a2 <open> 3c: 83 c4 10 add $0x10,%esp 3f: 85 c0 test %eax,%eax 41: 89 c7 mov %eax,%edi 43: 78 24 js 69 <main+0x69> printf(1, "cat: cannot open %s\n", argv[i]); exit(); } cat(fd); 45: 83 ec 0c sub $0xc,%esp for(i = 1; i < argc; i++){ 48: 83 c6 01 add $0x1,%esi 4b: 83 c3 04 add $0x4,%ebx cat(fd); 4e: 50 push %eax 4f: e8 3c 00 00 00 call 90 <cat> close(fd); 54: 89 3c 24 mov %edi,(%esp) 57: e8 2e 03 00 00 call 38a <close> for(i = 1; i < argc; i++){ 5c: 83 c4 10 add $0x10,%esp 5f: 39 75 e4 cmp %esi,-0x1c(%ebp) 62: 75 cc jne 30 <main+0x30> } exit(); 64: e8 f9 02 00 00 call 362 <exit> printf(1, "cat: cannot open %s\n", argv[i]); 69: 50 push %eax 6a: ff 33 pushl (%ebx) 6c: 68 3b 08 00 00 push $0x83b 71: 6a 01 push $0x1 73: e8 48 04 00 00 call 4c0 <printf> exit(); 78: e8 e5 02 00 00 call 362 <exit> cat(0); 7d: 83 ec 0c sub $0xc,%esp 80: 6a 00 push $0x0 82: e8 09 00 00 00 call 90 <cat> exit(); 87: e8 d6 02 00 00 call 362 <exit> 8c: 66 90 xchg %ax,%ax 8e: 66 90 xchg %ax,%ax 00000090 <cat>: { 90: 55 push %ebp 91: 89 e5 mov %esp,%ebp 93: 56 push %esi 94: 53 push %ebx 95: 8b 75 08 mov 0x8(%ebp),%esi while((n = read(fd, buf, sizeof(buf))) > 0) { 98: eb 1d jmp b7 <cat+0x27> 9a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi if (write(1, buf, n) != n) { a0: 83 ec 04 sub $0x4,%esp a3: 53 push %ebx a4: 68 60 0b 00 00 push $0xb60 a9: 6a 01 push $0x1 ab: e8 d2 02 00 00 call 382 <write> b0: 83 c4 10 add $0x10,%esp b3: 39 d8 cmp %ebx,%eax b5: 75 26 jne dd <cat+0x4d> while((n = read(fd, buf, sizeof(buf))) > 0) { b7: 83 ec 04 sub $0x4,%esp ba: 68 00 02 00 00 push $0x200 bf: 68 60 0b 00 00 push $0xb60 c4: 56 push %esi c5: e8 b0 02 00 00 call 37a <read> ca: 83 c4 10 add $0x10,%esp cd: 83 f8 00 cmp $0x0,%eax d0: 89 c3 mov %eax,%ebx d2: 7f cc jg a0 <cat+0x10> if(n < 0){ d4: 75 1b jne f1 <cat+0x61> } d6: 8d 65 f8 lea -0x8(%ebp),%esp d9: 5b pop %ebx da: 5e pop %esi db: 5d pop %ebp dc: c3 ret printf(1, "cat: write error\n"); dd: 83 ec 08 sub $0x8,%esp e0: 68 18 08 00 00 push $0x818 e5: 6a 01 push $0x1 e7: e8 d4 03 00 00 call 4c0 <printf> exit(); ec: e8 71 02 00 00 call 362 <exit> printf(1, "cat: read error\n"); f1: 50 push %eax f2: 50 push %eax f3: 68 2a 08 00 00 push $0x82a f8: 6a 01 push $0x1 fa: e8 c1 03 00 00 call 4c0 <printf> exit(); ff: e8 5e 02 00 00 call 362 <exit> 104: 66 90 xchg %ax,%ax 106: 66 90 xchg %ax,%ax 108: 66 90 xchg %ax,%ax 10a: 66 90 xchg %ax,%ax 10c: 66 90 xchg %ax,%ax 10e: 66 90 xchg %ax,%ax 00000110 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { 110: 55 push %ebp 111: 89 e5 mov %esp,%ebp 113: 53 push %ebx 114: 8b 45 08 mov 0x8(%ebp),%eax 117: 8b 4d 0c mov 0xc(%ebp),%ecx char *os; os = s; while((*s++ = *t++) != 0) 11a: 89 c2 mov %eax,%edx 11c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 120: 83 c1 01 add $0x1,%ecx 123: 0f b6 59 ff movzbl -0x1(%ecx),%ebx 127: 83 c2 01 add $0x1,%edx 12a: 84 db test %bl,%bl 12c: 88 5a ff mov %bl,-0x1(%edx) 12f: 75 ef jne 120 <strcpy+0x10> ; return os; } 131: 5b pop %ebx 132: 5d pop %ebp 133: c3 ret 134: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 13a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00000140 <strcmp>: int strcmp(const char *p, const char *q) { 140: 55 push %ebp 141: 89 e5 mov %esp,%ebp 143: 53 push %ebx 144: 8b 55 08 mov 0x8(%ebp),%edx 147: 8b 4d 0c mov 0xc(%ebp),%ecx while(*p && *p == *q) 14a: 0f b6 02 movzbl (%edx),%eax 14d: 0f b6 19 movzbl (%ecx),%ebx 150: 84 c0 test %al,%al 152: 75 1c jne 170 <strcmp+0x30> 154: eb 2a jmp 180 <strcmp+0x40> 156: 8d 76 00 lea 0x0(%esi),%esi 159: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi p++, q++; 160: 83 c2 01 add $0x1,%edx while(*p && *p == *q) 163: 0f b6 02 movzbl (%edx),%eax p++, q++; 166: 83 c1 01 add $0x1,%ecx 169: 0f b6 19 movzbl (%ecx),%ebx while(*p && *p == *q) 16c: 84 c0 test %al,%al 16e: 74 10 je 180 <strcmp+0x40> 170: 38 d8 cmp %bl,%al 172: 74 ec je 160 <strcmp+0x20> return (uchar)*p - (uchar)*q; 174: 29 d8 sub %ebx,%eax } 176: 5b pop %ebx 177: 5d pop %ebp 178: c3 ret 179: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 180: 31 c0 xor %eax,%eax return (uchar)*p - (uchar)*q; 182: 29 d8 sub %ebx,%eax } 184: 5b pop %ebx 185: 5d pop %ebp 186: c3 ret 187: 89 f6 mov %esi,%esi 189: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000190 <strlen>: uint strlen(const char *s) { 190: 55 push %ebp 191: 89 e5 mov %esp,%ebp 193: 8b 4d 08 mov 0x8(%ebp),%ecx int n; for(n = 0; s[n]; n++) 196: 80 39 00 cmpb $0x0,(%ecx) 199: 74 15 je 1b0 <strlen+0x20> 19b: 31 d2 xor %edx,%edx 19d: 8d 76 00 lea 0x0(%esi),%esi 1a0: 83 c2 01 add $0x1,%edx 1a3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1) 1a7: 89 d0 mov %edx,%eax 1a9: 75 f5 jne 1a0 <strlen+0x10> ; return n; } 1ab: 5d pop %ebp 1ac: c3 ret 1ad: 8d 76 00 lea 0x0(%esi),%esi for(n = 0; s[n]; n++) 1b0: 31 c0 xor %eax,%eax } 1b2: 5d pop %ebp 1b3: c3 ret 1b4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 1ba: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 000001c0 <memset>: void* memset(void *dst, int c, uint n) { 1c0: 55 push %ebp 1c1: 89 e5 mov %esp,%ebp 1c3: 57 push %edi 1c4: 8b 55 08 mov 0x8(%ebp),%edx } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : 1c7: 8b 4d 10 mov 0x10(%ebp),%ecx 1ca: 8b 45 0c mov 0xc(%ebp),%eax 1cd: 89 d7 mov %edx,%edi 1cf: fc cld 1d0: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 1d2: 89 d0 mov %edx,%eax 1d4: 5f pop %edi 1d5: 5d pop %ebp 1d6: c3 ret 1d7: 89 f6 mov %esi,%esi 1d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000001e0 <strchr>: char* strchr(const char *s, char c) { 1e0: 55 push %ebp 1e1: 89 e5 mov %esp,%ebp 1e3: 53 push %ebx 1e4: 8b 45 08 mov 0x8(%ebp),%eax 1e7: 8b 5d 0c mov 0xc(%ebp),%ebx for(; *s; s++) 1ea: 0f b6 10 movzbl (%eax),%edx 1ed: 84 d2 test %dl,%dl 1ef: 74 1d je 20e <strchr+0x2e> if(*s == c) 1f1: 38 d3 cmp %dl,%bl 1f3: 89 d9 mov %ebx,%ecx 1f5: 75 0d jne 204 <strchr+0x24> 1f7: eb 17 jmp 210 <strchr+0x30> 1f9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 200: 38 ca cmp %cl,%dl 202: 74 0c je 210 <strchr+0x30> for(; *s; s++) 204: 83 c0 01 add $0x1,%eax 207: 0f b6 10 movzbl (%eax),%edx 20a: 84 d2 test %dl,%dl 20c: 75 f2 jne 200 <strchr+0x20> return (char*)s; return 0; 20e: 31 c0 xor %eax,%eax } 210: 5b pop %ebx 211: 5d pop %ebp 212: c3 ret 213: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 219: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000220 <gets>: char* gets(char *buf, int max) { 220: 55 push %ebp 221: 89 e5 mov %esp,%ebp 223: 57 push %edi 224: 56 push %esi 225: 53 push %ebx int i, cc; char c; for(i=0; i+1 < max; ){ 226: 31 f6 xor %esi,%esi 228: 89 f3 mov %esi,%ebx { 22a: 83 ec 1c sub $0x1c,%esp 22d: 8b 7d 08 mov 0x8(%ebp),%edi for(i=0; i+1 < max; ){ 230: eb 2f jmp 261 <gets+0x41> 232: 8d b6 00 00 00 00 lea 0x0(%esi),%esi cc = read(0, &c, 1); 238: 8d 45 e7 lea -0x19(%ebp),%eax 23b: 83 ec 04 sub $0x4,%esp 23e: 6a 01 push $0x1 240: 50 push %eax 241: 6a 00 push $0x0 243: e8 32 01 00 00 call 37a <read> if(cc < 1) 248: 83 c4 10 add $0x10,%esp 24b: 85 c0 test %eax,%eax 24d: 7e 1c jle 26b <gets+0x4b> break; buf[i++] = c; 24f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax 253: 83 c7 01 add $0x1,%edi 256: 88 47 ff mov %al,-0x1(%edi) if(c == '\n' || c == '\r') 259: 3c 0a cmp $0xa,%al 25b: 74 23 je 280 <gets+0x60> 25d: 3c 0d cmp $0xd,%al 25f: 74 1f je 280 <gets+0x60> for(i=0; i+1 < max; ){ 261: 83 c3 01 add $0x1,%ebx 264: 3b 5d 0c cmp 0xc(%ebp),%ebx 267: 89 fe mov %edi,%esi 269: 7c cd jl 238 <gets+0x18> 26b: 89 f3 mov %esi,%ebx break; } buf[i] = '\0'; return buf; } 26d: 8b 45 08 mov 0x8(%ebp),%eax buf[i] = '\0'; 270: c6 03 00 movb $0x0,(%ebx) } 273: 8d 65 f4 lea -0xc(%ebp),%esp 276: 5b pop %ebx 277: 5e pop %esi 278: 5f pop %edi 279: 5d pop %ebp 27a: c3 ret 27b: 90 nop 27c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 280: 8b 75 08 mov 0x8(%ebp),%esi 283: 8b 45 08 mov 0x8(%ebp),%eax 286: 01 de add %ebx,%esi 288: 89 f3 mov %esi,%ebx buf[i] = '\0'; 28a: c6 03 00 movb $0x0,(%ebx) } 28d: 8d 65 f4 lea -0xc(%ebp),%esp 290: 5b pop %ebx 291: 5e pop %esi 292: 5f pop %edi 293: 5d pop %ebp 294: c3 ret 295: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 299: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000002a0 <stat>: int stat(const char *n, struct stat *st) { 2a0: 55 push %ebp 2a1: 89 e5 mov %esp,%ebp 2a3: 56 push %esi 2a4: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); 2a5: 83 ec 08 sub $0x8,%esp 2a8: 6a 00 push $0x0 2aa: ff 75 08 pushl 0x8(%ebp) 2ad: e8 f0 00 00 00 call 3a2 <open> if(fd < 0) 2b2: 83 c4 10 add $0x10,%esp 2b5: 85 c0 test %eax,%eax 2b7: 78 27 js 2e0 <stat+0x40> return -1; r = fstat(fd, st); 2b9: 83 ec 08 sub $0x8,%esp 2bc: ff 75 0c pushl 0xc(%ebp) 2bf: 89 c3 mov %eax,%ebx 2c1: 50 push %eax 2c2: e8 f3 00 00 00 call 3ba <fstat> close(fd); 2c7: 89 1c 24 mov %ebx,(%esp) r = fstat(fd, st); 2ca: 89 c6 mov %eax,%esi close(fd); 2cc: e8 b9 00 00 00 call 38a <close> return r; 2d1: 83 c4 10 add $0x10,%esp } 2d4: 8d 65 f8 lea -0x8(%ebp),%esp 2d7: 89 f0 mov %esi,%eax 2d9: 5b pop %ebx 2da: 5e pop %esi 2db: 5d pop %ebp 2dc: c3 ret 2dd: 8d 76 00 lea 0x0(%esi),%esi return -1; 2e0: be ff ff ff ff mov $0xffffffff,%esi 2e5: eb ed jmp 2d4 <stat+0x34> 2e7: 89 f6 mov %esi,%esi 2e9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000002f0 <atoi>: int atoi(const char *s) { 2f0: 55 push %ebp 2f1: 89 e5 mov %esp,%ebp 2f3: 53 push %ebx 2f4: 8b 4d 08 mov 0x8(%ebp),%ecx int n; n = 0; while('0' <= *s && *s <= '9') 2f7: 0f be 11 movsbl (%ecx),%edx 2fa: 8d 42 d0 lea -0x30(%edx),%eax 2fd: 3c 09 cmp $0x9,%al n = 0; 2ff: b8 00 00 00 00 mov $0x0,%eax while('0' <= *s && *s <= '9') 304: 77 1f ja 325 <atoi+0x35> 306: 8d 76 00 lea 0x0(%esi),%esi 309: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi n = n*10 + *s++ - '0'; 310: 8d 04 80 lea (%eax,%eax,4),%eax 313: 83 c1 01 add $0x1,%ecx 316: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax while('0' <= *s && *s <= '9') 31a: 0f be 11 movsbl (%ecx),%edx 31d: 8d 5a d0 lea -0x30(%edx),%ebx 320: 80 fb 09 cmp $0x9,%bl 323: 76 eb jbe 310 <atoi+0x20> return n; } 325: 5b pop %ebx 326: 5d pop %ebp 327: c3 ret 328: 90 nop 329: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000330 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { 330: 55 push %ebp 331: 89 e5 mov %esp,%ebp 333: 56 push %esi 334: 53 push %ebx 335: 8b 5d 10 mov 0x10(%ebp),%ebx 338: 8b 45 08 mov 0x8(%ebp),%eax 33b: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 33e: 85 db test %ebx,%ebx 340: 7e 14 jle 356 <memmove+0x26> 342: 31 d2 xor %edx,%edx 344: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi *dst++ = *src++; 348: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx 34c: 88 0c 10 mov %cl,(%eax,%edx,1) 34f: 83 c2 01 add $0x1,%edx while(n-- > 0) 352: 39 d3 cmp %edx,%ebx 354: 75 f2 jne 348 <memmove+0x18> return vdst; } 356: 5b pop %ebx 357: 5e pop %esi 358: 5d pop %ebp 359: c3 ret 0000035a <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 35a: b8 01 00 00 00 mov $0x1,%eax 35f: cd 40 int $0x40 361: c3 ret 00000362 <exit>: SYSCALL(exit) 362: b8 02 00 00 00 mov $0x2,%eax 367: cd 40 int $0x40 369: c3 ret 0000036a <wait>: SYSCALL(wait) 36a: b8 03 00 00 00 mov $0x3,%eax 36f: cd 40 int $0x40 371: c3 ret 00000372 <pipe>: SYSCALL(pipe) 372: b8 04 00 00 00 mov $0x4,%eax 377: cd 40 int $0x40 379: c3 ret 0000037a <read>: SYSCALL(read) 37a: b8 05 00 00 00 mov $0x5,%eax 37f: cd 40 int $0x40 381: c3 ret 00000382 <write>: SYSCALL(write) 382: b8 10 00 00 00 mov $0x10,%eax 387: cd 40 int $0x40 389: c3 ret 0000038a <close>: SYSCALL(close) 38a: b8 15 00 00 00 mov $0x15,%eax 38f: cd 40 int $0x40 391: c3 ret 00000392 <kill>: SYSCALL(kill) 392: b8 06 00 00 00 mov $0x6,%eax 397: cd 40 int $0x40 399: c3 ret 0000039a <exec>: SYSCALL(exec) 39a: b8 07 00 00 00 mov $0x7,%eax 39f: cd 40 int $0x40 3a1: c3 ret 000003a2 <open>: SYSCALL(open) 3a2: b8 0f 00 00 00 mov $0xf,%eax 3a7: cd 40 int $0x40 3a9: c3 ret 000003aa <mknod>: SYSCALL(mknod) 3aa: b8 11 00 00 00 mov $0x11,%eax 3af: cd 40 int $0x40 3b1: c3 ret 000003b2 <unlink>: SYSCALL(unlink) 3b2: b8 12 00 00 00 mov $0x12,%eax 3b7: cd 40 int $0x40 3b9: c3 ret 000003ba <fstat>: SYSCALL(fstat) 3ba: b8 08 00 00 00 mov $0x8,%eax 3bf: cd 40 int $0x40 3c1: c3 ret 000003c2 <link>: SYSCALL(link) 3c2: b8 13 00 00 00 mov $0x13,%eax 3c7: cd 40 int $0x40 3c9: c3 ret 000003ca <mkdir>: SYSCALL(mkdir) 3ca: b8 14 00 00 00 mov $0x14,%eax 3cf: cd 40 int $0x40 3d1: c3 ret 000003d2 <chdir>: SYSCALL(chdir) 3d2: b8 09 00 00 00 mov $0x9,%eax 3d7: cd 40 int $0x40 3d9: c3 ret 000003da <dup>: SYSCALL(dup) 3da: b8 0a 00 00 00 mov $0xa,%eax 3df: cd 40 int $0x40 3e1: c3 ret 000003e2 <getpid>: SYSCALL(getpid) 3e2: b8 0b 00 00 00 mov $0xb,%eax 3e7: cd 40 int $0x40 3e9: c3 ret 000003ea <sbrk>: SYSCALL(sbrk) 3ea: b8 0c 00 00 00 mov $0xc,%eax 3ef: cd 40 int $0x40 3f1: c3 ret 000003f2 <sleep>: SYSCALL(sleep) 3f2: b8 0d 00 00 00 mov $0xd,%eax 3f7: cd 40 int $0x40 3f9: c3 ret 000003fa <uptime>: SYSCALL(uptime) 3fa: b8 0e 00 00 00 mov $0xe,%eax 3ff: cd 40 int $0x40 401: c3 ret 00000402 <shutdown>: SYSCALL(shutdown) 402: b8 16 00 00 00 mov $0x16,%eax 407: cd 40 int $0x40 409: c3 ret 0000040a <date>: SYSCALL(date) 40a: b8 17 00 00 00 mov $0x17,%eax 40f: cd 40 int $0x40 411: c3 ret 00000412 <cps>: SYSCALL(cps) 412: b8 18 00 00 00 mov $0x18,%eax 417: cd 40 int $0x40 419: c3 ret 41a: 66 90 xchg %ax,%ax 41c: 66 90 xchg %ax,%ax 41e: 66 90 xchg %ax,%ax 00000420 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 420: 55 push %ebp 421: 89 e5 mov %esp,%ebp 423: 57 push %edi 424: 56 push %esi 425: 53 push %ebx 426: 83 ec 3c sub $0x3c,%esp char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ 429: 85 d2 test %edx,%edx { 42b: 89 45 c0 mov %eax,-0x40(%ebp) neg = 1; x = -xx; 42e: 89 d0 mov %edx,%eax if(sgn && xx < 0){ 430: 79 76 jns 4a8 <printint+0x88> 432: f6 45 08 01 testb $0x1,0x8(%ebp) 436: 74 70 je 4a8 <printint+0x88> x = -xx; 438: f7 d8 neg %eax neg = 1; 43a: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp) } else { x = xx; } i = 0; 441: 31 f6 xor %esi,%esi 443: 8d 5d d7 lea -0x29(%ebp),%ebx 446: eb 0a jmp 452 <printint+0x32> 448: 90 nop 449: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi do{ buf[i++] = digits[x % base]; 450: 89 fe mov %edi,%esi 452: 31 d2 xor %edx,%edx 454: 8d 7e 01 lea 0x1(%esi),%edi 457: f7 f1 div %ecx 459: 0f b6 92 58 08 00 00 movzbl 0x858(%edx),%edx }while((x /= base) != 0); 460: 85 c0 test %eax,%eax buf[i++] = digits[x % base]; 462: 88 14 3b mov %dl,(%ebx,%edi,1) }while((x /= base) != 0); 465: 75 e9 jne 450 <printint+0x30> if(neg) 467: 8b 45 c4 mov -0x3c(%ebp),%eax 46a: 85 c0 test %eax,%eax 46c: 74 08 je 476 <printint+0x56> buf[i++] = '-'; 46e: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1) 473: 8d 7e 02 lea 0x2(%esi),%edi 476: 8d 74 3d d7 lea -0x29(%ebp,%edi,1),%esi 47a: 8b 7d c0 mov -0x40(%ebp),%edi 47d: 8d 76 00 lea 0x0(%esi),%esi 480: 0f b6 06 movzbl (%esi),%eax write(fd, &c, 1); 483: 83 ec 04 sub $0x4,%esp 486: 83 ee 01 sub $0x1,%esi 489: 6a 01 push $0x1 48b: 53 push %ebx 48c: 57 push %edi 48d: 88 45 d7 mov %al,-0x29(%ebp) 490: e8 ed fe ff ff call 382 <write> while(--i >= 0) 495: 83 c4 10 add $0x10,%esp 498: 39 de cmp %ebx,%esi 49a: 75 e4 jne 480 <printint+0x60> putc(fd, buf[i]); } 49c: 8d 65 f4 lea -0xc(%ebp),%esp 49f: 5b pop %ebx 4a0: 5e pop %esi 4a1: 5f pop %edi 4a2: 5d pop %ebp 4a3: c3 ret 4a4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; 4a8: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp) 4af: eb 90 jmp 441 <printint+0x21> 4b1: eb 0d jmp 4c0 <printf> 4b3: 90 nop 4b4: 90 nop 4b5: 90 nop 4b6: 90 nop 4b7: 90 nop 4b8: 90 nop 4b9: 90 nop 4ba: 90 nop 4bb: 90 nop 4bc: 90 nop 4bd: 90 nop 4be: 90 nop 4bf: 90 nop 000004c0 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 4c0: 55 push %ebp 4c1: 89 e5 mov %esp,%ebp 4c3: 57 push %edi 4c4: 56 push %esi 4c5: 53 push %ebx 4c6: 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++){ 4c9: 8b 75 0c mov 0xc(%ebp),%esi 4cc: 0f b6 1e movzbl (%esi),%ebx 4cf: 84 db test %bl,%bl 4d1: 0f 84 b3 00 00 00 je 58a <printf+0xca> ap = (uint*)(void*)&fmt + 1; 4d7: 8d 45 10 lea 0x10(%ebp),%eax 4da: 83 c6 01 add $0x1,%esi state = 0; 4dd: 31 ff xor %edi,%edi ap = (uint*)(void*)&fmt + 1; 4df: 89 45 d4 mov %eax,-0x2c(%ebp) 4e2: eb 2f jmp 513 <printf+0x53> 4e4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 4e8: 83 f8 25 cmp $0x25,%eax 4eb: 0f 84 a7 00 00 00 je 598 <printf+0xd8> write(fd, &c, 1); 4f1: 8d 45 e2 lea -0x1e(%ebp),%eax 4f4: 83 ec 04 sub $0x4,%esp 4f7: 88 5d e2 mov %bl,-0x1e(%ebp) 4fa: 6a 01 push $0x1 4fc: 50 push %eax 4fd: ff 75 08 pushl 0x8(%ebp) 500: e8 7d fe ff ff call 382 <write> 505: 83 c4 10 add $0x10,%esp 508: 83 c6 01 add $0x1,%esi for(i = 0; fmt[i]; i++){ 50b: 0f b6 5e ff movzbl -0x1(%esi),%ebx 50f: 84 db test %bl,%bl 511: 74 77 je 58a <printf+0xca> if(state == 0){ 513: 85 ff test %edi,%edi c = fmt[i] & 0xff; 515: 0f be cb movsbl %bl,%ecx 518: 0f b6 c3 movzbl %bl,%eax if(state == 0){ 51b: 74 cb je 4e8 <printf+0x28> state = '%'; } else { putc(fd, c); } } else if(state == '%'){ 51d: 83 ff 25 cmp $0x25,%edi 520: 75 e6 jne 508 <printf+0x48> if(c == 'd'){ 522: 83 f8 64 cmp $0x64,%eax 525: 0f 84 05 01 00 00 je 630 <printf+0x170> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 52b: 81 e1 f7 00 00 00 and $0xf7,%ecx 531: 83 f9 70 cmp $0x70,%ecx 534: 74 72 je 5a8 <printf+0xe8> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 536: 83 f8 73 cmp $0x73,%eax 539: 0f 84 99 00 00 00 je 5d8 <printf+0x118> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 53f: 83 f8 63 cmp $0x63,%eax 542: 0f 84 08 01 00 00 je 650 <printf+0x190> putc(fd, *ap); ap++; } else if(c == '%'){ 548: 83 f8 25 cmp $0x25,%eax 54b: 0f 84 ef 00 00 00 je 640 <printf+0x180> write(fd, &c, 1); 551: 8d 45 e7 lea -0x19(%ebp),%eax 554: 83 ec 04 sub $0x4,%esp 557: c6 45 e7 25 movb $0x25,-0x19(%ebp) 55b: 6a 01 push $0x1 55d: 50 push %eax 55e: ff 75 08 pushl 0x8(%ebp) 561: e8 1c fe ff ff call 382 <write> 566: 83 c4 0c add $0xc,%esp 569: 8d 45 e6 lea -0x1a(%ebp),%eax 56c: 88 5d e6 mov %bl,-0x1a(%ebp) 56f: 6a 01 push $0x1 571: 50 push %eax 572: ff 75 08 pushl 0x8(%ebp) 575: 83 c6 01 add $0x1,%esi } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 578: 31 ff xor %edi,%edi write(fd, &c, 1); 57a: e8 03 fe ff ff call 382 <write> for(i = 0; fmt[i]; i++){ 57f: 0f b6 5e ff movzbl -0x1(%esi),%ebx write(fd, &c, 1); 583: 83 c4 10 add $0x10,%esp for(i = 0; fmt[i]; i++){ 586: 84 db test %bl,%bl 588: 75 89 jne 513 <printf+0x53> } } } 58a: 8d 65 f4 lea -0xc(%ebp),%esp 58d: 5b pop %ebx 58e: 5e pop %esi 58f: 5f pop %edi 590: 5d pop %ebp 591: c3 ret 592: 8d b6 00 00 00 00 lea 0x0(%esi),%esi state = '%'; 598: bf 25 00 00 00 mov $0x25,%edi 59d: e9 66 ff ff ff jmp 508 <printf+0x48> 5a2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi printint(fd, *ap, 16, 0); 5a8: 83 ec 0c sub $0xc,%esp 5ab: b9 10 00 00 00 mov $0x10,%ecx 5b0: 6a 00 push $0x0 5b2: 8b 7d d4 mov -0x2c(%ebp),%edi 5b5: 8b 45 08 mov 0x8(%ebp),%eax 5b8: 8b 17 mov (%edi),%edx 5ba: e8 61 fe ff ff call 420 <printint> ap++; 5bf: 89 f8 mov %edi,%eax 5c1: 83 c4 10 add $0x10,%esp state = 0; 5c4: 31 ff xor %edi,%edi ap++; 5c6: 83 c0 04 add $0x4,%eax 5c9: 89 45 d4 mov %eax,-0x2c(%ebp) 5cc: e9 37 ff ff ff jmp 508 <printf+0x48> 5d1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi s = (char*)*ap; 5d8: 8b 45 d4 mov -0x2c(%ebp),%eax 5db: 8b 08 mov (%eax),%ecx ap++; 5dd: 83 c0 04 add $0x4,%eax 5e0: 89 45 d4 mov %eax,-0x2c(%ebp) if(s == 0) 5e3: 85 c9 test %ecx,%ecx 5e5: 0f 84 8e 00 00 00 je 679 <printf+0x1b9> while(*s != 0){ 5eb: 0f b6 01 movzbl (%ecx),%eax state = 0; 5ee: 31 ff xor %edi,%edi s = (char*)*ap; 5f0: 89 cb mov %ecx,%ebx while(*s != 0){ 5f2: 84 c0 test %al,%al 5f4: 0f 84 0e ff ff ff je 508 <printf+0x48> 5fa: 89 75 d0 mov %esi,-0x30(%ebp) 5fd: 89 de mov %ebx,%esi 5ff: 8b 5d 08 mov 0x8(%ebp),%ebx 602: 8d 7d e3 lea -0x1d(%ebp),%edi 605: 8d 76 00 lea 0x0(%esi),%esi write(fd, &c, 1); 608: 83 ec 04 sub $0x4,%esp s++; 60b: 83 c6 01 add $0x1,%esi 60e: 88 45 e3 mov %al,-0x1d(%ebp) write(fd, &c, 1); 611: 6a 01 push $0x1 613: 57 push %edi 614: 53 push %ebx 615: e8 68 fd ff ff call 382 <write> while(*s != 0){ 61a: 0f b6 06 movzbl (%esi),%eax 61d: 83 c4 10 add $0x10,%esp 620: 84 c0 test %al,%al 622: 75 e4 jne 608 <printf+0x148> 624: 8b 75 d0 mov -0x30(%ebp),%esi state = 0; 627: 31 ff xor %edi,%edi 629: e9 da fe ff ff jmp 508 <printf+0x48> 62e: 66 90 xchg %ax,%ax printint(fd, *ap, 10, 1); 630: 83 ec 0c sub $0xc,%esp 633: b9 0a 00 00 00 mov $0xa,%ecx 638: 6a 01 push $0x1 63a: e9 73 ff ff ff jmp 5b2 <printf+0xf2> 63f: 90 nop write(fd, &c, 1); 640: 83 ec 04 sub $0x4,%esp 643: 88 5d e5 mov %bl,-0x1b(%ebp) 646: 8d 45 e5 lea -0x1b(%ebp),%eax 649: 6a 01 push $0x1 64b: e9 21 ff ff ff jmp 571 <printf+0xb1> putc(fd, *ap); 650: 8b 7d d4 mov -0x2c(%ebp),%edi write(fd, &c, 1); 653: 83 ec 04 sub $0x4,%esp putc(fd, *ap); 656: 8b 07 mov (%edi),%eax write(fd, &c, 1); 658: 6a 01 push $0x1 ap++; 65a: 83 c7 04 add $0x4,%edi putc(fd, *ap); 65d: 88 45 e4 mov %al,-0x1c(%ebp) write(fd, &c, 1); 660: 8d 45 e4 lea -0x1c(%ebp),%eax 663: 50 push %eax 664: ff 75 08 pushl 0x8(%ebp) 667: e8 16 fd ff ff call 382 <write> ap++; 66c: 89 7d d4 mov %edi,-0x2c(%ebp) 66f: 83 c4 10 add $0x10,%esp state = 0; 672: 31 ff xor %edi,%edi 674: e9 8f fe ff ff jmp 508 <printf+0x48> s = "(null)"; 679: bb 50 08 00 00 mov $0x850,%ebx while(*s != 0){ 67e: b8 28 00 00 00 mov $0x28,%eax 683: e9 72 ff ff ff jmp 5fa <printf+0x13a> 688: 66 90 xchg %ax,%ax 68a: 66 90 xchg %ax,%ax 68c: 66 90 xchg %ax,%ax 68e: 66 90 xchg %ax,%ax 00000690 <free>: static Header base; static Header *freep; void free(void *ap) { 690: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 691: a1 40 0b 00 00 mov 0xb40,%eax { 696: 89 e5 mov %esp,%ebp 698: 57 push %edi 699: 56 push %esi 69a: 53 push %ebx 69b: 8b 5d 08 mov 0x8(%ebp),%ebx bp = (Header*)ap - 1; 69e: 8d 4b f8 lea -0x8(%ebx),%ecx 6a1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 6a8: 39 c8 cmp %ecx,%eax 6aa: 8b 10 mov (%eax),%edx 6ac: 73 32 jae 6e0 <free+0x50> 6ae: 39 d1 cmp %edx,%ecx 6b0: 72 04 jb 6b6 <free+0x26> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 6b2: 39 d0 cmp %edx,%eax 6b4: 72 32 jb 6e8 <free+0x58> break; if(bp + bp->s.size == p->s.ptr){ 6b6: 8b 73 fc mov -0x4(%ebx),%esi 6b9: 8d 3c f1 lea (%ecx,%esi,8),%edi 6bc: 39 fa cmp %edi,%edx 6be: 74 30 je 6f0 <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; 6c0: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 6c3: 8b 50 04 mov 0x4(%eax),%edx 6c6: 8d 34 d0 lea (%eax,%edx,8),%esi 6c9: 39 f1 cmp %esi,%ecx 6cb: 74 3a je 707 <free+0x77> p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; 6cd: 89 08 mov %ecx,(%eax) freep = p; 6cf: a3 40 0b 00 00 mov %eax,0xb40 } 6d4: 5b pop %ebx 6d5: 5e pop %esi 6d6: 5f pop %edi 6d7: 5d pop %ebp 6d8: c3 ret 6d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 6e0: 39 d0 cmp %edx,%eax 6e2: 72 04 jb 6e8 <free+0x58> 6e4: 39 d1 cmp %edx,%ecx 6e6: 72 ce jb 6b6 <free+0x26> { 6e8: 89 d0 mov %edx,%eax 6ea: eb bc jmp 6a8 <free+0x18> 6ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi bp->s.size += p->s.ptr->s.size; 6f0: 03 72 04 add 0x4(%edx),%esi 6f3: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 6f6: 8b 10 mov (%eax),%edx 6f8: 8b 12 mov (%edx),%edx 6fa: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 6fd: 8b 50 04 mov 0x4(%eax),%edx 700: 8d 34 d0 lea (%eax,%edx,8),%esi 703: 39 f1 cmp %esi,%ecx 705: 75 c6 jne 6cd <free+0x3d> p->s.size += bp->s.size; 707: 03 53 fc add -0x4(%ebx),%edx freep = p; 70a: a3 40 0b 00 00 mov %eax,0xb40 p->s.size += bp->s.size; 70f: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 712: 8b 53 f8 mov -0x8(%ebx),%edx 715: 89 10 mov %edx,(%eax) } 717: 5b pop %ebx 718: 5e pop %esi 719: 5f pop %edi 71a: 5d pop %ebp 71b: c3 ret 71c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000720 <malloc>: return freep; } void* malloc(uint nbytes) { 720: 55 push %ebp 721: 89 e5 mov %esp,%ebp 723: 57 push %edi 724: 56 push %esi 725: 53 push %ebx 726: 83 ec 0c sub $0xc,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 729: 8b 45 08 mov 0x8(%ebp),%eax if((prevp = freep) == 0){ 72c: 8b 15 40 0b 00 00 mov 0xb40,%edx nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 732: 8d 78 07 lea 0x7(%eax),%edi 735: c1 ef 03 shr $0x3,%edi 738: 83 c7 01 add $0x1,%edi if((prevp = freep) == 0){ 73b: 85 d2 test %edx,%edx 73d: 0f 84 9d 00 00 00 je 7e0 <malloc+0xc0> 743: 8b 02 mov (%edx),%eax 745: 8b 48 04 mov 0x4(%eax),%ecx base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ 748: 39 cf cmp %ecx,%edi 74a: 76 6c jbe 7b8 <malloc+0x98> 74c: 81 ff 00 10 00 00 cmp $0x1000,%edi 752: bb 00 10 00 00 mov $0x1000,%ebx 757: 0f 43 df cmovae %edi,%ebx p = sbrk(nu * sizeof(Header)); 75a: 8d 34 dd 00 00 00 00 lea 0x0(,%ebx,8),%esi 761: eb 0e jmp 771 <malloc+0x51> 763: 90 nop 764: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 768: 8b 02 mov (%edx),%eax if(p->s.size >= nunits){ 76a: 8b 48 04 mov 0x4(%eax),%ecx 76d: 39 f9 cmp %edi,%ecx 76f: 73 47 jae 7b8 <malloc+0x98> p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) 771: 39 05 40 0b 00 00 cmp %eax,0xb40 777: 89 c2 mov %eax,%edx 779: 75 ed jne 768 <malloc+0x48> p = sbrk(nu * sizeof(Header)); 77b: 83 ec 0c sub $0xc,%esp 77e: 56 push %esi 77f: e8 66 fc ff ff call 3ea <sbrk> if(p == (char*)-1) 784: 83 c4 10 add $0x10,%esp 787: 83 f8 ff cmp $0xffffffff,%eax 78a: 74 1c je 7a8 <malloc+0x88> hp->s.size = nu; 78c: 89 58 04 mov %ebx,0x4(%eax) free((void*)(hp + 1)); 78f: 83 ec 0c sub $0xc,%esp 792: 83 c0 08 add $0x8,%eax 795: 50 push %eax 796: e8 f5 fe ff ff call 690 <free> return freep; 79b: 8b 15 40 0b 00 00 mov 0xb40,%edx if((p = morecore(nunits)) == 0) 7a1: 83 c4 10 add $0x10,%esp 7a4: 85 d2 test %edx,%edx 7a6: 75 c0 jne 768 <malloc+0x48> return 0; } } 7a8: 8d 65 f4 lea -0xc(%ebp),%esp return 0; 7ab: 31 c0 xor %eax,%eax } 7ad: 5b pop %ebx 7ae: 5e pop %esi 7af: 5f pop %edi 7b0: 5d pop %ebp 7b1: c3 ret 7b2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi if(p->s.size == nunits) 7b8: 39 cf cmp %ecx,%edi 7ba: 74 54 je 810 <malloc+0xf0> p->s.size -= nunits; 7bc: 29 f9 sub %edi,%ecx 7be: 89 48 04 mov %ecx,0x4(%eax) p += p->s.size; 7c1: 8d 04 c8 lea (%eax,%ecx,8),%eax p->s.size = nunits; 7c4: 89 78 04 mov %edi,0x4(%eax) freep = prevp; 7c7: 89 15 40 0b 00 00 mov %edx,0xb40 } 7cd: 8d 65 f4 lea -0xc(%ebp),%esp return (void*)(p + 1); 7d0: 83 c0 08 add $0x8,%eax } 7d3: 5b pop %ebx 7d4: 5e pop %esi 7d5: 5f pop %edi 7d6: 5d pop %ebp 7d7: c3 ret 7d8: 90 nop 7d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi base.s.ptr = freep = prevp = &base; 7e0: c7 05 40 0b 00 00 44 movl $0xb44,0xb40 7e7: 0b 00 00 7ea: c7 05 44 0b 00 00 44 movl $0xb44,0xb44 7f1: 0b 00 00 base.s.size = 0; 7f4: b8 44 0b 00 00 mov $0xb44,%eax 7f9: c7 05 48 0b 00 00 00 movl $0x0,0xb48 800: 00 00 00 803: e9 44 ff ff ff jmp 74c <malloc+0x2c> 808: 90 nop 809: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi prevp->s.ptr = p->s.ptr; 810: 8b 08 mov (%eax),%ecx 812: 89 0a mov %ecx,(%edx) 814: eb b1 jmp 7c7 <malloc+0xa7>
; A314898: Coordination sequence Gal.5.136.2 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,9,14,19,24,29,34,39,43,48,53,57,62,67,72,77,82,87,91,96,101,105,110,115,120,125,130,135,139,144,149,153,158,163,168,173,178,183,187,192,197,201,206,211,216,221,226,231,235 mov $5,$0 mov $6,$0 add $6,1 lpb $6 mov $0,$5 sub $6,1 sub $0,$6 mul $0,3 lpb $0 add $0,2 mov $2,$0 mov $0,$4 mod $2,10 add $4,$2 sub $0,$4 mul $0,2 add $0,5 div $0,10 add $0,4 lpe mov $3,$0 add $3,1 add $1,$3 lpe
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #include "tensorflow/core/platform/mlu.h" #include "tensorflow/stream_executor/mlu/mlu_api/lib_ops/util.h" #include "tensorflow/stream_executor/mlu/mlu_api/lib_ops/mlu_lib_ops.h" #include "tensorflow/stream_executor/mlu/mlu_api/lib_ops/mlu_lib_common.h" #include "third_party/mlu/include/bangc_kernel.h" #include "third_party/mlu/include/cnplugin.h" namespace stream_executor { namespace mlu { namespace lib { tensorflow::Status CreateAbsOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateAbsOp(op, input, output)); } tensorflow::Status ComputeAbsOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeAbsOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateActiveOp(MLUBaseOp** op, MLUActiveFunction function, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateActiveOp(op, function, input, output)); } tensorflow::Status ComputeActiveOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* inputs, void* outputs) { CNML_RETURN_STATUS(cnmlComputeActiveOpForward_V4(op, nullptr, inputs, nullptr, outputs, queue, nullptr)); } tensorflow::Status CreateAddOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateAddOp(op, input1, input2, output)); } tensorflow::Status ComputeAddOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeAddOpForward_V4(op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateAndOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateAndOp(op, input1, input2, output)); } tensorflow::Status ComputeAndOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeAndOpForward_V4(op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } void GetArgmaxOpOutputDim(MLUDimension_t argmax_axis, int ni, int ci, int hi, int wi, int *no, int *co, int *ho, int *wo) { if (argmax_axis == MLU_DIM_N) { (*no) = 1; (*co) = ci; (*ho) = hi; (*wo) = wi; } else if (argmax_axis == MLU_DIM_C) { (*no) = ni; (*co) = 1; (*ho) = hi; (*wo) = wi; } else if (argmax_axis == MLU_DIM_H) { (*no) = ni; (*co) = ci; (*ho) = 1; (*wo) = wi; } else if (argmax_axis == MLU_DIM_W) { (*no) = ni; (*co) = ci; (*ho) = hi; (*wo) = 1; } } tensorflow::Status CreateArgmaxOp(MLUBaseOp **op, int argmax_axis, MLUTensor *input, MLUTensor *output) { CNML_RETURN_STATUS(cnmlCreateNdArgmaxOp(op, argmax_axis, input, output)); } tensorflow::Status ComputeArgmaxOp(MLUBaseOp *op, MLUCnrtQueue *queue, void *inputs, void *outputs) { CNML_RETURN_STATUS(cnmlComputeNdArgmaxOpForward_V2(op, nullptr, inputs, nullptr, outputs, queue, nullptr)); } tensorflow::Status CreateBatch2SpaceOp(MLUBaseOp** op, int w_block_size, int h_block_size, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS( cnmlCreateBatch2spaceOp(op, w_block_size, h_block_size, input, output)); } tensorflow::Status ComputeBatch2SpaceOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* inputs, void* outputs) { CNML_RETURN_STATUS(cnmlComputeBatch2spaceOpForward_V4(op, nullptr, inputs, nullptr, outputs, queue, nullptr)); } tensorflow::Status CreateBatchMatMulOp(MLUBaseOp** op, MLUTensor* in0, MLUTensor* in1, bool adj_x, bool adj_y, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateBatchDotOp(op, in0, in1, output, adj_x, adj_y)); } tensorflow::Status ComputeBatchMatMulOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input0, void* input1, void* output) { CNML_RETURN_STATUS(cnmlComputeBatchDotOpForward_V4( op, nullptr, input0, nullptr, input1, nullptr, output, queue, nullptr)); } tensorflow::Status CreateBatchNormOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* mean, MLUTensor* var, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateBatchNormOp(op, input, output, mean, var)); } tensorflow::Status CreateNdBatchNormOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* mean, MLUTensor* var, MLUTensor* output, int dim) { CNML_RETURN_STATUS(cnmlCreateNdBatchNormOp(op, dim, input, output, mean, var)); } tensorflow::Status ComputeBatchNormOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* inputs, void* outputs) { CNML_RETURN_STATUS(cnmlComputeBatchNormOpForward_V4(op, nullptr, inputs, nullptr, outputs, queue, nullptr)); } tensorflow::Status CreateBertSquadOp(MLUBaseOp** op, MLUTensor** inputs, MLUTensor** outputs, MLUTensor** static_tensors, int static_tensors_num, int batch_num, int seq_len) { CNML_RETURN_STATUS(cnmlCreatePluginBertSquadOp(op, inputs, outputs, static_tensors, static_tensors_num, batch_num, seq_len)); } tensorflow::Status ComputeBertSquadOp(MLUBaseOp* op, MLUCnrtQueue* queue, void** inputs, void** outputs) { CNML_RETURN_STATUS(cnmlComputePluginBertSquadOpForward(op, nullptr, inputs, nullptr, outputs, queue, nullptr)); } tensorflow::Status CreateBroadcastAddOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateBroadcastAddOp(op, input1, input2, output)); } tensorflow::Status ComputeBroadcastAddOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeBroadcastAddOpForward_V4( op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateBroadcastMulOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateBroadcastMultOp(op, input1, input2, output)); } tensorflow::Status ComputeBroadcastMulOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeBroadcastMultOpForward_V4( op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateBroadcastOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdBroadcastOp(op, input, output)); } tensorflow::Status ComputeBroadcastOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* inputs, void* outputs) { CNML_RETURN_STATUS(cnmlComputeNdBroadcastOpForward_V2(op, nullptr, inputs, nullptr, outputs, queue, nullptr)); } tensorflow::Status CreateBroadcastSubOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateBroadcastSubOp(op, input1, input2, output)); } tensorflow::Status ComputeBroadcastSubOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeBroadcastSubOpForward_V4( op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateCastOp(MLUBaseOp** op, MLUCastType cast_type, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateCastOp(op, cast_type, input, output)); } tensorflow::Status ComputeCastOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeCastOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateClipOp(MLUBaseOp** op, MLUTensor* input, float lower_bound, float upper_bound, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateClipOp(op, input, output, lower_bound, upper_bound)); } tensorflow::Status ComputeClipOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeClipOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateConcatOp(MLUBaseOp** op, int dim, MLUTensor* inputs[], int input_num, MLUTensor* output) { CNML_RETURN_STATUS( cnmlCreateNdConcatOp(op, dim, inputs, input_num, &output, 1)); } tensorflow::Status ComputeConcatOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* inputs[], int input_num, void* output) { CNML_RETURN_STATUS(cnmlComputeNdConcatOpForward_V2( op, NULL, inputs, input_num, NULL, &output, 1, queue, NULL)); } tensorflow::Status CreateDepthwiseConvOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output, MLUTensor* filter, MLUTensor* bias, int stride_height, int stride_width, int pad_height, int pad_width) { MLUConvDepthwiseOpParam* depthwise_conv_param; TF_CNML_CHECK(cnmlCreateConvDepthwiseOpParam_V2(&depthwise_conv_param, stride_height, stride_width, pad_height, pad_width)); TF_CNML_CHECK(cnmlCreateConvDepthwiseOp(op, depthwise_conv_param, input, output, filter, bias)); TF_CNML_CHECK(cnmlDestroyConvDepthwiseOpParam(&depthwise_conv_param)); return tensorflow::Status::OK(); } tensorflow::Status ComputeDepthwise_ConvOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeConvDepthwiseOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateConv2DOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output, MLUTensor* filter, MLUTensor* bias, int stride_height, int stride_width, int dilation_height, int dilation_width, int pad_height, int pad_width) { MLUConvOpParam* conv_param; TF_CNML_CHECK(cnmlCreateConvOpParam(&conv_param, stride_height, stride_width, dilation_height, dilation_width, pad_height, pad_width)); TF_CNML_CHECK(cnmlCreateConvOp(op, conv_param, input, output, filter, bias)); TF_CNML_CHECK(cnmlDestroyConvOpParam(&conv_param)); return tensorflow::Status::OK(); } tensorflow::Status ComputeConv2DOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeConvOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateConvFirstOp(MLUBaseOp** op, MLUConvFirstOpParam* param, MLUTensor* input, MLUTensor* mean, MLUTensor* output, MLUTensor* filter, MLUTensor* bias, MLUTensor* std) { CNML_RETURN_STATUS(cnmlCreateConvFirstOp( op, param, input, mean , output, filter, bias, std)); } tensorflow::Status ComputeConvFirstOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeConvFirstOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateConv2DBackpropInputOp(MLUBaseOp** op, MLUTensor* w, MLUTensor* dy, MLUTensor* w_param, MLUTensor* dy_param, MLUTensor* output, int sh, int sw, int dh, int dw, int pad_top, int pad_bottom, int pad_left, int pad_right) { MLULOG(3) << "cnmlCreateConvOpBackwardDataParam: " << "sh: " << sh << " sw: " << sw << " dh: " << dh << " dw: " << dw << " pad_top: " << pad_top << " pad_bottom: " << pad_bottom << " pad_left: " << pad_left << " pad_right: " << pad_right; cnmlConvOpBackwardDataParam_t convbp_param; TF_CNML_CHECK(cnmlCreateConvOpBackwardDataParam(&convbp_param, sh, sw, dh, dw, pad_top, pad_bottom, pad_left, pad_right)); TF_CNML_CHECK(cnmlCreateConvOpBackwardData(op, convbp_param, dy, dy_param, output, w, w_param)); CNML_RETURN_STATUS(cnmlDestroyConvOpBackwardDataParam(&convbp_param)); } tensorflow::Status ComputeConv2DBackpropInputOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* w, void* dy, void* w_param, void* dy_param, void* output) { MLUInvokeFuncParam_t compute_forw_param = DefaultInvokeParam(); CNML_RETURN_STATUS(cnmlComputeConvOpBackwardData(op, dy, dy_param, w_param, w, output, &compute_forw_param, queue)); } tensorflow::Status CreateCropOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output, int startIndexOfN, int startIndexOfC, int startIndexOfH, int startIndexOfW, float space_number) { MLUCropOpParam* param; TF_CNML_CHECK(cnmlCreateCropOpParam(&param, startIndexOfN, startIndexOfC, startIndexOfH, startIndexOfW, space_number)); TF_CNML_CHECK(cnmlCreateCropOp(op, param, input, output)); TF_CNML_CHECK(cnmlDestroyCropOpParam(&param)); return tensorflow::Status::OK(); } tensorflow::Status ComputeCropOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeCropOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateCropAndResizeOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* boxes, MLUTensor* box_ind, int crop_height, int crop_width, float extrapolation_value, MLUTensor* output) { cnmlPluginResizeAndColorCvtParam_t params; MLUTensorUtil input_tensor_util(input); int batch_num = input_tensor_util.dim_size(0); int input_channel = input_tensor_util.dim_size(3); int input_height = input_tensor_util.dim_size(1); int input_width = input_tensor_util.dim_size(2); MLUTensorUtil boxes_tensor_util(boxes); int box_number = boxes_tensor_util.dim_size(0); int pad_size = 64; MLUCoreVersion core_ver = static_cast<MLUCoreVersion>(5); cnmlCreatePluginCropFeatureAndResizeOpParam(&params, input_height, input_width, crop_height, crop_width, batch_num, input_channel, box_number, pad_size, core_ver); const int input_num = 3; const int output_num = 1; MLUTensor* cnml_inputs[input_num]; MLUTensor* cnml_outputs[output_num]; cnml_inputs[0] = input; cnml_inputs[1] = boxes; cnml_inputs[2] = box_ind; cnml_outputs[0] = output; TF_CNML_CHECK(cnmlCreatePluginCropFeatureAndResizeOp(op, &params, cnml_inputs, cnml_outputs)); TF_CNML_CHECK(cnmlDestroyPluginCropFeatureAndResizeOpParam(&params)); return tensorflow::Status::OK(); } tensorflow::Status ComputeCropAndResizeOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* boxes, void* box_ind, void* output) { void* in_addr[3] = {input, boxes, box_ind}; void* out_addr[] = {output}; cnrtInvokeFuncParam_t compute_forw_param; int dp = 1; u32_t affinity = 0x01; compute_forw_param.data_parallelism = &dp; compute_forw_param.affinity = &affinity; compute_forw_param.end = CNRT_PARAM_END; CNML_RETURN_STATUS(cnmlComputePluginCropFeatureAndResizeOpForward(op, in_addr, out_addr, compute_forw_param, queue)); } // void CreateCustomizedActiveOpParam(MLUCustomizedActiveOpParam **param, // float x_start, float x_end, float y_min, int segment_num) { // MLU_EXIT_IF_ERROR(cnmlCreateCustomizedActiveOpParam(param, // x_start, x_end, y_min, segment_num)); //} // void DestroyCustomizedActiveOpParam(MLUCustomizedActiveOpParam **param) { // MLU_EXIT_IF_ERROR(cnmlDestroyCustomizedActiveOpParam(param)); //} tensorflow::Status CreateCustomizedActiveOp(MLUBaseOp** op, void* active_func_ptr, MLUTensor* input, MLUTensor* output) { float x_start = -25; float x_end = 25; float y_min = 0; int segment_num = 120; MLUCustomizedActiveOpParam* param; TF_CNML_CHECK(cnmlCreateCustomizedActiveOpParam(&param, x_start, x_end, y_min, segment_num)); TF_CNML_CHECK( cnmlCreateCustomizedActiveOp(op, active_func_ptr, param, input, output)); TF_CNML_CHECK(cnmlDestroyCustomizedActiveOpParam(&param)); return tensorflow::Status::OK(); } tensorflow::Status ComputeCustomizedActiveOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeCustomizedActiveForward_V4( op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateCycleAddOp(MLUBaseOp** op, int dim, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdCycleAddOp(op, dim, input1, input2, output)); } tensorflow::Status ComputeCycleAddOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeNdCycleAddOpForward( op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateCycleAndOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdCycleAndOp(op, MLUTensorUtil::GetTensorDims(input1) - 1, input1, input2, output)); } tensorflow::Status ComputeCycleAndOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeNdCycleAndOpForward( op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateCycleEqualOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdCycleEqualOp(op, MLUTensorUtil::GetTensorDims(input1) - 1, input1, input2, output)); } tensorflow::Status ComputeCycleEqualOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeNdCycleEqualOpForward( op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateCycleGreaterOp(MLUBaseOp** op, MLUTensor* in0, MLUTensor* in1, MLUTensor* output) { // CNML_RETURN_STATUS(cnmlCreateNdCycleGreaterOp(op, // MLUTensorUtil::GetTensorDims(in0) - 1, in0, in1, output)); CNML_RETURN_STATUS(cnmlCreateCycleGreaterOp(op, in0, in1, output)); } tensorflow::Status ComputeCycleGreaterOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input0, void* input1, void* output) { CNML_RETURN_STATUS(cnmlComputeCycleGreaterOpForward_V4( op, nullptr, input0, nullptr, input1, nullptr, output, queue, nullptr)); } tensorflow::Status CreateCycleGreaterEqualOp(MLUBaseOp** op, MLUTensor* in0, MLUTensor* in1, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdCycleGreaterEqualOp(op, MLUTensorUtil::GetTensorDims(in0) - 1, in0, in1, output)); } tensorflow::Status ComputeCycleGreaterEqualOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input0, void* input1, void* output) { CNML_RETURN_STATUS(cnmlComputeNdCycleGreaterEqualOpForward( op, nullptr, input0, nullptr, input1, nullptr, output, queue, nullptr)); } tensorflow::Status CreateCycleLessOp(MLUBaseOp** op, MLUTensor* in0, MLUTensor* in1, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdCycleLessOp(op, MLUTensorUtil::GetTensorDims(in0) - 1, in0, in1, output)); } tensorflow::Status ComputeCycleLessOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input0, void* input1, void* output) { CNML_RETURN_STATUS(cnmlComputeNdCycleLessOpForward( op, nullptr, input0, nullptr, input1, nullptr, output, queue, nullptr)); } tensorflow::Status CreateCycleLessEqualOp(MLUBaseOp** op, MLUTensor* in0, MLUTensor* in1, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdCycleLessEqualOp(op, MLUTensorUtil::GetTensorDims(in0) - 1, in0, in1, output)); } tensorflow::Status ComputeCycleLessEqualOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input0, void* input1, void* output) { CNML_RETURN_STATUS(cnmlComputeNdCycleLessEqualOpForward( op, nullptr, input0, nullptr, input1, nullptr, output, queue, nullptr)); } tensorflow::Status CreateCycleMulOp(MLUBaseOp** op, MLUTensor* in0, MLUTensor* in1, MLUTensor* output) { MLUTensorUtil in0_tensor_util(in0); int in0_dims = in0_tensor_util.dims() - 1; CNML_RETURN_STATUS(cnmlCreateNdCycleMultOp(op, in0_dims, in0, in1, output)); } tensorflow::Status ComputeCycleMulOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input0, void* input1, void* output) { CNML_RETURN_STATUS(cnmlComputeNdCycleMultOpForward( op, nullptr, input0, nullptr, input1, nullptr, output, queue, nullptr)); } tensorflow::Status CreateCycleOrOp(MLUBaseOp** op, MLUTensor* in0, MLUTensor* in1, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdCycleOrOp(op, MLUTensorUtil::GetTensorDims(in0) - 1, in0, in1, output)); } tensorflow::Status ComputeCycleOrOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input0, void* input1, void* output) { CNML_RETURN_STATUS(cnmlComputeNdCycleOrOpForward( op, nullptr, input0, nullptr, input1, nullptr, output, queue, nullptr)); } tensorflow::Status CreateCycleSubOp(MLUBaseOp** op, MLUTensor* in0, MLUTensor* in1, MLUTensor* output) { MLUTensorUtil in0_tensor_util(in0); int in0_dims = in0_tensor_util.dims() - 1; CNML_RETURN_STATUS(cnmlCreateNdCycleSubOp(op, in0_dims, in0, in1, output)); } tensorflow::Status ComputeCycleSubOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input0, void* input1, void* output) { CNML_RETURN_STATUS(cnmlComputeNdCycleSubOpForward( op, nullptr, input0, nullptr, input1, nullptr, output, queue, nullptr)); } tensorflow::Status CreateDeConvOp(MLUBaseOp** op, MLUTensor* in, MLUTensor* output, MLUTensor* filter, MLUTensor* bias, int stride_height, int stride_width, int hu, int hd, int wl, int wr) { MLUDeconvOpParam* param; TF_CNML_CHECK(cnmlCreateDeconvOpParam(&param, stride_height, stride_width, hu, hd, wl, wr)); TF_CNML_CHECK( cnmlCreateDeconvOp(op, param, in, output, filter, bias)); TF_CNML_CHECK(cnmlDestroyDeconvOpParam(&param)); return tensorflow::Status::OK(); } tensorflow::Status ComputeDeConvOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeDeconvOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateSnapshotOp(MLUBaseOp** op, MLUTensor* in, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateDeviceMemcpyOp(op, in, output)); } tensorflow::Status ComputeSnapshotOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeDeviceMemcpyOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateConv2DOpParam(MLUConvOpParam** op_param, int stride_height, int stride_width, int dilation_height, int dilation_width, int pad_height, int pad_width){ CNML_RETURN_STATUS(cnmlCreateConvOpParam(op_param, stride_height, stride_width, dilation_height, dilation_width, pad_height, pad_width)); } tensorflow::Status CreateQuantConv2DOp(MLUBaseOp** op, MLUConvOpParam* param, MLUTensor* input, MLUTensor* input_param, MLUTensor* filter, MLUTensor* filter_param, MLUTensor* bias, MLUTensor* output){ CNML_RETURN_STATUS(cnmlCreateConvOpTrainingForward(op, param, input, input_param, filter, filter_param, bias?bias:nullptr, output)); } tensorflow::Status ComputeQuantConv2DOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* input_param, void* filter, void* filter_param, void* bias, void* output){ CNML_RETURN_STATUS(cnmlComputeConvOpTrainingForward(op, nullptr, input, nullptr, input_param, nullptr, filter, nullptr, filter_param, nullptr, bias?bias:nullptr, nullptr, output, queue, nullptr)); } tensorflow::Status CreateRoundOp(MLUBaseOp** op, MLUTensor* in, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateCastOp(op, CNML_CAST_FLOAT16_TO_FLOAT16_ROUND_EVEN, in, output)); } tensorflow::Status ComputeRoundOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeCastOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateConvDepthwiseOp(MLUBaseOp** op, MLUTensor* in, MLUTensor* filter, MLUTensor* bias, MLUTensor* output, int stride_height, int stride_width) { MLUConvDepthwiseOpParam* param; TF_CNML_CHECK( cnmlCreateConvDepthwiseOpParam(&param, stride_height, stride_width)); TF_CNML_CHECK(cnmlCreateConvDepthwiseOp(op, param, in, output, filter, bias)); TF_CNML_CHECK(cnmlDestroyConvDepthwiseOpParam(&param)); return tensorflow::Status::OK(); } tensorflow::Status ComputeDepthwiseConvOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeConvDepthwiseOpForward_V4( op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateEluOp(MLUBaseOp** op, MLUTensor* in, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateEluOp(op, in, output)); } tensorflow::Status ComputeEluOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeEluOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateEqualOp(MLUBaseOp** op, MLUTensor* in0, MLUTensor* in1, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateEqualOp(op, in0, in1, output)); } tensorflow::Status ComputeEqualOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input0, void* input1, void* output) { CNML_RETURN_STATUS(cnmlComputeEqualOpForward_V4( op, nullptr, input0, nullptr, input1, nullptr, output, queue, nullptr)); } tensorflow::Status CreateErfOp(MLUBaseOp** op, MLUTensor* in, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateErfOp(op, in, output)); } tensorflow::Status ComputeErfOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeErfOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateExpOp(MLUBaseOp** op, MLUTensor* in, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateExpOp(op, in, output)); } tensorflow::Status ComputeExpOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeExpOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateFloorOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateFloorOp(op, input, output)); } tensorflow::Status ComputeFloorOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeFloorOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateGatherOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output, MLUDimension_t gather_mode) { CNML_RETURN_STATUS(cnmlCreateGatherV2Op(op, input1, input2, output, gather_mode)); } tensorflow::Status ComputeGatherOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeGatherV2OpForward_V4( op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateGreaterEqualOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateGreaterEqualOp(op, input1, input2, output)); } tensorflow::Status ComputeGreaterEqualOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeGreaterEqualOpForward_V4( op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateGreaterOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateGreaterOp(op, input1, input2, output)); } tensorflow::Status ComputeGreaterOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeGreaterOpForward_V4( op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateInterpOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output, int output_height, int output_width, bool align_corners) { MLUInterpOpParam* params; TF_CNML_CHECK(cnmlCreateInterpOpParam(&params, output_width, output_height, align_corners)); TF_CNML_CHECK(cnmlCreateInterpOp(op, input, output, params)); TF_CNML_CHECK(cnmlDestroyInterpOpParam(&params)); return tensorflow::Status::OK(); } tensorflow::Status ComputeInterpOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeInterpOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateInvertPermutationOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateInvertPermutationOp(op, input, output)); } tensorflow::Status ComputeInvertPermutationOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeInvertPermutationOpForward(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateIsFiniteOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateIsFiniteOp(op, input, output)); } tensorflow::Status ComputeIsFiniteOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeIsFiniteOpForward(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateLessEqualOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateLessEqualOp(op, input1, input2, output)); } tensorflow::Status ComputeLessEqualOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeLessEqualOpForward_V4( op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateLessOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateLessOp(op, input1, input2, output)); } tensorflow::Status ComputeLessOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeLessOpForward_V4( op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateMlpOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output, MLUTensor* filter, MLUTensor* bias) { CNML_RETURN_STATUS(cnmlCreateMlpOp(op, input, output, filter, bias)); } tensorflow::Status ComputeMlpOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeMlpOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateNearestNeighborOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output, int output_height, int output_width, bool align_corners) { MLUNearestNeighborOpParam *param = nullptr; TF_CNML_CHECK(cnmlCreateNearestNeighborOpParam(&param, output_width, output_height)); TF_CNML_CHECK(cnmlSetNearestNeighborAlignCorner(&param, align_corners)); TF_CNML_CHECK(cnmlCreateNearestNeighborOp(op, input, output, param)); TF_CNML_CHECK(cnmlDestroyNearestNeighborOpParam(&param)); return tensorflow::Status::OK(); } tensorflow::Status ComputeNearestNeighborOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeNearestNeighborOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateLrnOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output, MLULrnType lrn_type, int local_size, double alph, double beta, double k) { cnmlLrnOpParam_t cnml_param = nullptr; TF_CNML_CHECK(cnmlCreateLrnOpParam(&cnml_param, lrn_type, local_size, alph, beta, k)); TF_CNML_CHECK(cnmlCreateLrnOp(op, cnml_param, input, output)); TF_CNML_CHECK(cnmlDestroyLrnOpParam(&cnml_param)); return tensorflow::Status::OK(); } tensorflow::Status ComputeLrnOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeLrnOpForward_V4( op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateNegOp(MLUBaseOp** op, int dim, MLUTensor* input, MLUTensor* alpha, MLUTensor* beta, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdScaleOp(op, dim, input, output, alpha, beta)); } tensorflow::Status ComputeNegOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeNdScaleOpForward(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateOneHotOp(MLUBaseOp** op, MLUTensor* indices, MLUTensor* output, int *shape, int depth, float on_value, float off_value, int axis) { cnmlPluginOneHotOpParam_t param; cnmlCoreVersion_t core_version = CNML_MLU270; TF_CNML_CHECK(cnmlCreatePluginOneHotOpParam( &param, core_version, shape[0], shape[1], shape[2], shape[3], depth, on_value, off_value, axis)); cnmlTensor_t cnml_inputs_ptr[1]; cnmlTensor_t cnml_outputs_ptr[1]; cnml_inputs_ptr[0] = indices; cnml_outputs_ptr[0] = output; CNML_RETURN_STATUS(cnmlCreatePluginOneHotOp(op, param, cnml_inputs_ptr, cnml_outputs_ptr)); TF_CNML_CHECK(cnmlDestroyPluginOneHotOpParam(&param)); } tensorflow::Status ComputeOneHotOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input[], int in_size, void* output[], int out_size) { CNML_RETURN_STATUS(cnmlComputePluginOneHotOpForward(op, input, in_size, output, out_size, queue)); } tensorflow::Status CreateOnesLikeOp(MLUBaseOp** op, int dim, MLUTensor* input, MLUTensor* alpha, MLUTensor* beta, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdScaleOp(op, dim, input, output, alpha, beta)); } tensorflow::Status ComputeOnesLikeOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeNdScaleOpForward(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreatePad4Op(MLUBaseOp** op, MLUTensor* input, MLUTensor* output, int padding_htop, int padding_hbottom, int padding_wleft, int padding_wright, float pad_value) { cnmlAddPadOpParam_t cnml_para = nullptr; TF_CNML_CHECK(cnmlCreateAddPadOpParam_V2(&cnml_para, padding_htop, padding_hbottom, padding_wleft, padding_wright, pad_value)); TF_CNML_CHECK(cnmlCreateAddPadOp(op, cnml_para, input, output)); TF_CNML_CHECK(cnmlDestroyAddPadOpParam(&cnml_para)); return tensorflow::Status::OK(); } tensorflow::Status ComputePad4Op(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeAddPadOpForward_V4( op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreatePoolOp( MLUBaseOp** op, MLUTensor* input, MLUTensor* output, bool real, const std::vector<int>& kernel_size, const std::vector<int>& dilations, const std::vector<int>& strides, const std::vector<std::pair<int, int>>& paddings, MLUPoolMode pool_mode, MLUPoolStrategyMode pool_strategy_mode) { // prepare pool param int paddings_array[paddings.size()][2]; for (int i = 0; i < paddings.size(); ++i) { paddings_array[i][0] = paddings[i].first; paddings_array[i][1] = paddings[i].second; } MLUPoolOpParam* pool_param; TF_CNML_CHECK(cnmlCreateNdPoolOpParam( &pool_param, pool_mode, pool_strategy_mode, real, kernel_size.size(), (const_cast<std::vector<int>&>(kernel_size)).data(), (const_cast<std::vector<int>&>(dilations)).data(), (const_cast<std::vector<int>&>(strides)).data(), paddings_array)); TF_CNML_CHECK(cnmlCreateNdPoolOp(op, pool_param, input, output)); TF_CNML_CHECK(cnmlDestroyNdPoolOpParam(&pool_param)); return tensorflow::Status::OK(); } tensorflow::Status ComputePoolOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeNdPoolOpForward_V2(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreatePowOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output, float c) { CNML_RETURN_STATUS(cnmlCreatePowerOp(op, input, output, c)); } tensorflow::Status ComputePowOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputePowerOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateRealDivOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output, bool high_precision_flag) { TF_CNML_CHECK(cnmlCreateRealDivOp(op, input1, input2, output)); if(high_precision_flag) TF_CNML_CHECK(cnmlSetRealDivHighPrecision(op, high_precision_flag)); return tensorflow::Status::OK(); } tensorflow::Status ComputeRealDivOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input0, void* input1, void* output0) { CNML_RETURN_STATUS(cnmlComputeRealDivOpForward_V4( op, nullptr, input0, nullptr, input1, nullptr, output0, queue, nullptr)); } tensorflow::Status CreateReduceAllOp(MLUBaseOp** op, int axis, MLUTensor* input, MLUTensor* output) { int input_dims = MLUTensorUtil::GetTensorDims(input); TF_PARAMS_CHECK(input_dims >= 1 && input_dims <= 4, "Input dims must be within [1, 4], now ", input_dims); TF_PARAMS_CHECK(input_dims > axis, "The axis must be less than input dims"); cnmlReduce_andDim_t reduce_axis; if (axis == input_dims - 1) { reduce_axis = CNML_REDUCE_AND_DIM_C; } else if (axis == 0) { reduce_axis = CNML_REDUCE_AND_DIM_N; } else if (axis == 1) { reduce_axis = CNML_REDUCE_AND_DIM_H; } else { reduce_axis = CNML_REDUCE_AND_DIM_W; } CNML_RETURN_STATUS(cnmlCreateReduceAndOp(op, reduce_axis, input, output)); } tensorflow::Status ComputeReduceAllOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeReduceAndOpForward(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateReduceAnyOp(MLUBaseOp** op, int axis, MLUTensor* input, MLUTensor* output) { int input_dims = MLUTensorUtil::GetTensorDims(input); TF_PARAMS_CHECK(input_dims >= 1 && input_dims <= 4, "Input dims must be within [1, 4], now ", input_dims); TF_PARAMS_CHECK(input_dims > axis, "The axis must be less than input dims"); cnmlReduce_orDim_t reduce_axis; if (axis == input_dims - 1) { reduce_axis = CNML_REDUCE_OR_DIM_C; } else if (axis == 0) { reduce_axis = CNML_REDUCE_OR_DIM_N; } else if (axis == 1) { reduce_axis = CNML_REDUCE_OR_DIM_H; } else { reduce_axis = CNML_REDUCE_OR_DIM_W; } CNML_RETURN_STATUS(cnmlCreateReduceOrOp(op, reduce_axis, input, output)); } tensorflow::Status ComputeReduceAnyOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeReduceOrOpForward(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateReduceMaxOp(MLUBaseOp** op, int axis, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdReduceMaxOp(op, axis, input, output)); } tensorflow::Status ComputeReduceMaxOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeNdReduceMaxOpForward_V2(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateReduceMeanOp(MLUBaseOp** op, int axis, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdReduceMeanOp(op, axis, input, output)); } tensorflow::Status ComputeReduceMeanOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeNdReduceMeanOpForward_V2(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateReduceSumOp(MLUBaseOp** op, int axis, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdReduceSumOp(op, axis, input, output)); } tensorflow::Status ComputeReduceSumOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeNdReduceSumOpForward_V2(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateReshapeOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { MLUTensorUtil out_tensor_util(output); int output_dims = out_tensor_util.dims(); int* output_shape = out_tensor_util.dim_sizes_array(); MLUReshapeOpParam* reshape_param; TF_CNML_CHECK( cnmlCreateNdReshapeOpParam(&reshape_param, output_shape, output_dims)); TF_CNML_CHECK(cnmlCreateReshapeOp(op, reshape_param, input, output)); TF_CNML_CHECK(cnmlDestroyReshapeOpParam(&reshape_param)); return tensorflow::Status::OK(); } tensorflow::Status ComputeReshapeOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeReshapeOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateReverseOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output, int axis) { int input_dims = MLUTensorUtil::GetTensorDims(input); if (input_dims > 4 || input_dims < 2) { return tensorflow::errors::InvalidArgument( "The dimension size of input must be in [2, 4], now ", input_dims); } if (input_dims <= axis) { return tensorflow::errors::InvalidArgument( "The axis must be less than input dims"); } MLUDimension_t reverse_axis; if (axis == 0) { reverse_axis = MLU_DIM_N; } else if (axis == input_dims - 1) { reverse_axis = MLU_DIM_C; } else if (axis == 1) { reverse_axis = MLU_DIM_H; } else { reverse_axis = MLU_DIM_W; } CNML_RETURN_STATUS(cnmlCreateReverseOp(op, input, output, reverse_axis)); } tensorflow::Status ComputeReverseOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeReverseOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateRsqrtOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateRsqrtOp(op, input, output)); } tensorflow::Status ComputeRsqrtOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeRsqrtOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateScaleOp(MLUBaseOp** op, int dim, MLUTensor* input, MLUTensor* alpha, MLUTensor* beta, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdScaleOp(op, dim, input, output, alpha, beta)); } tensorflow::Status ComputeScaleOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeNdScaleOpForward(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateSelectOp(MLUBaseOp** op, MLUTensor* input0, MLUTensor* input1, MLUTensor* input2, MLUTensor* output, bool bool_index, bool batch_index) { TF_CNML_CHECK(cnmlCreateDyadicSelectOp(op, input0, input1, input2, output)); TF_CNML_CHECK(cnmlDyadicSelectOpSetParam(*op, bool_index, batch_index)); return tensorflow::Status::OK(); } tensorflow::Status ComputeSelectOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input0, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeDyadicSelectOpForward_V4( op, nullptr, input0, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateSeluOp(MLUBaseOp** op, MLUTensor* in, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateSeluOp(op, in, output)); } tensorflow::Status ComputeSeluOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeSeluOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateSoftmaxOp(MLUBaseOp** op, int dim, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdSoftmaxOp(op, dim, input, output)); } tensorflow::Status ComputeSoftmaxOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeNdSoftmaxOpForward_V2(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateSoftsignOp(MLUBaseOp** op, MLUTensor* in, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateSoftsignOp(op, in, output)); } tensorflow::Status ComputeSoftsignOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeSoftsignOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateSpace2BatchOp(MLUBaseOp** op, int w_block_size, int h_block_size, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS( cnmlCreateSpace2batchOp(op, w_block_size, h_block_size, input, output)); } tensorflow::Status ComputeSpace2BatchOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeSpace2batchOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateSplitOp(MLUBaseOp** op, int axis, MLUTensor* input, MLUTensor* outputs[], int output_num) { CNML_RETURN_STATUS(cnmlCreateNdSplitOp(op, axis, &input, 1, outputs, output_num)); } tensorflow::Status ComputeSplitOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* outputs[], int output_num) { CNML_RETURN_STATUS(cnmlComputeNdSplitOpForward_V2( op, nullptr, &input, 1, nullptr, outputs, output_num, queue, nullptr)); } tensorflow::Status CreateSqrtOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateSqrtOp(op, input, output)); } tensorflow::Status ComputeSqrtOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeSqrtOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateSquareOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateSquareOp(op, input, output)); } tensorflow::Status ComputeSquareOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeSquareOpForward_V2(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateSquaredDifferenceOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateSquaredDiffOp(op, input1, input2, output)); } tensorflow::Status ComputeSquaredDifferenceOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeSquaredDiffOpForward_V4( op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateNdStridedSliceOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output, int dim_num, int begin[], int end[], int stride[]) { MLUStridedSliceOpParam* param; TF_CNML_CHECK( cnmlCreateNdStridedSliceOpParam(&param, dim_num, begin, end, stride)); TF_CNML_CHECK(cnmlCreateNdStridedSliceOp(op, param, input, output)); TF_CNML_CHECK(cnmlDestroyNdStridedSliceOpParam(&param)); return tensorflow::Status::OK(); } tensorflow::Status ComputeNdStridedSliceOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeNdStridedSliceOpForward_V2( op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateSubOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateSubOp(op, input1, input2, output)); } tensorflow::Status ComputeSubOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeSubOpForward_V4(op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateTileOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateTileOp(op, input, output)); } tensorflow::Status ComputeTileOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeTileOpForward(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateTopKOp(MLUBaseOp** op, int k, bool sorted, MLUTensor* input, MLUTensor* values_out, MLUTensor* indices_out) { CNML_RETURN_STATUS(cnmlCreateTopkOp_V2( op, k, input, values_out, indices_out, CNML_DIM_C, (sorted ? CNML_TOPK_OP_MODE_MAX : CNML_TOPK_OP_MODE_MIN))); } tensorflow::Status ComputeTopKOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output, void* index) { CNML_RETURN_STATUS(cnmlComputeTopkOpForward_V4(op, nullptr, input, nullptr, output, nullptr, index, queue, nullptr)); } tensorflow::Status CreateTransposeProOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output, int dim_order[], int dim_num) { MLUTransposeOpParam* param; TF_CNML_CHECK(cnmlCreateNdTransposeOpParam(&param, dim_order, dim_num)); TF_CNML_CHECK( cnmlCreateNdTransposeProOp(op, input, output, param)); TF_CNML_CHECK(cnmlDestroyNdTransposeOpParam(&param)); return tensorflow::Status::OK(); } tensorflow::Status ComputeTransposeProOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeNdTransposeProOpForward_V2( op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateBiasAddGradOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateBiasAddOpBackwardBias(op, input, output)); } tensorflow::Status ComputeBiasAddGradOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeBiasAddOpBackwardBias( op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateCosOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateCosOp(op, input, output)); } tensorflow::Status ComputeCosOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeCosOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateConvFilterGradOp(MLUBaseOp** op, MLUTensor* x, MLUTensor* dy, MLUTensor* x_quant, MLUTensor* dy_quant, MLUTensor* dw, int kernel_height, int kernel_width, int stride_height, int stride_width, int dilation_height, int dilation_width, int pad_top, int pad_bottom, int pad_left, int pad_right) { MLUConvOpBackwardParam* param; TF_CNML_CHECK(cnmlCreateConvOpBackwardParam(&param, kernel_height, kernel_width, stride_height, stride_width, dilation_height, dilation_width, pad_top, pad_bottom, pad_left, pad_right)); TF_CNML_CHECK(cnmlCreateConvOpBackwardFilter(op, param, x, dy, x_quant, dy_quant, dw)); TF_CNML_CHECK(cnmlDestroyConvOpBackwardParam(&param)); return tensorflow::Status::OK(); } tensorflow::Status ComputeConvFilterGradOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* x, void* dy, void* x_quant, void* dy_quant, void* dw) { CNML_RETURN_STATUS(cnmlComputeConvOpBackwardFilter(op, nullptr, x, nullptr, dy, nullptr, x_quant, nullptr, dy_quant, nullptr, dw, queue, nullptr)); } tensorflow::Status CreateFloorDivOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateFloorDivOp(op, input1, input2, output)); } tensorflow::Status ComputeFloorDivOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeFloorDivOpForward(op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateFusedBatchNormGradOp( MLUBaseOp** op, MLUTensor* x, MLUTensor* dy, MLUTensor* mean, MLUTensor* variance, MLUTensor* scale, MLUTensor* dx, MLUTensor* d_gamma, MLUTensor* d_beta, float epsilon) { CNML_RETURN_STATUS(cnmlCreateFusedBatchNormOpBackward( op, x, nullptr, dy, mean, variance, scale, dx, d_gamma, d_beta, epsilon)); } tensorflow::Status ComputeFusedBatchNormGradOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* x, void* y, void* dz, void* mean, void* variance, void* gamma, void* dx, void* d_gamma, void* d_beta) { CNML_RETURN_STATUS(cnmlComputeFusedBatchNormOpBackward( op, nullptr, x, nullptr, y, nullptr, dz, nullptr, mean, nullptr, variance, nullptr, gamma, nullptr, dx, nullptr, d_gamma, nullptr, d_beta, queue, nullptr)); } tensorflow::Status CreateFusedBatchNormOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* es_mean, MLUTensor* es_var, MLUTensor* gamma, MLUTensor* beta, MLUTensor* eps, MLUTensor* output, MLUTensor* batch_mean, MLUTensor* batch_var, MLUTensor* mean, MLUTensor* var) { CNML_RETURN_STATUS(cnmlCreateFusedBatchNormOp_V2( op, input, es_mean, es_var, gamma, beta, eps, output, batch_mean, batch_var, mean, var)); } tensorflow::Status ComputeFusedBatchNormOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* es_mean, void* es_var, void* gamma, void* beta, void* output, void* batch_mean, void* batch_var, void* mean, void* var) { CNML_RETURN_STATUS(cnmlComputeFusedBatchNormOpForward_V2( op, nullptr, input, nullptr, es_mean, nullptr, es_var, nullptr, gamma, nullptr, beta, nullptr, output, nullptr, batch_mean, nullptr, batch_var, nullptr, mean, nullptr, var, queue, nullptr)); } tensorflow::Status CreateL2LossOp(MLUBaseOp** op, MLUTensor* x, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateMseOp(op, x, output, nullptr, nullptr)); } tensorflow::Status ComputeL2LossOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input_label, void* input_predicted, void* output) { CNML_RETURN_STATUS(cnmlComputeMseOpForward(op, nullptr, input_label, nullptr, input_predicted, nullptr, output, queue, nullptr)); } tensorflow::Status CreateListDiffOp(MLUBaseOp** op, MLUTensor* x, MLUTensor* y, MLUTensor* output_data, MLUTensor* output_index) { CNML_RETURN_STATUS(cnmlCreateListDiffOp(op, x, y, output_data, output_index)); } tensorflow::Status ComputeListDiffOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* inputX, void* inputY, void* out, void* out_idx) { CNML_RETURN_STATUS(cnmlComputeListDiffOpForward(op, nullptr, inputX, nullptr, inputY, nullptr, out, nullptr, out_idx, queue, nullptr)); } tensorflow::Status CreateLogOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateLogOp(op, input, output)); } tensorflow::Status ComputeLogOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeLogOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateLogicalNotOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNotOp(op, input, output)); } tensorflow::Status ComputeLogicalNotOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeNotOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateLogicalOrOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateOrOp(op, input1, input2, output)); } tensorflow::Status ComputeLogicalOrOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeOrOpForward_V4(op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateReciprocalOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateBasicDivOp(op, input, output)); } tensorflow::Status ComputeReciprocalOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeBasicDivOpForward(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateMaximumOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateMaximumOp(op, input1, input2, output)); } tensorflow::Status ComputeMaximumOpForward(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeMaximumOpForward_V2( op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateMinimumOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateMinimumOp(op, input1, input2, output)); } tensorflow::Status ComputeMinimumOpForward(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { CNML_RETURN_STATUS(cnmlComputeMinimumOpForward_V2( op, nullptr, input1, nullptr, input2, nullptr, output, queue, nullptr)); } tensorflow::Status CreateMaxPoolIndexOp(MLUBaseOp** op, MLUTensor* tensor_in, MLUTensor* output_no_use, MLUTensor* index, int window_height, int window_width, int stride_height, int stride_width, int padding_rows, int padding_cols, int dilation_height, int dilation_width, MLUPoolMode pool_mode, MLUPoolStrategyMode strategy_mode, bool real) { cnmlPoolOpParam* pool_param_ptr = nullptr; TF_CNML_CHECK(cnmlCreatePoolOpParam(&pool_param_ptr, window_height, window_width, stride_height, stride_width, padding_rows, padding_cols, dilation_height, dilation_width, pool_mode, strategy_mode, true)); TF_CNML_CHECK(cnmlCreatePoolIndexOp(op, pool_param_ptr, tensor_in, output_no_use, index)); CNML_RETURN_STATUS(cnmlDestroyPoolOpParam(&pool_param_ptr)); } tensorflow::Status ComputeMaxPoolIndexOp(MLUBaseOp* op, MLUCnrtQueue *queue, void* input, void* output_no_use, void* index) { CNML_RETURN_STATUS(cnmlComputePoolIndexOpForward(op, nullptr, input, nullptr, output_no_use, nullptr, index, queue, nullptr)); } tensorflow::Status CreatePoolBackwardOp(MLUBaseOp** op, MLUTensor* out_backprop, MLUTensor* index, MLUTensor* output, int window_height, int window_width, int stride_height, int stride_width, int pad_left, int pad_right, int pad_up, int pad_down, MLUPoolBackwardMode poolbp_mode, MLUPoolBackwardStrategyMode padding_mode) { MLUPoolOpBackwardParam* poolbp_param_ptr = nullptr; // the last parameter is for pytorch, we just set it to false. TF_CNML_CHECK(cnmlCreatePoolOpBackwardParam(&poolbp_param_ptr, window_height, window_width, stride_height, stride_width, pad_left, pad_right, pad_up, pad_down, poolbp_mode, padding_mode, false)); // in avgpoolbp mode, 3th parameter [index] is not used. TF_CNML_CHECK(cnmlCreatePoolOpBackward(op, out_backprop, index, output, poolbp_param_ptr)); CNML_RETURN_STATUS(cnmlDestroyPoolOpBackwardParam(&poolbp_param_ptr)); } tensorflow::Status ComputePoolBackwardOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* out_backprop, void* index, void* output) { CNML_RETURN_STATUS(cnmlComputePoolOpBackward(op, nullptr, out_backprop, nullptr, index, nullptr, output, queue, nullptr)); } tensorflow::Status CreateQuantifyOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* oldQuanParams, MLUTensor* oldMovPos, MLUTensor* interval, MLUTensor* output, MLUTensor* quanParams, MLUTensor* movPos) { CNML_RETURN_STATUS(cnmlCreateQuantifyOp(op, input, oldQuanParams, oldMovPos, output, quanParams, movPos, interval)); } tensorflow::Status ComputeQuantifyOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* input_param, void* input_mp, void* interval, void* output, void* output_param, void* output_mp) { CNML_RETURN_STATUS(cnmlComputeQuantifyOpForward( op, nullptr, input, nullptr, input_param, nullptr, input_mp, nullptr, output, nullptr, output_param, nullptr, output_mp, nullptr, interval, queue, nullptr)); } tensorflow::Status CreateQuantMatMulOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* filter, MLUTensor* input_param, MLUTensor* filter_param, MLUTensor* bias, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateMlpOpTrainingForward(op, input, input_param, filter, filter_param, bias ? bias : nullptr, output)); } tensorflow::Status ComputeQuantMatMulOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* filter, void* input_param, void* filter_param, void* bias, void* output) { CNML_RETURN_STATUS(cnmlComputeMlpOpTrainingForward(op, nullptr, input, nullptr, input_param, nullptr, filter, nullptr, filter_param, nullptr, bias ? bias : nullptr, nullptr, output, queue, nullptr)); } tensorflow::Status CreateRandomUniformOp(MLUBaseOp** op, MLUTensor* output, int seed) { MLURandomUniformParam* param; TF_CNML_CHECK(cnmlCreateRandomUniformOpParam(&param, CNML_RNG_MT19937, 0., 1.)); TF_CNML_CHECK(cnmlCreateRandomUniformOp(op, param, output)); TF_CNML_CHECK(cnmlSetRandomSeed(*op, seed)); CNML_RETURN_STATUS(cnmlDestroyRandomUniformOpParam(&param)); } tensorflow::Status ComputeRandomUniformOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* output) { CNML_RETURN_STATUS( cnmlComputeRandomUniformOpForward(op, nullptr, output, queue, nullptr)); } tensorflow::Status CreateRangeOp(MLUBaseOp** op, MLUTensor* start, MLUTensor* limit, MLUTensor* delta, int size, MLUTensor* output, cnmlPluginRangeOpParam_t param) { MLUTensor* inputs_ptr[3]; MLUTensor* outputs_ptr[1]; inputs_ptr[0] = start; inputs_ptr[1] = limit; inputs_ptr[2] = delta; outputs_ptr[0] = output; CNML_RETURN_STATUS(cnmlCreatePluginRangeOp(op, param, inputs_ptr, outputs_ptr)); } tensorflow::Status ComputeRangeOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* inputs[], int input_num, void* outputs[], int output_num) { CNML_RETURN_STATUS(cnmlComputePluginRangeOpForward(op, inputs, input_num, outputs, output_num, queue)); } tensorflow::Status CreateReduceProdOp(MLUBaseOp** cnml_reduce_prod_op_ptr_ptr, int axis, MLUTensor* input, MLUTensor* output) { int input_dims = MLUTensorUtil::GetTensorDims(input); TF_PARAMS_CHECK(input_dims >= 1 && input_dims <= 4, "Input dims must be within [1, 4], now ", input_dims); TF_PARAMS_CHECK(input_dims > axis, "The axis must be less than input dims"); MLUDimension_t reduce_axis; if (axis == input_dims - 1) { reduce_axis = MLU_DIM_C; } else if (axis == 0) { reduce_axis = MLU_DIM_N; } else if (axis == 1) { reduce_axis = MLU_DIM_H; } else { reduce_axis = MLU_DIM_W; } CNML_RETURN_STATUS(cnmlCreateReduceProductOp(cnml_reduce_prod_op_ptr_ptr, reduce_axis, input, output)); } tensorflow::Status ComputeReduceProdOp(MLUBaseOp* cnml_reduce_prod_op_ptr, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeReduceProductOpForward_V2( cnml_reduce_prod_op_ptr, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateReluGradOp(MLUBaseOp** op, MLUTensor* dy, MLUTensor* x, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateReluOpBackward(op, x, dy, output)); } tensorflow::Status ComputeReluGradOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* x, void* dy, void* output) { CNML_RETURN_STATUS(cnmlComputeReluOpBackward(op, nullptr, x, nullptr, dy, nullptr, output, queue, nullptr)); } tensorflow::Status CreateRsqrtOpBackward(MLUBaseOp** op, MLUTensor* x, MLUTensor* dy, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateRsqrtGradOp(op, x, dy, output)); } tensorflow::Status ComputeRsqrtOpBackward(MLUBaseOp* op, MLUCnrtQueue* queue, void* y, void* dy, void* output) { CNML_RETURN_STATUS(cnmlComputeRsqrtGradOpForward(op, nullptr, y, nullptr, dy, nullptr, output, queue, nullptr)); } tensorflow::Status CreateScatterNdOpParam(MLUScatterNdOpParam** param, cnmlDimension_t axis, int scatter_length) { CNML_RETURN_STATUS(cnmlCreateScatterOpParam(param, axis, scatter_length)); } tensorflow::Status DestroyScatterNdOpParam(MLUScatterNdOpParam** param) { CNML_RETURN_STATUS(cnmlDestroyScatterOpParam(param)); } tensorflow::Status CreateScatterNdOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, MLUTensor* output, MLUScatterNdOpParam* param) { CNML_RETURN_STATUS(cnmlCreateScatterOp(op, input2, input1, output, param)); } tensorflow::Status ComputeScatterNdOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* index, void* output) { CNML_RETURN_STATUS(cnmlComputeScatterOpForward( op, nullptr, input, nullptr, index, nullptr, output, queue, nullptr)); } tensorflow::Status CreateSinOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateSinOp(op, input, output)); } tensorflow::Status ComputeSinOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeSinOpForward_V4(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateSoftmaxXentWithLogitsOp(MLUBaseOp** op, int dim, MLUTensor* input, MLUTensor* label, MLUTensor* output, MLUTensor* back_out) { CNML_RETURN_STATUS( cnmlCreateNdSoftmaxCeLogitsOp(op, dim, input, label, output, back_out)); } tensorflow::Status ComputeSoftmaxXentWithLogitsOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* label, void* output, void* back_out) { CNML_RETURN_STATUS(cnmlComputeNdSoftmaxCeLogitsOpForward( op, nullptr, input, nullptr, label, nullptr, output, nullptr, back_out, queue, nullptr)); } tensorflow::Status CreateStridedSliceOpBackward( MLUBaseOp** op_ptr, MLUTensor* input, MLUTensor* output, const std::vector<int>& begin, const std::vector<int>& end, const std::vector<int>& strides) { MLUStridedSliceBackwardParam* param_ptr; TF_CNML_CHECK(cnmlCreateStridedSliceOpBackwardParam(&param_ptr, /*nb*/begin[0], /*cb*/begin[3], /*hb*/begin[1], /*wb*/begin[2], /*ne*/end[0], /*ce*/end[3], /*he*/end[1], /*we*/end[2], /*ns*/strides[0], /*cs*/strides[3], /*hs*/strides[1], /*ws*/strides[2])); TF_CNML_CHECK(cnmlCreateStridedSliceOpBackward( op_ptr, param_ptr, input, output)); CNML_RETURN_STATUS(cnmlDestroyStridedSliceOpBackwardParam(&param_ptr)); } tensorflow::Status ComputeStridedSliceGradOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeStridedSliceOpBackward( op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateUniqueOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output, MLUTensor* idx) { CNML_RETURN_STATUS(cnmlCreateUniqueOp(op, input, output, idx)); } tensorflow::Status ComputeUniqueOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output, void* index) { CNML_RETURN_STATUS(cnmlComputeUniqueOpForward( op, nullptr, input, nullptr, output, nullptr, index, queue, nullptr)); } tensorflow::Status CreateUnsortedSegmentSumOp(MLUBaseOp** op, MLUTensor* data, MLUTensor* segment_ids, MLUTensor* output, int num_segments, int data_dims) { cnmlScatterOpParam_t param; cnmlDimension_t axis = (data_dims == 1) ? CNML_DIM_C : CNML_DIM_N; TF_CNML_CHECK(cnmlCreateScatterOpParam(&param, axis, num_segments)); TF_CNML_CHECK(cnmlCreateScatterOp(op, data, segment_ids, output, param)); TF_CNML_CHECK(cnmlDestroyScatterOpParam(&param)); return tensorflow::Status::OK(); } tensorflow::Status ComputeUnsortedSegmentSumOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* data, void* segment_ids, void* output) { CNML_RETURN_STATUS(cnmlComputeScatterOpForward(op, nullptr, data, nullptr, segment_ids, nullptr, output, queue, nullptr)); } tensorflow::Status CreateZerosLikeOp(MLUBaseOp** op, int dim, MLUTensor* input, MLUTensor* alpha, MLUTensor* beta, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdScaleOp(op, dim, input, output, alpha, beta)); } tensorflow::Status ComputeZerosLikeOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeNdScaleOpForward(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateLogSoftmaxOp(MLUBaseOp** op, int dim, MLUTensor* input, MLUTensor* output) { CNML_RETURN_STATUS(cnmlCreateNdLogSoftmaxOp(op, input, output, dim)); } tensorflow::Status ComputeLogSoftmaxOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeNdLogSoftmaxOpForward_V2(op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateNonMaxSuppressionOp(MLUBaseOp** op, MLUTensor* input_boxes, MLUTensor* input_scores, MLUTensor* output, cnmlPluginNonMaxSuppressionOpParam_t param) { int input_num = 2; int output_num = 1; int static_num = 2; MLUTensor* inputs_ptr[2]; MLUTensor* outputs_ptr[1]; inputs_ptr[0] = input_boxes; inputs_ptr[1] = input_scores; outputs_ptr[0] = output; CNML_RETURN_STATUS(cnmlCreatePluginNonMaxSuppressionOp( op, param, inputs_ptr, input_num, outputs_ptr, output_num, static_num)); } tensorflow::Status ComputeNonMaxSuppressionOp(MLUBaseOp* op, void* input_boxes, void* input_scores, void* output, MLUCnrtQueue* queue) { int input_num = 2; int output_num = 1; void *inputs_ptr[2]; void *outputs_ptr[1]; inputs_ptr[0] = input_boxes; inputs_ptr[1] = input_scores; outputs_ptr[0] = output; CNML_RETURN_STATUS(cnmlComputePluginNonMaxSuppressionOpForward( op, nullptr, inputs_ptr, input_num, nullptr, outputs_ptr, output_num, queue, nullptr)); } tensorflow::Status CreateMatrixBandPartOp(MLUBaseOp** op, MLUTensor* input, MLUTensor* output, int num_lower, int num_upper) { CNML_RETURN_STATUS(cnmlCreateMatrixBandPartOp(op, input, output, num_lower, num_upper)); } tensorflow::Status ComputeMatrixBandPartOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input, void* output) { CNML_RETURN_STATUS(cnmlComputeMatrixBandPartOpForward( op, nullptr, input, nullptr, output, queue, nullptr)); } tensorflow::Status CreateLeakyReluOp(MLUBaseOp** op, MLUTensor* features, MLUTensor* alpha, MLUTensor* output, int dim) { CNML_RETURN_STATUS(cnmlCreateNdPreluOp(op, dim, features, output, alpha)); } tensorflow::Status ComputeLeakyReluOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* features, void* output) { CNML_RETURN_STATUS(cnmlComputeNdPreluOpForward(op, nullptr, features, nullptr, output, queue, nullptr)); } tensorflow::Status CreateYolov3DetectionOutputOp( MLUBaseOp** op, MLUTensor** input_tensors, MLUTensor** output_tensors, cnmlPluginYolov3DetectionOutputOpParam_t param) { CNML_RETURN_STATUS(cnmlCreatePluginYolov3DetectionOutputOp( op, param, input_tensors, output_tensors)); } tensorflow::Status ComputeYolov3DetectionOutputOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* inputs[], int input_num, void* outputs[], int output_num) { int dp = 1; cnrtInvokeFuncParam_t compute_forw_param; u32_t affinity = 0x01; compute_forw_param.data_parallelism = &dp; compute_forw_param.affinity = &affinity; compute_forw_param.end = CNRT_PARAM_END; cnmlComputePluginYolov3DetectionOutputOpForward( op, inputs, input_num, outputs, output_num, &compute_forw_param, queue); } tensorflow::Status CreatePowerDifferenceOp(MLUBaseOp** op, MLUTensor* input1, MLUTensor* input2, int input3, MLUTensor* output, int len) { MLUTensor* inputs_ptr[2] = {input1, input2}; MLUTensor* outputs_ptr[1] = {output}; CNML_RETURN_STATUS(cnmlCreatePluginPowerDifferenceOp(op, inputs_ptr, input3, outputs_ptr, len)); } tensorflow::Status ComputePowerDifferenceOp(MLUBaseOp* op, MLUCnrtQueue* queue, void* input1, void* input2, void* output) { void* inputs_ptr[2] = {input1, input2}; void* outputs_ptr[1] = {output}; CNML_RETURN_STATUS(cnmlComputePluginPowerDifferenceOpForward( op, inputs_ptr, outputs_ptr, queue)); } } // namespace lib } // namespace mlu } // namespace stream_executor
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <string.h> #include <openssl/err.h> #include <openssl/rand.h> #include <openssl/ssl.h> #include <openssl/rsa.h> #include <openssl_helpers.h> #include <tpm20.h> #include <tpm2_lib.h> #include <tpm2.pb.h> #include <gflags/gflags.h> // // Copyright 2015 Google Corporation, All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // or in the the file LICENSE-2.0.txt in the top level sourcedirectory // 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 // // Portions of this code were derived TPM2.0-TSS published // by Intel under the license set forth in intel_license.txt // and downloaded on or about August 6, 2015. // Portions of this code were derived tboot published // by Intel under the license set forth in intel_license.txt // and downloaded on or about August 6, 2015. // Portions of this code were derived from the crypto utility // published by John Manferdelli under the Apache 2.0 license. // See github.com/jlmucb/crypto. // File: CloudProxySignEndorsementKey.cc // Calling sequence // CloudProxySignEndorsementKey.exe --cloudproxy_private_key_file=file-name [IN] // --endorsement_info_file=file-name [IN] // --signing_instructions_file=file-name [IN] // --signed_endorsement_cert=file-name [OUT] using std::string; // This program reads the endorsement_info_file and sogns a certificate // for the endorsement key using the cloudproxy_signing_key in accordance with // the signing instructions. signing instructions contains a subset of: // duration, purpose, and other information to be included in the // signed certificate. #define MAX_BUF_SIZE 8192 #define CALLING_SEQUENCE "Calling secquence: CloudProxySignEndorsementKey.exe" \ "--cloudproxy_private_key_file=input-file-name" \ "--endorsement_info_file=file-name --signing_instructions_file=input-file-name" \ "--signed_endorsement_cert=output-file-name\n" void PrintOptions() { printf(CALLING_SEQUENCE); } DEFINE_string(endorsement_info_file, "", "output file"); DEFINE_string(cloudproxy_private_key_file, "", "private key file"); DEFINE_string(signing_instructions_file, "", "signing instructions file"); DEFINE_string(signed_endorsement_cert, "", "signed endorsement cert file"); #ifndef GFLAGS_NS #define GFLAGS_NS google #endif #define DEBUG int main(int an, char** av) { int ret_val = 0; printf("\nCloudProxySignEndorsementKey\n\n"); GFLAGS_NS::ParseCommandLineFlags(&an, &av, true); OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); if (FLAGS_signing_instructions_file == "") { printf("signing_instructions_file is empty\n"); return 1; } if (FLAGS_endorsement_info_file == "") { printf("endorsement_info_file is empty\n"); return 1; } if (FLAGS_cloudproxy_private_key_file == "") { printf("cloudproxy_private_key_file is empty\n"); return 1; } if (FLAGS_signed_endorsement_cert == "") { printf("signed_endorsement_cert is empty\n"); return 1; } int in_size = MAX_BUF_SIZE; byte in_buf[MAX_BUF_SIZE]; string input; signing_instructions_message signing_message; if (!ReadFileIntoBlock(FLAGS_signing_instructions_file, &in_size, in_buf)) { printf("Can't read signing instructions %s\n", FLAGS_signing_instructions_file.c_str()); return 1; } input.assign((const char*)in_buf, in_size); if (!signing_message.ParseFromString(input)) { printf("Can't parse signing instructions\n"); return 1; } #ifdef DEBUG printf("issuer: %s, duration: %ld, purpose: %s, hash: %s\n", signing_message.issuer().c_str(), (long)signing_message.duration(), signing_message.purpose().c_str(), signing_message.hash_alg().c_str()); #endif if (!signing_message.can_sign()) { printf("Signing is invalid\n"); return 1; } in_size = MAX_BUF_SIZE; endorsement_key_message endorsement_info; if (!ReadFileIntoBlock(FLAGS_endorsement_info_file, &in_size, in_buf)) { printf("Can't read endorsement info\n"); return 1; } input.assign((const char*)in_buf, in_size); if (!endorsement_info.ParseFromString(input)) { printf("Can't parse endorsement info\n"); return 1; } in_size = MAX_BUF_SIZE; private_key_blob_message private_key; if (!ReadFileIntoBlock(FLAGS_cloudproxy_private_key_file, &in_size, in_buf)) { printf("Can't read private key\n"); printf(" %s\n", FLAGS_cloudproxy_private_key_file.c_str()); return 1; } input.assign((const char*)in_buf, in_size); if (!private_key.ParseFromString(input)) { printf("Can't parse private key\n"); return 1; } #ifdef DEBUG printf("\nPolicy key type: %s\n", private_key.key_type().c_str()); printf("Policy key name: %s\n\n", private_key.key_name().c_str()); #endif string the_blob = private_key.blob(); PrintBytes(the_blob.size(), (byte*)the_blob.data()); const byte* p = (byte*)the_blob.data(); RSA* signing_key = d2i_RSAPrivateKey(nullptr, &p, the_blob.size()); if (signing_key == nullptr) { printf("Can't translate private key\n"); return 1; } #ifdef DEBUG print_internal_private_key(*signing_key); #endif string key_blob = endorsement_info.tpm2b_blob(); uint16_t size_in; ChangeEndian16((uint16_t*)key_blob.data(), (uint16_t*)&size_in); TPM2B_PUBLIC outPublic; if (!GetReadPublicOut(size_in, (byte*)(key_blob.data() + sizeof(uint16_t)), &outPublic)) { printf("Can't parse endorsement blob\n"); return 1; } #ifdef DEBUG printf("\nEndorsement key size: %d\n", (int)outPublic.publicArea.unique.rsa.size * 8); printf("Endorsement key modulus: "); PrintBytes((int)outPublic.publicArea.unique.rsa.size, outPublic.publicArea.unique.rsa.buffer); printf("\n\n"); #endif // fill x509_cert_request_parameters_message x509_cert_request_parameters_message req_message; req_message.set_common_name(endorsement_info.machine_identifier()); // country_name state_name locality_name organization_name // suborganization_name req_message.mutable_key()->set_key_type("RSA"); req_message.mutable_key()->mutable_rsa_key()->set_bit_modulus_size( (int)outPublic.publicArea.unique.rsa.size * 8); uint64_t expIn = (uint64_t) outPublic.publicArea.parameters.rsaDetail.exponent; uint64_t expOut; ChangeEndian64((uint64_t*)&expIn, (uint64_t*)(&expOut)); req_message.mutable_key()->mutable_rsa_key()->set_exponent( (const char*)&expOut, sizeof(uint64_t)); req_message.mutable_key()->mutable_rsa_key()->set_modulus( (const char*)outPublic.publicArea.unique.rsa.buffer, (int)outPublic.publicArea.unique.rsa.size); #ifdef DEBUG printf("\nCert request:\n"); print_cert_request_message(req_message); printf("\n"); #endif EVP_PKEY* subject_key = EVP_PKEY_new(); RSA* rsa_subject_key = RSA_new(); rsa_subject_key->n = bin_to_BN((int)outPublic.publicArea.unique.rsa.size, outPublic.publicArea.unique.rsa.buffer); rsa_subject_key->e = bin_to_BN(sizeof(uint64_t), (byte*)&expOut); EVP_PKEY_assign_RSA(subject_key, rsa_subject_key); X509_REQ* req = X509_REQ_new(); X509_REQ_set_version(req, 2); if (!GenerateX509CertificateRequest(req_message, false, req)) { printf("Can't generate x509 request\n"); return 1; } // sign it X509* cert = X509_new(); X509_set_pubkey(cert, subject_key); // X509_set_issuer_name(cert, issuerSubject) if (!SignX509Certificate(signing_key, false, signing_message, subject_key, req, false, cert)) { printf("Can't sign x509 request\n"); return 1; } #ifdef DEBUG printf("message signed\n"); #endif byte* out = nullptr; int size = i2d_X509(cert, &out); string output; output.assign((const char*)out, size); if (!WriteFileFromBlock(FLAGS_signed_endorsement_cert, output.size(), (byte*)output.data())) { printf("Can't write endorsement cert\n"); return 1; } return ret_val; }
// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chromecast/browser/devtools/cast_devtools_manager_delegate.h" #include "base/macros.h" #include "build/build_config.h" #include "chromecast/app/grit/shell_resources.h" #include "content/public/browser/devtools_agent_host.h" #include "ui/base/resource/resource_bundle.h" namespace chromecast { namespace shell { namespace { CastDevToolsManagerDelegate* g_devtools_manager_delegate = nullptr; } // namespace // static CastDevToolsManagerDelegate* CastDevToolsManagerDelegate::GetInstance() { DCHECK(g_devtools_manager_delegate); return g_devtools_manager_delegate; } CastDevToolsManagerDelegate::CastDevToolsManagerDelegate() { DCHECK(!g_devtools_manager_delegate); g_devtools_manager_delegate = this; } CastDevToolsManagerDelegate::~CastDevToolsManagerDelegate() { DCHECK_EQ(this, g_devtools_manager_delegate); g_devtools_manager_delegate = nullptr; } content::DevToolsAgentHost::List CastDevToolsManagerDelegate::RemoteDebuggingTargets() { content::DevToolsAgentHost::List enabled_hosts; for (auto* web_contents : enabled_webcontents_) { enabled_hosts.push_back( content::DevToolsAgentHost::GetOrCreateFor(web_contents)); } return enabled_hosts; } void CastDevToolsManagerDelegate::EnableWebContentsForDebugging( content::WebContents* web_contents) { DCHECK(web_contents); enabled_webcontents_.insert(web_contents); } void CastDevToolsManagerDelegate::DisableWebContentsForDebugging( content::WebContents* web_contents) { enabled_webcontents_.erase(web_contents); } bool CastDevToolsManagerDelegate::HasEnabledWebContents() const { return !enabled_webcontents_.empty(); } std::string CastDevToolsManagerDelegate::GetDiscoveryPageHTML() { #if defined(OS_ANDROID) return std::string(); #else return ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_CAST_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); #endif } } // namespace shell } // namespace chromecast
; Object Mappings Subtype Frame Arttile dbglistobj Obj_Ring, Map_Ring, 0, 0, make_art_tile($6BC,1,1) dbglistobj Obj_Monitor, Map_Monitor, 6, 0, make_art_tile($4C4,0,0) dbglistobj Obj_PathSwap, Map_PathSwap, 9, 1, make_art_tile($6BC,1,0) dbglistobj Obj_PathSwap, Map_PathSwap, $D, 5, make_art_tile($6BC,1,0) dbglistobj Obj_Spring, Map_Spring, $81, 0, make_art_tile($4A4,0,0) dbglistobj Obj_Spring, Map_Spring, $90, 3, make_art_tile($4B4,0,0) dbglistobj Obj_Spring, Map_Spring, $A0, 6, make_art_tile($4A4,0,0) dbglistobj Obj_Spikes, Map_Spikes, 0, 0, make_art_tile($49C,0,0)
/** This is free and unencumbered software released into the public domain. The authors of ISIS do not claim copyright on the contents of this file. For more details about the LICENSE terms and the AUTHORS, you will find files of those names at the top level of this repository. **/ /* SPDX-License-Identifier: CC0-1.0 */ #include "Isis.h" #include "cnetcombinept.h" #include "Application.h" using namespace std; using namespace Isis; void IsisMain() { UserInterface &ui = Application::GetUserInterface(); Pvl appLog; try { cnetcombinept(ui, &appLog); } catch (...) { for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) { Application::Log(*grpIt); } throw; } for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) { Application::Log(*grpIt); } }
db 0 ; species ID placeholder db 70, 90, 70, 70, 60, 60 ; hp atk def spd sat sdf db DARK, DARK ; type db 255 ; catch rate db 128 ; base exp db NO_ITEM, PSNCUREBERRY ; items db GENDER_F50 ; gender ratio db 100 ; unknown 1 db 15 ; step cycles to hatch db 5 ; unknown 2 INCBIN "gfx/pokemon/mightyena/front.dimensions" db 0, 0, 0, 0 ; padding db GROWTH_MEDIUM_FAST ; growth rate dn EGG_GROUND, EGG_GROUND ; egg groups ; tm/hm learnset tmhm HEADBUTT, CURSE, ROAR, TOXIC, ROCK_SMASH, PSYCH_UP, HIDDEN_POWER, SUNNY_DAY, SNORE, HYPER_BEAM, PROTECT, RAIN_DANCE, ENDURE, FRUSTRATION, IRON_TAIL, RETURN, DIG, DOUBLE_TEAM, SWAGGER, SLEEP_TALK, DETECT, REST, ATTRACT, THIEF, NIGHTMARE, STRENGTH ; end
; A340495: Records in first differences of A340494. ; Submitted by Jamie Morken(s2) ; 2,3,8,33,138,563,2268,9093,36398,145623,582528,2330153,9320658,37282683,149130788,596523213,2386092918,9544371743,38177487048,152709948273,610839793178,2443359172803 mov $2,1 lpb $0 sub $0,1 trn $1,1 add $1,$2 mul $2,4 add $2,2 lpe mov $0,$1 add $0,2
//========= Copyright Valve Corporation, All rights reserved. ============// // // Purpose: // //============================================================================= #include "movieobjects/dmetransforminput.h" #include "movieobjects_interfaces.h" #include "datamodel/dmelementfactoryhelper.h" // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" //----------------------------------------------------------------------------- // Expose this class to the scene database //----------------------------------------------------------------------------- IMPLEMENT_ELEMENT_FACTORY( DmeTranslationInput, CDmeTranslationInput ); void CDmeTranslationInput::OnConstruction() { m_translation.Init( this, "translation" ); } void CDmeTranslationInput::OnDestruction() { } bool CDmeTranslationInput::IsDirty() { return true; } void CDmeTranslationInput::Operate() { } void CDmeTranslationInput::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs ) { } void CDmeTranslationInput::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs ) { attrs.AddToTail( m_translation.GetAttribute() ); } //----------------------------------------------------------------------------- // Expose this class to the scene database //----------------------------------------------------------------------------- IMPLEMENT_ELEMENT_FACTORY( DmeRotationInput, CDmeRotationInput ); void CDmeRotationInput::OnConstruction() { m_orientation.Init( this, "orientation" ); m_angles.Init( this, "angles" ); } void CDmeRotationInput::OnDestruction() { } bool CDmeRotationInput::IsDirty() { return true; } void CDmeRotationInput::Operate() { } void CDmeRotationInput::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs ) { } void CDmeRotationInput::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs ) { attrs.AddToTail( m_orientation.GetAttribute() ); attrs.AddToTail( m_angles.GetAttribute() ); } void CDmeRotationInput::SetRotation( const Quaternion& quat ) { QAngle qangle; QuaternionAngles( quat, qangle ); m_angles = qangle; m_orientation = quat; } void CDmeRotationInput::SetRotation( const QAngle& qangle ) { Quaternion quat; AngleQuaternion( qangle, quat ); m_orientation = quat; m_angles = qangle; }
; ; Copyright (c) 2010 The WebM project authors. All Rights Reserved. ; ; Use of this source code is governed by a BSD-style license ; that can be found in the LICENSE file in the root of the source ; tree. An additional intellectual property rights grant can be found ; in the file PATENTS. All contributing project authors may ; be found in the AUTHORS file in the root of the source tree. ; EXPORT |vp8_loop_filter_horizontal_edge_armv6| EXPORT |vp8_mbloop_filter_horizontal_edge_armv6| EXPORT |vp8_loop_filter_vertical_edge_armv6| EXPORT |vp8_mbloop_filter_vertical_edge_armv6| AREA |.text|, CODE, READONLY ; name this block of code MACRO TRANSPOSE_MATRIX $a0, $a1, $a2, $a3, $b0, $b1, $b2, $b3 ; input: $a0, $a1, $a2, $a3; output: $b0, $b1, $b2, $b3 ; a0: 03 02 01 00 ; a1: 13 12 11 10 ; a2: 23 22 21 20 ; a3: 33 32 31 30 ; b3 b2 b1 b0 uxtb16 $b1, $a1 ; xx 12 xx 10 uxtb16 $b0, $a0 ; xx 02 xx 00 uxtb16 $b3, $a3 ; xx 32 xx 30 uxtb16 $b2, $a2 ; xx 22 xx 20 orr $b1, $b0, $b1, lsl #8 ; 12 02 10 00 orr $b3, $b2, $b3, lsl #8 ; 32 22 30 20 uxtb16 $a1, $a1, ror #8 ; xx 13 xx 11 uxtb16 $a3, $a3, ror #8 ; xx 33 xx 31 uxtb16 $a0, $a0, ror #8 ; xx 03 xx 01 uxtb16 $a2, $a2, ror #8 ; xx 23 xx 21 orr $a0, $a0, $a1, lsl #8 ; 13 03 11 01 orr $a2, $a2, $a3, lsl #8 ; 33 23 31 21 pkhtb $b2, $b3, $b1, asr #16 ; 32 22 12 02 -- p1 pkhbt $b0, $b1, $b3, lsl #16 ; 30 20 10 00 -- p3 pkhtb $b3, $a2, $a0, asr #16 ; 33 23 13 03 -- p0 pkhbt $b1, $a0, $a2, lsl #16 ; 31 21 11 01 -- p2 MEND src RN r0 pstep RN r1 count RN r5 ;r0 unsigned char *src_ptr, ;r1 int src_pixel_step, ;r2 const char *blimit, ;r3 const char *limit, ;stack const char *thresh, ;stack int count ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |vp8_loop_filter_horizontal_edge_armv6| PROC ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- stmdb sp!, {r4 - r11, lr} sub src, src, pstep, lsl #2 ; move src pointer down by 4 lines ldr count, [sp, #40] ; count for 8-in-parallel ldr r6, [sp, #36] ; load thresh address sub sp, sp, #16 ; create temp buffer ldr r9, [src], pstep ; p3 ldrb r4, [r2] ; blimit ldr r10, [src], pstep ; p2 ldrb r2, [r3] ; limit ldr r11, [src], pstep ; p1 orr r4, r4, r4, lsl #8 ldrb r3, [r6] ; thresh orr r2, r2, r2, lsl #8 mov count, count, lsl #1 ; 4-in-parallel orr r4, r4, r4, lsl #16 orr r3, r3, r3, lsl #8 orr r2, r2, r2, lsl #16 orr r3, r3, r3, lsl #16 |Hnext8| ; vp8_filter_mask() function ; calculate breakout conditions ldr r12, [src], pstep ; p0 uqsub8 r6, r9, r10 ; p3 - p2 uqsub8 r7, r10, r9 ; p2 - p3 uqsub8 r8, r10, r11 ; p2 - p1 uqsub8 r10, r11, r10 ; p1 - p2 orr r6, r6, r7 ; abs (p3-p2) orr r8, r8, r10 ; abs (p2-p1) uqsub8 lr, r6, r2 ; compare to limit. lr: vp8_filter_mask uqsub8 r8, r8, r2 ; compare to limit uqsub8 r6, r11, r12 ; p1 - p0 orr lr, lr, r8 uqsub8 r7, r12, r11 ; p0 - p1 ldr r9, [src], pstep ; q0 ldr r10, [src], pstep ; q1 orr r6, r6, r7 ; abs (p1-p0) uqsub8 r7, r6, r2 ; compare to limit uqsub8 r8, r6, r3 ; compare to thresh -- save r8 for later orr lr, lr, r7 uqsub8 r6, r11, r10 ; p1 - q1 uqsub8 r7, r10, r11 ; q1 - p1 uqsub8 r11, r12, r9 ; p0 - q0 uqsub8 r12, r9, r12 ; q0 - p0 orr r6, r6, r7 ; abs (p1-q1) ldr r7, c0x7F7F7F7F orr r12, r11, r12 ; abs (p0-q0) ldr r11, [src], pstep ; q2 uqadd8 r12, r12, r12 ; abs (p0-q0) * 2 and r6, r7, r6, lsr #1 ; abs (p1-q1) / 2 uqsub8 r7, r9, r10 ; q0 - q1 uqadd8 r12, r12, r6 ; abs (p0-q0)*2 + abs (p1-q1)/2 uqsub8 r6, r10, r9 ; q1 - q0 uqsub8 r12, r12, r4 ; compare to flimit uqsub8 r9, r11, r10 ; q2 - q1 orr lr, lr, r12 ldr r12, [src], pstep ; q3 uqsub8 r10, r10, r11 ; q1 - q2 orr r6, r7, r6 ; abs (q1-q0) orr r10, r9, r10 ; abs (q2-q1) uqsub8 r7, r6, r2 ; compare to limit uqsub8 r10, r10, r2 ; compare to limit uqsub8 r6, r6, r3 ; compare to thresh -- save r6 for later orr lr, lr, r7 orr lr, lr, r10 uqsub8 r10, r12, r11 ; q3 - q2 uqsub8 r9, r11, r12 ; q2 - q3 mvn r11, #0 ; r11 == -1 orr r10, r10, r9 ; abs (q3-q2) uqsub8 r10, r10, r2 ; compare to limit mov r12, #0 orr lr, lr, r10 sub src, src, pstep, lsl #2 usub8 lr, r12, lr ; use usub8 instead of ssub8 sel lr, r11, r12 ; filter mask: lr cmp lr, #0 beq hskip_filter ; skip filtering sub src, src, pstep, lsl #1 ; move src pointer down by 6 lines ;vp8_hevmask() function ;calculate high edge variance orr r10, r6, r8 ; calculate vp8_hevmask ldr r7, [src], pstep ; p1 usub8 r10, r12, r10 ; use usub8 instead of ssub8 sel r6, r12, r11 ; obtain vp8_hevmask: r6 ;vp8_filter() function ldr r8, [src], pstep ; p0 ldr r12, c0x80808080 ldr r9, [src], pstep ; q0 ldr r10, [src], pstep ; q1 eor r7, r7, r12 ; p1 offset to convert to a signed value eor r8, r8, r12 ; p0 offset to convert to a signed value eor r9, r9, r12 ; q0 offset to convert to a signed value eor r10, r10, r12 ; q1 offset to convert to a signed value str r9, [sp] ; store qs0 temporarily str r8, [sp, #4] ; store ps0 temporarily str r10, [sp, #8] ; store qs1 temporarily str r7, [sp, #12] ; store ps1 temporarily qsub8 r7, r7, r10 ; vp8_signed_char_clamp(ps1-qs1) qsub8 r8, r9, r8 ; vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0)) and r7, r7, r6 ; vp8_filter (r7) &= hev qadd8 r7, r7, r8 ldr r9, c0x03030303 ; r9 = 3 --modified for vp8 qadd8 r7, r7, r8 ldr r10, c0x04040404 qadd8 r7, r7, r8 and r7, r7, lr ; vp8_filter &= mask; ;modify code for vp8 -- Filter1 = vp8_filter (r7) qadd8 r8 , r7 , r9 ; Filter2 (r8) = vp8_signed_char_clamp(vp8_filter+3) qadd8 r7 , r7 , r10 ; vp8_filter = vp8_signed_char_clamp(vp8_filter+4) mov r9, #0 shadd8 r8 , r8 , r9 ; Filter2 >>= 3 shadd8 r7 , r7 , r9 ; vp8_filter >>= 3 shadd8 r8 , r8 , r9 shadd8 r7 , r7 , r9 shadd8 lr , r8 , r9 ; lr: Filter2 shadd8 r7 , r7 , r9 ; r7: filter ;usub8 lr, r8, r10 ; s = (s==4)*-1 ;sel lr, r11, r9 ;usub8 r8, r10, r8 ;sel r8, r11, r9 ;and r8, r8, lr ; -1 for each element that equals 4 ;calculate output ;qadd8 lr, r8, r7 ; u = vp8_signed_char_clamp(s + vp8_filter) ldr r8, [sp] ; load qs0 ldr r9, [sp, #4] ; load ps0 ldr r10, c0x01010101 qsub8 r8 ,r8, r7 ; u = vp8_signed_char_clamp(qs0 - vp8_filter) qadd8 r9, r9, lr ; u = vp8_signed_char_clamp(ps0 + Filter2) ;end of modification for vp8 mov lr, #0 sadd8 r7, r7 , r10 ; vp8_filter += 1 shadd8 r7, r7, lr ; vp8_filter >>= 1 ldr r11, [sp, #12] ; load ps1 ldr r10, [sp, #8] ; load qs1 bic r7, r7, r6 ; vp8_filter &= ~hev sub src, src, pstep, lsl #2 qadd8 r11, r11, r7 ; u = vp8_signed_char_clamp(ps1 + vp8_filter) qsub8 r10, r10,r7 ; u = vp8_signed_char_clamp(qs1 - vp8_filter) eor r11, r11, r12 ; *op1 = u^0x80 str r11, [src], pstep ; store op1 eor r9, r9, r12 ; *op0 = u^0x80 str r9, [src], pstep ; store op0 result eor r8, r8, r12 ; *oq0 = u^0x80 str r8, [src], pstep ; store oq0 result eor r10, r10, r12 ; *oq1 = u^0x80 str r10, [src], pstep ; store oq1 sub src, src, pstep, lsl #1 |hskip_filter| add src, src, #4 sub src, src, pstep, lsl #2 subs count, count, #1 ldrne r9, [src], pstep ; p3 ldrne r10, [src], pstep ; p2 ldrne r11, [src], pstep ; p1 bne Hnext8 add sp, sp, #16 ldmia sp!, {r4 - r11, pc} ENDP ; |vp8_loop_filter_horizontal_edge_armv6| ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |vp8_mbloop_filter_horizontal_edge_armv6| PROC ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- stmdb sp!, {r4 - r11, lr} sub src, src, pstep, lsl #2 ; move src pointer down by 4 lines ldr count, [sp, #40] ; count for 8-in-parallel ldr r6, [sp, #36] ; load thresh address sub sp, sp, #16 ; create temp buffer ldr r9, [src], pstep ; p3 ldrb r4, [r2] ; blimit ldr r10, [src], pstep ; p2 ldrb r2, [r3] ; limit ldr r11, [src], pstep ; p1 orr r4, r4, r4, lsl #8 ldrb r3, [r6] ; thresh orr r2, r2, r2, lsl #8 mov count, count, lsl #1 ; 4-in-parallel orr r4, r4, r4, lsl #16 orr r3, r3, r3, lsl #8 orr r2, r2, r2, lsl #16 orr r3, r3, r3, lsl #16 |MBHnext8| ; vp8_filter_mask() function ; calculate breakout conditions ldr r12, [src], pstep ; p0 uqsub8 r6, r9, r10 ; p3 - p2 uqsub8 r7, r10, r9 ; p2 - p3 uqsub8 r8, r10, r11 ; p2 - p1 uqsub8 r10, r11, r10 ; p1 - p2 orr r6, r6, r7 ; abs (p3-p2) orr r8, r8, r10 ; abs (p2-p1) uqsub8 lr, r6, r2 ; compare to limit. lr: vp8_filter_mask uqsub8 r8, r8, r2 ; compare to limit uqsub8 r6, r11, r12 ; p1 - p0 orr lr, lr, r8 uqsub8 r7, r12, r11 ; p0 - p1 ldr r9, [src], pstep ; q0 ldr r10, [src], pstep ; q1 orr r6, r6, r7 ; abs (p1-p0) uqsub8 r7, r6, r2 ; compare to limit uqsub8 r8, r6, r3 ; compare to thresh -- save r8 for later orr lr, lr, r7 uqsub8 r6, r11, r10 ; p1 - q1 uqsub8 r7, r10, r11 ; q1 - p1 uqsub8 r11, r12, r9 ; p0 - q0 uqsub8 r12, r9, r12 ; q0 - p0 orr r6, r6, r7 ; abs (p1-q1) ldr r7, c0x7F7F7F7F orr r12, r11, r12 ; abs (p0-q0) ldr r11, [src], pstep ; q2 uqadd8 r12, r12, r12 ; abs (p0-q0) * 2 and r6, r7, r6, lsr #1 ; abs (p1-q1) / 2 uqsub8 r7, r9, r10 ; q0 - q1 uqadd8 r12, r12, r6 ; abs (p0-q0)*2 + abs (p1-q1)/2 uqsub8 r6, r10, r9 ; q1 - q0 uqsub8 r12, r12, r4 ; compare to flimit uqsub8 r9, r11, r10 ; q2 - q1 orr lr, lr, r12 ldr r12, [src], pstep ; q3 uqsub8 r10, r10, r11 ; q1 - q2 orr r6, r7, r6 ; abs (q1-q0) orr r10, r9, r10 ; abs (q2-q1) uqsub8 r7, r6, r2 ; compare to limit uqsub8 r10, r10, r2 ; compare to limit uqsub8 r6, r6, r3 ; compare to thresh -- save r6 for later orr lr, lr, r7 orr lr, lr, r10 uqsub8 r10, r12, r11 ; q3 - q2 uqsub8 r9, r11, r12 ; q2 - q3 mvn r11, #0 ; r11 == -1 orr r10, r10, r9 ; abs (q3-q2) uqsub8 r10, r10, r2 ; compare to limit mov r12, #0 orr lr, lr, r10 usub8 lr, r12, lr ; use usub8 instead of ssub8 sel lr, r11, r12 ; filter mask: lr cmp lr, #0 beq mbhskip_filter ; skip filtering ;vp8_hevmask() function ;calculate high edge variance sub src, src, pstep, lsl #2 ; move src pointer down by 6 lines sub src, src, pstep, lsl #1 orr r10, r6, r8 ldr r7, [src], pstep ; p1 usub8 r10, r12, r10 sel r6, r12, r11 ; hev mask: r6 ;vp8_mbfilter() function ;p2, q2 are only needed at the end. Don't need to load them in now. ldr r8, [src], pstep ; p0 ldr r12, c0x80808080 ldr r9, [src], pstep ; q0 ldr r10, [src] ; q1 eor r7, r7, r12 ; ps1 eor r8, r8, r12 ; ps0 eor r9, r9, r12 ; qs0 eor r10, r10, r12 ; qs1 qsub8 r12, r9, r8 ; vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0)) str r7, [sp, #12] ; store ps1 temporarily qsub8 r7, r7, r10 ; vp8_signed_char_clamp(ps1-qs1) str r10, [sp, #8] ; store qs1 temporarily qadd8 r7, r7, r12 str r9, [sp] ; store qs0 temporarily qadd8 r7, r7, r12 str r8, [sp, #4] ; store ps0 temporarily qadd8 r7, r7, r12 ; vp8_filter: r7 ldr r10, c0x03030303 ; r10 = 3 --modified for vp8 ldr r9, c0x04040404 and r7, r7, lr ; vp8_filter &= mask (lr is free) mov r12, r7 ; Filter2: r12 and r12, r12, r6 ; Filter2 &= hev ;modify code for vp8 ;save bottom 3 bits so that we round one side +4 and the other +3 qadd8 r8 , r12 , r9 ; Filter1 (r8) = vp8_signed_char_clamp(Filter2+4) qadd8 r12 , r12 , r10 ; Filter2 (r12) = vp8_signed_char_clamp(Filter2+3) mov r10, #0 shadd8 r8 , r8 , r10 ; Filter1 >>= 3 shadd8 r12 , r12 , r10 ; Filter2 >>= 3 shadd8 r8 , r8 , r10 shadd8 r12 , r12 , r10 shadd8 r8 , r8 , r10 ; r8: Filter1 shadd8 r12 , r12 , r10 ; r12: Filter2 ldr r9, [sp] ; load qs0 ldr r11, [sp, #4] ; load ps0 qsub8 r9 , r9, r8 ; qs0 = vp8_signed_char_clamp(qs0 - Filter1) qadd8 r11, r11, r12 ; ps0 = vp8_signed_char_clamp(ps0 + Filter2) ;save bottom 3 bits so that we round one side +4 and the other +3 ;and r8, r12, r10 ; s = Filter2 & 7 (s: r8) ;qadd8 r12 , r12 , r9 ; Filter2 = vp8_signed_char_clamp(Filter2+4) ;mov r10, #0 ;shadd8 r12 , r12 , r10 ; Filter2 >>= 3 ;usub8 lr, r8, r9 ; s = (s==4)*-1 ;sel lr, r11, r10 ;shadd8 r12 , r12 , r10 ;usub8 r8, r9, r8 ;sel r8, r11, r10 ;ldr r9, [sp] ; load qs0 ;ldr r11, [sp, #4] ; load ps0 ;shadd8 r12 , r12 , r10 ;and r8, r8, lr ; -1 for each element that equals 4 ;qadd8 r10, r8, r12 ; u = vp8_signed_char_clamp(s + Filter2) ;qsub8 r9 , r9, r12 ; qs0 = vp8_signed_char_clamp(qs0 - Filter2) ;qadd8 r11, r11, r10 ; ps0 = vp8_signed_char_clamp(ps0 + u) ;end of modification for vp8 bic r12, r7, r6 ; vp8_filter &= ~hev ( r6 is free) ;mov r12, r7 ;roughly 3/7th difference across boundary mov lr, #0x1b ; 27 mov r7, #0x3f ; 63 sxtb16 r6, r12 sxtb16 r10, r12, ror #8 smlabb r8, r6, lr, r7 smlatb r6, r6, lr, r7 smlabb r7, r10, lr, r7 smultb r10, r10, lr ssat r8, #8, r8, asr #7 ssat r6, #8, r6, asr #7 add r10, r10, #63 ssat r7, #8, r7, asr #7 ssat r10, #8, r10, asr #7 ldr lr, c0x80808080 pkhbt r6, r8, r6, lsl #16 pkhbt r10, r7, r10, lsl #16 uxtb16 r6, r6 uxtb16 r10, r10 sub src, src, pstep orr r10, r6, r10, lsl #8 ; u = vp8_signed_char_clamp((63 + Filter2 * 27)>>7) qsub8 r8, r9, r10 ; s = vp8_signed_char_clamp(qs0 - u) qadd8 r10, r11, r10 ; s = vp8_signed_char_clamp(ps0 + u) eor r8, r8, lr ; *oq0 = s^0x80 str r8, [src] ; store *oq0 sub src, src, pstep eor r10, r10, lr ; *op0 = s^0x80 str r10, [src] ; store *op0 ;roughly 2/7th difference across boundary mov lr, #0x12 ; 18 mov r7, #0x3f ; 63 sxtb16 r6, r12 sxtb16 r10, r12, ror #8 smlabb r8, r6, lr, r7 smlatb r6, r6, lr, r7 smlabb r9, r10, lr, r7 smlatb r10, r10, lr, r7 ssat r8, #8, r8, asr #7 ssat r6, #8, r6, asr #7 ssat r9, #8, r9, asr #7 ssat r10, #8, r10, asr #7 ldr lr, c0x80808080 pkhbt r6, r8, r6, lsl #16 pkhbt r10, r9, r10, lsl #16 ldr r9, [sp, #8] ; load qs1 ldr r11, [sp, #12] ; load ps1 uxtb16 r6, r6 uxtb16 r10, r10 sub src, src, pstep orr r10, r6, r10, lsl #8 ; u = vp8_signed_char_clamp((63 + Filter2 * 18)>>7) qadd8 r11, r11, r10 ; s = vp8_signed_char_clamp(ps1 + u) qsub8 r8, r9, r10 ; s = vp8_signed_char_clamp(qs1 - u) eor r11, r11, lr ; *op1 = s^0x80 str r11, [src], pstep ; store *op1 eor r8, r8, lr ; *oq1 = s^0x80 add src, src, pstep, lsl #1 mov r7, #0x3f ; 63 str r8, [src], pstep ; store *oq1 ;roughly 1/7th difference across boundary mov lr, #0x9 ; 9 ldr r9, [src] ; load q2 sxtb16 r6, r12 sxtb16 r10, r12, ror #8 smlabb r8, r6, lr, r7 smlatb r6, r6, lr, r7 smlabb r12, r10, lr, r7 smlatb r10, r10, lr, r7 ssat r8, #8, r8, asr #7 ssat r6, #8, r6, asr #7 ssat r12, #8, r12, asr #7 ssat r10, #8, r10, asr #7 sub src, src, pstep, lsl #2 pkhbt r6, r8, r6, lsl #16 pkhbt r10, r12, r10, lsl #16 sub src, src, pstep ldr lr, c0x80808080 ldr r11, [src] ; load p2 uxtb16 r6, r6 uxtb16 r10, r10 eor r9, r9, lr eor r11, r11, lr orr r10, r6, r10, lsl #8 ; u = vp8_signed_char_clamp((63 + Filter2 * 9)>>7) qadd8 r8, r11, r10 ; s = vp8_signed_char_clamp(ps2 + u) qsub8 r10, r9, r10 ; s = vp8_signed_char_clamp(qs2 - u) eor r8, r8, lr ; *op2 = s^0x80 str r8, [src], pstep, lsl #2 ; store *op2 add src, src, pstep eor r10, r10, lr ; *oq2 = s^0x80 str r10, [src], pstep, lsl #1 ; store *oq2 |mbhskip_filter| add src, src, #4 sub src, src, pstep, lsl #3 subs count, count, #1 ldrne r9, [src], pstep ; p3 ldrne r10, [src], pstep ; p2 ldrne r11, [src], pstep ; p1 bne MBHnext8 add sp, sp, #16 ldmia sp!, {r4 - r11, pc} ENDP ; |vp8_mbloop_filter_horizontal_edge_armv6| ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |vp8_loop_filter_vertical_edge_armv6| PROC ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- stmdb sp!, {r4 - r11, lr} sub src, src, #4 ; move src pointer down by 4 ldr count, [sp, #40] ; count for 8-in-parallel ldr r12, [sp, #36] ; load thresh address sub sp, sp, #16 ; create temp buffer ldr r6, [src], pstep ; load source data ldrb r4, [r2] ; blimit ldr r7, [src], pstep ldrb r2, [r3] ; limit ldr r8, [src], pstep orr r4, r4, r4, lsl #8 ldrb r3, [r12] ; thresh orr r2, r2, r2, lsl #8 ldr lr, [src], pstep mov count, count, lsl #1 ; 4-in-parallel orr r4, r4, r4, lsl #16 orr r3, r3, r3, lsl #8 orr r2, r2, r2, lsl #16 orr r3, r3, r3, lsl #16 |Vnext8| ; vp8_filter_mask() function ; calculate breakout conditions ; transpose the source data for 4-in-parallel operation TRANSPOSE_MATRIX r6, r7, r8, lr, r9, r10, r11, r12 uqsub8 r7, r9, r10 ; p3 - p2 uqsub8 r8, r10, r9 ; p2 - p3 uqsub8 r9, r10, r11 ; p2 - p1 uqsub8 r10, r11, r10 ; p1 - p2 orr r7, r7, r8 ; abs (p3-p2) orr r10, r9, r10 ; abs (p2-p1) uqsub8 lr, r7, r2 ; compare to limit. lr: vp8_filter_mask uqsub8 r10, r10, r2 ; compare to limit sub src, src, pstep, lsl #2 ; move src pointer down by 4 lines orr lr, lr, r10 uqsub8 r6, r11, r12 ; p1 - p0 uqsub8 r7, r12, r11 ; p0 - p1 add src, src, #4 ; move src pointer up by 4 orr r6, r6, r7 ; abs (p1-p0) str r11, [sp, #12] ; save p1 uqsub8 r10, r6, r2 ; compare to limit uqsub8 r11, r6, r3 ; compare to thresh orr lr, lr, r10 ; transpose uses 8 regs(r6 - r12 and lr). Need to save reg value now ; transpose the source data for 4-in-parallel operation ldr r6, [src], pstep ; load source data str r11, [sp] ; push r11 to stack ldr r7, [src], pstep str r12, [sp, #4] ; save current reg before load q0 - q3 data ldr r8, [src], pstep str lr, [sp, #8] ldr lr, [src], pstep TRANSPOSE_MATRIX r6, r7, r8, lr, r9, r10, r11, r12 ldr lr, [sp, #8] ; load back (f)limit accumulator uqsub8 r6, r12, r11 ; q3 - q2 uqsub8 r7, r11, r12 ; q2 - q3 uqsub8 r12, r11, r10 ; q2 - q1 uqsub8 r11, r10, r11 ; q1 - q2 orr r6, r6, r7 ; abs (q3-q2) orr r7, r12, r11 ; abs (q2-q1) uqsub8 r6, r6, r2 ; compare to limit uqsub8 r7, r7, r2 ; compare to limit ldr r11, [sp, #4] ; load back p0 ldr r12, [sp, #12] ; load back p1 orr lr, lr, r6 orr lr, lr, r7 uqsub8 r6, r11, r9 ; p0 - q0 uqsub8 r7, r9, r11 ; q0 - p0 uqsub8 r8, r12, r10 ; p1 - q1 uqsub8 r11, r10, r12 ; q1 - p1 orr r6, r6, r7 ; abs (p0-q0) ldr r7, c0x7F7F7F7F orr r8, r8, r11 ; abs (p1-q1) uqadd8 r6, r6, r6 ; abs (p0-q0) * 2 and r8, r7, r8, lsr #1 ; abs (p1-q1) / 2 uqsub8 r11, r10, r9 ; q1 - q0 uqadd8 r6, r8, r6 ; abs (p0-q0)*2 + abs (p1-q1)/2 uqsub8 r12, r9, r10 ; q0 - q1 uqsub8 r6, r6, r4 ; compare to flimit orr r9, r11, r12 ; abs (q1-q0) uqsub8 r8, r9, r2 ; compare to limit uqsub8 r10, r9, r3 ; compare to thresh orr lr, lr, r6 orr lr, lr, r8 mvn r11, #0 ; r11 == -1 mov r12, #0 usub8 lr, r12, lr ldr r9, [sp] ; load the compared result sel lr, r11, r12 ; filter mask: lr cmp lr, #0 beq vskip_filter ; skip filtering ;vp8_hevmask() function ;calculate high edge variance sub src, src, pstep, lsl #2 ; move src pointer down by 4 lines orr r9, r9, r10 ldrh r7, [src, #-2] ldrh r8, [src], pstep usub8 r9, r12, r9 sel r6, r12, r11 ; hev mask: r6 ;vp8_filter() function ; load soure data to r6, r11, r12, lr ldrh r9, [src, #-2] ldrh r10, [src], pstep pkhbt r12, r7, r8, lsl #16 ldrh r7, [src, #-2] ldrh r8, [src], pstep pkhbt r11, r9, r10, lsl #16 ldrh r9, [src, #-2] ldrh r10, [src], pstep ; Transpose needs 8 regs(r6 - r12, and lr). Save r6 and lr first str r6, [sp] str lr, [sp, #4] pkhbt r6, r7, r8, lsl #16 pkhbt lr, r9, r10, lsl #16 ;transpose r12, r11, r6, lr to r7, r8, r9, r10 TRANSPOSE_MATRIX r12, r11, r6, lr, r7, r8, r9, r10 ;load back hev_mask r6 and filter_mask lr ldr r12, c0x80808080 ldr r6, [sp] ldr lr, [sp, #4] eor r7, r7, r12 ; p1 offset to convert to a signed value eor r8, r8, r12 ; p0 offset to convert to a signed value eor r9, r9, r12 ; q0 offset to convert to a signed value eor r10, r10, r12 ; q1 offset to convert to a signed value str r9, [sp] ; store qs0 temporarily str r8, [sp, #4] ; store ps0 temporarily str r10, [sp, #8] ; store qs1 temporarily str r7, [sp, #12] ; store ps1 temporarily qsub8 r7, r7, r10 ; vp8_signed_char_clamp(ps1-qs1) qsub8 r8, r9, r8 ; vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0)) and r7, r7, r6 ; vp8_filter (r7) &= hev (r7 : filter) qadd8 r7, r7, r8 ldr r9, c0x03030303 ; r9 = 3 --modified for vp8 qadd8 r7, r7, r8 ldr r10, c0x04040404 qadd8 r7, r7, r8 ;mvn r11, #0 ; r11 == -1 and r7, r7, lr ; vp8_filter &= mask ;modify code for vp8 -- Filter1 = vp8_filter (r7) qadd8 r8 , r7 , r9 ; Filter2 (r8) = vp8_signed_char_clamp(vp8_filter+3) qadd8 r7 , r7 , r10 ; vp8_filter = vp8_signed_char_clamp(vp8_filter+4) mov r9, #0 shadd8 r8 , r8 , r9 ; Filter2 >>= 3 shadd8 r7 , r7 , r9 ; vp8_filter >>= 3 shadd8 r8 , r8 , r9 shadd8 r7 , r7 , r9 shadd8 lr , r8 , r9 ; lr: filter2 shadd8 r7 , r7 , r9 ; r7: filter ;usub8 lr, r8, r10 ; s = (s==4)*-1 ;sel lr, r11, r9 ;usub8 r8, r10, r8 ;sel r8, r11, r9 ;and r8, r8, lr ; -1 for each element that equals 4 -- r8: s ;calculate output ;qadd8 lr, r8, r7 ; u = vp8_signed_char_clamp(s + vp8_filter) ldr r8, [sp] ; load qs0 ldr r9, [sp, #4] ; load ps0 ldr r10, c0x01010101 qsub8 r8, r8, r7 ; u = vp8_signed_char_clamp(qs0 - vp8_filter) qadd8 r9, r9, lr ; u = vp8_signed_char_clamp(ps0 + Filter2) ;end of modification for vp8 eor r8, r8, r12 eor r9, r9, r12 mov lr, #0 sadd8 r7, r7, r10 shadd8 r7, r7, lr ldr r10, [sp, #8] ; load qs1 ldr r11, [sp, #12] ; load ps1 bic r7, r7, r6 ; r7: vp8_filter qsub8 r10 , r10, r7 ; u = vp8_signed_char_clamp(qs1 - vp8_filter) qadd8 r11, r11, r7 ; u = vp8_signed_char_clamp(ps1 + vp8_filter) eor r10, r10, r12 eor r11, r11, r12 sub src, src, pstep, lsl #2 ;we can use TRANSPOSE_MATRIX macro to transpose output - input: q1, q0, p0, p1 ;output is b0, b1, b2, b3 ;b0: 03 02 01 00 ;b1: 13 12 11 10 ;b2: 23 22 21 20 ;b3: 33 32 31 30 ; p1 p0 q0 q1 ; (a3 a2 a1 a0) TRANSPOSE_MATRIX r11, r9, r8, r10, r6, r7, r12, lr strh r6, [src, #-2] ; store the result mov r6, r6, lsr #16 strh r6, [src], pstep strh r7, [src, #-2] mov r7, r7, lsr #16 strh r7, [src], pstep strh r12, [src, #-2] mov r12, r12, lsr #16 strh r12, [src], pstep strh lr, [src, #-2] mov lr, lr, lsr #16 strh lr, [src], pstep |vskip_filter| sub src, src, #4 subs count, count, #1 ldrne r6, [src], pstep ; load source data ldrne r7, [src], pstep ldrne r8, [src], pstep ldrne lr, [src], pstep bne Vnext8 add sp, sp, #16 ldmia sp!, {r4 - r11, pc} ENDP ; |vp8_loop_filter_vertical_edge_armv6| ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |vp8_mbloop_filter_vertical_edge_armv6| PROC ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- stmdb sp!, {r4 - r11, lr} sub src, src, #4 ; move src pointer down by 4 ldr count, [sp, #40] ; count for 8-in-parallel ldr r12, [sp, #36] ; load thresh address pld [src, #23] ; preload for next block sub sp, sp, #16 ; create temp buffer ldr r6, [src], pstep ; load source data ldrb r4, [r2] ; blimit pld [src, #23] ldr r7, [src], pstep ldrb r2, [r3] ; limit pld [src, #23] ldr r8, [src], pstep orr r4, r4, r4, lsl #8 ldrb r3, [r12] ; thresh orr r2, r2, r2, lsl #8 pld [src, #23] ldr lr, [src], pstep mov count, count, lsl #1 ; 4-in-parallel orr r4, r4, r4, lsl #16 orr r3, r3, r3, lsl #8 orr r2, r2, r2, lsl #16 orr r3, r3, r3, lsl #16 |MBVnext8| ; vp8_filter_mask() function ; calculate breakout conditions ; transpose the source data for 4-in-parallel operation TRANSPOSE_MATRIX r6, r7, r8, lr, r9, r10, r11, r12 uqsub8 r7, r9, r10 ; p3 - p2 uqsub8 r8, r10, r9 ; p2 - p3 uqsub8 r9, r10, r11 ; p2 - p1 uqsub8 r10, r11, r10 ; p1 - p2 orr r7, r7, r8 ; abs (p3-p2) orr r10, r9, r10 ; abs (p2-p1) uqsub8 lr, r7, r2 ; compare to limit. lr: vp8_filter_mask uqsub8 r10, r10, r2 ; compare to limit sub src, src, pstep, lsl #2 ; move src pointer down by 4 lines orr lr, lr, r10 uqsub8 r6, r11, r12 ; p1 - p0 uqsub8 r7, r12, r11 ; p0 - p1 add src, src, #4 ; move src pointer up by 4 orr r6, r6, r7 ; abs (p1-p0) str r11, [sp, #12] ; save p1 uqsub8 r10, r6, r2 ; compare to limit uqsub8 r11, r6, r3 ; compare to thresh orr lr, lr, r10 ; transpose uses 8 regs(r6 - r12 and lr). Need to save reg value now ; transpose the source data for 4-in-parallel operation ldr r6, [src], pstep ; load source data str r11, [sp] ; push r11 to stack ldr r7, [src], pstep str r12, [sp, #4] ; save current reg before load q0 - q3 data ldr r8, [src], pstep str lr, [sp, #8] ldr lr, [src], pstep TRANSPOSE_MATRIX r6, r7, r8, lr, r9, r10, r11, r12 ldr lr, [sp, #8] ; load back (f)limit accumulator uqsub8 r6, r12, r11 ; q3 - q2 uqsub8 r7, r11, r12 ; q2 - q3 uqsub8 r12, r11, r10 ; q2 - q1 uqsub8 r11, r10, r11 ; q1 - q2 orr r6, r6, r7 ; abs (q3-q2) orr r7, r12, r11 ; abs (q2-q1) uqsub8 r6, r6, r2 ; compare to limit uqsub8 r7, r7, r2 ; compare to limit ldr r11, [sp, #4] ; load back p0 ldr r12, [sp, #12] ; load back p1 orr lr, lr, r6 orr lr, lr, r7 uqsub8 r6, r11, r9 ; p0 - q0 uqsub8 r7, r9, r11 ; q0 - p0 uqsub8 r8, r12, r10 ; p1 - q1 uqsub8 r11, r10, r12 ; q1 - p1 orr r6, r6, r7 ; abs (p0-q0) ldr r7, c0x7F7F7F7F orr r8, r8, r11 ; abs (p1-q1) uqadd8 r6, r6, r6 ; abs (p0-q0) * 2 and r8, r7, r8, lsr #1 ; abs (p1-q1) / 2 uqsub8 r11, r10, r9 ; q1 - q0 uqadd8 r6, r8, r6 ; abs (p0-q0)*2 + abs (p1-q1)/2 uqsub8 r12, r9, r10 ; q0 - q1 uqsub8 r6, r6, r4 ; compare to flimit orr r9, r11, r12 ; abs (q1-q0) uqsub8 r8, r9, r2 ; compare to limit uqsub8 r10, r9, r3 ; compare to thresh orr lr, lr, r6 orr lr, lr, r8 mvn r11, #0 ; r11 == -1 mov r12, #0 usub8 lr, r12, lr ldr r9, [sp] ; load the compared result sel lr, r11, r12 ; filter mask: lr cmp lr, #0 beq mbvskip_filter ; skip filtering ;vp8_hevmask() function ;calculate high edge variance sub src, src, pstep, lsl #2 ; move src pointer down by 4 lines orr r9, r9, r10 ldrh r7, [src, #-2] ldrh r8, [src], pstep usub8 r9, r12, r9 sel r6, r12, r11 ; hev mask: r6 ; vp8_mbfilter() function ; p2, q2 are only needed at the end. Don't need to load them in now. ; Transpose needs 8 regs(r6 - r12, and lr). Save r6 and lr first ; load soure data to r6, r11, r12, lr ldrh r9, [src, #-2] ldrh r10, [src], pstep pkhbt r12, r7, r8, lsl #16 ldrh r7, [src, #-2] ldrh r8, [src], pstep pkhbt r11, r9, r10, lsl #16 ldrh r9, [src, #-2] ldrh r10, [src], pstep str r6, [sp] ; save r6 str lr, [sp, #4] ; save lr pkhbt r6, r7, r8, lsl #16 pkhbt lr, r9, r10, lsl #16 ;transpose r12, r11, r6, lr to p1, p0, q0, q1 TRANSPOSE_MATRIX r12, r11, r6, lr, r7, r8, r9, r10 ;load back hev_mask r6 and filter_mask lr ldr r12, c0x80808080 ldr r6, [sp] ldr lr, [sp, #4] eor r7, r7, r12 ; ps1 eor r8, r8, r12 ; ps0 eor r9, r9, r12 ; qs0 eor r10, r10, r12 ; qs1 qsub8 r12, r9, r8 ; vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0)) str r7, [sp, #12] ; store ps1 temporarily qsub8 r7, r7, r10 ; vp8_signed_char_clamp(ps1-qs1) str r10, [sp, #8] ; store qs1 temporarily qadd8 r7, r7, r12 str r9, [sp] ; store qs0 temporarily qadd8 r7, r7, r12 str r8, [sp, #4] ; store ps0 temporarily qadd8 r7, r7, r12 ; vp8_filter: r7 ldr r10, c0x03030303 ; r10 = 3 --modified for vp8 ldr r9, c0x04040404 ;mvn r11, #0 ; r11 == -1 and r7, r7, lr ; vp8_filter &= mask (lr is free) mov r12, r7 ; Filter2: r12 and r12, r12, r6 ; Filter2 &= hev ;modify code for vp8 ;save bottom 3 bits so that we round one side +4 and the other +3 qadd8 r8 , r12 , r9 ; Filter1 (r8) = vp8_signed_char_clamp(Filter2+4) qadd8 r12 , r12 , r10 ; Filter2 (r12) = vp8_signed_char_clamp(Filter2+3) mov r10, #0 shadd8 r8 , r8 , r10 ; Filter1 >>= 3 shadd8 r12 , r12 , r10 ; Filter2 >>= 3 shadd8 r8 , r8 , r10 shadd8 r12 , r12 , r10 shadd8 r8 , r8 , r10 ; r8: Filter1 shadd8 r12 , r12 , r10 ; r12: Filter2 ldr r9, [sp] ; load qs0 ldr r11, [sp, #4] ; load ps0 qsub8 r9 , r9, r8 ; qs0 = vp8_signed_char_clamp(qs0 - Filter1) qadd8 r11, r11, r12 ; ps0 = vp8_signed_char_clamp(ps0 + Filter2) ;save bottom 3 bits so that we round one side +4 and the other +3 ;and r8, r12, r10 ; s = Filter2 & 7 (s: r8) ;qadd8 r12 , r12 , r9 ; Filter2 = vp8_signed_char_clamp(Filter2+4) ;mov r10, #0 ;shadd8 r12 , r12 , r10 ; Filter2 >>= 3 ;usub8 lr, r8, r9 ; s = (s==4)*-1 ;sel lr, r11, r10 ;shadd8 r12 , r12 , r10 ;usub8 r8, r9, r8 ;sel r8, r11, r10 ;ldr r9, [sp] ; load qs0 ;ldr r11, [sp, #4] ; load ps0 ;shadd8 r12 , r12 , r10 ;and r8, r8, lr ; -1 for each element that equals 4 ;qadd8 r10, r8, r12 ; u = vp8_signed_char_clamp(s + Filter2) ;qsub8 r9 , r9, r12 ; qs0 = vp8_signed_char_clamp(qs0 - Filter2) ;qadd8 r11, r11, r10 ; ps0 = vp8_signed_char_clamp(ps0 + u) ;end of modification for vp8 bic r12, r7, r6 ;vp8_filter &= ~hev ( r6 is free) ;mov r12, r7 ;roughly 3/7th difference across boundary mov lr, #0x1b ; 27 mov r7, #0x3f ; 63 sxtb16 r6, r12 sxtb16 r10, r12, ror #8 smlabb r8, r6, lr, r7 smlatb r6, r6, lr, r7 smlabb r7, r10, lr, r7 smultb r10, r10, lr ssat r8, #8, r8, asr #7 ssat r6, #8, r6, asr #7 add r10, r10, #63 ssat r7, #8, r7, asr #7 ssat r10, #8, r10, asr #7 ldr lr, c0x80808080 pkhbt r6, r8, r6, lsl #16 pkhbt r10, r7, r10, lsl #16 uxtb16 r6, r6 uxtb16 r10, r10 sub src, src, pstep, lsl #2 ; move src pointer down by 4 lines orr r10, r6, r10, lsl #8 ; u = vp8_signed_char_clamp((63 + Filter2 * 27)>>7) qsub8 r8, r9, r10 ; s = vp8_signed_char_clamp(qs0 - u) qadd8 r10, r11, r10 ; s = vp8_signed_char_clamp(ps0 + u) eor r8, r8, lr ; *oq0 = s^0x80 eor r10, r10, lr ; *op0 = s^0x80 strb r10, [src, #-1] ; store op0 result strb r8, [src], pstep ; store oq0 result mov r10, r10, lsr #8 mov r8, r8, lsr #8 strb r10, [src, #-1] strb r8, [src], pstep mov r10, r10, lsr #8 mov r8, r8, lsr #8 strb r10, [src, #-1] strb r8, [src], pstep mov r10, r10, lsr #8 mov r8, r8, lsr #8 strb r10, [src, #-1] strb r8, [src], pstep ;roughly 2/7th difference across boundary mov lr, #0x12 ; 18 mov r7, #0x3f ; 63 sxtb16 r6, r12 sxtb16 r10, r12, ror #8 smlabb r8, r6, lr, r7 smlatb r6, r6, lr, r7 smlabb r9, r10, lr, r7 smlatb r10, r10, lr, r7 ssat r8, #8, r8, asr #7 ssat r6, #8, r6, asr #7 ssat r9, #8, r9, asr #7 ssat r10, #8, r10, asr #7 sub src, src, pstep, lsl #2 ; move src pointer down by 4 lines pkhbt r6, r8, r6, lsl #16 pkhbt r10, r9, r10, lsl #16 ldr r9, [sp, #8] ; load qs1 ldr r11, [sp, #12] ; load ps1 ldr lr, c0x80808080 uxtb16 r6, r6 uxtb16 r10, r10 add src, src, #2 orr r10, r6, r10, lsl #8 ; u = vp8_signed_char_clamp((63 + Filter2 * 18)>>7) qsub8 r8, r9, r10 ; s = vp8_signed_char_clamp(qs1 - u) qadd8 r10, r11, r10 ; s = vp8_signed_char_clamp(ps1 + u) eor r8, r8, lr ; *oq1 = s^0x80 eor r10, r10, lr ; *op1 = s^0x80 ldrb r11, [src, #-5] ; load p2 for 1/7th difference across boundary strb r10, [src, #-4] ; store op1 strb r8, [src, #-1] ; store oq1 ldrb r9, [src], pstep ; load q2 for 1/7th difference across boundary mov r10, r10, lsr #8 mov r8, r8, lsr #8 ldrb r6, [src, #-5] strb r10, [src, #-4] strb r8, [src, #-1] ldrb r7, [src], pstep mov r10, r10, lsr #8 mov r8, r8, lsr #8 orr r11, r11, r6, lsl #8 orr r9, r9, r7, lsl #8 ldrb r6, [src, #-5] strb r10, [src, #-4] strb r8, [src, #-1] ldrb r7, [src], pstep mov r10, r10, lsr #8 mov r8, r8, lsr #8 orr r11, r11, r6, lsl #16 orr r9, r9, r7, lsl #16 ldrb r6, [src, #-5] strb r10, [src, #-4] strb r8, [src, #-1] ldrb r7, [src], pstep orr r11, r11, r6, lsl #24 orr r9, r9, r7, lsl #24 ;roughly 1/7th difference across boundary eor r9, r9, lr eor r11, r11, lr mov lr, #0x9 ; 9 mov r7, #0x3f ; 63 sxtb16 r6, r12 sxtb16 r10, r12, ror #8 smlabb r8, r6, lr, r7 smlatb r6, r6, lr, r7 smlabb r12, r10, lr, r7 smlatb r10, r10, lr, r7 ssat r8, #8, r8, asr #7 ssat r6, #8, r6, asr #7 ssat r12, #8, r12, asr #7 ssat r10, #8, r10, asr #7 sub src, src, pstep, lsl #2 pkhbt r6, r8, r6, lsl #16 pkhbt r10, r12, r10, lsl #16 uxtb16 r6, r6 uxtb16 r10, r10 ldr lr, c0x80808080 orr r10, r6, r10, lsl #8 ; u = vp8_signed_char_clamp((63 + Filter2 * 9)>>7) qadd8 r8, r11, r10 ; s = vp8_signed_char_clamp(ps2 + u) qsub8 r10, r9, r10 ; s = vp8_signed_char_clamp(qs2 - u) eor r8, r8, lr ; *op2 = s^0x80 eor r10, r10, lr ; *oq2 = s^0x80 strb r8, [src, #-5] ; store *op2 strb r10, [src], pstep ; store *oq2 mov r8, r8, lsr #8 mov r10, r10, lsr #8 strb r8, [src, #-5] strb r10, [src], pstep mov r8, r8, lsr #8 mov r10, r10, lsr #8 strb r8, [src, #-5] strb r10, [src], pstep mov r8, r8, lsr #8 mov r10, r10, lsr #8 strb r8, [src, #-5] strb r10, [src], pstep ;adjust src pointer for next loop sub src, src, #2 |mbvskip_filter| sub src, src, #4 subs count, count, #1 pld [src, #23] ; preload for next block ldrne r6, [src], pstep ; load source data pld [src, #23] ldrne r7, [src], pstep pld [src, #23] ldrne r8, [src], pstep pld [src, #23] ldrne lr, [src], pstep bne MBVnext8 add sp, sp, #16 ldmia sp!, {r4 - r11, pc} ENDP ; |vp8_mbloop_filter_vertical_edge_armv6| ; Constant Pool c0x80808080 DCD 0x80808080 c0x03030303 DCD 0x03030303 c0x04040404 DCD 0x04040404 c0x01010101 DCD 0x01010101 c0x7F7F7F7F DCD 0x7F7F7F7F END
; uchar __FASTCALL__ *zx_aaddrcright(void *attraddr) ; aralbrec 06.2007 PUBLIC zx_aaddrcright .zx_aaddrcright ; hl = valid attribute address ; hl = new attribute address right one character with line wrap ; carry if off screen inc hl ld a,$5a cp h ret
; A285184: a(n) = 2*a(n-1) + a(n-3) with initial terms 1,3,5. ; 1,3,5,11,25,55,121,267,589,1299,2865,6319,13937,30739,67797,149531,329801,727399,1604329,3538459,7804317,17212963,37964385,83733087,184679137,407322659,898378405,1981435947,4370194553,9638767511,21258970969,46888136491,103415040493,228089051955,503066240401,1109547521295,2447184094545,5397434429491,11904416380277,26256016855099,57909468139689,127723352659655,281702722174409,621314912488507,1370353177636669,3022409077447747,6666133067384001 sub $0,2 mov $1,$0 lpb $0 mov $2,$0 cal $2,193641 ; Number of arrays of -1..1 integers x(1..n) with every x(i) in a subsequence of length 1 or 2 with sum zero. sub $0,1 add $1,$2 sub $1,1 lpe add $1,2 mul $1,2 add $1,1
// Copyright (c) 2016 The Zcash developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "zcash/JoinSplit.hpp" #include <iostream> #include "crypto/common.h" int main(int argc, char **argv) { if (init_and_check_sodium() == -1) { return 1; } if(argc != 4) { std::cerr << "Usage: " << argv[0] << " provingKeyFileName verificationKeyFileName r1csFileName" << std::endl; return 1; } std::string pkFile = argv[1]; std::string vkFile = argv[2]; std::string r1csFile = argv[3]; ZCJoinSplit::Generate(r1csFile, vkFile, pkFile); return 0; }
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Copyright (C) 2022 Intel Corporation ; ; SPDX-License-Identifier: MIT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %ifndef STDMAC_ASM %define STDMAC_ASM ;; internal macro used by push_all ;; push args L to R %macro push_all_ 1-* %xdefine _PUSH_ALL_REGS_COUNT_ %0 %rep %0 push %1 %rotate 1 %endrep %endmacro ;; internal macro used by pop_all ;; pop args R to L %macro pop_all_ 1-* %rep %0 %rotate -1 pop %1 %endrep %endmacro %xdefine _PUSH_ALL_REGS_COUNT_ 0 %xdefine _ALLOC_STACK_VAL_ 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; STACK_OFFSET ;; Number of bytes subtracted from stack due to PUSH_ALL and ALLOC_STACK ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %define STACK_OFFSET (_PUSH_ALL_REGS_COUNT_ * 8 + _ALLOC_STACK_VAL_) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; PUSH_ALL reg1, reg2, ... ;; push args L to R, remember regs for pop_all ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %macro PUSH_ALL 1+ %xdefine _PUSH_ALL_REGS_ %1 push_all_ %1 %endmacro ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; POP_ALL ;; push args from prev "push_all" R to L ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %macro POP_ALL 0 pop_all_ _PUSH_ALL_REGS_ %xdefine _PUSH_ALL_REGS_COUNT_ 0 %endmacro ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ALLOC_STACK n ;; subtract n from the stack pointer and remember the value for restore_stack ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %macro ALLOC_STACK 1 %xdefine _ALLOC_STACK_VAL_ %1 sub rsp, %1 %endmacro ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; RESTORE_STACK ;; add n to the stack pointer, where n is the arg to the previous alloc_stack ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %macro RESTORE_STACK 0 add rsp, _ALLOC_STACK_VAL_ %xdefine _ALLOC_STACK_VAL_ 0 %endmacro ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; NOPN n ;; Create n bytes of NOP, using nops of up to 8 bytes each ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %macro NOPN 1 %assign %%i %1 %rep 200 %if (%%i < 9) nopn %%i %exitrep %else nopn 8 %assign %%i (%%i - 8) %endif %endrep %endmacro ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; nopn n ;; Create n bytes of NOP, where n is between 1 and 9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %macro nopn 1 %if (%1 == 1) nop %elif (%1 == 2) db 0x66 nop %elif (%1 == 3) db 0x0F db 0x1F db 0x00 %elif (%1 == 4) db 0x0F db 0x1F db 0x40 db 0x00 %elif (%1 == 5) db 0x0F db 0x1F db 0x44 db 0x00 db 0x00 %elif (%1 == 6) db 0x66 db 0x0F db 0x1F db 0x44 db 0x00 db 0x00 %elif (%1 == 7) db 0x0F db 0x1F db 0x80 db 0x00 db 0x00 db 0x00 db 0x00 %elif (%1 == 8) db 0x0F db 0x1F db 0x84 db 0x00 db 0x00 db 0x00 db 0x00 db 0x00 %elif (%1 == 9) db 0x66 db 0x0F db 0x1F db 0x84 db 0x00 db 0x00 db 0x00 db 0x00 db 0x00 %else %error Invalid value to nopn %endif %endmacro ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; rolx64 dst, src, amount ;; Emulate a rolx instruction using rorx, assuming data 64 bits wide ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %macro rolx64 3 rorx %1, %2, (64-%3) %endm ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; rolx32 dst, src, amount ;; Emulate a rolx instruction using rorx, assuming data 32 bits wide ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %macro rolx32 3 rorx %1, %2, (32-%3) %endm ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Define a function void ssc(uint64_t x) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %macro DEF_SSC 0 global ssc ssc: mov rax, rbx mov rbx, rcx db 0x64 db 0x67 nop mov rbx, rax ret %endm %macro MOVDQU 2 %define %%dest %1 %define %%src %2 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04)) vmovdqu %%dest, %%src %else movdqu %%dest, %%src %endif %endm %macro MOVDQA 2 %define %%dest %1 %define %%src %2 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04)) vmovdqa %%dest, %%src %else movdqa %%dest, %%src %endif %endm %macro MOVD 2 %define %%dest %1 %define %%src %2 %if (ARCH == 02 || ARCH == 03 || ARCH == 04) vmovd %%dest, %%src %else movd %%dest, %%src %endif %endm %macro MOVQ 2 %define %%dest %1 %define %%src %2 %if (ARCH == 02 || ARCH == 03 || ARCH == 04) vmovq %%dest, %%src %else movq %%dest, %%src %endif %endm ;; Move register if the src and dest are not equal %macro MOVNIDN 2 %define dest %1 %define src %2 %ifnidn dest, src mov dest, src %endif %endm %macro MOVDQANIDN 2 %define dest %1 %define src %2 %ifnidn dest, src MOVDQA dest, src %endif %endm %macro PSHUFD 3 %define %%dest %1 %define %%src1 %2 %define %%imm8 %3 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04)) vpshufd %%dest, %%src1, %%imm8 %else pshufd %%dest, %%src1, %%imm8 %endif %endm %macro PSHUFB 3 %define %%dest %1 %define %%src1 %2 %define %%shuf %3 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04)) vpshufb %%dest, %%src1, %%shuf %else MOVDQANIDN %%dest, %%src1 pshufb %%dest, %%shuf %endif %endm %macro PBROADCASTD 2 %define %%dest %1 %define %%src %2 %if (ARCH == 04) vpbroadcastd %%dest, %%src %else MOVD %%dest, %%src PSHUFD %%dest, %%dest, 0 %endif %endm ;; Implement BZHI instruction on older architectures ;; Clobbers rcx, unless rcx is %%index %macro BZHI 4 %define %%dest %1 %define %%src %2 %define %%index %3 %define %%tmp1 %4 %ifdef USE_HSWNI bzhi %%dest, %%src, %%index %else MOVNIDN rcx, %%index mov %%tmp1, 1 shl %%tmp1, cl sub %%tmp1, 1 MOVNIDN %%dest, %%src and %%dest, %%tmp1 %endif %endm ;; Implement shrx instruction on older architectures ;; Clobbers rcx, unless rcx is %%index %macro SHRX 3 %define %%dest %1 %define %%src %2 %define %%index %3 %ifdef USE_HSWNI shrx %%dest, %%src, %%index %else MOVNIDN rcx, %%index MOVNIDN %%dest, %%src shr %%dest, cl %endif %endm ;; Implement shlx instruction on older architectures ;; Clobbers rcx, unless rcx is %%index %macro SHLX 3 %define %%dest %1 %define %%src %2 %define %%index %3 %ifdef USE_HSWNI shlx %%dest, %%src, %%index %else MOVNIDN %%dest, %%src MOVNIDN rcx, %%index shl %%dest, cl %endif %endm %macro PINSRD 3 %define %%dest %1 %define %%src %2 %define %%offset %3 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04)) vpinsrd %%dest, %%src, %%offset %else pinsrd %%dest, %%src, %%offset %endif %endm %macro PEXTRD 3 %define %%dest %1 %define %%src %2 %define %%offset %3 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04)) vpextrd %%dest, %%src, %%offset %else pextrd %%dest, %%src, %%offset %endif %endm %macro PSRLDQ 2 %define %%dest %1 %define %%offset %2 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04)) vpsrldq %%dest, %%offset %else psrldq %%dest, %%offset %endif %endm %macro PSLLD 3 %define %%dest %1 %define %%src %2 %define %%offset %3 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04)) vpslld %%dest, %%src, %%offset %else MOVDQANIDN %%dest, %%src pslld %%dest, %%offset %endif %endm %macro PAND 3 %define %%dest %1 %define %%src1 %2 %define %%src2 %3 %if (ARCH == 02 || ARCH == 03 || ARCH == 04) vpand %%dest, %%src1, %%src2 %else MOVDQANIDN %%dest, %%src1 pand %%dest, %%src2 %endif %endm %macro POR 3 %define %%dest %1 %define %%src1 %2 %define %%src2 %3 %if (ARCH == 02 || ARCH == 03 || ARCH == 04) vpor %%dest, %%src1, %%src2 %else MOVDQANIDN %%dest, %%src1 por %%dest, %%src2 %endif %endm %macro PXOR 3 %define %%dest %1 %define %%src1 %2 %define %%src2 %3 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04)) vpxor %%dest, %%src1, %%src2 %else MOVDQANIDN %%dest, %%src1 pxor %%dest, %%src2 %endif %endm %macro PADDD 3 %define %%dest %1 %define %%src1 %2 %define %%src2 %3 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04)) vpaddd %%dest, %%src1, %%src2 %else MOVDQANIDN %%dest, %%src1 paddd %%dest, %%src2 %endif %endm %macro PCMPEQB 3 %define %%dest %1 %define %%src1 %2 %define %%src2 %3 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04)) vpcmpeqb %%dest, %%src1, %%src2 %else MOVDQANIDN %%dest, %%src1 pcmpeqb %%dest, %%src2 %endif %endm %macro PMOVMSKB 2 %define %%dest %1 %define %%src %2 %if ((ARCH == 02) || (ARCH == 03) || (ARCH == 04)) vpmovmskb %%dest, %%src %else pmovmskb %%dest, %%src %endif %endm %endif ;; ifndef STDMAC_ASM
; A008346: a(n) = Fibonacci(n) + (-1)^n. ; 1,0,2,1,4,4,9,12,22,33,56,88,145,232,378,609,988,1596,2585,4180,6766,10945,17712,28656,46369,75024,121394,196417,317812,514228,832041,1346268,2178310,3524577,5702888,9227464,14930353,24157816,39088170,63245985,102334156,165580140,267914297,433494436,701408734,1134903169,1836311904,2971215072,4807526977,7778742048,12586269026,20365011073,32951280100,53316291172,86267571273,139583862444,225851433718,365435296161,591286729880,956722026040,1548008755921,2504730781960,4052739537882,6557470319841 mov $2,$0 seq $0,45 ; Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1. mul $2,2 mod $2,4 sub $0,$2 add $0,1
B8_Header: sHeaderInit ; Z80 offset is $D7A4 sHeaderPatch B8_Patches sHeaderTick $01 sHeaderCh $01 sHeaderSFX $80, $05, B8_FM5, $F0, $00 B8_FM5: sPatFM $00 ssModZ80 $01, $01, $F7, $EA B8_Loop1: dc.b nAb5, $02, $03, nRst, $02 saVolFM $06 sLoop $00, $0E, B8_Loop1 sStop B8_Patches: ; Patch $00 ; $45 ; $3F, $4F, $FF, $4F, $18, $18, $17, $10 ; $00, $00, $02, $06, $0B, $1C, $18, $1D ; $10, $1B, $1B, $02, $37, $80, $80, $80 spAlgorithm $05 spFeedback $00 spDetune $03, $0F, $04, $04 spMultiple $0F, $0F, $0F, $0F spRateScale $00, $00, $00, $00 spAttackRt $18, $17, $18, $10 spAmpMod $00, $00, $00, $00 spSustainRt $00, $02, $00, $06 spSustainLv $01, $01, $01, $00 spDecayRt $0B, $18, $1C, $1D spReleaseRt $00, $0B, $0B, $02 spTotalLv $37, $00, $00, $00
; constants.asm ; Application CoreMinVersion equ $3007 ; 3.00.07 DotBank1: equ 30 ResetWait equ 5 DisableScroll equ false //NGetServer equ "192.168.1.3" NGetServer equ "nget.nxtel.org" ; NextZXOS IDE_BANK equ $01BD ; UART UART_RxD equ $143B ; Also used to set the baudrate UART_TxD equ $133B ; Also reads status UART_SetBaud equ UART_RxD ; Sets baudrate UART_GetStatus equ UART_TxD ; Reads status bits UART_mRX_DATA_READY equ %xxxxx 0 0 1 ; Status bit masks UART_mTX_BUSY equ %xxxxx 0 1 0 ; Status bit masks UART_mRX_FIFO_FULL equ %xxxxx 1 0 0 ; Status bit masks IPDBuffer equ $C000 ; IPD buffer lives in two banks allocated IPDBufferLen equ $4000 ; by BANK_IDE, from $C000 to $FFFF. ; ESP ESPTimeout equ 65535*4;65535 ; Use 10000 for 3.5MHz, but 28NHz needs to be 65535 ESPTimeout2 equ 10000 ; Use 10000 for 3.5MHz, but 28NHz needs to be 65535 ESPTimeoutFrames equ 1000 ; Wait 20 seconds ; Ports Port proc NextReg equ $243B pend ; Registers Reg proc MachineID equ $00 Peripheral2 equ $06 CPUSpeed equ $07 CoreMSB equ $01 CoreLSB equ $0E pend ; Chars SMC equ 0 CR equ 13 LF equ 10 Space equ 32 Copyright equ 127 ; ROM Calls BC_SPACES equ $0030 ; Reserve BC bytes, rets DE addr first byte, HL addr last byte ROMSM equ $16B0 ; (SET-MIN, like BC_SPACES but clears) ; Screen SCREEN equ $4000 ; Start of screen bitmap ATTRS_8x8 equ $5800 ; Start of 8x8 attributes ATTRS_8x8_END equ $5B00 ; End of 8x8 attributes ATTRS_8x8_COUNT equ ATTRS_8x8_END-ATTRS_8x8 ; 768 SCREEN_LEN equ ATTRS_8x8_END-SCREEN PIXELS_COUNT equ ATTRS_8x8-SCREEN FRAMES equ 23672 ; Frame counter BORDCR equ 23624 ; Border colour system variable ULA_PORT equ $FE ; out (254), a STIMEOUT equ $5C81 ; Screensaver control sysvar SCR_CT equ $5C8C ; Scroll counter sysvar ; Font FWSpace equ 2 FWColon equ 4 FWFullStop equ 3 FW0 equ 4 FW1 equ 4 FW2 equ 4 FW3 equ 4 FW4 equ 4 FW5 equ 4 FW6 equ 4 FW7 equ 4 FW8 equ 4 FW9 equ 4 FWA equ 4 FWB equ 4 FWC equ 4 FWD equ 4 FWE equ 4 FWF equ 4 FWG equ 4 FWH equ 4 FWI equ 4 FWJ equ 4 FWK equ 4 FWL equ 4 FWM equ 6 FWN equ 4 FWO equ 4 FWP equ 4 FWQ equ 4 FWR equ 4 FWS equ 4 FWT equ 4 FWU equ 4 FWV equ 4 FWW equ 6 FWX equ 4 FWY equ 4 FWZ equ 4 FWa equ 4 FWb equ 4 FWc equ 4 FWd equ 4 FWe equ 4 FWf equ 4 FWg equ 4 FWh equ 4 FWi equ 4 FWj equ 4 FWk equ 4 FWl equ 4 FWm equ 6 FWn equ 4 FWo equ 4 FWp equ 4 FWq equ 4 FWr equ 4 FWs equ 4 FWt equ 4 FWu equ 4 FWv equ 4 FWw equ 6 FWx equ 4 FWy equ 4 FWz equ 4 VersionPrefix equ "1."
.size 8000 .text@48 jp lstatint .text@100 jp lbegin .data@143 c0 .text@150 lbegin: ld a, 00 ldff(ff), a ld a, 30 ldff(00), a ld a, 01 ldff(4d), a stop, 00 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 ld a, 03 ldff(43), a ei .text@1000 lstatint: nop .text@1077 ldff a, (c) and a, b jp lprint_a .text@7000 lprint_a: push af ld b, 91 call lwaitly_b xor a, a ldff(40), a pop af ld(9800), a ld bc, 7a00 ld hl, 8000 ld d, a0 lprint_copytiles: ld a, (bc) inc bc ld(hl++), a dec d jrnz lprint_copytiles ld a, c0 ldff(47), a ld a, 80 ldff(68), a ld a, ff ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a xor a, a ldff(69), a ldff(69), a ldff(43), a ld a, 91 ldff(40), a lprint_limbo: jr lprint_limbo .text@7400 lwaitly_b: ld c, 44 lwaitly_b_loop: ldff a, (c) cmp a, b jrnz lwaitly_b_loop ret .data@7a00 00 00 7f 7f 41 41 41 41 41 41 41 41 41 41 7f 7f 00 00 08 08 08 08 08 08 08 08 08 08 08 08 08 08 00 00 7f 7f 01 01 01 01 7f 7f 40 40 40 40 7f 7f 00 00 7f 7f 01 01 01 01 3f 3f 01 01 01 01 7f 7f 00 00 41 41 41 41 41 41 7f 7f 01 01 01 01 01 01 00 00 7f 7f 40 40 40 40 7e 7e 01 01 01 01 7e 7e 00 00 7f 7f 40 40 40 40 7f 7f 41 41 41 41 7f 7f 00 00 7f 7f 01 01 02 02 04 04 08 08 10 10 10 10 00 00 3e 3e 41 41 41 41 3e 3e 41 41 41 41 3e 3e 00 00 7f 7f 41 41 41 41 7f 7f 01 01 01 01 7f 7f
; A120145: a(1)=20; a(n)=floor((41+sum(a(1) to a(n-1)))/2). ; 20,30,45,68,102,153,229,344,516,774,1161,1741,2612,3918,5877,8815,13223,19834,29751,44627,66940,100410,150615,225923,338884,508326,762489,1143734,1715601,2573401,3860102,5790153,8685229,13027844 add $0,1 lpb $0 sub $0,1 add $2,$1 mov $1,11 add $1,$2 div $1,2 add $2,15 lpe add $1,15 mov $0,$1
Name: ys_w41.asm Type: file Size: 19785 Last-Modified: '2016-05-13T04:50:34Z' SHA-1: 968CBC06B8162D22563F75200EF24C264FDE2109 Description: null
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1991 -- All Rights Reserved PROJECT: PC GEOS MODULE: FILE: uiDuplicateControl.asm AUTHOR: Jon Witort REVISION HISTORY: Name Date Description ---- ---- ----------- jon 24 feb 1992 Initial version. DESCRIPTION: Code for the GrObjDuplicateControlClass $Id: uiDuplicateControl.asm,v 1.1 97/04/04 18:06:31 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjUIControllerCode segment resource COMMENT @---------------------------------------------------------------------- MESSAGE: GrObjDuplicateControlGetInfo -- MSG_GEN_CONTROL_GET_INFO for GrObjDuplicateControlClass DESCRIPTION: Return group PASS: *ds:si - instance data es - segment of GrObjDuplicateControlClass ax - The message cx:dx - GenControlBuildInfo structure to fill in RETURN: none DESTROYED: bx, si, di, ds, es (message handler) REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- Tony 10/31/91 Initial version ------------------------------------------------------------------------------@ GrObjDuplicateControlGetInfo method dynamic GrObjDuplicateControlClass, MSG_GEN_CONTROL_GET_INFO mov si, offset GrObjDuplicateControl_dupInfo call CopyDupInfoCommon ret GrObjDuplicateControlGetInfo endm GrObjDuplicateControl_dupInfo GenControlBuildInfo < mask GCBF_SUSPEND_ON_APPLY, ; GCBI_flags GrObjDuplicateControl_IniFileKey, ; GCBI_initFileKey GrObjDuplicateControl_gcnList, ; GCBI_gcnList length GrObjDuplicateControl_gcnList, ; GCBI_gcnCount GrObjDuplicateControl_notifyList, ; GCBI_notificationList length GrObjDuplicateControl_notifyList, ; GCBI_notificationCount GrObjDuplicateControlName, ; GCBI_controllerName handle GrObjDuplicateControlUI, ; GCBI_dupBlock GrObjDuplicateControl_childList, ; GCBI_childList length GrObjDuplicateControl_childList, ; GCBI_childCount GrObjDuplicateControl_featuresList, ; GCBI_featuresList length GrObjDuplicateControl_featuresList, ; GCBI_featuresCount GROBJ_DUPLICATE_CONTROL_DEFAULT_FEATURES, ; GCBI_defaultFeatures handle GrObjDuplicateToolControlUI, ; GCBI_dupBlock GrObjDuplicateControl_toolList, ; GCBI_childList length GrObjDuplicateControl_toolList, ; GCBI_childCount GrObjDuplicateControl_toolFeaturesList, ; GCBI_featuresList length GrObjDuplicateControl_toolFeaturesList, ; GCBI_featuresCount GROBJ_DUPLICATE_CONTROL_DEFAULT_TOOLBOX_FEATURES, ; GCBI_defaultFeatures GrObjDuplicateControl_helpContext> ; GCBI_helpContext if FULL_EXECUTE_IN_PLACE GrObjControlInfoXIP segment resource endif GrObjDuplicateControl_helpContext char "dbGrObjEdSpc", 0 GrObjDuplicateControl_IniFileKey char "GrObjDuplicate", 0 GrObjDuplicateControl_gcnList GCNListType \ <MANUFACTURER_ID_GEOWORKS, \ GAGCNLT_APP_TARGET_NOTIFY_GROBJ_BODY_SELECTION_STATE_CHANGE> GrObjDuplicateControl_notifyList NotificationType \ <MANUFACTURER_ID_GEOWORKS, GWNT_GROBJ_BODY_SELECTION_STATE_CHANGE> ;--- GrObjDuplicateControl_childList GenControlChildInfo \ <offset GrObjDuplicateTrigger, mask GODCF_DUPLICATE, mask GCCF_IS_DIRECTLY_A_FEATURE>, <offset GrObjCloneTrigger, mask GODCF_DUPLICATE_IN_PLACE, mask GCCF_IS_DIRECTLY_A_FEATURE> GrObjDuplicateControl_featuresList GenControlFeaturesInfo \ <offset GrObjCloneTrigger, CloneName, 0>, <offset GrObjDuplicateTrigger, DuplicateName, 0> GrObjDuplicateControl_toolList GenControlChildInfo \ <offset GrObjDuplicateTool, mask GODCTF_DUPLICATE, mask GCCF_IS_DIRECTLY_A_FEATURE>, <offset GrObjCloneTool, mask GODCTF_DUPLICATE_IN_PLACE, mask GCCF_IS_DIRECTLY_A_FEATURE> GrObjDuplicateControl_toolFeaturesList GenControlFeaturesInfo \ <offset GrObjCloneTool, CloneName, 0>, <offset GrObjDuplicateTool, DuplicateName, 0> if FULL_EXECUTE_IN_PLACE GrObjControlInfoXIP ends endif COMMENT @---------------------------------------------------------------------- MESSAGE: GrObjDuplicateControlUpdateUI -- MSG_GEN_CONTROL_UPDATE_UI for GrObjDuplicateControlClass DESCRIPTION: Handle notification of type change PASS: *ds:si - instance data es - segment of GrObjDuplicateControlClass ax - MSG_GEN_CONTROL_UPDATE_UI RETURN: nothing DESTROYED: ax REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- jon 11 feb 1992 Initial version ------------------------------------------------------------------------------@ GrObjDuplicateControlUpdateUI method dynamic GrObjDuplicateControlClass, MSG_GEN_CONTROL_UPDATE_UI uses cx .enter mov cx, 1 mov ax, mask GODCF_DUPLICATE_IN_PLACE mov si, offset GrObjCloneTrigger call GrObjControlUpdateUIBasedOnNumSelectedAndFeatureSet mov ax, mask GODCTF_DUPLICATE_IN_PLACE mov si, offset GrObjCloneTool call GrObjControlUpdateToolBasedOnNumSelectedAndToolboxFeatureSet mov ax, mask GODCF_DUPLICATE mov si, offset GrObjDuplicateTrigger call GrObjControlUpdateUIBasedOnNumSelectedAndFeatureSet mov ax, mask GODCTF_DUPLICATE mov si, offset GrObjDuplicateTool call GrObjControlUpdateToolBasedOnNumSelectedAndToolboxFeatureSet .leave ret GrObjDuplicateControlUpdateUI endm GrObjUIControllerCode ends GrObjUIControllerActionCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjDuplicateControlClone %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Description: GrObjDuplicateControl method for MSG_GrObjDuplicateControl_CLONE Called by: Pass: *ds:si = GrObjDuplicateControl object ds:di = GrObjDuplicateControl instance Return: nothing Destroyed: ax, bx, di Comments: Revision History: Name Date Description ---- ------------ ----------- jon Feb 24, 1992 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjDuplicateControlClone method dynamic GrObjDuplicateControlClass, MSG_GROBJ_DUPLICATE_CONTROL_DUPLICATE_IN_PLACE .enter mov ax, MSG_GB_CLONE_SELECTED_GROBJS call GrObjControlOutputActionRegsToBody .leave ret GrObjDuplicateControlClone endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjDuplicateControlDuplicate %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Description: GrObjDuplicateControl method for MSG_GrObjDuplicateControl_DUPLICATE Called by: Pass: *ds:si = GrObjDuplicateControl object ds:di = GrObjDuplicateControl instance Return: nothing Destroyed: ax, bx, di Comments: Revision History: Name Date Description ---- ------------ ----------- jon Feb 24, 1992 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjDuplicateControlDuplicate method dynamic GrObjDuplicateControlClass, MSG_GROBJ_DUPLICATE_CONTROL_DUPLICATE .enter mov ax, MSG_GB_DUPLICATE_SELECTED_GROBJS call GrObjControlOutputActionRegsToBody .leave ret GrObjDuplicateControlDuplicate endm GrObjUIControllerActionCode ends
// // 1_3.cpp // CPuzzleBook // // Created by masai on 2017/02/12. // Copyright (c) 2017年 masai. All rights reserved. // #include "1_3.h" #define PRINT(int) std::cout << int << std::endl void func_1_3(){ std::cout << "======= 1.3" << std::endl; int x, y, z; x = 2; y = 1; z = 0; x = x && y || z; PRINT(x); // bad syntax. int tmp = x || !y && z; // bad syntax. PRINT(tmp); x = y = 1; z = x ++ -1; PRINT(x); PRINT(z); z += - x ++ + ++ y; PRINT(x); PRINT(z); z = x / ++ x; PRINT(z); // bad syntax. }
; L0806.asm ; Generated 10.29.2000 by mlevel ; Modified 10.29.2000 by Abe Pralle INCLUDE "Source/Defs.inc" INCLUDE "Source/Levels.inc" ;--------------------------------------------------------------------- SECTION "Level0806Section",ROMX ;--------------------------------------------------------------------- L0806_Contents:: DW L0806_Load DW L0806_Init DW L0806_Check DW L0806_Map ;--------------------------------------------------------------------- ; Load ;--------------------------------------------------------------------- L0806_Load: DW ((L0806_LoadFinished - L0806_Load2)) ;size L0806_Load2: call ParseMap ret L0806_LoadFinished: ;--------------------------------------------------------------------- ; Map ;--------------------------------------------------------------------- L0806_Map: INCBIN "Data/Levels/L0806_moores.lvl" ;--------------------------------------------------------------------- ; Init ;--------------------------------------------------------------------- L0806_Init: DW ((L0806_InitFinished - L0806_Init2)) ;size L0806_Init2: ld a,BANK(main_in_game_gbm) ld hl,main_in_game_gbm call InitMusic ret L0806_InitFinished: ;--------------------------------------------------------------------- ; Check ;--------------------------------------------------------------------- L0806_Check: DW ((L0806_CheckFinished - L0806_Check2)) ;size L0806_Check2: ret L0806_CheckFinished: PRINT "0806 Script Sizes (Load/Init/Check) (of $500): " PRINT (L0806_LoadFinished - L0806_Load2) PRINT " / " PRINT (L0806_InitFinished - L0806_Init2) PRINT " / " PRINT (L0806_CheckFinished - L0806_Check2) PRINT "\n"
; A256296: Apply the transformation 0 -> 1 -> 2 -> 3 -> 4 -> 5 -> 0 to the digits of n written in base 6, then convert back to base 10. ; Submitted by Simon Strandgaard ; 1,2,3,4,5,0,13,14,15,16,17,12,19,20,21,22,23,18,25,26,27,28,29,24,31,32,33,34,35,30,1,2,3,4,5,0,79,80,81,82,83,78,85,86,87,88,89,84,91,92,93,94,95,90,97,98,99,100,101,96 bin $2,$0 mov $3,1 lpb $0 mov $2,$0 div $0,6 add $2,7 mod $2,6 mul $2,$3 add $1,$2 mov $2,$1 mul $3,6 lpe mov $0,$2
/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #include "tensorflow/compiler/xla/service/cpu/compiler_functor.h" #include <algorithm> #include <iterator> #include <memory> #include <string> #include <utility> #include <vector> #include "absl/memory/memory.h" #include "llvm/ADT/StringRef.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Verifier.h" #include "llvm/MC/MCContext.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/SmallVectorMemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO/AlwaysInliner.h" #include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "tensorflow/compiler/xla/service/cpu/cpu_runtime.h" #include "tensorflow/compiler/xla/service/cpu/llvm_ir_runtime.h" #include "tensorflow/compiler/xla/service/llvm_ir/llvm_util.h" #include "tensorflow/compiler/xla/statusor.h" #include "tensorflow/compiler/xla/types.h" #include "tensorflow/compiler/xla/util.h" #include "tensorflow/core/platform/logging.h" namespace xla { namespace cpu { /* Create filtered versions of the LLVM Pass Managers to filter out some of the expensive passes. Profiling: learning/brain/google/xla/benchmarks:inception_cpu_benchmark learning/brain/google/xla/benchmarks:cifarnet pointed to LICM and IndVarSimplify as the hottest passes. LICM is known to exhibit O(n^2) time in the number of instructions. IndVarSimplify is slow due to SCEV. If loops are emitted in canonical form, this pass is not necessary. Disabling these as a starting point. */ // TODO(b/64227304) Creating a custom pass pipeline will replace this. namespace { class FilteredPassManager : public llvm::legacy::PassManager { public: explicit FilteredPassManager(bool disable_expensive_passes) : disable_expensive_passes_(disable_expensive_passes) {} void add(llvm::Pass* p) override { if (disable_expensive_passes_) { llvm::StringRef PassName = p->getPassName(); if (PassName.contains("Unroll loops")) { return; } } llvm::legacy::PassManager::add(p); } private: bool disable_expensive_passes_; }; } // anonymous namespace std::unique_ptr<llvm::MemoryBuffer> CompilerFunctor::operator()( llvm::Module& module) const { FilteredPassManager module_passes(disable_expensive_passes_); llvm::legacy::FunctionPassManager function_passes(&module); VLOG(2) << "IR before optimizations"; XLA_VLOG_LINES(2, llvm_ir::DumpModuleToString(module)); if (pre_optimization_hook_) { pre_optimization_hook_(module); } // Add the appropriate TargetLibraryInfo and TargetTransformInfo. AddTargetInfoPasses(&module_passes); // Build up optimization pipeline. if (optimize_for_size_) { // Optimizing for size turns on -O2 level optimizations. // // TODO(b/64153864): Although the code generator supports size_level = 2 to // turn on more aggressive code size optimizations than size_level = 1, we // pass size_level = 1 because in many cases a size_level of 2 does // worse. Investigate why. AddOptimizationPasses(&module_passes, &function_passes, /*opt_level=*/2, /*size_level=*/1); } else { AddOptimizationPasses(&module_passes, &function_passes, /*opt_level=*/opt_level_, /*size_level=*/0); } // Run optimization passes on module. function_passes.doInitialization(); CHECK(!llvm::verifyModule(module, &llvm::dbgs())); for (auto func = module.begin(); func != module.end(); ++func) { function_passes.run(*func); } function_passes.doFinalization(); module_passes.run(module); CHECK(!llvm::verifyModule(module, &llvm::dbgs())); runtime::RewriteIRRuntimeFunctions(&module, enable_fast_math_); // Buffer for holding machine code prior to constructing the ObjectFile. llvm::SmallVector<char, 0> stream_buffer; llvm::raw_svector_ostream ostream(stream_buffer); VLOG(2) << "IR after optimizations"; XLA_VLOG_LINES(2, llvm_ir::DumpModuleToString(module)); if (post_optimization_hook_) { post_optimization_hook_(module); } // Generate code. llvm::MCContext* mc_context; llvm::legacy::PassManager codegen_passes; target_machine_->addPassesToEmitMC(codegen_passes, mc_context, ostream); codegen_passes.run(module); std::unique_ptr<llvm::MemoryBuffer> memory_buffer( new llvm::SmallVectorMemoryBuffer(std::move(stream_buffer))); if (post_codegen_hook_) { llvm::Expected<std::unique_ptr<llvm::object::ObjectFile>> obj_file = llvm::object::ObjectFile::createObjectFile(*memory_buffer); if (obj_file) { post_codegen_hook_(*obj_file.get()); } else { LOG(WARNING) << "Could convert memory buffer to object file!"; } } return memory_buffer; } static std::vector<llvm::VecDesc> VectorFunctionsForTargetLibraryInfoImpl() { std::vector<llvm::VecDesc> result = { {"tanhf", runtime::kTanhV4F32SymbolName, 4}, {"llvm.tanh.f32", runtime::kTanhV4F32SymbolName, 4}, {"tanhf", runtime::kTanhV8F32SymbolName, 8}, {"llvm.tanh.f32", runtime::kTanhV8F32SymbolName, 8}, {"expf", runtime::kExpV4F32SymbolName, 4}, {"llvm.exp.f32", runtime::kExpV4F32SymbolName, 4}, {"expf", runtime::kExpV8F32SymbolName, 8}, {"llvm.exp.f32", runtime::kExpV8F32SymbolName, 8}, {"logf", runtime::kLogV4F32SymbolName, 4}, {"llvm.log.f32", runtime::kLogV4F32SymbolName, 4}, {"logf", runtime::kLogV8F32SymbolName, 8}, {"llvm.log.f32", runtime::kLogV8F32SymbolName, 8}, }; return result; } void CompilerFunctor::AddTargetInfoPasses( llvm::legacy::PassManagerBase* passes) const { llvm::Triple target_triple(target_machine_->getTargetTriple()); auto target_library_info_impl = absl::make_unique<llvm::TargetLibraryInfoImpl>(target_triple); target_library_info_impl->addVectorizableFunctions( VectorFunctionsForTargetLibraryInfoImpl()); passes->add( new llvm::TargetLibraryInfoWrapperPass(*target_library_info_impl)); passes->add(createTargetTransformInfoWrapperPass( target_machine_->getTargetIRAnalysis())); } void CompilerFunctor::AddOptimizationPasses( llvm::legacy::PassManagerBase* module_passes, llvm::legacy::FunctionPassManager* function_passes, unsigned opt_level, unsigned size_level) const { llvm::PassManagerBuilder builder; builder.OptLevel = opt_level; builder.SizeLevel = size_level; if (opt_level > 1) { builder.Inliner = llvm::createFunctionInliningPass(); } else { // Only inline functions marked with "alwaysinline". builder.Inliner = llvm::createAlwaysInlinerLegacyPass(); } builder.DisableUnitAtATime = false; builder.DisableUnrollLoops = opt_level == 0; builder.LoopVectorize = opt_level > 0 && size_level == 0; builder.SLPVectorize = opt_level > 1 && size_level == 0; builder.populateFunctionPassManager(*function_passes); builder.populateModulePassManager(*module_passes); } } // namespace cpu } // namespace xla
compressedDataPointer: dw 0 vProgram: inc word[cs:compressedDataPointer] mov es,[cs:compressedDataPointer] mov al,[es:0x0] mov [ss:w0+3],al mov al,[es:0x3] mov [ss:w1+3],al mov al,[es:0x6] mov [ss:w2+3],al mov al,[es:0x9] mov [ss:w3+3],al mov ax,[es:0x1] mov [ss:f0+2],ax mov ax,[es:0x4] mov [ss:f1+2],ax mov ax,[es:0x7] mov [ss:f2+2],ax mov ax,[es:0xa] mov [ss:f3+2],ax w0: dw 0, 0 f0: dw 0, 0 w1: dw 0, 0 f1: dw 0, 0 w2: dw 0, 0 f2: dw 0, 0 w3: dw 0, 0 f3: dw 0, 0 mov sp,[es:0xc] crtcUpdate: mov ax,[es:0xe] mov [ss:sa1+7],al mov ax,[es:0xf] mov [ss:sa2+7],al sa1: mov bx,dx mov dx,0x3d4 mov ax,0x990c out dx,ax mov dx,bx sa2: mov bx,dx mov dx,0x3d4 mov ax,0x990d out dx,ax mov dx,bx mov sp,vProgram teletype: inc word[cs:screenUpdate+3] inc word[cs:screenUpdate+3] mov ax,[es:0xe] mov [ss:screenUpdate+5],ax mov ax,0xb800 mov es,ax screenUpdate: mov word[es:0x1234],0x5678 mov sp,vProgram moveCursor: mov ax,[es:0xe] mov [ss:screenUpdate+3],ax mov sp,vProgram finish: dw 0, 0x9090
; Listing generated by Microsoft (R) Optimizing Compiler Version 16.00.40219.01 TITLE D:\Projects\TaintAnalysis\AntiTaint\Epilog\src\func-va.c .686P .XMM include listing.inc .model flat INCLUDELIB MSVCRT INCLUDELIB OLDNAMES _DATA SEGMENT $SG3581 DB '%d ', 00H $SG3582 DB '%s', 0aH, 00H _DATA ENDS PUBLIC _func EXTRN __imp__printf:PROC EXTRN __imp__gets:PROC ; Function compile flags: /Odtp ; File d:\projects\taintanalysis\antitaint\epilog\src\func-va.c _TEXT SEGMENT _ap$ = -16 ; size = 4 _buf$ = -12 ; size = 8 _i$ = -4 ; size = 4 _num$ = 8 ; size = 4 _func PROC ; 10 : { push ebp mov ebp, esp sub esp, 16 ; 00000010H ; 11 : va_list ap; ; 12 : char buf[8]; ; 13 : int i; ; 14 : va_start(ap, num); lea eax, DWORD PTR _num$[ebp+4] mov DWORD PTR _ap$[ebp], eax ; 15 : gets(buf); lea ecx, DWORD PTR _buf$[ebp] push ecx call DWORD PTR __imp__gets add esp, 4 ; 16 : for (i = 0 ; i < num ; ++i) mov DWORD PTR _i$[ebp], 0 jmp SHORT $LN3@func $LN2@func: mov edx, DWORD PTR _i$[ebp] add edx, 1 mov DWORD PTR _i$[ebp], edx $LN3@func: mov eax, DWORD PTR _i$[ebp] cmp eax, DWORD PTR _num$[ebp] jge SHORT $LN1@func ; 17 : printf("%d ", va_arg(ap, int)); mov ecx, DWORD PTR _ap$[ebp] add ecx, 4 mov DWORD PTR _ap$[ebp], ecx mov edx, DWORD PTR _ap$[ebp] mov eax, DWORD PTR [edx-4] push eax push OFFSET $SG3581 call DWORD PTR __imp__printf add esp, 8 jmp SHORT $LN2@func $LN1@func: ; 18 : printf("%s\n", buf); lea ecx, DWORD PTR _buf$[ebp] push ecx push OFFSET $SG3582 call DWORD PTR __imp__printf add esp, 8 ; 19 : va_end(ap); mov DWORD PTR _ap$[ebp], 0 ; 20 : } mov esp, ebp pop ebp ret 0 _func ENDP _TEXT ENDS PUBLIC _main ; Function compile flags: /Odtp _TEXT SEGMENT _main PROC ; 23 : { push ebp mov ebp, esp ; 24 : func(2, 3, 4); push 4 push 3 push 2 call _func add esp, 12 ; 0000000cH ; 25 : return 0; xor eax, eax ; 26 : } pop ebp ret 0 _main ENDP _TEXT ENDS END
.data base: .space 800 exp: .space 800 cnt: .word 0 $str0: .asciiz "Number is out of range." $str1: .asciiz "Number is out of range." $str2: .asciiz "=" $str3: .asciiz "*" $str4: .asciiz "^" $str5: .asciiz "Number is out of range." $str6: .asciiz "Number is out of range." $str7: .asciiz "Prime numbers:" $str8: .asciiz " " .text jal main li $v0, 10 syscall mod: subi $gp, $gp, 8 sw $fp, 0($sp) sw $ra, -4($sp) lw $s0, 0($gp) lw $s1, 4($gp) move $t8, $s0 move $t9, $s1 div $t8, $t9 mflo $t8 move $a1, $t8 move $t8, $a1 move $t9, $s1 mul $t8, $t8, $t9 move $a2, $t8 move $t8, $s0 move $t9, $a2 sub $t8, $t8, $t9 move $a3, $t8 move $v0, $a3 lw $ra, -4($sp) lw $sp, 0($sp) lw $s0, -8($sp) lw $s1, -12($sp) lw $s2, -16($sp) lw $s3, -20($sp) lw $s4, -24($sp) lw $s5, -28($sp) lw $s6, -32($sp) lw $s7, -36($sp) jr $ra init: sw $fp, 0($sp) sw $ra, -4($sp) li $t8, 2 move $s0, $t8 li $t8, 0 la $t9, cnt sw $t8, 0($t9) $lab0: addi $t8, $sp, -40 move $t9, $s0 li $at, 4 mul $t9, $t9, $at sub $t8, $t8, $t9 li $t9, 1 sw $t9, 0($t8) move $t8, $s0 li $t9, 1 add $t8, $t8, $t9 move $s0, $t8 move $t8, $s0 li $t9, 1000 sle $t8, $t8, $t9 move $a1, $t8 move $t8, $a1 bne $t8, $0, $lab0 li $t8, 2 move $s0, $t8 $lab1: addi $t8, $sp, -40 move $t9, $s0 li $at, 4 mul $t9, $t9, $at sub $t8, $t8, $t9 lw $t8, 0($t8) move $a1, $t8 move $t8, $a1 beq $t8, $0, $lab3 la $t8, base la $t9, cnt lw $t9, 0($t9) li $at, 4 mul $t9, $t9, $at add $t8, $t8, $t9 move $t9, $s0 sw $t9, 0($t8) la $t8, exp la $t9, cnt lw $t9, 0($t9) li $at, 4 mul $t9, $t9, $at add $t8, $t8, $t9 li $t9, 0 sw $t9, 0($t8) la $t8, cnt lw $t8, 0($t8) li $t9, 1 add $t8, $t8, $t9 la $t9, cnt sw $t8, 0($t9) li $t8, 2 move $s1, $t8 move $t8, $s0 move $t9, $s1 mul $t8, $t8, $t9 move $a1, $t8 move $t8, $a1 li $t9, 1000 sle $t8, $t8, $t9 move $a2, $t8 move $t8, $a2 beq $t8, $0, $lab3 $lab4: move $t8, $s0 move $t9, $s1 mul $t8, $t8, $t9 move $a1, $t8 addi $t8, $sp, -40 move $t9, $a1 li $at, 4 mul $t9, $t9, $at sub $t8, $t8, $t9 li $t9, 0 sw $t9, 0($t8) move $t8, $s1 li $t9, 1 add $t8, $t8, $t9 move $s1, $t8 move $t8, $s0 move $t9, $s1 mul $t8, $t8, $t9 move $a2, $t8 move $t8, $a2 li $t9, 1000 sle $t8, $t8, $t9 move $a3, $t8 move $t8, $a3 bne $t8, $0, $lab4 $lab3: move $t8, $s0 li $t9, 1 add $t8, $t8, $t9 move $s0, $t8 move $t8, $s0 li $t9, 1000 sle $t8, $t8, $t9 move $a1, $t8 move $t8, $a1 bne $t8, $0, $lab1 lw $ra, -4($sp) lw $sp, 0($sp) lw $s0, -8($sp) lw $s1, -12($sp) lw $s2, -16($sp) lw $s3, -20($sp) lw $s4, -24($sp) lw $s5, -28($sp) lw $s6, -32($sp) lw $s7, -36($sp) jr $ra resolve: subi $gp, $gp, 8 sw $fp, 0($sp) sw $ra, -4($sp) lw $s1, 0($gp) lw $s0, 4($gp) move $t8, $s1 li $t9, 1 seq $t8, $t8, $t9 move $a1, $t8 move $t8, $a1 beq $t8, $0, $lab5 lw $ra, -4($sp) lw $sp, 0($sp) lw $s0, -8($sp) lw $s1, -12($sp) lw $s2, -16($sp) lw $s3, -20($sp) lw $s4, -24($sp) lw $s5, -28($sp) lw $s6, -32($sp) lw $s7, -36($sp) jr $ra $lab5: sw $s1, 0($gp) addi $gp, $gp, 4 la $t8, base move $t9, $s0 li $at, 4 mul $t9, $t9, $at add $t8, $t8, $t9 lw $t8, 0($t8) addi $t9, $sp, -40 sw $t8, 0($t9) lw $t8, -40($sp) sw $t8, 0($gp) addi $gp, $gp, 4 sw $s0, -8($sp) sw $s1, -12($sp) sw $s2, -16($sp) sw $s3, -20($sp) sw $s4, -24($sp) sw $s5, -28($sp) sw $s6, -32($sp) sw $s7, -36($sp) move $fp, $sp subi $sp, $sp, 64 jal mod move $a1, $v0 move $t8, $a1 li $t9, 0 seq $t8, $t8, $t9 move $a2, $t8 move $t8, $a2 beq $t8, $0, $lab6 la $t8, exp move $t9, $s0 li $at, 4 mul $t9, $t9, $at add $t8, $t8, $t9 lw $t8, 0($t8) addi $t9, $sp, -44 sw $t8, 0($t9) lw $t8, -44($sp) li $t9, 1 add $t8, $t8, $t9 sw $t8, -48($sp) la $t8, exp move $t9, $s0 li $at, 4 mul $t9, $t9, $at add $t8, $t8, $t9 lw $t9, -48($sp) sw $t9, 0($t8) la $t8, base move $t9, $s0 li $at, 4 mul $t9, $t9, $at add $t8, $t8, $t9 lw $t8, 0($t8) addi $t9, $sp, -52 sw $t8, 0($t9) move $t8, $s1 lw $t9, -52($sp) div $t8, $t9 mflo $t8 sw $t8, -56($sp) lw $t8, -56($sp) sw $t8, 0($gp) addi $gp, $gp, 4 sw $s0, 0($gp) addi $gp, $gp, 4 sw $s0, -8($sp) sw $s1, -12($sp) sw $s2, -16($sp) sw $s3, -20($sp) sw $s4, -24($sp) sw $s5, -28($sp) sw $s6, -32($sp) sw $s7, -36($sp) move $fp, $sp subi $sp, $sp, 64 jal resolve lw $ra, -4($sp) lw $sp, 0($sp) lw $s0, -8($sp) lw $s1, -12($sp) lw $s2, -16($sp) lw $s3, -20($sp) lw $s4, -24($sp) lw $s5, -28($sp) lw $s6, -32($sp) lw $s7, -36($sp) jr $ra $lab6: sw $s1, 0($gp) addi $gp, $gp, 4 move $t8, $s0 li $t9, 1 add $t8, $t8, $t9 sw $t8, -60($sp) lw $t8, -60($sp) sw $t8, 0($gp) addi $gp, $gp, 4 sw $s0, -8($sp) sw $s1, -12($sp) sw $s2, -16($sp) sw $s3, -20($sp) sw $s4, -24($sp) sw $s5, -28($sp) sw $s6, -32($sp) sw $s7, -36($sp) move $fp, $sp subi $sp, $sp, 64 jal resolve lw $ra, -4($sp) lw $sp, 0($sp) lw $s0, -8($sp) lw $s1, -12($sp) lw $s2, -16($sp) lw $s3, -20($sp) lw $s4, -24($sp) lw $s5, -28($sp) lw $s6, -32($sp) lw $s7, -36($sp) jr $ra main: sw $fp, 0($sp) sw $ra, -4($sp) sw $s0, -8($sp) sw $s1, -12($sp) sw $s2, -16($sp) sw $s3, -20($sp) sw $s4, -24($sp) sw $s5, -28($sp) sw $s6, -32($sp) sw $s7, -36($sp) move $fp, $sp subi $sp, $sp, 48 jal init li $v0, 12 syscall move $s2, $v0 li $v0, 5 syscall move $s1, $v0 move $t8, $s2 li $t9, 114 seq $t8, $t8, $t9 move $a1, $t8 move $t8, $a1 beq $t8, $0, $lab7 move $t8, $s1 li $t9, 2 slt $t8, $t8, $t9 move $a1, $t8 move $t8, $a1 beq $t8, $0, $lab8 la $a0, $str0 li $v0, 4 syscall lw $ra, -4($sp) lw $sp, 0($sp) lw $s0, -8($sp) lw $s1, -12($sp) lw $s2, -16($sp) lw $s3, -20($sp) lw $s4, -24($sp) lw $s5, -28($sp) lw $s6, -32($sp) lw $s7, -36($sp) jr $ra $lab8: move $t8, $s1 li $t9, 1000 sgt $t8, $t8, $t9 move $a1, $t8 move $t8, $a1 beq $t8, $0, $lab9 la $a0, $str1 li $v0, 4 syscall lw $ra, -4($sp) lw $sp, 0($sp) lw $s0, -8($sp) lw $s1, -12($sp) lw $s2, -16($sp) lw $s3, -20($sp) lw $s4, -24($sp) lw $s5, -28($sp) lw $s6, -32($sp) lw $s7, -36($sp) jr $ra $lab9: sw $s1, 0($gp) addi $gp, $gp, 4 li $t8, 0 sw $t8, 0($gp) addi $gp, $gp, 4 sw $s0, -8($sp) sw $s1, -12($sp) sw $s2, -16($sp) sw $s3, -20($sp) sw $s4, -24($sp) sw $s5, -28($sp) sw $s6, -32($sp) sw $s7, -36($sp) move $fp, $sp subi $sp, $sp, 48 jal resolve move $a0, $s1 li $v0, 1 syscall la $a0, $str2 li $v0, 4 syscall li $t8, 0 move $s3, $t8 li $t8, 0 move $s0, $t8 $lab10: la $t8, exp move $t9, $s0 li $at, 4 mul $t9, $t9, $at add $t8, $t8, $t9 lw $t8, 0($t8) move $a1, $t8 move $t8, $a1 li $t9, 0 sgt $t8, $t8, $t9 move $a2, $t8 move $t8, $a2 beq $t8, $0, $lab11 move $t8, $s3 beq $t8, $0, $lab12 la $a0, $str3 li $v0, 4 syscall $lab12: la $t8, base move $t9, $s0 li $at, 4 mul $t9, $t9, $at add $t8, $t8, $t9 lw $t8, 0($t8) move $a1, $t8 move $a0, $a1 li $v0, 1 syscall la $t8, exp move $t9, $s0 li $at, 4 mul $t9, $t9, $at add $t8, $t8, $t9 lw $t8, 0($t8) move $a2, $t8 move $t8, $a2 li $t9, 1 sgt $t8, $t8, $t9 move $a3, $t8 move $t8, $a3 beq $t8, $0, $lab13 la $a0, $str4 li $v0, 4 syscall la $t8, exp move $t9, $s0 li $at, 4 mul $t9, $t9, $at add $t8, $t8, $t9 lw $t8, 0($t8) move $a1, $t8 move $a0, $a1 li $v0, 1 syscall $lab13: li $t8, 1 move $s3, $t8 $lab11: move $t8, $s0 li $t9, 1 add $t8, $t8, $t9 move $s0, $t8 move $t8, $s0 la $t9, cnt lw $t9, 0($t9) slt $t8, $t8, $t9 move $a1, $t8 move $t8, $a1 bne $t8, $0, $lab10 $lab7: move $t8, $s2 li $t9, 116 seq $t8, $t8, $t9 move $a1, $t8 move $t8, $a1 beq $t8, $0, $lab14 move $t8, $s1 li $t9, 2 slt $t8, $t8, $t9 move $a1, $t8 move $t8, $a1 beq $t8, $0, $lab15 la $a0, $str5 li $v0, 4 syscall lw $ra, -4($sp) lw $sp, 0($sp) lw $s0, -8($sp) lw $s1, -12($sp) lw $s2, -16($sp) lw $s3, -20($sp) lw $s4, -24($sp) lw $s5, -28($sp) lw $s6, -32($sp) lw $s7, -36($sp) jr $ra $lab15: move $t8, $s1 li $t9, 1000 sgt $t8, $t8, $t9 move $a1, $t8 move $t8, $a1 beq $t8, $0, $lab16 la $a0, $str6 li $v0, 4 syscall lw $ra, -4($sp) lw $sp, 0($sp) lw $s0, -8($sp) lw $s1, -12($sp) lw $s2, -16($sp) lw $s3, -20($sp) lw $s4, -24($sp) lw $s5, -28($sp) lw $s6, -32($sp) lw $s7, -36($sp) jr $ra $lab16: la $a0, $str7 li $v0, 4 syscall li $t8, 0 move $s0, $t8 $lab17: la $a0, $str8 li $v0, 4 syscall la $t8, base move $t9, $s0 li $at, 4 mul $t9, $t9, $at add $t8, $t8, $t9 lw $t8, 0($t8) move $a1, $t8 move $a0, $a1 li $v0, 1 syscall move $t8, $s0 li $t9, 1 add $t8, $t8, $t9 move $s0, $t8 move $t8, $s0 la $t9, cnt lw $t9, 0($t9) sge $t8, $t8, $t9 move $a2, $t8 move $t8, $a2 beq $t8, $0, $lab18 lw $ra, -4($sp) lw $sp, 0($sp) lw $s0, -8($sp) lw $s1, -12($sp) lw $s2, -16($sp) lw $s3, -20($sp) lw $s4, -24($sp) lw $s5, -28($sp) lw $s6, -32($sp) lw $s7, -36($sp) jr $ra $lab18: la $t8, base move $t9, $s0 li $at, 4 mul $t9, $t9, $at add $t8, $t8, $t9 lw $t8, 0($t8) move $a1, $t8 move $t8, $a1 move $t9, $s1 sle $t8, $t8, $t9 move $a2, $t8 move $t8, $a2 bne $t8, $0, $lab17 $lab14: lw $ra, -4($sp) lw $sp, 0($sp) lw $s0, -8($sp) lw $s1, -12($sp) lw $s2, -16($sp) lw $s3, -20($sp) lw $s4, -24($sp) lw $s5, -28($sp) lw $s6, -32($sp) lw $s7, -36($sp) jr $ra
runner_frame ld a,3 dec a jr nz,runner_skipframe call runner_draw_currframe ; undraw call runner_advance call runner_draw_currframe ld a,3 runner_skipframe ld (runner_frame+1),a ret runner_advance ld a,(runner_frameno+1) inc a cp 12 jr nz,runner_nowrap xor a runner_nowrap ld (runner_frameno+1),a jr z,runner_nextchar cp 3 jr z,runner_nextchar cp 6 jr z,runner_nextchar cp 9 jr z,runner_nextchar ret runner_nextchar ld a,(runner_screenpos+1) inc a ld (runner_screenpos+1),a ret runner_draw_currframe runner_frameno ld b,0 runner_screenpos ld de,0x5063 ; enter with b=frame no, de=screen pos runner_draw_frame ld h,b ld l,0 srl h rr l ld bc,runner_sprites add hl,bc ld a,e and 0x1f cp 3 jp z,runner_draw_frame_w1 cp 4 jp z,runner_draw_frame_w2 cp 5 jp z,runner_draw_frame_w3 runner_draw_frame_w4 ld b,32 runner_rowlp_w4 push de ld a,(de) xor (hl) ld (de),a inc l inc e ld a,(de) xor (hl) ld (de),a inc l inc e ld a,(de) xor (hl) ld (de),a inc l inc e ld a,(de) xor (hl) ld (de),a inc hl pop de call upde djnz runner_rowlp_w4 ret ; left clip to 3 chars runner_draw_frame_w3 ld b,32 inc e runner_rowlp_w3 push de inc l ld a,(de) xor (hl) ld (de),a inc l inc e ld a,(de) xor (hl) ld (de),a inc l inc e ld a,(de) xor (hl) ld (de),a inc hl pop de call upde djnz runner_rowlp_w3 ret ; left clip to 2 chars runner_draw_frame_w2 ld b,32 inc e inc e runner_rowlp_w2 inc l inc l ld a,(de) xor (hl) ld (de),a inc l inc e ld a,(de) xor (hl) ld (de),a inc hl dec e call upde djnz runner_rowlp_w2 ret ; left clip to 1 char runner_draw_frame_w1 ld b,32 inc e inc e inc e runner_rowlp_w1 inc l inc l inc l ld a,(de) xor (hl) ld (de),a inc hl call upde djnz runner_rowlp_w1 ret align 0x100 runner_sprites incbin "assets/runner_sprites.bin"
MAC kp_setsongregister dc.b {2},[$00 | [{1} << 2]] ENDM MAC kp_settrackregister dc.b {2},[$01 | [{1} << 2]] ENDM MAC kp_setinstrument dc.b {2},[$02 | [{1} << 2]] ENDM MAC kp_rewind dc.b 0,[$03] ENDM MAC KP_OSCV dc.b {1},[[{2} & $01] << 6] | [[{3} & $01] << 5] | [[{4} & $01] << 4] | [{5} & %00001111] ENDM MAC KP_OSCJ dc.b $00,[{1} | %10000000] ENDM MAC KP_VOLV dc.b [ [{1} & %00001111] | [[{2} & %00000111] << 4] ] ENDM MAC KP_VOLJ dc.b [{1} | %10000000] ENDM
; A032962: Numbers whose base-12 representation Sum_{i=0..m} d(i)*12^(m-i) has even d(i) for all odd i. ; 1,2,3,4,5,6,7,8,9,10,11,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110 mov $1,$0 trn $0,11 add $1,$0 add $1,1
############################################################################### # Copyright 2019 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # You may not use this file except in compliance with the License. You may # obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # limitations under the License. ############################################################################### .text .p2align 4, 0x90 .globl _s8_cpInc_BNU _s8_cpInc_BNU: push %ebp mov %esp, %ebp push %ebx push %esi push %edi movl (8)(%ebp), %edi movl (12)(%ebp), %esi movl (20)(%ebp), %eax movd (20)(%ebp), %mm0 movl (16)(%ebp), %edx shl $(2), %edx xor %ecx, %ecx .p2align 4, 0x90 .Lmain_loopgas_1: movd (%esi,%ecx), %mm1 paddq %mm0, %mm1 movd %mm1, (%edi,%ecx) pshufw $(254), %mm1, %mm0 movd %mm0, %eax add $(4), %ecx cmp %edx, %ecx jl .Lmain_loopgas_1 .Lexit_loopgas_1: emms pop %edi pop %esi pop %ebx pop %ebp ret
#include <iostream> #include <vector> #include <cmath> #include <iomanip> using namespace std; /* Get the ownership relationship to a space on the board arguments: board - a vector of ints representing the stacks boardPosition - an int, which index of the board to examine myPosition - an int, from where on the board is the ownership assessed returns: a float, one of {1 - I own it fully 0.5 - I own half of it 0 - I don't own it at all} */ float ownedByMe(vector<int> board, int boardPosition, int myPosition) { /* base case, we're on the spot */ if (boardPosition == myPosition) { return 1; } /* other base case, someone else is on the spot */ if ((board.at(boardPosition) == 1) && (boardPosition != myPosition)) { return 0; } /* mark myPosition since it's a hypothetical spot as of now */ board.at(myPosition) = 1; /* start searching outward from the position in question */ for (int i = 1; i < board.size(); i++) { int lower = 0; int higher = 0; /* check if within board */ if ((boardPosition - i) >= 0) { lower = board.at(boardPosition - i); } if ((boardPosition + i) < board.size()) { higher = board.at(boardPosition + i); } /* check for a tie */ if ((lower == 1) && (higher == 1)) { if (((boardPosition - i) == myPosition) || ((boardPosition + i) == myPosition)) { return 0.5; } else { return 0; } } else { if (lower == 1) { if ((boardPosition - i) == myPosition) { return 1; } else { return 0; } } else if (higher == 1){ if ((boardPosition + i) == myPosition) { return 1; } else { return 0; } } } } return 0; } /* calculate the profitability of a board from a position arguments: board - a vector of ints representing the stacks tokenPosition - an int, which index of the board to base profit on */ float calculateProfit(vector<int> board, int tokenPosition) { float profit = 0; for (int i = 0; i < board.size(); i++) { float owned = ownedByMe(board, i, tokenPosition); profit += (i + 1) * owned; } return profit; } /* find the most profitable move given opponants' optimal moves arguments: board - a vector of ints representing the stacks nPlayers - int, how many more players are left, including me */ vector<int> makeOptimalMove(vector<int> board, int nPlayers) { float maxProfit = 0; int maxIndex = 0; vector<int> optimalHypoBoard; /* base case, find best spot on the current board */ if (nPlayers <= 1) { for (int i = 0; i < board.size(); i++) { if (board.at(i) == 0) { float profit = calculateProfit(board, i); if (profit > maxProfit) { maxProfit = profit; maxIndex = i; } } } board.at(maxIndex) = 1; return board; /* find best spot assuming next player will make an optimal move */ } else { for (int i = 0; i < board.size(); i++) { vector<int> hypoBoard = board; if (board.at(i) == 0) { hypoBoard.at(i) = 1; hypoBoard = makeOptimalMove(hypoBoard, nPlayers - 1); float profit = calculateProfit(hypoBoard, i); if (profit > maxProfit) { optimalHypoBoard = hypoBoard; maxProfit = profit; maxIndex = i; } } } board = optimalHypoBoard; return board; } } /* find the most profitable first move given opponants' optimal moves arguments: board - a vector of ints representing the stacks nPlayers - int, how many more players are left, including me */ vector<int> makeOptimalFirstMove(vector<int> board, int nPlayers) { float maxProfit = 0; int maxIndex = 0; /* find best spot assuming next player will make an optimal move */ for (int i = 0; i < board.size(); i++) { vector<int> hypoBoard = board; if (board.at(i) == 0) { hypoBoard.at(i) = 1; hypoBoard = makeOptimalMove(hypoBoard, nPlayers - 1); float profit = calculateProfit(hypoBoard, i); if (profit > maxProfit) { maxProfit = profit; maxIndex = i; } } } board.at(maxIndex) = 1; return board; } int main() { /* read in game information */ int players; int spaces; cout << "How many players? "; cin >> players; cout << "How many spaces? "; cin >> spaces; vector<int> gameBoard; for (int i = 0; i < spaces; i++) { gameBoard.push_back(0); } /* record information about first move */ vector<int> optimalBoard = gameBoard; int firstMoveIndex = 0; for (int i = 0; i < players; i++) { optimalBoard = makeOptimalFirstMove(optimalBoard, players - i); if (i == 0) { for (int j = 0; j < optimalBoard.size(); j++) { if (optimalBoard.at(j) == 1) { firstMoveIndex = j; } } } } /* generate summary statistics */ float firstMoveProfit = calculateProfit(optimalBoard, firstMoveIndex); float total = 0; float avg = 0; float allMoney = 0; for (int i = 0; i < optimalBoard.size(); i++) { if ((optimalBoard.at(i) == 1) && (i != firstMoveIndex)) { total += calculateProfit(optimalBoard, i); } allMoney += (i+1); } avg = total / (players - 1); optimalBoard.at(firstMoveIndex) = 11; cout << "Optimal game board shown below (first move marked '11')\n"; for (int i = 0; i < optimalBoard.size(); i++) { cout << i + 1 << ". " << optimalBoard.at(i) << "\n"; } cout << "Optimal first move is " << firstMoveIndex + 1 << " with profit $" << setprecision (2) << fixed << firstMoveProfit << " (" << ((firstMoveProfit/allMoney) * 100) << "% of the total money)" "\n"; cout << "Average profit for non-first moves is $" << setprecision (2) << fixed << avg << "\n"; cout << "Advantage of moving first is $" << setprecision (2) << fixed << firstMoveProfit - avg << "\n"; return 0; }
;--- Sample implementation of a MSX-UNAPI specification that installs in mapped RAM ; By Konamiman, 5-2019 ; ; This code implements a sample mathematical specification, "SIMPLE_MATH", ; which has just two functions: ; Function 1: Returns HL = L + E ; Function 2: Returns HL = L * E ; ; The code installs on a mapped RAM segment. ; The RAM helper must have been previously installed. ; ; You can compile it with sjasm (https://github.com/Konamiman/Sjasm/releases): ; sjasm unapi-ram.asm math.com ; The resulting file is a MSX-DOS .COM program that installs the implementation. ; ; Search for "TODO" comments for what to change/extend when creating your own implementation. ; ; Optional improvements (up to you): ; - Install a RAM helper if none is detected. ; - Let the user choose the install segment in DOS 1. ; - Add code for uninstallation. ;******************* ;*** CONSTANTS *** ;******************* ;--- System variables and routines _TERM0: equ 00h _STROUT: equ 09h ENASLT: equ 0024h EXTBIO: equ 0FFCAh ARG: equ 0F847h ;--- API version and implementation version ;TODO: Adjust for your implementation API_V_P: equ 1 API_V_S: equ 0 ROM_V_P: equ 1 ROM_V_S: equ 1 ;--- Maximum number of available standard and implementation-specific function numbers ;TODO: Adjust for your implementation ;Must be 0 to 127 MAX_FN: equ 2 ;Must be either zero (if no implementation-specific functions available), or 128 to 254 MAX_IMPFN: equ 0 ;*************************** ;*** INSTALLATION CODE *** ;*************************** org 100h ;--- Show welcome message ld de,WELCOME_S ld c,_STROUT call 5 ;--- Locate the RAM helper, terminate with error if not installed ld de,2222h ld hl,0 ld a,0FFh call EXTBIO ld a,h or l jr nz,HELPER_OK ld de,NOHELPER_S ld c,_STROUT call 5 ld c,_TERM0 jp 5 HELPER_OK: ld (HELPER_ADD),hl ld (MAPTAB_ADD),bc ;--- Check if we are already installed. ; Do this by searching all the SIMPLE_MATH ; implementations installed, and comparing ; the implementation name of each one with ; our implementation name. ;* Copy the implementation identifier to ARG ld hl,UNAPI_ID-SEG_CODE_START+SEG_CODE ld de,ARG ld bc,UNAPI_ID_END-UNAPI_ID ldir ;* Obtain the number of installed implementations ld de,2222h xor a ld b,0 call EXTBIO ld a,b or a jr z,NOT_INST ;>>> The loop for each installed implementations ; starts here, with A=implementation index IMPL_LOOP: push af ;* Obtain the slot, segment and entry point ; for the implementation ld de,2222h call EXTBIO ld (ALLOC_SLOT),a ld a,b ld (ALLOC_SEG),a ld (IMPLEM_ENTRY),hl ;* If the implementation is in page 3 ; or in ROM, skip it ld a,h and 10000000b jr nz,NEXT_IMP ld a,b cp 0FFh jr z,NEXT_IMP ;* Call the routine for obtaining ; the implementation information ld a,(ALLOC_SLOT) ld iyh,a ld a,(ALLOC_SEG) ld iyl,a ld ix,(IMPLEM_ENTRY) ld hl,(HELPER_ADD) xor a call CALL_HL ;Returns HL=name address ;* Compare the name of the implementation ; against our own name ld a,(ALLOC_SEG) ld b,a ld de,APIINFO-SEG_CODE_START+SEG_CODE ld ix,(HELPER_ADD) inc ix inc ix inc ix ;Now IX=helper routine to read from segment NAME_LOOP: ld a,(ALLOC_SLOT) push bc push de push hl push ix call CALL_IX pop ix pop hl pop de pop bc ld c,a ld a,(de) cp c jr nz,NEXT_IMP or a inc hl inc de jr nz,NAME_LOOP ;* The names match: already installed ld de,ALINST_S ld c,_STROUT call 5 ld c,_TERM0 jp 5 ;* Names don't match: go to the next implementation NEXT_IMP: pop af dec a jr nz,IMPL_LOOP ;* No more implementations: ; continue installation process NOT_INST: ;--- Obtain the mapper support routines table, if available xor a ld de,0402h call EXTBIO or a jr nz,ALLOC_DOS2 ;--- DOS 1: Use the last segment on the primary mapper ld a,2 ld (MAPTAB_ENTRY_SIZE),a ld hl,(MAPTAB_ADD) ld b,(hl) inc hl ld a,(hl) jr ALLOC_OK ;--- DOS 2: Allocate a segment using mapper support routines ALLOC_DOS2: ld a,b ld (PRIM_SLOT),a ld de,ALL_SEG ld bc,15*3 ldir ld de,0401h call EXTBIO ld (MAPTAB_ADD),hl ld a,8 ld (MAPTAB_ENTRY_SIZE),a ld a,(PRIM_SLOT) or 00100000b ;Try primary mapper, then try others ld b,a ld a,1 ;System segment call ALL_SEG jr nc,ALLOC_OK ld de,NOFREE_S ;Terminate if no free segments available ld c,_STROUT call 5 ld c,_TERM0 jp 5 ALLOC_OK: ld (ALLOC_SEG),a ld a,b ld (ALLOC_SLOT),a ;--- Switch segment, copy code, and setup data call GET_P1 ;Backup current segment ld (P1_SEG),a ld a,(ALLOC_SLOT) ;Switch slot and segment ld h,40h call ENASLT ld a,(ALLOC_SEG) call PUT_P1 ld hl,4000h ;Clear the segment first ld de,4001h ld bc,4000h-1 ld (hl),0 ldir ld hl,SEG_CODE ;Copy the code to the segment ld de,4000h ld bc,SEG_CODE_END-SEG_CODE_START ldir ld hl,(ALLOC_SLOT) ;Setup slot and segment information ld (MY_SLOT),hl ;* Now backup and patch the EXTBIO hook ; so that it calls address 4000h of the allocated segment ld hl,EXTBIO ld de,OLD_EXTBIO ld bc,5 ldir di ld a,0CDh ;Code for "CALL" ld (EXTBIO),a ld hl,(HELPER_ADD) ld bc,6 add hl,bc ;Now HL points to segment call routine ld (EXTBIO+1),hl ld hl,(MAPTAB_ADD) ld a,(ALLOC_SLOT) ld bc,(MAPTAB_ENTRY_SIZE) ld b,0 ld d,a ld e,0 ;Index on mappers table SRCHMAP: ld a,(hl) cp d jr z,MAPFND add hl,bc ;Next table entry inc e jr SRCHMAP MAPFND: ld a,e ;A = Index of slot on mappers table rrca rrca and 11000000b ;Entry point 4010h = index 0 ld (EXTBIO+3),a ld a,(ALLOC_SEG) ld (EXTBIO+4),a ei ;--- Restore slot and segment, and terminate ld a,(PRIM_SLOT) ld h,40h call ENASLT ld a,(P1_SEG) call PUT_P1 ld de,OK_S ld c,_STROUT call 5 ld c,_TERM0 jp 5 ;>>> Other auxiliary code CALL_IX: jp (ix) CALL_HL: jp (hl) ;**************************************************** ;*** DATA AND STRINGS FOR THE INSTALLATION CODE *** ;**************************************************** ;--- Variables PRIM_SLOT: db 0 ;Primary mapper slot number P1_SEG: db 0 ;Segment number for TPA on page 1 ALLOC_SLOT: db 0 ;Slot for the allocated segment ALLOC_SEG: db 0 ;Allocated segment HELPER_ADD: dw 0 ;Address of the RAM helper jump table MAPTAB_ADD: dw 0 ;Address of the mappers table supplied by either DOS 2 or the RAM helper MAPTAB_ENTRY_SIZE: db 0 ;Size of an entry in the mappers table: ;- 8 in DOS 2 (mappers table provided by standard mapper support routines), ;- 2 in DOS 1 (mappers table provided by the RAM helper) IMPLEM_ENTRY: dw 0 ;Entry point for implementations ;--- Mapper support routines, used at install time only ALL_SEG: ds 3 FRE_SEG: ds 3 RD_SEG: ds 3 WR_SEG: ds 3 CAL_SEG: ds 3 CALLS: ds 3 PUT_PH: ds 3 GET_PH: ds 3 PUT_P0: ds 3 GET_P0: ds 3 PUT_P1: jp _PUT_P1 GET_P1: ld a,2 ret PUT_P2: ds 3 GET_P2: ds 3 PUT_P3: ds 3 _PUT_P1: ld (GET_P1+1),a out (0FDh),a ret ;--- Strings ;TODO: Adjust welcome text for your implementation WELCOME_S: db "UNAPI Sample RAM implementation 1.0 (SIMPLE_MATH)",13,10 db "(c) 2019 by Konamiman",13,10 db 13,10 db "$" NOHELPER_S: db "*** ERROR: No UNAPI RAM helper is installed",13,10,"$" NOMAPPER_S: db "*** ERROR: No mapped RAM found",13,10,"$" NOFREE_S: db "*** ERROR: Could not allocate any RAM segment",13,10,"$" OK_S: db "Installed. Have fun!",13,10,"$" ALINST_S: db "*** Already installed.",13,10,"$" ;********************************************* ;*** CODE TO BE INSTALLED ON RAM SEGMENT *** ;********************************************* SEG_CODE: org 4000h SEG_CODE_START: ;=============================== ;=== EXTBIO hook execution === ;=============================== ;>>> Note that this code starts exactly at address 4000h DO_EXTBIO: push hl push bc push af ld a,d cp 22h jr nz,JUMP_OLD cp e jr nz,JUMP_OLD ;Check API ID ld hl,UNAPI_ID ld de,ARG LOOP: ld a,(de) call TOUPPER cp (hl) jr nz,JUMP_OLD2 inc hl inc de or a jr nz,LOOP ;A=255: Jump to old hook pop af push af inc a jr z,JUMP_OLD2 ;A=0: B=B+1 and jump to old hook pop af pop bc or a jr nz,DO_EXTBIO2 inc b pop hl ld de,2222h jp OLD_EXTBIO DO_EXTBIO2: ;A=1: Return A=Slot, B=Segment, HL=UNAPI entry address dec a jr nz,DO_EXTBIO3 pop hl ld a,(MY_SEG) ld b,a ld a,(MY_SLOT) ld hl,UNAPI_ENTRY ld de,2222h ret ;A>1: A=A-1, and jump to old hook DO_EXTBIO3: ;A=A-1 already done pop hl ld de,2222h jp OLD_EXTBIO ;--- Jump here to execute old EXTBIO code JUMP_OLD2: ld de,2222h JUMP_OLD: ;Assumes "push hl,bc,af" done pop af pop bc pop hl ;Old EXTBIO hook contents is here ;(it is setup at installation time) OLD_EXTBIO: ds 5 ;==================================== ;=== Functions entry point code === ;==================================== UNAPI_ENTRY: push hl push af ld hl,FN_TABLE bit 7,a if MAX_IMPFN >= 128 jr z,IS_STANDARD ld hl,IMPFN_TABLE and 01111111b cp MAX_IMPFN-128 jr z,OK_FNUM jr nc,UNDEFINED IS_STANDARD: else jr nz,UNDEFINED endif cp MAX_FN jr z,OK_FNUM jr nc,UNDEFINED OK_FNUM: add a,a push de ld e,a ld d,0 add hl,de pop de ld a,(hl) inc hl ld h,(hl) ld l,a pop af ex (sp),hl ret ;--- Undefined function: return with registers unmodified UNDEFINED: pop af pop hl ret ;=================================== ;=== Functions addresses table === ;=================================== ;TODO: Adjust for the routines of your implementation ;--- Standard routines addresses table FN_TABLE: FN_0: dw FN_INFO FN_1: dw FN_ADD FN_2: dw FN_MULT ;--- Implementation-specific routines addresses table if MAX_IMPFN >= 128 IMPFN_TABLE: FN_128: dw FN_DUMMY endif ;======================== ;=== Functions code === ;======================== ;--- Mandatory routine 0: return API information ; Input: A = 0 ; Output: HL = Descriptive string for this implementation, on this slot, zero terminated ; DE = API version supported, D.E ; BC = This implementation version, B.C. ; A = 0 and Cy = 0 FN_INFO: ld bc,256*ROM_V_P+ROM_V_S ld de,256*API_V_P+API_V_S ld hl,APIINFO xor a ret ;TODO: Replace the FN_* routines below with the appropriate routines for your implementation ;--- Sample routine 1: adds two 8-bit numbers ; Input: E, L = Numbers to add ; Output: HL = Result FN_ADD: ld h,0 ld d,0 add hl,de ret ;--- Sample routine 2: multiplies two 8-bit numbers ; Input: E, L = Numbers to multiply ; Output: HL = Result FN_MULT: ld b,e ld e,l ld d,0 ld hl,0 MULT_LOOP: add hl,de djnz MULT_LOOP ret ;============================ ;=== Auxiliary routines === ;============================ ;--- Convert a character to upper-case if it is a lower-case letter TOUPPER: cp "a" ret c cp "z"+1 ret nc and 0DFh ret ;============================ ;=== UNAPI related data === ;============================ ;This data is setup at installation time MY_SLOT: db 0 MY_SEG: db 0 ;TODO: Adjust this data for your implementation ;--- Specification identifier (up to 15 chars) UNAPI_ID: db "SIMPLE_MATH",0 UNAPI_ID_END: ;--- Implementation name (up to 63 chars and zero terminated) APIINFO: db "Konamiman's RAM implementation of SIMPLE_MATH UNAPI",0 SEG_CODE_END:
/** ****************************************************************************** * Xenia : Xbox 360 Emulator Research Project * ****************************************************************************** * Copyright 2014 Ben Vanik. All rights reserved. * * Released under the BSD license - see LICENSE in the root for more details. * ****************************************************************************** */ #include <xdb/postmortem_debug_target.h> #include <poly/poly.h> #include <xdb/postmortem_cursor.h> #include <xenia/logging.h> namespace xdb { using xdb::protocol::EventType; PostmortemDebugTarget::PostmortemDebugTarget() : file_(nullptr), file_mapping_(nullptr), trace_base_(0), process_start_event_(nullptr), process_exit_event_(nullptr) {} PostmortemDebugTarget::~PostmortemDebugTarget() { if (trace_base_) { UnmapViewOfFile(trace_base_); } CloseHandle(file_mapping_); CloseHandle(file_); } bool PostmortemDebugTarget::LoadTrace(const std::wstring& path, const std::wstring& content_path) { file_ = CreateFile(path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_TEMPORARY, nullptr); if (!file_) { XELOGE("Could not open trace file for writing"); return false; } file_mapping_ = CreateFileMapping(file_, nullptr, PAGE_READONLY, 0, 0, nullptr); if (!file_mapping_) { XELOGE("Could not create trace file mapping"); return false; } trace_base_ = reinterpret_cast<const uint8_t*>( MapViewOfFile(file_mapping_, FILE_MAP_READ, 0, 0, 0)); if (!trace_base_) { XELOGE("Could not map view of trace file"); return false; } // Find the process start event - it should be near the top and we need it for // path lookup. const uint8_t* ptr = trace_base_ + 8; EventType event_type; while ((event_type = poly::load<EventType>(ptr)) != EventType::END_OF_STREAM) { switch (event_type) { case EventType::PROCESS_START: { process_start_event_ = protocol::ProcessStartEvent::Get(ptr); break; } } if (process_start_event_) { break; } ptr += protocol::kEventSizes[static_cast<uint8_t>(event_type)]; } bool initialized_filesystem = false; if (!content_path.empty()) { initialized_filesystem = InitializeFileSystem(content_path); } else { // If no path was provided just use what's in the trace. auto trace_content_path = poly::to_wstring(std::string(process_start_event_->launch_path)); initialized_filesystem = InitializeFileSystem(trace_content_path); } if (!initialized_filesystem) { XELOGE("Unable to initialize filesystem."); return false; } return true; } bool PostmortemDebugTarget::Prepare() { std::atomic<bool> cancelled(false); return Prepare(cancelled); } bool PostmortemDebugTarget::Prepare(std::atomic<bool>& cancelled) { // TODO(benvanik): scan file, build indicies, etc. const uint8_t* ptr = trace_base_ + 8; EventType event_type; while ((event_type = poly::load<EventType>(ptr)) != EventType::END_OF_STREAM) { switch (event_type) { case EventType::PROCESS_START: { assert_true(process_start_event_ == protocol::ProcessStartEvent::Get(ptr)); break; } case EventType::PROCESS_EXIT: { process_exit_event_ = protocol::ProcessExitEvent::Get(ptr); break; } case EventType::MODULE_LOAD: { auto ev = protocol::ModuleLoadEvent::Get(ptr); break; } case EventType::MODULE_UNLOAD: { auto ev = protocol::ModuleUnloadEvent::Get(ptr); break; } case EventType::THREAD_CREATE: { auto ev = protocol::ThreadCreateEvent::Get(ptr); break; } case EventType::THREAD_INFO: { auto ev = protocol::ThreadInfoEvent::Get(ptr); break; } case EventType::THREAD_EXIT: { auto ev = protocol::ThreadExitEvent::Get(ptr); break; } case EventType::FUNCTION_COMPILED: { auto ev = protocol::FunctionCompiledEvent::Get(ptr); break; } case EventType::OUTPUT_STRING: { auto ev = protocol::OutputStringEvent::Get(ptr); break; } case EventType::KERNEL_CALL: { auto ev = protocol::KernelCallEvent::Get(ptr); break; } case EventType::KERNEL_CALL_RETURN: { auto ev = protocol::KernelCallReturnEvent::Get(ptr); break; } case EventType::USER_CALL: { auto ev = protocol::UserCallEvent::Get(ptr); break; } case EventType::USER_CALL_RETURN: { auto ev = protocol::UserCallReturnEvent::Get(ptr); break; } case EventType::INSTR: { auto ev = protocol::InstrEvent::Get(ptr); break; } case EventType::INSTR_R8: { auto ev = protocol::InstrEventR8::Get(ptr); break; } case EventType::INSTR_R8_R8: { auto ev = protocol::InstrEventR8R8::Get(ptr); break; } case EventType::INSTR_R8_R16: { auto ev = protocol::InstrEventR8R16::Get(ptr); break; } case EventType::INSTR_R16: { auto ev = protocol::InstrEventR16::Get(ptr); break; } case EventType::INSTR_R16_R8: { auto ev = protocol::InstrEventR16R8::Get(ptr); break; } case EventType::INSTR_R16_R16: { auto ev = protocol::InstrEventR16R16::Get(ptr); break; } } ptr += protocol::kEventSizes[static_cast<uint8_t>(event_type)]; }; trace_length_ = ptr - trace_base_; return true; } std::unique_ptr<Cursor> PostmortemDebugTarget::CreateCursor() { auto cursor = std::make_unique<PostmortemCursor>(this); return std::unique_ptr<Cursor>(cursor.release()); } } // namespace xdb
/* ----------------------------------------------------------------------------- This source file is part of OGRE (Object-oriented Graphics Rendering Engine) For the latest info, see http://www.ogre3d.org/ Copyright (c) 2000-2014 Torus Knot Software Ltd 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 "OgreCgProgram.h" #include "OgreGpuProgramManager.h" #include "OgreHighLevelGpuProgramManager.h" #include "OgreStringConverter.h" #include "OgreLogManager.h" #include <cctype> namespace Ogre { //----------------------------------------------------------------------- CgProgram::CmdEntryPoint CgProgram::msCmdEntryPoint; CgProgram::CmdProfiles CgProgram::msCmdProfiles; CgProgram::CmdArgs CgProgram::msCmdArgs; //----------------------------------------------------------------------- void CgProgram::selectProfile(void) { static const String specialCgProfiles[] = {"hlslv", "hlslf", "glslv", "glslf", "glslg"}; static const size_t specialCgProfilesCount = sizeof(specialCgProfiles)/sizeof(String); static const String* specialCgProfilesEnd = specialCgProfiles + specialCgProfilesCount; mSelectedProfile.clear(); mSelectedCgProfile = CG_PROFILE_UNKNOWN; StringVector::iterator i, iend; iend = mProfiles.end(); GpuProgramManager& gpuMgr = GpuProgramManager::getSingleton(); bool useDelegate = false; for (i = mProfiles.begin(); i != iend; ++i) { bool syntaxSupported = gpuMgr.isSyntaxSupported(*i); if (!syntaxSupported && find(specialCgProfiles, specialCgProfilesEnd, *i) != specialCgProfilesEnd) { // Cg has some "special" profiles which don't have direct equivalents // in the GpuProgramManager's supported syntaxes. // For now, the following works if (gpuMgr.isSyntaxSupported(i->substr(0, 4))) { syntaxSupported = true; useDelegate = true; } } if (syntaxSupported) { mSelectedProfile = *i; String selectedProfileForFind = mSelectedProfile; if(StringUtil::startsWith(mSelectedProfile,"vs_4_0_", true)) { selectedProfileForFind = "vs_4_0"; } if(StringUtil::startsWith(mSelectedProfile,"ps_4_0_", true)) { selectedProfileForFind = "ps_4_0"; } mSelectedCgProfile = cgGetProfile(selectedProfileForFind.c_str()); // Check for errors checkForCgError("CgProgram::selectProfile", "Unable to find CG profile enum for program " + mName + ": ", mCgContext); // do we need a delegate? if (useDelegate && !mDelegate) { mDelegate = HighLevelGpuProgramManager::getSingleton().createProgram( mName+"/Delegate", mGroup, getHighLevelLanguage(), mType); mDelegate->setParameter("target", getHighLevelTarget()); mDelegate->setParameter("entry_point", "main"); // HLSL/GLSL output uses row major matrices, so need to tell Ogre that mDelegate->setParameter("column_major_matrices", "false"); // HLSL output requires backwards compatibility to be enabled mDelegate->setParameter("backwards_compatibility", "true"); } else if (!useDelegate && mDelegate) { ResourcePtr rs (mDelegate); HighLevelGpuProgramManager::getSingleton().remove(rs); mDelegate.reset(); } break; } } } //----------------------------------------------------------------------- void CgProgram::buildArgs(void) { StringVector args; if (!mPreprocessorDefines.empty()) args = StringUtil::split(mPreprocessorDefines); StringVector::const_iterator i; if (mSelectedCgProfile == CG_PROFILE_VS_1_1) { // Need the 'dcls' argument whenever we use this profile // otherwise compilation of the assembler will fail bool dclsFound = false; for (i = args.begin(); i != args.end(); ++i) { if (*i == "dcls") { dclsFound = true; break; } } if (!dclsFound) { args.push_back("-profileopts"); args.push_back("dcls"); } } // Now split args into that god-awful char** that Cg insists on freeCgArgs(); mCgArguments = OGRE_ALLOC_T(char*, args.size() + 1, MEMCATEGORY_RESOURCE); int index = 0; for (i = args.begin(); i != args.end(); ++i, ++index) { mCgArguments[index] = OGRE_ALLOC_T(char, i->length() + 1, MEMCATEGORY_RESOURCE); strcpy(mCgArguments[index], i->c_str()); } // Null terminate list mCgArguments[index] = 0; } //----------------------------------------------------------------------- void CgProgram::freeCgArgs(void) { if (mCgArguments) { size_t index = 0; char* current = mCgArguments[index]; while (current) { OGRE_FREE(current, MEMCATEGORY_RESOURCE); mCgArguments[index] = 0; current = mCgArguments[++index]; } OGRE_FREE(mCgArguments, MEMCATEGORY_RESOURCE); mCgArguments = 0; } } //----------------------------------------------------------------------- void CgProgram::loadFromSource(void) { selectProfile(); if ( GpuProgramManager::getSingleton().isMicrocodeAvailableInCache(String("CG_") + mName) ) { getMicrocodeFromCache(); } else { compileMicrocode(); } if (mDelegate) { mDelegate->setSource(mProgramString); mDelegate->setAdjacencyInfoRequired(isAdjacencyInfoRequired()); if (mSelectedCgProfile == CG_PROFILE_GLSLG) { // need to set input and output operations if (mInputOp == CG_POINT) { mDelegate->setParameter("input_operation_type", "point_list"); } else if (mInputOp == CG_LINE) { mDelegate->setParameter("input_operation_type", "line_strip"); } else if (mInputOp == CG_LINE_ADJ) { mDelegate->setParameter("input_operation_type", "line_strip"); mDelegate->setAdjacencyInfoRequired(true); } else if (mInputOp == CG_TRIANGLE) { mDelegate->setParameter("input_operation_type", "triangle_strip"); } else if (mInputOp == CG_TRIANGLE_ADJ) { mDelegate->setParameter("input_operation_type", "triangle_strip"); mDelegate->setAdjacencyInfoRequired(true); } if (mOutputOp == CG_POINT_OUT) mDelegate->setParameter("output_operation_type", "point_list"); else if (mOutputOp == CG_LINE_OUT) mDelegate->setParameter("output_operation_type", "line_strip"); else if (mOutputOp == CG_TRIANGLE_OUT) mDelegate->setParameter("output_operation_type", "triangle_strip"); } if (getHighLevelLanguage() == "glsl") { // for GLSL, also ensure we explicitly bind samplers to their register // otherwise, GLSL will assign them in the order first used, which is // not what we want. GpuProgramParametersSharedPtr params = mDelegate->getDefaultParameters(); for (map<String,int>::type::iterator i = mSamplerRegisterMap.begin(); i != mSamplerRegisterMap.end(); ++i) params->setNamedConstant(i->first, i->second); } mDelegate->load(); } } //----------------------------------------------------------------------- void CgProgram::getMicrocodeFromCache(void) { GpuProgramManager::Microcode cacheMicrocode = GpuProgramManager::getSingleton().getMicrocodeFromCache(String("CG_") + mName); cacheMicrocode->seek(0); // get size of string size_t programStringSize = 0; cacheMicrocode->read(&programStringSize, sizeof(size_t)); // get microcode mProgramString.resize(programStringSize); cacheMicrocode->read(&mProgramString[0], programStringSize); // get size of param map size_t parametersMapSize = 0; cacheMicrocode->read(&parametersMapSize, sizeof(size_t)); // get params for(size_t i = 0 ; i < parametersMapSize ; i++) { String paramName; size_t stringSize = 0; GpuConstantDefinition def; // get string size cacheMicrocode->read(&stringSize, sizeof(size_t)); // get string paramName.resize(stringSize); cacheMicrocode->read(&paramName[0], stringSize); // get def cacheMicrocode->read( &def, sizeof(GpuConstantDefinition)); mParametersMap.insert(GpuConstantDefinitionMap::value_type(paramName, def)); } if (mDelegate) { // get sampler register mapping size_t samplerMapSize = 0; cacheMicrocode->read(&samplerMapSize, sizeof(size_t)); for (size_t i = 0; i < samplerMapSize; ++i) { String paramName; size_t stringSize = 0; int reg = -1; cacheMicrocode->read(&stringSize, sizeof(size_t)); paramName.resize(stringSize); cacheMicrocode->read(&paramName[0], stringSize); cacheMicrocode->read(&reg, sizeof(int)); } // get input/output operations type cacheMicrocode->read(&mInputOp, sizeof(CGenum)); cacheMicrocode->read(&mOutputOp, sizeof(CGenum)); } } //----------------------------------------------------------------------- void CgProgram::compileMicrocode(void) { // Create Cg Program /// Program handle CGprogram cgProgram; if (mSelectedCgProfile == CG_PROFILE_UNKNOWN) { LogManager::getSingleton().logMessage( "Attempted to load Cg program '" + mName + "', but no supported " "profile was found. "); return; } buildArgs(); // deal with includes String sourceToUse = resolveCgIncludes(mSource, this, mFilename); cgProgram = cgCreateProgram(mCgContext, CG_SOURCE, sourceToUse.c_str(), mSelectedCgProfile, mEntryPoint.c_str(), const_cast<const char**>(mCgArguments)); // Test //LogManager::getSingleton().logMessage(cgGetProgramString(mCgProgram, CG_COMPILED_PROGRAM)); // Check for errors checkForCgError("CgProgram::compileMicrocode", "Unable to compile Cg program " + mName + ": ", mCgContext); CGerror error = cgGetError(); if (error == CG_NO_ERROR) { // get program string (result of cg compile) mProgramString = cgGetProgramString(cgProgram, CG_COMPILED_PROGRAM); checkForCgError("CgProgram::compileMicrocode", "Unable to retrieve program code for Cg program " + mName + ": ", mCgContext); // get params mParametersMap.clear(); mParametersMapSizeAsBuffer = 0; mSamplerRegisterMap.clear(); recurseParams(cgGetFirstParameter(cgProgram, CG_PROGRAM)); recurseParams(cgGetFirstParameter(cgProgram, CG_GLOBAL)); if (mDelegate) { // Delegating to HLSL or GLSL, need to clean up Cg's output fixHighLevelOutput(mProgramString); if (mSelectedCgProfile == CG_PROFILE_GLSLG) { // need to determine input and output operations mInputOp = cgGetProgramInput(cgProgram); mOutputOp = cgGetProgramOutput(cgProgram); } } // Unload Cg Program - we don't need it anymore cgDestroyProgram(cgProgram); //checkForCgError("CgProgram::unloadImpl", // "Error while unloading Cg program " + mName + ": ", // mCgContext); cgProgram = 0; if ( GpuProgramManager::getSingleton().getSaveMicrocodesToCache()) { addMicrocodeToCache(); } } } //----------------------------------------------------------------------- void CgProgram::addMicrocodeToCache() { String name = String("CG_") + mName; size_t programStringSize = mProgramString.size(); uint32 sizeOfMicrocode = static_cast<uint32>( sizeof(size_t) + // size of mProgramString programStringSize + // microcode - mProgramString sizeof(size_t) + // size of param map mParametersMapSizeAsBuffer); // create microcode GpuProgramManager::Microcode newMicrocode = GpuProgramManager::getSingleton().createMicrocode(sizeOfMicrocode); newMicrocode->seek(0); // save size of string newMicrocode->write(&programStringSize, sizeof(size_t)); // save microcode newMicrocode->write(&mProgramString[0], programStringSize); // save size of param map size_t parametersMapSize = mParametersMap.size(); newMicrocode->write(&parametersMapSize, sizeof(size_t)); // save params GpuConstantDefinitionMap::const_iterator iter = mParametersMap.begin(); GpuConstantDefinitionMap::const_iterator iterE = mParametersMap.end(); for (; iter != iterE ; iter++) { const String & paramName = iter->first; const GpuConstantDefinition & def = iter->second; // save string size size_t stringSize = paramName.size(); newMicrocode->write(&stringSize, sizeof(size_t)); // save string newMicrocode->write(&paramName[0], stringSize); // save def newMicrocode->write(&def, sizeof(GpuConstantDefinition)); } if (mDelegate) { // save additional info required for delegating size_t samplerMapSize = mSamplerRegisterMap.size(); newMicrocode->write(&samplerMapSize, sizeof(size_t)); // save sampler register mapping map<String,int>::type::const_iterator sampRegister = mSamplerRegisterMap.begin(); map<String,int>::type::const_iterator sampRegisterE = mSamplerRegisterMap.end(); for (; sampRegister != sampRegisterE; ++sampRegister) { const String& paramName = sampRegister->first; int reg = sampRegister->second; size_t stringSize = paramName.size(); newMicrocode->write(&stringSize, sizeof(size_t)); newMicrocode->write(paramName.data(), stringSize); newMicrocode->write(&reg, sizeof(int)); } // save input/output operations type newMicrocode->write(&mInputOp, sizeof(CGenum)); newMicrocode->write(&mOutputOp, sizeof(CGenum)); } // add to the microcode to the cache GpuProgramManager::getSingleton().addMicrocodeToCache(name, newMicrocode); } //----------------------------------------------------------------------- void CgProgram::createLowLevelImpl(void) { if (mDelegate) return; // ignore any previous error if (mSelectedCgProfile != CG_PROFILE_UNKNOWN && !mCompileError) { if ( false // the hlsl 4 profiles are only supported in OGRE from CG 2.2 #if(CG_VERSION_NUM >= 2200) || mSelectedCgProfile == CG_PROFILE_VS_4_0 || mSelectedCgProfile == CG_PROFILE_PS_4_0 #endif #if(CG_VERSION_NUM >= 3000) || mSelectedCgProfile == CG_PROFILE_VS_5_0 || mSelectedCgProfile == CG_PROFILE_PS_5_0 || mSelectedCgProfile == CG_PROFILE_DS_5_0 || mSelectedCgProfile == CG_PROFILE_HS_5_0 #endif ) { // Create a high-level program, give it the same name as us HighLevelGpuProgramManager::getSingleton().remove(mName, mGroup); HighLevelGpuProgramPtr vp = HighLevelGpuProgramManager::getSingleton().createProgram( mName, mGroup, "hlsl", mType); vp->setSource(mProgramString); vp->setParameter("target", mSelectedProfile); vp->setParameter("entry_point", "main"); vp->load(); mAssemblerProgram = vp; } else { // Create a low-level program, give it the same name as us mAssemblerProgram = GpuProgramManager::getSingleton().createProgramFromString( mName, mGroup, mProgramString, mType, mSelectedProfile); } // Shader params need to be forwarded to low level implementation mAssemblerProgram->setAdjacencyInfoRequired(isAdjacencyInfoRequired()); } } //----------------------------------------------------------------------- String CgProgram::getHighLevelLanguage() const { switch (mSelectedCgProfile) { case CG_PROFILE_GLSLF: case CG_PROFILE_GLSLV: case CG_PROFILE_GLSLG: case CG_PROFILE_GLSLC: return "glsl"; case CG_PROFILE_HLSLF: case CG_PROFILE_HLSLV: return "hlsl"; default: return "unknown"; } } //----------------------------------------------------------------------- String CgProgram::getHighLevelTarget() const { // HLSL delegates need a target to compile to. // Return value for GLSL delegates is ignored. GpuProgramManager* gpuMgr = GpuProgramManager::getSingletonPtr(); if (mSelectedCgProfile == CG_PROFILE_HLSLF) { static const String fpProfiles[] = { #if(CG_VERSION_NUM >= 3000) "ps_5_0", #endif #if(CG_VERSION_NUM >= 2200) "ps_4_0", #endif "ps_3_0", "ps_2_x", "ps_2_0", "ps_1_4", "ps_1_3", "ps_1_2", "ps_1_1"}; static const size_t numFpProfiles = sizeof(fpProfiles)/sizeof(String); // find the highest profile available for (size_t i = 0; i < numFpProfiles; ++i) { if (gpuMgr->isSyntaxSupported(fpProfiles[i])) return fpProfiles[i]; } } else if (mSelectedCgProfile == CG_PROFILE_HLSLV) { static const String vpProfiles[] = { #if(CG_VERSION_NUM >= 3000) "vs_5_0", #endif #if(CG_VERSION_NUM >= 2200) "vs_4_0", #endif "vs_3_0", "vs_2_x", "vs_2_0", "vs_1_4", "vs_1_3", "vs_1_2", "vs_1_1"}; static const size_t numVpProfiles = sizeof(vpProfiles)/sizeof(String); // find the highest profile available for (size_t i = 0; i < numVpProfiles; ++i) { if (gpuMgr->isSyntaxSupported(vpProfiles[i])) return vpProfiles[i]; } } return "unknown"; } //----------------------------------------------------------------------- struct HighLevelOutputFixer { const String& source; const GpuConstantDefinitionMap& paramMap; const map<String,int>::type samplerMap; bool glsl; String output; map<String,String>::type paramNameMap; String::size_type start; struct ReplacementMark { String::size_type pos, len; String replaceWith; bool operator<(const ReplacementMark& o) const { return pos < o.pos; } }; vector<ReplacementMark>::type replacements; HighLevelOutputFixer(const String& src, const GpuConstantDefinitionMap& params, const map<String,int>::type& samplers, bool isGLSL) : source(src), paramMap(params), samplerMap(samplers), glsl(isGLSL), start(0) { findNameMappings(); replaceParameterNames(); buildOutput(); } void findNameMappings() { String::size_type cur = 0, end = 0; while (cur < source.size()) { // look for a comment line describing a parameter name mapping // comment format: //var type parameter : [something] : new name : [something] : [something] cur = source.find("//var", cur); if (cur == String::npos) break; end = source.find('\n', cur); vector<String>::type cols = StringUtil::split(source.substr(cur, end-cur), ":"); cur = end; if (cols.size() < 3) continue; vector<String>::type def = StringUtil::split(cols[0], "[ "); if (def.size() < 3) continue; StringUtil::trim(cols[2]); vector<String>::type repl = StringUtil::split(cols[2], "[ "); String oldName = def[2]; String newName = repl[0]; StringUtil::trim(oldName); StringUtil::trim(newName); if (newName.empty() || newName[0] != '_') continue; // if that name is present in our lists, mark in name translation map GpuConstantDefinitionMap::const_iterator it = paramMap.find(oldName); if (it != paramMap.end() || samplerMap.find(oldName) != samplerMap.end()) { LogManager::getSingleton().stream() << "Replacing parameter name: " << newName << " -> " << oldName; paramNameMap.insert(std::make_pair(oldName, newName)); } } // end now points at the end of the last comment, so we can strip anything before start = (end == String::npos ? end : end+1); } void replaceParameterNames() { for (GpuConstantDefinitionMap::const_iterator it = paramMap.begin(); it != paramMap.end(); ++it) { const String& oldName = it->first; map<String,String>::type::const_iterator pi = paramNameMap.find(oldName); if (pi != paramNameMap.end()) { const String& newName = pi->second; String::size_type beg = start; // do we need to replace the definition of the parameter? (GLSL only) if (glsl) { if (it->second.constType == GCT_MATRIX_2X2) beg = findAndMark("uniform vec2 "+newName+"[2]", "uniform mat2 "+oldName, beg); else if (it->second.constType == GCT_MATRIX_3X3) beg = findAndMark("uniform vec3 "+newName+"[3]", "uniform mat3 "+oldName, beg); else if (it->second.constType == GCT_MATRIX_4X4) beg = findAndMark("uniform vec4 "+newName+"[4]", "uniform mat4 "+oldName, beg); else if (it->second.constType == GCT_MATRIX_2X3) beg = findAndMark("uniform vec3 "+newName+"[2]", "uniform mat2x3 "+oldName, beg); else if (it->second.constType == GCT_MATRIX_2X4) beg = findAndMark("uniform vec4 "+newName+"[2]", "uniform mat2x4 "+oldName, beg); else if (it->second.constType == GCT_MATRIX_3X2) beg = findAndMark("uniform vec2 "+newName+"[3]", "uniform mat3x2 "+oldName, beg); else if (it->second.constType == GCT_MATRIX_3X4) beg = findAndMark("uniform vec4 "+newName+"[3]", "uniform mat3x4 "+oldName, beg); else if (it->second.constType == GCT_MATRIX_4X2) beg = findAndMark("uniform vec2 "+newName+"[4]", "uniform mat4x2 "+oldName, beg); else if (it->second.constType == GCT_MATRIX_4X3) beg = findAndMark("uniform vec3 "+newName+"[4]", "uniform mat4x3 "+oldName, beg); } // mark all occurrences of the parameter name for replacement findAndMark(newName, oldName, beg); } } for (map<String,int>::type::const_iterator it = samplerMap.begin(); it != samplerMap.end(); ++it) { const String& oldName = it->first; map<String,String>::type::const_iterator pi = paramNameMap.find(oldName); if (pi != paramNameMap.end()) { const String& newName = pi->second; findAndMark(newName, oldName, start); } } } String::size_type findAndMark(const String& search, const String& replaceWith, String::size_type cur) { ReplacementMark mark; mark.pos = String::npos; mark.len = search.size(); mark.replaceWith = replaceWith; while (cur < source.size()) { cur = source.find(search, cur); if (cur == String::npos) break; mark.pos = cur; cur += search.size(); // check if previous or following character continue an identifier // in that case, skip this occurrence as it's part of a longer identifier if (mark.pos > 0) { char c = source[mark.pos-1]; if (c == '_' || std::isalnum(c)) continue; } if (mark.pos+1 < search.size()) { char c = source[mark.pos+1]; if (c == '_' || std::isalnum(c)) continue; } replacements.push_back(mark); } if (mark.pos != String::npos) return mark.pos + search.size(); else return String::npos; } void buildOutput() { // sort replacements in order of occurrence std::sort(replacements.begin(), replacements.end()); String::size_type cur = start; for (vector<ReplacementMark>::type::iterator it = replacements.begin(); it != replacements.end(); ++it) { ReplacementMark& mark = *it; if (mark.pos > cur) output.append(source, cur, mark.pos-cur); output.append(mark.replaceWith); cur = mark.pos+mark.len; } if (cur < source.size()) output.append(source, cur, String::npos); } }; //----------------------------------------------------------------------- void CgProgram::fixHighLevelOutput(String& hlSource) { // Cg chooses to change parameter names when translating to another // high level language, possibly to avoid clashes with reserved keywords. // We need to revert that, otherwise Ogre parameter mappings fail. // Cg logs its renamings in the comments at the beginning of the // processed source file. We can get them from there. // We'll also get rid of those comments to trim down source code size. #if OGRE_DEBUG_MODE LogManager::getSingleton().stream() << "Cg high level output for " << getName() << ":\n" << hlSource; #endif hlSource = HighLevelOutputFixer(hlSource, mParametersMap, mSamplerRegisterMap, mSelectedCgProfile == CG_PROFILE_GLSLV || mSelectedCgProfile == CG_PROFILE_GLSLF || mSelectedCgProfile == CG_PROFILE_GLSLG).output; #if OGRE_DEBUG_MODE LogManager::getSingleton().stream() << "Cleaned high level output for " << getName() << ":\n" << hlSource; #endif } //----------------------------------------------------------------------- void CgProgram::loadHighLevelSafe() { OGRE_LOCK_AUTO_MUTEX; if (this->isSupported()) loadHighLevel(); } //----------------------------------------------------------------------- GpuProgramParametersSharedPtr CgProgram::createParameters() { loadHighLevelSafe(); if (mDelegate) return mDelegate->createParameters(); else return HighLevelGpuProgram::createParameters(); } //----------------------------------------------------------------------- GpuProgram* CgProgram::_getBindingDelegate() { if (mDelegate) return mDelegate->_getBindingDelegate(); else return HighLevelGpuProgram::_getBindingDelegate(); } //----------------------------------------------------------------------- bool CgProgram::isSkeletalAnimationIncluded(void) const { if (mDelegate) return mDelegate->isSkeletalAnimationIncluded(); else return HighLevelGpuProgram::isSkeletalAnimationIncluded(); } //----------------------------------------------------------------------- bool CgProgram::isMorphAnimationIncluded(void) const { if (mDelegate) return mDelegate->isMorphAnimationIncluded(); else return HighLevelGpuProgram::isMorphAnimationIncluded(); } //----------------------------------------------------------------------- bool CgProgram::isPoseAnimationIncluded(void) const { if (mDelegate) return mDelegate->isPoseAnimationIncluded(); else return HighLevelGpuProgram::isPoseAnimationIncluded(); } //----------------------------------------------------------------------- bool CgProgram::isVertexTextureFetchRequired(void) const { if (mDelegate) return mDelegate->isVertexTextureFetchRequired(); else return HighLevelGpuProgram::isVertexTextureFetchRequired(); } //----------------------------------------------------------------------- GpuProgramParametersSharedPtr CgProgram::getDefaultParameters(void) { loadHighLevelSafe(); if (mDelegate) return mDelegate->getDefaultParameters(); else return HighLevelGpuProgram::getDefaultParameters(); } //----------------------------------------------------------------------- bool CgProgram::hasDefaultParameters(void) const { if (mDelegate) return mDelegate->hasDefaultParameters(); else return HighLevelGpuProgram::hasDefaultParameters(); } //----------------------------------------------------------------------- bool CgProgram::getPassSurfaceAndLightStates(void) const { if (mDelegate) return mDelegate->getPassSurfaceAndLightStates(); else return HighLevelGpuProgram::getPassSurfaceAndLightStates(); } //----------------------------------------------------------------------- bool CgProgram::getPassFogStates(void) const { if (mDelegate) return mDelegate->getPassFogStates(); else return HighLevelGpuProgram::getPassFogStates(); } //----------------------------------------------------------------------- bool CgProgram::getPassTransformStates(void) const { if (mDelegate) return mDelegate->getPassTransformStates(); else { return true; /* CG uses MVP matrix when -posinv argument passed */ } } //----------------------------------------------------------------------- bool CgProgram::hasCompileError(void) const { if (mDelegate) return mDelegate->hasCompileError(); else return HighLevelGpuProgram::hasCompileError(); } //----------------------------------------------------------------------- void CgProgram::resetCompileError(void) { if (mDelegate) mDelegate->resetCompileError(); else HighLevelGpuProgram::resetCompileError(); } //----------------------------------------------------------------------- size_t CgProgram::getSize() const { if (mDelegate) return mDelegate->getSize(); else return HighLevelGpuProgram::getSize(); } //----------------------------------------------------------------------- void CgProgram::touch() { if (mDelegate) mDelegate->touch(); else HighLevelGpuProgram::touch(); } //----------------------------------------------------------------------- void CgProgram::unloadHighLevelImpl(void) { if (mDelegate) { mDelegate->getCreator()->remove(mDelegate); mDelegate.reset(); } } //----------------------------------------------------------------------- void CgProgram::buildConstantDefinitions() const { // Derive parameter names from Cg createParameterMappingStructures(true); if ( mProgramString.empty() ) return; mConstantDefs->floatBufferSize = mFloatLogicalToPhysical->bufferSize; mConstantDefs->intBufferSize = mIntLogicalToPhysical->bufferSize; GpuConstantDefinitionMap::const_iterator iter = mParametersMap.begin(); GpuConstantDefinitionMap::const_iterator iterE = mParametersMap.end(); for (; iter != iterE ; iter++) { const String & paramName = iter->first; GpuConstantDefinition def = iter->second; mConstantDefs->map.insert(GpuConstantDefinitionMap::value_type(iter->first, iter->second)); // Record logical / physical mapping if (def.isFloat()) { OGRE_LOCK_MUTEX(mFloatLogicalToPhysical->mutex); mFloatLogicalToPhysical->map.insert( GpuLogicalIndexUseMap::value_type(def.logicalIndex, GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, GPV_GLOBAL))); mFloatLogicalToPhysical->bufferSize += def.arraySize * def.elementSize; } else { OGRE_LOCK_MUTEX(mIntLogicalToPhysical->mutex); mIntLogicalToPhysical->map.insert( GpuLogicalIndexUseMap::value_type(def.logicalIndex, GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, GPV_GLOBAL))); mIntLogicalToPhysical->bufferSize += def.arraySize * def.elementSize; } // Deal with array indexing mConstantDefs->generateConstantDefinitionArrayEntries(paramName, def); } } //--------------------------------------------------------------------- void CgProgram::recurseParams(CGparameter parameter, size_t contextArraySize) { while (parameter != 0) { // Look for uniform parameters only // Don't bother enumerating unused parameters, especially since they will // be optimised out and therefore not in the indexed versions CGtype paramType = cgGetParameterType(parameter); if (cgGetParameterVariability(parameter) == CG_UNIFORM && paramType != CG_SAMPLER1D && paramType != CG_SAMPLER2D && paramType != CG_SAMPLER3D && paramType != CG_SAMPLERCUBE && paramType != CG_SAMPLERRECT && cgGetParameterDirection(parameter) != CG_OUT && cgIsParameterReferenced(parameter)) { int arraySize; switch(paramType) { case CG_STRUCT: recurseParams(cgGetFirstStructParameter(parameter)); break; case CG_ARRAY: // Support only 1-dimensional arrays arraySize = cgGetArraySize(parameter, 0); recurseParams(cgGetArrayParameter(parameter, 0), (size_t)arraySize); break; default: // Normal path (leaf) String paramName = cgGetParameterName(parameter); size_t logicalIndex = cgGetParameterResourceIndex(parameter); // Get the parameter resource, to calculate the physical index CGresource res = cgGetParameterResource(parameter); bool isRegisterCombiner = false; size_t regCombinerPhysicalIndex = 0; switch (res) { case CG_COMBINER_STAGE_CONST0: // register combiner, const 0 // the index relates to the texture stage; store this as (stage * 2) + 0 regCombinerPhysicalIndex = logicalIndex * 2; isRegisterCombiner = true; break; case CG_COMBINER_STAGE_CONST1: // register combiner, const 1 // the index relates to the texture stage; store this as (stage * 2) + 1 regCombinerPhysicalIndex = (logicalIndex * 2) + 1; isRegisterCombiner = true; break; default: // normal constant break; } // Trim the '[0]' suffix if it exists, we will add our own indexing later if (StringUtil::endsWith(paramName, "[0]", false)) { paramName.erase(paramName.size() - 3); } GpuConstantDefinition def; def.arraySize = contextArraySize; mapTypeAndElementSize(paramType, isRegisterCombiner, def); if (def.constType == GCT_UNKNOWN) { LogManager::getSingleton().logMessage( "Problem parsing the following Cg Uniform: '" + paramName + "' in file " + mName); // next uniform parameter = cgGetNextParameter(parameter); continue; } if (isRegisterCombiner) { def.physicalIndex = regCombinerPhysicalIndex; } else { // base position on existing buffer contents if (def.isFloat()) { def.physicalIndex = mFloatLogicalToPhysical->bufferSize; } else { def.physicalIndex = mIntLogicalToPhysical->bufferSize; } } def.logicalIndex = logicalIndex; if( mParametersMap.find(paramName) == mParametersMap.end()) { mParametersMap.insert(GpuConstantDefinitionMap::value_type(paramName, def)); mParametersMapSizeAsBuffer += sizeof(size_t); mParametersMapSizeAsBuffer += paramName.size(); mParametersMapSizeAsBuffer += sizeof(GpuConstantDefinition); } // Record logical / physical mapping if (def.isFloat()) { OGRE_LOCK_MUTEX(mFloatLogicalToPhysical->mutex); mFloatLogicalToPhysical->map.insert( GpuLogicalIndexUseMap::value_type(def.logicalIndex, GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, GPV_GLOBAL))); mFloatLogicalToPhysical->bufferSize += def.arraySize * def.elementSize; } else { OGRE_LOCK_MUTEX(mIntLogicalToPhysical->mutex); mIntLogicalToPhysical->map.insert( GpuLogicalIndexUseMap::value_type(def.logicalIndex, GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, GPV_GLOBAL))); mIntLogicalToPhysical->bufferSize += def.arraySize * def.elementSize; } break; } } // now handle uniform samplers. This is needed to fix their register positions // if delegating to a GLSL shader. if (mDelegate && cgGetParameterVariability(parameter) == CG_UNIFORM && ( paramType == CG_SAMPLER1D || paramType == CG_SAMPLER2D || paramType == CG_SAMPLER3D || paramType == CG_SAMPLERCUBE || paramType == CG_SAMPLERRECT) && cgGetParameterDirection(parameter) != CG_OUT && cgIsParameterReferenced(parameter)) { String paramName = cgGetParameterName(parameter); CGresource res = cgGetParameterResource(parameter); int pos = -1; switch (res) { case CG_TEXUNIT0: pos = 0; break; case CG_TEXUNIT1: pos = 1; break; case CG_TEXUNIT2: pos = 2; break; case CG_TEXUNIT3: pos = 3; break; case CG_TEXUNIT4: pos = 4; break; case CG_TEXUNIT5: pos = 5; break; case CG_TEXUNIT6: pos = 6; break; case CG_TEXUNIT7: pos = 7; break; case CG_TEXUNIT8: pos = 8; break; case CG_TEXUNIT9: pos = 9; break; case CG_TEXUNIT10: pos = 10; break; case CG_TEXUNIT11: pos = 11; break; case CG_TEXUNIT12: pos = 12; break; case CG_TEXUNIT13: pos = 13; break; case CG_TEXUNIT14: pos = 14; break; case CG_TEXUNIT15: pos = 15; break; #if(CG_VERSION_NUM >= 3000) case CG_TEXUNIT16: pos = 16; break; case CG_TEXUNIT17: pos = 17; break; case CG_TEXUNIT18: pos = 18; break; case CG_TEXUNIT19: pos = 19; break; case CG_TEXUNIT20: pos = 20; break; case CG_TEXUNIT21: pos = 21; break; case CG_TEXUNIT22: pos = 22; break; case CG_TEXUNIT23: pos = 23; break; case CG_TEXUNIT24: pos = 24; break; case CG_TEXUNIT25: pos = 25; break; case CG_TEXUNIT26: pos = 26; break; case CG_TEXUNIT27: pos = 27; break; case CG_TEXUNIT28: pos = 28; break; case CG_TEXUNIT29: pos = 29; break; case CG_TEXUNIT30: pos = 30; break; case CG_TEXUNIT31: pos = 31; break; #endif default: break; } if (pos != -1) { mSamplerRegisterMap.insert(std::make_pair(paramName, pos)); } } // Get next parameter = cgGetNextParameter(parameter); } } //----------------------------------------------------------------------- void CgProgram::mapTypeAndElementSize(CGtype cgType, bool isRegisterCombiner, GpuConstantDefinition& def) const { if (isRegisterCombiner) { // register combiners are the only single-float entries in our buffer def.constType = GCT_FLOAT1; def.elementSize = 1; } else { switch(cgType) { case CG_FLOAT: case CG_FLOAT1: case CG_HALF: case CG_HALF1: def.constType = GCT_FLOAT1; break; case CG_FLOAT2: case CG_HALF2: def.constType = GCT_FLOAT2; break; case CG_FLOAT3: case CG_HALF3: def.constType = GCT_FLOAT3; break; case CG_FLOAT4: case CG_HALF4: def.constType = GCT_FLOAT4; break; case CG_FLOAT2x2: case CG_HALF2x2: def.constType = GCT_MATRIX_2X2; break; case CG_FLOAT2x3: case CG_HALF2x3: def.constType = GCT_MATRIX_2X3; break; case CG_FLOAT2x4: case CG_HALF2x4: def.constType = GCT_MATRIX_2X4; break; case CG_FLOAT3x2: case CG_HALF3x2: def.constType = GCT_MATRIX_3X2; break; case CG_FLOAT3x3: case CG_HALF3x3: def.constType = GCT_MATRIX_3X3; break; case CG_FLOAT3x4: case CG_HALF3x4: def.constType = GCT_MATRIX_3X4; break; case CG_FLOAT4x2: case CG_HALF4x2: def.constType = GCT_MATRIX_4X2; break; case CG_FLOAT4x3: case CG_HALF4x3: def.constType = GCT_MATRIX_4X3; break; case CG_FLOAT4x4: case CG_HALF4x4: def.constType = GCT_MATRIX_4X4; break; case CG_INT: case CG_INT1: def.constType = GCT_INT1; break; case CG_INT2: def.constType = GCT_INT2; break; case CG_INT3: def.constType = GCT_INT3; break; case CG_INT4: def.constType = GCT_INT4; break; default: def.constType = GCT_UNKNOWN; break; } // Cg pads def.elementSize = GpuConstantDefinition::getElementSize(def.constType, true); } } //----------------------------------------------------------------------- CgProgram::CgProgram(ResourceManager* creator, const String& name, ResourceHandle handle, const String& group, bool isManual, ManualResourceLoader* loader, CGcontext context) : HighLevelGpuProgram(creator, name, handle, group, isManual, loader), mCgContext(context), mSelectedCgProfile(CG_PROFILE_UNKNOWN), mCgArguments(0), mParametersMapSizeAsBuffer(0) { if (createParamDictionary("CgProgram")) { setupBaseParamDictionary(); ParamDictionary* dict = getParamDictionary(); dict->addParameter(ParameterDef("entry_point", "The entry point for the Cg program.", PT_STRING),&msCmdEntryPoint); dict->addParameter(ParameterDef("profiles", "Space-separated list of Cg profiles supported by this profile.", PT_STRING),&msCmdProfiles); dict->addParameter(ParameterDef("compile_arguments", "A string of compilation arguments to pass to the Cg compiler.", PT_STRING),&msCmdArgs); } } //----------------------------------------------------------------------- CgProgram::~CgProgram() { freeCgArgs(); // have to call this here reather than in Resource destructor // since calling virtual methods in base destructors causes crash if (isLoaded()) { unload(); } else { unloadHighLevel(); } } //----------------------------------------------------------------------- bool CgProgram::isSupported(void) const { if (mDelegate) return mDelegate->isSupported(); if (mCompileError || !isRequiredCapabilitiesSupported()) return false; return mSelectedCgProfile != CG_PROFILE_UNKNOWN; } //----------------------------------------------------------------------- void CgProgram::setProfiles(const StringVector& profiles) { mProfiles = profiles; selectProfile(); } //----------------------------------------------------------------------- String CgProgram::resolveCgIncludes(const String& inSource, Resource* resourceBeingLoaded, const String& fileName) { String outSource; // output will be at least this big outSource.reserve(inSource.length()); size_t startMarker = 0; size_t i = inSource.find("#include"); while (i != String::npos) { size_t includePos = i; size_t afterIncludePos = includePos + 8; size_t newLineBefore = inSource.rfind('\n', includePos); // check we're not in a comment size_t lineCommentIt = inSource.rfind("//", includePos); if (lineCommentIt != String::npos) { if (newLineBefore == String::npos || lineCommentIt > newLineBefore) { // commented i = inSource.find("#include", afterIncludePos); continue; } } size_t blockCommentIt = inSource.rfind("/*", includePos); if (blockCommentIt != String::npos) { size_t closeCommentIt = inSource.rfind("*/", includePos); if (closeCommentIt == String::npos || closeCommentIt < blockCommentIt) { // commented i = inSource.find("#include", afterIncludePos); continue; } } // find following newline (or EOF) size_t newLineAfter = inSource.find('\n', afterIncludePos); // find include file string container String endDelimeter = "\""; size_t startIt = inSource.find('\"', afterIncludePos); if (startIt == String::npos || startIt > newLineAfter) { // try <> startIt = inSource.find('<', afterIncludePos); if (startIt == String::npos || startIt > newLineAfter) { OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Badly formed #include directive (expected \" or <) in file " + fileName + ": " + inSource.substr(includePos, newLineAfter-includePos), "CgProgram::preprocessor"); } else { endDelimeter = ">"; } } size_t endIt = inSource.find(endDelimeter, startIt+1); if (endIt == String::npos || endIt <= startIt) { OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Badly formed #include directive (expected " + endDelimeter + ") in file " + fileName + ": " + inSource.substr(includePos, newLineAfter-includePos), "CgProgram::preprocessor"); } // extract filename String filename(inSource.substr(startIt+1, endIt-startIt-1)); // open included file DataStreamPtr resource = ResourceGroupManager::getSingleton(). openResource(filename, resourceBeingLoaded->getGroup(), resourceBeingLoaded); // replace entire include directive line // copy up to just before include if (newLineBefore != String::npos && newLineBefore >= startMarker) outSource.append(inSource.substr(startMarker, newLineBefore-startMarker+1)); size_t lineCount = 0; size_t lineCountPos = 0; // Count the line number of #include statement lineCountPos = outSource.find('\n'); while(lineCountPos != String::npos) { lineCountPos = outSource.find('\n', lineCountPos+1); lineCount++; } // Add #line to the start of the included file to correct the line count outSource.append("#line 1 \"" + filename + "\"\n"); outSource.append(resource->getAsString()); // Add #line to the end of the included file to correct the line count outSource.append("\n#line " + Ogre::StringConverter::toString(lineCount) + "\"" + fileName + "\"\n"); startMarker = newLineAfter; if (startMarker != String::npos) i = inSource.find("#include", startMarker); else i = String::npos; } // copy any remaining characters outSource.append(inSource.substr(startMarker)); return outSource; } //----------------------------------------------------------------------- const String& CgProgram::getLanguage(void) const { static const String language = "cg"; return language; } //----------------------------------------------------------------------- //----------------------------------------------------------------------- //----------------------------------------------------------------------- String CgProgram::CmdEntryPoint::doGet(const void *target) const { return static_cast<const CgProgram*>(target)->getEntryPoint(); } void CgProgram::CmdEntryPoint::doSet(void *target, const String& val) { static_cast<CgProgram*>(target)->setEntryPoint(val); } //----------------------------------------------------------------------- String CgProgram::CmdProfiles::doGet(const void *target) const { return StringConverter::toString( static_cast<const CgProgram*>(target)->getProfiles() ); } void CgProgram::CmdProfiles::doSet(void *target, const String& val) { static_cast<CgProgram*>(target)->setProfiles(StringUtil::split(val)); } //----------------------------------------------------------------------- String CgProgram::CmdArgs::doGet(const void *target) const { return static_cast<const CgProgram*>(target)->getPreprocessorDefines(); } void CgProgram::CmdArgs::doSet(void *target, const String& val) { static_cast<CgProgram*>(target)->setPreprocessorDefines(val); } }
; int esxdos_f_write(uchar handle, void *src, size_t nbyte) SECTION code_clib SECTION code_esxdos PUBLIC esxdos_f_write EXTERN asm_esxdos_f_write esxdos_f_write: pop af pop bc pop hl pop de push de push hl push bc push af ld a,e jp asm_esxdos_f_write
; A130862: a(n) = (n-1)*(n+2)*(2*n+11)/2. ; 0,30,85,171,294,460,675,945,1276,1674,2145,2695,3330,4056,4879,5805,6840,7990,9261,10659,12190,13860,15675,17641,19764,22050,24505,27135,29946,32944,36135,39525,43120,46926,50949,55195,59670,64380,69331,74529,79980,85690,91665,97911,104434,111240,118335,125725,133416,141414,149725,158355,167310,176596,186219,196185,206500,217170,228201,239599,251370,263520,276055,288981,302304,316030,330165,344715,359686,375084,390915,407185,423900,441066,458689,476775,495330,514360,533871,553869,574360,595350,616845,638851,661374,684420,707995,732105,756756,781954,807705,834015,860890,888336,916359,944965,974160,1003950,1034341,1065339,1096950,1129180,1162035,1195521,1229644,1264410,1299825,1335895,1372626,1410024,1448095,1486845,1526280,1566406,1607229,1648755,1690990,1733940,1777611,1822009,1867140,1913010,1959625,2006991,2055114,2104000,2153655,2204085,2255296,2307294,2360085,2413675,2468070,2523276,2579299,2636145,2693820,2752330,2811681,2871879,2932930,2994840,3057615,3121261,3185784,3251190,3317485,3384675,3452766,3521764,3591675,3662505,3734260,3806946,3880569,3955135,4030650,4107120,4184551,4262949,4342320,4422670,4504005,4586331,4669654,4753980,4839315,4925665,5013036,5101434,5190865,5281335,5372850,5465416,5559039,5653725,5749480,5846310,5944221,6043219,6143310,6244500,6346795,6450201,6554724,6660370,6767145,6875055,6984106,7094304,7205655,7318165,7431840,7546686,7662709,7779915,7898310,8017900,8138691,8260689,8383900,8508330,8633985,8760871,8888994,9018360,9148975,9280845,9413976,9548374,9684045,9820995,9959230,10098756,10239579,10381705,10525140,10669890,10815961,10963359,11112090,11262160,11413575,11566341,11720464,11875950,12032805,12191035,12350646,12511644,12674035,12837825,13003020,13169626,13337649,13507095,13677970,13850280,14024031,14199229,14375880,14553990,14733565,14914611,15097134,15281140,15466635,15653625,15842116,16032114 mov $1,$0 mov $2,$0 lpb $0,1 add $1,$0 sub $0,1 add $1,3 add $3,$1 lpe add $1,$3 add $0,$1 mul $3,2 add $3,$0 add $3,2 mov $1,$3 lpb $2,1 add $1,10 sub $2,1 lpe sub $1,2
.global s_prepare_buffers s_prepare_buffers: push %r15 push %rcx push %rdi push %rdx push %rsi lea addresses_D_ht+0x1a09a, %rsi lea addresses_WC_ht+0x18e42, %rdi clflush (%rdi) nop sub $61031, %r15 mov $49, %rcx rep movsw nop nop nop add $62890, %rdx pop %rsi pop %rdx pop %rdi pop %rcx pop %r15 ret .global s_faulty_load s_faulty_load: push %r10 push %r8 push %rbp push %rbx push %rdi push %rdx push %rsi // Store lea addresses_UC+0x9e42, %rdi nop cmp %r10, %r10 movb $0x51, (%rdi) nop nop nop nop add $62577, %rdx // Store lea addresses_RW+0xd452, %rsi nop nop nop xor %rbp, %rbp mov $0x5152535455565758, %rdi movq %rdi, %xmm5 movups %xmm5, (%rsi) cmp %rdx, %rdx // Store lea addresses_US+0x1b42, %rsi nop nop nop sub %rbp, %rbp movl $0x51525354, (%rsi) add %r10, %r10 // Load lea addresses_PSE+0x1d842, %rdi clflush (%rdi) nop nop nop nop nop add $59441, %r10 mov (%rdi), %bp nop add $1753, %r8 // Store lea addresses_A+0xa89a, %rbp and $20435, %rdi movb $0x51, (%rbp) nop nop nop and %r10, %r10 // Faulty Load lea addresses_D+0x9c42, %rdi nop cmp %r8, %r8 vmovups (%rdi), %ymm5 vextracti128 $1, %ymm5, %xmm5 vpextrq $1, %xmm5, %rbx lea oracles, %r10 and $0xff, %rbx shlq $12, %rbx mov (%r10,%rbx,1), %rbx pop %rsi pop %rdx pop %rdi pop %rbx pop %rbp pop %r8 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'size': 2, 'NT': False, 'type': 'addresses_D', 'same': False, 'AVXalign': False, 'congruent': 0}} {'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_UC', 'same': False, 'AVXalign': False, 'congruent': 9}} {'OP': 'STOR', 'dst': {'size': 16, 'NT': False, 'type': 'addresses_RW', 'same': False, 'AVXalign': False, 'congruent': 4}} {'OP': 'STOR', 'dst': {'size': 4, 'NT': False, 'type': 'addresses_US', 'same': False, 'AVXalign': False, 'congruent': 8}} {'OP': 'LOAD', 'src': {'size': 2, 'NT': True, 'type': 'addresses_PSE', 'same': False, 'AVXalign': False, 'congruent': 9}} {'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_A', 'same': False, 'AVXalign': False, 'congruent': 0}} [Faulty Load] {'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_D', 'same': True, 'AVXalign': False, 'congruent': 0}} <gen_prepare_buffer> {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_D_ht', 'congruent': 3}, 'dst': {'same': False, 'type': 'addresses_WC_ht', 'congruent': 8}} {'36': 21829} 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 */
;Testname=warning; Arguments=-fbin -omacdef.bin -w+macro-defaults; Files=stdout stderr macdef.bin ;Testname=nonwarning; Arguments=-fbin -omacdef.bin -w-macro-defaults; Files=stdout stderr macdef.bin %MACRO mmac_fix 1 a ; While defined to take one parameter, any invocation will ; see two, due to the default parameter. %warning %0 %1 %2 %3 %4 %5 %ENDMACRO mmac_fix one %MACRO mmac_var 1-2 a,b ; While defined to take one or two parameters, invocations ; will see three, due to the default parameters. %warning %0 %1 %2 %3 %4 %5 %ENDMACRO mmac_var one mmac_var one,two %MACRO mmac_plus 1-2+ a,b ; This does not warn. Although this looks like two default ; parameters, it ends up being only one: the "+" limits it ; to two parameters; if invoked without a second parameter ; the second parameter will be "a,b". %warning %0 %1 %2 %3 %4 %5 ;Check rotating behaviour %ENDMACRO mmac_plus one mmac_plus one,two mmac_plus one,two,three %MACRO mmac_star 1-* a,b ; This does not warn. Because the "*" extends the range of ; parameters to infinity, the "a,b" default parameters can ; not exceed that range. %warning %0 %1 %2 %3 %4 %5 %ENDMACRO mmac_star one mmac_star one,two mmac_star one,two,three %MACRO mmac_rotate 0-* a,b %warning %0 %1 %2 %3 %4 %5 ;%rotate should rotate all parameters %rotate 1 %warning %0 %1 %2 %3 %4 %5 %ENDMACRO mmac_rotate mmac_rotate one mmac_rotate one,two mmac_rotate one,two,three ;Scope / evaluation time test %define I 0 %assign J 0 %xdefine K 0 %MACRO mmac_scope 0 I J K %warning %1 %2 %3 %ENDMACRO %define I 1 %assign J 1 %xdefine K 1 mmac_scope
; int obstack_align_to(struct obstack *ob, size_t alignment) SECTION code_clib SECTION code_alloc_obstack PUBLIC obstack_align_to EXTERN asm_obstack_align_to obstack_align_to: pop af pop bc pop hl push hl push bc push af jp asm_obstack_align_to
#include "fontpreviewlabel.h" #include <qdebug.h> #include <QMouseEvent> #include <qmenu.h> #include <qaction.h> FontPreviewLabel::FontPreviewLabel(QWidget *parent) : QLabel(parent) { } FontPreviewLabel::~FontPreviewLabel() { } void FontPreviewLabel::mousePressEvent(QMouseEvent *ev) { // qDebug() << ev->pos(); for(int i=0; i<m_charList.count(); i++) { int x1 = m_charList.at(i)->rect.x(); int x2 = m_charList.at(((i+1)<m_charList.count()) ? i+1 : i)->rect.x()+(((i+1)<m_charList.count()) ? 0 : m_charList.at(i)->rect.width()); if(x1 < ev->pos().x() && ev->pos().x() < x2) { //qDebug() << m_charList.at(i)->ch << m_charList.at(i)->rect; CharInfo *charInfo = m_charList.at(i); if(ev->button() == Qt::RightButton) { QMenu menu(this); QAction *actIgnore = new QAction(tr("Ignore '%1'").arg(charInfo->ch), this); QAction *actIgnoreLikeThis = new QAction(tr("Ignore every '%1'").arg(charInfo->ch), this); menu.addAction(actIgnore); menu.addAction(actIgnoreLikeThis); QAction *ret = menu.exec(ev->globalPos()); if(ret == actIgnore) { charInfo->ignore = true; } else if (ret == actIgnoreLikeThis) { for(int j=0; j<m_charList.count(); j++){ CharInfo *charI = m_charList.at(j); if(charI->ch == charInfo->ch) charI->ignore = true; } } } emit charInfoSelected(i); } } } void FontPreviewLabel::setRectList(QList<CharInfo*> list) { m_charList = list; } QList<CharInfo*> FontPreviewLabel::getRectList() { return m_charList; }
ZERAR: CLR A; 1 MOV R0, #99; 1 ROT: MOV @R0, A; 1 NOP;1 DJNZ R0, ROT; 99* (2 + 2) RET;2 ; 1 + 1 +99(4) + 2 = 400
; A116483: Expansion of (1 + x) / (5*x^2 - 2*x + 1). ; 1,3,1,-13,-31,3,161,307,-191,-1917,-2879,3827,22049,24963,-60319,-245453,-189311,848643,2643841,1044467,-11130271,-27482877,685601,138785587,274143169,-145641597,-1661999039,-2595790093,3118415009,19215780483,22839485921,-50399930573,-214997290751,-177994928637,718996596481,2327967836147,1060952689889,-9517933800957,-24340631051359,-1091593097933,119519969060929,244497903611523,-108604038081599,-1439697594220813,-2336374998033631,2525737975036803 mov $1,1 mov $2,3 lpb $0 sub $0,1 mul $1,4 mul $3,2 sub $3,$4 add $2,$3 mov $3,1 add $4,$1 mov $1,$2 lpe