text
stringlengths
1
1.05M
; A075105: Numerator of n/floor(log_2(n)); denominator is A075106(n). ; 2,3,2,5,3,7,8,3,10,11,4,13,14,5,4,17,9,19,5,21,11,23,6,25,13,27,7,29,15,31,32,33,34,7,36,37,38,39,8,41,42,43,44,9,46,47,48,49,10,51,52,53,54,11,56,57,58,59,12,61,62,63,32,65,11,67,34,23,35,71,12,73,37,25,38,77,13,79,40,27,41,83,14,85,43,29,44,89,15,91,46,31,47,95,16,97,49,33,50,101,17,103,52,35,53,107,18,109,55,37,56,113,19,115,58,39,59,119,20,121,61,41,62,125,21,127,128,129,130,131,132,19,134,135,136,137,138,139,20,141,142,143,144,145,146,21,148,149,150,151,152,153,22,155,156,157,158,159,160,23,162,163,164,165,166,167,24,169,170,171,172,173,174,25,176,177,178,179,180,181,26,183,184,185,186,187,188,27,190,191,192,193,194,195,28,197,198,199,200,201,202,29,204,205,206,207,208,209,30,211,212,213,214,215,216,31,218,219,220,221,222,223,32,225,226,227,228,229,230,33,232,233,234,235,236,237,34,239,240,241,242,243,244,35,246,247,248,249,250,251 mov $2,$0 add $2,2 mov $0,$2 mov $1,$2 log $1,2 gcd $1,$2 div $0,$1 mov $1,$0
push ebp mov ebp,esp push ecx call dword ptr ds:[16D1BCh] mov ecx,dword ptr [dev] and eax,3Fh shl eax,0Ch or eax,ecx mov dword ptr [dev],eax mov esp,ebp pop ebp ret
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1992 -- All Rights Reserved PROJECT: PC GEOS MODULE: FILE: trSmallGState.asm AUTHOR: John Wedgwood, Feb 25, 1992 ROUTINES: Name Description ---- ----------- REVISION HISTORY: Name Date Description ---- ---- ----------- John 2/25/92 Initial revision DESCRIPTION: GState related stuff. $Id: trSmallGState.asm,v 1.1 97/04/07 11:21:46 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ TextFixed segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SmallRegionTransformGState %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Transform the gstate so that 0,0 falls at the upper-left corner of the region. CALLED BY: TR_RegionTransformGState via CallRegionHandlers PASS: *ds:si = Instance cx = Region dl = DrawFlags RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- jcw 2/25/92 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SmallRegionTransformGState proc near uses ax, bx, cx, dx, di, si class VisTextClass .enter EC < call ECSmallCheckRegionNumber > mov si, ds:[si] add si, ds:[si].Vis_offset ; ds:si <- instance mov di, ds:[si].VTI_gstate ; di <- gstate push dx ; ; The top-left corner is at: ; (bounds.left + lrMargin), (bounds.top + tbMargin) ; ; NOTE: We do not translate by VTI_leftOffset because one line ; text objects are handled specially ; mov ax, ds:[si].VI_bounds.R_left ; ax <- X translation add al, ds:[si].VTI_lrMargin adc ah, 0 ; ; Sign-extend the X translation. ; cwd ; dx.ax <- X translation mov_tr cx, ax mov bx, dx ; bx.cx <- X translation clr bx mov ax, ds:[si].VI_bounds.R_top add al, ds:[si].VTI_tbMargin adc ah, 0 cwd ; dx.ax <- Y translation xchg bx, dx ; dx.cx <- X & bx.ax <- Y call GrApplyTranslationDWord ; Apply the translation ; now set the clip rectangle pop dx test dl, mask DF_PRINT jnz noSetClip call SmallSetClip noSetClip: .leave ret SmallRegionTransformGState endp SmallSetClip proc far class VisTextClass mov cx, ds:[si].VI_bounds.R_right sub cx, ds:[si].VI_bounds.R_left clr ax mov al, ds:[si].VTI_lrMargin shl ax sub cx, ax mov dx, ds:[si].VI_bounds.R_bottom sub dx, ds:[si].VI_bounds.R_top mov al, ds:[si].VTI_tbMargin shl ax sub dx, ax clr ax clr bx mov si, PCT_REPLACE ; Replace old clip rect call GrSetClipRect ret SmallSetClip endp TextFixed ends
CLO ; Close unwanted windows. MOV BL,C0 Input: IN 00 ; Wait for key press - Store it in AL. MOV [BL],AL CMP BL,FF JZ Clear INC BL CMP AL,0D ; Was it the Enter key? (ASCII 0D) JNZ Input ; No - jump back. Yes - end. Clear: CALL 30 MOV BL,C0 JMP Input ; Clear display ORG 30 PUSHF PUSH BL MOV BL,C0 MOV AL,20 Loop: MOV [BL],AL INC BL JNZ Loop POP BL POPF RET END
; A060494: a(n) = floor(n^4/64). ; 0,0,0,1,4,9,20,37,64,102,156,228,324,446,600,791,1024,1305,1640,2036,2500,3038,3660,4372,5184,6103,7140,8303,9604,11051,12656,14430,16384,18530,20880,23447,26244,29283,32580,36147,40000,44152,48620,53418,58564,64072,69960,76245,82944,90075,97656,105706,114244,123288,132860,142978,153664,164937,176820,189333,202500,216341,230880,246140,262144,278916,296480,314861,334084,354173,375156,397057,419904,443722,468540,494384,521284,549266,578360,608595,640000,672605,706440,741536,777924,815634,854700 pow $0,4 div $0,64
mov ecx,dword ptr ds:[1072A88] lea eax,dword ptr ss:[ebp-18] push eax call aok hd.AE26F0 mov dword ptr ss:[ebp-4],4 mov eax,dword ptr ds:[eax] mov dword ptr ss:[ebp-14],8 cmp dword ptr ds:[eax+380],0 jne aok hd.C2547C mov eax,dword ptr ds:[ebx+64] mov byte ptr ss:[ebp-D],1 cmp dword ptr ds:[eax+A20],1 jne aok hd.C25480 mov byte ptr ss:[ebp-D],0 mov dword ptr ss:[ebp-4],FFFFFFFF mov eax,8 mov dword ptr ss:[ebp-14],eax and eax,FFFFFFF7 mov dword ptr ss:[ebp-14],eax mov ecx,dword ptr ss:[ebp-18] test ecx,ecx je aok hd.C254A6 add dword ptr ds:[ecx+4],FFFFFFFF jne aok hd.C254A6 mov eax,dword ptr ds:[ecx] call dword ptr ds:[eax] cmp byte ptr ss:[ebp-D],0 je aok hd.C25969 mov esi,dword ptr ds:[1072A88] mov ecx,ebx call aok hd.CCDB60 test al,al mov ecx,esi sete al movzx eax,al push eax call aok hd.AE3950 mov ecx,ebx call aok hd.CCDB60 mov ecx,dword ptr ds:[ebx+84] push 4000000 mov ecx,dword ptr ds:[ecx+5AEC] test al,al je aok hd.C254F0 call aok hd.E20DC0 jmp aok hd.C254F5 call aok hd.E21680 mov ecx,dword ptr ds:[1072A88] mov eax,dword ptr ds:[ecx] call dword ptr ds:[eax+24] test eax,eax je aok hd.C25969 mov ecx,eax call aok hd.DD27B0 mov ecx,dword ptr ss:[ebp-C] mov dword ptr fs:[0],ecx pop ecx pop edi pop esi pop ebx mov esp,ebp pop ebp ret 8
/*========================================================================= * * Copyright NumFOCUS * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * *=========================================================================*/ #include "itkAmoebaOptimizer.h" #include "itkConjugateGradientOptimizer.h" #include "itkCumulativeGaussianOptimizer.h" #include "itkLBFGSOptimizer.h" #include "itkVersorTransformOptimizer.h" #include "itkQuaternionRigidTransformGradientDescentOptimizer.h" #include "itkOnePlusOneEvolutionaryOptimizer.h" #include <iostream> /** * * This file performs only simple C++ tests of * the base classes in the Optimizers hierarchy. * * Nothing numerical is computed in these tests, * only code conformance. */ int itkOptimizersHierarchyTest(int, char *[]) { bool pass = true; using OptimizerType = itk::Optimizer; auto genericOptimizer = OptimizerType::New(); unsigned int spaceDimension = 10; OptimizerType::ParametersType initialPosition(spaceDimension); OptimizerType::ParametersType currentPosition(spaceDimension); OptimizerType::ScalesType parameterScale(spaceDimension); parameterScale.Fill(1.5); initialPosition.Fill(2.0); genericOptimizer->SetInitialPosition(initialPosition); genericOptimizer->SetScales(parameterScale); const OptimizerType::ScalesType & parameterScaleGot = genericOptimizer->GetScales(); const double tolerance = 1e-10; for (unsigned int i = 0; i < spaceDimension; ++i) { if (itk::Math::abs(parameterScaleGot[i] - parameterScale[i]) > tolerance) { std::cout << "Test failed." << std::endl; std::cout << "Scale parameters are damaged after being set." << std::endl; std::cout << "Scale was set to: " << parameterScale << std::endl; std::cout << "Scale was got as: " << parameterScaleGot << std::endl; return EXIT_FAILURE; } } OptimizerType::ParametersType initialPositionGot = genericOptimizer->GetInitialPosition(); for (unsigned int i = 0; i < spaceDimension; ++i) { if (itk::Math::abs(initialPositionGot[i] - initialPosition[i]) > tolerance) { std::cout << "Test failed." << std::endl; std::cout << "InitialPosition parameters are damaged after being set." << std::endl; std::cout << "InitialPosition was set to: " << initialPosition << std::endl; std::cout << "InitialPosition was got as: " << initialPositionGot << std::endl; return EXIT_FAILURE; } } using NonLinearOptimizerType = itk::NonLinearOptimizer; auto nonLinearOptimizer = NonLinearOptimizerType::New(); if (nonLinearOptimizer.IsNull()) { pass = false; } using SingleValuedNonLinearOptimizerType = itk::SingleValuedNonLinearOptimizer; auto singleValuedOptimizer = SingleValuedNonLinearOptimizerType::New(); if (singleValuedOptimizer.IsNull()) { pass = false; } using AmoebaOptimizerType = itk::AmoebaOptimizer; auto amoeba = AmoebaOptimizerType::New(); if (amoeba.IsNull()) { pass = false; } using ConjugateGradientOptimizerType = itk::ConjugateGradientOptimizer; auto conjugate = ConjugateGradientOptimizerType::New(); if (conjugate.IsNull()) { pass = false; } using LBFGSOptimizerType = itk::LBFGSOptimizer; auto lbfgs = LBFGSOptimizerType::New(); if (lbfgs.IsNull()) { pass = false; } // Note that a "Versor" is a Unit Quaternion using VersorOptimizerType = itk::VersorTransformOptimizer; auto versoropt = VersorOptimizerType::New(); if (versoropt.IsNull()) { pass = false; } using QuaternionOptimizerType = itk::QuaternionRigidTransformGradientDescentOptimizer; auto quaternionopt = QuaternionOptimizerType::New(); if (quaternionopt.IsNull()) { pass = false; } using OnePlusOneEvolutionaryOptimizerType = itk::OnePlusOneEvolutionaryOptimizer; auto onePlusOne = OnePlusOneEvolutionaryOptimizerType::New(); if (onePlusOne.IsNull()) { pass = false; } using CumulativeGaussianOptimizerType = itk::CumulativeGaussianOptimizer; auto cumgaussopt = CumulativeGaussianOptimizerType::New(); if (cumgaussopt.IsNull()) { pass = false; } using CumulativeGaussianCostFunctionType = itk::CumulativeGaussianCostFunction; auto cumgausstype = CumulativeGaussianCostFunctionType::New(); if (cumgausstype.IsNull()) { pass = false; } if (!pass) { std::cout << "Test failed." << std::endl; return EXIT_FAILURE; } std::cout << "Test passed." << std::endl; return EXIT_SUCCESS; }
; A167484: For n people on one side of a river, the number of ways they can all travel to the opposite side following the pattern of 2 sent, 1 returns, 2 sent, 1 returns, ..., 2 sent. ; Submitted by Jon Maiga ; 1,1,6,108,4320,324000,40824000,8001504000,2304433152000,933295426560000,513312484608000000,372664863825408000000,348814312540581888000000,412647331735508373504000000,606591577651197309050880000000,1091864839772155156291584000000000,2375897891344209620090486784000000000,6179710415386289221855356125184000000000,19021148658558998224870786153316352000000000,68666346657397983591783538013472030720000000000,288398655961071531085490859656582529024000000000000 mov $2,1 mov $4,1 lpb $0 sub $0,1 add $3,$2 mul $4,$3 mul $4,$2 add $2,1 lpe mov $0,$4
.model small .stack .data .code .startup ;mov ax,5h ;mov bl,2h ;div bl mov dx, WORD PTR 244h mov ax, WORD PTR 259h mov bl,8h div bl end
;------------------------------------------------------------------------------ ;* ;* Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.<BR> ;* SPDX-License-Identifier: BSD-2-Clause-Patent ;* ;* ;------------------------------------------------------------------------------ DEFAULT REL SECTION .text %macro tdcall 0 db 0x66,0x0f,0x01,0xcc %endmacro %macro tdcall_push_regs 0 push rbp mov rbp, rsp push r15 push r14 push r13 push r12 push rbx push rsi push rdi %endmacro %macro tdcall_pop_regs 0 pop rdi pop rsi pop rbx pop r12 pop r13 pop r14 pop r15 pop rbp %endmacro %define number_of_regs_pushed 8 %define number_of_parameters 4 ; ; Keep these in sync for push_regs/pop_regs, code below ; uses them to find 5th or greater parameters ; %define first_variable_on_stack_offset \ ((number_of_regs_pushed * 8) + (number_of_parameters * 8) + 8) %define second_variable_on_stack_offset \ ((first_variable_on_stack_offset) + 8) ; TdCall ( ; UINT64 Leaf, // Rcx ; UINT64 P1, // Rdx ; UINT64 P2, // R8 ; UINT64 P3, // R9 ; UINT64 Results, // rsp + 0x28 ; ) global ASM_PFX(TdCall) ASM_PFX(TdCall): tdcall_push_regs mov rax, rcx mov rcx, rdx mov rdx, r8 mov r8, r9 tdcall ; exit if tdcall reports failure. test rax, rax jnz .exit ; test if caller wanted results mov r12, [rsp + first_variable_on_stack_offset ] test r12, r12 jz .exit mov [r12 + 0 ], rcx mov [r12 + 8 ], rdx mov [r12 + 16], r8 mov [r12 + 24], r9 mov [r12 + 32], r10 mov [r12 + 40], r11 .exit: tdcall_pop_regs ret
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r12 push %r13 push %r14 push %rax push %rbx push %rdi lea addresses_UC_ht+0x147a6, %r12 nop sub %r14, %r14 mov (%r12), %r13w nop nop sub %rbx, %rbx lea addresses_A_ht+0x1b51e, %rdi nop cmp %r11, %r11 mov $0x6162636465666768, %rax movq %rax, %xmm0 and $0xffffffffffffffc0, %rdi movntdq %xmm0, (%rdi) nop nop nop sub %rax, %rax lea addresses_UC_ht+0x12f66, %r14 nop nop nop nop nop add $61883, %r11 mov (%r14), %r12 nop nop xor $30014, %r11 pop %rdi pop %rbx pop %rax pop %r14 pop %r13 pop %r12 pop %r11 ret .global s_faulty_load s_faulty_load: push %r12 push %r13 push %r14 push %r15 push %rcx push %rdi push %rsi // Load lea addresses_A+0x1f1a6, %rcx nop nop add %rsi, %rsi mov (%rcx), %di nop xor %r12, %r12 // Load mov $0x15aa4a0000000bba, %rsi nop dec %r13 movb (%rsi), %cl nop nop nop nop xor %rcx, %rcx // Faulty Load lea addresses_RW+0x1b3a6, %rsi nop nop nop nop xor $30941, %r14 mov (%rsi), %r13d lea oracles, %rcx and $0xff, %r13 shlq $12, %r13 mov (%rcx,%r13,1), %r13 pop %rsi pop %rdi pop %rcx pop %r15 pop %r14 pop %r13 pop %r12 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_RW', 'congruent': 0}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_A', 'congruent': 4}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': True, 'size': 1, 'type': 'addresses_NC', 'congruent': 0}} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_RW', 'congruent': 0}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_UC_ht', 'congruent': 10}} {'dst': {'same': False, 'NT': True, 'AVXalign': False, 'size': 16, 'type': 'addresses_A_ht', 'congruent': 2}, 'OP': 'STOR'} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_UC_ht', 'congruent': 4}} {'32': 2689} 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 */
#include "Z80Word.h" //@formatter:off Z80Word::Z80Word(int wordValue) : highByte{(wordValue & 0xFF00) >> 8}, lowByte{(wordValue & 0xFF)} {} // NOLINT //@formatter:on //@formatter:off Z80Word::Z80Word(unsigned long wordValue) : highByte{(wordValue & 0xFF00) >> 8}, lowByte{(wordValue & 0xFF)} {} // NOLINT //@formatter:on //@formatter:off Z80Word::Z80Word(Z80Word::word wordValue) : highByte{(wordValue & 0xFF00) >> 8}, lowByte{(wordValue & 0xFF)} {} // NOLINT //@formatter:on Z80Word::Z80Word(Z80Byte highByte, Z80Byte lowByte) : highByte{highByte}, lowByte{lowByte} {} Z80Word::word Z80Word::getValue() const { auto highByteValue = this->highByte.getValue(); auto lowByteValue = this->lowByte.getValue(); return (0xFF00 & (highByteValue << 8)) | lowByteValue; // NOLINT } Z80Byte Z80Word::getHighByte() const { return highByte; } Z80Byte Z80Word::getLowByte() const { return lowByte; } Z80Word Z80Word::reverseBytes() const { return Z80Word{lowByte, highByte}; }
/* * Copyright (c) 2021 Grant Erickson * 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. * */ /** * @file * This file implements a unit test for * HLX::Common::ConnectionBuffer. * */ #include <errno.h> #include <string.h> #include <nlunit-test.h> #include <OpenHLX/Common/ConnectionBuffer.hpp> using namespace HLX; using namespace HLX::Common; static void TestConstruction(nlTestSuite *inSuite __attribute__((unused)), void *inContext __attribute__((unused))) { ConnectionBuffer lConnectionBuffer; } static void TestDefaultInitialization(nlTestSuite *inSuite, void *inContext __attribute__((unused))) { ConnectionBuffer lConnectionBuffer_1; Status lStatus; lStatus = lConnectionBuffer_1.Init(); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); } static void TestValueInitialization(nlTestSuite *inSuite, void *inContext __attribute__((unused))) { constexpr size_t kCapacity = 257; ConnectionBuffer lConnectionBuffer_1; ConnectionBuffer lConnectionBuffer_2; ConnectionBuffer lConnectionBuffer_3; ConnectionBuffer lConnectionBuffer_4; ConnectionBuffer lConnectionBuffer_5; ConnectionBuffer lConnectionBuffer_6; size_t lCapacity; uint8_t * lOurData; uint8_t lBackingBuffer[kCapacity]; Status lStatus; // 1: Test capacity-only // 1.1: Test zero capacity. lCapacity = 0; lStatus = lConnectionBuffer_1.Init(lCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); // 1.2: Test arbitrary capacity. lCapacity = 257; lStatus = lConnectionBuffer_2.Init(lCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); // 2: Test pointer and capacity // 2.1: Test null (their-owned buffer) pointer and capacity. lOurData = nullptr; // 2.1.1: Test zero capacity. lCapacity = 0; lStatus = lConnectionBuffer_3.Init(lOurData, lCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); // 2.1.2: Test arbitrary capacity. lCapacity = 257; lStatus = lConnectionBuffer_4.Init(lOurData, lCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); // 2.2: Test non-null (our owned buffer) pointer and capacity. lOurData = &lBackingBuffer[0]; // 2.2.1: Test zero capacity. lCapacity = 0; lStatus = lConnectionBuffer_5.Init(lOurData, lCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); // 2.2.2: Test arbitrary capacity. lCapacity = 257; lStatus = lConnectionBuffer_6.Init(lOurData, lCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); } static void TestInitialization(nlTestSuite *inSuite, void *inContext) { TestDefaultInitialization(inSuite, inContext); TestValueInitialization(inSuite, inContext); } static void TestObservation(const ConnectionBuffer &inBuffer, nlTestSuite *inSuite, const size_t &inExpectedCapacity) { size_t lCapacity; size_t lSize; uint8_t * lHead; uint8_t * lTail; lCapacity = inBuffer.GetCapacity(); NL_TEST_ASSERT(inSuite, lCapacity == inExpectedCapacity); lSize = inBuffer.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 0); lHead = inBuffer.GetHead(); lTail = inBuffer.GetTail(); NL_TEST_ASSERT(inSuite, lHead != nullptr); NL_TEST_ASSERT(inSuite, lTail != nullptr); NL_TEST_ASSERT(inSuite, lHead == lTail); } static void TestObservation(nlTestSuite *inSuite, void *inContext __attribute__((unused))) { constexpr size_t kCapacity = 257; ConnectionBuffer lConnectionBuffer_1; ConnectionBuffer lConnectionBuffer_2; ConnectionBuffer lConnectionBuffer_3; ConnectionBuffer lConnectionBuffer_4; ConnectionBuffer lConnectionBuffer_5; ConnectionBuffer lConnectionBuffer_6; size_t lCapacity; uint8_t * lOurData; uint8_t lBackingBuffer[kCapacity]; Status lStatus; // 1: Test capacity-only // 1.1: Test zero capacity. lCapacity = 0; lStatus = lConnectionBuffer_1.Init(lCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); TestObservation(lConnectionBuffer_1, inSuite, lCapacity); // 1.2: Test arbitrary capacity. lCapacity = 257; lStatus = lConnectionBuffer_2.Init(lCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); TestObservation(lConnectionBuffer_2, inSuite, lCapacity); // 2: Test pointer and capacity // 2.1: Test null (their-owned buffer) pointer and capacity. lOurData = nullptr; // 2.1.1: Test zero capacity. lCapacity = 0; lStatus = lConnectionBuffer_3.Init(lOurData, lCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); TestObservation(lConnectionBuffer_3, inSuite, lCapacity); // 2.1.2: Test arbitrary capacity. lCapacity = 257; lStatus = lConnectionBuffer_4.Init(lOurData, lCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); TestObservation(lConnectionBuffer_4, inSuite, lCapacity); // 2.2: Test non-null (our owned buffer) pointer and capacity. lOurData = &lBackingBuffer[0]; // 2.2.1: Test zero capacity. lCapacity = 0; lStatus = lConnectionBuffer_5.Init(lOurData, lCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); TestObservation(lConnectionBuffer_5, inSuite, lCapacity); // 2.2.2: Test arbitrary capacity. lCapacity = 257; lStatus = lConnectionBuffer_6.Init(lOurData, lCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); TestObservation(lConnectionBuffer_6, inSuite, lCapacity); } static void TestDestroy(ConnectionBuffer &inBuffer, nlTestSuite *inSuite) { size_t lCapacity; size_t lSize; uint8_t * lHead; uint8_t * lTail; inBuffer.Destroy(); lCapacity = inBuffer.GetCapacity(); NL_TEST_ASSERT(inSuite, lCapacity == 0); lSize = inBuffer.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 0); lHead = inBuffer.GetHead(); lTail = inBuffer.GetTail(); NL_TEST_ASSERT(inSuite, lHead == nullptr); NL_TEST_ASSERT(inSuite, lTail == nullptr); NL_TEST_ASSERT(inSuite, lHead == lTail); } static void TestDestroy(nlTestSuite *inSuite, void *inContext __attribute__((unused))) { constexpr size_t kCapacity = 257; ConnectionBuffer lConnectionBuffer_1; ConnectionBuffer lConnectionBuffer_2; size_t lCapacity; uint8_t * lOurData; uint8_t lBackingBuffer[kCapacity]; Status lStatus; // 1: Test pointer and capacity // 1.1: Test null (their-owned buffer) pointer and capacity. lOurData = nullptr; // 1.1.1: Test arbitrary capacity. lCapacity = 257; lStatus = lConnectionBuffer_1.Init(lOurData, lCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); // 1.1.2: Test destroy. TestDestroy(lConnectionBuffer_1, inSuite); // 1.2: Test non-null (our owned buffer) pointer and capacity. lOurData = &lBackingBuffer[0]; // 1.2.1: Test arbitrary capacity. lCapacity = 257; lStatus = lConnectionBuffer_2.Init(lOurData, lCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); // 1.2.2: Test destroy. TestDestroy(lConnectionBuffer_2, inSuite); } static void TestPut(nlTestSuite *inSuite, void *inContext __attribute__((unused))) { constexpr size_t kCapacity = 257; const char * const kTestData = "This is a test."; const size_t kTestDataLength = strlen(kTestData); ConnectionBuffer lConnectionBuffer_1; ConnectionBuffer lConnectionBuffer_2; ConnectionBuffer lConnectionBuffer_3; ConnectionBuffer lConnectionBuffer_4; ConnectionBuffer lConnectionBuffer_5; ConnectionBuffer lConnectionBuffer_6; ConnectionBuffer lConnectionBuffer_7; ConnectionBuffer lConnectionBuffer_8; const uint8_t * lOurData; size_t lOurSize; uint8_t lBackingBuffer[kCapacity]; uint8_t * lHead; int lComparison; Status lStatus; lOurData = reinterpret_cast<const uint8_t *>(kTestData); lOurSize = kTestDataLength; // 1.1: Test put with a data pointer // 1.1.1: Test put on a caller-owned backing store // 1.1.1.1: Test put with insufficient head room NL_TEST_ASSERT(inSuite, lOurSize - 1 <= sizeof (lBackingBuffer)); lStatus = lConnectionBuffer_1.Init(&lBackingBuffer[0], lOurSize - 1); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lHead = lConnectionBuffer_1.Put(lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lHead == nullptr); // 1.1.1.2: Test put with sufficient head room NL_TEST_ASSERT(inSuite, lOurSize + 1 <= sizeof (lBackingBuffer)); lStatus = lConnectionBuffer_2.Init(&lBackingBuffer[0], lOurSize + 1); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lHead = lConnectionBuffer_2.Put(lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lHead != nullptr); NL_TEST_ASSERT(inSuite, lHead == &lBackingBuffer[0]); lComparison = memcmp(lHead, lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lComparison == 0); // 1.1.2: Test put on a buffer-owned backing store // 1.1.2.1: Test put with insufficient head room lStatus = lConnectionBuffer_3.Init(nullptr, lOurSize - 1); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lHead = lConnectionBuffer_3.Put(lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lHead == nullptr); // 1.1.2.2: Test put with sufficient head room lStatus = lConnectionBuffer_4.Init(nullptr, lOurSize + 1); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lHead = lConnectionBuffer_4.Put(lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lHead != nullptr); lComparison = memcmp(lHead, lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lComparison == 0); // 1.2: Test put without a data pointer // 1.2.1: Test put on a caller-owned backing store // 1.2.1.1: Test put with insufficient head room NL_TEST_ASSERT(inSuite, lOurSize - 1 <= sizeof (lBackingBuffer)); lStatus = lConnectionBuffer_5.Init(&lBackingBuffer[0], lOurSize - 1); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lHead = lConnectionBuffer_5.Put(lOurSize); NL_TEST_ASSERT(inSuite, lHead == nullptr); // 1.2.1.2: Test put with sufficient head room NL_TEST_ASSERT(inSuite, lOurSize + 1 <= sizeof (lBackingBuffer)); lStatus = lConnectionBuffer_6.Init(&lBackingBuffer[0], lOurSize + 1); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lHead = lConnectionBuffer_6.Put(lOurSize); NL_TEST_ASSERT(inSuite, lHead != nullptr); NL_TEST_ASSERT(inSuite, lHead == &lBackingBuffer[0]); // 1.2.2: Test put on a buffer-owned backing store // 1.2.2.1: Test put with insufficient head room lStatus = lConnectionBuffer_7.Init(nullptr, lOurSize - 1); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lHead = lConnectionBuffer_7.Put(lOurSize); NL_TEST_ASSERT(inSuite, lHead == nullptr); // 1.2.2.2: Test put with sufficient head room lStatus = lConnectionBuffer_8.Init(nullptr, lOurSize + 1); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lHead = lConnectionBuffer_8.Put(lOurSize); NL_TEST_ASSERT(inSuite, lHead != nullptr); } static void TestGet(nlTestSuite *inSuite, void *inContext __attribute__((unused))) { constexpr size_t kCapacity = 257; const char * const kTestData = "This is a test."; const size_t kTestDataLength = strlen(kTestData); ConnectionBuffer lConnectionBuffer_1; ConnectionBuffer lConnectionBuffer_2; const uint8_t * lOurData; size_t lOurSize; uint8_t lBackingBuffer[kCapacity]; uint8_t lCopyBuffer[16]; size_t lSize; uint8_t * lResult; int lComparison; Status lStatus; lOurData = reinterpret_cast<const uint8_t *>(kTestData); lOurSize = kTestDataLength; // 1.1: Test get on a caller-owned backing store lStatus = lConnectionBuffer_1.Init(&lBackingBuffer[0], kCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); // 1.1.1: Test get with a pointer and a size // 1.1.1.1: Test get with insufficient data lResult = lConnectionBuffer_1.Put(lOurData, lOurSize - 1); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize - 1); lResult = lConnectionBuffer_1.Get(lCopyBuffer, lOurSize); NL_TEST_ASSERT(inSuite, lResult == nullptr); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize - 1); // 1.1.1.2: Test get with sufficient data // 1.1.1.2.1: Test get with complete retrieval of data lResult = lConnectionBuffer_1.Put(lOurData + lOurSize - 1, 1); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize); lResult = lConnectionBuffer_1.Get(lCopyBuffer, lOurSize); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 0); lComparison = memcmp(lResult, lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lComparison == 0); // 1.1.1.2.2: Test get with partial retrieval of data lResult = lConnectionBuffer_1.Put(lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize); lResult = lConnectionBuffer_1.Get(lCopyBuffer, lOurSize - 3); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 3); lComparison = memcmp(lResult, lOurData, lOurSize - 3); NL_TEST_ASSERT(inSuite, lComparison == 0); lResult = lConnectionBuffer_1.Get(lCopyBuffer + lOurSize - 3, 3); NL_TEST_ASSERT(inSuite, lResult != nullptr); lComparison = memcmp(lResult, lOurData + lOurSize - 3, 3); NL_TEST_ASSERT(inSuite, lComparison == 0); // 1.1.2: Test get with a size only // 1.1.2.1: Test get with insufficient data lResult = lConnectionBuffer_1.Put(lOurData, lOurSize - 1); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize - 1); lResult = lConnectionBuffer_1.Get(lOurSize); NL_TEST_ASSERT(inSuite, lResult == nullptr); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize - 1); // 1.1.2.2: Test get with sufficient data // 1.1.2.2.1: Test get with complete retrieval of data lResult = lConnectionBuffer_1.Put(lOurData + lOurSize - 1, 1); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize); lResult = lConnectionBuffer_1.Get(lOurSize); NL_TEST_ASSERT(inSuite, lResult == nullptr); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 0); // 1.1.2.2.2: Test get with partial retrieval of data lResult = lConnectionBuffer_1.Put(lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize); lResult = lConnectionBuffer_1.Get(lOurSize - 3); NL_TEST_ASSERT(inSuite, lResult == nullptr); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 3); lResult = lConnectionBuffer_1.Get(3); NL_TEST_ASSERT(inSuite, lResult == nullptr); // 1.2: Test get on a buffer-owned backing store lStatus = lConnectionBuffer_2.Init(nullptr, kCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); // 1.2.1: Test get with a pointer and a size // 1.2.1.1: Test get with insufficient data lResult = lConnectionBuffer_2.Put(lOurData, lOurSize - 1); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize - 1); lResult = lConnectionBuffer_2.Get(lCopyBuffer, lOurSize); NL_TEST_ASSERT(inSuite, lResult == nullptr); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize - 1); // 1.2.1.2: Test get with sufficient data // 1.2.1.2.1: Test get with complete retrieval of data lResult = lConnectionBuffer_2.Put(lOurData + lOurSize - 1, 1); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize); lResult = lConnectionBuffer_2.Get(lCopyBuffer, lOurSize); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 0); lComparison = memcmp(lResult, lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lComparison == 0); // 1.2.1.2.2: Test get with partial retrieval of data lResult = lConnectionBuffer_2.Put(lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize); lResult = lConnectionBuffer_2.Get(lCopyBuffer, lOurSize - 3); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 3); lComparison = memcmp(lResult, lOurData, lOurSize - 3); NL_TEST_ASSERT(inSuite, lComparison == 0); lResult = lConnectionBuffer_2.Get(lCopyBuffer + lOurSize - 3, 3); NL_TEST_ASSERT(inSuite, lResult != nullptr); lComparison = memcmp(lResult, lOurData + lOurSize - 3, 3); NL_TEST_ASSERT(inSuite, lComparison == 0); // 1.2.2: Test get with a size only // 1.2.2.1: Test get with insufficient data lResult = lConnectionBuffer_2.Put(lOurData, lOurSize - 1); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize - 1); lResult = lConnectionBuffer_2.Get(lOurSize); NL_TEST_ASSERT(inSuite, lResult == nullptr); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize - 1); // 1.2.2.2: Test get with sufficient data // 1.2.2.2.1: Test get with complete retrieval of data lResult = lConnectionBuffer_2.Put(lOurData + lOurSize - 1, 1); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize); lResult = lConnectionBuffer_2.Get(lOurSize); NL_TEST_ASSERT(inSuite, lResult == nullptr); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 0); // 1.2.2.2.2: Test get with partial retrieval of data lResult = lConnectionBuffer_2.Put(lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lResult != nullptr); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize); lResult = lConnectionBuffer_2.Get(lOurSize - 3); NL_TEST_ASSERT(inSuite, lResult == nullptr); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 3); lResult = lConnectionBuffer_2.Get(3); NL_TEST_ASSERT(inSuite, lResult == nullptr); } static void TestSetSize(nlTestSuite *inSuite, void *inContext __attribute__((unused))) { constexpr size_t kCapacity = 257; const char * const kTestData = "This is a test."; const size_t kTestDataLength = strlen(kTestData); ConnectionBuffer lConnectionBuffer_1; ConnectionBuffer lConnectionBuffer_2; const uint8_t * lOurData; size_t lOurSize; uint8_t lBackingBuffer[kCapacity]; size_t lSize; Status lStatus; lOurData = reinterpret_cast<const uint8_t *>(kTestData); lOurSize = kTestDataLength; // 1.1: Test set size on a caller-owned backing store lStatus = lConnectionBuffer_1.Init(&lBackingBuffer[0], kCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); // 1.1.1: Test set size with a size greater than capacity lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 0); lStatus = lConnectionBuffer_1.SetSize(kCapacity + 1); NL_TEST_ASSERT(inSuite, lStatus == -ENOSPC); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 0); // 1.1.2: Test set size with a size less than or equal to capacity lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 0); lStatus = lConnectionBuffer_1.SetSize(7); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 7); // 1.2: Test set on a buffer-owned backing store lStatus = lConnectionBuffer_2.Init(nullptr, kCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); // 1.2.1: Test set size with a size greater than capacity lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 0); lStatus = lConnectionBuffer_2.SetSize(kCapacity + 1); NL_TEST_ASSERT(inSuite, lStatus == -ENOSPC); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 0); // 1.2.2: Test set size with a size less than or equal to capacity lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 0); lStatus = lConnectionBuffer_2.SetSize(7); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == 7); } static void TestFlush(ConnectionBuffer &inBuffer, nlTestSuite *inSuite, const size_t &inExpectedCapacity) { inBuffer.Flush(); TestObservation(inBuffer, inSuite, inExpectedCapacity); } static void TestFlush(nlTestSuite *inSuite, void *inContext __attribute__((unused))) { constexpr size_t kCapacity = 257; const char * const kTestData = "This is a test."; const size_t kTestDataLength = strlen(kTestData); ConnectionBuffer lConnectionBuffer_1; ConnectionBuffer lConnectionBuffer_2; const uint8_t * lOurData; size_t lOurSize; uint8_t lBackingBuffer[kCapacity]; size_t lSize; uint8_t * lHead; Status lStatus; lOurData = reinterpret_cast<const uint8_t *>(kTestData); lOurSize = kTestDataLength; // 1.1: Test flush on a caller-owned backing store lStatus = lConnectionBuffer_1.Init(&lBackingBuffer[0], kCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lHead = lConnectionBuffer_1.Put(lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lHead != nullptr); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == kTestDataLength); TestFlush(lConnectionBuffer_1, inSuite, kCapacity); // 1.2: Test flush on a buffer-owned backing store lStatus = lConnectionBuffer_2.Init(nullptr, kCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lHead = lConnectionBuffer_2.Put(lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lHead != nullptr); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == kTestDataLength); TestFlush(lConnectionBuffer_2, inSuite, kCapacity); } static void TestReserve(nlTestSuite *inSuite, void *inContext __attribute__((unused))) { constexpr size_t kCapacity = 257; const char * const kTestData = "This is a test."; const size_t kTestDataLength = strlen(kTestData); ConnectionBuffer lConnectionBuffer_1; ConnectionBuffer lConnectionBuffer_2; ConnectionBuffer lConnectionBuffer_3; const uint8_t * lOurData; size_t lOurSize; uint8_t lBackingBuffer[kCapacity]; size_t lSize; size_t lReserveCapacity; size_t lActualCapacity; uint8_t * lHead; int lComparison; Status lStatus; lOurData = reinterpret_cast<const uint8_t *>(kTestData); lOurSize = kTestDataLength; // 1.1: Test reserve on a caller-owned backing store lStatus = lConnectionBuffer_1.Init(&lBackingBuffer[0], kCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lHead = lConnectionBuffer_1.Put(lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lHead != nullptr); lSize = lConnectionBuffer_1.GetSize(); NL_TEST_ASSERT(inSuite, lSize == kTestDataLength); lStatus = lConnectionBuffer_1.Reserve(kCapacity << 1); NL_TEST_ASSERT(inSuite, lStatus == kError_BufferNotOwned); // 1.2: Test reserve on a buffer-owned backing store // 1.2.1: Test reserve at less than or equal to current capacity lStatus = lConnectionBuffer_3.Init(nullptr, kCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lHead = lConnectionBuffer_3.Put(lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lHead != nullptr); lSize = lConnectionBuffer_3.GetSize(); NL_TEST_ASSERT(inSuite, lSize == kTestDataLength); lReserveCapacity = kCapacity - 1; lStatus = lConnectionBuffer_3.Reserve(lReserveCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lSize = lConnectionBuffer_3.GetSize(); NL_TEST_ASSERT(inSuite, lSize == kTestDataLength); // Note: capacity should be UNCHANGED lActualCapacity = lConnectionBuffer_3.GetCapacity(); NL_TEST_ASSERT(inSuite, lActualCapacity == kCapacity); lHead = lConnectionBuffer_3.GetHead(); NL_TEST_ASSERT(inSuite, lHead != nullptr); lComparison = memcmp(lHead, lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lComparison == 0); // 1.2.2: Test reserve at greater than current capacity lStatus = lConnectionBuffer_3.Init(nullptr, kCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lHead = lConnectionBuffer_3.Put(lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lHead != nullptr); lSize = lConnectionBuffer_3.GetSize(); NL_TEST_ASSERT(inSuite, lSize == kTestDataLength); lReserveCapacity = kCapacity << 1; lStatus = lConnectionBuffer_3.Reserve(lReserveCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lSize = lConnectionBuffer_3.GetSize(); NL_TEST_ASSERT(inSuite, lSize == kTestDataLength); lActualCapacity = lConnectionBuffer_3.GetCapacity(); NL_TEST_ASSERT(inSuite, lActualCapacity == lReserveCapacity); lHead = lConnectionBuffer_3.GetHead(); NL_TEST_ASSERT(inSuite, lHead != nullptr); lComparison = memcmp(lHead, lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lComparison == 0); } static void TestMutation(nlTestSuite *inSuite, void *inContext __attribute__((unused))) { TestDestroy(inSuite, inContext); TestPut(inSuite, inContext); TestGet(inSuite, inContext); TestSetSize(inSuite, inContext); TestFlush(inSuite, inContext); TestReserve(inSuite, inContext); } static void TestUtilities(nlTestSuite *inSuite, void *inContext __attribute__((unused))) { constexpr size_t kCapacity = 257; const char * const kTestData = "This is a test."; const size_t kTestDataLength = strlen(kTestData); ConnectionBuffer lConnectionBuffer_1; ConnectionBuffer lConnectionBuffer_2; ConnectionBuffer lConnectionBuffer_3; ConnectionBuffer lConnectionBuffer_4; const uint8_t * lOurData; size_t lOurSize; uint8_t lBackingBuffer[kCapacity]; size_t lSize; size_t lCapacity; Status lStatus; lOurData = reinterpret_cast<const uint8_t *>(kTestData); lOurSize = kTestDataLength; // 1.1: Test get on a caller-owned backing store // 1.1.1: Test put with insufficient head room lStatus = lConnectionBuffer_1.Init(&lBackingBuffer[0], kTestDataLength >> 1); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lStatus = Utilities::Put(lConnectionBuffer_1, lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lStatus == kError_BufferNotOwned); // 1.1.2: Test put with sufficient head room lStatus = lConnectionBuffer_2.Init(&lBackingBuffer[0], kCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lStatus = Utilities::Put(lConnectionBuffer_2, lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lSize = lConnectionBuffer_2.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize); lCapacity = lConnectionBuffer_2.GetCapacity(); NL_TEST_ASSERT(inSuite, lCapacity == kCapacity); // 1.2: Test get on a buffer-owned backing store // 1.2.1: Test put with insufficient head room lStatus = lConnectionBuffer_3.Init(nullptr, kTestDataLength >> 1); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lStatus = Utilities::Put(lConnectionBuffer_3, lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lSize = lConnectionBuffer_3.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize); // The requested size is 15, twice that rounded up to the capacity // of 7 is 35, and the next power of two up from that is 64. lCapacity = lConnectionBuffer_3.GetCapacity(); NL_TEST_ASSERT(inSuite, lCapacity == 64); // 1.2.2: Test put with sufficient head room lStatus = lConnectionBuffer_4.Init(nullptr, kCapacity); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lStatus = Utilities::Put(lConnectionBuffer_4, lOurData, lOurSize); NL_TEST_ASSERT(inSuite, lStatus == kStatus_Success); lSize = lConnectionBuffer_4.GetSize(); NL_TEST_ASSERT(inSuite, lSize == lOurSize); lCapacity = lConnectionBuffer_4.GetCapacity(); NL_TEST_ASSERT(inSuite, lCapacity == kCapacity); } /** * Test Suite. It lists all the test functions. */ static const nlTest sTests[] = { NL_TEST_DEF("Construction", TestConstruction), NL_TEST_DEF("Initialization", TestInitialization), NL_TEST_DEF("Observation", TestObservation), NL_TEST_DEF("Mutation", TestMutation), NL_TEST_DEF("Utilities", TestUtilities), NL_TEST_SENTINEL() }; int main(void) { nlTestSuite theSuite = { "Connection Buffer", &sTests[0], nullptr, nullptr, nullptr, nullptr, 0, 0, 0, 0, 0 }; // Generate human-readable output. nlTestSetOutputStyle(OUTPUT_DEF); // Run test suit againt one context. nlTestRunner(&theSuite, nullptr); return nlTestRunnerStats(&theSuite); }
; A109340: Expansion of x^2*(1+x+4*x^2)/((1+x+x^2)*(1-x)^3). ; 0,0,1,3,9,16,24,36,49,63,81,100,120,144,169,195,225,256,288,324,361,399,441,484,528,576,625,675,729,784,840,900,961,1023,1089,1156,1224,1296,1369,1443,1521,1600,1680,1764,1849,1935,2025,2116,2208,2304,2401 lpb $0,1 sub $0,1 add $1,$4 trn $1,$2 sub $2,$1 mov $3,$1 mov $1,$2 add $3,$0 add $2,$3 add $4,2 lpe add $1,$2
//////////////////////////////////////////////////////////////////////////////// // SbCamera.cpp #include "ApConfig.h" #include "BtTime.h" #include "MtMatrix3.h" #include "ShTouch.h" #include "UiKeyboard.h" #include "RsUtil.h" #include "ShHMD.h" #include "FsFile.h" #include "HlKeyboard.h" #include "HlModel.h" #include "ShIMU.h" #include <stdio.h> #include "ScMain.h" #include "ScCamera.h" //////////////////////////////////////////////////////////////////////////////// // Init void SbCamera::Init( MtVector2 v2Dimension ) { BtFloat width = v2Dimension.x; BtFloat height = v2Dimension.y; m_camera = RsCamera( 0.01f, 1000.0f, width / height, RsViewport( 0, 0, (BtU32)width, (BtU32)height ), MtDegreesToRadians( 60.0f ) ); m_camera.SetDimension(MtVector2(width, height)); m_camera.SetPerspective( BtTrue ); m_cameraData.m_v3Position = MtVector3( 0, 0, -2.0f ); m_cameraData.m_m3Rotation.SetIdentity(); MtMatrix3 m3Rotation; m3Rotation.LookAt( m_cameraData.m_v3Position, MtVector3( 0, 0, 0 ), MtVector3( 0, 1, 0 ) ); m_cameraData.m_m3Rotation = m3Rotation; m_speed = 100.0f; m_cameraData.m_pitch = 0; m_cameraData.m_yaw = 0; } //////////////////////////////////////////////////////////////////////////////// // SetPosition void SbCamera::SetPosition( const MtVector3 &v3Position ) { m_cameraData.m_v3Position = v3Position; } //////////////////////////////////////////////////////////////////////////////// // GetPosition MtVector3 SbCamera::GetPosition() { return m_cameraData.m_v3Position; } //////////////////////////////////////////////////////////////////////////////// // SetSpeed void SbCamera::SetSpeed( BtFloat speed ) { m_speed = speed; } //////////////////////////////////////////////////////////////////////////////// // Update void SbCamera::Update() { static MtMatrix3 m3StartingRotation; static BtBool isLoaded = BtFalse; if( isLoaded == BtFalse ) { // Load the camera FsFile file; BtChar filename[256]; sprintf(filename, "%s%s", ApConfig::GetResourcePath(), "camera.txt"); file.Open( filename, FsMode_Read ); if(file.IsOpen()) { file.Read(m_cameraData); file.Close(); } isLoaded = BtTrue; } BtFloat speed = BtTime::GetTick() * m_speed; if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_LSHIFT)) { speed = speed * 10.0f; } if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_W)) { MoveForward(speed); } if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_S)) { MoveBackward(speed); } if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_D)) { MoveRight(speed); } if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_A)) { MoveLeft(speed); } // Rotate the camera speed = BtTime::GetTick(); if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_LSHIFT)) { if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_LEFT)) { m_cameraData.m_yaw += speed; } if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_RIGHT)) { m_cameraData.m_yaw -= speed; } if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_UP)) { m_cameraData.m_pitch -= speed; } if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_DOWN)) { m_cameraData.m_pitch += speed; } } MtMatrix3 m3RotateY; m3RotateY.SetRotationX( m_cameraData.m_pitch); MtMatrix3 m3RotateX; m3RotateX.SetRotationY( m_cameraData.m_yaw); m_cameraData.m_m3Rotation = m3RotateX * m3RotateY; if( UiKeyboard::pInstance()->IsPressed(SaveCameraKey) ) { FsFile file; BtChar filename[256]; sprintf( filename, "%s%s", ApConfig::GetResourcePath(), "camera.txt" ); file.Open( filename, FsMode_Write ); if( file.IsOpen() ) { file.Write( m_cameraData ); file.Close(); } } } void SbCamera::Render() { // Set the rotation m_camera.SetRotation(m_cameraData.m_m3Rotation); // Set the position m_camera.SetPosition(m_cameraData.m_v3Position); // Update the camera m_camera.Update(); } //////////////////////////////////////////////////////////////////////////////// // SetFarPlane void SbCamera::SetFarPlane(BtFloat farPlane ) { m_camera.FarPlane( farPlane ); } //////////////////////////////////////////////////////////////////////////////// // MoveUpward void SbCamera::MoveRight( BtFloat speed ) { speed = BtTime::GetTick() * speed; MtMatrix3 m3Rotation = m_camera.GetRotation(); m_cameraData.m_v3Position += m3Rotation.Col0() * speed; } //////////////////////////////////////////////////////////////////////////////// // MoveDownward void SbCamera::MoveLeft( BtFloat speed ) { speed = BtTime::GetTick() * -speed; MtMatrix3 m3Rotation = m_camera.GetRotation(); m_cameraData.m_v3Position += m3Rotation.Col0() * speed; } //////////////////////////////////////////////////////////////////////////////// // MoveForward void SbCamera::MoveForward( BtFloat speed ) { speed = BtTime::GetTick() * speed; MtMatrix3 m3Rotation = m_camera.GetRotation(); m_cameraData.m_v3Position += m3Rotation.Col2() * speed; } //////////////////////////////////////////////////////////////////////////////// // MoveBackward void SbCamera::MoveBackward( BtFloat speed ) { speed = BtTime::GetTick() * speed; MtMatrix3 m3Rotation = m_camera.GetRotation(); m_cameraData.m_v3Position -= m3Rotation.Col2() * speed; } //////////////////////////////////////////////////////////////////////////////// // StrafeRight void SbCamera::StrafeRight( BtFloat speed ) { speed = BtTime::GetTick() * speed; MtMatrix3 m3Rotation = m_camera.GetRotation(); m_cameraData.m_v3Position += m3Rotation.Col0() * speed; } //////////////////////////////////////////////////////////////////////////////// // StrafeLeft void SbCamera::StrafeLeft( BtFloat speed ) { speed = BtTime::GetTick() * speed; MtMatrix3 m3Rotation = m_camera.GetRotation(); m_cameraData.m_v3Position -= m3Rotation.Col0() * speed; } //////////////////////////////////////////////////////////////////////////////// // GetCamera RsCamera &SbCamera::GetCamera() { return m_camera; }
; A202565: Indices of decagonal numbers which are also pentagonal. ; Submitted by Jon Maiga ; 1,56,5451,534106,52336901,5128482156,502538914351,49243685124206,4825378603257801,472837859434140256,46333284845942487251,4540189077042929610306,444892196265361159322701,43594895044928350684014356,4271854822206713005874084151 mul $0,2 mov $3,3 lpb $0 sub $0,1 mov $1,$3 mul $1,8 add $2,$1 add $3,$2 lpe mov $0,$3 div $0,24 mul $0,5 add $0,1
DATA SEGMENT NUMBER DW 1210h NUMB2 DW 9D4Bh NUMB1 DD 5A829D4Bh STRIN DB 'SOMETHING' DATA ENDS INITDS MACRO NUMBER INC NUMBER ENDM CODE1 SEGMENT INITDS AX TEST_START: SCASB NUMB3 DD 5A829D4Bh CMP BX, AX JB WORKPLACE DEC NUMB2 DEC WORD PTR [BX] WORKPLACE: AND NUMBER, BX OR CX, NUMB2 MOV AX,[SI] INC AX INITDS BX INITDS BL INITDS CL DEC NUMBER MOV AX, 0Bh ADD NUMB2, 0Bh MOV CX, DS:[DI] MOV DX, ES:[BX] JB TEST_START CODE1 ENDS END
; A278127: a(n) = 99*n + 71. ; 71,170,269,368,467,566,665,764,863,962,1061,1160,1259,1358,1457,1556,1655,1754,1853,1952,2051,2150,2249,2348,2447,2546,2645,2744,2843,2942,3041,3140,3239,3338,3437,3536,3635,3734,3833,3932,4031,4130,4229,4328,4427,4526 mul $0,99 add $0,71
; A049690: a(n) = Sum_{k=1..n} phi(2*k), where phi = Euler totient function, cf. A000010. ; 0,1,3,5,9,13,17,23,31,37,45,55,63,75,87,95,111,127,139,157,173,185,205,227,243,263,287,305,329,357,373,403,435,455,487,511,535,571,607,631,663,703,727,769,809,833,877,923,955,997,1037,1069,1117,1169,1205,1245,1293,1329,1385,1443,1475,1535,1595,1631,1695,1743,1783,1849,1913,1957,2005,2075,2123,2195,2267,2307,2379,2439,2487,2565,2629,2683,2763,2845,2893,2957,3041,3097,3177,3265,3313,3385,3473,3533,3625,3697,3761,3857,3941,4001 lpb $0 mov $2,$0 div $0,2 seq $2,2088 ; Sum of totient function: a(n) = Sum_{k=1..n} phi(k), cf. A000010. add $1,$2 lpe mov $0,$1
; A029716: Partial sums of Kempner numbers A002034. ; Submitted by Jon Maiga ; 1,3,6,10,15,18,25,29,35,40,51,55,68,75,80,86,103,109,128,133,140,151,174,178,188,201,210,217,246,251,282,290,301,318,325,331,368,387,400,405,446,453,496,507,513,536,583,589,603,613,630,643,696,705,716,723,742,771,830,835,896,927,934,942,955,966,1033,1050,1073,1080,1151,1157,1230,1267,1277,1296,1307,1320,1399,1405,1414,1455,1538,1545,1562,1605,1634,1645,1734,1740,1753,1776,1807,1854,1873,1881,1978,1992,2003,2013 mov $7,$0 mov $9,$0 add $9,1 lpb $9 mov $0,$7 sub $9,1 sub $0,$9 add $0,1 mov $2,2 mov $3,$0 mov $4,$0 mov $5,1 lpb $3 mov $6,$2 add $2,1 mul $5,$6 mov $6,$0 cmp $6,1 cmp $6,0 mov $0,$6 sub $3,$6 mod $5,$4 add $0,$5 lpe mov $0,$2 sub $0,1 add $8,$0 lpe mov $0,$8
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r12 push %r8 push %r9 lea addresses_WT_ht+0x18260, %r10 nop nop inc %r12 mov (%r10), %r8d nop nop nop inc %r9 pop %r9 pop %r8 pop %r12 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r14 push %r8 push %rbp push %rbx push %rdi push %rdx // Store mov $0x28b, %r8 nop nop and %rdi, %rdi mov $0x5152535455565758, %r10 movq %r10, %xmm4 vmovups %ymm4, (%r8) nop nop nop and $2512, %r8 // Store lea addresses_WT+0x18d70, %rdx nop nop and %rdi, %rdi mov $0x5152535455565758, %r10 movq %r10, %xmm4 vmovups %ymm4, (%rdx) and %r8, %r8 // Faulty Load lea addresses_RW+0x63f0, %r14 nop nop nop and $38217, %r10 mov (%r14), %edx lea oracles, %rbx and $0xff, %rdx shlq $12, %rdx mov (%rbx,%rdx,1), %rdx pop %rdx pop %rdi pop %rbx pop %rbp pop %r8 pop %r14 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'size': 1, 'NT': False, 'type': 'addresses_RW', 'same': False, 'AVXalign': False, 'congruent': 0}} {'OP': 'STOR', 'dst': {'size': 32, 'NT': False, 'type': 'addresses_P', 'same': False, 'AVXalign': False, 'congruent': 0}} {'OP': 'STOR', 'dst': {'size': 32, 'NT': False, 'type': 'addresses_WT', 'same': False, 'AVXalign': False, 'congruent': 5}} [Faulty Load] {'OP': 'LOAD', 'src': {'size': 4, 'NT': False, 'type': 'addresses_RW', 'same': True, 'AVXalign': True, 'congruent': 0}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'size': 4, 'NT': True, 'type': 'addresses_WT_ht', 'same': False, 'AVXalign': False, 'congruent': 1}} {'32': 21829} 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 */
db "WOOD GECKO@" ; species name dw 108, 110 ; height, weight db "It quickly scales" next "even vertical" next "walls. It senses" page "humidity with its" next "tail to predict" next "the weather.@"
; A184009: n-1+ceiling((3/4)n^2); complement of A184008. ; 1,3,6,10,15,21,27,35,43,52,62,73,85,97,111,125,140,156,173,191,209,229,249,270,292,315,339,363,389,415,442,470,499,529,559,591,623,656,690,725,761,797,835,873,912,952,993,1035,1077,1121,1165,1210,1256,1303,1351,1399,1449,1499,1550,1602,1655,1709,1763,1819,1875,1932,1990,2049,2109,2169,2231,2293 mov $1,3 mul $1,$0 add $1,13 mul $1,$0 div $1,7 add $1,1
; A075317: Pair the odd numbers such that the k-th pair is (r, r+2k) where r is the smallest odd number not included earlier: (1,3),(5,9),(7,13),(11,19),(15,25),(17,29),(21,35),(23,39),(27,45),... This is the sequence of the first member of pairs. ; Submitted by Christian Krause ; 1,5,7,11,15,17,21,23,27,31,33,37,41,43,47,49,53,57,59,63,65,69,73,75,79,83,85,89,91,95,99,101,105,109,111,115,117,121,125,127,131,133,137,141,143,147,151,153,157,159,163,167,169,173,175,179,183,185,189,193,195,199,201,205,209,211,215,219,221,225,227,231,235,237,241,243,247,251,253,257,261,263,267,269,273,277,279,283,287,289,293,295,299,303,305,309,311,315,319,321 mov $2,$0 add $0,1 mov $1,$0 pow $1,2 lpb $1 add $2,2 trn $1,$2 lpe add $0,$2 sub $0,2
; A141032: a(n) = 4*(16^n-1)/15. ; 0,4,68,1092,17476,279620,4473924,71582788,1145324612,18325193796,293203100740,4691249611844,75059993789508,1200959900632132,19215358410114116,307445734561825860,4919131752989213764,78706108047827420228,1259297728765238723652,20148763660243819578436,322380218563901113254980,5158083497022417812079684,82529335952358684993274948,1320469375237738959892399172,21127510003803823358278386756,338040160060861173732454188100,5408642560973778779719267009604,86538280975580460475508272153668 mov $1,16 pow $1,$0 div $1,15 mul $1,4 mov $0,$1
.MODEL SMALL .STACK 100H .CODE MAIN PROC ; display user prompt MOV AH,2 MOV DL,'?' INT 21H ;initialize character count XOR CX , CX ;read character MOV AH , 1 INT 21H ;while character is not a carriage return do WHILE_: CMP AL ,0DH JE END_WHILE PUSH AX INC CX INT 21H JMP WHILE_ END_WHILE: MOV AH , 2 MOV DL , 0DH INT 21H MOV DL , 0AH INT 21H JCXZ EXIT TOP: POP DX INT 21H LOOP TOP EXIT: MOV AH , 4CH INT 21H MAIN ENDP END MAIN
INCLUDE "constants/hardware.inc" INCLUDE "constants/other-hardware.inc" INCLUDE "constants/game-select.inc" INCLUDE "constants/actors.inc" INCLUDE "constants/sfx.inc" INCLUDE "constants/transition.inc" INCLUDE "constants/screens.inc" SECTION UNION "Game Variables", HRAM hCurrentSelection: DS 1 SECTION "Game Select Screen Setup", ROM0 ScreenSetupGameSelect:: ; Set palette ld a, GAME_SELECT_BGP ldh [hBGP], a ; Reset scroll xor a, a ldh [hSCX], a ldh [hSCY], a ; Set appropriate LCDC flags ld a, LCDCF_ON | LCDCF_BG8800 | LCDCF_BG9800 | LCDCF_BGON | LCDCF_OBJ16 | LCDCF_OBJON ldh [hLCDC], a ; Load background tiles ld a, BANK(xBackgroundTiles9000) ld [rROMB0], a ld de, xBackgroundTiles9000 ld hl, $9000 ld bc, xBackgroundTiles9000.end - xBackgroundTiles9000 rst LCDMemcopy ld a, BANK(xBackgroundTiles8000) ld [rROMB0], a ld de, xBackgroundTiles8000 ld hl, $8000 ld bc, xBackgroundTiles8000.end - xBackgroundTiles8000 rst LCDMemcopy ; Load sprite tiles ld de, SpriteTiles ld hl, $8800 ld bc, SpriteTiles.end - SpriteTiles rst LCDMemcopy ; Reset current selection ; TODO: Set it to the previously played game. Would probably require ; a separate "current/last game" variable. xor a, a ldh [hCurrentSelection], a ; Disable tile streaming ; a = 0 ldh [hTileStreamingEnable], a ; Create cursor actor ld de, ActorCursorDefinition call ActorNew ; Load background map ld a, BANK(xMap) ld [rROMB0], a ld de, xMap ld hl, _SCRN0 ld c, SCRN_Y_B call LCDMemcopyMap ; Set up text engine for game descriptions ld a, DESC_TEXT_LINE_LENGTH * 8 - 1 ld [wTextLineLength], a ld a, DESC_TEXT_LINE_COUNT ld [wTextNbLines], a ; wTextRemainingLines and wNewlinesUntilFull set in DrawDescription xor a, a ld [wTextStackSize], a ld [wTextFlags], a ASSERT DESC_TEXT_SPEED == 1 inc a ld [wTextLetterDelay], a ; Set up text tiles ld a, DESC_TEXT_TILES_START ; wTextCurTile set in DrawDescription ld [wWrapTileID], a ld a, DESC_TEXT_LAST_TILE ld [wLastTextTile], a ld a, HIGH(vDescTextTiles) & $F0 ld [wTextTileBlock], a ; Reset current selection ; TODO: Set it to the previously played game. Would probably require ; a separate "current/last game" variable. xor a, a ldh [hCurrentSelection], a jp UpdateSelection.initial SECTION "Game Select Cursor Actor Definition", ROM0 ActorCursorDefinition: DB ACTOR_CURSOR DB 0, 0 DB 0, 0 SECTION "Game Select Screen Sprite Tiles", ROM0 SpriteTiles: INCBIN "res/game-select/cursor.obj.2bpp" .end SECTION "Game Select Screen Background Tiles for $9000", ROMX xBackgroundTiles9000: INCBIN "res/game-select/background-1.bg.2bpp" .end SECTION "Game Select Screen Background Tiles for $8000", ROMX xBackgroundTiles8000: INCBIN "res/game-select/background-2.bg.2bpp" .end SECTION "Game Select Screen Background Map", ROMX xMap: INCBIN "res/game-select/background-1.bg.tilemap" INCBIN "res/game-select/background-2.bg.tilemap" SECTION "Game Select Screen Extra LYC Interrupt Handler", ROM0 LYCHandlerGameSelect:: ld hl, rLCDC .waitHBlank ldh a, [rSTAT] ASSERT STATF_HBL == 0 and a, STAT_MODE_MASK jr nz, .waitHBlank ; Switch tiles ASSERT LCDCF_BG8000 != 0 set LCDCB_BGTILE, [hl] ret SECTION "Game Select Screen Loop", ROM0 ScreenGameSelect:: ; Set up extra LYC interrupts ld a, LYCTable.gameSelect - LYCTable ldh [hLYCResetIndex], a .loop rst WaitVBlank ldh a, [hTransitionState] ldh [hScratch1], a ASSERT TRANSITION_STATE_OFF == 0 and a, a call nz, TransitionUpdate ; Calling SoundSystem_Process directly instead of SoundUpdate ; because this is in ROM0 and there is no sync data to be looking ; for call SoundSystem_Process ; Draw 2 characters per frame ASSERT DESC_TEXT_SPEED < 2 call PrintVWFChar call DrawVWFChars call PrintVWFChar call DrawVWFChars ; Check if the transition just ended ldh a, [hScratch1] ; Old transition state ld b, a ldh a, [hTransitionState] ; Transition state will only go from transition in to off here cp a, b jr nz, .transitionEnd ; Run the body of the game loop if the transition is off ASSERT TRANSITION_STATE_OFF == 0 or a, b jr z, .noTransition jr .loop .transitionEnd ; Start music ld c, BANK(Inst_GameSelect) ld de, Inst_GameSelect call Music_PrepareInst ld c, BANK(Music_GameSelect) ld de, Music_GameSelect call Music_Play jr .loop .noTransition call ActorsUpdate ; Move selection ldh a, [hNewKeys] bit PADB_LEFT, a call nz, MoveLeft ldh a, [hNewKeys] bit PADB_RIGHT, a call nz, MoveRight ldh a, [hNewKeys] bit PADB_UP, a call nz, MoveUp ldh a, [hNewKeys] bit PADB_DOWN, a call nz, MoveDown ldh a, [hNewKeys] ; B goes back to title screen bit PADB_B, a jr nz, .back ; If pressed A or START, jump to the selected game and a, PADF_A | PADF_START jr z, .loop ; Don't allow starting the non-existent game ldh a, [hCurrentSelection] cp a, GAME_NOTHING jr z, ScreenGameSelect ; Play start sound effect ld b, SFX_START call SFX_Play ; Transition to selected game ldh a, [hCurrentSelection] call TransitionStart jr .loop .back ld a, SCREEN_TITLE call TransitionStart jr .loop SECTION "Game Select Screen Selection", ROM0 MoveLeft: ld c, LOW(hCurrentSelection) ldh a, [c] cp a, SCREEN_JUKEBOX ret nc ; Move to jukebox if at the leftmost column of games ; 2 columns wide: lefmost = bit 0 reset rrca ; Move bit 0 to carry jr nc, .jukebox add a, a ; Equivalent to `rlca / dec a` when bit 0 is set ldh [c], a jr UpdateSelection .jukebox ld a, SCREEN_JUKEBOX ldh [c], a jr UpdateSelection MoveRight: ld c, LOW(hCurrentSelection) ldh a, [c] cp a, SCREEN_JUKEBOX jr nc, .jukebox ; Don't move if at the rightmost column of games or at last game ; 2 columns wide: rightmost = bit 0 set rrca ; Move bit 0 to carry ret c rlca ; Undo rrca cp a, GAME_COUNT - 1 ret z inc a ldh [c], a jr UpdateSelection .jukebox ; Go back to the first game xor a, a ldh [c], a jr UpdateSelection MoveUp: ld c, LOW(hCurrentSelection) ldh a, [c] cp a, SCREEN_JUKEBOX ret nc ; Don't move if already at the topmost row cp a, 2 ; 2 columns wide, 2nd row starts with 2 ret c ldh a, [c] sub a, 2 ; 2 columns wide ldh [c], a jr UpdateSelection MoveDown: ld c, LOW(hCurrentSelection) ldh a, [c] ; Don't move if already at the bottommost row of games or jukebox ; 2 columns wide ASSERT SCREEN_JUKEBOX > GAME_COUNT - 2 cp a, GAME_COUNT - 2 ret nc ldh a, [c] add a, 2 ; 2 columns wide ldh [c], a ; Fall-through UpdateSelection: ; Play the selection sound effect ld b, SFX_SELECT call SFX_Play ; Clear description box ld hl, vDescText ld de, SCRN_VX_B - DESC_TEXT_LINE_LENGTH ld b, DESC_TEXT_LINE_COUNT .clearLoop ld c, DESC_TEXT_LINE_LENGTH .clearRowLoop ldh a, [rSTAT] and a, STATF_BUSY jr nz, .clearRowLoop ASSERT DESC_TEXT_BLANK_TILE == 0 xor a, a ld [hli], a dec c jr nz, .clearRowLoop add hl, de dec b jr nz, .clearLoop ; Get the new selection's cursor position ldh a, [hCurrentSelection] .initial add a, a add a, LOW(CursorPositionTable) ld l, a ASSERT HIGH(CursorPositionTable.end - 1) == HIGH(CursorPositionTable) ld h, HIGH(CursorPositionTable) ; Update the position of the cursor ld a, [hli] ld [wActorXPosTable], a ld a, [hl] ld [wActorYPosTable], a ; Use the correct cursor size ld hl, wActorCelTable ldh a, [hCurrentSelection] ld b, a ; Save for getting description cp a, SCREEN_JUKEBOX ld a, [hl] jr z, .jukebox and a, ~1 jr z, .doneCel ld a, [hl] sub a, CEL_CURSOR_JUKEBOX - CEL_CURSOR_GAME jr .setCel .jukebox and a, ~1 jr nz, .doneCel ld a, [hl] add a, CEL_CURSOR_JUKEBOX - CEL_CURSOR_GAME .setCel ld [hl], a .doneCel ; Get pointer to description text ld a, b ; a = game number add a, a ; game number * 2 (Pointer) add a, b ; game number * 3 (+Bank) add a, LOW(DescTextTable) ld l, a ASSERT HIGH(DescTextTable.end - 1) == HIGH(DescTextTable) ld h, HIGH(DescTextTable) ld a, [hli] ld b, a ; b = bank number ld a, [hli] ld h, [hl] ld l, a ; hl = pointer to text ld a, TEXT_NEW_STR call PrintVWFText ; Reset pen position ld a, DESC_TEXT_LINE_COUNT ld [wTextRemainingLines], a ld [wNewlinesUntilFull], a ld a, DESC_TEXT_TILES_START ld [wTextCurTile], a ld hl, vDescText jp SetPenPosition SECTION "Game Select Screen Cursor Position Table", ROM0 CursorPositionTable: ; X,Y X,Y DB 65,16, 114,16 DB 65,57, 114,57 DB 65,98 ; Jukebox DB 5, 116 .end
; A131963: Expansion of f(x, x^2) * f(x^4, x^12) in powers of x where f(, ) is Ramanujan's general theta function. ; Submitted by Jon Maiga ; 1,1,1,0,1,2,1,1,0,1,0,1,2,1,1,1,1,1,0,2,0,0,1,0,2,1,3,1,0,1,1,1,0,0,1,1,1,0,1,2,2,1,1,0,1,1,1,2,0,0,1,1,2,0,0,2,0,1,0,1,1,2,2,1,1,1,1,1,0,1,1,0,1,0,1,3,0,1,0,0,1,2,2,0,1,1,2,0,0,2,0,2,1,0,1,1,2,1,0,1 mul $0,4 add $0,2 mul $0,6 seq $0,123331 ; Expansion of (c(q)^2/(3c(q^2))-1)/2 in powers of q where c(q) is a cubic AGM function. div $0,2
#include "../precomp.hpp" #if defined(ENABLE_TORCH_IMPORTER) && ENABLE_TORCH_IMPORTER #include "THFile.h" #include "THFilePrivate.h" namespace TH { #define IMPLEMENT_THFILE_RW(TYPEC, TYPE) \ long THFile_read##TYPEC##Raw(THFile *self, TYPE *data, long n) \ { \ return (*self->vtable->read##TYPEC)(self, data, n); \ } IMPLEMENT_THFILE_RW(Byte, unsigned char) IMPLEMENT_THFILE_RW(Char, char) IMPLEMENT_THFILE_RW(Short, short) IMPLEMENT_THFILE_RW(Int, int) IMPLEMENT_THFILE_RW(Long, int64) IMPLEMENT_THFILE_RW(Float, float) IMPLEMENT_THFILE_RW(Double, double) long THFile_readStringRaw(THFile *self, const char *format, char **str_) { return self->vtable->readString(self, format, str_); } void THFile_seek(THFile *self, long position) { self->vtable->seek(self, position); } void THFile_seekEnd(THFile *self) { self->vtable->seekEnd(self); } long THFile_position(THFile *self) { return self->vtable->position(self); } void THFile_close(THFile *self) { self->vtable->close(self); } void THFile_free(THFile *self) { self->vtable->free(self); } int THFile_isOpened(THFile *self) { return self->vtable->isOpened(self); } #define IMPLEMENT_THFILE_FLAGS(FLAG) \ int THFile_##FLAG(THFile *self) \ { \ return self->FLAG; \ } IMPLEMENT_THFILE_FLAGS(isQuiet) IMPLEMENT_THFILE_FLAGS(isReadable) IMPLEMENT_THFILE_FLAGS(isWritable) IMPLEMENT_THFILE_FLAGS(isBinary) IMPLEMENT_THFILE_FLAGS(isAutoSpacing) IMPLEMENT_THFILE_FLAGS(hasError) void THFile_binary(THFile *self) { self->isBinary = 1; } void THFile_ascii(THFile *self) { self->isBinary = 0; } void THFile_autoSpacing(THFile *self) { self->isAutoSpacing = 1; } void THFile_noAutoSpacing(THFile *self) { self->isAutoSpacing = 0; } void THFile_quiet(THFile *self) { self->isQuiet = 1; } void THFile_pedantic(THFile *self) { self->isQuiet = 0; } void THFile_clearError(THFile *self) { self->hasError = 0; } #define IMPLEMENT_THFILE_SCALAR(TYPEC, TYPE) \ TYPE THFile_read##TYPEC##Scalar(THFile *self) \ { \ TYPE scalar; \ THFile_read##TYPEC##Raw(self, &scalar, 1); \ return scalar; \ } IMPLEMENT_THFILE_SCALAR(Byte, unsigned char) IMPLEMENT_THFILE_SCALAR(Char, char) IMPLEMENT_THFILE_SCALAR(Short, short) IMPLEMENT_THFILE_SCALAR(Int, int) IMPLEMENT_THFILE_SCALAR(Long, int64) IMPLEMENT_THFILE_SCALAR(Float, float) IMPLEMENT_THFILE_SCALAR(Double, double) } // namespace #endif
/* * Copyright (c) 2013-, Stephen Miller * All rights reserved. * * Redistribution and use in source and binary forms, * with or without modification, are permitted provided * that the following conditions are met: * * 1. Redistributions of source code must retain the * above copyright notice, this list of conditions * and the following disclaimer. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or * other materials provided with the distribution. * * 3. Neither the name of the copyright holder nor the * names of its contributors may be used to endorse or * promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS * AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <cpu_tsdf/marching_cubes_tsdf_octree.h> void cpu_tsdf::MarchingCubesTSDFOctree::setInputTSDF (cpu_tsdf::TSDFVolumeOctree::ConstPtr tsdf_volume) { tsdf_volume_ = tsdf_volume; // Set the grid resolution so it mimics the tsdf's int res_x, res_y, res_z; tsdf_volume_->getResolution (res_x, res_y, res_z); setGridResolution (res_x, res_y, res_z); float size_x, size_y, size_z; tsdf_volume_->getGridSize (size_x, size_y, size_z); // Set the "input cloud" to the 8 corners of the tsdf, to trick our parent // into voxelizing it the same pcl::PointCloud<pcl::PointXYZ>::Ptr corner_cloud (new pcl::PointCloud<pcl::PointXYZ>); for (int x_i = 0; x_i <= res_x; x_i += res_x) { for (int y_i = 0; y_i <= res_y; y_i += res_y) { for (int z_i = 0; z_i <= res_z; z_i += res_z) { pcl::PointXYZ center = tsdf_volume_->getVoxelCenter (x_i, y_i, z_i); // Go from center to corner center.x += (x_i == 0 ? -1 : 1) * 0.5 * size_x / res_x; center.y += (y_i == 0 ? -1 : 1) * 0.5 * size_y / res_y; center.z += (z_i == 0 ? -1 : 1) * 0.5 * size_z / res_z; corner_cloud->points.push_back (center); } } } setInputCloud (corner_cloud); // No extending setPercentageExtendGrid (0); float iso_x = 0; float iso_y = 0; float iso_z = 0; PCL_INFO ("iso_x = %f, iso_y = %f, iso_z = %f\n", iso_x, iso_y, iso_z); setIsoLevel (std::min (iso_x, std::min (iso_y, iso_z))); // Initialize size_voxel_ which is needed by pcl::MarchingCubes::createSurface // If left uninitialized createSurface creates erroneous coordinates for the mesh getBoundingBox(); size_voxel_ = (upper_boundary_ - lower_boundary_)* Eigen::Array3f(res_x_, res_y_, res_z_).inverse(); } void cpu_tsdf::MarchingCubesTSDFOctree::voxelizeData () { // Do nothing, extending getGridValue instead to save memory } float cpu_tsdf::MarchingCubesTSDFOctree::getGridValue (Eigen::Vector3i pos) { pcl::PointXYZ ctr = tsdf_volume_->getVoxelCenter (pos[0], pos[1], pos[2]); const cpu_tsdf::OctreeNode* voxel = tsdf_volume_->octree_->getContainingVoxel (ctr.x, ctr.y, ctr.z); float d; float w; voxel->getData (d, w); //float size_x, size_y, size_z; //voxel->getSize (size_x, size_y, size_z); if (w < w_min_ || fabs(d) >= 1) return (std::numeric_limits<float>::quiet_NaN ()); float max_dist_pos, max_dist_neg; tsdf_volume_->getDepthTruncationLimits (max_dist_pos, max_dist_neg); return (d * max_dist_neg); //was fabs } void cpu_tsdf::MarchingCubesTSDFOctree::performReconstruction (pcl::PolygonMesh &output) { getBoundingBox (); voxelizeData (); // Run the actual marching cubes algorithm, store it into a point cloud, // and copy the point cloud + connectivity into output pcl::PointCloud<pcl::PointXYZ> cloud; // Recursive reconstruction OctreeNode::Ptr root = tsdf_volume_->octree_->getRoot (); if (color_by_confidence_ || color_by_rgb_) { pcl::PointCloud<pcl::PointXYZRGB> cloud_colored; reconstructVoxel (root.get (), cloud, &cloud_colored); pcl::transformPointCloud (cloud_colored, cloud_colored, tsdf_volume_->getGlobalTransform ()); pcl::toPCLPointCloud2 (cloud_colored, output.cloud); } else { reconstructVoxel (root.get (), cloud); pcl::transformPointCloud (cloud, cloud, tsdf_volume_->getGlobalTransform ()); pcl::toPCLPointCloud2 (cloud, output.cloud); } output.polygons.resize (cloud.size () / 3); for (size_t i = 0; i < output.polygons.size (); ++i) { pcl::Vertices v; v.vertices.resize (3); for (int j = 0; j < 3; ++j) { v.vertices[j] = static_cast<int> (i) * 3 + j; } output.polygons[i] = v; } } bool cpu_tsdf::MarchingCubesTSDFOctree::getValidNeighborList1D (std::vector<float> &leaf, Eigen::Vector3i &index3d) { leaf = std::vector<float> (8, 0.0f); leaf[0] = getGridValue (index3d); if (std::isnan (leaf[0])) return (false); leaf[1] = getGridValue (index3d + Eigen::Vector3i (1, 0, 0)); if (std::isnan (leaf[1])) return (false); leaf[2] = getGridValue (index3d + Eigen::Vector3i (1, 0, 1)); if (std::isnan (leaf[2])) return (false); leaf[3] = getGridValue (index3d + Eigen::Vector3i (0, 0, 1)); if (std::isnan (leaf[3])) return (false); leaf[4] = getGridValue (index3d + Eigen::Vector3i (0, 1, 0)); if (std::isnan (leaf[4])) return (false); leaf[5] = getGridValue (index3d + Eigen::Vector3i (1, 1, 0)); if (std::isnan (leaf[5])) return (false); leaf[6] = getGridValue (index3d + Eigen::Vector3i (1, 1, 1)); if (std::isnan (leaf[6])) return (false); leaf[7] = getGridValue (index3d + Eigen::Vector3i (0, 1, 1)); if (std::isnan (leaf[7])) return (false); return (true); } void cpu_tsdf::MarchingCubesTSDFOctree::reconstructVoxel (const OctreeNode* voxel, pcl::PointCloud<pcl::PointXYZ> &output, pcl::PointCloud<pcl::PointXYZRGB>* output_colored) { if (voxel->hasChildren ()) { const std::vector <OctreeNode::Ptr> &children = voxel->getChildren (); for (size_t i = 0; i < children.size (); i++) reconstructVoxel (children[i].get (), output, output_colored); } else { float d; float w; voxel->getData (d, w); if (w >= w_min_ && fabs (d) < 1) { float x, y, z; voxel->getCenter (x, y, z); Eigen::Vector3i idx; tsdf_volume_->getVoxelIndex (x, y, z, idx (0), idx (1), idx (2)); if (idx (0) <= 0 || idx (0) >= res_x_-1 || idx (1) <= 0 || idx (1) >= res_y_-1 || idx (2) <= 0 || idx (2) >= res_z_-1) return; // Reconstruct std::vector<float> leaf_node; if (!getValidNeighborList1D (leaf_node, idx)) return; createSurface (leaf_node, idx, output); if (output_colored != NULL) { for (size_t i = output_colored->size (); i < output.size (); ++i) { pcl::PointXYZRGB pt_rgb; pt_rgb.getVector3fMap () = output.at (i).getVector3fMap (); // Color by variance instead uint8_t r, g, b; if (color_by_confidence_) { //float std_dev = std::sqrt (voxel->getVariance ()); float std_dev = (100. - voxel->w_)/100.; pt_rgb.r = std::max (0., std::min ((1-std_dev)*255., 255.)); pt_rgb.g = 0; pt_rgb.b = std::max (0., std::min ((std_dev)*255., 255.)); } // Color by rgb else if (color_by_rgb_ && voxel->getRGB (r, g, b)) { pt_rgb.r = r; pt_rgb.g = g; pt_rgb.b = b; } output_colored->push_back (pt_rgb); } } } } }
; A232423: a(n) = ceiling(sqrt(n^4 - n^3 - n^2 + n + 1))^2 - (n^4 - n^3 - n^2 + n + 1). ; 0,0,2,0,15,3,38,8,71,15,114,24,167,35,230,48,303,63,386,80,479,99,582,120,695,143,818,168,951,195,1094,224,1247,255,1410,288,1583,323,1766,360,1959,399,2162,440,2375,483,2598,528,2831,575,3074,624,3327,675 mov $3,$0 mov $5,2 lpb $5 mov $0,$3 sub $5,1 add $0,$5 sub $0,1 mov $2,1 mov $4,$0 lpb $0 div $0,2 pow $0,2 add $4,1 mul $0,$4 mov $4,$2 mov $2,$0 mov $0,1 mul $4,2 lpe add $2,$4 mov $4,$2 mov $6,$5 lpb $6 mov $1,$4 sub $6,1 lpe lpe lpb $3 sub $1,$4 mov $3,0 lpe sub $1,1
LD A, A LD A, B LD A, C LD A, D LD A, E LD A, H LD A, L LD A, I LD A, R LD B, A LD B, B LD B, C LD B, D LD B, E LD B, H LD B, L LD C, A LD C, B LD C, C LD C, D LD C, E LD C, H LD C, L LD D, A LD D, B LD D, C LD D, D LD D, E LD D, H LD D, L LD E, A LD E, B LD E, C LD E, D LD E, E LD E, H LD H, A LD H, B LD H, C LD H, D LD H, E LD H, H LD H, L LD L, A LD L, B LD L, C LD L, D LD L, E LD L, H LD L, L LD E, A LD I, A LD R, A LD (HL), A LD (HL), B LD (HL), C LD (HL), D LD (HL), E LD (HL), H LD (HL), L LD A, (HL) LD B, (HL) LD C, (HL) LD D, (HL) LD E, (HL) LD H, (HL) LD L, (HL) LD (BC), A LD (DE), A LD A, (BC) LD A, (DE) LD A, (IX+3DH) LD B, (IX+3DH) LD C, (IX+3DH) LD D, (IX+3DH) LD E, (IX+3DH) LD H, (IX+3DH) LD L, (IX+3DH) LD A, (IY+1DH) LD B, (IY+8DH) LD C, (IY+2DH) LD D, (IY+15H) LD E, (IY+3DH) LD H, (IY+3DH) LD L, (IY+3DH) LD A, (IX+3DH) LD B, (IX+3DH) LD C, (IX+3DH) LD D, (IX+3DH) LD E, (IX+3DH) LD H, (IX+3DH) LD L, (IX+3DH) LD A, (IY+1DH) LD B, (IY+8DH) LD C, (IY+2DH) LD D, (IY+15H) LD E, (IY+3DH) LD H, (IY+3DH) LD (IX+3DH), A LD (IX+3DH), B LD (IX+3DH), C LD (IX+3DH), D LD (IX+3DH), E LD (IX+3DH), H LD (IX+3DH), L LD (IY+3DH), A LD (IY+3DH), B LD (IY+3DH), C LD (IY+3DH), D LD (IY+3DH), E LD (IY+3DH), H LD (IY+3DH), L LD A, 31H LD B, 31H LD C, 31H LD D, 31H LD E, 31H LD H, 31H LD L, 31H LD (BC), A LD (DE), A LD I, A LD R, A LD A, (8765H) LD (8762H), A LD (IX+87H), 65H LD (IY+87H), 65H
; A216134: Numbers n such that T_n and 2*T_n + 1 are triangular. ; Submitted by Jamie Morken(s2) ; 0,1,4,9,26,55,154,323,900,1885,5248,10989,30590,64051,178294,373319,1039176,2175865,6056764,12681873,35301410,73915375,205751698,430810379,1199208780,2510946901,6989500984,14634871029,40737797126,85298279275,237437281774,497154804623,1383885893520,2897630548465,8065878079348,16888628486169,47011382582570,98434140368551,274002417416074,573716213725139,1597003121913876,3343863141982285,9308016314067184,19489462638168573,54251094762489230,113592912687029155,316198552260868198,662068013484006359 lpb $0 add $1,$0 add $2,1 sub $2,$1 add $2,4 add $3,$1 add $1,$2 sub $1,$0 sub $0,1 sub $1,3 mov $2,$1 trn $1,3 trn $2,2 add $2,3 div $3,2 add $2,$3 mul $2,2 sub $2,4 mov $3,0 lpe mov $0,$2 div $0,2
.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, 02 ld d, 03 lbegin_waitm2: ldff a, (c) and a, d cmp a, b jrnz lbegin_waitm2 ld a, 08 ldff(c), a ld a, 02 ldff(ff), a ei ld hl, 8000 ld a, 01 .text@1000 lstatint: ld a, 05 ldff(43), a .text@10da ld(hl), a ld a, (hl) and a, 07 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
// Copyright (c) 2016-2019 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ #ifndef TAO_PEGTL_INTERNAL_REQUIRE_HPP #define TAO_PEGTL_INTERNAL_REQUIRE_HPP #include "../config.hpp" #include "skip_control.hpp" #include "trivial.hpp" #include "../analysis/generic.hpp" namespace tao { namespace TAO_PEGTL_NAMESPACE { namespace internal { template< unsigned Amount > struct require; template<> struct require< 0 > : trivial< true > { }; template< unsigned Amount > struct require { using analyze_t = analysis::generic< analysis::rule_type::opt >; template< typename Input > static bool match( Input& in ) noexcept( noexcept( in.size( 0 ) ) ) { return in.size( Amount ) >= Amount; } }; template< unsigned Amount > struct skip_control< require< Amount > > : std::true_type { }; } // namespace internal } // namespace TAO_PEGTL_NAMESPACE } // namespace tao #endif
; A047310: Numbers that are congruent to {0, 1, 3, 4, 5, 6} mod 7. ; 0,1,3,4,5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,24,25,26,27,28,29,31,32,33,34,35,36,38,39,40,41,42,43,45,46,47,48,49,50,52,53,54,55,56,57,59,60,61,62,63,64,66,67,68,69,70,71,73,74,75,76,77,78 mov $1,$0 mul $1,7 add $1,4 div $1,6
; $Id: ASMAtomicUoDecU32.asm 69111 2017-10-17 14:26:02Z vboxsync $ ;; @file ; IPRT - ASMAtomicUoDecU32(). ; ; ; Copyright (C) 2014-2017 Oracle Corporation ; ; This file is part of VirtualBox Open Source Edition (OSE), as ; available from http://www.virtualbox.org. This file is free software; ; you can redistribute it and/or modify it under the terms of the GNU ; General Public License (GPL) as published by the Free Software ; Foundation, in version 2 as it comes in the "COPYING" file of the ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. ; ; The contents of this file may alternatively be used under the terms ; of the Common Development and Distribution License Version 1.0 ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the ; VirtualBox OSE distribution, in which case the provisions of the ; CDDL are applicable instead of those of the GPL. ; ; You may elect to license modified versions of this file under the ; terms and conditions of either the GPL or the CDDL or both. ; ;******************************************************************************* ;* Header Files * ;******************************************************************************* %include "iprt/asmdefs.mac" BEGINCODE ;; ; Atomically decrement an unsigned 32-bit value, unordered. ; ; @param pu32 x86:esp+4 gcc:rdi msc:rcx ; @returns the new decremented value. ; BEGINPROC_EXPORTED ASMAtomicUoDecU32 mov eax, -1 %ifdef RT_ARCH_AMD64 %ifdef ASM_CALL64_MSC xadd [rcx], eax %else xadd [rdi], eax %endif %elifdef RT_ARCH_X86 mov ecx, [esp + 04h] xadd [ecx], eax %endif dec eax ret ENDPROC ASMAtomicUoDecU32
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r12 push %r8 push %rax push %rbx push %rcx push %rdi push %rsi lea addresses_normal_ht+0x10c4a, %rbx nop nop nop xor %r8, %r8 mov (%rbx), %r10w nop nop nop nop and $3683, %rax lea addresses_WT_ht+0x14b1, %r12 clflush (%r12) nop nop nop cmp $41066, %r10 mov $0x6162636465666768, %r8 movq %r8, %xmm1 movups %xmm1, (%r12) nop nop nop nop nop sub $13687, %r12 lea addresses_A_ht+0xb6d4, %rsi lea addresses_WC_ht+0x3ec4, %rdi nop add %r8, %r8 mov $121, %rcx rep movsw nop nop nop nop xor %r12, %r12 lea addresses_WC_ht+0x6e44, %rdi inc %r8 vmovups (%rdi), %ymm1 vextracti128 $0, %ymm1, %xmm1 vpextrq $0, %xmm1, %r10 nop cmp %r10, %r10 lea addresses_WT_ht+0x6ac4, %rbx clflush (%rbx) nop nop nop nop nop dec %r12 mov (%rbx), %rcx nop nop nop nop nop xor %r8, %r8 lea addresses_D_ht+0x1e6c4, %r12 nop cmp $61090, %rsi mov $0x6162636465666768, %rbx movq %rbx, (%r12) dec %rax lea addresses_normal_ht+0x129ed, %rsi lea addresses_normal_ht+0x7ec4, %rdi nop inc %rbx mov $94, %rcx rep movsq nop nop nop cmp $27716, %rdi lea addresses_normal_ht+0xf6c4, %rdi nop nop nop nop and $1170, %rax mov $0x6162636465666768, %r10 movq %r10, %xmm7 movups %xmm7, (%rdi) nop nop nop lfence lea addresses_UC_ht+0x1d330, %rax clflush (%rax) nop cmp %r12, %r12 mov $0x6162636465666768, %rdi movq %rdi, %xmm6 vmovups %ymm6, (%rax) nop nop nop nop and $51159, %r12 lea addresses_D_ht+0x1cff4, %rdi nop nop xor $16422, %r12 mov $0x6162636465666768, %rax movq %rax, %xmm7 movups %xmm7, (%rdi) nop nop nop nop and %rcx, %rcx pop %rsi pop %rdi pop %rcx pop %rbx pop %rax pop %r8 pop %r12 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r13 push %r15 push %rdi push %rsi // Store lea addresses_RW+0x15c44, %rsi nop nop nop nop and $15168, %r11 movw $0x5152, (%rsi) nop nop nop nop inc %rsi // Faulty Load lea addresses_D+0xcac4, %r10 clflush (%r10) nop nop nop nop and %rsi, %rsi mov (%r10), %r11d lea oracles, %r13 and $0xff, %r11 shlq $12, %r11 mov (%r13,%r11,1), %r11 pop %rsi pop %rdi pop %r15 pop %r13 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_D', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 6}} [Faulty Load] {'src': {'type': 'addresses_D', 'AVXalign': False, 'size': 4, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 2, 'NT': False, 'same': True, 'congruent': 1}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 0}} {'src': {'type': 'addresses_A_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WC_ht', 'congruent': 10, 'same': False}} {'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 32, 'NT': False, 'same': False, 'congruent': 7}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 11}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 10}} {'src': {'type': 'addresses_normal_ht', 'congruent': 0, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 10}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 32, 'NT': False, 'same': False, 'congruent': 0}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 1}} {'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 */
INCLUDE<P16F84A.INC> #DEFINE BOTAO0 PORTA,0 ;define o pino 0 de A como o botao 0. SOMA #DEFINE BOTAO1 PORTA,1 ;define o pino 1 de A como o botao 1. SUBTRAI TEMP EQU 0X2C ;registrador temporario ORG 0X00 GOTO INICIO ;--- A CONTÉM 2 BOTÕES, UM QUE SOMA 1 EM B E OUTRO QUE SUBTRAI 1 EM B ---; ;--- SE A SOMA PASSAR DE 1O ESSA SOMA NAO DEVE MAIS FUNCIONAR ---; ;--- LÓGICA: FAZER 10 - VALOR ATUAL, SE DER 0 ATIVA O BIT Z (VAI PRA 1) E USA ISSO COMO CONDIÇÃO DE PARADA ---; ;--- SE NAO DER 0 O BIT Z FICA 0 ENTAO PODE REALIZAR A SOMA ---; INICIO CLRW CLRF PORTA CLRF PORTB BCF STATUS, RP0 BSF TRISA, 0 ;seta o bit 0 de A como de entrada BSF TRISB, 1 ;seta o bit 1 de A como de entrada CLRF PORTB ;todos os bit de B sao 0 (de saida) BSF STATUS, RP0 ;---CONTROLE DOS BOTOES ---; MAIN BTFSS BOTAO0 ;quando a entrada ta em 1 o botao ta solto, quando ta em 0 o botao ta pressionado GOTO BOTAO0_PRESS ;quando da 0 ele ta pressionado GOTO CHECA_BOTAO1 ;se chegou e ta solto vai chegar o proximo botao BOTAO0_PRESS BTFSS BOTAO0 GOTO BOTAO0_PRESS ;se ele permanecer em 0 o botao ainda ta pressionado GOTO CHECA_VALOR ;antes de somar precisa checar se ja chegou a 10 CHECA_BOTAO1 BTFSS BOTAO1 GOTO BOTAO1_PRESS ;se tiver 0 o botao ta pressionado e vai para a label de pressionar GOTO MAIN ;se tiver 1 volta o botao ta solto e volta pro começo para checar o botao 0 novamente BOTAO1_PRESS BTFSS BOTAO1 GOTO BOTAO1_PRESS ;se tiver 0 ainda ta pressionado GOTO SUB ;se tiver em 1 foi solto e vai realizar a subtracao ;--- OPERACOES ---; SOMA INCF PORTB, 1 ;incrementa 1 no registrador GOTO MAIN SUB DECF PORTB,1 ;decrementa 1 no registrador GOTO MAIN CHECA_VALOR MOVF PORTB,0 ;coloca o que tem na porta B no registrador de trabalho MOVWF TEMP ;move o que tem no registrador de trabalho para temp MOVLW 0XA ;move a constante A que vale 10 para o registrador de trabalho SUBWF TEMP,0 ;subtrai o que tem em temp do registrador de trabalho. registrador de trabalho(10) - temp BTFSS STATUS,Z ;chegar o valor do bit Z do registrador de trabalho GOTO SOMA ;se ele tiver em 0 é pq a subtração nao deu 0 GOTO MAIN ;se ele tiver 1 é pq a subtração deu 0 então ja atingiu 10 END
#include "./time.hpp" #include <chrono> // chrono::system_clock #include <ctime> // localtime #include <sstream> // stringstream #include <iomanip> // put_time namespace Utils::Time { std::string getCurrentTimestamp(const char *format) { auto now = std::chrono::system_clock::now(); auto in_time_t = std::chrono::system_clock::to_time_t(now); std::stringstream ss; ss << std::put_time(std::localtime(&in_time_t), format); return ss.str(); } } //!namespace Utils::Time
; A074796: Number of numbers k <= n such that tau(k) == 2 (mod 3) where tau(k) = A000005(k) is the number of divisors of k. ; 0,1,2,2,3,3,4,4,4,4,5,5,6,6,6,7,8,8,9,9,9,9,10,11,11,11,11,11,12,13,14,14,14,14,14,14,15,15,15,16,17,18,19,19,19,19,20,20,20,20,20,20,21,22,22,23,23,23,24,24,25,25,25,25,25,26,27,27,27,28,29,29,30,30,30,30,30,31,32,32,33,33,34,34,34,34,34,35,36,36,36,36,36,36,36,36,37,37,37,37 mov $2,$0 mov $3,$0 lpb $3 mov $0,$2 sub $3,1 sub $0,$3 seq $0,74943 ; tau(n) (mod 3). div $0,2 add $1,$0 lpe mov $0,$1
#include "signverifymessagedialog.h" #include "ui_signverifymessagedialog.h" #include "addressbookpage.h" #include "base58.h" #include "guiutil.h" #include "init.h" #include "main.h" #include "optionsmodel.h" #include "walletmodel.h" #include "wallet.h" #include <string> #include <vector> #include <QClipboard> SignVerifyMessageDialog::SignVerifyMessageDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SignVerifyMessageDialog), model(0) { ui->setupUi(this); #if (QT_VERSION >= 0x040700) /* Do not move this to the XML file, Qt before 4.7 will choke on it */ ui->addressIn_SM->setPlaceholderText(tr("Enter a Boson address")); ui->signatureOut_SM->setPlaceholderText(tr("Click \"Sign Message\" to generate signature")); ui->addressIn_VM->setPlaceholderText(tr("Enter a Boson address")); ui->signatureIn_VM->setPlaceholderText(tr("Enter Boson signature")); #endif GUIUtil::setupAddressWidget(ui->addressIn_SM, this); GUIUtil::setupAddressWidget(ui->addressIn_VM, this); ui->addressIn_SM->installEventFilter(this); ui->messageIn_SM->installEventFilter(this); ui->signatureOut_SM->installEventFilter(this); ui->addressIn_VM->installEventFilter(this); ui->messageIn_VM->installEventFilter(this); ui->signatureIn_VM->installEventFilter(this); ui->signatureOut_SM->setFont(GUIUtil::bitcoinAddressFont()); ui->signatureIn_VM->setFont(GUIUtil::bitcoinAddressFont()); } SignVerifyMessageDialog::~SignVerifyMessageDialog() { delete ui; } void SignVerifyMessageDialog::setModel(WalletModel *model) { this->model = model; } void SignVerifyMessageDialog::setAddress_SM(QString address) { ui->addressIn_SM->setText(address); ui->messageIn_SM->setFocus(); } void SignVerifyMessageDialog::setAddress_VM(QString address) { ui->addressIn_VM->setText(address); ui->messageIn_VM->setFocus(); } void SignVerifyMessageDialog::showTab_SM(bool fShow) { ui->tabWidget->setCurrentIndex(0); if (fShow) this->show(); } void SignVerifyMessageDialog::showTab_VM(bool fShow) { ui->tabWidget->setCurrentIndex(1); if (fShow) this->show(); } void SignVerifyMessageDialog::on_addressBookButton_SM_clicked() { if (model && model->getAddressTableModel()) { AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::ReceivingTab, this); dlg.setModel(model->getAddressTableModel()); if (dlg.exec()) { setAddress_SM(dlg.getReturnValue()); } } } void SignVerifyMessageDialog::on_pasteButton_SM_clicked() { setAddress_SM(QApplication::clipboard()->text()); } void SignVerifyMessageDialog::on_signMessageButton_SM_clicked() { /* Clear old signature to ensure users don't get confused on error with an old signature displayed */ ui->signatureOut_SM->clear(); CBitcoinAddress addr(ui->addressIn_SM->text().toStdString()); if (!addr.IsValid()) { ui->addressIn_SM->setValid(false); ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_SM->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again.")); return; } CKeyID keyID; if (!addr.GetKeyID(keyID)) { ui->addressIn_SM->setValid(false); ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_SM->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again.")); return; } WalletModel::UnlockContext ctx(model->requestUnlock()); if (!ctx.isValid()) { ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_SM->setText(tr("Wallet unlock was cancelled.")); return; } CKey key; if (!pwalletMain->GetKey(keyID, key)) { ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_SM->setText(tr("Private key for the entered address is not available.")); return; } CDataStream ss(SER_GETHASH, 0); ss << strMessageMagic; ss << ui->messageIn_SM->document()->toPlainText().toStdString(); std::vector<unsigned char> vchSig; if (!key.SignCompact(Hash(ss.begin(), ss.end()), vchSig)) { ui->statusLabel_SM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_SM->setText(QString("<nobr>") + tr("Message signing failed.") + QString("</nobr>")); return; } ui->statusLabel_SM->setStyleSheet("QLabel { color: green; }"); ui->statusLabel_SM->setText(QString("<nobr>") + tr("Message signed.") + QString("</nobr>")); ui->signatureOut_SM->setText(QString::fromStdString(EncodeBase64(&vchSig[0], vchSig.size()))); } void SignVerifyMessageDialog::on_copySignatureButton_SM_clicked() { QApplication::clipboard()->setText(ui->signatureOut_SM->text()); } void SignVerifyMessageDialog::on_clearButton_SM_clicked() { ui->addressIn_SM->clear(); ui->messageIn_SM->clear(); ui->signatureOut_SM->clear(); ui->statusLabel_SM->clear(); ui->addressIn_SM->setFocus(); } void SignVerifyMessageDialog::on_addressBookButton_VM_clicked() { if (model && model->getAddressTableModel()) { AddressBookPage dlg(AddressBookPage::ForSending, AddressBookPage::SendingTab, this); dlg.setModel(model->getAddressTableModel()); if (dlg.exec()) { setAddress_VM(dlg.getReturnValue()); } } } void SignVerifyMessageDialog::on_verifyMessageButton_VM_clicked() { CBitcoinAddress addr(ui->addressIn_VM->text().toStdString()); if (!addr.IsValid()) { ui->addressIn_VM->setValid(false); ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_VM->setText(tr("The entered address is invalid.") + QString(" ") + tr("Please check the address and try again.")); return; } CKeyID keyID; if (!addr.GetKeyID(keyID)) { ui->addressIn_VM->setValid(false); ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_VM->setText(tr("The entered address does not refer to a key.") + QString(" ") + tr("Please check the address and try again.")); return; } bool fInvalid = false; std::vector<unsigned char> vchSig = DecodeBase64(ui->signatureIn_VM->text().toStdString().c_str(), &fInvalid); if (fInvalid) { ui->signatureIn_VM->setValid(false); ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_VM->setText(tr("The signature could not be decoded.") + QString(" ") + tr("Please check the signature and try again.")); return; } CDataStream ss(SER_GETHASH, 0); ss << strMessageMagic; ss << ui->messageIn_VM->document()->toPlainText().toStdString(); CKey key; if (!key.SetCompactSignature(Hash(ss.begin(), ss.end()), vchSig)) { ui->signatureIn_VM->setValid(false); ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_VM->setText(tr("The signature did not match the message digest.") + QString(" ") + tr("Please check the signature and try again.")); return; } if (!(CBitcoinAddress(key.GetPubKey().GetID()) == addr)) { ui->statusLabel_VM->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_VM->setText(QString("<nobr>") + tr("Message verification failed.") + QString("</nobr>")); return; } ui->statusLabel_VM->setStyleSheet("QLabel { color: green; }"); ui->statusLabel_VM->setText(QString("<nobr>") + tr("Message verified.") + QString("</nobr>")); } void SignVerifyMessageDialog::on_clearButton_VM_clicked() { ui->addressIn_VM->clear(); ui->signatureIn_VM->clear(); ui->messageIn_VM->clear(); ui->statusLabel_VM->clear(); ui->addressIn_VM->setFocus(); } bool SignVerifyMessageDialog::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::FocusIn) { if (ui->tabWidget->currentIndex() == 0) { /* Clear status message on focus change */ ui->statusLabel_SM->clear(); /* Select generated signature */ if (object == ui->signatureOut_SM) { ui->signatureOut_SM->selectAll(); return true; } } else if (ui->tabWidget->currentIndex() == 1) { /* Clear status message on focus change */ ui->statusLabel_VM->clear(); } } return QDialog::eventFilter(object, event); }
JoeyPhoneCalleeScript: gettrainername STRING_BUFFER_3, YOUNGSTER, JOEY1 checkflag ENGINE_JOEY iftrue .WantsBattle farscall PhoneScript_AnswerPhone_Male checkflag ENGINE_JOEY_MONDAY_AFTERNOON iftrue .NotMonday readvar VAR_WEEKDAY ifnotequal MONDAY, .NotMonday checktime DAY iftrue JoeyMondayAfternoon .NotMonday: special RandomPhoneMon farsjump UnknownScript_0xa0930 .WantsBattle: getlandmarkname STRING_BUFFER_5, ROUTE_101 farsjump UnknownScript_0xa0a4b JoeyPhoneCallerScript: gettrainername STRING_BUFFER_3, YOUNGSTER, JOEY1 farscall PhoneScript_GreetPhone_Male checkflag ENGINE_JOEY iftrue .Generic checkflag ENGINE_JOEY_MONDAY_AFTERNOON iftrue .Generic farscall PhoneScript_Random3 ifequal 0, JoeyWantsBattle ifequal 1, JoeyWantsBattle .Generic: farsjump Phone_GenericCall_Male JoeyMondayAfternoon: setflag ENGINE_JOEY_MONDAY_AFTERNOON JoeyWantsBattle: getlandmarkname STRING_BUFFER_5, ROUTE_101 setflag ENGINE_JOEY farsjump PhoneScript_WantsToBattle_Male
// // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE.md file in the project root for full license information. // #include "stdafx.h" #include "CNTKLibrary.h" #include "Utils.h" #include "TensorView.h" #include "Matrix.h" #include <algorithm> #include "TensorShape.h" using namespace Microsoft::MSR::CNTK; namespace CNTK { template <typename ElementType> static TensorView<ElementType>* AllocateTensorView(const NDShape& viewShape, const DeviceDescriptor& device, void* dataBuffer, size_t bufferSizeInBytes) { if (dataBuffer == nullptr) InvalidArgument("Cannot create a NDArrayView over a null data buffer"); if (bufferSizeInBytes < (viewShape.TotalSize() * sizeof(ElementType))) InvalidArgument("Size of the specified buffer for creating the NDArrayView is smaller than the specified view shape"); auto matrixDims = GetMatrixDimensions(viewShape); std::shared_ptr<Matrix<ElementType>> matrix = std::make_shared<Matrix<ElementType>>(matrixDims.first, matrixDims.second, (ElementType*)dataBuffer, AsCNTKImplDeviceId(device), matrixFlagDontOwnBuffer); return new TensorView<ElementType>(matrix, AsTensorViewShape(viewShape)); } static void* AllocateTensorView(CNTK::DataType dataType, const NDShape& viewShape, const DeviceDescriptor& device, void* dataBuffer, size_t bufferSizeInBytes) { switch (dataType) { case DataType::Float: return AllocateTensorView<float>(viewShape, device, dataBuffer, bufferSizeInBytes); case DataType::Double: return AllocateTensorView<double>(viewShape, device, dataBuffer, bufferSizeInBytes); default: LogicError("Unsupported DataType %s", DataTypeName(dataType)); break; } } template <typename ElementType> static TensorView<ElementType>* AllocateTensorView(const NDShape& viewShape, CNTK::StorageFormat storageType, const DeviceDescriptor& device) { auto matrixDims = GetMatrixDimensions(viewShape); std::shared_ptr<Matrix<ElementType>> matrix = std::make_shared<Matrix<ElementType>>(matrixDims.first, matrixDims.second, AsCNTKImplDeviceId(device), IsSparseStorageFormat(storageType) ? MatrixType::SPARSE : MatrixType::DENSE, AsCNTKImplMatrixFormat(storageType)); return new TensorView<ElementType>(matrix, AsTensorViewShape(viewShape)); } static void* AllocateTensorView(CNTK::DataType dataType, CNTK::StorageFormat storageType, const NDShape& viewShape, const DeviceDescriptor& device) { switch (dataType) { case DataType::Float: return AllocateTensorView<float>(viewShape, storageType, device); case DataType::Double: return AllocateTensorView<double>(viewShape, storageType, device); default: LogicError("Unsupported DataType %s", DataTypeName(dataType)); break; } } NDArrayView::NDArrayView(CNTK::DataType dataType, const NDShape& viewShape, void* dataBuffer, size_t bufferSizeInBytes, const DeviceDescriptor& device, bool readOnly/* = false*/) : NDArrayView(dataType, device, StorageFormat::Dense, viewShape, readOnly, AllocateTensorView(dataType, viewShape, device, dataBuffer, bufferSizeInBytes)) { } template <typename ElementType> NDArrayView::NDArrayView(const NDShape& viewShape, const SparseIndexType* colStarts, const SparseIndexType* rowIndices, const ElementType* nonZeroValues, size_t numNonZeroValues, const DeviceDescriptor& device, bool readOnly/* = false*/) : NDArrayView(AsDataType<ElementType>(), device, StorageFormat::SparseCSC, viewShape, false, AllocateTensorView<ElementType>(viewShape, StorageFormat::SparseCSC, device)) { if ((colStarts == nullptr) || (rowIndices == nullptr) || (nonZeroValues == nullptr) || (numNonZeroValues == 0) || (numNonZeroValues > viewShape.TotalSize())) InvalidArgument("Invalid sparse CSC format initial data specified for NDArrayView construction"); auto sparseMatrix = GetWritableMatrix<ElementType>(1); sparseMatrix->SetMatrixFromCSCFormat(colStarts, rowIndices, nonZeroValues, numNonZeroValues, sparseMatrix->GetNumRows(), sparseMatrix->GetNumCols()); m_isReadOnly = readOnly; } NDArrayView::NDArrayView(CNTK::DataType dataType, const DeviceDescriptor& device, CNTK::StorageFormat storageType, const NDShape& viewShape, bool readOnly, void* tensorView) : m_dataType(dataType), m_device(device), m_storageFormat(storageType), m_viewShape(viewShape), m_isReadOnly(readOnly) { m_tensorView = std::shared_ptr<void>(tensorView, [this](void*) { switch (m_dataType) { case DataType::Float: delete GetTensorView<float>(); break; case DataType::Double: delete GetTensorView<double>(); break; default: LogicError("Unsupported DataType %s", DataTypeName(m_dataType)); break; } }); } NDArrayView::NDArrayView(CNTK::DataType dataType, CNTK::StorageFormat storageType, const NDShape& viewShape, const DeviceDescriptor& device) : NDArrayView(dataType, device, storageType, viewShape, false, AllocateTensorView(dataType, storageType, viewShape, device)) { } NDArrayView::~NDArrayView() { } void NDArrayView::SetValue(float value) { if (IsSparse()) LogicError("Filling a NDArrayView with a scalar is only allowed for NDArrayView objects with dense storage format"); GetWritableMatrix<float>()->SetValue(value); } void NDArrayView::SetValue(double value) { if (IsSparse()) LogicError("Filling a NDArrayView with a scalar is only allowed for NDArrayView objects with dense storage format"); GetWritableMatrix<double>()->SetValue(value); } template <typename ElementType> /*static*/ std::shared_ptr<Matrix<ElementType>> NDArrayView::GetMatrixImpl(const TensorView<ElementType>* tensorView, size_t rowColSplitPoint) { auto tensorShape = tensorView->GetShape(); if (tensorShape.GetRank() <= 2) return tensorView->AsMatrix(); size_t splitPoint = rowColSplitPoint; if (splitPoint == NDArrayView::AutoSelectRowColSplitPoint) { // Determine the split point by determining which of the axes can be // folded and selecting the non-foldable axis as the split point std::vector<bool> dimsToDrop(tensorShape.GetRank(), false); for (size_t k = 1; k < tensorShape.GetRank(); ++k) if (tensorShape.CanFlatten(k)) dimsToDrop[k - 1] = true; // There should be at most 2 dims we cannot drop auto numDimsThatCannotBeDropped = std::count_if(dimsToDrop.begin(), dimsToDrop.end(), [](const bool& val) { return !val; }); if (numDimsThatCannotBeDropped > 2) LogicError("The TensorView underlying this NDArrayView cannot be flattened to a Matrix"); // If we can fold the entire tensor down to a vector so any of the axes can be a valid split point, // let's pick the split point to be 1 splitPoint = 1; if (numDimsThatCannotBeDropped > 1) { while (dimsToDrop[splitPoint - 1]) splitPoint++; } } tensorShape.FlattenTo2DInPlace(splitPoint, "NDArrayView::GetMatrix"); return tensorView->Reshaped(tensorShape).AsMatrix(); } template <typename ElementType> std::shared_ptr<const Matrix<ElementType>> NDArrayView::GetMatrix(size_t rowColSplitPoint/* = AutoSelectRowColSplitPoint*/) const { return GetMatrixImpl<ElementType>(GetTensorView<ElementType>(), rowColSplitPoint); } template <typename ElementType> std::shared_ptr<Matrix<ElementType>> NDArrayView::GetWritableMatrix(size_t rowColSplitPoint/* = AutoSelectRowColSplitPoint*/) { return GetMatrixImpl<ElementType>(GetWritableTensorView<ElementType>(), rowColSplitPoint); } template <typename ElementType> const TensorView<ElementType>* NDArrayView::GetTensorView() const { if (AsDataType<ElementType>() != m_dataType) LogicError("NDArrayView::GetTensorView: The specified ElementType %s does not match the DataType %s", typeid(ElementType).name(), DataTypeName(m_dataType)); return (const TensorView<ElementType>*)(m_tensorView.get()); } template <typename ElementType> TensorView<ElementType>* NDArrayView::GetWritableTensorView() { if (IsReadOnly()) InvalidArgument("NDArrayView::GetWritableTensorView: Cannot get writable TensorView from a read-only NDArrayView"); return const_cast<TensorView<ElementType>*>(GetTensorView<ElementType>()); } NDArrayViewPtr NDArrayView::DeepClone(const DeviceDescriptor& device, bool readOnly/* = false*/) const { NDArrayViewPtr newView = MakeSharedObject<NDArrayView>(this->GetDataType(), this->GetStorageFormat(), this->Shape(), device); switch (m_dataType) { case DataType::Float: { auto newMatrix = newView->GetWritableMatrix<float>(); auto thisMatrix = GetMatrix<float>(); newMatrix->AssignValuesOf(*thisMatrix); break; } case DataType::Double: { auto newMatrix = newView->GetWritableMatrix<double>(); auto thisMatrix = GetMatrix<double>(); newMatrix->AssignValuesOf(*thisMatrix); break; } default: LogicError("Unsupported DataType %s", DataTypeName(m_dataType)); break; } newView->m_isReadOnly = readOnly; return newView; } void NDArrayView::CopyFrom(const NDArrayView& source) { if ((source.Shape() != Shape()) && (AsTensorShape(source.Shape()) != AsTensorShape(Shape()))) InvalidArgument("NDArrayView::CopyFrom: The 'source' view's shape must be same as the shape of this NDArrayView"); if (IsReadOnly()) RuntimeError("NDArrayView::CopyFrom: Cannot modify contents of a readonly NDArrayView"); switch (m_dataType) { case DataType::Float: { auto sourceMatrix = source.GetMatrix<float>(); auto destMatrix = GetWritableMatrix<float>(); destMatrix->AssignValuesOf(*sourceMatrix); break; } case DataType::Double: { auto sourceMatrix = source.GetMatrix<double>(); auto destMatrix = GetWritableMatrix<double>(); destMatrix->AssignValuesOf(*sourceMatrix); break; } default: LogicError("Unsupported DataType %s", DataTypeName(m_dataType)); break; } } NDArrayViewPtr NDArrayView::Alias(bool readOnly/* = false*/) const { void* tensorView = nullptr; switch (m_dataType) { case DataType::Float: tensorView = new TensorView<float>(*(GetTensorView<float>())); break; case DataType::Double: tensorView = new TensorView<double>(*(GetTensorView<double>())); break; default: LogicError("Unsupported DataType %s", DataTypeName(m_dataType)); break; } return MakeSharedObject<NDArrayView>(GetDataType(), Device(), GetStorageFormat(), Shape(), IsReadOnly() || readOnly, tensorView); } // TODO: This could actually be strided? template <typename ElementType> ElementType* NDArrayView::WritableDataBuffer() { if (IsReadOnly()) InvalidArgument("NDArrayView::WritableDataBuffer: Cannot get writable data buffer from a read-only NDArrayView"); return const_cast<ElementType*>(DataBuffer<ElementType>()); } // TODO: This could actually be strided? template <typename ElementType> const ElementType* NDArrayView::DataBuffer() const { if (AsDataType<ElementType>() != m_dataType) InvalidArgument("The specified ElementType %s does not match the DataType %s", typeid(ElementType).name(), DataTypeName(m_dataType)); if (IsSparse()) InvalidArgument("DataBuffer/WritableDataBuffer methods can only be called for NDArrayiew objects with dense storage format"); // First make sure that the underlying matrix is on the right device auto matrix = GetMatrix<ElementType>(); matrix->TransferToDeviceIfNotThere(AsCNTKImplDeviceId(m_device), true); return matrix->Data(); } template <typename ElementType> /*static*/ NDArrayViewPtr NDArrayView::RandomNormal(const NDShape& shape, double mean, double stdDev, unsigned long seed, const DeviceDescriptor& device /*= DeviceDescriptor::UseDefaultDevice()*/) { auto matrixDims = GetMatrixDimensions(shape); auto randomNormalMatrix = std::make_shared<Matrix<ElementType>>(Matrix<ElementType>::RandomGaussian(matrixDims.first, matrixDims.second, AsCNTKImplDeviceId(device), (ElementType)mean, (ElementType)stdDev, seed)); auto tensorView = new TensorView<ElementType>(randomNormalMatrix, AsTensorViewShape(shape)); return MakeSharedObject<NDArrayView>(AsDataType<ElementType>(), device, StorageFormat::Dense, shape, false, tensorView); } template <typename ElementType> /*static*/ NDArrayViewPtr NDArrayView::RandomUniform(const NDShape& shape, double rangeBegin, double rangeEnd, unsigned long seed, const DeviceDescriptor& device/* = DeviceDescriptor::UseDefaultDevice()*/) { auto matrixDims = GetMatrixDimensions(shape); auto randomUniformMatrix = std::make_shared<Matrix<ElementType>>(Matrix<ElementType>::RandomUniform(matrixDims.first, matrixDims.second, AsCNTKImplDeviceId(device), (ElementType)rangeBegin, (ElementType)rangeEnd, seed)); auto tensorView = new TensorView<ElementType>(randomUniformMatrix, AsTensorViewShape(shape)); return MakeSharedObject<NDArrayView>(AsDataType<ElementType>(), device, StorageFormat::Dense, shape, false, tensorView); } // Explicit template instantiations template CNTK_API NDArrayViewPtr NDArrayView::RandomUniform<float>(const NDShape& shape, double rangeBegin, double rangeEnd, unsigned long seed, const DeviceDescriptor& device/* = DeviceDescriptor::UseDefaultDevice()*/); template CNTK_API NDArrayViewPtr NDArrayView::RandomUniform<double>(const NDShape& shape, double rangeBegin, double rangeEnd, unsigned long seed, const DeviceDescriptor& device/* = DeviceDescriptor::UseDefaultDevice()*/); template CNTK_API NDArrayViewPtr NDArrayView::RandomNormal<float>(const NDShape& shape, double mean, double stdDev, unsigned long seed, const DeviceDescriptor& device/* = DeviceDescriptor::UseDefaultDevice()*/); template CNTK_API NDArrayViewPtr NDArrayView::RandomNormal<double>(const NDShape& shape, double mean, double stdDev, unsigned long seed, const DeviceDescriptor& device/* = DeviceDescriptor::UseDefaultDevice()*/); template CNTK_API const float* NDArrayView::DataBuffer<float>() const; template CNTK_API const double* NDArrayView::DataBuffer<double>() const; template CNTK_API float* NDArrayView::WritableDataBuffer<float>(); template CNTK_API double* NDArrayView::WritableDataBuffer<double>(); template std::shared_ptr<const Matrix<float>> NDArrayView::GetMatrix(size_t rowColSplitPoint/* = AutoSelectRowColSplitPoint*/) const; template std::shared_ptr<const Matrix<double>> NDArrayView::GetMatrix(size_t rowColSplitPoint/* = AutoSelectRowColSplitPoint*/) const; template std::shared_ptr<Matrix<float>> NDArrayView::GetWritableMatrix<float>(size_t rowColSplitPoint/* = AutoSelectRowColSplitPoint*/); template std::shared_ptr<Matrix<double>> NDArrayView::GetWritableMatrix<double>(size_t rowColSplitPoint/* = AutoSelectRowColSplitPoint*/); template TensorView<float>* NDArrayView::GetWritableTensorView<float>(); template TensorView<double>* NDArrayView::GetWritableTensorView<double>(); template CNTK_API NDArrayView::NDArrayView(const NDShape& viewShape, const SparseIndexType* colStarts, const SparseIndexType* rowIndices, const float* nonZeroValues, size_t numNonZeroValues, const DeviceDescriptor& device, bool readOnly/* = false*/); template CNTK_API NDArrayView::NDArrayView(const NDShape& viewShape, const SparseIndexType* colStarts, const SparseIndexType* rowIndices, const double* nonZeroValues, size_t numNonZeroValues, const DeviceDescriptor& device, bool readOnly/* = false*/); }
;------------------------------------------------------------------------------ ; ; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR> ; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; ; ZeroMem.Asm ; ; Abstract: ; ; ZeroMem function ; ; Notes: ; ;------------------------------------------------------------------------------ DEFAULT REL SECTION .text ;------------------------------------------------------------------------------ ; VOID * ; InternalMemZeroMem ( ; IN VOID *Buffer, ; IN UINTN Count ; ); ;------------------------------------------------------------------------------ global ASM_PFX(InternalMemZeroMem) ASM_PFX(InternalMemZeroMem): push rdi push rcx xor rax, rax mov rdi, rcx mov rcx, rdx shr rcx, 3 and rdx, 7 rep stosq mov ecx, edx rep stosb pop rax pop rdi ret
/*************************************************************************/ /* shader_language.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* 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 "shader_language.h" #include "os/os.h" #include "print_string.h" static bool _is_text_char(CharType c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'; } static bool _is_number(CharType c) { return (c >= '0' && c <= '9'); } static bool _is_hex(CharType c) { return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); } String ShaderLanguage::get_operator_text(Operator p_op) { static const char *op_names[OP_MAX] = { "==", "!=", "<", "<=", ">", ">=", "&&", "||", "!", "-", "+", "-", "*", "/", "%", "<<", ">>", "=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", "&=", "|=", "^=", "&", "|", "^", "~", "++", "--", "?", ":", "++", "--", "()", "construct", "index" }; return op_names[p_op]; } const char *ShaderLanguage::token_names[TK_MAX] = { "EMPTY", "IDENTIFIER", "TRUE", "FALSE", "REAL_CONSTANT", "INT_CONSTANT", "TYPE_VOID", "TYPE_BOOL", "TYPE_BVEC2", "TYPE_BVEC3", "TYPE_BVEC4", "TYPE_INT", "TYPE_IVEC2", "TYPE_IVEC3", "TYPE_IVEC4", "TYPE_UINT", "TYPE_UVEC2", "TYPE_UVEC3", "TYPE_UVEC4", "TYPE_FLOAT", "TYPE_VEC2", "TYPE_VEC3", "TYPE_VEC4", "TYPE_MAT2", "TYPE_MAT3", "TYPE_MAT4", "TYPE_SAMPLER2D", "TYPE_ISAMPLER2D", "TYPE_USAMPLER2D", "TYPE_SAMPLER2DARRAY", "TYPE_ISAMPLER2DARRAY", "TYPE_USAMPLER2DARRAY", "TYPE_SAMPLER3D", "TYPE_ISAMPLER3D", "TYPE_USAMPLER3D", "TYPE_SAMPLERCUBE", "INTERPOLATION_FLAT", "INTERPOLATION_NO_PERSPECTIVE", "INTERPOLATION_SMOOTH", "PRECISION_LOW", "PRECISION_MID", "PRECISION_HIGH", "OP_EQUAL", "OP_NOT_EQUAL", "OP_LESS", "OP_LESS_EQUAL", "OP_GREATER", "OP_GREATER_EQUAL", "OP_AND", "OP_OR", "OP_NOT", "OP_ADD", "OP_SUB", "OP_MUL", "OP_DIV", "OP_MOD", "OP_SHIFT_LEFT", "OP_SHIFT_RIGHT", "OP_ASSIGN", "OP_ASSIGN_ADD", "OP_ASSIGN_SUB", "OP_ASSIGN_MUL", "OP_ASSIGN_DIV", "OP_ASSIGN_MOD", "OP_ASSIGN_SHIFT_LEFT", "OP_ASSIGN_SHIFT_RIGHT", "OP_ASSIGN_BIT_AND", "OP_ASSIGN_BIT_OR", "OP_ASSIGN_BIT_XOR", "OP_BIT_AND", "OP_BIT_OR", "OP_BIT_XOR", "OP_BIT_INVERT", "OP_INCREMENT", "OP_DECREMENT", "CF_IF", "CF_ELSE", "CF_FOR", "CF_WHILE", "CF_DO", "CF_SWITCH", "CF_CASE", "CF_BREAK", "CF_CONTINUE", "CF_RETURN", "CF_DISCARD", "BRACKET_OPEN", "BRACKET_CLOSE", "CURLY_BRACKET_OPEN", "CURLY_BRACKET_CLOSE", "PARENTHESIS_OPEN", "PARENTHESIS_CLOSE", "QUESTION", "COMMA", "COLON", "SEMICOLON", "PERIOD", "UNIFORM", "VARYING", "IN", "OUT", "INOUT", "RENDER_MODE", "HINT_WHITE_TEXTURE", "HINT_BLACK_TEXTURE", "HINT_NORMAL_TEXTURE", "HINT_ANISO_TEXTURE", "HINT_ALBEDO_TEXTURE", "HINT_BLACK_ALBEDO_TEXTURE", "HINT_COLOR", "HINT_RANGE", "SHADER_TYPE", "CURSOR", "ERROR", "EOF", }; String ShaderLanguage::get_token_text(Token p_token) { String name = token_names[p_token.type]; if (p_token.type == TK_INT_CONSTANT || p_token.type == TK_REAL_CONSTANT) { name += "(" + rtos(p_token.constant) + ")"; } else if (p_token.type == TK_IDENTIFIER) { name += "(" + String(p_token.text) + ")"; } else if (p_token.type == TK_ERROR) { name += "(" + String(p_token.text) + ")"; } return name; } ShaderLanguage::Token ShaderLanguage::_make_token(TokenType p_type, const StringName &p_text) { Token tk; tk.type = p_type; tk.text = p_text; tk.line = tk_line; if (tk.type == TK_ERROR) { _set_error(p_text); } return tk; } const ShaderLanguage::KeyWord ShaderLanguage::keyword_list[] = { { TK_TRUE, "true" }, { TK_FALSE, "false" }, { TK_TYPE_VOID, "void" }, { TK_TYPE_BOOL, "bool" }, { TK_TYPE_BVEC2, "bvec2" }, { TK_TYPE_BVEC3, "bvec3" }, { TK_TYPE_BVEC4, "bvec4" }, { TK_TYPE_INT, "int" }, { TK_TYPE_IVEC2, "ivec2" }, { TK_TYPE_IVEC3, "ivec3" }, { TK_TYPE_IVEC4, "ivec4" }, { TK_TYPE_UINT, "uint" }, { TK_TYPE_UVEC2, "uvec2" }, { TK_TYPE_UVEC3, "uvec3" }, { TK_TYPE_UVEC4, "uvec4" }, { TK_TYPE_FLOAT, "float" }, { TK_TYPE_VEC2, "vec2" }, { TK_TYPE_VEC3, "vec3" }, { TK_TYPE_VEC4, "vec4" }, { TK_TYPE_MAT2, "mat2" }, { TK_TYPE_MAT3, "mat3" }, { TK_TYPE_MAT4, "mat4" }, { TK_TYPE_SAMPLER2D, "sampler2D" }, { TK_TYPE_ISAMPLER2D, "isampler2D" }, { TK_TYPE_USAMPLER2D, "usampler2D" }, { TK_TYPE_SAMPLER2DARRAY, "sampler2DArray" }, { TK_TYPE_ISAMPLER2DARRAY, "isampler2DArray" }, { TK_TYPE_USAMPLER2DARRAY, "usampler2DArray" }, { TK_TYPE_SAMPLER3D, "sampler3D" }, { TK_TYPE_ISAMPLER3D, "isampler3D" }, { TK_TYPE_USAMPLER3D, "usampler3D" }, { TK_TYPE_SAMPLERCUBE, "samplerCube" }, { TK_INTERPOLATION_FLAT, "flat" }, { TK_INTERPOLATION_NO_PERSPECTIVE, "noperspective" }, { TK_INTERPOLATION_SMOOTH, "smooth" }, { TK_PRECISION_LOW, "lowp" }, { TK_PRECISION_MID, "mediump" }, { TK_PRECISION_HIGH, "highp" }, { TK_CF_IF, "if" }, { TK_CF_ELSE, "else" }, { TK_CF_FOR, "for" }, { TK_CF_WHILE, "while" }, { TK_CF_DO, "do" }, { TK_CF_SWITCH, "switch" }, { TK_CF_CASE, "case" }, { TK_CF_BREAK, "break" }, { TK_CF_CONTINUE, "continue" }, { TK_CF_RETURN, "return" }, { TK_CF_DISCARD, "discard" }, { TK_UNIFORM, "uniform" }, { TK_VARYING, "varying" }, { TK_ARG_IN, "in" }, { TK_ARG_OUT, "out" }, { TK_ARG_INOUT, "inout" }, { TK_RENDER_MODE, "render_mode" }, { TK_HINT_WHITE_TEXTURE, "hint_white" }, { TK_HINT_BLACK_TEXTURE, "hint_black" }, { TK_HINT_NORMAL_TEXTURE, "hint_normal" }, { TK_HINT_ANISO_TEXTURE, "hint_aniso" }, { TK_HINT_ALBEDO_TEXTURE, "hint_albedo" }, { TK_HINT_BLACK_ALBEDO_TEXTURE, "hint_black_albedo" }, { TK_HINT_COLOR, "hint_color" }, { TK_HINT_RANGE, "hint_range" }, { TK_SHADER_TYPE, "shader_type" }, { TK_ERROR, NULL } }; ShaderLanguage::Token ShaderLanguage::_get_token() { #define GETCHAR(m_idx) (((char_idx + m_idx) < code.length()) ? code[char_idx + m_idx] : CharType(0)) while (true) { char_idx++; switch (GETCHAR(-1)) { case 0: return _make_token(TK_EOF); case 0xFFFF: return _make_token(TK_CURSOR); //for completion case '\t': case '\r': case ' ': continue; case '\n': tk_line++; continue; case '/': { switch (GETCHAR(0)) { case '*': { // block comment char_idx++; while (true) { if (GETCHAR(0) == 0) { return _make_token(TK_EOF); } if (GETCHAR(0) == '*' && GETCHAR(1) == '/') { char_idx += 2; break; } else if (GETCHAR(0) == '\n') { tk_line++; } char_idx++; } } break; case '/': { // line comment skip while (true) { if (GETCHAR(0) == '\n') { tk_line++; char_idx++; break; } if (GETCHAR(0) == 0) { return _make_token(TK_EOF); } char_idx++; } } break; case '=': { // diveq char_idx++; return _make_token(TK_OP_ASSIGN_DIV); } break; default: return _make_token(TK_OP_DIV); } continue; //a comment, continue to next token } break; case '=': { if (GETCHAR(0) == '=') { char_idx++; return _make_token(TK_OP_EQUAL); } return _make_token(TK_OP_ASSIGN); } break; case '<': { if (GETCHAR(0) == '=') { char_idx++; return _make_token(TK_OP_LESS_EQUAL); } else if (GETCHAR(0) == '<') { char_idx++; if (GETCHAR(0) == '=') { char_idx++; return _make_token(TK_OP_ASSIGN_SHIFT_LEFT); } return _make_token(TK_OP_SHIFT_LEFT); } return _make_token(TK_OP_LESS); } break; case '>': { if (GETCHAR(0) == '=') { char_idx++; return _make_token(TK_OP_GREATER_EQUAL); } else if (GETCHAR(0) == '>') { char_idx++; if (GETCHAR(0) == '=') { char_idx++; return _make_token(TK_OP_ASSIGN_SHIFT_RIGHT); } return _make_token(TK_OP_SHIFT_RIGHT); } return _make_token(TK_OP_GREATER); } break; case '!': { if (GETCHAR(0) == '=') { char_idx++; return _make_token(TK_OP_NOT_EQUAL); } return _make_token(TK_OP_NOT); } break; //case '"' //string - no strings in shader //case '\'' //string - no strings in shader case '{': return _make_token(TK_CURLY_BRACKET_OPEN); case '}': return _make_token(TK_CURLY_BRACKET_CLOSE); case '[': return _make_token(TK_BRACKET_OPEN); case ']': return _make_token(TK_BRACKET_CLOSE); case '(': return _make_token(TK_PARENTHESIS_OPEN); case ')': return _make_token(TK_PARENTHESIS_CLOSE); case ',': return _make_token(TK_COMMA); case ';': return _make_token(TK_SEMICOLON); case '?': return _make_token(TK_QUESTION); case ':': return _make_token(TK_COLON); case '^': return _make_token(TK_OP_BIT_XOR); case '~': return _make_token(TK_OP_BIT_INVERT); case '&': { if (GETCHAR(0) == '=') { char_idx++; return _make_token(TK_OP_ASSIGN_BIT_AND); } else if (GETCHAR(0) == '&') { char_idx++; return _make_token(TK_OP_AND); } return _make_token(TK_OP_BIT_AND); } break; case '|': { if (GETCHAR(0) == '=') { char_idx++; return _make_token(TK_OP_ASSIGN_BIT_OR); } else if (GETCHAR(0) == '|') { char_idx++; return _make_token(TK_OP_OR); } return _make_token(TK_OP_BIT_OR); } break; case '*': { if (GETCHAR(0) == '=') { char_idx++; return _make_token(TK_OP_ASSIGN_MUL); } return _make_token(TK_OP_MUL); } break; case '+': { if (GETCHAR(0) == '=') { char_idx++; return _make_token(TK_OP_ASSIGN_ADD); } else if (GETCHAR(0) == '+') { char_idx++; return _make_token(TK_OP_INCREMENT); } return _make_token(TK_OP_ADD); } break; case '-': { if (GETCHAR(0) == '=') { char_idx++; return _make_token(TK_OP_ASSIGN_SUB); } else if (GETCHAR(0) == '-') { char_idx++; return _make_token(TK_OP_DECREMENT); } return _make_token(TK_OP_SUB); } break; case '%': { if (GETCHAR(0) == '=') { char_idx++; return _make_token(TK_OP_ASSIGN_MOD); } return _make_token(TK_OP_MOD); } break; default: { char_idx--; //go back one, since we have no idea what this is if (_is_number(GETCHAR(0)) || (GETCHAR(0) == '.' && _is_number(GETCHAR(1)))) { // parse number bool period_found = false; bool exponent_found = false; bool hexa_found = false; bool sign_found = false; bool minus_exponent_found = false; bool float_suffix_found = false; String str; int i = 0; while (true) { if (GETCHAR(i) == '.') { if (period_found || exponent_found || hexa_found || float_suffix_found) return _make_token(TK_ERROR, "Invalid numeric constant"); period_found = true; } else if (GETCHAR(i) == 'x') { if (hexa_found || str.length() != 1 || str[0] != '0') return _make_token(TK_ERROR, "Invalid numeric constant"); hexa_found = true; } else if (GETCHAR(i) == 'e') { if (hexa_found || exponent_found || float_suffix_found) return _make_token(TK_ERROR, "Invalid numeric constant"); exponent_found = true; } else if (GETCHAR(i) == 'f') { if (hexa_found || exponent_found) return _make_token(TK_ERROR, "Invalid numeric constant"); float_suffix_found = true; } else if (_is_number(GETCHAR(i))) { if (float_suffix_found) return _make_token(TK_ERROR, "Invalid numeric constant"); } else if (hexa_found && _is_hex(GETCHAR(i))) { } else if ((GETCHAR(i) == '-' || GETCHAR(i) == '+') && exponent_found) { if (sign_found) return _make_token(TK_ERROR, "Invalid numeric constant"); sign_found = true; if (GETCHAR(i) == '-') minus_exponent_found = true; } else break; str += CharType(GETCHAR(i)); i++; } CharType last_char = str[str.length() - 1]; if (hexa_found) { //hex integers eg."0xFF" or "0x12AB", etc - NOT supported yet return _make_token(TK_ERROR, "Invalid (hexadecimal) numeric constant - Not supported"); } else if (period_found || float_suffix_found) { //floats if (period_found) { if (float_suffix_found) { //checks for eg "1.f" or "1.99f" notations if (last_char != 'f') { return _make_token(TK_ERROR, "Invalid (float) numeric constant"); } } else { //checks for eg. "1." or "1.99" notations if (last_char != '.' && !_is_number(last_char)) { return _make_token(TK_ERROR, "Invalid (float) numeric constant"); } } } else if (float_suffix_found) { // if no period found the float suffix must be the last character, like in "2f" for "2.0" if (last_char != 'f') { return _make_token(TK_ERROR, "Invalid (float) numeric constant"); } } if (float_suffix_found) { //strip the suffix str = str.left(str.length() - 1); //compensate reading cursor position char_idx += 1; } if (!str.is_valid_float()) { return _make_token(TK_ERROR, "Invalid (float) numeric constant"); } } else { //integers if (!_is_number(last_char)) { return _make_token(TK_ERROR, "Invalid (integer) numeric constant"); } if (!str.is_valid_integer()) { return _make_token(TK_ERROR, "Invalid numeric constant"); } } char_idx += str.length(); Token tk; if (period_found || minus_exponent_found || float_suffix_found) tk.type = TK_REAL_CONSTANT; else tk.type = TK_INT_CONSTANT; tk.constant = str.to_double(); //wont work with hex tk.line = tk_line; return tk; } if (GETCHAR(0) == '.') { //parse period char_idx++; return _make_token(TK_PERIOD); } if (_is_text_char(GETCHAR(0))) { // parse identifier String str; while (_is_text_char(GETCHAR(0))) { str += CharType(GETCHAR(0)); char_idx++; } //see if keyword //should be converted to a static map int idx = 0; while (keyword_list[idx].text) { if (str == keyword_list[idx].text) { return _make_token(keyword_list[idx].token); } idx++; } return _make_token(TK_IDENTIFIER, str); } if (GETCHAR(0) > 32) return _make_token(TK_ERROR, "Tokenizer: Unknown character #" + itos(GETCHAR(0)) + ": '" + String::chr(GETCHAR(0)) + "'"); else return _make_token(TK_ERROR, "Tokenizer: Unknown character #" + itos(GETCHAR(0))); } break; } } ERR_PRINT("BUG"); return Token(); #undef GETCHAR } String ShaderLanguage::token_debug(const String &p_code) { clear(); code = p_code; String output; Token tk = _get_token(); while (tk.type != TK_EOF && tk.type != TK_ERROR) { output += itos(tk_line) + ": " + get_token_text(tk) + "\n"; tk = _get_token(); } return output; } bool ShaderLanguage::is_token_datatype(TokenType p_type) { return ( p_type == TK_TYPE_VOID || p_type == TK_TYPE_BOOL || p_type == TK_TYPE_BVEC2 || p_type == TK_TYPE_BVEC3 || p_type == TK_TYPE_BVEC4 || p_type == TK_TYPE_INT || p_type == TK_TYPE_IVEC2 || p_type == TK_TYPE_IVEC3 || p_type == TK_TYPE_IVEC4 || p_type == TK_TYPE_UINT || p_type == TK_TYPE_UVEC2 || p_type == TK_TYPE_UVEC3 || p_type == TK_TYPE_UVEC4 || p_type == TK_TYPE_FLOAT || p_type == TK_TYPE_VEC2 || p_type == TK_TYPE_VEC3 || p_type == TK_TYPE_VEC4 || p_type == TK_TYPE_MAT2 || p_type == TK_TYPE_MAT3 || p_type == TK_TYPE_MAT4 || p_type == TK_TYPE_SAMPLER2D || p_type == TK_TYPE_ISAMPLER2D || p_type == TK_TYPE_USAMPLER2D || p_type == TK_TYPE_SAMPLER2DARRAY || p_type == TK_TYPE_ISAMPLER2DARRAY || p_type == TK_TYPE_USAMPLER2DARRAY || p_type == TK_TYPE_SAMPLER3D || p_type == TK_TYPE_ISAMPLER3D || p_type == TK_TYPE_USAMPLER3D || p_type == TK_TYPE_SAMPLERCUBE); } ShaderLanguage::DataType ShaderLanguage::get_token_datatype(TokenType p_type) { return DataType(p_type - TK_TYPE_VOID); } bool ShaderLanguage::is_token_interpolation(TokenType p_type) { return ( p_type == TK_INTERPOLATION_FLAT || p_type == TK_INTERPOLATION_NO_PERSPECTIVE || p_type == TK_INTERPOLATION_SMOOTH); } ShaderLanguage::DataInterpolation ShaderLanguage::get_token_interpolation(TokenType p_type) { if (p_type == TK_INTERPOLATION_FLAT) return INTERPOLATION_FLAT; else if (p_type == TK_INTERPOLATION_NO_PERSPECTIVE) return INTERPOLATION_NO_PERSPECTIVE; else return INTERPOLATION_SMOOTH; } bool ShaderLanguage::is_token_precision(TokenType p_type) { return ( p_type == TK_PRECISION_LOW || p_type == TK_PRECISION_MID || p_type == TK_PRECISION_HIGH); } ShaderLanguage::DataPrecision ShaderLanguage::get_token_precision(TokenType p_type) { if (p_type == TK_PRECISION_LOW) return PRECISION_LOWP; else if (p_type == TK_PRECISION_HIGH) return PRECISION_HIGHP; else return PRECISION_MEDIUMP; } String ShaderLanguage::get_datatype_name(DataType p_type) { switch (p_type) { case TYPE_VOID: return "void"; case TYPE_BOOL: return "bool"; case TYPE_BVEC2: return "bvec2"; case TYPE_BVEC3: return "bvec3"; case TYPE_BVEC4: return "bvec4"; case TYPE_INT: return "int"; case TYPE_IVEC2: return "ivec2"; case TYPE_IVEC3: return "ivec3"; case TYPE_IVEC4: return "ivec4"; case TYPE_UINT: return "uint"; case TYPE_UVEC2: return "uvec2"; case TYPE_UVEC3: return "uvec3"; case TYPE_UVEC4: return "uvec4"; case TYPE_FLOAT: return "float"; case TYPE_VEC2: return "vec2"; case TYPE_VEC3: return "vec3"; case TYPE_VEC4: return "vec4"; case TYPE_MAT2: return "mat2"; case TYPE_MAT3: return "mat3"; case TYPE_MAT4: return "mat4"; case TYPE_SAMPLER2D: return "sampler2D"; case TYPE_ISAMPLER2D: return "isampler2D"; case TYPE_USAMPLER2D: return "usampler2D"; case TYPE_SAMPLER2DARRAY: return "sampler2DArray"; case TYPE_ISAMPLER2DARRAY: return "isampler2DArray"; case TYPE_USAMPLER2DARRAY: return "usampler2DArray"; case TYPE_SAMPLER3D: return "sampler3D"; case TYPE_ISAMPLER3D: return "isampler3D"; case TYPE_USAMPLER3D: return "usampler3D"; case TYPE_SAMPLERCUBE: return "samplerCube"; } return ""; } bool ShaderLanguage::is_token_nonvoid_datatype(TokenType p_type) { return is_token_datatype(p_type) && p_type != TK_TYPE_VOID; } void ShaderLanguage::clear() { current_function = StringName(); completion_type = COMPLETION_NONE; completion_block = NULL; completion_function = StringName(); error_line = 0; tk_line = 1; char_idx = 0; error_set = false; error_str = ""; while (nodes) { Node *n = nodes; nodes = nodes->next; memdelete(n); } } bool ShaderLanguage::_find_identifier(const BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, const StringName &p_identifier, DataType *r_data_type, IdentifierType *r_type) { if (p_builtin_types.has(p_identifier)) { if (r_data_type) { *r_data_type = p_builtin_types[p_identifier].type; } if (r_type) { *r_type = IDENTIFIER_BUILTIN_VAR; } return true; } FunctionNode *function = NULL; while (p_block) { if (p_block->variables.has(p_identifier)) { if (r_data_type) { *r_data_type = p_block->variables[p_identifier].type; } if (r_type) { *r_type = IDENTIFIER_LOCAL_VAR; } return true; } if (p_block->parent_function) { function = p_block->parent_function; break; } else { ERR_FAIL_COND_V(!p_block->parent_block, false); p_block = p_block->parent_block; } } if (function) { for (int i = 0; i < function->arguments.size(); i++) { if (function->arguments[i].name == p_identifier) { if (r_data_type) { *r_data_type = function->arguments[i].type; } if (r_type) { *r_type = IDENTIFIER_FUNCTION_ARGUMENT; } return true; } } } if (shader->varyings.has(p_identifier)) { if (r_data_type) { *r_data_type = shader->varyings[p_identifier].type; } if (r_type) { *r_type = IDENTIFIER_VARYING; } return true; } if (shader->uniforms.has(p_identifier)) { if (r_data_type) { *r_data_type = shader->uniforms[p_identifier].type; } if (r_type) { *r_type = IDENTIFIER_UNIFORM; } return true; } for (int i = 0; i < shader->functions.size(); i++) { if (!shader->functions[i].callable) continue; if (shader->functions[i].name == p_identifier) { if (r_data_type) { *r_data_type = shader->functions[i].function->return_type; } if (r_type) { *r_type = IDENTIFIER_FUNCTION; } } } return false; } bool ShaderLanguage::_validate_operator(OperatorNode *p_op, DataType *r_ret_type) { bool valid = false; DataType ret_type; switch (p_op->op) { case OP_EQUAL: case OP_NOT_EQUAL: { DataType na = p_op->arguments[0]->get_datatype(); DataType nb = p_op->arguments[1]->get_datatype(); valid = na == nb; ret_type = TYPE_BOOL; } break; case OP_LESS: case OP_LESS_EQUAL: case OP_GREATER: case OP_GREATER_EQUAL: { DataType na = p_op->arguments[0]->get_datatype(); DataType nb = p_op->arguments[1]->get_datatype(); valid = na == nb && (na == TYPE_UINT || na == TYPE_INT || na == TYPE_FLOAT); ret_type = TYPE_BOOL; } break; case OP_AND: case OP_OR: { DataType na = p_op->arguments[0]->get_datatype(); DataType nb = p_op->arguments[1]->get_datatype(); valid = na == nb && na == TYPE_BOOL; ret_type = TYPE_BOOL; } break; case OP_NOT: { DataType na = p_op->arguments[0]->get_datatype(); valid = na == TYPE_BOOL; ret_type = TYPE_BOOL; } break; case OP_INCREMENT: case OP_DECREMENT: case OP_POST_INCREMENT: case OP_POST_DECREMENT: case OP_NEGATE: { DataType na = p_op->arguments[0]->get_datatype(); valid = na > TYPE_BOOL && na < TYPE_MAT2; ret_type = na; } break; case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV: { DataType na = p_op->arguments[0]->get_datatype(); DataType nb = p_op->arguments[1]->get_datatype(); if (na > nb) { //make things easier; SWAP(na, nb); } if (na == nb) { valid = (na > TYPE_BOOL && na <= TYPE_MAT4); ret_type = na; } else if (na == TYPE_INT && nb == TYPE_IVEC2) { valid = true; ret_type = TYPE_IVEC2; } else if (na == TYPE_INT && nb == TYPE_IVEC3) { valid = true; ret_type = TYPE_IVEC3; } else if (na == TYPE_INT && nb == TYPE_IVEC4) { valid = true; ret_type = TYPE_IVEC4; } else if (na == TYPE_UINT && nb == TYPE_UVEC2) { valid = true; ret_type = TYPE_UVEC2; } else if (na == TYPE_UINT && nb == TYPE_UVEC3) { valid = true; ret_type = TYPE_UVEC3; } else if (na == TYPE_UINT && nb == TYPE_UVEC4) { valid = true; ret_type = TYPE_UVEC4; } else if (na == TYPE_FLOAT && nb == TYPE_VEC2) { valid = true; ret_type = TYPE_VEC2; } else if (na == TYPE_FLOAT && nb == TYPE_VEC3) { valid = true; ret_type = TYPE_VEC3; } else if (na == TYPE_FLOAT && nb == TYPE_VEC4) { valid = true; ret_type = TYPE_VEC4; } else if (p_op->op == OP_MUL && na == TYPE_FLOAT && nb == TYPE_MAT2) { valid = true; ret_type = TYPE_MAT2; } else if (p_op->op == OP_MUL && na == TYPE_FLOAT && nb == TYPE_MAT3) { valid = true; ret_type = TYPE_MAT3; } else if (p_op->op == OP_MUL && na == TYPE_FLOAT && nb == TYPE_MAT4) { valid = true; ret_type = TYPE_MAT4; } else if (p_op->op == OP_MUL && na == TYPE_VEC2 && nb == TYPE_MAT2) { valid = true; ret_type = TYPE_VEC2; } else if (p_op->op == OP_MUL && na == TYPE_VEC3 && nb == TYPE_MAT3) { valid = true; ret_type = TYPE_VEC3; } else if (p_op->op == OP_MUL && na == TYPE_VEC4 && nb == TYPE_MAT4) { valid = true; ret_type = TYPE_VEC4; } } break; case OP_ASSIGN_MOD: case OP_MOD: { /* * The operator modulus (%) operates on signed or unsigned integers or integer vectors. The operand * types must both be signed or both be unsigned. The operands cannot be vectors of differing size. If * one operand is a scalar and the other vector, then the scalar is applied component-wise to the vector, * resulting in the same type as the vector. If both are vectors of the same size, the result is computed * component-wise. */ DataType na = p_op->arguments[0]->get_datatype(); DataType nb = p_op->arguments[1]->get_datatype(); if (na == TYPE_INT && nb == TYPE_INT) { valid = true; ret_type = TYPE_INT; } else if (na == TYPE_IVEC2 && nb == TYPE_INT) { valid = true; ret_type = TYPE_IVEC2; } else if (na == TYPE_IVEC3 && nb == TYPE_INT) { valid = true; ret_type = TYPE_IVEC3; } else if (na == TYPE_IVEC4 && nb == TYPE_INT) { valid = true; ret_type = TYPE_IVEC4; } else if (na == TYPE_IVEC2 && nb == TYPE_IVEC2) { valid = true; ret_type = TYPE_IVEC2; } else if (na == TYPE_IVEC3 && nb == TYPE_IVEC3) { valid = true; ret_type = TYPE_IVEC3; } else if (na == TYPE_IVEC4 && nb == TYPE_IVEC4) { valid = true; ret_type = TYPE_IVEC4; ///// } else if (na == TYPE_UINT && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UINT; } else if (na == TYPE_UVEC2 && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UVEC2; } else if (na == TYPE_UVEC3 && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UVEC3; } else if (na == TYPE_UVEC4 && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UVEC4; } else if (na == TYPE_UVEC2 && nb == TYPE_UVEC2) { valid = true; ret_type = TYPE_UVEC2; } else if (na == TYPE_UVEC3 && nb == TYPE_UVEC3) { valid = true; ret_type = TYPE_UVEC3; } else if (na == TYPE_UVEC4 && nb == TYPE_UVEC4) { valid = true; ret_type = TYPE_UVEC4; } } break; case OP_ASSIGN_SHIFT_LEFT: case OP_ASSIGN_SHIFT_RIGHT: case OP_SHIFT_LEFT: case OP_SHIFT_RIGHT: { DataType na = p_op->arguments[0]->get_datatype(); DataType nb = p_op->arguments[1]->get_datatype(); if (na == TYPE_INT && nb == TYPE_INT) { valid = true; ret_type = TYPE_INT; } else if (na == TYPE_IVEC2 && nb == TYPE_INT) { valid = true; ret_type = TYPE_IVEC2; } else if (na == TYPE_IVEC3 && nb == TYPE_INT) { valid = true; ret_type = TYPE_IVEC3; } else if (na == TYPE_IVEC4 && nb == TYPE_INT) { valid = true; ret_type = TYPE_IVEC4; } else if (na == TYPE_IVEC2 && nb == TYPE_IVEC2) { valid = true; ret_type = TYPE_IVEC2; } else if (na == TYPE_IVEC3 && nb == TYPE_IVEC3) { valid = true; ret_type = TYPE_IVEC3; } else if (na == TYPE_IVEC4 && nb == TYPE_IVEC4) { valid = true; ret_type = TYPE_IVEC4; } else if (na == TYPE_UINT && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UINT; } else if (na == TYPE_UVEC2 && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UVEC2; } else if (na == TYPE_UVEC3 && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UVEC3; } else if (na == TYPE_UVEC4 && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UVEC4; } else if (na == TYPE_UVEC2 && nb == TYPE_UVEC2) { valid = true; ret_type = TYPE_UVEC2; } else if (na == TYPE_UVEC3 && nb == TYPE_UVEC3) { valid = true; ret_type = TYPE_UVEC3; } else if (na == TYPE_UVEC4 && nb == TYPE_UVEC4) { valid = true; ret_type = TYPE_UVEC4; } } break; case OP_ASSIGN: { DataType na = p_op->arguments[0]->get_datatype(); DataType nb = p_op->arguments[1]->get_datatype(); valid = na == nb; ret_type = na; } break; case OP_ASSIGN_ADD: case OP_ASSIGN_SUB: case OP_ASSIGN_MUL: case OP_ASSIGN_DIV: { DataType na = p_op->arguments[0]->get_datatype(); DataType nb = p_op->arguments[1]->get_datatype(); if (na == nb) { valid = (na > TYPE_BOOL && na < TYPE_MAT2) || (p_op->op == OP_ASSIGN_MUL && na >= TYPE_MAT2 && na <= TYPE_MAT4); ret_type = na; } else if (na == TYPE_IVEC2 && nb == TYPE_INT) { valid = true; ret_type = TYPE_IVEC2; } else if (na == TYPE_IVEC3 && nb == TYPE_INT) { valid = true; ret_type = TYPE_IVEC3; } else if (na == TYPE_IVEC4 && nb == TYPE_INT) { valid = true; ret_type = TYPE_IVEC4; } else if (na == TYPE_UVEC2 && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UVEC2; } else if (na == TYPE_UVEC3 && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UVEC3; } else if (na == TYPE_UVEC4 && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UVEC4; } else if (na == TYPE_VEC2 && nb == TYPE_FLOAT) { valid = true; ret_type = TYPE_VEC2; } else if (na == TYPE_VEC3 && nb == TYPE_FLOAT) { valid = true; ret_type = TYPE_VEC3; } else if (na == TYPE_VEC4 && nb == TYPE_FLOAT) { valid = true; ret_type = TYPE_VEC4; } else if (p_op->op == OP_ASSIGN_MUL && na == TYPE_MAT2 && nb == TYPE_VEC2) { valid = true; ret_type = TYPE_MAT2; } else if (p_op->op == OP_ASSIGN_MUL && na == TYPE_MAT3 && nb == TYPE_VEC3) { valid = true; ret_type = TYPE_MAT3; } else if (p_op->op == OP_ASSIGN_MUL && na == TYPE_MAT4 && nb == TYPE_VEC4) { valid = true; ret_type = TYPE_MAT4; } } break; case OP_ASSIGN_BIT_AND: case OP_ASSIGN_BIT_OR: case OP_ASSIGN_BIT_XOR: case OP_BIT_AND: case OP_BIT_OR: case OP_BIT_XOR: { /* * The bitwise operators and (&), exclusive-or (^), and inclusive-or (|). The operands must be of type * signed or unsigned integers or integer vectors. The operands cannot be vectors of differing size. If * one operand is a scalar and the other a vector, the scalar is applied component-wise to the vector, * resulting in the same type as the vector. The fundamental types of the operands (signed or unsigned) * must match. */ DataType na = p_op->arguments[0]->get_datatype(); DataType nb = p_op->arguments[1]->get_datatype(); if (na > nb && p_op->op >= OP_BIT_AND) { //can swap for non assign SWAP(na, nb); } if (na == TYPE_INT && nb == TYPE_INT) { valid = true; ret_type = TYPE_INT; } else if (na == TYPE_IVEC2 && nb == TYPE_INT) { valid = true; ret_type = TYPE_IVEC2; } else if (na == TYPE_IVEC3 && nb == TYPE_INT) { valid = true; ret_type = TYPE_IVEC3; } else if (na == TYPE_IVEC4 && nb == TYPE_INT) { valid = true; ret_type = TYPE_IVEC4; } else if (na == TYPE_IVEC2 && nb == TYPE_IVEC2) { valid = true; ret_type = TYPE_IVEC2; } else if (na == TYPE_IVEC3 && nb == TYPE_IVEC3) { valid = true; ret_type = TYPE_IVEC3; } else if (na == TYPE_IVEC4 && nb == TYPE_IVEC4) { valid = true; ret_type = TYPE_IVEC4; ///// } else if (na == TYPE_UINT && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UINT; } else if (na == TYPE_UVEC2 && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UVEC2; } else if (na == TYPE_UVEC3 && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UVEC3; } else if (na == TYPE_UVEC4 && nb == TYPE_UINT) { valid = true; ret_type = TYPE_UVEC4; } else if (na == TYPE_UVEC2 && nb == TYPE_UVEC2) { valid = true; ret_type = TYPE_UVEC2; } else if (na == TYPE_UVEC3 && nb == TYPE_UVEC3) { valid = true; ret_type = TYPE_UVEC3; } else if (na == TYPE_UVEC4 && nb == TYPE_UVEC4) { valid = true; ret_type = TYPE_UVEC4; } } break; case OP_BIT_INVERT: { //unaries DataType na = p_op->arguments[0]->get_datatype(); valid = na >= TYPE_INT && na < TYPE_FLOAT; ret_type = na; } break; case OP_SELECT_IF: { DataType na = p_op->arguments[0]->get_datatype(); DataType nb = p_op->arguments[1]->get_datatype(); DataType nc = p_op->arguments[2]->get_datatype(); valid = na == TYPE_BOOL && (nb == nc); ret_type = nb; } break; default: { ERR_FAIL_V(false); } } if (r_ret_type) *r_ret_type = ret_type; return valid; } const ShaderLanguage::BuiltinFuncDef ShaderLanguage::builtin_func_defs[] = { //constructors { "bool", TYPE_BOOL, { TYPE_BOOL, TYPE_VOID } }, { "bvec2", TYPE_BVEC2, { TYPE_BOOL, TYPE_VOID } }, { "bvec2", TYPE_BVEC2, { TYPE_BOOL, TYPE_BOOL, TYPE_VOID } }, { "bvec3", TYPE_BVEC3, { TYPE_BOOL, TYPE_VOID } }, { "bvec3", TYPE_BVEC3, { TYPE_BOOL, TYPE_BOOL, TYPE_BOOL, TYPE_VOID } }, { "bvec3", TYPE_BVEC3, { TYPE_BVEC2, TYPE_BOOL, TYPE_VOID } }, { "bvec3", TYPE_BVEC3, { TYPE_BOOL, TYPE_BVEC2, TYPE_VOID } }, { "bvec4", TYPE_BVEC4, { TYPE_BOOL, TYPE_VOID } }, { "bvec4", TYPE_BVEC4, { TYPE_BOOL, TYPE_BOOL, TYPE_BOOL, TYPE_BOOL, TYPE_VOID } }, { "bvec4", TYPE_BVEC4, { TYPE_BOOL, TYPE_BVEC2, TYPE_BOOL, TYPE_VOID } }, { "bvec4", TYPE_BVEC4, { TYPE_BVEC2, TYPE_BOOL, TYPE_BOOL, TYPE_VOID } }, { "bvec4", TYPE_BVEC4, { TYPE_BOOL, TYPE_BOOL, TYPE_BVEC2, TYPE_VOID } }, { "bvec4", TYPE_BVEC4, { TYPE_BOOL, TYPE_BVEC3, TYPE_VOID } }, { "bvec4", TYPE_BVEC4, { TYPE_BVEC3, TYPE_BOOL, TYPE_VOID } }, { "bvec4", TYPE_BVEC4, { TYPE_BVEC2, TYPE_BVEC2, TYPE_VOID } }, { "float", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "vec2", TYPE_VEC2, { TYPE_FLOAT, TYPE_VOID } }, { "vec2", TYPE_VEC2, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "vec3", TYPE_VEC3, { TYPE_FLOAT, TYPE_VOID } }, { "vec3", TYPE_VEC3, { TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "vec3", TYPE_VEC3, { TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } }, { "vec3", TYPE_VEC3, { TYPE_FLOAT, TYPE_VEC2, TYPE_VOID } }, { "vec4", TYPE_VEC4, { TYPE_FLOAT, TYPE_VOID } }, { "vec4", TYPE_VEC4, { TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "vec4", TYPE_VEC4, { TYPE_FLOAT, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } }, { "vec4", TYPE_VEC4, { TYPE_VEC2, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "vec4", TYPE_VEC4, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VEC2, TYPE_VOID } }, { "vec4", TYPE_VEC4, { TYPE_FLOAT, TYPE_VEC3, TYPE_VOID } }, { "vec4", TYPE_VEC4, { TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "vec4", TYPE_VEC4, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "int", TYPE_INT, { TYPE_INT, TYPE_VOID } }, { "ivec2", TYPE_IVEC2, { TYPE_INT, TYPE_VOID } }, { "ivec2", TYPE_IVEC2, { TYPE_INT, TYPE_INT, TYPE_VOID } }, { "ivec3", TYPE_IVEC3, { TYPE_INT, TYPE_VOID } }, { "ivec3", TYPE_IVEC3, { TYPE_INT, TYPE_INT, TYPE_INT, TYPE_VOID } }, { "ivec3", TYPE_IVEC3, { TYPE_IVEC2, TYPE_INT, TYPE_VOID } }, { "ivec3", TYPE_IVEC3, { TYPE_INT, TYPE_IVEC2, TYPE_VOID } }, { "ivec4", TYPE_IVEC4, { TYPE_INT, TYPE_VOID } }, { "ivec4", TYPE_IVEC4, { TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_VOID } }, { "ivec4", TYPE_IVEC4, { TYPE_INT, TYPE_IVEC2, TYPE_INT, TYPE_VOID } }, { "ivec4", TYPE_IVEC4, { TYPE_IVEC2, TYPE_INT, TYPE_INT, TYPE_VOID } }, { "ivec4", TYPE_IVEC4, { TYPE_INT, TYPE_INT, TYPE_IVEC2, TYPE_VOID } }, { "ivec4", TYPE_IVEC4, { TYPE_INT, TYPE_IVEC3, TYPE_VOID } }, { "ivec4", TYPE_IVEC4, { TYPE_IVEC3, TYPE_INT, TYPE_VOID } }, { "ivec4", TYPE_IVEC4, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } }, { "uint", TYPE_UINT, { TYPE_UINT, TYPE_VOID } }, { "uvec2", TYPE_UVEC2, { TYPE_UINT, TYPE_VOID } }, { "uvec2", TYPE_UVEC2, { TYPE_UINT, TYPE_UINT, TYPE_VOID } }, { "uvec3", TYPE_UVEC3, { TYPE_UINT, TYPE_VOID } }, { "uvec3", TYPE_UVEC3, { TYPE_UINT, TYPE_UINT, TYPE_UINT, TYPE_VOID } }, { "uvec3", TYPE_UVEC3, { TYPE_UVEC2, TYPE_UINT, TYPE_VOID } }, { "uvec3", TYPE_UVEC3, { TYPE_UINT, TYPE_UVEC2, TYPE_VOID } }, { "uvec4", TYPE_UVEC4, { TYPE_UINT, TYPE_VOID } }, { "uvec4", TYPE_UVEC4, { TYPE_UINT, TYPE_UINT, TYPE_UINT, TYPE_UINT, TYPE_VOID } }, { "uvec4", TYPE_UVEC4, { TYPE_UINT, TYPE_UVEC2, TYPE_UINT, TYPE_VOID } }, { "uvec4", TYPE_UVEC4, { TYPE_UVEC2, TYPE_UINT, TYPE_UINT, TYPE_VOID } }, { "uvec4", TYPE_UVEC4, { TYPE_UINT, TYPE_UINT, TYPE_UVEC2, TYPE_VOID } }, { "uvec4", TYPE_UVEC4, { TYPE_UINT, TYPE_UVEC3, TYPE_VOID } }, { "uvec4", TYPE_UVEC4, { TYPE_UVEC3, TYPE_UINT, TYPE_VOID } }, { "uvec4", TYPE_UVEC4, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } }, { "mat2", TYPE_MAT2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "mat3", TYPE_MAT3, { TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "mat4", TYPE_MAT4, { TYPE_VEC4, TYPE_VEC4, TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "mat2", TYPE_MAT2, { TYPE_FLOAT, TYPE_VOID } }, { "mat3", TYPE_MAT3, { TYPE_FLOAT, TYPE_VOID } }, { "mat4", TYPE_MAT4, { TYPE_FLOAT, TYPE_VOID } }, //conversion scalars { "int", TYPE_INT, { TYPE_BOOL, TYPE_VOID } }, { "int", TYPE_INT, { TYPE_INT, TYPE_VOID } }, { "int", TYPE_INT, { TYPE_UINT, TYPE_VOID } }, { "int", TYPE_INT, { TYPE_FLOAT, TYPE_VOID } }, { "float", TYPE_FLOAT, { TYPE_BOOL, TYPE_VOID } }, { "float", TYPE_FLOAT, { TYPE_INT, TYPE_VOID } }, { "float", TYPE_FLOAT, { TYPE_UINT, TYPE_VOID } }, { "float", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "uint", TYPE_UINT, { TYPE_BOOL, TYPE_VOID } }, { "uint", TYPE_UINT, { TYPE_INT, TYPE_VOID } }, { "uint", TYPE_UINT, { TYPE_UINT, TYPE_VOID } }, { "uint", TYPE_UINT, { TYPE_FLOAT, TYPE_VOID } }, { "bool", TYPE_BOOL, { TYPE_BOOL, TYPE_VOID } }, { "bool", TYPE_BOOL, { TYPE_INT, TYPE_VOID } }, { "bool", TYPE_BOOL, { TYPE_UINT, TYPE_VOID } }, { "bool", TYPE_BOOL, { TYPE_FLOAT, TYPE_VOID } }, //conversion vectors { "ivec2", TYPE_IVEC2, { TYPE_BVEC2, TYPE_VOID } }, { "ivec2", TYPE_IVEC2, { TYPE_IVEC2, TYPE_VOID } }, { "ivec2", TYPE_IVEC2, { TYPE_UVEC2, TYPE_VOID } }, { "ivec2", TYPE_IVEC2, { TYPE_VEC2, TYPE_VOID } }, { "vec2", TYPE_VEC2, { TYPE_BVEC2, TYPE_VOID } }, { "vec2", TYPE_VEC2, { TYPE_IVEC2, TYPE_VOID } }, { "vec2", TYPE_VEC2, { TYPE_UVEC2, TYPE_VOID } }, { "vec2", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "uvec2", TYPE_UVEC2, { TYPE_BVEC2, TYPE_VOID } }, { "uvec2", TYPE_UVEC2, { TYPE_IVEC2, TYPE_VOID } }, { "uvec2", TYPE_UVEC2, { TYPE_UVEC2, TYPE_VOID } }, { "uvec2", TYPE_UVEC2, { TYPE_VEC2, TYPE_VOID } }, { "bvec2", TYPE_BVEC2, { TYPE_BVEC2, TYPE_VOID } }, { "bvec2", TYPE_BVEC2, { TYPE_IVEC2, TYPE_VOID } }, { "bvec2", TYPE_BVEC2, { TYPE_UVEC2, TYPE_VOID } }, { "bvec2", TYPE_BVEC2, { TYPE_VEC2, TYPE_VOID } }, { "ivec3", TYPE_IVEC3, { TYPE_BVEC3, TYPE_VOID } }, { "ivec3", TYPE_IVEC3, { TYPE_IVEC3, TYPE_VOID } }, { "ivec3", TYPE_IVEC3, { TYPE_UVEC3, TYPE_VOID } }, { "ivec3", TYPE_IVEC3, { TYPE_VEC3, TYPE_VOID } }, { "vec3", TYPE_VEC3, { TYPE_BVEC3, TYPE_VOID } }, { "vec3", TYPE_VEC3, { TYPE_IVEC3, TYPE_VOID } }, { "vec3", TYPE_VEC3, { TYPE_UVEC3, TYPE_VOID } }, { "vec3", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "uvec3", TYPE_UVEC3, { TYPE_BVEC3, TYPE_VOID } }, { "uvec3", TYPE_UVEC3, { TYPE_IVEC3, TYPE_VOID } }, { "uvec3", TYPE_UVEC3, { TYPE_UVEC3, TYPE_VOID } }, { "uvec3", TYPE_UVEC3, { TYPE_VEC3, TYPE_VOID } }, { "bvec3", TYPE_BVEC3, { TYPE_BVEC3, TYPE_VOID } }, { "bvec3", TYPE_BVEC3, { TYPE_IVEC3, TYPE_VOID } }, { "bvec3", TYPE_BVEC3, { TYPE_UVEC3, TYPE_VOID } }, { "bvec3", TYPE_BVEC3, { TYPE_VEC3, TYPE_VOID } }, { "ivec4", TYPE_IVEC4, { TYPE_BVEC4, TYPE_VOID } }, { "ivec4", TYPE_IVEC4, { TYPE_IVEC4, TYPE_VOID } }, { "ivec4", TYPE_IVEC4, { TYPE_UVEC4, TYPE_VOID } }, { "ivec4", TYPE_IVEC4, { TYPE_VEC4, TYPE_VOID } }, { "vec4", TYPE_VEC4, { TYPE_BVEC4, TYPE_VOID } }, { "vec4", TYPE_VEC4, { TYPE_IVEC4, TYPE_VOID } }, { "vec4", TYPE_VEC4, { TYPE_UVEC4, TYPE_VOID } }, { "vec4", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "uvec4", TYPE_UVEC4, { TYPE_BVEC4, TYPE_VOID } }, { "uvec4", TYPE_UVEC4, { TYPE_IVEC4, TYPE_VOID } }, { "uvec4", TYPE_UVEC4, { TYPE_UVEC4, TYPE_VOID } }, { "uvec4", TYPE_UVEC4, { TYPE_VEC4, TYPE_VOID } }, { "bvec4", TYPE_BVEC4, { TYPE_BVEC4, TYPE_VOID } }, { "bvec4", TYPE_BVEC4, { TYPE_IVEC4, TYPE_VOID } }, { "bvec4", TYPE_BVEC4, { TYPE_UVEC4, TYPE_VOID } }, { "bvec4", TYPE_BVEC4, { TYPE_VEC4, TYPE_VOID } }, //conversion between matrixes { "mat2", TYPE_MAT2, { TYPE_MAT3, TYPE_VOID } }, { "mat2", TYPE_MAT2, { TYPE_MAT4, TYPE_VOID } }, { "mat3", TYPE_MAT3, { TYPE_MAT2, TYPE_VOID } }, { "mat3", TYPE_MAT3, { TYPE_MAT4, TYPE_VOID } }, { "mat4", TYPE_MAT4, { TYPE_MAT2, TYPE_VOID } }, { "mat4", TYPE_MAT4, { TYPE_MAT3, TYPE_VOID } }, //builtins - trigonometry { "radians", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "radians", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "radians", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "radians", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "degrees", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "degrees", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "degrees", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "degrees", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "sin", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "sin", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "sin", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "sin", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "cos", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "cos", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "cos", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "cos", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "tan", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "tan", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "tan", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "tan", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "asin", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "asin", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "asin", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "asin", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "acos", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "acos", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "acos", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "acos", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "atan", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "atan", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "atan", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "atan", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "atan", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "atan", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "atan", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "atan", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "sinh", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "sinh", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "sinh", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "sinh", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "cosh", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "cosh", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "cosh", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "cosh", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "tanh", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "tanh", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "tanh", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "tanh", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "asinh", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "asinh", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "asinh", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "asinh", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "acosh", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "acosh", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "acosh", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "acosh", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "atanh", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "atanh", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "atanh", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "atanh", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, //builtins - exponential { "pow", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "pow", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "pow", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "pow", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "exp", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "exp", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "exp", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "exp", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "log", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "log", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "log", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "log", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "exp2", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "exp2", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "exp2", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "exp2", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "log2", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "log2", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "log2", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "log2", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "sqrt", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "sqrt", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "sqrt", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "sqrt", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "inversesqrt", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "inversesqrt", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "inversesqrt", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "inversesqrt", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, //builtins - common { "abs", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "abs", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "abs", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "abs", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "abs", TYPE_INT, { TYPE_INT, TYPE_VOID } }, { "abs", TYPE_IVEC2, { TYPE_IVEC2, TYPE_VOID } }, { "abs", TYPE_IVEC3, { TYPE_IVEC3, TYPE_VOID } }, { "abs", TYPE_IVEC4, { TYPE_IVEC4, TYPE_VOID } }, { "sign", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "sign", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "sign", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "sign", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "sign", TYPE_INT, { TYPE_INT, TYPE_VOID } }, { "sign", TYPE_IVEC2, { TYPE_IVEC2, TYPE_VOID } }, { "sign", TYPE_IVEC3, { TYPE_IVEC3, TYPE_VOID } }, { "sign", TYPE_IVEC4, { TYPE_IVEC4, TYPE_VOID } }, { "floor", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "floor", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "floor", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "floor", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "trunc", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "trunc", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "trunc", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "trunc", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "round", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "round", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "round", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "round", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "roundEven", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "roundEven", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "roundEven", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "roundEven", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "ceil", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "ceil", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "ceil", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "ceil", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "fract", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "fract", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "fract", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "fract", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "mod", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "mod", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "mod", TYPE_VEC2, { TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } }, { "mod", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "mod", TYPE_VEC3, { TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "mod", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "mod", TYPE_VEC4, { TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } }, { "modf", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "modf", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "modf", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "modf", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "min", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "min", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "min", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "min", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "min", TYPE_INT, { TYPE_INT, TYPE_INT, TYPE_VOID } }, { "min", TYPE_IVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } }, { "min", TYPE_IVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } }, { "min", TYPE_IVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } }, { "min", TYPE_UINT, { TYPE_UINT, TYPE_UINT, TYPE_VOID } }, { "min", TYPE_UVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } }, { "min", TYPE_UVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } }, { "min", TYPE_UVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } }, { "max", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "max", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "max", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "max", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "max", TYPE_INT, { TYPE_INT, TYPE_INT, TYPE_VOID } }, { "max", TYPE_IVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } }, { "max", TYPE_IVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } }, { "max", TYPE_IVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } }, { "max", TYPE_UINT, { TYPE_UINT, TYPE_UINT, TYPE_VOID } }, { "max", TYPE_UVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } }, { "max", TYPE_UVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } }, { "max", TYPE_UVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } }, { "clamp", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "clamp", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "clamp", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "clamp", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "clamp", TYPE_VEC2, { TYPE_VEC2, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "clamp", TYPE_VEC3, { TYPE_VEC3, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "clamp", TYPE_VEC4, { TYPE_VEC4, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "clamp", TYPE_INT, { TYPE_INT, TYPE_INT, TYPE_INT, TYPE_VOID } }, { "clamp", TYPE_IVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } }, { "clamp", TYPE_IVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } }, { "clamp", TYPE_IVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } }, { "clamp", TYPE_IVEC2, { TYPE_IVEC2, TYPE_INT, TYPE_INT, TYPE_VOID } }, { "clamp", TYPE_IVEC3, { TYPE_IVEC3, TYPE_INT, TYPE_INT, TYPE_VOID } }, { "clamp", TYPE_IVEC4, { TYPE_IVEC4, TYPE_INT, TYPE_INT, TYPE_VOID } }, { "clamp", TYPE_UINT, { TYPE_UINT, TYPE_UINT, TYPE_UINT, TYPE_VOID } }, { "clamp", TYPE_UVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } }, { "clamp", TYPE_UVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } }, { "clamp", TYPE_UVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } }, { "clamp", TYPE_UVEC2, { TYPE_UVEC2, TYPE_UINT, TYPE_UINT, TYPE_VOID } }, { "clamp", TYPE_UVEC3, { TYPE_UVEC3, TYPE_UINT, TYPE_UINT, TYPE_VOID } }, { "clamp", TYPE_UVEC4, { TYPE_UVEC4, TYPE_UINT, TYPE_UINT, TYPE_VOID } }, { "mix", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "mix", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_BOOL, TYPE_VOID } }, { "mix", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } }, { "mix", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_BOOL, TYPE_VOID } }, { "mix", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_BVEC2, TYPE_VOID } }, { "mix", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "mix", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "mix", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_BOOL, TYPE_VOID } }, { "mix", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_BVEC3, TYPE_VOID } }, { "mix", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "mix", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } }, { "mix", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_BOOL, TYPE_VOID } }, { "mix", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_BVEC4, TYPE_VOID } }, { "mix", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "step", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "step", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "step", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "step", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "step", TYPE_VEC2, { TYPE_FLOAT, TYPE_VEC2, TYPE_VOID } }, { "step", TYPE_VEC3, { TYPE_FLOAT, TYPE_VEC3, TYPE_VOID } }, { "step", TYPE_VEC4, { TYPE_FLOAT, TYPE_VEC4, TYPE_VOID } }, { "smoothstep", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } }, { "smoothstep", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "smoothstep", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "smoothstep", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "smoothstep", TYPE_VEC2, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VEC2, TYPE_VOID } }, { "smoothstep", TYPE_VEC3, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VEC3, TYPE_VOID } }, { "smoothstep", TYPE_VEC4, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VEC4, TYPE_VOID } }, { "isnan", TYPE_BOOL, { TYPE_FLOAT, TYPE_VOID } }, { "isnan", TYPE_BVEC2, { TYPE_VEC2, TYPE_VOID } }, { "isnan", TYPE_BVEC3, { TYPE_VEC3, TYPE_VOID } }, { "isnan", TYPE_BVEC4, { TYPE_VEC4, TYPE_VOID } }, { "isinf", TYPE_BOOL, { TYPE_FLOAT, TYPE_VOID } }, { "isinf", TYPE_BVEC2, { TYPE_VEC2, TYPE_VOID } }, { "isinf", TYPE_BVEC3, { TYPE_VEC3, TYPE_VOID } }, { "isinf", TYPE_BVEC4, { TYPE_VEC4, TYPE_VOID } }, { "floatBitsToInt", TYPE_INT, { TYPE_FLOAT, TYPE_VOID } }, { "floatBitsToInt", TYPE_IVEC2, { TYPE_VEC2, TYPE_VOID } }, { "floatBitsToInt", TYPE_IVEC3, { TYPE_VEC3, TYPE_VOID } }, { "floatBitsToInt", TYPE_IVEC4, { TYPE_VEC4, TYPE_VOID } }, { "floatBitsToUint", TYPE_UINT, { TYPE_FLOAT, TYPE_VOID } }, { "floatBitsToUint", TYPE_UVEC2, { TYPE_VEC2, TYPE_VOID } }, { "floatBitsToUint", TYPE_UVEC3, { TYPE_VEC3, TYPE_VOID } }, { "floatBitsToUint", TYPE_UVEC4, { TYPE_VEC4, TYPE_VOID } }, { "intBitsToFloat", TYPE_FLOAT, { TYPE_INT, TYPE_VOID } }, { "intBitsToFloat", TYPE_VEC2, { TYPE_IVEC2, TYPE_VOID } }, { "intBitsToFloat", TYPE_VEC3, { TYPE_IVEC3, TYPE_VOID } }, { "intBitsToFloat", TYPE_VEC4, { TYPE_IVEC4, TYPE_VOID } }, { "uintBitsToFloat", TYPE_FLOAT, { TYPE_UINT, TYPE_VOID } }, { "uintBitsToFloat", TYPE_VEC2, { TYPE_UVEC2, TYPE_VOID } }, { "uintBitsToFloat", TYPE_VEC3, { TYPE_UVEC3, TYPE_VOID } }, { "uintBitsToFloat", TYPE_VEC4, { TYPE_UVEC4, TYPE_VOID } }, //builtins - geometric { "length", TYPE_FLOAT, { TYPE_VEC2, TYPE_VOID } }, { "length", TYPE_FLOAT, { TYPE_VEC3, TYPE_VOID } }, { "length", TYPE_FLOAT, { TYPE_VEC4, TYPE_VOID } }, { "distance", TYPE_FLOAT, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "distance", TYPE_FLOAT, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "distance", TYPE_FLOAT, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "dot", TYPE_FLOAT, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "dot", TYPE_FLOAT, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "dot", TYPE_FLOAT, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "cross", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "normalize", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "normalize", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "normalize", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "reflect", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "refract", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "faceforward", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "faceforward", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "faceforward", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "matrixCompMult", TYPE_MAT2, { TYPE_MAT2, TYPE_MAT2, TYPE_VOID } }, { "matrixCompMult", TYPE_MAT3, { TYPE_MAT3, TYPE_MAT3, TYPE_VOID } }, { "matrixCompMult", TYPE_MAT4, { TYPE_MAT4, TYPE_MAT4, TYPE_VOID } }, { "outerProduct", TYPE_MAT2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "outerProduct", TYPE_MAT3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "outerProduct", TYPE_MAT4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "transpose", TYPE_MAT2, { TYPE_MAT2, TYPE_VOID } }, { "transpose", TYPE_MAT3, { TYPE_MAT3, TYPE_VOID } }, { "transpose", TYPE_MAT4, { TYPE_MAT4, TYPE_VOID } }, { "determinant", TYPE_FLOAT, { TYPE_MAT2, TYPE_VOID } }, { "determinant", TYPE_FLOAT, { TYPE_MAT3, TYPE_VOID } }, { "determinant", TYPE_FLOAT, { TYPE_MAT4, TYPE_VOID } }, { "inverse", TYPE_MAT2, { TYPE_MAT2, TYPE_VOID } }, { "inverse", TYPE_MAT3, { TYPE_MAT3, TYPE_VOID } }, { "inverse", TYPE_MAT4, { TYPE_MAT4, TYPE_VOID } }, { "lessThan", TYPE_BVEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "lessThan", TYPE_BVEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "lessThan", TYPE_BVEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "lessThan", TYPE_BVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } }, { "lessThan", TYPE_BVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } }, { "lessThan", TYPE_BVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } }, { "lessThan", TYPE_BVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } }, { "lessThan", TYPE_BVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } }, { "lessThan", TYPE_BVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } }, { "greaterThan", TYPE_BVEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "greaterThan", TYPE_BVEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "greaterThan", TYPE_BVEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "greaterThan", TYPE_BVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } }, { "greaterThan", TYPE_BVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } }, { "greaterThan", TYPE_BVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } }, { "greaterThan", TYPE_BVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } }, { "greaterThan", TYPE_BVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } }, { "greaterThan", TYPE_BVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } }, { "lessThanEqual", TYPE_BVEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "lessThanEqual", TYPE_BVEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "lessThanEqual", TYPE_BVEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "lessThanEqual", TYPE_BVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } }, { "lessThanEqual", TYPE_BVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } }, { "lessThanEqual", TYPE_BVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } }, { "lessThanEqual", TYPE_BVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } }, { "lessThanEqual", TYPE_BVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } }, { "lessThanEqual", TYPE_BVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } }, { "greaterThanEqual", TYPE_BVEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "greaterThanEqual", TYPE_BVEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "greaterThanEqual", TYPE_BVEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "greaterThanEqual", TYPE_BVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } }, { "greaterThanEqual", TYPE_BVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } }, { "greaterThanEqual", TYPE_BVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } }, { "greaterThanEqual", TYPE_BVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } }, { "greaterThanEqual", TYPE_BVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } }, { "greaterThanEqual", TYPE_BVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } }, { "equal", TYPE_BVEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "equal", TYPE_BVEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "equal", TYPE_BVEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "equal", TYPE_BVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } }, { "equal", TYPE_BVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } }, { "equal", TYPE_BVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } }, { "equal", TYPE_BVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } }, { "equal", TYPE_BVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } }, { "equal", TYPE_BVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } }, { "equal", TYPE_BVEC2, { TYPE_BVEC2, TYPE_BVEC2, TYPE_VOID } }, { "equal", TYPE_BVEC3, { TYPE_BVEC3, TYPE_BVEC3, TYPE_VOID } }, { "equal", TYPE_BVEC4, { TYPE_BVEC4, TYPE_BVEC4, TYPE_VOID } }, { "notEqual", TYPE_BVEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "notEqual", TYPE_BVEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "notEqual", TYPE_BVEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } }, { "notEqual", TYPE_BVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } }, { "notEqual", TYPE_BVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } }, { "notEqual", TYPE_BVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } }, { "notEqual", TYPE_BVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } }, { "notEqual", TYPE_BVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } }, { "notEqual", TYPE_BVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } }, { "notEqual", TYPE_BVEC2, { TYPE_BVEC2, TYPE_BVEC2, TYPE_VOID } }, { "notEqual", TYPE_BVEC3, { TYPE_BVEC3, TYPE_BVEC3, TYPE_VOID } }, { "notEqual", TYPE_BVEC4, { TYPE_BVEC4, TYPE_BVEC4, TYPE_VOID } }, { "any", TYPE_BOOL, { TYPE_BVEC2, TYPE_VOID } }, { "any", TYPE_BOOL, { TYPE_BVEC3, TYPE_VOID } }, { "any", TYPE_BOOL, { TYPE_BVEC4, TYPE_VOID } }, { "all", TYPE_BOOL, { TYPE_BVEC2, TYPE_VOID } }, { "all", TYPE_BOOL, { TYPE_BVEC3, TYPE_VOID } }, { "all", TYPE_BOOL, { TYPE_BVEC4, TYPE_VOID } }, { "not", TYPE_BOOL, { TYPE_BVEC2, TYPE_VOID } }, { "not", TYPE_BOOL, { TYPE_BVEC3, TYPE_VOID } }, { "not", TYPE_BOOL, { TYPE_BVEC4, TYPE_VOID } }, //builtins - texture { "textureSize", TYPE_IVEC2, { TYPE_SAMPLER2D, TYPE_INT, TYPE_VOID } }, { "textureSize", TYPE_IVEC2, { TYPE_ISAMPLER2D, TYPE_INT, TYPE_VOID } }, { "textureSize", TYPE_IVEC2, { TYPE_USAMPLER2D, TYPE_INT, TYPE_VOID } }, { "textureSize", TYPE_IVEC3, { TYPE_SAMPLER2DARRAY, TYPE_INT, TYPE_VOID } }, { "textureSize", TYPE_IVEC3, { TYPE_ISAMPLER2DARRAY, TYPE_INT, TYPE_VOID } }, { "textureSize", TYPE_IVEC3, { TYPE_USAMPLER2DARRAY, TYPE_INT, TYPE_VOID } }, { "textureSize", TYPE_IVEC3, { TYPE_SAMPLER3D, TYPE_INT, TYPE_VOID } }, { "textureSize", TYPE_IVEC3, { TYPE_ISAMPLER3D, TYPE_INT, TYPE_VOID } }, { "textureSize", TYPE_IVEC3, { TYPE_USAMPLER3D, TYPE_INT, TYPE_VOID } }, { "textureSize", TYPE_IVEC2, { TYPE_SAMPLERCUBE, TYPE_INT, TYPE_VOID } }, { "texture", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC2, TYPE_VOID } }, { "texture", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } }, { "texture", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC2, TYPE_VOID } }, { "texture", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } }, { "texture", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC2, TYPE_VOID } }, { "texture", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } }, { "texture", TYPE_VEC4, { TYPE_SAMPLER2DARRAY, TYPE_VEC3, TYPE_VOID } }, { "texture", TYPE_VEC4, { TYPE_SAMPLER2DARRAY, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "texture", TYPE_UVEC4, { TYPE_USAMPLER2DARRAY, TYPE_VEC3, TYPE_VOID } }, { "texture", TYPE_UVEC4, { TYPE_USAMPLER2DARRAY, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "texture", TYPE_IVEC4, { TYPE_ISAMPLER2DARRAY, TYPE_VEC3, TYPE_VOID } }, { "texture", TYPE_IVEC4, { TYPE_ISAMPLER2DARRAY, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "texture", TYPE_VEC4, { TYPE_SAMPLER3D, TYPE_VEC3, TYPE_VOID } }, { "texture", TYPE_VEC4, { TYPE_SAMPLER3D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "texture", TYPE_UVEC4, { TYPE_USAMPLER3D, TYPE_VEC3, TYPE_VOID } }, { "texture", TYPE_UVEC4, { TYPE_USAMPLER3D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "texture", TYPE_IVEC4, { TYPE_ISAMPLER3D, TYPE_VEC3, TYPE_VOID } }, { "texture", TYPE_IVEC4, { TYPE_ISAMPLER3D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "texture", TYPE_VEC4, { TYPE_SAMPLERCUBE, TYPE_VEC3, TYPE_VOID } }, { "texture", TYPE_VEC4, { TYPE_SAMPLERCUBE, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "textureProj", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC3, TYPE_VOID } }, { "textureProj", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC4, TYPE_VOID } }, { "textureProj", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "textureProj", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } }, { "textureProj", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC3, TYPE_VOID } }, { "textureProj", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC4, TYPE_VOID } }, { "textureProj", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "textureProj", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } }, { "textureProj", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC3, TYPE_VOID } }, { "textureProj", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC4, TYPE_VOID } }, { "textureProj", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "textureProj", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } }, { "textureProj", TYPE_VEC4, { TYPE_SAMPLER3D, TYPE_VEC4, TYPE_VOID } }, { "textureProj", TYPE_VEC4, { TYPE_SAMPLER3D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } }, { "textureProj", TYPE_IVEC4, { TYPE_ISAMPLER3D, TYPE_VEC4, TYPE_VOID } }, { "textureProj", TYPE_IVEC4, { TYPE_ISAMPLER3D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } }, { "textureProj", TYPE_UVEC4, { TYPE_USAMPLER3D, TYPE_VEC4, TYPE_VOID } }, { "textureProj", TYPE_UVEC4, { TYPE_USAMPLER3D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } }, { "textureLod", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } }, { "textureLod", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } }, { "textureLod", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } }, { "textureLod", TYPE_VEC4, { TYPE_SAMPLER2DARRAY, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "textureLod", TYPE_IVEC4, { TYPE_ISAMPLER2DARRAY, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "textureLod", TYPE_UVEC4, { TYPE_USAMPLER2DARRAY, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "textureLod", TYPE_VEC4, { TYPE_SAMPLER3D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "textureLod", TYPE_IVEC4, { TYPE_ISAMPLER3D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "textureLod", TYPE_UVEC4, { TYPE_USAMPLER3D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "textureLod", TYPE_VEC4, { TYPE_SAMPLERCUBE, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "texelFetch", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_IVEC2, TYPE_INT, TYPE_VOID } }, { "texelFetch", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_IVEC2, TYPE_INT, TYPE_VOID } }, { "texelFetch", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_IVEC2, TYPE_INT, TYPE_VOID } }, { "texelFetch", TYPE_VEC4, { TYPE_SAMPLER2DARRAY, TYPE_IVEC3, TYPE_INT, TYPE_VOID } }, { "texelFetch", TYPE_IVEC4, { TYPE_ISAMPLER2DARRAY, TYPE_IVEC3, TYPE_INT, TYPE_VOID } }, { "texelFetch", TYPE_UVEC4, { TYPE_USAMPLER2DARRAY, TYPE_IVEC3, TYPE_INT, TYPE_VOID } }, { "texelFetch", TYPE_VEC4, { TYPE_SAMPLER3D, TYPE_IVEC3, TYPE_INT, TYPE_VOID } }, { "texelFetch", TYPE_IVEC4, { TYPE_ISAMPLER3D, TYPE_IVEC3, TYPE_INT, TYPE_VOID } }, { "texelFetch", TYPE_UVEC4, { TYPE_USAMPLER3D, TYPE_IVEC3, TYPE_INT, TYPE_VOID } }, { "textureProjLod", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "textureProjLod", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } }, { "textureProjLod", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "textureProjLod", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } }, { "textureProjLod", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } }, { "textureProjLod", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } }, { "textureGrad", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "textureGrad", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "textureGrad", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "textureGrad", TYPE_VEC4, { TYPE_SAMPLER2DARRAY, TYPE_VEC3, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "textureGrad", TYPE_IVEC4, { TYPE_ISAMPLER2DARRAY, TYPE_VEC3, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "textureGrad", TYPE_UVEC4, { TYPE_USAMPLER2DARRAY, TYPE_VEC3, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "textureGrad", TYPE_VEC4, { TYPE_SAMPLER3D, TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "textureGrad", TYPE_IVEC4, { TYPE_ISAMPLER3D, TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "textureGrad", TYPE_UVEC4, { TYPE_USAMPLER3D, TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "textureGrad", TYPE_VEC4, { TYPE_SAMPLERCUBE, TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, { "dFdx", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "dFdx", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "dFdx", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "dFdx", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "dFdy", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "dFdy", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "dFdy", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "dFdy", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { "fwidth", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "fwidth", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "fwidth", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "fwidth", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, { NULL, TYPE_VOID, { TYPE_VOID } } }; bool ShaderLanguage::_validate_function_call(BlockNode *p_block, OperatorNode *p_func, DataType *r_ret_type) { ERR_FAIL_COND_V(p_func->op != OP_CALL && p_func->op != OP_CONSTRUCT, NULL); Vector<DataType> args; ERR_FAIL_COND_V(p_func->arguments[0]->type != Node::TYPE_VARIABLE, NULL); StringName name = static_cast<VariableNode *>(p_func->arguments[0])->name.operator String(); bool all_const = true; for (int i = 1; i < p_func->arguments.size(); i++) { if (p_func->arguments[i]->type != Node::TYPE_CONSTANT) all_const = false; args.push_back(p_func->arguments[i]->get_datatype()); } int argcount = args.size(); bool failed_builtin = false; if (argcount <= 4) { // test builtins int idx = 0; while (builtin_func_defs[idx].name) { if (name == builtin_func_defs[idx].name) { failed_builtin = true; bool fail = false; for (int i = 0; i < argcount; i++) { if (get_scalar_type(args[i]) == args[i] && p_func->arguments[i + 1]->type == Node::TYPE_CONSTANT && convert_constant(static_cast<ConstantNode *>(p_func->arguments[i + 1]), builtin_func_defs[idx].args[i])) { //all good } else if (args[i] != builtin_func_defs[idx].args[i]) { fail = true; break; } } if (!fail && argcount < 4 && builtin_func_defs[idx].args[argcount] != TYPE_VOID) fail = true; //make sure the number of arguments matches if (!fail) { if (r_ret_type) *r_ret_type = builtin_func_defs[idx].rettype; return true; } } idx++; } } if (failed_builtin) { String err = "Invalid arguments for built-in function: " + String(name) + "("; for (int i = 0; i < argcount; i++) { if (i > 0) err += ","; if (p_func->arguments[i + 1]->type == Node::TYPE_CONSTANT && p_func->arguments[i + 1]->get_datatype() == TYPE_INT && static_cast<ConstantNode *>(p_func->arguments[i + 1])->values[0].sint < 0) { err += "-"; } err += get_datatype_name(args[i]); } err += ")"; _set_error(err); return false; } // try existing functions.. StringName exclude_function; BlockNode *block = p_block; while (block) { if (block->parent_function) { exclude_function = block->parent_function->name; } block = block->parent_block; } if (name == exclude_function) { _set_error("Recursion is not allowed"); return false; } for (int i = 0; i < shader->functions.size(); i++) { if (name != shader->functions[i].name) continue; if (!shader->functions[i].callable) { _set_error("Function '" + String(name) + " can't be called from source code."); return false; } FunctionNode *pfunc = shader->functions[i].function; if (pfunc->arguments.size() != args.size()) continue; bool fail = false; for (int i = 0; i < args.size(); i++) { if (get_scalar_type(args[i]) == args[i] && p_func->arguments[i + 1]->type == Node::TYPE_CONSTANT && convert_constant(static_cast<ConstantNode *>(p_func->arguments[i + 1]), pfunc->arguments[i].type)) { //all good } else if (args[i] != pfunc->arguments[i].type) { fail = true; break; } } if (!fail) { if (r_ret_type) *r_ret_type = pfunc->return_type; return true; } } return false; } bool ShaderLanguage::_parse_function_arguments(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, OperatorNode *p_func, int *r_complete_arg) { TkPos pos = _get_tkpos(); Token tk = _get_token(); if (tk.type == TK_PARENTHESIS_CLOSE) { return true; } _set_tkpos(pos); while (true) { if (r_complete_arg) { pos = _get_tkpos(); tk = _get_token(); if (tk.type == TK_CURSOR) { *r_complete_arg = p_func->arguments.size() - 1; } else { _set_tkpos(pos); } } Node *arg = _parse_and_reduce_expression(p_block, p_builtin_types); if (!arg) { return false; } p_func->arguments.push_back(arg); tk = _get_token(); if (tk.type == TK_PARENTHESIS_CLOSE) { return true; } else if (tk.type != TK_COMMA) { // something is broken _set_error("Expected ',' or ')' after argument"); return false; } } return true; } bool ShaderLanguage::is_token_operator(TokenType p_type) { return (p_type == TK_OP_EQUAL || p_type == TK_OP_NOT_EQUAL || p_type == TK_OP_LESS || p_type == TK_OP_LESS_EQUAL || p_type == TK_OP_GREATER || p_type == TK_OP_GREATER_EQUAL || p_type == TK_OP_AND || p_type == TK_OP_OR || p_type == TK_OP_NOT || p_type == TK_OP_ADD || p_type == TK_OP_SUB || p_type == TK_OP_MUL || p_type == TK_OP_DIV || p_type == TK_OP_MOD || p_type == TK_OP_SHIFT_LEFT || p_type == TK_OP_SHIFT_RIGHT || p_type == TK_OP_ASSIGN || p_type == TK_OP_ASSIGN_ADD || p_type == TK_OP_ASSIGN_SUB || p_type == TK_OP_ASSIGN_MUL || p_type == TK_OP_ASSIGN_DIV || p_type == TK_OP_ASSIGN_MOD || p_type == TK_OP_ASSIGN_SHIFT_LEFT || p_type == TK_OP_ASSIGN_SHIFT_RIGHT || p_type == TK_OP_ASSIGN_BIT_AND || p_type == TK_OP_ASSIGN_BIT_OR || p_type == TK_OP_ASSIGN_BIT_XOR || p_type == TK_OP_BIT_AND || p_type == TK_OP_BIT_OR || p_type == TK_OP_BIT_XOR || p_type == TK_OP_BIT_INVERT || p_type == TK_OP_INCREMENT || p_type == TK_OP_DECREMENT || p_type == TK_QUESTION || p_type == TK_COLON); } bool ShaderLanguage::convert_constant(ConstantNode *p_constant, DataType p_to_type, ConstantNode::Value *p_value) { if (p_constant->datatype == p_to_type) { if (p_value) { for (int i = 0; i < p_constant->values.size(); i++) { p_value[i] = p_constant->values[i]; } } return true; } else if (p_constant->datatype == TYPE_INT && p_to_type == TYPE_FLOAT) { if (p_value) { p_value->real = p_constant->values[0].sint; } return true; } else if (p_constant->datatype == TYPE_UINT && p_to_type == TYPE_FLOAT) { if (p_value) { p_value->real = p_constant->values[0].uint; } return true; } else if (p_constant->datatype == TYPE_INT && p_to_type == TYPE_UINT) { if (p_constant->values[0].sint < 0) { return false; } if (p_value) { p_value->uint = p_constant->values[0].sint; } return true; } else if (p_constant->datatype == TYPE_UINT && p_to_type == TYPE_INT) { if (p_constant->values[0].uint > 0x7FFFFFFF) { return false; } if (p_value) { p_value->sint = p_constant->values[0].uint; } return true; } else return false; } bool ShaderLanguage::is_scalar_type(DataType p_type) { return p_type == TYPE_BOOL || p_type == TYPE_INT || p_type == TYPE_UINT || p_type == TYPE_FLOAT; } bool ShaderLanguage::is_sampler_type(DataType p_type) { return p_type == TYPE_SAMPLER2D || p_type == TYPE_ISAMPLER2D || p_type == TYPE_USAMPLER2D || p_type == TYPE_SAMPLER2DARRAY || p_type == TYPE_ISAMPLER2DARRAY || p_type == TYPE_USAMPLER2DARRAY || p_type == TYPE_SAMPLER3D || p_type == TYPE_ISAMPLER3D || p_type == TYPE_USAMPLER3D || p_type == TYPE_SAMPLERCUBE; } void ShaderLanguage::get_keyword_list(List<String> *r_keywords) { Set<String> kws; int idx = 0; while (keyword_list[idx].text) { kws.insert(keyword_list[idx].text); idx++; } idx = 0; while (builtin_func_defs[idx].name) { kws.insert(builtin_func_defs[idx].name); idx++; } for (Set<String>::Element *E = kws.front(); E; E = E->next()) { r_keywords->push_back(E->get()); } } void ShaderLanguage::get_builtin_funcs(List<String> *r_keywords) { Set<String> kws; int idx = 0; while (builtin_func_defs[idx].name) { kws.insert(builtin_func_defs[idx].name); idx++; } for (Set<String>::Element *E = kws.front(); E; E = E->next()) { r_keywords->push_back(E->get()); } } ShaderLanguage::DataType ShaderLanguage::get_scalar_type(DataType p_type) { static const DataType scalar_types[] = { TYPE_VOID, TYPE_BOOL, TYPE_BOOL, TYPE_BOOL, TYPE_BOOL, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_UINT, TYPE_UINT, TYPE_UINT, TYPE_UINT, TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_INT, TYPE_UINT, TYPE_FLOAT, }; return scalar_types[p_type]; } int ShaderLanguage::get_cardinality(DataType p_type) { static const int cardinality_table[] = { 0, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 2, 3, 4, 1, 1, 1, 1, }; return cardinality_table[p_type]; } bool ShaderLanguage::_get_completable_identifier(BlockNode *p_block, CompletionType p_type, StringName &identifier) { identifier = StringName(); TkPos pos; Token tk = _get_token(); if (tk.type == TK_IDENTIFIER) { identifier = tk.text; pos = _get_tkpos(); tk = _get_token(); } if (tk.type == TK_CURSOR) { completion_type = p_type; completion_line = tk_line; completion_block = p_block; pos = _get_tkpos(); tk = _get_token(); if (tk.type == TK_IDENTIFIER) { identifier = identifier.operator String() + tk.text.operator String(); } else { _set_tkpos(pos); } return true; } else if (identifier != StringName()) { _set_tkpos(pos); } return false; } bool ShaderLanguage::_is_operator_assign(Operator p_op) const { switch (p_op) { case OP_ASSIGN: case OP_ASSIGN_ADD: case OP_ASSIGN_SUB: case OP_ASSIGN_MUL: case OP_ASSIGN_DIV: case OP_ASSIGN_MOD: case OP_ASSIGN_SHIFT_LEFT: case OP_ASSIGN_SHIFT_RIGHT: case OP_ASSIGN_BIT_AND: case OP_ASSIGN_BIT_OR: case OP_ASSIGN_BIT_XOR: return true; default: return false; } return false; } bool ShaderLanguage::_validate_assign(Node *p_node, const Map<StringName, BuiltInInfo> &p_builtin_types, String *r_message) { if (p_node->type == Node::TYPE_OPERATOR) { OperatorNode *op = static_cast<OperatorNode *>(p_node); if (op->op == OP_INDEX) { return _validate_assign(op->arguments[0], p_builtin_types, r_message); } else if (_is_operator_assign(op->op)) { //chained assignment return _validate_assign(op->arguments[1], p_builtin_types, r_message); } else if (op->op == OP_CALL) { if (r_message) *r_message = RTR("Assignment to function."); return false; } } else if (p_node->type == Node::TYPE_MEMBER) { MemberNode *member = static_cast<MemberNode *>(p_node); return _validate_assign(member->owner, p_builtin_types, r_message); } else if (p_node->type == Node::TYPE_VARIABLE) { VariableNode *var = static_cast<VariableNode *>(p_node); if (shader->uniforms.has(var->name)) { if (r_message) *r_message = RTR("Assignment to uniform."); return false; } if (shader->varyings.has(var->name) && current_function != String("vertex")) { if (r_message) *r_message = RTR("Varyings can only be assigned in vertex function."); return false; } if (!(p_builtin_types.has(var->name) && p_builtin_types[var->name].constant)) { return true; } } if (r_message) *r_message = "Assignment to constant expression."; return false; } ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types) { Vector<Expression> expression; //Vector<TokenType> operators; while (true) { Node *expr = NULL; TkPos prepos = _get_tkpos(); Token tk = _get_token(); TkPos pos = _get_tkpos(); if (tk.type == TK_PARENTHESIS_OPEN) { //handle subexpression expr = _parse_and_reduce_expression(p_block, p_builtin_types); if (!expr) return NULL; tk = _get_token(); if (tk.type != TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' in expression"); return NULL; } } else if (tk.type == TK_REAL_CONSTANT) { ConstantNode *constant = alloc_node<ConstantNode>(); ConstantNode::Value v; v.real = tk.constant; constant->values.push_back(v); constant->datatype = TYPE_FLOAT; expr = constant; } else if (tk.type == TK_INT_CONSTANT) { ConstantNode *constant = alloc_node<ConstantNode>(); ConstantNode::Value v; v.sint = tk.constant; constant->values.push_back(v); constant->datatype = TYPE_INT; expr = constant; } else if (tk.type == TK_TRUE) { //handle true constant ConstantNode *constant = alloc_node<ConstantNode>(); ConstantNode::Value v; v.boolean = true; constant->values.push_back(v); constant->datatype = TYPE_BOOL; expr = constant; } else if (tk.type == TK_FALSE) { //handle false constant ConstantNode *constant = alloc_node<ConstantNode>(); ConstantNode::Value v; v.boolean = false; constant->values.push_back(v); constant->datatype = TYPE_BOOL; expr = constant; } else if (tk.type == TK_TYPE_VOID) { //make sure void is not used in expression _set_error("Void value not allowed in Expression"); return NULL; } else if (is_token_nonvoid_datatype(tk.type)) { //basic type constructor OperatorNode *func = alloc_node<OperatorNode>(); func->op = OP_CONSTRUCT; if (is_token_precision(tk.type)) { func->return_precision_cache = get_token_precision(tk.type); tk = _get_token(); } VariableNode *funcname = alloc_node<VariableNode>(); funcname->name = get_datatype_name(get_token_datatype(tk.type)); func->arguments.push_back(funcname); tk = _get_token(); if (tk.type != TK_PARENTHESIS_OPEN) { _set_error("Expected '(' after type name"); return NULL; } int carg = -1; bool ok = _parse_function_arguments(p_block, p_builtin_types, func, &carg); if (carg >= 0) { completion_type = COMPLETION_CALL_ARGUMENTS; completion_line = tk_line; completion_block = p_block; completion_function = funcname->name; completion_argument = carg; } if (!ok) return NULL; if (!_validate_function_call(p_block, func, &func->return_cache)) { _set_error("No matching constructor found for: '" + String(funcname->name) + "'"); return NULL; } //validate_Function_call() expr = _reduce_expression(p_block, func); } else if (tk.type == TK_IDENTIFIER) { _set_tkpos(prepos); StringName identifier; _get_completable_identifier(p_block, COMPLETION_IDENTIFIER, identifier); tk = _get_token(); if (tk.type == TK_PARENTHESIS_OPEN) { //a function StringName name = identifier; OperatorNode *func = alloc_node<OperatorNode>(); func->op = OP_CALL; VariableNode *funcname = alloc_node<VariableNode>(); funcname->name = name; func->arguments.push_back(funcname); int carg = -1; bool ok = _parse_function_arguments(p_block, p_builtin_types, func, &carg); //test if function was parsed first for (int i = 0; i < shader->functions.size(); i++) { if (shader->functions[i].name == name) { //add to current function as dependency for (int j = 0; j < shader->functions.size(); j++) { if (shader->functions[j].name == current_function) { shader->functions.write[j].uses_function.insert(name); break; } } break; } } if (carg >= 0) { completion_type = COMPLETION_CALL_ARGUMENTS; completion_line = tk_line; completion_block = p_block; completion_function = funcname->name; completion_argument = carg; } if (!ok) return NULL; if (!_validate_function_call(p_block, func, &func->return_cache)) { _set_error("No matching function found for: '" + String(funcname->name) + "'"); return NULL; } expr = func; } else { //an identifier _set_tkpos(pos); DataType data_type; IdentifierType ident_type; if (!_find_identifier(p_block, p_builtin_types, identifier, &data_type, &ident_type)) { _set_error("Unknown identifier in expression: " + String(identifier)); return NULL; } if (ident_type == IDENTIFIER_FUNCTION) { _set_error("Can't use function as identifier: " + String(identifier)); return NULL; } VariableNode *varname = alloc_node<VariableNode>(); varname->name = identifier; varname->datatype_cache = data_type; expr = varname; } } else if (tk.type == TK_OP_ADD) { continue; //this one does nothing } else if (tk.type == TK_OP_SUB || tk.type == TK_OP_NOT || tk.type == TK_OP_BIT_INVERT || tk.type == TK_OP_INCREMENT || tk.type == TK_OP_DECREMENT) { Expression e; e.is_op = true; switch (tk.type) { case TK_OP_SUB: e.op = OP_NEGATE; break; case TK_OP_NOT: e.op = OP_NOT; break; case TK_OP_BIT_INVERT: e.op = OP_BIT_INVERT; break; case TK_OP_INCREMENT: e.op = OP_INCREMENT; break; case TK_OP_DECREMENT: e.op = OP_DECREMENT; break; default: ERR_FAIL_V(NULL); } expression.push_back(e); continue; } else { _set_error("Expected expression, found: " + get_token_text(tk)); return NULL; //nothing } ERR_FAIL_COND_V(!expr, NULL); /* OK now see what's NEXT to the operator.. */ /* OK now see what's NEXT to the operator.. */ /* OK now see what's NEXT to the operator.. */ while (true) { TkPos pos = _get_tkpos(); tk = _get_token(); if (tk.type == TK_CURSOR) { //do nothing } else if (tk.type == TK_PERIOD) { StringName identifier; if (_get_completable_identifier(p_block, COMPLETION_INDEX, identifier)) { completion_base = expr->get_datatype(); } if (identifier == StringName()) { _set_error("Expected identifier as member"); return NULL; } DataType dt = expr->get_datatype(); String ident = identifier; bool ok = true; DataType member_type; switch (dt) { case TYPE_BVEC2: case TYPE_IVEC2: case TYPE_UVEC2: case TYPE_VEC2: { int l = ident.length(); if (l == 1) { member_type = DataType(dt - 1); } else if (l == 2) { member_type = dt; } else { ok = false; break; } const CharType *c = ident.ptr(); for (int i = 0; i < l; i++) { switch (c[i]) { case 'r': case 'g': case 'x': case 'y': break; default: ok = false; break; } } } break; case TYPE_BVEC3: case TYPE_IVEC3: case TYPE_UVEC3: case TYPE_VEC3: { int l = ident.length(); if (l == 1) { member_type = DataType(dt - 2); } else if (l == 2) { member_type = DataType(dt - 1); } else if (l == 3) { member_type = dt; } else { ok = false; break; } const CharType *c = ident.ptr(); for (int i = 0; i < l; i++) { switch (c[i]) { case 'r': case 'g': case 'b': case 'x': case 'y': case 'z': break; default: ok = false; break; } } } break; case TYPE_BVEC4: case TYPE_IVEC4: case TYPE_UVEC4: case TYPE_VEC4: { int l = ident.length(); if (l == 1) { member_type = DataType(dt - 3); } else if (l == 2) { member_type = DataType(dt - 2); } else if (l == 3) { member_type = DataType(dt - 1); } else if (l == 4) { member_type = dt; } else { ok = false; break; } const CharType *c = ident.ptr(); for (int i = 0; i < l; i++) { switch (c[i]) { case 'r': case 'g': case 'b': case 'a': case 'x': case 'y': case 'z': case 'w': break; default: ok = false; break; } } } break; default: { ok = false; } } if (!ok) { _set_error("Invalid member for " + get_datatype_name(dt) + " expression: ." + ident); return NULL; } MemberNode *mn = alloc_node<MemberNode>(); mn->basetype = dt; mn->datatype = member_type; mn->name = ident; mn->owner = expr; expr = mn; //todo //member (period) has priority over any operator //creates a subindexing expression in place /*} else if (tk.type==TK_BRACKET_OPEN) { //todo //subindexing has priority over any operator //creates a subindexing expression in place */ } else if (tk.type == TK_BRACKET_OPEN) { Node *index = _parse_and_reduce_expression(p_block, p_builtin_types); if (!index) return NULL; if (index->get_datatype() != TYPE_INT && index->get_datatype() != TYPE_UINT) { _set_error("Only integer datatypes are allowed for indexing"); return NULL; } DataType member_type = TYPE_VOID; switch (expr->get_datatype()) { case TYPE_BVEC2: case TYPE_VEC2: case TYPE_IVEC2: case TYPE_UVEC2: case TYPE_MAT2: if (index->type == Node::TYPE_CONSTANT) { uint32_t index_constant = static_cast<ConstantNode *>(index)->values[0].uint; if (index_constant >= 2) { _set_error("Index out of range (0-1)"); return NULL; } } else { _set_error("Only integer constants are allowed as index at the moment"); return NULL; } switch (expr->get_datatype()) { case TYPE_BVEC2: member_type = TYPE_BOOL; break; case TYPE_VEC2: member_type = TYPE_FLOAT; break; case TYPE_IVEC2: member_type = TYPE_INT; break; case TYPE_UVEC2: member_type = TYPE_UINT; break; case TYPE_MAT2: member_type = TYPE_VEC2; break; } break; case TYPE_BVEC3: case TYPE_VEC3: case TYPE_IVEC3: case TYPE_UVEC3: case TYPE_MAT3: if (index->type == Node::TYPE_CONSTANT) { uint32_t index_constant = static_cast<ConstantNode *>(index)->values[0].uint; if (index_constant >= 3) { _set_error("Index out of range (0-2)"); return NULL; } } else { _set_error("Only integer constants are allowed as index at the moment"); return NULL; } switch (expr->get_datatype()) { case TYPE_BVEC3: member_type = TYPE_BOOL; break; case TYPE_VEC3: member_type = TYPE_FLOAT; break; case TYPE_IVEC3: member_type = TYPE_INT; break; case TYPE_UVEC3: member_type = TYPE_UINT; break; case TYPE_MAT3: member_type = TYPE_VEC3; break; } break; case TYPE_BVEC4: case TYPE_VEC4: case TYPE_IVEC4: case TYPE_UVEC4: case TYPE_MAT4: if (index->type == Node::TYPE_CONSTANT) { uint32_t index_constant = static_cast<ConstantNode *>(index)->values[0].uint; if (index_constant >= 4) { _set_error("Index out of range (0-3)"); return NULL; } } else { _set_error("Only integer constants are allowed as index at the moment"); return NULL; } switch (expr->get_datatype()) { case TYPE_BVEC4: member_type = TYPE_BOOL; break; case TYPE_VEC4: member_type = TYPE_FLOAT; break; case TYPE_IVEC4: member_type = TYPE_INT; break; case TYPE_UVEC4: member_type = TYPE_UINT; break; case TYPE_MAT4: member_type = TYPE_VEC4; break; } break; default: { _set_error("Object of type '" + get_datatype_name(expr->get_datatype()) + "' can't be indexed"); return NULL; } } OperatorNode *op = alloc_node<OperatorNode>(); op->op = OP_INDEX; op->return_cache = member_type; op->arguments.push_back(expr); op->arguments.push_back(index); expr = op; tk = _get_token(); if (tk.type != TK_BRACKET_CLOSE) { _set_error("Expected ']' after indexing expression"); return NULL; } } else if (tk.type == TK_OP_INCREMENT || tk.type == TK_OP_DECREMENT) { OperatorNode *op = alloc_node<OperatorNode>(); op->op = tk.type == TK_OP_DECREMENT ? OP_POST_DECREMENT : OP_POST_INCREMENT; op->arguments.push_back(expr); if (!_validate_operator(op, &op->return_cache)) { _set_error("Invalid base type for increment/decrement operator"); return NULL; } if (!_validate_assign(expr, p_builtin_types)) { _set_error("Invalid use of increment/decrement operator in constant expression."); return NULL; } expr = op; } else { _set_tkpos(pos); break; } } Expression e; e.is_op = false; e.node = expr; expression.push_back(e); pos = _get_tkpos(); tk = _get_token(); if (is_token_operator(tk.type)) { Expression o; o.is_op = true; switch (tk.type) { case TK_OP_EQUAL: o.op = OP_EQUAL; break; case TK_OP_NOT_EQUAL: o.op = OP_NOT_EQUAL; break; case TK_OP_LESS: o.op = OP_LESS; break; case TK_OP_LESS_EQUAL: o.op = OP_LESS_EQUAL; break; case TK_OP_GREATER: o.op = OP_GREATER; break; case TK_OP_GREATER_EQUAL: o.op = OP_GREATER_EQUAL; break; case TK_OP_AND: o.op = OP_AND; break; case TK_OP_OR: o.op = OP_OR; break; case TK_OP_ADD: o.op = OP_ADD; break; case TK_OP_SUB: o.op = OP_SUB; break; case TK_OP_MUL: o.op = OP_MUL; break; case TK_OP_DIV: o.op = OP_DIV; break; case TK_OP_MOD: o.op = OP_MOD; break; case TK_OP_SHIFT_LEFT: o.op = OP_SHIFT_LEFT; break; case TK_OP_SHIFT_RIGHT: o.op = OP_SHIFT_RIGHT; break; case TK_OP_ASSIGN: o.op = OP_ASSIGN; break; case TK_OP_ASSIGN_ADD: o.op = OP_ASSIGN_ADD; break; case TK_OP_ASSIGN_SUB: o.op = OP_ASSIGN_SUB; break; case TK_OP_ASSIGN_MUL: o.op = OP_ASSIGN_MUL; break; case TK_OP_ASSIGN_DIV: o.op = OP_ASSIGN_DIV; break; case TK_OP_ASSIGN_MOD: o.op = OP_ASSIGN_MOD; break; case TK_OP_ASSIGN_SHIFT_LEFT: o.op = OP_ASSIGN_SHIFT_LEFT; break; case TK_OP_ASSIGN_SHIFT_RIGHT: o.op = OP_ASSIGN_SHIFT_RIGHT; break; case TK_OP_ASSIGN_BIT_AND: o.op = OP_ASSIGN_BIT_AND; break; case TK_OP_ASSIGN_BIT_OR: o.op = OP_ASSIGN_BIT_OR; break; case TK_OP_ASSIGN_BIT_XOR: o.op = OP_ASSIGN_BIT_XOR; break; case TK_OP_BIT_AND: o.op = OP_BIT_AND; break; case TK_OP_BIT_OR: o.op = OP_BIT_OR; break; case TK_OP_BIT_XOR: o.op = OP_BIT_XOR; break; case TK_QUESTION: o.op = OP_SELECT_IF; break; case TK_COLON: o.op = OP_SELECT_ELSE; break; default: { _set_error("Invalid token for operator: " + get_token_text(tk)); return NULL; } } expression.push_back(o); } else { _set_tkpos(pos); //something else, so rollback and end break; } } /* Reduce the set set of expressions and place them in an operator tree, respecting precedence */ while (expression.size() > 1) { int next_op = -1; int min_priority = 0xFFFFF; bool is_unary = false; bool is_ternary = false; for (int i = 0; i < expression.size(); i++) { if (!expression[i].is_op) { continue; } bool unary = false; bool ternary = false; int priority; switch (expression[i].op) { case OP_EQUAL: priority = 8; break; case OP_NOT_EQUAL: priority = 8; break; case OP_LESS: priority = 7; break; case OP_LESS_EQUAL: priority = 7; break; case OP_GREATER: priority = 7; break; case OP_GREATER_EQUAL: priority = 7; break; case OP_AND: priority = 12; break; case OP_OR: priority = 14; break; case OP_NOT: priority = 3; unary = true; break; case OP_NEGATE: priority = 3; unary = true; break; case OP_ADD: priority = 5; break; case OP_SUB: priority = 5; break; case OP_MUL: priority = 4; break; case OP_DIV: priority = 4; break; case OP_MOD: priority = 4; break; case OP_SHIFT_LEFT: priority = 6; break; case OP_SHIFT_RIGHT: priority = 6; break; case OP_ASSIGN: priority = 16; break; case OP_ASSIGN_ADD: priority = 16; break; case OP_ASSIGN_SUB: priority = 16; break; case OP_ASSIGN_MUL: priority = 16; break; case OP_ASSIGN_DIV: priority = 16; break; case OP_ASSIGN_MOD: priority = 16; break; case OP_ASSIGN_SHIFT_LEFT: priority = 16; break; case OP_ASSIGN_SHIFT_RIGHT: priority = 16; break; case OP_ASSIGN_BIT_AND: priority = 16; break; case OP_ASSIGN_BIT_OR: priority = 16; break; case OP_ASSIGN_BIT_XOR: priority = 16; break; case OP_BIT_AND: priority = 9; break; case OP_BIT_OR: priority = 11; break; case OP_BIT_XOR: priority = 10; break; case OP_BIT_INVERT: priority = 3; unary = true; break; case OP_INCREMENT: priority = 3; unary = true; break; case OP_DECREMENT: priority = 3; unary = true; break; case OP_SELECT_IF: priority = 15; ternary = true; break; case OP_SELECT_ELSE: priority = 15; ternary = true; break; default: ERR_FAIL_V(NULL); //unexpected operator } if (priority < min_priority) { // < is used for left to right (default) // <= is used for right to left next_op = i; min_priority = priority; is_unary = unary; is_ternary = ternary; } } ERR_FAIL_COND_V(next_op == -1, NULL); // OK! create operator.. // OK! create operator.. if (is_unary) { int expr_pos = next_op; while (expression[expr_pos].is_op) { expr_pos++; if (expr_pos == expression.size()) { //can happen.. _set_error("Unexpected end of expression..."); return NULL; } } //consecutively do unary opeators for (int i = expr_pos - 1; i >= next_op; i--) { OperatorNode *op = alloc_node<OperatorNode>(); op->op = expression[i].op; if ((op->op == OP_INCREMENT || op->op == OP_DECREMENT) && !_validate_assign(expression[i + 1].node, p_builtin_types)) { _set_error("Can't use increment/decrement operator in constant expression."); return NULL; } op->arguments.push_back(expression[i + 1].node); expression.write[i].is_op = false; expression.write[i].node = op; if (!_validate_operator(op, &op->return_cache)) { String at; for (int i = 0; i < op->arguments.size(); i++) { if (i > 0) at += " and "; at += get_datatype_name(op->arguments[i]->get_datatype()); } _set_error("Invalid arguments to unary operator '" + get_operator_text(op->op) + "' :" + at); return NULL; } expression.remove(i + 1); } } else if (is_ternary) { if (next_op < 1 || next_op >= (expression.size() - 1)) { _set_error("Parser bug..."); ERR_FAIL_V(NULL); } if (next_op + 2 >= expression.size() || !expression[next_op + 2].is_op || expression[next_op + 2].op != OP_SELECT_ELSE) { _set_error("Missing matching ':' for select operator"); return NULL; } OperatorNode *op = alloc_node<OperatorNode>(); op->op = expression[next_op].op; op->arguments.push_back(expression[next_op - 1].node); op->arguments.push_back(expression[next_op + 1].node); op->arguments.push_back(expression[next_op + 3].node); expression.write[next_op - 1].is_op = false; expression.write[next_op - 1].node = op; if (!_validate_operator(op, &op->return_cache)) { String at; for (int i = 0; i < op->arguments.size(); i++) { if (i > 0) at += " and "; at += get_datatype_name(op->arguments[i]->get_datatype()); } _set_error("Invalid argument to ternary ?: operator: " + at); return NULL; } for (int i = 0; i < 4; i++) { expression.remove(next_op); } } else { if (next_op < 1 || next_op >= (expression.size() - 1)) { _set_error("Parser bug..."); ERR_FAIL_V(NULL); } OperatorNode *op = alloc_node<OperatorNode>(); op->op = expression[next_op].op; if (expression[next_op - 1].is_op) { _set_error("Parser bug..."); ERR_FAIL_V(NULL); } if (_is_operator_assign(op->op)) { String assign_message; if (!_validate_assign(expression[next_op - 1].node, p_builtin_types, &assign_message)) { _set_error(assign_message); return NULL; } } if (expression[next_op + 1].is_op) { // this is not invalid and can really appear // but it becomes invalid anyway because no binary op // can be followed by a unary op in a valid combination, // due to how precedence works, unaries will always disappear first _set_error("Parser bug..."); } op->arguments.push_back(expression[next_op - 1].node); //expression goes as left op->arguments.push_back(expression[next_op + 1].node); //next expression goes as right expression.write[next_op - 1].node = op; //replace all 3 nodes by this operator and make it an expression if (!_validate_operator(op, &op->return_cache)) { String at; for (int i = 0; i < op->arguments.size(); i++) { if (i > 0) at += " and "; at += get_datatype_name(op->arguments[i]->get_datatype()); } _set_error("Invalid arguments to operator '" + get_operator_text(op->op) + "' :" + at); return NULL; } expression.remove(next_op); expression.remove(next_op); } } return expression[0].node; } ShaderLanguage::Node *ShaderLanguage::_reduce_expression(BlockNode *p_block, ShaderLanguage::Node *p_node) { if (p_node->type != Node::TYPE_OPERATOR) return p_node; //for now only reduce simple constructors OperatorNode *op = static_cast<OperatorNode *>(p_node); if (op->op == OP_CONSTRUCT) { ERR_FAIL_COND_V(op->arguments[0]->type != Node::TYPE_VARIABLE, p_node); DataType base = get_scalar_type(op->get_datatype()); Vector<ConstantNode::Value> values; for (int i = 1; i < op->arguments.size(); i++) { op->arguments.write[i] = _reduce_expression(p_block, op->arguments[i]); if (op->arguments[i]->type == Node::TYPE_CONSTANT) { ConstantNode *cn = static_cast<ConstantNode *>(op->arguments[i]); if (get_scalar_type(cn->datatype) == base) { int cardinality = get_cardinality(op->arguments[i]->get_datatype()); if (cn->values.size() == cardinality) { for (int j = 0; j < cn->values.size(); j++) { values.push_back(cn->values[j]); } } else if (cn->values.size() == 1) { for (int j = 0; j < cardinality; j++) { values.push_back(cn->values[0]); } } // else: should be filtered by the parser as it's an invalid constructor } else if (get_scalar_type(cn->datatype) == cn->datatype) { ConstantNode::Value v; if (!convert_constant(cn, base, &v)) { return p_node; } values.push_back(v); } else { return p_node; } } else { return p_node; } } ConstantNode *cn = alloc_node<ConstantNode>(); cn->datatype = op->get_datatype(); cn->values = values; return cn; } else if (op->op == OP_NEGATE) { op->arguments.write[0] = _reduce_expression(p_block, op->arguments[0]); if (op->arguments[0]->type == Node::TYPE_CONSTANT) { ConstantNode *cn = static_cast<ConstantNode *>(op->arguments[0]); DataType base = get_scalar_type(cn->datatype); Vector<ConstantNode::Value> values; for (int i = 0; i < cn->values.size(); i++) { ConstantNode::Value nv; switch (base) { case TYPE_BOOL: { nv.boolean = !cn->values[i].boolean; } break; case TYPE_INT: { nv.sint = -cn->values[i].sint; } break; case TYPE_UINT: { nv.uint = -cn->values[i].uint; } break; case TYPE_FLOAT: { nv.real = -cn->values[i].real; } break; default: {} } values.push_back(nv); } cn->values = values; return cn; } } return p_node; } ShaderLanguage::Node *ShaderLanguage::_parse_and_reduce_expression(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types) { ShaderLanguage::Node *expr = _parse_expression(p_block, p_builtin_types); if (!expr) //errored return NULL; expr = _reduce_expression(p_block, expr); return expr; } Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, bool p_just_one, bool p_can_break, bool p_can_continue) { while (true) { TkPos pos = _get_tkpos(); Token tk = _get_token(); if (tk.type == TK_CURLY_BRACKET_CLOSE) { //end of block if (p_just_one) { _set_error("Unexpected '}'"); return ERR_PARSE_ERROR; } return OK; } else if (is_token_precision(tk.type) || is_token_nonvoid_datatype(tk.type)) { DataPrecision precision = PRECISION_DEFAULT; if (is_token_precision(tk.type)) { precision = get_token_precision(tk.type); tk = _get_token(); if (!is_token_nonvoid_datatype(tk.type)) { _set_error("Expected datatype after precision"); return ERR_PARSE_ERROR; } } DataType type = get_token_datatype(tk.type); tk = _get_token(); VariableDeclarationNode *vardecl = alloc_node<VariableDeclarationNode>(); vardecl->datatype = type; vardecl->precision = precision; p_block->statements.push_back(vardecl); while (true) { if (tk.type != TK_IDENTIFIER) { _set_error("Expected identifier after type"); return ERR_PARSE_ERROR; } StringName name = tk.text; if (_find_identifier(p_block, p_builtin_types, name)) { _set_error("Redefinition of '" + String(name) + "'"); return ERR_PARSE_ERROR; } BlockNode::Variable var; var.type = type; var.precision = precision; var.line = tk_line; VariableDeclarationNode::Declaration decl; decl.name = name; decl.initializer = NULL; tk = _get_token(); if (tk.type == TK_OP_ASSIGN) { //variable created with assignment! must parse an expression Node *n = _parse_and_reduce_expression(p_block, p_builtin_types); if (!n) return ERR_PARSE_ERROR; decl.initializer = n; if (var.type != n->get_datatype()) { _set_error("Invalid assignment of '" + get_datatype_name(n->get_datatype()) + "' to '" + get_datatype_name(var.type) + "'"); return ERR_PARSE_ERROR; } tk = _get_token(); } p_block->variables[name] = var; vardecl->declarations.push_back(decl); if (tk.type == TK_COMMA) { tk = _get_token(); //another variable } else if (tk.type == TK_SEMICOLON) { break; } else { _set_error("Expected ',' or ';' after variable"); return ERR_PARSE_ERROR; } } } else if (tk.type == TK_CURLY_BRACKET_OPEN) { //a sub block, just because.. BlockNode *block = alloc_node<BlockNode>(); block->parent_block = p_block; _parse_block(block, p_builtin_types, false, p_can_break, p_can_continue); p_block->statements.push_back(block); } else if (tk.type == TK_CF_IF) { //if () {} tk = _get_token(); if (tk.type != TK_PARENTHESIS_OPEN) { _set_error("Expected '(' after if"); return ERR_PARSE_ERROR; } ControlFlowNode *cf = alloc_node<ControlFlowNode>(); cf->flow_op = FLOW_OP_IF; Node *n = _parse_and_reduce_expression(p_block, p_builtin_types); if (!n) return ERR_PARSE_ERROR; tk = _get_token(); if (tk.type != TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' after expression"); return ERR_PARSE_ERROR; } BlockNode *block = alloc_node<BlockNode>(); block->parent_block = p_block; cf->expressions.push_back(n); cf->blocks.push_back(block); p_block->statements.push_back(cf); Error err = _parse_block(block, p_builtin_types, true, p_can_break, p_can_continue); if (err) return err; pos = _get_tkpos(); tk = _get_token(); if (tk.type == TK_CF_ELSE) { block = alloc_node<BlockNode>(); block->parent_block = p_block; cf->blocks.push_back(block); err = _parse_block(block, p_builtin_types, true, p_can_break, p_can_continue); } else { _set_tkpos(pos); //rollback } } else if (tk.type == TK_CF_WHILE) { //if () {} tk = _get_token(); if (tk.type != TK_PARENTHESIS_OPEN) { _set_error("Expected '(' after while"); return ERR_PARSE_ERROR; } ControlFlowNode *cf = alloc_node<ControlFlowNode>(); cf->flow_op = FLOW_OP_WHILE; Node *n = _parse_and_reduce_expression(p_block, p_builtin_types); if (!n) return ERR_PARSE_ERROR; tk = _get_token(); if (tk.type != TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' after expression"); return ERR_PARSE_ERROR; } BlockNode *block = alloc_node<BlockNode>(); block->parent_block = p_block; cf->expressions.push_back(n); cf->blocks.push_back(block); p_block->statements.push_back(cf); Error err = _parse_block(block, p_builtin_types, true, true, true); if (err) return err; } else if (tk.type == TK_CF_FOR) { //if () {} tk = _get_token(); if (tk.type != TK_PARENTHESIS_OPEN) { _set_error("Expected '(' after for"); return ERR_PARSE_ERROR; } ControlFlowNode *cf = alloc_node<ControlFlowNode>(); cf->flow_op = FLOW_OP_FOR; BlockNode *init_block = alloc_node<BlockNode>(); init_block->parent_block = p_block; init_block->single_statement = true; cf->blocks.push_back(init_block); if (_parse_block(init_block, p_builtin_types, true, false, false) != OK) { return ERR_PARSE_ERROR; } Node *n = _parse_and_reduce_expression(init_block, p_builtin_types); if (!n) return ERR_PARSE_ERROR; if (n->get_datatype() != TYPE_BOOL) { _set_error("Middle expression is expected to be boolean."); return ERR_PARSE_ERROR; } tk = _get_token(); if (tk.type != TK_SEMICOLON) { _set_error("Expected ';' after middle expression"); return ERR_PARSE_ERROR; } cf->expressions.push_back(n); n = _parse_and_reduce_expression(init_block, p_builtin_types); if (!n) return ERR_PARSE_ERROR; cf->expressions.push_back(n); tk = _get_token(); if (tk.type != TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' after third expression"); return ERR_PARSE_ERROR; } BlockNode *block = alloc_node<BlockNode>(); block->parent_block = init_block; cf->blocks.push_back(block); p_block->statements.push_back(cf); Error err = _parse_block(block, p_builtin_types, true, true, true); if (err) return err; } else if (tk.type == TK_CF_RETURN) { //check return type BlockNode *b = p_block; while (b && !b->parent_function) { b = b->parent_block; } if (!b) { _set_error("Bug"); return ERR_BUG; } ControlFlowNode *flow = alloc_node<ControlFlowNode>(); flow->flow_op = FLOW_OP_RETURN; pos = _get_tkpos(); tk = _get_token(); if (tk.type == TK_SEMICOLON) { //all is good if (b->parent_function->return_type != TYPE_VOID) { _set_error("Expected return with expression of type '" + get_datatype_name(b->parent_function->return_type) + "'"); return ERR_PARSE_ERROR; } } else { _set_tkpos(pos); //rollback, wants expression Node *expr = _parse_and_reduce_expression(p_block, p_builtin_types); if (!expr) return ERR_PARSE_ERROR; if (b->parent_function->return_type != expr->get_datatype()) { _set_error("Expected return expression of type '" + get_datatype_name(b->parent_function->return_type) + "'"); return ERR_PARSE_ERROR; } tk = _get_token(); if (tk.type != TK_SEMICOLON) { _set_error("Expected ';' after return expression"); return ERR_PARSE_ERROR; } flow->expressions.push_back(expr); } p_block->statements.push_back(flow); } else if (tk.type == TK_CF_DISCARD) { //check return type BlockNode *b = p_block; while (b && !b->parent_function) { b = b->parent_block; } if (!b) { _set_error("Bug"); return ERR_BUG; } if (!b->parent_function->can_discard) { _set_error("Use of 'discard' is not allowed here."); return ERR_PARSE_ERROR; } ControlFlowNode *flow = alloc_node<ControlFlowNode>(); flow->flow_op = FLOW_OP_DISCARD; pos = _get_tkpos(); tk = _get_token(); if (tk.type != TK_SEMICOLON) { //all is good _set_error("Expected ';' after discard"); } p_block->statements.push_back(flow); } else if (tk.type == TK_CF_BREAK) { if (!p_can_break) { //all is good _set_error("Breaking is not allowed here"); } ControlFlowNode *flow = alloc_node<ControlFlowNode>(); flow->flow_op = FLOW_OP_BREAK; pos = _get_tkpos(); tk = _get_token(); if (tk.type != TK_SEMICOLON) { //all is good _set_error("Expected ';' after break"); } p_block->statements.push_back(flow); } else if (tk.type == TK_CF_CONTINUE) { if (!p_can_break) { //all is good _set_error("Continuing is not allowed here"); } ControlFlowNode *flow = alloc_node<ControlFlowNode>(); flow->flow_op = FLOW_OP_CONTINUE; pos = _get_tkpos(); tk = _get_token(); if (tk.type != TK_SEMICOLON) { //all is good _set_error("Expected ';' after continue"); } p_block->statements.push_back(flow); } else { //nothng else, so expression _set_tkpos(pos); //rollback Node *expr = _parse_and_reduce_expression(p_block, p_builtin_types); if (!expr) return ERR_PARSE_ERROR; p_block->statements.push_back(expr); tk = _get_token(); if (tk.type != TK_SEMICOLON) { _set_error("Expected ';' after statement"); return ERR_PARSE_ERROR; } } if (p_just_one) break; } return OK; } Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_functions, const Vector<StringName> &p_render_modes, const Set<String> &p_shader_types) { Token tk = _get_token(); if (tk.type != TK_SHADER_TYPE) { _set_error("Expected 'shader_type' at the beginning of shader."); return ERR_PARSE_ERROR; } tk = _get_token(); if (tk.type != TK_IDENTIFIER) { _set_error("Expected identifier after 'shader_type', indicating type of shader."); return ERR_PARSE_ERROR; } String shader_type_identifier; shader_type_identifier = tk.text; if (!p_shader_types.has(shader_type_identifier)) { String valid; for (Set<String>::Element *E = p_shader_types.front(); E; E = E->next()) { if (valid != String()) { valid += ", "; } valid += "'" + E->get() + "'"; } _set_error("Invalid shader type, valid types are: " + valid); return ERR_PARSE_ERROR; } tk = _get_token(); if (tk.type != TK_SEMICOLON) { _set_error("Expected ';' after 'shader_type <type>'."); } tk = _get_token(); int texture_uniforms = 0; int uniforms = 0; while (tk.type != TK_EOF) { switch (tk.type) { case TK_RENDER_MODE: { while (true) { StringName mode; _get_completable_identifier(NULL, COMPLETION_RENDER_MODE, mode); if (mode == StringName()) { _set_error("Expected identifier for render mode"); return ERR_PARSE_ERROR; } if (p_render_modes.find(mode) == -1) { _set_error("Invalid render mode: '" + String(mode) + "'"); return ERR_PARSE_ERROR; } if (shader->render_modes.find(mode) != -1) { _set_error("Duplicate render mode: '" + String(mode) + "'"); return ERR_PARSE_ERROR; } shader->render_modes.push_back(mode); tk = _get_token(); if (tk.type == TK_COMMA) { //all good, do nothing } else if (tk.type == TK_SEMICOLON) { break; //done } else { _set_error("Unexpected token: " + get_token_text(tk)); return ERR_PARSE_ERROR; } } } break; case TK_UNIFORM: case TK_VARYING: { bool uniform = tk.type == TK_UNIFORM; DataPrecision precision = PRECISION_DEFAULT; DataInterpolation interpolation = INTERPOLATION_SMOOTH; DataType type; StringName name; tk = _get_token(); if (is_token_interpolation(tk.type)) { interpolation = get_token_interpolation(tk.type); tk = _get_token(); } if (is_token_precision(tk.type)) { precision = get_token_precision(tk.type); tk = _get_token(); } if (!is_token_datatype(tk.type)) { _set_error("Expected datatype. "); return ERR_PARSE_ERROR; } type = get_token_datatype(tk.type); if (type == TYPE_VOID) { _set_error("void datatype not allowed here"); return ERR_PARSE_ERROR; } if (!uniform && (type < TYPE_FLOAT || type > TYPE_MAT4)) { _set_error("Invalid type for varying, only float,vec2,vec3,vec4,mat2,mat3,mat4 allowed."); return ERR_PARSE_ERROR; } tk = _get_token(); if (tk.type != TK_IDENTIFIER) { _set_error("Expected identifier!"); return ERR_PARSE_ERROR; } name = tk.text; if (_find_identifier(NULL, Map<StringName, BuiltInInfo>(), name)) { _set_error("Redefinition of '" + String(name) + "'"); return ERR_PARSE_ERROR; } if (uniform) { ShaderNode::Uniform uniform; if (is_sampler_type(type)) { uniform.texture_order = texture_uniforms++; uniform.order = -1; } else { uniform.texture_order = -1; uniform.order = uniforms++; } uniform.type = type; uniform.precission = precision; //todo parse default value tk = _get_token(); if (tk.type == TK_COLON) { //hint tk = _get_token(); if (tk.type == TK_HINT_WHITE_TEXTURE) { uniform.hint = ShaderNode::Uniform::HINT_WHITE; } else if (tk.type == TK_HINT_BLACK_TEXTURE) { uniform.hint = ShaderNode::Uniform::HINT_BLACK; } else if (tk.type == TK_HINT_NORMAL_TEXTURE) { uniform.hint = ShaderNode::Uniform::HINT_NORMAL; } else if (tk.type == TK_HINT_ANISO_TEXTURE) { uniform.hint = ShaderNode::Uniform::HINT_ANISO; } else if (tk.type == TK_HINT_ALBEDO_TEXTURE) { uniform.hint = ShaderNode::Uniform::HINT_ALBEDO; } else if (tk.type == TK_HINT_BLACK_ALBEDO_TEXTURE) { uniform.hint = ShaderNode::Uniform::HINT_BLACK_ALBEDO; } else if (tk.type == TK_HINT_COLOR) { if (type != TYPE_VEC4) { _set_error("Color hint is for vec4 only"); return ERR_PARSE_ERROR; } uniform.hint = ShaderNode::Uniform::HINT_COLOR; } else if (tk.type == TK_HINT_RANGE) { uniform.hint = ShaderNode::Uniform::HINT_RANGE; if (type != TYPE_FLOAT && type != TYPE_INT) { _set_error("Range hint is for float and int only"); return ERR_PARSE_ERROR; } tk = _get_token(); if (tk.type != TK_PARENTHESIS_OPEN) { _set_error("Expected '(' after hint_range"); return ERR_PARSE_ERROR; } tk = _get_token(); float sign = 1.0; if (tk.type == TK_OP_SUB) { sign = -1.0; tk = _get_token(); } if (tk.type != TK_REAL_CONSTANT && tk.type != TK_INT_CONSTANT) { _set_error("Expected integer constant"); return ERR_PARSE_ERROR; } uniform.hint_range[0] = tk.constant; uniform.hint_range[0] *= sign; tk = _get_token(); if (tk.type != TK_COMMA) { _set_error("Expected ',' after integer constant"); return ERR_PARSE_ERROR; } tk = _get_token(); sign = 1.0; if (tk.type == TK_OP_SUB) { sign = -1.0; tk = _get_token(); } if (tk.type != TK_REAL_CONSTANT && tk.type != TK_INT_CONSTANT) { _set_error("Expected integer constant after ','"); return ERR_PARSE_ERROR; } uniform.hint_range[1] = tk.constant; uniform.hint_range[1] *= sign; tk = _get_token(); if (tk.type == TK_COMMA) { tk = _get_token(); if (tk.type != TK_REAL_CONSTANT && tk.type != TK_INT_CONSTANT) { _set_error("Expected integer constant after ','"); return ERR_PARSE_ERROR; } uniform.hint_range[2] = tk.constant; tk = _get_token(); } else { if (type == TYPE_INT) { uniform.hint_range[2] = 1; } else { uniform.hint_range[2] = 0.001; } } if (tk.type != TK_PARENTHESIS_CLOSE) { _set_error("Expected ','"); return ERR_PARSE_ERROR; } } else { _set_error("Expected valid type hint after ':'."); } if (uniform.hint != ShaderNode::Uniform::HINT_RANGE && uniform.hint != ShaderNode::Uniform::HINT_NONE && uniform.hint != ShaderNode::Uniform::HINT_COLOR && type <= TYPE_MAT4) { _set_error("This hint is only for sampler types"); return ERR_PARSE_ERROR; } tk = _get_token(); } if (tk.type == TK_OP_ASSIGN) { Node *expr = _parse_and_reduce_expression(NULL, Map<StringName, BuiltInInfo>()); if (!expr) return ERR_PARSE_ERROR; if (expr->type != Node::TYPE_CONSTANT) { _set_error("Expected constant expression after '='"); return ERR_PARSE_ERROR; } ConstantNode *cn = static_cast<ConstantNode *>(expr); uniform.default_value.resize(cn->values.size()); if (!convert_constant(cn, uniform.type, uniform.default_value.ptrw())) { _set_error("Can't convert constant to " + get_datatype_name(uniform.type)); return ERR_PARSE_ERROR; } tk = _get_token(); } shader->uniforms[name] = uniform; if (tk.type != TK_SEMICOLON) { _set_error("Expected ';'"); return ERR_PARSE_ERROR; } } else { ShaderNode::Varying varying; varying.type = type; varying.precission = precision; varying.interpolation = interpolation; shader->varyings[name] = varying; tk = _get_token(); if (tk.type != TK_SEMICOLON) { _set_error("Expected ';'"); return ERR_PARSE_ERROR; } } } break; default: { //function DataPrecision precision = PRECISION_DEFAULT; DataType type; StringName name; if (is_token_precision(tk.type)) { precision = get_token_precision(tk.type); tk = _get_token(); } if (!is_token_datatype(tk.type)) { _set_error("Expected function, uniform or varying "); return ERR_PARSE_ERROR; } type = get_token_datatype(tk.type); _get_completable_identifier(NULL, COMPLETION_MAIN_FUNCTION, name); if (name == StringName()) { _set_error("Expected function name after datatype"); return ERR_PARSE_ERROR; } if (_find_identifier(NULL, Map<StringName, BuiltInInfo>(), name)) { _set_error("Redefinition of '" + String(name) + "'"); return ERR_PARSE_ERROR; } tk = _get_token(); if (tk.type != TK_PARENTHESIS_OPEN) { _set_error("Expected '(' after identifier"); return ERR_PARSE_ERROR; } Map<StringName, BuiltInInfo> builtin_types; if (p_functions.has(name)) { builtin_types = p_functions[name].built_ins; } ShaderNode::Function function; function.callable = !p_functions.has(name); function.name = name; FunctionNode *func_node = alloc_node<FunctionNode>(); function.function = func_node; shader->functions.push_back(function); func_node->name = name; func_node->return_type = type; func_node->return_precision = precision; if (p_functions.has(name)) { func_node->can_discard = p_functions[name].can_discard; } func_node->body = alloc_node<BlockNode>(); func_node->body->parent_function = func_node; tk = _get_token(); while (true) { if (tk.type == TK_PARENTHESIS_CLOSE) { break; } ArgumentQualifier qualifier = ARGUMENT_QUALIFIER_IN; if (tk.type == TK_ARG_IN) { qualifier = ARGUMENT_QUALIFIER_IN; tk = _get_token(); } else if (tk.type == TK_ARG_OUT) { qualifier = ARGUMENT_QUALIFIER_OUT; tk = _get_token(); } else if (tk.type == TK_ARG_INOUT) { qualifier = ARGUMENT_QUALIFIER_INOUT; tk = _get_token(); } DataType ptype; StringName pname; DataPrecision pprecision = PRECISION_DEFAULT; if (is_token_precision(tk.type)) { pprecision = get_token_precision(tk.type); tk = _get_token(); } if (!is_token_datatype(tk.type)) { _set_error("Expected a valid datatype for argument"); return ERR_PARSE_ERROR; } ptype = get_token_datatype(tk.type); if (ptype == TYPE_VOID) { _set_error("void not allowed in argument"); return ERR_PARSE_ERROR; } tk = _get_token(); if (tk.type != TK_IDENTIFIER) { _set_error("Expected identifier for argument name"); return ERR_PARSE_ERROR; } pname = tk.text; if (_find_identifier(func_node->body, builtin_types, pname)) { _set_error("Redefinition of '" + String(pname) + "'"); return ERR_PARSE_ERROR; } FunctionNode::Argument arg; arg.type = ptype; arg.name = pname; arg.precision = pprecision; arg.qualifier = qualifier; func_node->arguments.push_back(arg); tk = _get_token(); if (tk.type == TK_COMMA) { tk = _get_token(); //do none and go on } else if (tk.type != TK_PARENTHESIS_CLOSE) { _set_error("Expected ',' or ')' after identifier"); return ERR_PARSE_ERROR; } } if (p_functions.has(name)) { //if one of the core functions, make sure they are of the correct form if (func_node->arguments.size() > 0) { _set_error("Function '" + String(name) + "' expects no arguments."); return ERR_PARSE_ERROR; } if (func_node->return_type != TYPE_VOID) { _set_error("Function '" + String(name) + "' must be of void return type."); return ERR_PARSE_ERROR; } } //all good let's parse inside the function! tk = _get_token(); if (tk.type != TK_CURLY_BRACKET_OPEN) { _set_error("Expected '{' to begin function"); return ERR_PARSE_ERROR; } current_function = name; Error err = _parse_block(func_node->body, builtin_types); if (err) return err; current_function = StringName(); } } tk = _get_token(); } return OK; } // skips over whitespace and /* */ and // comments static int _get_first_ident_pos(const String &p_code) { int idx = 0; #define GETCHAR(m_idx) (((idx + m_idx) < p_code.length()) ? p_code[idx + m_idx] : CharType(0)) while (true) { if (GETCHAR(0) == '/' && GETCHAR(1) == '/') { idx += 2; while (true) { if (GETCHAR(0) == 0) return 0; if (GETCHAR(0) == '\n') { idx++; break; // loop } idx++; } } else if (GETCHAR(0) == '/' && GETCHAR(1) == '*') { idx += 2; while (true) { if (GETCHAR(0) == 0) return 0; if (GETCHAR(0) == '*' && GETCHAR(1) == '/') { idx += 2; break; // loop } idx++; } } else { switch (GETCHAR(0)) { case ' ': case '\t': case '\r': case '\n': { idx++; } break; // switch default: return idx; } } } #undef GETCHAR } String ShaderLanguage::get_shader_type(const String &p_code) { bool reading_type = false; String cur_identifier; for (int i = _get_first_ident_pos(p_code); i < p_code.length(); i++) { if (p_code[i] == ';') { break; } else if (p_code[i] <= 32) { if (cur_identifier != String()) { if (!reading_type) { if (cur_identifier != "shader_type") { return String(); } reading_type = true; cur_identifier = String(); } else { return cur_identifier; } } } else { cur_identifier += String::chr(p_code[i]); } } if (reading_type) return cur_identifier; return String(); } Error ShaderLanguage::compile(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Vector<StringName> &p_render_modes, const Set<String> &p_shader_types) { clear(); code = p_code; nodes = NULL; shader = alloc_node<ShaderNode>(); Error err = _parse_shader(p_functions, p_render_modes, p_shader_types); if (err != OK) { return err; } return OK; } Error ShaderLanguage::complete(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Vector<StringName> &p_render_modes, const Set<String> &p_shader_types, List<String> *r_options, String &r_call_hint) { clear(); code = p_code; nodes = NULL; shader = alloc_node<ShaderNode>(); Error err = _parse_shader(p_functions, p_render_modes, p_shader_types); if (err != OK) ERR_PRINT("Failed to parse shader"); switch (completion_type) { case COMPLETION_NONE: { //do nothing return OK; } break; case COMPLETION_RENDER_MODE: { for (int i = 0; i < p_render_modes.size(); i++) { r_options->push_back(p_render_modes[i]); } return OK; } break; case COMPLETION_MAIN_FUNCTION: { for (const Map<StringName, FunctionInfo>::Element *E = p_functions.front(); E; E = E->next()) { r_options->push_back(E->key()); } return OK; } break; case COMPLETION_IDENTIFIER: case COMPLETION_FUNCTION_CALL: { bool comp_ident = completion_type == COMPLETION_IDENTIFIER; Set<String> matches; StringName skip_function; BlockNode *block = completion_block; while (block) { if (comp_ident) { for (const Map<StringName, BlockNode::Variable>::Element *E = block->variables.front(); E; E = E->next()) { if (E->get().line < completion_line) { matches.insert(E->key()); } } } if (block->parent_function) { if (comp_ident) { for (int i = 0; i < block->parent_function->arguments.size(); i++) { matches.insert(block->parent_function->arguments[i].name); } } skip_function = block->parent_function->name; } block = block->parent_block; } if (comp_ident && skip_function != StringName() && p_functions.has(skip_function)) { for (Map<StringName, BuiltInInfo>::Element *E = p_functions[skip_function].built_ins.front(); E; E = E->next()) { matches.insert(E->key()); } } if (comp_ident) { for (const Map<StringName, ShaderNode::Varying>::Element *E = shader->varyings.front(); E; E = E->next()) { matches.insert(E->key()); } for (const Map<StringName, ShaderNode::Uniform>::Element *E = shader->uniforms.front(); E; E = E->next()) { matches.insert(E->key()); } } for (int i = 0; i < shader->functions.size(); i++) { if (!shader->functions[i].callable || shader->functions[i].name == skip_function) continue; matches.insert(String(shader->functions[i].name) + "("); } int idx = 0; while (builtin_func_defs[idx].name) { matches.insert(String(builtin_func_defs[idx].name) + "("); idx++; } for (Set<String>::Element *E = matches.front(); E; E = E->next()) { r_options->push_back(E->get()); } return OK; } break; case COMPLETION_CALL_ARGUMENTS: { for (int i = 0; i < shader->functions.size(); i++) { if (!shader->functions[i].callable) continue; if (shader->functions[i].name == completion_function) { String calltip; calltip += get_datatype_name(shader->functions[i].function->return_type); calltip += " "; calltip += shader->functions[i].name; calltip += "("; for (int j = 0; j < shader->functions[i].function->arguments.size(); j++) { if (j > 0) calltip += ", "; else calltip += " "; if (j == completion_argument) { calltip += CharType(0xFFFF); } calltip += get_datatype_name(shader->functions[i].function->arguments[j].type); calltip += " "; calltip += shader->functions[i].function->arguments[j].name; if (j == completion_argument) { calltip += CharType(0xFFFF); } } if (shader->functions[i].function->arguments.size()) calltip += " "; calltip += ")"; r_call_hint = calltip; return OK; } } int idx = 0; String calltip; while (builtin_func_defs[idx].name) { if (completion_function == builtin_func_defs[idx].name) { if (calltip.length()) calltip += "\n"; calltip += get_datatype_name(builtin_func_defs[idx].rettype); calltip += " "; calltip += builtin_func_defs[idx].name; calltip += "("; bool found_arg = false; for (int i = 0; i < 4; i++) { if (builtin_func_defs[idx].args[i] == TYPE_VOID) break; if (i > 0) calltip += ", "; else calltip += " "; if (i == completion_argument) { calltip += CharType(0xFFFF); } calltip += get_datatype_name(builtin_func_defs[idx].args[i]); if (i == completion_argument) { calltip += CharType(0xFFFF); } found_arg = true; } if (found_arg) calltip += " "; calltip += ")"; } idx++; } r_call_hint = calltip; return OK; } break; case COMPLETION_INDEX: { const char colv[4] = { 'r', 'g', 'b', 'a' }; const char coordv[4] = { 'x', 'y', 'z', 'w' }; int limit = 0; switch (completion_base) { case TYPE_BVEC2: case TYPE_IVEC2: case TYPE_UVEC2: case TYPE_VEC2: { limit = 2; } break; case TYPE_BVEC3: case TYPE_IVEC3: case TYPE_UVEC3: case TYPE_VEC3: { limit = 3; } break; case TYPE_BVEC4: case TYPE_IVEC4: case TYPE_UVEC4: case TYPE_VEC4: { limit = 4; } break; case TYPE_MAT2: limit = 2; break; case TYPE_MAT3: limit = 3; break; case TYPE_MAT4: limit = 4; break; default: {} } for (int i = 0; i < limit; i++) { r_options->push_back(String::chr(colv[i])); r_options->push_back(String::chr(coordv[i])); } } break; } return ERR_PARSE_ERROR; } String ShaderLanguage::get_error_text() { return error_str; } int ShaderLanguage::get_error_line() { return error_line; } ShaderLanguage::ShaderNode *ShaderLanguage::get_shader() { return shader; } ShaderLanguage::ShaderLanguage() { nodes = NULL; } ShaderLanguage::~ShaderLanguage() { clear(); }
; MapGroupRoofs values; Roofs indexes const_def const ROOF_NEW_BARK ; 0 const ROOF_VIOLET ; 1 const ROOF_AZALEA ; 2 const ROOF_OLIVINE ; 3 const ROOF_GOLDENROD ; 4 MapGroupRoofs: ; entries correspond to map groups ; values are indexes for Roofs (see below) db -1 ; 0 db ROOF_NEW_BARK ; 1 (Pallet) db -1 ; 2 (Viridian) db -1 ; 3 (Pewter) db -1 ; 4 (Dungeons) db -1 ; 5 (Indigo) db ROOF_OLIVINE ; 6 (Battle Tower) db -1 ; 7 (Cable Club) Roofs: ; entries correspond to ROOF_* constants INCBIN "gfx/tilesets/roofs/new_bark.2bpp" INCBIN "gfx/tilesets/roofs/violet.2bpp" INCBIN "gfx/tilesets/roofs/azalea.2bpp" INCBIN "gfx/tilesets/roofs/olivine.2bpp" INCBIN "gfx/tilesets/roofs/goldenrod.2bpp"
/* MIT License Copyright(c) 2020 Evgeny Pereguda 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 "SessionControl.h" #include "Session.h" #include "../Common/ComPtrCustom.h" #include "../LogPrintOut/LogPrintOut.h" #include "../Common/Common.h" namespace CaptureManager { namespace COMServer { enum class MethodsEnum :DISPID { CreateSession = 1 }; STDMETHODIMP SessionControl::createSession( VARIANT aArrayPtrSourceNodesOfTopology, REFIID aREFIID, IUnknown **aPtrPtrSession) { HRESULT lresult; do { LOG_CHECK_STATE(aPtrPtrSession == nullptr); LOG_CHECK_STATE(!(aArrayPtrSourceNodesOfTopology.vt & VT_UNKNOWN) || !(aArrayPtrSourceNodesOfTopology.vt & VT_SAFEARRAY)); CComPtrCustom<IUnknown> ltempInstance; if (aREFIID == __uuidof(ISession)) { auto lSession = CComPtrCustom<Session>(new (std::nothrow)Session); LOG_INVOKE_POINTER_METHOD(lSession, init, aArrayPtrSourceNodesOfTopology); LOG_INVOKE_QUERY_INTERFACE_METHOD(lSession, &ltempInstance); } else { lresult = E_NOINTERFACE; break; } LOG_CHECK_PTR_MEMORY(ltempInstance); LOG_INVOKE_FUNCTION(ltempInstance->QueryInterface, aREFIID, (void**)aPtrPtrSession); } while (false); return lresult; } // IDispatch interface stub STDMETHODIMP SessionControl::GetIDsOfNames( __RPC__in REFIID riid, /* [size_is][in] */ __RPC__in_ecount_full(cNames) LPOLESTR *rgszNames, /* [range][in] */ __RPC__in_range(0, 16384) UINT cNames, LCID lcid, /* [size_is][out] */ __RPC__out_ecount_full(cNames) DISPID *rgDispId) { HRESULT lresult(DISP_E_UNKNOWNNAME); do { LOG_CHECK_STATE(cNames != 1); if (_wcsicmp(*rgszNames, OLESTR("createSession")) == 0) { *rgDispId = (int)MethodsEnum::CreateSession; lresult = S_OK; } } while (false); return lresult; } HRESULT SessionControl::invokeMethod( /* [annotation][in] */ _In_ DISPID dispIdMember, /* [annotation][out][in] */ _In_ DISPPARAMS *pDispParams, /* [annotation][out] */ _Out_opt_ VARIANT *pVarResult) { HRESULT lresult(DISP_E_UNKNOWNINTERFACE); do { LOG_CHECK_STATE_DESCR(pDispParams == nullptr, DISP_E_PARAMNOTFOUND); LOG_CHECK_PTR_MEMORY(pVarResult); switch (dispIdMember) { case (int)MethodsEnum::CreateSession: { LOG_CHECK_STATE_DESCR(pDispParams->cArgs != 2, DISP_E_BADPARAMCOUNT) VARIANT lArrayPtrSourceNodesOfTopology; GUID lIID; if (pDispParams->rgvarg[1].vt == VT_VARIANT && pDispParams->rgvarg[1].pvarVal != nullptr) { lArrayPtrSourceNodesOfTopology = *(pDispParams->rgvarg[1].pvarVal); } else if (pDispParams->rgvarg[1].vt == (VT_ARRAY | VT_VARIANT)) { SAFEARRAY* lPtrSAMediaTypes = nullptr; lPtrSAMediaTypes = pDispParams->rgvarg[1].parray; LOG_CHECK_STATE_DESCR(lPtrSAMediaTypes == nullptr, DISP_E_BADVARTYPE); lArrayPtrSourceNodesOfTopology.vt = VT_UNKNOWN | VT_SAFEARRAY; lArrayPtrSourceNodesOfTopology.parray = lPtrSAMediaTypes; } else { lresult = DISP_E_BADVARTYPE; break; } if (pDispParams->rgvarg[0].vt == VT_CLSID) { } else if (pDispParams->rgvarg[0].vt == VT_BSTR && pDispParams->rgvarg[0].bstrVal != nullptr) { LOG_INVOKE_FUNCTION(CLSIDFromString, pDispParams->rgvarg[0].bstrVal, &lIID); } else { lresult = DISP_E_BADVARTYPE; break; } CComPtrCustom<IUnknown> lSession; LOG_INVOKE_FUNCTION(createSession, lArrayPtrSourceNodesOfTopology, lIID, &lSession); pVarResult->vt = VT_UNKNOWN; pVarResult->punkVal = lSession.detach(); } break; default: break; } } while (false); return lresult; } } }
;------------------------------------------------------------------------------ ; ; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR> ; This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BSD License ; which accompanies this distribution. The full text of the license may be found at ; http://opensource.org/licenses/bsd-license.php. ; ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. ; ; Module Name: ; ; WriteDr3.Asm ; ; Abstract: ; ; AsmWriteDr3 function ; ; Notes: ; ;------------------------------------------------------------------------------ .586p .model flat,C .code ;------------------------------------------------------------------------------ ; UINTN ; EFIAPI ; AsmWriteDr3 ( ; IN UINTN Value ; ); ;------------------------------------------------------------------------------ AsmWriteDr3 PROC mov eax, [esp + 4] mov dr3, eax ret AsmWriteDr3 ENDP END
#if defined PLAT_PC #ifndef WINDOWS_APPLICATION_HPP #define WINDOWS_APPLICATION_HPP ////////////////////////////////////////////////////// // INCLUDES ////////////////////////////////////////////////////// #include <windows.h> ////////////////////////////////////////////////////// // CLASSES ////////////////////////////////////////////////////// class WindowsApplication { public: // // This constructor will initialize the application // WindowsApplication( HINSTANCE hInst, wchar_t* className, WNDPROC wndPrc, LPCTSTR menuName = NULL ); // // Destructor // ~WindowsApplication(); // // Class Registration // void Register(); private: // // Global variable that holds the application // WNDCLASSEX mWindowsClassEx; }; #endif #endif
; A131844: 3*A131821 - 2*A000012. ; Submitted by Simon Strandgaard ; 1,4,4,7,1,7,10,1,1,10,13,1,1,1,13,16,1,1,1,1,16,19,1,1,1,1,1,19,22,1,1,1,1,1,1,22,25,1,1,1,1,1,1,1,25,28,1,1,1,1,1,1,1,1,28 lpb $0 add $1,1 sub $0,$1 mov $2,$1 lpe bin $1,$0 pow $1,2 div $2,$1 mov $0,$2 mul $0,3 add $0,1
; A063657: Numbers with property that truncated square root is unequal to rounded square root. ; 3,7,8,13,14,15,21,22,23,24,31,32,33,34,35,43,44,45,46,47,48,57,58,59,60,61,62,63,73,74,75,76,77,78,79,80,91,92,93,94,95,96,97,98,99,111,112,113,114,115,116,117,118,119,120,133,134,135,136,137,138,139,140,141,142,143,157,158,159,160,161,162,163,164,165,166,167,168,183,184,185,186,187,188,189,190,191,192,193,194,195,211,212,213,214,215,216,217,218,219,220,221,222,223,224,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525 mov $1,3 mov $2,$0 lpb $2 add $1,2 add $3,1 add $0,$3 sub $2,1 trn $2,$3 lpe add $1,$0
;****************************************************************************** ;* VP9 Intra prediction SIMD optimizations ;* ;* Copyright (c) 2015 Ronald S. Bultje <rsbultje gmail com> ;* Copyright (c) 2015 Henrik Gramner <henrik gramner com> ;* ;* This file is part of FFmpeg. ;* ;* FFmpeg is free software; you can redistribute it and/or ;* modify it under the terms of the GNU Lesser General Public ;* License as published by the Free Software Foundation; either ;* version 2.1 of the License, or (at your option) any later version. ;* ;* FFmpeg is distributed in the hope that it will be useful, ;* but WITHOUT ANY WARRANTY; without even the implied warranty of ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;* Lesser General Public License for more details. ;* ;* You should have received a copy of the GNU Lesser General Public ;* License along with FFmpeg; if not, write to the Free Software ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ;****************************************************************************** %include "libavutil/x86/x86util.asm" SECTION_RODATA 32 pd_2: times 8 dd 2 pd_4: times 8 dd 4 pd_8: times 8 dd 8 pb_2to15_14_15: db 2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,15 pb_4_5_8to13_8x0: db 4,5,8,9,10,11,12,13,0,0,0,0,0,0,0,0 pb_0to7_67x4: db 0,1,2,3,4,5,6,7,6,7,6,7,6,7,6,7 cextern pw_1 cextern pw_1023 cextern pw_4095 cextern pd_16 cextern pd_32 cextern pd_65535; ; FIXME most top-only functions (ddl, vl, v, dc_top) can be modified to take ; only 3 registers on x86-32, which would make it one cycle faster, but that ; would make the code quite a bit uglier... SECTION .text %macro SCRATCH 3-4 %if ARCH_X86_64 SWAP %1, %2 %if %0 == 4 %define reg_%4 m%2 %endif %else mova [%3], m%1 %if %0 == 4 %define reg_%4 [%3] %endif %endif %endmacro %macro UNSCRATCH 3-4 %if ARCH_X86_64 SWAP %1, %2 %else mova m%1, [%3] %endif %if %0 == 4 %undef reg_%4 %endif %endmacro %macro PRELOAD 2-3 %if ARCH_X86_64 mova m%1, [%2] %if %0 == 3 %define reg_%3 m%1 %endif %elif %0 == 3 %define reg_%3 [%2] %endif %endmacro INIT_MMX mmx cglobal vp9_ipred_v_4x4_16, 2, 4, 1, dst, stride, l, a movifnidn aq, amp mova m0, [aq] DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m0 mova [dstq+strideq*2], m0 mova [dstq+stride3q ], m0 RET INIT_XMM sse cglobal vp9_ipred_v_8x8_16, 2, 4, 1, dst, stride, l, a movifnidn aq, amp mova m0, [aq] DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m0 mova [dstq+strideq*2], m0 mova [dstq+stride3q ], m0 lea dstq, [dstq+strideq*4] mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m0 mova [dstq+strideq*2], m0 mova [dstq+stride3q ], m0 RET INIT_XMM sse cglobal vp9_ipred_v_16x16_16, 2, 4, 2, dst, stride, l, a movifnidn aq, amp mova m0, [aq] mova m1, [aq+mmsize] DEFINE_ARGS dst, stride, stride3, cnt lea stride3q, [strideq*3] mov cntd, 4 .loop: mova [dstq+strideq*0+ 0], m0 mova [dstq+strideq*0+16], m1 mova [dstq+strideq*1+ 0], m0 mova [dstq+strideq*1+16], m1 mova [dstq+strideq*2+ 0], m0 mova [dstq+strideq*2+16], m1 mova [dstq+stride3q + 0], m0 mova [dstq+stride3q +16], m1 lea dstq, [dstq+strideq*4] dec cntd jg .loop RET INIT_XMM sse cglobal vp9_ipred_v_32x32_16, 2, 4, 4, dst, stride, l, a movifnidn aq, amp mova m0, [aq+mmsize*0] mova m1, [aq+mmsize*1] mova m2, [aq+mmsize*2] mova m3, [aq+mmsize*3] DEFINE_ARGS dst, stride, cnt mov cntd, 16 .loop: mova [dstq+strideq*0+ 0], m0 mova [dstq+strideq*0+16], m1 mova [dstq+strideq*0+32], m2 mova [dstq+strideq*0+48], m3 mova [dstq+strideq*1+ 0], m0 mova [dstq+strideq*1+16], m1 mova [dstq+strideq*1+32], m2 mova [dstq+strideq*1+48], m3 lea dstq, [dstq+strideq*2] dec cntd jg .loop RET INIT_MMX mmxext cglobal vp9_ipred_h_4x4_16, 3, 3, 4, dst, stride, l, a mova m3, [lq] DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] pshufw m0, m3, q3333 pshufw m1, m3, q2222 pshufw m2, m3, q1111 pshufw m3, m3, q0000 mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m1 mova [dstq+strideq*2], m2 mova [dstq+stride3q ], m3 RET INIT_XMM sse2 cglobal vp9_ipred_h_8x8_16, 3, 3, 4, dst, stride, l, a mova m2, [lq] DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] punpckhwd m3, m2, m2 pshufd m0, m3, q3333 pshufd m1, m3, q2222 mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m1 pshufd m0, m3, q1111 pshufd m1, m3, q0000 mova [dstq+strideq*2], m0 mova [dstq+stride3q ], m1 lea dstq, [dstq+strideq*4] punpcklwd m2, m2 pshufd m0, m2, q3333 pshufd m1, m2, q2222 mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m1 pshufd m0, m2, q1111 pshufd m1, m2, q0000 mova [dstq+strideq*2], m0 mova [dstq+stride3q ], m1 RET INIT_XMM sse2 cglobal vp9_ipred_h_16x16_16, 3, 5, 4, dst, stride, l, stride3, cnt mov cntd, 3 lea stride3q, [strideq*3] .loop: movh m3, [lq+cntq*8] punpcklwd m3, m3 pshufd m0, m3, q3333 pshufd m1, m3, q2222 pshufd m2, m3, q1111 pshufd m3, m3, q0000 mova [dstq+strideq*0+ 0], m0 mova [dstq+strideq*0+16], m0 mova [dstq+strideq*1+ 0], m1 mova [dstq+strideq*1+16], m1 mova [dstq+strideq*2+ 0], m2 mova [dstq+strideq*2+16], m2 mova [dstq+stride3q + 0], m3 mova [dstq+stride3q +16], m3 lea dstq, [dstq+strideq*4] dec cntd jge .loop RET INIT_XMM sse2 cglobal vp9_ipred_h_32x32_16, 3, 5, 4, dst, stride, l, stride3, cnt mov cntd, 7 lea stride3q, [strideq*3] .loop: movh m3, [lq+cntq*8] punpcklwd m3, m3 pshufd m0, m3, q3333 pshufd m1, m3, q2222 pshufd m2, m3, q1111 pshufd m3, m3, q0000 mova [dstq+strideq*0+ 0], m0 mova [dstq+strideq*0+16], m0 mova [dstq+strideq*0+32], m0 mova [dstq+strideq*0+48], m0 mova [dstq+strideq*1+ 0], m1 mova [dstq+strideq*1+16], m1 mova [dstq+strideq*1+32], m1 mova [dstq+strideq*1+48], m1 mova [dstq+strideq*2+ 0], m2 mova [dstq+strideq*2+16], m2 mova [dstq+strideq*2+32], m2 mova [dstq+strideq*2+48], m2 mova [dstq+stride3q + 0], m3 mova [dstq+stride3q +16], m3 mova [dstq+stride3q +32], m3 mova [dstq+stride3q +48], m3 lea dstq, [dstq+strideq*4] dec cntd jge .loop RET INIT_MMX mmxext cglobal vp9_ipred_dc_4x4_16, 4, 4, 2, dst, stride, l, a mova m0, [lq] paddw m0, [aq] DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] pmaddwd m0, [pw_1] pshufw m1, m0, q3232 paddd m0, [pd_4] paddd m0, m1 psrad m0, 3 pshufw m0, m0, q0000 mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m0 mova [dstq+strideq*2], m0 mova [dstq+stride3q ], m0 RET INIT_XMM sse2 cglobal vp9_ipred_dc_8x8_16, 4, 4, 2, dst, stride, l, a mova m0, [lq] paddw m0, [aq] DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] pmaddwd m0, [pw_1] pshufd m1, m0, q3232 paddd m0, m1 pshufd m1, m0, q1111 paddd m0, [pd_8] paddd m0, m1 psrad m0, 4 pshuflw m0, m0, q0000 punpcklqdq m0, m0 mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m0 mova [dstq+strideq*2], m0 mova [dstq+stride3q ], m0 lea dstq, [dstq+strideq*4] mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m0 mova [dstq+strideq*2], m0 mova [dstq+stride3q ], m0 RET INIT_XMM sse2 cglobal vp9_ipred_dc_16x16_16, 4, 4, 2, dst, stride, l, a mova m0, [lq] paddw m0, [lq+mmsize] paddw m0, [aq] paddw m0, [aq+mmsize] DEFINE_ARGS dst, stride, stride3, cnt lea stride3q, [strideq*3] mov cntd, 4 pmaddwd m0, [pw_1] pshufd m1, m0, q3232 paddd m0, m1 pshufd m1, m0, q1111 paddd m0, [pd_16] paddd m0, m1 psrad m0, 5 pshuflw m0, m0, q0000 punpcklqdq m0, m0 .loop: mova [dstq+strideq*0+ 0], m0 mova [dstq+strideq*0+16], m0 mova [dstq+strideq*1+ 0], m0 mova [dstq+strideq*1+16], m0 mova [dstq+strideq*2+ 0], m0 mova [dstq+strideq*2+16], m0 mova [dstq+stride3q + 0], m0 mova [dstq+stride3q +16], m0 lea dstq, [dstq+strideq*4] dec cntd jg .loop RET INIT_XMM sse2 cglobal vp9_ipred_dc_32x32_16, 4, 4, 2, dst, stride, l, a mova m0, [lq+mmsize*0] paddw m0, [lq+mmsize*1] paddw m0, [lq+mmsize*2] paddw m0, [lq+mmsize*3] paddw m0, [aq+mmsize*0] paddw m0, [aq+mmsize*1] paddw m0, [aq+mmsize*2] paddw m0, [aq+mmsize*3] DEFINE_ARGS dst, stride, stride3, cnt lea stride3q, [strideq*3] mov cntd, 16 pmaddwd m0, [pw_1] pshufd m1, m0, q3232 paddd m0, m1 pshufd m1, m0, q1111 paddd m0, [pd_32] paddd m0, m1 psrad m0, 6 pshuflw m0, m0, q0000 punpcklqdq m0, m0 .loop: mova [dstq+strideq*0+ 0], m0 mova [dstq+strideq*0+16], m0 mova [dstq+strideq*0+32], m0 mova [dstq+strideq*0+48], m0 mova [dstq+strideq*1+ 0], m0 mova [dstq+strideq*1+16], m0 mova [dstq+strideq*1+32], m0 mova [dstq+strideq*1+48], m0 lea dstq, [dstq+strideq*2] dec cntd jg .loop RET %macro DC_1D_FNS 2 INIT_MMX mmxext cglobal vp9_ipred_dc_%1_4x4_16, 4, 4, 2, dst, stride, l, a mova m0, [%2] DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] pmaddwd m0, [pw_1] pshufw m1, m0, q3232 paddd m0, [pd_2] paddd m0, m1 psrad m0, 2 pshufw m0, m0, q0000 mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m0 mova [dstq+strideq*2], m0 mova [dstq+stride3q ], m0 RET INIT_XMM sse2 cglobal vp9_ipred_dc_%1_8x8_16, 4, 4, 2, dst, stride, l, a mova m0, [%2] DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] pmaddwd m0, [pw_1] pshufd m1, m0, q3232 paddd m0, m1 pshufd m1, m0, q1111 paddd m0, [pd_4] paddd m0, m1 psrad m0, 3 pshuflw m0, m0, q0000 punpcklqdq m0, m0 mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m0 mova [dstq+strideq*2], m0 mova [dstq+stride3q ], m0 lea dstq, [dstq+strideq*4] mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m0 mova [dstq+strideq*2], m0 mova [dstq+stride3q ], m0 RET INIT_XMM sse2 cglobal vp9_ipred_dc_%1_16x16_16, 4, 4, 2, dst, stride, l, a mova m0, [%2] paddw m0, [%2+mmsize] DEFINE_ARGS dst, stride, stride3, cnt lea stride3q, [strideq*3] mov cntd, 4 pmaddwd m0, [pw_1] pshufd m1, m0, q3232 paddd m0, m1 pshufd m1, m0, q1111 paddd m0, [pd_8] paddd m0, m1 psrad m0, 4 pshuflw m0, m0, q0000 punpcklqdq m0, m0 .loop: mova [dstq+strideq*0+ 0], m0 mova [dstq+strideq*0+16], m0 mova [dstq+strideq*1+ 0], m0 mova [dstq+strideq*1+16], m0 mova [dstq+strideq*2+ 0], m0 mova [dstq+strideq*2+16], m0 mova [dstq+stride3q + 0], m0 mova [dstq+stride3q +16], m0 lea dstq, [dstq+strideq*4] dec cntd jg .loop RET INIT_XMM sse2 cglobal vp9_ipred_dc_%1_32x32_16, 4, 4, 2, dst, stride, l, a mova m0, [%2+mmsize*0] paddw m0, [%2+mmsize*1] paddw m0, [%2+mmsize*2] paddw m0, [%2+mmsize*3] DEFINE_ARGS dst, stride, cnt mov cntd, 16 pmaddwd m0, [pw_1] pshufd m1, m0, q3232 paddd m0, m1 pshufd m1, m0, q1111 paddd m0, [pd_16] paddd m0, m1 psrad m0, 5 pshuflw m0, m0, q0000 punpcklqdq m0, m0 .loop: mova [dstq+strideq*0+ 0], m0 mova [dstq+strideq*0+16], m0 mova [dstq+strideq*0+32], m0 mova [dstq+strideq*0+48], m0 mova [dstq+strideq*1+ 0], m0 mova [dstq+strideq*1+16], m0 mova [dstq+strideq*1+32], m0 mova [dstq+strideq*1+48], m0 lea dstq, [dstq+strideq*2] dec cntd jg .loop RET %endmacro DC_1D_FNS top, aq DC_1D_FNS left, lq INIT_MMX mmxext cglobal vp9_ipred_tm_4x4_10, 4, 4, 6, dst, stride, l, a mova m5, [pw_1023] .body: mova m4, [aq] mova m3, [lq] movd m0, [aq-4] pshufw m0, m0, q1111 psubw m4, m0 DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] pshufw m0, m3, q3333 pshufw m1, m3, q2222 pshufw m2, m3, q1111 pshufw m3, m3, q0000 paddw m0, m4 paddw m1, m4 paddw m2, m4 paddw m3, m4 pxor m4, m4 pmaxsw m0, m4 pmaxsw m1, m4 pmaxsw m2, m4 pmaxsw m3, m4 pminsw m0, m5 pminsw m1, m5 pminsw m2, m5 pminsw m3, m5 mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m1 mova [dstq+strideq*2], m2 mova [dstq+stride3q ], m3 RET cglobal vp9_ipred_tm_4x4_12, 4, 4, 6, dst, stride, l, a mova m5, [pw_4095] jmp mangle(private_prefix %+ _ %+ vp9_ipred_tm_4x4_10 %+ SUFFIX).body INIT_XMM sse2 cglobal vp9_ipred_tm_8x8_10, 4, 5, 7, dst, stride, l, a mova m4, [pw_1023] .body: pxor m6, m6 mova m5, [aq] movd m0, [aq-4] pshuflw m0, m0, q1111 punpcklqdq m0, m0 psubw m5, m0 DEFINE_ARGS dst, stride, l, stride3, cnt lea stride3q, [strideq*3] mov cntd, 1 .loop: movh m3, [lq+cntq*8] punpcklwd m3, m3 pshufd m0, m3, q3333 pshufd m1, m3, q2222 pshufd m2, m3, q1111 pshufd m3, m3, q0000 paddw m0, m5 paddw m1, m5 paddw m2, m5 paddw m3, m5 pmaxsw m0, m6 pmaxsw m1, m6 pmaxsw m2, m6 pmaxsw m3, m6 pminsw m0, m4 pminsw m1, m4 pminsw m2, m4 pminsw m3, m4 mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m1 mova [dstq+strideq*2], m2 mova [dstq+stride3q ], m3 lea dstq, [dstq+strideq*4] dec cntd jge .loop RET cglobal vp9_ipred_tm_8x8_12, 4, 5, 7, dst, stride, l, a mova m4, [pw_4095] jmp mangle(private_prefix %+ _ %+ vp9_ipred_tm_8x8_10 %+ SUFFIX).body INIT_XMM sse2 cglobal vp9_ipred_tm_16x16_10, 4, 4, 8, dst, stride, l, a mova m7, [pw_1023] .body: pxor m6, m6 mova m4, [aq] mova m5, [aq+mmsize] movd m0, [aq-4] pshuflw m0, m0, q1111 punpcklqdq m0, m0 psubw m4, m0 psubw m5, m0 DEFINE_ARGS dst, stride, l, cnt mov cntd, 7 .loop: movd m3, [lq+cntq*4] punpcklwd m3, m3 pshufd m2, m3, q1111 pshufd m3, m3, q0000 paddw m0, m2, m4 paddw m2, m5 paddw m1, m3, m4 paddw m3, m5 pmaxsw m0, m6 pmaxsw m2, m6 pmaxsw m1, m6 pmaxsw m3, m6 pminsw m0, m7 pminsw m2, m7 pminsw m1, m7 pminsw m3, m7 mova [dstq+strideq*0+ 0], m0 mova [dstq+strideq*0+16], m2 mova [dstq+strideq*1+ 0], m1 mova [dstq+strideq*1+16], m3 lea dstq, [dstq+strideq*2] dec cntd jge .loop RET cglobal vp9_ipred_tm_16x16_12, 4, 4, 8, dst, stride, l, a mova m7, [pw_4095] jmp mangle(private_prefix %+ _ %+ vp9_ipred_tm_16x16_10 %+ SUFFIX).body INIT_XMM sse2 cglobal vp9_ipred_tm_32x32_10, 4, 4, 10, 32 * -ARCH_X86_32, dst, stride, l, a mova m0, [pw_1023] .body: pxor m1, m1 %if ARCH_X86_64 SWAP 0, 8 SWAP 1, 9 %define reg_min m9 %define reg_max m8 %else mova [rsp+ 0], m0 mova [rsp+16], m1 %define reg_min [rsp+16] %define reg_max [rsp+ 0] %endif mova m4, [aq+mmsize*0] mova m5, [aq+mmsize*1] mova m6, [aq+mmsize*2] mova m7, [aq+mmsize*3] movd m0, [aq-4] pshuflw m0, m0, q1111 punpcklqdq m0, m0 psubw m4, m0 psubw m5, m0 psubw m6, m0 psubw m7, m0 DEFINE_ARGS dst, stride, l, cnt mov cntd, 31 .loop: pinsrw m3, [lq+cntq*2], 0 punpcklwd m3, m3 pshufd m3, m3, q0000 paddw m0, m3, m4 paddw m1, m3, m5 paddw m2, m3, m6 paddw m3, m7 pmaxsw m0, reg_min pmaxsw m1, reg_min pmaxsw m2, reg_min pmaxsw m3, reg_min pminsw m0, reg_max pminsw m1, reg_max pminsw m2, reg_max pminsw m3, reg_max mova [dstq+strideq*0+ 0], m0 mova [dstq+strideq*0+16], m1 mova [dstq+strideq*0+32], m2 mova [dstq+strideq*0+48], m3 add dstq, strideq dec cntd jge .loop RET cglobal vp9_ipred_tm_32x32_12, 4, 4, 10, 32 * -ARCH_X86_32, dst, stride, l, a mova m0, [pw_4095] jmp mangle(private_prefix %+ _ %+ vp9_ipred_tm_32x32_10 %+ SUFFIX).body ; Directional intra predicion functions ; ; in the functions below, 'abcdefgh' refers to above data (sometimes simply ; abbreviated as a[N-M]). 'stuvwxyz' refers to left data (sometimes simply ; abbreviated as l[N-M]). * is top-left data. ABCDEFG or A[N-M] is filtered ; above data, STUVWXYZ or L[N-M] is filtered left data, and # is filtered ; top-left data. ; left=(left+2*center+right+2)>>2 %macro LOWPASS 3 ; left [dst], center, right paddw m%1, m%3 psraw m%1, 1 pavgw m%1, m%2 %endmacro ; abcdefgh (src) -> bcdefghh (dst) ; dst/src can be the same register %macro SHIFT_RIGHT 2-3 [pb_2to15_14_15] ; dst, src, [ssse3_shift_reg] %if cpuflag(ssse3) pshufb %1, %2, %3 ; abcdefgh -> bcdefghh %else psrldq %1, %2, 2 ; abcdefgh -> bcdefgh. pshufhw %1, %1, q2210 ; bcdefgh. -> bcdefghh %endif %endmacro ; abcdefgh (src) -> bcdefghh (dst1) and cdefghhh (dst2) %macro SHIFT_RIGHTx2 3-4 [pb_2to15_14_15] ; dst1, dst2, src, [ssse3_shift_reg] %if cpuflag(ssse3) pshufb %1, %3, %4 ; abcdefgh -> bcdefghh pshufb %2, %1, %4 ; bcdefghh -> cdefghhh %else psrldq %1, %3, 2 ; abcdefgh -> bcdefgh. psrldq %2, %3, 4 ; abcdefgh -> cdefgh.. pshufhw %1, %1, q2210 ; bcdefgh. -> bcdefghh pshufhw %2, %2, q1110 ; cdefgh.. -> cdefghhh %endif %endmacro %macro DL_FUNCS 0 cglobal vp9_ipred_dl_4x4_16, 2, 4, 3, dst, stride, l, a movifnidn aq, amp movu m1, [aq] ; abcdefgh pshufhw m0, m1, q3310 ; abcdefhh SHIFT_RIGHT m1, m1 ; bcdefghh psrldq m2, m1, 2 ; cdefghh. LOWPASS 0, 1, 2 ; BCDEFGh. pshufd m1, m0, q3321 ; DEFGh... movh [dstq+strideq*0], m0 movh [dstq+strideq*2], m1 add dstq, strideq psrldq m0, 2 ; CDEFGh.. psrldq m1, 2 ; EFGh.... movh [dstq+strideq*0], m0 movh [dstq+strideq*2], m1 RET cglobal vp9_ipred_dl_8x8_16, 2, 4, 5, dst, stride, l, a movifnidn aq, amp mova m0, [aq] ; abcdefgh %if cpuflag(ssse3) mova m4, [pb_2to15_14_15] %endif SHIFT_RIGHTx2 m1, m2, m0, m4 ; bcdefghh/cdefghhh LOWPASS 0, 1, 2 ; BCDEFGHh shufps m1, m0, m2, q3332 ; FGHhhhhh shufps m3, m0, m1, q2121 ; DEFGHhhh DEFINE_ARGS dst, stride, stride5 lea stride5q, [strideq*5] mova [dstq+strideq*0], m0 mova [dstq+strideq*4], m1 SHIFT_RIGHT m0, m0, m4 ; CDEFGHhh pshuflw m1, m1, q3321 ; GHhhhhhh pshufd m2, m0, q3321 ; EFGHhhhh mova [dstq+strideq*1], m0 mova [dstq+stride5q ], m1 lea dstq, [dstq+strideq*2] pshuflw m1, m1, q3321 ; Hhhhhhhh mova [dstq+strideq*0], m3 mova [dstq+strideq*4], m1 pshuflw m1, m1, q3321 ; hhhhhhhh mova [dstq+strideq*1], m2 mova [dstq+stride5q ], m1 RET cglobal vp9_ipred_dl_16x16_16, 2, 4, 5, dst, stride, l, a movifnidn aq, amp mova m0, [aq] ; abcdefgh mova m3, [aq+mmsize] ; ijklmnop PALIGNR m1, m3, m0, 2, m4 ; bcdefghi PALIGNR m2, m3, m0, 4, m4 ; cdefghij LOWPASS 0, 1, 2 ; BCDEFGHI %if cpuflag(ssse3) mova m4, [pb_2to15_14_15] %endif SHIFT_RIGHTx2 m2, m1, m3, m4 ; jklmnopp/klmnoppp LOWPASS 1, 2, 3 ; JKLMNOPp pshufd m2, m2, q3333 ; pppppppp DEFINE_ARGS dst, stride, cnt mov cntd, 8 .loop: mova [dstq+strideq*0+ 0], m0 mova [dstq+strideq*0+16], m1 mova [dstq+strideq*8+ 0], m1 mova [dstq+strideq*8+16], m2 add dstq, strideq %if cpuflag(avx) vpalignr m0, m1, m0, 2 %else PALIGNR m3, m1, m0, 2, m4 mova m0, m3 %endif SHIFT_RIGHT m1, m1, m4 dec cntd jg .loop RET cglobal vp9_ipred_dl_32x32_16, 2, 5, 7, dst, stride, l, a movifnidn aq, amp mova m0, [aq+mmsize*0] ; abcdefgh mova m1, [aq+mmsize*1] ; ijklmnop mova m2, [aq+mmsize*2] ; qrstuvwx mova m3, [aq+mmsize*3] ; yz012345 PALIGNR m4, m1, m0, 2, m6 PALIGNR m5, m1, m0, 4, m6 LOWPASS 0, 4, 5 ; BCDEFGHI PALIGNR m4, m2, m1, 2, m6 PALIGNR m5, m2, m1, 4, m6 LOWPASS 1, 4, 5 ; JKLMNOPQ PALIGNR m4, m3, m2, 2, m6 PALIGNR m5, m3, m2, 4, m6 LOWPASS 2, 4, 5 ; RSTUVWXY %if cpuflag(ssse3) mova m6, [pb_2to15_14_15] %endif SHIFT_RIGHTx2 m4, m5, m3, m6 LOWPASS 3, 4, 5 ; Z0123455 pshufd m4, m4, q3333 ; 55555555 DEFINE_ARGS dst, stride, stride8, stride24, cnt mov cntd, 8 lea stride8q, [strideq*8] lea stride24q, [stride8q*3] .loop: mova [dstq+stride8q*0+ 0], m0 mova [dstq+stride8q*0+16], m1 mova [dstq+stride8q*0+32], m2 mova [dstq+stride8q*0+48], m3 mova [dstq+stride8q*1+ 0], m1 mova [dstq+stride8q*1+16], m2 mova [dstq+stride8q*1+32], m3 mova [dstq+stride8q*1+48], m4 mova [dstq+stride8q*2+ 0], m2 mova [dstq+stride8q*2+16], m3 mova [dstq+stride8q*2+32], m4 mova [dstq+stride8q*2+48], m4 mova [dstq+stride24q + 0], m3 mova [dstq+stride24q +16], m4 mova [dstq+stride24q +32], m4 mova [dstq+stride24q +48], m4 add dstq, strideq %if cpuflag(avx) vpalignr m0, m1, m0, 2 vpalignr m1, m2, m1, 2 vpalignr m2, m3, m2, 2 %else PALIGNR m5, m1, m0, 2, m6 mova m0, m5 PALIGNR m5, m2, m1, 2, m6 mova m1, m5 PALIGNR m5, m3, m2, 2, m6 mova m2, m5 %endif SHIFT_RIGHT m3, m3, m6 dec cntd jg .loop RET %endmacro INIT_XMM sse2 DL_FUNCS INIT_XMM ssse3 DL_FUNCS INIT_XMM avx DL_FUNCS %if HAVE_AVX2_EXTERNAL INIT_YMM avx2 cglobal vp9_ipred_dl_16x16_16, 2, 4, 5, dst, stride, l, a movifnidn aq, amp mova m0, [aq] ; abcdefghijklmnop vpbroadcastw xm1, [aq+30] ; pppppppp vperm2i128 m2, m0, m1, q0201 ; ijklmnoppppppppp vpalignr m3, m2, m0, 2 ; bcdefghijklmnopp vpalignr m4, m2, m0, 4 ; cdefghijklmnoppp LOWPASS 0, 3, 4 ; BCDEFGHIJKLMNOPp vperm2i128 m2, m0, m1, q0201 ; JKLMNOPppppppppp DEFINE_ARGS dst, stride, stride3, cnt mov cntd, 2 lea stride3q, [strideq*3] .loop: mova [dstq+strideq*0], m0 vpalignr m3, m2, m0, 2 vpalignr m4, m2, m0, 4 mova [dstq+strideq*1], m3 mova [dstq+strideq*2], m4 vpalignr m3, m2, m0, 6 vpalignr m4, m2, m0, 8 mova [dstq+stride3q ], m3 lea dstq, [dstq+strideq*4] mova [dstq+strideq*0], m4 vpalignr m3, m2, m0, 10 vpalignr m4, m2, m0, 12 mova [dstq+strideq*1], m3 mova [dstq+strideq*2], m4 vpalignr m3, m2, m0, 14 mova [dstq+stride3q ], m3 lea dstq, [dstq+strideq*4] mova m0, m2 vperm2i128 m2, m2, m2, q0101 ; pppppppppppppppp dec cntd jg .loop RET cglobal vp9_ipred_dl_32x32_16, 2, 6, 7, dst, stride, l, a movifnidn aq, amp mova m0, [aq+mmsize*0+ 0] ; abcdefghijklmnop mova m1, [aq+mmsize*1+ 0] ; qrstuvwxyz012345 vpbroadcastw xm4, [aq+mmsize*1+30] ; 55555555 vperm2i128 m5, m0, m1, q0201 ; ijklmnopqrstuvwx vpalignr m2, m5, m0, 2 ; bcdefghijklmnopq vpalignr m3, m5, m0, 4 ; cdefghijklmnopqr LOWPASS 0, 2, 3 ; BCDEFGHIJKLMNOPQ vperm2i128 m5, m1, m4, q0201 ; yz01234555555555 vpalignr m2, m5, m1, 2 ; rstuvwxyz0123455 vpalignr m3, m5, m1, 4 ; stuvwxyz01234555 LOWPASS 1, 2, 3 ; RSTUVWXYZ......5 vperm2i128 m2, m1, m4, q0201 ; Z......555555555 vperm2i128 m5, m0, m1, q0201 ; JKLMNOPQRSTUVWXY DEFINE_ARGS dst, stride, stride3, cnt lea stride3q, [strideq*3] mov cntd, 4 .loop: mova [dstq+strideq*0 + 0], m0 mova [dstq+strideq*0 +32], m1 vpalignr m3, m5, m0, 2 vpalignr m4, m2, m1, 2 mova [dstq+strideq*1 + 0], m3 mova [dstq+strideq*1 +32], m4 vpalignr m3, m5, m0, 4 vpalignr m4, m2, m1, 4 mova [dstq+strideq*2 + 0], m3 mova [dstq+strideq*2 +32], m4 vpalignr m3, m5, m0, 6 vpalignr m4, m2, m1, 6 mova [dstq+stride3q*1+ 0], m3 mova [dstq+stride3q*1+32], m4 lea dstq, [dstq+strideq*4] vpalignr m3, m5, m0, 8 vpalignr m4, m2, m1, 8 mova [dstq+strideq*0 + 0], m3 mova [dstq+strideq*0 +32], m4 vpalignr m3, m5, m0, 10 vpalignr m4, m2, m1, 10 mova [dstq+strideq*1 + 0], m3 mova [dstq+strideq*1 +32], m4 vpalignr m3, m5, m0, 12 vpalignr m4, m2, m1, 12 mova [dstq+strideq*2+ 0], m3 mova [dstq+strideq*2+32], m4 vpalignr m3, m5, m0, 14 vpalignr m4, m2, m1, 14 mova [dstq+stride3q+ 0], m3 mova [dstq+stride3q+ 32], m4 vpalignr m3, m5, m0, 16 vpalignr m4, m2, m1, 16 vperm2i128 m5, m3, m4, q0201 vperm2i128 m2, m4, m4, q0101 mova m0, m3 mova m1, m4 lea dstq, [dstq+strideq*4] dec cntd jg .loop RET %endif %macro DR_FUNCS 1 ; stack_mem_for_32x32_32bit_function cglobal vp9_ipred_dr_4x4_16, 4, 4, 3, dst, stride, l, a movh m0, [lq] ; wxyz.... movhps m0, [aq-2] ; wxyz*abc movd m1, [aq+6] ; d....... PALIGNR m1, m0, 2, m2 ; xyz*abcd psrldq m2, m1, 2 ; yz*abcd. LOWPASS 0, 1, 2 ; XYZ#ABC. DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] movh [dstq+stride3q ], m0 psrldq m0, 2 ; YZ#ABC.. movh [dstq+strideq*2], m0 psrldq m0, 2 ; Z#ABC... movh [dstq+strideq*1], m0 psrldq m0, 2 ; #ABC.... movh [dstq+strideq*0], m0 RET cglobal vp9_ipred_dr_8x8_16, 4, 4, 5, dst, stride, l, a mova m0, [lq] ; stuvwxyz movu m1, [aq-2] ; *abcdefg mova m2, [aq] ; abcdefgh psrldq m3, m2, 2 ; bcdefgh. LOWPASS 3, 2, 1 ; ABCDEFG. PALIGNR m1, m0, 2, m4 ; tuvwxyz* PALIGNR m2, m1, 2, m4 ; uvwxyz*a LOWPASS 2, 1, 0 ; TUVWXYZ# DEFINE_ARGS dst, stride, dst4, stride3 lea stride3q, [strideq*3] lea dst4q, [dstq+strideq*4] movhps [dstq +stride3q +0], m2 movh [dstq+ stride3q +8], m3 mova [dst4q+stride3q +0], m2 PALIGNR m1, m3, m2, 2, m0 psrldq m3, 2 movhps [dstq +strideq*2+0], m1 movh [dstq+ strideq*2+8], m3 mova [dst4q+strideq*2+0], m1 PALIGNR m2, m3, m1, 2, m0 psrldq m3, 2 movhps [dstq +strideq*1+0], m2 movh [dstq+ strideq*1+8], m3 mova [dst4q+strideq*1+0], m2 PALIGNR m1, m3, m2, 2, m0 psrldq m3, 2 movhps [dstq +strideq*0+0], m1 movh [dstq+ strideq*0+8], m3 mova [dst4q+strideq*0+0], m1 RET cglobal vp9_ipred_dr_16x16_16, 4, 4, 7, dst, stride, l, a mova m0, [lq] ; klmnopqr mova m1, [lq+mmsize] ; stuvwxyz movu m2, [aq-2] ; *abcdefg movu m3, [aq+mmsize-2] ; hijklmno mova m4, [aq] ; abcdefgh mova m5, [aq+mmsize] ; ijklmnop psrldq m6, m5, 2 ; jklmnop. LOWPASS 6, 5, 3 ; IJKLMNO. PALIGNR m5, m4, 2, m3 ; bcdefghi LOWPASS 5, 4, 2 ; ABCDEFGH PALIGNR m2, m1, 2, m3 ; tuvwxyz* PALIGNR m4, m2, 2, m3 ; uvwxyz*a LOWPASS 4, 2, 1 ; TUVWXYZ# PALIGNR m1, m0, 2, m3 ; lmnopqrs PALIGNR m2, m1, 2, m3 ; mnopqrst LOWPASS 2, 1, 0 ; LMNOPQRS DEFINE_ARGS dst, stride, dst8, cnt lea dst8q, [dstq+strideq*8] mov cntd, 8 .loop: sub dst8q, strideq mova [dst8q+strideq*0+ 0], m4 mova [dst8q+strideq*0+16], m5 mova [dst8q+strideq*8+ 0], m2 mova [dst8q+strideq*8+16], m4 %if cpuflag(avx) vpalignr m2, m4, m2, 2 vpalignr m4, m5, m4, 2 vpalignr m5, m6, m5, 2 %else PALIGNR m0, m4, m2, 2, m1 mova m2, m0 PALIGNR m0, m5, m4, 2, m1 mova m4, m0 PALIGNR m0, m6, m5, 2, m1 mova m5, m0 %endif psrldq m6, 2 dec cntd jg .loop RET cglobal vp9_ipred_dr_32x32_16, 4, 5, 10 + notcpuflag(ssse3), \ %1 * ARCH_X86_32 * -mmsize, dst, stride, l, a mova m0, [aq+mmsize*3] ; a[24-31] movu m1, [aq+mmsize*3-2] ; a[23-30] psrldq m2, m0, 2 ; a[25-31]. LOWPASS 2, 0, 1 ; A[24-30]. mova m1, [aq+mmsize*2] ; a[16-23] movu m3, [aq+mmsize*2-2] ; a[15-22] PALIGNR m0, m1, 2, m4 ; a[17-24] LOWPASS 0, 1, 3 ; A[16-23] mova m3, [aq+mmsize*1] ; a[8-15] movu m4, [aq+mmsize*1-2] ; a[7-14] PALIGNR m1, m3, 2, m5 ; a[9-16] LOWPASS 1, 3, 4 ; A[8-15] mova m4, [aq+mmsize*0] ; a[0-7] movu m5, [aq+mmsize*0-2] ; *a[0-6] PALIGNR m3, m4, 2, m6 ; a[1-8] LOWPASS 3, 4, 5 ; A[0-7] SCRATCH 1, 8, rsp+0*mmsize SCRATCH 3, 9, rsp+1*mmsize %if notcpuflag(ssse3) SCRATCH 0, 10, rsp+2*mmsize %endif mova m6, [lq+mmsize*3] ; l[24-31] PALIGNR m5, m6, 2, m0 ; l[25-31]* PALIGNR m4, m5, 2, m0 ; l[26-31]*a LOWPASS 4, 5, 6 ; L[25-31]# mova m7, [lq+mmsize*2] ; l[16-23] PALIGNR m6, m7, 2, m0 ; l[17-24] PALIGNR m5, m6, 2, m0 ; l[18-25] LOWPASS 5, 6, 7 ; L[17-24] mova m1, [lq+mmsize*1] ; l[8-15] PALIGNR m7, m1, 2, m0 ; l[9-16] PALIGNR m6, m7, 2, m0 ; l[10-17] LOWPASS 6, 7, 1 ; L[9-16] mova m3, [lq+mmsize*0] ; l[0-7] PALIGNR m1, m3, 2, m0 ; l[1-8] PALIGNR m7, m1, 2, m0 ; l[2-9] LOWPASS 7, 1, 3 ; L[1-8] %if cpuflag(ssse3) %if cpuflag(avx) UNSCRATCH 1, 8, rsp+0*mmsize %endif UNSCRATCH 3, 9, rsp+1*mmsize %else UNSCRATCH 0, 10, rsp+2*mmsize %endif DEFINE_ARGS dst8, stride, stride8, stride24, cnt lea stride8q, [strideq*8] lea stride24q, [stride8q*3] lea dst8q, [dst8q+strideq*8] mov cntd, 8 .loop: sub dst8q, strideq %if notcpuflag(avx) UNSCRATCH 1, 8, rsp+0*mmsize %if notcpuflag(ssse3) UNSCRATCH 3, 9, rsp+1*mmsize %endif %endif mova [dst8q+stride8q*0+ 0], m4 mova [dst8q+stride8q*0+16], m3 mova [dst8q+stride8q*0+32], m1 mova [dst8q+stride8q*0+48], m0 mova [dst8q+stride8q*1+ 0], m5 mova [dst8q+stride8q*1+16], m4 mova [dst8q+stride8q*1+32], m3 mova [dst8q+stride8q*1+48], m1 mova [dst8q+stride8q*2+ 0], m6 mova [dst8q+stride8q*2+16], m5 mova [dst8q+stride8q*2+32], m4 mova [dst8q+stride8q*2+48], m3 mova [dst8q+stride24q + 0], m7 mova [dst8q+stride24q +16], m6 mova [dst8q+stride24q +32], m5 mova [dst8q+stride24q +48], m4 %if cpuflag(avx) vpalignr m7, m6, m7, 2 vpalignr m6, m5, m6, 2 vpalignr m5, m4, m5, 2 vpalignr m4, m3, m4, 2 vpalignr m3, m1, m3, 2 vpalignr m1, m0, m1, 2 vpalignr m0, m2, m0, 2 %else SCRATCH 2, 8, rsp+0*mmsize %if notcpuflag(ssse3) SCRATCH 0, 9, rsp+1*mmsize %endif PALIGNR m2, m6, m7, 2, m0 mova m7, m2 PALIGNR m2, m5, m6, 2, m0 mova m6, m2 PALIGNR m2, m4, m5, 2, m0 mova m5, m2 PALIGNR m2, m3, m4, 2, m0 mova m4, m2 PALIGNR m2, m1, m3, 2, m0 mova m3, m2 %if notcpuflag(ssse3) UNSCRATCH 0, 9, rsp+1*mmsize SCRATCH 3, 9, rsp+1*mmsize %endif PALIGNR m2, m0, m1, 2, m3 mova m1, m2 UNSCRATCH 2, 8, rsp+0*mmsize SCRATCH 1, 8, rsp+0*mmsize PALIGNR m1, m2, m0, 2, m3 mova m0, m1 %endif psrldq m2, 2 dec cntd jg .loop RET %endmacro INIT_XMM sse2 DR_FUNCS 3 INIT_XMM ssse3 DR_FUNCS 2 INIT_XMM avx DR_FUNCS 2 %if HAVE_AVX2_EXTERNAL INIT_YMM avx2 cglobal vp9_ipred_dr_16x16_16, 4, 5, 6, dst, stride, l, a mova m0, [lq] ; klmnopqrstuvwxyz movu m1, [aq-2] ; *abcdefghijklmno mova m2, [aq] ; abcdefghijklmnop vperm2i128 m4, m2, m2, q2001 ; ijklmnop........ vpalignr m5, m4, m2, 2 ; bcdefghijklmnop. vperm2i128 m3, m0, m1, q0201 ; stuvwxyz*abcdefg LOWPASS 1, 2, 5 ; ABCDEFGHIJKLMNO. vpalignr m4, m3, m0, 2 ; lmnopqrstuvwxyz* vpalignr m5, m3, m0, 4 ; mnopqrstuvwxyz*a LOWPASS 0, 4, 5 ; LMNOPQRSTUVWXYZ# vperm2i128 m5, m0, m1, q0201 ; TUVWXYZ#ABCDEFGH DEFINE_ARGS dst, stride, stride3, stride5, dst3 lea dst3q, [dstq+strideq*4] lea stride3q, [strideq*3] lea stride5q, [stride3q+strideq*2] vpalignr m3, m5, m0, 2 vpalignr m4, m1, m5, 2 mova [dst3q+stride5q*2], m3 ; 14 mova [ dstq+stride3q*2], m4 ; 6 vpalignr m3, m5, m0, 4 vpalignr m4, m1, m5, 4 sub dst3q, strideq mova [dst3q+stride5q*2], m3 ; 13 mova [dst3q+strideq*2 ], m4 ; 5 mova [dst3q+stride3q*4], m0 ; 15 vpalignr m3, m5, m0, 6 vpalignr m4, m1, m5, 6 mova [dstq+stride3q*4], m3 ; 12 mova [dst3q+strideq*1], m4 ; 4 vpalignr m3, m5, m0, 8 vpalignr m4, m1, m5, 8 mova [dst3q+strideq*8], m3 ; 11 mova [dst3q+strideq*0], m4 ; 3 vpalignr m3, m5, m0, 10 vpalignr m4, m1, m5, 10 mova [dstq+stride5q*2], m3 ; 10 mova [dstq+strideq*2 ], m4 ; 2 vpalignr m3, m5, m0, 12 vpalignr m4, m1, m5, 12 mova [dst3q+stride3q*2], m3 ; 9 mova [dstq+strideq*1 ], m4 ; 1 vpalignr m3, m5, m0, 14 vpalignr m4, m1, m5, 14 mova [dstq+strideq*8], m3 ; 8 mova [dstq+strideq*0], m4 ; 0 mova [dst3q+strideq*4], m5 ; 7 RET %if ARCH_X86_64 cglobal vp9_ipred_dr_32x32_16, 4, 7, 10, dst, stride, l, a mova m0, [lq+mmsize*0+0] ; l[0-15] mova m1, [lq+mmsize*1+0] ; l[16-31] movu m2, [aq+mmsize*0-2] ; *abcdefghijklmno mova m3, [aq+mmsize*0+0] ; abcdefghijklmnop mova m4, [aq+mmsize*1+0] ; qrstuvwxyz012345 vperm2i128 m5, m0, m1, q0201 ; lmnopqrstuvwxyz0 vpalignr m6, m5, m0, 2 ; mnopqrstuvwxyz01 vpalignr m7, m5, m0, 4 ; nopqrstuvwxyz012 LOWPASS 0, 6, 7 ; L[0-15] vperm2i128 m7, m1, m2, q0201 ; stuvwxyz*abcdefg vpalignr m5, m7, m1, 2 ; lmnopqrstuvwxyz* vpalignr m6, m7, m1, 4 ; mnopqrstuvwxyz*a LOWPASS 1, 5, 6 ; L[16-31]# vperm2i128 m5, m3, m4, q0201 ; ijklmnopqrstuvwx vpalignr m6, m5, m3, 2 ; bcdefghijklmnopq LOWPASS 2, 3, 6 ; A[0-15] movu m3, [aq+mmsize*1-2] ; pqrstuvwxyz01234 vperm2i128 m6, m4, m4, q2001 ; yz012345........ vpalignr m7, m6, m4, 2 ; rstuvwxyz012345. LOWPASS 3, 4, 7 ; A[16-31]. vperm2i128 m4, m1, m2, q0201 ; TUVWXYZ#ABCDEFGH vperm2i128 m5, m0, m1, q0201 ; L[7-15]L[16-23] vperm2i128 m8, m2, m3, q0201 ; IJKLMNOPQRSTUVWX DEFINE_ARGS dst8, stride, stride3, stride7, stride5, dst24, cnt lea stride3q, [strideq*3] lea stride5q, [stride3q+strideq*2] lea stride7q, [strideq*4+stride3q] lea dst24q, [dst8q+stride3q*8] lea dst8q, [dst8q+strideq*8] mov cntd, 2 .loop: mova [dst24q+stride7q+0 ], m0 ; 31 23 15 7 mova [dst24q+stride7q+32], m1 mova [dst8q+stride7q+0], m1 mova [dst8q+stride7q+32], m2 vpalignr m6, m4, m1, 2 vpalignr m7, m5, m0, 2 vpalignr m9, m8, m2, 2 mova [dst24q+stride3q*2+0], m7 ; 30 22 14 6 mova [dst24q+stride3q*2+32], m6 mova [dst8q+stride3q*2+0], m6 mova [dst8q+stride3q*2+32], m9 vpalignr m6, m4, m1, 4 vpalignr m7, m5, m0, 4 vpalignr m9, m8, m2, 4 mova [dst24q+stride5q+0], m7 ; 29 21 13 5 mova [dst24q+stride5q+32], m6 mova [dst8q+stride5q+0], m6 mova [dst8q+stride5q+32], m9 vpalignr m6, m4, m1, 6 vpalignr m7, m5, m0, 6 vpalignr m9, m8, m2, 6 mova [dst24q+strideq*4+0 ], m7 ; 28 20 12 4 mova [dst24q+strideq*4+32], m6 mova [dst8q+strideq*4+0], m6 mova [dst8q+strideq*4+32], m9 vpalignr m6, m4, m1, 8 vpalignr m7, m5, m0, 8 vpalignr m9, m8, m2, 8 mova [dst24q+stride3q+0 ], m7 ; 27 19 11 3 mova [dst24q+stride3q+32], m6 mova [dst8q+stride3q+0], m6 mova [dst8q+stride3q+32], m9 vpalignr m6, m4, m1, 10 vpalignr m7, m5, m0, 10 vpalignr m9, m8, m2, 10 mova [dst24q+strideq*2+0 ], m7 ; 26 18 10 2 mova [dst24q+strideq*2+32], m6 mova [dst8q+strideq*2+0], m6 mova [dst8q+strideq*2+32], m9 vpalignr m6, m4, m1, 12 vpalignr m7, m5, m0, 12 vpalignr m9, m8, m2, 12 mova [dst24q+strideq+0 ], m7 ; 25 17 9 1 mova [dst24q+strideq+32], m6 mova [dst8q+strideq+0], m6 mova [dst8q+strideq+32], m9 vpalignr m6, m4, m1, 14 vpalignr m7, m5, m0, 14 vpalignr m9, m8, m2, 14 mova [dst24q+strideq*0+0 ], m7 ; 24 16 8 0 mova [dst24q+strideq*0+32], m6 mova [dst8q+strideq*0+0], m6 mova [dst8q+strideq*0+32], m9 mova m0, m5 mova m5, m1 mova m1, m4 mova m4, m2 mova m2, m8 mova m8, m3 sub dst24q, stride7q sub dst24q, strideq sub dst8q, stride7q sub dst8q, strideq dec cntd jg .loop RET %endif %endif %macro VL_FUNCS 1 ; stack_mem_for_32x32_32bit_function cglobal vp9_ipred_vl_4x4_16, 2, 4, 3, dst, stride, l, a movifnidn aq, amp movu m0, [aq] ; abcdefgh psrldq m1, m0, 2 ; bcdefgh. psrldq m2, m0, 4 ; cdefgh.. LOWPASS 2, 1, 0 ; BCDEFGH. pavgw m1, m0 ; ABCDEFG. DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] movh [dstq+strideq*0], m1 movh [dstq+strideq*1], m2 psrldq m1, 2 psrldq m2, 2 movh [dstq+strideq*2], m1 movh [dstq+stride3q ], m2 RET cglobal vp9_ipred_vl_8x8_16, 2, 4, 4, dst, stride, l, a movifnidn aq, amp mova m0, [aq] ; abcdefgh %if cpuflag(ssse3) mova m3, [pb_2to15_14_15] %endif SHIFT_RIGHTx2 m1, m2, m0, m3 ; bcdefghh/cdefghhh LOWPASS 2, 1, 0 ; BCDEFGHh pavgw m1, m0 ; ABCDEFGh DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] mova [dstq+strideq*0], m1 mova [dstq+strideq*1], m2 SHIFT_RIGHT m1, m1, m3 SHIFT_RIGHT m2, m2, m3 mova [dstq+strideq*2], m1 mova [dstq+stride3q ], m2 lea dstq, [dstq+strideq*4] SHIFT_RIGHT m1, m1, m3 SHIFT_RIGHT m2, m2, m3 mova [dstq+strideq*0], m1 mova [dstq+strideq*1], m2 SHIFT_RIGHT m1, m1, m3 SHIFT_RIGHT m2, m2, m3 mova [dstq+strideq*2], m1 mova [dstq+stride3q ], m2 RET cglobal vp9_ipred_vl_16x16_16, 2, 4, 6, dst, stride, l, a movifnidn aq, amp mova m0, [aq] mova m1, [aq+mmsize] PALIGNR m2, m1, m0, 2, m3 PALIGNR m3, m1, m0, 4, m4 LOWPASS 3, 2, 0 pavgw m2, m0 %if cpuflag(ssse3) mova m4, [pb_2to15_14_15] %endif SHIFT_RIGHTx2 m5, m0, m1, m4 LOWPASS 0, 5, 1 pavgw m1, m5 DEFINE_ARGS dst, stride, cnt mov cntd, 8 .loop: mova [dstq+strideq*0+ 0], m2 mova [dstq+strideq*0+16], m1 mova [dstq+strideq*1+ 0], m3 mova [dstq+strideq*1+16], m0 lea dstq, [dstq+strideq*2] %if cpuflag(avx) vpalignr m2, m1, m2, 2 vpalignr m3, m0, m3, 2 %else PALIGNR m5, m1, m2, 2, m4 mova m2, m5 PALIGNR m5, m0, m3, 2, m4 mova m3, m5 %endif SHIFT_RIGHT m1, m1, m4 SHIFT_RIGHT m0, m0, m4 dec cntd jg .loop RET cglobal vp9_ipred_vl_32x32_16, 2, 5, 11, %1 * mmsize * ARCH_X86_32, dst, stride, l, a movifnidn aq, amp mova m0, [aq+mmsize*0] mova m1, [aq+mmsize*1] mova m2, [aq+mmsize*2] PALIGNR m6, m1, m0, 2, m5 PALIGNR m7, m1, m0, 4, m5 LOWPASS 7, 6, 0 pavgw m6, m0 SCRATCH 6, 8, rsp+0*mmsize PALIGNR m4, m2, m1, 2, m0 PALIGNR m5, m2, m1, 4, m0 LOWPASS 5, 4, 1 pavgw m4, m1 mova m0, [aq+mmsize*3] PALIGNR m1, m0, m2, 2, m6 PALIGNR m3, m0, m2, 4, m6 LOWPASS 3, 1, 2 pavgw m2, m1 %if cpuflag(ssse3) PRELOAD 10, pb_2to15_14_15, shuf %endif SHIFT_RIGHTx2 m6, m1, m0, reg_shuf LOWPASS 1, 6, 0 pavgw m0, m6 %if ARCH_X86_64 pshufd m9, m6, q3333 %endif %if cpuflag(avx) UNSCRATCH 6, 8, rsp+0*mmsize %endif DEFINE_ARGS dst, stride, cnt, stride16, stride17 mov stride16q, strideq mov cntd, 8 shl stride16q, 4 lea stride17q, [stride16q+strideq] ; FIXME m8 is unused for avx, so we could save one register here for win64 .loop: %if notcpuflag(avx) UNSCRATCH 6, 8, rsp+0*mmsize %endif mova [dstq+strideq*0+ 0], m6 mova [dstq+strideq*0+16], m4 mova [dstq+strideq*0+32], m2 mova [dstq+strideq*0+48], m0 mova [dstq+strideq*1+ 0], m7 mova [dstq+strideq*1+16], m5 mova [dstq+strideq*1+32], m3 mova [dstq+strideq*1+48], m1 mova [dstq+stride16q+ 0], m4 mova [dstq+stride16q+16], m2 mova [dstq+stride16q+32], m0 %if ARCH_X86_64 mova [dstq+stride16q+48], m9 %endif mova [dstq+stride17q+ 0], m5 mova [dstq+stride17q+16], m3 mova [dstq+stride17q+32], m1 %if ARCH_X86_64 mova [dstq+stride17q+48], m9 %endif lea dstq, [dstq+strideq*2] %if cpuflag(avx) vpalignr m6, m4, m6, 2 vpalignr m4, m2, m4, 2 vpalignr m2, m0, m2, 2 vpalignr m7, m5, m7, 2 vpalignr m5, m3, m5, 2 vpalignr m3, m1, m3, 2 %else SCRATCH 3, 8, rsp+0*mmsize %if notcpuflag(ssse3) SCRATCH 1, 10, rsp+1*mmsize %endif PALIGNR m3, m4, m6, 2, m1 mova m6, m3 PALIGNR m3, m2, m4, 2, m1 mova m4, m3 PALIGNR m3, m0, m2, 2, m1 mova m2, m3 PALIGNR m3, m5, m7, 2, m1 mova m7, m3 UNSCRATCH 3, 8, rsp+0*mmsize SCRATCH 6, 8, rsp+0*mmsize %if notcpuflag(ssse3) UNSCRATCH 1, 10, rsp+1*mmsize SCRATCH 7, 10, rsp+1*mmsize %endif PALIGNR m6, m3, m5, 2, m7 mova m5, m6 PALIGNR m6, m1, m3, 2, m7 mova m3, m6 %if notcpuflag(ssse3) UNSCRATCH 7, 10, rsp+1*mmsize %endif %endif SHIFT_RIGHT m1, m1, reg_shuf SHIFT_RIGHT m0, m0, reg_shuf dec cntd jg .loop %if ARCH_X86_32 DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] %assign %%n 0 %rep 4 mova [dstq+strideq*0+48], m0 mova [dstq+strideq*1+48], m0 mova [dstq+strideq*2+48], m0 mova [dstq+stride3q +48], m0 %if %%n < 3 lea dstq, [dstq+strideq*4] %endif %assign %%n (%%n+1) %endrep %endif RET %endmacro INIT_XMM sse2 VL_FUNCS 2 INIT_XMM ssse3 VL_FUNCS 1 INIT_XMM avx VL_FUNCS 1 %macro VR_FUNCS 0 cglobal vp9_ipred_vr_4x4_16, 4, 4, 3, dst, stride, l, a movu m0, [aq-2] movhps m1, [lq] PALIGNR m0, m1, 10, m2 ; xyz*abcd pslldq m1, m0, 2 ; .xyz*abc pslldq m2, m0, 4 ; ..xyz*ab LOWPASS 2, 1, 0 ; ..YZ#ABC pavgw m1, m0 ; ....#ABC DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] movhps [dstq+strideq*0], m1 movhps [dstq+strideq*1], m2 shufps m0, m2, m1, q3210 %if cpuflag(ssse3) pshufb m2, [pb_4_5_8to13_8x0] %else pshuflw m2, m2, q2222 psrldq m2, 6 %endif psrldq m0, 6 movh [dstq+strideq*2], m0 movh [dstq+stride3q ], m2 RET cglobal vp9_ipred_vr_8x8_16, 4, 4, 5, dst, stride, l, a movu m1, [aq-2] ; *abcdefg movu m2, [lq] ; stuvwxyz mova m0, [aq] ; abcdefgh PALIGNR m3, m1, m2, 14, m4 ; z*abcdef LOWPASS 3, 1, 0 pavgw m0, m1 PALIGNR m1, m2, 2, m4 ; tuvwxyz* pslldq m4, m2, 2 ; .stuvwxy LOWPASS 4, 2, 1 DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m3 PALIGNR m0, m4, 14, m1 pslldq m4, 2 PALIGNR m3, m4, 14, m1 pslldq m4, 2 mova [dstq+strideq*2], m0 mova [dstq+stride3q ], m3 lea dstq, [dstq+strideq*4] PALIGNR m0, m4, 14, m1 pslldq m4, 2 PALIGNR m3, m4, 14, m1 pslldq m4, 2 mova [dstq+strideq*0], m0 mova [dstq+strideq*1], m3 PALIGNR m0, m4, 14, m1 pslldq m4, 2 PALIGNR m3, m4, 14, m4 mova [dstq+strideq*2], m0 mova [dstq+stride3q ], m3 RET cglobal vp9_ipred_vr_16x16_16, 4, 4, 8, dst, stride, l, a movu m1, [aq-2] ; *abcdefg movu m2, [aq+mmsize-2] ; hijklmno mova m3, [aq] ; abcdefgh mova m4, [aq+mmsize] ; ijklmnop mova m5, [lq+mmsize] ; stuvwxyz PALIGNR m0, m1, m5, 14, m6 ; z*abcdef movu m6, [aq+mmsize-4] ; ghijklmn LOWPASS 6, 2, 4 pavgw m2, m4 LOWPASS 0, 1, 3 pavgw m3, m1 PALIGNR m1, m5, 2, m7 ; tuvwxyz* movu m7, [lq+mmsize-2] ; rstuvwxy LOWPASS 1, 5, 7 movu m5, [lq+2] ; lmnopqrs pslldq m4, m5, 2 ; .lmnopqr pslldq m7, m5, 4 ; ..lmnopq LOWPASS 5, 4, 7 psrld m4, m1, 16 psrld m7, m5, 16 pand m1, [pd_65535] pand m5, [pd_65535] packssdw m7, m4 packssdw m5, m1 DEFINE_ARGS dst, stride, cnt mov cntd, 8 .loop: mova [dstq+strideq*0+ 0], m3 mova [dstq+strideq*0+16], m2 mova [dstq+strideq*1+ 0], m0 mova [dstq+strideq*1+16], m6 lea dstq, [dstq+strideq*2] PALIGNR m2, m3, 14, m4 PALIGNR m3, m7, 14, m4 pslldq m7, 2 PALIGNR m6, m0, 14, m4 PALIGNR m0, m5, 14, m4 pslldq m5, 2 dec cntd jg .loop RET cglobal vp9_ipred_vr_32x32_16, 4, 5, 14, 6 * mmsize * ARCH_X86_32, dst, stride, l, a movu m0, [aq+mmsize*0-2] ; *a[0-6] movu m1, [aq+mmsize*1-2] ; a[7-14] movu m2, [aq+mmsize*2-2] ; a[15-22] movu m3, [aq+mmsize*3-2] ; a[23-30] mova m4, [aq+mmsize*3+0] ; a[24-31] movu m5, [aq+mmsize*3-4] ; a[22-29] LOWPASS 5, 3, 4 ; A[23-30] SCRATCH 5, 8, rsp+0*mmsize pavgw m3, m4 mova m4, [aq+mmsize*2+0] ; a[16-23] movu m6, [aq+mmsize*2-4] ; a[14-21] LOWPASS 6, 2, 4 ; A[15-22] SCRATCH 6, 9, rsp+1*mmsize pavgw m2, m4 mova m4, [aq+mmsize*1+0] ; a[8-15] movu m7, [aq+mmsize*1-4] ; a[6-13] LOWPASS 7, 1, 4 ; A[7-14] SCRATCH 7, 10, rsp+2*mmsize pavgw m1, m4 mova m4, [aq+mmsize*0+0] ; a[0-7] mova m5, [lq+mmsize*3+0] ; l[24-31] PALIGNR m6, m0, m5, 14, m7 ; l[31]*a[0-5] LOWPASS 6, 0, 4 ; #A[0-6] SCRATCH 6, 11, rsp+3*mmsize pavgw m4, m0 PALIGNR m0, m5, 2, m7 ; l[25-31]* movu m7, [lq+mmsize*3-2] ; l[23-30] LOWPASS 0, 5, 7 ; L[24-31] movu m5, [lq+mmsize*2-2] ; l[15-22] mova m7, [lq+mmsize*2+0] ; l[16-23] movu m6, [lq+mmsize*2+2] ; l[17-24] LOWPASS 5, 7, 6 ; L[16-23] psrld m7, m0, 16 psrld m6, m5, 16 pand m0, [pd_65535] pand m5, [pd_65535] packssdw m6, m7 packssdw m5, m0 SCRATCH 5, 12, rsp+4*mmsize SCRATCH 6, 13, rsp+5*mmsize movu m6, [lq+mmsize*1-2] ; l[7-14] mova m0, [lq+mmsize*1+0] ; l[8-15] movu m5, [lq+mmsize*1+2] ; l[9-16] LOWPASS 6, 0, 5 ; L[8-15] movu m0, [lq+mmsize*0+2] ; l[1-8] pslldq m5, m0, 2 ; .l[1-7] pslldq m7, m0, 4 ; ..l[1-6] LOWPASS 0, 5, 7 psrld m5, m6, 16 psrld m7, m0, 16 pand m6, [pd_65535] pand m0, [pd_65535] packssdw m7, m5 packssdw m0, m6 UNSCRATCH 6, 13, rsp+5*mmsize DEFINE_ARGS dst, stride, stride16, cnt, stride17 mov stride16q, strideq mov cntd, 8 shl stride16q, 4 %if ARCH_X86_64 lea stride17q, [stride16q+strideq] %endif .loop: mova [dstq+strideq*0+ 0], m4 mova [dstq+strideq*0+16], m1 mova [dstq+strideq*0+32], m2 mova [dstq+strideq*0+48], m3 %if ARCH_X86_64 mova [dstq+strideq*1+ 0], m11 mova [dstq+strideq*1+16], m10 mova [dstq+strideq*1+32], m9 mova [dstq+strideq*1+48], m8 %endif mova [dstq+stride16q+ 0], m6 mova [dstq+stride16q+16], m4 mova [dstq+stride16q+32], m1 mova [dstq+stride16q+48], m2 %if ARCH_X86_64 mova [dstq+stride17q+ 0], m12 mova [dstq+stride17q+16], m11 mova [dstq+stride17q+32], m10 mova [dstq+stride17q+48], m9 %endif lea dstq, [dstq+strideq*2] PALIGNR m3, m2, 14, m5 PALIGNR m2, m1, 14, m5 PALIGNR m1, m4, 14, m5 PALIGNR m4, m6, 14, m5 PALIGNR m6, m7, 14, m5 pslldq m7, 2 %if ARCH_X86_64 PALIGNR m8, m9, 14, m5 PALIGNR m9, m10, 14, m5 PALIGNR m10, m11, 14, m5 PALIGNR m11, m12, 14, m5 PALIGNR m12, m0, 14, m5 pslldq m0, 2 %endif dec cntd jg .loop %if ARCH_X86_32 UNSCRATCH 5, 12, rsp+4*mmsize UNSCRATCH 4, 11, rsp+3*mmsize UNSCRATCH 3, 10, rsp+2*mmsize UNSCRATCH 2, 9, rsp+1*mmsize UNSCRATCH 1, 8, rsp+0*mmsize mov dstq, dstm mov cntd, 8 add dstq, strideq .loop2: mova [dstq+strideq*0+ 0], m4 mova [dstq+strideq*0+16], m3 mova [dstq+strideq*0+32], m2 mova [dstq+strideq*0+48], m1 mova [dstq+stride16q+ 0], m5 mova [dstq+stride16q+16], m4 mova [dstq+stride16q+32], m3 mova [dstq+stride16q+48], m2 lea dstq, [dstq+strideq*2] PALIGNR m1, m2, 14, m6 PALIGNR m2, m3, 14, m6 PALIGNR m3, m4, 14, m6 PALIGNR m4, m5, 14, m6 PALIGNR m5, m0, 14, m6 pslldq m0, 2 dec cntd jg .loop2 %endif RET %endmacro INIT_XMM sse2 VR_FUNCS INIT_XMM ssse3 VR_FUNCS INIT_XMM avx VR_FUNCS %macro HU_FUNCS 1 ; stack_mem_for_32x32_32bit_function cglobal vp9_ipred_hu_4x4_16, 3, 3, 3, dst, stride, l, a movh m0, [lq] ; abcd %if cpuflag(ssse3) pshufb m0, [pb_0to7_67x4] ; abcddddd %else punpcklqdq m0, m0 pshufhw m0, m0, q3333 ; abcddddd %endif psrldq m1, m0, 2 ; bcddddd. psrldq m2, m0, 4 ; cddddd.. LOWPASS 2, 1, 0 ; BCDddd.. pavgw m1, m0 ; abcddddd SBUTTERFLY wd, 1, 2, 0 ; aBbCcDdd, dddddddd PALIGNR m2, m1, 4, m0 ; bCcDdddd DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] movh [dstq+strideq*0], m1 ; aBbC movh [dstq+strideq*1], m2 ; bCcD movhps [dstq+strideq*2], m1 ; cDdd movhps [dstq+stride3q ], m2 ; dddd RET cglobal vp9_ipred_hu_8x8_16, 3, 3, 4, dst, stride, l, a mova m0, [lq] %if cpuflag(ssse3) mova m3, [pb_2to15_14_15] %endif SHIFT_RIGHTx2 m1, m2, m0, m3 LOWPASS 2, 1, 0 pavgw m1, m0 SBUTTERFLY wd, 1, 2, 0 shufps m0, m1, m2, q1032 pshufd m3, m2, q3332 DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] mova [dstq+strideq *0], m1 mova [dstq+strideq *2], m0 mova [dstq+strideq *4], m2 mova [dstq+stride3q*2], m3 add dstq, strideq %if cpuflag(avx) vpalignr m1, m2, m1, 4 %else PALIGNR m0, m2, m1, 4, m3 mova m1, m0 %endif pshufd m2, m2, q3321 shufps m0, m1, m2, q1032 pshufd m3, m2, q3332 mova [dstq+strideq *0], m1 mova [dstq+strideq *2], m0 mova [dstq+strideq *4], m2 mova [dstq+stride3q*2], m3 RET cglobal vp9_ipred_hu_16x16_16, 3, 4, 6 + notcpuflag(ssse3), dst, stride, l, a mova m0, [lq] mova m3, [lq+mmsize] movu m1, [lq+2] movu m2, [lq+4] LOWPASS 2, 1, 0 pavgw m1, m0 SBUTTERFLY wd, 1, 2, 0 %if cpuflag(ssse3) mova m5, [pb_2to15_14_15] %endif SHIFT_RIGHTx2 m0, m4, m3, m5 LOWPASS 4, 0, 3 pavgw m3, m0 SBUTTERFLY wd, 3, 4, 5 pshufd m0, m0, q3333 DEFINE_ARGS dst, stride, stride3, cnt lea stride3q, [strideq*3] mov cntd, 4 .loop: mova [dstq+strideq *0+ 0], m1 mova [dstq+strideq *0+16], m2 mova [dstq+strideq *4+ 0], m2 mova [dstq+strideq *4+16], m3 mova [dstq+strideq *8+ 0], m3 mova [dstq+strideq *8+16], m4 mova [dstq+stride3q*4+ 0], m4 mova [dstq+stride3q*4+16], m0 add dstq, strideq %if cpuflag(avx) vpalignr m1, m2, m1, 4 vpalignr m2, m3, m2, 4 vpalignr m3, m4, m3, 4 vpalignr m4, m0, m4, 4 %else PALIGNR m5, m2, m1, 4, m6 mova m1, m5 PALIGNR m5, m3, m2, 4, m6 mova m2, m5 PALIGNR m5, m4, m3, 4, m6 mova m3, m5 PALIGNR m5, m0, m4, 4, m6 mova m4, m5 %endif dec cntd jg .loop RET cglobal vp9_ipred_hu_32x32_16, 3, 7, 10 + notcpuflag(ssse3), \ %1 * -mmsize * ARCH_X86_32, dst, stride, l, a mova m2, [lq+mmsize*0+0] movu m1, [lq+mmsize*0+2] movu m0, [lq+mmsize*0+4] LOWPASS 0, 1, 2 pavgw m1, m2 SBUTTERFLY wd, 1, 0, 2 SCRATCH 1, 8, rsp+0*mmsize mova m4, [lq+mmsize*1+0] movu m3, [lq+mmsize*1+2] movu m2, [lq+mmsize*1+4] LOWPASS 2, 3, 4 pavgw m3, m4 SBUTTERFLY wd, 3, 2, 4 mova m6, [lq+mmsize*2+0] movu m5, [lq+mmsize*2+2] movu m4, [lq+mmsize*2+4] LOWPASS 4, 5, 6 pavgw m5, m6 SBUTTERFLY wd, 5, 4, 6 mova m7, [lq+mmsize*3+0] SCRATCH 0, 9, rsp+1*mmsize %if cpuflag(ssse3) mova m0, [pb_2to15_14_15] %endif SHIFT_RIGHTx2 m1, m6, m7, m0 LOWPASS 6, 1, 7 pavgw m7, m1 SBUTTERFLY wd, 7, 6, 0 pshufd m1, m1, q3333 UNSCRATCH 0, 9, rsp+1*mmsize DEFINE_ARGS dst, stride, cnt, stride3, stride4, stride20, stride28 lea stride3q, [strideq*3] lea stride4q, [strideq*4] lea stride28q, [stride4q*8] lea stride20q, [stride4q*5] sub stride28q, stride4q mov cntd, 4 .loop: %if ARCH_X86_64 SWAP 1, 8 %else mova [rsp+1*mmsize], m1 mova m1, [rsp+0*mmsize] %endif mova [dstq+strideq *0+ 0], m1 mova [dstq+strideq *0+16], m0 mova [dstq+strideq *0+32], m3 mova [dstq+strideq *0+48], m2 mova [dstq+stride4q*1+ 0], m0 mova [dstq+stride4q*1+16], m3 mova [dstq+stride4q*1+32], m2 mova [dstq+stride4q*1+48], m5 mova [dstq+stride4q*2+ 0], m3 mova [dstq+stride4q*2+16], m2 mova [dstq+stride4q*2+32], m5 mova [dstq+stride4q*2+48], m4 %if cpuflag(avx) vpalignr m1, m0, m1, 4 vpalignr m0, m3, m0, 4 vpalignr m3, m2, m3, 4 %else SCRATCH 6, 9, rsp+2*mmsize %if notcpuflag(ssse3) SCRATCH 7, 10, rsp+3*mmsize %endif PALIGNR m6, m0, m1, 4, m7 mova m1, m6 PALIGNR m6, m3, m0, 4, m7 mova m0, m6 PALIGNR m6, m2, m3, 4, m7 mova m3, m6 UNSCRATCH 6, 9, rsp+2*mmsize SCRATCH 0, 9, rsp+2*mmsize %if notcpuflag(ssse3) UNSCRATCH 7, 10, rsp+3*mmsize SCRATCH 3, 10, rsp+3*mmsize %endif %endif %if ARCH_X86_64 SWAP 1, 8 %else mova [rsp+0*mmsize], m1 mova m1, [rsp+1*mmsize] %endif mova [dstq+stride3q*4+ 0], m2 mova [dstq+stride3q*4+16], m5 mova [dstq+stride3q*4+32], m4 mova [dstq+stride3q*4+48], m7 mova [dstq+stride4q*4+ 0], m5 mova [dstq+stride4q*4+16], m4 mova [dstq+stride4q*4+32], m7 mova [dstq+stride4q*4+48], m6 mova [dstq+stride20q + 0], m4 mova [dstq+stride20q +16], m7 mova [dstq+stride20q +32], m6 mova [dstq+stride20q +48], m1 mova [dstq+stride3q*8+ 0], m7 mova [dstq+stride3q*8+16], m6 mova [dstq+stride3q*8+32], m1 mova [dstq+stride3q*8+48], m1 mova [dstq+stride28q + 0], m6 mova [dstq+stride28q +16], m1 mova [dstq+stride28q +32], m1 mova [dstq+stride28q +48], m1 %if cpuflag(avx) vpalignr m2, m5, m2, 4 vpalignr m5, m4, m5, 4 vpalignr m4, m7, m4, 4 vpalignr m7, m6, m7, 4 vpalignr m6, m1, m6, 4 %else PALIGNR m0, m5, m2, 4, m3 mova m2, m0 PALIGNR m0, m4, m5, 4, m3 mova m5, m0 PALIGNR m0, m7, m4, 4, m3 mova m4, m0 PALIGNR m0, m6, m7, 4, m3 mova m7, m0 PALIGNR m0, m1, m6, 4, m3 mova m6, m0 UNSCRATCH 0, 9, rsp+2*mmsize %if notcpuflag(ssse3) UNSCRATCH 3, 10, rsp+3*mmsize %endif %endif add dstq, strideq dec cntd jg .loop RET %endmacro INIT_XMM sse2 HU_FUNCS 4 INIT_XMM ssse3 HU_FUNCS 3 INIT_XMM avx HU_FUNCS 2 %macro HD_FUNCS 0 cglobal vp9_ipred_hd_4x4_16, 4, 4, 4, dst, stride, l, a movh m0, [lq] movhps m0, [aq-2] psrldq m1, m0, 2 psrldq m2, m0, 4 LOWPASS 2, 1, 0 pavgw m1, m0 punpcklwd m1, m2 DEFINE_ARGS dst, stride, stride3 lea stride3q, [strideq*3] movh [dstq+stride3q ], m1 movhps [dstq+strideq*1], m1 movhlps m2, m2 PALIGNR m2, m1, 4, m0 movh [dstq+strideq*2], m2 movhps [dstq+strideq*0], m2 RET cglobal vp9_ipred_hd_8x8_16, 4, 4, 5, dst, stride, l, a mova m0, [lq] movu m1, [aq-2] PALIGNR m2, m1, m0, 2, m3 PALIGNR m3, m1, m0, 4, m4 LOWPASS 3, 2, 0 pavgw m2, m0 SBUTTERFLY wd, 2, 3, 0 psrldq m0, m1, 2 psrldq m4, m1, 4 LOWPASS 1, 0, 4 DEFINE_ARGS dst8, mstride, cnt lea dst8q, [dst8q+mstrideq*8] neg mstrideq mov cntd, 4 .loop: add dst8q, mstrideq mova [dst8q+mstrideq*0], m2 mova [dst8q+mstrideq*4], m3 %if cpuflag(avx) vpalignr m2, m3, m2, 4 vpalignr m3, m1, m3, 4 %else PALIGNR m0, m3, m2, 4, m4 mova m2, m0 PALIGNR m0, m1, m3, 4, m4 mova m3, m0 %endif psrldq m1, 4 dec cntd jg .loop RET cglobal vp9_ipred_hd_16x16_16, 4, 4, 8, dst, stride, l, a mova m2, [lq] movu m1, [lq+2] movu m0, [lq+4] LOWPASS 0, 1, 2 pavgw m1, m2 mova m4, [lq+mmsize] movu m5, [aq-2] PALIGNR m3, m5, m4, 2, m6 PALIGNR m2, m5, m4, 4, m6 LOWPASS 2, 3, 4 pavgw m3, m4 SBUTTERFLY wd, 1, 0, 4 SBUTTERFLY wd, 3, 2, 4 mova m6, [aq] movu m4, [aq+2] LOWPASS 4, 6, 5 movu m5, [aq+mmsize-2] psrldq m6, m5, 2 psrldq m7, m5, 4 LOWPASS 5, 6, 7 DEFINE_ARGS dst, mstride, mstride3, cnt lea dstq, [dstq+mstrideq*8] lea dstq, [dstq+mstrideq*8] neg mstrideq lea mstride3q, [mstrideq*3] mov cntd, 4 .loop: add dstq, mstrideq mova [dstq+mstride3q*4+ 0], m2 mova [dstq+mstride3q*4+16], m4 mova [dstq+mstrideq *8+ 0], m3 mova [dstq+mstrideq *8+16], m2 mova [dstq+mstrideq *4+ 0], m0 mova [dstq+mstrideq *4+16], m3 mova [dstq+mstrideq *0+ 0], m1 mova [dstq+mstrideq *0+16], m0 %if cpuflag(avx) vpalignr m1, m0, m1, 4 vpalignr m0, m3, m0, 4 vpalignr m3, m2, m3, 4 vpalignr m2, m4, m2, 4 vpalignr m4, m5, m4, 4 %else PALIGNR m6, m0, m1, 4, m7 mova m1, m6 PALIGNR m6, m3, m0, 4, m7 mova m0, m6 PALIGNR m6, m2, m3, 4, m7 mova m3, m6 PALIGNR m6, m4, m2, 4, m7 mova m2, m6 PALIGNR m6, m5, m4, 4, m7 mova m4, m6 %endif psrldq m5, 4 dec cntd jg .loop RET cglobal vp9_ipred_hd_32x32_16, 4, 4 + 3 * ARCH_X86_64, 14, \ 10 * -mmsize * ARCH_X86_32, dst, stride, l, a mova m2, [lq+mmsize*0+0] movu m1, [lq+mmsize*0+2] movu m0, [lq+mmsize*0+4] LOWPASS 0, 1, 2 pavgw m1, m2 SBUTTERFLY wd, 1, 0, 2 mova m4, [lq+mmsize*1+0] movu m3, [lq+mmsize*1+2] movu m2, [lq+mmsize*1+4] LOWPASS 2, 3, 4 pavgw m3, m4 SBUTTERFLY wd, 3, 2, 4 SCRATCH 0, 8, rsp+0*mmsize SCRATCH 1, 9, rsp+1*mmsize SCRATCH 2, 10, rsp+2*mmsize SCRATCH 3, 11, rsp+3*mmsize mova m6, [lq+mmsize*2+0] movu m5, [lq+mmsize*2+2] movu m4, [lq+mmsize*2+4] LOWPASS 4, 5, 6 pavgw m5, m6 SBUTTERFLY wd, 5, 4, 6 mova m0, [lq+mmsize*3+0] movu m1, [aq+mmsize*0-2] PALIGNR m7, m1, m0, 2, m2 PALIGNR m6, m1, m0, 4, m2 LOWPASS 6, 7, 0 pavgw m7, m0 SBUTTERFLY wd, 7, 6, 0 mova m2, [aq+mmsize*0+0] movu m0, [aq+mmsize*0+2] LOWPASS 0, 2, 1 movu m1, [aq+mmsize*1-2] mova m2, [aq+mmsize*1+0] movu m3, [aq+mmsize*1+2] LOWPASS 1, 2, 3 SCRATCH 6, 12, rsp+6*mmsize SCRATCH 7, 13, rsp+7*mmsize movu m2, [aq+mmsize*2-2] mova m3, [aq+mmsize*2+0] movu m6, [aq+mmsize*2+2] LOWPASS 2, 3, 6 movu m3, [aq+mmsize*3-2] psrldq m6, m3, 2 psrldq m7, m3, 4 LOWPASS 3, 6, 7 UNSCRATCH 6, 12, rsp+6*mmsize UNSCRATCH 7, 13, rsp+7*mmsize %if ARCH_X86_32 mova [rsp+4*mmsize], m4 mova [rsp+5*mmsize], m5 ; we already backed up m6/m7 earlier on x86-32 in SCRATCH, so we don't need ; to do it again here %endif DEFINE_ARGS dst, stride, cnt, stride3, stride4, stride20, stride28 mov cntd, 4 lea stride3q, [strideq*3] %if ARCH_X86_64 lea stride4q, [strideq*4] lea stride28q, [stride4q*8] lea stride20q, [stride4q*5] sub stride28q, stride4q %endif add dstq, stride3q ; x86-32 doesn't have enough registers, so on that platform, we split ; the loop in 2... Otherwise you spend most of the loop (un)scratching .loop: %if ARCH_X86_64 mova [dstq+stride28q + 0], m9 mova [dstq+stride28q +16], m8 mova [dstq+stride28q +32], m11 mova [dstq+stride28q +48], m10 mova [dstq+stride3q*8+ 0], m8 mova [dstq+stride3q*8+16], m11 mova [dstq+stride3q*8+32], m10 mova [dstq+stride3q*8+48], m5 mova [dstq+stride20q + 0], m11 mova [dstq+stride20q +16], m10 mova [dstq+stride20q +32], m5 mova [dstq+stride20q +48], m4 mova [dstq+stride4q*4+ 0], m10 mova [dstq+stride4q*4+16], m5 mova [dstq+stride4q*4+32], m4 mova [dstq+stride4q*4+48], m7 %endif mova [dstq+stride3q*4+ 0], m5 mova [dstq+stride3q*4+16], m4 mova [dstq+stride3q*4+32], m7 mova [dstq+stride3q*4+48], m6 mova [dstq+strideq* 8+ 0], m4 mova [dstq+strideq* 8+16], m7 mova [dstq+strideq* 8+32], m6 mova [dstq+strideq* 8+48], m0 mova [dstq+strideq* 4+ 0], m7 mova [dstq+strideq* 4+16], m6 mova [dstq+strideq* 4+32], m0 mova [dstq+strideq* 4+48], m1 mova [dstq+strideq* 0+ 0], m6 mova [dstq+strideq* 0+16], m0 mova [dstq+strideq* 0+32], m1 mova [dstq+strideq* 0+48], m2 sub dstq, strideq %if cpuflag(avx) %if ARCH_X86_64 vpalignr m9, m8, m9, 4 vpalignr m8, m11, m8, 4 vpalignr m11, m10, m11, 4 vpalignr m10, m5, m10, 4 %endif vpalignr m5, m4, m5, 4 vpalignr m4, m7, m4, 4 vpalignr m7, m6, m7, 4 vpalignr m6, m0, m6, 4 vpalignr m0, m1, m0, 4 vpalignr m1, m2, m1, 4 vpalignr m2, m3, m2, 4 %else %if ARCH_X86_64 PALIGNR m12, m8, m9, 4, m13 mova m9, m12 PALIGNR m12, m11, m8, 4, m13 mova m8, m12 PALIGNR m12, m10, m11, 4, m13 mova m11, m12 PALIGNR m12, m5, m10, 4, m13 mova m10, m12 %endif SCRATCH 3, 12, rsp+8*mmsize, sh %if notcpuflag(ssse3) SCRATCH 2, 13, rsp+9*mmsize %endif PALIGNR m3, m4, m5, 4, m2 mova m5, m3 PALIGNR m3, m7, m4, 4, m2 mova m4, m3 PALIGNR m3, m6, m7, 4, m2 mova m7, m3 PALIGNR m3, m0, m6, 4, m2 mova m6, m3 PALIGNR m3, m1, m0, 4, m2 mova m0, m3 %if notcpuflag(ssse3) UNSCRATCH 2, 13, rsp+9*mmsize SCRATCH 0, 13, rsp+9*mmsize %endif PALIGNR m3, m2, m1, 4, m0 mova m1, m3 PALIGNR m3, reg_sh, m2, 4, m0 mova m2, m3 %if notcpuflag(ssse3) UNSCRATCH 0, 13, rsp+9*mmsize %endif UNSCRATCH 3, 12, rsp+8*mmsize, sh %endif psrldq m3, 4 dec cntd jg .loop %if ARCH_X86_32 UNSCRATCH 0, 8, rsp+0*mmsize UNSCRATCH 1, 9, rsp+1*mmsize UNSCRATCH 2, 10, rsp+2*mmsize UNSCRATCH 3, 11, rsp+3*mmsize mova m4, [rsp+4*mmsize] mova m5, [rsp+5*mmsize] mova m6, [rsp+6*mmsize] mova m7, [rsp+7*mmsize] DEFINE_ARGS dst, stride, stride5, stride3 lea stride5q, [strideq*5] lea dstq, [dstq+stride5q*4] DEFINE_ARGS dst, stride, cnt, stride3 mov cntd, 4 .loop_2: mova [dstq+stride3q*4+ 0], m1 mova [dstq+stride3q*4+16], m0 mova [dstq+stride3q*4+32], m3 mova [dstq+stride3q*4+48], m2 mova [dstq+strideq* 8+ 0], m0 mova [dstq+strideq* 8+16], m3 mova [dstq+strideq* 8+32], m2 mova [dstq+strideq* 8+48], m5 mova [dstq+strideq* 4+ 0], m3 mova [dstq+strideq* 4+16], m2 mova [dstq+strideq* 4+32], m5 mova [dstq+strideq* 4+48], m4 mova [dstq+strideq* 0+ 0], m2 mova [dstq+strideq* 0+16], m5 mova [dstq+strideq* 0+32], m4 mova [dstq+strideq* 0+48], m7 sub dstq, strideq %if cpuflag(avx) vpalignr m1, m0, m1, 4 vpalignr m0, m3, m0, 4 vpalignr m3, m2, m3, 4 vpalignr m2, m5, m2, 4 vpalignr m5, m4, m5, 4 vpalignr m4, m7, m4, 4 vpalignr m7, m6, m7, 4 %else SCRATCH 6, 12, rsp+8*mmsize, sh %if notcpuflag(ssse3) SCRATCH 7, 13, rsp+9*mmsize %endif PALIGNR m6, m0, m1, 4, m7 mova m1, m6 PALIGNR m6, m3, m0, 4, m7 mova m0, m6 PALIGNR m6, m2, m3, 4, m7 mova m3, m6 PALIGNR m6, m5, m2, 4, m7 mova m2, m6 PALIGNR m6, m4, m5, 4, m7 mova m5, m6 %if notcpuflag(ssse3) UNSCRATCH 7, 13, rsp+9*mmsize SCRATCH 5, 13, rsp+9*mmsize %endif PALIGNR m6, m7, m4, 4, m5 mova m4, m6 PALIGNR m6, reg_sh, m7, 4, m5 mova m7, m6 %if notcpuflag(ssse3) UNSCRATCH 5, 13, rsp+9*mmsize %endif UNSCRATCH 6, 12, rsp+8*mmsize, sh %endif psrldq m6, 4 dec cntd jg .loop_2 %endif RET %endmacro INIT_XMM sse2 HD_FUNCS INIT_XMM ssse3 HD_FUNCS INIT_XMM avx HD_FUNCS
.size 8000 .text@40 ret nop nop nop nop nop nop nop jp l1000 .text@100 jp lbegin .data@143 80 .text@150 lbegin: ld a, ff ldff(45), a ld b, 8d call lwaitly_b ld a, 40 ldff(41), a ld a, 02 ldff(ff), a ei ld a, b inc a inc a ldff(45), a ld c, 0f xor a, a ldff(0f), a ld b, 03 ld a, b ldff(ff), a .text@1000 l1000: ei .text@1069 ldff a, (c) and a, b ld(ff80), a jp lprintff80 .text@7000 lprintff80: ld b, 91 call lwaitly_b xor a, a ldff(40), a ld bc, 7a00 ld hl, 8000 ld d, a0 lprintff80_copytiles: ld a, (bc) inc bc ld(hl++), a dec d jrnz lprintff80_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 ld a, 00 ldff(69), a ldff(69), a ldff a, (80) ld(9800), a xor a, a ldff(43), a ld a, 91 ldff(40), a lprintff80_limbo: jr lprintff80_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
; A061205: a(n) = n times R(n) where R(n) (A004086) is the digit reversal of n. ; 0,1,4,9,16,25,36,49,64,81,10,121,252,403,574,765,976,1207,1458,1729,40,252,484,736,1008,1300,1612,1944,2296,2668,90,403,736,1089,1462,1855,2268,2701,3154,3627,160,574,1008,1462,1936,2430,2944,3478,4032,4606,250,765,1300,1855,2430,3025,3640,4275,4930,5605,360,976,1612,2268,2944,3640,4356,5092,5848,6624,490,1207,1944,2701,3478,4275,5092,5929,6786,7663,640,1458,2296,3154,4032,4930,5848,6786,7744,8722,810,1729,2668,3627,4606,5605,6624,7663,8722,9801,100,10201,20502,31003,41704,52605,63706,75007,86508,98209,1210,12321,23632,35143,46854,58765,70876,83187,95698,108409,2520,14641,26962,39483,52204,65125,78246,91567,105088,118809,4030,17161,30492,44023,57754,71685,85816,100147,114678,129409,5740,19881,34222,48763,63504,78445,93586,108927,124468,140209,7650,22801,38152,53703,69454,85405,101556,117907,134458,151209,9760,25921,42282,58843,75604,92565,109726,127087,144648,162409,12070,29241,46612,64183,81954,99925,118096,136467,155038,173809,14580,32761,51142,69723,88504,107485,126666,146047,165628,185409,17290,36481,55872,75463,95254,115245,135436,155827,176418,197209,400,20502,40804,61306,82008,102910,124012,145314,166816,188518,2520,23632,44944,66456,88168,110080,132192,154504,177016,199728,4840,26962,49284,71806,94528,117450,140572,163894,187416,211138,7360,30492,53824,77356,101088,125020,149152,173484,198016,222748,10080,34222,58564,83106,107848,132790,157932,183274,208816,234558 mov $1,$0 cal $1,4086 ; Read n backwards (referred to as R(n) in many sequences). mul $1,$0
; A020130: Ceiling of GAMMA(n+1/5)/GAMMA(1/5). ; Submitted by Jon Maiga ; 1,1,1,1,2,8,37,229,1648,13508,124269,1267543,14196478,173197025,2286200719,32464050200,493453563030,7993947721072,137495900802424,2502425394604114,48046567576398987,970540665043259526 mov $2,1 mov $3,$0 mul $3,5 lpb $3 sub $3,4 mov $5,$3 mul $5,2 mul $2,$5 sub $3,1 lpe mov $4,10 pow $4,$0 add $4,1 div $2,$4 mov $0,$2 add $0,1
; A170174: Number of reduced words of length n in Coxeter group on 21 generators S_i with relations (S_i)^2 = (S_i S_j)^39 = I. ; Submitted by Jamie Morken(s1) ; 1,21,420,8400,168000,3360000,67200000,1344000000,26880000000,537600000000,10752000000000,215040000000000,4300800000000000,86016000000000000,1720320000000000000,34406400000000000000 add $0,1 mov $3,1 lpb $0 sub $0,1 mul $1,20 add $1,$3 add $2,$3 div $3,$2 lpe mov $0,$1
; A183190: Triangle T(n,k), read by rows, given by (1, 1, 0, 0, 0, 0, 0, 0, 0, ...) DELTA (0, 1, 0, 0, 0, 0, 0, 0, 0, ...) where DELTA is the operator defined in A084938. ; Submitted by Christian Krause ; 1,1,0,2,1,0,4,4,1,0,8,12,6,1,0,16,32,24,8,1,0,32,80,80,40,10,1,0,64,192,240,160,60,12,1,0,128,448,672,560,280,84,14,1,0,256,1024,1792,1792,1120,448,112,16,1,0,512,2304,4608,5376,4032,2016,672,144,18,1,0 lpb $0 add $1,1 sub $0,$1 mov $2,$1 sub $2,$0 lpe sub $1,1 bin $1,$0 mov $0,2 pow $0,$2 mul $1,$0 dif $1,2 mov $0,$1
; A033380: a(n) = floor(60/n). ; 60,30,20,15,12,10,8,7,6,6,5,5,4,4,4,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 add $0,1 mov $1,60 div $1,$0 mov $0,$1
; A054623: Number of ways to color vertices of a 9-gon using <= n colors, allowing only rotations. ; 0,1,60,2195,29144,217045,1119796,4483815,14913200,43046889,111111340,261994491,573309320,1178278205,2295672484,4271485135,7635498336,13176431825,22039922460,35854190179,56888890680,88253340581,134141026580,200128076215,293534174224,423855255225,603278190476,847288613835,1175383999720,1611905113869,2187000006020,2937735802271,3909374683840,5156831608225,6746332538364,8757293195315,11284439640216,14440193321845,18357344596980,23192040141959,29127111125360,36375770503561,45185709333100 mov $1,$0 pow $0,8 add $0,6 mov $2,$1 mov $3,$1 mov $1,$0 mul $1,$2 mov $0,$1 mov $4,$3 mul $4,$3 mul $4,$3 mov $5,$4 mul $5,2 add $0,$5 div $0,9
[extern isr_handler] [extern irq_handler] [extern signal_handler] ; Common ISR code isr_common_stub: ; 1. Save CPU state pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax push ds push es push fs push gs mov ax, 0x10 ; kernel data segment descriptor mov ds, ax mov es, ax mov fs, ax mov gs, ax ; 2. Call C handler cld ; C code following the sysV ABI requires DF to be clear on function entry push esp ; interrupt_registers *r call isr_handler call signal_handler add esp, 4 ; 3. Restore state pop gs pop fs pop es pop ds popa add esp, 8 ; Cleans up the pushed error code and pushed ISR number iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP ; Common IRQ code. Identical to ISR code except for the 'call' ; and the 'pop ebx' irq_common_stub: pusha push ds push es push fs push gs mov ax, 0x10 mov ds, ax mov es, ax mov fs, ax mov gs, ax cld push esp call irq_handler ; Different than the ISR code call signal_handler add esp, 4 pop gs pop fs pop es pop ds popa add esp, 8 iret ; We don't get information about which interrupt was caller ; when the handler is run, so we will need to have a different handler ; for every interrupt. ; Furthermore, some interrupts push an error code onto the stack but others ; don't, so we will push a dummy error code for those which don't, so that ; we have a consistent stack for all of them. ; First make the ISRs global [global isr0] [global isr1] [global isr2] [global isr3] [global isr4] [global isr5] [global isr6] [global isr7] [global isr8] [global isr9] [global isr10] [global isr11] [global isr12] [global isr13] [global isr14] [global isr15] [global isr16] [global isr17] [global isr18] [global isr19] [global isr20] [global isr21] [global isr22] [global isr23] [global isr24] [global isr25] [global isr26] [global isr27] [global isr28] [global isr29] [global isr30] [global isr31] [global isr127] ; IRQs [global irq0] [global irq1] [global irq2] [global irq3] [global irq4] [global irq5] [global irq6] [global irq7] [global irq8] [global irq9] [global irq10] [global irq11] [global irq12] [global irq13] [global irq14] [global irq15] ; 0: Divide By Zero Exception isr0: push byte 0 push byte 0 jmp isr_common_stub ; 1: Debug Exception isr1: push byte 0 push byte 1 jmp isr_common_stub ; 2: Non Maskable Interrupt Exception isr2: push byte 0 push byte 2 jmp isr_common_stub ; 3: Int 3 Exception isr3: push byte 0 push byte 3 jmp isr_common_stub ; 4: INTO Exception isr4: push byte 0 push byte 4 jmp isr_common_stub ; 5: Out of Bounds Exception isr5: push byte 0 push byte 5 jmp isr_common_stub ; 6: Invalid Opcode Exception isr6: push byte 0 push byte 6 jmp isr_common_stub ; 7: Coprocessor Not Available Exception isr7: push byte 0 push byte 7 jmp isr_common_stub ; 8: Double Fault Exception (With Error Code!) isr8: push byte 8 jmp isr_common_stub ; 9: Coprocessor Segment Overrun Exception isr9: push byte 0 push byte 9 jmp isr_common_stub ; 10: Bad TSS Exception (With Error Code!) isr10: push byte 10 jmp isr_common_stub ; 11: Segment Not Present Exception (With Error Code!) isr11: push byte 11 jmp isr_common_stub ; 12: Stack Fault Exception (With Error Code!) isr12: push byte 12 jmp isr_common_stub ; 13: General Protection Fault Exception (With Error Code!) isr13: push byte 13 jmp isr_common_stub ; 14: Page Fault Exception (With Error Code!) isr14: push byte 14 jmp isr_common_stub ; 15: Reserved Exception isr15: push byte 0 push byte 15 jmp isr_common_stub ; 16: Floating Point Exception isr16: push byte 0 push byte 16 jmp isr_common_stub ; 17: Alignment Check Exception isr17: push byte 0 push byte 17 jmp isr_common_stub ; 18: Machine Check Exception isr18: push byte 0 push byte 18 jmp isr_common_stub ; 19: Reserved isr19: push byte 0 push byte 19 jmp isr_common_stub ; 20: Reserved isr20: push byte 0 push byte 20 jmp isr_common_stub ; 21: Reserved isr21: push byte 0 push byte 21 jmp isr_common_stub ; 22: Reserved isr22: push byte 0 push byte 22 jmp isr_common_stub ; 23: Reserved isr23: push byte 0 push byte 23 jmp isr_common_stub ; 24: Reserved isr24: push byte 0 push byte 24 jmp isr_common_stub ; 25: Reserved isr25: push byte 0 push byte 25 jmp isr_common_stub ; 26: Reserved isr26: push byte 0 push byte 26 jmp isr_common_stub ; 27: Reserved isr27: push byte 0 push byte 27 jmp isr_common_stub ; 28: Reserved isr28: push byte 0 push byte 28 jmp isr_common_stub ; 29: Reserved isr29: push byte 0 push byte 29 jmp isr_common_stub ; 30: Reserved isr30: push byte 0 push byte 30 jmp isr_common_stub ; 31: Reserved isr31: push byte 0 push byte 31 jmp isr_common_stub isr127: push byte 0 push 0x7F jmp isr_common_stub ; IRQ handlers irq0: push byte 0 push byte 32 jmp irq_common_stub irq1: push byte 1 push byte 33 jmp irq_common_stub irq2: push byte 2 push byte 34 jmp irq_common_stub irq3: push byte 3 push byte 35 jmp irq_common_stub irq4: push byte 4 push byte 36 jmp irq_common_stub irq5: push byte 5 push byte 37 jmp irq_common_stub irq6: push byte 6 push byte 38 jmp irq_common_stub irq7: push byte 7 push byte 39 jmp irq_common_stub irq8: push byte 8 push byte 40 jmp irq_common_stub irq9: push byte 9 push byte 41 jmp irq_common_stub irq10: push byte 10 push byte 42 jmp irq_common_stub irq11: push byte 11 push byte 43 jmp irq_common_stub irq12: push byte 12 push byte 44 jmp irq_common_stub irq13: push byte 13 push byte 45 jmp irq_common_stub irq14: push byte 14 push byte 46 jmp irq_common_stub irq15: push byte 15 push byte 47 jmp irq_common_stub
; Licensed to the .NET Foundation under one or more agreements. ; The .NET Foundation licenses this file to you under the MIT license. ; See the LICENSE file in the project root for more information. ; ==++== ; ; ; ==--== #include "ksarm.h" #include "asmconstants.h" #include "asmmacros.h" IMPORT FixContextHandler IMPORT LinkFrameAndThrow IMPORT HijackHandler IMPORT ThrowControlForThread ; ; WARNING!! These functions immediately ruin thread unwindability. This is ; WARNING!! OK as long as there is a mechanism for saving the thread context ; WARNING!! prior to running these functions as well as a mechanism for ; WARNING!! restoring the context prior to any stackwalk. This means that ; WARNING!! we need to ensure that no GC can occur while the stack is ; WARNING!! unwalkable. This further means that we cannot allow any exception ; WARNING!! to occur when the stack is unwalkable ; TEXTAREA ; GSCookie, scratch area GBLA OFFSET_OF_FRAME ; GSCookie + alignment padding OFFSET_OF_FRAME SETA 4 + SIZEOF__GSCookie MACRO GenerateRedirectedStubWithFrame $STUB, $TARGET ; ; This is the primary function to which execution will be redirected to. ; NESTED_ENTRY $STUB ; ; IN: lr: original IP before redirect ; PROLOG_PUSH {r4,r7,lr} PROLOG_STACK_ALLOC OFFSET_OF_FRAME + SIZEOF__FaultingExceptionFrame ; At this point, the stack maybe misaligned if the thread abort was asynchronously ; triggered in the prolog or epilog of the managed method. For such a case, we must ; align the stack before calling into the VM. ; ; Runtime check for 8-byte alignment. PROLOG_STACK_SAVE r7 and r0, r7, #4 sub sp, sp, r0 ; Save pointer to FEF for GetFrameFromRedirectedStubStackFrame add r4, sp, #OFFSET_OF_FRAME ; Prepare to initialize to NULL mov r1,#0 str r1, [r4] ; Initialize vtbl (it is not strictly necessary) str r1, [r4, #FaultingExceptionFrame__m_fFilterExecuted] ; Initialize BOOL for personality routine mov r0, r4 ; move the ptr to FEF in R0 ; stack must be 8 byte aligned CHECK_STACK_ALIGNMENT bl $TARGET ; Target should not return. EMIT_BREAKPOINT NESTED_END $STUB MEND ; ------------------------------------------------------------------ ; ; Helpers for async (NullRef, AccessViolation) exceptions ; NESTED_ENTRY NakedThrowHelper2,,FixContextHandler PROLOG_PUSH {r0, lr} ; On entry: ; ; R0 = Address of FaultingExceptionFrame bl LinkFrameAndThrow ; Target should not return. EMIT_BREAKPOINT NESTED_END NakedThrowHelper2 GenerateRedirectedStubWithFrame NakedThrowHelper, NakedThrowHelper2 ; ------------------------------------------------------------------ ; ; Helpers for ThreadAbort exceptions ; NESTED_ENTRY RedirectForThreadAbort2,,HijackHandler PROLOG_PUSH {r0, lr} ; stack must be 8 byte aligned CHECK_STACK_ALIGNMENT ; On entry: ; ; R0 = Address of FaultingExceptionFrame. ; ; Invoke the helper to setup the FaultingExceptionFrame and raise the exception bl ThrowControlForThread ; ThrowControlForThread doesn't return. EMIT_BREAKPOINT NESTED_END RedirectForThreadAbort2 GenerateRedirectedStubWithFrame RedirectForThreadAbort, RedirectForThreadAbort2 ; ------------------------------------------------------------------ ; This helper enables us to call into a funclet after applying the non-volatiles NESTED_ENTRY CallEHFunclet PROLOG_PUSH {r4-r11, lr} PROLOG_STACK_ALLOC 4 ; On entry: ; ; R0 = throwable ; R1 = PC to invoke ; R2 = address of R4 register in CONTEXT record; used to restore the non-volatile registers of CrawlFrame ; R3 = address of the location where the SP of funclet's caller (i.e. this helper) should be saved. ; ; Save the SP of this function str sp, [r3] ; apply the non-volatiles corresponding to the CrawlFrame ldm r2, {r4-r11} ; Invoke the funclet blx r1 EPILOG_STACK_FREE 4 EPILOG_POP {r4-r11, pc} NESTED_END CallEHFunclet ; This helper enables us to call into a filter funclet by passing it the CallerSP to lookup the ; frame pointer for accessing the locals in the parent method. NESTED_ENTRY CallEHFilterFunclet PROLOG_PUSH {lr} PROLOG_STACK_ALLOC 4 ; On entry: ; ; R0 = throwable ; R1 = SP of the caller of the method/funclet containing the filter ; R2 = PC to invoke ; R3 = address of the location where the SP of funclet's caller (i.e. this helper) should be saved. ; ; Save the SP of this function str sp, [r3] ; Invoke the filter funclet blx r2 EPILOG_STACK_FREE 4 EPILOG_POP {pc} NESTED_END CallEHFilterFunclet END
// Copyright Catch2 Authors // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) // SPDX-License-Identifier: BSL-1.0 /** \file * This is a special TU that combines what would otherwise be a very * small benchmarking-related TUs into one bigger TU. * * The reason for this is compilation performance improvements by * avoiding reparsing headers for many small TUs, instead having this * one TU include bit more, but having it all parsed only once. * * To avoid heavy-tail problem with compilation times, each "subpart" * of Catch2 has its own combined TU like this. */ //////////////////////////////////////////// // vvv formerly catch_chronometer.cpp vvv // //////////////////////////////////////////// #include <catch2/benchmark/catch_chronometer.hpp> namespace Catch { namespace Benchmark { namespace Detail { ChronometerConcept::~ChronometerConcept() = default; } // namespace Detail } // namespace Benchmark } // namespace Catch /////////////////////////////////////////////////// // vvv formerly catch_benchmark_function.cpp vvv // /////////////////////////////////////////////////// #include <catch2/benchmark/detail/catch_benchmark_function.hpp> namespace Catch { namespace Benchmark { namespace Detail { BenchmarkFunction::callable::~callable() = default; } // namespace Detail } // namespace Benchmark } // namespace Catch ///////////////////////////////////////////////// // vvv formerly catch_run_for_at_least.cpp vvv // ///////////////////////////////////////////////// #include <catch2/benchmark/detail/catch_run_for_at_least.hpp> #include <exception> #include <catch2/internal/catch_enforce.hpp> namespace Catch { namespace Benchmark { namespace Detail { struct optimized_away_error : std::exception { const char* what() const noexcept override; }; const char* optimized_away_error::what() const noexcept { return "could not measure benchmark, maybe it was optimized away"; } void throw_optimized_away_error() { Catch::throw_exception(optimized_away_error{}); } } // namespace Detail } // namespace Benchmark } // namespace Catch
; A143938: The Wiener index of a benzenoid consisting of a linear chain of n hexagons. ; 27,109,279,569,1011,1637,2479,3569,4939,6621,8647,11049,13859,17109,20831,25057,29819,35149,41079,47641,54867,62789,71439,80849,91051,102077,113959,126729,140419,155061,170687,187329,205019,223789,243671,264697,286899,310309,334959,360881,388107,416669,446599,477929,510691,544917,580639,617889,656699,697101,739127,782809,828179,875269,924111,974737,1027179,1081469,1137639,1195721,1255747,1317749,1381759,1447809,1515931,1586157,1658519,1733049,1809779,1888741,1969967,2053489,2139339,2227549 add $0,2 mul $0,4 bin $0,3 sub $0,2 div $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/llvm_ir/fused_ir_emitter.h" #include <algorithm> #include <functional> #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Value.h" #include "tensorflow/compiler/xla/service/elemental_ir_emitter.h" #include "tensorflow/compiler/xla/service/hlo_computation.h" #include "tensorflow/compiler/xla/service/hlo_instruction.h" #include "tensorflow/compiler/xla/service/hlo_opcode.h" #include "tensorflow/compiler/xla/service/llvm_ir/ir_array.h" #include "tensorflow/compiler/xla/service/llvm_ir/llvm_util.h" #include "tensorflow/compiler/xla/service/llvm_ir/tuple_ops.h" #include "tensorflow/compiler/xla/shape.h" #include "tensorflow/compiler/xla/shape_util.h" #include "tensorflow/compiler/xla/status_macros.h" #include "tensorflow/compiler/xla/statusor.h" #include "tensorflow/compiler/xla/util.h" #include "tensorflow/core/platform/logging.h" namespace xla { using llvm_ir::IrArray; Status FusedIrEmitter::DefaultAction(HloInstruction* hlo) { indexed_generators_[hlo] = [=](const IrArray::Index& index) -> StatusOr<llvm::Value*> { if (generated_value_cache_[hlo].contains(index.multidim())) { llvm::Value* generated_value = generated_value_cache_[hlo][index.multidim()]; llvm::BasicBlock* generated_value_bb = nullptr; if (auto* generated_instruction = llvm::dyn_cast<llvm::Instruction>(generated_value)) { generated_value_bb = generated_instruction->getParent(); } // Ideally, we should be able to reuse the cached generated value if it // dominates the current insertion block. However, the check for dominance // can be expensive and unreliable when the function is being constructed. // // It's also worth experimenting what if we don't do caching at all. // LLVM's CSE or GVN should be able to easily merge common subexpressions // that would be regenerated without caching. But this might increase the // JIT compilation time. if (generated_value_bb == nullptr || generated_value_bb == b_->GetInsertBlock()) { VLOG(3) << "The cached generated value is reused."; return generated_value; } VLOG(3) << "The cached generated value can't be reused, because it is in " "a different BB (" << generated_value_bb->getName().str() << ") from the current insertion block (" << b_->GetInsertBlock()->getName().str() << ")."; } TF_ASSIGN_OR_RETURN(generated_value_cache_[hlo][index.multidim()], elemental_emitter_->MakeElementGenerator( hlo, indexed_generators_)(index)); return generated_value_cache_[hlo][index.multidim()]; }; return Status::OK(); } Status FusedIrEmitter::HandleConstant(HloInstruction* constant) { unsigned global_address_space = llvm_ir::GetGlobalMemoryAddressSpace(*module_); indexed_generators_[constant] = [=](const IrArray::Index& index) { const Literal& literal = constant->literal(); llvm::Constant* initializer = llvm_ir::ConvertLiteralToIrConstant(literal, module_); llvm::GlobalVariable* global = new llvm::GlobalVariable( *b_->GetInsertBlock()->getModule(), initializer->getType(), /*isConstant=*/true, /*Linkage=*/llvm::GlobalValue::PrivateLinkage, /*Initializer=*/initializer, /*Name=*/"", /*InsertBefore=*/nullptr, /*TLMode=*/llvm::GlobalValue::NotThreadLocal, /*AddressSpace=*/global_address_space, /*isExternallyInitialized=*/false); global->setUnnamedAddr(llvm::GlobalVariable::UnnamedAddr::Global); llvm::Constant* shape_constant = llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast( global, llvm_ir::ShapeToIrType(literal.shape(), module_)->getPointerTo()); return IrArray(shape_constant, constant->shape()) .EmitReadArrayElement(index, b_); }; return Status::OK(); } Status FusedIrEmitter::HandleGetTupleElement( HloInstruction* get_tuple_element) { auto emit_tuple_element_ptr = [=]() -> StatusOr<llvm::Value*> { const HloInstruction* tuple_operand = get_tuple_element->operand(0); llvm::Value* tuple_ptr; if (tuple_operand->opcode() == HloOpcode::kGetTupleElement) { TF_ASSIGN_OR_RETURN(tuple_ptr, non_indexed_generators_[tuple_operand]()); } else { if (tuple_operand->opcode() != HloOpcode::kParameter) { return Unimplemented( "GetTupleElement fusion currently only supports parameter or " "nested" "GetTupleElement as tuple operand, found an exception: %s", tuple_operand->name()); } tuple_ptr = GetBasePointerForFusedParameter(tuple_operand->parameter_number()); } // Lookup tuple element pointer. return llvm_ir::EmitGetTupleElement(get_tuple_element->shape(), get_tuple_element->tuple_index(), /*alignment=*/1, tuple_ptr, b_); }; if (!get_tuple_element->shape().IsTuple()) { indexed_generators_[get_tuple_element] = [=](const IrArray::Index& index) -> StatusOr<llvm::Value*> { // TODO(b/34080002) Add aliasing information to tuple element IrArray. TF_ASSIGN_OR_RETURN(llvm::Value * tuple_element_ptr, emit_tuple_element_ptr()); return IrArray(tuple_element_ptr, get_tuple_element->shape()) .EmitReadArrayElement(index, b_); }; } else { non_indexed_generators_[get_tuple_element] = emit_tuple_element_ptr; } return Status::OK(); } Status FusedIrEmitter::HandleParameter(HloInstruction* parameter) { indexed_generators_[parameter] = [=](const IrArray::Index& index) -> llvm::Value* { if (tiled_parameter_info_) { if (llvm::Value* param_tile_buffer = tiled_parameter_info_->GetBufferForParameter( parameter->parameter_number())) { // TODO(jlebar): Add AA metadata to this load. Tile buffers are global // variables, so LLVM's points-to analysis doesn't help us much. And we // want the AA info to be present before address spaces are inferred // (which is pretty late in the pipeline), so even if we had // address-space-based AA in LLVM, it wouldn't help us much here. return b_->CreateLoad( b_->CreateGEP(param_tile_buffer, {index.GetConstantWithIndexType(0), tiled_parameter_info_->x(), tiled_parameter_info_->y()}), "tiled_buffer"); } } return GetIrArrayForFusedParameter(parameter->parameter_number()) .EmitReadArrayElement(index, b_); }; return Status::OK(); } Status FusedIrEmitter::HandleTuple(HloInstruction* tuple) { absl::Span<HloInstruction* const> operands(tuple->operands()); std::vector<llvm::Type*> operand_elemental_ir_types; for (HloInstruction* operand : operands) { operand_elemental_ir_types.push_back(llvm_ir::PrimitiveTypeToIrType( operand->shape().element_type(), module_)); } indexed_generators_[tuple] = [=](const IrArray::Index& index) -> StatusOr<llvm::Value*> { llvm::Value* ret = llvm::UndefValue::get( llvm::StructType::get(b_->getContext(), operand_elemental_ir_types)); for (size_t i = 0; i < ShapeUtil::TupleElementCount(tuple->shape()); ++i) { TF_ASSIGN_OR_RETURN(llvm::Value * val_i, indexed_generators_[operands[i]](index)); ret = b_->CreateInsertValue(ret, val_i, i); } return ret; }; return Status::OK(); } Status FusedIrEmitter::FinishVisit(HloInstruction* root) { fused_root_ = root; return Status::OK(); } FusedIrEmitter::IndexedGenerator FusedIrEmitter::GetRootGenerator() const { CHECK_NE(nullptr, fused_root_) << "GetRootGenerator should be called after Accept."; return indexed_generators_.at(fused_root_); } FusedIrEmitter::IndexedGenerator FusedIrEmitter::GetGenerator( const HloInstruction* instruction) const { return indexed_generators_.at(instruction); } bool FusedIrEmitter::IsFusedIrEmitterInefficient( const HloInstruction* consumer, const HloInstruction* producer) { if (consumer->opcode() != HloOpcode::kFusion) { return false; } // Collects for each instruction in the fusion node from which (indirect) // users newly created index values are passed. Roughly speaking, we reuse // index values if the shapes are equal when ignoring the element type (we may // reuse also if the shape change is a bitcast, but we don't consider that // here). By ignoring potential reuses our estimate whether the fusion emitter // is inefficient is a bit more conservative than necessary. absl::flat_hash_map<const HloInstruction*, absl::flat_hash_set<const HloInstruction*>> indexing_users; // Stores the number of different index accesses for each instruction in the // fusion node. The fusion emitter caches access with the same index, so this // value indicates how many times a specific instruction will be emitted. absl::flat_hash_map<const HloInstruction*, int64> index_usage_count; index_usage_count[consumer] = 1; auto evaluate_fusion_computation = [&indexing_users, &index_usage_count]( const HloInstruction* fusion) { auto postorder = fusion->fused_instructions_computation()->MakeInstructionPostOrder(); std::reverse(postorder.begin(), postorder.end()); for (const auto* instruction : postorder) { if (instruction->opcode() == HloOpcode::kParameter) { continue; } int64& total = index_usage_count[instruction]; if (indexing_users[instruction].empty()) { total = index_usage_count[fusion]; } else { total = 0; for (const auto* user : indexing_users[instruction]) { int64 weight = 1; // Concatenate is special: the index differs for each operand, so // in the worst case we have to deal with as many index values as // the number of operands of Concatenate. By considering the worst // case, we are more conservative than necessary regarding // refusing to fuse. if (user->opcode() == HloOpcode::kConcatenate) { weight = user->operand_count(); } total += index_usage_count[user] * weight; } } for (const auto* operand : instruction->operands()) { // For simplicity we assume that all shape and layout changing // operations invalidate index reuse. if (Shape::Equal().IgnoreElementType()(operand->shape(), instruction->shape())) { // If the index is reused, it means the operand gets index values // from the same set of (indirect) users as 'instruction' itself. indexing_users[operand].insert(indexing_users[instruction].begin(), indexing_users[instruction].end()); } else { // If the index is not reused, it means 'instruction' computes a // new index derived from the index it gets. indexing_users[operand].insert(instruction); } } } }; evaluate_fusion_computation(consumer); // Also account for the 'producer' if it would be fused. Find the operand it // corresponds to. for (int64 operand_num = 0; operand_num < consumer->operand_count(); ++operand_num) { if (consumer->operand(operand_num) == producer) { auto instruction = consumer->fused_parameter(operand_num); int64& total = index_usage_count[producer]; total = 0; for (const auto* user : indexing_users[instruction]) { total += index_usage_count[user]; } break; } } // If 'producer' is a fusion node as well, also evaluate it. if (producer->opcode() == HloOpcode::kFusion) { evaluate_fusion_computation(producer); } // Sum up the total number of emitted ops. int64 total = 0; for (const auto& entry : index_usage_count) { total += entry.second; } // Check that the code duplication has at most a factor of 15 (where 15 is an // arbitrary constant that seems to work). return total > 15 * index_usage_count.size(); } } // namespace xla
//===- TestConvertCallOp.cpp - Test LLVM Conversion of Func CallOp --------===// // // 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 "TestDialect.h" #include "TestTypes.h" #include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h" #include "mlir/Conversion/LLVMCommon/Pattern.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Pass/Pass.h" using namespace mlir; namespace { class TestTypeProducerOpConverter : public ConvertOpToLLVMPattern<test::TestTypeProducerOp> { public: using ConvertOpToLLVMPattern< test::TestTypeProducerOp>::ConvertOpToLLVMPattern; LogicalResult matchAndRewrite(test::TestTypeProducerOp op, OpAdaptor adaptor, ConversionPatternRewriter &rewriter) const override { rewriter.replaceOpWithNewOp<LLVM::NullOp>(op, getVoidPtrType()); return success(); } }; struct TestConvertCallOp : public PassWrapper<TestConvertCallOp, OperationPass<ModuleOp>> { MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestConvertCallOp) void getDependentDialects(DialectRegistry &registry) const final { registry.insert<LLVM::LLVMDialect>(); } StringRef getArgument() const final { return "test-convert-call-op"; } StringRef getDescription() const final { return "Tests conversion of `func.call` to `llvm.call` in " "presence of custom types"; } void runOnOperation() override { ModuleOp m = getOperation(); // Populate type conversions. LLVMTypeConverter typeConverter(m.getContext()); typeConverter.addConversion([&](test::TestType type) { return LLVM::LLVMPointerType::get(IntegerType::get(m.getContext(), 8)); }); typeConverter.addConversion([&](test::SimpleAType type) { return IntegerType::get(type.getContext(), 42); }); // Populate patterns. RewritePatternSet patterns(m.getContext()); populateFuncToLLVMConversionPatterns(typeConverter, patterns); patterns.add<TestTypeProducerOpConverter>(typeConverter); // Set target. ConversionTarget target(getContext()); target.addLegalDialect<LLVM::LLVMDialect>(); target.addIllegalDialect<test::TestDialect>(); target.addIllegalDialect<func::FuncDialect>(); if (failed(applyPartialConversion(m, target, std::move(patterns)))) signalPassFailure(); } }; } // namespace namespace mlir { namespace test { void registerConvertCallOpPass() { PassRegistration<TestConvertCallOp>(); } } // namespace test } // namespace mlir
.file "example.cpp" __SREG__ = 0x3f __SP_H__ = 0x3e __SP_L__ = 0x3d __CCP__ = 0x34 __tmp_reg__ = 0 __zero_reg__ = 1 .stabs "/compiler-explorer/",100,0,4,.Ltext0 .stabs "/tmp/compiler-explorer-compiler116922-97-ldr5x6/example.cpp",100,0,4,.Ltext0 .text .Ltext0: .stabs "gcc2_compiled.",60,0,0,0 .stabs "__builtin_va_list:t(0,1)=*(0,2)=(0,2)",128,0,0,0 .stabs "complex long double:t(0,3)=R3;8;0;",128,0,0,0 .stabs "complex double:t(0,4)=R3;8;0;",128,0,0,0 .stabs "complex float:t(0,5)=R3;8;0;",128,0,0,0 .stabs "complex int:t(0,6)=s4real:(0,7)=r(0,7);-32768;32767;,0,16;imag:(0,7),16,16;;",128,0,0,0 .stabs "long long unsigned int:t(0,8)=@s64;r(0,8);0;01777777777777777777777;",128,0,0,0 .stabs "long unsigned int:t(0,9)=@s32;r(0,9);0;037777777777;",128,0,0,0 .stabs "unsigned int:t(0,10)=r(0,10);0;0177777;",128,0,0,0 .stabs "unsigned char:t(0,11)=@s8;r(0,11);0;255;",128,0,0,0 .stabs "long long int:t(0,12)=@s64;r(0,12);01000000000000000000000;0777777777777777777777;",128,0,0,0 .stabs "long int:t(0,13)=@s32;r(0,13);020000000000;017777777777;",128,0,0,0 .stabs "int:t(0,7)",128,0,0,0 .stabs "signed char:t(0,14)=@s8;r(0,14);-128;127;",128,0,0,0 .stabs "char:t(0,15)=r(0,15);0;127;",128,0,0,0 .stabs "signed:t(0,7)",128,0,0,0 .stabs "unsigned long:t(0,9)",128,0,0,0 .stabs "long long unsigned:t(0,8)",128,0,0,0 .stabs "short int:t(0,16)=r(0,16);-32768;32767;",128,0,0,0 .stabs "short unsigned int:t(0,17)=r(0,17);0;0177777;",128,0,0,0 .stabs "unsigned short:t(0,17)",128,0,0,0 .stabs "float:t(0,18)=r(0,7);4;0;",128,0,0,0 .stabs "double:t(0,19)=r(0,7);4;0;",128,0,0,0 .stabs "long double:t(0,20)=r(0,7);4;0;",128,0,0,0 .stabs "void:t(0,2)",128,0,0,0 .stabs "wchar_t:t(0,21)=r(0,21);-32768;32767;",128,0,0,0 .stabs "bool:t(0,22)=@s8;-16;",128,0,0,0 .stabs "__vtbl_ptr_type:t(0,23)=*(0,24)=f(0,7)",128,0,0,0 .stabs "foo():F(0,7)",36,0,2,foo() .global foo() .type foo(), @function foo(): .stabd 46,0,0 .stabn 68,0,2,.LM0-.LFBB1 .LM0: .LFBB1: push r29 push r28 rcall . rcall . in r28,__SP_L__ in r29,__SP_H__ /* prologue: function */ /* frame size = 4 */ /* stack size = 6 */ .L__stack_usage = 6 .LBB2: .stabn 68,0,3,.LM1-.LFBB1 .LM1: std Y+2,__zero_reg__ std Y+1,__zero_reg__ .LBB3: .stabn 68,0,4,.LM2-.LFBB1 .LM2: std Y+4,__zero_reg__ std Y+3,__zero_reg__ rjmp .L2 .L4: .stabn 68,0,5,.LM3-.LFBB1 .LM3: rcall bar() ldd r18,Y+1 ldd r19,Y+2 add r24,r18 adc r25,r19 std Y+2,r25 std Y+1,r24 .stabn 68,0,4,.LM4-.LFBB1 .LM4: ldd r24,Y+3 ldd r25,Y+4 adiw r24,1 std Y+4,r25 std Y+3,r24 .L2: .stabn 68,0,4,.LM5-.LFBB1 .LM5: ldi r18,lo8(1) ldd r24,Y+3 ldd r25,Y+4 cpi r24,100 cpc r25,__zero_reg__ brlt .L3 ldi r18,lo8(0) .L3: tst r18 brne .L4 .LBE3: .stabn 68,0,7,.LM6-.LFBB1 .LM6: ldd r24,Y+1 ldd r25,Y+2 /* epilogue start */ .LBE2: .stabn 68,0,8,.LM7-.LFBB1 .LM7: pop __tmp_reg__ pop __tmp_reg__ pop __tmp_reg__ pop __tmp_reg__ pop r28 pop r29 ret .size foo(), .-foo() .stabs "a:(0,7)",128,0,3,1 .stabn 192,0,0,.LBB2-.LFBB1 .stabs "i:(0,7)",128,0,4,3 .stabn 192,0,0,.LBB3-.LFBB1 .stabn 224,0,0,.LBE3-.LFBB1 .stabn 224,0,0,.LBE2-.LFBB1 .Lscope1: .stabs "",36,0,0,.Lscope1-.LFBB1 .stabd 78,0,0 .stabs "",100,0,0,.Letext0 .Letext0:
namespace hx { unsigned char __res_4[] = { 0x80, 0x00, 0x00, 0x80, 137,80,78,71,13,10,26,10,0,0, 0,13,73,72,68,82,0,0,0,16, 0,0,0,16,8,3,0,0,0,40, 45,15,83,0,0,0,32,99,72,82, 77,0,0,122,37,0,0,128,131,0, 0,249,255,0,0,128,233,0,0,117, 48,0,0,234,96,0,0,58,152,0, 0,23,111,146,95,197,70,0,0,3, 0,80,76,84,69,0,0,0,62,62, 62,212,208,200,235,235,235,255,255,255, 5,5,5,6,6,6,7,7,7,8, 8,8,9,9,9,10,10,10,11,11, 11,12,12,12,13,13,13,14,14,14, 15,15,15,16,16,16,17,17,17,18, 18,18,19,19,19,20,20,20,21,21, 21,22,22,22,23,23,23,24,24,24, 25,25,25,26,26,26,27,27,27,28, 28,28,29,29,29,30,30,30,31,31, 31,32,32,32,33,33,33,34,34,34, 35,35,35,36,36,36,37,37,37,38, 38,38,39,39,39,40,40,40,41,41, 41,42,42,42,43,43,43,44,44,44, 45,45,45,46,46,46,47,47,47,48, 48,48,49,49,49,50,50,50,51,51, 51,52,52,52,53,53,53,54,54,54, 55,55,55,56,56,56,57,57,57,58, 58,58,59,59,59,60,60,60,61,61, 61,62,62,62,63,63,63,64,64,64, 65,65,65,66,66,66,67,67,67,68, 68,68,69,69,69,70,70,70,71,71, 71,72,72,72,73,73,73,74,74,74, 75,75,75,76,76,76,77,77,77,78, 78,78,79,79,79,80,80,80,81,81, 81,82,82,82,83,83,83,84,84,84, 85,85,85,86,86,86,87,87,87,88, 88,88,89,89,89,90,90,90,91,91, 91,92,92,92,93,93,93,94,94,94, 95,95,95,96,96,96,97,97,97,98, 98,98,99,99,99,100,100,100,101,101, 101,102,102,102,103,103,103,104,104,104, 105,105,105,106,106,106,107,107,107,108, 108,108,109,109,109,110,110,110,111,111, 111,112,112,112,113,113,113,114,114,114, 115,115,115,116,116,116,117,117,117,118, 118,118,119,119,119,120,120,120,121,121, 121,122,122,122,123,123,123,124,124,124, 125,125,125,126,126,126,127,127,127,128, 128,128,129,129,129,130,130,130,131,131, 131,132,132,132,133,133,133,134,134,134, 135,135,135,136,136,136,137,137,137,138, 138,138,139,139,139,140,140,140,141,141, 141,142,142,142,143,143,143,144,144,144, 145,145,145,146,146,146,147,147,147,148, 148,148,149,149,149,150,150,150,151,151, 151,152,152,152,153,153,153,154,154,154, 155,155,155,156,156,156,157,157,157,158, 158,158,159,159,159,160,160,160,161,161, 161,162,162,162,163,163,163,164,164,164, 165,165,165,166,166,166,167,167,167,168, 168,168,169,169,169,170,170,170,171,171, 171,172,172,172,173,173,173,174,174,174, 175,175,175,176,176,176,177,177,177,178, 178,178,179,179,179,180,180,180,181,181, 181,182,182,182,183,183,183,184,184,184, 185,185,185,186,186,186,187,187,187,188, 188,188,189,189,189,190,190,190,191,191, 191,192,192,192,193,193,193,194,194,194, 195,195,195,196,196,196,197,197,197,198, 198,198,199,199,199,200,200,200,201,201, 201,202,202,202,203,203,203,204,204,204, 205,205,205,206,206,206,207,207,207,208, 208,208,209,209,209,210,210,210,211,211, 211,212,212,212,213,213,213,214,214,214, 215,215,215,216,216,216,217,217,217,218, 218,218,219,219,219,220,220,220,221,221, 221,222,222,222,223,223,223,224,224,224, 225,225,225,226,226,226,227,227,227,228, 228,228,229,229,229,230,230,230,231,231, 231,232,232,232,233,233,233,234,234,234, 235,235,235,236,236,236,237,237,237,238, 238,238,239,239,239,240,240,240,241,241, 241,242,242,242,243,243,243,244,244,244, 245,245,245,246,246,246,247,247,247,248, 248,248,249,249,249,250,250,250,251,251, 251,252,252,252,253,253,253,254,254,254, 255,255,255,126,142,201,110,0,0,0, 31,73,68,65,84,120,218,98,96,64, 3,140,12,44,40,252,63,76,232,42, 134,147,0,6,0,0,0,0,255,255, 3,0,255,23,1,28,13,236,244,96, 0,0,0,0,73,69,78,68,174,66, 96,130,0x00 }; }
LMHeart7 label byte word C_BLACK Bitmap <71,100,BMC_PACKBITS,BMF_MONO> db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0x01, 0x0f, 0xf8, 0xfc, 0x00, 0x01, 0x1d, 0xc0 db 0x01, 0x0f, 0xf8, 0xfc, 0x00, 0x01, 0x37, 0x60 db 0x01, 0x0c, 0x18, 0xfc, 0x00, 0x01, 0x2a, 0xa0 db 0x01, 0x0c, 0x38, 0xfc, 0x00, 0x01, 0x35, 0x60 db 0x01, 0x00, 0x30, 0xfc, 0x00, 0x01, 0x1a, 0xc0 db 0x01, 0x00, 0x60, 0xfc, 0x00, 0x01, 0x0d, 0x80 db 0x01, 0x00, 0x60, 0xfc, 0x00, 0x01, 0x07, 0x00 db 0x01, 0x00, 0xc0, 0xfc, 0x00, 0x01, 0x02, 0x00 db 0x08, 0x00, 0xc0, 0x1e, 0x3c, 0x00, 0x78, 0xf0, 0x00, 0x00 db 0x08, 0x01, 0x80, 0x37, 0x76, 0x00, 0xdd, 0xd8, 0x00, 0x00 db 0x08, 0x01, 0x80, 0x6b, 0xeb, 0x01, 0xaf, 0xac, 0x00, 0x00 db 0x08, 0x01, 0x80, 0x55, 0xd5, 0x01, 0x57, 0x54, 0x00, 0x00 db 0x08, 0x01, 0x80, 0x6a, 0xab, 0x01, 0xaa, 0xac, 0x00, 0x00 db 0x08, 0x01, 0x80, 0x55, 0x55, 0x01, 0x55, 0x54, 0x00, 0x00 db 0x08, 0x01, 0x80, 0x2a, 0xaa, 0x00, 0xaa, 0xa8, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x35, 0x56, 0x00, 0xd5, 0x58, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x1a, 0xac, 0x00, 0x6a, 0xb0, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x0d, 0x58, 0x00, 0x35, 0x60, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x06, 0xb0, 0x00, 0x1a, 0xc0, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x03, 0x60, 0x00, 0x0d, 0x80, 0x00, 0x00 db 0x05, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x07, 0xfe, 0x00 db 0xfe, 0x00, 0x02, 0x80, 0x00, 0x02, 0xfe, 0x00 db 0xf8, 0x00 db 0xfe, 0x00, 0x02, 0x03, 0xc7, 0x80, 0xfe, 0x00 db 0xfe, 0x00, 0x02, 0x06, 0xee, 0xc0, 0xfe, 0x00 db 0xfe, 0x00, 0x02, 0x0d, 0x7d, 0x60, 0xfe, 0x00 db 0xfe, 0x00, 0x02, 0x0a, 0xba, 0xa0, 0xfe, 0x00 db 0xfe, 0x00, 0x02, 0x0d, 0x55, 0x60, 0xfe, 0x00 db 0xfe, 0x00, 0x02, 0x0a, 0xaa, 0xa0, 0xfe, 0x00 db 0xfe, 0x00, 0x02, 0x05, 0x55, 0x40, 0xfe, 0x00 db 0xfe, 0x00, 0x02, 0x06, 0xaa, 0xc0, 0xfe, 0x00 db 0xfe, 0x00, 0x02, 0x03, 0x55, 0x80, 0xfe, 0x00 db 0xfe, 0x00, 0x01, 0x01, 0xab, 0xfd, 0x00 db 0xfd, 0x00, 0x00, 0xd6, 0xfd, 0x00 db 0xfd, 0x00, 0x00, 0x6c, 0xfd, 0x00 db 0xfd, 0x00, 0x00, 0x38, 0xfd, 0x00 db 0xfd, 0x00, 0x00, 0x10, 0xfd, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0x08, 0x00, 0x00, 0x1e, 0x3c, 0x00, 0x78, 0xf0, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x37, 0x76, 0x00, 0xdd, 0xd8, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x6b, 0xeb, 0x01, 0xaf, 0xac, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x55, 0xd5, 0x01, 0x57, 0x54, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x6a, 0xab, 0x01, 0xaa, 0xac, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x55, 0x55, 0x01, 0x55, 0x54, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x2a, 0xaa, 0x00, 0xaa, 0xa8, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x35, 0x56, 0x00, 0xd5, 0x58, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x1a, 0xac, 0x00, 0x6a, 0xb0, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x0d, 0x58, 0x00, 0x35, 0x60, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x06, 0xb0, 0x00, 0x1a, 0xc0, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x03, 0x60, 0x00, 0x0d, 0x80, 0x00, 0x00 db 0x05, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x07, 0xfe, 0x00 db 0xfe, 0x00, 0x02, 0x80, 0x00, 0x02, 0xfe, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xfe, 0x00, 0x02, 0x80, 0x00, 0x02, 0xfe, 0x00 db 0x05, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x07, 0xfe, 0x00 db 0x08, 0x00, 0x00, 0x03, 0x60, 0x00, 0x0d, 0x80, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x06, 0xb0, 0x00, 0x1a, 0xc0, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x0d, 0x58, 0x00, 0x35, 0x60, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x1a, 0xac, 0x00, 0x6a, 0xb0, 0x00, 0x00 db 0x08, 0x00, 0x00, 0x35, 0x56, 0x00, 0xd5, 0x58, 0x03, 0x00 db 0x08, 0x00, 0x00, 0x2a, 0xaa, 0x00, 0xaa, 0xa8, 0x03, 0x00 db 0x08, 0x00, 0x00, 0x55, 0x55, 0x01, 0x55, 0x54, 0x03, 0x00 db 0x08, 0x00, 0x00, 0x6a, 0xab, 0x01, 0xaa, 0xac, 0x03, 0x00 db 0x08, 0x00, 0x00, 0x55, 0xd5, 0x01, 0x57, 0x54, 0x03, 0x00 db 0x08, 0x00, 0x00, 0x6b, 0xeb, 0x01, 0xaf, 0xac, 0x03, 0x00 db 0x08, 0x00, 0x00, 0x37, 0x76, 0x00, 0xdd, 0xd8, 0x06, 0x00 db 0x08, 0x00, 0x80, 0x1e, 0x3c, 0x00, 0x78, 0xf0, 0x06, 0x00 db 0x01, 0x01, 0xc0, 0xfc, 0x00, 0x01, 0x0c, 0x00 db 0x01, 0x03, 0x60, 0xfc, 0x00, 0x01, 0x0c, 0x00 db 0x01, 0x06, 0xb0, 0xfc, 0x00, 0x01, 0x18, 0x00 db 0x01, 0x0d, 0x58, 0xfc, 0x00, 0x01, 0x38, 0x60 db 0x01, 0x0a, 0xa8, 0xfc, 0x00, 0x01, 0x30, 0x60 db 0x01, 0x0d, 0xd8, 0xfc, 0x00, 0x01, 0x3f, 0xe0 db 0x01, 0x07, 0x70, 0xfc, 0x00, 0x01, 0x3f, 0xe0 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00 db 0xf8, 0x00
; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ; klib.asm ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ; Forrest Yu, 2005 ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %include "sconst.inc" ; 导入全局变量 extern disp_pos [SECTION .text] ; 导出函数 global disp_str global disp_color_str global out_byte global in_byte global enable_irq global disable_irq ; ======================================================================== ; void disp_str(char * info); ; ======================================================================== disp_str: push ebp mov ebp, esp mov esi, [ebp + 8] ; pszInfo mov edi, [disp_pos] mov ah, 0Fh .1: lodsb test al, al jz .2 cmp al, 0Ah ; 是回车吗? jnz .3 push eax mov eax, edi mov bl, 160 div bl and eax, 0FFh inc eax mov bl, 160 mul bl mov edi, eax pop eax jmp .1 .3: mov [gs:edi], ax add edi, 2 jmp .1 .2: mov [disp_pos], edi pop ebp ret ; ======================================================================== ; void disp_color_str(char * info, int color); ; ======================================================================== disp_color_str: push ebp mov ebp, esp mov esi, [ebp + 8] ; pszInfo mov edi, [disp_pos] mov ah, [ebp + 12] ; color .1: lodsb test al, al jz .2 cmp al, 0Ah ; 是回车吗? jnz .3 push eax mov eax, edi mov bl, 160 div bl and eax, 0FFh inc eax mov bl, 160 mul bl mov edi, eax pop eax jmp .1 .3: mov [gs:edi], ax add edi, 2 jmp .1 .2: mov [disp_pos], edi pop ebp ret ; ======================================================================== ; void out_byte(u16 port, u8 value); ; ======================================================================== out_byte: mov edx, [esp + 4] ; port mov al, [esp + 4 + 4] ; value out dx, al nop ; 一点延迟 nop ret ; ======================================================================== ; u8 in_byte(u16 port); ; ======================================================================== in_byte: mov edx, [esp + 4] ; port xor eax, eax in al, dx nop ; 一点延迟 nop ret ; ======================================================================== ; void disable_irq(int irq); ; ======================================================================== ; Disable an interrupt request line by setting an 8259 bit. ; Equivalent code: ; if(irq < 8){ ; out_byte(INT_M_CTLMASK, in_byte(INT_M_CTLMASK) | (1 << irq)); ; } ; else{ ; out_byte(INT_S_CTLMASK, in_byte(INT_S_CTLMASK) | (1 << irq)); ; } disable_irq: mov ecx, [esp + 4] ; irq pushf cli mov ah, 1 rol ah, cl ; ah = (1 << (irq % 8)) cmp cl, 8 jae disable_8 ; disable irq >= 8 at the slave 8259 disable_0: in al, INT_M_CTLMASK test al, ah jnz dis_already ; already disabled? or al, ah out INT_M_CTLMASK, al ; set bit at master 8259 popf mov eax, 1 ; disabled by this function ret disable_8: in al, INT_S_CTLMASK test al, ah jnz dis_already ; already disabled? or al, ah out INT_S_CTLMASK, al ; set bit at slave 8259 popf mov eax, 1 ; disabled by this function ret dis_already: popf xor eax, eax ; already disabled ret ; ======================================================================== ; void enable_irq(int irq); ; ======================================================================== ; Enable an interrupt request line by clearing an 8259 bit. ; Equivalent code: ; if(irq < 8){ ; out_byte(INT_M_CTLMASK, in_byte(INT_M_CTLMASK) & ~(1 << irq)); ; } ; else{ ; out_byte(INT_S_CTLMASK, in_byte(INT_S_CTLMASK) & ~(1 << irq)); ; } ; enable_irq: mov ecx, [esp + 4] ; irq pushf cli mov ah, ~1 rol ah, cl ; ah = ~(1 << (irq % 8)) cmp cl, 8 jae enable_8 ; enable irq >= 8 at the slave 8259 enable_0: in al, INT_M_CTLMASK and al, ah out INT_M_CTLMASK, al ; clear bit at master 8259 popf ret enable_8: in al, INT_S_CTLMASK and al, ah out INT_S_CTLMASK, al ; clear bit at slave 8259 popf ret
; A192305: 0-sequence of reduction of (2n) by x^2 -> x+1. ; Submitted by Jon Maiga ; 2,2,8,16,36,72,142,270,504,924,1672,2992,5306,9338,16328,28392,49132,84664,145350,248710,424312,721972,1225488,2075616,3508466,5919602,9970952,16768960,28161204,47229864,79112062,132362622,221216376,369341388,616061848,1026669712,1709502122,2844208874,4728518600,7855572120 mov $3,1 lpb $0 mov $2,$3 add $3,$1 mov $1,$0 sub $0,1 add $1,$2 lpe mov $0,$3 mul $0,2
#pragma once #include <nano/lib/locks.hpp> #include <nano/lib/rate_limiting.hpp> #include <nano/lib/stats.hpp> #include <nano/node/common.hpp> #include <nano/node/socket.hpp> namespace nano { class bandwidth_limiter final { public: // initialize with limit 0 = unbounded bandwidth_limiter (const double, const size_t); bool should_drop (const size_t &); private: nano::rate::token_bucket bucket; }; namespace transport { class message; nano::endpoint map_endpoint_to_v6 (nano::endpoint const &); nano::endpoint map_tcp_to_endpoint (nano::tcp_endpoint const &); nano::tcp_endpoint map_endpoint_to_tcp (nano::endpoint const &); // Unassigned, reserved, self bool reserved_address (nano::endpoint const &, bool = false); static std::chrono::seconds constexpr syn_cookie_cutoff = std::chrono::seconds (5); enum class transport_type : uint8_t { undefined = 0, udp = 1, tcp = 2, loopback = 3 }; class channel { public: channel (nano::node &); virtual ~channel () = default; virtual size_t hash_code () const = 0; virtual bool operator== (nano::transport::channel const &) const = 0; void send (nano::message const & message_a, std::function<void(boost::system::error_code const &, size_t)> const & callback_a = nullptr, nano::buffer_drop_policy policy_a = nano::buffer_drop_policy::limiter); virtual void send_buffer (nano::shared_const_buffer const &, std::function<void(boost::system::error_code const &, size_t)> const & = nullptr, nano::buffer_drop_policy = nano::buffer_drop_policy::limiter) = 0; virtual std::string to_string () const = 0; virtual nano::endpoint get_endpoint () const = 0; virtual nano::tcp_endpoint get_tcp_endpoint () const = 0; virtual nano::transport::transport_type get_type () const = 0; std::chrono::steady_clock::time_point get_last_bootstrap_attempt () const { nano::lock_guard<std::mutex> lk (channel_mutex); return last_bootstrap_attempt; } void set_last_bootstrap_attempt (std::chrono::steady_clock::time_point const time_a) { nano::lock_guard<std::mutex> lk (channel_mutex); last_bootstrap_attempt = time_a; } std::chrono::steady_clock::time_point get_last_packet_received () const { nano::lock_guard<std::mutex> lk (channel_mutex); return last_packet_received; } void set_last_packet_received (std::chrono::steady_clock::time_point const time_a) { nano::lock_guard<std::mutex> lk (channel_mutex); last_packet_received = time_a; } std::chrono::steady_clock::time_point get_last_packet_sent () const { nano::lock_guard<std::mutex> lk (channel_mutex); return last_packet_sent; } void set_last_packet_sent (std::chrono::steady_clock::time_point const time_a) { nano::lock_guard<std::mutex> lk (channel_mutex); last_packet_sent = time_a; } boost::optional<nano::account> get_node_id_optional () const { nano::lock_guard<std::mutex> lk (channel_mutex); return node_id; } nano::account get_node_id () const { nano::lock_guard<std::mutex> lk (channel_mutex); if (node_id.is_initialized ()) { return node_id.get (); } else { return 0; } } void set_node_id (nano::account node_id_a) { nano::lock_guard<std::mutex> lk (channel_mutex); node_id = node_id_a; } uint8_t get_network_version () const { return network_version; } void set_network_version (uint8_t network_version_a) { network_version = network_version_a; } mutable std::mutex channel_mutex; private: std::chrono::steady_clock::time_point last_bootstrap_attempt{ std::chrono::steady_clock::time_point () }; std::chrono::steady_clock::time_point last_packet_received{ std::chrono::steady_clock::now () }; std::chrono::steady_clock::time_point last_packet_sent{ std::chrono::steady_clock::now () }; boost::optional<nano::account> node_id{ boost::none }; std::atomic<uint8_t> network_version{ 0 }; protected: nano::node & node; }; class channel_loopback final : public nano::transport::channel { public: channel_loopback (nano::node &); size_t hash_code () const override; bool operator== (nano::transport::channel const &) const override; void send_buffer (nano::shared_const_buffer const &, std::function<void(boost::system::error_code const &, size_t)> const & = nullptr, nano::buffer_drop_policy = nano::buffer_drop_policy::limiter) override; std::string to_string () const override; bool operator== (nano::transport::channel_loopback const & other_a) const { return endpoint == other_a.get_endpoint (); } nano::endpoint get_endpoint () const override { return endpoint; } nano::tcp_endpoint get_tcp_endpoint () const override { return nano::transport::map_endpoint_to_tcp (endpoint); } nano::transport::transport_type get_type () const override { return nano::transport::transport_type::loopback; } private: nano::endpoint const endpoint; }; } // namespace transport } // namespace nano namespace std { template <> struct hash<::nano::transport::channel> { size_t operator() (::nano::transport::channel const & channel_a) const { return channel_a.hash_code (); } }; template <> struct equal_to<std::reference_wrapper<::nano::transport::channel const>> { bool operator() (std::reference_wrapper<::nano::transport::channel const> const & lhs, std::reference_wrapper<::nano::transport::channel const> const & rhs) const { return lhs.get () == rhs.get (); } }; } namespace boost { template <> struct hash<::nano::transport::channel> { size_t operator() (::nano::transport::channel const & channel_a) const { std::hash<::nano::transport::channel> hash; return hash (channel_a); } }; template <> struct hash<std::reference_wrapper<::nano::transport::channel const>> { size_t operator() (std::reference_wrapper<::nano::transport::channel const> const & channel_a) const { std::hash<::nano::transport::channel> hash; return hash (channel_a.get ()); } }; }
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r14 push %r15 push %r8 push %rcx push %rdi push %rsi lea addresses_WC_ht+0xc7b6, %rsi lea addresses_WT_ht+0x3bb6, %rdi nop nop nop nop nop xor $37018, %r10 mov $6, %rcx rep movsq nop and $30951, %r11 lea addresses_WT_ht+0x11736, %rsi lea addresses_WC_ht+0x1391e, %rdi nop nop nop xor $43608, %r15 mov $119, %rcx rep movsb nop cmp $47628, %rcx lea addresses_D_ht+0x1cfb6, %r15 nop nop nop nop nop sub $65318, %r8 mov (%r15), %edi nop nop nop nop nop cmp %rdi, %rdi lea addresses_UC_ht+0x276, %rsi lea addresses_WT_ht+0xb7b6, %rdi and %r14, %r14 mov $124, %rcx rep movsq nop nop and $49766, %r10 lea addresses_D_ht+0x20ac, %rdi nop nop nop nop inc %r8 mov $0x6162636465666768, %rcx movq %rcx, %xmm2 movups %xmm2, (%rdi) nop cmp %r8, %r8 lea addresses_WT_ht+0x79e8, %rcx nop nop nop nop nop add $25160, %rdi mov (%rcx), %r10w add %rcx, %rcx lea addresses_UC_ht+0x1c7b6, %rsi clflush (%rsi) nop and %rcx, %rcx movb (%rsi), %r10b nop nop nop nop nop add %r15, %r15 lea addresses_UC_ht+0x12a76, %r8 nop nop nop nop add $52245, %r14 mov $0x6162636465666768, %rsi movq %rsi, %xmm0 movups %xmm0, (%r8) nop nop nop nop sub %r8, %r8 lea addresses_WT_ht+0xcef0, %rsi lea addresses_A_ht+0x13bb6, %rdi nop nop nop nop nop add $46925, %r8 mov $108, %rcx rep movsb add %rdi, %rdi lea addresses_A_ht+0x1da76, %rsi nop nop dec %r10 movl $0x61626364, (%rsi) nop nop nop nop cmp %r8, %r8 lea addresses_normal_ht+0x5196, %rsi lea addresses_WT_ht+0x197b6, %rdi cmp %r11, %r11 mov $92, %rcx rep movsw inc %r11 lea addresses_UC_ht+0x1db48, %rsi lea addresses_D_ht+0x113b6, %rdi nop and $61960, %r11 mov $9, %rcx rep movsb nop nop nop nop nop add %rsi, %rsi pop %rsi pop %rdi pop %rcx pop %r8 pop %r15 pop %r14 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r11 push %r13 push %r14 push %r8 push %r9 push %rdx push %rsi // Store lea addresses_US+0x1ff46, %r9 clflush (%r9) nop nop nop nop add $56733, %rsi mov $0x5152535455565758, %r8 movq %r8, %xmm3 movups %xmm3, (%r9) nop nop nop nop nop sub %r14, %r14 // Store lea addresses_UC+0xbf40, %r13 clflush (%r13) nop nop nop nop nop sub $52340, %rdx mov $0x5152535455565758, %r8 movq %r8, %xmm3 movntdq %xmm3, (%r13) nop nop nop nop nop add $64873, %r11 // Store mov $0x4742900000000d26, %rsi nop nop nop dec %r14 mov $0x5152535455565758, %rdx movq %rdx, (%rsi) and %r13, %r13 // Faulty Load lea addresses_normal+0x5bb6, %r14 and $37581, %rdx mov (%r14), %r13 lea oracles, %r11 and $0xff, %r13 shlq $12, %r13 mov (%r11,%r13,1), %r13 pop %rsi pop %rdx pop %r9 pop %r8 pop %r14 pop %r13 pop %r11 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'size': 4, 'AVXalign': True, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_US', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'size': 16, 'AVXalign': False, 'NT': True, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 2, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 4, 'AVXalign': False, 'NT': True, 'congruent': 6, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 11, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 3, 'same': True}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 9, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}} {'34': 21829} 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 */
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r14 push %r15 push %rax push %rbp push %rcx push %rsi lea addresses_normal_ht+0x39cd, %r14 nop nop nop nop nop inc %r15 mov (%r14), %r12 nop nop nop nop nop xor %rcx, %rcx lea addresses_WT_ht+0x282d, %rsi and %rbp, %rbp mov (%rsi), %r12 nop nop nop nop nop sub $56273, %r14 lea addresses_A_ht+0x105b6, %rcx clflush (%rcx) nop nop and %rsi, %rsi vmovups (%rcx), %ymm2 vextracti128 $1, %ymm2, %xmm2 vpextrq $0, %xmm2, %r12 nop nop nop dec %rsi lea addresses_normal_ht+0x522d, %rcx nop nop nop nop nop cmp %rax, %rax movb (%rcx), %r15b nop nop nop nop xor %rsi, %rsi lea addresses_D_ht+0x1462d, %rsi nop nop nop nop nop xor $15587, %rcx movl $0x61626364, (%rsi) nop nop dec %rsi pop %rsi pop %rcx pop %rbp pop %rax pop %r15 pop %r14 pop %r12 ret .global s_faulty_load s_faulty_load: push %r13 push %r8 push %r9 push %rcx push %rdi // Faulty Load lea addresses_A+0x19c2d, %r13 clflush (%r13) nop nop and $65516, %r8 movb (%r13), %cl lea oracles, %rdi and $0xff, %rcx shlq $12, %rcx mov (%rdi,%rcx,1), %rcx pop %rdi pop %rcx pop %r9 pop %r8 pop %r13 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_A', 'AVXalign': False, 'size': 2, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'} [Faulty Load] {'src': {'type': 'addresses_A', 'AVXalign': False, 'size': 1, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 4}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 8}, 'OP': 'LOAD'} {'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'size': 32, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'} {'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 7}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'size': 4, 'NT': False, 'same': True, 'congruent': 9}} {'35': 21828, '00': 1} 00 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 */
;============================================ ;::MRENDER_SCOREBOARD ;============================================ macro MRENDER_SCOREBOARD LD de, MWORK.CAMERA_SCREEN CALL RENDER_LIVES CALL TRATE_HI_SCORE LD de, MWORK.CAMERA_SCREEN+24 LD HL, MWORK.PLAYER_POINTS CALL RENDER_POINTS LD de, MWORK.CAMERA_SCREEN+15 ;19 LD HL, MWORK.HI_SCORE CALL RENDER_POINTS DEC DE LD A, 218 LD [DE], A DEC DE ;SC LD A, 215 LD [DE], A DEC DE LD A, 214 LD [DE], A LD de, MWORK.CAMERA_SCREEN+32 CALL RENDER_BULLETS LD de, MWORK.CAMERA_SCREEN+29 CALL RENDER_SURVIVORS endmacro
//================================================================================================== /*! @file @copyright 2016 NumScale SAS @copyright 2016 J.T.Lapreste Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ //================================================================================================== #ifndef BOOST_SIMD_FUNCTION_DEFINITION_SIGNIFICANTS_HPP_INCLUDED #define BOOST_SIMD_FUNCTION_DEFINITION_SIGNIFICANTS_HPP_INCLUDED #include <boost/simd/config.hpp> #include <boost/dispatch/function/make_callable.hpp> #include <boost/dispatch/hierarchy/functions.hpp> #include <boost/simd/detail/dispatch.hpp> namespace boost { namespace simd { namespace tag { BOOST_DISPATCH_MAKE_TAG(ext, significants_, boost::dispatch::elementwise_<significants_>); } namespace ext { BOOST_DISPATCH_FUNCTION_DECLARATION(tag, significants_); } BOOST_DISPATCH_CALLABLE_DEFINITION(tag::significants_,significants); } } #endif
enter_key equ 0 bspace equ 0 tab equ 0 ctrl_key equ 0 lshift equ 0 rshift equ 0 prnscr equ 0 alt_key equ 0 caps equ 0 f1 equ 0 f2 equ 0 f3 equ 0 f4 equ 0 f5 equ 0 f6 equ 0 f7 equ 0 f8 equ 0 f9 equ 0 f10 equ 0 f11 equ 0 f12 equ 0 numlock equ 0 scroll equ 0 home equ 0 arrowup equ 0 pgup equ 0 num_sub equ 0 arrowleft equ 0 center5 equ 0 arrowright equ 0 num_plus equ 0 _end equ 0 arrowdown equ 0 pgdn equ 0 _ins equ 0 del equ 0 keymap: db 0 db '1234567890-=', bspace db tab,'qwertyuiop[]',enter_key db ctrl_key,'asdfghjkl;',39,'`',lshift db '\','zxcvbnm,./',rshift,prnscr,alt_key,' ' db caps,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,numlock db scroll,home,arrowup,pgup,num_sub,arrowleft,center5,arrowright db num_plus,_end,arrowdown,pgdn,_ins,del input: db 0 keyboard_isr: push eax push ebx in al,60h mov [input],al mov al,20h out 20h,al pop ebx pop eax ret ;==========================; ; al = char, ah = scancode ; ;==========================; get_char: mov ax,0xFF mov [input],al .waiting: mov al,[input] cmp al,0xFF je .waiting mov ah,0 movzx esi,ax mov al,[esi + keymap] mov ah,[input] ret
; A312892: Coordination sequence Gal.5.50.4 where G.u.t.v denotes the coordination sequence for a vertex of type v in tiling number t in the Galebach list of u-uniform tilings. ; 1,4,9,13,17,21,25,29,33,38,42,46,51,55,59,63,67,71,75,80,84,88,93,97,101,105,109,113,117,122,126,130,135,139,143,147,151,155,159,164,168,172,177,181,185,189,193,197,201,206 mov $4,$0 sub $0,1 mov $2,11 lpb $0,1 sub $0,1 add $3,1 lpb $2,1 sub $0,1 div $1,5 mul $2,$1 mov $5,$0 sub $0,3 lpe trn $0,2 mov $1,$5 sub $2,7 mov $5,1 lpe mov $1,$3 mov $6,$4 mul $6,4 add $1,$6
;; contextSwitch [System] ;; Triggers a context switch early. This will transfer control from your thread to ;; another and eventaully return to yours with interrupts enabled. contextSwitch: di push af push bc push de push hl push ix push iy exx ex af, af' push af push bc push de push hl jr doContextSwitch sysInterrupt: di push af push bc push de push hl push ix push iy exx ex af, af' push af push bc push de push hl #ifdef USB jp usbInterrupt interruptResume: #endif in a, (PORT_INT_TRIG) #ifdef CRYSTAL_TIMERS bit BIT_INT_TRIG_CRYS1, a jp nz, io_timer_expired bit BIT_INT_TRIG_CRYS2, a jp nz, intHandleCrys2 bit BIT_INT_TRIG_CRYS3, a jp nz, intHandleCrys3 #endif bit BIT_INT_TRIG_ON, a jp nz, intHandleON bit BIT_INT_TRIG_TIMER1, a jp nz, intHandleTimer1 bit BIT_INT_TRIG_TIMER2, a jp nz, intHandleTimer2 bit BIT_INT_TRIG_LINK, a jp nz, intHandleLink #ifdef LINK_ASSIST in a, (PORT_LINK_ASSIST_STATUS) and 0b00000111 ; LA_INT_* bits jp nz, la_handleInterrupt #endif #ifdef LINK_ASSIST_RO ; TODO #endif jr contextSwitch intHandleON: in a, (PORT_INT_MASK) res BIT_INT_ON, a out (PORT_INT_MASK), a set BIT_INT_ON, a out (PORT_INT_MASK), a ; Check for special keycodes jp handleKeyboard intHandleCrys2: ld c, PORT_CRYS2_FREQ jr _ intHandleCrys3: ld c, PORT_CRYS3_FREQ _: xor a out (c), a inc c ; LOOP port for interrupt ACK in a, (c) out (c), a jp sysInterruptDone intHandleTimer1: in a, (PORT_INT_MASK) res BIT_INT_TIMER1, a out (PORT_INT_MASK), a set BIT_INT_TIMER1, a out (PORT_INT_MASK), a ; Timer 1 interrupt ld hl, (kernel_current_time) inc hl ld (kernel_current_time), hl doContextSwitch: ld a, (currentThreadIndex) cp -1 jr z, contextSwitch_manual add a, a add a, a add a, a ld hl, threadTable + 3 add a, l ld l, a ex de, hl ld hl, 0 add hl, sp ex de, hl ; Save stack pointer ld (hl), e inc hl ld (hl), d contextSwitch_manual: ld a, (activeThreads) or a \ jr z, noThreads ; Error out when there are no active threads ld c, a \ inc c contextSwitch_search: dec c xor a cp c jr z, noActiveThreads ld a, (currentThreadIndex) inc a \ ld (currentThreadIndex), a ld b, a ld a, (activeThreads) dec a \ cp b jr nc, _ xor a ld b, a ld (currentThreadIndex), a _: ld a, b add a, a add a, a add a, a ld hl, threadTable + 5 add a, l ld l, a ld a, (hl) bit 1, a ; May be suspended jr nz, _ bit 2, a jr nz, contextSwitch_search ; Suspended _: dec hl ld d, (hl) dec hl ld e, (hl) ex de, hl ld sp, hl jr sysInterruptDone noThreads: jr sysInterruptDone ld a, panic_no_threads jp panic noActiveThreads: ld a, -1 ld (currentThreadIndex), a ld hl, idlethread_stack ld de, userMemory - (idlethread_stack_end - idlethread_stack) ld bc, idlethread_stack_end - idlethread_stack ldir ld sp, userMemory - (idlethread_stack_end - idlethread_stack) jr sysInterruptDone intHandleTimer2: in a, (PORT_INT_MASK) res BIT_INT_TIMER2, a out (PORT_INT_MASK), a set BIT_INT_TIMER2, a out (PORT_INT_MASK), a ; Timer 2 interrupt jr sysInterruptDone intHandleLink: in a, (PORT_INT_MASK) res BIT_INT_LINK, a out (PORT_INT_MASK), a set BIT_INT_LINK, a out (PORT_INT_MASK), a ; Link interrupt sysInterruptDone: pop hl pop de pop bc pop af exx ex af, af' pop iy pop ix pop hl pop de pop bc pop af ei ret ; Sits and spins if all other threads are suspended idlethread: jr idlethread idlethread_stack: .dw 0 .dw 0 .dw 0 .dw 0 .dw 0 .dw 0 .dw 0 .dw 0 .dw 0 .dw 0 .dw idlethread idlethread_stack_end: handleKeyboard: call getKey_skipCheck call flushKeys_skipCheck cp kK jr z, handleOnK cp kR jp z, reboot cp kMODE jr z, handleOnMODE #ifdef DEBUG cp kPRGM jr z, handleOnPRGM #endif jr sysInterruptDone handleOnMODE: ld de, init call launchProgram ld h, 1 call setInitialA jr sysInterruptDone handleOnK: ld a, (hwLockLCD) call killThread jp contextSwitch_manual #ifdef DEBUG handleOnPRGM: rst 0x30 jp sysInterruptDone #endif #ifdef USB usbInterrupt: in a, (0x55) ; USB Interrupt status bit BIT_USB_INT_BUS, a jr z, usbUnknownEvent bit BIT_USB_INT_LINE, a jr z, usbLineEvent bit BIT_USB_INT_PROTOCOL, a jr z, usbProtocolEvent jp interruptResume usbUnknownEvent: jp interruptResume usbLineEvent: in a, (PORT_USB_LINE) ; USB Line Events xor 0xFF out (PORT_USB_LINE_MASK), a ; Acknowledge interrupt and disable further interrupts jp interruptResume usbProtocolEvent: in a, (PORT_USB_WRPIPE1) in a, (PORT_USB_WRPIPE2) in a, (PORT_USB_RDPIPE1) in a, (PORT_USB_RDPIPE2) in a, (PORT_USB_MISC_EVENTS) ; Merely reading from these will acknowledge the interrupt jp interruptResume #endif
#-- INPUT N START: PRINT @S0[PROGRAM_END+0] N[MEMORY_CONTEXT+0] = READ #-- LET F = 1 F[MEMORY_CONTEXT+8] = 1 #-- FOR I=2 TO N LET F = (F*I) NEXT I I[MEMORY_CONTEXT+16] = 2 L1: @T1[MEMORY_CONTEXT+24] = (I[MEMORY_CONTEXT+16] <= N[MEMORY_CONTEXT+0]) JMP L2[PROGRAM_START+320] IF NOT @T1[MEMORY_CONTEXT+24] #-- LET F = (F*I) @T2[MEMORY_CONTEXT+32] = (F[MEMORY_CONTEXT+8] * I[MEMORY_CONTEXT+16]) F[MEMORY_CONTEXT+8] = @T2[MEMORY_CONTEXT+32] I[MEMORY_CONTEXT+16] = (I[MEMORY_CONTEXT+16] + 1) JMP L1[PROGRAM_START+128] #-- PRINT ((N+"! = ")+F) L2: @T3[MEMORY_CONTEXT+40] = (N[MEMORY_CONTEXT+0] + @S2[PROGRAM_END+5]) @T4[MEMORY_CONTEXT+48] = (@T3[MEMORY_CONTEXT+40] + F[MEMORY_CONTEXT+8]) PRINT @T4[MEMORY_CONTEXT+48] PRINT @S1[PROGRAM_END+3] #-- END EXIT
#ifndef STAN_MATH_PRIM_PROB_GAMMA_LCDF_HPP #define STAN_MATH_PRIM_PROB_GAMMA_LCDF_HPP #include <stan/math/prim/meta.hpp> #include <stan/math/prim/err.hpp> #include <stan/math/prim/fun/constants.hpp> #include <stan/math/prim/fun/digamma.hpp> #include <stan/math/prim/fun/exp.hpp> #include <stan/math/prim/fun/gamma_p.hpp> #include <stan/math/prim/fun/grad_reg_inc_gamma.hpp> #include <stan/math/prim/fun/log.hpp> #include <stan/math/prim/fun/max_size.hpp> #include <stan/math/prim/fun/size.hpp> #include <stan/math/prim/fun/size_zero.hpp> #include <stan/math/prim/fun/tgamma.hpp> #include <stan/math/prim/fun/value_of.hpp> #include <cmath> namespace stan { namespace math { template <typename T_y, typename T_shape, typename T_inv_scale> return_type_t<T_y, T_shape, T_inv_scale> gamma_lcdf(const T_y& y, const T_shape& alpha, const T_inv_scale& beta) { using T_partials_return = partials_return_t<T_y, T_shape, T_inv_scale>; using std::exp; using std::log; using std::pow; static const char* function = "gamma_lcdf"; check_positive_finite(function, "Shape parameter", alpha); check_positive_finite(function, "Inverse scale parameter", beta); check_not_nan(function, "Random variable", y); check_nonnegative(function, "Random variable", y); check_consistent_sizes(function, "Random variable", y, "Shape parameter", alpha, "Inverse scale parameter", beta); if (size_zero(y, alpha, beta)) { return 0; } T_partials_return P(0.0); operands_and_partials<T_y, T_shape, T_inv_scale> ops_partials(y, alpha, beta); scalar_seq_view<T_y> y_vec(y); scalar_seq_view<T_shape> alpha_vec(alpha); scalar_seq_view<T_inv_scale> beta_vec(beta); size_t N = max_size(y, alpha, beta); // Explicit return for extreme values // The gradients are technically ill-defined, but treated as zero for (size_t i = 0; i < stan::math::size(y); i++) { if (value_of(y_vec[i]) == 0) { return ops_partials.build(negative_infinity()); } } VectorBuilder<!is_constant_all<T_shape>::value, T_partials_return, T_shape> gamma_vec(size(alpha)); VectorBuilder<!is_constant_all<T_shape>::value, T_partials_return, T_shape> digamma_vec(size(alpha)); if (!is_constant_all<T_shape>::value) { for (size_t i = 0; i < stan::math::size(alpha); i++) { const T_partials_return alpha_dbl = value_of(alpha_vec[i]); gamma_vec[i] = tgamma(alpha_dbl); digamma_vec[i] = digamma(alpha_dbl); } } for (size_t n = 0; n < N; n++) { // Explicit results for extreme values // The gradients are technically ill-defined, but treated as zero if (value_of(y_vec[n]) == INFTY) { return ops_partials.build(0.0); } const T_partials_return y_dbl = value_of(y_vec[n]); const T_partials_return alpha_dbl = value_of(alpha_vec[n]); const T_partials_return beta_dbl = value_of(beta_vec[n]); const T_partials_return Pn = gamma_p(alpha_dbl, beta_dbl * y_dbl); P += log(Pn); if (!is_constant_all<T_y>::value) { ops_partials.edge1_.partials_[n] += beta_dbl * exp(-beta_dbl * y_dbl) * pow(beta_dbl * y_dbl, alpha_dbl - 1) / tgamma(alpha_dbl) / Pn; } if (!is_constant_all<T_shape>::value) { ops_partials.edge2_.partials_[n] -= grad_reg_inc_gamma(alpha_dbl, beta_dbl * y_dbl, gamma_vec[n], digamma_vec[n]) / Pn; } if (!is_constant_all<T_inv_scale>::value) { ops_partials.edge3_.partials_[n] += y_dbl * exp(-beta_dbl * y_dbl) * pow(beta_dbl * y_dbl, alpha_dbl - 1) / tgamma(alpha_dbl) / Pn; } } return ops_partials.build(P); } } // namespace math } // namespace stan #endif
ViridianGymScript: ld hl, Gym8CityName ld de, Gym8LeaderName call LoadGymLeaderAndCityName call EnableAutoTextBoxDrawing ld hl, ViridianGymTrainerHeaders ld de, ViridianGymScriptPointers ld a, [wViridianGymCurScript] call ExecuteCurMapScriptInTable ld [wViridianGymCurScript], a ret Gym8CityName: db "VIRIDIAN CITY@" Gym8LeaderName: db "GIOVANNI@" ViridianGymScript_748d6: xor a ld [wJoyIgnore], a ld [wViridianGymCurScript], a ld [wCurMapScript], a ret ViridianGymScriptPointers: dw ViridianGymScript0 dw DisplayEnemyTrainerTextAndStartBattle dw EndTrainerBattle dw ViridianGymScript3 dw ViridianGymScript4 ViridianGymScript0: ld a, [wYCoord] ld b, a ld a, [wXCoord] ld c, a ld hl, ViridianGymArrowTilePlayerMovement call DecodeArrowMovementRLE cp $ff jp z, CheckFightingMapTrainers call StartSimulatingJoypadStates ld hl, wd736 set 7, [hl] ld a, SFX_ARROW_TILES call PlaySound ld a, $ff ld [wJoyIgnore], a ld a, $4 ld [wCurMapScript], a ret ;format: ;db y,x ;dw pointer to movement ViridianGymArrowTilePlayerMovement: db $b,$13 dw ViridianGymArrowMovement1 db $1,$13 dw ViridianGymArrowMovement2 db $2,$12 dw ViridianGymArrowMovement3 db $2,$b dw ViridianGymArrowMovement4 db $a,$10 dw ViridianGymArrowMovement5 db $6,$4 dw ViridianGymArrowMovement6 db $d,$5 dw ViridianGymArrowMovement7 db $e,$4 dw ViridianGymArrowMovement8 db $f,$0 dw ViridianGymArrowMovement9 db $f,$1 dw ViridianGymArrowMovement10 db $10,$d dw ViridianGymArrowMovement11 db $11,$d dw ViridianGymArrowMovement12 db $FF ;format: direction, count ViridianGymArrowMovement1: db D_UP,$09,$FF ViridianGymArrowMovement2: db D_LEFT,$08,$FF ViridianGymArrowMovement3: db D_DOWN,$09,$FF ViridianGymArrowMovement4: db D_RIGHT,$06,$FF ViridianGymArrowMovement5: db D_DOWN,$02,$FF ViridianGymArrowMovement6: db D_DOWN,$07,$FF ViridianGymArrowMovement7: db D_RIGHT,$08,$FF ViridianGymArrowMovement8: db D_RIGHT,$09,$FF ViridianGymArrowMovement9: db D_UP,$08,$FF ViridianGymArrowMovement10: db D_UP,$06,$FF ViridianGymArrowMovement11: db D_LEFT,$06,$FF ViridianGymArrowMovement12: db D_LEFT,$0C,$FF ViridianGymScript4: ld a, [wSimulatedJoypadStatesIndex] and a jr nz, .asm_74980 xor a ld [wJoyIgnore], a ld hl, wd736 res 7, [hl] ld a, $0 ld [wCurMapScript], a ret .asm_74980 jpba LoadSpinnerArrowTiles ViridianGymScript3: ld a, [wIsInBattle] cp $ff jp z, ViridianGymScript_748d6 ld a, $f0 ld [wJoyIgnore], a ViridianGymScript3_74995: ld a, $c ld [hSpriteIndexOrTextID], a call DisplayTextID SetEvent EVENT_BEAT_VIRIDIAN_GYM_GIOVANNI lb bc, TM_27, 1 call GiveItem jr nc, .BagFull ld a, $d ld [hSpriteIndexOrTextID], a call DisplayTextID SetEvent EVENT_GOT_TM27 jr .asm_749be .BagFull ld a, $e ld [hSpriteIndexOrTextID], a call DisplayTextID .asm_749be ld hl, wObtainedBadges set 7, [hl] ld hl, wBeatGymFlags set 7, [hl] ; deactivate gym trainers SetEventRange EVENT_BEAT_VIRIDIAN_GYM_TRAINER_0, EVENT_BEAT_VIRIDIAN_GYM_TRAINER_7 ld a, HS_ROUTE_22_RIVAL_2 ld [wMissableObjectIndex], a predef ShowObject SetEvents EVENT_2ND_ROUTE22_RIVAL_BATTLE, EVENT_ROUTE22_RIVAL_WANTS_BATTLE jp ViridianGymScript_748d6 ViridianGymTextPointers: dw ViridianGymText1 dw ViridianGymText2 dw ViridianGymText3 dw ViridianGymText4 dw ViridianGymText5 dw ViridianGymText6 dw ViridianGymText7 dw ViridianGymText8 dw ViridianGymText9 dw ViridianGymText10 dw PickUpItemText dw ViridianGymText12 dw ViridianGymText13 dw ViridianGymText14 ViridianGymTrainerHeaders: ViridianGymTrainerHeader0: dbEventFlagBit EVENT_BEAT_VIRIDIAN_GYM_TRAINER_0 db ($4 << 4) ; trainer's view range dwEventFlagAddress EVENT_BEAT_VIRIDIAN_GYM_TRAINER_0 dw ViridianGymBattleText1 ; TextBeforeBattle dw ViridianGymAfterBattleText1 ; TextAfterBattle dw ViridianGymEndBattleText1 ; TextEndBattle dw ViridianGymEndBattleText1 ; TextEndBattle ViridianGymTrainerHeader1: dbEventFlagBit EVENT_BEAT_VIRIDIAN_GYM_TRAINER_1 db ($4 << 4) ; trainer's view range dwEventFlagAddress EVENT_BEAT_VIRIDIAN_GYM_TRAINER_1 dw ViridianGymBattleText2 ; TextBeforeBattle dw ViridianGymAfterBattleText2 ; TextAfterBattle dw ViridianGymEndBattleText2 ; TextEndBattle dw ViridianGymEndBattleText2 ; TextEndBattle ViridianGymTrainerHeader2: dbEventFlagBit EVENT_BEAT_VIRIDIAN_GYM_TRAINER_2 db ($4 << 4) ; trainer's view range dwEventFlagAddress EVENT_BEAT_VIRIDIAN_GYM_TRAINER_2 dw ViridianGymBattleText3 ; TextBeforeBattle dw ViridianGymAfterBattleText3 ; TextAfterBattle dw ViridianGymEndBattleText3 ; TextEndBattle dw ViridianGymEndBattleText3 ; TextEndBattle ViridianGymTrainerHeader3: dbEventFlagBit EVENT_BEAT_VIRIDIAN_GYM_TRAINER_3 db ($2 << 4) ; trainer's view range dwEventFlagAddress EVENT_BEAT_VIRIDIAN_GYM_TRAINER_3 dw ViridianGymBattleText4 ; TextBeforeBattle dw ViridianGymAfterBattleText4 ; TextAfterBattle dw ViridianGymEndBattleText4 ; TextEndBattle dw ViridianGymEndBattleText4 ; TextEndBattle ViridianGymTrainerHeader4: dbEventFlagBit EVENT_BEAT_VIRIDIAN_GYM_TRAINER_4 db ($3 << 4) ; trainer's view range dwEventFlagAddress EVENT_BEAT_VIRIDIAN_GYM_TRAINER_4 dw ViridianGymBattleText5 ; TextBeforeBattle dw ViridianGymAfterBattleText5 ; TextAfterBattle dw ViridianGymEndBattleText5 ; TextEndBattle dw ViridianGymEndBattleText5 ; TextEndBattle ViridianGymTrainerHeader5: dbEventFlagBit EVENT_BEAT_VIRIDIAN_GYM_TRAINER_5 db ($4 << 4) ; trainer's view range dwEventFlagAddress EVENT_BEAT_VIRIDIAN_GYM_TRAINER_5 dw ViridianGymBattleText6 ; TextBeforeBattle dw ViridianGymAfterBattleText6 ; TextAfterBattle dw ViridianGymEndBattleText6 ; TextEndBattle dw ViridianGymEndBattleText6 ; TextEndBattle ViridianGymTrainerHeader6: dbEventFlagBit EVENT_BEAT_VIRIDIAN_GYM_TRAINER_6, 1 db ($3 << 4) ; trainer's view range dwEventFlagAddress EVENT_BEAT_VIRIDIAN_GYM_TRAINER_6, 1 dw ViridianGymBattleText7 ; TextBeforeBattle dw ViridianGymAfterBattleText7 ; TextAfterBattle dw ViridianGymEndBattleText7 ; TextEndBattle dw ViridianGymEndBattleText7 ; TextEndBattle ViridianGymTrainerHeader7: dbEventFlagBit EVENT_BEAT_VIRIDIAN_GYM_TRAINER_7, 1 db ($4 << 4) ; trainer's view range dwEventFlagAddress EVENT_BEAT_VIRIDIAN_GYM_TRAINER_7, 1 dw ViridianGymBattleText8 ; TextBeforeBattle dw ViridianGymAfterBattleText8 ; TextAfterBattle dw ViridianGymEndBattleText8 ; TextEndBattle dw ViridianGymEndBattleText8 ; TextEndBattle db $ff ViridianGymText1: TX_ASM CheckEvent EVENT_BEAT_VIRIDIAN_GYM_GIOVANNI jr z, .asm_6de66 CheckEventReuseA EVENT_GOT_TM27 jr nz, .asm_9fc95 call z, ViridianGymScript3_74995 call DisableWaitingAfterTextDisplay jr .asm_6dff7 .asm_9fc95 ld a, $1 ld [wDoNotWaitForButtonPressAfterDisplayingText], a ld hl, ViridianGymText_74ad9 call PrintText call GBFadeOutToBlack ld a, HS_VIRIDIAN_GYM_GIOVANNI ld [wMissableObjectIndex], a predef HideObject call UpdateSprites call Delay3 call GBFadeInFromBlack jr .asm_6dff7 .asm_6de66 ld hl, ViridianGymText_74ace call PrintText ld hl, wd72d set 6, [hl] set 7, [hl] ld hl, ViridianGymText_74ad3 ld de, ViridianGymText_74ad3 call SaveEndBattleTextPointers ld a, [H_SPRITEINDEX] ld [wSpriteIndex], a call EngageMapTrainer call InitBattleEnemyParameters ld a, $8 ld [wGymLeaderNo], a ld a, $3 ld [wViridianGymCurScript], a .asm_6dff7 jp TextScriptEnd ViridianGymText_74ace: TX_FAR _ViridianGymText_74ace db "@" ViridianGymText_74ad3: TX_FAR _ViridianGymText_74ad3 db $0b, "@" ViridianGymText_74ad9: TX_FAR _ViridianGymText_74ad9 db $0d, "@" ViridianGymText12: TX_FAR _ViridianGymText12 db "@" ViridianGymText13: TX_FAR _ReceivedTM27Text db $0b TM27ExplanationText: TX_FAR _TM27ExplanationText db "@" ViridianGymText14: TX_FAR _TM27NoRoomText db "@" ViridianGymText2: TX_ASM ld hl, ViridianGymTrainerHeader0 call TalkToTrainer jp TextScriptEnd ViridianGymBattleText1: TX_FAR _ViridianGymBattleText1 db "@" ViridianGymEndBattleText1: TX_FAR _ViridianGymEndBattleText1 db "@" ViridianGymAfterBattleText1: TX_FAR _ViridianGymAfterBattleText1 db "@" ViridianGymText3: TX_ASM ld hl, ViridianGymTrainerHeader1 call TalkToTrainer jp TextScriptEnd ViridianGymBattleText2: TX_FAR _ViridianGymBattleText2 db "@" ViridianGymEndBattleText2: TX_FAR _ViridianGymEndBattleText2 db "@" ViridianGymAfterBattleText2: TX_FAR _ViridianGymAfterBattleText2 db "@" ViridianGymText4: TX_ASM ld hl, ViridianGymTrainerHeader2 call TalkToTrainer jp TextScriptEnd ViridianGymBattleText3: TX_FAR _ViridianGymBattleText3 db "@" ViridianGymEndBattleText3: TX_FAR _ViridianGymEndBattleText3 db "@" ViridianGymAfterBattleText3: TX_FAR _ViridianGymAfterBattleText3 db "@" ViridianGymText5: TX_ASM ld hl, ViridianGymTrainerHeader3 call TalkToTrainer jp TextScriptEnd ViridianGymBattleText4: TX_FAR _ViridianGymBattleText4 db "@" ViridianGymEndBattleText4: TX_FAR _ViridianGymEndBattleText4 db "@" ViridianGymAfterBattleText4: TX_FAR _ViridianGymAfterBattleText4 db "@" ViridianGymText6: TX_ASM ld hl, ViridianGymTrainerHeader4 call TalkToTrainer jp TextScriptEnd ViridianGymBattleText5: TX_FAR _ViridianGymBattleText5 db "@" ViridianGymEndBattleText5: TX_FAR _ViridianGymEndBattleText5 db "@" ViridianGymAfterBattleText5: TX_FAR _ViridianGymAfterBattleText5 db "@" ViridianGymText7: TX_ASM ld hl, ViridianGymTrainerHeader5 call TalkToTrainer jp TextScriptEnd ViridianGymBattleText6: TX_FAR _ViridianGymBattleText6 db "@" ViridianGymEndBattleText6: TX_FAR _ViridianGymEndBattleText6 db "@" ViridianGymAfterBattleText6: TX_FAR _ViridianGymAfterBattleText6 db "@" ViridianGymText8: TX_ASM ld hl, ViridianGymTrainerHeader6 call TalkToTrainer jp TextScriptEnd ViridianGymBattleText7: TX_FAR _ViridianGymBattleText7 db "@" ViridianGymEndBattleText7: TX_FAR _ViridianGymEndBattleText7 db "@" ViridianGymAfterBattleText7: TX_FAR _ViridianGymAfterBattleText7 db "@" ViridianGymText9: TX_ASM ld hl, ViridianGymTrainerHeader7 call TalkToTrainer jp TextScriptEnd ViridianGymBattleText8: TX_FAR _ViridianGymBattleText8 db "@" ViridianGymEndBattleText8: TX_FAR _ViridianGymEndBattleText8 db "@" ViridianGymAfterBattleText8: TX_FAR _ViridianGymAfterBattleText8 db "@" ViridianGymText10: TX_ASM CheckEvent EVENT_BEAT_VIRIDIAN_GYM_GIOVANNI jr nz, .asm_1abd1 ld hl, ViridianGymText_74bd4 call PrintText jr .asm_6064d .asm_1abd1 ResetEvent EVENT_BEAT_VIRIDIAN_GYM_GIOVANNI ResetEventRange EVENT_BEAT_VIRIDIAN_GYM_TRAINER_0, EVENT_BEAT_VIRIDIAN_GYM_TRAINER_7 call GBFadeOutToBlack ld a, HS_VIRIDIAN_GYM_GIOVANNI ld [wMissableObjectIndex], a predef ShowObject call UpdateSprites call Delay3 call GBFadeInFromBlack ld hl, ViridianGymText_74bd9 call PrintText .asm_6064d jp TextScriptEnd ViridianGymText_74bd4: TX_FAR _ViridianGymText_74bd4 db "@" ViridianGymText_74bd9: TX_FAR _ViridianGymText_74bd9 db "@"
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r14 push %r15 push %r9 push %rbp push %rcx push %rdi push %rsi lea addresses_UC_ht+0xa08b, %rsi lea addresses_WC_ht+0x1bb8b, %rdi clflush (%rdi) nop nop nop nop nop and $60932, %r14 mov $28, %rcx rep movsb and $57821, %rbp lea addresses_UC_ht+0x14287, %r15 nop inc %r14 vmovups (%r15), %ymm2 vextracti128 $1, %ymm2, %xmm2 vpextrq $1, %xmm2, %rbp nop add %rcx, %rcx lea addresses_WC_ht+0x608b, %rdi nop nop nop add %r9, %r9 mov (%rdi), %cx nop nop nop nop nop add %rcx, %rcx lea addresses_UC_ht+0x1538b, %rdi nop nop add %rcx, %rcx mov $0x6162636465666768, %rbp movq %rbp, %xmm6 vmovups %ymm6, (%rdi) dec %rbp lea addresses_UC_ht+0x16a8b, %r15 clflush (%r15) nop nop nop nop nop sub $49793, %rdi movl $0x61626364, (%r15) sub $45041, %r9 lea addresses_D_ht+0x52cb, %rcx clflush (%rcx) nop nop xor %rsi, %rsi movups (%rcx), %xmm6 vpextrq $1, %xmm6, %r15 add $11204, %r15 lea addresses_WC_ht+0x1400b, %r15 nop nop nop nop nop sub $13439, %rdi mov $0x6162636465666768, %r14 movq %r14, %xmm6 vmovups %ymm6, (%r15) nop nop nop nop and %rsi, %rsi lea addresses_A_ht+0x18f0b, %rsi lea addresses_D_ht+0x1ddf1, %rdi nop nop xor $10944, %r10 mov $90, %rcx rep movsw xor $57191, %rsi pop %rsi pop %rdi pop %rcx pop %rbp pop %r9 pop %r15 pop %r14 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r14 push %r15 push %r8 push %rax push %rbp // Store lea addresses_D+0xcccb, %rax nop nop nop nop nop cmp $19626, %r15 mov $0x5152535455565758, %rbp movq %rbp, %xmm0 vmovaps %ymm0, (%rax) add %r14, %r14 // Faulty Load lea addresses_WT+0x19f8b, %r15 and %r11, %r11 movups (%r15), %xmm6 vpextrq $1, %xmm6, %r10 lea oracles, %rax and $0xff, %r10 shlq $12, %r10 mov (%rax,%r10,1), %r10 pop %rbp pop %rax pop %r8 pop %r15 pop %r14 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_WT', 'size': 16, 'AVXalign': False}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 6, 'NT': True, 'type': 'addresses_D', 'size': 32, 'AVXalign': True}} [Faulty Load] {'src': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_WT', 'size': 16, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_UC_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WC_ht', 'congruent': 7, 'same': False}} {'src': {'same': False, 'congruent': 2, 'NT': False, 'type': 'addresses_UC_ht', 'size': 32, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'same': False, 'congruent': 5, 'NT': False, 'type': 'addresses_WC_ht', 'size': 2, 'AVXalign': False}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_UC_ht', 'size': 32, 'AVXalign': False}} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 5, 'NT': False, 'type': 'addresses_UC_ht', 'size': 4, 'AVXalign': False}} {'src': {'same': False, 'congruent': 5, 'NT': False, 'type': 'addresses_D_ht', 'size': 16, 'AVXalign': False}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 5, 'NT': False, 'type': 'addresses_WC_ht', 'size': 32, 'AVXalign': False}} {'src': {'type': 'addresses_A_ht', 'congruent': 5, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_D_ht', 'congruent': 1, 'same': False}} {'39': 1299} 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 */
; A139289: (2^(2p - 1)/2)-1, where p is prime. ; Submitted by Jamie Morken(r1) ; 3,15,255,4095,1048575,16777215,4294967295,68719476735,17592186044415,72057594037927935,1152921504606846975,4722366482869645213695,1208925819614629174706175,19342813113834066795298815,4951760157141521099596496895,20282409603651670423947251286015,83076749736557242056487941267521535,1329227995784915872903807060280344575,5444517870735015415413993718908291383295,1393796574908163946345982392040522594123775,22300745198530623141535718272648361505980415,91343852333181432387730302044767688728495783935 seq $0,6005 ; The odd prime numbers together with 1. trn $0,2 mov $2,4 pow $2,$0 mov $0,$2 sub $0,1 mul $0,4 add $0,3
#pragma once #include <bts/bitname/bitname_block.hpp> namespace bts { namespace bitname { /** * Defines the call back methods when a name is found. */ class name_miner_delegate { public: virtual ~name_miner_delegate(){} /** * Called with a block that satisifies the current block * target difficulty. */ virtual void found_name_block( const name_block& t ){}; /** * Called when a nonce good enough for broadcasting a * trx is found. Mining will continue in an attempt to * solve the block until the miner is told otherwise. */ virtual void found_name_trx( const name_trx& t ){}; }; namespace detail { class name_miner_impl; } /** * @brief Searches for a nonce that will satisify the target difficulty. * * The name miner should be given a target difficulty and a level of effort * and will search the nonce space until the difficulty is met. Part of * mining your name is also merged-mining for the entire block and so including * other names in the process can earn you additional reputation points. */ class name_miner { public: name_miner(); ~name_miner(); void set_delegate( name_miner_delegate* d ); /** Sets the hash value required for finding a block. The * difficulty of finding a name is 1/5000 * the block difficulty * with a minimum difficulty of about 1 hour per CPU. */ void set_block_target( uint64_t difficulty ); /** * Clears all name_trx that have been added thus far. */ void set_name_header( const name_header& header_to_mine ); /** * If another transaction with the same name is already * in the queue, the lowest hash will win. * * @note miner does not perform any validation aside from checking * for duplicates in the same block. Validation should be * performed prior to this call. */ void add_name_trx( const name_header& ); void start( float effort = 1 ); void stop(); private: std::unique_ptr<detail::name_miner_impl> my; }; } } // namespace bts
;; Copyright (C) 2020, Vi Grey ;; All rights reserved. ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions ;; are met: ;; ;; 1. Redistributions of source code must retain the above copyright ;; notice, this list of conditions and the following disclaimer. ;; 2. Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; ;; THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;; ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ;; SUCH DAMAGE. PPU_CTRL = $2000 PPU_MASK = $2001 PPU_STATUS = $2002 PPU_OAM_ADDR = $2003 PPU_OAM_DATA = $2004 PPU_SCROLL = $2005 PPU_ADDR = $2006 PPU_DATA = $2007 CALLBACK = $FFFA STACK = $0100
<% from pwnlib.shellcraft.arm.linux import syscall %> <%page args="request, vararg"/> <%docstring> Invokes the syscall ptrace. See 'man 2 ptrace' for more information. Arguments: request(ptrace_request): request vararg(int): vararg </%docstring> ${syscall('SYS_ptrace', request, vararg)}
/* * Copyright (C) 2012 The Android Open Source Project * * 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 <errno.h> #include <signal.h> #include <sys/syscall.h> #include <sys/types.h> #include <unistd.h> #include <chrono> #include <thread> #include <android-base/macros.h> #include <android-base/threads.h> #include <gtest/gtest.h> #include "SignalUtils.h" #include "utils.h" using namespace std::chrono_literals; static int SIGNAL_MIN() { return 1; // Signals start at 1 (SIGHUP), not 0. } template <typename SigSetT> static int SIGNAL_MAX(SigSetT* set) { return sizeof(*set) * 8; } template <typename SigSetT> static void TestSigSet1(int (fn)(SigSetT*)) { // nullptr sigset_t*/sigset64_t*. SigSetT* set_ptr = nullptr; errno = 0; ASSERT_EQ(-1, fn(set_ptr)); ASSERT_EQ(EINVAL, errno); // Non-nullptr. SigSetT set = {}; errno = 0; ASSERT_EQ(0, fn(&set)); ASSERT_EQ(0, errno); } template <typename SigSetT> static void TestSigSet2(int (fn)(SigSetT*, int)) { // nullptr sigset_t*/sigset64_t*. SigSetT* set_ptr = nullptr; errno = 0; ASSERT_EQ(-1, fn(set_ptr, SIGSEGV)); ASSERT_EQ(EINVAL, errno); SigSetT set = {}; // Bad signal number: too small. errno = 0; ASSERT_EQ(-1, fn(&set, 0)); ASSERT_EQ(EINVAL, errno); // Bad signal number: too high. errno = 0; ASSERT_EQ(-1, fn(&set, SIGNAL_MAX(&set) + 1)); ASSERT_EQ(EINVAL, errno); // Good signal numbers, low and high ends of range. errno = 0; ASSERT_EQ(0, fn(&set, SIGNAL_MIN())); ASSERT_EQ(0, errno); ASSERT_EQ(0, fn(&set, SIGNAL_MAX(&set))); ASSERT_EQ(0, errno); } TEST(signal, sigaddset_invalid) { TestSigSet2(sigaddset); } TEST(signal, sigaddset64_invalid) { #if defined(__BIONIC__) TestSigSet2(sigaddset64); #endif } TEST(signal, sigdelset_invalid) { TestSigSet2(sigdelset); } TEST(signal, sigdelset64_invalid) { #if defined(__BIONIC__) TestSigSet2(sigdelset64); #endif } TEST(signal, sigemptyset_invalid) { TestSigSet1(sigemptyset); } TEST(signal, sigemptyset64_invalid) { #if defined(__BIONIC__) TestSigSet1(sigemptyset64); #endif } TEST(signal, sigfillset_invalid) { TestSigSet1(sigfillset); } TEST(signal, sigfillset64_invalid) { #if defined(__BIONIC__) TestSigSet1(sigfillset64); #endif } TEST(signal, sigismember_invalid) { TestSigSet2(sigismember); } TEST(signal, sigismember64_invalid) { #if defined(__BIONIC__) TestSigSet2(sigismember64); #endif } TEST(signal, raise_invalid) { errno = 0; ASSERT_EQ(-1, raise(-1)); ASSERT_EQ(EINVAL, errno); } static void raise_in_signal_handler_helper(int signal_number) { ASSERT_EQ(SIGALRM, signal_number); static int count = 0; if (++count == 1) { raise(SIGALRM); } } TEST(signal, raise_in_signal_handler) { ScopedSignalHandler ssh(SIGALRM, raise_in_signal_handler_helper); raise(SIGALRM); } static int g_sigsuspend_signal_handler_call_count = 0; TEST(signal, sigsuspend_sigpending) { SignalMaskRestorer smr; // Block SIGALRM. sigset_t just_SIGALRM; sigemptyset(&just_SIGALRM); sigaddset(&just_SIGALRM, SIGALRM); ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, nullptr)); ScopedSignalHandler ssh(SIGALRM, [](int) { ++g_sigsuspend_signal_handler_call_count; }); // There should be no pending signals. sigset_t pending; sigemptyset(&pending); ASSERT_EQ(0, sigpending(&pending)); for (int i = SIGNAL_MIN(); i <= SIGNAL_MAX(&pending); ++i) { EXPECT_FALSE(sigismember(&pending, i)) << i; } // Raise SIGALRM and check our signal handler wasn't called. raise(SIGALRM); ASSERT_EQ(0, g_sigsuspend_signal_handler_call_count); // We should now have a pending SIGALRM but nothing else. sigemptyset(&pending); ASSERT_EQ(0, sigpending(&pending)); for (int i = SIGNAL_MIN(); i <= SIGNAL_MAX(&pending); ++i) { EXPECT_EQ((i == SIGALRM), sigismember(&pending, i)); } // Use sigsuspend to block everything except SIGALRM... sigset_t not_SIGALRM; sigfillset(&not_SIGALRM); sigdelset(&not_SIGALRM, SIGALRM); ASSERT_EQ(-1, sigsuspend(&not_SIGALRM)); ASSERT_EQ(EINTR, errno); // ...and check that we now receive our pending SIGALRM. ASSERT_EQ(1, g_sigsuspend_signal_handler_call_count); } static int g_sigsuspend64_signal_handler_call_count = 0; TEST(signal, sigsuspend64_sigpending64) { SignalMaskRestorer smr; // Block SIGRTMIN. sigset64_t just_SIGRTMIN; sigemptyset64(&just_SIGRTMIN); sigaddset64(&just_SIGRTMIN, SIGRTMIN); ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, &just_SIGRTMIN, nullptr)); ScopedSignalHandler ssh(SIGRTMIN, [](int) { ++g_sigsuspend64_signal_handler_call_count; }); // There should be no pending signals. sigset64_t pending; sigemptyset64(&pending); ASSERT_EQ(0, sigpending64(&pending)); for (int i = SIGNAL_MIN(); i <= SIGNAL_MAX(&pending); ++i) { EXPECT_FALSE(sigismember64(&pending, i)) << i; } // Raise SIGRTMIN and check our signal handler wasn't called. raise(SIGRTMIN); ASSERT_EQ(0, g_sigsuspend64_signal_handler_call_count); // We should now have a pending SIGRTMIN but nothing else. sigemptyset64(&pending); ASSERT_EQ(0, sigpending64(&pending)); for (int i = SIGNAL_MIN(); i <= SIGNAL_MAX(&pending); ++i) { EXPECT_EQ((i == SIGRTMIN), sigismember64(&pending, i)); } // Use sigsuspend64 to block everything except SIGRTMIN... sigset64_t not_SIGRTMIN; sigfillset64(&not_SIGRTMIN); sigdelset64(&not_SIGRTMIN, SIGRTMIN); ASSERT_EQ(-1, sigsuspend64(&not_SIGRTMIN)); ASSERT_EQ(EINTR, errno); // ...and check that we now receive our pending SIGRTMIN. ASSERT_EQ(1, g_sigsuspend64_signal_handler_call_count); } template <typename SigActionT, typename SigSetT> static void TestSigAction(int (sigaction_fn)(int, const SigActionT*, SigActionT*), int (sigaddset_fn)(SigSetT*, int), int sig) { // Both bionic and glibc set SA_RESTORER when talking to the kernel on arm, // arm64, x86, and x86-64. The version of glibc we're using also doesn't // define SA_RESTORER, but luckily it's the same value everywhere. static const unsigned sa_restorer = 0x4000000; // See what's currently set for this signal. SigActionT original_sa = {}; ASSERT_EQ(0, sigaction_fn(sig, nullptr, &original_sa)); ASSERT_TRUE(original_sa.sa_handler == nullptr); ASSERT_TRUE(original_sa.sa_sigaction == nullptr); ASSERT_EQ(0U, original_sa.sa_flags & ~sa_restorer); #ifdef SA_RESTORER ASSERT_EQ(bool(original_sa.sa_flags & sa_restorer), bool(original_sa.sa_restorer)); #endif // Set a traditional sa_handler signal handler. auto no_op_signal_handler = [](int) {}; SigActionT sa = {}; sigaddset_fn(&sa.sa_mask, sig); sa.sa_flags = SA_ONSTACK; sa.sa_handler = no_op_signal_handler; ASSERT_EQ(0, sigaction_fn(sig, &sa, nullptr)); // Check that we can read it back. sa = {}; ASSERT_EQ(0, sigaction_fn(sig, nullptr, &sa)); ASSERT_TRUE(sa.sa_handler == no_op_signal_handler); ASSERT_TRUE((void*) sa.sa_sigaction == (void*) sa.sa_handler); ASSERT_EQ(static_cast<unsigned>(SA_ONSTACK), sa.sa_flags & ~sa_restorer); #ifdef SA_RESTORER ASSERT_EQ(bool(sa.sa_flags & sa_restorer), bool(sa.sa_restorer)); #endif // Set a new-style sa_sigaction signal handler. auto no_op_sigaction = [](int, siginfo_t*, void*) {}; sa = {}; sigaddset_fn(&sa.sa_mask, sig); sa.sa_flags = SA_ONSTACK | SA_SIGINFO; sa.sa_sigaction = no_op_sigaction; ASSERT_EQ(0, sigaction_fn(sig, &sa, nullptr)); // Check that we can read it back. sa = {}; ASSERT_EQ(0, sigaction_fn(sig, nullptr, &sa)); ASSERT_TRUE(sa.sa_sigaction == no_op_sigaction); ASSERT_TRUE((void*) sa.sa_sigaction == (void*) sa.sa_handler); ASSERT_EQ(static_cast<unsigned>(SA_ONSTACK | SA_SIGINFO), sa.sa_flags & ~sa_restorer); #ifdef SA_RESTORER ASSERT_EQ(bool(sa.sa_flags & sa_restorer), bool(sa.sa_restorer)); #endif // Put everything back how it was. ASSERT_EQ(0, sigaction_fn(sig, &original_sa, nullptr)); } TEST(signal, sigaction) { TestSigAction(sigaction, sigaddset, SIGALRM); } TEST(signal, sigaction64_SIGRTMIN) { TestSigAction(sigaction64, sigaddset64, SIGRTMIN); } static void ClearSignalMask() { uint64_t sigset = 0; SignalSetAdd(&sigset, __SIGRTMIN); if (syscall(__NR_rt_sigprocmask, SIG_SETMASK, &sigset, nullptr, sizeof(sigset)) != 0) { abort(); } } static void FillSignalMask() { uint64_t sigset = ~0ULL; for (int signo = __SIGRTMIN + 1; signo < SIGRTMIN; ++signo) { SignalSetDel(&sigset, signo); } if (syscall(__NR_rt_sigprocmask, SIG_SETMASK, &sigset, nullptr, sizeof(sigset)) != 0) { abort(); } } static uint64_t GetSignalMask() { uint64_t sigset; if (syscall(__NR_rt_sigprocmask, SIG_SETMASK, nullptr, &sigset, sizeof(sigset)) != 0) { abort(); } return sigset; } static void TestSignalMaskFiltered(uint64_t sigset) { #if defined(__BIONIC__) for (int signo = __SIGRTMIN; signo < SIGRTMIN; ++signo) { bool signal_blocked = sigset & (1ULL << (signo - 1)); if (signo == __SIGRTMIN) { // TIMER_SIGNAL must be blocked. EXPECT_EQ(true, signal_blocked) << "signal " << signo; } else { // The other reserved signals must not be blocked. EXPECT_EQ(false, signal_blocked) << "signal " << signo; } } #else UNUSED(sigset); #endif } static void TestSignalMaskFunction(std::function<void()> fn) { ClearSignalMask(); fn(); TestSignalMaskFiltered(GetSignalMask()); } TEST(signal, sigaction_filter) { ClearSignalMask(); static uint64_t sigset; struct sigaction sa = {}; sa.sa_handler = [](int) { sigset = GetSignalMask(); }; sa.sa_flags = SA_ONSTACK | SA_NODEFER; sigfillset(&sa.sa_mask); sigaction(SIGUSR1, &sa, nullptr); raise(SIGUSR1); // On LP32, struct sigaction::sa_mask is only 32-bits wide. unsigned long expected_sigset = ~0UL; // SIGKILL and SIGSTOP are always blocked. expected_sigset &= ~(1UL << (SIGKILL - 1)); expected_sigset &= ~(1UL << (SIGSTOP - 1)); ASSERT_EQ(static_cast<uint64_t>(expected_sigset), sigset); } TEST(signal, sigaction64_filter) { ClearSignalMask(); static uint64_t sigset; struct sigaction64 sa = {}; sa.sa_handler = [](int) { sigset = GetSignalMask(); }; sa.sa_flags = SA_ONSTACK | SA_NODEFER; sigfillset64(&sa.sa_mask); sigaction64(SIGUSR1, &sa, nullptr); raise(SIGUSR1); uint64_t expected_sigset = ~0ULL; // SIGKILL and SIGSTOP are always blocked. expected_sigset &= ~(1ULL << (SIGKILL - 1)); expected_sigset &= ~(1ULL << (SIGSTOP - 1)); ASSERT_EQ(expected_sigset, sigset); } TEST(signal, sigprocmask_setmask_filter) { TestSignalMaskFunction([]() { ClearSignalMask(); sigset_t sigset_libc; sigfillset(&sigset_libc); ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &sigset_libc, nullptr)); }); } TEST(signal, sigprocmask64_setmask_filter) { TestSignalMaskFunction([]() { ClearSignalMask(); sigset64_t sigset_libc; sigfillset64(&sigset_libc); ASSERT_EQ(0, sigprocmask64(SIG_SETMASK, &sigset_libc, nullptr)); }); } TEST(signal, pthread_sigmask_setmask_filter) { TestSignalMaskFunction([]() { ClearSignalMask(); sigset_t sigset_libc; sigfillset(&sigset_libc); ASSERT_EQ(0, pthread_sigmask(SIG_SETMASK, &sigset_libc, nullptr)); }); } TEST(signal, pthread_sigmask64_setmask_filter) { TestSignalMaskFunction([]() { ClearSignalMask(); sigset64_t sigset_libc; sigfillset64(&sigset_libc); ASSERT_EQ(0, pthread_sigmask64(SIG_SETMASK, &sigset_libc, nullptr)); }); } TEST(signal, sigprocmask_block_filter) { TestSignalMaskFunction([]() { ClearSignalMask(); sigset_t sigset_libc; sigfillset(&sigset_libc); ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &sigset_libc, nullptr)); }); } TEST(signal, sigprocmask64_block_filter) { TestSignalMaskFunction([]() { ClearSignalMask(); sigset64_t sigset_libc; sigfillset64(&sigset_libc); ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, &sigset_libc, nullptr)); }); } TEST(signal, pthread_sigmask_block_filter) { TestSignalMaskFunction([]() { ClearSignalMask(); sigset_t sigset_libc; sigfillset(&sigset_libc); ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, &sigset_libc, nullptr)); }); } TEST(signal, pthread_sigmask64_block_filter) { TestSignalMaskFunction([]() { ClearSignalMask(); sigset64_t sigset_libc; sigfillset64(&sigset_libc); ASSERT_EQ(0, pthread_sigmask64(SIG_BLOCK, &sigset_libc, nullptr)); }); } TEST(signal, sigprocmask_unblock_filter) { TestSignalMaskFunction([]() { FillSignalMask(); sigset_t sigset_libc; sigfillset(&sigset_libc); ASSERT_EQ(0, sigprocmask(SIG_UNBLOCK, &sigset_libc, nullptr)); }); } TEST(signal, sigprocmask64_unblock_filter) { TestSignalMaskFunction([]() { FillSignalMask(); sigset64_t sigset_libc; sigfillset64(&sigset_libc); ASSERT_EQ(0, sigprocmask64(SIG_UNBLOCK, &sigset_libc, nullptr)); }); } TEST(signal, pthread_sigmask_unblock_filter) { TestSignalMaskFunction([]() { FillSignalMask(); sigset_t sigset_libc; sigfillset(&sigset_libc); ASSERT_EQ(0, pthread_sigmask(SIG_UNBLOCK, &sigset_libc, nullptr)); }); } TEST(signal, pthread_sigmask64_unblock_filter) { TestSignalMaskFunction([]() { FillSignalMask(); sigset64_t sigset_libc; sigfillset64(&sigset_libc); ASSERT_EQ(0, pthread_sigmask64(SIG_UNBLOCK, &sigset_libc, nullptr)); }); } // glibc filters out signals via sigfillset, not the actual underlying functions. TEST(signal, sigset_filter) { #if defined(__BIONIC__) TestSignalMaskFunction([]() { for (int i = 1; i <= 64; ++i) { sigset(i, SIG_HOLD); } }); #endif } TEST(signal, sighold_filter) { #if defined(__BIONIC__) TestSignalMaskFunction([]() { for (int i = 1; i <= 64; ++i) { sighold(i); } }); #endif } #if defined(__BIONIC__) // Not exposed via headers, but the symbols are available if you declare them yourself. extern "C" int sigblock(int); extern "C" int sigsetmask(int); #endif TEST(signal, sigblock_filter) { #if defined(__BIONIC__) TestSignalMaskFunction([]() { sigblock(~0U); }); #endif } TEST(signal, sigsetmask_filter) { #if defined(__BIONIC__) TestSignalMaskFunction([]() { sigsetmask(~0U); }); #endif } TEST(signal, sys_signame) { #if defined(__BIONIC__) ASSERT_TRUE(sys_signame[0] == nullptr); ASSERT_STREQ("HUP", sys_signame[SIGHUP]); #else GTEST_SKIP() << "glibc doesn't have sys_signame"; #endif } TEST(signal, sys_siglist) { ASSERT_TRUE(sys_siglist[0] == nullptr); ASSERT_STREQ("Hangup", sys_siglist[SIGHUP]); } TEST(signal, limits) { // These come from the kernel. ASSERT_EQ(32, __SIGRTMIN); ASSERT_EQ(64, __SIGRTMAX); // We reserve a non-zero number at the bottom for ourselves. ASSERT_GT(SIGRTMIN, __SIGRTMIN); // We don't currently reserve any at the top. ASSERT_EQ(SIGRTMAX, __SIGRTMAX); } static int g_sigqueue_signal_handler_call_count = 0; static void SigqueueSignalHandler(int signum, siginfo_t* info, void*) { ASSERT_EQ(SIGALRM, signum); ASSERT_EQ(SIGALRM, info->si_signo); ASSERT_EQ(SI_QUEUE, info->si_code); ASSERT_EQ(1, info->si_value.sival_int); ++g_sigqueue_signal_handler_call_count; } TEST(signal, sigqueue) { ScopedSignalHandler ssh(SIGALRM, SigqueueSignalHandler, SA_SIGINFO); sigval_t sigval = {.sival_int = 1}; errno = 0; ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval)); ASSERT_EQ(0, errno); ASSERT_EQ(1, g_sigqueue_signal_handler_call_count); } TEST(signal, pthread_sigqueue_self) { ScopedSignalHandler ssh(SIGALRM, SigqueueSignalHandler, SA_SIGINFO); sigval_t sigval = {.sival_int = 1}; errno = 0; ASSERT_EQ(0, pthread_sigqueue(pthread_self(), SIGALRM, sigval)); ASSERT_EQ(0, errno); ASSERT_EQ(1, g_sigqueue_signal_handler_call_count); } TEST(signal, pthread_sigqueue_other) { ScopedSignalHandler ssh(SIGALRM, SigqueueSignalHandler, SA_SIGINFO); sigval_t sigval = {.sival_int = 1}; sigset_t mask; sigfillset(&mask); pthread_sigmask(SIG_SETMASK, &mask, nullptr); pthread_t thread; int rc = pthread_create(&thread, nullptr, [](void*) -> void* { sigset_t mask; sigemptyset(&mask); sigsuspend(&mask); return nullptr; }, nullptr); ASSERT_EQ(0, rc); errno = 0; ASSERT_EQ(0, pthread_sigqueue(thread, SIGALRM, sigval)); ASSERT_EQ(0, errno); pthread_join(thread, nullptr); ASSERT_EQ(1, g_sigqueue_signal_handler_call_count); } TEST(signal, sigwait_SIGALRM) { SignalMaskRestorer smr; // Block SIGALRM. sigset_t just_SIGALRM; sigemptyset(&just_SIGALRM); sigaddset(&just_SIGALRM, SIGALRM); ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, nullptr)); // Raise SIGALRM. sigval_t sigval = {.sival_int = 1}; ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval)); // Get pending SIGALRM. int sig; ASSERT_EQ(0, sigwait(&just_SIGALRM, &sig)); ASSERT_EQ(SIGALRM, sig); } TEST(signal, sigwait64_SIGRTMIN) { SignalMaskRestorer smr; // Block SIGRTMIN. sigset64_t just_SIGRTMIN; sigemptyset64(&just_SIGRTMIN); sigaddset64(&just_SIGRTMIN, SIGRTMIN); ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, &just_SIGRTMIN, nullptr)); // Raise SIGRTMIN. sigval_t sigval = {.sival_int = 1}; ASSERT_EQ(0, sigqueue(getpid(), SIGRTMIN, sigval)); // Get pending SIGRTMIN. int sig; ASSERT_EQ(0, sigwait64(&just_SIGRTMIN, &sig)); ASSERT_EQ(SIGRTMIN, sig); } TEST(signal, sigwaitinfo) { SignalMaskRestorer smr; // Block SIGALRM. sigset_t just_SIGALRM; sigemptyset(&just_SIGALRM); sigaddset(&just_SIGALRM, SIGALRM); ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, nullptr)); // Raise SIGALRM. sigval_t sigval = {.sival_int = 1}; ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval)); // Get pending SIGALRM. siginfo_t info; errno = 0; ASSERT_EQ(SIGALRM, sigwaitinfo(&just_SIGALRM, &info)); ASSERT_EQ(0, errno); ASSERT_EQ(SIGALRM, info.si_signo); ASSERT_EQ(1, info.si_value.sival_int); } TEST(signal, sigwaitinfo64_SIGRTMIN) { SignalMaskRestorer smr; // Block SIGRTMIN. sigset64_t just_SIGRTMIN; sigemptyset64(&just_SIGRTMIN); sigaddset64(&just_SIGRTMIN, SIGRTMIN); ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, &just_SIGRTMIN, nullptr)); // Raise SIGRTMIN. sigval_t sigval = {.sival_int = 1}; ASSERT_EQ(0, sigqueue(getpid(), SIGRTMIN, sigval)); // Get pending SIGRTMIN. siginfo_t info; errno = 0; ASSERT_EQ(SIGRTMIN, sigwaitinfo64(&just_SIGRTMIN, &info)); ASSERT_EQ(0, errno); ASSERT_EQ(SIGRTMIN, info.si_signo); ASSERT_EQ(1, info.si_value.sival_int); } TEST(signal, sigtimedwait) { SignalMaskRestorer smr; // Block SIGALRM. sigset_t just_SIGALRM; sigemptyset(&just_SIGALRM); sigaddset(&just_SIGALRM, SIGALRM); ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, nullptr)); // Raise SIGALRM. sigval_t sigval = { .sival_int = 1 }; ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval)); // Get pending SIGALRM. siginfo_t info; timespec timeout = { .tv_sec = 2, .tv_nsec = 0 }; errno = 0; ASSERT_EQ(SIGALRM, sigtimedwait(&just_SIGALRM, &info, &timeout)); ASSERT_EQ(0, errno); } TEST(signal, sigtimedwait64_SIGRTMIN) { SignalMaskRestorer smr; // Block SIGRTMIN. sigset64_t just_SIGRTMIN; sigemptyset64(&just_SIGRTMIN); sigaddset64(&just_SIGRTMIN, SIGRTMIN); ASSERT_EQ(0, sigprocmask64(SIG_BLOCK, &just_SIGRTMIN, nullptr)); // Raise SIGALRM. sigval_t sigval = { .sival_int = 1 }; ASSERT_EQ(0, sigqueue(getpid(), SIGRTMIN, sigval)); // Get pending SIGALRM. siginfo_t info; timespec timeout = { .tv_sec = 2, .tv_nsec = 0 }; errno = 0; ASSERT_EQ(SIGRTMIN, sigtimedwait64(&just_SIGRTMIN, &info, &timeout)); ASSERT_EQ(0, errno); } TEST(signal, sigtimedwait_timeout) { // Block SIGALRM. sigset_t just_SIGALRM; sigemptyset(&just_SIGALRM); sigaddset(&just_SIGALRM, SIGALRM); sigset_t original_set; ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, &original_set)); // Wait timeout. auto t0 = std::chrono::steady_clock::now(); siginfo_t info; timespec timeout = { .tv_sec = 0, .tv_nsec = 1000000 }; errno = 0; ASSERT_EQ(-1, sigtimedwait(&just_SIGALRM, &info, &timeout)); ASSERT_EQ(EAGAIN, errno); auto t1 = std::chrono::steady_clock::now(); ASSERT_GE(t1-t0, 1000000ns); ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &original_set, nullptr)); } #if defined(__BIONIC__) TEST(signal, rt_tgsigqueueinfo) { // Test whether rt_tgsigqueueinfo allows sending arbitrary si_code values to self. // If this fails, your kernel needs commit 66dd34a to be backported. static constexpr char error_msg[] = "\nPlease ensure that the following kernel patch has been applied:\n" "* https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=66dd34ad31e5963d72a700ec3f2449291d322921\n"; static siginfo received; struct sigaction handler = {}; handler.sa_sigaction = [](int, siginfo_t* siginfo, void*) { received = *siginfo; }; handler.sa_flags = SA_SIGINFO; ASSERT_EQ(0, sigaction(SIGUSR1, &handler, nullptr)); siginfo sent; memset(&sent, 0, sizeof(sent)); sent.si_code = SI_TKILL; ASSERT_EQ(0, syscall(SYS_rt_tgsigqueueinfo, getpid(), gettid(), SIGUSR1, &sent)) << "rt_tgsigqueueinfo failed: " << strerror(errno) << error_msg; ASSERT_EQ(sent.si_code, received.si_code) << "rt_tgsigqueueinfo modified si_code, expected " << sent.si_code << ", received " << received.si_code << error_msg; sent.si_code = SI_USER; ASSERT_EQ(0, syscall(SYS_rt_tgsigqueueinfo, getpid(), gettid(), SIGUSR1, &sent)) << "rt_tgsigqueueinfo failed: " << strerror(errno) << error_msg; ASSERT_EQ(sent.si_code, received.si_code) << "rt_tgsigqueueinfo modified si_code, expected " << sent.si_code << ", received " << received.si_code << error_msg; } #endif TEST(signal, sigset_size) { // The setjmp implementations assume that sigset_t can fit in a // long. This is true because ARM and x86 have broken rt signal support, // and AArch64 and x86_64 both have a SIGRTMAX defined as 64. #if defined(__BIONIC__) static_assert(sizeof(sigset_t) <= sizeof(long), "sigset_t doesn't fit in a long"); #endif static_assert(sizeof(sigset64_t)*8 >= 64, "sigset64_t too small for real-time signals"); } TEST(signal, sigignore_EINVAL) { errno = 0; ASSERT_EQ(-1, sigignore(99999)); ASSERT_EQ(EINVAL, errno); } TEST(signal, sigignore) { errno = 0; EXPECT_EQ(-1, sigignore(SIGKILL)); EXPECT_EQ(errno, EINVAL); errno = 0; EXPECT_EQ(-1, sigignore(SIGSTOP)); EXPECT_EQ(errno, EINVAL); ScopedSignalHandler sigalrm{SIGALRM}; ASSERT_EQ(0, sigignore(SIGALRM)); struct sigaction sa; ASSERT_EQ(0, sigaction(SIGALRM, nullptr, &sa)); EXPECT_EQ(SIG_IGN, sa.sa_handler); } TEST(signal, sighold_EINVAL) { errno = 0; ASSERT_EQ(-1, sighold(99999)); ASSERT_EQ(EINVAL, errno); } TEST(signal, sigpause_EINVAL) { errno = 0; ASSERT_EQ(-1, sigpause(99999)); ASSERT_EQ(EINVAL, errno); } TEST(signal, sigrelse_EINVAL) { errno = 0; ASSERT_EQ(-1, sigpause(99999)); ASSERT_EQ(EINVAL, errno); } static void TestSigholdSigpauseSigrelse(int sig) { static int signal_handler_call_count = 0; ScopedSignalHandler ssh{sig, [](int) { signal_handler_call_count++; }}; SignalMaskRestorer mask_restorer; sigset_t set; // sighold(SIGALRM/SIGRTMIN) should add SIGALRM/SIGRTMIN to the signal mask ... ASSERT_EQ(0, sighold(sig)); ASSERT_EQ(0, sigprocmask(SIG_SETMASK, nullptr, &set)); EXPECT_TRUE(sigismember(&set, sig)); // ... preventing our SIGALRM/SIGRTMIN handler from running ... raise(sig); ASSERT_EQ(0, signal_handler_call_count); // ... until sigpause(SIGALRM/SIGRTMIN) temporarily unblocks it. ASSERT_EQ(-1, sigpause(sig)); ASSERT_EQ(EINTR, errno); ASSERT_EQ(1, signal_handler_call_count); if (sig >= SIGRTMIN && sizeof(void*) == 8) { // But sigpause(SIGALRM/SIGRTMIN) shouldn't permanently unblock SIGALRM/SIGRTMIN. ASSERT_EQ(0, sigprocmask(SIG_SETMASK, nullptr, &set)); EXPECT_TRUE(sigismember(&set, sig)); // Whereas sigrelse(SIGALRM/SIGRTMIN) should. ASSERT_EQ(0, sigrelse(sig)); ASSERT_EQ(0, sigprocmask(SIG_SETMASK, nullptr, &set)); EXPECT_FALSE(sigismember(&set, sig)); } else { // sigismember won't work for SIGRTMIN on LP32. } } TEST(signal, sighold_sigpause_sigrelse) { TestSigholdSigpauseSigrelse(SIGALRM); } TEST(signal, sighold_sigpause_sigrelse_RT) { TestSigholdSigpauseSigrelse(SIGRTMIN); } TEST(signal, sigset_EINVAL) { errno = 0; ASSERT_EQ(SIG_ERR, sigset(99999, SIG_DFL)); ASSERT_EQ(EINVAL, errno); } TEST(signal, sigset_RT) { static int signal_handler_call_count = 0; auto signal_handler = [](int) { signal_handler_call_count++; }; ScopedSignalHandler ssh{SIGRTMIN, signal_handler}; SignalMaskRestorer mask_restorer; ASSERT_EQ(signal_handler, sigset(SIGRTMIN, SIG_HOLD)); #if defined(__LP64__) sigset_t set; ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set)); ASSERT_TRUE(sigismember(&set, SIGRTMIN)); #endif ASSERT_EQ(SIG_HOLD, sigset(SIGRTMIN, signal_handler)); ASSERT_EQ(signal_handler, sigset(SIGRTMIN, signal_handler)); ASSERT_EQ(0, signal_handler_call_count); raise(SIGRTMIN); ASSERT_EQ(1, signal_handler_call_count); } TEST(signal, sigset) { static int signal_handler_call_count = 0; auto signal_handler = [](int) { signal_handler_call_count++; }; ScopedSignalHandler ssh{SIGALRM, signal_handler}; SignalMaskRestorer mask_restorer; ASSERT_EQ(0, signal_handler_call_count); raise(SIGALRM); ASSERT_EQ(1, signal_handler_call_count); // Block SIGALRM so the next sigset(SIGARLM) call will return SIG_HOLD. sigset_t set; sigemptyset(&set); sigaddset(&set, SIGALRM); ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &set, nullptr)); sigemptyset(&set); ASSERT_EQ(SIG_HOLD, sigset(SIGALRM, signal_handler)); ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set)); EXPECT_FALSE(sigismember(&set, SIGALRM)); ASSERT_EQ(signal_handler, sigset(SIGALRM, SIG_IGN)); ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set)); EXPECT_FALSE(sigismember(&set, SIGALRM)); ASSERT_EQ(SIG_IGN, sigset(SIGALRM, SIG_DFL)); ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set)); EXPECT_FALSE(sigismember(&set, SIGALRM)); ASSERT_EQ(SIG_DFL, sigset(SIGALRM, SIG_HOLD)); ASSERT_EQ(0, sigprocmask(SIG_BLOCK, nullptr, &set)); EXPECT_TRUE(sigismember(&set, SIGALRM)); } TEST(signal, killpg_EINVAL) { // POSIX leaves pgrp <= 1 undefined, but glibc fails with EINVAL for < 0 // and passes 0 through to kill(2). errno = 0; ASSERT_EQ(-1, killpg(-1, SIGKILL)); ASSERT_EQ(EINVAL, errno); }
ORG 32768 ; === b e g i n === ld (Stop+1), SP ; 4:20 init storing the original SP value when the "bye" word is used ld L, 0x1A ; 2:7 init Upper screen call 0x1605 ; 3:17 init Open channel ld HL, 60000 ; 3:10 init Init Return address stack exx ; 1:4 init call Fillin ; 3:17 scall Stop: ; stop ld SP, 0x0000 ; 3:10 stop restoring the original SP value when the "bye" word is used ld HL, 0x2758 ; 3:10 stop exx ; 1:4 stop ret ; 1:10 stop ; ===== e n d ===== ; --- the beginning of a data stack function --- Fillin: ; ( -- ) push DE ; 1:11 push2(65535,0) ld DE, 65535 ; 3:10 push2(65535,0) push HL ; 1:11 push2(65535,0) ld HL, 0 ; 3:10 push2(65535,0) ld BC, 16384 ; 3:10 xdo(23296,16384) 101 xdo101save: ; xdo(23296,16384) 101 ld (idx101),BC ; 4:20 xdo(23296,16384) 101 xdo101: ; xdo(23296,16384) 101 ex DE, HL ; 1:4 drop pop DE ; 1:10 drop ( a -- ) push DE ; 1:11 index(101) xi ex DE, HL ; 1:4 index(101) xi ld HL, (idx101) ; 3:16 index(101) xi idx always points to a 16-bit index push DE ; 1:11 2dup push HL ; 1:11 2dup ( a b -- a b a b ) ;[5:40] ! store ( x addr -- ) ld (HL),E ; 1:7 ! store inc HL ; 1:6 ! store ld (HL),D ; 1:7 ! store pop HL ; 1:10 ! store pop DE ; 1:10 ! store ;[10:57/37] xloop 101 variant +1.I: step one with hi(real_stop) exclusivity, run 6912x idx101 EQU $+1 ; xloop 101 idx always points to a 16-bit index ld BC, 0x0000 ; 3:10 xloop 101 16384.. +1 ..(23296), real_stop:0x5B00 inc BC ; 1:6 xloop 101 index++ ld A, B ; 1:4 xloop 101 xor 0x5B ; 2:7 xloop 101 hi(real_stop) jp nz, xdo101save ; 3:10 xloop 101 xleave101: ; xloop 101 xexit101: ; xloop 101 pop HL ; 1:10 2drop pop DE ; 1:10 2drop ( b a -- ) Fillin_end: ret ; 1:10 s; ; --------- end of data stack function ---------
; A231104: Number of n X 4 0..3 arrays x(i,j) with each element horizontally or antidiagonally next to at least one element with value (x(i,j)+1) mod 4, no adjacent elements equal, and upper left element zero. ; 0,6,48,438,3936,35430,318864,2869782,25828032,232452294,2092070640,18828635766,169457721888,1525119496998,13726075472976,123534679256790,1111812113311104,10006309019799942 mov $2,3 pow $2,$0 pow $2,2 mov $1,$2 add $1,1 div $1,5 mul $1,6 div $1,4 mul $1,2
<% import collections import pwnlib.abi import pwnlib.constants import pwnlib.shellcraft import six %> <%docstring>ftime(timebuf) -> str Invokes the syscall ftime. See 'man 2 ftime' for more information. Arguments: timebuf(timeb*): timebuf Returns: int </%docstring> <%page args="timebuf=0"/> <% abi = pwnlib.abi.ABI.syscall() stack = abi.stack regs = abi.register_arguments[1:] allregs = pwnlib.shellcraft.registers.current() can_pushstr = [] can_pushstr_array = [] argument_names = ['timebuf'] argument_values = [timebuf] # Load all of the arguments into their destination registers / stack slots. register_arguments = dict() stack_arguments = collections.OrderedDict() string_arguments = dict() dict_arguments = dict() array_arguments = dict() syscall_repr = [] for name, arg in zip(argument_names, argument_values): if arg is not None: syscall_repr.append('%s=%r' % (name, arg)) # If the argument itself (input) is a register... if arg in allregs: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[index] = arg # The argument is not a register. It is a string value, and we # are expecting a string value elif name in can_pushstr and isinstance(arg, (six.binary_type, six.text_type)): if isinstance(arg, six.text_type): arg = arg.encode('utf-8') string_arguments[name] = arg # The argument is not a register. It is a dictionary, and we are # expecting K:V paris. elif name in can_pushstr_array and isinstance(arg, dict): array_arguments[name] = ['%s=%s' % (k,v) for (k,v) in arg.items()] # The arguent is not a register. It is a list, and we are expecting # a list of arguments. elif name in can_pushstr_array and isinstance(arg, (list, tuple)): array_arguments[name] = arg # The argument is not a register, string, dict, or list. # It could be a constant string ('O_RDONLY') for an integer argument, # an actual integer value, or a constant. else: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[target] = arg # Some syscalls have different names on various architectures. # Determine which syscall number to use for the current architecture. for syscall in ['SYS_ftime']: if hasattr(pwnlib.constants, syscall): break else: raise Exception("Could not locate any syscalls: %r" % syscalls) %> /* ftime(${', '.join(syscall_repr)}) */ %for name, arg in string_arguments.items(): ${pwnlib.shellcraft.pushstr(arg, append_null=(b'\x00' not in arg))} ${pwnlib.shellcraft.mov(regs[argument_names.index(name)], abi.stack)} %endfor %for name, arg in array_arguments.items(): ${pwnlib.shellcraft.pushstr_array(regs[argument_names.index(name)], arg)} %endfor %for name, arg in stack_arguments.items(): ${pwnlib.shellcraft.push(arg)} %endfor ${pwnlib.shellcraft.setregs(register_arguments)} ${pwnlib.shellcraft.syscall(syscall)}
;------------------------------------------------------------------------------ ; @file ; Sets the CR3 register for 64-bit paging ; ; Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.<BR> ; Copyright (c) 2019, Citrix Systems, Inc. ; SPDX-License-Identifier: BSD-2-Clause-Patent ; ;------------------------------------------------------------------------------ BITS 32 %define PAGE_PRESENT 0x01 %define PAGE_READ_WRITE 0x02 %define PAGE_USER_SUPERVISOR 0x04 %define PAGE_WRITE_THROUGH 0x08 %define PAGE_CACHE_DISABLE 0x010 %define PAGE_ACCESSED 0x020 %define PAGE_DIRTY 0x040 %define PAGE_PAT 0x080 %define PAGE_GLOBAL 0x0100 %define PAGE_2M_MBO 0x080 %define PAGE_2M_PAT 0x01000 %define PAGE_2M_PDE_ATTR (PAGE_2M_MBO + \ PAGE_ACCESSED + \ PAGE_DIRTY + \ PAGE_READ_WRITE + \ PAGE_PRESENT) %define PAGE_PDP_ATTR (PAGE_ACCESSED + \ PAGE_READ_WRITE + \ PAGE_PRESENT) ; Check if Secure Encrypted Virtualization (SEV) feature is enabled ; ; If SEV is enabled then EAX will be at least 32 ; If SEV is disabled then EAX will be zero. ; CheckSevFeature: ; Check if we have a valid (0x8000_001F) CPUID leaf mov eax, 0x80000000 cpuid ; This check should fail on Intel or Non SEV AMD CPUs. In future if ; Intel CPUs supports this CPUID leaf then we are guranteed to have exact ; same bit definition. cmp eax, 0x8000001f jl NoSev ; Check for memory encryption feature: ; CPUID Fn8000_001F[EAX] - Bit 1 ; mov eax, 0x8000001f cpuid bt eax, 1 jnc NoSev ; Check if memory encryption is enabled ; MSR_0xC0010131 - Bit 0 (SEV enabled) mov ecx, 0xc0010131 rdmsr bt eax, 0 jnc NoSev ; Get pte bit position to enable memory encryption ; CPUID Fn8000_001F[EBX] - Bits 5:0 ; mov eax, ebx and eax, 0x3f jmp SevExit NoSev: xor eax, eax SevExit: OneTimeCallRet CheckSevFeature ; ; Modified: EAX, EBX, ECX, EDX ; SetCr3ForPageTables64: OneTimeCall CheckSevFeature xor edx, edx test eax, eax jz SevNotActive ; If SEV is enabled, C-bit is always above 31 sub eax, 32 bts edx, eax SevNotActive: ; ; For OVMF, build some initial page tables at ; PcdOvmfSecPageTablesBase - (PcdOvmfSecPageTablesBase + 0x6000). ; ; This range should match with PcdOvmfSecPageTablesSize which is ; declared in the FDF files. ; ; At the end of PEI, the pages tables will be rebuilt into a ; more permanent location by DxeIpl. ; mov ecx, 6 * 0x1000 / 4 xor eax, eax clearPageTablesMemoryLoop: mov dword[ecx * 4 + PT_ADDR (0) - 4], eax loop clearPageTablesMemoryLoop ; ; Top level Page Directory Pointers (1 * 512GB entry) ; mov dword[PT_ADDR (0)], PT_ADDR (0x1000) + PAGE_PDP_ATTR mov dword[PT_ADDR (4)], edx ; ; Next level Page Directory Pointers (4 * 1GB entries => 4GB) ; mov dword[PT_ADDR (0x1000)], PT_ADDR (0x2000) + PAGE_PDP_ATTR mov dword[PT_ADDR (0x1004)], edx mov dword[PT_ADDR (0x1008)], PT_ADDR (0x3000) + PAGE_PDP_ATTR mov dword[PT_ADDR (0x100C)], edx mov dword[PT_ADDR (0x1010)], PT_ADDR (0x4000) + PAGE_PDP_ATTR mov dword[PT_ADDR (0x1014)], edx mov dword[PT_ADDR (0x1018)], PT_ADDR (0x5000) + PAGE_PDP_ATTR mov dword[PT_ADDR (0x101C)], edx ; ; Page Table Entries (2048 * 2MB entries => 4GB) ; mov ecx, 0x800 pageTableEntriesLoop: mov eax, ecx dec eax shl eax, 21 add eax, PAGE_2M_PDE_ATTR mov [ecx * 8 + PT_ADDR (0x2000 - 8)], eax mov [(ecx * 8 + PT_ADDR (0x2000 - 8)) + 4], edx loop pageTableEntriesLoop ; ; Set CR3 now that the paging structures are available ; mov eax, PT_ADDR (0) mov cr3, eax OneTimeCallRet SetCr3ForPageTables64
/* * All Video Processing kernels * Copyright © <2010>, Intel Corporation. * * This program is licensed under the terms and conditions of the * Eclipse Public License (EPL), version 1.0. The full text of the EPL is at * http://www.opensource.org/licenses/eclipse-1.0.php. * * Authors: * Halley Zhao <halley.zhao@intel.com> */ // Module name: RGB_to_YUV_Coef.asm //---------------------------------------------------------------- // is src surface |R|G|B|X| layout? otherwise it is |B|G|R|X| and.nz.f0.1 (1) dNULLREG r1.1:ud 0xFF000000:ud #ifdef FIX_POINT_CONVERSION // Y = ( ( 66 * R + 129 * G + 25 * B + 128 ) >> 8) + 16 (-f0.1) mov (1) REG2(r, nTEMP0, 0):ud 0x00428119:ud // used as unsigned byte ( f0.1) mov (1) REG2(r, nTEMP0, 0):ud 0x00198142:ud // used as unsigned byte // U = ( ( -38 * R - 74 * G + 112 * B + 128 ) >> 8) + 128 (-f0.1) mov (1) REG2(r, nTEMP0, 1):ud 0x00DAB670:ud // used as signed byte ( f0.1) mov (1) REG2(r, nTEMP0, 1):ud 0x0070B6DA:ud // used as signed byte // V = ( ( 112 * R - 94 * G - 18 * B + 128 ) >> 8) + 128 (-f0.1) mov (1) REG2(r, nTEMP0, 2):ud 0x0070A2EEud // used as signed byte ( f0.1) mov (1) REG2(r, nTEMP0, 2):ud 0x00EEA270ud // used as signed byte #define ubRGB_to_Y_Coef_Fix REG2(r, nTEMP0, 0) #define bRGB_to_U_Coef_Fix REG2(r, nTEMP0, 4) #define bRGB_to_V_Coef_Fix REG2(r, nTEMP0, 8) #else // Y = 0.299R + 0.587G + 0.114B (-f0.1) mov (1) REG2(r, nTEMP8, 0):f 0.114f // B coef ( f0.1) mov (1) REG2(r, nTEMP8, 2):f 0.114f // R coef mov (1) REG2(r, nTEMP8, 1):f 0.587f // G coef (-f0.1) mov (1) REG2(r, nTEMP8, 2):f 0.299f // R coef ( f0.1) mov (1) REG2(r, nTEMP8, 0):f 0.299f // B coef mov (1) REG2(r, nTEMP8, 3):f 0.000f // A coef // Cb= -0.169R - 0.331G + 0.499B + 128 // U = -0.147R - 0.289G + 0.436B + 128 (-f0.1) mov (1) REG2(r, nTEMP8, 4):f 0.436f // B coef ( f0.1) mov (1) REG2(r, nTEMP8, 6):f 0.436f // R coef mov (1) REG2(r, nTEMP8, 5):f -0.289f // G coef (-f0.1) mov (1) REG2(r, nTEMP8, 6):f -0.147f // R coef ( f0.1) mov (1) REG2(r, nTEMP8, 4):f -0.147f // B coef mov (1) REG2(r, nTEMP8, 7):f 0.000f // A coef // Cr= 0.499R - 0.418G - 0.0813B+ 128 // V = 0.615R - 0.515G - 0.100B + 128 (-f0.1) mov (1) REG2(r, nTEMP10, 0):f -0.100f // B coef ( f0.1) mov (1) REG2(r, nTEMP10, 2):f -0.100f // R coef mov (1) REG2(r, nTEMP10, 1):f -0.515f // G coef (-f0.1) mov (1) REG2(r, nTEMP10, 2):f 0.615f // R coef ( f0.1) mov (1) REG2(r, nTEMP10, 0):f 0.615f // B coef mov (1) REG2(r, nTEMP10, 3):f 0.000f // A coef #define fRGB_to_Y_Coef_Float REG2(r, nTEMP8, 0) #define fRGB_to_U_Coef_Float REG2(r, nTEMP8, 4) #define fRGB_to_V_Coef_Float REG2(r, nTEMP10, 0) .declare fROW_BGRX Base=REG(r,nTEMP0) ElementSize=4 SrcRegion=REGION(8,8) Type=f // r nTEMP0 - r nTEMP7 #endif
; ff3_rand.asm ; ; description: ; small patch for pseudorandom generator for battle ; ; version: ; 0.01 (2006-10-12) ; ;====================================================================================================== ff3_rand_begin: .bank $3f .org $fc27 initBattleRandom: .org $fc37 adc #RANDOM_LCG_A ;original:3 ;====================================================================================================== RESTORE_PC ff3_rand_begin
/******************************************************************************* CREATED: 29.05.2019, by Vana Radek DESCRIPTION: Inspired by https://github.com/canton7/StateMechanic But much lighter version unlike original I do not use names in constreuctor - need to save RAM targetted for IAR compilled V850 Extended Embedded c++ == no namespaces no exceptions and c++03 and some other limitations FILE: StateMechanic.h *******************************************************************************/ #ifndef __STATEMECHANIC__ #define __STATEMECHANIC__ #include "IEvent.hpp" #include "State.hpp" #include "IStateMachineWithEventFireRequest.hpp" #include "IInfo.hpp" #include <queue> /******************************************************************************/ //StateMachine //has a few useful events: // //Transition will be raised whenever a transition occurs //(either one this state machine or on one of its children). - to be implemented //This is very useful for logging: you can track exactly what your application //is doing, for free, with this log output. TransitionNotFound will be raised //whenever an Event.Fire() or an Event. TryFire() fails. In the case of recursive //transitions and Event.TryFire(), this is the only way to know that the transition //failed. Again, useful for logging. Faulted is raised whenever the state machine //faults, i.e. an exception is raised by a transition or state entry/exit handler. //Event is an outer influence, so state machine does not need to know it class StateMachine: public IStateMachineWithEventFireRequest{ //EventFireLocker forces eventfire to go to the queue if an event is being fired // used in recursive transmissions //when an instance is created it locks the lock //when the instance is destroyed, lock is released //bool would be fine for 1 instance, uint32_t just to ba able have multiple instances uint32_t AnEventIsBeingFired; bool IsAnEventBeingFired(){return AnEventIsBeingFired;} queue<EventFireData> evQueue; bool enque(EventFireData efd); bool deque(); class EventFireLocker{ StateMachine& _machine; public: EventFireLocker(StateMachine& machine):_machine(machine){++_machine.AnEventIsBeingFired;} ~EventFireLocker(){--_machine.AnEventIsBeingFired;} }; //state is not copyable, i need pointers vector<State*>::iterator currentState; //do not have unique_ptr vector<State*> states; vector<State*> DefaultStates; vector<vector<State*>::iterator> DefaultStatesTransitions; //DS_TRANSITION_NOT_FOUNT - state machine will stay in its state typedef enum { DS_UNINICIALIZED = 0, DS_FAULTED, DS_COUNT } DEFAULT_STATES; State* __createState( auto_ptr<EvHandler> entry = auto_ptr<EvHandler>(new DummyEvHandler()), auto_ptr<EvHandler> exit = auto_ptr<EvHandler>(new DummyEvHandler())); auto_ptr<EvHandler> transitionEv;//any nondefault transmission fires it auto_ptr<EvHandler> defaultTransitionEv;//any default transmission fires it auto_ptr<EvHandler> transitionNotFoundEv; auto_ptr<EvHandler> faultedEv; //void setDefState(DEFAULT_STATES s); bool isDefaultState(vector<State*>::iterator state); void defaultTransition(vector<State*>::iterator itActualState, vector<State*>::iterator itNextState, IEvent& ev); DEFAULT_STATES getDefaultId(vector<State*>::iterator state); //first fires exit state, than event, than enter, than transition void _changeState_FireEvents(const ITransition& transition, IEvHandler& transmEv, vector<State*>::iterator to, auto_ptr<IFiredData> firedData); virtual bool RequestEventFireFromEvent(EventFireData efd); bool __requestEventFireFromEvent(EventFireData efd); public: StateMachine(); //const State* == NULL == erorr State* CreateInitialState( auto_ptr<EvHandler> entry = auto_ptr<EvHandler>(new DummyEvHandler()), auto_ptr<EvHandler> exit = auto_ptr<EvHandler>(new DummyEvHandler())); State* CreateState( auto_ptr<EvHandler> entry = auto_ptr<EvHandler>(new DummyEvHandler()), auto_ptr<EvHandler> exit = auto_ptr<EvHandler>(new DummyEvHandler())); virtual State* GetInitialState() const; virtual State& GetCurrentState() const;//Machine is allways in some state void Reset(); void SinkTransitionEv(auto_ptr<EvHandler> eh);//raised on any transition void SinkTransitionNotFoundEv(auto_ptr<EvHandler> eh); void SinkFaultedEv(auto_ptr<EvHandler> eh); virtual ~StateMachine(); }; #endif
; ; jccolor.asm - colorspace conversion (MMX) ; ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB ; Copyright (C) 2009, 2016, D. R. Commander. ; ; Based on the x86 SIMD extension for IJG JPEG library ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; ; This file should be assembled with NASM (Netwide Assembler), ; can *not* be assembled with Microsoft's MASM or any compatible ; assembler (including Borland's Turbo Assembler). ; NASM is available from http://nasm.sourceforge.net/ or ; http://sourceforge.net/project/showfiles.php?group_id=6208 ; ; [TAB8] %include "jsimdext.inc" ; -------------------------------------------------------------------------- %define SCALEBITS 16 F_0_081 equ 5329 ; FIX(0.08131) F_0_114 equ 7471 ; FIX(0.11400) F_0_168 equ 11059 ; FIX(0.16874) F_0_250 equ 16384 ; FIX(0.25000) F_0_299 equ 19595 ; FIX(0.29900) F_0_331 equ 21709 ; FIX(0.33126) F_0_418 equ 27439 ; FIX(0.41869) F_0_587 equ 38470 ; FIX(0.58700) F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000) ; -------------------------------------------------------------------------- SECTION SEG_CONST alignz 32 GLOBAL_DATA(jconst_rgb_ycc_convert_mmx) EXTN(jconst_rgb_ycc_convert_mmx): PW_F0299_F0337 times 2 dw F_0_299, F_0_337 PW_F0114_F0250 times 2 dw F_0_114, F_0_250 PW_MF016_MF033 times 2 dw -F_0_168, -F_0_331 PW_MF008_MF041 times 2 dw -F_0_081, -F_0_418 PD_ONEHALFM1_CJ times 2 dd (1 << (SCALEBITS - 1)) - 1 + \ (CENTERJSAMPLE << SCALEBITS) PD_ONEHALF times 2 dd (1 << (SCALEBITS - 1)) alignz 32 ; -------------------------------------------------------------------------- SECTION SEG_TEXT BITS 32 %include "jccolext-mmx.asm" %undef RGB_RED %undef RGB_GREEN %undef RGB_BLUE %undef RGB_PIXELSIZE %define RGB_RED EXT_RGB_RED %define RGB_GREEN EXT_RGB_GREEN %define RGB_BLUE EXT_RGB_BLUE %define RGB_PIXELSIZE EXT_RGB_PIXELSIZE %define jsimd_rgb_ycc_convert_mmx jsimd_extrgb_ycc_convert_mmx %include "jccolext-mmx.asm" %undef RGB_RED %undef RGB_GREEN %undef RGB_BLUE %undef RGB_PIXELSIZE %define RGB_RED EXT_RGBX_RED %define RGB_GREEN EXT_RGBX_GREEN %define RGB_BLUE EXT_RGBX_BLUE %define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE %define jsimd_rgb_ycc_convert_mmx jsimd_extrgbx_ycc_convert_mmx %include "jccolext-mmx.asm" %undef RGB_RED %undef RGB_GREEN %undef RGB_BLUE %undef RGB_PIXELSIZE %define RGB_RED EXT_BGR_RED %define RGB_GREEN EXT_BGR_GREEN %define RGB_BLUE EXT_BGR_BLUE %define RGB_PIXELSIZE EXT_BGR_PIXELSIZE %define jsimd_rgb_ycc_convert_mmx jsimd_extbgr_ycc_convert_mmx %include "jccolext-mmx.asm" %undef RGB_RED %undef RGB_GREEN %undef RGB_BLUE %undef RGB_PIXELSIZE %define RGB_RED EXT_BGRX_RED %define RGB_GREEN EXT_BGRX_GREEN %define RGB_BLUE EXT_BGRX_BLUE %define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE %define jsimd_rgb_ycc_convert_mmx jsimd_extbgrx_ycc_convert_mmx %include "jccolext-mmx.asm" %undef RGB_RED %undef RGB_GREEN %undef RGB_BLUE %undef RGB_PIXELSIZE %define RGB_RED EXT_XBGR_RED %define RGB_GREEN EXT_XBGR_GREEN %define RGB_BLUE EXT_XBGR_BLUE %define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE %define jsimd_rgb_ycc_convert_mmx jsimd_extxbgr_ycc_convert_mmx %include "jccolext-mmx.asm" %undef RGB_RED %undef RGB_GREEN %undef RGB_BLUE %undef RGB_PIXELSIZE %define RGB_RED EXT_XRGB_RED %define RGB_GREEN EXT_XRGB_GREEN %define RGB_BLUE EXT_XRGB_BLUE %define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE %define jsimd_rgb_ycc_convert_mmx jsimd_extxrgb_ycc_convert_mmx %include "jccolext-mmx.asm"
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1992 -- All Rights Reserved PROJECT: PC GEOS MODULE: Specific Screen Saver -- Circles FILE: circles.asm AUTHOR: Gene, Mar 25, 1992 REVISION HISTORY: Name Date Description ---- ---- ----------- eca 3/23/92 Initial revision DESCRIPTION: This is a specific screen-saver library $Id: circles.asm,v 1.1 97/04/04 16:44:38 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ include stdapp.def include timer.def include initfile.def UseLib ui.def UseLib saver.def include circles.def ;============================================================================= ; ; CONSTANTS AND DATA TYPES ; ;============================================================================= CirclesApplicationClass class SaverApplicationClass MSG_CIRCLES_APP_DRAW message ; ; Draw the next circle. Sent by our timer. ; ; Pass: nothing ; Return: nothing ; SAI_interval word CIRCLES_DEFAULT_INTERVAL; SAI_numCircles word CIRCLES_DEFAULT_NUM; SAI_clearMode byte FALSE SAI_drawMode byte MM_COPY SAI_inColor byte CRC_RANDOM SAI_outColor byte CRC_NONE SAI_timerHandle hptr 0 noreloc SAI_timerHandle SAI_timerID word SAI_random hptr 0 noreloc SAI_random CirclesApplicationClass endc CirclesProcessClass class GenProcessClass CirclesProcessClass endc ;============================================================================= ; ; VARIABLES ; ;============================================================================= include circles.rdef ForceRef CirclesApp udata segment ; ; all our circles ; circles CircleGroupStruct <> ; ; Number of circles drawn ; numCircles word udata ends idata segment CirclesProcessClass mask CLASSF_NEVER_SAVED CirclesApplicationClass idata ends ;============================================================================= ; ; CODE ; ;============================================================================= CircleCode segment resource .warn -private circlesOptionTable SAOptionTable < circlesCategory, length circlesOptions > circlesOptions SAOptionDesc < circlesIntervalKey, size SAI_interval, offset SAI_interval >, < circlesNumCirclesKey, size SAI_numCircles, offset SAI_numCircles >, < circlesClearModeKey, size SAI_clearMode, offset SAI_clearMode >, < circlesDrawModeKey, size SAI_drawMode, offset SAI_drawMode >, < circlesInColorKey, size SAI_inColor, offset SAI_inColor >, < circlesOutColorKey, size SAI_outColor, offset SAI_outColor > .warn @private circlesCategory char 'circles', 0 circlesIntervalKey char 'interval', 0 circlesNumCirclesKey char 'number', 0 circlesClearModeKey char 'clearScreen', 0 circlesDrawModeKey char 'drawMode', 0 circlesInColorKey char 'inside', 0 circlesOutColorKey char 'outside', 0 COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CirclesLoadOptions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Load our options from the ini file. CALLED BY: MSG_META_LOAD_OPTIONS PASS: *ds:si = CirclesApplicationClass object RETURN: nothing DESTROYED: ax, cx, dx, bp PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- stevey 12/29/92 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CirclesLoadOptions method dynamic CirclesApplicationClass, MSG_META_LOAD_OPTIONS uses ax,es .enter segmov es, cs mov bx, offset circlesOptionTable call SaverApplicationGetOptions .leave mov di, offset CirclesApplicationClass GOTO ObjCallSuperNoLock CirclesLoadOptions endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CirclesAppSetWin %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Record the window and gstate to use and start things going. CALLED BY: MSG_SAVER_APP_SET_WIN PASS: *ds:si = CirclesApplicationClass object ds:di = CirclesApplicationClass instance data dx = window bp = gstate RETURN: nothing DESTROYED: ax, cx, dx, bp PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- stevey 12/29/92 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CirclesAppSetWin method dynamic CirclesApplicationClass, MSG_SAVER_APP_SET_WIN .enter ; ; Let the superclass do its little thing. ; mov di, offset CirclesApplicationClass call ObjCallSuperNoLock mov di, ds:[si] add di, ds:[di].CirclesApplication_offset ; ; Create a random number generator. ; call TimerGetCount mov dx, bx ; dxax <- seed clr bx ; bx <- allocate a new one call SaverSeedRandom mov ds:[di].SAI_random, bx mov dx, ds:[di].SAI_bounds.R_right sub dx, ds:[di].SAI_bounds.R_left mov es:[circles].CGS_width, dx mov dx, ds:[di].SAI_bounds.R_bottom sub dx, ds:[di].SAI_bounds.R_top mov es:[circles].CGS_height, dx ; ; Set the map mode ; push di mov di, ds:[di].SAI_curGState mov al, CMT_DITHER call GrSetAreaColorMap pop di ; ; Set drawing mode ; push di mov al, ds:[di].SAI_drawMode mov di, ds:[di].SAI_curGState call GrSetMixMode pop di ; ; Fetch the number of circles the user wants us to draw concurrently ; clr es:[numCircles] mov cx, ds:[di].SAI_numCircles mov es:[circles].CGS_numCircles, cx push si ; save CircleApp object clr si circleLoop: call InitCircle add si, size CircleStruct ; si <- offset to next circle loop circleLoop ; ; Start up the timer to draw a new circle. ; pop si ; *ds:si = CircleApp call CircleSetTimer .leave ret CirclesAppSetWin endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CirclesAppUnsetWin %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Stop saving the screen. CALLED BY: MSG_SAVER_APP_UNSET_WIN PASS: *ds:si = CirclesApplicationClass object ds:di = CirclesApplicationClass instance data RETURN: dx = old window bp = old gstate DESTROYED: ax, cx PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- stevey 12/29/92 initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CirclesAppUnsetWin method dynamic CirclesApplicationClass, MSG_SAVER_APP_UNSET_WIN ; ; Stop the draw timer. ; clr bx xchg bx, ds:[di].SAI_timerHandle mov ax, ds:[di].SAI_timerID call TimerStop ; ; Nuke the random number generator. ; clr bx xchg bx, ds:[di].SAI_random call SaverEndRandom ; ; Call our superclass to take care of the rest. ; mov ax, MSG_SAVER_APP_UNSET_WIN mov di, offset CirclesApplicationClass GOTO ObjCallSuperNoLock CirclesAppUnsetWin endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CirclesAppGetWinColor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Determines whether the screen should be cleared at first. CALLED BY: MSG_SAVER_APP_GET_WIN_COLOR PASS: *ds:si = CirclesApplicationClass object ds:di = CirclesApplicationClass instance data RETURN: ax = WinColorFlags DESTROYED: nothing PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- stevey 12/29/92 port to 2.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CirclesAppGetWinColor method dynamic CirclesApplicationClass, MSG_SAVER_APP_GET_WIN_COLOR ; ; Let the superclass do its little thing. ; mov di, offset CirclesApplicationClass call ObjCallSuperNoLock mov di, ds:[si] add di, ds:[di].CirclesApplication_offset cmp ds:[di].SAI_clearMode, TRUE je done ornf ah, mask WCF_TRANSPARENT done: ret CirclesAppGetWinColor endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CircleSetTimer %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Set a one-shot timer to draw the next circle. CALLED BY: CirclesAppDraw, CirclesAppSetWin PASS: *ds:si = CirclesApplicationObject RETURN: nothing DESTROYED: ax, bx, cx, dx PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- eca 6/28/92 Initial version stevey 12/29/92 port to 2.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CircleSetTimer proc near class CirclesApplicationClass uses di .enter mov di, ds:[si] add di, ds:[di].CirclesApplication_offset mov al, TIMER_EVENT_ONE_SHOT mov cx, CIRCLE_TIMER_SPEED mov dx, MSG_CIRCLES_APP_DRAW mov bx, ds:[LMBH_handle] ; ^lbx:si = destination call TimerStart mov ds:[di].SAI_timerHandle, bx mov ds:[di].SAI_timerID, ax .leave ret CircleSetTimer endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% InitCircle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Initialize one circle CALLED BY: CirclesAppDraw, CirclesAppSetWin PASS: es = dgroup si = offset of CircleStruct ds:[di] = CirclesApplicationInstance RETURN: nothing DESTROYED: ax, dx PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- eca 4/ 1/92 Initial version stevey 12/29/92 port to 2.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ InitCircle proc near class CirclesApplicationClass .enter mov bx, ds:[di].SAI_random ; ; Get random (x,y) position for circle ; mov dx, es:[circles].CGS_width call SaverRandom mov es:[circles].CGS_circles[si].CS_pos.P_x, dx mov dx, es:[circles].CGS_height call SaverRandom mov es:[circles].CGS_circles[si].CS_pos.P_y, dx ; ; Get random maximum size ; mov dx, (CIRCLE_MAX_SIZE - CIRCLE_MIN_MAX_SIZE) call SaverRandom add dx, CIRCLE_MIN_MAX_SIZE mov es:[circles].CGS_circles[si].CS_maxSize, dx ; ; Get random initial size ; mov dx, CIRCLE_MAX_INIT_SIZE call SaverRandom mov es:[circles].CGS_circles[si].CS_size, dx ; ; Set the inside color ; mov al, ds:[di].SAI_inColor cmp al, CRC_RANDOM jne gotInsideColor call PickAColor gotInsideColor: mov es:[circles].CGS_circles[si].CS_insideColor.CC_color, al ; ; Set the outside color ; mov al, ds:[di].SAI_outColor cmp al, CRC_RANDOM jne gotOutsideColor call PickAColor gotOutsideColor: mov es:[circles].CGS_circles[si].CS_outsideColor.CC_color, al ; ; One more circle drawn ; inc es:[numCircles] mov ax, es:[numCircles] cmp ax, ds:[di].SAI_interval ; enough circles drawn? jb done ; ; If we've drawn enough circles, clear the screen ; call ClearForMode clr es:[numCircles] done: .leave ret InitCircle endp ClearForMode proc near class CirclesApplicationClass uses ax .enter push di mov di, ds:[di].SAI_curGState mov al, MM_COPY call GrSetMixMode pop di mov ax, C_BLACK or (CF_INDEX shl 8) cmp ds:[di].SAI_drawMode, MM_AND jne doClear mov ax, C_WHITE or (CF_INDEX shl 8) doClear: call DoClear push di mov al, ds:[di].SAI_drawMode mov di, ds:[di].SAI_curGState call GrSetMixMode pop di .leave ret ClearForMode endp DoClear proc near class CirclesApplicationClass uses bx,cx,dx,si,di .enter mov di, ds:[di].SAI_curGState call GrSetAreaColor clr ax clr bx mov cx, es:[circles].CGS_width mov dx, es:[circles].CGS_height ;(ax,bx),(cx,dx) <- bounds mov si, SAVER_FADE_FAST_SPEED call SaverFadePatternFade .leave ret DoClear endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PickAColor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Pick a random color CALLED BY: INTERNAL PASS: ds:[di] = CirclesApplicationInstance RETURN: al - Color ah - CF_INDEX DESTROYED: nothing PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- eca 3/23/92 Initial version stevey 12/29/92 port to 2.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ PickAColor proc near class CirclesApplicationClass uses bx, dx .enter mov bx, ds:[di].SAI_random mov dx, 16 call SaverRandom mov al, dl ; al <- random color mov ah, CF_INDEX .leave ret PickAColor endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CalcCircleBounds %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Calculate circle bounds CALLED BY: DrawCircleOutside(), DrawCircleInside() PASS: (ax,bx) = center of circle dx = radius of circle RETURN: (ax,bx,cx,dx) = bounds of circle DESTROYED: nothing PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- eca 4/ 1/92 Initial version stevey 12/29/92 port to 2.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CalcCircleBounds proc near uses si .enter mov cx, ax ; cx <- y position add cx, dx ; cx <- right of circle sub ax, dx ; ax <- left of circle mov si, bx add bx, dx ; bx <- top of circle sub si, dx mov dx, si ; dx <- bottom of circle .leave ret CalcCircleBounds endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DrawCircleOutside %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draw outside of one circle CALLED BY: CirclesAppDraw PASS: ds:[di] = CirclesApplicationInstance (ax,bx) = center of circle dx = radius of circle es = dgroup si = offset to current CircleStruct RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- eca 4/ 1/92 Initial version stevey 12/29/92 port to 2.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DrawCircleOutside proc near class CirclesApplicationClass uses ax,bx,cx,dx,di .enter ; ; Draw the outside, if any ; cmp es:[circles].CGS_circles[si].CS_outsideColor.CC_random, CRC_NONE je noOutside call CalcCircleBounds push ax mov ah, CF_INDEX mov al, es:[circles].CGS_circles[si].CS_outsideColor.CC_color cmp al, CRC_VERY_RANDOM jne gotColor call PickAColor gotColor: mov di, ds:[di].SAI_curGState call GrSetLineColor pop ax call GrDrawEllipse noOutside: .leave ret DrawCircleOutside endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DrawCircleInside %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Draw inside of one circle CALLED BY: CirclesAppDraw PASS: ds:[di] = CirclesApplicationInstance (ax,bx) = center of circle dx = radius of circle es = dgroup si = offset to current CircleStruct RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- eca 4/ 1/92 Initial version stevey 12/29/92 port to 2.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DrawCircleInside proc near class CirclesApplicationClass uses ax,bx,cx,dx,di .enter ; ; Draw the inside, if any ; cmp es:[circles].CGS_circles[si].CS_insideColor.CC_random, CRC_NONE je noInside call CalcCircleBounds push ax mov ah, CF_INDEX mov al, es:[circles].CGS_circles[si].CS_insideColor.CC_color cmp al, CRC_VERY_RANDOM jne gotColor call PickAColor gotColor: mov di, ds:[di].SAI_curGState call GrSetAreaColor pop ax call GrFillEllipse noInside: .leave ret DrawCircleInside endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CirclesAppDraw %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Routine called to draw the circles CALLED BY: MSG_CIRCLES_APP_DRAW PASS: *ds:si = CirclesApplication object ds:[di] = CirclesApplication instance data es = dgroup RETURN: nothing DESTROYED: ax, cx, dx, bp PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- gene 3/25/92 Initial version stevey 12/29/92 port to 2.0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CirclesAppDraw method dynamic CirclesApplicationClass, MSG_CIRCLES_APP_DRAW .enter tst ds:[di].SAI_curGState LONG jz quit push si ; save *ds:si mov cx, es:[circles].CGS_numCircles ; cx <- # of circles clr si circleLoop: mov ax, es:[circles].CGS_circles[si].CS_pos.P_x mov bx, es:[circles].CGS_circles[si].CS_pos.P_y mov dx, es:[circles].CGS_circles[si].CS_size cmp dx, es:[circles].CGS_circles[si].CS_maxSize jae circleDone add dx, CIRCLE_CHANGE_RATE call DrawCircleOutside xchg dx, es:[circles].CGS_circles[si].CS_size call DrawCircleInside add si, size CircleStruct loop circleLoop nextDraw: pop si ; *ds:si = CircleApp call CircleSetTimer ; start timer for next draw quit: .leave ret circleDone: call DrawCircleInside ; one last draw (to erase) call InitCircle ; start a new circle jmp nextDraw CirclesAppDraw endm CircleCode ends
[org 0x0100] push _str push substr2 call findSubstr mov ax, 0x4c00 int 21h findSubstr: push bp mov bp,sp push ax push bx push cx push dx push si push di push es sub sp, 2 push word [bp+4] call strlen pop dx sub sp, 2 push word [bp+6] call strlen pop cx sub cx, dx add cx, 1 cmp cx, 0 jl not_found mov bx, [bp+4] mov al, [bx] mov bx, ds mov es, bx mov di, [bp+6] _main: repne scasb cmp cx, 0 je not_found push 0 push di push word [bp+4] call confirm_found pop dx cmp dx, 1 je found inc di dec cx jmp _main found: push msg1 jmp _end not_found: push msg2 _end: call print pop es pop di pop si pop dx pop cx pop bx pop ax pop bp ret 4 ;clear parameters strlen: push bp mov bp,sp push ax push bx push cx push dx push si push di push es mov cx, 0xffff mov ax, 0 mov bx, ds mov es, bx mov di, [bp+4] repne scasb mov ax, 0xffff sub ax, cx mov [bp+6], ax pop es pop di pop si pop dx pop cx pop bx pop ax pop bp ret 2 ;clear parameters confirm_found: push bp mov bp,sp push ax push bx push cx push dx push si push di push es sub sp, 2 push word [bp+4] call strlen pop cx dec cx mov si, [bp+6] mov bx, ds mov es, bx mov di, [bp+4] inc di repe cmpsb cmp cx, 0 jne __end mov word [bp+8], 1 __end: pop es pop di pop si pop dx pop cx pop bx pop ax pop bp ret 4 ;clear parameters print: push bp mov bp,sp push ax push bx push cx push dx push si push di push es mov bx, 0xb800 mov es, bx mov di, 0 sub sp, 2 push word [bp+4] call strlen pop cx dec cx cld mov si, 0 mov ah, 0x07 mov bx, [bp+4] main_print: mov al, [bx+si] stosw inc si loop main_print pop es pop di pop si pop dx pop cx pop bx pop ax pop bp ret 2 ;clear parameters _str: db 'Marry has a little lamb.',0 substr1: db 'lamb',0 ; findSubstr prints “Substring Found.” for this substring. substr2: db 'lame',0 ; findSubstr prints “Substring Not Found.” for this substring. msg1: db 'Substring Found.',0 msg2: db 'Substring Not Found.',0
<% from pwnlib.shellcraft.powerpc.linux import syscall %> <%page args="addr, length, advice"/> <%docstring> Invokes the syscall madvise. See 'man 2 madvise' for more information. Arguments: addr(void): addr len(size_t): len advice(int): advice </%docstring> ${syscall('SYS_madvise', addr, length, advice)}
; A070489: a(n) = n^3 mod 27. ; 0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0,19,26,0,1,8,0,10,17,0 pow $0,3 mod $0,27 mov $1,$0