text stringlengths 1 1.05M |
|---|
; A234740: Sum of the eleventh powers of the first n primes.
; 2048,179195,49007320,2026334063,287338004674,2079498398711,36351394706344,152841653604563,1105651411518490,13306161177224319,38714638073629150,216632259853089563,766961291569338004,1696255031040560711,4168414246124573014,13437450175496764611,43593338620234607270,87107256231670445931,209237389136638463014,440359681258340028285,754086366826699736662,1502080177354220665541,2789911595892306501808,5565084669659296842297,12718098700540100969050,23874782167193266520151,37717120874437722301198
lpb $0
mov $2,$0
sub $0,1
seq $2,79395 ; a(n) = prime(n)^11.
add $3,$2
lpe
mov $0,$3
add $0,2048
|
; A037566: Base 9 digits are, in order, the first n terms of the periodic sequence with initial period 2,2,1.
; Submitted by Jamie Morken(s4)
; 2,20,181,1631,14681,132130,1189172,10702550,96322951,866906561,7802159051,70219431460,631974883142,5687773948280,51189965534521,460709689810691,4146387208296221
add $0,1
mov $2,3
lpb $0
mov $3,$2
lpb $3
mod $0,30
add $2,1
mod $3,5
div $3,2
add $2,$3
add $4,1
lpe
sub $0,1
add $2,1
mul $4,9
lpe
mov $0,$4
sub $0,18
div $0,9
add $0,2
|
; A119651: Number of different values of exactly n standard American coins (pennies, nickels, dimes and quarters).
; 4,10,20,34,52,73,96,120,144,168,192,216,240,264,288,312,336,360,384,408,432,456,480,504,528,552,576,600,624,648,672,696,720,744,768,792,816,840,864,888,912,936,960,984,1008,1032,1056,1080,1104,1128,1152,1176,1200,1224,1248,1272,1296,1320,1344,1368,1392,1416,1440,1464,1488,1512,1536,1560,1584,1608,1632,1656,1680,1704,1728,1752,1776,1800,1824,1848,1872,1896,1920,1944,1968,1992,2016,2040,2064,2088,2112,2136,2160,2184,2208,2232,2256,2280,2304,2328,2352,2376,2400,2424,2448,2472,2496,2520,2544,2568,2592,2616,2640,2664,2688,2712,2736,2760,2784,2808,2832,2856,2880,2904,2928,2952,2976,3000,3024,3048,3072,3096,3120,3144,3168,3192,3216,3240,3264,3288,3312,3336,3360,3384,3408,3432,3456,3480,3504,3528,3552,3576,3600,3624,3648,3672,3696,3720,3744,3768,3792,3816,3840,3864,3888,3912,3936,3960,3984,4008,4032,4056,4080,4104,4128,4152,4176,4200,4224,4248,4272,4296,4320,4344,4368,4392,4416,4440,4464,4488,4512,4536,4560,4584,4608,4632,4656,4680,4704,4728,4752,4776,4800,4824,4848,4872,4896,4920,4944,4968,4992,5016,5040,5064,5088,5112,5136,5160,5184,5208,5232,5256,5280,5304,5328,5352,5376,5400,5424,5448,5472,5496,5520,5544,5568,5592,5616,5640,5664,5688,5712,5736,5760,5784,5808,5832,5856,5880,5904,5928
mov $17,$0
mov $19,$0
add $19,1
lpb $19
clr $0,17
mov $0,$17
sub $19,1
sub $0,$19
mov $14,$0
mov $16,$0
add $16,1
lpb $16
clr $0,14
mov $0,$14
sub $16,1
sub $0,$16
mov $1,$0
add $0,8
mov $3,$0
mov $0,5
mov $5,$3
sub $5,$1
trn $1,4
add $1,1
sub $0,$1
add $2,7
mov $8,$5
add $8,9
mov $6,$8
pow $6,2
add $2,$6
add $2,10
add $7,7
mov $10,$3
gcd $10,9
trn $10,$7
sub $0,$10
add $0,$2
mov $1,$0
trn $1,306
add $15,$1
lpe
add $18,$15
lpe
mov $1,$18
|
copyright zengfr site:http://github.com/zengfr/romhack
00042A move.l D1, (A0)+
00042C dbra D0, $42a
004D22 move.l D0, (A4)+
004D24 move.l D0, (A4)+
017FA4 move.w ($4f6,A5), D0
017FA8 lea ($10a,PC) ; ($180b4), A0
017FF6 clr.w ($4f6,A5) [base+5F0]
017FFA move.b ($777b,A5), D0
018282 clr.w ($4f6,A5)
018286 rts
0AAACA move.l (A0), D2
0AAACC move.w D0, (A0) [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, base+6FFE, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
0AAACE move.w D0, ($2,A0)
0AAAD2 cmp.l (A0), D0
0AAAD4 bne $aaafc
0AAAD8 move.l D2, (A0)+
0AAADA cmpa.l A0, A1 [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, base+6FFE, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
0AAAE6 move.l (A0), D2
0AAAE8 move.w D0, (A0) [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, base+6FFE, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
0AAAF4 move.l D2, (A0)+
0AAAF6 cmpa.l A0, A1 [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, base+6FFE, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
copyright zengfr site:http://github.com/zengfr/romhack
|
/*
-----------------------------------------------------------------------------
This source file is part of OGRE-Next
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2014 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#include "OgreStableHeaders.h"
#include "OgreHlmsPbs.h"
#include "OgreHlmsListener.h"
#include "OgreHlmsManager.h"
#include "OgreHlmsPbsDatablock.h"
#include "OgreLwString.h"
#if !OGRE_NO_JSON
# include "OgreHlmsJsonPbs.h"
#endif
#include "Animation/OgreSkeletonInstance.h"
#include "CommandBuffer/OgreCbShaderBuffer.h"
#include "CommandBuffer/OgreCbTexture.h"
#include "CommandBuffer/OgreCommandBuffer.h"
#include "Compositor/OgreCompositorShadowNode.h"
#include "Compositor/Pass/PassScene/OgreCompositorPassSceneDef.h"
#include "Cubemaps/OgreParallaxCorrectedCubemap.h"
#include "IrradianceField/OgreIrradianceField.h"
#include "OgreCamera.h"
#include "OgreForward3D.h"
#include "OgreHighLevelGpuProgram.h"
#include "OgreHighLevelGpuProgramManager.h"
#include "OgreIrradianceVolume.h"
#include "OgrePixelFormatGpuUtils.h"
#include "OgreRenderQueue.h"
#include "OgreRootLayout.h"
#include "OgreSceneManager.h"
#include "OgreTextureGpu.h"
#include "OgreTextureGpuManager.h"
#include "OgreViewport.h"
#include "Vao/OgreConstBufferPacked.h"
#include "Vao/OgreReadOnlyBufferPacked.h"
#include "Vao/OgreVaoManager.h"
#include "Vao/OgreVertexArrayObject.h"
#include "Vct/OgreVctLighting.h"
#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
# include "OgrePlanarReflections.h"
#endif
#include "OgreLogManager.h"
#include "OgreProfiler.h"
#include "OgreStackVector.h"
#define TODO_irradianceField_samplerblock
namespace Ogre
{
static const TextureGpuVec c_emptyTextureContainer;
const IdString PbsProperty::useLightBuffers = IdString( "use_light_buffers" );
const IdString PbsProperty::HwGammaRead = IdString( "hw_gamma_read" );
const IdString PbsProperty::HwGammaWrite = IdString( "hw_gamma_write" );
const IdString PbsProperty::MaterialsPerBuffer = IdString( "materials_per_buffer" );
const IdString PbsProperty::LowerGpuOverhead = IdString( "lower_gpu_overhead" );
const IdString PbsProperty::DebugPssmSplits = IdString( "debug_pssm_splits" );
const IdString PbsProperty::PerceptualRoughness = IdString( "perceptual_roughness" );
const IdString PbsProperty::HasPlanarReflections = IdString( "has_planar_reflections" );
const IdString PbsProperty::Set0TextureSlotEnd = IdString( "set0_texture_slot_end" );
const IdString PbsProperty::Set1TextureSlotEnd = IdString( "set1_texture_slot_end" );
const IdString PbsProperty::NumTextures = IdString( "num_textures" );
const IdString PbsProperty::NumSamplers = IdString( "num_samplers" );
const IdString PbsProperty::DiffuseMapGrayscale = IdString( "diffuse_map_grayscale" );
const IdString PbsProperty::EmissiveMapGrayscale = IdString( "emissive_map_grayscale" );
const char *PbsProperty::DiffuseMap = "diffuse_map";
const char *PbsProperty::NormalMapTex = "normal_map_tex";
const char *PbsProperty::SpecularMap = "specular_map";
const char *PbsProperty::RoughnessMap = "roughness_map";
const char *PbsProperty::EmissiveMap = "emissive_map";
const char *PbsProperty::EnvProbeMap = "envprobe_map";
const char *PbsProperty::DetailWeightMap = "detail_weight_map";
const char *PbsProperty::DetailMapN = "detail_map"; // detail_map0-4
const char *PbsProperty::DetailMapNmN = "detail_map_nm"; // detail_map_nm0-4
const IdString PbsProperty::DetailMap0 = "detail_map0";
const IdString PbsProperty::DetailMap1 = "detail_map1";
const IdString PbsProperty::DetailMap2 = "detail_map2";
const IdString PbsProperty::DetailMap3 = "detail_map3";
const IdString PbsProperty::NormalMap = IdString( "normal_map" );
const IdString PbsProperty::FresnelScalar = IdString( "fresnel_scalar" );
const IdString PbsProperty::UseTextureAlpha = IdString( "use_texture_alpha" );
const IdString PbsProperty::TransparentMode = IdString( "transparent_mode" );
const IdString PbsProperty::FresnelWorkflow = IdString( "fresnel_workflow" );
const IdString PbsProperty::MetallicWorkflow = IdString( "metallic_workflow" );
const IdString PbsProperty::TwoSidedLighting = IdString( "two_sided_lighting" );
const IdString PbsProperty::ReceiveShadows = IdString( "receive_shadows" );
const IdString PbsProperty::UsePlanarReflections = IdString( "use_planar_reflections" );
const IdString PbsProperty::NormalSamplingFormat = IdString( "normal_sampling_format" );
const IdString PbsProperty::NormalLa = IdString( "normal_la" );
const IdString PbsProperty::NormalRgUnorm = IdString( "normal_rg_unorm" );
const IdString PbsProperty::NormalRgSnorm = IdString( "normal_rg_snorm" );
const IdString PbsProperty::NormalBc3Unorm = IdString( "normal_bc3_unorm" );
const IdString PbsProperty::NormalWeight = IdString( "normal_weight" );
const IdString PbsProperty::NormalWeightTex = IdString( "normal_weight_tex" );
const IdString PbsProperty::NormalWeightDetail0 = IdString( "normal_weight_detail0" );
const IdString PbsProperty::NormalWeightDetail1 = IdString( "normal_weight_detail1" );
const IdString PbsProperty::NormalWeightDetail2 = IdString( "normal_weight_detail2" );
const IdString PbsProperty::NormalWeightDetail3 = IdString( "normal_weight_detail3" );
const IdString PbsProperty::DetailWeights = IdString( "detail_weights" );
const IdString PbsProperty::DetailOffsets0 = IdString( "detail_offsets0" );
const IdString PbsProperty::DetailOffsets1 = IdString( "detail_offsets1" );
const IdString PbsProperty::DetailOffsets2 = IdString( "detail_offsets2" );
const IdString PbsProperty::DetailOffsets3 = IdString( "detail_offsets3" );
const IdString PbsProperty::UvDiffuse = IdString( "uv_diffuse" );
const IdString PbsProperty::UvNormal = IdString( "uv_normal" );
const IdString PbsProperty::UvSpecular = IdString( "uv_specular" );
const IdString PbsProperty::UvRoughness = IdString( "uv_roughness" );
const IdString PbsProperty::UvDetailWeight = IdString( "uv_detail_weight" );
const IdString PbsProperty::UvDetail0 = IdString( "uv_detail0" );
const IdString PbsProperty::UvDetail1 = IdString( "uv_detail1" );
const IdString PbsProperty::UvDetail2 = IdString( "uv_detail2" );
const IdString PbsProperty::UvDetail3 = IdString( "uv_detail3" );
const IdString PbsProperty::UvDetailNm0 = IdString( "uv_detail_nm0" );
const IdString PbsProperty::UvDetailNm1 = IdString( "uv_detail_nm1" );
const IdString PbsProperty::UvDetailNm2 = IdString( "uv_detail_nm2" );
const IdString PbsProperty::UvDetailNm3 = IdString( "uv_detail_nm3" );
const IdString PbsProperty::UvEmissive = IdString( "uv_emissive" );
const IdString PbsProperty::BlendModeIndex0 = IdString( "blend_mode_idx0" );
const IdString PbsProperty::BlendModeIndex1 = IdString( "blend_mode_idx1" );
const IdString PbsProperty::BlendModeIndex2 = IdString( "blend_mode_idx2" );
const IdString PbsProperty::BlendModeIndex3 = IdString( "blend_mode_idx3" );
const IdString PbsProperty::DetailMapsDiffuse = IdString( "detail_maps_diffuse" );
const IdString PbsProperty::DetailMapsNormal = IdString( "detail_maps_normal" );
const IdString PbsProperty::FirstValidDetailMapNm = IdString( "first_valid_detail_map_nm" );
const IdString PbsProperty::EmissiveConstant = IdString( "emissive_constant" );
const IdString PbsProperty::EmissiveAsLightmap = IdString( "emissive_as_lightmap" );
const IdString PbsProperty::Pcf = IdString( "pcf" );
const IdString PbsProperty::PcfIterations = IdString( "pcf_iterations" );
const IdString PbsProperty::ShadowsReceiveOnPs = IdString( "shadows_receive_on_ps" );
const IdString PbsProperty::ExponentialShadowMaps = IdString( "exponential_shadow_maps" );
const IdString PbsProperty::EnvMapScale = IdString( "envmap_scale" );
const IdString PbsProperty::LightProfilesTexture = IdString( "light_profiles_texture" );
const IdString PbsProperty::LtcTextureAvailable = IdString( "ltc_texture_available" );
const IdString PbsProperty::AmbientFixed = IdString( "ambient_fixed" );
const IdString PbsProperty::AmbientHemisphere = IdString( "ambient_hemisphere" );
const IdString PbsProperty::AmbientSh = IdString( "ambient_sh" );
const IdString PbsProperty::AmbientShMonochrome = IdString( "ambient_sh_monochrome" );
const IdString PbsProperty::TargetEnvprobeMap = IdString( "target_envprobe_map" );
const IdString PbsProperty::ParallaxCorrectCubemaps = IdString( "parallax_correct_cubemaps" );
const IdString PbsProperty::UseParallaxCorrectCubemaps = IdString( "use_parallax_correct_cubemaps" );
const IdString PbsProperty::EnableCubemapsAuto = IdString( "hlms_enable_cubemaps_auto" );
const IdString PbsProperty::CubemapsUseDpm = IdString( "hlms_cubemaps_use_dpm" );
const IdString PbsProperty::CubemapsAsDiffuseGi = IdString( "cubemaps_as_diffuse_gi" );
const IdString PbsProperty::IrradianceVolumes = IdString( "irradiance_volumes" );
const IdString PbsProperty::VctNumProbes = IdString( "vct_num_probes" );
const IdString PbsProperty::VctConeDirs = IdString( "vct_cone_dirs" );
const IdString PbsProperty::VctDisableDiffuse = IdString( "vct_disable_diffuse" );
const IdString PbsProperty::VctDisableSpecular = IdString( "vct_disable_specular" );
const IdString PbsProperty::VctAnisotropic = IdString( "vct_anisotropic" );
const IdString PbsProperty::VctEnableSpecularSdfQuality =
IdString( "vct_enable_specular_sdf_quality" );
const IdString PbsProperty::VctAmbientSphere = IdString( "vct_ambient_hemisphere" );
const IdString PbsProperty::IrradianceField = IdString( "irradiance_field" );
const IdString PbsProperty::ObbRestraintApprox = IdString( "obb_restraint_approx" );
const IdString PbsProperty::ObbRestraintLtc = IdString( "obb_restraint_ltc" );
const IdString PbsProperty::BrdfDefault = IdString( "BRDF_Default" );
const IdString PbsProperty::BrdfCookTorrance = IdString( "BRDF_CookTorrance" );
const IdString PbsProperty::BrdfBlinnPhong = IdString( "BRDF_BlinnPhong" );
const IdString PbsProperty::FresnelSeparateDiffuse = IdString( "fresnel_separate_diffuse" );
const IdString PbsProperty::GgxHeightCorrelated = IdString( "GGX_height_correlated" );
const IdString PbsProperty::ClearCoat = IdString( "clear_coat" );
const IdString PbsProperty::LegacyMathBrdf = IdString( "legacy_math_brdf" );
const IdString PbsProperty::RoughnessIsShininess = IdString( "roughness_is_shininess" );
const IdString PbsProperty::UseEnvProbeMap = IdString( "use_envprobe_map" );
const IdString PbsProperty::NeedsViewDir = IdString( "needs_view_dir" );
const IdString PbsProperty::NeedsReflDir = IdString( "needs_refl_dir" );
const IdString PbsProperty::NeedsEnvBrdf = IdString( "needs_env_brdf" );
// clang-format off
const IdString *PbsProperty::UvSourcePtrs[NUM_PBSM_SOURCES] =
{
&PbsProperty::UvDiffuse,
&PbsProperty::UvNormal,
&PbsProperty::UvSpecular,
&PbsProperty::UvRoughness,
&PbsProperty::UvDetailWeight,
&PbsProperty::UvDetail0,
&PbsProperty::UvDetail1,
&PbsProperty::UvDetail2,
&PbsProperty::UvDetail3,
&PbsProperty::UvDetailNm0,
&PbsProperty::UvDetailNm1,
&PbsProperty::UvDetailNm2,
&PbsProperty::UvDetailNm3,
&PbsProperty::UvEmissive,
};
const IdString *PbsProperty::DetailNormalWeights[4] =
{
&PbsProperty::NormalWeightDetail0,
&PbsProperty::NormalWeightDetail1,
&PbsProperty::NormalWeightDetail2,
&PbsProperty::NormalWeightDetail3
};
const IdString *PbsProperty::DetailOffsetsPtrs[4] =
{
&PbsProperty::DetailOffsets0,
&PbsProperty::DetailOffsets1,
&PbsProperty::DetailOffsets2,
&PbsProperty::DetailOffsets3
};
const IdString *PbsProperty::BlendModes[4] =
{
&PbsProperty::BlendModeIndex0,
&PbsProperty::BlendModeIndex1,
&PbsProperty::BlendModeIndex2,
&PbsProperty::BlendModeIndex3
};
// clang-format on
extern const String c_pbsBlendModes[];
HlmsPbs::HlmsPbs( Archive *dataFolder, ArchiveVec *libraryFolders ) :
HlmsBufferManager( HLMS_PBS, "pbs", dataFolder, libraryFolders ),
ConstBufferPool( HlmsPbsDatablock::MaterialSizeInGpuAligned,
ConstBufferPool::ExtraBufferParams() ),
mShadowmapSamplerblock( 0 ),
mShadowmapCmpSamplerblock( 0 ),
mShadowmapEsmSamplerblock( 0 ),
mCurrentShadowmapSamplerblock( 0 ),
mParallaxCorrectedCubemap( 0 ),
mPccVctMinDistance( 1.0f ),
mInvPccVctInvDistance( 1.0f ),
mCurrentPassBuffer( 0 ),
mGridBuffer( 0 ),
mGlobalLightListBuffer( 0 ),
mMaxSpecIblMipmap( 1.0f ),
mTexBufUnitSlotEnd( 0u ),
mTexUnitSlotStart( 0 ),
mPrePassTextures( 0 ),
mDepthTexture( 0 ),
mSsrTexture( 0 ),
mDepthTextureNoMsaa( 0 ),
mRefractionsTexture( 0 ),
mIrradianceVolume( 0 ),
mVctLighting( 0 ),
mIrradianceField( 0 ),
#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
mPlanarReflections( 0 ),
mPlanarReflectionsSamplerblock( 0 ),
mHasPlanarReflections( false ),
mLastBoundPlanarReflection( 0u ),
#endif
mAreaLightMasks( 0 ),
mAreaLightMasksSamplerblock( 0 ),
mUsingAreaLightMasks( false ),
mLightProfilesTexture( 0 ),
mSkipRequestSlotInChangeRS( false ),
mLtcMatrixTexture( 0 ),
mDecalsDiffuseMergedEmissive( false ),
mDecalsSamplerblock( 0 ),
mLastBoundPool( 0 ),
mConstantBiasScale( 0.1f ),
mHasSeparateSamplers( 0 ),
mLastDescTexture( 0 ),
mLastDescSampler( 0 ),
mReservedTexBufferSlots( 1u ), // Vertex shader consumes 1 slot with its tbuffer.
mReservedTexSlots( 0u ),
#if !OGRE_NO_FINE_LIGHT_MASK_GRANULARITY
mFineLightMaskGranularity( true ),
#endif
mSetupWorldMatBuf( true ),
mDebugPssmSplits( false ),
mShadowReceiversInPixelShader( false ),
mPerceptualRoughness( true ),
mAutoSpecIblMaxMipmap( true ),
mVctFullConeCount( false ),
#if OGRE_ENABLE_LIGHT_OBB_RESTRAINT
mUseObbRestraintAreaApprox( false ),
mUseObbRestraintAreaLtc( false ),
#endif
mUseLightBuffers( false ),
mShadowFilter( PCF_3x3 ),
mEsmK( 600u ),
mAmbientLightMode( AmbientAuto )
{
memset( mDecalsTextures, 0, sizeof( mDecalsTextures ) );
// Override defaults
mLightGatheringMode = LightGatherForwardPlus;
}
//-----------------------------------------------------------------------------------
HlmsPbs::~HlmsPbs() { destroyAllBuffers(); }
//-----------------------------------------------------------------------------------
void HlmsPbs::_changeRenderSystem( RenderSystem *newRs )
{
ConstBufferPool::_changeRenderSystem( newRs );
HlmsBufferManager::_changeRenderSystem( newRs );
if( newRs )
{
if( !mSkipRequestSlotInChangeRS )
{
HlmsDatablockMap::const_iterator itor = mDatablocks.begin();
HlmsDatablockMap::const_iterator end = mDatablocks.end();
while( itor != end )
{
assert( dynamic_cast<HlmsPbsDatablock *>( itor->second.datablock ) );
HlmsPbsDatablock *datablock =
static_cast<HlmsPbsDatablock *>( itor->second.datablock );
requestSlot( datablock->mTextureHash, datablock, false );
++itor;
}
}
const ColourValue maxValBorder =
ColourValue( std::numeric_limits<float>::max(), std::numeric_limits<float>::max(),
std::numeric_limits<float>::max(), std::numeric_limits<float>::max() );
const ColourValue pitchBlackBorder = ColourValue( 0, 0, 0, 0 );
HlmsSamplerblock samplerblock;
samplerblock.mU = TAM_BORDER;
samplerblock.mV = TAM_BORDER;
samplerblock.mW = TAM_CLAMP;
if( !mRenderSystem->isReverseDepth() )
samplerblock.mBorderColour = maxValBorder;
else
samplerblock.mBorderColour = pitchBlackBorder;
if( mShaderProfile != "hlsl" && mShaderProfile != "hlslvk" )
{
samplerblock.mMinFilter = FO_POINT;
samplerblock.mMagFilter = FO_POINT;
samplerblock.mMipFilter = FO_NONE;
if( !mShadowmapSamplerblock )
mShadowmapSamplerblock = mHlmsManager->getSamplerblock( samplerblock );
}
if( !mShadowmapEsmSamplerblock )
{
samplerblock.mMinFilter = FO_LINEAR;
samplerblock.mMagFilter = FO_LINEAR;
samplerblock.mMipFilter = FO_NONE;
// ESM uses standard linear Z in range [0; 1], thus we need a different border colour
const ColourValue oldValue = samplerblock.mBorderColour;
samplerblock.mBorderColour = maxValBorder;
mShadowmapEsmSamplerblock = mHlmsManager->getSamplerblock( samplerblock );
// Restore border colour
samplerblock.mBorderColour = oldValue;
}
samplerblock.mMinFilter = FO_LINEAR;
samplerblock.mMagFilter = FO_LINEAR;
samplerblock.mMipFilter = FO_NONE;
samplerblock.mCompareFunction = CMPF_LESS_EQUAL;
if( mRenderSystem->isReverseDepth() )
{
samplerblock.mCompareFunction =
RenderSystem::reverseCompareFunction( samplerblock.mCompareFunction );
}
if( !mShadowmapCmpSamplerblock )
mShadowmapCmpSamplerblock = mHlmsManager->getSamplerblock( samplerblock );
#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
if( !mPlanarReflectionsSamplerblock )
{
samplerblock.mMinFilter = FO_LINEAR;
samplerblock.mMagFilter = FO_LINEAR;
samplerblock.mMipFilter = FO_LINEAR;
samplerblock.mCompareFunction = NUM_COMPARE_FUNCTIONS;
samplerblock.mU = TAM_CLAMP;
samplerblock.mV = TAM_CLAMP;
samplerblock.mW = TAM_CLAMP;
mPlanarReflectionsSamplerblock = mHlmsManager->getSamplerblock( samplerblock );
}
#endif
if( !mAreaLightMasksSamplerblock )
{
samplerblock.mMinFilter = FO_LINEAR;
samplerblock.mMagFilter = FO_LINEAR;
samplerblock.mMipFilter = FO_LINEAR;
samplerblock.mCompareFunction = NUM_COMPARE_FUNCTIONS;
samplerblock.mU = TAM_CLAMP;
samplerblock.mV = TAM_CLAMP;
samplerblock.mW = TAM_CLAMP;
mAreaLightMasksSamplerblock = mHlmsManager->getSamplerblock( samplerblock );
}
if( !mDecalsSamplerblock )
{
samplerblock.mMinFilter = FO_LINEAR;
samplerblock.mMagFilter = FO_LINEAR;
samplerblock.mMipFilter = FO_LINEAR;
samplerblock.mCompareFunction = NUM_COMPARE_FUNCTIONS;
samplerblock.mU = TAM_CLAMP;
samplerblock.mV = TAM_CLAMP;
samplerblock.mW = TAM_CLAMP;
mDecalsSamplerblock = mHlmsManager->getSamplerblock( samplerblock );
}
const RenderSystemCapabilities *caps = newRs->getCapabilities();
mHasSeparateSamplers = caps->hasCapability( RSC_SEPARATE_SAMPLERS_FROM_TEXTURES );
}
}
//-----------------------------------------------------------------------------------
void HlmsPbs::setupRootLayout( RootLayout &rootLayout )
{
DescBindingRange *descBindingRanges = rootLayout.mDescBindingRanges[0];
if( getProperty( PbsProperty::useLightBuffers ) )
descBindingRanges[DescBindingTypes::ConstBuffer].end = 7u;
else
{
// PccManualProbeDecl piece uses more conditionals to whether use a 4th const buffer
// However we don't need to test them all. It's ok to have false positives
// (it just wastes a little bit more memory)
if( getProperty( PbsProperty::UseParallaxCorrectCubemaps ) &&
!getProperty( PbsProperty::EnableCubemapsAuto ) )
{
descBindingRanges[DescBindingTypes::ConstBuffer].end = 4u;
}
else
descBindingRanges[DescBindingTypes::ConstBuffer].end = 3u;
}
if( mSetupWorldMatBuf )
{
descBindingRanges[DescBindingTypes::ReadOnlyBuffer].start = 0u;
descBindingRanges[DescBindingTypes::ReadOnlyBuffer].end = 1u;
}
else
{
descBindingRanges[DescBindingTypes::ReadOnlyBuffer].start = 0u;
descBindingRanges[DescBindingTypes::ReadOnlyBuffer].end = 0u;
}
// if( getProperty( HlmsBaseProp::Pose ) )
// descBindingRanges[DescBindingTypes::TexBuffer].end = 4u;
// else
{
if( getProperty( HlmsBaseProp::ForwardPlus ) )
{
descBindingRanges[DescBindingTypes::ReadOnlyBuffer].end =
(uint16)getProperty( "f3dLightList" ) + 1u;
descBindingRanges[DescBindingTypes::TexBuffer].start = (uint16)getProperty( "f3dGrid" );
descBindingRanges[DescBindingTypes::TexBuffer].end =
descBindingRanges[DescBindingTypes::TexBuffer].start + 1u;
}
}
// It's not a typo: we start Texture where max( ReadOnlyBuffer, TexBuffer ) left off
// because we treat ReadOnly buffers numbering as if they all were texbuffer slots
// (in terms of contiguity)
if( descBindingRanges[DescBindingTypes::ReadOnlyBuffer].isInUse() )
{
descBindingRanges[DescBindingTypes::Texture].start =
descBindingRanges[DescBindingTypes::ReadOnlyBuffer].end;
}
if( descBindingRanges[DescBindingTypes::TexBuffer].isInUse() )
{
descBindingRanges[DescBindingTypes::Texture].start =
std::max( descBindingRanges[DescBindingTypes::Texture].end,
descBindingRanges[DescBindingTypes::TexBuffer].end );
}
descBindingRanges[DescBindingTypes::Texture].end =
(uint16)getProperty( PbsProperty::Set0TextureSlotEnd );
descBindingRanges[DescBindingTypes::Sampler].start =
descBindingRanges[DescBindingTypes::Texture].start;
descBindingRanges[DescBindingTypes::Sampler].end =
(uint16)( getProperty( "samplerStateStart" ) );
rootLayout.mBaked[1] = true;
DescBindingRange *bakedRanges = rootLayout.mDescBindingRanges[1];
bakedRanges[DescBindingTypes::Texture].start = descBindingRanges[DescBindingTypes::Texture].end;
bakedRanges[DescBindingTypes::Texture].end =
(uint16)getProperty( PbsProperty::Set1TextureSlotEnd );
bakedRanges[DescBindingTypes::Sampler].start = descBindingRanges[DescBindingTypes::Sampler].end;
bakedRanges[DescBindingTypes::Sampler].end = bakedRanges[DescBindingTypes::Sampler].start +
(uint16)getProperty( PbsProperty::NumSamplers );
int32 poseBufReg = getProperty( "poseBuf", -1 );
if( poseBufReg >= 0 )
{
DescBindingRange *poseRanges = rootLayout.mDescBindingRanges[2];
if( !bakedRanges[DescBindingTypes::Texture].isInUse() &&
!bakedRanges[DescBindingTypes::Sampler].isInUse() )
{
poseRanges = rootLayout.mDescBindingRanges[1];
rootLayout.mBaked[1] = false;
}
poseRanges[DescBindingTypes::TexBuffer].start = static_cast<uint16>( poseBufReg );
poseRanges[DescBindingTypes::TexBuffer].end = static_cast<uint16>( poseBufReg + 1 );
}
const int32 numVctProbes = getProperty( PbsProperty::VctNumProbes );
if( numVctProbes > 1 )
{
int32 vctProbeIdx = getProperty( "vctProbes" );
rootLayout.addArrayBinding( DescBindingTypes::Texture,
RootLayout::ArrayDesc( static_cast<uint16>( vctProbeIdx ),
static_cast<uint16>( numVctProbes ) ) );
if( getProperty( PbsProperty::VctAnisotropic ) )
{
for( int32 i = 0; i < 3; ++i )
{
vctProbeIdx += numVctProbes;
rootLayout.addArrayBinding(
DescBindingTypes::Texture,
RootLayout::ArrayDesc( static_cast<uint16>( vctProbeIdx ),
static_cast<uint16>( numVctProbes ) ) );
}
}
}
mListener->setupRootLayout( rootLayout, mSetProperties );
}
//-----------------------------------------------------------------------------------
const HlmsCache *HlmsPbs::createShaderCacheEntry( uint32 renderableHash, const HlmsCache &passCache,
uint32 finalHash,
const QueuedRenderable &queuedRenderable )
{
OgreProfileExhaustive( "HlmsPbs::createShaderCacheEntry" );
const HlmsCache *retVal =
Hlms::createShaderCacheEntry( renderableHash, passCache, finalHash, queuedRenderable );
if( mShaderProfile != "glsl" )
{
mListener->shaderCacheEntryCreated( mShaderProfile, retVal, passCache, mSetProperties,
queuedRenderable );
return retVal; // D3D embeds the texture slots in the shader.
}
GpuProgramParametersSharedPtr vsParams = retVal->pso.vertexShader->getDefaultParameters();
if( mSetupWorldMatBuf && mVaoManager->readOnlyIsTexBuffer() )
vsParams->setNamedConstant( "worldMatBuf", 0 );
mListener->shaderCacheEntryCreated( mShaderProfile, retVal, passCache, mSetProperties,
queuedRenderable );
mRenderSystem->_setPipelineStateObject( &retVal->pso );
mRenderSystem->bindGpuProgramParameters( GPT_VERTEX_PROGRAM, vsParams, GPV_ALL );
if( retVal->pso.pixelShader )
{
GpuProgramParametersSharedPtr psParams = retVal->pso.pixelShader->getDefaultParameters();
mRenderSystem->bindGpuProgramParameters( GPT_FRAGMENT_PROGRAM, psParams, GPV_ALL );
}
if( !mRenderSystem->getCapabilities()->hasCapability( RSC_CONST_BUFFER_SLOTS_IN_SHADER ) )
{
// Setting it to the vertex shader will set it to the PSO actually.
retVal->pso.vertexShader->setUniformBlockBinding( "PassBuffer", 0 );
retVal->pso.vertexShader->setUniformBlockBinding( "MaterialBuf", 1 );
retVal->pso.vertexShader->setUniformBlockBinding( "InstanceBuffer", 2 );
}
return retVal;
}
//-----------------------------------------------------------------------------------
void HlmsPbs::setDetailMapProperties( HlmsPbsDatablock *datablock, PiecesMap *inOutPieces,
const bool bCasterPass )
{
int32 minNormalMap = 4;
bool hasDiffuseMaps = false;
bool hasNormalMaps = false;
bool anyDetailWeight = false;
for( int32 i = 0; i < 4; ++i )
{
uint8 blendMode = datablock->mBlendModes[i];
const uint8 idx = static_cast<uint8>( i );
setDetailTextureProperty( PbsProperty::DetailMapN, datablock, PBSM_DETAIL0, idx );
if( !bCasterPass )
setDetailTextureProperty( PbsProperty::DetailMapNmN, datablock, PBSM_DETAIL0_NM, idx );
if( datablock->getTexture( PBSM_DETAIL0 + idx ) )
{
inOutPieces[PixelShader][*PbsProperty::BlendModes[i]] =
"@insertpiece( " + c_pbsBlendModes[blendMode] + ")";
hasDiffuseMaps = true;
}
if( !bCasterPass && datablock->getTexture( PBSM_DETAIL0_NM + idx ) )
{
minNormalMap = std::min<int32>( minNormalMap, i );
hasNormalMaps = true;
}
if( datablock->getDetailMapOffsetScale( idx ) != Vector4( 0, 0, 1, 1 ) )
setProperty( *PbsProperty::DetailOffsetsPtrs[i], 1 );
if( datablock->mDetailWeight[i] != 1.0f &&
( datablock->getTexture( static_cast<uint8>( PBSM_DETAIL0 + i ) ) ||
( !bCasterPass &&
datablock->getTexture( static_cast<uint8>( PBSM_DETAIL0_NM + i ) ) ) ) )
{
anyDetailWeight = true;
}
}
if( hasDiffuseMaps )
setProperty( PbsProperty::DetailMapsDiffuse, 4 );
if( hasNormalMaps )
setProperty( PbsProperty::DetailMapsNormal, 4 );
setProperty( PbsProperty::FirstValidDetailMapNm, minNormalMap );
if( anyDetailWeight )
setProperty( PbsProperty::DetailWeights, 1 );
}
//-----------------------------------------------------------------------------------
void HlmsPbs::setTextureProperty( const char *propertyName, HlmsPbsDatablock *datablock,
PbsTextureTypes texType )
{
uint8 idx = datablock->getIndexToDescriptorTexture( texType );
if( idx != NUM_PBSM_TEXTURE_TYPES )
{
char tmpData[64];
LwString propName = LwString::FromEmptyPointer( tmpData, sizeof( tmpData ) );
propName = propertyName; // diffuse_map
const size_t basePropSize = propName.size(); // diffuse_map
// In the template the we subtract the "+1" for the index.
// We need to increment it now otherwise @property( diffuse_map )
// can translate to @property( 0 ) which is not what we want.
setProperty( propertyName, idx + 1 );
propName.resize( basePropSize );
propName.a( "_idx" ); // diffuse_map_idx
setProperty( propName.c_str(), idx );
if( mHasSeparateSamplers )
{
const uint8 samplerIdx = datablock->getIndexToDescriptorSampler( texType );
propName.resize( basePropSize );
propName.a( "_sampler" ); // diffuse_map_sampler
setProperty( propName.c_str(), samplerIdx );
}
}
}
//-----------------------------------------------------------------------------------
void HlmsPbs::setDetailTextureProperty( const char *propertyName, HlmsPbsDatablock *datablock,
PbsTextureTypes baseTexType, uint8 detailIdx )
{
const PbsTextureTypes texType = static_cast<PbsTextureTypes>( baseTexType + detailIdx );
char tmpData[32];
LwString propName = LwString::FromEmptyPointer( tmpData, sizeof( tmpData ) );
propName.a( propertyName, detailIdx ); // detail_map0
setTextureProperty( propName.c_str(), datablock, texType );
}
//-----------------------------------------------------------------------------------
void HlmsPbs::calculateHashFor( Renderable *renderable, uint32 &outHash, uint32 &outCasterHash )
{
assert( dynamic_cast<HlmsPbsDatablock *>( renderable->getDatablock() ) );
HlmsPbsDatablock *datablock = static_cast<HlmsPbsDatablock *>( renderable->getDatablock() );
if( datablock->getDirtyFlags() & ( DirtyTextures | DirtySamplers ) )
{
// Delay hash generation for later, when we have the final (or temporary) descriptor sets.
outHash = 0;
outCasterHash = 0;
}
else
{
Hlms::calculateHashFor( renderable, outHash, outCasterHash );
}
datablock->loadAllTextures();
}
//-----------------------------------------------------------------------------------
void HlmsPbs::calculateHashForPreCreate( Renderable *renderable, PiecesMap *inOutPieces )
{
assert( dynamic_cast<HlmsPbsDatablock *>( renderable->getDatablock() ) );
HlmsPbsDatablock *datablock = static_cast<HlmsPbsDatablock *>( renderable->getDatablock() );
const bool metallicWorkflow = datablock->getWorkflow() == HlmsPbsDatablock::MetallicWorkflow;
const bool fresnelWorkflow =
datablock->getWorkflow() == HlmsPbsDatablock::SpecularAsFresnelWorkflow;
setProperty( PbsProperty::FresnelScalar, datablock->hasSeparateFresnel() || metallicWorkflow );
setProperty( PbsProperty::FresnelWorkflow, fresnelWorkflow );
setProperty( PbsProperty::MetallicWorkflow, metallicWorkflow );
if( datablock->getTwoSidedLighting() )
setProperty( PbsProperty::TwoSidedLighting, 1 );
if( datablock->getReceiveShadows() )
setProperty( PbsProperty::ReceiveShadows, 1 );
if( datablock->mTransparencyMode == HlmsPbsDatablock::Refractive )
{
setProperty( HlmsBaseProp::ScreenSpaceRefractions, 1 );
setProperty( HlmsBaseProp::VPos, 1 );
setProperty( HlmsBaseProp::ScreenPosInt, 1 );
setProperty( HlmsBaseProp::ScreenPosUv, 1 );
}
if( !getProperty( HlmsBaseProp::QTangent ) && !getProperty( HlmsBaseProp::Normal ) )
{
// No normals means we can't use normal offset bias.
// Without normals, PBS is probably a very poor fit for this object
// but at least don't crash
setProperty( "skip_normal_offset_bias_vs", 1 );
}
uint32 brdf = datablock->getBrdf();
if( ( brdf & PbsBrdf::BRDF_MASK ) == PbsBrdf::Default )
{
setProperty( PbsProperty::BrdfDefault, 1 );
if( !( brdf & PbsBrdf::FLAG_UNCORRELATED ) )
setProperty( PbsProperty::GgxHeightCorrelated, 1 );
setProperty( PbsProperty::ClearCoat, datablock->mClearCoat != 0.0f );
}
else if( ( brdf & PbsBrdf::BRDF_MASK ) == PbsBrdf::CookTorrance )
setProperty( PbsProperty::BrdfCookTorrance, 1 );
else if( ( brdf & PbsBrdf::BRDF_MASK ) == PbsBrdf::BlinnPhong )
setProperty( PbsProperty::BrdfBlinnPhong, 1 );
if( brdf & PbsBrdf::FLAG_SPERATE_DIFFUSE_FRESNEL )
setProperty( PbsProperty::FresnelSeparateDiffuse, 1 );
if( brdf & PbsBrdf::FLAG_LEGACY_MATH )
setProperty( PbsProperty::LegacyMathBrdf, 1 );
if( brdf & PbsBrdf::FLAG_FULL_LEGACY )
setProperty( PbsProperty::RoughnessIsShininess, 1 );
for( size_t i = 0u; i < PBSM_REFLECTION; ++i )
{
uint8 uvSource = datablock->mUvSource[i];
setProperty( *PbsProperty::UvSourcePtrs[i], uvSource );
if( datablock->getTexture( static_cast<uint8>( i ) ) &&
getProperty( *HlmsBaseProp::UvCountPtrs[uvSource] ) < 2 )
{
OGRE_EXCEPT( Exception::ERR_INVALID_STATE,
"Renderable needs at least 2 coordinates in UV set #" +
StringConverter::toString( uvSource ) +
". Either change the mesh, or change the UV source settings",
"HlmsPbs::calculateHashForPreCreate" );
}
}
int numNormalWeights = 0;
if( datablock->getNormalMapWeight() != 1.0f && datablock->getTexture( PBSM_NORMAL ) )
{
setProperty( PbsProperty::NormalWeightTex, 1 );
++numNormalWeights;
}
for( size_t i = 0u; i < 4u; ++i )
{
if( datablock->getTexture( uint8( PBSM_DETAIL0_NM + i ) ) )
{
if( datablock->getDetailNormalWeight( (uint8)i ) != 1.0f )
{
setProperty( *PbsProperty::DetailNormalWeights[i], 1 );
++numNormalWeights;
}
}
}
setProperty( PbsProperty::NormalWeight, numNormalWeights );
if( datablock->mTexturesDescSet )
setDetailMapProperties( datablock, inOutPieces, false );
else
setProperty( PbsProperty::FirstValidDetailMapNm, 4 );
if( datablock->mSamplersDescSet )
{
setProperty( PbsProperty::NumSamplers,
(int32)datablock->mSamplersDescSet->mSamplers.size() );
}
if( datablock->mTexturesDescSet )
{
bool envMap = datablock->getTexture( PBSM_REFLECTION ) != 0;
setProperty( PbsProperty::NumTextures,
int32( datablock->mTexturesDescSet->mTextures.size() - envMap ) );
setTextureProperty( PbsProperty::DiffuseMap, datablock, PBSM_DIFFUSE );
setTextureProperty( PbsProperty::NormalMapTex, datablock, PBSM_NORMAL );
setTextureProperty( PbsProperty::SpecularMap, datablock, PBSM_SPECULAR );
setTextureProperty( PbsProperty::RoughnessMap, datablock, PBSM_ROUGHNESS );
setTextureProperty( PbsProperty::EmissiveMap, datablock, PBSM_EMISSIVE );
setTextureProperty( PbsProperty::EnvProbeMap, datablock, PBSM_REFLECTION );
setTextureProperty( PbsProperty::DetailWeightMap, datablock, PBSM_DETAIL_WEIGHT );
if( getProperty( PbsProperty::DiffuseMap ) )
{
if( datablock->getUseDiffuseMapAsGrayscale() )
setProperty( PbsProperty::DiffuseMapGrayscale, 1 );
}
if( datablock->getTexture( PBSM_EMISSIVE ) && getProperty( PbsProperty::EmissiveMap ) )
{
TextureGpu *emissiveTexture = datablock->getTexture( PBSM_EMISSIVE );
if( PixelFormatGpuUtils::getNumberOfComponents( emissiveTexture->getPixelFormat() ) ==
1u )
{
setProperty( PbsProperty::EmissiveMapGrayscale, 1 );
}
}
// Save the name of the cubemap for hazard prevention
//(don't sample the cubemap and render to it at the same time).
const TextureGpu *reflectionTexture = datablock->getTexture( PBSM_REFLECTION );
if( reflectionTexture )
{
// Manual reflection texture
if( datablock->getCubemapProbe() )
setProperty( PbsProperty::UseParallaxCorrectCubemaps, 1 );
setProperty( PbsProperty::EnvProbeMap,
static_cast<int32>( reflectionTexture->getName().mHash ) );
}
}
if( datablock->_hasEmissive() )
{
if( datablock->hasEmissiveConstant() )
setProperty( PbsProperty::EmissiveConstant, 1 );
if( datablock->getTexture( PBSM_EMISSIVE ) )
{
if( datablock->getUseEmissiveAsLightmap() )
setProperty( PbsProperty::EmissiveAsLightmap, 1 );
}
}
// normal maps used in this datablock
StackVector<TextureGpu *, 5u> datablockNormalMaps;
// normal maps that are being used and have also been loaded
// NB We could just use the loadedNormalMaps for the logic below
// however other parts of the code may make assumptions based on
// the fact a normal map texture is registered with datablock but not loaded.
StackVector<TextureGpu *, 5u> loadedNormalMaps;
TextureGpu *tempTex;
if( ( tempTex = datablock->getTexture( PBSM_NORMAL ) ) != 0 )
{
datablockNormalMaps.push_back( tempTex );
if( tempTex->isMetadataReady() )
loadedNormalMaps.push_back( tempTex );
}
for( size_t i = PBSM_DETAIL0_NM; i <= PBSM_DETAIL3_NM; ++i )
{
if( ( tempTex = datablock->getTexture( (uint8)i ) ) != 0 )
{
datablockNormalMaps.push_back( tempTex );
if( tempTex->isMetadataReady() )
loadedNormalMaps.push_back( tempTex );
}
}
setProperty( PbsProperty::NormalMap, !datablockNormalMaps.empty() );
/*setProperty( HlmsBaseProp::, (bool)datablock->getTexture( PBSM_DETAIL0 ) );
setProperty( HlmsBaseProp::DiffuseMap, (bool)datablock->getTexture( PBSM_DETAIL1 ) );*/
bool normalMapCanBeSupported =
( getProperty( HlmsBaseProp::Normal ) && getProperty( HlmsBaseProp::Tangent ) ) ||
getProperty( HlmsBaseProp::QTangent );
if( !normalMapCanBeSupported && !datablockNormalMaps.empty() )
{
OGRE_EXCEPT( Exception::ERR_INVALID_STATE,
"Renderable can't use normal maps but datablock wants normal maps. "
"Generate Tangents for this mesh to fix the problem or use a "
"datablock without normal maps.",
"HlmsPbs::calculateHashForPreCreate" );
}
if( !datablockNormalMaps.empty() )
{
// NB if texture has not loaded yet, getPixelFormat will return PFG_UNKNOWN and so
// isSigned may be incorrect. However calculateHasFor will be called again when it
// has loaded, so just assume default for now.
PixelFormatGpu nmPixelFormat = datablockNormalMaps[0]->getPixelFormat();
const bool isSigned = PixelFormatGpuUtils::isSigned( nmPixelFormat );
if( isSigned )
{
setProperty( PbsProperty::NormalSamplingFormat,
static_cast<int32>( PbsProperty::NormalRgSnorm.mHash ) );
setProperty( PbsProperty::NormalRgSnorm,
static_cast<int32>( PbsProperty::NormalRgSnorm.mHash ) );
}
else
{
if( nmPixelFormat != PFG_BC3_UNORM )
{
setProperty( PbsProperty::NormalSamplingFormat,
static_cast<int32>( PbsProperty::NormalRgUnorm.mHash ) );
setProperty( PbsProperty::NormalRgUnorm,
static_cast<int32>( PbsProperty::NormalRgUnorm.mHash ) );
}
else
{
setProperty( PbsProperty::NormalSamplingFormat,
static_cast<int32>( PbsProperty::NormalBc3Unorm.mHash ) );
setProperty( PbsProperty::NormalBc3Unorm,
static_cast<int32>( PbsProperty::NormalBc3Unorm.mHash ) );
}
}
}
// check and ensure all normal maps use the same signed convention
if( !loadedNormalMaps.empty() )
{
const bool isSigned = PixelFormatGpuUtils::isSigned( loadedNormalMaps[0]->getPixelFormat() );
// check normal maps all use the same one convention
for( size_t i = 1u; i < loadedNormalMaps.size(); ++i )
{
const bool isSignedOther =
PixelFormatGpuUtils::isSigned( loadedNormalMaps[i]->getPixelFormat() );
if( isSignedOther != isSigned )
{
OGRE_EXCEPT(
Exception::ERR_INVALID_STATE,
"Renderable can't use normal maps and detailed normal maps which have "
"different signed conventions in the same datablock. e.g. SNORM vs UNORM ",
"HlmsPbs::calculateHashForPreCreate" );
}
}
}
if( datablock->mUseAlphaFromTextures &&
( datablock->getAlphaTest() != CMPF_ALWAYS_PASS ||
datablock->mBlendblock[0]->isAutoTransparent() ||
datablock->mBlendblock[0]->mAlphaToCoverageEnabled ||
datablock->mTransparencyMode == HlmsPbsDatablock::Refractive ) &&
( getProperty( PbsProperty::DiffuseMap ) || //
getProperty( PbsProperty::DetailMapsDiffuse ) ) )
{
setProperty( PbsProperty::UseTextureAlpha, 1 );
// When we don't use the alpha in the texture, transparency still works but
// only at material level (i.e. what datablock->mTransparency says). The
// alpha from the texture will be ignored.
if( datablock->mTransparencyMode == HlmsPbsDatablock::Transparent )
setProperty( PbsProperty::TransparentMode, 1 );
}
#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
if( mPlanarReflections && mPlanarReflections->hasPlanarReflections( renderable ) )
{
if( !mPlanarReflections->_isUpdatingRenderablesHlms() )
mPlanarReflections->_notifyRenderableFlushedHlmsDatablock( renderable );
else
setProperty( PbsProperty::UsePlanarReflections, 1 );
}
#endif
if( mFastShaderBuildHack )
setProperty( PbsProperty::MaterialsPerBuffer, static_cast<int>( 2 ) );
else
setProperty( PbsProperty::MaterialsPerBuffer, static_cast<int>( mSlotsPerPool ) );
}
//-----------------------------------------------------------------------------------
void HlmsPbs::calculateHashForPreCaster( Renderable *renderable, PiecesMap *inOutPieces )
{
HlmsPbsDatablock *datablock = static_cast<HlmsPbsDatablock *>( renderable->getDatablock() );
const bool hasAlphaTest = datablock->getAlphaTest() != CMPF_ALWAYS_PASS;
HlmsPropertyVec::iterator itor = mSetProperties.begin();
HlmsPropertyVec::iterator end = mSetProperties.end();
while( itor != end )
{
if( itor->keyName == PbsProperty::FirstValidDetailMapNm )
{
itor->value = 0;
++itor;
}
else if( itor->keyName != PbsProperty::HwGammaRead &&
itor->keyName != PbsProperty::UvDiffuse &&
itor->keyName != HlmsPsoProp::InputLayoutId &&
itor->keyName != HlmsBaseProp::Skeleton && itor->keyName != HlmsBaseProp::Pose &&
itor->keyName != HlmsBaseProp::PoseHalfPrecision &&
itor->keyName != HlmsBaseProp::PoseNormals &&
itor->keyName != HlmsBaseProp::BonesPerVertex &&
itor->keyName != HlmsBaseProp::DualParaboloidMapping &&
itor->keyName != HlmsBaseProp::AlphaTest &&
itor->keyName != HlmsBaseProp::AlphaBlend &&
( !hasAlphaTest || !requiredPropertyByAlphaTest( itor->keyName ) ) )
{
itor = mSetProperties.erase( itor );
end = mSetProperties.end();
}
else
{
++itor;
}
}
if( hasAlphaTest && getProperty( PbsProperty::UseTextureAlpha ) )
{
if( datablock->mTexturesDescSet )
setDetailMapProperties( datablock, inOutPieces, true );
if( datablock->mSamplersDescSet )
{
setProperty( PbsProperty::NumSamplers,
(int32)datablock->mSamplersDescSet->mSamplers.size() );
}
if( datablock->mTexturesDescSet )
{
const bool envMap = datablock->getTexture( PBSM_REFLECTION ) != 0;
setProperty( PbsProperty::NumTextures,
int32( datablock->mTexturesDescSet->mTextures.size() - envMap ) );
setTextureProperty( PbsProperty::DiffuseMap, datablock, PBSM_DIFFUSE );
setTextureProperty( PbsProperty::DetailWeightMap, datablock, PBSM_DETAIL_WEIGHT );
if( getProperty( PbsProperty::DiffuseMap ) )
{
if( datablock->getUseDiffuseMapAsGrayscale() )
setProperty( PbsProperty::DiffuseMapGrayscale, 1 );
}
}
}
if( mFastShaderBuildHack )
setProperty( PbsProperty::MaterialsPerBuffer, static_cast<int>( 2 ) );
else
setProperty( PbsProperty::MaterialsPerBuffer, static_cast<int>( mSlotsPerPool ) );
}
//-----------------------------------------------------------------------------------
void HlmsPbs::notifyPropertiesMergedPreGenerationStep()
{
const int32 numVctProbes = getProperty( PbsProperty::VctNumProbes );
const bool hasVct = numVctProbes > 0;
if( getProperty( HlmsBaseProp::DecalsNormals ) || hasVct )
{
// If decals normals are enabled or VCT is used, we need to generate the TBN matrix.
bool normalMapCanBeSupported =
( getProperty( HlmsBaseProp::Normal ) && getProperty( HlmsBaseProp::Tangent ) ) ||
getProperty( HlmsBaseProp::QTangent );
setProperty( PbsProperty::NormalMap, normalMapCanBeSupported );
}
// If the pass does not have planar reflections, then the object cannot use it
if( !getProperty( PbsProperty::HasPlanarReflections ) )
setProperty( PbsProperty::UsePlanarReflections, 0 );
if( getProperty( HlmsBaseProp::Pose ) > 0 )
setProperty( HlmsBaseProp::VertexId, 1 );
const int32 envProbeMapVal = getProperty( PbsProperty::EnvProbeMap );
const bool canUseManualProbe =
envProbeMapVal && envProbeMapVal != getProperty( PbsProperty::TargetEnvprobeMap );
if( canUseManualProbe || getProperty( PbsProperty::ParallaxCorrectCubemaps ) )
{
setProperty( PbsProperty::UseEnvProbeMap, 1 );
if( !canUseManualProbe )
{
/// "No cubemap"? Then we're in auto mode or...
/// We're rendering to the cubemap probe we're using as manual.
/// Use the auto mode as fallback.
setProperty( PbsProperty::UseParallaxCorrectCubemaps, 1 );
}
}
OGRE_ASSERT_MEDIUM( ( !getProperty( PbsProperty::UseParallaxCorrectCubemaps ) ||
getProperty( PbsProperty::ParallaxCorrectCubemaps ) ) &&
"Object with manual cubemap probe but "
"setParallaxCorrectedCubemap() was not called!" );
const bool hasIrradianceField = getProperty( PbsProperty::IrradianceField ) != 0;
bool bNeedsEnvBrdf = false;
if( getProperty( HlmsBaseProp::UseSsr ) || getProperty( PbsProperty::UseEnvProbeMap ) ||
getProperty( PbsProperty::UsePlanarReflections ) ||
getProperty( PbsProperty::AmbientHemisphere ) || getProperty( PbsProperty::AmbientSh ) ||
getProperty( PbsProperty::EnableCubemapsAuto ) || hasIrradianceField || hasVct )
{
setProperty( PbsProperty::NeedsReflDir, 1 );
setProperty( PbsProperty::NeedsEnvBrdf, 1 );
bNeedsEnvBrdf = true;
}
if( getProperty( HlmsBaseProp::LightsSpot ) || getProperty( HlmsBaseProp::ForwardPlus ) ||
getProperty( HlmsBaseProp::LightsAreaApprox ) ||
getProperty( HlmsBaseProp::LightsAreaLtc ) || bNeedsEnvBrdf || hasIrradianceField || hasVct )
{
setProperty( PbsProperty::NeedsViewDir, 1 );
}
int32 texUnit = mReservedTexBufferSlots;
if( getProperty( HlmsBaseProp::ForwardPlus ) )
{
if( mVaoManager->readOnlyIsTexBuffer() )
setTextureReg( PixelShader, "f3dLightList", texUnit++ );
else
setProperty( "f3dLightList", texUnit++ );
setTextureReg( PixelShader, "f3dGrid", texUnit++ );
}
texUnit += mReservedTexSlots;
bool depthTextureDefined = false;
if( getProperty( HlmsBaseProp::UsePrePass ) )
{
setTextureReg( PixelShader, "gBuf_normals", texUnit++ );
setTextureReg( PixelShader, "gBuf_shadowRoughness", texUnit++ );
if( getProperty( HlmsBaseProp::UsePrePassMsaa ) )
{
setTextureReg( PixelShader, "gBuf_depthTexture", texUnit++ );
depthTextureDefined = true;
}
else
{
++texUnit;
}
if( getProperty( HlmsBaseProp::UseSsr ) )
setTextureReg( PixelShader, "ssrTexture", texUnit++ );
}
const bool refractionsAvailable = getProperty( HlmsBaseProp::SsRefractionsAvailable );
if( refractionsAvailable )
{
if( !depthTextureDefined && !getProperty( HlmsBaseProp::UsePrePassMsaa ) )
{
setTextureReg( PixelShader, "gBuf_depthTexture", texUnit++ );
depthTextureDefined = true;
}
else
{
setTextureReg( PixelShader, "depthTextureNoMsaa", texUnit++ );
}
setTextureReg( PixelShader, "refractionMap", texUnit++ );
}
OGRE_ASSERT_HIGH(
( refractionsAvailable || getProperty( HlmsBaseProp::ScreenSpaceRefractions ) == 0 ) &&
"A material that uses refractions is used in a pass where refractions are unavailable! See "
"Samples/2.0/ApiUsage/Refractions for which pass refractions must be rendered in" );
const bool casterPass = getProperty( HlmsBaseProp::ShadowCaster ) != 0;
if( !casterPass && getProperty( PbsProperty::IrradianceVolumes ) )
setTextureReg( PixelShader, "irradianceVolume", texUnit++ );
if( numVctProbes > 0 )
{
setTextureReg( PixelShader, "vctProbes", texUnit, numVctProbes );
texUnit += numVctProbes;
if( getProperty( PbsProperty::VctAnisotropic ) )
{
setTextureReg( PixelShader, "vctProbeX", texUnit, numVctProbes );
texUnit += numVctProbes;
setTextureReg( PixelShader, "vctProbeY", texUnit, numVctProbes );
texUnit += numVctProbes;
setTextureReg( PixelShader, "vctProbeZ", texUnit, numVctProbes );
texUnit += numVctProbes;
}
}
if( getProperty( PbsProperty::IrradianceField ) )
{
setTextureReg( PixelShader, "ifdColour", texUnit++ );
setTextureReg( PixelShader, "ifdDepth", texUnit++ );
}
if( getProperty( HlmsBaseProp::LightsAreaTexMask ) > 0 )
setTextureReg( PixelShader, "areaLightMasks", texUnit++ );
if( getProperty( PbsProperty::LightProfilesTexture ) > 0 )
setTextureReg( PixelShader, "lightProfiles", texUnit++ );
if( getProperty( PbsProperty::LtcTextureAvailable ) )
{
if( bNeedsEnvBrdf || getProperty( HlmsBaseProp::LightsAreaLtc ) > 0 )
setTextureReg( PixelShader, "ltcMatrix", texUnit++ );
else
{
// Always occupy the texture unit
++texUnit;
}
}
if( getProperty( HlmsBaseProp::EnableDecals ) )
{
const int32 decalsDiffuseProp = getProperty( HlmsBaseProp::DecalsDiffuse );
// This is a regular property!
setProperty( "decalsSampler", texUnit );
if( decalsDiffuseProp )
setTextureReg( PixelShader, "decalsDiffuseTex", texUnit++ );
if( getProperty( HlmsBaseProp::DecalsNormals ) )
setTextureReg( PixelShader, "decalsNormalsTex", texUnit++ );
const int32 decalsEmissiveProp = getProperty( HlmsBaseProp::DecalsEmissive );
if( decalsEmissiveProp && decalsEmissiveProp != decalsDiffuseProp )
setTextureReg( PixelShader, "decalsEmissiveTex", texUnit++ );
}
const int32 numShadowMaps = getProperty( HlmsBaseProp::NumShadowMapTextures );
if( numShadowMaps )
{
if( getProperty( HlmsBaseProp::NumShadowMapLights ) != 0 )
{
char tmpData[32];
LwString texName = LwString::FromEmptyPointer( tmpData, sizeof( tmpData ) );
texName = "texShadowMap";
const size_t baseTexSize = texName.size();
for( int32 i = 0; i < numShadowMaps; ++i )
{
texName.resize( baseTexSize );
texName.a( i ); // texShadowMap0
setTextureReg( PixelShader, texName.c_str(), texUnit++ );
}
}
else
{
// No visible lights casting shadow maps.
texUnit += numShadowMaps;
}
}
int cubemapTexUnit = 0;
const int32 parallaxCorrectCubemaps = getProperty( PbsProperty::ParallaxCorrectCubemaps );
if( parallaxCorrectCubemaps )
cubemapTexUnit = texUnit++;
const int32 hasPlanarReflections = getProperty( PbsProperty::HasPlanarReflections );
if( hasPlanarReflections )
{
const bool usesPlanarReflections = getProperty( PbsProperty::UsePlanarReflections ) != 0;
if( usesPlanarReflections )
setTextureReg( PixelShader, "planarReflectionTex", texUnit );
++texUnit;
}
texUnit += mListener->getNumExtraPassTextures( mSetProperties, casterPass );
setProperty( PbsProperty::Set0TextureSlotEnd, texUnit );
const int32 samplerStateStart = texUnit;
{
char tmpData[32];
LwString texName = LwString::FromEmptyPointer( tmpData, sizeof( tmpData ) );
texName = "textureMaps";
const size_t baseTexSize = texName.size();
int32 numTextures = getProperty( PbsProperty::NumTextures );
for( int32 i = 0; i < numTextures; ++i )
{
texName.resize( baseTexSize );
texName.a( i ); // textureMaps0
setTextureReg( PixelShader, texName.c_str(), texUnit++ );
}
}
const int32 envProbeMap = getProperty( PbsProperty::EnvProbeMap );
const int32 targetEnvProbeMap = getProperty( PbsProperty::TargetEnvprobeMap );
if( ( envProbeMap && envProbeMap != targetEnvProbeMap ) || parallaxCorrectCubemaps )
{
if( !envProbeMap || envProbeMap == targetEnvProbeMap )
setTextureReg( PixelShader, "texEnvProbeMap", cubemapTexUnit );
else
setTextureReg( PixelShader, "texEnvProbeMap", texUnit++ );
}
setProperty( PbsProperty::Set1TextureSlotEnd, texUnit );
if( getProperty( HlmsBaseProp::Pose ) )
setTextureReg( VertexShader, "poseBuf", texUnit++ );
// This is a regular property!
setProperty( "samplerStateStart", samplerStateStart );
}
//-----------------------------------------------------------------------------------
bool HlmsPbs::requiredPropertyByAlphaTest( IdString keyName )
{
bool retVal = keyName == PbsProperty::UvDetailWeight || keyName == PbsProperty::UvDetail0 ||
keyName == PbsProperty::UvDetail1 || keyName == PbsProperty::UvDetail2 ||
keyName == PbsProperty::UvDetail3 || keyName == HlmsBaseProp::UvCount ||
keyName == PbsProperty::UseTextureAlpha;
for( int i = 0; i < 8 && !retVal; ++i )
retVal |= keyName == *HlmsBaseProp::UvCountPtrs[i];
return retVal;
}
//-----------------------------------------------------------------------------------
static bool SortByTextureLightMaskIdx( const Light *_a, const Light *_b )
{
return _a->mTextureLightMaskIdx < _b->mTextureLightMaskIdx;
}
//-----------------------------------------------------------------------------------
#if OGRE_ENABLE_LIGHT_OBB_RESTRAINT
inline float *fillObbRestraint( const Light *light, const Matrix4 &viewMatrix, float *passBufferPtr )
{
// float4x3 obbRestraint;
Node *obbRestraint = light->getObbRestraint();
if( obbRestraint )
{
Matrix4 obbMat = obbRestraint->_getFullTransform();
obbMat = viewMatrix * obbMat;
obbMat = obbMat.inverseAffine();
# if !OGRE_DOUBLE_PRECISION
memcpy( passBufferPtr, &obbMat, sizeof( float ) * 12u );
passBufferPtr += 12u;
# else
for( size_t i = 0u; i < 12u; ++i )
*passBufferPtr++ = static_cast<float>( obbMat[0][i] );
# endif
}
else
{
memset( passBufferPtr, 0, sizeof( float ) * 12u );
passBufferPtr += 12u;
}
return passBufferPtr;
}
#endif
//-----------------------------------------------------------------------------------
void HlmsPbs::analyzeBarriers( BarrierSolver &barrierSolver,
ResourceTransitionArray &resourceTransitions, Camera *renderingCamera,
const bool bCasterPass )
{
if( bCasterPass )
return;
#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
if( mPlanarReflections && mPlanarReflections->cameraMatches( renderingCamera ) )
{
const size_t maxActiveActors = mPlanarReflections->getMaxActiveActors();
for( size_t i = 0u; i < maxActiveActors; ++i )
{
barrierSolver.resolveTransition(
resourceTransitions, mPlanarReflections->getTexture( (uint8)i ),
ResourceLayout::Texture, ResourceAccess::Read, 1u << PixelShader );
}
}
#endif
if( mVctLighting )
{
const size_t numCascades = mVctLighting->getNumCascades();
const size_t numVctTextures = mVctLighting->getNumVoxelTextures();
for( size_t cascadeIdx = 0; cascadeIdx < numCascades; ++cascadeIdx )
{
TextureGpu **lightVoxelTexs = mVctLighting->getLightVoxelTextures( cascadeIdx );
for( size_t i = 0; i < numVctTextures; ++i )
{
barrierSolver.resolveTransition( resourceTransitions, lightVoxelTexs[i],
ResourceLayout::Texture, ResourceAccess::Read,
1u << PixelShader );
}
}
}
if( mIrradianceField )
{
barrierSolver.resolveTransition( //
resourceTransitions, mIrradianceField->getIrradianceTex(), ResourceLayout::Texture,
ResourceAccess::Read, 1u << PixelShader );
barrierSolver.resolveTransition(
resourceTransitions, mIrradianceField->getDepthVarianceTex(), ResourceLayout::Texture,
ResourceAccess::Read, 1u << PixelShader );
}
}
//-----------------------------------------------------------------------------------
HlmsCache HlmsPbs::preparePassHash( const CompositorShadowNode *shadowNode, bool casterPass,
bool dualParaboloid, SceneManager *sceneManager )
{
OgreProfileExhaustive( "HlmsPbs::preparePassHash" );
mSetProperties.clear();
if( shadowNode && mShadowFilter == ExponentialShadowMaps )
setProperty( PbsProperty::ExponentialShadowMaps, mEsmK );
// The properties need to be set before preparePassHash so that
// they are considered when building the HlmsCache's hash.
if( shadowNode && !casterPass )
{
// Shadow receiving can be improved in performance by using gather sampling.
//(it's the only feature so far that uses gather)
const RenderSystemCapabilities *capabilities = mRenderSystem->getCapabilities();
if( capabilities->hasCapability( RSC_TEXTURE_GATHER ) )
setProperty( HlmsBaseProp::TexGather, 1 );
if( mShadowFilter == PCF_3x3 )
{
setProperty( PbsProperty::Pcf, 3 );
setProperty( PbsProperty::PcfIterations, 4 );
}
else if( mShadowFilter == PCF_4x4 )
{
setProperty( PbsProperty::Pcf, 4 );
setProperty( PbsProperty::PcfIterations, 9 );
}
else if( mShadowFilter == PCF_5x5 )
{
setProperty( PbsProperty::Pcf, 5 );
setProperty( PbsProperty::PcfIterations, 16 );
}
else if( mShadowFilter == PCF_6x6 )
{
setProperty( PbsProperty::Pcf, 6 );
setProperty( PbsProperty::PcfIterations, 25 );
}
else if( mShadowFilter == ExponentialShadowMaps )
{
// Already set
// setProperty( PbsProperty::ExponentialShadowMaps, 1 );
}
else
{
setProperty( PbsProperty::PcfIterations, 1 );
}
if( mShadowReceiversInPixelShader )
setProperty( PbsProperty::ShadowsReceiveOnPs, 1 );
if( mDebugPssmSplits )
{
int32 numPssmSplits = 0;
const vector<Real>::type *pssmSplits = shadowNode->getPssmSplits( 0 );
if( pssmSplits )
{
numPssmSplits = static_cast<int32>( pssmSplits->size() - 1 );
if( numPssmSplits > 0 )
setProperty( PbsProperty::DebugPssmSplits, 1 );
}
}
}
mPrePassTextures = &sceneManager->getCurrentPrePassTextures();
assert( mPrePassTextures->empty() || mPrePassTextures->size() == 2u );
mPrePassMsaaDepthTexture = 0;
if( !mPrePassTextures->empty() && ( *mPrePassTextures )[0]->isMultisample() )
{
TextureGpu *msaaDepthTexture = sceneManager->getCurrentPrePassDepthTexture();
if( msaaDepthTexture )
mPrePassMsaaDepthTexture = msaaDepthTexture;
assert(
( mPrePassMsaaDepthTexture && mPrePassMsaaDepthTexture->getSampleDescription() ==
( *mPrePassTextures )[0]->getSampleDescription() ) &&
"Prepass + MSAA must specify an MSAA depth texture" );
}
mDepthTexture = sceneManager->getCurrentPrePassDepthTexture();
mDepthTextureNoMsaa = sceneManager->getCurrentPassDepthTextureNoMsaa();
mSsrTexture = sceneManager->getCurrentSsrTexture();
assert( !( mPrePassTextures->empty() && mSsrTexture ) &&
"Using SSR *requires* to be in prepass mode" );
mRefractionsTexture = sceneManager->getCurrentRefractionsTexture();
OGRE_ASSERT_LOW( ( !mRefractionsTexture || ( mRefractionsTexture && mDepthTextureNoMsaa ) ) &&
"Refractions texture requires a depth texture!" );
const bool vctNeedsAmbientHemi =
!casterPass && mVctLighting && mVctLighting->needsAmbientHemisphere();
AmbientLightMode ambientMode = mAmbientLightMode;
ColourValue upperHemisphere = sceneManager->getAmbientLightUpperHemisphere();
ColourValue lowerHemisphere = sceneManager->getAmbientLightLowerHemisphere();
const float envMapScale = upperHemisphere.a;
// Ignore alpha channel
upperHemisphere.a = lowerHemisphere.a = 1.0;
const CompositorPass *pass = sceneManager->getCurrentCompositorPass();
CompositorPassSceneDef const *passSceneDef = 0;
if( pass && pass->getType() == PASS_SCENE )
{
OGRE_ASSERT_HIGH( dynamic_cast<const CompositorPassSceneDef *>( pass->getDefinition() ) );
passSceneDef = static_cast<const CompositorPassSceneDef *>( pass->getDefinition() );
}
const bool isInstancedStereo = passSceneDef && passSceneDef->mInstancedStereo;
if( isInstancedStereo )
setProperty( HlmsBaseProp::VPos, 1 );
if( !casterPass )
{
if( mPerceptualRoughness )
setProperty( PbsProperty::PerceptualRoughness, 1 );
if( mLightProfilesTexture )
setProperty( PbsProperty::LightProfilesTexture, 1 );
if( mLtcMatrixTexture )
setProperty( PbsProperty::LtcTextureAvailable, 1 );
if( mAmbientLightMode == AmbientAuto )
{
if( upperHemisphere == lowerHemisphere )
{
if( upperHemisphere == ColourValue::Black )
ambientMode = AmbientNone;
else
ambientMode = AmbientFixed;
}
else
{
ambientMode = AmbientHemisphere;
}
}
if( ambientMode == AmbientFixed )
setProperty( PbsProperty::AmbientFixed, 1 );
if( ambientMode == AmbientHemisphere )
setProperty( PbsProperty::AmbientHemisphere, 1 );
if( ambientMode == AmbientSh || ambientMode == AmbientShMonochrome )
{
setProperty( PbsProperty::AmbientSh, 1 );
if( ambientMode == AmbientShMonochrome )
setProperty( PbsProperty::AmbientShMonochrome, 1 );
}
if( envMapScale != 1.0f )
setProperty( PbsProperty::EnvMapScale, 1 );
const uint32 envFeatures = sceneManager->getEnvFeatures();
if( envFeatures & SceneManager::EnvFeatures_DiffuseGiFromReflectionProbe )
setProperty( PbsProperty::CubemapsAsDiffuseGi, 1 );
// Save cubemap's name so that we never try to render & sample to/from it at the same time
RenderPassDescriptor *renderPassDescriptor = mRenderSystem->getCurrentPassDescriptor();
if( renderPassDescriptor->getNumColourEntries() > 0u )
{
TextureGpu *firstColourTarget = renderPassDescriptor->mColour[0].texture;
if( firstColourTarget->getTextureType() == TextureTypes::TypeCube )
{
setProperty( PbsProperty::TargetEnvprobeMap,
static_cast<int32>( firstColourTarget->getName().mHash ) );
}
}
if( mParallaxCorrectedCubemap && !mParallaxCorrectedCubemap->isRendering() )
{
setProperty( PbsProperty::ParallaxCorrectCubemaps, 1 );
if( mParallaxCorrectedCubemap->getAutomaticMode() )
{
setProperty( PbsProperty::EnableCubemapsAuto, 1 );
if( mParallaxCorrectedCubemap->getUseDpm2DArray() )
setProperty( PbsProperty::CubemapsUseDpm, 1 );
}
}
if( mVctLighting )
{
setProperty( PbsProperty::VctNumProbes,
static_cast<int32>( mVctLighting->getNumCascades() ) );
setProperty( PbsProperty::VctConeDirs, mVctFullConeCount ? 6 : 4 );
setProperty( PbsProperty::VctAnisotropic, mVctLighting->isAnisotropic() );
setProperty( PbsProperty::VctEnableSpecularSdfQuality,
mVctLighting->shouldEnableSpecularSdfQuality() );
setProperty( PbsProperty::VctAmbientSphere, vctNeedsAmbientHemi );
//'Static' reflections on cubemaps look horrible
if( mParallaxCorrectedCubemap && mParallaxCorrectedCubemap->isRendering() )
setProperty( PbsProperty::VctDisableSpecular, 1 );
}
if( mIrradianceField )
{
setProperty( PbsProperty::IrradianceField, 1 );
setProperty( PbsProperty::VctDisableDiffuse, 1 );
}
if( mIrradianceVolume )
setProperty( PbsProperty::IrradianceVolumes, 1 );
if( mAreaLightMasks )
{
const size_t numComponents =
PixelFormatGpuUtils::getNumberOfComponents( mAreaLightMasks->getPixelFormat() );
if( numComponents > 2u )
setProperty( HlmsBaseProp::LightsAreaTexColour, 1 );
}
#if OGRE_ENABLE_LIGHT_OBB_RESTRAINT
if( mUseObbRestraintAreaApprox )
setProperty( PbsProperty::ObbRestraintApprox, 1 );
if( mUseObbRestraintAreaLtc )
setProperty( PbsProperty::ObbRestraintLtc, 1 );
#endif
#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
mHasPlanarReflections = false;
mLastBoundPlanarReflection = 0u;
if( mPlanarReflections && mPlanarReflections->cameraMatches(
sceneManager->getCamerasInProgress().renderingCamera ) )
{
mHasPlanarReflections = true;
setProperty( PbsProperty::HasPlanarReflections,
mPlanarReflections->getMaxActiveActors() );
}
#endif
#if !OGRE_NO_FINE_LIGHT_MASK_GRANULARITY
if( mFineLightMaskGranularity )
setProperty( HlmsBaseProp::FineLightMask, 1 );
#endif
}
if( mOptimizationStrategy == LowerGpuOverhead )
setProperty( PbsProperty::LowerGpuOverhead, 1 );
HlmsCache retVal =
Hlms::preparePassHashBase( shadowNode, casterPass, dualParaboloid, sceneManager );
if( mUseLightBuffers )
setProperty( PbsProperty::useLightBuffers, 1 );
const RenderSystemCapabilities *capabilities = mRenderSystem->getCapabilities();
setProperty( PbsProperty::HwGammaRead, capabilities->hasCapability( RSC_HW_GAMMA ) );
// setProperty( PbsProperty::HwGammaWrite, capabilities->hasCapability( RSC_HW_GAMMA ) &&
// renderTarget->isHardwareGammaEnabled()
// );
setProperty( PbsProperty::HwGammaWrite, 1 );
retVal.setProperties = mSetProperties;
CamerasInProgress cameras = sceneManager->getCamerasInProgress();
mConstantBiasScale = cameras.renderingCamera->_getConstantBiasScale();
Matrix4 viewMatrix = cameras.renderingCamera->getVrViewMatrix( 0 );
Matrix4 projectionMatrix = cameras.renderingCamera->getProjectionMatrixWithRSDepth();
RenderPassDescriptor *renderPassDesc = mRenderSystem->getCurrentPassDescriptor();
if( renderPassDesc->requiresTextureFlipping() )
{
projectionMatrix[1][0] = -projectionMatrix[1][0];
projectionMatrix[1][1] = -projectionMatrix[1][1];
projectionMatrix[1][2] = -projectionMatrix[1][2];
projectionMatrix[1][3] = -projectionMatrix[1][3];
}
const size_t numLights = static_cast<size_t>( getProperty( HlmsBaseProp::LightsSpot ) );
const size_t numDirectionalLights =
static_cast<size_t>( getProperty( HlmsBaseProp::LightsDirNonCaster ) );
const size_t numShadowMapLights =
static_cast<size_t>( getProperty( HlmsBaseProp::NumShadowMapLights ) );
const size_t numPssmSplits = static_cast<size_t>( getProperty( HlmsBaseProp::PssmSplits ) );
const size_t numAreaApproxLights =
static_cast<size_t>( getProperty( HlmsBaseProp::LightsAreaApprox ) );
const size_t numAreaLtcLights =
static_cast<size_t>( getProperty( HlmsBaseProp::LightsAreaLtc ) );
const uint32 realNumDirectionalLights = mRealNumDirectionalLights;
const uint32 realNumAreaApproxLightsWithMask = mRealNumAreaApproxLightsWithMask;
const uint32 realNumAreaApproxLights = mRealNumAreaApproxLights;
const uint32 realNumAreaLtcLights = mRealNumAreaLtcLights;
#if OGRE_ENABLE_LIGHT_OBB_RESTRAINT
const size_t numAreaApproxFloat4Vars = 7u + ( mUseObbRestraintAreaApprox ? 4u : 0u );
const size_t numAreaLtcFloat4Vars = 7u + ( mUseObbRestraintAreaLtc ? 3u : 0u );
#else
const size_t numAreaApproxFloat4Vars = 7u;
const size_t numAreaLtcFloat4Vars = 7u;
#endif
bool isPssmBlend = getProperty( HlmsBaseProp::PssmBlend ) != 0;
bool isPssmFade = getProperty( HlmsBaseProp::PssmFade ) != 0;
bool isStaticBranchShadowMapLights =
getProperty( HlmsBaseProp::StaticBranchShadowMapLights ) != 0;
bool isShadowCastingPointLight = false;
// mat4 viewProj;
size_t mapSize = 16 * 4;
size_t mapSizeLight0 = 0;
size_t mapSizeLight1 = 0;
size_t mapSizeLight2 = 0;
mGridBuffer = 0;
mGlobalLightListBuffer = 0;
mDecalsTextures[0] = 0;
mDecalsTextures[1] = 0;
mDecalsTextures[2] = 0;
mDecalsDiffuseMergedEmissive = true;
ForwardPlusBase *forwardPlus = sceneManager->_getActivePassForwardPlus();
if( !casterPass )
{
if( forwardPlus )
{
mapSize += forwardPlus->getConstBufferSize();
mGridBuffer = forwardPlus->getGridBuffer( cameras.cullingCamera );
mGlobalLightListBuffer = forwardPlus->getGlobalLightListBuffer( cameras.cullingCamera );
if( forwardPlus->getDecalsEnabled() )
{
const PrePassMode prePassMode = sceneManager->getCurrentPrePassMode();
if( prePassMode != PrePassCreate )
mDecalsTextures[0] = sceneManager->getDecalsDiffuse();
if( prePassMode != PrePassUse )
mDecalsTextures[1] = sceneManager->getDecalsNormals();
if( prePassMode != PrePassCreate )
mDecalsTextures[2] = sceneManager->getDecalsEmissive();
mDecalsDiffuseMergedEmissive = sceneManager->isDecalsDiffuseEmissiveMerged();
}
}
if( mParallaxCorrectedCubemap && !mParallaxCorrectedCubemap->isRendering() )
{
mParallaxCorrectedCubemap->_notifyPreparePassHash( viewMatrix );
mapSize += mParallaxCorrectedCubemap->getConstBufferSize();
}
if( mVctLighting )
mapSize += mVctLighting->getConstBufferSize();
if( mIrradianceField )
mapSize += mIrradianceField->getConstBufferSize();
// mat4 view + mat4 shadowRcv[numShadowMapLights].texViewProj +
// vec2 shadowRcv[numShadowMapLights].shadowDepthRange +
// float normalOffsetBias +
// float padding +
// vec4 shadowRcv[numShadowMapLights].invShadowMapSize +
// mat3 invViewMatCubemap (upgraded to three vec4)
mapSize += ( 16 + ( 16 + 2 + 2 + 4 ) * numShadowMapLights + 4 * 3 ) * 4;
// float4 pccVctMinDistance_invPccVctInvDistance_rightEyePixelStartX_envMapNumMipmaps;
mapSize += 4u * 4u;
// float4 aspectRatio_planarReflNumMips_unused2;
mapSize += 4u * 4u;
// float2 invWindowRes + float2 windowResolution
mapSize += 4u * 4u;
// vec4 shadowRcv[numShadowMapLights].texViewZRow
if( mShadowFilter == ExponentialShadowMaps )
mapSize += ( 4 * 4 ) * numShadowMapLights;
// vec4 pixelOffset2x
if( passSceneDef && passSceneDef->mUvBakingSet != 0xFF )
mapSize += 4u * 4u;
// vec3 ambientUpperHemi + float envMapScale
if( ambientMode == AmbientFixed || ambientMode == AmbientHemisphere || envMapScale != 1.0f ||
vctNeedsAmbientHemi )
{
mapSize += 4 * 4;
}
// vec3 ambientLowerHemi + padding + vec3 ambientHemisphereDir + padding
if( ambientMode == AmbientHemisphere || vctNeedsAmbientHemi )
{
mapSize += 8 * 4;
}
// float4 sh0 - sh6;
if( ambientMode == AmbientSh )
mapSize += 7u * 4u * 4u;
// float4 sh0 - sh2;
if( ambientMode == AmbientShMonochrome )
mapSize += 3u * 4u * 4u;
// vec3 irradianceOrigin + float maxPower +
// vec3 irradianceSize + float invHeight + mat4 invView
if( mIrradianceVolume )
mapSize += ( 4 + 4 + 4 * 4 ) * 4;
#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
if( mHasPlanarReflections )
mapSize += mPlanarReflections->getConstBufferSize();
#endif
// float pssmSplitPoints N times.
mapSize += numPssmSplits * 4;
if( isPssmBlend )
{
// float pssmBlendPoints N-1 times.
mapSize += ( numPssmSplits - 1 ) * 4;
}
if( isPssmFade )
{
// float pssmFadePoint.
mapSize += 4;
}
if( isStaticBranchShadowMapLights )
{
// float numShadowMapPointLights;
// float numShadowMapSpotLights;
mapSize += 4 + 4;
}
mapSize = alignToNextMultiple<size_t>( mapSize, 16 );
if( numShadowMapLights > 0 )
{
// Six variables * 4 (padded vec3) * 4 (bytes) * numLights
mapSizeLight0 += ( 6 * 4 * 4 ) * numLights;
}
else
{
// Three variables * 4 (padded vec3) * 4 (bytes) * numDirectionalLights
mapSizeLight0 += ( 3 * 4 * 4 ) * numDirectionalLights;
}
mapSizeLight1 += ( numAreaApproxFloat4Vars * 4 * 4 ) * numAreaApproxLights;
mapSizeLight2 += ( numAreaLtcFloat4Vars * 4 * 4 ) * numAreaLtcLights;
}
else
{
isShadowCastingPointLight = getProperty( HlmsBaseProp::ShadowCasterPoint ) != 0;
// vec4 cameraPosWS
if( isShadowCastingPointLight )
mapSize += 4 * 4;
// vec4 viewZRow
if( mShadowFilter == ExponentialShadowMaps )
mapSize += 4 * 4;
// vec4 depthRange
mapSize += ( 2 + 2 ) * 4;
}
const bool isCameraReflected = cameras.renderingCamera->isReflected();
// vec4 clipPlane0
if( isCameraReflected )
mapSize += 4 * 4;
// float4x4 viewProj[2] (second only) + float4 leftToRightView
if( isInstancedStereo )
{
mapSize += 16u * 4u + 4u * 4u;
// float4x4 leftEyeViewSpaceToCullCamClipSpace
if( forwardPlus )
mapSize += 16u * 4u;
}
mapSize += mListener->getPassBufferSize( shadowNode, casterPass, dualParaboloid, sceneManager );
// Arbitrary 16kb (minimum supported by GL), should be enough.
const size_t maxBufferSizeRaw = 16 * 1024;
const size_t maxBufferSizeLight0 = ( 6 * 4 * 4 ) * 32; // 32 forward lights should be enough
const size_t maxBufferSizeLight1 = ( numAreaApproxFloat4Vars * 4 * 4 ) * 8; // 8 area lights
const size_t maxBufferSizeLight2 = ( numAreaLtcFloat4Vars * 4 * 4 ) * 8; // 8 Ltc area lights
assert( mapSize <= maxBufferSizeRaw );
assert( !mUseLightBuffers || mapSizeLight0 <= maxBufferSizeLight0 );
assert( !mUseLightBuffers || mapSizeLight1 <= maxBufferSizeLight1 );
assert( !mUseLightBuffers || mapSizeLight2 <= maxBufferSizeLight2 );
size_t maxBufferSize = maxBufferSizeRaw;
if( !mUseLightBuffers )
mapSize += mapSizeLight0 + mapSizeLight1 + mapSizeLight2;
if( mCurrentPassBuffer >= mPassBuffers.size() )
{
mPassBuffers.push_back(
mVaoManager->createConstBuffer( maxBufferSize, BT_DYNAMIC_PERSISTENT, 0, false ) );
}
if( mUseLightBuffers )
{
while( mCurrentPassBuffer >= mLight0Buffers.size() )
{
mLight0Buffers.push_back( mVaoManager->createConstBuffer(
maxBufferSizeLight0, BT_DYNAMIC_PERSISTENT, 0, false ) );
mLight1Buffers.push_back( mVaoManager->createConstBuffer(
maxBufferSizeLight1, BT_DYNAMIC_PERSISTENT, 0, false ) );
mLight2Buffers.push_back( mVaoManager->createConstBuffer(
maxBufferSizeLight2, BT_DYNAMIC_PERSISTENT, 0, false ) );
}
}
ConstBufferPacked *passBuffer = mPassBuffers[mCurrentPassBuffer++];
float *passBufferPtr = reinterpret_cast<float *>( passBuffer->map( 0, mapSize ) );
ConstBufferPacked *light0Buffer = 0;
ConstBufferPacked *light1Buffer = 0;
ConstBufferPacked *light2Buffer = 0;
float *light0BufferPtr = 0;
float *light1BufferPtr = 0;
float *light2BufferPtr = 0;
if( mUseLightBuffers )
{
light0Buffer = mLight0Buffers[mCurrentPassBuffer - 1u];
light1Buffer = mLight1Buffers[mCurrentPassBuffer - 1u];
light2Buffer = mLight2Buffers[mCurrentPassBuffer - 1u];
if( mapSizeLight0 > 0 )
light0BufferPtr = reinterpret_cast<float *>( light0Buffer->map( 0, mapSizeLight0 ) );
if( mapSizeLight1 > 0 )
light1BufferPtr = reinterpret_cast<float *>( light1Buffer->map( 0, mapSizeLight1 ) );
if( mapSizeLight2 > 0 )
light2BufferPtr = reinterpret_cast<float *>( light2Buffer->map( 0, mapSizeLight2 ) );
}
#ifndef NDEBUG
const float *startupPtr = passBufferPtr;
const float *light0startupPtr = light0BufferPtr;
const float *light1startupPtr = light1BufferPtr;
const float *light2startupPtr = light2BufferPtr;
#endif
//---------------------------------------------------------------------------
// ---- VERTEX SHADER ----
//---------------------------------------------------------------------------
if( !isInstancedStereo )
{
// mat4 viewProj;
Matrix4 viewProjMatrix = projectionMatrix * viewMatrix;
for( size_t i = 0u; i < 16u; ++i )
*passBufferPtr++ = (float)viewProjMatrix[0][i];
}
else
{
// float4x4 viewProj[2];
Matrix4 vrViewMat[2];
for( size_t eyeIdx = 0u; eyeIdx < 2u; ++eyeIdx )
{
vrViewMat[eyeIdx] = cameras.renderingCamera->getVrViewMatrix( eyeIdx );
Matrix4 vrProjMat = cameras.renderingCamera->getVrProjectionMatrix( eyeIdx );
if( renderPassDesc->requiresTextureFlipping() )
{
vrProjMat[1][0] = -vrProjMat[1][0];
vrProjMat[1][1] = -vrProjMat[1][1];
vrProjMat[1][2] = -vrProjMat[1][2];
vrProjMat[1][3] = -vrProjMat[1][3];
}
Matrix4 viewProjMatrix = vrProjMat * vrViewMat[eyeIdx];
for( size_t i = 0; i < 16; ++i )
*passBufferPtr++ = (float)viewProjMatrix[0][i];
}
// float4x4 leftEyeViewSpaceToCullCamClipSpace
if( forwardPlus )
{
Matrix4 cullViewMat = cameras.cullingCamera->getViewMatrix( true );
Matrix4 cullProjMat = cameras.cullingCamera->getProjectionMatrix();
if( renderPassDesc->requiresTextureFlipping() )
{
cullProjMat[1][0] = -cullProjMat[1][0];
cullProjMat[1][1] = -cullProjMat[1][1];
cullProjMat[1][2] = -cullProjMat[1][2];
cullProjMat[1][3] = -cullProjMat[1][3];
}
Matrix4 leftEyeViewSpaceToCullCamClipSpace;
leftEyeViewSpaceToCullCamClipSpace =
cullProjMat * cullViewMat * vrViewMat[0].inverseAffine();
for( size_t i = 0u; i < 16u; ++i )
*passBufferPtr++ = (float)leftEyeViewSpaceToCullCamClipSpace[0][i];
}
// float4 leftToRightView
const VrData *vrData = cameras.renderingCamera->getVrData();
if( vrData )
{
for( size_t i = 0u; i < 3u; ++i )
*passBufferPtr++ = (float)vrData->mLeftToRight[i];
*passBufferPtr++ = 0;
}
else
{
for( size_t i = 0u; i < 4u; ++i )
*passBufferPtr++ = 0.0f;
}
}
if( mRenderSystem->getInvertedClipSpaceY() )
{
projectionMatrix[1][0] = -projectionMatrix[1][0];
projectionMatrix[1][1] = -projectionMatrix[1][1];
projectionMatrix[1][2] = -projectionMatrix[1][2];
projectionMatrix[1][3] = -projectionMatrix[1][3];
}
// vec4 clipPlane0
if( isCameraReflected )
{
const Plane &reflPlane = cameras.renderingCamera->getReflectionPlane();
*passBufferPtr++ = (float)reflPlane.normal.x;
*passBufferPtr++ = (float)reflPlane.normal.y;
*passBufferPtr++ = (float)reflPlane.normal.z;
*passBufferPtr++ = (float)reflPlane.d;
}
// vec4 cameraPosWS;
if( isShadowCastingPointLight )
{
const Vector3 &camPos = cameras.renderingCamera->getDerivedPosition();
*passBufferPtr++ = (float)camPos.x;
*passBufferPtr++ = (float)camPos.y;
*passBufferPtr++ = (float)camPos.z;
*passBufferPtr++ = 1.0f;
}
mPreparedPass.viewMatrix = viewMatrix;
mPreparedPass.shadowMaps.clear();
Viewport *currViewports = mRenderSystem->getCurrentRenderViewports();
TextureGpu *renderTarget = currViewports[0].getCurrentTarget();
if( !casterPass )
{
// mat4 view;
for( size_t i = 0; i < 16; ++i )
*passBufferPtr++ = (float)viewMatrix[0][i];
size_t shadowMapTexIdx = 0;
const TextureGpuVec &contiguousShadowMapTex =
shadowNode ? shadowNode->getContiguousShadowMapTex() : c_emptyTextureContainer;
for( size_t i = 0u; i < numShadowMapLights; ++i )
{
// Skip inactive lights (e.g. no directional lights are available
// and there's a shadow map that only accepts dir lights)
while( !shadowNode->isShadowMapIdxActive( shadowMapTexIdx ) )
++shadowMapTexIdx;
// mat4 shadowRcv[numShadowMapLights].texViewProj
Matrix4 viewProjTex = shadowNode->getViewProjectionMatrix( shadowMapTexIdx );
for( size_t j = 0; j < 16; ++j )
*passBufferPtr++ = (float)viewProjTex[0][j];
// vec4 texViewZRow;
if( mShadowFilter == ExponentialShadowMaps )
{
const Matrix4 &viewTex = shadowNode->getViewMatrix( shadowMapTexIdx );
*passBufferPtr++ = viewTex[2][0];
*passBufferPtr++ = viewTex[2][1];
*passBufferPtr++ = viewTex[2][2];
*passBufferPtr++ = viewTex[2][3];
}
const Light *shadowLight = shadowNode->getLightAssociatedWith( shadowMapTexIdx );
// vec2 shadowRcv[numShadowMapLights].shadowDepthRange
Real fNear, fFar;
shadowNode->getMinMaxDepthRange( shadowMapTexIdx, fNear, fFar );
const Real depthRange = fFar - fNear;
if( shadowLight && shadowLight->getType() == Light::LT_POINT &&
mShadowFilter != ExponentialShadowMaps && mRenderSystem->isReverseDepth() )
{
*passBufferPtr++ = fFar;
}
else
{
*passBufferPtr++ = fNear;
}
*passBufferPtr++ = 1.0f / depthRange;
*passBufferPtr++ = shadowNode->getNormalOffsetBias( (size_t)shadowMapTexIdx );
*passBufferPtr++ = 0.0f; // Padding
// vec2 shadowRcv[numShadowMapLights].invShadowMapSize
size_t shadowMapTexContigIdx =
shadowNode->getIndexToContiguousShadowMapTex( (size_t)shadowMapTexIdx );
uint32 texWidth = contiguousShadowMapTex[shadowMapTexContigIdx]->getWidth();
uint32 texHeight = contiguousShadowMapTex[shadowMapTexContigIdx]->getHeight();
*passBufferPtr++ = 1.0f / texWidth;
*passBufferPtr++ = 1.0f / texHeight;
*passBufferPtr++ = static_cast<float>( texWidth );
*passBufferPtr++ = static_cast<float>( texHeight );
++shadowMapTexIdx;
}
// vec4 pixelOffset2x
if( passSceneDef && passSceneDef->mUvBakingSet != 0xFF )
{
*passBufferPtr++ = static_cast<float>( passSceneDef->mUvBakingOffset.x * Real( 2.0 ) /
renderTarget->getWidth() );
*passBufferPtr++ = static_cast<float>( passSceneDef->mUvBakingOffset.y * Real( 2.0 ) /
renderTarget->getHeight() );
*passBufferPtr++ = 0.0f;
*passBufferPtr++ = 0.0f;
}
//---------------------------------------------------------------------------
// ---- PIXEL SHADER ----
//---------------------------------------------------------------------------
Matrix3 viewMatrix3, invViewMatrixCubemap;
viewMatrix.extract3x3Matrix( viewMatrix3 );
// Cubemaps are left-handed.
invViewMatrixCubemap = viewMatrix3;
invViewMatrixCubemap[0][2] = -invViewMatrixCubemap[0][2];
invViewMatrixCubemap[1][2] = -invViewMatrixCubemap[1][2];
invViewMatrixCubemap[2][2] = -invViewMatrixCubemap[2][2];
invViewMatrixCubemap = invViewMatrixCubemap.Inverse();
// mat3 invViewMatCubemap
for( size_t i = 0; i < 9; ++i )
{
#ifdef OGRE_GLES2_WORKAROUND_2
Matrix3 xRot( 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f );
xRot = xRot * invViewMatrixCubemap;
*passBufferPtr++ = (float)xRot[0][i];
#else
*passBufferPtr++ = (float)invViewMatrixCubemap[0][i];
#endif
// Alignment: each row/column is one vec4, despite being 3x3
if( !( ( i + 1 ) % 3 ) )
++passBufferPtr;
}
// float4 pccVctMinDistance_invPccVctInvDistance_rightEyePixelStartX_envMapNumMipmaps
*passBufferPtr++ = mPccVctMinDistance;
*passBufferPtr++ = mInvPccVctInvDistance;
*passBufferPtr++ = (float)currViewports[1].getActualLeft();
*passBufferPtr++ = mMaxSpecIblMipmap;
{
const float windowWidth = (float)renderTarget->getWidth();
const float windowHeight = (float)renderTarget->getHeight();
// float4 aspectRatio_planarReflNumMips_unused2
*passBufferPtr++ = windowWidth / windowHeight;
#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
if( mPlanarReflections )
{
// Assume all planar refl. probes have the same num. of mipmaps
*passBufferPtr++ = mPlanarReflections->getMaxNumMipmaps();
}
else
{
*passBufferPtr++ = 0.0f;
}
#else
*passBufferPtr++ = 0.0f;
#endif
*passBufferPtr++ = 0.0f;
*passBufferPtr++ = 0.0f;
// float2 invWindowRes + float2 windowResolution;
*passBufferPtr++ = 1.0f / windowWidth;
*passBufferPtr++ = 1.0f / windowHeight;
*passBufferPtr++ = windowWidth;
*passBufferPtr++ = windowHeight;
}
// vec3 ambientUpperHemi + padding
if( ambientMode == AmbientFixed || ambientMode == AmbientHemisphere || envMapScale != 1.0f ||
vctNeedsAmbientHemi )
{
*passBufferPtr++ = static_cast<float>( upperHemisphere.r );
*passBufferPtr++ = static_cast<float>( upperHemisphere.g );
*passBufferPtr++ = static_cast<float>( upperHemisphere.b );
*passBufferPtr++ = envMapScale;
}
// vec3 ambientLowerHemi + padding + vec3 ambientHemisphereDir + padding
if( ambientMode == AmbientHemisphere || vctNeedsAmbientHemi )
{
*passBufferPtr++ = static_cast<float>( lowerHemisphere.r );
*passBufferPtr++ = static_cast<float>( lowerHemisphere.g );
*passBufferPtr++ = static_cast<float>( lowerHemisphere.b );
*passBufferPtr++ = 1.0f;
Vector3 hemisphereDir = viewMatrix3 * sceneManager->getAmbientLightHemisphereDir();
hemisphereDir.normalise();
*passBufferPtr++ = static_cast<float>( hemisphereDir.x );
*passBufferPtr++ = static_cast<float>( hemisphereDir.y );
*passBufferPtr++ = static_cast<float>( hemisphereDir.z );
*passBufferPtr++ = 1.0f;
}
// float4 sh0 - sh6;
if( ambientMode == AmbientSh )
{
const float *ambientSphericalHarmonics = sceneManager->getSphericalHarmonics();
for( size_t i = 0u; i < 9u; ++i )
{
*passBufferPtr++ = ambientSphericalHarmonics[i * 3u + 0u];
*passBufferPtr++ = ambientSphericalHarmonics[i * 3u + 1u];
*passBufferPtr++ = ambientSphericalHarmonics[i * 3u + 2u];
}
*passBufferPtr++ = 0.0f; // Unused / padding
}
// float4 sh0 - sh2;
if( ambientMode == AmbientShMonochrome )
{
const float *ambientSphericalHarmonics = sceneManager->getSphericalHarmonics();
for( size_t i = 0u; i < 9u; ++i )
*passBufferPtr++ = ambientSphericalHarmonics[i * 3u + 0u];
*passBufferPtr++ = 0.0f; // Unused / padding
*passBufferPtr++ = 0.0f; // Unused / padding
*passBufferPtr++ = 0.0f; // Unused / padding
}
if( mIrradianceVolume )
{
const Vector3 irradianceCellSize = mIrradianceVolume->getIrradianceCellSize();
const Vector3 irradianceVolumeOrigin =
mIrradianceVolume->getIrradianceOrigin() / irradianceCellSize;
const float fTexWidth =
static_cast<float>( mIrradianceVolume->getIrradianceVolumeTexture()->getWidth() );
const float fTexDepth =
static_cast<float>( mIrradianceVolume->getIrradianceVolumeTexture()->getDepth() );
*passBufferPtr++ = static_cast<float>( irradianceVolumeOrigin.x ) / fTexWidth;
*passBufferPtr++ = static_cast<float>( irradianceVolumeOrigin.y );
*passBufferPtr++ = static_cast<float>( irradianceVolumeOrigin.z ) / fTexDepth;
*passBufferPtr++ =
mIrradianceVolume->getIrradianceMaxPower() * mIrradianceVolume->getPowerScale();
const float fTexHeight =
static_cast<float>( mIrradianceVolume->getIrradianceVolumeTexture()->getHeight() );
*passBufferPtr++ = 1.0f / ( fTexWidth * irradianceCellSize.x );
*passBufferPtr++ = 1.0f / irradianceCellSize.y;
*passBufferPtr++ = 1.0f / ( fTexDepth * irradianceCellSize.z );
*passBufferPtr++ = 1.0f / fTexHeight;
// mat4 invView;
Matrix4 invViewMatrix = viewMatrix.inverse();
for( size_t i = 0; i < 16; ++i )
*passBufferPtr++ = (float)invViewMatrix[0][i];
}
// float pssmSplitPoints
for( size_t i = 0; i < numPssmSplits; ++i )
*passBufferPtr++ = ( *shadowNode->getPssmSplits( 0 ) )[i + 1];
size_t numPssmBlendsAndFade = 0u;
if( isPssmBlend )
{
numPssmBlendsAndFade += numPssmSplits - 1u;
// float pssmBlendPoints
for( size_t i = 0u; i < numPssmSplits - 1u; ++i )
*passBufferPtr++ = ( *shadowNode->getPssmBlends( 0 ) )[i];
}
if( isPssmFade )
{
numPssmBlendsAndFade += 1u;
// float pssmFadePoint
*passBufferPtr++ = *shadowNode->getPssmFade( 0 );
}
if( isStaticBranchShadowMapLights )
{
// float numShadowMapPointLights;
// float numShadowMapSpotLights;
*reinterpret_cast<uint32 * RESTRICT_ALIAS>( passBufferPtr ) = mRealShadowMapPointLights;
passBufferPtr++;
*reinterpret_cast<uint32 * RESTRICT_ALIAS>( passBufferPtr ) = mRealShadowMapSpotLights;
passBufferPtr++;
numPssmBlendsAndFade += 2;
}
passBufferPtr += alignToNextMultiple<size_t>( numPssmSplits + numPssmBlendsAndFade, 4 ) -
( numPssmSplits + numPssmBlendsAndFade );
if( !mUseLightBuffers )
light0BufferPtr = passBufferPtr;
if( numShadowMapLights > 0 )
{
float invHeightLightProfileTex = 1.0f;
if( mLightProfilesTexture )
invHeightLightProfileTex = 1.0f / mLightProfilesTexture->getHeight();
// All directional lights (caster and non-caster) are sent.
// Then non-directional shadow-casting shadow lights are sent.
size_t shadowLightIdx = 0;
size_t nonShadowLightIdx = 0;
const LightListInfo &globalLightList = sceneManager->getGlobalLightList();
const LightClosestArray &lights = shadowNode->getShadowCastingLights();
const CompositorShadowNode::LightsBitSet &affectedLights =
shadowNode->getAffectedLightsBitSet();
const size_t shadowCastingDirLights =
static_cast<size_t>( getProperty( HlmsBaseProp::LightsDirectional ) );
for( size_t i = 0u; i < numLights; ++i )
{
Light const *light = 0;
if( i >= shadowCastingDirLights && i < numDirectionalLights )
{
if( i < realNumDirectionalLights )
{
while( affectedLights[nonShadowLightIdx] )
++nonShadowLightIdx;
light = globalLightList.lights[nonShadowLightIdx++];
assert( light->getType() == Light::LT_DIRECTIONAL );
}
else
{
AutoParamDataSource *autoParamDataSource =
sceneManager->_getAutoParamDataSource();
light = &autoParamDataSource->_getBlankLight();
}
}
else
{
// Skip inactive lights (e.g. no directional lights are available
// and there's a shadow map that only accepts dir lights)
while( !lights[shadowLightIdx].light )
++shadowLightIdx;
light = lights[shadowLightIdx++].light;
}
Vector4 lightPos4 = light->getAs4DVector();
Vector3 lightPos;
if( light->getType() == Light::LT_DIRECTIONAL )
lightPos = viewMatrix3 * Vector3( lightPos4.x, lightPos4.y, lightPos4.z );
else
lightPos = viewMatrix * Vector3( lightPos4.x, lightPos4.y, lightPos4.z );
// vec3 lights[numLights].position
*light0BufferPtr++ = lightPos.x;
*light0BufferPtr++ = lightPos.y;
*light0BufferPtr++ = lightPos.z;
#if !OGRE_NO_FINE_LIGHT_MASK_GRANULARITY
*reinterpret_cast<uint32 * RESTRICT_ALIAS>( light0BufferPtr ) =
light->getLightMask();
#endif
++light0BufferPtr;
// vec3 lights[numLights].diffuse
ColourValue colour = light->getDiffuseColour() * light->getPowerScale();
*light0BufferPtr++ = colour.r;
*light0BufferPtr++ = colour.g;
*light0BufferPtr++ = colour.b;
*reinterpret_cast<uint32 * RESTRICT_ALIAS>( light0BufferPtr ) =
uint32( realNumDirectionalLights - shadowCastingDirLights );
++light0BufferPtr;
// vec3 lights[numLights].specular
colour = light->getSpecularColour() * light->getPowerScale();
*light0BufferPtr++ = colour.r;
*light0BufferPtr++ = colour.g;
*light0BufferPtr++ = colour.b;
++light0BufferPtr;
// vec3 lights[numLights].attenuation;
Real attenRange = light->getAttenuationRange();
Real attenLinear = light->getAttenuationLinear();
Real attenQuadratic = light->getAttenuationQuadric();
*light0BufferPtr++ = attenRange;
*light0BufferPtr++ = attenLinear;
*light0BufferPtr++ = attenQuadratic;
++light0BufferPtr;
const uint16 lightProfileIdx = light->getLightProfileIdx();
// vec4 lights[numLights].spotDirection;
Vector3 spotDir = viewMatrix3 * light->getDerivedDirection();
*light0BufferPtr++ = spotDir.x;
*light0BufferPtr++ = spotDir.y;
*light0BufferPtr++ = spotDir.z;
*light0BufferPtr++ =
( static_cast<float>( lightProfileIdx ) + 0.5f ) * invHeightLightProfileTex;
// vec4 lights[numLights].spotParams;
if( light->getType() != Light::LT_AREA_APPROX )
{
Radian innerAngle = light->getSpotlightInnerAngle();
Radian outerAngle = light->getSpotlightOuterAngle();
*light0BufferPtr++ = 1.0f / ( cosf( innerAngle.valueRadians() * 0.5f ) -
cosf( outerAngle.valueRadians() * 0.5f ) );
*light0BufferPtr++ = cosf( outerAngle.valueRadians() * 0.5f );
*light0BufferPtr++ = light->getSpotlightFalloff();
}
else
{
Quaternion qRot = light->getParentNode()->_getDerivedOrientation();
Vector3 xAxis = viewMatrix3 * qRot.xAxis();
*light0BufferPtr++ = xAxis.x;
*light0BufferPtr++ = xAxis.y;
*light0BufferPtr++ = xAxis.z;
}
*light0BufferPtr++ = 0.0f;
}
}
else
{
// No shadow maps, only send directional lights
const LightListInfo &globalLightList = sceneManager->getGlobalLightList();
for( size_t i = 0u; i < realNumDirectionalLights; ++i )
{
assert( globalLightList.lights[i]->getType() == Light::LT_DIRECTIONAL );
Vector4 lightPos4 = globalLightList.lights[i]->getAs4DVector();
Vector3 lightPos = viewMatrix3 * Vector3( lightPos4.x, lightPos4.y, lightPos4.z );
// vec3 lights[numLights].position
*light0BufferPtr++ = lightPos.x;
*light0BufferPtr++ = lightPos.y;
*light0BufferPtr++ = lightPos.z;
#if !OGRE_NO_FINE_LIGHT_MASK_GRANULARITY
*reinterpret_cast<uint32 * RESTRICT_ALIAS>( light0BufferPtr ) =
globalLightList.lights[i]->getLightMask();
#endif
++light0BufferPtr;
// vec3 lights[numLights].diffuse
ColourValue colour = globalLightList.lights[i]->getDiffuseColour() *
globalLightList.lights[i]->getPowerScale();
*light0BufferPtr++ = colour.r;
*light0BufferPtr++ = colour.g;
*light0BufferPtr++ = colour.b;
*reinterpret_cast<uint32 * RESTRICT_ALIAS>( light0BufferPtr ) =
realNumDirectionalLights;
++light0BufferPtr;
// vec3 lights[numLights].specular
colour = globalLightList.lights[i]->getSpecularColour() *
globalLightList.lights[i]->getPowerScale();
*light0BufferPtr++ = colour.r;
*light0BufferPtr++ = colour.g;
*light0BufferPtr++ = colour.b;
++light0BufferPtr;
}
memset(
light0BufferPtr, 0,
( numDirectionalLights - realNumDirectionalLights ) * sizeof( float ) * 4u * 3u );
light0BufferPtr += ( numDirectionalLights - realNumDirectionalLights ) * 4u * 3u;
}
if( !mUseLightBuffers )
passBufferPtr = light0BufferPtr;
float areaLightNumMipmaps = 0.0f;
float areaLightNumMipmapsSpecFactor = 0.0f;
if( mAreaLightMasks )
{
// Roughness minimum value is 0.02, so we need to map
//[0.02; 1.0] -> [0; 1] in the pixel shader that's why we divide by 0.98.
// The 2.0 is just arbitrary (it looks good)
areaLightNumMipmaps = float( mAreaLightMasks->getNumMipmaps() - 1u );
areaLightNumMipmapsSpecFactor = areaLightNumMipmaps * 2.0f / 0.98f;
}
// Send area lights. We need them sorted so textured ones
// come first, as that what our shader expects
mAreaLights.reserve( numAreaApproxLights );
mAreaLights.clear();
const LightListInfo &globalLightList = sceneManager->getGlobalLightList();
size_t areaLightNumber = 0;
for( size_t idx = mAreaLightsGlobalLightListStart;
idx < globalLightList.lights.size() && areaLightNumber < realNumAreaApproxLights;
++idx )
{
if( globalLightList.lights[idx]->getType() == Light::LT_AREA_APPROX )
{
mAreaLights.push_back( globalLightList.lights[idx] );
++areaLightNumber;
}
}
std::sort( mAreaLights.begin(), mAreaLights.end(), SortByTextureLightMaskIdx );
if( !mUseLightBuffers )
light1BufferPtr = passBufferPtr;
for( size_t i = 0u; i < realNumAreaApproxLights; ++i )
{
Light const *light = mAreaLights[i];
Vector4 lightPos4 = light->getAs4DVector();
Vector3 lightPos = viewMatrix * Vector3( lightPos4.x, lightPos4.y, lightPos4.z );
// vec3 areaApproxLights[numLights].position
*light1BufferPtr++ = lightPos.x;
*light1BufferPtr++ = lightPos.y;
*light1BufferPtr++ = lightPos.z;
#if !OGRE_NO_FINE_LIGHT_MASK_GRANULARITY
*reinterpret_cast<uint32 * RESTRICT_ALIAS>( light1BufferPtr ) = light->getLightMask();
#endif
++light1BufferPtr;
// vec3 areaApproxLights[numLights].diffuse
ColourValue colour = light->getDiffuseColour() * light->getPowerScale();
*light1BufferPtr++ = colour.r;
*light1BufferPtr++ = colour.g;
*light1BufferPtr++ = colour.b;
*light1BufferPtr++ =
areaLightNumMipmaps * ( light->mTexLightMaskDiffuseMipStart / 65535.0f );
// vec3 areaApproxLights[numLights].specular
colour = light->getSpecularColour() * light->getPowerScale();
*light1BufferPtr++ = colour.r;
*light1BufferPtr++ = colour.g;
*light1BufferPtr++ = colour.b;
*light1BufferPtr++ = areaLightNumMipmapsSpecFactor;
// vec4 areaApproxLights[numLights].attenuation;
Real attenRange = light->getAttenuationRange();
Real attenLinear = light->getAttenuationLinear();
Real attenQuadratic = light->getAttenuationQuadric();
*light1BufferPtr++ = attenRange;
*light1BufferPtr++ = attenLinear;
*light1BufferPtr++ = attenQuadratic;
*light1BufferPtr++ = static_cast<float>( light->mTextureLightMaskIdx );
const Vector2 rectSize = light->getDerivedRectSize();
// vec4 areaApproxLights[numLights].direction;
Vector3 areaDir = viewMatrix3 * light->getDerivedDirection();
*light1BufferPtr++ = areaDir.x;
*light1BufferPtr++ = areaDir.y;
*light1BufferPtr++ = areaDir.z;
*light1BufferPtr++ = 1.0f / rectSize.x;
// vec4 areaApproxLights[numLights].tangent;
Quaternion qRot = light->getParentNode()->_getDerivedOrientation();
Vector3 xAxis = viewMatrix3 * qRot.xAxis();
*light1BufferPtr++ = xAxis.x;
*light1BufferPtr++ = xAxis.y;
*light1BufferPtr++ = xAxis.z;
*light1BufferPtr++ = 1.0f / rectSize.y;
// vec4 doubleSided;
*light1BufferPtr++ = light->getDoubleSided() ? 1.0f : 0.0f;
*reinterpret_cast<uint32 * RESTRICT_ALIAS>( light1BufferPtr ) = realNumAreaApproxLights;
++light1BufferPtr;
*reinterpret_cast<uint32 * RESTRICT_ALIAS>( light1BufferPtr ) =
realNumAreaApproxLightsWithMask;
++light1BufferPtr;
*light1BufferPtr++ = 0.0f;
#if OGRE_ENABLE_LIGHT_OBB_RESTRAINT
if( mUseObbRestraintAreaApprox )
{
// float4 obbFadeFactorApprox
const Vector3 obbRestraintFadeFactor = light->_getObbRestraintFadeFactor();
*light1BufferPtr++ = obbRestraintFadeFactor.x;
*light1BufferPtr++ = obbRestraintFadeFactor.y;
*light1BufferPtr++ = obbRestraintFadeFactor.z;
*light1BufferPtr++ = 0.0f;
// float4x3 obbRestraint;
light1BufferPtr = fillObbRestraint( light, viewMatrix, light1BufferPtr );
}
#endif
}
memset( light1BufferPtr, 0,
( numAreaApproxLights - realNumAreaApproxLights ) * sizeof( float ) * 4u *
numAreaApproxFloat4Vars );
light1BufferPtr +=
( numAreaApproxLights - realNumAreaApproxLights ) * 4u * numAreaApproxFloat4Vars;
if( !mUseLightBuffers )
passBufferPtr = light1BufferPtr;
mAreaLights.reserve( numAreaLtcLights );
mAreaLights.clear();
areaLightNumber = 0;
for( size_t idx = mAreaLightsGlobalLightListStart;
idx < globalLightList.lights.size() && areaLightNumber < realNumAreaLtcLights; ++idx )
{
if( globalLightList.lights[idx]->getType() == Light::LT_AREA_LTC )
{
mAreaLights.push_back( globalLightList.lights[idx] );
++areaLightNumber;
}
}
// std::sort( mAreaLights.begin(), mAreaLights.end(), SortByTextureLightMaskIdx );
if( !mUseLightBuffers )
light2BufferPtr = passBufferPtr;
for( size_t i = 0u; i < realNumAreaLtcLights; ++i )
{
Light const *light = mAreaLights[i];
Vector4 lightPos4 = light->getAs4DVector();
Vector3 lightPos = viewMatrix * Vector3( lightPos4.x, lightPos4.y, lightPos4.z );
// vec3 areaLtcLights[numLights].position
*light2BufferPtr++ = lightPos.x;
*light2BufferPtr++ = lightPos.y;
*light2BufferPtr++ = lightPos.z;
#if !OGRE_NO_FINE_LIGHT_MASK_GRANULARITY
*reinterpret_cast<uint32 * RESTRICT_ALIAS>( light2BufferPtr ) = light->getLightMask();
#endif
++light2BufferPtr;
const Real attenRange = light->getAttenuationRange();
// vec3 areaLtcLights[numLights].diffuse
ColourValue colour = light->getDiffuseColour() * light->getPowerScale();
*light2BufferPtr++ = colour.r;
*light2BufferPtr++ = colour.g;
*light2BufferPtr++ = colour.b;
*light2BufferPtr++ = attenRange;
// vec3 areaLtcLights[numLights].specular
colour = light->getSpecularColour() * light->getPowerScale();
*light2BufferPtr++ = colour.r;
*light2BufferPtr++ = colour.g;
*light2BufferPtr++ = colour.b;
*light2BufferPtr++ = light->getDoubleSided() ? 1.0f : 0.0f;
const Vector2 rectSize = light->getDerivedRectSize() * 0.5f;
Quaternion qRot = light->getParentNode()->_getDerivedOrientation();
Vector3 xAxis = ( viewMatrix3 * qRot.xAxis() ) * rectSize.x;
Vector3 yAxis = ( viewMatrix3 * qRot.yAxis() ) * rectSize.y;
Vector3 rectPoints[4];
// vec4 areaLtcLights[numLights].points[4];
rectPoints[0] = lightPos - xAxis - yAxis;
rectPoints[1] = lightPos + xAxis - yAxis;
rectPoints[2] = lightPos + xAxis + yAxis;
rectPoints[3] = lightPos - xAxis + yAxis;
#if OGRE_ENABLE_LIGHT_OBB_RESTRAINT
// float4 obbFadeFactorApprox
const Vector3 obbRestraintFadeFactor = light->_getObbRestraintFadeFactor();
#endif
for( size_t j = 0; j < 4u; ++j )
{
*light2BufferPtr++ = rectPoints[j].x;
*light2BufferPtr++ = rectPoints[j].y;
*light2BufferPtr++ = rectPoints[j].z;
#if OGRE_ENABLE_LIGHT_OBB_RESTRAINT
if( j == 0u )
{
*reinterpret_cast<uint32 * RESTRICT_ALIAS>( light2BufferPtr ) =
realNumAreaLtcLights;
++light2BufferPtr;
}
else
*light2BufferPtr++ = obbRestraintFadeFactor[j - 1u];
#else
*reinterpret_cast<uint32 * RESTRICT_ALIAS>( light2BufferPtr ) = realNumAreaLtcLights;
++light2BufferPtr;
#endif
}
#if OGRE_ENABLE_LIGHT_OBB_RESTRAINT
if( mUseObbRestraintAreaLtc )
{
// float4x3 obbRestraint;
light2BufferPtr = fillObbRestraint( light, viewMatrix, light2BufferPtr );
}
#endif
}
memset( light2BufferPtr, 0,
( numAreaLtcLights - realNumAreaLtcLights ) * sizeof( float ) * 4u *
numAreaLtcFloat4Vars );
light2BufferPtr += ( numAreaLtcLights - realNumAreaLtcLights ) * 4u * numAreaLtcFloat4Vars;
if( !mUseLightBuffers )
passBufferPtr = light2BufferPtr;
if( shadowNode )
{
mPreparedPass.shadowMaps.reserve( contiguousShadowMapTex.size() );
TextureGpuVec::const_iterator itShadowMap = contiguousShadowMapTex.begin();
TextureGpuVec::const_iterator enShadowMap = contiguousShadowMapTex.end();
while( itShadowMap != enShadowMap )
{
mPreparedPass.shadowMaps.push_back( *itShadowMap );
++itShadowMap;
}
}
if( forwardPlus )
{
forwardPlus->fillConstBufferData(
sceneManager->getCurrentViewport0(), renderPassDesc->requiresTextureFlipping(),
renderTarget->getHeight(), mShaderSyntax, isInstancedStereo, passBufferPtr );
passBufferPtr += forwardPlus->getConstBufferSize() >> 2u;
}
#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
if( mHasPlanarReflections )
{
mPlanarReflections->fillConstBufferData( renderTarget, cameras.renderingCamera,
projectionMatrix, passBufferPtr );
passBufferPtr += mPlanarReflections->getConstBufferSize() >> 2u;
}
#endif
if( mParallaxCorrectedCubemap && !mParallaxCorrectedCubemap->isRendering() )
{
mParallaxCorrectedCubemap->fillConstBufferData( viewMatrix, passBufferPtr );
passBufferPtr += mParallaxCorrectedCubemap->getConstBufferSize() >> 2u;
}
if( mVctLighting )
{
mVctLighting->fillConstBufferData( viewMatrix, passBufferPtr );
passBufferPtr += mVctLighting->getConstBufferSize() >> 2u;
}
if( mIrradianceField )
{
mIrradianceField->fillConstBufferData( viewMatrix, passBufferPtr );
passBufferPtr += mIrradianceField->getConstBufferSize() >> 2u;
}
}
else
{
// vec4 viewZRow
if( mShadowFilter == ExponentialShadowMaps )
{
*passBufferPtr++ = viewMatrix[2][0];
*passBufferPtr++ = viewMatrix[2][1];
*passBufferPtr++ = viewMatrix[2][2];
*passBufferPtr++ = viewMatrix[2][3];
}
// vec2 depthRange;
Real fNear, fFar;
shadowNode->getMinMaxDepthRange( cameras.renderingCamera, fNear, fFar );
const Real depthRange = fFar - fNear;
*passBufferPtr++ = fNear;
*passBufferPtr++ = 1.0f / depthRange;
passBufferPtr += 2;
}
passBufferPtr = mListener->preparePassBuffer( shadowNode, casterPass, dualParaboloid,
sceneManager, passBufferPtr );
assert( (size_t)( passBufferPtr - startupPtr ) * 4u == mapSize );
if( mUseLightBuffers )
{
assert( (size_t)( light0BufferPtr - light0startupPtr ) * 4u == mapSizeLight0 );
assert( (size_t)( light1BufferPtr - light1startupPtr ) * 4u == mapSizeLight1 );
assert( (size_t)( light2BufferPtr - light2startupPtr ) * 4u == mapSizeLight2 );
if( mapSizeLight0 > 0 )
light0Buffer->unmap( UO_KEEP_PERSISTENT );
if( mapSizeLight1 > 0 )
light1Buffer->unmap( UO_KEEP_PERSISTENT );
if( mapSizeLight2 > 0 )
light2Buffer->unmap( UO_KEEP_PERSISTENT );
}
passBuffer->unmap( UO_KEEP_PERSISTENT );
// mTexBuffers must hold at least one buffer to prevent out of bound exceptions.
if( mTexBuffers.empty() )
{
size_t bufferSize =
std::min<size_t>( mTextureBufferDefaultSize, mVaoManager->getReadOnlyBufferMaxSize() );
ReadOnlyBufferPacked *newBuffer = mVaoManager->createReadOnlyBuffer(
PFG_RGBA32_FLOAT, bufferSize, BT_DYNAMIC_PERSISTENT, 0, false );
mTexBuffers.push_back( newBuffer );
}
mLastDescTexture = 0;
mLastDescSampler = 0;
mLastBoundPool = 0;
if( mShadowFilter == ExponentialShadowMaps )
mCurrentShadowmapSamplerblock = mShadowmapEsmSamplerblock;
else if( mShadowmapSamplerblock && !getProperty( HlmsBaseProp::ShadowUsesDepthTexture ) )
mCurrentShadowmapSamplerblock = mShadowmapSamplerblock;
else
mCurrentShadowmapSamplerblock = mShadowmapCmpSamplerblock;
mTexBufUnitSlotEnd = mReservedTexBufferSlots;
mTexUnitSlotStart =
uint32( mPreparedPass.shadowMaps.size() + mReservedTexSlots + mReservedTexBufferSlots +
mListener->getNumExtraPassTextures( mSetProperties, casterPass ) );
if( !casterPass )
{
if( mGridBuffer )
{
mTexUnitSlotStart += 2;
mTexBufUnitSlotEnd += 2;
}
if( mIrradianceVolume )
mTexUnitSlotStart += 1;
if( mVctLighting )
{
mTexUnitSlotStart +=
uint32( mVctLighting->getNumVoxelTextures() * mVctLighting->getNumCascades() );
}
if( mIrradianceField )
mTexUnitSlotStart += 2u;
if( mParallaxCorrectedCubemap && !mParallaxCorrectedCubemap->isRendering() )
mTexUnitSlotStart += 1;
if( !mPrePassTextures->empty() )
mTexUnitSlotStart += 2;
if( mPrePassMsaaDepthTexture )
mTexUnitSlotStart += 1;
if( mDepthTexture )
mTexUnitSlotStart += 1;
if( mSsrTexture )
mTexUnitSlotStart += 1;
if( mDepthTextureNoMsaa && mDepthTexture != mDepthTextureNoMsaa )
mTexUnitSlotStart += 1;
if( mRefractionsTexture )
mTexUnitSlotStart += 1;
if( mAreaLightMasks && getProperty( HlmsBaseProp::LightsAreaTexMask ) > 0 )
{
mTexUnitSlotStart += 1;
mUsingAreaLightMasks = true;
}
else
{
mUsingAreaLightMasks = false;
}
if( mLightProfilesTexture )
mTexUnitSlotStart += 1;
/// LTC / BRDF IBL reserved slot
if( mLtcMatrixTexture )
++mTexUnitSlotStart;
for( size_t i = 0u; i < 3u; ++i )
{
if( mDecalsTextures[i] && ( i != 2u || !mDecalsDiffuseMergedEmissive ) )
{
++mTexUnitSlotStart;
}
}
#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
if( mHasPlanarReflections )
mTexUnitSlotStart += 1;
#endif
}
uploadDirtyDatablocks();
return retVal;
}
//-----------------------------------------------------------------------------------
uint32 HlmsPbs::fillBuffersFor( const HlmsCache *cache, const QueuedRenderable &queuedRenderable,
bool casterPass, uint32 lastCacheHash, uint32 lastTextureHash )
{
OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED,
"Trying to use slow-path on a desktop implementation. "
"Change the RenderQueue settings.",
"HlmsPbs::fillBuffersFor" );
}
//-----------------------------------------------------------------------------------
uint32 HlmsPbs::fillBuffersForV1( const HlmsCache *cache, const QueuedRenderable &queuedRenderable,
bool casterPass, uint32 lastCacheHash,
CommandBuffer *commandBuffer )
{
return fillBuffersFor( cache, queuedRenderable, casterPass, lastCacheHash, commandBuffer, true );
}
//-----------------------------------------------------------------------------------
uint32 HlmsPbs::fillBuffersForV2( const HlmsCache *cache, const QueuedRenderable &queuedRenderable,
bool casterPass, uint32 lastCacheHash,
CommandBuffer *commandBuffer )
{
return fillBuffersFor( cache, queuedRenderable, casterPass, lastCacheHash, commandBuffer,
false );
}
//-----------------------------------------------------------------------------------
uint32 HlmsPbs::fillBuffersFor( const HlmsCache *cache, const QueuedRenderable &queuedRenderable,
bool casterPass, uint32 lastCacheHash, CommandBuffer *commandBuffer,
bool isV1 )
{
assert( dynamic_cast<const HlmsPbsDatablock *>( queuedRenderable.renderable->getDatablock() ) );
const HlmsPbsDatablock *datablock =
static_cast<const HlmsPbsDatablock *>( queuedRenderable.renderable->getDatablock() );
if( OGRE_EXTRACT_HLMS_TYPE_FROM_CACHE_HASH( lastCacheHash ) != mType )
{
// layout(binding = 0) uniform PassBuffer {} pass
ConstBufferPacked *passBuffer = mPassBuffers[mCurrentPassBuffer - 1];
*commandBuffer->addCommand<CbShaderBuffer>() = CbShaderBuffer(
VertexShader, 0, passBuffer, 0, (uint32)passBuffer->getTotalSizeBytes() );
*commandBuffer->addCommand<CbShaderBuffer>() =
CbShaderBuffer( PixelShader, 0, passBuffer, 0, (uint32)passBuffer->getTotalSizeBytes() );
if( mUseLightBuffers )
{
ConstBufferPacked *light0Buffer = mLight0Buffers[mCurrentPassBuffer - 1];
*commandBuffer->addCommand<CbShaderBuffer>() = CbShaderBuffer(
VertexShader, 4, light0Buffer, 0, (uint32)light0Buffer->getTotalSizeBytes() );
*commandBuffer->addCommand<CbShaderBuffer>() = CbShaderBuffer(
PixelShader, 4, light0Buffer, 0, (uint32)light0Buffer->getTotalSizeBytes() );
ConstBufferPacked *light1Buffer = mLight1Buffers[mCurrentPassBuffer - 1];
*commandBuffer->addCommand<CbShaderBuffer>() = CbShaderBuffer(
VertexShader, 5, light1Buffer, 0, (uint32)light1Buffer->getTotalSizeBytes() );
*commandBuffer->addCommand<CbShaderBuffer>() = CbShaderBuffer(
PixelShader, 5, light1Buffer, 0, (uint32)light1Buffer->getTotalSizeBytes() );
ConstBufferPacked *light2Buffer = mLight2Buffers[mCurrentPassBuffer - 1];
*commandBuffer->addCommand<CbShaderBuffer>() = CbShaderBuffer(
VertexShader, 6, light2Buffer, 0, (uint32)light2Buffer->getTotalSizeBytes() );
*commandBuffer->addCommand<CbShaderBuffer>() = CbShaderBuffer(
PixelShader, 6, light2Buffer, 0, (uint32)light2Buffer->getTotalSizeBytes() );
}
size_t texUnit = mReservedTexBufferSlots;
if( !casterPass )
{
if( mGridBuffer )
{
*commandBuffer->addCommand<CbShaderBuffer>() =
CbShaderBuffer( PixelShader, (uint16)texUnit++, mGlobalLightListBuffer, 0, 0 );
*commandBuffer->addCommand<CbShaderBuffer>() =
CbShaderBuffer( PixelShader, (uint16)texUnit++, mGridBuffer, 0, 0 );
}
texUnit += mReservedTexSlots;
if( !mPrePassTextures->empty() )
{
*commandBuffer->addCommand<CbTexture>() =
CbTexture( (uint16)texUnit++, ( *mPrePassTextures )[0], 0 );
*commandBuffer->addCommand<CbTexture>() =
CbTexture( (uint16)texUnit++, ( *mPrePassTextures )[1], 0 );
}
if( mPrePassMsaaDepthTexture )
{
*commandBuffer->addCommand<CbTexture>() = CbTexture(
(uint16)texUnit++, mPrePassMsaaDepthTexture, 0,
PixelFormatGpuUtils::isDepth( mPrePassMsaaDepthTexture->getPixelFormat() ) );
}
if( mDepthTexture )
{
*commandBuffer->addCommand<CbTexture>() =
CbTexture( (uint16)texUnit++, mDepthTexture, mDecalsSamplerblock,
PixelFormatGpuUtils::isDepth( mDepthTexture->getPixelFormat() ) );
}
if( mSsrTexture )
{
*commandBuffer->addCommand<CbTexture>() =
CbTexture( (uint16)texUnit++, mSsrTexture, 0 );
}
if( mDepthTextureNoMsaa && mDepthTextureNoMsaa != mPrePassMsaaDepthTexture )
{
*commandBuffer->addCommand<CbTexture>() = CbTexture(
(uint16)texUnit++, mDepthTextureNoMsaa, mDecalsSamplerblock,
PixelFormatGpuUtils::isDepth( mDepthTextureNoMsaa->getPixelFormat() ) );
}
if( mRefractionsTexture )
{
*commandBuffer->addCommand<CbTexture>() =
CbTexture( (uint16)texUnit++, mRefractionsTexture, mDecalsSamplerblock );
}
if( mIrradianceVolume )
{
TextureGpu *irradianceTex = mIrradianceVolume->getIrradianceVolumeTexture();
const HlmsSamplerblock *samplerblock = mIrradianceVolume->getIrradSamplerblock();
*commandBuffer->addCommand<CbTexture>() =
CbTexture( (uint16)texUnit, irradianceTex, samplerblock );
++texUnit;
}
if( mVctLighting )
{
const size_t numCascades = mVctLighting->getNumCascades();
const size_t numVctTextures = mVctLighting->getNumVoxelTextures();
const HlmsSamplerblock *samplerblock = mVctLighting->getBindTrilinearSamplerblock();
for( size_t i = 0u; i < numVctTextures; ++i )
{
for( size_t cascadeIdx = 0; cascadeIdx < numCascades; ++cascadeIdx )
{
TextureGpu **lightVoxelTexs =
mVctLighting->getLightVoxelTextures( cascadeIdx );
*commandBuffer->addCommand<CbTexture>() =
CbTexture( (uint16)texUnit, lightVoxelTexs[i], samplerblock );
++texUnit;
}
}
}
if( mIrradianceField )
{
TODO_irradianceField_samplerblock;
const HlmsSamplerblock *samplerblock = mDecalsSamplerblock;
*commandBuffer->addCommand<CbTexture>() = CbTexture(
(uint16)texUnit++, mIrradianceField->getIrradianceTex(), samplerblock );
*commandBuffer->addCommand<CbTexture>() = CbTexture(
(uint16)texUnit++, mIrradianceField->getDepthVarianceTex(), samplerblock );
}
if( mUsingAreaLightMasks )
{
*commandBuffer->addCommand<CbTexture>() =
CbTexture( (uint16)texUnit, mAreaLightMasks, mAreaLightMasksSamplerblock );
++texUnit;
}
if( mLightProfilesTexture )
{
*commandBuffer->addCommand<CbTexture>() =
CbTexture( (uint16)texUnit, mLightProfilesTexture, mAreaLightMasksSamplerblock );
++texUnit;
}
if( mLtcMatrixTexture )
{
*commandBuffer->addCommand<CbTexture>() =
CbTexture( (uint16)texUnit, mLtcMatrixTexture, mAreaLightMasksSamplerblock );
++texUnit;
}
for( size_t i = 0u; i < 3u; ++i )
{
if( mDecalsTextures[i] && ( i != 2u || !mDecalsDiffuseMergedEmissive ) )
{
*commandBuffer->addCommand<CbTexture>() =
CbTexture( (uint16)texUnit, mDecalsTextures[i], mDecalsSamplerblock );
++texUnit;
}
}
// We changed HlmsType, rebind the shared textures.
FastArray<TextureGpu *>::const_iterator itor = mPreparedPass.shadowMaps.begin();
FastArray<TextureGpu *>::const_iterator end = mPreparedPass.shadowMaps.end();
while( itor != end )
{
*commandBuffer->addCommand<CbTexture>() =
CbTexture( (uint16)texUnit, *itor, mCurrentShadowmapSamplerblock );
++texUnit;
++itor;
}
if( mParallaxCorrectedCubemap && !mParallaxCorrectedCubemap->isRendering() )
{
TextureGpu *pccTexture = mParallaxCorrectedCubemap->getBindTexture();
const HlmsSamplerblock *samplerblock =
mParallaxCorrectedCubemap->getBindTrilinearSamplerblock();
*commandBuffer->addCommand<CbTexture>() =
CbTexture( (uint16)texUnit, pccTexture, samplerblock );
++texUnit;
}
}
mLastDescTexture = 0;
mLastDescSampler = 0;
mLastBoundPool = 0;
// layout(binding = 2) uniform InstanceBuffer {} instance
if( mCurrentConstBuffer < mConstBuffers.size() &&
(size_t)( ( mCurrentMappedConstBuffer - mStartMappedConstBuffer ) + 4 ) <=
mCurrentConstBufferSize )
{
*commandBuffer->addCommand<CbShaderBuffer>() =
CbShaderBuffer( VertexShader, 2, mConstBuffers[mCurrentConstBuffer], 0, 0 );
*commandBuffer->addCommand<CbShaderBuffer>() =
CbShaderBuffer( PixelShader, 2, mConstBuffers[mCurrentConstBuffer], 0, 0 );
}
rebindTexBuffer( commandBuffer );
#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
mLastBoundPlanarReflection = 0u;
#endif
mListener->hlmsTypeChanged( casterPass, commandBuffer, datablock, texUnit );
}
// Don't bind the material buffer on caster passes (important to keep
// MDI & auto-instancing running on shadow map passes)
if( mLastBoundPool != datablock->getAssignedPool() &&
( !casterPass || datablock->getAlphaTest() != CMPF_ALWAYS_PASS ) )
{
// layout(binding = 1) uniform MaterialBuf {} materialArray
const ConstBufferPool::BufferPool *newPool = datablock->getAssignedPool();
*commandBuffer->addCommand<CbShaderBuffer>() =
CbShaderBuffer( VertexShader, 1, newPool->materialBuffer, 0,
(uint32)newPool->materialBuffer->getTotalSizeBytes() );
*commandBuffer->addCommand<CbShaderBuffer>() =
CbShaderBuffer( PixelShader, 1, newPool->materialBuffer, 0,
(uint32)newPool->materialBuffer->getTotalSizeBytes() );
CubemapProbe *manualProbe = datablock->getCubemapProbe();
if( manualProbe )
{
OGRE_ASSERT_HIGH( manualProbe->getCreator() == mParallaxCorrectedCubemap &&
"Material has manual cubemap probe that does not match the "
"PCC currently set" );
ConstBufferPacked *probeConstBuf = manualProbe->getConstBufferForManualProbes();
*commandBuffer->addCommand<CbShaderBuffer>() =
CbShaderBuffer( PixelShader, 3, probeConstBuf, 0, 0 );
}
mLastBoundPool = newPool;
}
uint32 *RESTRICT_ALIAS currentMappedConstBuffer = mCurrentMappedConstBuffer;
float *RESTRICT_ALIAS currentMappedTexBuffer = mCurrentMappedTexBuffer;
bool hasSkeletonAnimation = queuedRenderable.renderable->hasSkeletonAnimation();
uint32 numPoses = queuedRenderable.renderable->getNumPoses();
uint32 poseWeightsNumFloats = ( ( numPoses >> 2u ) + std::min( numPoses % 4u, 1u ) ) * 4u;
const Matrix4 &worldMat = queuedRenderable.movableObject->_getParentNodeFullTransform();
//---------------------------------------------------------------------------
// ---- VERTEX SHADER ----
//---------------------------------------------------------------------------
if( !hasSkeletonAnimation && numPoses == 0 )
{
// We need to correct currentMappedConstBuffer to point to the right texture buffer's
// offset, which may not be in sync if the previous draw had skeletal and/or pose animation.
const size_t currentConstOffset =
static_cast<size_t>( currentMappedTexBuffer - mStartMappedTexBuffer ) >>
( 2u + !casterPass );
currentMappedConstBuffer = currentConstOffset + mStartMappedConstBuffer;
bool exceedsConstBuffer =
static_cast<size_t>( ( currentMappedConstBuffer - mStartMappedConstBuffer ) + 4u ) >
mCurrentConstBufferSize;
const size_t minimumTexBufferSize = 16u * ( 1u + !casterPass );
bool exceedsTexBuffer =
( static_cast<size_t>( currentMappedTexBuffer - mStartMappedTexBuffer ) +
minimumTexBufferSize ) >= mCurrentTexBufferSize;
if( exceedsConstBuffer || exceedsTexBuffer )
{
currentMappedConstBuffer = mapNextConstBuffer( commandBuffer );
if( exceedsTexBuffer )
mapNextTexBuffer( commandBuffer, minimumTexBufferSize * sizeof( float ) );
else
rebindTexBuffer( commandBuffer, true, minimumTexBufferSize * sizeof( float ) );
currentMappedTexBuffer = mCurrentMappedTexBuffer;
}
// uint worldMaterialIdx[]
*currentMappedConstBuffer = datablock->getAssignedSlot() & 0x1FF;
// mat4x3 world
#if !OGRE_DOUBLE_PRECISION
memcpy( currentMappedTexBuffer, &worldMat, 4 * 3 * sizeof( float ) );
currentMappedTexBuffer += 16;
#else
for( int y = 0; y < 3; ++y )
{
for( int x = 0; x < 4; ++x )
{
*currentMappedTexBuffer++ = worldMat[y][x];
}
}
currentMappedTexBuffer += 4;
#endif
// mat4 worldView
Matrix4 tmp = mPreparedPass.viewMatrix.concatenateAffine( worldMat );
#if !OGRE_DOUBLE_PRECISION
memcpy( currentMappedTexBuffer, &tmp, sizeof( Matrix4 ) * !casterPass );
currentMappedTexBuffer += 16 * !casterPass;
#else
if( !casterPass )
{
for( int y = 0; y < 4; ++y )
{
for( int x = 0; x < 4; ++x )
{
*currentMappedTexBuffer++ = tmp[y][x];
}
}
}
#endif
}
else
{
bool exceedsConstBuffer = (size_t)( ( currentMappedConstBuffer - mStartMappedConstBuffer ) +
4 ) > mCurrentConstBufferSize;
if( hasSkeletonAnimation )
{
if( isV1 )
{
uint16 numWorldTransforms = queuedRenderable.renderable->getNumWorldTransforms();
assert( numWorldTransforms <= 256u );
const size_t poseDataSize = numPoses > 0u ? ( 4u + poseWeightsNumFloats ) : 0u;
const size_t minimumTexBufferSize = 12 * numWorldTransforms + poseDataSize;
const bool exceedsTexBuffer =
static_cast<size_t>( currentMappedTexBuffer - mStartMappedTexBuffer ) +
minimumTexBufferSize >=
mCurrentTexBufferSize;
if( exceedsConstBuffer || exceedsTexBuffer )
{
currentMappedConstBuffer = mapNextConstBuffer( commandBuffer );
if( exceedsTexBuffer )
mapNextTexBuffer( commandBuffer, minimumTexBufferSize * sizeof( float ) );
else
rebindTexBuffer( commandBuffer, true,
minimumTexBufferSize * sizeof( float ) );
currentMappedTexBuffer = mCurrentMappedTexBuffer;
}
// uint worldMaterialIdx[]
size_t distToWorldMatStart =
static_cast<size_t>( mCurrentMappedTexBuffer - mStartMappedTexBuffer );
distToWorldMatStart >>= 2;
*currentMappedConstBuffer = uint32( ( distToWorldMatStart << 9 ) |
( datablock->getAssignedSlot() & 0x1FF ) );
// vec4 worldMat[][3]
// TODO: Don't rely on a virtual function + make a direct 4x3 copy
Matrix4 tmp[256];
queuedRenderable.renderable->getWorldTransforms( tmp );
for( size_t i = 0u; i < numWorldTransforms; ++i )
{
#if !OGRE_DOUBLE_PRECISION
memcpy( currentMappedTexBuffer, &tmp[i], 12 * sizeof( float ) );
currentMappedTexBuffer += 12;
#else
for( int y = 0; y < 3; ++y )
{
for( int x = 0; x < 4; ++x )
{
*currentMappedTexBuffer++ = tmp[i][y][x];
}
}
#endif
}
}
else
{
SkeletonInstance *skeleton = queuedRenderable.movableObject->getSkeletonInstance();
#if OGRE_DEBUG_MODE
assert( dynamic_cast<const RenderableAnimated *>( queuedRenderable.renderable ) );
#endif
const RenderableAnimated *renderableAnimated =
static_cast<const RenderableAnimated *>( queuedRenderable.renderable );
const RenderableAnimated::IndexMap *indexMap =
renderableAnimated->getBlendIndexToBoneIndexMap();
const size_t poseDataSize = numPoses > 0u ? ( 4u + poseWeightsNumFloats ) : 0u;
const size_t minimumTexBufferSize = 12 * indexMap->size() + poseDataSize;
bool exceedsTexBuffer =
static_cast<size_t>( currentMappedTexBuffer - mStartMappedTexBuffer ) +
minimumTexBufferSize >=
mCurrentTexBufferSize;
if( exceedsConstBuffer || exceedsTexBuffer )
{
currentMappedConstBuffer = mapNextConstBuffer( commandBuffer );
if( exceedsTexBuffer )
mapNextTexBuffer( commandBuffer, minimumTexBufferSize * sizeof( float ) );
else
rebindTexBuffer( commandBuffer, true,
minimumTexBufferSize * sizeof( float ) );
currentMappedTexBuffer = mCurrentMappedTexBuffer;
}
// uint worldMaterialIdx[]
size_t distToWorldMatStart =
static_cast<size_t>( mCurrentMappedTexBuffer - mStartMappedTexBuffer );
distToWorldMatStart >>= 2;
*currentMappedConstBuffer = uint32( ( distToWorldMatStart << 9 ) |
( datablock->getAssignedSlot() & 0x1FF ) );
RenderableAnimated::IndexMap::const_iterator itBone = indexMap->begin();
RenderableAnimated::IndexMap::const_iterator enBone = indexMap->end();
while( itBone != enBone )
{
const SimpleMatrixAf4x3 &mat4x3 = skeleton->_getBoneFullTransform( *itBone );
mat4x3.streamTo4x3( currentMappedTexBuffer );
currentMappedTexBuffer += 12;
++itBone;
}
}
}
if( numPoses > 0 )
{
if( !hasSkeletonAnimation )
{
// If not combined with skeleton animation, pose animations are gonna need 1 vec4's
// for pose data (base vertex, num vertices), enough vec4's to accomodate
// the weight of each pose, 3 vec4's for worldMat, and 4 vec4's for worldView.
const size_t minimumTexBufferSize = 4 + poseWeightsNumFloats + 3 * 4 + 4 * 4;
bool exceedsTexBuffer =
static_cast<size_t>( currentMappedTexBuffer - mStartMappedTexBuffer ) +
minimumTexBufferSize >=
mCurrentTexBufferSize;
if( exceedsConstBuffer || exceedsTexBuffer )
{
currentMappedConstBuffer = mapNextConstBuffer( commandBuffer );
if( exceedsTexBuffer )
mapNextTexBuffer( commandBuffer, minimumTexBufferSize * sizeof( float ) );
else
rebindTexBuffer( commandBuffer, true,
minimumTexBufferSize * sizeof( float ) );
currentMappedTexBuffer = mCurrentMappedTexBuffer;
}
// uint worldMaterialIdx[]
size_t distToWorldMatStart =
static_cast<size_t>( mCurrentMappedTexBuffer - mStartMappedTexBuffer );
distToWorldMatStart >>= 2;
*currentMappedConstBuffer = uint32( ( distToWorldMatStart << 9 ) |
( datablock->getAssignedSlot() & 0x1FF ) );
}
uint8 meshLod = queuedRenderable.movableObject->getCurrentMeshLod();
const VertexArrayObjectArray &vaos =
queuedRenderable.renderable->getVaos( static_cast<VertexPass>( casterPass ) );
VertexArrayObject *vao = vaos[meshLod];
// According to this https://forums.ogre3d.org/viewtopic.php?f=25&t=95040#p545057
// "macOS uses an old OpenGL version which doesn't use baseVertex"
#ifdef __APPLE__
uint32 baseVertex = 0;
#else
uint32 baseVertex =
static_cast<uint32>( vao->getBaseVertexBuffer()->_getFinalBufferStart() );
#endif
memcpy( currentMappedTexBuffer, &baseVertex, sizeof( baseVertex ) );
size_t numVertices = vao->getBaseVertexBuffer()->getNumElements();
memcpy( currentMappedTexBuffer + 1, &numVertices, sizeof( numVertices ) );
currentMappedTexBuffer += 4;
memcpy( currentMappedTexBuffer, queuedRenderable.renderable->getPoseWeights(),
sizeof( float ) * numPoses );
currentMappedTexBuffer += poseWeightsNumFloats;
if( !hasSkeletonAnimation )
{
// mat4x3 world
#if !OGRE_DOUBLE_PRECISION
memcpy( currentMappedTexBuffer, &worldMat, 4 * 3 * sizeof( float ) );
currentMappedTexBuffer += 12;
#else
for( int y = 0; y < 3; ++y )
{
for( int x = 0; x < 4; ++x )
{
*currentMappedTexBuffer++ = worldMat[y][x];
}
}
#endif
// mat4 worldView
Matrix4 tmp = mPreparedPass.viewMatrix.concatenateAffine( worldMat );
#if !OGRE_DOUBLE_PRECISION
memcpy( currentMappedTexBuffer, &tmp, sizeof( Matrix4 ) * !casterPass );
currentMappedTexBuffer += 16 * !casterPass;
#else
if( !casterPass )
{
for( int y = 0; y < 4; ++y )
{
for( int x = 0; x < 4; ++x )
{
*currentMappedTexBuffer++ = tmp[y][x];
}
}
}
#endif
}
size_t numTextures = 0u;
if( datablock->mTexturesDescSet )
numTextures = datablock->mTexturesDescSet->mTextures.size();
TexBufferPacked *poseBuf = queuedRenderable.renderable->getPoseTexBuffer();
*commandBuffer->addCommand<CbShaderBuffer>() =
CbShaderBuffer( VertexShader, uint16( mTexUnitSlotStart + numTextures ), poseBuf, 0,
(uint32)poseBuf->getTotalSizeBytes() );
}
// If the next entity will not be skeletally animated, we'll need
// currentMappedTexBuffer to be 16/32-byte aligned.
// Non-skeletally animated objects are far more common than skeletal ones,
// so we do this here instead of doing it before rendering the non-skeletal ones.
size_t currentConstOffset = (size_t)( currentMappedTexBuffer - mStartMappedTexBuffer );
currentConstOffset =
alignToNextMultiple<size_t>( currentConstOffset, 16 + 16 * !casterPass );
currentConstOffset = std::min( currentConstOffset, mCurrentTexBufferSize );
currentMappedTexBuffer = mStartMappedTexBuffer + currentConstOffset;
}
*reinterpret_cast<float * RESTRICT_ALIAS>( currentMappedConstBuffer + 1 ) =
datablock->mShadowConstantBias * mConstantBiasScale;
#if !OGRE_NO_FINE_LIGHT_MASK_GRANULARITY
*( currentMappedConstBuffer + 2u ) = queuedRenderable.movableObject->getLightMask();
#endif
#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
*( currentMappedConstBuffer + 3u ) = queuedRenderable.renderable->mCustomParameter & 0x7F;
#endif
currentMappedConstBuffer += 4;
//---------------------------------------------------------------------------
// ---- PIXEL SHADER ----
//---------------------------------------------------------------------------
if( !casterPass || datablock->getAlphaTest() != CMPF_ALWAYS_PASS )
{
#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
if( !casterPass && mHasPlanarReflections &&
( queuedRenderable.renderable->mCustomParameter & 0x80 /* UseActiveActor */ ) &&
mLastBoundPlanarReflection != queuedRenderable.renderable->mCustomParameter )
{
const uint8 activeActorIdx = queuedRenderable.renderable->mCustomParameter & 0x7F;
TextureGpu *planarReflTex = mPlanarReflections->getTexture( activeActorIdx );
*commandBuffer->addCommand<CbTexture>() = CbTexture(
uint16( mTexUnitSlotStart - 1u ), planarReflTex, mPlanarReflectionsSamplerblock );
mLastBoundPlanarReflection = queuedRenderable.renderable->mCustomParameter;
}
#endif
if( datablock->mTexturesDescSet != mLastDescTexture )
{
if( datablock->mTexturesDescSet )
{
// Rebind textures
size_t texUnit = mTexUnitSlotStart;
*commandBuffer->addCommand<CbTextures>() = CbTextures(
(uint16)texUnit, datablock->mCubemapIdxInDescSet, datablock->mTexturesDescSet );
if( !mHasSeparateSamplers )
{
*commandBuffer->addCommand<CbSamplers>() =
CbSamplers( (uint16)texUnit, datablock->mSamplersDescSet );
}
// texUnit += datablock->mTexturesDescSet->mTextures.size();
}
mLastDescTexture = datablock->mTexturesDescSet;
}
if( datablock->mSamplersDescSet != mLastDescSampler && mHasSeparateSamplers )
{
if( datablock->mSamplersDescSet )
{
// Bind samplers
size_t texUnit = mTexUnitSlotStart;
*commandBuffer->addCommand<CbSamplers>() =
CbSamplers( (uint16)texUnit, datablock->mSamplersDescSet );
mLastDescSampler = datablock->mSamplersDescSet;
}
}
}
mCurrentMappedConstBuffer = currentMappedConstBuffer;
mCurrentMappedTexBuffer = currentMappedTexBuffer;
return uint32( ( ( mCurrentMappedConstBuffer - mStartMappedConstBuffer ) >> 2u ) - 1u );
}
//-----------------------------------------------------------------------------------
void HlmsPbs::destroyAllBuffers()
{
HlmsBufferManager::destroyAllBuffers();
mCurrentPassBuffer = 0;
{
ConstBufferPackedVec::const_iterator itor = mPassBuffers.begin();
ConstBufferPackedVec::const_iterator end = mPassBuffers.end();
while( itor != end )
{
if( ( *itor )->getMappingState() != MS_UNMAPPED )
( *itor )->unmap( UO_UNMAP_ALL );
mVaoManager->destroyConstBuffer( *itor );
++itor;
}
mPassBuffers.clear();
}
///////// light buffers
{
ConstBufferPackedVec::const_iterator itor = mLight0Buffers.begin();
ConstBufferPackedVec::const_iterator end = mLight0Buffers.end();
while( itor != end )
{
if( ( *itor )->getMappingState() != MS_UNMAPPED )
( *itor )->unmap( UO_UNMAP_ALL );
mVaoManager->destroyConstBuffer( *itor );
++itor;
}
mLight0Buffers.clear();
}
{
ConstBufferPackedVec::const_iterator itor = mLight1Buffers.begin();
ConstBufferPackedVec::const_iterator end = mLight1Buffers.end();
while( itor != end )
{
if( ( *itor )->getMappingState() != MS_UNMAPPED )
( *itor )->unmap( UO_UNMAP_ALL );
mVaoManager->destroyConstBuffer( *itor );
++itor;
}
mLight1Buffers.clear();
}
{
ConstBufferPackedVec::const_iterator itor = mLight2Buffers.begin();
ConstBufferPackedVec::const_iterator end = mLight2Buffers.end();
while( itor != end )
{
if( ( *itor )->getMappingState() != MS_UNMAPPED )
( *itor )->unmap( UO_UNMAP_ALL );
mVaoManager->destroyConstBuffer( *itor );
++itor;
}
mLight2Buffers.clear();
}
}
//-----------------------------------------------------------------------------------
void HlmsPbs::postCommandBufferExecution( CommandBuffer *commandBuffer )
{
HlmsBufferManager::postCommandBufferExecution( commandBuffer );
if( mPrePassMsaaDepthTexture )
{
// We need to unbind the depth texture, it may be used as a depth buffer later.
size_t texUnit = mReservedTexBufferSlots + mReservedTexSlots + ( mGridBuffer ? 2u : 0u );
if( !mPrePassTextures->empty() )
texUnit += 2;
mRenderSystem->_setTexture( texUnit, 0, false );
}
}
//-----------------------------------------------------------------------------------
void HlmsPbs::frameEnded()
{
HlmsBufferManager::frameEnded();
mCurrentPassBuffer = 0;
}
//-----------------------------------------------------------------------------------
void HlmsPbs::setStaticBranchingLights( bool staticBranchingLights )
{
if( staticBranchingLights )
{
// Make sure we calculate light positions in pixel shaders
setShadowReceiversInPixelShader( true );
}
Hlms::setStaticBranchingLights( staticBranchingLights );
}
//-----------------------------------------------------------------------------------
void HlmsPbs::resetIblSpecMipmap( uint8 numMipmaps )
{
if( numMipmaps != 0u )
{
mAutoSpecIblMaxMipmap = false;
mMaxSpecIblMipmap = numMipmaps;
}
else
{
mAutoSpecIblMaxMipmap = true;
mMaxSpecIblMipmap = 1.0f;
HlmsDatablockMap::const_iterator itor = mDatablocks.begin();
HlmsDatablockMap::const_iterator endt = mDatablocks.end();
while( itor != endt )
{
assert( dynamic_cast<HlmsPbsDatablock *>( itor->second.datablock ) );
HlmsPbsDatablock *datablock = static_cast<HlmsPbsDatablock *>( itor->second.datablock );
TextureGpu *reflTexture = datablock->getTexture( PBSM_REFLECTION );
if( reflTexture )
{
mMaxSpecIblMipmap =
std::max<float>( reflTexture->getNumMipmaps(), mMaxSpecIblMipmap );
}
++itor;
}
if( mParallaxCorrectedCubemap )
{
TextureGpu *bindTexture = mParallaxCorrectedCubemap->getBindTexture();
if( bindTexture )
{
mMaxSpecIblMipmap =
std::max<float>( bindTexture->getNumMipmaps(), mMaxSpecIblMipmap );
}
}
}
}
//-----------------------------------------------------------------------------------
void HlmsPbs::_notifyIblSpecMipmap( uint8 numMipmaps )
{
if( mAutoSpecIblMaxMipmap )
mMaxSpecIblMipmap = std::max<float>( numMipmaps, mMaxSpecIblMipmap );
}
//-----------------------------------------------------------------------------------
void HlmsPbs::loadLtcMatrix()
{
const uint32 poolId = 992044u;
TextureGpuManager *textureGpuManager = mRenderSystem->getTextureGpuManager();
if( !textureGpuManager->hasPoolId( poolId, 64u, 64u, 1u, PFG_RGBA16_FLOAT ) )
textureGpuManager->reservePoolId( poolId, 64u, 64u, 3u, 1u, PFG_RGBA16_FLOAT );
TextureGpu *ltcMat0 = textureGpuManager->createOrRetrieveTexture(
"ltcMatrix0.dds", GpuPageOutStrategy::Discard, TextureFlags::AutomaticBatching,
TextureTypes::Type2D, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, 0, poolId );
TextureGpu *ltcMat1 = textureGpuManager->createOrRetrieveTexture(
"ltcMatrix1.dds", GpuPageOutStrategy::Discard, TextureFlags::AutomaticBatching,
TextureTypes::Type2D, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, 0, poolId );
TextureGpu *brtfLut2 = textureGpuManager->createOrRetrieveTexture(
"brtfLutDfg.dds", GpuPageOutStrategy::Discard, TextureFlags::AutomaticBatching,
TextureTypes::Type2D, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, 0, poolId );
ltcMat0->scheduleTransitionTo( GpuResidency::Resident );
ltcMat1->scheduleTransitionTo( GpuResidency::Resident );
brtfLut2->scheduleTransitionTo( GpuResidency::Resident );
ltcMat0->waitForMetadata();
ltcMat1->waitForMetadata();
brtfLut2->waitForMetadata();
OGRE_ASSERT_LOW(
ltcMat0->getTexturePool() == ltcMat1->getTexturePool() &&
"ltcMatrix0.dds & ltcMatrix1.dds must be the same resolution and pixel format" );
OGRE_ASSERT_LOW(
ltcMat0->getTexturePool() == brtfLut2->getTexturePool() &&
"ltcMatrix0.dds & brtfLutDfg2.dds must be the same resolution and pixel format" );
OGRE_ASSERT_LOW( ltcMat0->getInternalSliceStart() == 0u );
OGRE_ASSERT_LOW( ltcMat1->getInternalSliceStart() == 1u );
OGRE_ASSERT_LOW( brtfLut2->getInternalSliceStart() == 2u );
mLtcMatrixTexture = ltcMat0;
}
//-----------------------------------------------------------------------------------
void HlmsPbs::getDefaultPaths( String &outDataFolderPath, StringVector &outLibraryFoldersPaths )
{
// We need to know what RenderSystem is currently in use, as the
// name of the compatible shading language is part of the path
Ogre::RenderSystem *renderSystem = Ogre::Root::getSingleton().getRenderSystem();
Ogre::String shaderSyntax = "GLSL";
if( renderSystem->getName() == "OpenGL ES 2.x Rendering Subsystem" )
shaderSyntax = "GLSLES";
else if( renderSystem->getName() == "Direct3D11 Rendering Subsystem" )
shaderSyntax = "HLSL";
else if( renderSystem->getName() == "Metal Rendering Subsystem" )
shaderSyntax = "Metal";
// Fill the library folder paths with the relevant folders
outLibraryFoldersPaths.clear();
outLibraryFoldersPaths.push_back( "Hlms/Common/" + shaderSyntax );
outLibraryFoldersPaths.push_back( "Hlms/Common/Any" );
outLibraryFoldersPaths.push_back( "Hlms/Pbs/Any" );
outLibraryFoldersPaths.push_back( "Hlms/Pbs/Any/Main" );
// Fill the data folder path
outDataFolderPath = "Hlms/Pbs/" + shaderSyntax;
}
//-----------------------------------------------------------------------------------
void HlmsPbs::setShadowReceiversInPixelShader( bool bInPixelShader )
{
mShadowReceiversInPixelShader = bInPixelShader;
}
//-----------------------------------------------------------------------------------
void HlmsPbs::setDebugPssmSplits( bool bDebug ) { mDebugPssmSplits = bDebug; }
//-----------------------------------------------------------------------------------
void HlmsPbs::setPerceptualRoughness( bool bPerceptualRoughness )
{
mPerceptualRoughness = bPerceptualRoughness;
}
//-----------------------------------------------------------------------------------
bool HlmsPbs::getPerceptualRoughness() const { return mPerceptualRoughness; }
//-----------------------------------------------------------------------------------
void HlmsPbs::setShadowSettings( ShadowFilter filter )
{
mShadowFilter = filter;
ShadowCameraSetup::setUseEsm( filter == ExponentialShadowMaps );
}
//-----------------------------------------------------------------------------------
void HlmsPbs::setEsmK( uint16 K )
{
assert( K != 0 && "A value of K = 0 is invalid!" );
mEsmK = K;
}
//-----------------------------------------------------------------------------------
void HlmsPbs::setAmbientLightMode( AmbientLightMode mode ) { mAmbientLightMode = mode; }
//-----------------------------------------------------------------------------------
void HlmsPbs::setParallaxCorrectedCubemap( ParallaxCorrectedCubemapBase *pcc,
float pccVctMinDistance, float pccVctMaxDistance )
{
OGRE_ASSERT_LOW( pccVctMinDistance < pccVctMaxDistance );
mParallaxCorrectedCubemap = pcc;
mPccVctMinDistance = pccVctMinDistance;
mInvPccVctInvDistance = 1.0f / ( pccVctMaxDistance - pccVctMinDistance );
}
//-----------------------------------------------------------------------------------
void HlmsPbs::setAreaLightMasks( TextureGpu *areaLightMask ) { mAreaLightMasks = areaLightMask; }
//-----------------------------------------------------------------------------------
void HlmsPbs::setLightProfilesTexture( TextureGpu *lightProfilesTex )
{
mLightProfilesTexture = lightProfilesTex;
}
#ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS
//-----------------------------------------------------------------------------------
void HlmsPbs::setPlanarReflections( PlanarReflections *planarReflections )
{
mPlanarReflections = planarReflections;
if( !mPlanarReflections )
mHasPlanarReflections = false;
}
//-----------------------------------------------------------------------------------
PlanarReflections *HlmsPbs::getPlanarReflections() const { return mPlanarReflections; }
#endif
#if OGRE_ENABLE_LIGHT_OBB_RESTRAINT
//-----------------------------------------------------------------------------------
void HlmsPbs::setUseObbRestraints( bool areaApprox, bool areaLtc )
{
mUseObbRestraintAreaApprox = areaApprox;
mUseObbRestraintAreaLtc = areaLtc;
}
#endif
void HlmsPbs::setUseLightBuffers( bool b ) { mUseLightBuffers = b; }
#if !OGRE_NO_JSON
//-----------------------------------------------------------------------------------
void HlmsPbs::_loadJson( const rapidjson::Value &jsonValue, const HlmsJson::NamedBlocks &blocks,
HlmsDatablock *datablock, const String &resourceGroup,
HlmsJsonListener *listener, const String &additionalTextureExtension ) const
{
HlmsJsonPbs jsonPbs( mHlmsManager, mRenderSystem->getTextureGpuManager(), listener,
additionalTextureExtension );
jsonPbs.loadMaterial( jsonValue, blocks, datablock, resourceGroup );
}
//-----------------------------------------------------------------------------------
void HlmsPbs::_saveJson( const HlmsDatablock *datablock, String &outString,
HlmsJsonListener *listener, const String &additionalTextureExtension ) const
{
HlmsJsonPbs jsonPbs( mHlmsManager, mRenderSystem->getTextureGpuManager(), listener,
additionalTextureExtension );
jsonPbs.saveMaterial( datablock, outString );
}
//-----------------------------------------------------------------------------------
void HlmsPbs::_collectSamplerblocks( set<const HlmsSamplerblock *>::type &outSamplerblocks,
const HlmsDatablock *datablock ) const
{
HlmsJsonPbs::collectSamplerblocks( datablock, outSamplerblocks );
}
#endif
//-----------------------------------------------------------------------------------
HlmsDatablock *HlmsPbs::createDatablockImpl( IdString datablockName,
const HlmsMacroblock *macroblock,
const HlmsBlendblock *blendblock,
const HlmsParamVec ¶mVec )
{
return OGRE_NEW HlmsPbsDatablock( datablockName, this, macroblock, blendblock, paramVec );
}
} // namespace Ogre
|
; A280172: Lexicographically earliest table of positive integers read by antidiagonals such that no row or column contains a repeated term.
; Submitted by Jon Maiga
; 1,2,2,3,1,3,4,4,4,4,5,3,1,3,5,6,6,2,2,6,6,7,5,7,1,7,5,7,8,8,8,8,8,8,8,8,9,7,5,7,1,7,5,7,9,10,10,6,6,2,2,6,6,10,10,11,9,11,5,3,1,3,5,11,9,11,12,12,12,12,4,4,4,4,12,12,12,12,13,11,9,11,13,3,1,3,13,11,9,11,13,14,14,10,10,14,14,2,2,14
seq $0,3987 ; Table of n XOR m (or Nim-sum of n and m) read by antidiagonals, i.e., with entries in the order (n,m) = (0,0), (0,1), (1,0), (0,2), (1,1), (2,0), ...
add $0,1
|
; A021457: Decimal expansion of 1/453.
; Submitted by Jon Maiga
; 0,0,2,2,0,7,5,0,5,5,1,8,7,6,3,7,9,6,9,0,9,4,9,2,2,7,3,7,3,0,6,8,4,3,2,6,7,1,0,8,1,6,7,7,7,0,4,1,9,4,2,6,0,4,8,5,6,5,1,2,1,4,1,2,8,0,3,5,3,2,0,0,8,8,3,0,0,2,2,0,7,5,0,5,5,1,8,7,6,3,7,9,6,9,0,9,4,9,2
mov $2,10
pow $2,$0
mul $2,10
div $2,453
mov $0,$2
mod $0,10
|
;------------------------------------------------------------------------------
;
; 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:
;
; ReadEs.Asm
;
; Abstract:
;
; AsmReadEs function
;
; Notes:
;
;------------------------------------------------------------------------------
SECTION .text
;------------------------------------------------------------------------------
; UINT16
; EFIAPI
; AsmReadEs (
; VOID
; );
;------------------------------------------------------------------------------
global ASM_PFX(AsmReadEs)
ASM_PFX(AsmReadEs):
mov eax, es
ret
|
org 100h
.data
str db 10,13,”Enter Values: $”
str1 db 0dh,0ah,”Sorted: $”
array db 10dup(0)
.code
mov ah,9
lea dx,str
int 21h
mov cx,10
mov bx,offset array
mov ah,1
inputs:
int 21h
mov [bx],al
inc bx
Loop inputs
mov cx,10
dec cx
nextscan:
mov bx,cx
mov si,0
nextcomp:
mov al,array[si] mov dl,array[si+1] cmp al,dl
jc noswap
mov array[si],dl
mov array[si+1],al
noswap:
inc si
dec bx
jnz nextcomp
loop nextscan
mov ah,9
lea dx,str1
int 21h
mov cx,10
mov bx,offset array
print:
mov ah,2
mov dl,[bx] int 21h
inc bx
loop print
ret
|
%ifdef CONFIG
{
"RegData": {
"RAX": "0x0",
"RBX": "0x3"
},
"MemoryRegions": {
"0x100000000": "4096"
}
}
%endif
mov rdx, 0xe0000000
mov rax, 0x4142434445464748
mov [rdx + 8 * 0], rax
mov rax, 0x5152535455565758
mov [rdx + 8 * 1], rax
mov rax, 0x8000000080000000
mov [rdx + 8 * 2], rax
mov rax, 0x7000000070000000
mov [rdx + 8 * 3], rax
movaps xmm0, [rdx + 8 * 0]
movaps xmm1, [rdx + 8 * 2]
movmskps rax, xmm0
movmskps rbx, xmm1
hlt
|
; A207255: Number of 4 X n 0..1 arrays avoiding 0 0 1 and 1 0 1 horizontally and 0 1 0 and 1 0 1 vertically.
; 10,100,370,940,1950,3560,5950,9320,13890,19900,27610,37300,49270,63840,81350,102160,126650,155220,188290,226300,269710,319000,374670,437240,507250,585260,671850,767620,873190,989200,1116310,1255200,1406570,1571140,1749650,1942860,2151550,2376520,2618590,2878600,3157410,3455900,3774970,4115540,4478550,4864960,5275750,5711920,6174490,6664500,7183010,7731100,8309870,8920440,9563950,10241560,10954450,11703820,12490890,13316900,14183110,15090800,16041270,17035840,18075850,19162660,20297650,21482220
add $0,1
mov $2,1
sub $2,$0
pow $0,3
add $0,5
bin $2,4
add $2,1
add $0,$2
add $0,$2
sub $0,8
mul $0,10
add $0,10
|
; A001650: n appears n times (n odd).
; 1,3,3,3,5,5,5,5,5,7,7,7,7,7,7,7,9,9,9,9,9,9,9,9,9,11,11,11,11,11,11,11,11,11,11,11,13,13,13,13,13,13,13,13,13,13,13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31
add $0,1
lpb $0,1
add $1,2
sub $0,$1
lpe
add $1,1
|
; SLAE - Assignment #3: Small Egghunter (Linux/x86) - 19 bytes
; Author: Julien Ahrens (@MrTuxracer)
; Website: http://www.rcesecurity.com
global _start
section .text
_start:
mov eax, esp ;get current working stack address
mov ebx, 0x42904a90 ;egg=INC EDX, NOP, DEC EDX, NOP
search_the_egg:
inc eax ;go upwards the stack addresses
cmp dword [eax], ebx ;check if address contains egg
jne search_the_egg ;loop until we found it
cmp dword[eax+4], ebx ;if egg is found, dheck next four bytes for egg again
jne search_the_egg ;not found? must be a standalone egg ;)
jmp eax ;execute egg+shellcode
|
TITLE prscg.asm - Parser Code Generation Functions
;==========================================================================
;
; Module: prscg.asm - Parser Code Generation Functions
; Subsystem: Parser
; System: Quick BASIC Interpreter
;
;==========================================================================
include version.inc
PRSCG_ASM = ON
includeOnce architec
includeOnce context
includeOnce heap
includeOnce opmin
includeOnce opcontrl
includeOnce opstmt
includeOnce opintrsc
includeOnce parser
includeOnce pcode
includeOnce prstab
includeOnce psint
includeOnce qbimsgs
includeOnce rtps
includeOnce scanner
includeOnce txtmgr
includeOnce ui
includeOnce util
includeOnce variable
;--------------------------------------------------------------------------
; Code Generation Overview
;
; During the course of interpreting the parse state tables, NtParse()
; encounters MARK(nnn) directives. These cause NtParse to push
; the current pcode offset and the constant nnn onto a stack as follows:
;
; Given BNF of
; exp MARK(1) exp MARK(2) exp
;
; Before parsing the statement, the marker stack looks like:
; high memory:
; maxStkMark--> <--pCurStkMark
; :
; minStkMark-->
; low memory:
;
; After parsing the statement, but before calling the code generation
; function for the statement, the marker stack looks like:
; high memory:
; maxStkMark-->[oDstPcode]
;
; [oDstPcode]
; <--pCurStkMark
; :
; minStkMark-->
; low memory:
;
; Code generation functions use the information on the marker stack to
; decide how to alter pcode already emitted to the pcode buffer during
; parsing.
; An Argument may be passed to a code generation function in ax.
;
;--------------------------------------------------------------------------
assumes ds,DATA
assumes ss,DATA
assumes es,NOTHING
sBegin DATA
sEnd DATA
sBegin CP
assumes cs,CP
;*********************************************************************
; VOID InsertOp(ax:opcode, bx:oDst)
;
; Purpose:
; Insert an opcode at a given offset into the pcode buffer
; If out-of-memory, ps.errCode = ER_OM on exit
;
; Entry:
; bx = offset into ps.bdpDst where word is to be inserted
; ax = word to be inserted
; Exit:
; Caller's can depend on bx being preserved
; If an out-of-memory error occurs, ps.errCode = ER_OM
;
;*********************************************************************
InsertOp PROC NEAR
;make room for 2 bytes in pcode buffer before oDst
; BdShiftRight((bd *)&ps.bdpDst, oDst, (ushort)2))
push bx ;save caller's bx
push ax ;save opcode
push bx ;save oDst
PUSHI ax,<dataOFFSET ps.PS_bdpDst>
push bx ;pass oDst
PUSHI ax,2
call BdShiftRight ;grow buf, can cause heap movement
or ax,ax
je InsOpOmErr ;brif out-of-memory
call SetDstPbCur ;update ps.bdpDst.pbCur,
pop bx ;restore bx = oDst
add bx,[ps.PS_bdpDst.BDP_pb]
pop [bx] ;pop and store opcode
InsOpExit:
pop bx ;restore caller's bx
ret
InsOpOmErr:
call ParseErrOm ;Error "Out of memory"
pop bx
pop ax
jmp SHORT InsOpExit
InsertOp ENDP
;*********************************************************************
; VOID NEAR CgOn(ax:opcode)
;
; Purpose:
; Called after the RESTORE/RETURN statement has been parsed.
; It generates code for the statement.
;
; Entry:
; The top of the MARK stack (*pCurStkMark) is 1 or 2 for
; 1 for RESTORE
; 2 for RESTORE <label>
; opcode = the opcode to emit if top of MARK stack = 1
; This can be opStRestore0 or opStReturn0
;
; The bnf which causes this to occur is:
; tkON (event (tkGOSUB ((Lit0 EMIT(opEvGosub) EMIT(UNDEFINED)) |
; (EMIT(opEvGosub) LabLn)))) |
; (tkERROR tkGOTO ((Lit0 EMIT(opStOnError) EMIT(UNDEFINED)) |
; (EMIT(opStOnError) LabLn))) |
; (Exp (tkGOTO MARK(1) | tkGOSUB MARK(2)) LabLn {tkComma LabLn})
; <CgOn()>
;
;*********************************************************************
PUBLIC CgOn
CgOn PROC NEAR
mov bx,[pCurStkMark]
cmp bx,MAX_STK_MARK
je OnExit ;brif no MARK directives from BNF
push [bx] ;save markId
mov bx,[bx+2] ;bx = offset into pcode which preceeded
; markId
mov ax,[ps.PS_bdpDst.BDP_cbLogical]
sub ax,bx ;ax = byte count of operands
call InsertOp ;insert word AX at offset BX
; (bx is preserved)
pop ax ;restore ax = markId
cmp al,1 ;markId
mov ax,opStOnGoto
je GotGoto ;brif if MARK(1) directive (GOTO)
mov ax,opStOnGosub ;else it must be MARK(2) (GOSUB)
GotGoto:
call InsertOp ;insert word AX at offset BX
OnExit:
ret
CgOn ENDP
;*********************************************************************
; VOID NEAR CgInsert0or1(opcode)
;
; Purpose:
; Called after the RESTORE/RETURN statement has been parsed.
; It generates code for the statement.
; If out-of-memory, ps.errCode = ER_OM on exit
;
; Entry:
; The top of the MARK stack (*pCurStkMark) is 1 or 2 for
; 1 for RESTORE/RETURN/RESUME
; (generated pcode = opStRestore0/opStReturn0/opStResume0)
; 2 for RESTORE/RETURN/RESUME <label>
; (generated pcode = opStRestore1/opStReturn1/opStResume <label>)
; 3 for RESUME 0
; (generated pcode = opStResume <UNDEFINED>)
; 4 for RESUME NEXT
; (generated pcode = opStResumeNext)
;
; opcode = the opcode to emit if top of MARK stack = 1
; This can be opStRestore0, opStReturn0, or opStResume0
;
; The bnf which causes this to occur is:
; tkRESTORE MARK(1) [LabLn MARK(2)]
; <CgInsert0or1(opStRestore0)>
; tkRETURN MARK(1) [LabLn MARK(2)]
; <CgInsert0or1(opStReturn0)>
; tkRESUME MARK(1) [(LabLn MARK(2)) | (Lit0 MARK(3)) |
; (tkNEXT MARK(4))]
; <CgResume(opStResume0)>
;
;*********************************************************************
PUBLIC CgInsert0or1
CgInsert0or1 PROC NEAR
xchg dx,ax ;save opcode in dx
mov bx,[pCurStkMark]
mov al,[bx] ;al = markId
cmp al,1
je InsMark1 ;brif got RESUME or RETURN or RESTORE
; with no parameter
cmp al,2
je InsMark2
cmp al,3
je InsMark3 ;brif got RESUME 0
;else it must be MARK(4) RESUME NEXT
mov ax,opStResumeNext
jmp SHORT InsEmit
;got RESUME or RETURN or RESTORE with no parameter
InsMark1:
xchg ax,dx ;ax = opcode
InsEmit:
call Emit16_AX
jmp SHORT InsExit
InsMark2:
push dx ;save opcode
;make room for 2 more bytes at end of pcode buffer
PUSHI ax,<dataOFFSET ps.PS_bdpDst>
PUSHI ax,2
call BdGrow ;grow buf, can cause heap movement
or ax,ax
je InsOmErr
;move label's oNam forward in buffer by 2 bytes
mov bx,[ps.PS_bdpDst.BDP_pbCur]
mov ax,[bx-2]
mov [bx],ax
;Insert opcode before label's oNam
pop ax ;ax = opcode
inc ax ;map to opcode variant with no parm
; opStResumeLab opStRestoreLab or
; opStReturnLab
mov [bx-2],ax ;store opcode
call SetDstPbCur ;update ps.bdpDst.pbCur
jmp SHORT InsExit
;map RESUME 0 to opStResume(UNDEFINED)
InsMark3:
mov ax,opStResume
call Emit16_AX
mov ax,UNDEFINED
call Emit16_AX
InsExit:
ret
InsOmErr:
jmp ParseErrOm ;Error "Out of memory"
; and return to caller
CgInsert0or1 ENDP
;*********************************************************************
; ErrIfPrsHasTxtTbl()
; Purpose:
; If the current prs (prsCur) has a text table, generate an error.
; This is called by functions which are about to do something which
; can only be done to a "compiled" (external) procedure, not a
; pcoded procedure.
;
; Exit:
; returns FALSE if prsCur has a text table (condition codes set)
;
;*********************************************************************
ErrIfPrsHasTxtTbl PROC NEAR
sub ax,ax ;prepare to return FALSE
test [txdCur.TXD_flags],FTX_mrs
jne ErrNoText ;brif prs has no text table
mov ax,MSG_InvDecl OR PSERR_fAlert
call ParseErr0
mov ax,sp ;return TRUE (non-zero)
ErrNoText:
or ax,ax ;set condition codes for caller
ret
ErrIfPrsHasTxtTbl ENDP
;*********************************************************************
; VOID NEAR CgDeclare(opcode)
;
; Purpose:
; Called after the DECLARE, SUB, FUNCTION or DEF FN statement has
; been parsed. It generates code for the statement.
; The prs has already been created (by MakeProc in prsid.asm),
; and is active for all statements except DECLARE.
;
; Entry:
; Structure pdcl is filled in by parser terminal recognizers like
; NtIdSubDecl, NtIdFn [QB4], etc. to describe to prs being declared/defined
; The MARK stack (*pCurStkMark) contains entries built by the bnf:
; MARK 1 indicates CDECL was present
; MARK 2 -> ALIAS's string literal
; MARK 3 -> start of formal parm list
; MARK 4 indicates STATIC was found
; MARK 5 -> single line DEF FN's definition expression
; MARK 6 indicates ([parmlist]) was seen
; MARK 7 -> LIB's string literal [EB specific] [07]
; MARK 8 indicates AUTO was found [EB specific] [07]
;
; BNF which builds entry pcode:
; tkDECLARE
; (tkFUNCTION IdFuncDecl [tkCDECL MARK(1)]
; [tkALIAS MARK(2) LitString] MARK(3) parms) |
; (tkSUB IdSubDecl [tkCDECL MARK(1)]
; [tkALIAS MARK(2) LitString] MARK(3) parms)
; <CgDeclare(opStDeclare)>
; tkDEF IdFn MARK(3) parms [tkEQ MARK(5) Exp]
; <CgDeclare(opStDefFn)>
; tkFUNCTION IdFuncDef MARK(3) parms [tkSTATIC MARK(4)]
; <CgDeclare(opStFunction)>
; tkSUB IdSubDef MARK(3) parms [tkSTATIC MARK(4)]
; <CgDeclare(opStSub)>
;
; For the statement DECLARE SUB X CDECL ALIAS "abc" (BYVAL A(), B, ...)
; The pcode buffer contains:
; <"abc"> <idA> <idB> ...
; MARK(1)MARK(2)^MARK(3)^
;
; For the statement SUB X (BYVAL A(), B, ...) STATIC
; The pcode buffer contains:
; <idA> <idB> ...
; MARK(3)^MARK(8)
;
; Where <idX> is 3 16 bit words: oPrs, oNamProc, oTypProc
;
;*********************************************************************
cProc CgDeclare,<PUBLIC,NEAR,NODATA>,<si,di>
localW opcode
localW oDstParms
localW oDstAlias
localW oDstEndDef
localW cbLibInfo
localW procAtr
procAtr_LO EQU BYTE PTR (procAtr)
procAtr_HI EQU BYTE PTR (procAtr+1)
cBegin
mov [opcode],ax
mov ax,[ps.PS_bdpDst.BDP_cbLogical]
mov [oDstEndDef],ax ;save current size of output
sub ax,ax
mov [procAtr],ax
mov [oDstAlias],ax
mov [cbLibInfo],ax
mov al,[pdcl.PDCL_procType]
.errnz DCLA_procType - 0300h
or [procAtr_HI],al ;save procType in pcode field
mov al,[pdcl.PDCL_oTyp] ;al = value for low byte of ProcAtr
; word which DCLA_Explicit,
; DCLA_AsClause, and DCLA_oTyp
mov [procAtr_LO],al ;save oTyp in pcode field
sub ax,ax
cmp [pdcl.PDCL_fDeclare],al
je NotDeclare ;brif not DECLARE stmt
cmp [pdcl.PDCL_cParms],ax
jne MarkDisp ;brif got a parm list
dec [pdcl.PDCL_cParms] ;set to UNDEFINED so scanner knows
; to not use this for parm
; type/count checking
jmp SHORT MarkDisp
NotDeclare:
;If we don't get MARK(4), this SUB/FUNCTION has no STATIC keyword
and [prsCur.PRS_flags],NOT FP_STATIC
;-------------------------------------------------
;walk through MARK(xxx) entries from left to right
;-------------------------------------------------
MarkDisp:
mov si,MAX_STK_MARK
DeclMarkLoop:
cmp [pCurStkMark],si
jne DeclNextMark
jmp SHORT DeclEndOfMarks
DeclNextMark:
dec si
dec si
mov di,[si] ;di = oDstOpcode
dec si
dec si
mov ax,[si] ;ax = al = markId
dec ax
DbAssertRel ax,be,9,CP,<Unexpected MARK in CgDeclare()>
shl ax,1
xchg ax,bx ;bx = 2 * (markId - 1)
jmp WORD PTR cs:DeclDispTbl[bx] ;dispatch based on markId
DeclDispTbl:
DW DeclMark1 ;CDECL
DW DeclMark2 ;ALIAS
DW DeclMark3 ;parms (before left paren)
DW DeclMark4 ;STATIC
DW DeclMark5 ;single line DEF
DW DeclMark6 ;1st parm (after left paren)
;MARK(1): Got CDECL directive
DeclMark1:
call ErrIfPrsHasTxtTbl
jne DeclMarkLoop ;brif prs has a text table
.errnz DCLA_cdecl - 8000h
or [procAtr_HI],80h ;remember we got CDECL
jmp SHORT DeclMarkLoop
;MARK(2): Got ALIAS directive
DeclMark2:
call ErrIfPrsHasTxtTbl
mov [oDstAlias],di ;save offset to opLitSD("<alias>")
jmp SHORT DeclMarkLoop
;MARK(3): got offset to formal parm list
DeclMark3:
mov [oDstParms],di
jmp SHORT DeclMarkLoop
;MARK(4): got STATIC keyword at end of proc definition
DeclMark4:
or [prsCur.PRS_flags],FP_STATIC
jmp SHORT DeclMarkLoop
;MARK(5): got single line DEF FN
DeclMark5:
mov [oDstEndDef],di
mov ax,opEndSingleDef
call Emit16_AX
mov ax,2
call Emit16_AX ;emit cntEos word
call Emit16_0 ;emit space for link field
jmp SHORT DeclMarkLoop
;MARK(6): got ( [parmlist] )
DeclMark6:
cmp [pdcl.PDCL_cParms],UNDEFINED ;so scanner knows to not use this
; for parm type/count checking
jne DeclMarkLoop ;brif got a parm list
inc [pdcl.PDCL_cParms] ;so scanner knows to use this declare
; for parm type/count checking
jmp SHORT DeclMarkLoop
DeclEndOfMarks:
;Copy Alias text after formal parms
mov ax,[oDstAlias]
or ax,ax
je NoAliasArg
call CopyLit ;ax = cbAlias
mov [cbLibInfo],ax
shl al,1
shl al,1
.errnz DCLA_cbAlias - 7C00h
or [procAtr_HI],al ;save cbAlias in pcode field
;squeeze source of ALIAS lit out of pcode buffer
;BdShiftLeft((bd *)&ps.bdpDst, oDstAlias, oDstParms - oDstAlias)
PUSHI ax,<dataOFFSET ps.PS_bdpDst>
push [oDstAlias]
mov ax,[oDstParms]
sub ax,[oDstAlias] ;ax = number of bytes to delete
push ax
sub [oDstParms],ax ;update for the left shift
sub [oDstEndDef],ax ;update for the left shift
call BdShiftLeft ;grow buf, can cause heap movement
NoAliasArg:
;Now make room for things to insert before parm list:
; opcode, byte-count-till-end-of-stmt, link field for DEF FNs, oPrs
mov si,10 ;assume we need to insert 10 bytes
cmp [pdcl.PDCL_procType],PT_DEFFN
jne NotDefFn1 ;brif not DEF FN stmt
inc si ;need 2 extra bytes for link field
inc si
NotDefFn1:
;BdShiftRight((bd *)&ps.bdpDst, oDstParms, cbInsert)
PUSHI ax,<dataOFFSET ps.PS_bdpDst>
push [oDstParms]
push si ;pass cbInsert parm
call BdShiftRight
or ax,ax
jne ShiftOk ;brif no out-of-memory error
call ParseErrOm ;Error "Out of memory"
jmp SHORT DeclExit
ShiftOk:
call SetDstPbCur ;update ps.bdpDst.pbCur after BdShift...
push ds
pop es ;es = ds for stosw below
mov di,[oDstParms]
add di,[ps.PS_bdpDst.BDP_pb]
mov ax,[opcode]
stosw ;store opcode in pcode buffer
;emit cntEos operand
mov ax,[oDstEndDef]
sub ax,[oDstParms]
add ax,si ;include cbInsert
add ax,[cbLibInfo] ;add #bytes in LIB and ALIAS clause
sub ax,4
inc ax ;round up to even byte count
and al,0FEH
stosw ;store cntEos operand
cmp [pdcl.PDCL_procType],PT_DEFFN
jne NotDefFn2 ;brif not DEF FN stmt
stosw ;leave room for DEF FN link field
NotDefFn2:
mov ax,[pdcl.PDCL_oPrs]
or ax,ax
jns NotUnboundDefFn
mov ax,[pdcl.PDCL_oNam] ;for [DECLARE] DEF FNs, in SS_RUDE
;state, emit the oNam
NotUnboundDefFn:
stosw ;store oPrs/oNam operand
mov ax,[procAtr]
stosw ;store proc's oTyp
mov ax,[pdcl.PDCL_cParms]
stosw ;store cParms operand
DeclExit:
cEnd
;*********************************************************************
; CopyLit(ax:oDstLit)
; Purpose:
; Move the ASCII text of an opLitSD to the end of the pcode buffer.
; If string is longer than 255 bytes, it is truncated.
; Entry:
; ax = offset into pcode buffer to opLitSD opcode
; [EB] bx = TRUE iff length of string is to output as byte preceeding
; text of string.
; Exit:
; string is moved to end of pcode buffer and the opLitSd is removed
; ax = length of string
;
;*********************************************************************
CopyLit PROC NEAR
push si
mov si,ax
add si,[ps.PS_bdpDst.BDP_pb]
lodsw ;skip opLitSD opcode
DbAssertRel ax,e,opLitSD,CP,<CopyLit: expected opLitSD>
lodsw ;ax = cb operand from opLitSD
or ah,ah
je LenOk
mov ax,255 ;truncate string
LenOk:
push ax ;save for return value
inc ax ;round up to word count
shr ax,1
mov cx,ax
jcxz CLitExit ;brif entire string has been copied
CLitLoop:
push cx ;save word count
lodsw ;ax = next 2 bytes of string
sub si,[ps.PS_bdpDst.BDP_pb] ;Emit16 can cause heap movement
call Emit16_AX
add si,[ps.PS_bdpDst.BDP_pb] ;reconvert offset to pointer
pop cx ;restore word count
loop CLitLoop
CLitExit:
pop ax ;ax = string length
pop si
ret
CopyLit ENDP
;*********************************************************************
; CgCall(opcode)
; Purpose:
; Called to generate pcode for the following bnf:
; tkCALL (MARK(1) IdImplicit
; [tkLParen IdCallArg {tkComma IdCallArg} tkRParen])
; tkCALLS MARK(1) IdImplicit
; [tkLParen IdCallArg {tkComma IdCallArg} tkRParen]
;
;*********************************************************************
PUBLIC CgCall
CgCall PROC NEAR
push si ;save caller's si
mov bx,MAX_STK_MARK
mov si,[bx-2] ;si=offset in pcode for item after MARK
push ax ;save opcode for Emit16 below
mov bx,[ps.PS_bdpDst.BDP_pb]
mov ax,[bx][si] ;ax = oNamIdSub
call SubRef ;ax = oPrs for sub being called
;We can ignore error results, because
;if error occurs, no code will ever
;try to activate this oPrs, because
;line will be stored as opReParse
;delete the information emitted by NtIdImplicit()
;BdShiftLeft((bd *)&ps.bdpDst, oDstCur, 2)
PUSHI dx,<dataOFFSET ps.PS_bdpDst>
push si
PUSHI dx,2
mov si,ax ;si = oPrs
call BdShiftLeft ;grow buf, can cause heap movement
call SetDstPbCur ;set ps.bdpDst.pbCur after BdShiftLeft
call Emit16 ;emit opcode pushed ~15 lines above
push [cIdArgs]
call Emit16 ;emit arg count
push si ;push oPrs
call Emit16
pop si ;restore caller's si
ret
CgCall ENDP
;*********************************************************************
; VOID NEAR CgRun(opcode)
; Purpose:
; Invoked to generate code for the following bnf:
; tkRUN [(Ln MARK(1)) | (Exp MARK(2))]; <CgRun()>
;
;*********************************************************************
PUBLIC CgRun
CgRun PROC NEAR
mov bx,[pCurStkMark]
cmp bx,MAX_STK_MARK
mov ax,opStRunMain ;ax = opcode to emit for RUN
je RunEmitExit ;brif simple RUN (no MARKs)
DbAssertRelB [bx],be,2,CP,<Invalid MARK id in CgRun()>
cmp BYTE PTR [bx],1
jne RunFile ;brif markId != 1 (RUN <filename>)
;Got RUN <line number>, insert opStRunLabel before Ln
mov bx,[bx+2] ;bx = pcode offset
dec bx
dec bx ;bx = pcode offset where opcode is to go
mov ax,opStRunLabel
call InsertOp ;insert word AX at offset BX
jmp SHORT RunExit
RunFile:
mov ax,opStRunFile
RunEmitExit:
call Emit16_AX
RunExit:
ret
CgRun ENDP
;*********************************************************************
; VOID NEAR CgInput(opcode)
; Purpose:
; Invoked to generate code for the following bnf:
;
; tkINPUT
; [(lbsInpExpComma MARK(16)) |
; (tkSColon MARK(2) [LitString MARK(4) (tkSColon | (tkComma MARK(1)))])|
; (LitString MARK(4) (tkSColon | (tkComma MARK(1))))]
; MARK(8) IdAryElemRef EMIT(opStInput) {tkComma IdAryElemRef
; EMIT(opStInput)}
; EMIT(opInputEos)
; <CgInput(opInputPrompt)>
;
; tkLINE tkINPUT
; [(lbsInpExpComma MARK(16)) |
; (tkSColon MARK(2) [LitString MARK(4) (tkSColon | (tkComma MARK(1)))]) |
; (LitString MARK(4) (tkSColon | (tkComma MARK(1))))]
; IdAryElemRef
; <CgInput(opStLineInput)>
;
; It maps syntax to pcode as follows:
; INPUT [;] [prompt (,|;) <list> =>
; [sdExp] opInputPrompt(cnt,mask,<typelist>)
; If prompt is followed by a semicolon, FINP_QSupress is not ORed into
; 'mask' which causes a question mark to be appended to the prompt
; string.
; The optional semicolon after INPUT causes FINP_CrLf not to be ORed into
; 'mask' which causes the user's terminating carriage return not to be
; echoed.
;
;*********************************************************************
PUBLIC CgInput
CgInput PROC NEAR
.errnz FINP_QSupress - 1
.errnz FINP_CrLf - 2
.errnz FINP_Prompt - 4
push si ;save caller's si
push di ;save caller's di
sub di,di ;init bit mask
mov bx,MAX_STK_MARK
;OR bit mask with to 1 for comma after prompt (MARK(1)),
; 2 for semicolon after INPUT (MARK(2)),
; 4 for prompt (MARK(4))
InpMarkLoop:
cmp [pCurStkMark],bx
je InpMarkLoopDone
dec bx
dec bx
mov si,[bx] ;si = oDstOpcode from mark stack
dec bx
dec bx
cmp WORD PTR [bx],16
jne NotMark16 ;brif markId != 16
cmp ax,opStLineInput
je InpMarkLoop ;brif not INPUT #n
jmp SHORT InpExit ;If INPUT #n, pcode is already complete
NotMark16:
or di,[bx]
DbAssertRel di,b,16,CP,<Invalid markId in CgInput>
jmp SHORT InpMarkLoop
;di = bit mask (built by ORing markIds)
;ax = opcode
;
InpMarkLoopDone:
cmp ax,opStLineInput
jne NotLineInput
call Emit16_AX ;emit opcode
push di ;emit bit mask
call Emit16
jmp SHORT InpExit
;It was INPUT, not LINE INPUT
;insert opStInputPrompt[cbOperands:16,mask:8,types:8]
;don't count string literal in cInputItems (its in cIdArgs)
;count mask in cInputItems (cancels string literal)
;di = bit mask (built by ORing markIds)
;ax = opcode
;
NotLineInput:
push ax ;save opcode on stack
mov ax,[cIdArgs]
shr ax,1 ;round down to word count
mov cx,ax ;cx = word count
mov bx,si ;bx = oDstOpcode (place to insert ops)
jcxz InpLoopDone
;emit garbage typelist (scanner will fill in)
InpLoop:
push cx ;save word count
call InsertOp ;insert word AX at offset BX
;any value in ax would do, scanner fills
; (bx is preserved)
pop cx ;restore word count
loop InpLoop
;now emit mask and space for 1st entry in type list
InpLoopDone:
mov ax,di
and al,7 ;mask off bits > 7
call InsertOp ;insert word AX at offset BX
; (bx is preserved)
mov ax,[cIdArgs]
inc ax
call InsertOp ;insert word AX at offset BX
; (bx is preserved)
pop ax ;ax = opcode (pushed ~25 lines above)
call InsertOp ;insert word AX at offset BX
InpExit:
pop di ;save caller's di
pop si ;save caller's si
ret
CgInput ENDP
;*********************************************************************
; CgStmtCnt(opcode)
; Purpose:
; Called for statements like CLEAR, CLOSE, COLOR, ERASE, FIELD, LOCATE
; and SCREEN, which take as an operand the number of arguments
; preceding them.
;
;*********************************************************************
PUBLIC CgStmtCnt
CgStmtCnt PROC NEAR
call Emit16_AX ;emit the opcode
mov ax,[cIdArgs]
jmp Emit16_AX ;emit the arg count
;and return to caller
CgStmtCnt ENDP
;*********************************************************************
; CgCntHigh(opcode)
;
; Purpose:
;
; Called for the Format$ function.
;
;*********************************************************************
;Added with [11]
;End of [11]
;*********************************************************************
; CgLineStmt(opcode)
;
; Purpose:
; Invoked to generate code for the following bnf:
; tkLINE [coordStep] tkMinus coord2Step
; [tkComma [Exp MARK(1)]
; [tkComma [(RwBF MARK(3)) | (RwB (RwF MARK(3)) | MARK(2))]
; [tkComma Exp MARK(4)]]]
; <CgLineStmt(opStLine)>
;
;*********************************************************************
PUBLIC CgLineStmt
CgLineStmt PROC NEAR
push si ;save caller's si
sub dx,dx ;operand = 0
mov cx,ax ;cx = opcode
mov si,[pCurStkMark]
LineLoop:
cmp si,MAX_STK_MARK
je LineLoopDone
lodsw ;ax = markId
inc si ;skip oDstPcode
inc si
dec ax
je LineMark1 ;brif MARK(1)
dec ax
je LineMark2 ;brif MARK(2)
dec ax
je LineMark3 ;brif MARK(3)
;MARK(4) means line style parm was specified
inc cx ;convert opStLine, opStLineColor->
; opStLineStyle, opStLineColorStyle
;fall into case 1
;MARK(1) means color parm was specified
LineMark1:
inc cx ;convert opStLine to opStLineColor
jmp SHORT LineLoop
;MARK(2) means B parm was specified
LineMark2:
mov dl,1 ;operand = 1
jmp SHORT LineLoop
LineMark3:
;MARK(3) means BF parm was specified
mov dl,2 ;operand = 2
jmp SHORT LineLoop
LineLoopDone:
push dx ;pass operand to Emit16 below
xchg ax,cx ;ax=opcode for Emit16_AX
call Emit16_AX ;emit the opcode
call Emit16 ;emit the operand
pop si ;restore caller's si
ret
CgLineStmt ENDP
;*********************************************************************
; CgOpen(opcode)
;
; Purpose:
; Invoked to generate code for the following bnf:
; tkOPEN Exp
; ([(tkFOR ((tkAPPEND MARK(1)) |
; (tkINPUT MARK(2)) |
; (tkOUTPUT MARK(3)) |
; (tkRANDOM MARK(4)) |
; (tkBINARY MARK(5))))]
; [tkACCESS ((tkREAD MARK(6) [tkWRITE MARK(8)]) | (tkWRITE MARK(7)))]
; [(tkLOCK ((tkREAD ((tkWRITE MARK(11)) | MARK(9))) |
; (tkWRITE MARK(10)))) |
; (tkSHARED MARK(12))]
; tkAS optFilenum [tkLEN tkEQ Exp MARK(13)]) |
; (tkComma optFilenum exp12 MARK(14))
; <CgOpen(opStOpen2)>
;
;*********************************************************************
tModeMask LABEL WORD
DW MD_APP ; MARK(1) means APPEND was specified
DW MD_SQI ; MARK(2) means INPUT was specified
DW MD_SQO ; MARK(3) means OUTPUT was specified
DW MD_RND ; MARK(4) means RANDOM (or default) was speced
DW MD_BIN ; MARK(5) means BINARY was specified
DW ACCESS_READ * 256 ; MARK(6) means READ was specified
DW ACCESS_WRITE * 256 ; MARK(7) means WRITE was specified
DW ACCESS_BOTH * 256 ; MARK(8) means READ WRITE was specified
DW LOCK_READ * 256 ; MARK(9) means LOCK READ was specified
DW LOCK_WRITE * 256 ; MARK(10) means LOCK WRITE was specified
DW LOCK_BOTH * 256 ; MARK(11) means LOCK READ WRITE was specified
DW LOCK_SHARED * 256 ; MARK(12) means SHARED was specified
PUBLIC CgOpen
CgOpen PROC NEAR
push si ;save caller's si
mov cx,ax ;cx = opcode
sub dx,dx ;mode = 0
mov si,[pCurStkMark]
OpenLoop:
cmp si,MAX_STK_MARK
je OpenLoopDone
lodsw ;ax = markId
inc si ;skip pcode offset
inc si
cmp al,14
je OpenMark14
cmp al,13
je OpenMark13
;mode |= tModeMask[markId - 1]
xchg bx,ax ;bx = markId
shl bx,1 ;convert to word index
mov ax,tModeMask - 2[bx] ;ax = mask
or dx,ax ;or mask into mode
jmp SHORT OpenLoop
;MARK(13) means LEN=nnn was specified
OpenMark13:
inc cx ;convert opStOpen2 to opStOpen3
jmp SHORT OpenLoop
OpenLoopDone:
push dx ;save mode
xchg ax,cx ;emit opcode
call Emit16_AX
pop ax ;ax = open mode
test al,MD_APP OR MD_SQI OR MD_SQO OR MD_RND OR MD_BIN
jne OpenEmitExit ;brif open mode was specified
or al,MD_DEFAULT ;default open mode
OpenEmitExit:
call Emit16_AX ;emit open mode
pop si ;restore caller's si
ret
;MARK(14) means old open syntax
OpenMark14:
mov ax,[cIdArgs]
add ax,opStOpenOld3 - 3 ;ax = old open opcode
jmp SHORT OpenEmitExit
CgOpen ENDP
;*********************************************************************
; CgLock(opcode)
;
; Purpose:
; Invoked to generate code for the following bnf:
; tkLOCK optFileNum
; (tkComma (Exp MARK(1) [tkTO MARK(2) Exp]) | (tkTO MARK(3) Exp]))
; <CgLock(opStLock)>
; tkUNLOCK optFileNum
; (tkComma (Exp MARK(1) [tkTO MARK(2) Exp]) | (tkTO MARK(3) Exp]))
; <CgLock(opStLock)>
;
;*********************************************************************
PUBLIC CgLock
CgLock PROC NEAR
push si ;save caller's si
push di ;save caller's di
mov di,ax ;di = opcode
sub dx,dx ;mode = markId = 0
cmp ax,opStUnLock
jne NotUnlock
mov dl,LOCK_UNLOCK ;mode = LOCK_UNLOCK
NotUnlock:
mov si,[pCurStkMark]
LockLoop:
cmp si,MAX_STK_MARK
je LockLoopDone ;brif done with MARK directives
lodsw ;al = markId
xchg cx,ax ;cl = markId
lodsw ;ax = oDstOpcode
cmp cl,1
jne NotMark1 ;brif not MARK(1)
test dl,LOCK_1stToLast
jne NotMark1 ;brif MARK(2) was seen
or dh,LOCK_DefLastArg/256 ;tell executor to default last record
NotMark1:
cmp cl,3
jne NotMark3 ;brif not MARK(3)
xchg bx,ax ;bx = oDstOpcode
;Emit default 1st record before the 2nd Exp
push dx ;save dx
.erre opLitI2Max GE 1 ; Assure 1 is allowed
mov ax,opLitI2+OPCODE_MASK+1; pass opLitI2 with value of 1
call InsertOp ;insert word AX at offset BX
; (bx is preserved)
pop dx ;restore dx = mode & markId
or dh,LOCK_Def1stArg/256 ;tell lister to default 1st record
NotMark3:
or dl,LOCK_1stToLast
jmp SHORT LockLoop
LockLoopDone:
push dx ;pass mode to 2nd call of Emit16
xchg ax,di ;pass opcode to Emit16_AX
call Emit16_AX ;emit the opcode
call Emit16 ;emit the mode operand
pop di ;restore caller's di
pop si ;restore caller's si
ret
CgLock ENDP
PUBLIC Cg0or1Args, Cg1or2Args, Cg2or3Args, Cg3or4Args
Cg3or4Args PROC NEAR
dec ax
Cg3or4Args ENDP ;fall into Cg2or3Args
Cg2or3Args PROC NEAR
dec ax
Cg2or3Args ENDP ;fall into Cg1or2Args
Cg1or2Args PROC NEAR
dec ax
Cg1or2Args ENDP ;fall into Cg0or1Args
Cg0or1Args PROC NEAR
mov dx,ax ;save base opcode in dx
add ax,[cIdArgs] ;ax = opcode + cIdArgs
cmp dx,opStMid_2 - 3
je CgMoveOpsToEnd ;brif MID$ statement
J1_Emit16_AX:
jmp Emit16_AX ;emit ax and return to caller
Cg0or1Args ENDP
;*********************************************************************
; CgMoveOpsToEnd(opcode)
;
; Purpose:
; Invoked to generate code for the following bnf:
; tkLSET MARK(1) idAryElemRef MARK(2) tkEQ Exp
; CgMoveOpsToEnd(opStLset)
; tkRSET MARK(1) idAryElemRef MARK(2) tkEQ Exp
; CgMoveOpsToEnd(opStRset)
; tkMID_ tkLParen MARK(1) idAryElemRef MARK(2) exp12 tkRParen tkEQ Exp
; Cg3or4Args(opStMid_2)
; Moves the pcode for idAryElemRef to the end of the buffer
;
;*********************************************************************
cProc CgMoveOpsToEnd,<PUBLIC,NEAR,NODATA>,<si,di>
cBegin
push ax ;pass opcode to Emit16 (at end of proc)
mov si,[pCurStkMark]
lodsw ;al = markId (2)
lodsw ;ax = text offset for MARK(2)
xchg di,ax ;bx = text offset for MARK(2)
lodsw ;al = markId (1)
lodsw ;ax = text offset for MARK(1)
xchg si,ax ;si = text offset for MARK(1)
;setup for BdShiftLeft((bd *)&ps.bdpDst, oDstCur, cbMoved)
PUSHI ax,<dataOFFSET ps.PS_bdpDst>
push si
mov ax,di
sub ax,si
push ax ;pass cbMoved
;call to BdShiftLeft is after loop
MoveLoop:
cmp si,di
je MoveDone
add si,[ps.PS_bdpDst.BDP_pb] ;si = ptr to next word to be moved
lodsw ;ax = next word to be moved
sub si,[ps.PS_bdpDst.BDP_pb] ;si = offset to next word to be moved
call Emit16_AX ;copy word to end of buffer
jmp SHORT MoveLoop
MoveDone:
;delete the source of copied words - parms pushed several lines above
call BdShiftLeft ;grow buf, can cause heap movement
call SetDstPbCur ;update ps.bdpDst.pbCur for BdShiftLeft
;emit opcode - parm pushed several lines above
call Emit16
cEnd
PUBLIC CgCircle
CgCircle PROC NEAR
mov dx,MAX_STK_MARK
cmp [pCurStkMark],dx
je NoCircleMark
inc ax ;got a MARK(1), color parm included
;map opStCircle to opStCircleColor
NoCircleMark:
jmp Emit16_AX ;emit ax and return to caller
CgCircle ENDP
sEnd CP
end
|
li $t0,1 #a
li $t1,4 #b
beq $t0,1,if
j print
if:
la $t2,($t0) #c
beq $t1,3,print
add $t2,$t2,$t1
print:
li $v0,1
move $a0,$t2
syscall
|
; int ba_stack_pop(ba_stack_t *s)
SECTION code_adt_ba_stack
PUBLIC _ba_stack_pop
EXTERN _b_array_pop_back
defc _ba_stack_pop = _b_array_pop_back
|
; A307912: a(n) = n - 1 - pi(2*n-1) + pi(n), where pi is the prime counting function.
; Submitted by Jon Maiga
; 0,0,1,1,3,3,4,5,5,5,7,7,9,10,10,10,12,13,14,15,15,15,17,17,18,19,19,20,22,22,23,24,25,25,26,26,27,28,29,29,31,31,33,34,34,35,37,38,38,39,39,39,41,41,41,42,42,43,45,46,48,49,50,50,51,51,53,54
mov $2,$0
add $0,1
mov $4,1
mov $5,$0
lpb $2
sub $2,1
mov $3,$5
seq $3,10051 ; Characteristic function of primes: 1 if n is prime, else 0.
sub $0,$3
add $5,1
lpe
add $0,$4
sub $0,2
|
/************************
* Z=long specialization
************************/
#ifndef FPLLL_NR_Z_L_H
#define FPLLL_NR_Z_L_H
FPLLL_BEGIN_NAMESPACE
/* specialization long */
#ifdef FPLLL_WITH_ZLONG
template<>
inline Z_NR<long>::Z_NR() {}
template<>
inline Z_NR<long>::Z_NR(const Z_NR<long>& z) : data(z.data) {}
template<>
inline Z_NR<long>::~Z_NR() {}
/** get data */
template<>
inline double Z_NR<long>::get_d() const {
return static_cast<double>(data);
}
#ifdef FPLLL_WITH_LONG_DOUBLE
template<>
inline long double Z_NR<long>::get_ld() const {
return static_cast<long double>(data);
}
#endif
template<>
inline long Z_NR<long>::get_si() const {
return data;
}
template<>
inline void Z_NR<long>::get_mpz(mpz_t r) const {
mpz_set_si (r, data);
}
inline long compute_long_exponent(long data) {
unsigned long y = static_cast<unsigned long>(abs(data));
long e;
for (e = 0; y; e++, y >>= 1) {}
return e;
}
template<>
inline long Z_NR<long>::exponent() const {
int int_expo;
double f_norm = frexp(static_cast<double>(data), &int_expo);
if (data > MAX_LONG_FAST && fabs(f_norm) == 0.5)
return compute_long_exponent(data);
else
return static_cast<long>(int_expo);
}
/** set data */
template<>
inline void Z_NR<long>::set_str(const char* s) {
data = atol(s);
}
/** comparison */
template<>
inline int Z_NR<long>::cmp(const Z_NR<long>& m) const {
if (data > m.data) return 1;
if (data == m.data) return 0;
return -1;
}
template<>
inline int Z_NR<long>::sgn() const {
if (data > 0) return 1;
if (data == 0) return 0;
return -1;
}
/** operator */
template<>
inline void Z_NR<long>::operator=(const Z_NR<long>& a) {
data = a.data;
}
template<>
inline void Z_NR<long>::operator=(long a) {
data = static_cast<long>(a);
}
template<>
inline void Z_NR<long>::operator=(const mpz_t& a) {
data = mpz_get_si(a);
}
template<>
inline bool Z_NR<long>::operator<(const Z_NR<long>& a) const {
return data < a.data;
}
template<>
inline bool Z_NR<long>::operator<(long a) const {
return data < a;
}
template<>
inline bool Z_NR<long>::operator>(const Z_NR<long>& a) const {
return data > a.data;
}
template<>
inline bool Z_NR<long>::operator>(long a) const {
return data > a;
}
template<>
inline bool Z_NR<long>::operator<=(const Z_NR<long>& a) const {
return data <= a.data;
}
template<>
inline bool Z_NR<long>::operator<=(long a) const {
return data <= a;
}
template<>
inline bool Z_NR<long>::operator>=(const Z_NR<long>& a) const {
return data >= a.data;
}
template<>
inline bool Z_NR<long>::operator>=(long a) const {
return data >= a;
}
template<>
inline bool Z_NR<long>::operator==(const Z_NR<long>& a) const {
return data == a.data;
}
template<>
inline bool Z_NR<long>::operator==(long a) const {
return data == a;
}
template<>
inline bool Z_NR<long>::operator!=(const Z_NR<long>& a) const {
return data != a.data;
}
template<>
inline bool Z_NR<long>::operator!=(long a) const {
return data != a;
}
/** arithmetic */
template<>
inline void Z_NR<long>::add(const Z_NR<long>& a, const Z_NR<long>& b) {
data = a.data + b.data;
}
template<>
inline void Z_NR<long>::add_ui(const Z_NR<long>& a, unsigned int b) {
data = a.data + b;
}
template<>
inline void Z_NR<long>::sub(const Z_NR<long>& a, const Z_NR<long>& b) {
data = a.data - b.data;
}
template<>
inline void Z_NR<long>::sub_ui(const Z_NR<long>& a, unsigned int b) {
data = a.data - b;
}
template<>
inline void Z_NR<long>::neg(const Z_NR<long>& a) {
data = -a.data;
}
template<>
inline void Z_NR<long>::mul(const Z_NR<long>& a, const Z_NR<long>& b) {
data = a.data * b.data;
}
template<>
inline void Z_NR<long>::mul_si(const Z_NR<long>& a, long b) {
data = a.data * b;
}
template<>
inline void Z_NR<long>::mul_ui(const Z_NR<long>& a, unsigned long b) {
data = a.data * b;
}
template<>
inline void Z_NR<long>::mul_2si(const Z_NR<long>& a, long b) {
//NOTE: if b >= size_in_bits(a), the result is undefined
if (b >= 0)
data = a.data << b;
else
data = a.data >> -b;
}
template<>
inline void Z_NR<long>::div_2si(const Z_NR<long>& a, long b) {
//NOTE: if b >= size_in_bits(a), the result is undefined
if (b >= 0)
data = a.data >> b;
else
data = a.data << -b;
}
template<>
inline void Z_NR<long>::addmul(const Z_NR<long>& a, const Z_NR<long>& b) {
data += a.data * b.data;
}
template<>
inline void Z_NR<long>::addmul_ui(const Z_NR<long>& a, unsigned long b) {
data += a.data * b;
}
template<>
inline void Z_NR<long>::addmul_si(const Z_NR<long>& a, long b) {
data += a.data * b;
}
template<>
inline void Z_NR<long>::submul(const Z_NR<long>& a, const Z_NR<long>& b) {
data -= a.data * b.data;
}
template<>
inline void Z_NR<long>::submul_ui(const Z_NR<long>& a, unsigned long b) {
data -= a.data * b;
}
template<>
inline void Z_NR<long>::abs(const Z_NR<long>& a) {
data = labs(a.data);
}
template<>
inline void Z_NR<long>::swap(Z_NR<long>& a) {
std::swap(data, a.data);
}
/** random numbers */
template<>
inline void Z_NR<long>::randb(int bits) {
mpz_t temp;
mpz_init(temp);
mpz_urandomb(temp, RandGen::get_gmp_state(), bits);
data = mpz_get_si(temp);
mpz_clear(temp);
}
template<>
inline void Z_NR<long>::randb_si(int bits) {
randb (bits);
data = data * RandGenInt::get_bit();
}
template<>
inline void Z_NR<long>::randm(const Z_NR<long>& max) {
mpz_t temp, lim;
mpz_init(temp);
mpz_init(lim);
mpz_set_si(lim, max.data);
mpz_urandomm(temp, RandGen::get_gmp_state(), lim);
data = mpz_get_si(temp);
mpz_clear(temp);
mpz_clear(lim);
}
template<>
inline void Z_NR<long>::randm_si(const Z_NR<long>& max) {
randm (max);
data = data * RandGenInt::get_bit();
}
template<>
inline void Z_NR<long>::nextprime(const Z_NR<long>& nbr) {
mpz_t temp, temp2;
mpz_init(temp);
mpz_init(temp2);
mpz_set_ui(temp, nbr.data);
mpz_nextprime(temp2, temp);
data = mpz_get_ui(temp2);
mpz_clear(temp);
mpz_clear(temp2);
}
/* operators Z_NR<long> */
template<>
inline ostream& operator<<(ostream& os, const Z_NR<long>& x) {
return os << x.get_data();
}
template<>
inline istream& operator>>(istream& is, Z_NR<long>& x) {
return is >> x.get_data();
}
#endif // #ifdef FPLLL_WITH_ZLONG
FPLLL_END_NAMESPACE
#endif
|
; A109753: n^3 mod 8; the periodic sequence {0,1,0,3,0,5,0,7}.
; 0,1,0,3,0,5,0,7,0,1,0,3,0,5,0,7,0,1,0,3,0,5,0,7,0,1,0,3,0,5,0,7,0,1,0,3,0,5,0,7,0,1,0,3,0,5,0,7,0,1,0,3,0,5,0,7,0,1,0,3,0,5,0,7,0,1,0,3,0,5,0,7,0,1,0,3,0,5,0,7,0,1,0,3,0,5,0,7,0,1,0,3,0,5,0,7,0,1,0,3
pow $0,5
mod $0,8
|
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) GeoWorks 1991 -- All Rights Reserved
PROJECT: PC GEOS
MODULE: GeoCalc
FILE: spreadsheetRowArray.asm
AUTHOR: Gene Anderson, Mar 7, 1991
ROUTINES:
Name Description
---- -----------
EXT ColumnGetWidth Get width of a column
EXT ColumnSetWidth Set width of a column
EXT RowGetHeight Get height of a row
EXT RowSetHeight Set height of a row
EXT RowGetRelPos32 Get 32-bit relative position
EXT RowGetRelPos16 Get 16-bit visible position
EXT ColumnGetRelPos32 Get 32-bit relative position
EXT ColumnGetRelPos16 Get 16-bit visible position
EXT Pos32ToVisCell Get cell under visible position
EXT Pos32ToCellRel Get cell under position
EXT Pos32ToRowRel Get row under position
EXT Pos32ToColRel Get column under position
INT LockRowArray Lock row or column array
INT RowGetHeightInt Get width or height from array
INT RowGetPositionInt Get row of column offset from array
EXT RowColArrayInit Create and initialize row and column arrays
INT RowArrayAlloc Create row or column array
REVISION HISTORY:
Name Date Description
---- ---- -----------
Gene 3/ 7/91 Initial revision
DESCRIPTION:
Routines for manipulating row height and column width arrays.
Since there are large number of rows (8192), a normal array
is not practical. Instead, row heights are stored as runs.
Each entry in the array implies: "all rows since the last entry
up to and including the current row are of this height."
The result is generally a very compact method of storage.
A direct-acess array of row heights would be faster to
access, but would require a staggering 16K of space to
hold, no matter how many rows were actually in use in the
spreadsheet. The method described here will result in a
very compact array. The worst-case is if each row was
was a different height than the one before it, resulting in
twice as much space (32K) as required for the direct array. The
average case for normal spreadsheets will be much more compact.
NOTE: To simplify changing a row height, the definition of
the array is expanded to include the rows outside the
bounds of spreadsheet, similar to the way regions are defined.
Rows outside the spreadsheet have height -1 so they will never
match rows within the spreadsheet.
Consider the following examples:
A new spreadsheet will have:
r=0,h=-1
r=8192,h=14
r=8193,h=-1
-----------
= 12 bytes
A spreadsheet with rows 5 and 6 18 points will have:
r=0,h=-1
r=4,h=14
r=6,h=18
r=8192,h=14
r=8193,h=-1
----------
= 20 bytes
A spreadsheet with all rows changed to 18 points will have:
r=0,h=-1
r=8192,h=18
r=8193,h=-1
---------
= 12 bytes
NOTE: Along with the row heights, we also need to store the
baseline for each row. To commonize code, the column width
array has the same size entries but uses the extra data
for the default attributes for new cells in that column.
NOTE: Since there is common code, the row and column
arrays are frequently both referred to as row arrays.
$Id: spreadsheetRowArray.asm,v 1.1 97/04/07 11:13:24 newdeal Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
InitCode segment resource
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowColArrayInit
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Initialize the row height and column width arrays.
CALLED BY: SpreadsheetInitFile()
PASS: bx - file handle of VM file
dx - # of rows
cx - # of columns
RETURN: ax - VM handle of array
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/ 7/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowColArrayInit proc near
uses bx, cx, dx, si, di, bp, ds
.enter
push cx
clr ax ;ax <- no user ID
mov cx, STD_INIT_HEAP ;cx <- # of bytes
call VMAlloc
pop cx
push ax ;save VM handle of array
push cx ;save # of columns
push dx ;save # rows
;
; Lock and initalize the block
;
call VMLock ;ax <- seg addr of block
mov ds, ax ;ds <- seg addr of block
mov bx, bp ;bx <- memory handle
mov dx, (size LMemBlockHeader) ;dx <- offset of heap
mov ax, LMEM_TYPE_GENERAL ;ax <- LMemType
mov cx, ROW_ARRAY_NUM_HANDLES ;cx <- # of handles
push si, di, bp
mov si, (size RowArrayEntry)*6 ;si <- amount of free space
clr di ;di <- LocalMemoryFlags
clr bp ;bp <- end of space (0 = end)
call LMemInitHeap
pop si, di, bp
;
; Allocate and initalize a block to use for the row height array
;
pop cx ;cx <- # of rows
;;;
;;; Added 5/17/95 -jw
;;;
;;; The problem is that when you move between different platforms, the
;;; number of rows/columns varies. In order to avoid death due to the
;;; RowArray not having runs out to the right distance, or to avoid
;;; the RowArray being "too long", I've decided that it is preferable
;;; to assume some arbitrary "largest row / column" and use that value.
;;;
;;; This, combined with another minor change later to handle older docs
;;; should make this sort of thing work.
;;;
;;; The only bug I can think of, which we will probably have to live with,
;;; is that if you insert columns, then delete columns, the columns which
;;; scroll back onto the right edge (or bottom edge, for rows) will have
;;; a width that is non-standard, because it will have been preserved in
;;; the RowArray, even though the columns/rows were pushed off the bottom
;;; of the spreadsheet.
;;;
mov cx, ROW_ARRAY_TERMINATOR+1
mov dx, ROW_HEIGHT_DEFAULT
mov bx, ROW_BASELINE_DEFAULT or ROW_HEIGHT_AUTOMATIC
call RowArrayAlloc
;
; Allocate and initalize a block to use for the column width array
;
pop cx ;cx <- # of columns
;;;
;;; Same fix as above 5/17/95 -jw
;;;
mov cx, COLUMN_ARRAY_TERMINATOR+1
mov dx, COLUMN_WIDTH_DEFAULT
clr bx ;bx <- default style for cols
CheckHack <DEFAULT_STYLE_TOKEN eq 0>
call RowArrayAlloc
;
; Mark the block as dirty and release it
;
call VMDirty
call VMUnlock
pop ax ;ax <- VM handle of array
.leave
ret
RowColArrayInit endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowArrayAlloc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Allocate row or column array
CALLED BY: RowColArrayInit()
PASS: cx - # of rows or columns
dx - value for 1st word
bx - value for 2nd word
ds - seg addr of array
di - chunk handle of array
RETURN: none
DESTROYED: ax, di
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/ 7/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowArrayAlloc proc near
.enter
push cx
mov cx, (size RowArrayEntry)*3 ;cx <- size of chunk
call LMemAlloc
pop cx ;cx <- # rows/columns
mov di, ax ;di <- chunk handle
mov di, ds:[di] ;ds:di <- ptr to chunk
;
; Initialize rows 0 through 'cx'-1 to be 'dx' points tall
;
dec cx
mov ds:[di][(size RowArrayEntry)*1].RAE_row, cx
mov ds:[di][(size RowArrayEntry)*1].RAE_height, dx
mov ds:[di][(size RowArrayEntry)*1].RAE_baseline, bx
;
; Initialize all rows up to first to be NULL
;
mov ax, -1
mov ds:[di][(size RowArrayEntry)*0].RAE_row, (MIN_ROW-1)
mov ds:[di][(size RowArrayEntry)*0].RAE_height, ax
mov ds:[di][(size RowArrayEntry)*0].RAE_baseline, ax
;
; Initialize all rows after 'cx' to be NULL
;
inc cx
mov ds:[di][(size RowArrayEntry)*2].RAE_row, cx
mov ds:[di][(size RowArrayEntry)*2].RAE_height, ax
mov ds:[di][(size RowArrayEntry)*2].RAE_baseline, ax
.leave
ret
RowArrayAlloc endp
InitCode ends
DrawCode segment resource
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
LockRowArray
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Lock a row array (either row heights or column widths)
CALLED BY: RowGetHeight(), ColumnGetWidth()
PASS: ds:si - ptr to Spreadsheet instance data
ax - chunk handle of array
RETURN: ds:si - ptr to 1st RowArrayEntry
bp - memory handle of block
di - chunk handle of array
DESTROYED: ax
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
ASSUMES: first entry can be skipped (for rows < 0)
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/ 8/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
LockRowArrayFar proc far
call LockRowArray
ret
LockRowArrayFar endp
LockRowArray proc near
uses bx
class SpreadsheetClass
.enter
EC < call ECCheckInstancePtr ;>
push ax
mov ax, ds:[si].SSI_rowArray ;ax <- VM block handle
mov bx, ds:[si].SSI_cellParams.CFP_file ;bx <- handle of file
call VMLock
mov ds, ax ;ds <- seg addr of block
pop di ;di <- chunk handle
EC < call ECCheckRowArray ;>
mov si, ds:[di] ;ds:si <- ptr to chunk
add si, (size RowArrayEntry) ;ds:si <- ptr to 1st entry
.leave
ret
LockRowArray endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ECCheckRowArray
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Verify a row array is valid
CALLED BY: LockRowArray()
PASS: *ds:di - ptr to start of row array
RETURN: none
DESTROYED: none
PSEUDO CODE/STRATEGY:
to be valid:
(1) no adjacent entries have have the same height and baseline
(2) for entries i & j, i<j, row(i)<row(j)
(3) row(0) = -1, height(0) = -1, baseline(0) = -1
(4) row(n) = MAX+1, height(n) = -1, baseline(n) = -1
(5) size(array) MOD (size RowArrayEntry) = 0
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
gene 8/12/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
if ERROR_CHECK
ECCheckRowArray proc far
uses si, ax, di
.enter
mov si, ds:[di] ;ds:si <- ptr to array
ChunkSizePtr ds, si, di ;di <- size of chunk
add di, si ;ds:di <- ptr to end
;
; Verify (3): row(0) = -1, height(0) = -1, baseline(0) = -1
;
cmp ds:[si].RAE_row, -1
ERROR_NE ROW_ARRAY_CORRUPTED
cmp ds:[si].RAE_height, -1
ERROR_NE ROW_ARRAY_CORRUPTED
cmp ds:[si].RAE_baseline, -1
ERROR_NE ROW_ARRAY_CORRUPTED
;
; For each entry, verify (1) and (2)
;
rowLoop:
cmp si, di ;end of array?
ERROR_AE ROW_ARRAY_CORRUPTED ;should have stopped on last row
cmp ds:[si].RAE_height, -1 ;first or last row?
jne checkEntry
cmp ds:[si].RAE_row, -1 ;last row?
jne endArray ;branch if last row
checkEntry:
mov ax, ds:[si].RAE_row
cmp ax, ds:[si][+(size RowArrayEntry)].RAE_row
ERROR_GE ROW_ARRAY_CORRUPTED ;row(i) >= row(j)
mov ax, ds:[si].RAE_height
cmp ax, ds:[si][+(size RowArrayEntry)].RAE_height
jne nextEntry
mov ax, ds:[si].RAE_baseline
cmp ax, ds:[si][+(size RowArrayEntry)].RAE_baseline
ERROR_E ROW_ARRAY_CORRUPTED ;i=j
;
; Also make sure the height and baseline are reasonable:
; (a) baseline < height
; (b) height < MAX
;
cmp ds:[si].RAE_height, -1
je nextEntry ;skip row(0) = -1
mov ax, ds:[si].RAE_baseline
andnf ax, not (ROW_HEIGHT_AUTOMATIC)
cmp ax, ds:[si].RAE_height
ERROR_A ROW_ARRAY_CORRUPTED ;baseline > height
cmp ds:[si].RAE_height, ROW_HEIGHT_MAX
ERROR_A ROW_ARRAY_CORRUPTED ;height > MAX
nextEntry:
add si, (size RowArrayEntry) ;ds:si <- ptr to next entry
jmp rowLoop
;
; (5) Make sure we've hit the end of the chunk exactly
;
endArray:
sub di, (size RowArrayEntry) ;ds:di <- ptr to last entry(?)
cmp si, di ;end of array?
ERROR_NE ROW_ARRAY_CORRUPTED
;
; Make sure height(n) = -1, baseline(n) = -1
;
cmp ds:[si].RAE_height, -1
ERROR_NE ROW_ARRAY_CORRUPTED
cmp ds:[si].RAE_baseline, -1
ERROR_NE ROW_ARRAY_CORRUPTED
.leave
ret
ECCheckRowArray endp
endif
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ColumnGetWidth
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get the width of a column
CALLED BY: GetCellBounds()
PASS: cx = column #
ds:si = ptr to Spreadsheet instance data
RETURN: dx = column width
z flag - set if column hidden
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/ 8/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ColumnGetWidthFar proc far
call ColumnGetWidth
ret
ColumnGetWidthFar endp
ColumnGetWidth proc near
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
push ax, cx
mov ax, COLUMN_ARRAY_CHUNK ;ax <- chunk of column array
GOTO RowGetHeightInt, cx, ax
ColumnGetWidth endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowGetHeight
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get the height of a row
CALLED BY: GetCellBounds()
PASS: ax - row
ds:si - ptr to Spreadsheet instance data
RETURN: dx - row height
z flag - set if row hidden
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/ 8/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowGetHeightFar proc far
call RowGetHeight
ret
RowGetHeightFar endp
RowGetHeight proc near
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
push ax, cx
mov cx, ax ;cx <- row #
mov ax, ROW_ARRAY_CHUNK ;ax <- chunk of row array
FALL_THRU RowGetHeightInt, cx, ax
RowGetHeight endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowGetHeightInt
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get the row height, part II
CALLED BY: RowGetHeight(), ColumnGetWidth()
PASS: ax - VM handle of row or column array
cx - row/column to find
ds:si - ptr to Spreadsheet instance data
on stack:
saved ax
saved cx
RETURN: dx - row height/column width
z flag - set if row/column hidden (cmp dx, 0)
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/ 8/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowGetHeightInt proc near
uses bp, ds, si, di
.enter
EC < call ECCheckInstancePtr ;>
call LockRowArray ;ds:si <- ptr to 1st entry
mov ax, cx ;ax <- row/column to find
rowLoop:
EC < call ECRowCheckOffset ;>
cmp ds:[si].RAE_row, ax ;correct row?
jae found
add si, (size RowArrayEntry) ;ds:si <- ptr to next entry
jmp rowLoop
found:
mov dx, ds:[si].RAE_height ;dx <- height
call VMUnlock ;all done with array
.leave
FALL_THRU_POP cx, ax
cmp dx, 0 ;set flags
ret
RowGetHeightInt endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ColumnGetDefaultAttrs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get the default attributes for a column
CALLED BY: UTILITY
PASS: ds:si - ptr to Spreadsheet instance
cx - column to find
RETURN: dx - default attrs for column
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
gene 1/15/93 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ColumnGetDefaultAttrs proc far
EC < call ECCheckInstancePtr ;>
push ax, cx
mov ax, COLUMN_ARRAY_CHUNK ;ax <- chunk of column array
GOTO RowGetBaselineInt, cx, ax
ColumnGetDefaultAttrs endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowGetBaseline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get the baseline for a row
CALLED BY: CellDrawString()
PASS: ds:si - ptr to Spreadsheet instance
ax - row to find
RETURN: dx - baseline of row
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
gene 1/15/93 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowGetBaseline proc far
EC < call ECCheckInstancePtr ;>
push ax, cx
mov cx, ax ;cx <- row #
mov ax, ROW_ARRAY_CHUNK ;ax <- chunk of row array
FALL_THRU RowGetBaselineInt, cx, ax
RowGetBaseline endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowGetBaselineInt
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get the row baseline offset or column default attrs
CALLED BY: RowGetBaseline(), ColumnGetDefaultAttrs()
PASS: ax - VM handle of row or column array
cx - row/column to find
ds:si - ptr to Spreadsheet instance data
on stack:
saved ax
saved cx
RETURN: dx - row baseline
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/ 8/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowGetBaselineInt proc far
uses bp, ds, si, di
.enter
EC < call ECCheckInstancePtr ;>
call LockRowArray ;ds:si <- ptr to 1st element
mov ax, cx ;ax <- row/column to find
rowLoop:
EC < call ECRowCheckOffset ;>
cmp ds:[si].RAE_row, ax ;correct row?
jae found
add si, (size RowArrayEntry) ;ds:si <- ptr to next entry
jmp rowLoop
found:
mov dx, ds:[si].RAE_baseline ;dx <- height
call VMUnlock ;all done with array
.leave
FALL_THRU_POP cx, ax
ret
RowGetBaselineInt endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ColumnGetRelPos16
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get a column's document position, relative to another column
CALLED BY: UTILITY
PASS: cx - column #
dx - origin column #
RETURN: dx - position of column 'cx'
bx - width of column 'cx'
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/25/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ColumnGetRelPos16 proc near
uses ax
class SpreadsheetClass
.enter
mov ax, COLUMN_ARRAY_CHUNK ;ax <- chunk of column array
call RowGetPositionInt
EC < cmp ax, 0xffff ;>
EC < je noDeath ;>
EC < tst ax ;result too big?>
EC < ERROR_NZ VISIBLE_POSITION_TOO_LARGE ;>
EC <noDeath: ;>
.leave
ret
ColumnGetRelPos16 endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ColumnGetRelPos32
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get a column's document position, relative to another column
CALLED BY: UTILITY
PASS: cx - column #
dx - column # origin
ds:si - ptr to Spreadsheet instance data
RETURN: ax:dx - position of column 'cx' relative to column 'dx'
bx - width of column 'cx'
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/ 8/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ColumnGetRelPos32 proc near
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
mov ax, COLUMN_ARRAY_CHUNK ;ax <- chunk of column array
GOTO RowGetPositionInt
ColumnGetRelPos32 endp
ColumnGetRelPos32Far proc far
call ColumnGetRelPos32
ret
ColumnGetRelPos32Far endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowGetRelPos16
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get position of row relative to another row
CALLED BY: GetCellBounds()
PASS: ax - row #
dx - row # origin
ds:si - ptr to Spreadsheet instance data
RETURN: dx - position of row 'ax'
bx - height of row 'ax'
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/25/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowGetRelPos16 proc near
uses ax, cx
class SpreadsheetClass
.enter
EC < call ECCheckInstancePtr ;>
mov cx, ax ;cx <- row #
mov ax, ROW_ARRAY_CHUNK ;ax <- chunk of row array
call RowGetPositionInt
EC < cmp ax, 0xffff ;>
EC < je noDeath ;>
EC < tst ax ;result too big?>
EC < ERROR_NZ VISIBLE_POSITION_TOO_LARGE ;>
EC <noDeath: ;>
.leave
ret
RowGetRelPos16 endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowGetRelPos32
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get a row's document position, relative to another row.
CALLED BY: GetCellBounds()
PASS: ax - row #
dx - row # origin
ds:si - ptr to Spreadsheet instance data
RETURN: ax:dx - position of row 'ax' relative to row 'dx'
bx - height of row 'ax'
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/ 8/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowGetRelPos32Far proc far
call RowGetRelPos32
ret
RowGetRelPos32Far endp
RowGetRelPos32 proc near
uses cx
class SpreadsheetClass
.enter
EC < call ECCheckInstancePtr ;>
mov cx, ax ;cx <- row #
mov ax, ROW_ARRAY_CHUNK ;ax <- chunk of row array
call RowGetPositionInt
.leave
ret
RowGetRelPos32 endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowGetPositionInt
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get row or column position relative to a cell
CALLED BY: ColumnGetRelPosition(), RowGetRelPosition()
PASS: ax - chunk handle of row or column array
cx - row/column #
dx - row/column # origin
ds:si - ptr to Spreadsheet instance data
RETURN: ax:dx - position of row/col cx relative to row/col dx
bx - height/width of row/column
DESTROYED: none
PSEUDO CODE/STRATEGY:
The idea behind this is that the Spreadsheet object will
be keeping track of the upper left visible cell, and so
cell positions for drawing can be computed based on it
rather than from $A$1 every time.
This routine will return a negative value if the row/column passed
is before the row/column origin specified.
KNOWN BUGS/SIDE EFFECTS/IDEAS:
There may be a faster way to add up row heights, like
computing the # of rows for a gap and multiplying instead
of adding each one up. However, given the intended use
of these routines, the current method should be OK.
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/ 8/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowGetPositionInt proc near
uses cx, bp, ds, si, di
.enter
EC < call ECCheckInstancePtr ;>
call LockRowArray ;ds:si <- ptr to 1st element
mov ax, dx ;ax <- row # origin
;
; If the cell is before the origin cell specified, swap the rows.
; Later we will negate the result to make this value correct.
;
cmp ax, cx ;is row before origin?
pushf ;save results for later
jbe noSwap
xchg ax, cx ;swap row and origin
noSwap:
;
; Find the starting row
;
startRowLoop:
EC < call ECRowCheckOffset ;>
cmp ds:[si].RAE_row, ax ;correct row?
jae startFound
add si, (size RowArrayEntry) ;ds:si <- ptr to next entry
jmp startRowLoop
;
; From the starting row, add heights until the
; target row is reached.
;
startFound:
push ds:[si].RAE_height
clr bx
mov dx, bx ;bx:dx <- position
endRowLoop:
EC < call ECRowCheckOffset ;>
cmp ax, ds:[si].RAE_row ;height still same?
jbe rowOK ;branch if same height
add si, (size RowArrayEntry) ;skip to next block
rowOK:
cmp ax, cx ;to last row?
je done ;branch if at last row
add dx, ds:[si].RAE_height ;dx <- add height of row
adc bx, 0
inc ax ;ax <- next row
jmp endRowLoop
done:
mov ax, bx ;ax:dx <- position
mov bx, ds:[si].RAE_height ;bx <- height of row
call VMUnlock ;done with array
pop cx ;cx = width/height of 1st row
;
; If the cell was before the specified origin, we negate
; the position we've found.
;
popf ;flags from swap comparison
jbe noNegation
negdw axdx ;ax:dx <- -position
mov bx, cx ;bx = width/height of 1st row
noNegation:
.leave
ret
RowGetPositionInt endp
DrawCode ends
AttrCode segment resource
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ColumnSetDefaultAttrs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Set the default attributes for a column
CALLED BY: SetSpreadsheetAttrs()
PASS: cx - column #
ax - default attributes for column
ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: dx
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
gene 1/18/93 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ColumnSetDefaultAttrs proc far
EC < call ECCheckInstancePtr ;>
push ax, bx, cx
mov bx, ax ;bx <- new attr token
mov ax, COLUMN_ARRAY_CHUNK
mov dx, -1 ;dx <- don't change width
GOTO RowSetHeightInt, cx, bx, ax
ColumnSetDefaultAttrs endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ColumnSetWidth
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Set the width of a column
CALLED BY: SpreadsheetSetColumnWidth()
PASS: cx - column #
dx - new column width
ds:si - ptr to Spreadsheet instance data
RETURN: dx - actual column width set
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/ 8/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ColumnSetWidth proc far
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
cmp dx, SS_COLUMN_WIDTH_MAX ;dx <- MIN( width, maxWidth )
jbe gotWidth
mov dx, SS_COLUMN_WIDTH_MAX
gotWidth:
push ax, bx, cx
mov ax, COLUMN_ARRAY_CHUNK ;ax <- chunk of column array
mov bx, -1 ;don't change default attrs
GOTO RowSetHeightInt, cx, bx, ax
ColumnSetWidth endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowSetHeight
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Set the height of a row
CALLED BY: SpreadsheetSetRowHeight()
PASS: ax - row #
dx - new row height
bx - new row baseline (ROW_HEIGHT_AUTOMATIC OR'd for automatic)
ds:si - ptr to Spreadsheet instance data
RETURN: none
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/ 8/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowSetHeight proc far
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
cmp dx, ROW_HEIGHT_MAX ; dx <- MIN( height, maxHeight )
jbe gotHeight
mov dx, ROW_HEIGHT_MAX
gotHeight:
push ax, bx, cx
mov cx, ax ;cx <- row #
mov ax, ROW_ARRAY_CHUNK ;ax <- chunk of row array
FALL_THRU RowSetHeightInt, cx, bx, ax
RowSetHeight endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowSetHeightInt
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Set the row height / column width, part II
CALLED BY: ColumnSetWidth(), RowSetHeight()
PASS: ax - VM block handle of row/column array
cx - row #
dx - new row height / column width
bx - new baseline (0 for columns)
(if either of dx or bx is -1, it will not be set)
on stack:
saved ax
saved bx
saved cx
ds:si - ptr to Spreadsheet instance
RETURN: none
DESTROYED: none
PSEUDO CODE/STRATEGY:
There are several cases for setting the row height:
(1) do nothing -- height hasn't changed
(2) insert 0 entries (separate entry already exists)
(3) insert 0 entries (matches run before)
(4) insert 0 entries (matches run after)
(5) insert 1 entry (new entry at end of run)
(6) insert 1 entry (new entry at beginning of run)
(7) insert 2 entries (new entry in middle of run)
(8) delete 1 entry (was separate, matches run before)
(9) delete 1 entry (was separate, matches run after)
(10) delete 2 entries (was separate, matches before & after, combine 3)
KNOWN BUGS/SIDE EFFECTS/IDEAS:
Little effort has been put into making this routine efficient,
as setting row heights and column widths is not a frequently
done operation. Given the number of possibilities enumerated
above, optimization would be difficult, in any event.
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/ 8/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowSetHeightInt proc far
uses bp, ds, si, di
.enter
EC < call ECCheckInstancePtr ;>
call LockRowArrayFar ;ds:si <- ptr to 1st entry
findRowLoop:
EC < call ECRowCheckOffset ;>
cmp ds:[si].RAE_row, cx ;correct row?
jae foundRow ;branch if correct row
add si, (size RowArrayEntry) ;ds:si <- ptr to next entry
jmp findRowLoop
foundRow:
cmp bx, -1 ;skip baseline check?
jne afterBaselineCheck
mov bx, ds:[si].RAE_baseline ;bx <- current baseline
afterBaselineCheck:
cmp dx, -1 ;skip height check?
jne afterHeightCheck
mov dx, ds:[si].RAE_height ;dx <- current row height
afterHeightCheck:
;
; Height or baseline changed? If not, we're done.
; (1) do nothing -- height hasn't changed
;
cmp ds:[si].RAE_height, dx ;height changed?
jne changed
cmp ds:[si].RAE_baseline, bx ;baseline changed?
je noChange
;
; Check if at border of runs
;
changed:
EC < call ECRowCheckOffset ;>
mov ax, ds:[si][-(size RowArrayEntry)].RAE_row
inc ax
cmp ax, cx ;after rows before?
je atEnd
cmp ds:[si].RAE_row, cx
je atTop
;
; The row is in the middle of a run. We need to insert two
; new entries, one for the first half of the old run, and
; one for the new run.
; (7) insert 2 entries (new entry in middle of run)
;
mov ax, (size RowArrayEntry)*2 ;ax <- # bytes to insert
call RowArrayInsert
mov ax, ds:[si][+(size RowArrayEntry)*2].RAE_height
mov ds:[si].RAE_height, ax
mov ax, ds:[si][+(size RowArrayEntry)*2].RAE_baseline
mov ds:[si].RAE_baseline, ax
cmp dx, -1
mov ds:[si][+(size RowArrayEntry)].RAE_height, dx
mov ds:[si][+(size RowArrayEntry)].RAE_baseline, bx
mov ds:[si][+(size RowArrayEntry)].RAE_row, cx
dec cx
mov ds:[si].RAE_row, cx
done:
call VMDirty
noChange:
EC < call ECCheckRowArray ;>
call VMUnlock ;done with array
.leave
FALL_THRU_POP cx, bx, ax
ret
;
; The row is at the end of the run before.
atEnd:
;
; See if a separate entry
;
cmp ds:[si].RAE_row, cx ;separate entry?
je separateEntry
;
; See if the row heights and baselines match. If so, we can
; just extend the run before to include our row.
;
cmp ds:[si][-(size RowArrayEntry)].RAE_height, dx
jne insertOne
cmp ds:[si][-(size RowArrayEntry)].RAE_baseline, bx
jne insertOne
;
; The row is at the end of the run before, and the
; height and baseline are the same, so we can just
; extend the run to include our row.
; (3) insert 0 entries (matches run before)
;
mov ds:[si][-(size RowArrayEntry)].RAE_row, cx
jmp done
;
; The row is at the top of the current run.
; Because of the order of checks, we know it isn't
; after the end of the run before, too.
atTop:
;
; See if the row heights and baselines match the next run.
; If so, we can just extend the run after to include our row.
;
cmp ds:[si][+(size RowArrayEntry)].RAE_height, dx
jne insertOneAfter
cmp ds:[si][+(size RowArrayEntry)].RAE_baseline, bx
jne insertOneAfter
;
; The row is at the start of the next run, and the
; height and baseline are the same, so we can just
; extend the run to include our row.
; This is actually done by shortening the current run.
; (4) insert 0 entries (matches run after)
;
dec cx
mov ds:[si].RAE_row, cx
jmp done
; The row is at the end of the run before and the heights don't match.
; (5) insert 1 entry (new entry at end of run)
;
insertOne:
mov ax, (size RowArrayEntry) ;ax <- # bytes to insert
call RowArrayInsert ;insert me jesus
setCurrentRow:
mov ds:[si].RAE_row, cx
setCurrent:
mov ds:[si].RAE_height, dx
mov ds:[si].RAE_baseline, bx
jmp done
;
; The row is at the start of the run after and the heights don't match
; (6) insert 1 entry (new entry at beginning of run)
;
insertOneAfter:
mov ax, (size RowArrayEntry) ;ax <- # bytes to insert
add si, ax
call RowArrayInsert ;insert me jesus
mov ax, cx
dec ax
mov ds:[si][-(size RowArrayEntry)].RAE_row, ax
jmp setCurrentRow
;
; There is currently a separate entry for this row.
; Either the new row matches, none, one, or both
; of the runs before and after, in which case we
; delete 0, 1 or 2 runs, respectively.
; (2) insert 0 entries (separate entry already exists)
; (8) delete 1 entry (was separate, matches run before)
; (9) delete 1 entry (was separate, matches run after)
; (10) delete 2 entries (was separate, matches before & after, combine)
;
separateEntry:
cmp ds:[si][-(size RowArrayEntry)].RAE_height, dx
jne mismatchBefore
cmp ds:[si][-(size RowArrayEntry)].RAE_baseline, bx
jne mismatchBefore
cmp ds:[si][+(size RowArrayEntry)].RAE_height, dx
jne mergeBefore
cmp ds:[si][+(size RowArrayEntry)].RAE_baseline, bx
jne mergeBefore
;
; The new row matches before and after, so we can combine
; three entries into one.
; (10) delete 2 entries (was separate, matches before and after)
;
sub si, (size RowArrayEntry) ;ds:si <- ptr to deletion
mov ax, (size RowArrayEntry)*2 ;ax <- # bytes to delete
call RowArrayDelete
jmp done
;
; The new row mismatches before. If it mismatches after, too,
; then we can just set the new values in the existing entry.
; (2) insert 0 entries (separate entry already)
;
mismatchBefore:
cmp ds:[si][+(size RowArrayEntry)].RAE_height, dx
jne setCurrent
cmp ds:[si][+(size RowArrayEntry)].RAE_baseline, bx
jne setCurrent
;
; The new row mismatches before, but matches after.
; Combine the old separate entry with the run after.
; (9) delete 1 entry (was separate, matches run after)
;
deleteCurrent:
mov ax, (size RowArrayEntry) ;ax <- # bytes to delete
call RowArrayDelete
jmp done
;
; The new row matches before, and mismatches after.
; Combine the old separate entry with the run before
; (8) delete 1 entry (was separate, matches run before)
;
mergeBefore:
mov ds:[si][-(size RowArrayEntry)].RAE_row, cx
jmp deleteCurrent
RowSetHeightInt endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowArrayInsert
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Insert space in the middle of the row/column array
CALLED BY: RowSetHeightInt()
PASS: ds:si - ptr to insertion
ax - # of bytes to insert
di - chunk handle of row or column array
RETURN: ds:si - ptr to insertion
DESTROYED: ax
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/10/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowArrayInsert proc near
uses bx, cx
.enter
mov cx, ax ;cx <- # bytes to insert
mov ax, di ;ax <- chunk handle
mov bx, ds:[di] ;bx <- offset of chunk
sub si, bx
mov bx, si ;bx <- offset of insertion
call LMemInsertAt
mov si, ds:[di] ;ds:si <- ptr to chunk
add si, bx ;ds:si <- ptr to insertion
.leave
ret
RowArrayInsert endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowArrayDelete
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Delete space in the middle of a row/column array
CALLED BY: RowSetHeightInt()
PASS: ds:si - ptr to deletion
ax - # of bytes to delete
di - chunk handle of row or column array
RETURN: ds:si - ptr to deletion
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/10/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowArrayDelete proc far
uses ax, bx, cx
.enter
mov cx, ax ;cx <- # bytes to insert
mov ax, di ;ax <- chunk handle
mov bx, ds:[di] ;bx <- offset of chunk
sub si, bx
mov bx, si ;bx <- offset of insertion
call LMemDeleteAt
mov si, ds:[di] ;ds:si <- ptr to chunk
add si, bx ;ds:si <- ptr to insertion
.leave
ret
RowArrayDelete endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ECRowCheckOffset
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Verify that the offset passed is within array bounds.
CALLED BY: RowSetHeightInt(), RowGetHeightInt(), RowGetPositionInt()
PASS: ds - seg addr of row/column array
si - offset to check
di - chunk handle of row/column array
RETURN: none
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 3/ 8/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
if ERROR_CHECK
ECRowCheckOffset proc far
uses ax, cx, si
.enter
mov ax, si ;ax <- offset to check
mov si, ds:[di] ;ds:si <- ptr to chunk
cmp ax, si ;offset large enough?
ERROR_B ROW_ARRAY_BAD_ROW
ChunkSizePtr ds, si, cx ;cx <- size of chunk
add si, cx ;si <- ptr to end of chunk
cmp ax, si ;offset small enough?
ERROR_A ROW_ARRAY_BAD_ROW
.leave
ret
ECRowCheckOffset endp
endif
AttrCode ends
DrawCode segment resource
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Pos32ToVisCell
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Return row and column relative to cell given a visible position
CALLED BY: SpreadsheetStartSelect()
PASS: ds:si - ptr to Spreadsheet instance
ss:bx - ptr to point (ptr to PointDWord)
RETURN: (ax,cx) - row, column
DESTROYED: ss:bx - point destroyed
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 4/ 2/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
Pos32ToVisCellFar proc far
call Pos32ToVisCell
ret
Pos32ToVisCellFar endp
Pos32ToVisCell proc near
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
mov ax, ds:[si].SSI_offset.PD_x.low
sub ss:[bx].PD_x.low, ax
mov ax, ds:[si].SSI_offset.PD_x.high
sbb ss:[bx].PD_x.high, ax
mov ax, ds:[si].SSI_offset.PD_y.low
sub ss:[bx].PD_y.low, ax
mov ax, ds:[si].SSI_offset.PD_y.high
sbb ss:[bx].PD_y.high, ax
mov ax, ds:[si].SSI_visible.CR_start.CR_row
mov cx, ds:[si].SSI_visible.CR_start.CR_column
FALL_THRU Pos32ToCellRel
Pos32ToVisCell endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Pos32ToCellRel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Return row and column relative to cell given a position
CALLED BY: FindLowerRightCell(), RangeDrawGrid()
PASS: ds:si - ptr to Spreadsheet instance
(ax,cx) - (r,c) to get position relative to
ss:bx - ptr to point (ptr to PointDWord)
RETURN: (ax,cx) - row, column
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 4/ 2/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
Pos32ToCellRel proc near
uses dx, bp
.enter
EC < call ECCheckInstancePtr ;>
push cx ;save column origin
mov cx, ax ;cx <- origin row
lea bp, ss:[bx].PD_y ;ss:bp <- ptr to coordinate
call Pos32ToRowRel
pop cx ;cx <- column origin
push ax ;save row #
lea bp, ss:[bx].PD_x ;ss:bp <- ptr to coordinate
call Pos32ToColRel
mov cx, ax ;cx <- column #
pop ax ;ax <- row #
.leave
ret
Pos32ToCellRel endp
Pos32ToCellRelFar proc far
call Pos32ToCellRel
ret
Pos32ToCellRelFar endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Pos32ToColRel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Convert 32-bit position to column (relative to specified origin)
CALLED BY: Pos32ToCellRel()
PASS: ds:si - ptr to Spreadsheet instance
cx - column to get position relative to
ss:bp - ptr to sdword
RETURN: ax - column #
cx - distance to column right edge (<=0)
dx - distance to column left edge (>=0)
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 7/27/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
Pos32ToColRel proc near
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
mov ax, COLUMN_ARRAY_CHUNK ;ax <- chunk of array
mov dx, ds:[si].SSI_maxCol ;dx <- maximum column to check
GOTO PositionToCommon
Pos32ToColRel endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Pos32ToRowRel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Convert 32-bit position to row (relative to specified origin)
CALLED BY: Pos32ToCellRel()
PASS: ds:si - ptr to Spreadsheet instance
cx - row to get position relative to
ss:bp - ptr to sdword
RETURN: ax - row #
cx - distance to row bottom edge (<=0)
dx - distance to row top edge (>=0)
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 7/27/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
Pos32ToRowRel proc near
class SpreadsheetClass
EC < call ECCheckInstancePtr ;>
mov ax, ROW_ARRAY_CHUNK ;ax <- chunk of array
mov dx, ds:[si].SSI_maxRow ;dx <- maximum row to check
FALL_THRU PositionToCommon
Pos32ToRowRel endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PositionToCommon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Find nearest row/column to relative position
CALLED BY: PositionToColumn(), PositionToRow(), PositionToCell()
PASS: ds:si - ptr to Spreadsheet instance
ss:bp - ptr to position (x or y coordinate)
ax - row/column array chunk handle
cx - row/column to start at
dx - maximum row/column to check
RETURN: ax - row/column #
cx - distance to row/column bottom/right edge (<=0)
dx - distance to row/column top/left edge (>=0)
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
If the position specified is negative, then the first row/column
is returned. If the position specified is beyond the last
row/column, then the last row/column is returned.
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 4/ 2/91 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
PositionToCommon proc near
uses bx, si, di, bp, ds
.enter
EC < call ECCheckInstancePtr ;>
mov bx, ss:[bp].high ;bx <- high word of position
tst bx ;check for before first row
js beforeFirst ;branch if negative
push ss:[bp].low ;save low word
call LockRowArray ;ds:si <- ptr to RowArray
pop di ;bx:di <- position to find
startRowLoop:
cmp cx, ds:[si].RAE_row ;at start row yet?
jbe foundStart
add si, (size RowArrayEntry) ;ds:si <- ptr to next entry
jmp startRowLoop
foundStart:
push bp ;save VM handle
clrdw bpax ;bp:ax <- running total
rowLoop:
cmp cx, dx ;at end of row block?
ja foundPastRow ;branch if after last row
cmp bp, bx ;check high word
ja foundPastRow ;branch if far enough
jb rowOK
cmp ax, di ;check low word
ja foundPastRow ;branch if far enough
; If they're equal, we proceed as if AX < DI, so that BP:AX
; will correctly point to the right edge of the current column
; (or the bottom of the current row).
rowOK:
cmp cx, ds:[si].RAE_row ;height still same?
jbe sameHeight ;branch if height same
add si, (size RowArrayEntry) ;skip to next block
sameHeight:
add ax, ds:[si].RAE_height
adc bp, 0 ;bp:ax <- running total
inc cx ;cx <- new current row
jmp rowLoop
foundPastRow:
dec cx ;cx <- row/column
;
; cx - row/column #
; bp:ax - total position
; bx:di - position to match
;
sub di, ax ;di <- distance to start
mov_tr ax, cx ;ax <- row/column
mov cx, di ;cx <- distance to bottom (<=0)
mov dx, cx
add dx, ds:[si].RAE_height ;dx <- distance to top (>= 0)
;
; Unlock the row array
;
pop bp ;bp <- VM handle
call VMUnlock ;preserves flags
done:
.leave
ret
beforeFirst:
mov ax, cx ;ax <- first row/column
clrdw dxcx ;dxcx <- at edge
jmp done
PositionToCommon endp
DrawCode ends
AttrCode segment resource
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
GetRowDiffs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get row heights and/or differences for a range
CALLED BY: UTILITY
PASS: ds:si - ptr to Spreadsheet instance
cx - start row
dx - end row
RETURN: ax - row height for selection
ROW_HEIGHT_AUTOMATIC set if appropriate
carry - set if multiple row heights
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 7/28/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
GetRowDiffs proc near
mov ax, ROW_ARRAY_CHUNK ;ax <- chunk of array
GOTO RowDiffsCommon
GetRowDiffs endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
GetColumnDiffs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Get column widths and/or differences for a range
CALLED BY: UTILITY
PASS: ds:si - ptr to Spreadsheet instance
cx - start row
dx - end row
RETURN: ax - column width for selection
carry - set if multiple column widths
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 7/28/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
GetColumnDiffs proc near
mov ax, COLUMN_ARRAY_CHUNK
FALL_THRU RowDiffsCommon
GetColumnDiffs endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowDiffsCommon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Common routine to get row or column differences for a range
CALLED BY: GetRowDiffs(), GetColumnDiffs()
PASS: ds:si - ptr to Spreadsheet instance
ax - row/column array chunk handle
cx - start row
dx - end row
RETURN: ax - row height / column width for selection
carry - set if multiple row heights
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 7/28/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowDiffsCommon proc near
uses bp, si, di, ds
.enter
EC < call ECCheckInstancePtr ;>
call LockRowArrayFar ;ds:si <- ptr to RowArray
;
; Find the entry for the first row
;
startRowLoop:
EC < call ECRowCheckOffset ;>
cmp cx, ds:[si].RAE_row ;at start row yet?
jbe foundStart
add si, (size RowArrayEntry) ;ds:si <- ptr to next entry
jmp startRowLoop
;
; If the last row is in the same entry, then there are
; no differences, otherwise there are.
;
foundStart:
clr ax
cmp di, COLUMN_ARRAY_CHUNK ;doing columns?
je getHeight ;if columns, ignore baseline
mov ax, ds:[si].RAE_baseline
andnf ax, ROW_HEIGHT_AUTOMATIC ;ax <- automatic flag
getHeight:
ornf ax, ds:[si].RAE_height ;ax <- height of first row
cmp dx, ds:[si].RAE_row
jbe noDiffs
stc ;carry <- diffs
jmp done
noDiffs:
clc ;carry <- no diffs
done:
call VMUnlock ;preserves flags
.leave
ret
RowDiffsCommon endp
AttrCode ends
;
; NOTE: this code is placed in the same resource as
; MSG_SPREADSHEET_INSERT_SPACE since that is the only code that
; calls it.
;
SpreadsheetSortSpaceCode segment resource
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowInsertHeights
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Insert specified number of new row heights
CALLED BY: UTILITY
PASS: ds:si - ptr to Spreadsheet instance
cx - starting row
dx - # of rows (<0 == delete)
RETURN: none
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
gene 8/11/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowInsertHeights proc near
class SpreadsheetClass
push ax, bx
mov ax, ROW_ARRAY_CHUNK
;;;
;;; Hack 5/17/95 -jw
;;;
;;; We need a consistent value, otherwise spreadsheets with different
;;; numbers of rows can't move between platforms.
;;;
;;; mov bx, ds:[si].SSI_maxRow ;bx <- maximum row to check
mov bx, ROW_ARRAY_TERMINATOR
GOTO RowInsertCommon, bx, ax
RowInsertHeights endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ColumnInsertWidths
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Insert specified number of new column heights
CALLED BY: UTILITY
PASS: ds:si - ptr to Spreadsheet instance
cx - starting column
dx - # of columns (<0 == delete)
RETURN: none
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
gene 8/11/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
ColumnInsertWidths proc near
class SpreadsheetClass
push ax, bx
mov ax, COLUMN_ARRAY_CHUNK
;;;
;;; Hack 5/17/95 -jw
;;;
;;; We need a consistent value, otherwise spreadsheets with different
;;; numbers of columns can't move between platforms.
;;;
;;; mov bx, ds:[si].SSI_maxCol ;bx <- maximum column to check
mov bx, COLUMN_ARRAY_TERMINATOR
FALL_THRU RowInsertCommon, bx, ax
ColumnInsertWidths endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RowInsertCommon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Common code to insert # of row/column heights/widths
CALLED BY: RowInsertHeights(), ColumnInsertWidths()
PASS: ax - chunk of row/column array
bx - max row/column to check
ds:si - ptr to Spreadsheet instance
cx - starting row
dx - # of rows/columns (<0 == delete)
on stack:
saved ax
saved bx
RETURN: none
DESTROYED: none
PSEUDO CODE/STRATEGY:
Two different cases:
Inserting:
----------
(1) All rows after the starting row are shifted by the number
of rows being inserted. (one exception to this is the
last row entry, because it never changes).
(2) All entries are normalized -- checked for duplicate entries,
or adjacent entries that can be combined.
(3) The new rows are set to the default height.
Deleting:
---------
(1) All entries which are entirely in the deleted area are marked
as needing to be nuked
(2) All entries which span the end of the deleted area are set
so they start at the end of the deleted area
(3) All entries beyond the deleted area are adjusted
(4) All entries are normalized -- checked for duplicate entries,
or adjacent entries that can be combined.
(5) The new rows are set to the default height.
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
gene 8/11/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
RowInsertCommon proc near
uses ax, ds, si, di, bp
.enter
;;;vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
;;; Changes, 4/23/93 -jw
;;; Much of this did not change, but I did add some comments. The changed
;;; part really starts where the "===" appears below
;
; Lock the row array and find the first entry which begins after the
; start of the affected area. That is to say, find the first entry
; after the place we inserted or deleted.
;
call LockRowArrayFar ; ds:si <- ptr to 1st entry
; di <- chunk handle
; bp <- VM block handle
push si ; Save this, for merging later
;
; Find the entry for the first row after the affected area.
;
clr bp ; bp <- previous entry
startRowLoop:
EC < call ECRowCheckOffset >
cmp cx, ds:[si].RAE_row
jbe adjustRows ; Branch if at affected row
mov bp, ds:[si].RAE_row ; bp <- previous row
add si, (size RowArrayEntry); ds:si <- ptr to next entry
jmp startRowLoop
;
; Check to see if we have run into the very last entry, in which case
; there's nothing to modify and we can quit out early.
;
adjustRows:
cmp bx, ds:[si].RAE_row
LONG je noChange ; if at last row, no change
;
; For each affected entry, do something meaningful.
;
adjustRowLoop:
EC < call ECRowCheckOffset >
mov ax, ds:[si].RAE_row
;
; Check for having reached the last row (which means we can quit this)
;
cmp bx, ax
je doneAdjust ; Branch if on last row
;;;=============================================================================
;;; This code handles deleting correctly. The cases for inserting haven't
;;; changed at all, they're still really simple.
;
; Adjust the row value for this entry and make a few special cases
; row + adjust > maxRow
; row <- maxRow, make this entry the last one
; This can only happen when inserting
;
tst dx
js deletingSpace
add ax, dx ; ax <- adjusted row
cmp ax, bx
jg adjustTooBig ; Branch if adjusted to far
jmp storeAdjust
deletingSpace:
;
; 1) Range spans start of deleted area:
; +--- del ---+
; +-------e
; Test: (range.start < del.start) &&
; (range.end >= del.start)
; Set: range.end = del.start - 1
;
; 2) Range is inside deleted area:
; +--- del ---+
; +-------e
; Test: (range.start >= del.start) &&
; (range.start <= del.end) &&
; (range.end >= del.start) &&
; (range.end <= del.end)
; Set: range.end = -1
;
; All other cases mean that the end of the range is beyond the end
; of the deleted range, and therefore should simply be adjusted by
; the amount of space that is being deleted.
;
; We already know that range.start is > del.start, since that's what
; that first loop in this routine produced.
;
push cx
sub cx, dx ; cx <- del.end
dec cx
cmp ax, cx ; Check r.end, d.end
pop cx
jae adjustForDelete
;
; The end of the range falls before the end of the deleted area
; This indicates one of the two special cases above. The only
; real check we need to do is to find if the start of the range
; is before or after the start of the deleted area.
;
cmp bp, cx ; Check r.start , d.start
jae rangeInsideDel
;
; The range spans the start of the deleted range
;
mov ax, cx
dec ax
jmp storeAdjust
rangeInsideDel:
;
; The range is entirely inside the deleted area
;
mov ax, -1
jmp storeAdjust
adjustForDelete:
add ax, dx ; Adjust for deletion
storeAdjust:
;
; Save the value to adjust.
;
mov bp, ds:[si].RAE_row ; di <- previous row
;;;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
mov ds:[si].RAE_row, ax ;store adjusted row
add si, (size RowArrayEntry) ;ds:si <- next entry
jmp adjustRowLoop
adjustTooBig:
mov ax, bx ;ax <- maximum row
jmp storeAdjust
;
; Make sure there are no duplicate entries, and merge
; any adjacent entries that can be merged.
;
doneAdjust:
pop si ;ds:si <- ptr to 1st entry
mergeLoop:
cmp ds:[si].RAE_height, -1 ;beyond last row?
je doneMerge
;
; Is this entry for the same row(s) as the next?
;
mov ax, ds:[si].RAE_row ;ax <- row #
cmp ax, ds:[si][+(size RowArrayEntry)].RAE_row
jb checkAdjacent
;
; This entry is the same as the next...delete it.
; We branch back to the top of the loop without
; advancing the pointer because the next entry
; has been shifted down, so the ptr is correct.
;
cmp ax, cx ;beyond start row?
ja deleteMergeEntry
mov ax, (size RowArrayEntry) ;ax <- # of bytes to delete
add si, ax ;delete next entry for insert
call RowArrayDelete
sub si, ax ;ds:si <- back up to original
jmp mergeLoop
deleteMergeEntry:
mov ax, (size RowArrayEntry) ;ax <- # of bytes to deletee
call RowArrayDelete
jmp mergeLoop ;branch do next entry
;
; See if the row height and baseline for this entry are
; the same as the next entry.
;
checkAdjacent:
mov ax, ds:[si].RAE_height
cmp ax, ds:[si][+(size RowArrayEntry)].RAE_height
jne nextMergeEntry
mov ax, ds:[si].RAE_baseline
cmp ax, ds:[si][+(size RowArrayEntry)].RAE_baseline
je deleteMergeEntry
;
; Advance to the next entry
;
nextMergeEntry:
add si, (size RowArrayEntry) ;ds:si <- ptr to next entry
jmp mergeLoop
noChange:
pop si ;clean up stack
jmp unlockArray
;
; Mark the block as dirty, and unlock it.
;
doneMerge:
mov bp, ds:LMBH_handle
call VMDirty
unlockArray:
EC < call ECCheckRowArray ;>
mov bp, ds:LMBH_handle
call VMUnlock
.leave
FALL_THRU_POP bx, ax
ret
RowInsertCommon endp
SpreadsheetSortSpaceCode ends
|
BITS 32
;TEST_FILE_META_BEGIN
;TEST_TYPE=TEST_F
;TEST_IGNOREFLAGS=
;TEST_FILE_META_END
; set up st0 to be 3.141593
FLDPI
FLD1
FLD1
;TEST_BEGIN_RECORDING
FDIVR st0, st2
mov edi, 0
;TEST_END_RECORDING
|
; A245327: Numerators in recursive bijection from positive integers to positive rationals (the bijection is f(1) = 1, f(2n) = 1/(f(n)+1), f(2n+1) = f(n)+1 .
; Submitted by Jon Maiga
; 1,1,2,2,3,1,3,3,5,2,5,3,4,1,4,5,8,3,8,5,7,2,7,4,7,3,7,4,5,1,5,8,13,5,13,8,11,3,11,7,12,5,12,7,9,2,9,7,11,4,11,7,10,3,10,5,9,4,9,5,6,1,6,13,21,8,21,13,18,5,18,11,19,8,19,11,14,3,14,12,19,7,19,12,17,5,17,9,16,7,16,9,11,2,11,11,18,7,18,11
add $0,1
mul $0,2
mov $2,2
mov $3,1
lpb $0
div $0,2
sub $2,$3
add $3,1
add $3,$0
mod $3,2
mov $4,$2
add $2,$1
add $4,1
mul $3,$4
add $1,$3
lpe
mov $0,$1
div $0,2
|
void v() {
int j = 0;
while(int k = j < 5) {
}
}
|
/*********************************************************************************
*
* Inviwo - Interactive Visualization Workshop
*
* Copyright (c) 2016-2017 Inviwo Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*********************************************************************************/
#include <modules/animation/datastructures/animationobserver.h>
namespace inviwo {
namespace animation {
void AnimationObservable::notifyTrackAdded(Track* track) {
forEachObserver([&](AnimationObserver* o) { o->onTrackAdded(track); });
}
void AnimationObservable::notifyTrackRemoved(Track* track) {
forEachObserver([&](AnimationObserver* o) { o->onTrackRemoved(track); });
}
void AnimationObservable::notifyFirstMoved() {
forEachObserver([&](AnimationObserver* o) { o->onFirstMoved(); });
}
void AnimationObservable::notifyLastMoved() {
forEachObserver([&](AnimationObserver* o) { o->onLastMoved(); });
}
} // namespace
} // namespace
|
; ===============================================================
; Dec 2013
; ===============================================================
;
; void *heap_init(void *heap, size_t size)
;
; Initialize a heap of size bytes.
; An unchecked condition is that size > 14 bytes.
;
; ===============================================================
SECTION code_clib
SECTION code_alloc_malloc
PUBLIC asm_heap_init
EXTERN mtx_plain, asm_mtx_init, error_enolck_zc
EXTERN l_setmem_hl
asm_heap_init:
; initialize the heap to empty
; area reserved for the heap must be at least 14 bytes
;
; enter : hl = void *heap
; bc = number of available bytes >= 14
;
; exit : success
;
; hl = void *heap
; carry reset
;
; fail if mutex init fails
;
; hl = 0
; de = void *heap
; carry set, errno = ENOLCK
;
; uses : af, bc, de, hl
ld de,hl ; de = void *heap
push hl ; save void *heap
push bc ; save num bytes
ld c,mtx_plain
call asm_mtx_init
jp C, error_enolck_zc - 2 ; if mutex init failed
ld hl,6 ; sizeof(mutex)
add hl,de
ex de,hl ; de = start of heap proper
pop bc ; bc = num bytes
add hl,bc ; hl = & byte past heap
xor a
dec hl
ld (hl),a
dec hl
ld (hl),a ; write end of heap marker
ex de,hl
ld (hl),e
inc hl
ld (hl),d ; block_first->next = & heap_end
inc hl
call l_setmem_hl - 8 ; zero out four bytes
pop hl ; hl = void *heap
ret
|
#include <stdio.h>
#include <component153/lib1.h>
#include <externalComponent23/lib1.h>
#include <component719/lib1.h>
#include <component652/lib1.h>
#include <externalComponent156/lib1.h>
#include <component785/lib1.h>
#include <component1079/lib1.h>
#include <component158/lib1.h>
#include <component1077/lib1.h>
#include <component1078/lib1.h>
#include <component164/lib1.h>
#include <component783/lib1.h>
#include <component788/lib1.h>
#include <externalComponent9/lib1.h>
#include <externalComponent10/lib1.h>
#include <externalComponent11/lib1.h>
#include <externalComponent12/lib1.h>
#include <externalComponent13/lib1.h>
#include <externalComponent14/lib1.h>
#include <externalComponent15/lib1.h>
#include <externalComponent16/lib1.h>
#include <externalComponent17/lib1.h>
#include <externalComponent18/lib1.h>
#include <externalComponent19/lib1.h>
#include <externalComponent20/lib1.h>
#include <externalComponent21/lib1.h>
#include <externalComponent167/lib1.h>
#include <component169/lib1.h>
#include <externalComponent170/lib1.h>
#include <component265/lib1.h>
#include <externalComponent1/lib1.h>
#include <externalComponent2/lib1.h>
#include <externalComponent3/lib1.h>
#include <externalComponent4/lib1.h>
#include <externalComponent5/lib1.h>
#include <externalComponent6/lib1.h>
#include <externalComponent7/lib1.h>
#include <component172/lib1.h>
#include <externalComponent23/lib1.h>
#include <externalComponent24/lib1.h>
#include <externalComponent25/lib1.h>
#include <externalComponent26/lib1.h>
#include <externalComponent27/lib1.h>
#include <externalComponent28/lib1.h>
#include <externalComponent29/lib1.h>
#include <externalComponent30/lib1.h>
#include <externalComponent31/lib1.h>
#include <externalComponent32/lib1.h>
#include <externalComponent33/lib1.h>
#include <externalComponent34/lib1.h>
#include <externalComponent35/lib1.h>
#include <externalComponent36/lib1.h>
#include <externalComponent37/lib1.h>
#include <externalComponent38/lib1.h>
#include <externalComponent39/lib1.h>
#include <externalComponent40/lib1.h>
#include <externalComponent41/lib1.h>
#include <externalComponent42/lib1.h>
#include <externalComponent43/lib1.h>
#include <externalComponent44/lib1.h>
#include <externalComponent45/lib1.h>
#include <externalComponent46/lib1.h>
#include <externalComponent47/lib1.h>
#include <externalComponent48/lib1.h>
#include <externalComponent49/lib1.h>
#include <externalComponent50/lib1.h>
#include <externalComponent51/lib1.h>
#include <externalComponent111/lib1.h>
#include <externalComponent53/lib1.h>
#include <externalComponent54/lib1.h>
#include <externalComponent55/lib1.h>
#include <externalComponent56/lib1.h>
#include <externalComponent57/lib1.h>
#include <externalComponent58/lib1.h>
#include <externalComponent59/lib1.h>
#include <externalComponent60/lib1.h>
#include <externalComponent61/lib1.h>
#include <externalComponent62/lib1.h>
#include <externalComponent63/lib1.h>
#include <externalComponent64/lib1.h>
#include <externalComponent65/lib1.h>
#include <externalComponent66/lib1.h>
#include <externalComponent67/lib1.h>
#include <externalComponent68/lib1.h>
#include <externalComponent69/lib1.h>
#include <externalComponent70/lib1.h>
#include <externalComponent71/lib1.h>
#include <externalComponent72/lib1.h>
#include <externalComponent73/lib1.h>
#include <externalComponent74/lib1.h>
#include <externalComponent75/lib1.h>
#include <externalComponent174/lib1.h>
#include <externalComponent204/lib1.h>
#include <externalComponent138/lib1.h>
int main() {
printf("Hello from Main\n");
}
|
; A004373: Binomial coefficient C(7n,n-5).
; 1,42,1176,27720,595665,12103014,237093780,4529365776,84986896995,1573664496040,28848458598960,524780754733872,9488573603719938,170737530940919250,3060335715568296000,54680757182029915776
mov $1,7
mul $1,$0
add $1,35
bin $1,$0
mov $0,$1
|
; A169109: Number of reduced words of length n in Coxeter group on 48 generators S_i with relations (S_i)^2 = (S_i S_j)^25 = I.
; 1,48,2256,106032,4983504,234224688,11008560336,517402335792,24317909782224,1142941759764528,53718262708932816,2524758347319842352,118663642324032590544,5577191189229531755568,262127985893787992511696
add $0,1
mov $3,1
lpb $0
sub $0,1
add $2,$3
div $3,$2
mul $2,47
lpe
mov $0,$2
div $0,47
|
/////////////////////////////////////////////////////////////////////////////
//
// File : QIODevice.cpp
// Copyright : (c) David Harley 2010
// Project : qtHaskell
// Version : 1.1.4
// Modified : 2010-09-02 17:01:55
//
// Warning : this file is machine generated - do not modify.
//
/////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <wchar.h>
#include <qtc_wrp_core.h>
#include <qtc_subclass.h>
#include <core/QIODevice_DhClass.h>
extern "C"
{
QTCEXPORT(int,qtc_QIODevice_atEnd)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
return (int)((DhQIODevice*)tx0)->DhatEnd();
} else {
return (int)((QIODevice*)tx0)->atEnd();
}
}
QTCEXPORT(int,qtc_QIODevice_atEnd_h)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (int)((DhQIODevice*)tx0)->DvhatEnd();
}
QTCEXPORT(long long int,qtc_QIODevice_bytesAvailable)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
return (long long int)((DhQIODevice*)tx0)->DhbytesAvailable();
} else {
return (long long int)((QIODevice*)tx0)->bytesAvailable();
}
}
QTCEXPORT(long long int,qtc_QIODevice_bytesAvailable_h)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (long long int)((DhQIODevice*)tx0)->DvhbytesAvailable();
}
QTCEXPORT(long long int,qtc_QIODevice_bytesToWrite)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
return (long long int)((DhQIODevice*)tx0)->DhbytesToWrite();
} else {
return (long long int)((QIODevice*)tx0)->bytesToWrite();
}
}
QTCEXPORT(long long int,qtc_QIODevice_bytesToWrite_h)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (long long int)((DhQIODevice*)tx0)->DvhbytesToWrite();
}
QTCEXPORT(int,qtc_QIODevice_canReadLine)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
return (int)((DhQIODevice*)tx0)->DhcanReadLine();
} else {
return (int)((QIODevice*)tx0)->canReadLine();
}
}
QTCEXPORT(int,qtc_QIODevice_canReadLine_h)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (int)((DhQIODevice*)tx0)->DvhcanReadLine();
}
QTCEXPORT(void,qtc_QIODevice_close)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
((DhQIODevice*)tx0)->Dhclose();
} else {
((QIODevice*)tx0)->close();
}
}
QTCEXPORT(void,qtc_QIODevice_close_h)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
((DhQIODevice*)tx0)->Dvhclose();
}
QTCEXPORT(void*,qtc_QIODevice_errorString)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QString * tq = new QString(((QIODevice*)tx0)->errorString());
return (void*)(tq);
}
QTCEXPORT(int,qtc_QIODevice_isOpen)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (int) ((QIODevice*)tx0)->isOpen();
}
QTCEXPORT(int,qtc_QIODevice_isReadable)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (int) ((QIODevice*)tx0)->isReadable();
}
QTCEXPORT(int,qtc_QIODevice_isSequential)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
return (int)((DhQIODevice*)tx0)->DhisSequential();
} else {
return (int)((QIODevice*)tx0)->isSequential();
}
}
QTCEXPORT(int,qtc_QIODevice_isSequential_h)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (int)((DhQIODevice*)tx0)->DvhisSequential();
}
QTCEXPORT(int,qtc_QIODevice_isTextModeEnabled)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (int) ((QIODevice*)tx0)->isTextModeEnabled();
}
QTCEXPORT(int,qtc_QIODevice_isWritable)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (int) ((QIODevice*)tx0)->isWritable();
}
QTCEXPORT(int,qtc_QIODevice_open)(void* x0, long x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
return (int)((DhQIODevice*)tx0)->Dhopen((QIODevice::OpenMode)x1);
} else {
return (int)((QIODevice*)tx0)->open((QIODevice::OpenMode)x1);
}
}
QTCEXPORT(int,qtc_QIODevice_open_h)(void* x0, long x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (int)((DhQIODevice*)tx0)->Dvhopen((int)x1);
}
QTCEXPORT(long,qtc_QIODevice_openMode)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (long) ((QIODevice*)tx0)->openMode();
}
QTCEXPORT(void*,qtc_QIODevice_peek)(void* x0, long long int x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QString * tq = new QString(((QIODevice*)tx0)->peek((qint64)x1));
return (void*)(tq);
}
QTCEXPORT(long long int,qtc_QIODevice_pos)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
return (long long int)((DhQIODevice*)tx0)->Dhpos();
} else {
return (long long int)((QIODevice*)tx0)->pos();
}
}
QTCEXPORT(long long int,qtc_QIODevice_pos_h)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (long long int)((DhQIODevice*)tx0)->Dvhpos();
}
QTCEXPORT(void*,qtc_QIODevice_read)(void* x0, long long int x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QString * tq = new QString(((QIODevice*)tx0)->read((qint64)x1));
return (void*)(tq);
}
QTCEXPORT(void*,qtc_QIODevice_readAll)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QString * tq = new QString(((QIODevice*)tx0)->readAll());
return (void*)(tq);
}
QTCEXPORT(void*,qtc_QIODevice_readLine)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QString * tq = new QString(((QIODevice*)tx0)->readLine());
return (void*)(tq);
}
QTCEXPORT(void*,qtc_QIODevice_readLine1)(void* x0, long long int x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QString * tq = new QString(((QIODevice*)tx0)->readLine((qint64)x1));
return (void*)(tq);
}
QTCEXPORT(int,qtc_QIODevice_reset)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
return (int)((DhQIODevice*)tx0)->Dhreset();
} else {
return (int)((QIODevice*)tx0)->reset();
}
}
QTCEXPORT(int,qtc_QIODevice_reset_h)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (int)((DhQIODevice*)tx0)->Dvhreset();
}
QTCEXPORT(int,qtc_QIODevice_seek)(void* x0, long long int x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
return (int)((DhQIODevice*)tx0)->Dhseek((qint64)x1);
} else {
return (int)((QIODevice*)tx0)->seek((qint64)x1);
}
}
QTCEXPORT(int,qtc_QIODevice_seek_h)(void* x0, long long int x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (int)((DhQIODevice*)tx0)->Dvhseek((qint64)x1);
}
QTCEXPORT(void,qtc_QIODevice_setErrorString)(void* x0, wchar_t* x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
((DhQIODevice*)tx0)->DhsetErrorString(from_method(x1));
}
QTCEXPORT(void,qtc_QIODevice_setOpenMode)(void* x0, long x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
((DhQIODevice*)tx0)->DhsetOpenMode((int)x1);
}
QTCEXPORT(void,qtc_QIODevice_setTextModeEnabled)(void* x0, int x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
((QIODevice*)tx0)->setTextModeEnabled((bool)x1);
}
QTCEXPORT(long long int,qtc_QIODevice_size)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
return (long long int)((DhQIODevice*)tx0)->Dhsize();
} else {
return (long long int)((QIODevice*)tx0)->size();
}
}
QTCEXPORT(long long int,qtc_QIODevice_size_h)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (long long int)((DhQIODevice*)tx0)->Dvhsize();
}
QTCEXPORT(int,qtc_QIODevice_waitForBytesWritten)(void* x0, int x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
return (int)((DhQIODevice*)tx0)->DhwaitForBytesWritten((int)x1);
} else {
return (int)((QIODevice*)tx0)->waitForBytesWritten((int)x1);
}
}
QTCEXPORT(int,qtc_QIODevice_waitForBytesWritten_h)(void* x0, int x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (int)((DhQIODevice*)tx0)->DvhwaitForBytesWritten((int)x1);
}
QTCEXPORT(int,qtc_QIODevice_waitForReadyRead)(void* x0, int x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
return (int)((DhQIODevice*)tx0)->DhwaitForReadyRead((int)x1);
} else {
return (int)((QIODevice*)tx0)->waitForReadyRead((int)x1);
}
}
QTCEXPORT(int,qtc_QIODevice_waitForReadyRead_h)(void* x0, int x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (int)((DhQIODevice*)tx0)->DvhwaitForReadyRead((int)x1);
}
QTCEXPORT(long long int,qtc_QIODevice_write)(void* x0, wchar_t* x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QString tx1(from_method(x1));
QByteArray txa1(tx1.toLocal8Bit());
return (long long int) ((QIODevice*)tx0)->write(txa1);
}
QTCEXPORT(long long int,qtc_QIODevice_write1)(void* x0, wchar_t* x1, long long int x2) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QString tx1(from_method(x1));
QByteArray txa1(tx1.toAscii());
return (long long int) ((QIODevice*)tx0)->write(txa1.data(), (qint64)x2);
}
QTCEXPORT(long long int,qtc_QIODevice_writeData)(void* x0, wchar_t* x1, long long int x2) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QString tx1(from_method(x1));
QByteArray txa1(tx1.toAscii());
return (long long int)((DhQIODevice*)tx0)->DhwriteData(txa1.data(), (qint64)x2);
}
QTCEXPORT(long long int,qtc_QIODevice_writeData_h)(void* x0, wchar_t* x1, long long int x2) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QString tx1(from_method(x1));
QByteArray txa1(tx1.toAscii());
return (long long int)((DhQIODevice*)tx0)->DvhwriteData(txa1.data(), (qint64)x2);
}
QTCEXPORT(void,qtc_QIODevice_finalizer)(void* x0) {
delete ((QPointer<QIODevice>*)x0);
}
QTCEXPORT(void*,qtc_QIODevice_getFinalizer)() {
return (void*)(&qtc_QIODevice_finalizer);
}
QTCEXPORT(void,qtc_QIODevice_delete)(void* x0) {
QObject* tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&(((QObject*)tx0)->property(QTC_PROP).isValid())) {
qtc_DynamicQObject* ttx0 = (qtc_DynamicQObject*)tx0;
tx0 = ((QObject*)(tx0->parent()));
ttx0->freeDynamicSlots();
delete ttx0;
}
if ((tx0!=NULL)&&(((QObject*)tx0)->property(QTC_DHPROP).isValid())) {
((DhQIODevice*)tx0)->freeDynamicHandlers();
delete((DhQIODevice*)tx0);
} else {
delete((QIODevice*)tx0);
}
}
QTCEXPORT(void,qtc_QIODevice_deleteLater)(void* x0) {
QObject* tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&(((QObject*)tx0)->property(QTC_PROP).isValid())) {
qtc_DynamicQObject* ttx0 = (qtc_DynamicQObject*)tx0;
tx0 = ((QObject*)(tx0->parent()));
ttx0->freeDynamicSlots();
ttx0->deleteLater();
}
if ((tx0!=NULL)&&(((QObject*)tx0)->property(QTC_DHPROP).isValid())) {
((DhQIODevice*)tx0)->freeDynamicHandlers();
((DhQIODevice*)tx0)->deleteLater();
} else {
((QIODevice*)tx0)->deleteLater();
}
}
QTCEXPORT(void,qtc_QIODevice_childEvent)(void* x0, void* x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
((DhQIODevice*)tx0)->DhchildEvent((QChildEvent*)x1);
}
QTCEXPORT(void,qtc_QIODevice_connectNotify)(void* x0, wchar_t* x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QString tx1(from_method(x1));
QByteArray txa1(tx1.toAscii());
((DhQIODevice*)tx0)->DhconnectNotify(txa1.data());
}
QTCEXPORT(void,qtc_QIODevice_customEvent)(void* x0, void* x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
((DhQIODevice*)tx0)->DhcustomEvent((QEvent*)x1);
}
QTCEXPORT(void,qtc_QIODevice_disconnectNotify)(void* x0, wchar_t* x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QString tx1(from_method(x1));
QByteArray txa1(tx1.toAscii());
((DhQIODevice*)tx0)->DhdisconnectNotify(txa1.data());
}
QTCEXPORT(int,qtc_QIODevice_event)(void* x0, void* x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
return (int)((DhQIODevice*)tx0)->Dhevent((QEvent*)x1);
} else {
return (int)((QObject*)tx0)->event((QEvent*)x1);
}
}
QTCEXPORT(int,qtc_QIODevice_event_h)(void* x0, void* x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
return (int)((DhQIODevice*)tx0)->Dvhevent((QEvent*)x1);
}
QTCEXPORT(int,qtc_QIODevice_eventFilter)(void* x0, void* x1, void* x2) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QObject*tx1 = *((QPointer<QObject>*)x1);
if ((tx1!=NULL)&&((QObject *)tx1)->property(QTC_PROP).isValid()) tx1 = ((QObject*)(((qtc_DynamicQObject*)tx1)->parent()));
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_DHPROP).isValid()) {
return (int)((DhQIODevice*)tx0)->DheventFilter((QObject*)tx1, (QEvent*)x2);
} else {
return (int)((QObject*)tx0)->eventFilter((QObject*)tx1, (QEvent*)x2);
}
}
QTCEXPORT(int,qtc_QIODevice_eventFilter_h)(void* x0, void* x1, void* x2) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QObject*tx1 = *((QPointer<QObject>*)x1);
if ((tx1!=NULL)&&((QObject *)tx1)->property(QTC_PROP).isValid()) tx1 = ((QObject*)(((qtc_DynamicQObject*)tx1)->parent()));
return (int)((DhQIODevice*)tx0)->DvheventFilter((QObject*)tx1, (QEvent*)x2);
}
QTCEXPORT(int,qtc_QIODevice_receivers)(void* x0, wchar_t* x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
QString tx1(from_method(x1));
QByteArray txa1(tx1.toAscii());
return (int)((DhQIODevice*)tx0)->Dhreceivers(txa1.data());
}
QTCEXPORT(void*,qtc_QIODevice_sender)(void* x0) {
QObject*tx0 = *((QPointer<QObject>*)x0);
QObject * tc = (QObject*)(((DhQIODevice*)tx0)->Dhsender());
QPointer<QObject> * ttc = new QPointer<QObject>(tc);
return (void*)(ttc);
}
QTCEXPORT(void,qtc_QIODevice_timerEvent)(void* x0, void* x1) {
QObject*tx0 = *((QPointer<QObject>*)x0);
if ((tx0!=NULL)&&((QObject *)tx0)->property(QTC_PROP).isValid()) tx0 = ((QObject*)(((qtc_DynamicQObject*)tx0)->parent()));
((DhQIODevice*)tx0)->DhtimerEvent((QTimerEvent*)x1);
}
QTCEXPORT(void, qtc_QIODevice_userMethod)(void * evt_obj, int evt_typ) {
QObject * te = *((QPointer<QObject>*)evt_obj);
if (((QObject *)te)->property(QTC_PROP).isValid()) te = (((qtc_DynamicQObject *)te)->parent());
((DhQIODevice*)te)->userDefined(evt_typ);
}
QTCEXPORT(void*, qtc_QIODevice_userMethodVariant)(void * evt_obj, int evt_typ, void * xv) {
QObject * te = *((QPointer<QObject>*)evt_obj);
if (((QObject *)te)->property(QTC_PROP).isValid()) te = (((qtc_DynamicQObject *)te)->parent());
return (void*)(((DhQIODevice*)te)->userDefinedVariant(evt_typ, (QVariant*)xv));
}
QTCEXPORT(int, qtc_QIODevice_setUserMethod)(void * evt_obj, int evt_typ, void * rf_ptr, void * st_ptr, void * df_ptr) {
QObject * te = *((QPointer<QObject>*)evt_obj);
QObject * tr = te;
if (((QObject *)te)->property(QTC_PROP).isValid()) te = (((qtc_DynamicQObject *)te)->parent());
QPointer<QObject> * ttr = new QPointer<QObject>(tr);
return (int) ((DhQIODevice*)te)->setDynamicQHandlerud(0, (void*)ttr, evt_typ, rf_ptr, st_ptr, df_ptr);
}
QTCEXPORT(int, qtc_QIODevice_setUserMethodVariant)(void * evt_obj, int evt_typ, void * rf_ptr, void * st_ptr, void * df_ptr) {
QObject * te = *((QPointer<QObject>*)evt_obj);
QObject * tr = te;
if (((QObject *)te)->property(QTC_PROP).isValid()) te = (((qtc_DynamicQObject *)te)->parent());
QPointer<QObject> * ttr = new QPointer<QObject>(tr);
return (int) ((DhQIODevice*)te)->setDynamicQHandlerud(1, (void*)ttr, evt_typ, rf_ptr, st_ptr, df_ptr);
}
QTCEXPORT(int, qtc_QIODevice_unSetUserMethod)(void * evt_obj, int udm_typ, int evt_typ) {
QObject * te = *((QPointer<QObject>*)evt_obj);
if (((QObject *)te)->property(QTC_PROP).isValid()) te = (((qtc_DynamicQObject *)te)->parent());
return (int) ((DhQIODevice*)te)->unSetDynamicQHandlerud(udm_typ, evt_typ);
}
QTCEXPORT(int, qtc_QIODevice_setHandler)(void * evt_obj, wchar_t * evt_typ, void * rf_ptr, void * st_ptr, void * df_ptr) {
QObject * te = *((QPointer<QObject>*)evt_obj);
QObject * tr = te;
if (((QObject *)te)->property(QTC_PROP).isValid()) te = (((qtc_DynamicQObject *)te)->parent());
QString tq_evt(from_method((wchar_t *)evt_typ));
QByteArray tqba_evt(tq_evt.toAscii());
QPointer<QObject> * ttr = new QPointer<QObject>(tr);
return (int) ((DhQIODevice*)te)->setDynamicQHandler((void*)ttr, tqba_evt.data(), rf_ptr, st_ptr, df_ptr);
}
QTCEXPORT(int, qtc_QIODevice_unSetHandler)(void * evt_obj, wchar_t * evt_typ) {
QObject * te = *((QPointer<QObject>*)evt_obj);
if (((QObject *)te)->property(QTC_PROP).isValid()) te = (((qtc_DynamicQObject *)te)->parent());
QString tq_evt(from_method((wchar_t *)evt_typ));
QByteArray tqba_evt(tq_evt.toAscii());
return (int) ((DhQIODevice*)te)->unSetDynamicQHandler(tqba_evt.data());
}
QTCEXPORT(int, qtc_QIODevice_setHandler1)(void * evt_obj, wchar_t * evt_typ, void * rf_ptr, void * st_ptr, void * df_ptr) {
return (int) qtc_QIODevice_setHandler(evt_obj, evt_typ, rf_ptr, st_ptr, df_ptr);
}
QTCEXPORT(int, qtc_QIODevice_setHandler2)(void * evt_obj, wchar_t * evt_typ, void * rf_ptr, void * st_ptr, void * df_ptr) {
return (int) qtc_QIODevice_setHandler(evt_obj, evt_typ, rf_ptr, st_ptr, df_ptr);
}
QTCEXPORT(int, qtc_QIODevice_setHandler3)(void * evt_obj, wchar_t * evt_typ, void * rf_ptr, void * st_ptr, void * df_ptr) {
return (int) qtc_QIODevice_setHandler(evt_obj, evt_typ, rf_ptr, st_ptr, df_ptr);
}
QTCEXPORT(int, qtc_QIODevice_setHandler4)(void * evt_obj, wchar_t * evt_typ, void * rf_ptr, void * st_ptr, void * df_ptr) {
return (int) qtc_QIODevice_setHandler(evt_obj, evt_typ, rf_ptr, st_ptr, df_ptr);
}
QTCEXPORT(int, qtc_QIODevice_setHandler5)(void * evt_obj, wchar_t * evt_typ, void * rf_ptr, void * st_ptr, void * df_ptr) {
return (int) qtc_QIODevice_setHandler(evt_obj, evt_typ, rf_ptr, st_ptr, df_ptr);
}
QTCEXPORT(int, qtc_QIODevice_setHandler6)(void * evt_obj, wchar_t * evt_typ, void * rf_ptr, void * st_ptr, void * df_ptr) {
return (int) qtc_QIODevice_setHandler(evt_obj, evt_typ, rf_ptr, st_ptr, df_ptr);
}
QTCEXPORT(int, qtc_QIODevice_setHandler7)(void * evt_obj, wchar_t * evt_typ, void * rf_ptr, void * st_ptr, void * df_ptr) {
return (int) qtc_QIODevice_setHandler(evt_obj, evt_typ, rf_ptr, st_ptr, df_ptr);
}
QTCEXPORT(int, qtc_QIODevice_setHandler8)(void * evt_obj, wchar_t * evt_typ, void * rf_ptr, void * st_ptr, void * df_ptr) {
return (int) qtc_QIODevice_setHandler(evt_obj, evt_typ, rf_ptr, st_ptr, df_ptr);
}
}
|
;***
;sehprolog.asm - defines __SEH_prolog and __SEH_epilog
;
; Copyright (c) 1994-2001, Microsoft Corporation. All rights reserved.
;
;Purpose:
; SEH prolog/epilog helper function. Sets up the frame for a function
; with SEH try block.
;
;Revision History:
; 03-28-2000 LL Module created.
; 10-17-2001 PML VS7#313643 Don't set FS:0 until frame set up
;
;*******************************************************************************
title sehprolog.asm
.386P
.model FLAT
ASSUME FS: FLAT
PUBLIC __SEH_prolog
PUBLIC __SEH_epilog
EXTRN __except_handler3:DWORD
_TEXT SEGMENT
; First argument: local frame size
; Second argument: address of SEH try table
__SEH_prolog PROC NEAR
push OFFSET FLAT:__except_handler3 ; push address of SEH handler
mov eax, DWORD PTR fs:0
push eax ; push previous except list head
mov eax, DWORD PTR [esp+16] ; load frame size
mov DWORD PTR [esp+16], ebp ; save off EBP
lea ebp, [esp+16] ; setup base pointer
sub esp, eax ; allocate frame
push ebx ; push callee save regs
push esi
push edi
mov eax, DWORD PTR [ebp-8] ; load return address
mov DWORD PTR [ebp-24], esp ; save off ESP in except record
push eax ; push back return address
mov eax, DWORD PTR [ebp-4] ; load SEH table address
mov DWORD PTR [ebp-4], -1 ; initialize SEH state index
mov DWORD PTR [ebp-8], eax ; Move SEH table addr to the right place
lea eax, [ebp-16] ; link this node to except list
mov DWORD PTR fs:0, eax
ret 0
__SEH_prolog ENDP
__SEH_epilog PROC NEAR
mov ecx, DWORD PTR [ebp-16] ; unlink from except list
mov DWORD PTR fs:0, ecx
pop ecx ; pop return address
pop edi ; pop callee save regs
pop esi
pop ebx
leave
push ecx ; push back return address
ret 0
__SEH_epilog ENDP
_TEXT ENDS
END
|
.global s_prepare_buffers
s_prepare_buffers:
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r13
push %r15
push %r8
push %r9
push %rbp
push %rcx
push %rdi
push %rdx
push %rsi
// Load
lea addresses_PSE+0x1c254, %r9
nop
nop
nop
nop
and $11930, %r13
movb (%r9), %r8b
add $31127, %r13
// Load
lea addresses_A+0x7a54, %rdx
nop
nop
nop
nop
dec %r15
mov (%rdx), %ebp
xor $12691, %r10
// REPMOV
lea addresses_A+0xe054, %rsi
lea addresses_A+0xb254, %rdi
nop
nop
sub %r8, %r8
mov $36, %rcx
rep movsq
nop
nop
nop
add %rcx, %rcx
// Faulty Load
lea addresses_US+0x1254, %r15
nop
nop
nop
nop
nop
xor $206, %r9
mov (%r15), %si
lea oracles, %rdx
and $0xff, %rsi
shlq $12, %rsi
mov (%rdx,%rsi,1), %rsi
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbp
pop %r9
pop %r8
pop %r15
pop %r13
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_US', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 0}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_PSE', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 11}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_A', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 10}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 8, 'type': 'addresses_A'}, 'dst': {'same': False, 'congruent': 10, 'type': 'addresses_A'}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_US', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 0}}
<gen_prepare_buffer>
{'00': 15}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
; graphics.asm - An pure 32-bit and 64-bit win32 assembly GDI+ program
; Made by Bastiaan van der Plaat (https://bastiaan.ml/)
; 32-bit: nasm -f bin graphics.asm -o graphics-x86.exe && ./graphics-x86
; 64-bit: nasm -DWIN64 -f bin graphics.asm -o graphics-x64.exe && ./graphics-x64
; Because the flat GDI+ API gives antialiased drawing methods
; This program uses SSE floating point extentions: this is mandatory for x86-64
; but can crash an 32-bit program on a realy old processor
%include "libwindows.inc"
header
code_section
; ### Some stdlib like Win32 wrappers ###
function malloc, size
invoke GetProcessHeap
invoke HeapAlloc, _ax, 0, [size]
return
function free, ptr
invoke GetProcessHeap
invoke HeapFree, _ax, 0, [ptr]
return
function srand, seed
mov eax, [seed]
mov [rand_seed], eax
return
function rand
imul eax, [rand_seed], 1103515245
add eax, 12345
xor edx, edx
mov ecx, 1 << 31
idiv ecx
mov [rand_seed], edx
return _dx
; ### Window code ###
struct WindowData, \
background_color, DWORD_size
; Window procedure function
function WindowProc, hwnd, uMsg, wParam, lParam
mov eax, [uMsg]
cmp eax, WM_CREATE
je .wm_create
cmp eax, WM_SIZE
je .wm_size
cmp eax, WM_GETMINMAXINFO
je .wm_getminmaxinfo
cmp eax, WM_ERASEBKGND
je .wm_erasebkgnd
cmp eax, WM_PAINT
je .wm_paint
cmp eax, WM_DESTROY
je .wm_destroy
jmp .default
.wm_create:
local window_data, POINTER_size, \
time, SYSTEMTIME_size, \
window_rect, RECT_size, \
new_window_rect, Rect_size
; Create window data
fcall malloc, WindowData_size
mov [window_data], _ax
invoke SetWindowLongPtrA, [hwnd], GWLP_USERDATA, _ax
; Generate random seed by time
invoke GetLocalTime, addr time
movzx eax, word [time + SYSTEMTIME.wHour]
imul eax, 60
movzx ecx, word [time + SYSTEMTIME.wMinute]
add eax, ecx
imul eax, 60
movzx ecx, word [time + SYSTEMTIME.wSecond]
add eax, ecx
fcall srand, _ax
; Generate random background color
fcall rand
and eax, 0x007f7f7f
or eax, 0xff000000
mov _di, [window_data]
mov [_di + WindowData.background_color], eax
; Center window
invoke GetClientRect, [hwnd], addr window_rect
mov eax, [window_width]
shl eax, 1
sub eax, [window_rect + RECT.right]
mov [new_window_rect + Rect.width], eax
mov eax, [window_height]
shl eax, 1
sub eax, [window_rect + RECT.bottom]
mov [new_window_rect + Rect.height], eax
invoke GetSystemMetrics, SM_CXSCREEN
sub eax, [new_window_rect + Rect.width]
shr eax, 1
mov [new_window_rect + Rect.x], eax
invoke GetSystemMetrics, SM_CYSCREEN
sub eax, [new_window_rect + Rect.height]
shr eax, 1
mov [new_window_rect + Rect.y], eax
invoke SetWindowPos, [hwnd], HWND_TOP, [new_window_rect + Rect.x], [new_window_rect + Rect.y], [new_window_rect + Rect.width], [new_window_rect + Rect.height], SWP_NOZORDER
end_local
return 0
%undef window_data
.wm_size:
; Save new window size
movzx eax, word [lParam]
mov [window_width], eax
mov eax, [lParam]
shr eax, 16
mov [window_height], eax
return 0
.wm_getminmaxinfo:
; Set window min size
mov _di, [lParam]
mov dword [_di + MINMAXINFO.ptMinTrackSize + POINT.x], 320
mov dword [_di + MINMAXINFO.ptMinTrackSize + POINT.y], 240
return 0
.wm_erasebkgnd:
; Draw no background
return TRUE
.wm_paint:
; Draw stuff in the window via GDI+
local window_data, POINTER_size, \
paint_struct, PAINTSTRUCT_size, \
hdc_buffer, POINTER_size, \
bitmap_buffer, POINTER_size, \
graphics, POINTER_size, \
\
line_width, DWORD_size, \
pen, POINTER_size, \
items_rect, Rect_size, \
\
font_family, POINTER_size, \
font_size, DWORD_size, \
font, POINTER_size, \
text_brush, POINTER_size, \
string_format, POINTER_size, \
text_rect, Rect_size, \
text_buffer, 64
; Get window data
invoke GetWindowLongPtrA, [hwnd], GWLP_USERDATA
mov [window_data], _ax
; Begin paint
invoke BeginPaint, [hwnd], addr paint_struct
; Create back buffer
invoke CreateCompatibleDC, [paint_struct + PAINTSTRUCT.hdc]
mov [hdc_buffer], _ax
invoke CreateCompatibleBitmap, [paint_struct + PAINTSTRUCT.hdc], [window_width], [window_height]
mov [bitmap_buffer], _ax
invoke SelectObject, [hdc_buffer], [bitmap_buffer]
; Create graphics object
invoke GdipCreateFromHDC, [hdc_buffer], addr graphics
; Enable anti aliasing
invoke GdipSetSmoothingMode, [graphics], SmoothingModeAntiAlias
invoke GdipSetTextRenderingHint, [graphics], TextRenderingHintClearTypeGridFit
; Clear screen with window background color
mov _si, [window_data]
invoke GdipGraphicsClear, [graphics], [_si + WindowData.background_color]
; Create pen object
mov eax, 3
cvtsi2ss xmm0, eax
movss [line_width], xmm0
invoke GdipCreatePen1, 0xffffffff, float [line_width], UnitPixel, addr pen
; Draw a cross with lines
invoke GdipDrawLineI, [graphics], [pen], 0, 0, [window_width], [window_height]
invoke GdipDrawLineI, [graphics], [pen], [window_width], 0, 0, [window_height]
; Calculate items rect
mov eax, [window_width]
shr eax, 2
mov [items_rect + Rect.x], eax
mov eax, [window_height]
shr eax, 2
mov [items_rect + Rect.y], eax
mov eax, [window_width]
shr eax, 1
mov [items_rect + Rect.width], eax
mov eax, [window_height]
shr eax, 1
mov [items_rect + Rect.height], eax
; Draw a circle and a rect in the middle with items rect
invoke GdipDrawEllipseI, [graphics], [pen], [items_rect + Rect.x], [items_rect + Rect.y], [items_rect + Rect.width], [items_rect + Rect.height]
invoke GdipDrawRectangleI, [graphics], [pen], [items_rect + Rect.x], [items_rect + Rect.y], [items_rect + Rect.width], [items_rect + Rect.height]
; Calculate font size by window width
mov eax, [window_width]
cvtsi2ss xmm0, eax
mov eax, 30
cvtsi2ss xmm1, eax
divss xmm0, xmm1
movss [font_size], xmm0
; Create font object
invoke GdipCreateFontFamilyFromName, font_name, NULL, addr font_family
invoke GdipCreateFont, [font_family], float [font_size], FontStyleRegular, UnitPixel, addr font
; Create text solid fill brush object
invoke GdipCreateSolidFill, 0xffffffff, addr text_brush
; Create centered string format object
invoke GdipStringFormatGetGenericDefault, addr string_format
invoke GdipSetStringFormatAlign, [string_format], StringAlignmentCenter
; Calculate text_rect
mov eax, [window_width]
cvtsi2ss xmm0, eax
movss [text_rect + Rect.width], xmm0
movss xmm1, [font_size]
mov eax, 2
cvtsi2ss xmm2, eax
mulss xmm1, xmm2
movss [text_rect + Rect.height], xmm1
xor eax, eax
cvtsi2ss xmm0, eax
movss [text_rect + Rect.x], xmm0
mov eax, [window_height]
cvtsi2ss xmm0, eax
subss xmm0, xmm1
movss [text_rect + Rect.y], xmm0
; Generate window size string
cinvoke wsprintfW, addr text_buffer, window_size_format, [window_width], [window_height]
; Draw window size text
invoke GdipDrawString, [graphics], addr text_buffer, -1, [font], addr text_rect, [string_format], [text_brush]
; Delete the GDI+ objects
invoke GdipDeleteStringFormat, [string_format]
invoke GdipDeleteBrush, [text_brush]
invoke GdipDeleteFont, [font]
invoke GdipDeleteFontFamily, [font_family]
invoke GdipDeletePen, [pen]
invoke GdipDeleteGraphics, [graphics]
; Draw and delete back buffer
invoke BitBlt, [paint_struct + PAINTSTRUCT.hdc], 0, 0, [window_width], [window_height], [hdc_buffer], 0, 0, SRCCOPY
invoke DeleteObject, [bitmap_buffer]
invoke DeleteDC, [hdc_buffer]
; End paint
invoke EndPaint, [hwnd], addr paint_struct
end_local
return 0
.wm_destroy:
; Free window data
invoke GetWindowLongPtrA, [hwnd], GWLP_USERDATA
fcall free, _ax
; Close process
invoke PostQuitMessage, 0
return 0
.default:
invoke DefWindowProcA, [hwnd], [uMsg], [wParam], [lParam]
return
%undef hwnd
; Main entry point
entrypoint
local gdiplusToken, DWORD_size, \
gdiplusStartupInput, GdiplusStartupInput_size, \
window_class, WNDCLASSEX_size, \
hwnd, POINTER_size, \
message, MSG_size
; Startup GDI+
mov dword [gdiplusStartupInput + GdiplusStartupInput.GdiplusVersion], 1
mov pointer [gdiplusStartupInput + GdiplusStartupInput.DebugEventCallback], NULL
mov dword [gdiplusStartupInput + GdiplusStartupInput.SuppressBackgroundThread], FALSE
mov dword [gdiplusStartupInput + GdiplusStartupInput.SuppressExternalCodecs], FALSE
invoke GdiplusStartup, addr gdiplusToken, addr gdiplusStartupInput, NULL
; Register the window class
mov dword [window_class + WNDCLASSEX.cbSize], WNDCLASSEX_size
mov dword [window_class + WNDCLASSEX.style], CS_HREDRAW | CS_VREDRAW
mov pointer [window_class + WNDCLASSEX.lpfnWndProc], WindowProc
mov dword [window_class + WNDCLASSEX.cbClsExtra], 0
mov dword [window_class + WNDCLASSEX.cbWndExtra], 0
invoke GetModuleHandleA, NULL
mov [window_class + WNDCLASSEX.hInstance], _ax
invoke LoadIconA, NULL, IDI_APPLICATION
mov [window_class + WNDCLASSEX.hIcon], _ax
mov [window_class + WNDCLASSEX.hIconSm], _ax
invoke LoadCursorA, NULL, IDC_ARROW
mov [window_class + WNDCLASSEX.hCursor], _ax
mov pointer [window_class + WNDCLASSEX.hbrBackground], NULL
mov pointer [window_class + WNDCLASSEX.lpszMenuName], NULL
mov pointer [window_class + WNDCLASSEX.lpszClassName], window_class_name
invoke RegisterClassExA, addr window_class
; Create the window
invoke CreateWindowExA, 0, window_class_name, window_title, WS_OVERLAPPEDWINDOW, \
CW_USEDEFAULT, CW_USEDEFAULT, [window_width], [window_height], \
HWND_DESKTOP, NULL, [window_class + WNDCLASSEX.hInstance], NULL
mov [hwnd], _ax
invoke ShowWindow, [hwnd], SW_SHOWDEFAULT
invoke UpdateWindow, [hwnd]
; Message loop
loop
invoke GetMessageA, addr message, NULL, 0, 0
test _ax, _ax
jle %$end_loop
invoke TranslateMessage, addr message
invoke DispatchMessageA, addr message
end_loop
; Shutdown GDI+
invoke GdiplusShutdown, [gdiplusToken]
invoke ExitProcess, [message + MSG.wParam]
end_local
end_code_section
data_section
; String constants
window_class_name db "graphics-test", 0
%ifdef WIN64
window_title db "This is a test GDI+ window (64-bit)", 0
%else
window_title db "This is a test GDI+ window (32-bit)", 0
%endif
font_name dw utf16("Tahoma"), 0
window_size_format dw utf16("(%d x %d)"), 0
; Global variables
rand_seed dd 0
window_width dd 1280
window_height dd 720
; Import table
import_table
library gdi_table, "GDI32.DLL", \
gdiplus_table, "gdiplus.dll", \
kernel_table, "KERNEL32.DLL", \
user_table, "USER32.DLL"
import gdi_table, \
BitBlt, "BitBlt", \
CreateCompatibleBitmap, "CreateCompatibleBitmap", \
CreateCompatibleDC, "CreateCompatibleDC", \
DeleteDC, "DeleteDC", \
DeleteObject, "DeleteObject", \
SelectObject, "SelectObject"
import gdiplus_table, \
GdipCreateFont, "GdipCreateFont", \
GdipCreateFontFamilyFromName, "GdipCreateFontFamilyFromName", \
GdipCreateFromHDC, "GdipCreateFromHDC", \
GdipCreatePen1, "GdipCreatePen1", \
GdipCreateSolidFill, "GdipCreateSolidFill", \
GdipDeleteBrush, "GdipDeleteBrush", \
GdipDeleteFont, "GdipDeleteFont", \
GdipDeleteFontFamily, "GdipDeleteFontFamily", \
GdipDeleteGraphics, "GdipDeleteGraphics", \
GdipDeletePen, "GdipDeletePen", \
GdipDeleteStringFormat, "GdipDeleteStringFormat", \
GdipDrawEllipseI, "GdipDrawEllipseI", \
GdipDrawLineI, "GdipDrawLineI", \
GdipDrawRectangleI, "GdipDrawRectangleI", \
GdipDrawString, "GdipDrawString", \
GdipGraphicsClear, "GdipGraphicsClear", \
GdipSetSmoothingMode, "GdipSetSmoothingMode", \
GdipSetStringFormatAlign, "GdipSetStringFormatAlign", \
GdipStringFormatGetGenericDefault, "GdipStringFormatGetGenericDefault", \
GdipSetTextRenderingHint, "GdipSetTextRenderingHint", \
GdiplusShutdown, "GdiplusShutdown", \
GdiplusStartup, "GdiplusStartup"
import kernel_table, \
ExitProcess, "ExitProcess", \
GetLocalTime, "GetLocalTime", \
GetModuleHandleA, "GetModuleHandleA", \
GetProcessHeap, "GetProcessHeap", \
HeapAlloc, "HeapAlloc", \
HeapFree, "HeapFree"
import user_table, \
BeginPaint, "BeginPaint", \
CreateWindowExA, "CreateWindowExA", \
DefWindowProcA, "DefWindowProcA", \
DispatchMessageA, "DispatchMessageA", \
EndPaint, "EndPaint", \
GetClientRect, "GetClientRect", \
GetMessageA, "GetMessageA", \
GetSystemMetrics, "GetSystemMetrics", \
GetWindowLongPtrA, GetWindowLongPtrAString, \
LoadCursorA, "LoadCursorA", \
LoadIconA, "LoadIconA", \
PostQuitMessage, "PostQuitMessage", \
RegisterClassExA, "RegisterClassExA", \
SetWindowLongPtrA, SetWindowLongPtrAString, \
SetWindowPos, "SetWindowPos", \
ShowWindow, "ShowWindow", \
TranslateMessage, "TranslateMessage", \
UpdateWindow, "UpdateWindow", \
wsprintfW, "wsprintfW"
end_import_table
end_data_section
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright(c) 2011-2016 Intel Corporation All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions
; are met:
; * Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; * Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in
; the documentation and/or other materials provided with the
; distribution.
; * Neither the name of Intel Corporation nor the names of its
; contributors may be used to endorse or promote products derived
; from this software without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Function API:
; uint64_t crc64_iso_norm_by8(
; uint64_t init_crc, //initial CRC value, 64 bits
; const unsigned char *buf, //buffer pointer to calculate CRC on
; uint64_t len //buffer length in bytes (64-bit data)
; );
;
%include "reg_sizes.asm"
%define fetch_dist 1024
[bits 64]
default rel
section .text
%ifidn __OUTPUT_FORMAT__, win64
%xdefine arg1 rcx
%xdefine arg2 rdx
%xdefine arg3 r8
%else
%xdefine arg1 rdi
%xdefine arg2 rsi
%xdefine arg3 rdx
%endif
%define TMP 16*0
%ifidn __OUTPUT_FORMAT__, win64
%define XMM_SAVE 16*2
%define VARIABLE_OFFSET 16*10+8
%else
%define VARIABLE_OFFSET 16*2+8
%endif
align 16
global crc64_iso_norm_by8:function
crc64_iso_norm_by8:
not arg1 ;~init_crc
sub rsp,VARIABLE_OFFSET
%ifidn __OUTPUT_FORMAT__, win64
; push the xmm registers into the stack to maintain
movdqa [rsp + XMM_SAVE + 16*0], xmm6
movdqa [rsp + XMM_SAVE + 16*1], xmm7
movdqa [rsp + XMM_SAVE + 16*2], xmm8
movdqa [rsp + XMM_SAVE + 16*3], xmm9
movdqa [rsp + XMM_SAVE + 16*4], xmm10
movdqa [rsp + XMM_SAVE + 16*5], xmm11
movdqa [rsp + XMM_SAVE + 16*6], xmm12
movdqa [rsp + XMM_SAVE + 16*7], xmm13
%endif
; check if smaller than 256
cmp arg3, 256
; for sizes less than 256, we can't fold 128B at a time...
jl _less_than_256
; load the initial crc value
movq xmm10, arg1 ; initial crc
; crc value does not need to be byte-reflected, but it needs to be moved to the high part of the register.
; because data will be byte-reflected and will align with initial crc at correct place.
pslldq xmm10, 8
movdqa xmm11, [SHUF_MASK]
; receive the initial 128B data, xor the initial crc value
movdqu xmm0, [arg2+16*0]
movdqu xmm1, [arg2+16*1]
movdqu xmm2, [arg2+16*2]
movdqu xmm3, [arg2+16*3]
movdqu xmm4, [arg2+16*4]
movdqu xmm5, [arg2+16*5]
movdqu xmm6, [arg2+16*6]
movdqu xmm7, [arg2+16*7]
pshufb xmm0, xmm11
; XOR the initial_crc value
pxor xmm0, xmm10
pshufb xmm1, xmm11
pshufb xmm2, xmm11
pshufb xmm3, xmm11
pshufb xmm4, xmm11
pshufb xmm5, xmm11
pshufb xmm6, xmm11
pshufb xmm7, xmm11
movdqa xmm10, [rk3] ;xmm10 has rk3 and rk4
;imm value of pclmulqdq instruction will determine which constant to use
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; we subtract 256 instead of 128 to save one instruction from the loop
sub arg3, 256
; at this section of the code, there is 128*x+y (0<=y<128) bytes of buffer. The _fold_128_B_loop
; loop will fold 128B at a time until we have 128+y Bytes of buffer
; fold 128B at a time. This section of the code folds 8 xmm registers in parallel
_fold_128_B_loop:
; update the buffer pointer
add arg2, 128 ; buf += 128;
prefetchnta [arg2+fetch_dist+0]
movdqu xmm9, [arg2+16*0]
movdqu xmm12, [arg2+16*1]
pshufb xmm9, xmm11
pshufb xmm12, xmm11
movdqa xmm8, xmm0
movdqa xmm13, xmm1
pclmulqdq xmm0, xmm10, 0x0
pclmulqdq xmm8, xmm10 , 0x11
pclmulqdq xmm1, xmm10, 0x0
pclmulqdq xmm13, xmm10 , 0x11
pxor xmm0, xmm9
xorps xmm0, xmm8
pxor xmm1, xmm12
xorps xmm1, xmm13
prefetchnta [arg2+fetch_dist+32]
movdqu xmm9, [arg2+16*2]
movdqu xmm12, [arg2+16*3]
pshufb xmm9, xmm11
pshufb xmm12, xmm11
movdqa xmm8, xmm2
movdqa xmm13, xmm3
pclmulqdq xmm2, xmm10, 0x0
pclmulqdq xmm8, xmm10 , 0x11
pclmulqdq xmm3, xmm10, 0x0
pclmulqdq xmm13, xmm10 , 0x11
pxor xmm2, xmm9
xorps xmm2, xmm8
pxor xmm3, xmm12
xorps xmm3, xmm13
prefetchnta [arg2+fetch_dist+64]
movdqu xmm9, [arg2+16*4]
movdqu xmm12, [arg2+16*5]
pshufb xmm9, xmm11
pshufb xmm12, xmm11
movdqa xmm8, xmm4
movdqa xmm13, xmm5
pclmulqdq xmm4, xmm10, 0x0
pclmulqdq xmm8, xmm10 , 0x11
pclmulqdq xmm5, xmm10, 0x0
pclmulqdq xmm13, xmm10 , 0x11
pxor xmm4, xmm9
xorps xmm4, xmm8
pxor xmm5, xmm12
xorps xmm5, xmm13
prefetchnta [arg2+fetch_dist+96]
movdqu xmm9, [arg2+16*6]
movdqu xmm12, [arg2+16*7]
pshufb xmm9, xmm11
pshufb xmm12, xmm11
movdqa xmm8, xmm6
movdqa xmm13, xmm7
pclmulqdq xmm6, xmm10, 0x0
pclmulqdq xmm8, xmm10 , 0x11
pclmulqdq xmm7, xmm10, 0x0
pclmulqdq xmm13, xmm10 , 0x11
pxor xmm6, xmm9
xorps xmm6, xmm8
pxor xmm7, xmm12
xorps xmm7, xmm13
sub arg3, 128
; check if there is another 128B in the buffer to be able to fold
jge _fold_128_B_loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
add arg2, 128
; at this point, the buffer pointer is pointing at the last y Bytes of the buffer, where 0 <= y < 128
; the 128B of folded data is in 8 of the xmm registers: xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7
; fold the 8 xmm registers to 1 xmm register with different constants
movdqa xmm10, [rk9]
movdqa xmm8, xmm0
pclmulqdq xmm0, xmm10, 0x11
pclmulqdq xmm8, xmm10, 0x0
pxor xmm7, xmm8
xorps xmm7, xmm0
movdqa xmm10, [rk11]
movdqa xmm8, xmm1
pclmulqdq xmm1, xmm10, 0x11
pclmulqdq xmm8, xmm10, 0x0
pxor xmm7, xmm8
xorps xmm7, xmm1
movdqa xmm10, [rk13]
movdqa xmm8, xmm2
pclmulqdq xmm2, xmm10, 0x11
pclmulqdq xmm8, xmm10, 0x0
pxor xmm7, xmm8
pxor xmm7, xmm2
movdqa xmm10, [rk15]
movdqa xmm8, xmm3
pclmulqdq xmm3, xmm10, 0x11
pclmulqdq xmm8, xmm10, 0x0
pxor xmm7, xmm8
xorps xmm7, xmm3
movdqa xmm10, [rk17]
movdqa xmm8, xmm4
pclmulqdq xmm4, xmm10, 0x11
pclmulqdq xmm8, xmm10, 0x0
pxor xmm7, xmm8
pxor xmm7, xmm4
movdqa xmm10, [rk19]
movdqa xmm8, xmm5
pclmulqdq xmm5, xmm10, 0x11
pclmulqdq xmm8, xmm10, 0x0
pxor xmm7, xmm8
xorps xmm7, xmm5
movdqa xmm10, [rk1] ;xmm10 has rk1 and rk2
movdqa xmm8, xmm6
pclmulqdq xmm6, xmm10, 0x11
pclmulqdq xmm8, xmm10, 0x0
pxor xmm7, xmm8
pxor xmm7, xmm6
; instead of 128, we add 112 to the loop counter to save 1 instruction from the loop
; instead of a cmp instruction, we use the negative flag with the jl instruction
add arg3, 128-16
jl _final_reduction_for_128
; now we have 16+y bytes left to reduce. 16 Bytes is in register xmm7 and the rest is in memory
; we can fold 16 bytes at a time if y>=16
; continue folding 16B at a time
_16B_reduction_loop:
movdqa xmm8, xmm7
pclmulqdq xmm7, xmm10, 0x11
pclmulqdq xmm8, xmm10, 0x0
pxor xmm7, xmm8
movdqu xmm0, [arg2]
pshufb xmm0, xmm11
pxor xmm7, xmm0
add arg2, 16
sub arg3, 16
; instead of a cmp instruction, we utilize the flags with the jge instruction
; equivalent of: cmp arg3, 16-16
; check if there is any more 16B in the buffer to be able to fold
jge _16B_reduction_loop
;now we have 16+z bytes left to reduce, where 0<= z < 16.
;first, we reduce the data in the xmm7 register
_final_reduction_for_128:
; check if any more data to fold. If not, compute the CRC of the final 128 bits
add arg3, 16
je _128_done
; here we are getting data that is less than 16 bytes.
; since we know that there was data before the pointer, we can offset the input pointer before the actual point, to receive exactly 16 bytes.
; after that the registers need to be adjusted.
_get_last_two_xmms:
movdqa xmm2, xmm7
movdqu xmm1, [arg2 - 16 + arg3]
pshufb xmm1, xmm11
; get rid of the extra data that was loaded before
; load the shift constant
lea rax, [pshufb_shf_table + 16]
sub rax, arg3
movdqu xmm0, [rax]
; shift xmm2 to the left by arg3 bytes
pshufb xmm2, xmm0
; shift xmm7 to the right by 16-arg3 bytes
pxor xmm0, [mask1]
pshufb xmm7, xmm0
pblendvb xmm1, xmm2 ;xmm0 is implicit
; fold 16 Bytes
movdqa xmm2, xmm1
movdqa xmm8, xmm7
pclmulqdq xmm7, xmm10, 0x11
pclmulqdq xmm8, xmm10, 0x0
pxor xmm7, xmm8
pxor xmm7, xmm2
_128_done:
; compute crc of a 128-bit value
movdqa xmm10, [rk5] ; rk5 and rk6 in xmm10
movdqa xmm0, xmm7
;64b fold
pclmulqdq xmm7, xmm10, 0x01 ; H*L
pslldq xmm0, 8
pxor xmm7, xmm0
;barrett reduction
_barrett:
movdqa xmm10, [rk7] ; rk7 and rk8 in xmm10
movdqa xmm0, xmm7
movdqa xmm1, xmm7
pand xmm1, [mask3]
pclmulqdq xmm7, xmm10, 0x01
pxor xmm7, xmm1
pclmulqdq xmm7, xmm10, 0x11
pxor xmm7, xmm0
pextrq rax, xmm7, 0
_cleanup:
not rax
%ifidn __OUTPUT_FORMAT__, win64
movdqa xmm6, [rsp + XMM_SAVE + 16*0]
movdqa xmm7, [rsp + XMM_SAVE + 16*1]
movdqa xmm8, [rsp + XMM_SAVE + 16*2]
movdqa xmm9, [rsp + XMM_SAVE + 16*3]
movdqa xmm10, [rsp + XMM_SAVE + 16*4]
movdqa xmm11, [rsp + XMM_SAVE + 16*5]
movdqa xmm12, [rsp + XMM_SAVE + 16*6]
movdqa xmm13, [rsp + XMM_SAVE + 16*7]
%endif
add rsp, VARIABLE_OFFSET
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
align 16
_less_than_256:
; check if there is enough buffer to be able to fold 16B at a time
cmp arg3, 32
jl _less_than_32
movdqa xmm11, [SHUF_MASK]
; if there is, load the constants
movdqa xmm10, [rk1] ; rk1 and rk2 in xmm10
movq xmm0, arg1 ; get the initial crc value
pslldq xmm0, 8 ; align it to its correct place
movdqu xmm7, [arg2] ; load the plaintext
pshufb xmm7, xmm11 ; byte-reflect the plaintext
pxor xmm7, xmm0
; update the buffer pointer
add arg2, 16
; update the counter. subtract 32 instead of 16 to save one instruction from the loop
sub arg3, 32
jmp _16B_reduction_loop
align 16
_less_than_32:
; mov initial crc to the return value. this is necessary for zero-length buffers.
mov rax, arg1
test arg3, arg3
je _cleanup
movdqa xmm11, [SHUF_MASK]
movq xmm0, arg1 ; get the initial crc value
pslldq xmm0, 8 ; align it to its correct place
cmp arg3, 16
je _exact_16_left
jl _less_than_16_left
movdqu xmm7, [arg2] ; load the plaintext
pshufb xmm7, xmm11 ; byte-reflect the plaintext
pxor xmm7, xmm0 ; xor the initial crc value
add arg2, 16
sub arg3, 16
movdqa xmm10, [rk1] ; rk1 and rk2 in xmm10
jmp _get_last_two_xmms
align 16
_less_than_16_left:
; use stack space to load data less than 16 bytes, zero-out the 16B in memory first.
pxor xmm1, xmm1
mov r11, rsp
movdqa [r11], xmm1
; backup the counter value
mov r9, arg3
cmp arg3, 8
jl _less_than_8_left
; load 8 Bytes
mov rax, [arg2]
mov [r11], rax
add r11, 8
sub arg3, 8
add arg2, 8
_less_than_8_left:
cmp arg3, 4
jl _less_than_4_left
; load 4 Bytes
mov eax, [arg2]
mov [r11], eax
add r11, 4
sub arg3, 4
add arg2, 4
_less_than_4_left:
cmp arg3, 2
jl _less_than_2_left
; load 2 Bytes
mov ax, [arg2]
mov [r11], ax
add r11, 2
sub arg3, 2
add arg2, 2
_less_than_2_left:
cmp arg3, 1
jl _zero_left
; load 1 Byte
mov al, [arg2]
mov [r11], al
_zero_left:
movdqa xmm7, [rsp]
pshufb xmm7, xmm11
pxor xmm7, xmm0 ; xor the initial crc value
; shl r9, 4
lea rax, [pshufb_shf_table + 16]
sub rax, r9
cmp r9, 8
jl _end_1to7
_end_8to15:
movdqu xmm0, [rax]
pxor xmm0, [mask1]
pshufb xmm7, xmm0
jmp _128_done
_end_1to7:
; Right shift (8-length) bytes in XMM
add rax, 8
movdqu xmm0, [rax]
pshufb xmm7,xmm0
jmp _barrett
align 16
_exact_16_left:
movdqu xmm7, [arg2]
pshufb xmm7, xmm11
pxor xmm7, xmm0 ; xor the initial crc value
jmp _128_done
section .data
; precomputed constants
align 16
rk1:
DQ 0x0000000000000145
rk2:
DQ 0x0000000000001db7
rk3:
DQ 0x000100000001001a
rk4:
DQ 0x001b0000001b015e
rk5:
DQ 0x0000000000000145
rk6:
DQ 0x0000000000000000
rk7:
DQ 0x000000000000001b
rk8:
DQ 0x000000000000001b
rk9:
DQ 0x0150145145145015
rk10:
DQ 0x1c71db6db6db71c7
rk11:
DQ 0x0001110110110111
rk12:
DQ 0x001aab1ab1ab1aab
rk13:
DQ 0x0000014445014445
rk14:
DQ 0x00001daab71daab7
rk15:
DQ 0x0000000101000101
rk16:
DQ 0x0000001b1b001b1b
rk17:
DQ 0x0000000001514515
rk18:
DQ 0x000000001c6db6c7
rk19:
DQ 0x0000000000011011
rk20:
DQ 0x00000000001ab1ab
mask1:
dq 0x8080808080808080, 0x8080808080808080
mask2:
dq 0xFFFFFFFFFFFFFFFF, 0x00000000FFFFFFFF
mask3:
dq 0x0000000000000000, 0xFFFFFFFFFFFFFFFF
SHUF_MASK:
dq 0x08090A0B0C0D0E0F, 0x0001020304050607
pshufb_shf_table:
; use these values for shift constants for the pshufb instruction
; different alignments result in values as shown:
; dq 0x8887868584838281, 0x008f8e8d8c8b8a89 ; shl 15 (16-1) / shr1
; dq 0x8988878685848382, 0x01008f8e8d8c8b8a ; shl 14 (16-3) / shr2
; dq 0x8a89888786858483, 0x0201008f8e8d8c8b ; shl 13 (16-4) / shr3
; dq 0x8b8a898887868584, 0x030201008f8e8d8c ; shl 12 (16-4) / shr4
; dq 0x8c8b8a8988878685, 0x04030201008f8e8d ; shl 11 (16-5) / shr5
; dq 0x8d8c8b8a89888786, 0x0504030201008f8e ; shl 10 (16-6) / shr6
; dq 0x8e8d8c8b8a898887, 0x060504030201008f ; shl 9 (16-7) / shr7
; dq 0x8f8e8d8c8b8a8988, 0x0706050403020100 ; shl 8 (16-8) / shr8
; dq 0x008f8e8d8c8b8a89, 0x0807060504030201 ; shl 7 (16-9) / shr9
; dq 0x01008f8e8d8c8b8a, 0x0908070605040302 ; shl 6 (16-10) / shr10
; dq 0x0201008f8e8d8c8b, 0x0a09080706050403 ; shl 5 (16-11) / shr11
; dq 0x030201008f8e8d8c, 0x0b0a090807060504 ; shl 4 (16-12) / shr12
; dq 0x04030201008f8e8d, 0x0c0b0a0908070605 ; shl 3 (16-13) / shr13
; dq 0x0504030201008f8e, 0x0d0c0b0a09080706 ; shl 2 (16-14) / shr14
; dq 0x060504030201008f, 0x0e0d0c0b0a090807 ; shl 1 (16-15) / shr15
dq 0x8786858483828100, 0x8f8e8d8c8b8a8988
dq 0x0706050403020100, 0x0f0e0d0c0b0a0908
dq 0x8080808080808080, 0x0f0e0d0c0b0a0908
dq 0x8080808080808080, 0x8080808080808080
;;; func core, ver, snum
slversion crc64_iso_norm_by8, 01, 00, 0020
|
// Copyright 2008-present Contributors to the OpenImageIO project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/OpenImageIO/oiio/blob/master/LICENSE.md
#include "py_oiio.h"
#include <memory>
#include <OpenImageIO/platform.h>
namespace PyOpenImageIO {
py::tuple
ImageBuf_getpixel(const ImageBuf& buf, int x, int y, int z = 0,
const std::string& wrapname = "black")
{
ImageBuf::WrapMode wrap = ImageBuf::WrapMode_from_string(wrapname);
int nchans = buf.nchannels();
float* pixel = OIIO_ALLOCA(float, nchans);
buf.getpixel(x, y, z, pixel, nchans, wrap);
return C_to_tuple(pixel, nchans);
}
py::tuple
ImageBuf_interppixel(const ImageBuf& buf, float x, float y,
const std::string& wrapname = "black")
{
ImageBuf::WrapMode wrap = ImageBuf::WrapMode_from_string(wrapname);
int nchans = buf.nchannels();
float* pixel = OIIO_ALLOCA(float, nchans);
buf.interppixel(x, y, pixel, wrap);
return C_to_tuple(pixel, nchans);
}
py::tuple
ImageBuf_interppixel_NDC(const ImageBuf& buf, float x, float y,
const std::string& wrapname = "black")
{
ImageBuf::WrapMode wrap = ImageBuf::WrapMode_from_string(wrapname);
int nchans = buf.nchannels();
float* pixel = OIIO_ALLOCA(float, nchans);
buf.interppixel_NDC(x, y, pixel, wrap);
return C_to_tuple(pixel, nchans);
}
py::tuple
ImageBuf_interppixel_bicubic(const ImageBuf& buf, float x, float y,
const std::string& wrapname = "black")
{
ImageBuf::WrapMode wrap = ImageBuf::WrapMode_from_string(wrapname);
int nchans = buf.nchannels();
float* pixel = OIIO_ALLOCA(float, nchans);
buf.interppixel_bicubic(x, y, pixel, wrap);
return C_to_tuple(pixel, nchans);
}
py::tuple
ImageBuf_interppixel_bicubic_NDC(const ImageBuf& buf, float x, float y,
const std::string& wrapname = "black")
{
ImageBuf::WrapMode wrap = ImageBuf::WrapMode_from_string(wrapname);
int nchans = buf.nchannels();
float* pixel = OIIO_ALLOCA(float, nchans);
buf.interppixel_bicubic_NDC(x, y, pixel, wrap);
return C_to_tuple(pixel, nchans);
}
void
ImageBuf_setpixel(ImageBuf& buf, int x, int y, int z, py::object p)
{
std::vector<float> pixel;
py_to_stdvector(pixel, p);
if (pixel.size())
buf.setpixel(x, y, z, pixel);
}
void
ImageBuf_setpixel2(ImageBuf& buf, int x, int y, py::object p)
{
ImageBuf_setpixel(buf, x, y, 0, p);
}
void
ImageBuf_setpixel1(ImageBuf& buf, int i, py::object p)
{
std::vector<float> pixel;
py_to_stdvector(pixel, p);
if (pixel.size())
buf.setpixel(i, pixel);
}
py::object
ImageBuf_get_pixels(const ImageBuf& buf, TypeDesc format, ROI roi = ROI::All())
{
// Allocate our own temp buffer and try to read the image into it.
// If the read fails, return None.
if (!roi.defined())
roi = buf.roi();
roi.chend = std::min(roi.chend, buf.nchannels());
size_t size = (size_t)roi.npixels() * roi.nchannels() * format.size();
std::unique_ptr<char[]> data(new char[size]);
if (buf.get_pixels(roi, format, &data[0]))
return make_numpy_array(format, data.release(),
buf.spec().depth > 1 ? 4 : 3, roi.nchannels(),
roi.width(), roi.height(), roi.depth());
else
return py::none();
}
void
ImageBuf_set_deep_value(ImageBuf& buf, int x, int y, int z, int c, int s,
float value)
{
buf.set_deep_value(x, y, z, c, s, value);
}
void
ImageBuf_set_deep_value_uint(ImageBuf& buf, int x, int y, int z, int c, int s,
uint32_t value)
{
buf.set_deep_value(x, y, z, c, s, value);
}
bool
ImageBuf_set_pixels_buffer(ImageBuf& self, ROI roi, py::buffer& buffer)
{
if (!roi.defined())
roi = self.roi();
roi.chend = std::min(roi.chend, self.nchannels());
size_t size = (size_t)roi.npixels() * roi.nchannels();
if (size == 0) {
return true; // done
}
oiio_bufinfo buf(buffer.request(), roi.nchannels(), roi.width(),
roi.height(), roi.depth(), self.spec().depth > 1 ? 3 : 2);
if (!buf.data || buf.error.size()) {
self.errorf("set_pixels error: %s",
buf.error.size() ? buf.error.c_str() : "unspecified");
return false; // failed sanity checks
}
if (!buf.data || buf.size != size) {
self.error(
"ImageBuf.set_pixels: array size (%d) did not match ROI size w=%d h=%d d=%d ch=%d (total %d)",
buf.size, roi.width(), roi.height(), roi.depth(), roi.nchannels(),
size);
return false;
}
py::gil_scoped_release gil;
return self.set_pixels(roi, buf.format, buf.data, buf.xstride, buf.ystride,
buf.zstride);
}
void
ImageBuf_set_write_format(ImageBuf& self, const py::object& py_channelformats)
{
std::vector<TypeDesc> formats;
py_to_stdvector(formats, py_channelformats);
self.set_write_format(formats);
}
void
declare_imagebuf(py::module& m)
{
using namespace pybind11::literals;
py::class_<ImageBuf>(m, "ImageBuf")
.def(py::init<>())
.def(py::init<const std::string&>())
.def(py::init<const std::string&, int, int>())
.def(py::init<const ImageSpec&>())
.def(py::init([](const ImageSpec& spec, bool zero) {
auto z = zero ? InitializePixels::Yes : InitializePixels::No;
return ImageBuf(spec, z);
}))
.def(py::init([](const std::string& name, int subimage, int miplevel,
const ImageSpec& config) {
return ImageBuf(name, subimage, miplevel, nullptr, &config);
}),
"name"_a, "subimage"_a, "miplevel"_a, "config"_a)
.def("clear", &ImageBuf::clear)
.def(
"reset",
[](ImageBuf& self, const std::string& name, int subimage,
int miplevel) { self.reset(name, subimage, miplevel); },
"name"_a, "subimage"_a = 0, "miplevel"_a = 0)
.def(
"reset",
[](ImageBuf& self, const std::string& name, int subimage,
int miplevel, const ImageSpec& config) {
self.reset(name, subimage, miplevel, nullptr, &config);
},
"name"_a, "subimage"_a = 0, "miplevel"_a = 0,
"config"_a = ImageSpec())
.def(
"reset",
[](ImageBuf& self, const ImageSpec& spec, bool zero) {
auto z = zero ? InitializePixels::Yes : InitializePixels::No;
self.reset(spec, z);
},
"spec"_a, "zero"_a = true)
.def_property_readonly("initialized",
[](const ImageBuf& self) {
return self.initialized();
})
.def(
"init_spec",
[](ImageBuf& self, std::string filename, int subimage,
int miplevel) {
py::gil_scoped_release gil;
self.init_spec(filename, subimage, miplevel);
},
"filename"_a, "subimage"_a = 0, "miplevel"_a = 0)
.def(
"read",
[](ImageBuf& self, int subimage, int miplevel, int chbegin,
int chend, bool force, TypeDesc convert) {
py::gil_scoped_release gil;
return self.read(subimage, miplevel, chbegin, chend, force,
convert);
},
"subimage"_a, "miplevel"_a, "chbegin"_a, "chend"_a, "force"_a,
"convert"_a)
.def(
"read",
[](ImageBuf& self, int subimage, int miplevel, bool force,
TypeDesc convert) {
py::gil_scoped_release gil;
return self.read(subimage, miplevel, force, convert);
},
"subimage"_a = 0, "miplevel"_a = 0, "force"_a = false,
"convert"_a = TypeUnknown)
.def(
"write",
[](ImageBuf& self, const std::string& filename, TypeDesc dtype,
const std::string& fileformat) {
py::gil_scoped_release gil;
return self.write(filename, dtype, fileformat);
},
"filename"_a, "dtype"_a = TypeUnknown, "fileformat"_a = "")
.def(
"write",
[](ImageBuf& self, ImageOutput& out) {
py::gil_scoped_release gil;
return self.write(&out);
},
"out"_a)
.def(
"make_writable",
[](ImageBuf& self, bool keep_cache_type) {
py::gil_scoped_release gil;
return self.make_writable(keep_cache_type);
},
"keep_cache_type"_a = false)
// DEPRECATED(2.2): nonstandard spelling
.def(
"make_writeable",
[](ImageBuf& self, bool keep_cache_type) {
py::gil_scoped_release gil;
return self.make_writable(keep_cache_type);
},
"keep_cache_type"_a = false)
.def("set_write_format", &ImageBuf_set_write_format)
// FIXME -- write(ImageOut&)
.def("set_write_tiles", &ImageBuf::set_write_tiles, "width"_a = 0,
"height"_a = 0, "depth"_a = 0)
.def("spec", &ImageBuf::spec,
py::return_value_policy::reference_internal)
.def("nativespec", &ImageBuf::nativespec,
py::return_value_policy::reference_internal)
.def("specmod", &ImageBuf::specmod,
py::return_value_policy::reference_internal)
.def_property_readonly("name",
[](const ImageBuf& self) {
return PY_STR(self.name());
})
.def_property_readonly("file_format_name",
[](const ImageBuf& self) {
return PY_STR(self.file_format_name());
})
.def_property_readonly("subimage", &ImageBuf::subimage)
.def_property_readonly("nsubimages", &ImageBuf::nsubimages)
.def_property_readonly("miplevel", &ImageBuf::miplevel)
.def_property_readonly("nmiplevels", &ImageBuf::nmiplevels)
.def_property_readonly("nchannels", &ImageBuf::nchannels)
.def_property("orientation", &ImageBuf::orientation,
&ImageBuf::set_orientation)
.def_property_readonly("oriented_width", &ImageBuf::oriented_width)
.def_property_readonly("oriented_height", &ImageBuf::oriented_height)
.def_property_readonly("oriented_x", &ImageBuf::oriented_x)
.def_property_readonly("oriented_y", &ImageBuf::oriented_y)
.def_property_readonly("oriented_full_width",
&ImageBuf::oriented_full_width)
.def_property_readonly("oriented_full_height",
&ImageBuf::oriented_full_height)
.def_property_readonly("oriented_full_x", &ImageBuf::oriented_full_x)
.def_property_readonly("oriented_full_y", &ImageBuf::oriented_full_y)
.def_property_readonly("xbegin", &ImageBuf::xbegin)
.def_property_readonly("xend", &ImageBuf::xend)
.def_property_readonly("ybegin", &ImageBuf::ybegin)
.def_property_readonly("yend", &ImageBuf::yend)
.def_property_readonly("zbegin", &ImageBuf::zbegin)
.def_property_readonly("zend", &ImageBuf::zend)
.def_property_readonly("xmin", &ImageBuf::xmin)
.def_property_readonly("xmax", &ImageBuf::xmax)
.def_property_readonly("ymin", &ImageBuf::ymin)
.def_property_readonly("ymax", &ImageBuf::ymax)
.def_property_readonly("zmin", &ImageBuf::zmin)
.def_property_readonly("zmax", &ImageBuf::zmax)
.def_property_readonly("roi", &ImageBuf::roi)
.def_property("roi_full", &ImageBuf::roi_full, &ImageBuf::set_roi_full)
.def("set_origin", &ImageBuf::set_origin, "x"_a, "y"_a, "z"_a = 0)
.def("set_full", &ImageBuf::set_full)
.def_property_readonly("pixels_valid", &ImageBuf::pixels_valid)
.def_property_readonly("pixeltype", &ImageBuf::pixeltype)
.def_property_readonly("has_error", &ImageBuf::has_error)
.def(
"geterror",
[](const ImageBuf& self, bool clear) {
return PY_STR(self.geterror(clear));
},
"clear"_a = true)
.def("pixelindex", &ImageBuf::pixelindex, "x"_a, "y"_a, "z"_a,
"check_range"_a = false)
.def("copy_metadata", &ImageBuf::copy_metadata)
.def("copy_pixels", &ImageBuf::copy_pixels)
.def(
"copy",
[](ImageBuf& self, const ImageBuf& src, TypeDesc format) {
py::gil_scoped_release gil;
return self.copy(src, format);
},
"src"_a, "format"_a = TypeUnknown)
.def(
"copy",
[](const ImageBuf& src, TypeDesc format) {
py::gil_scoped_release gil;
return src.copy(format);
},
"format"_a = TypeUnknown)
.def("swap", &ImageBuf::swap)
.def("getchannel", &ImageBuf::getchannel, "x"_a, "y"_a, "z"_a, "c"_a,
"wrap"_a = "black")
.def("getpixel", &ImageBuf_getpixel, "x"_a, "y"_a, "z"_a = 0,
"wrap"_a = "black")
.def("interppixel", &ImageBuf_interppixel, "x"_a, "y"_a,
"wrap"_a = "black")
.def("interppixel_NDC", &ImageBuf_interppixel_NDC, "x"_a, "y"_a,
"wrap"_a = "black")
.def("interppixel_NDC_full", &ImageBuf_interppixel_NDC, "x"_a, "y"_a,
"wrap"_a = "black")
.def("interppixel_bicubic", &ImageBuf_interppixel_bicubic, "x"_a, "y"_a,
"wrap"_a = "black")
.def("interppixel_bicubic_NDC", &ImageBuf_interppixel_bicubic_NDC,
"x"_a, "y"_a, "wrap"_a = "black")
.def("setpixel", &ImageBuf_setpixel, "x"_a, "y"_a, "z"_a, "pixel"_a)
.def("setpixel", &ImageBuf_setpixel2, "x"_a, "y"_a, "pixel"_a)
.def("setpixel", &ImageBuf_setpixel1, "i"_a, "pixel"_a)
.def("get_pixels", &ImageBuf_get_pixels, "format"_a = TypeFloat,
"roi"_a = ROI::All())
.def("set_pixels", &ImageBuf_set_pixels_buffer, "roi"_a, "pixels"_a)
.def_property_readonly("deep", &ImageBuf::deep)
.def("deep_samples", &ImageBuf::deep_samples, "x"_a, "y"_a, "z"_a = 0)
.def("set_deep_samples", &ImageBuf::set_deep_samples, "x"_a, "y"_a,
"z"_a = 0, "nsamples"_a = 1)
.def("deep_insert_samples", &ImageBuf::deep_insert_samples, "x"_a,
"y"_a, "z"_a = 0, "samplepos"_a, "nsamples"_a = 1)
.def("deep_erase_samples", &ImageBuf::deep_erase_samples, "x"_a, "y"_a,
"z"_a = 0, "samplepos"_a, "nsamples"_a = 1)
.def("deep_value", &ImageBuf::deep_value, "x"_a, "y"_a, "z"_a,
"channel"_a, "sample"_a)
.def("deep_value_uint", &ImageBuf::deep_value_uint, "x"_a, "y"_a, "z"_a,
"channel"_a, "sample"_a)
.def("set_deep_value", &ImageBuf_set_deep_value, "x"_a, "y"_a, "z"_a,
"channel"_a, "sample"_a, "value"_a = 0.0f)
.def("set_deep_value_uint", &ImageBuf_set_deep_value_uint, "x"_a, "y"_a,
"z"_a, "channel"_a, "sample"_a, "value"_a = 0)
.def(
"deepdata", [](ImageBuf& self) { return *self.deepdata(); },
py::return_value_policy::reference_internal)
// FIXME -- do we want to provide pixel iterators?
;
}
} // namespace PyOpenImageIO
|
!to "shasum.o", plain
* = $6000
jmp main
!addr SRC = $06
!addr DST = $08
!addr SHAINPUT = $eb
!addr SHALENGTH = $ee
!addr PRBYTE = $FDDA
!addr COUT = $FDED
!macro set32 .target, .value {
lda #<(.value >> 24)
sta .target
lda #<(.value >> 16)
sta .target+1
lda #<(.value >> 8)
sta .target+2
lda #<(.value)
sta .target+3
}
!macro setSRC .source {
lda #<.source
sta SRC
lda #>.source
sta SRC+1
}
!macro setDST .dest {
lda #<.dest
sta DST
lda #>.dest
sta DST+1
}
;;; Print a string of bytes, as hex.
;;; Address in SRC, count in A.
;;; Burns A,Y.
prbytes:
ldy #0
- pha
lda (SRC),y
jsr PRBYTE
iny
pla
adc #$ff
bne -
rts
main:
;; Test shasum ""
lda #0
sta SHAINPUT
lda #$fe
sta SHAINPUT+1
lda #0
sta SHALENGTH+1
lda #0 ; da39a3ee5e6b4b0d3255bfef95601890afd80709
sta SHALENGTH
jsr SHASUM
; lda #$8d
; jsr COUT
+setSRC SHA
lda #SHALEN
jsr prbytes
;; Test shasum FE00[:0x37]
lda #0
sta SHAINPUT
lda #$fe
sta SHAINPUT+1
lda #0
sta SHALENGTH+1
lda #$37 ; 1CF73FC6156B548A949D315120B5256245EAA33E
sta SHALENGTH
jsr SHASUM
; lda #$8d
; jsr COUT
+setSRC SHA
lda #SHALEN
jsr prbytes
;; Test shasum FE00[:0x100]
lda #0
sta SHAINPUT
lda #$fe
sta SHAINPUT+1
lda #1
sta SHALENGTH+1
lda #0 ; 7B3D05347B52210065E27054FDFD0B8B699F0965
sta SHALENGTH
jsr SHASUM
; lda #$8d
; jsr COUT
+setSRC SHA
lda #SHALEN
jsr prbytes
;; Test shasum FE00[:0x1ff]
lda #0
sta SHAINPUT
lda #$fe
sta SHAINPUT+1
lda #$1
sta SHALENGTH+1
lda #$ff ; 269CA6B0C644DAC01D908B20C10C0D5B19C52ABF
sta SHALENGTH
jsr SHASUM
; lda #$8d
; jsr COUT
+setSRC SHA
lda #SHALEN
jsr prbytes
;; Test shasum FE00[:0x200]
lda #0
sta SHAINPUT
lda #$fe
sta SHAINPUT+1
lda #2
sta SHALENGTH+1
lda #0 ; D5AC71D5EE76E31CC82CF5136151BF4CDA503601
sta SHALENGTH
jsr SHASUM
; lda #$8d
; jsr COUT
+setSRC SHA
lda #SHALEN
jsr prbytes
rts
!src "shasum.asm"
|
#include <iostream>
#include <functional>
#include <thread>
#include <future>
#include <exception>
static void __get_int(std::promise<int>& prom) {
int x;
std::cout << "Please, enter an integer value: ";
std::cin.exceptions (std::ios::failbit);
try {
std::cin >> x;
prom.set_value(x);
} catch (std::exception&) {
prom.set_exception(std::current_exception());
}
}
static void __print_int(std::future<int>& fut) {
try {
int x = fut.get();
std::cout << "value: " << x << '\n';
} catch (std::exception& e) {
std::cout << "[exception caught: " << e.what() << "]\n";
}
}
int main () {
std::promise<int> prom;
std::future<int> fut = prom.get_future();
std::thread th1(__get_int, std::ref(prom));
std::thread th2(__print_int, std::ref(fut));
th1.join();
th2.join();
return 0;
} |
; A140354: a(n) = binomial(n+9,9)*2^n.
; 1,20,220,1760,11440,64064,320320,1464320,6223360,24893440,94595072,343982080,1203937280,4074864640,13388840960,42844291072,133888409600,409541017600,1228623052800,3621204787200,10501493882880,30004268236800,84557483212800,235290388070400,647048567193600,1759972102766592,4738386430525440,12635697148067840,33394342462750720,87516207833415680,227542140366880768,587205523527434240,1504714154039050240,3830181483008491520,9688106104080302080,24358666775973330944,60896666939933327360
mov $1,-2
pow $1,$0
mov $2,-10
bin $2,$0
mul $1,$2
mov $0,$1
|
;
;
; ZX Maths Routines
;
; 8/12/02 - Stefano Bodrato
;
; $Id: pow.asm,v 1.5 2016-06-22 19:59:18 dom Exp $
;
;double pow(double x,double y)
;y is in the FA
;x is on the stack +8 (+2=y)
;
IF FORzx
INCLUDE "zxfp.def"
ENDIF
IF FORzx81
INCLUDE "81fp.def"
ENDIF
IF FORlambda
INCLUDE "lambdafp.def"
ENDIF
SECTION code_fp
PUBLIC pow
EXTERN fsetupf
EXTERN stkequ
.pow
call fsetupf
IF FORlambda
defb ZXFP_TO_POWER + 128
ELSE
defb ZXFP_TO_POWER
defb ZXFP_END_CALC
ENDIF
jp stkequ
|
; ulong esxdos_m_getdate(void)
SECTION code_clib
SECTION code_esxdos
PUBLIC esxdos_m_getdate
EXTERN asm_esxdos_m_getdate
defc esxdos_m_getdate = asm_esxdos_m_getdate
|
#include "Units.h"
#include <string>
#include "../llvmUtils/llvmUtils.h"
#include "../llvm_Linker.h"
#include "../llvm_Module.h"
namespace dale {
Units::Units(Module::Reader *mr) {
this->mr = mr;
this->prefunction_ns = NULL;
}
Units::~Units() {}
Unit *Units::top() {
if (!units.size()) {
assert(false && "no unit available");
abort();
}
return units.back();
}
bool Units::empty() { return units.empty(); }
size_t Units::size() { return units.size(); }
void Units::pop() {
Unit *popped = units.back();
units.pop_back();
if (empty()) {
return;
}
Unit *current = units.back();
std::string link_error;
if (popped->hasOwnModule()) {
linkModule(current->linker, popped->module);
}
current->ctx->merge(popped->ctx);
current->ctx->regetPointers(current->module);
return;
}
void Units::push(Unit *new_unit) {
if (units.size()) {
Unit *current = units.back();
new_unit->ctx->merge(current->ctx);
new_unit->ee = current->ee;
}
units.push_back(new_unit);
return;
}
}
|
Title_screen_Header:
smpsHeaderStartSong 2
smpsHeaderVoice Title_screen_Voices
smpsHeaderChan $06, $03
smpsHeaderTempo $01, $CD
smpsHeaderDAC Title_screen_DAC
smpsHeaderFM Title_screen_FM1, $F4, $0C
smpsHeaderFM Title_screen_FM2, $F4, $0C
smpsHeaderFM Title_screen_FM3, $F4, $0B
smpsHeaderFM Title_screen_FM4, $F4, $0B
smpsHeaderFM Title_screen_FM5, $F4, $0E
smpsHeaderPSG Title_screen_PSG1, $00, $00, $00, fTone_03
smpsHeaderPSG Title_screen_PSG2, $00, $02, $00, fTone_03
smpsHeaderPSG Title_screen_PSG3, $00, $03, $00, fTone_04
; FM5 Data
Title_screen_FM5:
smpsAlterNote $03
; FM1 Data
Title_screen_FM1:
smpsSetvoice $00
dc.b nRst, $3C, nCs6, $15, nRst, $03, nCs6, $06, nRst, nD6, $0F, nRst
dc.b $03, nB5, $18, nRst, $06, nCs6, nRst, nCs6, nRst, nCs6, nRst, nA5
dc.b nRst, nG5, $0F, nRst, $03, nB5, $0C, nRst, $12, nA5, $06, nRst
dc.b nCs6, nRst, nA6, nRst, nE6, $0C, nRst, $06, nAb6, $12, nA6, $06
dc.b nRst, $72
smpsStop
; FM2 Data
Title_screen_FM2:
smpsSetvoice $03
smpsNop $01
dc.b nRst, $30, nA3, $06, nRst, nA3, nRst, nE3, nRst, nE3, nRst, nG3
dc.b $12, nB3, nD4, $0C, nA3, $06, nRst, nA3, nRst, nE3, nRst, nE3
dc.b nRst, nD4, $12, nCs4, nB3, $0C, nRst, nA3, nRst, nA3, nRst, $06
dc.b nAb3, $12, nA3, $06, nRst
smpsSetvoice $01
smpsAlterVol $02
dc.b nA2, $6C
smpsNop $01
smpsStop
; FM3 Data
Title_screen_FM3:
smpsSetvoice $02
dc.b nRst, $30, nE6, $06, nRst, nE6, nRst, nCs6, nRst, nCs6, nRst, nD6
dc.b $0F, nRst, $03, nD6, $18, nRst, $06, nE6, nRst, nE6, nRst, nCs6
dc.b nRst, nCs6, nRst, nG6, $0F, nRst, $03, nG6, $18, nRst, $06, nE6
dc.b $0C, nRst, nE6, nRst, nRst, $06, nEb6, $12, nE6, $0C
smpsAlterVol $FC
smpsSetvoice $01
smpsAlterNote $03
dc.b nA2, $6C
smpsStop
; FM4 Data
Title_screen_FM4:
smpsSetvoice $02
dc.b nRst, $30, nCs6, $06, nRst, nCs6, nRst, nA5, nRst, nA5, nRst, nB5
dc.b $0F, nRst, $03, nB5, $18, nRst, $06, nCs6, nRst, nCs6, nRst, nA5
dc.b nRst, nA5, nRst, nD6, $0F, nRst, $03, nD6, $18, nRst, $06, nCs6
dc.b $0C, nRst, nCs6, nRst, nRst, $06, nC6, $12, nCs6, $0C
smpsAlterVol $FD
smpsSetvoice $01
smpsModSet $00, $01, $06, $04
dc.b nA2, $6C
smpsStop
; PSG3 Data
Title_screen_PSG3:
smpsPSGform $E7
dc.b nRst, $30
Title_screen_Loop02:
smpsNoteFill $03
dc.b nMaxPSG, $0C
smpsNoteFill $0C
dc.b $0C
smpsNoteFill $03
dc.b $0C
smpsNoteFill $0C
dc.b $0C
smpsLoop $00, $05, Title_screen_Loop02
smpsNoteFill $03
dc.b $06
smpsNoteFill $0E
dc.b $12
smpsNoteFill $03
dc.b $0C
smpsNoteFill $0F
dc.b $0C
smpsStop
; DAC Data
Title_screen_DAC:
dc.b dKick, $0C, dSnare, dSnare, dSnare, $08, dSnare, $04, dKick, $0C, dSnare, dKick
dc.b dSnare, dKick, dSnare, dKick, dSnare, dKick, dSnare, dKick, dSnare, dKick, dSnare, dKick
dc.b $06, nRst, $02, dSnare, dSnare, dSnare, $09, dSnare, $03, dKick, $0C, dSnare
dc.b dSnare, $04, dSnare, dSnare, dSnare, nRst, nRst, dSnare, $06, dSnare, $12, dSnare
dc.b $0C, dKick
smpsStop
; PSG2 Data
Title_screen_PSG2:
dc.b nRst, $03
; PSG1 Data
Title_screen_PSG1:
dc.b nRst, $30
smpsLoop $00, $06, Title_screen_PSG1
dc.b nRst, $20
Title_screen_Loop00:
dc.b nD5, $03, nE5, nFs5
smpsPSGAlterVol $01
smpsAlterPitch $FF
smpsLoop $00, $05, Title_screen_Loop00
Title_screen_Loop01:
dc.b nD5, $03, nE5, nFs5
smpsPSGAlterVol $01
smpsAlterPitch $01
smpsLoop $00, $07, Title_screen_Loop01
smpsStop
Title_screen_Voices:
; Voice $00
; $3A
; $51, $08, $51, $02, $1E, $1E, $1E, $10, $1F, $1F, $1F, $0F
; $00, $00, $00, $02, $0F, $0F, $0F, $1F, $18, $24, $22, $81
smpsVcAlgorithm $02
smpsVcFeedback $07
smpsVcUnusedBits $00
smpsVcDetune $00, $05, $00, $05
smpsVcCoarseFreq $02, $01, $08, $01
smpsVcRateScale $00, $00, $00, $00
smpsVcAttackRate $10, $1E, $1E, $1E
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $0F, $1F, $1F, $1F
smpsVcDecayRate2 $02, $00, $00, $00
smpsVcDecayLevel $01, $00, $00, $00
smpsVcReleaseRate $0F, $0F, $0F, $0F
smpsVcTotalLevel $01, $22, $24, $18
; Voice $01
; $20
; $36, $35, $30, $31, $DF, $DF, $9F, $9F, $07, $06, $09, $06
; $07, $06, $06, $08, $2F, $1F, $1F, $FF, $19, $37, $13, $80
smpsVcAlgorithm $00
smpsVcFeedback $04
smpsVcUnusedBits $00
smpsVcDetune $03, $03, $03, $03
smpsVcCoarseFreq $01, $00, $05, $06
smpsVcRateScale $02, $02, $03, $03
smpsVcAttackRate $1F, $1F, $1F, $1F
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $06, $09, $06, $07
smpsVcDecayRate2 $08, $06, $06, $07
smpsVcDecayLevel $0F, $01, $01, $02
smpsVcReleaseRate $0F, $0F, $0F, $0F
smpsVcTotalLevel $00, $13, $37, $19
; Voice $02
; $3A
; $01, $07, $01, $01, $7D, $7D, $7D, $33, $0E, $0E, $0E, $03
; $00, $00, $00, $00, $1F, $FF, $1F, $1F, $18, $20, $2F, $80
smpsVcAlgorithm $02
smpsVcFeedback $07
smpsVcUnusedBits $00
smpsVcDetune $00, $00, $00, $00
smpsVcCoarseFreq $01, $01, $07, $01
smpsVcRateScale $00, $01, $01, $01
smpsVcAttackRate $33, $3D, $3D, $3D
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $03, $0E, $0E, $0E
smpsVcDecayRate2 $00, $00, $00, $00
smpsVcDecayLevel $01, $01, $0F, $01
smpsVcReleaseRate $0F, $0F, $0F, $0F
smpsVcTotalLevel $00, $2F, $20, $18
; Voice $03
; $39
; $06, $60, $30, $01, $3F, $3F, $5F, $5F, $11, $0F, $13, $09
; $05, $04, $04, $03, $2F, $2F, $2F, $2F, $27, $2C, $97, $80
smpsVcAlgorithm $01
smpsVcFeedback $07
smpsVcUnusedBits $00
smpsVcDetune $00, $03, $06, $00
smpsVcCoarseFreq $01, $00, $00, $06
smpsVcRateScale $01, $01, $00, $00
smpsVcAttackRate $1F, $1F, $3F, $3F
smpsVcAmpMod $00, $00, $00, $00
smpsVcDecayRate1 $09, $13, $0F, $11
smpsVcDecayRate2 $03, $04, $04, $05
smpsVcDecayLevel $02, $02, $02, $02
smpsVcReleaseRate $0F, $0F, $0F, $0F
smpsVcTotalLevel $00, $97, $2C, $27
|
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/ast/scopes.h"
#include "src/compiler/code-generator.h"
#include "src/compiler/code-generator-impl.h"
#include "src/compiler/gap-resolver.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/osr.h"
#include "src/mips/macro-assembler-mips.h"
namespace v8 {
namespace internal {
namespace compiler {
#define __ masm()->
// TODO(plind): Possibly avoid using these lithium names.
#define kScratchReg kLithiumScratchReg
#define kCompareReg kLithiumScratchReg2
#define kScratchReg2 kLithiumScratchReg2
#define kScratchDoubleReg kLithiumScratchDouble
// TODO(plind): consider renaming these macros.
#define TRACE_MSG(msg) \
PrintF("code_gen: \'%s\' in function %s at line %d\n", msg, __FUNCTION__, \
__LINE__)
#define TRACE_UNIMPL() \
PrintF("UNIMPLEMENTED code_generator_mips: %s at line %d\n", __FUNCTION__, \
__LINE__)
// Adds Mips-specific methods to convert InstructionOperands.
class MipsOperandConverter final : public InstructionOperandConverter {
public:
MipsOperandConverter(CodeGenerator* gen, Instruction* instr)
: InstructionOperandConverter(gen, instr) {}
FloatRegister OutputSingleRegister(size_t index = 0) {
return ToSingleRegister(instr_->OutputAt(index));
}
FloatRegister InputSingleRegister(size_t index) {
return ToSingleRegister(instr_->InputAt(index));
}
FloatRegister ToSingleRegister(InstructionOperand* op) {
// Single (Float) and Double register namespace is same on MIPS,
// both are typedefs of FPURegister.
return ToDoubleRegister(op);
}
DoubleRegister InputOrZeroDoubleRegister(size_t index) {
if (instr_->InputAt(index)->IsImmediate()) return kDoubleRegZero;
return InputDoubleRegister(index);
}
DoubleRegister InputOrZeroSingleRegister(size_t index) {
if (instr_->InputAt(index)->IsImmediate()) return kDoubleRegZero;
return InputSingleRegister(index);
}
Operand InputImmediate(size_t index) {
Constant constant = ToConstant(instr_->InputAt(index));
switch (constant.type()) {
case Constant::kInt32:
return Operand(constant.ToInt32());
case Constant::kFloat32:
return Operand(
isolate()->factory()->NewNumber(constant.ToFloat32(), TENURED));
case Constant::kFloat64:
return Operand(
isolate()->factory()->NewNumber(constant.ToFloat64(), TENURED));
case Constant::kInt64:
case Constant::kExternalReference:
case Constant::kHeapObject:
// TODO(plind): Maybe we should handle ExtRef & HeapObj here?
// maybe not done on arm due to const pool ??
break;
case Constant::kRpoNumber:
UNREACHABLE(); // TODO(titzer): RPO immediates on mips?
break;
}
UNREACHABLE();
return Operand(zero_reg);
}
Operand InputOperand(size_t index) {
InstructionOperand* op = instr_->InputAt(index);
if (op->IsRegister()) {
return Operand(ToRegister(op));
}
return InputImmediate(index);
}
MemOperand MemoryOperand(size_t* first_index) {
const size_t index = *first_index;
switch (AddressingModeField::decode(instr_->opcode())) {
case kMode_None:
break;
case kMode_MRI:
*first_index += 2;
return MemOperand(InputRegister(index + 0), InputInt32(index + 1));
case kMode_MRR:
// TODO(plind): r6 address mode, to be implemented ...
UNREACHABLE();
}
UNREACHABLE();
return MemOperand(no_reg);
}
MemOperand MemoryOperand(size_t index = 0) { return MemoryOperand(&index); }
MemOperand ToMemOperand(InstructionOperand* op) const {
DCHECK_NOT_NULL(op);
DCHECK(op->IsStackSlot() || op->IsFPStackSlot());
return SlotToMemOperand(AllocatedOperand::cast(op)->index());
}
MemOperand SlotToMemOperand(int slot) const {
FrameOffset offset = frame_access_state()->GetFrameOffset(slot);
return MemOperand(offset.from_stack_pointer() ? sp : fp, offset.offset());
}
};
static inline bool HasRegisterInput(Instruction* instr, size_t index) {
return instr->InputAt(index)->IsRegister();
}
namespace {
class OutOfLineLoadSingle final : public OutOfLineCode {
public:
OutOfLineLoadSingle(CodeGenerator* gen, FloatRegister result)
: OutOfLineCode(gen), result_(result) {}
void Generate() final {
__ Move(result_, std::numeric_limits<float>::quiet_NaN());
}
private:
FloatRegister const result_;
};
class OutOfLineLoadDouble final : public OutOfLineCode {
public:
OutOfLineLoadDouble(CodeGenerator* gen, DoubleRegister result)
: OutOfLineCode(gen), result_(result) {}
void Generate() final {
__ Move(result_, std::numeric_limits<double>::quiet_NaN());
}
private:
DoubleRegister const result_;
};
class OutOfLineLoadInteger final : public OutOfLineCode {
public:
OutOfLineLoadInteger(CodeGenerator* gen, Register result)
: OutOfLineCode(gen), result_(result) {}
void Generate() final { __ mov(result_, zero_reg); }
private:
Register const result_;
};
class OutOfLineRound : public OutOfLineCode {
public:
OutOfLineRound(CodeGenerator* gen, DoubleRegister result)
: OutOfLineCode(gen), result_(result) {}
void Generate() final {
// Handle rounding to zero case where sign has to be preserved.
// High bits of double input already in kScratchReg.
__ srl(at, kScratchReg, 31);
__ sll(at, at, 31);
__ Mthc1(at, result_);
}
private:
DoubleRegister const result_;
};
class OutOfLineRound32 : public OutOfLineCode {
public:
OutOfLineRound32(CodeGenerator* gen, DoubleRegister result)
: OutOfLineCode(gen), result_(result) {}
void Generate() final {
// Handle rounding to zero case where sign has to be preserved.
// High bits of float input already in kScratchReg.
__ srl(at, kScratchReg, 31);
__ sll(at, at, 31);
__ mtc1(at, result_);
}
private:
DoubleRegister const result_;
};
class OutOfLineRecordWrite final : public OutOfLineCode {
public:
OutOfLineRecordWrite(CodeGenerator* gen, Register object, Register index,
Register value, Register scratch0, Register scratch1,
RecordWriteMode mode)
: OutOfLineCode(gen),
object_(object),
index_(index),
value_(value),
scratch0_(scratch0),
scratch1_(scratch1),
mode_(mode),
must_save_lr_(!gen->frame_access_state()->has_frame()) {}
void Generate() final {
if (mode_ > RecordWriteMode::kValueIsPointer) {
__ JumpIfSmi(value_, exit());
}
__ CheckPageFlag(value_, scratch0_,
MemoryChunk::kPointersToHereAreInterestingMask, eq,
exit());
RememberedSetAction const remembered_set_action =
mode_ > RecordWriteMode::kValueIsMap ? EMIT_REMEMBERED_SET
: OMIT_REMEMBERED_SET;
SaveFPRegsMode const save_fp_mode =
frame()->DidAllocateDoubleRegisters() ? kSaveFPRegs : kDontSaveFPRegs;
if (must_save_lr_) {
// We need to save and restore ra if the frame was elided.
__ Push(ra);
}
RecordWriteStub stub(isolate(), object_, scratch0_, scratch1_,
remembered_set_action, save_fp_mode);
__ Addu(scratch1_, object_, index_);
__ CallStub(&stub);
if (must_save_lr_) {
__ Pop(ra);
}
}
private:
Register const object_;
Register const index_;
Register const value_;
Register const scratch0_;
Register const scratch1_;
RecordWriteMode const mode_;
bool must_save_lr_;
};
Condition FlagsConditionToConditionCmp(FlagsCondition condition) {
switch (condition) {
case kEqual:
return eq;
case kNotEqual:
return ne;
case kSignedLessThan:
return lt;
case kSignedGreaterThanOrEqual:
return ge;
case kSignedLessThanOrEqual:
return le;
case kSignedGreaterThan:
return gt;
case kUnsignedLessThan:
return lo;
case kUnsignedGreaterThanOrEqual:
return hs;
case kUnsignedLessThanOrEqual:
return ls;
case kUnsignedGreaterThan:
return hi;
case kUnorderedEqual:
case kUnorderedNotEqual:
break;
default:
break;
}
UNREACHABLE();
return kNoCondition;
}
Condition FlagsConditionToConditionTst(FlagsCondition condition) {
switch (condition) {
case kNotEqual:
return ne;
case kEqual:
return eq;
default:
break;
}
UNREACHABLE();
return kNoCondition;
}
FPUCondition FlagsConditionToConditionCmpFPU(bool& predicate,
FlagsCondition condition) {
switch (condition) {
case kEqual:
predicate = true;
return EQ;
case kNotEqual:
predicate = false;
return EQ;
case kUnsignedLessThan:
predicate = true;
return OLT;
case kUnsignedGreaterThanOrEqual:
predicate = false;
return ULT;
case kUnsignedLessThanOrEqual:
predicate = true;
return OLE;
case kUnsignedGreaterThan:
predicate = false;
return ULE;
case kUnorderedEqual:
case kUnorderedNotEqual:
predicate = true;
break;
default:
predicate = true;
break;
}
UNREACHABLE();
return kNoFPUCondition;
}
} // namespace
#define ASSEMBLE_CHECKED_LOAD_FLOAT(width, asm_instr) \
do { \
auto result = i.Output##width##Register(); \
auto ool = new (zone()) OutOfLineLoad##width(this, result); \
if (instr->InputAt(0)->IsRegister()) { \
auto offset = i.InputRegister(0); \
__ Branch(USE_DELAY_SLOT, ool->entry(), hs, offset, i.InputOperand(1)); \
__ addu(kScratchReg, i.InputRegister(2), offset); \
__ asm_instr(result, MemOperand(kScratchReg, 0)); \
} else { \
auto offset = i.InputOperand(0).immediate(); \
__ Branch(ool->entry(), ls, i.InputRegister(1), Operand(offset)); \
__ asm_instr(result, MemOperand(i.InputRegister(2), offset)); \
} \
__ bind(ool->exit()); \
} while (0)
#define ASSEMBLE_CHECKED_LOAD_INTEGER(asm_instr) \
do { \
auto result = i.OutputRegister(); \
auto ool = new (zone()) OutOfLineLoadInteger(this, result); \
if (instr->InputAt(0)->IsRegister()) { \
auto offset = i.InputRegister(0); \
__ Branch(USE_DELAY_SLOT, ool->entry(), hs, offset, i.InputOperand(1)); \
__ addu(kScratchReg, i.InputRegister(2), offset); \
__ asm_instr(result, MemOperand(kScratchReg, 0)); \
} else { \
auto offset = i.InputOperand(0).immediate(); \
__ Branch(ool->entry(), ls, i.InputRegister(1), Operand(offset)); \
__ asm_instr(result, MemOperand(i.InputRegister(2), offset)); \
} \
__ bind(ool->exit()); \
} while (0)
#define ASSEMBLE_CHECKED_STORE_FLOAT(width, asm_instr) \
do { \
Label done; \
if (instr->InputAt(0)->IsRegister()) { \
auto offset = i.InputRegister(0); \
auto value = i.Input##width##Register(2); \
__ Branch(USE_DELAY_SLOT, &done, hs, offset, i.InputOperand(1)); \
__ addu(kScratchReg, i.InputRegister(3), offset); \
__ asm_instr(value, MemOperand(kScratchReg, 0)); \
} else { \
auto offset = i.InputOperand(0).immediate(); \
auto value = i.Input##width##Register(2); \
__ Branch(&done, ls, i.InputRegister(1), Operand(offset)); \
__ asm_instr(value, MemOperand(i.InputRegister(3), offset)); \
} \
__ bind(&done); \
} while (0)
#define ASSEMBLE_CHECKED_STORE_INTEGER(asm_instr) \
do { \
Label done; \
if (instr->InputAt(0)->IsRegister()) { \
auto offset = i.InputRegister(0); \
auto value = i.InputRegister(2); \
__ Branch(USE_DELAY_SLOT, &done, hs, offset, i.InputOperand(1)); \
__ addu(kScratchReg, i.InputRegister(3), offset); \
__ asm_instr(value, MemOperand(kScratchReg, 0)); \
} else { \
auto offset = i.InputOperand(0).immediate(); \
auto value = i.InputRegister(2); \
__ Branch(&done, ls, i.InputRegister(1), Operand(offset)); \
__ asm_instr(value, MemOperand(i.InputRegister(3), offset)); \
} \
__ bind(&done); \
} while (0)
#define ASSEMBLE_ROUND_DOUBLE_TO_DOUBLE(mode) \
if (IsMipsArchVariant(kMips32r6)) { \
__ cfc1(kScratchReg, FCSR); \
__ li(at, Operand(mode_##mode)); \
__ ctc1(at, FCSR); \
__ rint_d(i.OutputDoubleRegister(), i.InputDoubleRegister(0)); \
__ ctc1(kScratchReg, FCSR); \
} else { \
auto ool = new (zone()) OutOfLineRound(this, i.OutputDoubleRegister()); \
Label done; \
__ Mfhc1(kScratchReg, i.InputDoubleRegister(0)); \
__ Ext(at, kScratchReg, HeapNumber::kExponentShift, \
HeapNumber::kExponentBits); \
__ Branch(USE_DELAY_SLOT, &done, hs, at, \
Operand(HeapNumber::kExponentBias + HeapNumber::kMantissaBits)); \
__ mov_d(i.OutputDoubleRegister(), i.InputDoubleRegister(0)); \
__ mode##_l_d(i.OutputDoubleRegister(), i.InputDoubleRegister(0)); \
__ Move(at, kScratchReg2, i.OutputDoubleRegister()); \
__ or_(at, at, kScratchReg2); \
__ Branch(USE_DELAY_SLOT, ool->entry(), eq, at, Operand(zero_reg)); \
__ cvt_d_l(i.OutputDoubleRegister(), i.OutputDoubleRegister()); \
__ bind(ool->exit()); \
__ bind(&done); \
}
#define ASSEMBLE_ROUND_FLOAT_TO_FLOAT(mode) \
if (IsMipsArchVariant(kMips32r6)) { \
__ cfc1(kScratchReg, FCSR); \
__ li(at, Operand(mode_##mode)); \
__ ctc1(at, FCSR); \
__ rint_s(i.OutputDoubleRegister(), i.InputDoubleRegister(0)); \
__ ctc1(kScratchReg, FCSR); \
} else { \
int32_t kFloat32ExponentBias = 127; \
int32_t kFloat32MantissaBits = 23; \
int32_t kFloat32ExponentBits = 8; \
auto ool = new (zone()) OutOfLineRound32(this, i.OutputDoubleRegister()); \
Label done; \
__ mfc1(kScratchReg, i.InputDoubleRegister(0)); \
__ Ext(at, kScratchReg, kFloat32MantissaBits, kFloat32ExponentBits); \
__ Branch(USE_DELAY_SLOT, &done, hs, at, \
Operand(kFloat32ExponentBias + kFloat32MantissaBits)); \
__ mov_s(i.OutputDoubleRegister(), i.InputDoubleRegister(0)); \
__ mode##_w_s(i.OutputDoubleRegister(), i.InputDoubleRegister(0)); \
__ mfc1(at, i.OutputDoubleRegister()); \
__ Branch(USE_DELAY_SLOT, ool->entry(), eq, at, Operand(zero_reg)); \
__ cvt_s_w(i.OutputDoubleRegister(), i.OutputDoubleRegister()); \
__ bind(ool->exit()); \
__ bind(&done); \
}
#define ASSEMBLE_ATOMIC_LOAD_INTEGER(asm_instr) \
do { \
__ asm_instr(i.OutputRegister(), i.MemoryOperand()); \
__ sync(); \
} while (0)
#define ASSEMBLE_ATOMIC_STORE_INTEGER(asm_instr) \
do { \
__ sync(); \
__ asm_instr(i.InputRegister(2), i.MemoryOperand()); \
__ sync(); \
} while (0)
void CodeGenerator::AssembleDeconstructFrame() {
__ mov(sp, fp);
__ Pop(ra, fp);
}
void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) {
int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta);
if (sp_slot_delta > 0) {
__ addiu(sp, sp, sp_slot_delta * kPointerSize);
}
frame_access_state()->SetFrameAccessToDefault();
}
void CodeGenerator::AssemblePrepareTailCall(int stack_param_delta) {
int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta);
if (sp_slot_delta < 0) {
__ Subu(sp, sp, Operand(-sp_slot_delta * kPointerSize));
frame_access_state()->IncreaseSPDelta(-sp_slot_delta);
}
if (frame_access_state()->has_frame()) {
__ lw(ra, MemOperand(fp, StandardFrameConstants::kCallerPCOffset));
__ lw(fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
}
frame_access_state()->SetFrameAccessToSP();
}
void CodeGenerator::AssemblePopArgumentsAdaptorFrame(Register args_reg,
Register scratch1,
Register scratch2,
Register scratch3) {
DCHECK(!AreAliased(args_reg, scratch1, scratch2, scratch3));
Label done;
// Check if current frame is an arguments adaptor frame.
__ lw(scratch1, MemOperand(fp, StandardFrameConstants::kContextOffset));
__ Branch(&done, ne, scratch1,
Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
// Load arguments count from current arguments adaptor frame (note, it
// does not include receiver).
Register caller_args_count_reg = scratch1;
__ lw(caller_args_count_reg,
MemOperand(fp, ArgumentsAdaptorFrameConstants::kLengthOffset));
__ SmiUntag(caller_args_count_reg);
ParameterCount callee_args_count(args_reg);
__ PrepareForTailCall(callee_args_count, caller_args_count_reg, scratch2,
scratch3);
__ bind(&done);
}
// Assembles an instruction after register allocation, producing machine code.
CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
Instruction* instr) {
MipsOperandConverter i(this, instr);
InstructionCode opcode = instr->opcode();
ArchOpcode arch_opcode = ArchOpcodeField::decode(opcode);
switch (arch_opcode) {
case kArchCallCodeObject: {
EnsureSpaceForLazyDeopt();
if (instr->InputAt(0)->IsImmediate()) {
__ Call(Handle<Code>::cast(i.InputHeapObject(0)),
RelocInfo::CODE_TARGET);
} else {
__ addiu(at, i.InputRegister(0), Code::kHeaderSize - kHeapObjectTag);
__ Call(at);
}
RecordCallPosition(instr);
frame_access_state()->ClearSPDelta();
break;
}
case kArchTailCallCodeObjectFromJSFunction:
case kArchTailCallCodeObject: {
int stack_param_delta = i.InputInt32(instr->InputCount() - 1);
AssembleDeconstructActivationRecord(stack_param_delta);
if (arch_opcode == kArchTailCallCodeObjectFromJSFunction) {
AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister,
i.TempRegister(0), i.TempRegister(1),
i.TempRegister(2));
}
if (instr->InputAt(0)->IsImmediate()) {
__ Jump(Handle<Code>::cast(i.InputHeapObject(0)),
RelocInfo::CODE_TARGET);
} else {
__ addiu(at, i.InputRegister(0), Code::kHeaderSize - kHeapObjectTag);
__ Jump(at);
}
frame_access_state()->ClearSPDelta();
break;
}
case kArchTailCallAddress: {
int stack_param_delta = i.InputInt32(instr->InputCount() - 1);
AssembleDeconstructActivationRecord(stack_param_delta);
CHECK(!instr->InputAt(0)->IsImmediate());
__ Jump(i.InputRegister(0));
frame_access_state()->ClearSPDelta();
break;
}
case kArchCallJSFunction: {
EnsureSpaceForLazyDeopt();
Register func = i.InputRegister(0);
if (FLAG_debug_code) {
// Check the function's context matches the context argument.
__ lw(kScratchReg, FieldMemOperand(func, JSFunction::kContextOffset));
__ Assert(eq, kWrongFunctionContext, cp, Operand(kScratchReg));
}
__ lw(at, FieldMemOperand(func, JSFunction::kCodeEntryOffset));
__ Call(at);
RecordCallPosition(instr);
frame_access_state()->ClearSPDelta();
break;
}
case kArchTailCallJSFunctionFromJSFunction:
case kArchTailCallJSFunction: {
Register func = i.InputRegister(0);
if (FLAG_debug_code) {
// Check the function's context matches the context argument.
__ lw(kScratchReg, FieldMemOperand(func, JSFunction::kContextOffset));
__ Assert(eq, kWrongFunctionContext, cp, Operand(kScratchReg));
}
int stack_param_delta = i.InputInt32(instr->InputCount() - 1);
AssembleDeconstructActivationRecord(stack_param_delta);
if (arch_opcode == kArchTailCallJSFunctionFromJSFunction) {
AssemblePopArgumentsAdaptorFrame(kJavaScriptCallArgCountRegister,
i.TempRegister(0), i.TempRegister(1),
i.TempRegister(2));
}
__ lw(at, FieldMemOperand(func, JSFunction::kCodeEntryOffset));
__ Jump(at);
frame_access_state()->ClearSPDelta();
break;
}
case kArchPrepareCallCFunction: {
int const num_parameters = MiscField::decode(instr->opcode());
__ PrepareCallCFunction(num_parameters, kScratchReg);
// Frame alignment requires using FP-relative frame addressing.
frame_access_state()->SetFrameAccessToFP();
break;
}
case kArchPrepareTailCall:
AssemblePrepareTailCall(i.InputInt32(instr->InputCount() - 1));
break;
case kArchCallCFunction: {
int const num_parameters = MiscField::decode(instr->opcode());
if (instr->InputAt(0)->IsImmediate()) {
ExternalReference ref = i.InputExternalReference(0);
__ CallCFunction(ref, num_parameters);
} else {
Register func = i.InputRegister(0);
__ CallCFunction(func, num_parameters);
}
frame_access_state()->SetFrameAccessToDefault();
frame_access_state()->ClearSPDelta();
break;
}
case kArchJmp:
AssembleArchJump(i.InputRpo(0));
break;
case kArchLookupSwitch:
AssembleArchLookupSwitch(instr);
break;
case kArchTableSwitch:
AssembleArchTableSwitch(instr);
break;
case kArchDebugBreak:
__ stop("kArchDebugBreak");
break;
case kArchNop:
case kArchThrowTerminator:
// don't emit code for nops.
break;
case kArchDeoptimize: {
int deopt_state_id =
BuildTranslation(instr, -1, 0, OutputFrameStateCombine::Ignore());
Deoptimizer::BailoutType bailout_type =
Deoptimizer::BailoutType(MiscField::decode(instr->opcode()));
CodeGenResult result =
AssembleDeoptimizerCall(deopt_state_id, bailout_type);
if (result != kSuccess) return result;
break;
}
case kArchRet:
AssembleReturn();
break;
case kArchStackPointer:
__ mov(i.OutputRegister(), sp);
break;
case kArchFramePointer:
__ mov(i.OutputRegister(), fp);
break;
case kArchParentFramePointer:
if (frame_access_state()->has_frame()) {
__ lw(i.OutputRegister(), MemOperand(fp, 0));
} else {
__ mov(i.OutputRegister(), fp);
}
break;
case kArchTruncateDoubleToI:
__ TruncateDoubleToI(i.OutputRegister(), i.InputDoubleRegister(0));
break;
case kArchStoreWithWriteBarrier: {
RecordWriteMode mode =
static_cast<RecordWriteMode>(MiscField::decode(instr->opcode()));
Register object = i.InputRegister(0);
Register index = i.InputRegister(1);
Register value = i.InputRegister(2);
Register scratch0 = i.TempRegister(0);
Register scratch1 = i.TempRegister(1);
auto ool = new (zone()) OutOfLineRecordWrite(this, object, index, value,
scratch0, scratch1, mode);
__ Addu(at, object, index);
__ sw(value, MemOperand(at));
__ CheckPageFlag(object, scratch0,
MemoryChunk::kPointersFromHereAreInterestingMask, ne,
ool->entry());
__ bind(ool->exit());
break;
}
case kArchStackSlot: {
FrameOffset offset =
frame_access_state()->GetFrameOffset(i.InputInt32(0));
__ Addu(i.OutputRegister(), offset.from_stack_pointer() ? sp : fp,
Operand(offset.offset()));
break;
}
case kMipsAdd:
__ Addu(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
break;
case kMipsAddOvf:
// Pseudo-instruction used for overflow/branch. No opcode emitted here.
break;
case kMipsSub:
__ Subu(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
break;
case kMipsSubOvf:
// Pseudo-instruction used for overflow/branch. No opcode emitted here.
break;
case kMipsMul:
__ Mul(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
break;
case kMipsMulHigh:
__ Mulh(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
break;
case kMipsMulHighU:
__ Mulhu(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
break;
case kMipsDiv:
__ Div(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
if (IsMipsArchVariant(kMips32r6)) {
__ selnez(i.OutputRegister(), i.InputRegister(0), i.InputRegister(1));
} else {
__ Movz(i.OutputRegister(), i.InputRegister(1), i.InputRegister(1));
}
break;
case kMipsDivU:
__ Divu(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
if (IsMipsArchVariant(kMips32r6)) {
__ selnez(i.OutputRegister(), i.InputRegister(0), i.InputRegister(1));
} else {
__ Movz(i.OutputRegister(), i.InputRegister(1), i.InputRegister(1));
}
break;
case kMipsMod:
__ Mod(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
break;
case kMipsModU:
__ Modu(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
break;
case kMipsAnd:
__ And(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
break;
case kMipsOr:
__ Or(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
break;
case kMipsNor:
if (instr->InputAt(1)->IsRegister()) {
__ Nor(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
} else {
DCHECK(i.InputOperand(1).immediate() == 0);
__ Nor(i.OutputRegister(), i.InputRegister(0), zero_reg);
}
break;
case kMipsXor:
__ Xor(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
break;
case kMipsClz:
__ Clz(i.OutputRegister(), i.InputRegister(0));
break;
case kMipsCtz: {
Register reg1 = kScratchReg;
Register reg2 = kScratchReg2;
Label skip_for_zero;
Label end;
// Branch if the operand is zero
__ Branch(&skip_for_zero, eq, i.InputRegister(0), Operand(zero_reg));
// Find the number of bits before the last bit set to 1.
__ Subu(reg2, zero_reg, i.InputRegister(0));
__ And(reg2, reg2, i.InputRegister(0));
__ clz(reg2, reg2);
// Get the number of bits after the last bit set to 1.
__ li(reg1, 0x1F);
__ Subu(i.OutputRegister(), reg1, reg2);
__ Branch(&end);
__ bind(&skip_for_zero);
// If the operand is zero, return word length as the result.
__ li(i.OutputRegister(), 0x20);
__ bind(&end);
} break;
case kMipsPopcnt: {
Register reg1 = kScratchReg;
Register reg2 = kScratchReg2;
uint32_t m1 = 0x55555555;
uint32_t m2 = 0x33333333;
uint32_t m4 = 0x0f0f0f0f;
uint32_t m8 = 0x00ff00ff;
uint32_t m16 = 0x0000ffff;
// Put count of ones in every 2 bits into those 2 bits.
__ li(at, m1);
__ srl(reg1, i.InputRegister(0), 1);
__ And(reg2, i.InputRegister(0), at);
__ And(reg1, reg1, at);
__ addu(reg1, reg1, reg2);
// Put count of ones in every 4 bits into those 4 bits.
__ li(at, m2);
__ srl(reg2, reg1, 2);
__ And(reg2, reg2, at);
__ And(reg1, reg1, at);
__ addu(reg1, reg1, reg2);
// Put count of ones in every 8 bits into those 8 bits.
__ li(at, m4);
__ srl(reg2, reg1, 4);
__ And(reg2, reg2, at);
__ And(reg1, reg1, at);
__ addu(reg1, reg1, reg2);
// Put count of ones in every 16 bits into those 16 bits.
__ li(at, m8);
__ srl(reg2, reg1, 8);
__ And(reg2, reg2, at);
__ And(reg1, reg1, at);
__ addu(reg1, reg1, reg2);
// Calculate total number of ones.
__ li(at, m16);
__ srl(reg2, reg1, 16);
__ And(reg2, reg2, at);
__ And(reg1, reg1, at);
__ addu(i.OutputRegister(), reg1, reg2);
} break;
case kMipsShl:
if (instr->InputAt(1)->IsRegister()) {
__ sllv(i.OutputRegister(), i.InputRegister(0), i.InputRegister(1));
} else {
int32_t imm = i.InputOperand(1).immediate();
__ sll(i.OutputRegister(), i.InputRegister(0), imm);
}
break;
case kMipsShr:
if (instr->InputAt(1)->IsRegister()) {
__ srlv(i.OutputRegister(), i.InputRegister(0), i.InputRegister(1));
} else {
int32_t imm = i.InputOperand(1).immediate();
__ srl(i.OutputRegister(), i.InputRegister(0), imm);
}
break;
case kMipsSar:
if (instr->InputAt(1)->IsRegister()) {
__ srav(i.OutputRegister(), i.InputRegister(0), i.InputRegister(1));
} else {
int32_t imm = i.InputOperand(1).immediate();
__ sra(i.OutputRegister(), i.InputRegister(0), imm);
}
break;
case kMipsShlPair: {
if (instr->InputAt(2)->IsRegister()) {
__ ShlPair(i.OutputRegister(0), i.OutputRegister(1), i.InputRegister(0),
i.InputRegister(1), i.InputRegister(2));
} else {
uint32_t imm = i.InputOperand(2).immediate();
__ ShlPair(i.OutputRegister(0), i.OutputRegister(1), i.InputRegister(0),
i.InputRegister(1), imm);
}
} break;
case kMipsShrPair: {
if (instr->InputAt(2)->IsRegister()) {
__ ShrPair(i.OutputRegister(0), i.OutputRegister(1), i.InputRegister(0),
i.InputRegister(1), i.InputRegister(2));
} else {
uint32_t imm = i.InputOperand(2).immediate();
__ ShrPair(i.OutputRegister(0), i.OutputRegister(1), i.InputRegister(0),
i.InputRegister(1), imm);
}
} break;
case kMipsSarPair: {
if (instr->InputAt(2)->IsRegister()) {
__ SarPair(i.OutputRegister(0), i.OutputRegister(1), i.InputRegister(0),
i.InputRegister(1), i.InputRegister(2));
} else {
uint32_t imm = i.InputOperand(2).immediate();
__ SarPair(i.OutputRegister(0), i.OutputRegister(1), i.InputRegister(0),
i.InputRegister(1), imm);
}
} break;
case kMipsExt:
__ Ext(i.OutputRegister(), i.InputRegister(0), i.InputInt8(1),
i.InputInt8(2));
break;
case kMipsIns:
if (instr->InputAt(1)->IsImmediate() && i.InputInt8(1) == 0) {
__ Ins(i.OutputRegister(), zero_reg, i.InputInt8(1), i.InputInt8(2));
} else {
__ Ins(i.OutputRegister(), i.InputRegister(0), i.InputInt8(1),
i.InputInt8(2));
}
break;
case kMipsRor:
__ Ror(i.OutputRegister(), i.InputRegister(0), i.InputOperand(1));
break;
case kMipsTst:
// Pseudo-instruction used for tst/branch. No opcode emitted here.
break;
case kMipsCmp:
// Pseudo-instruction used for cmp/branch. No opcode emitted here.
break;
case kMipsMov:
// TODO(plind): Should we combine mov/li like this, or use separate instr?
// - Also see x64 ASSEMBLE_BINOP & RegisterOrOperandType
if (HasRegisterInput(instr, 0)) {
__ mov(i.OutputRegister(), i.InputRegister(0));
} else {
__ li(i.OutputRegister(), i.InputOperand(0));
}
break;
case kMipsLsa:
DCHECK(instr->InputAt(2)->IsImmediate());
__ Lsa(i.OutputRegister(), i.InputRegister(0), i.InputRegister(1),
i.InputInt8(2));
break;
case kMipsCmpS:
// Psuedo-instruction used for FP cmp/branch. No opcode emitted here.
break;
case kMipsAddS:
// TODO(plind): add special case: combine mult & add.
__ add_s(i.OutputDoubleRegister(), i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
break;
case kMipsSubS:
__ sub_s(i.OutputDoubleRegister(), i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
break;
case kMipsMulS:
// TODO(plind): add special case: right op is -1.0, see arm port.
__ mul_s(i.OutputDoubleRegister(), i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
break;
case kMipsDivS:
__ div_s(i.OutputDoubleRegister(), i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
break;
case kMipsModS: {
// TODO(bmeurer): We should really get rid of this special instruction,
// and generate a CallAddress instruction instead.
FrameScope scope(masm(), StackFrame::MANUAL);
__ PrepareCallCFunction(0, 2, kScratchReg);
__ MovToFloatParameters(i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
// TODO(balazs.kilvady): implement mod_two_floats_operation(isolate())
__ CallCFunction(ExternalReference::mod_two_doubles_operation(isolate()),
0, 2);
// Move the result in the double result register.
__ MovFromFloatResult(i.OutputSingleRegister());
break;
}
case kMipsAbsS:
__ abs_s(i.OutputSingleRegister(), i.InputSingleRegister(0));
break;
case kMipsSqrtS: {
__ sqrt_s(i.OutputDoubleRegister(), i.InputDoubleRegister(0));
break;
}
case kMipsMaxS:
__ max_s(i.OutputDoubleRegister(), i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
break;
case kMipsMinS:
__ min_s(i.OutputDoubleRegister(), i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
break;
case kMipsCmpD:
// Psuedo-instruction used for FP cmp/branch. No opcode emitted here.
break;
case kMipsAddPair:
__ AddPair(i.OutputRegister(0), i.OutputRegister(1), i.InputRegister(0),
i.InputRegister(1), i.InputRegister(2), i.InputRegister(3));
break;
case kMipsSubPair:
__ SubPair(i.OutputRegister(0), i.OutputRegister(1), i.InputRegister(0),
i.InputRegister(1), i.InputRegister(2), i.InputRegister(3));
break;
case kMipsMulPair: {
__ Mulu(i.OutputRegister(1), i.OutputRegister(0), i.InputRegister(0),
i.InputRegister(2));
__ mul(kScratchReg, i.InputRegister(0), i.InputRegister(3));
__ mul(kScratchReg2, i.InputRegister(1), i.InputRegister(2));
__ Addu(i.OutputRegister(1), i.OutputRegister(1), kScratchReg);
__ Addu(i.OutputRegister(1), i.OutputRegister(1), kScratchReg2);
} break;
case kMipsAddD:
// TODO(plind): add special case: combine mult & add.
__ add_d(i.OutputDoubleRegister(), i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
break;
case kMipsSubD:
__ sub_d(i.OutputDoubleRegister(), i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
break;
case kMipsMulD:
// TODO(plind): add special case: right op is -1.0, see arm port.
__ mul_d(i.OutputDoubleRegister(), i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
break;
case kMipsDivD:
__ div_d(i.OutputDoubleRegister(), i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
break;
case kMipsModD: {
// TODO(bmeurer): We should really get rid of this special instruction,
// and generate a CallAddress instruction instead.
FrameScope scope(masm(), StackFrame::MANUAL);
__ PrepareCallCFunction(0, 2, kScratchReg);
__ MovToFloatParameters(i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
__ CallCFunction(ExternalReference::mod_two_doubles_operation(isolate()),
0, 2);
// Move the result in the double result register.
__ MovFromFloatResult(i.OutputDoubleRegister());
break;
}
case kMipsAbsD:
__ abs_d(i.OutputDoubleRegister(), i.InputDoubleRegister(0));
break;
case kMipsSqrtD: {
__ sqrt_d(i.OutputDoubleRegister(), i.InputDoubleRegister(0));
break;
}
case kMipsMaxD:
__ max_d(i.OutputDoubleRegister(), i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
break;
case kMipsMinD:
__ min_d(i.OutputDoubleRegister(), i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
break;
case kMipsFloat64RoundDown: {
ASSEMBLE_ROUND_DOUBLE_TO_DOUBLE(floor);
break;
}
case kMipsFloat32RoundDown: {
ASSEMBLE_ROUND_FLOAT_TO_FLOAT(floor);
break;
}
case kMipsFloat64RoundTruncate: {
ASSEMBLE_ROUND_DOUBLE_TO_DOUBLE(trunc);
break;
}
case kMipsFloat32RoundTruncate: {
ASSEMBLE_ROUND_FLOAT_TO_FLOAT(trunc);
break;
}
case kMipsFloat64RoundUp: {
ASSEMBLE_ROUND_DOUBLE_TO_DOUBLE(ceil);
break;
}
case kMipsFloat32RoundUp: {
ASSEMBLE_ROUND_FLOAT_TO_FLOAT(ceil);
break;
}
case kMipsFloat64RoundTiesEven: {
ASSEMBLE_ROUND_DOUBLE_TO_DOUBLE(round);
break;
}
case kMipsFloat32RoundTiesEven: {
ASSEMBLE_ROUND_FLOAT_TO_FLOAT(round);
break;
}
case kMipsFloat64Max: {
// (b < a) ? a : b
if (IsMipsArchVariant(kMips32r6)) {
__ cmp_d(OLT, i.OutputDoubleRegister(), i.InputDoubleRegister(1),
i.InputDoubleRegister(0));
__ sel_d(i.OutputDoubleRegister(), i.InputDoubleRegister(1),
i.InputDoubleRegister(0));
} else {
__ c_d(OLT, i.InputDoubleRegister(0), i.InputDoubleRegister(1));
// Left operand is result, passthrough if false.
__ movt_d(i.OutputDoubleRegister(), i.InputDoubleRegister(1));
}
break;
}
case kMipsFloat64Min: {
// (a < b) ? a : b
if (IsMipsArchVariant(kMips32r6)) {
__ cmp_d(OLT, i.OutputDoubleRegister(), i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
__ sel_d(i.OutputDoubleRegister(), i.InputDoubleRegister(1),
i.InputDoubleRegister(0));
} else {
__ c_d(OLT, i.InputDoubleRegister(1), i.InputDoubleRegister(0));
// Right operand is result, passthrough if false.
__ movt_d(i.OutputDoubleRegister(), i.InputDoubleRegister(1));
}
break;
}
case kMipsFloat32Max: {
// (b < a) ? a : b
if (IsMipsArchVariant(kMips32r6)) {
__ cmp_s(OLT, i.OutputDoubleRegister(), i.InputDoubleRegister(1),
i.InputDoubleRegister(0));
__ sel_s(i.OutputDoubleRegister(), i.InputDoubleRegister(1),
i.InputDoubleRegister(0));
} else {
__ c_s(OLT, i.InputDoubleRegister(0), i.InputDoubleRegister(1));
// Left operand is result, passthrough if false.
__ movt_s(i.OutputDoubleRegister(), i.InputDoubleRegister(1));
}
break;
}
case kMipsFloat32Min: {
// (a < b) ? a : b
if (IsMipsArchVariant(kMips32r6)) {
__ cmp_s(OLT, i.OutputDoubleRegister(), i.InputDoubleRegister(0),
i.InputDoubleRegister(1));
__ sel_s(i.OutputDoubleRegister(), i.InputDoubleRegister(1),
i.InputDoubleRegister(0));
} else {
__ c_s(OLT, i.InputDoubleRegister(1), i.InputDoubleRegister(0));
// Right operand is result, passthrough if false.
__ movt_s(i.OutputDoubleRegister(), i.InputDoubleRegister(1));
}
break;
}
case kMipsCvtSD: {
__ cvt_s_d(i.OutputSingleRegister(), i.InputDoubleRegister(0));
break;
}
case kMipsCvtDS: {
__ cvt_d_s(i.OutputDoubleRegister(), i.InputSingleRegister(0));
break;
}
case kMipsCvtDW: {
FPURegister scratch = kScratchDoubleReg;
__ mtc1(i.InputRegister(0), scratch);
__ cvt_d_w(i.OutputDoubleRegister(), scratch);
break;
}
case kMipsCvtSW: {
FPURegister scratch = kScratchDoubleReg;
__ mtc1(i.InputRegister(0), scratch);
__ cvt_s_w(i.OutputDoubleRegister(), scratch);
break;
}
case kMipsCvtSUw: {
FPURegister scratch = kScratchDoubleReg;
__ Cvt_d_uw(i.OutputDoubleRegister(), i.InputRegister(0), scratch);
__ cvt_s_d(i.OutputDoubleRegister(), i.OutputDoubleRegister());
break;
}
case kMipsCvtDUw: {
FPURegister scratch = kScratchDoubleReg;
__ Cvt_d_uw(i.OutputDoubleRegister(), i.InputRegister(0), scratch);
break;
}
case kMipsFloorWD: {
FPURegister scratch = kScratchDoubleReg;
__ floor_w_d(scratch, i.InputDoubleRegister(0));
__ mfc1(i.OutputRegister(), scratch);
break;
}
case kMipsCeilWD: {
FPURegister scratch = kScratchDoubleReg;
__ ceil_w_d(scratch, i.InputDoubleRegister(0));
__ mfc1(i.OutputRegister(), scratch);
break;
}
case kMipsRoundWD: {
FPURegister scratch = kScratchDoubleReg;
__ round_w_d(scratch, i.InputDoubleRegister(0));
__ mfc1(i.OutputRegister(), scratch);
break;
}
case kMipsTruncWD: {
FPURegister scratch = kScratchDoubleReg;
// Other arches use round to zero here, so we follow.
__ trunc_w_d(scratch, i.InputDoubleRegister(0));
__ mfc1(i.OutputRegister(), scratch);
break;
}
case kMipsFloorWS: {
FPURegister scratch = kScratchDoubleReg;
__ floor_w_s(scratch, i.InputDoubleRegister(0));
__ mfc1(i.OutputRegister(), scratch);
break;
}
case kMipsCeilWS: {
FPURegister scratch = kScratchDoubleReg;
__ ceil_w_s(scratch, i.InputDoubleRegister(0));
__ mfc1(i.OutputRegister(), scratch);
break;
}
case kMipsRoundWS: {
FPURegister scratch = kScratchDoubleReg;
__ round_w_s(scratch, i.InputDoubleRegister(0));
__ mfc1(i.OutputRegister(), scratch);
break;
}
case kMipsTruncWS: {
FPURegister scratch = kScratchDoubleReg;
__ trunc_w_s(scratch, i.InputDoubleRegister(0));
__ mfc1(i.OutputRegister(), scratch);
break;
}
case kMipsTruncUwD: {
FPURegister scratch = kScratchDoubleReg;
// TODO(plind): Fix wrong param order of Trunc_uw_d() macro-asm function.
__ Trunc_uw_d(i.InputDoubleRegister(0), i.OutputRegister(), scratch);
break;
}
case kMipsTruncUwS: {
FPURegister scratch = kScratchDoubleReg;
// TODO(plind): Fix wrong param order of Trunc_uw_s() macro-asm function.
__ Trunc_uw_s(i.InputDoubleRegister(0), i.OutputRegister(), scratch);
break;
}
case kMipsFloat64ExtractLowWord32:
__ FmoveLow(i.OutputRegister(), i.InputDoubleRegister(0));
break;
case kMipsFloat64ExtractHighWord32:
__ FmoveHigh(i.OutputRegister(), i.InputDoubleRegister(0));
break;
case kMipsFloat64InsertLowWord32:
__ FmoveLow(i.OutputDoubleRegister(), i.InputRegister(1));
break;
case kMipsFloat64InsertHighWord32:
__ FmoveHigh(i.OutputDoubleRegister(), i.InputRegister(1));
break;
// ... more basic instructions ...
case kMipsLbu:
__ lbu(i.OutputRegister(), i.MemoryOperand());
break;
case kMipsLb:
__ lb(i.OutputRegister(), i.MemoryOperand());
break;
case kMipsSb:
__ sb(i.InputRegister(2), i.MemoryOperand());
break;
case kMipsLhu:
__ lhu(i.OutputRegister(), i.MemoryOperand());
break;
case kMipsLh:
__ lh(i.OutputRegister(), i.MemoryOperand());
break;
case kMipsSh:
__ sh(i.InputRegister(2), i.MemoryOperand());
break;
case kMipsLw:
__ lw(i.OutputRegister(), i.MemoryOperand());
break;
case kMipsSw:
__ sw(i.InputRegister(2), i.MemoryOperand());
break;
case kMipsLwc1: {
__ lwc1(i.OutputSingleRegister(), i.MemoryOperand());
break;
}
case kMipsSwc1: {
size_t index = 0;
MemOperand operand = i.MemoryOperand(&index);
__ swc1(i.InputSingleRegister(index), operand);
break;
}
case kMipsLdc1:
__ ldc1(i.OutputDoubleRegister(), i.MemoryOperand());
break;
case kMipsSdc1:
__ sdc1(i.InputDoubleRegister(2), i.MemoryOperand());
break;
case kMipsPush:
if (instr->InputAt(0)->IsFPRegister()) {
__ sdc1(i.InputDoubleRegister(0), MemOperand(sp, -kDoubleSize));
__ Subu(sp, sp, Operand(kDoubleSize));
frame_access_state()->IncreaseSPDelta(kDoubleSize / kPointerSize);
} else {
__ Push(i.InputRegister(0));
frame_access_state()->IncreaseSPDelta(1);
}
break;
case kMipsStackClaim: {
__ Subu(sp, sp, Operand(i.InputInt32(0)));
frame_access_state()->IncreaseSPDelta(i.InputInt32(0) / kPointerSize);
break;
}
case kMipsStoreToStackSlot: {
if (instr->InputAt(0)->IsFPRegister()) {
__ sdc1(i.InputDoubleRegister(0), MemOperand(sp, i.InputInt32(1)));
} else {
__ sw(i.InputRegister(0), MemOperand(sp, i.InputInt32(1)));
}
break;
}
case kCheckedLoadInt8:
ASSEMBLE_CHECKED_LOAD_INTEGER(lb);
break;
case kCheckedLoadUint8:
ASSEMBLE_CHECKED_LOAD_INTEGER(lbu);
break;
case kCheckedLoadInt16:
ASSEMBLE_CHECKED_LOAD_INTEGER(lh);
break;
case kCheckedLoadUint16:
ASSEMBLE_CHECKED_LOAD_INTEGER(lhu);
break;
case kCheckedLoadWord32:
ASSEMBLE_CHECKED_LOAD_INTEGER(lw);
break;
case kCheckedLoadFloat32:
ASSEMBLE_CHECKED_LOAD_FLOAT(Single, lwc1);
break;
case kCheckedLoadFloat64:
ASSEMBLE_CHECKED_LOAD_FLOAT(Double, ldc1);
break;
case kCheckedStoreWord8:
ASSEMBLE_CHECKED_STORE_INTEGER(sb);
break;
case kCheckedStoreWord16:
ASSEMBLE_CHECKED_STORE_INTEGER(sh);
break;
case kCheckedStoreWord32:
ASSEMBLE_CHECKED_STORE_INTEGER(sw);
break;
case kCheckedStoreFloat32:
ASSEMBLE_CHECKED_STORE_FLOAT(Single, swc1);
break;
case kCheckedStoreFloat64:
ASSEMBLE_CHECKED_STORE_FLOAT(Double, sdc1);
break;
case kCheckedLoadWord64:
case kCheckedStoreWord64:
UNREACHABLE(); // currently unsupported checked int64 load/store.
break;
case kAtomicLoadInt8:
ASSEMBLE_ATOMIC_LOAD_INTEGER(lb);
break;
case kAtomicLoadUint8:
ASSEMBLE_ATOMIC_LOAD_INTEGER(lbu);
break;
case kAtomicLoadInt16:
ASSEMBLE_ATOMIC_LOAD_INTEGER(lh);
break;
case kAtomicLoadUint16:
ASSEMBLE_ATOMIC_LOAD_INTEGER(lhu);
break;
case kAtomicLoadWord32:
ASSEMBLE_ATOMIC_LOAD_INTEGER(lw);
break;
case kAtomicStoreWord8:
ASSEMBLE_ATOMIC_STORE_INTEGER(sb);
break;
case kAtomicStoreWord16:
ASSEMBLE_ATOMIC_STORE_INTEGER(sh);
break;
case kAtomicStoreWord32:
ASSEMBLE_ATOMIC_STORE_INTEGER(sw);
break;
}
return kSuccess;
} // NOLINT(readability/fn_size)
#define UNSUPPORTED_COND(opcode, condition) \
OFStream out(stdout); \
out << "Unsupported " << #opcode << " condition: \"" << condition << "\""; \
UNIMPLEMENTED();
static bool convertCondition(FlagsCondition condition, Condition& cc) {
switch (condition) {
case kEqual:
cc = eq;
return true;
case kNotEqual:
cc = ne;
return true;
case kUnsignedLessThan:
cc = lt;
return true;
case kUnsignedGreaterThanOrEqual:
cc = uge;
return true;
case kUnsignedLessThanOrEqual:
cc = le;
return true;
case kUnsignedGreaterThan:
cc = ugt;
return true;
default:
break;
}
return false;
}
// Assembles branches after an instruction.
void CodeGenerator::AssembleArchBranch(Instruction* instr, BranchInfo* branch) {
MipsOperandConverter i(this, instr);
Label* tlabel = branch->true_label;
Label* flabel = branch->false_label;
Condition cc = kNoCondition;
// MIPS does not have condition code flags, so compare and branch are
// implemented differently than on the other arch's. The compare operations
// emit mips pseudo-instructions, which are handled here by branch
// instructions that do the actual comparison. Essential that the input
// registers to compare pseudo-op are not modified before this branch op, as
// they are tested here.
if (instr->arch_opcode() == kMipsTst) {
cc = FlagsConditionToConditionTst(branch->condition);
__ And(at, i.InputRegister(0), i.InputOperand(1));
__ Branch(tlabel, cc, at, Operand(zero_reg));
} else if (instr->arch_opcode() == kMipsAddOvf) {
switch (branch->condition) {
case kOverflow:
__ AddBranchOvf(i.OutputRegister(), i.InputRegister(0),
i.InputOperand(1), tlabel, flabel);
break;
case kNotOverflow:
__ AddBranchOvf(i.OutputRegister(), i.InputRegister(0),
i.InputOperand(1), flabel, tlabel);
break;
default:
UNSUPPORTED_COND(kMipsAddOvf, branch->condition);
break;
}
} else if (instr->arch_opcode() == kMipsSubOvf) {
switch (branch->condition) {
case kOverflow:
__ SubBranchOvf(i.OutputRegister(), i.InputRegister(0),
i.InputOperand(1), tlabel, flabel);
break;
case kNotOverflow:
__ SubBranchOvf(i.OutputRegister(), i.InputRegister(0),
i.InputOperand(1), flabel, tlabel);
break;
default:
UNSUPPORTED_COND(kMipsAddOvf, branch->condition);
break;
}
} else if (instr->arch_opcode() == kMipsCmp) {
cc = FlagsConditionToConditionCmp(branch->condition);
__ Branch(tlabel, cc, i.InputRegister(0), i.InputOperand(1));
} else if (instr->arch_opcode() == kMipsCmpS) {
if (!convertCondition(branch->condition, cc)) {
UNSUPPORTED_COND(kMips64CmpS, branch->condition);
}
FPURegister left = i.InputOrZeroSingleRegister(0);
FPURegister right = i.InputOrZeroSingleRegister(1);
if ((left.is(kDoubleRegZero) || right.is(kDoubleRegZero)) &&
!__ IsDoubleZeroRegSet()) {
__ Move(kDoubleRegZero, 0.0);
}
__ BranchF32(tlabel, nullptr, cc, left, right);
} else if (instr->arch_opcode() == kMipsCmpD) {
if (!convertCondition(branch->condition, cc)) {
UNSUPPORTED_COND(kMips64CmpD, branch->condition);
}
FPURegister left = i.InputOrZeroDoubleRegister(0);
FPURegister right = i.InputOrZeroDoubleRegister(1);
if ((left.is(kDoubleRegZero) || right.is(kDoubleRegZero)) &&
!__ IsDoubleZeroRegSet()) {
__ Move(kDoubleRegZero, 0.0);
}
__ BranchF64(tlabel, nullptr, cc, left, right);
} else {
PrintF("AssembleArchBranch Unimplemented arch_opcode: %d\n",
instr->arch_opcode());
UNIMPLEMENTED();
}
if (!branch->fallthru) __ Branch(flabel); // no fallthru to flabel.
}
void CodeGenerator::AssembleArchJump(RpoNumber target) {
if (!IsNextInAssemblyOrder(target)) __ Branch(GetLabel(target));
}
// Assembles boolean materializations after an instruction.
void CodeGenerator::AssembleArchBoolean(Instruction* instr,
FlagsCondition condition) {
MipsOperandConverter i(this, instr);
Label done;
// Materialize a full 32-bit 1 or 0 value. The result register is always the
// last output of the instruction.
Label false_value;
DCHECK_NE(0u, instr->OutputCount());
Register result = i.OutputRegister(instr->OutputCount() - 1);
Condition cc = kNoCondition;
// MIPS does not have condition code flags, so compare and branch are
// implemented differently than on the other arch's. The compare operations
// emit mips psuedo-instructions, which are checked and handled here.
if (instr->arch_opcode() == kMipsTst) {
cc = FlagsConditionToConditionTst(condition);
__ And(kScratchReg, i.InputRegister(0), i.InputOperand(1));
__ Sltu(result, zero_reg, kScratchReg);
if (cc == eq) {
// Sltu produces 0 for equality, invert the result.
__ xori(result, result, 1);
}
return;
} else if (instr->arch_opcode() == kMipsAddOvf ||
instr->arch_opcode() == kMipsSubOvf) {
Label flabel, tlabel;
switch (instr->arch_opcode()) {
case kMipsAddOvf:
__ AddBranchNoOvf(i.OutputRegister(), i.InputRegister(0),
i.InputOperand(1), &flabel);
break;
case kMipsSubOvf:
__ SubBranchNoOvf(i.OutputRegister(), i.InputRegister(0),
i.InputOperand(1), &flabel);
break;
default:
UNREACHABLE();
break;
}
__ li(result, 1);
__ Branch(&tlabel);
__ bind(&flabel);
__ li(result, 0);
__ bind(&tlabel);
} else if (instr->arch_opcode() == kMipsCmp) {
cc = FlagsConditionToConditionCmp(condition);
switch (cc) {
case eq:
case ne: {
Register left = i.InputRegister(0);
Operand right = i.InputOperand(1);
Register select;
if (instr->InputAt(1)->IsImmediate() && right.immediate() == 0) {
// Pass left operand if right is zero.
select = left;
} else {
__ Subu(kScratchReg, left, right);
select = kScratchReg;
}
__ Sltu(result, zero_reg, select);
if (cc == eq) {
// Sltu produces 0 for equality, invert the result.
__ xori(result, result, 1);
}
} break;
case lt:
case ge: {
Register left = i.InputRegister(0);
Operand right = i.InputOperand(1);
__ Slt(result, left, right);
if (cc == ge) {
__ xori(result, result, 1);
}
} break;
case gt:
case le: {
Register left = i.InputRegister(1);
Operand right = i.InputOperand(0);
__ Slt(result, left, right);
if (cc == le) {
__ xori(result, result, 1);
}
} break;
case lo:
case hs: {
Register left = i.InputRegister(0);
Operand right = i.InputOperand(1);
__ Sltu(result, left, right);
if (cc == hs) {
__ xori(result, result, 1);
}
} break;
case hi:
case ls: {
Register left = i.InputRegister(1);
Operand right = i.InputOperand(0);
__ Sltu(result, left, right);
if (cc == ls) {
__ xori(result, result, 1);
}
} break;
default:
UNREACHABLE();
}
return;
} else if (instr->arch_opcode() == kMipsCmpD ||
instr->arch_opcode() == kMipsCmpS) {
FPURegister left = i.InputOrZeroDoubleRegister(0);
FPURegister right = i.InputOrZeroDoubleRegister(1);
if ((left.is(kDoubleRegZero) || right.is(kDoubleRegZero)) &&
!__ IsDoubleZeroRegSet()) {
__ Move(kDoubleRegZero, 0.0);
}
bool predicate;
FPUCondition cc = FlagsConditionToConditionCmpFPU(predicate, condition);
if (!IsMipsArchVariant(kMips32r6)) {
__ li(result, Operand(1));
if (instr->arch_opcode() == kMipsCmpD) {
__ c(cc, D, left, right);
} else {
DCHECK(instr->arch_opcode() == kMipsCmpS);
__ c(cc, S, left, right);
}
if (predicate) {
__ Movf(result, zero_reg);
} else {
__ Movt(result, zero_reg);
}
} else {
if (instr->arch_opcode() == kMipsCmpD) {
__ cmp(cc, L, kDoubleCompareReg, left, right);
} else {
DCHECK(instr->arch_opcode() == kMipsCmpS);
__ cmp(cc, W, kDoubleCompareReg, left, right);
}
__ mfc1(result, kDoubleCompareReg);
__ andi(result, result, 1); // Cmp returns all 1's/0's, use only LSB.
if (!predicate) // Toggle result for not equal.
__ xori(result, result, 1);
}
return;
} else {
PrintF("AssembleArchBranch Unimplemented arch_opcode is : %d\n",
instr->arch_opcode());
TRACE_UNIMPL();
UNIMPLEMENTED();
}
}
void CodeGenerator::AssembleArchLookupSwitch(Instruction* instr) {
MipsOperandConverter i(this, instr);
Register input = i.InputRegister(0);
for (size_t index = 2; index < instr->InputCount(); index += 2) {
__ li(at, Operand(i.InputInt32(index + 0)));
__ beq(input, at, GetLabel(i.InputRpo(index + 1)));
}
__ nop(); // Branch delay slot of the last beq.
AssembleArchJump(i.InputRpo(1));
}
void CodeGenerator::AssembleArchTableSwitch(Instruction* instr) {
MipsOperandConverter i(this, instr);
Register input = i.InputRegister(0);
size_t const case_count = instr->InputCount() - 2;
__ Branch(GetLabel(i.InputRpo(1)), hs, input, Operand(case_count));
__ GenerateSwitchTable(input, case_count, [&i, this](size_t index) {
return GetLabel(i.InputRpo(index + 2));
});
}
CodeGenerator::CodeGenResult CodeGenerator::AssembleDeoptimizerCall(
int deoptimization_id, Deoptimizer::BailoutType bailout_type) {
Address deopt_entry = Deoptimizer::GetDeoptimizationEntry(
isolate(), deoptimization_id, bailout_type);
if (deopt_entry == nullptr) return kTooManyDeoptimizationBailouts;
__ Call(deopt_entry, RelocInfo::RUNTIME_ENTRY);
return kSuccess;
}
void CodeGenerator::FinishFrame(Frame* frame) {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
const RegList saves_fpu = descriptor->CalleeSavedFPRegisters();
if (saves_fpu != 0) {
frame->AlignSavedCalleeRegisterSlots();
}
if (saves_fpu != 0) {
int count = base::bits::CountPopulation32(saves_fpu);
DCHECK(kNumCalleeSavedFPU == count);
frame->AllocateSavedCalleeRegisterSlots(count *
(kDoubleSize / kPointerSize));
}
const RegList saves = descriptor->CalleeSavedRegisters();
if (saves != 0) {
int count = base::bits::CountPopulation32(saves);
DCHECK(kNumCalleeSaved == count + 1);
frame->AllocateSavedCalleeRegisterSlots(count);
}
}
void CodeGenerator::AssembleConstructFrame() {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
if (frame_access_state()->has_frame()) {
if (descriptor->IsCFunctionCall()) {
__ Push(ra, fp);
__ mov(fp, sp);
} else if (descriptor->IsJSFunctionCall()) {
__ Prologue(this->info()->GeneratePreagedPrologue());
} else {
__ StubPrologue(info()->GetOutputStackFrameType());
}
}
int shrink_slots = frame()->GetSpillSlotCount();
if (info()->is_osr()) {
// TurboFan OSR-compiled functions cannot be entered directly.
__ Abort(kShouldNotDirectlyEnterOsrFunction);
// Unoptimized code jumps directly to this entrypoint while the unoptimized
// frame is still on the stack. Optimized code uses OSR values directly from
// the unoptimized frame. Thus, all that needs to be done is to allocate the
// remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset();
shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots();
}
const RegList saves_fpu = descriptor->CalleeSavedFPRegisters();
if (shrink_slots > 0) {
__ Subu(sp, sp, Operand(shrink_slots * kPointerSize));
}
// Save callee-saved FPU registers.
if (saves_fpu != 0) {
__ MultiPushFPU(saves_fpu);
}
const RegList saves = descriptor->CalleeSavedRegisters();
if (saves != 0) {
// Save callee-saved registers.
__ MultiPush(saves);
DCHECK(kNumCalleeSaved == base::bits::CountPopulation32(saves) + 1);
}
}
void CodeGenerator::AssembleReturn() {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
int pop_count = static_cast<int>(descriptor->StackParameterCount());
// Restore GP registers.
const RegList saves = descriptor->CalleeSavedRegisters();
if (saves != 0) {
__ MultiPop(saves);
}
// Restore FPU registers.
const RegList saves_fpu = descriptor->CalleeSavedFPRegisters();
if (saves_fpu != 0) {
__ MultiPopFPU(saves_fpu);
}
if (descriptor->IsCFunctionCall()) {
AssembleDeconstructFrame();
} else if (frame_access_state()->has_frame()) {
// Canonicalize JSFunction return sites for now.
if (return_label_.is_bound()) {
__ Branch(&return_label_);
return;
} else {
__ bind(&return_label_);
AssembleDeconstructFrame();
}
}
if (pop_count != 0) {
__ DropAndRet(pop_count);
} else {
__ Ret();
}
}
void CodeGenerator::AssembleMove(InstructionOperand* source,
InstructionOperand* destination) {
MipsOperandConverter g(this, nullptr);
// Dispatch on the source and destination operand kinds. Not all
// combinations are possible.
if (source->IsRegister()) {
DCHECK(destination->IsRegister() || destination->IsStackSlot());
Register src = g.ToRegister(source);
if (destination->IsRegister()) {
__ mov(g.ToRegister(destination), src);
} else {
__ sw(src, g.ToMemOperand(destination));
}
} else if (source->IsStackSlot()) {
DCHECK(destination->IsRegister() || destination->IsStackSlot());
MemOperand src = g.ToMemOperand(source);
if (destination->IsRegister()) {
__ lw(g.ToRegister(destination), src);
} else {
Register temp = kScratchReg;
__ lw(temp, src);
__ sw(temp, g.ToMemOperand(destination));
}
} else if (source->IsConstant()) {
Constant src = g.ToConstant(source);
if (destination->IsRegister() || destination->IsStackSlot()) {
Register dst =
destination->IsRegister() ? g.ToRegister(destination) : kScratchReg;
switch (src.type()) {
case Constant::kInt32:
if (src.rmode() == RelocInfo::WASM_MEMORY_REFERENCE ||
src.rmode() == RelocInfo::WASM_MEMORY_SIZE_REFERENCE) {
__ li(dst, Operand(src.ToInt32(), src.rmode()));
} else {
__ li(dst, Operand(src.ToInt32()));
}
break;
case Constant::kFloat32:
__ li(dst, isolate()->factory()->NewNumber(src.ToFloat32(), TENURED));
break;
case Constant::kInt64:
UNREACHABLE();
break;
case Constant::kFloat64:
__ li(dst, isolate()->factory()->NewNumber(src.ToFloat64(), TENURED));
break;
case Constant::kExternalReference:
__ li(dst, Operand(src.ToExternalReference()));
break;
case Constant::kHeapObject: {
Handle<HeapObject> src_object = src.ToHeapObject();
Heap::RootListIndex index;
int slot;
if (IsMaterializableFromFrame(src_object, &slot)) {
__ lw(dst, g.SlotToMemOperand(slot));
} else if (IsMaterializableFromRoot(src_object, &index)) {
__ LoadRoot(dst, index);
} else {
__ li(dst, src_object);
}
break;
}
case Constant::kRpoNumber:
UNREACHABLE(); // TODO(titzer): loading RPO numbers on mips.
break;
}
if (destination->IsStackSlot()) __ sw(dst, g.ToMemOperand(destination));
} else if (src.type() == Constant::kFloat32) {
if (destination->IsFPStackSlot()) {
MemOperand dst = g.ToMemOperand(destination);
__ li(at, Operand(bit_cast<int32_t>(src.ToFloat32())));
__ sw(at, dst);
} else {
FloatRegister dst = g.ToSingleRegister(destination);
__ Move(dst, src.ToFloat32());
}
} else {
DCHECK_EQ(Constant::kFloat64, src.type());
DoubleRegister dst = destination->IsFPRegister()
? g.ToDoubleRegister(destination)
: kScratchDoubleReg;
__ Move(dst, src.ToFloat64());
if (destination->IsFPStackSlot()) {
__ sdc1(dst, g.ToMemOperand(destination));
}
}
} else if (source->IsFPRegister()) {
FPURegister src = g.ToDoubleRegister(source);
if (destination->IsFPRegister()) {
FPURegister dst = g.ToDoubleRegister(destination);
__ Move(dst, src);
} else {
DCHECK(destination->IsFPStackSlot());
__ sdc1(src, g.ToMemOperand(destination));
}
} else if (source->IsFPStackSlot()) {
DCHECK(destination->IsFPRegister() || destination->IsFPStackSlot());
MemOperand src = g.ToMemOperand(source);
if (destination->IsFPRegister()) {
__ ldc1(g.ToDoubleRegister(destination), src);
} else {
FPURegister temp = kScratchDoubleReg;
__ ldc1(temp, src);
__ sdc1(temp, g.ToMemOperand(destination));
}
} else {
UNREACHABLE();
}
}
void CodeGenerator::AssembleSwap(InstructionOperand* source,
InstructionOperand* destination) {
MipsOperandConverter g(this, nullptr);
// Dispatch on the source and destination operand kinds. Not all
// combinations are possible.
if (source->IsRegister()) {
// Register-register.
Register temp = kScratchReg;
Register src = g.ToRegister(source);
if (destination->IsRegister()) {
Register dst = g.ToRegister(destination);
__ Move(temp, src);
__ Move(src, dst);
__ Move(dst, temp);
} else {
DCHECK(destination->IsStackSlot());
MemOperand dst = g.ToMemOperand(destination);
__ mov(temp, src);
__ lw(src, dst);
__ sw(temp, dst);
}
} else if (source->IsStackSlot()) {
DCHECK(destination->IsStackSlot());
Register temp_0 = kScratchReg;
Register temp_1 = kCompareReg;
MemOperand src = g.ToMemOperand(source);
MemOperand dst = g.ToMemOperand(destination);
__ lw(temp_0, src);
__ lw(temp_1, dst);
__ sw(temp_0, dst);
__ sw(temp_1, src);
} else if (source->IsFPRegister()) {
FPURegister temp = kScratchDoubleReg;
FPURegister src = g.ToDoubleRegister(source);
if (destination->IsFPRegister()) {
FPURegister dst = g.ToDoubleRegister(destination);
__ Move(temp, src);
__ Move(src, dst);
__ Move(dst, temp);
} else {
DCHECK(destination->IsFPStackSlot());
MemOperand dst = g.ToMemOperand(destination);
__ Move(temp, src);
__ ldc1(src, dst);
__ sdc1(temp, dst);
}
} else if (source->IsFPStackSlot()) {
DCHECK(destination->IsFPStackSlot());
Register temp_0 = kScratchReg;
FPURegister temp_1 = kScratchDoubleReg;
MemOperand src0 = g.ToMemOperand(source);
MemOperand src1(src0.rm(), src0.offset() + kIntSize);
MemOperand dst0 = g.ToMemOperand(destination);
MemOperand dst1(dst0.rm(), dst0.offset() + kIntSize);
__ ldc1(temp_1, dst0); // Save destination in temp_1.
__ lw(temp_0, src0); // Then use temp_0 to copy source to destination.
__ sw(temp_0, dst0);
__ lw(temp_0, src1);
__ sw(temp_0, dst1);
__ sdc1(temp_1, src0);
} else {
// No other combinations are possible.
UNREACHABLE();
}
}
void CodeGenerator::AssembleJumpTable(Label** targets, size_t target_count) {
// On 32-bit MIPS we emit the jump tables inline.
UNREACHABLE();
}
void CodeGenerator::EnsureSpaceForLazyDeopt() {
if (!info()->ShouldEnsureSpaceForLazyDeopt()) {
return;
}
int space_needed = Deoptimizer::patch_size();
// Ensure that we have enough space after the previous lazy-bailout
// instruction for patching the code here.
int current_pc = masm()->pc_offset();
if (current_pc < last_lazy_deopt_pc_ + space_needed) {
// Block tramoline pool emission for duration of padding.
v8::internal::Assembler::BlockTrampolinePoolScope block_trampoline_pool(
masm());
int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc;
DCHECK_EQ(0, padding_size % v8::internal::Assembler::kInstrSize);
while (padding_size > 0) {
__ nop();
padding_size -= v8::internal::Assembler::kInstrSize;
}
}
}
#undef __
} // namespace compiler
} // namespace internal
} // namespace v8
|
/* This file is part of Nokia HEIF library
*
* Copyright (c) 2015-2018 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
*
* Contact: heif@nokia.com
*
* This software, including documentation, is protected by copyright controlled by Nokia Corporation and/ or its subsidiaries. All rights are reserved.
*
* Copying, including reproducing, storing, adapting or translating, any or all of this material requires the prior written consent of Nokia.
*/
#ifndef HEVCDECODERCONFIGRECORD_HPP
#define HEVCDECODERCONFIGRECORD_HPP
#include "hevccommondefs.hpp"
#include "decoderconfigrecord.hpp"
namespace ISOBMFF
{
class BitStream;
}
/**
* @brief HEVC decoder configuration record
*/
class HevcDecoderConfigurationRecord : public DecoderConfigurationRecord
{
public:
HevcDecoderConfigurationRecord();
~HevcDecoderConfigurationRecord() = default;
/**
* Read configuration parameters from a SPS NAL unit.
* @param sps Sequence Parameter Set data
* @param frameRate Frame rate of video
*/
void makeConfigFromSPS(const Vector<std::uint8_t> &sps, float frameRate);
/**
* Add NAL unit to the NAL unit array
* @param sps Sequence Parameter Set data
* @param nalUnitType Type of the NAL unit
* @param arrayCompleteness TBD
*/
void addNalUnit(const Vector<std::uint8_t> &sps, HevcNalUnitType nalUnitType,
bool arrayCompleteness);
/**
* Serialize decoder configuration to ISOBMFF::BitStream.
* @param [in,out] bitstr Decoder configuration appended is appended to
* bitstr.
*/
void writeDecConfigRecord(ISOBMFF::BitStream &bitstr) const;
/**
* Deserialize HevcDecoderConfigurationRecord from ISOBMFF::BitStream
* @param [in,out] bitstr ISOBMFF::BitStream including decoder configuration
* data. ISOBMFF::BitStream position is modified accordingly.
*/
void parseConfig(ISOBMFF::BitStream &bitstr);
/**
* @brief Append one parameter set of type nalUnitType.
* @details If NAL unit of type nalUnitType is not found, nothing is appended.
* @param [in,out] byteStream Vector where the parameter set is appended
* @param nalUnitType NAL unit type to append
*/
void getOneParameterSet(Vector<std::uint8_t> &byteStream,
HevcNalUnitType nalUnitType) const;
/**
* @pre makeConfigFromSPS has been called successfully.
* @return Picture width in pixels.
*/
std::uint16_t getPicWidth() const;
/**
* @pre makeConfigFromSPS has been called successfully.
* @return Picture height in pixels.
*/
std::uint16_t getPicHeight() const;
/**
* @pre makeConfigFromSPS or parseConfig has been called successfully.
* @return Average frame rate
*/
std::uint16_t getAvgFrameRate() const;
/* @brief Returns configuration parameter map for this record */
virtual void getConfigurationMap(ConfigurationMap& aMap) const override;
private:
// Member variables can be found from the High Efficiency Video Coding (HEVC)
// specification
struct NALArray
{
bool arrayCompleteness = false;
HevcNalUnitType nalUnitType = HevcNalUnitType::INVALID;
Vector<Vector<std::uint8_t>> nalList;
};
std::uint8_t mConfigurationVersion;
std::uint8_t mGeneralProfileSpace;
std::uint8_t mGeneralTierFlag;
std::uint8_t mGeneralProfileIdc;
std::uint32_t mGeneralProfileCompatibilityFlags;
Vector<std::uint8_t> mGeneralConstraintIndicatorFlags;
std::uint8_t mGeneralLevelIdc;
std::uint16_t mMinSpatialSegmentationIdc;
std::uint8_t mParallelismType;
std::uint8_t mChromaFormat;
std::uint16_t mPicWidthInLumaSamples; // this is not written to an mp4 file
std::uint16_t mPicHeightInLumaSamples; // this is not written to an mp4 file
std::uint16_t mConfWinLeftOffset; // this is not written to an mp4 file
std::uint16_t mConfWinRightOffset; // this is not written to an mp4 file
std::uint16_t mConfWinTopOffset; // this is not written to an mp4 file
std::uint16_t mConfWinBottomOffset; // this is not written to an mp4 file
std::uint8_t mBitDepthLumaMinus8;
std::uint8_t mBitDepthChromaMinus8;
std::uint16_t mAvgFrameRate;
std::uint8_t mConstantFrameRate;
std::uint8_t mNumTemporalLayers;
std::uint8_t mTemporalIdNested;
std::uint8_t mLengthSizeMinus1;
Vector<NALArray> mNalArray;
};
#endif /* end of include guard: HEVCDECODERCONFIGRECORD_HPP */
|
<% from pwnlib.shellcraft import arm, common %>
<% from pwnlib.util.misc import binary_ip %>
<% from pwnlib.util.packing import u32 %>
<% from socket import htons %>
<%page args="port=31337"/>
<%docstring>
listens on specific port infinity
Args:
port (int/str): specific port (default: 31337)
</%docstring>
<%
sockaddr_in = common.label("sockaddr_in")
looplabel = common.label("looplabel")
cleanup = common.label("cleanup")
after_fork = common.label("after_fork")
after_sockaddr_in = common.label("after_sockaddr_in")
%>
mov r0, AF_INET
mov r1, SOCK_STREAM
sub r2, r2, r2
svc SYS_socket
mov r6, r0
adr r4, ${sockaddr_in}
ldr r1, [r4]
sub r2, r2, r2
push { r1, r2 }
mov r0, r6
mov r1, sp
mov r2, #16
svc SYS_bind
b ${after_sockaddr_in}
${sockaddr_in}:
.short AF_INET
.short ${htons(int(port))}
${after_sockaddr_in}:
mov r1, #16
mov r0, r6
svc SYS_listen
${looplabel}:
mov r0, r6
sub r1, r1, r1
sub r2, r2, r2
svc SYS_accept
mov r5, r0
svc SYS_fork
cmp r0, 0
bgt ${cleanup}
mov r0, r6
svc SYS_close
mov r0, r5
b ${after_fork}
${cleanup}:
mov r0, r5
svc SYS_close
b ${looplabel}
${after_fork}:
|
; A168952: Number of reduced words of length n in Coxeter group on 35 generators S_i with relations (S_i)^2 = (S_i S_j)^22 = I.
; 1,35,1190,40460,1375640,46771760,1590239840,54068154560,1838317255040,62502786671360,2125094746826240,72253221392092160,2456609527331133440,83524723929258536960,2839840613594790256640,96554580862222868725760
add $0,1
mov $3,1
lpb $0
sub $0,1
add $2,$3
div $3,$2
mul $2,34
lpe
mov $0,$2
div $0,34
|
; A065128: Number of invertible n X n matrices mod 4 (i.e., over the ring Z_4).
; Submitted by Jon Maiga
; 1,2,96,86016,1321205760,335522845163520,1385295986380096143360,92239345887620476544860815360,98654363640526679389774053813465907200,1691558770638735027870457216848672340872423014400,464518059995994038184379206447729320401459864818351813427200
mov $2,1
mov $4,1
lpb $0
sub $0,1
add $3,$2
mul $2,2
mul $4,$3
mul $3,2
mul $4,$2
mul $2,2
lpe
mov $0,$4
|
SECTION code_clib
SECTION code_fp_math48
PUBLIC asm_isgreater
EXTERN am48_isgreater
defc asm_isgreater = am48_isgreater
|
; A173856: Expansion of 10/9 in base phi.
; 1,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0
mul $0,2
pow $0,2
dif $0,4
sub $0,1
dif $0,4
add $0,1
mov $2,2985984
gcd $2,$0
div $0,$2
mov $1,$0
seq $1,133882 ; a(n) = binomial(n+2,n) mod 2^2.
mov $2,2
bin $2,$1
add $0,$2
sub $0,1
mod $0,2
|
#include <netlistDB/transform/indexed_assignment_to_assignment_of_concat.h>
#include <exception>
#include <thread>
#include <netlistDB/statement_assignment.h>
using namespace std;
namespace netlistDB {
namespace transform {
pair<size_t, size_t> net_val_as_range(Net & n) {
throw runtime_error("not implemented");
}
bool TransformIndexedAssignmentsToAssignmentOfConcat::is_result_of_indexed_assignment(
Net & sig, vector<Net*> & inputs) {
inputs.clear();
if (sig.drivers.size() == 0)
return false;
vector<range_and_src_t> match;
// note: a[0] = b is also replaced case
for (auto d : sig.drivers) {
auto assig = dynamic_cast<Assignment*>(d);
if (assig != nullptr and assig->dst_index.size() > 0) {
bool all_indx_const = true;
for (auto i : assig->dst_index) {
if (not i->is_const()) {
all_indx_const = false;
break;
}
}
if (all_indx_const) {
if (assig->dst_index.size() > 1)
throw std::runtime_error("not implemented");
auto range = net_val_as_range(*assig->dst_index[0]);
match.push_back( { range, &assig->dst });
}
} else {
break;
}
}
if (sig.drivers.size() != match.size()) {
match.clear();
return false;
} else {
// Sort items to correct order
sort(match.begin(), match.end(),
[](const range_and_src_t & a, const range_and_src_t & b) -> bool {
return a.first.first > b.first.first;
});
// Assert the parts are not overlapping
// and whole signal is driven
size_t expected_next_start = 0;
for (size_t i = 0; i < match.size(); i++) {
auto r = match[i].first;
assert(r.first == expected_next_start);
assert(r.first <= r.second);
expected_next_start = r.second + 1;
}
assert(
sig.t.bit_length() == expected_next_start
&& "All parts of the signal are driven");
for (auto m : match) {
inputs.push_back(m.second);
}
return true;
}
}
bool TransformIndexedAssignmentsToAssignmentOfConcat::apply(Netlist & ctx) {
throw std::runtime_error("not implemented");
// walk all signals
size_t thread_cnt = thread::hardware_concurrency();
auto to_update = make_unique<vector<pair<Net*, vector<Net*> > > []>(
thread_cnt);
// If the signal is driven by multiple combinational assignments to parts of this signal
// Assert all parts of the signals are driven
// Collect all the input signals for specified target signal
{
utils::TaskGroup g(thread_pool);
g.parallel_for(size_t(0), size_t(thread_cnt),
[&] (const size_t thread_i) {
size_t step = thread_cnt;
auto & to_upd = to_update[thread_i];
for(size_t i = thread_i; i < ctx.nets.size(); i+= step) {
Net * n = ctx.nets[i];
vector<Net*> inputs;
if (is_result_of_indexed_assignment(*n, inputs)) {
to_upd.push_back( {n, inputs});
}
}
});
g.wait();
}
bool updated = false;
// sequentially replace the indexed assignments
for (size_t t = 0; t < thread_cnt; t++) {
for (auto rec : to_update[t]) {
// delete all drivers as they are being replaced
// create concatenation of all inputs
// connect concatenated inputs to output
throw std::runtime_error("not implemented");
updated = true;
}
}
return updated;
}
}
}
|
; ---------------------------------------------------------------------------
; Animation script - electrocution orbs (SBZ)
; ---------------------------------------------------------------------------
Ani_Elec: dc.w byte_161CC-Ani_Elec
dc.w byte_161D0-Ani_Elec
byte_161CC: dc.b 7, 0, afEnd
even
byte_161D0: dc.b 0, 1, 1, 1, 2, 3, 3, 4, 4, 4, 5, 5, 5, 0, afChange, 0
even |
; A274427: Positions in A274426 of products of distinct Fibonacci numbers > 1.
; 1,2,4,5,7,8,11,12,13,16,17,18,22,23,24,25,29,30,31,32,37,38,39,40,41,46,47,48,49,50,56,57,58,59,60,61,67,68,69,70,71,72,79,80,81,82,83,84,85,92,93,94,95,96,97,98,106,107,108,109,110,111,112,113,121,122,123,124,125,126,127,128,137,138,139,140,141,142,143,144,145,154,155,156,157,158,159,160,161,162,172,173,174,175,176,177,178,179,180,181,191,192,193,194,195,196,197,198,199,200,211,212,213,214,215,216,217,218,219,220,221,232,233,234,235,236,237,238,239,240,241,242,254,255,256,257,258,259,260,261,262,263,264,265,277,278,279,280,281,282,283,284,285,286,287,288,301,302,303,304,305,306,307,308,309,310,311,312,313,326,327,328,329,330,331,332,333,334,335,336,337,338,352,353,354,355,356,357,358,359,360,361,362,363,364,365,379,380,381,382,383,384,385,386,387,388,389,390,391,392,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,466,467,468,469,470,471,472,473,474,475
mov $4,$0
add $4,1
mov $9,$0
lpb $4
mov $0,$9
sub $4,1
sub $0,$4
mov $5,$0
mov $7,2
lpb $7
mov $0,$5
sub $7,1
add $0,$7
sub $0,1
mov $10,$0
sub $10,$0
mul $0,2
lpb $0
sub $0,1
sub $0,$3
mov $2,$3
div $2,2
add $3,1
add $10,$2
lpe
mov $2,$3
sub $3,2
sub $10,$3
mov $3,1
mov $8,$7
add $10,$2
mul $10,5
sub $10,9
div $10,5
lpb $8
mov $6,$10
sub $8,1
lpe
lpe
lpb $5
mov $5,0
sub $6,$10
lpe
mov $10,$6
add $10,1
add $1,$10
lpe
|
; A000538: Sum of fourth powers: 0^4 + 1^4 + ... + n^4.
; 0,1,17,98,354,979,2275,4676,8772,15333,25333,39974,60710,89271,127687,178312,243848,327369,432345,562666,722666,917147,1151403,1431244,1763020,2153645,2610621,3142062,3756718,4463999,5273999,6197520,7246096,8432017,9768353,11268978,12948594,14822755,16907891,19221332,21781332,24607093,27718789,31137590,34885686,38986311,43463767,48343448,53651864,59416665,65666665,72431866,79743482,87633963,96137019,105287644,115122140,125678141,136994637,149111998,162071998,175917839,190694175,206447136,223224352,241074977,260049713,280200834,301582210,324249331,348259331,373671012,400544868,428943109,458929685,490570310,523932486,559085527,596100583,635050664,676010664,719057385,764269561,811727882,861515018,913715643,968416459,1025706220,1085675756,1148417997,1214027997,1282602958,1354242254,1429047455,1507122351,1588572976,1673507632,1762036913,1854273729,1950333330
lpb $0
mov $2,$0
sub $0,1
pow $2,4
add $1,$2
lpe
mov $0,$1
|
/*****************************************************************************
* GATB : Genome Assembly Tool Box
* Copyright (C) 2014 INRIA
* Authors: R.Chikhi, G.Rizk, E.Drezen
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
/** \file StorageFile.hpp
* \date 01/03/2013
* \author edrezen
* \brief Collection interface
*
* This file holds interfaces related to the Collection interface
*/
#ifndef _GATB_CORE_TOOLS_STORAGE_IMPL_STORAGE_FILE_HPP_
#define _GATB_CORE_TOOLS_STORAGE_IMPL_STORAGE_FILE_HPP_
/********************************************************************************/
#include <cassert>
#include <gatb/tools/storage/impl/CollectionFile.hpp>
#define DEBUG_STORAGE(a) //printf a
/********************************************************************************/
namespace gatb {
namespace core {
namespace tools {
namespace storage {
namespace impl {
/********************************************************************************/
/** \brief Factory used for storage of kind STORAGE_FILE
*/
class StorageFileFactory
{
public:
/** Create a Storage instance.
* \param[in] name : name of the instance to be created
* \param[in] deleteIfExist : if the storage exits in file system, delete it if true.
* \param[in] autoRemove : auto delete the storage from file system during Storage destructor.
* \return the created Storage instance
*/
static Storage* createStorage (const std::string& name, bool deleteIfExist, bool autoRemove)
{
DEBUG_STORAGE (("StorageFileFactory::createStorage name='%s'\n", name.c_str()));
return new Storage (STORAGE_FILE, name, autoRemove);
}
/** Tells whether or not a Storage exists in file system given a name
* \param[in] name : name of the storage to be checked
* \return true if the storage exists in file system, false otherwise.
*/
static bool exists (const std::string& name)
{
return false;
}
/** Create a Group instance and attach it to a cell in a storage.
* \param[in] parent : parent of the group to be created
* \param[in] name : name of the group to be created
* \return the created Group instance.
*/
static Group* createGroup (ICell* parent, const std::string& name)
{
DEBUG_STORAGE (("StorageFileFactory::createGroup name='%s'\n", name.c_str()));
ICell* root = ICell::getRoot (parent);
Storage* storage = dynamic_cast<Storage*> (root);
assert (storage != 0);
return new Group (storage->getFactory(), parent, name);
}
/** Create a Partition instance and attach it to a cell in a storage.
* \param[in] parent : parent of the partition to be created
* \param[in] name : name of the partition to be created
* \param[in] nb : number of collections of the partition
* \return the created Partition instance.
*/
template<typename Type>
static Partition<Type>* createPartition (ICell* parent, const std::string& name, size_t nb)
{
DEBUG_STORAGE (("StorageFileFactory::createPartition name='%s'\n", name.c_str()));
ICell* root = ICell::getRoot (parent);
Storage* storage = dynamic_cast<Storage*> (root);
assert (storage != 0);
Partition<Type>* result = new Partition<Type> (storage->getFactory(), parent, name, nb);
return result;
}
/** Create a Collection instance and attach it to a cell in a storage.
* \param[in] parent : parent of the collection to be created
* \param[in] name : name of the collection to be created
* \param[in] synchro : synchronizer instance if needed
* \return the created Collection instance.
*/
template<typename Type>
static CollectionNode<Type>* createCollection (ICell* parent, const std::string& name, system::ISynchronizer* synchro)
{
ICell* root = ICell::getRoot (parent);
Storage* storage = dynamic_cast<Storage*> (root);
assert (storage != 0);
/** We define the full qualified id of the current collection to be created. */
std::string actualName = storage->getName() + std::string(".") + parent->getFullId('.') + std::string(".") + name;
DEBUG_STORAGE (("StorageFileFactory::createCollection name='%s' actualName='%s' \n", name.c_str(), actualName.c_str() ));
return new CollectionNode<Type> (storage->getFactory(), parent, name, new CollectionFile<Type>(actualName));
}
};
/********************************************************************************/
/* Experimental (not documented). */
class StorageGzFileFactory
{
public:
/** */
static Storage* createStorage (const std::string& name, bool deleteIfExist, bool autoRemove)
{
return new Storage (STORAGE_GZFILE, name, autoRemove);
}
/** */
static bool exists (const std::string& name)
{
return false;
}
/** */
static Group* createGroup (ICell* parent, const std::string& name)
{
ICell* root = ICell::getRoot (parent);
Storage* storage = dynamic_cast<Storage*> (root);
assert (storage != 0);
return new Group (storage->getFactory(), parent, name);
}
/** */
template<typename Type>
static Partition<Type>* createPartition (ICell* parent, const std::string& name, size_t nb)
{
ICell* root = ICell::getRoot (parent);
Storage* storage = dynamic_cast<Storage*> (root);
assert (storage != 0);
Partition<Type>* result = new Partition<Type> (storage->getFactory(), parent, name, nb);
return result;
}
/** */
template<typename Type>
static CollectionNode<Type>* createCollection (ICell* parent, const std::string& name, system::ISynchronizer* synchro)
{
/** We define the full qualified id of the current collection to be created. */
std::string actualName = std::string("tmp.") + name;
ICell* root = ICell::getRoot (parent);
Storage* storage = dynamic_cast<Storage*> (root);
assert (storage != 0);
return new CollectionNode<Type> (storage->getFactory(), parent, name, new CollectionGzFile<Type>(actualName));
}
};
/********************************************************************************/
/* Experimental (not documented). */
class StorageSortedFactory
{
public:
/** */
static Storage* createStorage (const std::string& name, bool deleteIfExist, bool autoRemove)
{
return new Storage (STORAGE_COMPRESSED_FILE, name, autoRemove);
}
/** */
static bool exists (const std::string& name)
{
return false;
}
/** */
static Group* createGroup (ICell* parent, const std::string& name)
{
ICell* root = ICell::getRoot (parent);
Storage* storage = dynamic_cast<Storage*> (root);
assert (storage != 0);
return new Group (storage->getFactory(), parent, name);
}
/** */
template<typename Type>
static Partition<Type>* createPartition (ICell* parent, const std::string& name, size_t nb)
{
ICell* root = ICell::getRoot (parent);
Storage* storage = dynamic_cast<Storage*> (root);
assert (storage != 0);
Partition<Type>* result = new Partition<Type> (storage->getFactory(), parent, name, nb);
return result;
}
/** */
template<typename Type>
static CollectionNode<Type>* createCollection (ICell* parent, const std::string& name, system::ISynchronizer* synchro)
{
/** We define the full qualified id of the current collection to be created. */
std::string actualName = std::string("tmp.") + name;
ICell* root = ICell::getRoot (parent);
Storage* storage = dynamic_cast<Storage*> (root);
assert (storage != 0);
return new CollectionNode<Type> (storage->getFactory(), parent, name, new CollectionCountFile<Type>(actualName));
}
};
/********************************************************************************/
} } } } } /* end of namespaces. */
/********************************************************************************/
#endif /* _GATB_CORE_TOOLS_STORAGE_IMPL_STORAGE_FILE_HPP_ */
|
.code
ALIGN 16
add1 proc
push rdi
push rsi
mov rdi, rcx
mov rsi, rdx
mov rdx, r8
xor r8, r8
xor r9, r9
xor r10, r10
xor r11, r11
xor rax, rax
add rdx, qword ptr [rsi + 0]
mov qword ptr [rdi + 0], rdx
adcx r8, qword ptr [rsi + 8]
mov qword ptr [rdi + 8], r8
adcx r9, qword ptr [rsi + 16]
mov qword ptr [rdi + 16], r9
adcx r10, qword ptr [rsi + 24]
mov qword ptr [rdi + 24], r10
adcx rax, r11
pop rsi
pop rdi
ret
add1 endp
ALIGN 16
fadd_ proc
push rdi
push rsi
mov rdi, rcx
mov rsi, rdx
mov rdx, r8
mov r8, qword ptr [rdx + 0]
add r8, qword ptr [rsi + 0]
mov r9, qword ptr [rdx + 8]
adcx r9, qword ptr [rsi + 8]
mov r10, qword ptr [rdx + 16]
adcx r10, qword ptr [rsi + 16]
mov r11, qword ptr [rdx + 24]
adcx r11, qword ptr [rsi + 24]
mov rax, 0
mov rdx, 38
cmovc rax, rdx
xor rcx, rcx
add r8, rax
adcx r9, rcx
mov qword ptr [rdi + 8], r9
adcx r10, rcx
mov qword ptr [rdi + 16], r10
adcx r11, rcx
mov qword ptr [rdi + 24], r11
mov rax, 0
cmovc rax, rdx
add r8, rax
mov qword ptr [rdi + 0], r8
pop rsi
pop rdi
ret
fadd_ endp
ALIGN 16
fsub_ proc
push rdi
push rsi
mov rdi, rcx
mov rsi, rdx
mov rdx, r8
mov r8, qword ptr [rsi + 0]
sub r8, qword ptr [rdx + 0]
mov r9, qword ptr [rsi + 8]
sbb r9, qword ptr [rdx + 8]
mov r10, qword ptr [rsi + 16]
sbb r10, qword ptr [rdx + 16]
mov r11, qword ptr [rsi + 24]
sbb r11, qword ptr [rdx + 24]
mov rax, 0
mov rcx, 38
cmovc rax, rcx
sub r8, rax
sbb r9, 0
sbb r10, 0
sbb r11, 0
mov rax, 0
cmovc rax, rcx
sub r8, rax
mov qword ptr [rdi + 0], r8
mov qword ptr [rdi + 8], r9
mov qword ptr [rdi + 16], r10
mov qword ptr [rdi + 24], r11
pop rsi
pop rdi
ret
fsub_ endp
ALIGN 16
fmul1 proc
push rdi
push r12
push r13
push rsi
mov rdi, rcx
mov rsi, rdx
mov rdx, r8
mulx rcx, r8, qword ptr [rsi + 0]
mulx r12, r9, qword ptr [rsi + 8]
add r9, rcx
mov rcx, 0
mulx r13, r10, qword ptr [rsi + 16]
adcx r10, r12
mulx rax, r11, qword ptr [rsi + 24]
adcx r11, r13
adcx rax, rcx
mov rdx, 38
imul rax, rdx
add r8, rax
adcx r9, rcx
mov qword ptr [rdi + 8], r9
adcx r10, rcx
mov qword ptr [rdi + 16], r10
adcx r11, rcx
mov qword ptr [rdi + 24], r11
mov rax, 0
cmovc rax, rdx
add r8, rax
mov qword ptr [rdi + 0], r8
pop rsi
pop r13
pop r12
pop rdi
ret
fmul1 endp
ALIGN 16
fmul_ proc
push r12
push r13
push r14
push r15
push rsi
push rdi
mov rdi, rcx
mov rsi, rdx
mov rdx, r8
mov rcx, r9
mov r15, rdx
mov rdx, qword ptr [rsi + 0]
mulx r9, r8, qword ptr [rcx + 0]
xor r10, r10
mov qword ptr [rdi + 0], r8
mulx r11, r10, qword ptr [rcx + 8]
adox r10, r9
mov qword ptr [rdi + 8], r10
mulx r13, r12, qword ptr [rcx + 16]
adox r12, r11
mulx rdx, r14, qword ptr [rcx + 24]
adox r14, r13
mov rax, 0
adox rax, rdx
mov rdx, qword ptr [rsi + 8]
mulx r9, r8, qword ptr [rcx + 0]
xor r10, r10
adcx r8, qword ptr [rdi + 8]
mov qword ptr [rdi + 8], r8
mulx r11, r10, qword ptr [rcx + 8]
adox r10, r9
adcx r10, r12
mov qword ptr [rdi + 16], r10
mulx r13, r12, qword ptr [rcx + 16]
adox r12, r11
adcx r12, r14
mov r8, 0
mulx rdx, r14, qword ptr [rcx + 24]
adox r14, r13
adcx r14, rax
mov rax, 0
adox rax, rdx
adcx rax, r8
mov rdx, qword ptr [rsi + 16]
mulx r9, r8, qword ptr [rcx + 0]
xor r10, r10
adcx r8, qword ptr [rdi + 16]
mov qword ptr [rdi + 16], r8
mulx r11, r10, qword ptr [rcx + 8]
adox r10, r9
adcx r10, r12
mov qword ptr [rdi + 24], r10
mulx r13, r12, qword ptr [rcx + 16]
adox r12, r11
adcx r12, r14
mov r8, 0
mulx rdx, r14, qword ptr [rcx + 24]
adox r14, r13
adcx r14, rax
mov rax, 0
adox rax, rdx
adcx rax, r8
mov rdx, qword ptr [rsi + 24]
mulx r9, r8, qword ptr [rcx + 0]
xor r10, r10
adcx r8, qword ptr [rdi + 24]
mov qword ptr [rdi + 24], r8
mulx r11, r10, qword ptr [rcx + 8]
adox r10, r9
adcx r10, r12
mov qword ptr [rdi + 32], r10
mulx r13, r12, qword ptr [rcx + 16]
adox r12, r11
adcx r12, r14
mov qword ptr [rdi + 40], r12
mov r8, 0
mulx rdx, r14, qword ptr [rcx + 24]
adox r14, r13
adcx r14, rax
mov qword ptr [rdi + 48], r14
mov rax, 0
adox rax, rdx
adcx rax, r8
mov qword ptr [rdi + 56], rax
mov rsi, rdi
mov rdi, r15
mov rdx, 38
mulx r13, r8, qword ptr [rsi + 32]
xor rcx, rcx
adox r8, qword ptr [rsi + 0]
mulx r12, r9, qword ptr [rsi + 40]
adcx r9, r13
adox r9, qword ptr [rsi + 8]
mulx r13, r10, qword ptr [rsi + 48]
adcx r10, r12
adox r10, qword ptr [rsi + 16]
mulx rax, r11, qword ptr [rsi + 56]
adcx r11, r13
adox r11, qword ptr [rsi + 24]
adcx rax, rcx
adox rax, rcx
imul rax, rdx
add r8, rax
adcx r9, rcx
mov qword ptr [rdi + 8], r9
adcx r10, rcx
mov qword ptr [rdi + 16], r10
adcx r11, rcx
mov qword ptr [rdi + 24], r11
mov rax, 0
cmovc rax, rdx
add r8, rax
mov qword ptr [rdi + 0], r8
pop rdi
pop rsi
pop r15
pop r14
pop r13
pop r12
ret
fmul_ endp
ALIGN 16
fmul2 proc
push r12
push r13
push r14
push r15
push rsi
push rdi
mov rdi, rcx
mov rsi, rdx
mov rdx, r8
mov rcx, r9
mov r15, rdx
mov rdx, qword ptr [rsi + 0]
mulx r9, r8, qword ptr [rcx + 0]
xor r10, r10
mov qword ptr [rdi + 0], r8
mulx r11, r10, qword ptr [rcx + 8]
adox r10, r9
mov qword ptr [rdi + 8], r10
mulx r13, r12, qword ptr [rcx + 16]
adox r12, r11
mulx rdx, r14, qword ptr [rcx + 24]
adox r14, r13
mov rax, 0
adox rax, rdx
mov rdx, qword ptr [rsi + 8]
mulx r9, r8, qword ptr [rcx + 0]
xor r10, r10
adcx r8, qword ptr [rdi + 8]
mov qword ptr [rdi + 8], r8
mulx r11, r10, qword ptr [rcx + 8]
adox r10, r9
adcx r10, r12
mov qword ptr [rdi + 16], r10
mulx r13, r12, qword ptr [rcx + 16]
adox r12, r11
adcx r12, r14
mov r8, 0
mulx rdx, r14, qword ptr [rcx + 24]
adox r14, r13
adcx r14, rax
mov rax, 0
adox rax, rdx
adcx rax, r8
mov rdx, qword ptr [rsi + 16]
mulx r9, r8, qword ptr [rcx + 0]
xor r10, r10
adcx r8, qword ptr [rdi + 16]
mov qword ptr [rdi + 16], r8
mulx r11, r10, qword ptr [rcx + 8]
adox r10, r9
adcx r10, r12
mov qword ptr [rdi + 24], r10
mulx r13, r12, qword ptr [rcx + 16]
adox r12, r11
adcx r12, r14
mov r8, 0
mulx rdx, r14, qword ptr [rcx + 24]
adox r14, r13
adcx r14, rax
mov rax, 0
adox rax, rdx
adcx rax, r8
mov rdx, qword ptr [rsi + 24]
mulx r9, r8, qword ptr [rcx + 0]
xor r10, r10
adcx r8, qword ptr [rdi + 24]
mov qword ptr [rdi + 24], r8
mulx r11, r10, qword ptr [rcx + 8]
adox r10, r9
adcx r10, r12
mov qword ptr [rdi + 32], r10
mulx r13, r12, qword ptr [rcx + 16]
adox r12, r11
adcx r12, r14
mov qword ptr [rdi + 40], r12
mov r8, 0
mulx rdx, r14, qword ptr [rcx + 24]
adox r14, r13
adcx r14, rax
mov qword ptr [rdi + 48], r14
mov rax, 0
adox rax, rdx
adcx rax, r8
mov qword ptr [rdi + 56], rax
mov rdx, qword ptr [rsi + 32]
mulx r9, r8, qword ptr [rcx + 32]
xor r10, r10
mov qword ptr [rdi + 64], r8
mulx r11, r10, qword ptr [rcx + 40]
adox r10, r9
mov qword ptr [rdi + 72], r10
mulx r13, r12, qword ptr [rcx + 48]
adox r12, r11
mulx rdx, r14, qword ptr [rcx + 56]
adox r14, r13
mov rax, 0
adox rax, rdx
mov rdx, qword ptr [rsi + 40]
mulx r9, r8, qword ptr [rcx + 32]
xor r10, r10
adcx r8, qword ptr [rdi + 72]
mov qword ptr [rdi + 72], r8
mulx r11, r10, qword ptr [rcx + 40]
adox r10, r9
adcx r10, r12
mov qword ptr [rdi + 80], r10
mulx r13, r12, qword ptr [rcx + 48]
adox r12, r11
adcx r12, r14
mov r8, 0
mulx rdx, r14, qword ptr [rcx + 56]
adox r14, r13
adcx r14, rax
mov rax, 0
adox rax, rdx
adcx rax, r8
mov rdx, qword ptr [rsi + 48]
mulx r9, r8, qword ptr [rcx + 32]
xor r10, r10
adcx r8, qword ptr [rdi + 80]
mov qword ptr [rdi + 80], r8
mulx r11, r10, qword ptr [rcx + 40]
adox r10, r9
adcx r10, r12
mov qword ptr [rdi + 88], r10
mulx r13, r12, qword ptr [rcx + 48]
adox r12, r11
adcx r12, r14
mov r8, 0
mulx rdx, r14, qword ptr [rcx + 56]
adox r14, r13
adcx r14, rax
mov rax, 0
adox rax, rdx
adcx rax, r8
mov rdx, qword ptr [rsi + 56]
mulx r9, r8, qword ptr [rcx + 32]
xor r10, r10
adcx r8, qword ptr [rdi + 88]
mov qword ptr [rdi + 88], r8
mulx r11, r10, qword ptr [rcx + 40]
adox r10, r9
adcx r10, r12
mov qword ptr [rdi + 96], r10
mulx r13, r12, qword ptr [rcx + 48]
adox r12, r11
adcx r12, r14
mov qword ptr [rdi + 104], r12
mov r8, 0
mulx rdx, r14, qword ptr [rcx + 56]
adox r14, r13
adcx r14, rax
mov qword ptr [rdi + 112], r14
mov rax, 0
adox rax, rdx
adcx rax, r8
mov qword ptr [rdi + 120], rax
mov rsi, rdi
mov rdi, r15
mov rdx, 38
mulx r13, r8, qword ptr [rsi + 32]
xor rcx, rcx
adox r8, qword ptr [rsi + 0]
mulx r12, r9, qword ptr [rsi + 40]
adcx r9, r13
adox r9, qword ptr [rsi + 8]
mulx r13, r10, qword ptr [rsi + 48]
adcx r10, r12
adox r10, qword ptr [rsi + 16]
mulx rax, r11, qword ptr [rsi + 56]
adcx r11, r13
adox r11, qword ptr [rsi + 24]
adcx rax, rcx
adox rax, rcx
imul rax, rdx
add r8, rax
adcx r9, rcx
mov qword ptr [rdi + 8], r9
adcx r10, rcx
mov qword ptr [rdi + 16], r10
adcx r11, rcx
mov qword ptr [rdi + 24], r11
mov rax, 0
cmovc rax, rdx
add r8, rax
mov qword ptr [rdi + 0], r8
mov rdx, 38
mulx r13, r8, qword ptr [rsi + 96]
xor rcx, rcx
adox r8, qword ptr [rsi + 64]
mulx r12, r9, qword ptr [rsi + 104]
adcx r9, r13
adox r9, qword ptr [rsi + 72]
mulx r13, r10, qword ptr [rsi + 112]
adcx r10, r12
adox r10, qword ptr [rsi + 80]
mulx rax, r11, qword ptr [rsi + 120]
adcx r11, r13
adox r11, qword ptr [rsi + 88]
adcx rax, rcx
adox rax, rcx
imul rax, rdx
add r8, rax
adcx r9, rcx
mov qword ptr [rdi + 40], r9
adcx r10, rcx
mov qword ptr [rdi + 48], r10
adcx r11, rcx
mov qword ptr [rdi + 56], r11
mov rax, 0
cmovc rax, rdx
add r8, rax
mov qword ptr [rdi + 32], r8
pop rdi
pop rsi
pop r15
pop r14
pop r13
pop r12
ret
fmul2 endp
ALIGN 16
fsqr proc
push r15
push r12
push r13
push r14
push rbx
push rsi
push rdi
mov rdi, rcx
mov rsi, rdx
mov rdx, r8
mov rbx, rdx
mov rdx, qword ptr [rsi + 0]
mulx r14, r8, qword ptr [rsi + 8]
xor r15, r15
mulx r10, r9, qword ptr [rsi + 16]
adcx r9, r14
mulx rcx, rax, qword ptr [rsi + 24]
adcx r10, rax
mov rdx, qword ptr [rsi + 24]
mulx r12, r11, qword ptr [rsi + 8]
adcx r11, rcx
mulx r13, rax, qword ptr [rsi + 16]
adcx r12, rax
mov rdx, qword ptr [rsi + 8]
adcx r13, r15
mulx rcx, rax, qword ptr [rsi + 16]
mov r14, 0
xor r15, r15
adox r10, rax
adcx r8, r8
adox r11, rcx
adcx r9, r9
adox r12, r15
adcx r10, r10
adox r13, r15
adcx r11, r11
adox r14, r15
adcx r12, r12
adcx r13, r13
adcx r14, r14
mov rdx, qword ptr [rsi + 0]
mulx rcx, rax, rdx
mov qword ptr [rdi + 0], rax
add r8, rcx
mov qword ptr [rdi + 8], r8
mov rdx, qword ptr [rsi + 8]
mulx rcx, rax, rdx
adcx r9, rax
mov qword ptr [rdi + 16], r9
adcx r10, rcx
mov qword ptr [rdi + 24], r10
mov rdx, qword ptr [rsi + 16]
mulx rcx, rax, rdx
adcx r11, rax
mov qword ptr [rdi + 32], r11
adcx r12, rcx
mov qword ptr [rdi + 40], r12
mov rdx, qword ptr [rsi + 24]
mulx rcx, rax, rdx
adcx r13, rax
mov qword ptr [rdi + 48], r13
adcx r14, rcx
mov qword ptr [rdi + 56], r14
mov rsi, rdi
mov rdi, rbx
mov rdx, 38
mulx r13, r8, qword ptr [rsi + 32]
xor rcx, rcx
adox r8, qword ptr [rsi + 0]
mulx r12, r9, qword ptr [rsi + 40]
adcx r9, r13
adox r9, qword ptr [rsi + 8]
mulx r13, r10, qword ptr [rsi + 48]
adcx r10, r12
adox r10, qword ptr [rsi + 16]
mulx rax, r11, qword ptr [rsi + 56]
adcx r11, r13
adox r11, qword ptr [rsi + 24]
adcx rax, rcx
adox rax, rcx
imul rax, rdx
add r8, rax
adcx r9, rcx
mov qword ptr [rdi + 8], r9
adcx r10, rcx
mov qword ptr [rdi + 16], r10
adcx r11, rcx
mov qword ptr [rdi + 24], r11
mov rax, 0
cmovc rax, rdx
add r8, rax
mov qword ptr [rdi + 0], r8
pop rdi
pop rsi
pop rbx
pop r14
pop r13
pop r12
pop r15
ret
fsqr endp
ALIGN 16
fsqr2 proc
push r15
push r12
push r13
push r14
push rbx
push rsi
push rdi
mov rdi, rcx
mov rsi, rdx
mov rdx, r8
mov rbx, rdx
mov rdx, qword ptr [rsi + 0]
mulx r14, r8, qword ptr [rsi + 8]
xor r15, r15
mulx r10, r9, qword ptr [rsi + 16]
adcx r9, r14
mulx rcx, rax, qword ptr [rsi + 24]
adcx r10, rax
mov rdx, qword ptr [rsi + 24]
mulx r12, r11, qword ptr [rsi + 8]
adcx r11, rcx
mulx r13, rax, qword ptr [rsi + 16]
adcx r12, rax
mov rdx, qword ptr [rsi + 8]
adcx r13, r15
mulx rcx, rax, qword ptr [rsi + 16]
mov r14, 0
xor r15, r15
adox r10, rax
adcx r8, r8
adox r11, rcx
adcx r9, r9
adox r12, r15
adcx r10, r10
adox r13, r15
adcx r11, r11
adox r14, r15
adcx r12, r12
adcx r13, r13
adcx r14, r14
mov rdx, qword ptr [rsi + 0]
mulx rcx, rax, rdx
mov qword ptr [rdi + 0], rax
add r8, rcx
mov qword ptr [rdi + 8], r8
mov rdx, qword ptr [rsi + 8]
mulx rcx, rax, rdx
adcx r9, rax
mov qword ptr [rdi + 16], r9
adcx r10, rcx
mov qword ptr [rdi + 24], r10
mov rdx, qword ptr [rsi + 16]
mulx rcx, rax, rdx
adcx r11, rax
mov qword ptr [rdi + 32], r11
adcx r12, rcx
mov qword ptr [rdi + 40], r12
mov rdx, qword ptr [rsi + 24]
mulx rcx, rax, rdx
adcx r13, rax
mov qword ptr [rdi + 48], r13
adcx r14, rcx
mov qword ptr [rdi + 56], r14
mov rdx, qword ptr [rsi + 32]
mulx r14, r8, qword ptr [rsi + 40]
xor r15, r15
mulx r10, r9, qword ptr [rsi + 48]
adcx r9, r14
mulx rcx, rax, qword ptr [rsi + 56]
adcx r10, rax
mov rdx, qword ptr [rsi + 56]
mulx r12, r11, qword ptr [rsi + 40]
adcx r11, rcx
mulx r13, rax, qword ptr [rsi + 48]
adcx r12, rax
mov rdx, qword ptr [rsi + 40]
adcx r13, r15
mulx rcx, rax, qword ptr [rsi + 48]
mov r14, 0
xor r15, r15
adox r10, rax
adcx r8, r8
adox r11, rcx
adcx r9, r9
adox r12, r15
adcx r10, r10
adox r13, r15
adcx r11, r11
adox r14, r15
adcx r12, r12
adcx r13, r13
adcx r14, r14
mov rdx, qword ptr [rsi + 32]
mulx rcx, rax, rdx
mov qword ptr [rdi + 64], rax
add r8, rcx
mov qword ptr [rdi + 72], r8
mov rdx, qword ptr [rsi + 40]
mulx rcx, rax, rdx
adcx r9, rax
mov qword ptr [rdi + 80], r9
adcx r10, rcx
mov qword ptr [rdi + 88], r10
mov rdx, qword ptr [rsi + 48]
mulx rcx, rax, rdx
adcx r11, rax
mov qword ptr [rdi + 96], r11
adcx r12, rcx
mov qword ptr [rdi + 104], r12
mov rdx, qword ptr [rsi + 56]
mulx rcx, rax, rdx
adcx r13, rax
mov qword ptr [rdi + 112], r13
adcx r14, rcx
mov qword ptr [rdi + 120], r14
mov rsi, rdi
mov rdi, rbx
mov rdx, 38
mulx r13, r8, qword ptr [rsi + 32]
xor rcx, rcx
adox r8, qword ptr [rsi + 0]
mulx r12, r9, qword ptr [rsi + 40]
adcx r9, r13
adox r9, qword ptr [rsi + 8]
mulx r13, r10, qword ptr [rsi + 48]
adcx r10, r12
adox r10, qword ptr [rsi + 16]
mulx rax, r11, qword ptr [rsi + 56]
adcx r11, r13
adox r11, qword ptr [rsi + 24]
adcx rax, rcx
adox rax, rcx
imul rax, rdx
add r8, rax
adcx r9, rcx
mov qword ptr [rdi + 8], r9
adcx r10, rcx
mov qword ptr [rdi + 16], r10
adcx r11, rcx
mov qword ptr [rdi + 24], r11
mov rax, 0
cmovc rax, rdx
add r8, rax
mov qword ptr [rdi + 0], r8
mov rdx, 38
mulx r13, r8, qword ptr [rsi + 96]
xor rcx, rcx
adox r8, qword ptr [rsi + 64]
mulx r12, r9, qword ptr [rsi + 104]
adcx r9, r13
adox r9, qword ptr [rsi + 72]
mulx r13, r10, qword ptr [rsi + 112]
adcx r10, r12
adox r10, qword ptr [rsi + 80]
mulx rax, r11, qword ptr [rsi + 120]
adcx r11, r13
adox r11, qword ptr [rsi + 88]
adcx rax, rcx
adox rax, rcx
imul rax, rdx
add r8, rax
adcx r9, rcx
mov qword ptr [rdi + 40], r9
adcx r10, rcx
mov qword ptr [rdi + 48], r10
adcx r11, rcx
mov qword ptr [rdi + 56], r11
mov rax, 0
cmovc rax, rdx
add r8, rax
mov qword ptr [rdi + 32], r8
pop rdi
pop rsi
pop rbx
pop r14
pop r13
pop r12
pop r15
ret
fsqr2 endp
ALIGN 16
cswap2 proc
push rdi
push rsi
mov rdi, rcx
mov rsi, rdx
mov rdx, r8
add rdi, 18446744073709551615
mov r8, qword ptr [rsi + 0]
mov r9, qword ptr [rdx + 0]
mov r10, r8
cmovc r8, r9
cmovc r9, r10
mov qword ptr [rsi + 0], r8
mov qword ptr [rdx + 0], r9
mov r8, qword ptr [rsi + 8]
mov r9, qword ptr [rdx + 8]
mov r10, r8
cmovc r8, r9
cmovc r9, r10
mov qword ptr [rsi + 8], r8
mov qword ptr [rdx + 8], r9
mov r8, qword ptr [rsi + 16]
mov r9, qword ptr [rdx + 16]
mov r10, r8
cmovc r8, r9
cmovc r9, r10
mov qword ptr [rsi + 16], r8
mov qword ptr [rdx + 16], r9
mov r8, qword ptr [rsi + 24]
mov r9, qword ptr [rdx + 24]
mov r10, r8
cmovc r8, r9
cmovc r9, r10
mov qword ptr [rsi + 24], r8
mov qword ptr [rdx + 24], r9
mov r8, qword ptr [rsi + 32]
mov r9, qword ptr [rdx + 32]
mov r10, r8
cmovc r8, r9
cmovc r9, r10
mov qword ptr [rsi + 32], r8
mov qword ptr [rdx + 32], r9
mov r8, qword ptr [rsi + 40]
mov r9, qword ptr [rdx + 40]
mov r10, r8
cmovc r8, r9
cmovc r9, r10
mov qword ptr [rsi + 40], r8
mov qword ptr [rdx + 40], r9
mov r8, qword ptr [rsi + 48]
mov r9, qword ptr [rdx + 48]
mov r10, r8
cmovc r8, r9
cmovc r9, r10
mov qword ptr [rsi + 48], r8
mov qword ptr [rdx + 48], r9
mov r8, qword ptr [rsi + 56]
mov r9, qword ptr [rdx + 56]
mov r10, r8
cmovc r8, r9
cmovc r9, r10
mov qword ptr [rsi + 56], r8
mov qword ptr [rdx + 56], r9
pop rsi
pop rdi
ret
cswap2 endp
end
|
; A270867: a(n) = n^3 + 2*n^2 + 4*n + 1.
; 1,8,25,58,113,196,313,470,673,928,1241,1618,2065,2588,3193,3886,4673,5560,6553,7658,8881,10228,11705,13318,15073,16976,19033,21250,23633,26188,28921,31838,34945,38248,41753,45466,49393,53540,57913,62518,67361,72448,77785,83378,89233,95356,101753,108430,115393,122648,130201,138058,146225,154708,163513,172646,182113,191920,202073,212578,223441,234668,246265,258238,270593,283336,296473,310010,323953,338308,353081,368278,383905,399968,416473,433426,450833,468700,487033,505838,525121,544888,565145,585898,607153,628916,651193,673990,697313,721168,745561,770498,795985,822028,848633,875806,903553,931880,960793,990298,1020401,1051108,1082425,1114358,1146913,1180096,1213913,1248370,1283473,1319228,1355641,1392718,1430465,1468888,1507993,1547786,1588273,1629460,1671353,1713958,1757281,1801328,1846105,1891618,1937873,1984876,2032633,2081150,2130433,2180488,2231321,2282938,2335345,2388548,2442553,2497366,2552993,2609440,2666713,2724818,2783761,2843548,2904185,2965678,3028033,3091256,3155353,3220330,3286193,3352948,3420601,3489158,3558625,3629008,3700313,3772546,3845713,3919820,3994873,4070878,4147841,4225768,4304665,4384538,4465393,4547236,4630073,4713910,4798753,4884608,4971481,5059378,5148305,5238268,5329273,5421326,5514433,5608600,5703833,5800138,5897521,5995988,6095545,6196198,6297953,6400816,6504793,6609890,6716113,6823468,6931961,7041598,7152385,7264328,7377433,7491706,7607153,7723780,7841593,7960598,8080801,8202208,8324825,8448658,8573713,8699996,8827513,8956270,9086273,9217528,9350041,9483818,9618865,9755188,9892793,10031686,10171873,10313360,10456153,10600258,10745681,10892428,11040505,11189918,11340673,11492776,11646233,11801050,11957233,12114788,12273721,12434038,12595745,12758848,12923353,13089266,13256593,13425340,13595513,13767118,13940161,14114648,14290585,14467978,14646833,14827156,15008953,15192230,15376993,15563248
add $0,1
mov $1,$0
mul $1,$0
sub $0,1
add $1,3
mul $1,$0
add $1,1
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/wm/core/cursor_manager.h"
#include "base/memory/ptr_util.h"
#include "ui/aura/client/cursor_client_observer.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/base/cursor/cursor_size.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
#include "ui/wm/core/native_cursor_manager.h"
#include "ui/wm/test/testing_cursor_client_observer.h"
namespace {
class TestingCursorManager : public wm::NativeCursorManager {
public:
// Overridden from wm::NativeCursorManager:
void SetDisplay(const display::Display& display,
wm::NativeCursorManagerDelegate* delegate) override {}
void SetCursor(gfx::NativeCursor cursor,
wm::NativeCursorManagerDelegate* delegate) override {
delegate->CommitCursor(cursor);
}
void SetVisibility(bool visible,
wm::NativeCursorManagerDelegate* delegate) override {
delegate->CommitVisibility(visible);
}
void SetMouseEventsEnabled(
bool enabled,
wm::NativeCursorManagerDelegate* delegate) override {
delegate->CommitMouseEventsEnabled(enabled);
}
void SetCursorSize(ui::CursorSize cursor_size,
wm::NativeCursorManagerDelegate* delegate) override {
delegate->CommitCursorSize(cursor_size);
}
};
} // namespace
class CursorManagerTest : public aura::test::AuraTestBase {
protected:
CursorManagerTest()
: delegate_(new TestingCursorManager),
cursor_manager_(base::WrapUnique(delegate_)) {}
TestingCursorManager* delegate_;
wm::CursorManager cursor_manager_;
};
TEST_F(CursorManagerTest, ShowHideCursor) {
cursor_manager_.SetCursor(ui::mojom::CursorType::kCopy);
EXPECT_EQ(ui::mojom::CursorType::kCopy, cursor_manager_.GetCursor().type());
cursor_manager_.ShowCursor();
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
cursor_manager_.HideCursor();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
// The current cursor does not change even when the cursor is not shown.
EXPECT_EQ(ui::mojom::CursorType::kCopy, cursor_manager_.GetCursor().type());
// Check if cursor visibility is locked.
cursor_manager_.LockCursor();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
cursor_manager_.ShowCursor();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
cursor_manager_.UnlockCursor();
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
cursor_manager_.LockCursor();
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
cursor_manager_.HideCursor();
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
cursor_manager_.UnlockCursor();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
// Checks setting visiblity while cursor is locked does not affect the
// subsequent uses of UnlockCursor.
cursor_manager_.LockCursor();
cursor_manager_.HideCursor();
cursor_manager_.UnlockCursor();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
cursor_manager_.ShowCursor();
cursor_manager_.LockCursor();
cursor_manager_.UnlockCursor();
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
cursor_manager_.LockCursor();
cursor_manager_.ShowCursor();
cursor_manager_.UnlockCursor();
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
cursor_manager_.HideCursor();
cursor_manager_.LockCursor();
cursor_manager_.UnlockCursor();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
}
// Verifies that LockCursor/UnlockCursor work correctly with
// EnableMouseEvents and DisableMouseEvents
TEST_F(CursorManagerTest, EnableDisableMouseEvents) {
cursor_manager_.SetCursor(ui::mojom::CursorType::kCopy);
EXPECT_EQ(ui::mojom::CursorType::kCopy, cursor_manager_.GetCursor().type());
cursor_manager_.EnableMouseEvents();
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.DisableMouseEvents();
EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
// The current cursor does not change even when the cursor is not shown.
EXPECT_EQ(ui::mojom::CursorType::kCopy, cursor_manager_.GetCursor().type());
// Check if cursor enable state is locked.
cursor_manager_.LockCursor();
EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.EnableMouseEvents();
EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.UnlockCursor();
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.LockCursor();
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.DisableMouseEvents();
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.UnlockCursor();
EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
// Checks enabling cursor while cursor is locked does not affect the
// subsequent uses of UnlockCursor.
cursor_manager_.LockCursor();
cursor_manager_.DisableMouseEvents();
cursor_manager_.UnlockCursor();
EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.EnableMouseEvents();
cursor_manager_.LockCursor();
cursor_manager_.UnlockCursor();
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.LockCursor();
cursor_manager_.EnableMouseEvents();
cursor_manager_.UnlockCursor();
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.DisableMouseEvents();
cursor_manager_.LockCursor();
cursor_manager_.UnlockCursor();
EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
}
TEST_F(CursorManagerTest, SetCursorSize) {
wm::TestingCursorClientObserver observer;
cursor_manager_.AddObserver(&observer);
EXPECT_EQ(ui::CursorSize::kNormal, cursor_manager_.GetCursorSize());
EXPECT_EQ(ui::CursorSize::kNormal, observer.cursor_size());
cursor_manager_.SetCursorSize(ui::CursorSize::kNormal);
EXPECT_EQ(ui::CursorSize::kNormal, cursor_manager_.GetCursorSize());
EXPECT_EQ(ui::CursorSize::kNormal, observer.cursor_size());
cursor_manager_.SetCursorSize(ui::CursorSize::kLarge);
EXPECT_EQ(ui::CursorSize::kLarge, cursor_manager_.GetCursorSize());
EXPECT_EQ(ui::CursorSize::kLarge, observer.cursor_size());
cursor_manager_.SetCursorSize(ui::CursorSize::kNormal);
EXPECT_EQ(ui::CursorSize::kNormal, cursor_manager_.GetCursorSize());
EXPECT_EQ(ui::CursorSize::kNormal, observer.cursor_size());
}
TEST_F(CursorManagerTest, IsMouseEventsEnabled) {
cursor_manager_.EnableMouseEvents();
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.DisableMouseEvents();
EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
}
// Verifies that the mouse events enable state changes correctly when
// ShowCursor/HideCursor and EnableMouseEvents/DisableMouseEvents are used
// together.
TEST_F(CursorManagerTest, ShowAndEnable) {
// Changing the visibility of the cursor does not affect the enable state.
cursor_manager_.EnableMouseEvents();
cursor_manager_.ShowCursor();
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.HideCursor();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.ShowCursor();
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
// When mouse events are disabled, it also gets invisible.
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
cursor_manager_.DisableMouseEvents();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
// When mouse events are enabled, it restores the visibility state.
cursor_manager_.EnableMouseEvents();
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.ShowCursor();
cursor_manager_.DisableMouseEvents();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.EnableMouseEvents();
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.HideCursor();
cursor_manager_.DisableMouseEvents();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.EnableMouseEvents();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
// When mouse events are disabled, ShowCursor is ignored.
cursor_manager_.DisableMouseEvents();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.ShowCursor();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.DisableMouseEvents();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
}
// Verifies that calling DisableMouseEvents multiple times in a row makes no
// difference compared with calling it once.
// This is a regression test for http://crbug.com/169404.
TEST_F(CursorManagerTest, MultipleDisableMouseEvents) {
cursor_manager_.DisableMouseEvents();
cursor_manager_.DisableMouseEvents();
cursor_manager_.EnableMouseEvents();
cursor_manager_.LockCursor();
cursor_manager_.UnlockCursor();
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
}
// Verifies that calling EnableMouseEvents multiple times in a row makes no
// difference compared with calling it once.
TEST_F(CursorManagerTest, MultipleEnableMouseEvents) {
cursor_manager_.DisableMouseEvents();
cursor_manager_.EnableMouseEvents();
cursor_manager_.EnableMouseEvents();
cursor_manager_.LockCursor();
cursor_manager_.UnlockCursor();
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
}
TEST_F(CursorManagerTest, TestCursorClientObserver) {
cursor_manager_.SetCursor(ui::mojom::CursorType::kPointer);
// Add two observers. Both should have OnCursorVisibilityChanged()
// invoked when the visibility of the cursor changes.
wm::TestingCursorClientObserver observer_a;
wm::TestingCursorClientObserver observer_b;
cursor_manager_.AddObserver(&observer_a);
cursor_manager_.AddObserver(&observer_b);
// Initial state before any events have been sent.
observer_a.reset();
observer_b.reset();
EXPECT_FALSE(observer_a.did_visibility_change());
EXPECT_FALSE(observer_b.did_visibility_change());
EXPECT_FALSE(observer_a.is_cursor_visible());
EXPECT_FALSE(observer_b.is_cursor_visible());
EXPECT_FALSE(observer_a.did_cursor_size_change());
EXPECT_FALSE(observer_b.did_cursor_size_change());
// Hide the cursor using HideCursor().
cursor_manager_.HideCursor();
EXPECT_TRUE(observer_a.did_visibility_change());
EXPECT_TRUE(observer_b.did_visibility_change());
EXPECT_FALSE(observer_a.is_cursor_visible());
EXPECT_FALSE(observer_b.is_cursor_visible());
// Set the cursor size.
cursor_manager_.SetCursorSize(ui::CursorSize::kLarge);
EXPECT_TRUE(observer_a.did_cursor_size_change());
EXPECT_EQ(ui::CursorSize::kLarge, observer_a.cursor_size());
EXPECT_TRUE(observer_b.did_cursor_size_change());
EXPECT_EQ(ui::CursorSize::kLarge, observer_b.cursor_size());
// Show the cursor using ShowCursor().
observer_a.reset();
observer_b.reset();
cursor_manager_.ShowCursor();
EXPECT_TRUE(observer_a.did_visibility_change());
EXPECT_TRUE(observer_b.did_visibility_change());
EXPECT_TRUE(observer_a.is_cursor_visible());
EXPECT_TRUE(observer_b.is_cursor_visible());
// Remove observer_b. Its OnCursorVisibilityChanged() should
// not be invoked past this point.
cursor_manager_.RemoveObserver(&observer_b);
// Hide the cursor using HideCursor().
observer_a.reset();
observer_b.reset();
cursor_manager_.HideCursor();
EXPECT_TRUE(observer_a.did_visibility_change());
EXPECT_FALSE(observer_b.did_visibility_change());
EXPECT_FALSE(observer_a.is_cursor_visible());
// Set back the cursor set to normal.
cursor_manager_.SetCursorSize(ui::CursorSize::kNormal);
EXPECT_TRUE(observer_a.did_cursor_size_change());
EXPECT_EQ(ui::CursorSize::kNormal, observer_a.cursor_size());
EXPECT_FALSE(observer_b.did_cursor_size_change());
// Show the cursor using ShowCursor().
observer_a.reset();
observer_b.reset();
cursor_manager_.ShowCursor();
EXPECT_TRUE(observer_a.did_visibility_change());
EXPECT_FALSE(observer_b.did_visibility_change());
EXPECT_TRUE(observer_a.is_cursor_visible());
// Hide the cursor by changing the cursor type.
cursor_manager_.SetCursor(ui::mojom::CursorType::kPointer);
observer_a.reset();
cursor_manager_.SetCursor(ui::mojom::CursorType::kNone);
EXPECT_TRUE(observer_a.did_visibility_change());
EXPECT_FALSE(observer_a.is_cursor_visible());
// Show the cursor by changing the cursor type.
observer_a.reset();
cursor_manager_.SetCursor(ui::mojom::CursorType::kPointer);
EXPECT_TRUE(observer_a.did_visibility_change());
EXPECT_TRUE(observer_a.is_cursor_visible());
// Changing the type to another visible type doesn't cause unnecessary
// callbacks.
observer_a.reset();
cursor_manager_.SetCursor(ui::mojom::CursorType::kHand);
EXPECT_FALSE(observer_a.did_visibility_change());
EXPECT_FALSE(observer_a.is_cursor_visible());
// If the type is kNone, showing the cursor shouldn't cause observers to
// think that the cursor is now visible.
cursor_manager_.HideCursor();
cursor_manager_.SetCursor(ui::mojom::CursorType::kNone);
observer_a.reset();
cursor_manager_.ShowCursor();
EXPECT_TRUE(observer_a.did_visibility_change());
EXPECT_FALSE(observer_a.is_cursor_visible());
}
// This test validates that the cursor visiblity state is restored when a
// CursorManager instance is destroyed and recreated.
TEST(CursorManagerCreateDestroyTest, VisibilityTest) {
// This block ensures that the cursor is hidden when the CursorManager
// instance is destroyed.
{
wm::CursorManager cursor_manager1(
base::WrapUnique(new TestingCursorManager));
cursor_manager1.ShowCursor();
EXPECT_TRUE(cursor_manager1.IsCursorVisible());
cursor_manager1.HideCursor();
EXPECT_FALSE(cursor_manager1.IsCursorVisible());
}
// This block validates that the cursor is hidden initially. It ensures that
// the cursor is visible when the CursorManager instance is destroyed.
{
wm::CursorManager cursor_manager2(
base::WrapUnique(new TestingCursorManager));
EXPECT_FALSE(cursor_manager2.IsCursorVisible());
cursor_manager2.ShowCursor();
EXPECT_TRUE(cursor_manager2.IsCursorVisible());
}
// This block validates that the cursor is visible initially. It then
// performs normal cursor visibility operations.
{
wm::CursorManager cursor_manager3(
base::WrapUnique(new TestingCursorManager));
EXPECT_TRUE(cursor_manager3.IsCursorVisible());
cursor_manager3.HideCursor();
EXPECT_FALSE(cursor_manager3.IsCursorVisible());
}
}
|
; A001614: Connell sequence: 1 odd, 2 even, 3 odd, ...
; 1,2,4,5,7,9,10,12,14,16,17,19,21,23,25,26,28,30,32,34,36,37,39,41,43,45,47,49,50,52,54,56,58,60,62,64,65,67,69,71,73,75,77,79,81,82,84,86,88,90,92,94,96,98,100,101,103,105,107,109,111,113,115,117,119,121,122,124,126,128,130,132,134,136,138,140,142,144,145,147,149,151,153,155,157,159,161,163,165,167,169,170,172,174,176,178,180,182,184,186,188,190,192,194,196,197,199,201,203,205,207,209,211,213,215,217,219,221,223,225,226,228,230,232,234,236,238,240,242,244,246,248,250,252,254,256,257,259,261,263,265,267,269,271,273,275,277,279,281,283,285,287,289,290,292,294,296,298,300,302,304,306,308,310,312,314,316,318,320,322,324,325,327,329,331,333,335,337,339,341,343,345,347,349,351,353,355,357,359,361,362,364,366,368,370,372,374,376,378,380,382,384,386,388,390,392,394,396,398,400,401,403,405,407,409,411,413,415,417,419,421,423,425,427,429,431,433,435,437,439,441,442,444,446,448,450,452,454,456,458,460,462,464,466,468,470,472,474,476,478
mul $0,2
mov $1,2
add $1,$0
add $0,$1
lpb $0,1
sub $1,1
add $2,4
trn $0,$2
lpe
|
default rel
%define XMMWORD
%define YMMWORD
%define ZMMWORD
section .text code align=64
EXTERN OPENSSL_ia32cap_P
global bn_mul_mont
ALIGN 16
bn_mul_mont:
mov QWORD[8+rsp],rdi ;WIN64 prologue
mov QWORD[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_bn_mul_mont:
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD[40+rsp]
mov r9,QWORD[48+rsp]
test r9d,3
jnz NEAR $L$mul_enter
cmp r9d,8
jb NEAR $L$mul_enter
cmp rdx,rsi
jne NEAR $L$mul4x_enter
test r9d,7
jz NEAR $L$sqr8x_enter
jmp NEAR $L$mul4x_enter
ALIGN 16
$L$mul_enter:
push rbx
push rbp
push r12
push r13
push r14
push r15
mov r9d,r9d
lea r10,[2+r9]
mov r11,rsp
neg r10
lea rsp,[r10*8+rsp]
and rsp,-1024
mov QWORD[8+r9*8+rsp],r11
$L$mul_body:
mov r12,rdx
mov r8,QWORD[r8]
mov rbx,QWORD[r12]
mov rax,QWORD[rsi]
xor r14,r14
xor r15,r15
mov rbp,r8
mul rbx
mov r10,rax
mov rax,QWORD[rcx]
imul rbp,r10
mov r11,rdx
mul rbp
add r10,rax
mov rax,QWORD[8+rsi]
adc rdx,0
mov r13,rdx
lea r15,[1+r15]
jmp NEAR $L$1st_enter
ALIGN 16
$L$1st:
add r13,rax
mov rax,QWORD[r15*8+rsi]
adc rdx,0
add r13,r11
mov r11,r10
adc rdx,0
mov QWORD[((-16))+r15*8+rsp],r13
mov r13,rdx
$L$1st_enter:
mul rbx
add r11,rax
mov rax,QWORD[r15*8+rcx]
adc rdx,0
lea r15,[1+r15]
mov r10,rdx
mul rbp
cmp r15,r9
jne NEAR $L$1st
add r13,rax
mov rax,QWORD[rsi]
adc rdx,0
add r13,r11
adc rdx,0
mov QWORD[((-16))+r15*8+rsp],r13
mov r13,rdx
mov r11,r10
xor rdx,rdx
add r13,r11
adc rdx,0
mov QWORD[((-8))+r9*8+rsp],r13
mov QWORD[r9*8+rsp],rdx
lea r14,[1+r14]
jmp NEAR $L$outer
ALIGN 16
$L$outer:
mov rbx,QWORD[r14*8+r12]
xor r15,r15
mov rbp,r8
mov r10,QWORD[rsp]
mul rbx
add r10,rax
mov rax,QWORD[rcx]
adc rdx,0
imul rbp,r10
mov r11,rdx
mul rbp
add r10,rax
mov rax,QWORD[8+rsi]
adc rdx,0
mov r10,QWORD[8+rsp]
mov r13,rdx
lea r15,[1+r15]
jmp NEAR $L$inner_enter
ALIGN 16
$L$inner:
add r13,rax
mov rax,QWORD[r15*8+rsi]
adc rdx,0
add r13,r10
mov r10,QWORD[r15*8+rsp]
adc rdx,0
mov QWORD[((-16))+r15*8+rsp],r13
mov r13,rdx
$L$inner_enter:
mul rbx
add r11,rax
mov rax,QWORD[r15*8+rcx]
adc rdx,0
add r10,r11
mov r11,rdx
adc r11,0
lea r15,[1+r15]
mul rbp
cmp r15,r9
jne NEAR $L$inner
add r13,rax
mov rax,QWORD[rsi]
adc rdx,0
add r13,r10
mov r10,QWORD[r15*8+rsp]
adc rdx,0
mov QWORD[((-16))+r15*8+rsp],r13
mov r13,rdx
xor rdx,rdx
add r13,r11
adc rdx,0
add r13,r10
adc rdx,0
mov QWORD[((-8))+r9*8+rsp],r13
mov QWORD[r9*8+rsp],rdx
lea r14,[1+r14]
cmp r14,r9
jb NEAR $L$outer
xor r14,r14
mov rax,QWORD[rsp]
lea rsi,[rsp]
mov r15,r9
jmp NEAR $L$sub
ALIGN 16
$L$sub: sbb rax,QWORD[r14*8+rcx]
mov QWORD[r14*8+rdi],rax
mov rax,QWORD[8+r14*8+rsi]
lea r14,[1+r14]
dec r15
jnz NEAR $L$sub
sbb rax,0
xor r14,r14
mov r15,r9
ALIGN 16
$L$copy:
mov rsi,QWORD[r14*8+rsp]
mov rcx,QWORD[r14*8+rdi]
xor rsi,rcx
and rsi,rax
xor rsi,rcx
mov QWORD[r14*8+rsp],r14
mov QWORD[r14*8+rdi],rsi
lea r14,[1+r14]
sub r15,1
jnz NEAR $L$copy
mov rsi,QWORD[8+r9*8+rsp]
mov rax,1
mov r15,QWORD[rsi]
mov r14,QWORD[8+rsi]
mov r13,QWORD[16+rsi]
mov r12,QWORD[24+rsi]
mov rbp,QWORD[32+rsi]
mov rbx,QWORD[40+rsi]
lea rsp,[48+rsi]
$L$mul_epilogue:
mov rdi,QWORD[8+rsp] ;WIN64 epilogue
mov rsi,QWORD[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_bn_mul_mont:
ALIGN 16
bn_mul4x_mont:
mov QWORD[8+rsp],rdi ;WIN64 prologue
mov QWORD[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_bn_mul4x_mont:
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD[40+rsp]
mov r9,QWORD[48+rsp]
$L$mul4x_enter:
push rbx
push rbp
push r12
push r13
push r14
push r15
mov r9d,r9d
lea r10,[4+r9]
mov r11,rsp
neg r10
lea rsp,[r10*8+rsp]
and rsp,-1024
mov QWORD[8+r9*8+rsp],r11
$L$mul4x_body:
mov QWORD[16+r9*8+rsp],rdi
mov r12,rdx
mov r8,QWORD[r8]
mov rbx,QWORD[r12]
mov rax,QWORD[rsi]
xor r14,r14
xor r15,r15
mov rbp,r8
mul rbx
mov r10,rax
mov rax,QWORD[rcx]
imul rbp,r10
mov r11,rdx
mul rbp
add r10,rax
mov rax,QWORD[8+rsi]
adc rdx,0
mov rdi,rdx
mul rbx
add r11,rax
mov rax,QWORD[8+rcx]
adc rdx,0
mov r10,rdx
mul rbp
add rdi,rax
mov rax,QWORD[16+rsi]
adc rdx,0
add rdi,r11
lea r15,[4+r15]
adc rdx,0
mov QWORD[rsp],rdi
mov r13,rdx
jmp NEAR $L$1st4x
ALIGN 16
$L$1st4x:
mul rbx
add r10,rax
mov rax,QWORD[((-16))+r15*8+rcx]
adc rdx,0
mov r11,rdx
mul rbp
add r13,rax
mov rax,QWORD[((-8))+r15*8+rsi]
adc rdx,0
add r13,r10
adc rdx,0
mov QWORD[((-24))+r15*8+rsp],r13
mov rdi,rdx
mul rbx
add r11,rax
mov rax,QWORD[((-8))+r15*8+rcx]
adc rdx,0
mov r10,rdx
mul rbp
add rdi,rax
mov rax,QWORD[r15*8+rsi]
adc rdx,0
add rdi,r11
adc rdx,0
mov QWORD[((-16))+r15*8+rsp],rdi
mov r13,rdx
mul rbx
add r10,rax
mov rax,QWORD[r15*8+rcx]
adc rdx,0
mov r11,rdx
mul rbp
add r13,rax
mov rax,QWORD[8+r15*8+rsi]
adc rdx,0
add r13,r10
adc rdx,0
mov QWORD[((-8))+r15*8+rsp],r13
mov rdi,rdx
mul rbx
add r11,rax
mov rax,QWORD[8+r15*8+rcx]
adc rdx,0
lea r15,[4+r15]
mov r10,rdx
mul rbp
add rdi,rax
mov rax,QWORD[((-16))+r15*8+rsi]
adc rdx,0
add rdi,r11
adc rdx,0
mov QWORD[((-32))+r15*8+rsp],rdi
mov r13,rdx
cmp r15,r9
jb NEAR $L$1st4x
mul rbx
add r10,rax
mov rax,QWORD[((-16))+r15*8+rcx]
adc rdx,0
mov r11,rdx
mul rbp
add r13,rax
mov rax,QWORD[((-8))+r15*8+rsi]
adc rdx,0
add r13,r10
adc rdx,0
mov QWORD[((-24))+r15*8+rsp],r13
mov rdi,rdx
mul rbx
add r11,rax
mov rax,QWORD[((-8))+r15*8+rcx]
adc rdx,0
mov r10,rdx
mul rbp
add rdi,rax
mov rax,QWORD[rsi]
adc rdx,0
add rdi,r11
adc rdx,0
mov QWORD[((-16))+r15*8+rsp],rdi
mov r13,rdx
xor rdi,rdi
add r13,r10
adc rdi,0
mov QWORD[((-8))+r15*8+rsp],r13
mov QWORD[r15*8+rsp],rdi
lea r14,[1+r14]
ALIGN 4
$L$outer4x:
mov rbx,QWORD[r14*8+r12]
xor r15,r15
mov r10,QWORD[rsp]
mov rbp,r8
mul rbx
add r10,rax
mov rax,QWORD[rcx]
adc rdx,0
imul rbp,r10
mov r11,rdx
mul rbp
add r10,rax
mov rax,QWORD[8+rsi]
adc rdx,0
mov rdi,rdx
mul rbx
add r11,rax
mov rax,QWORD[8+rcx]
adc rdx,0
add r11,QWORD[8+rsp]
adc rdx,0
mov r10,rdx
mul rbp
add rdi,rax
mov rax,QWORD[16+rsi]
adc rdx,0
add rdi,r11
lea r15,[4+r15]
adc rdx,0
mov QWORD[rsp],rdi
mov r13,rdx
jmp NEAR $L$inner4x
ALIGN 16
$L$inner4x:
mul rbx
add r10,rax
mov rax,QWORD[((-16))+r15*8+rcx]
adc rdx,0
add r10,QWORD[((-16))+r15*8+rsp]
adc rdx,0
mov r11,rdx
mul rbp
add r13,rax
mov rax,QWORD[((-8))+r15*8+rsi]
adc rdx,0
add r13,r10
adc rdx,0
mov QWORD[((-24))+r15*8+rsp],r13
mov rdi,rdx
mul rbx
add r11,rax
mov rax,QWORD[((-8))+r15*8+rcx]
adc rdx,0
add r11,QWORD[((-8))+r15*8+rsp]
adc rdx,0
mov r10,rdx
mul rbp
add rdi,rax
mov rax,QWORD[r15*8+rsi]
adc rdx,0
add rdi,r11
adc rdx,0
mov QWORD[((-16))+r15*8+rsp],rdi
mov r13,rdx
mul rbx
add r10,rax
mov rax,QWORD[r15*8+rcx]
adc rdx,0
add r10,QWORD[r15*8+rsp]
adc rdx,0
mov r11,rdx
mul rbp
add r13,rax
mov rax,QWORD[8+r15*8+rsi]
adc rdx,0
add r13,r10
adc rdx,0
mov QWORD[((-8))+r15*8+rsp],r13
mov rdi,rdx
mul rbx
add r11,rax
mov rax,QWORD[8+r15*8+rcx]
adc rdx,0
add r11,QWORD[8+r15*8+rsp]
adc rdx,0
lea r15,[4+r15]
mov r10,rdx
mul rbp
add rdi,rax
mov rax,QWORD[((-16))+r15*8+rsi]
adc rdx,0
add rdi,r11
adc rdx,0
mov QWORD[((-32))+r15*8+rsp],rdi
mov r13,rdx
cmp r15,r9
jb NEAR $L$inner4x
mul rbx
add r10,rax
mov rax,QWORD[((-16))+r15*8+rcx]
adc rdx,0
add r10,QWORD[((-16))+r15*8+rsp]
adc rdx,0
mov r11,rdx
mul rbp
add r13,rax
mov rax,QWORD[((-8))+r15*8+rsi]
adc rdx,0
add r13,r10
adc rdx,0
mov QWORD[((-24))+r15*8+rsp],r13
mov rdi,rdx
mul rbx
add r11,rax
mov rax,QWORD[((-8))+r15*8+rcx]
adc rdx,0
add r11,QWORD[((-8))+r15*8+rsp]
adc rdx,0
lea r14,[1+r14]
mov r10,rdx
mul rbp
add rdi,rax
mov rax,QWORD[rsi]
adc rdx,0
add rdi,r11
adc rdx,0
mov QWORD[((-16))+r15*8+rsp],rdi
mov r13,rdx
xor rdi,rdi
add r13,r10
adc rdi,0
add r13,QWORD[r9*8+rsp]
adc rdi,0
mov QWORD[((-8))+r15*8+rsp],r13
mov QWORD[r15*8+rsp],rdi
cmp r14,r9
jb NEAR $L$outer4x
mov rdi,QWORD[16+r9*8+rsp]
mov rax,QWORD[rsp]
mov rdx,QWORD[8+rsp]
shr r9,2
lea rsi,[rsp]
xor r14,r14
sub rax,QWORD[rcx]
mov rbx,QWORD[16+rsi]
mov rbp,QWORD[24+rsi]
sbb rdx,QWORD[8+rcx]
lea r15,[((-1))+r9]
jmp NEAR $L$sub4x
ALIGN 16
$L$sub4x:
mov QWORD[r14*8+rdi],rax
mov QWORD[8+r14*8+rdi],rdx
sbb rbx,QWORD[16+r14*8+rcx]
mov rax,QWORD[32+r14*8+rsi]
mov rdx,QWORD[40+r14*8+rsi]
sbb rbp,QWORD[24+r14*8+rcx]
mov QWORD[16+r14*8+rdi],rbx
mov QWORD[24+r14*8+rdi],rbp
sbb rax,QWORD[32+r14*8+rcx]
mov rbx,QWORD[48+r14*8+rsi]
mov rbp,QWORD[56+r14*8+rsi]
sbb rdx,QWORD[40+r14*8+rcx]
lea r14,[4+r14]
dec r15
jnz NEAR $L$sub4x
mov QWORD[r14*8+rdi],rax
mov rax,QWORD[32+r14*8+rsi]
sbb rbx,QWORD[16+r14*8+rcx]
mov QWORD[8+r14*8+rdi],rdx
sbb rbp,QWORD[24+r14*8+rcx]
mov QWORD[16+r14*8+rdi],rbx
sbb rax,0
DB 66h, 48h, 0fh, 6eh, 0c0h
punpcklqdq xmm0,xmm0
mov QWORD[24+r14*8+rdi],rbp
xor r14,r14
mov r15,r9
pxor xmm5,xmm5
jmp NEAR $L$copy4x
ALIGN 16
$L$copy4x:
movdqu xmm2,XMMWORD[r14*1+rsp]
movdqu xmm4,XMMWORD[16+r14*1+rsp]
movdqu xmm1,XMMWORD[r14*1+rdi]
movdqu xmm3,XMMWORD[16+r14*1+rdi]
pxor xmm2,xmm1
pxor xmm4,xmm3
pand xmm2,xmm0
pand xmm4,xmm0
pxor xmm2,xmm1
pxor xmm4,xmm3
movdqu XMMWORD[r14*1+rdi],xmm2
movdqu XMMWORD[16+r14*1+rdi],xmm4
movdqa XMMWORD[r14*1+rsp],xmm5
movdqa XMMWORD[16+r14*1+rsp],xmm5
lea r14,[32+r14]
dec r15
jnz NEAR $L$copy4x
shl r9,2
mov rsi,QWORD[8+r9*8+rsp]
mov rax,1
mov r15,QWORD[rsi]
mov r14,QWORD[8+rsi]
mov r13,QWORD[16+rsi]
mov r12,QWORD[24+rsi]
mov rbp,QWORD[32+rsi]
mov rbx,QWORD[40+rsi]
lea rsp,[48+rsi]
$L$mul4x_epilogue:
mov rdi,QWORD[8+rsp] ;WIN64 epilogue
mov rsi,QWORD[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_bn_mul4x_mont:
EXTERN bn_sqr8x_internal
ALIGN 32
bn_sqr8x_mont:
mov QWORD[8+rsp],rdi ;WIN64 prologue
mov QWORD[16+rsp],rsi
mov rax,rsp
$L$SEH_begin_bn_sqr8x_mont:
mov rdi,rcx
mov rsi,rdx
mov rdx,r8
mov rcx,r9
mov r8,QWORD[40+rsp]
mov r9,QWORD[48+rsp]
$L$sqr8x_enter:
mov rax,rsp
push rbx
push rbp
push r12
push r13
push r14
push r15
mov r10d,r9d
shl r9d,3
shl r10,3+2
neg r9
lea r11,[((-64))+r9*2+rsp]
mov r8,QWORD[r8]
sub r11,rsi
and r11,4095
cmp r10,r11
jb NEAR $L$sqr8x_sp_alt
sub rsp,r11
lea rsp,[((-64))+r9*2+rsp]
jmp NEAR $L$sqr8x_sp_done
ALIGN 32
$L$sqr8x_sp_alt:
lea r10,[((4096-64))+r9*2]
lea rsp,[((-64))+r9*2+rsp]
sub r11,r10
mov r10,0
cmovc r11,r10
sub rsp,r11
$L$sqr8x_sp_done:
and rsp,-64
mov r10,r9
neg r9
mov QWORD[32+rsp],r8
mov QWORD[40+rsp],rax
$L$sqr8x_body:
DB 102,72,15,110,209
pxor xmm0,xmm0
DB 102,72,15,110,207
DB 102,73,15,110,218
call bn_sqr8x_internal
lea rbx,[r9*1+rdi]
mov rcx,r9
mov rdx,r9
DB 102,72,15,126,207
sar rcx,3+2
jmp NEAR $L$sqr8x_sub
ALIGN 32
$L$sqr8x_sub:
mov r12,QWORD[rbx]
mov r13,QWORD[8+rbx]
mov r14,QWORD[16+rbx]
mov r15,QWORD[24+rbx]
lea rbx,[32+rbx]
sbb r12,QWORD[rbp]
sbb r13,QWORD[8+rbp]
sbb r14,QWORD[16+rbp]
sbb r15,QWORD[24+rbp]
lea rbp,[32+rbp]
mov QWORD[rdi],r12
mov QWORD[8+rdi],r13
mov QWORD[16+rdi],r14
mov QWORD[24+rdi],r15
lea rdi,[32+rdi]
inc rcx
jnz NEAR $L$sqr8x_sub
sbb rax,0
lea rbx,[r9*1+rbx]
lea rdi,[r9*1+rdi]
DB 102,72,15,110,200
pxor xmm0,xmm0
pshufd xmm1,xmm1,0
mov rsi,QWORD[40+rsp]
jmp NEAR $L$sqr8x_cond_copy
ALIGN 32
$L$sqr8x_cond_copy:
movdqa xmm2,XMMWORD[rbx]
movdqa xmm3,XMMWORD[16+rbx]
lea rbx,[32+rbx]
movdqu xmm4,XMMWORD[rdi]
movdqu xmm5,XMMWORD[16+rdi]
lea rdi,[32+rdi]
movdqa XMMWORD[(-32)+rbx],xmm0
movdqa XMMWORD[(-16)+rbx],xmm0
movdqa XMMWORD[(-32)+rdx*1+rbx],xmm0
movdqa XMMWORD[(-16)+rdx*1+rbx],xmm0
pcmpeqd xmm0,xmm1
pand xmm2,xmm1
pand xmm3,xmm1
pand xmm4,xmm0
pand xmm5,xmm0
pxor xmm0,xmm0
por xmm4,xmm2
por xmm5,xmm3
movdqu XMMWORD[(-32)+rdi],xmm4
movdqu XMMWORD[(-16)+rdi],xmm5
add r9,32
jnz NEAR $L$sqr8x_cond_copy
mov rax,1
mov r15,QWORD[((-48))+rsi]
mov r14,QWORD[((-40))+rsi]
mov r13,QWORD[((-32))+rsi]
mov r12,QWORD[((-24))+rsi]
mov rbp,QWORD[((-16))+rsi]
mov rbx,QWORD[((-8))+rsi]
lea rsp,[rsi]
$L$sqr8x_epilogue:
mov rdi,QWORD[8+rsp] ;WIN64 epilogue
mov rsi,QWORD[16+rsp]
DB 0F3h,0C3h ;repret
$L$SEH_end_bn_sqr8x_mont:
DB 77,111,110,116,103,111,109,101,114,121,32,77,117,108,116,105
DB 112,108,105,99,97,116,105,111,110,32,102,111,114,32,120,56
DB 54,95,54,52,44,32,67,82,89,80,84,79,71,65,77,83
DB 32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115
DB 115,108,46,111,114,103,62,0
ALIGN 16
EXTERN __imp_RtlVirtualUnwind
ALIGN 16
mul_handler:
push rsi
push rdi
push rbx
push rbp
push r12
push r13
push r14
push r15
pushfq
sub rsp,64
mov rax,QWORD[120+r8]
mov rbx,QWORD[248+r8]
mov rsi,QWORD[8+r9]
mov r11,QWORD[56+r9]
mov r10d,DWORD[r11]
lea r10,[r10*1+rsi]
cmp rbx,r10
jb NEAR $L$common_seh_tail
mov rax,QWORD[152+r8]
mov r10d,DWORD[4+r11]
lea r10,[r10*1+rsi]
cmp rbx,r10
jae NEAR $L$common_seh_tail
mov r10,QWORD[192+r8]
mov rax,QWORD[8+r10*8+rax]
lea rax,[48+rax]
mov rbx,QWORD[((-8))+rax]
mov rbp,QWORD[((-16))+rax]
mov r12,QWORD[((-24))+rax]
mov r13,QWORD[((-32))+rax]
mov r14,QWORD[((-40))+rax]
mov r15,QWORD[((-48))+rax]
mov QWORD[144+r8],rbx
mov QWORD[160+r8],rbp
mov QWORD[216+r8],r12
mov QWORD[224+r8],r13
mov QWORD[232+r8],r14
mov QWORD[240+r8],r15
jmp NEAR $L$common_seh_tail
ALIGN 16
sqr_handler:
push rsi
push rdi
push rbx
push rbp
push r12
push r13
push r14
push r15
pushfq
sub rsp,64
mov rax,QWORD[120+r8]
mov rbx,QWORD[248+r8]
mov rsi,QWORD[8+r9]
mov r11,QWORD[56+r9]
mov r10d,DWORD[r11]
lea r10,[r10*1+rsi]
cmp rbx,r10
jb NEAR $L$common_seh_tail
mov rax,QWORD[152+r8]
mov r10d,DWORD[4+r11]
lea r10,[r10*1+rsi]
cmp rbx,r10
jae NEAR $L$common_seh_tail
mov rax,QWORD[40+rax]
mov rbx,QWORD[((-8))+rax]
mov rbp,QWORD[((-16))+rax]
mov r12,QWORD[((-24))+rax]
mov r13,QWORD[((-32))+rax]
mov r14,QWORD[((-40))+rax]
mov r15,QWORD[((-48))+rax]
mov QWORD[144+r8],rbx
mov QWORD[160+r8],rbp
mov QWORD[216+r8],r12
mov QWORD[224+r8],r13
mov QWORD[232+r8],r14
mov QWORD[240+r8],r15
$L$common_seh_tail:
mov rdi,QWORD[8+rax]
mov rsi,QWORD[16+rax]
mov QWORD[152+r8],rax
mov QWORD[168+r8],rsi
mov QWORD[176+r8],rdi
mov rdi,QWORD[40+r9]
mov rsi,r8
mov ecx,154
DD 0xa548f3fc
mov rsi,r9
xor rcx,rcx
mov rdx,QWORD[8+rsi]
mov r8,QWORD[rsi]
mov r9,QWORD[16+rsi]
mov r10,QWORD[40+rsi]
lea r11,[56+rsi]
lea r12,[24+rsi]
mov QWORD[32+rsp],r10
mov QWORD[40+rsp],r11
mov QWORD[48+rsp],r12
mov QWORD[56+rsp],rcx
call QWORD[__imp_RtlVirtualUnwind]
mov eax,1
add rsp,64
popfq
pop r15
pop r14
pop r13
pop r12
pop rbp
pop rbx
pop rdi
pop rsi
DB 0F3h,0C3h ;repret
section .pdata rdata align=4
ALIGN 4
DD $L$SEH_begin_bn_mul_mont wrt ..imagebase
DD $L$SEH_end_bn_mul_mont wrt ..imagebase
DD $L$SEH_info_bn_mul_mont wrt ..imagebase
DD $L$SEH_begin_bn_mul4x_mont wrt ..imagebase
DD $L$SEH_end_bn_mul4x_mont wrt ..imagebase
DD $L$SEH_info_bn_mul4x_mont wrt ..imagebase
DD $L$SEH_begin_bn_sqr8x_mont wrt ..imagebase
DD $L$SEH_end_bn_sqr8x_mont wrt ..imagebase
DD $L$SEH_info_bn_sqr8x_mont wrt ..imagebase
section .xdata rdata align=8
ALIGN 8
$L$SEH_info_bn_mul_mont:
DB 9,0,0,0
DD mul_handler wrt ..imagebase
DD $L$mul_body wrt ..imagebase,$L$mul_epilogue wrt ..imagebase
$L$SEH_info_bn_mul4x_mont:
DB 9,0,0,0
DD mul_handler wrt ..imagebase
DD $L$mul4x_body wrt ..imagebase,$L$mul4x_epilogue wrt ..imagebase
$L$SEH_info_bn_sqr8x_mont:
DB 9,0,0,0
DD sqr_handler wrt ..imagebase
DD $L$sqr8x_body wrt ..imagebase,$L$sqr8x_epilogue wrt ..imagebase
|
// This file is auto-generated. Do not edit!
#include "precomp.hpp"
#include "cvconfig.h"
#include "opencl_kernels_objdetect.hpp"
#ifdef HAVE_OPENCL
namespace cv
{
namespace ocl
{
namespace objdetect
{
static const char* const moduleName = "objdetect";
struct cv::ocl::internal::ProgramEntry cascadedetect_oclsrc={moduleName, "cascadedetect",
"#ifdef HAAR\n"
"typedef struct __attribute__((aligned(4))) OptHaarFeature\n"
"{\n"
"int4 ofs[3] __attribute__((aligned (4)));\n"
"float4 weight __attribute__((aligned (4)));\n"
"}\n"
"OptHaarFeature;\n"
"#endif\n"
"#ifdef LBP\n"
"typedef struct __attribute__((aligned(4))) OptLBPFeature\n"
"{\n"
"int16 ofs __attribute__((aligned (4)));\n"
"}\n"
"OptLBPFeature;\n"
"#endif\n"
"typedef struct __attribute__((aligned(4))) Stump\n"
"{\n"
"float4 st __attribute__((aligned (4)));\n"
"}\n"
"Stump;\n"
"typedef struct __attribute__((aligned(4))) Node\n"
"{\n"
"int4 n __attribute__((aligned (4)));\n"
"}\n"
"Node;\n"
"typedef struct __attribute__((aligned (4))) Stage\n"
"{\n"
"int first __attribute__((aligned (4)));\n"
"int ntrees __attribute__((aligned (4)));\n"
"float threshold __attribute__((aligned (4)));\n"
"}\n"
"Stage;\n"
"typedef struct __attribute__((aligned (4))) ScaleData\n"
"{\n"
"float scale __attribute__((aligned (4)));\n"
"int szi_width __attribute__((aligned (4)));\n"
"int szi_height __attribute__((aligned (4)));\n"
"int layer_ofs __attribute__((aligned (4)));\n"
"int ystep __attribute__((aligned (4)));\n"
"}\n"
"ScaleData;\n"
"#ifndef SUM_BUF_SIZE\n"
"#define SUM_BUF_SIZE 0\n"
"#endif\n"
"#ifndef NODE_COUNT\n"
"#define NODE_COUNT 1\n"
"#endif\n"
"#ifdef HAAR\n"
"__kernel __attribute__((reqd_work_group_size(LOCAL_SIZE_X,LOCAL_SIZE_Y,1)))\n"
"void runHaarClassifier(\n"
"int nscales, __global const ScaleData* scaleData,\n"
"__global const int* sum,\n"
"int _sumstep, int sumoffset,\n"
"__global const OptHaarFeature* optfeatures,\n"
"__global const Stage* stages,\n"
"__global const Node* nodes,\n"
"__global const float* leaves0,\n"
"volatile __global int* facepos,\n"
"int4 normrect, int sqofs, int2 windowsize)\n"
"{\n"
"int lx = get_local_id(0);\n"
"int ly = get_local_id(1);\n"
"int groupIdx = get_group_id(0);\n"
"int i, ngroups = get_global_size(0)/LOCAL_SIZE_X;\n"
"int scaleIdx, tileIdx, stageIdx;\n"
"int sumstep = (int)(_sumstep/sizeof(int));\n"
"int4 nofs0 = (int4)(mad24(normrect.y, sumstep, normrect.x),\n"
"mad24(normrect.y, sumstep, normrect.x + normrect.z),\n"
"mad24(normrect.y + normrect.w, sumstep, normrect.x),\n"
"mad24(normrect.y + normrect.w, sumstep, normrect.x + normrect.z));\n"
"int normarea = normrect.z * normrect.w;\n"
"float invarea = 1.f/normarea;\n"
"int lidx = ly*LOCAL_SIZE_X + lx;\n"
"#if SUM_BUF_SIZE > 0\n"
"int4 nofs = (int4)(mad24(normrect.y, SUM_BUF_STEP, normrect.x),\n"
"mad24(normrect.y, SUM_BUF_STEP, normrect.x + normrect.z),\n"
"mad24(normrect.y + normrect.w, SUM_BUF_STEP, normrect.x),\n"
"mad24(normrect.y + normrect.w, SUM_BUF_STEP, normrect.x + normrect.z));\n"
"#else\n"
"int4 nofs = nofs0;\n"
"#endif\n"
"#define LOCAL_SIZE (LOCAL_SIZE_X*LOCAL_SIZE_Y)\n"
"__local int lstore[SUM_BUF_SIZE + LOCAL_SIZE*5/2+1];\n"
"#if SUM_BUF_SIZE > 0\n"
"__local int* ibuf = lstore;\n"
"__local int* lcount = ibuf + SUM_BUF_SIZE;\n"
"#else\n"
"__local int* lcount = lstore;\n"
"#endif\n"
"__local float* lnf = (__local float*)(lcount + 1);\n"
"__local float* lpartsum = lnf + LOCAL_SIZE;\n"
"__local short* lbuf = (__local short*)(lpartsum + LOCAL_SIZE);\n"
"for( scaleIdx = nscales-1; scaleIdx >= 0; scaleIdx-- )\n"
"{\n"
"__global const ScaleData* s = scaleData + scaleIdx;\n"
"int ystep = s->ystep;\n"
"int2 worksize = (int2)(max(s->szi_width - windowsize.x, 0), max(s->szi_height - windowsize.y, 0));\n"
"int2 ntiles = (int2)((worksize.x + LOCAL_SIZE_X-1)/LOCAL_SIZE_X,\n"
"(worksize.y + LOCAL_SIZE_Y-1)/LOCAL_SIZE_Y);\n"
"int totalTiles = ntiles.x*ntiles.y;\n"
"for( tileIdx = groupIdx; tileIdx < totalTiles; tileIdx += ngroups )\n"
"{\n"
"int ix0 = (tileIdx % ntiles.x)*LOCAL_SIZE_X;\n"
"int iy0 = (tileIdx / ntiles.x)*LOCAL_SIZE_Y;\n"
"int ix = lx, iy = ly;\n"
"__global const int* psum0 = sum + mad24(iy0, sumstep, ix0) + s->layer_ofs;\n"
"__global const int* psum1 = psum0 + mad24(iy, sumstep, ix);\n"
"if( ix0 >= worksize.x || iy0 >= worksize.y )\n"
"continue;\n"
"#if SUM_BUF_SIZE > 0\n"
"for( i = lidx*4; i < SUM_BUF_SIZE; i += LOCAL_SIZE_X*LOCAL_SIZE_Y*4 )\n"
"{\n"
"int dy = i/SUM_BUF_STEP, dx = i - dy*SUM_BUF_STEP;\n"
"vstore4(vload4(0, psum0 + mad24(dy, sumstep, dx)), 0, ibuf+i);\n"
"}\n"
"#endif\n"
"if( lidx == 0 )\n"
"lcount[0] = 0;\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if( ix0 + ix < worksize.x && iy0 + iy < worksize.y )\n"
"{\n"
"#if NODE_COUNT==1\n"
"__global const Stump* stump = (__global const Stump*)nodes;\n"
"#else\n"
"__global const Node* node = nodes;\n"
"__global const float* leaves = leaves0;\n"
"#endif\n"
"#if SUM_BUF_SIZE > 0\n"
"__local const int* psum = ibuf + mad24(iy, SUM_BUF_STEP, ix);\n"
"#else\n"
"__global const int* psum = psum1;\n"
"#endif\n"
"__global const int* psqsum = (__global const int*)(psum1 + sqofs);\n"
"float sval = (psum[nofs.x] - psum[nofs.y] - psum[nofs.z] + psum[nofs.w])*invarea;\n"
"float sqval = (psqsum[nofs0.x] - psqsum[nofs0.y] - psqsum[nofs0.z] + psqsum[nofs0.w])*invarea;\n"
"float nf = (float)normarea * sqrt(max(sqval - sval * sval, 0.f));\n"
"nf = nf > 0 ? nf : 1.f;\n"
"for( stageIdx = 0; stageIdx < SPLIT_STAGE; stageIdx++ )\n"
"{\n"
"int ntrees = stages[stageIdx].ntrees;\n"
"float s = 0.f;\n"
"#if NODE_COUNT==1\n"
"for( i = 0; i < ntrees; i++ )\n"
"{\n"
"float4 st = stump[i].st;\n"
"__global const OptHaarFeature* f = optfeatures + as_int(st.x);\n"
"float4 weight = f->weight;\n"
"int4 ofs = f->ofs[0];\n"
"sval = (psum[ofs.x] - psum[ofs.y] - psum[ofs.z] + psum[ofs.w])*weight.x;\n"
"ofs = f->ofs[1];\n"
"sval = mad((float)(psum[ofs.x] - psum[ofs.y] - psum[ofs.z] + psum[ofs.w]), weight.y, sval);\n"
"if( weight.z > 0 )\n"
"{\n"
"ofs = f->ofs[2];\n"
"sval = mad((float)(psum[ofs.x] - psum[ofs.y] - psum[ofs.z] + psum[ofs.w]), weight.z, sval);\n"
"}\n"
"s += (sval < st.y*nf) ? st.z : st.w;\n"
"}\n"
"stump += ntrees;\n"
"#else\n"
"for( i = 0; i < ntrees; i++, node += NODE_COUNT, leaves += NODE_COUNT+1 )\n"
"{\n"
"int idx = 0;\n"
"do\n"
"{\n"
"int4 n = node[idx].n;\n"
"__global const OptHaarFeature* f = optfeatures + n.x;\n"
"float4 weight = f->weight;\n"
"int4 ofs = f->ofs[0];\n"
"sval = (psum[ofs.x] - psum[ofs.y] - psum[ofs.z] + psum[ofs.w])*weight.x;\n"
"ofs = f->ofs[1];\n"
"sval = mad((float)(psum[ofs.x] - psum[ofs.y] - psum[ofs.z] + psum[ofs.w]), weight.y, sval);\n"
"if( weight.z > 0 )\n"
"{\n"
"ofs = f->ofs[2];\n"
"sval = mad((float)(psum[ofs.x] - psum[ofs.y] - psum[ofs.z] + psum[ofs.w]), weight.z, sval);\n"
"}\n"
"idx = (sval < as_float(n.y)*nf) ? n.z : n.w;\n"
"}\n"
"while(idx > 0);\n"
"s += leaves[-idx];\n"
"}\n"
"#endif\n"
"if( s < stages[stageIdx].threshold )\n"
"break;\n"
"}\n"
"if( stageIdx == SPLIT_STAGE && (ystep == 1 || ((ix | iy) & 1) == 0) )\n"
"{\n"
"int count = atomic_inc(lcount);\n"
"lbuf[count] = (int)(ix | (iy << 8));\n"
"lnf[count] = nf;\n"
"}\n"
"}\n"
"for( stageIdx = SPLIT_STAGE; stageIdx < N_STAGES; stageIdx++ )\n"
"{\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"int nrects = lcount[0];\n"
"if( nrects == 0 )\n"
"break;\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if( lidx == 0 )\n"
"lcount[0] = 0;\n"
"{\n"
"#if NODE_COUNT == 1\n"
"__global const Stump* stump = (__global const Stump*)nodes + stages[stageIdx].first;\n"
"#else\n"
"__global const Node* node = nodes + stages[stageIdx].first*NODE_COUNT;\n"
"__global const float* leaves = leaves0 + stages[stageIdx].first*(NODE_COUNT+1);\n"
"#endif\n"
"int nparts = LOCAL_SIZE / nrects;\n"
"int ntrees = stages[stageIdx].ntrees;\n"
"int ntrees_p = (ntrees + nparts - 1)/nparts;\n"
"int nr = lidx / nparts;\n"
"int partidx = -1, idxval = 0;\n"
"float partsum = 0.f, nf = 0.f;\n"
"if( nr < nrects )\n"
"{\n"
"partidx = lidx % nparts;\n"
"idxval = lbuf[nr];\n"
"nf = lnf[nr];\n"
"{\n"
"int ntrees0 = ntrees_p*partidx;\n"
"int ntrees1 = min(ntrees0 + ntrees_p, ntrees);\n"
"int ix1 = idxval & 255, iy1 = idxval >> 8;\n"
"#if SUM_BUF_SIZE > 0\n"
"__local const int* psum = ibuf + mad24(iy1, SUM_BUF_STEP, ix1);\n"
"#else\n"
"__global const int* psum = psum0 + mad24(iy1, sumstep, ix1);\n"
"#endif\n"
"#if NODE_COUNT == 1\n"
"for( i = ntrees0; i < ntrees1; i++ )\n"
"{\n"
"float4 st = stump[i].st;\n"
"__global const OptHaarFeature* f = optfeatures + as_int(st.x);\n"
"float4 weight = f->weight;\n"
"int4 ofs = f->ofs[0];\n"
"float sval = (psum[ofs.x] - psum[ofs.y] - psum[ofs.z] + psum[ofs.w])*weight.x;\n"
"ofs = f->ofs[1];\n"
"sval = mad((float)(psum[ofs.x] - psum[ofs.y] - psum[ofs.z] + psum[ofs.w]), weight.y, sval);\n"
"if( fabs(weight.z) > 0 )\n"
"{\n"
"ofs = f->ofs[2];\n"
"sval = mad((float)(psum[ofs.x] - psum[ofs.y] - psum[ofs.z] + psum[ofs.w]), weight.z, sval);\n"
"}\n"
"partsum += (sval < st.y*nf) ? st.z : st.w;\n"
"}\n"
"#else\n"
"for( i = ntrees0; i < ntrees1; i++ )\n"
"{\n"
"int idx = 0;\n"
"do\n"
"{\n"
"int4 n = node[i*2 + idx].n;\n"
"__global const OptHaarFeature* f = optfeatures + n.x;\n"
"float4 weight = f->weight;\n"
"int4 ofs = f->ofs[0];\n"
"float sval = (psum[ofs.x] - psum[ofs.y] - psum[ofs.z] + psum[ofs.w])*weight.x;\n"
"ofs = f->ofs[1];\n"
"sval = mad((float)(psum[ofs.x] - psum[ofs.y] - psum[ofs.z] + psum[ofs.w]), weight.y, sval);\n"
"if( weight.z > 0 )\n"
"{\n"
"ofs = f->ofs[2];\n"
"sval = mad((float)(psum[ofs.x] - psum[ofs.y] - psum[ofs.z] + psum[ofs.w]), weight.z, sval);\n"
"}\n"
"idx = (sval < as_float(n.y)*nf) ? n.z : n.w;\n"
"}\n"
"while(idx > 0);\n"
"partsum += leaves[i*3-idx];\n"
"}\n"
"#endif\n"
"}\n"
"}\n"
"lpartsum[lidx] = partsum;\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if( partidx == 0 )\n"
"{\n"
"float s = lpartsum[nr*nparts];\n"
"for( i = 1; i < nparts; i++ )\n"
"s += lpartsum[i + nr*nparts];\n"
"if( s >= stages[stageIdx].threshold )\n"
"{\n"
"int count = atomic_inc(lcount);\n"
"lbuf[count] = idxval;\n"
"lnf[count] = nf;\n"
"}\n"
"}\n"
"}\n"
"}\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if( stageIdx == N_STAGES )\n"
"{\n"
"int nrects = lcount[0];\n"
"if( lidx < nrects )\n"
"{\n"
"int nfaces = atomic_inc(facepos);\n"
"if( nfaces < MAX_FACES )\n"
"{\n"
"volatile __global int* face = facepos + 1 + nfaces*3;\n"
"int val = lbuf[lidx];\n"
"face[0] = scaleIdx;\n"
"face[1] = ix0 + (val & 255);\n"
"face[2] = iy0 + (val >> 8);\n"
"}\n"
"}\n"
"}\n"
"}\n"
"}\n"
"}\n"
"#endif\n"
"#ifdef LBP\n"
"#undef CALC_SUM_OFS_\n"
"#define CALC_SUM_OFS_(p0, p1, p2, p3, ptr) \\\n"
"((ptr)[p0] - (ptr)[p1] - (ptr)[p2] + (ptr)[p3])\n"
"__kernel void runLBPClassifierStumpSimple(\n"
"int nscales, __global const ScaleData* scaleData,\n"
"__global const int* sum,\n"
"int _sumstep, int sumoffset,\n"
"__global const OptLBPFeature* optfeatures,\n"
"__global const Stage* stages,\n"
"__global const Stump* stumps,\n"
"__global const int* bitsets,\n"
"int bitsetSize,\n"
"volatile __global int* facepos,\n"
"int2 windowsize)\n"
"{\n"
"int lx = get_local_id(0);\n"
"int ly = get_local_id(1);\n"
"int local_size_x = get_local_size(0);\n"
"int local_size_y = get_local_size(1);\n"
"int groupIdx = get_group_id(1)*get_num_groups(0) + get_group_id(0);\n"
"int ngroups = get_num_groups(0)*get_num_groups(1);\n"
"int scaleIdx, tileIdx, stageIdx;\n"
"int sumstep = (int)(_sumstep/sizeof(int));\n"
"for( scaleIdx = nscales-1; scaleIdx >= 0; scaleIdx-- )\n"
"{\n"
"__global const ScaleData* s = scaleData + scaleIdx;\n"
"int ystep = s->ystep;\n"
"int2 worksize = (int2)(max(s->szi_width - windowsize.x, 0), max(s->szi_height - windowsize.y, 0));\n"
"int2 ntiles = (int2)((worksize.x/ystep + local_size_x-1)/local_size_x,\n"
"(worksize.y/ystep + local_size_y-1)/local_size_y);\n"
"int totalTiles = ntiles.x*ntiles.y;\n"
"for( tileIdx = groupIdx; tileIdx < totalTiles; tileIdx += ngroups )\n"
"{\n"
"int iy = mad24((tileIdx / ntiles.x), local_size_y, ly) * ystep;\n"
"int ix = mad24((tileIdx % ntiles.x), local_size_x, lx) * ystep;\n"
"if( ix < worksize.x && iy < worksize.y )\n"
"{\n"
"__global const int* p = sum + mad24(iy, sumstep, ix) + s->layer_ofs;\n"
"__global const Stump* stump = stumps;\n"
"__global const int* bitset = bitsets;\n"
"for( stageIdx = 0; stageIdx < N_STAGES; stageIdx++ )\n"
"{\n"
"int i, ntrees = stages[stageIdx].ntrees;\n"
"float s = 0.f;\n"
"for( i = 0; i < ntrees; i++, stump++, bitset += bitsetSize )\n"
"{\n"
"float4 st = stump->st;\n"
"__global const OptLBPFeature* f = optfeatures + as_int(st.x);\n"
"int16 ofs = f->ofs;\n"
"int cval = CALC_SUM_OFS_( ofs.s5, ofs.s6, ofs.s9, ofs.sa, p );\n"
"int mask, idx = (CALC_SUM_OFS_( ofs.s0, ofs.s1, ofs.s4, ofs.s5, p ) >= cval ? 4 : 0);\n"
"idx |= (CALC_SUM_OFS_( ofs.s1, ofs.s2, ofs.s5, ofs.s6, p ) >= cval ? 2 : 0);\n"
"idx |= (CALC_SUM_OFS_( ofs.s2, ofs.s3, ofs.s6, ofs.s7, p ) >= cval ? 1 : 0);\n"
"mask = (CALC_SUM_OFS_( ofs.s6, ofs.s7, ofs.sa, ofs.sb, p ) >= cval ? 16 : 0);\n"
"mask |= (CALC_SUM_OFS_( ofs.sa, ofs.sb, ofs.se, ofs.sf, p ) >= cval ? 8 : 0);\n"
"mask |= (CALC_SUM_OFS_( ofs.s9, ofs.sa, ofs.sd, ofs.se, p ) >= cval ? 4 : 0);\n"
"mask |= (CALC_SUM_OFS_( ofs.s8, ofs.s9, ofs.sc, ofs.sd, p ) >= cval ? 2 : 0);\n"
"mask |= (CALC_SUM_OFS_( ofs.s4, ofs.s5, ofs.s8, ofs.s9, p ) >= cval ? 1 : 0);\n"
"s += (bitset[idx] & (1 << mask)) ? st.z : st.w;\n"
"}\n"
"if( s < stages[stageIdx].threshold )\n"
"break;\n"
"}\n"
"if( stageIdx == N_STAGES )\n"
"{\n"
"int nfaces = atomic_inc(facepos);\n"
"if( nfaces < MAX_FACES )\n"
"{\n"
"volatile __global int* face = facepos + 1 + nfaces*3;\n"
"face[0] = scaleIdx;\n"
"face[1] = ix;\n"
"face[2] = iy;\n"
"}\n"
"}\n"
"}\n"
"}\n"
"}\n"
"}\n"
"__kernel __attribute__((reqd_work_group_size(LOCAL_SIZE_X,LOCAL_SIZE_Y,1)))\n"
"void runLBPClassifierStump(\n"
"int nscales, __global const ScaleData* scaleData,\n"
"__global const int* sum,\n"
"int _sumstep, int sumoffset,\n"
"__global const OptLBPFeature* optfeatures,\n"
"__global const Stage* stages,\n"
"__global const Stump* stumps,\n"
"__global const int* bitsets,\n"
"int bitsetSize,\n"
"volatile __global int* facepos,\n"
"int2 windowsize)\n"
"{\n"
"int lx = get_local_id(0);\n"
"int ly = get_local_id(1);\n"
"int groupIdx = get_group_id(0);\n"
"int i, ngroups = get_global_size(0)/LOCAL_SIZE_X;\n"
"int scaleIdx, tileIdx, stageIdx;\n"
"int sumstep = (int)(_sumstep/sizeof(int));\n"
"int lidx = ly*LOCAL_SIZE_X + lx;\n"
"#define LOCAL_SIZE (LOCAL_SIZE_X*LOCAL_SIZE_Y)\n"
"__local int lstore[SUM_BUF_SIZE + LOCAL_SIZE*3/2+1];\n"
"#if SUM_BUF_SIZE > 0\n"
"__local int* ibuf = lstore;\n"
"__local int* lcount = ibuf + SUM_BUF_SIZE;\n"
"#else\n"
"__local int* lcount = lstore;\n"
"#endif\n"
"__local float* lpartsum = (__local float*)(lcount + 1);\n"
"__local short* lbuf = (__local short*)(lpartsum + LOCAL_SIZE);\n"
"for( scaleIdx = nscales-1; scaleIdx >= 0; scaleIdx-- )\n"
"{\n"
"__global const ScaleData* s = scaleData + scaleIdx;\n"
"int ystep = s->ystep;\n"
"int2 worksize = (int2)(max(s->szi_width - windowsize.x, 0), max(s->szi_height - windowsize.y, 0));\n"
"int2 ntiles = (int2)((worksize.x + LOCAL_SIZE_X-1)/LOCAL_SIZE_X,\n"
"(worksize.y + LOCAL_SIZE_Y-1)/LOCAL_SIZE_Y);\n"
"int totalTiles = ntiles.x*ntiles.y;\n"
"for( tileIdx = groupIdx; tileIdx < totalTiles; tileIdx += ngroups )\n"
"{\n"
"int ix0 = (tileIdx % ntiles.x)*LOCAL_SIZE_X;\n"
"int iy0 = (tileIdx / ntiles.x)*LOCAL_SIZE_Y;\n"
"int ix = lx, iy = ly;\n"
"__global const int* psum0 = sum + mad24(iy0, sumstep, ix0) + s->layer_ofs;\n"
"if( ix0 >= worksize.x || iy0 >= worksize.y )\n"
"continue;\n"
"#if SUM_BUF_SIZE > 0\n"
"for( i = lidx*4; i < SUM_BUF_SIZE; i += LOCAL_SIZE_X*LOCAL_SIZE_Y*4 )\n"
"{\n"
"int dy = i/SUM_BUF_STEP, dx = i - dy*SUM_BUF_STEP;\n"
"vstore4(vload4(0, psum0 + mad24(dy, sumstep, dx)), 0, ibuf+i);\n"
"}\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"#endif\n"
"if( lidx == 0 )\n"
"lcount[0] = 0;\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if( ix0 + ix < worksize.x && iy0 + iy < worksize.y )\n"
"{\n"
"__global const Stump* stump = stumps;\n"
"__global const int* bitset = bitsets;\n"
"#if SUM_BUF_SIZE > 0\n"
"__local const int* p = ibuf + mad24(iy, SUM_BUF_STEP, ix);\n"
"#else\n"
"__global const int* p = psum0 + mad24(iy, sumstep, ix);\n"
"#endif\n"
"for( stageIdx = 0; stageIdx < SPLIT_STAGE; stageIdx++ )\n"
"{\n"
"int ntrees = stages[stageIdx].ntrees;\n"
"float s = 0.f;\n"
"for( i = 0; i < ntrees; i++, stump++, bitset += bitsetSize )\n"
"{\n"
"float4 st = stump->st;\n"
"__global const OptLBPFeature* f = optfeatures + as_int(st.x);\n"
"int16 ofs = f->ofs;\n"
"int cval = CALC_SUM_OFS_( ofs.s5, ofs.s6, ofs.s9, ofs.sa, p );\n"
"int mask, idx = (CALC_SUM_OFS_( ofs.s0, ofs.s1, ofs.s4, ofs.s5, p ) >= cval ? 4 : 0);\n"
"idx |= (CALC_SUM_OFS_( ofs.s1, ofs.s2, ofs.s5, ofs.s6, p ) >= cval ? 2 : 0);\n"
"idx |= (CALC_SUM_OFS_( ofs.s2, ofs.s3, ofs.s6, ofs.s7, p ) >= cval ? 1 : 0);\n"
"mask = (CALC_SUM_OFS_( ofs.s6, ofs.s7, ofs.sa, ofs.sb, p ) >= cval ? 16 : 0);\n"
"mask |= (CALC_SUM_OFS_( ofs.sa, ofs.sb, ofs.se, ofs.sf, p ) >= cval ? 8 : 0);\n"
"mask |= (CALC_SUM_OFS_( ofs.s9, ofs.sa, ofs.sd, ofs.se, p ) >= cval ? 4 : 0);\n"
"mask |= (CALC_SUM_OFS_( ofs.s8, ofs.s9, ofs.sc, ofs.sd, p ) >= cval ? 2 : 0);\n"
"mask |= (CALC_SUM_OFS_( ofs.s4, ofs.s5, ofs.s8, ofs.s9, p ) >= cval ? 1 : 0);\n"
"s += (bitset[idx] & (1 << mask)) ? st.z : st.w;\n"
"}\n"
"if( s < stages[stageIdx].threshold )\n"
"break;\n"
"}\n"
"if( stageIdx == SPLIT_STAGE && (ystep == 1 || ((ix | iy) & 1) == 0) )\n"
"{\n"
"int count = atomic_inc(lcount);\n"
"lbuf[count] = (int)(ix | (iy << 8));\n"
"}\n"
"}\n"
"for( stageIdx = SPLIT_STAGE; stageIdx < N_STAGES; stageIdx++ )\n"
"{\n"
"int nrects = lcount[0];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if( nrects == 0 )\n"
"break;\n"
"if( lidx == 0 )\n"
"lcount[0] = 0;\n"
"{\n"
"__global const Stump* stump = stumps + stages[stageIdx].first;\n"
"__global const int* bitset = bitsets + stages[stageIdx].first*bitsetSize;\n"
"int nparts = LOCAL_SIZE / nrects;\n"
"int ntrees = stages[stageIdx].ntrees;\n"
"int ntrees_p = (ntrees + nparts - 1)/nparts;\n"
"int nr = lidx / nparts;\n"
"int partidx = -1, idxval = 0;\n"
"float partsum = 0.f, nf = 0.f;\n"
"if( nr < nrects )\n"
"{\n"
"partidx = lidx % nparts;\n"
"idxval = lbuf[nr];\n"
"{\n"
"int ntrees0 = ntrees_p*partidx;\n"
"int ntrees1 = min(ntrees0 + ntrees_p, ntrees);\n"
"int ix1 = idxval & 255, iy1 = idxval >> 8;\n"
"#if SUM_BUF_SIZE > 0\n"
"__local const int* p = ibuf + mad24(iy1, SUM_BUF_STEP, ix1);\n"
"#else\n"
"__global const int* p = psum0 + mad24(iy1, sumstep, ix1);\n"
"#endif\n"
"for( i = ntrees0; i < ntrees1; i++ )\n"
"{\n"
"float4 st = stump[i].st;\n"
"__global const OptLBPFeature* f = optfeatures + as_int(st.x);\n"
"int16 ofs = f->ofs;\n"
"#define CALC_SUM_OFS_(p0, p1, p2, p3, ptr) \\\n"
"((ptr)[p0] - (ptr)[p1] - (ptr)[p2] + (ptr)[p3])\n"
"int cval = CALC_SUM_OFS_( ofs.s5, ofs.s6, ofs.s9, ofs.sa, p );\n"
"int mask, idx = (CALC_SUM_OFS_( ofs.s0, ofs.s1, ofs.s4, ofs.s5, p ) >= cval ? 4 : 0);\n"
"idx |= (CALC_SUM_OFS_( ofs.s1, ofs.s2, ofs.s5, ofs.s6, p ) >= cval ? 2 : 0);\n"
"idx |= (CALC_SUM_OFS_( ofs.s2, ofs.s3, ofs.s6, ofs.s7, p ) >= cval ? 1 : 0);\n"
"mask = (CALC_SUM_OFS_( ofs.s6, ofs.s7, ofs.sa, ofs.sb, p ) >= cval ? 16 : 0);\n"
"mask |= (CALC_SUM_OFS_( ofs.sa, ofs.sb, ofs.se, ofs.sf, p ) >= cval ? 8 : 0);\n"
"mask |= (CALC_SUM_OFS_( ofs.s9, ofs.sa, ofs.sd, ofs.se, p ) >= cval ? 4 : 0);\n"
"mask |= (CALC_SUM_OFS_( ofs.s8, ofs.s9, ofs.sc, ofs.sd, p ) >= cval ? 2 : 0);\n"
"mask |= (CALC_SUM_OFS_( ofs.s4, ofs.s5, ofs.s8, ofs.s9, p ) >= cval ? 1 : 0);\n"
"partsum += (bitset[i*bitsetSize + idx] & (1 << mask)) ? st.z : st.w;\n"
"}\n"
"}\n"
"}\n"
"lpartsum[lidx] = partsum;\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if( partidx == 0 )\n"
"{\n"
"float s = lpartsum[nr*nparts];\n"
"for( i = 1; i < nparts; i++ )\n"
"s += lpartsum[i + nr*nparts];\n"
"if( s >= stages[stageIdx].threshold )\n"
"{\n"
"int count = atomic_inc(lcount);\n"
"lbuf[count] = idxval;\n"
"}\n"
"}\n"
"}\n"
"}\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if( stageIdx == N_STAGES )\n"
"{\n"
"int nrects = lcount[0];\n"
"if( lidx < nrects )\n"
"{\n"
"int nfaces = atomic_inc(facepos);\n"
"if( nfaces < MAX_FACES )\n"
"{\n"
"volatile __global int* face = facepos + 1 + nfaces*3;\n"
"int val = lbuf[lidx];\n"
"face[0] = scaleIdx;\n"
"face[1] = ix0 + (val & 255);\n"
"face[2] = iy0 + (val >> 8);\n"
"}\n"
"}\n"
"}\n"
"}\n"
"}\n"
"}\n"
"#endif\n"
, "91af1bca5e8f46e8426e0f3a1eb8d1f2", NULL};
struct cv::ocl::internal::ProgramEntry objdetect_hog_oclsrc={moduleName, "objdetect_hog",
"#define CELL_WIDTH 8\n"
"#define CELL_HEIGHT 8\n"
"#define CELLS_PER_BLOCK_X 2\n"
"#define CELLS_PER_BLOCK_Y 2\n"
"#define NTHREADS 256\n"
"#define CV_PI_F M_PI_F\n"
"#ifdef INTEL_DEVICE\n"
"#define QANGLE_TYPE int\n"
"#define QANGLE_TYPE2 int2\n"
"#else\n"
"#define QANGLE_TYPE uchar\n"
"#define QANGLE_TYPE2 uchar2\n"
"#endif\n"
"__kernel void compute_hists_lut_kernel(\n"
"const int cblock_stride_x, const int cblock_stride_y,\n"
"const int cnbins, const int cblock_hist_size, const int img_block_width,\n"
"const int blocks_in_group, const int blocks_total,\n"
"const int grad_quadstep, const int qangle_step,\n"
"__global const float* grad, __global const QANGLE_TYPE* qangle,\n"
"__global const float* gauss_w_lut,\n"
"__global float* block_hists, __local float* smem)\n"
"{\n"
"const int lx = get_local_id(0);\n"
"const int lp = lx / 24; \n"
"const int gid = get_group_id(0) * blocks_in_group + lp;\n"
"const int gidY = gid / img_block_width;\n"
"const int gidX = gid - gidY * img_block_width;\n"
"const int lidX = lx - lp * 24;\n"
"const int lidY = get_local_id(1);\n"
"const int cell_x = lidX / 12;\n"
"const int cell_y = lidY;\n"
"const int cell_thread_x = lidX - cell_x * 12;\n"
"__local float* hists = smem + lp * cnbins * (CELLS_PER_BLOCK_X *\n"
"CELLS_PER_BLOCK_Y * 12 + CELLS_PER_BLOCK_X * CELLS_PER_BLOCK_Y);\n"
"__local float* final_hist = hists + cnbins *\n"
"(CELLS_PER_BLOCK_X * CELLS_PER_BLOCK_Y * 12);\n"
"const int offset_x = gidX * cblock_stride_x + (cell_x << 2) + cell_thread_x;\n"
"const int offset_y = gidY * cblock_stride_y + (cell_y << 2);\n"
"__global const float* grad_ptr = (gid < blocks_total) ?\n"
"grad + offset_y * grad_quadstep + (offset_x << 1) : grad;\n"
"__global const QANGLE_TYPE* qangle_ptr = (gid < blocks_total) ?\n"
"qangle + offset_y * qangle_step + (offset_x << 1) : qangle;\n"
"__local float* hist = hists + 12 * (cell_y * CELLS_PER_BLOCK_Y + cell_x) +\n"
"cell_thread_x;\n"
"for (int bin_id = 0; bin_id < cnbins; ++bin_id)\n"
"hist[bin_id * 48] = 0.f;\n"
"const int dist_x = -4 + cell_thread_x - 4 * cell_x;\n"
"const int dist_center_x = dist_x - 4 * (1 - 2 * cell_x);\n"
"const int dist_y_begin = -4 - 4 * lidY;\n"
"for (int dist_y = dist_y_begin; dist_y < dist_y_begin + 12; ++dist_y)\n"
"{\n"
"float2 vote = (float2) (grad_ptr[0], grad_ptr[1]);\n"
"QANGLE_TYPE2 bin = (QANGLE_TYPE2) (qangle_ptr[0], qangle_ptr[1]);\n"
"grad_ptr += grad_quadstep;\n"
"qangle_ptr += qangle_step;\n"
"int dist_center_y = dist_y - 4 * (1 - 2 * cell_y);\n"
"int idx = (dist_center_y + 8) * 16 + (dist_center_x + 8);\n"
"float gaussian = gauss_w_lut[idx];\n"
"idx = (dist_y + 8) * 16 + (dist_x + 8);\n"
"float interp_weight = gauss_w_lut[256+idx];\n"
"hist[bin.x * 48] += gaussian * interp_weight * vote.x;\n"
"hist[bin.y * 48] += gaussian * interp_weight * vote.y;\n"
"}\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"volatile __local float* hist_ = hist;\n"
"for (int bin_id = 0; bin_id < cnbins; ++bin_id, hist_ += 48)\n"
"{\n"
"if (cell_thread_x < 6)\n"
"hist_[0] += hist_[6];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (cell_thread_x < 3)\n"
"hist_[0] += hist_[3];\n"
"#ifdef CPU\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"#endif\n"
"if (cell_thread_x == 0)\n"
"final_hist[(cell_x * 2 + cell_y) * cnbins + bin_id] =\n"
"hist_[0] + hist_[1] + hist_[2];\n"
"}\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"int tid = (cell_y * CELLS_PER_BLOCK_Y + cell_x) * 12 + cell_thread_x;\n"
"if ((tid < cblock_hist_size) && (gid < blocks_total))\n"
"{\n"
"__global float* block_hist = block_hists +\n"
"(gidY * img_block_width + gidX) * cblock_hist_size;\n"
"block_hist[tid] = final_hist[tid];\n"
"}\n"
"}\n"
"__kernel void normalize_hists_36_kernel(__global float* block_hists,\n"
"const float threshold, __local float *squares)\n"
"{\n"
"const int tid = get_local_id(0);\n"
"const int gid = get_global_id(0);\n"
"const int bid = tid / 36; \n"
"const int boffset = bid * 36; \n"
"const int hid = tid - boffset; \n"
"float elem = block_hists[gid];\n"
"squares[tid] = elem * elem;\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"__local float* smem = squares + boffset;\n"
"float sum = smem[hid];\n"
"if (hid < 18)\n"
"smem[hid] = sum = sum + smem[hid + 18];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (hid < 9)\n"
"smem[hid] = sum = sum + smem[hid + 9];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (hid < 4)\n"
"smem[hid] = sum + smem[hid + 4];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"sum = smem[0] + smem[1] + smem[2] + smem[3] + smem[8];\n"
"elem = elem / (sqrt(sum) + 3.6f);\n"
"elem = min(elem, threshold);\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"squares[tid] = elem * elem;\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"sum = smem[hid];\n"
"if (hid < 18)\n"
"smem[hid] = sum = sum + smem[hid + 18];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (hid < 9)\n"
"smem[hid] = sum = sum + smem[hid + 9];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (hid < 4)\n"
"smem[hid] = sum + smem[hid + 4];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"sum = smem[0] + smem[1] + smem[2] + smem[3] + smem[8];\n"
"block_hists[gid] = elem / (sqrt(sum) + 1e-3f);\n"
"}\n"
"inline float reduce_smem(volatile __local float* smem, int size)\n"
"{\n"
"unsigned int tid = get_local_id(0);\n"
"float sum = smem[tid];\n"
"if (size >= 512) { if (tid < 256) smem[tid] = sum = sum + smem[tid + 256];\n"
"barrier(CLK_LOCAL_MEM_FENCE); }\n"
"if (size >= 256) { if (tid < 128) smem[tid] = sum = sum + smem[tid + 128];\n"
"barrier(CLK_LOCAL_MEM_FENCE); }\n"
"if (size >= 128) { if (tid < 64) smem[tid] = sum = sum + smem[tid + 64];\n"
"barrier(CLK_LOCAL_MEM_FENCE); }\n"
"#ifdef CPU\n"
"if (size >= 64) { if (tid < 32) smem[tid] = sum = sum + smem[tid + 32];\n"
"barrier(CLK_LOCAL_MEM_FENCE); }\n"
"if (size >= 32) { if (tid < 16) smem[tid] = sum = sum + smem[tid + 16];\n"
"barrier(CLK_LOCAL_MEM_FENCE); }\n"
"if (size >= 16) { if (tid < 8) smem[tid] = sum = sum + smem[tid + 8];\n"
"barrier(CLK_LOCAL_MEM_FENCE); }\n"
"if (size >= 8) { if (tid < 4) smem[tid] = sum = sum + smem[tid + 4];\n"
"barrier(CLK_LOCAL_MEM_FENCE); }\n"
"if (size >= 4) { if (tid < 2) smem[tid] = sum = sum + smem[tid + 2];\n"
"barrier(CLK_LOCAL_MEM_FENCE); }\n"
"if (size >= 2) { if (tid < 1) smem[tid] = sum = sum + smem[tid + 1];\n"
"barrier(CLK_LOCAL_MEM_FENCE); }\n"
"#else\n"
"if (tid < 32)\n"
"{\n"
"if (size >= 64) smem[tid] = sum = sum + smem[tid + 32];\n"
"#if WAVE_SIZE < 32\n"
"} barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (tid < 16) {\n"
"#endif\n"
"if (size >= 32) smem[tid] = sum = sum + smem[tid + 16];\n"
"if (size >= 16) smem[tid] = sum = sum + smem[tid + 8];\n"
"if (size >= 8) smem[tid] = sum = sum + smem[tid + 4];\n"
"if (size >= 4) smem[tid] = sum = sum + smem[tid + 2];\n"
"if (size >= 2) smem[tid] = sum = sum + smem[tid + 1];\n"
"}\n"
"#endif\n"
"return sum;\n"
"}\n"
"__kernel void normalize_hists_kernel(\n"
"const int nthreads, const int block_hist_size, const int img_block_width,\n"
"__global float* block_hists, const float threshold, __local float *squares)\n"
"{\n"
"const int tid = get_local_id(0);\n"
"const int gidX = get_group_id(0);\n"
"const int gidY = get_group_id(1);\n"
"__global float* hist = block_hists + (gidY * img_block_width + gidX) *\n"
"block_hist_size + tid;\n"
"float elem = 0.f;\n"
"if (tid < block_hist_size)\n"
"elem = hist[0];\n"
"squares[tid] = elem * elem;\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"float sum = reduce_smem(squares, nthreads);\n"
"float scale = 1.0f / (sqrt(sum) + 0.1f * block_hist_size);\n"
"elem = min(elem * scale, threshold);\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"squares[tid] = elem * elem;\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"sum = reduce_smem(squares, nthreads);\n"
"scale = 1.0f / (sqrt(sum) + 1e-3f);\n"
"if (tid < block_hist_size)\n"
"hist[0] = elem * scale;\n"
"}\n"
"__kernel void classify_hists_180_kernel(\n"
"const int cdescr_width, const int cdescr_height, const int cblock_hist_size,\n"
"const int img_win_width, const int img_block_width,\n"
"const int win_block_stride_x, const int win_block_stride_y,\n"
"__global const float * block_hists, __global const float* coefs,\n"
"float free_coef, float threshold, __global uchar* labels)\n"
"{\n"
"const int tid = get_local_id(0);\n"
"const int gidX = get_group_id(0);\n"
"const int gidY = get_group_id(1);\n"
"__global const float* hist = block_hists + (gidY * win_block_stride_y *\n"
"img_block_width + gidX * win_block_stride_x) * cblock_hist_size;\n"
"float product = 0.f;\n"
"for (int i = 0; i < cdescr_height; i++)\n"
"{\n"
"product += coefs[i * cdescr_width + tid] *\n"
"hist[i * img_block_width * cblock_hist_size + tid];\n"
"}\n"
"__local float products[180];\n"
"products[tid] = product;\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (tid < 90) products[tid] = product = product + products[tid + 90];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (tid < 45) products[tid] = product = product + products[tid + 45];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"volatile __local float* smem = products;\n"
"#ifdef CPU\n"
"if (tid < 13) smem[tid] = product = product + smem[tid + 32];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (tid < 16) smem[tid] = product = product + smem[tid + 16];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(tid<8) smem[tid] = product = product + smem[tid + 8];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(tid<4) smem[tid] = product = product + smem[tid + 4];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(tid<2) smem[tid] = product = product + smem[tid + 2];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"#else\n"
"if (tid < 13)\n"
"{\n"
"smem[tid] = product = product + smem[tid + 32];\n"
"}\n"
"#if WAVE_SIZE < 32\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"#endif\n"
"if (tid < 16)\n"
"{\n"
"smem[tid] = product = product + smem[tid + 16];\n"
"smem[tid] = product = product + smem[tid + 8];\n"
"smem[tid] = product = product + smem[tid + 4];\n"
"smem[tid] = product = product + smem[tid + 2];\n"
"}\n"
"#endif\n"
"if (tid == 0){\n"
"product = product + smem[tid + 1];\n"
"labels[gidY * img_win_width + gidX] = (product + free_coef >= threshold);\n"
"}\n"
"}\n"
"__kernel void classify_hists_252_kernel(\n"
"const int cdescr_width, const int cdescr_height, const int cblock_hist_size,\n"
"const int img_win_width, const int img_block_width,\n"
"const int win_block_stride_x, const int win_block_stride_y,\n"
"__global const float * block_hists, __global const float* coefs,\n"
"float free_coef, float threshold, __global uchar* labels)\n"
"{\n"
"const int tid = get_local_id(0);\n"
"const int gidX = get_group_id(0);\n"
"const int gidY = get_group_id(1);\n"
"__global const float* hist = block_hists + (gidY * win_block_stride_y *\n"
"img_block_width + gidX * win_block_stride_x) * cblock_hist_size;\n"
"float product = 0.f;\n"
"if (tid < cdescr_width)\n"
"{\n"
"for (int i = 0; i < cdescr_height; i++)\n"
"product += coefs[i * cdescr_width + tid] *\n"
"hist[i * img_block_width * cblock_hist_size + tid];\n"
"}\n"
"__local float products[NTHREADS];\n"
"products[tid] = product;\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (tid < 128) products[tid] = product = product + products[tid + 128];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (tid < 64) products[tid] = product = product + products[tid + 64];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"volatile __local float* smem = products;\n"
"#ifdef CPU\n"
"if(tid<32) smem[tid] = product = product + smem[tid + 32];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(tid<16) smem[tid] = product = product + smem[tid + 16];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(tid<8) smem[tid] = product = product + smem[tid + 8];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(tid<4) smem[tid] = product = product + smem[tid + 4];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(tid<2) smem[tid] = product = product + smem[tid + 2];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"#else\n"
"if (tid < 32)\n"
"{\n"
"smem[tid] = product = product + smem[tid + 32];\n"
"#if WAVE_SIZE < 32\n"
"} barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (tid < 16) {\n"
"#endif\n"
"smem[tid] = product = product + smem[tid + 16];\n"
"smem[tid] = product = product + smem[tid + 8];\n"
"smem[tid] = product = product + smem[tid + 4];\n"
"smem[tid] = product = product + smem[tid + 2];\n"
"}\n"
"#endif\n"
"if (tid == 0){\n"
"product = product + smem[tid + 1];\n"
"labels[gidY * img_win_width + gidX] = (product + free_coef >= threshold);\n"
"}\n"
"}\n"
"__kernel void classify_hists_kernel(\n"
"const int cdescr_size, const int cdescr_width, const int cblock_hist_size,\n"
"const int img_win_width, const int img_block_width,\n"
"const int win_block_stride_x, const int win_block_stride_y,\n"
"__global const float * block_hists, __global const float* coefs,\n"
"float free_coef, float threshold, __global uchar* labels)\n"
"{\n"
"const int tid = get_local_id(0);\n"
"const int gidX = get_group_id(0);\n"
"const int gidY = get_group_id(1);\n"
"__global const float* hist = block_hists + (gidY * win_block_stride_y *\n"
"img_block_width + gidX * win_block_stride_x) * cblock_hist_size;\n"
"float product = 0.f;\n"
"for (int i = tid; i < cdescr_size; i += NTHREADS)\n"
"{\n"
"int offset_y = i / cdescr_width;\n"
"int offset_x = i - offset_y * cdescr_width;\n"
"product += coefs[i] *\n"
"hist[offset_y * img_block_width * cblock_hist_size + offset_x];\n"
"}\n"
"__local float products[NTHREADS];\n"
"products[tid] = product;\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (tid < 128) products[tid] = product = product + products[tid + 128];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (tid < 64) products[tid] = product = product + products[tid + 64];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"volatile __local float* smem = products;\n"
"#ifdef CPU\n"
"if(tid<32) smem[tid] = product = product + smem[tid + 32];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(tid<16) smem[tid] = product = product + smem[tid + 16];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(tid<8) smem[tid] = product = product + smem[tid + 8];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(tid<4) smem[tid] = product = product + smem[tid + 4];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if(tid<2) smem[tid] = product = product + smem[tid + 2];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"#else\n"
"if (tid < 32)\n"
"{\n"
"smem[tid] = product = product + smem[tid + 32];\n"
"#if WAVE_SIZE < 32\n"
"} barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (tid < 16) {\n"
"#endif\n"
"smem[tid] = product = product + smem[tid + 16];\n"
"smem[tid] = product = product + smem[tid + 8];\n"
"smem[tid] = product = product + smem[tid + 4];\n"
"smem[tid] = product = product + smem[tid + 2];\n"
"}\n"
"#endif\n"
"if (tid == 0){\n"
"smem[tid] = product = product + smem[tid + 1];\n"
"labels[gidY * img_win_width + gidX] = (product + free_coef >= threshold);\n"
"}\n"
"}\n"
"__kernel void extract_descrs_by_rows_kernel(\n"
"const int cblock_hist_size, const int descriptors_quadstep,\n"
"const int cdescr_size, const int cdescr_width, const int img_block_width,\n"
"const int win_block_stride_x, const int win_block_stride_y,\n"
"__global const float* block_hists, __global float* descriptors)\n"
"{\n"
"int tid = get_local_id(0);\n"
"int gidX = get_group_id(0);\n"
"int gidY = get_group_id(1);\n"
"__global const float* hist = block_hists + (gidY * win_block_stride_y *\n"
"img_block_width + gidX * win_block_stride_x) * cblock_hist_size;\n"
"__global float* descriptor = descriptors +\n"
"(gidY * get_num_groups(0) + gidX) * descriptors_quadstep;\n"
"for (int i = tid; i < cdescr_size; i += NTHREADS)\n"
"{\n"
"int offset_y = i / cdescr_width;\n"
"int offset_x = i - offset_y * cdescr_width;\n"
"descriptor[i] = hist[offset_y * img_block_width * cblock_hist_size + offset_x];\n"
"}\n"
"}\n"
"__kernel void extract_descrs_by_cols_kernel(\n"
"const int cblock_hist_size, const int descriptors_quadstep, const int cdescr_size,\n"
"const int cnblocks_win_x, const int cnblocks_win_y, const int img_block_width,\n"
"const int win_block_stride_x, const int win_block_stride_y,\n"
"__global const float* block_hists, __global float* descriptors)\n"
"{\n"
"int tid = get_local_id(0);\n"
"int gidX = get_group_id(0);\n"
"int gidY = get_group_id(1);\n"
"__global const float* hist = block_hists + (gidY * win_block_stride_y *\n"
"img_block_width + gidX * win_block_stride_x) * cblock_hist_size;\n"
"__global float* descriptor = descriptors +\n"
"(gidY * get_num_groups(0) + gidX) * descriptors_quadstep;\n"
"for (int i = tid; i < cdescr_size; i += NTHREADS)\n"
"{\n"
"int block_idx = i / cblock_hist_size;\n"
"int idx_in_block = i - block_idx * cblock_hist_size;\n"
"int y = block_idx / cnblocks_win_x;\n"
"int x = block_idx - y * cnblocks_win_x;\n"
"descriptor[(x * cnblocks_win_y + y) * cblock_hist_size + idx_in_block] =\n"
"hist[(y * img_block_width + x) * cblock_hist_size + idx_in_block];\n"
"}\n"
"}\n"
"__kernel void compute_gradients_8UC4_kernel(\n"
"const int height, const int width,\n"
"const int img_step, const int grad_quadstep, const int qangle_step,\n"
"const __global uchar4 * img, __global float * grad, __global QANGLE_TYPE * qangle,\n"
"const float angle_scale, const char correct_gamma, const int cnbins)\n"
"{\n"
"const int x = get_global_id(0);\n"
"const int tid = get_local_id(0);\n"
"const int gSizeX = get_local_size(0);\n"
"const int gidY = get_group_id(1);\n"
"__global const uchar4* row = img + gidY * img_step;\n"
"__local float sh_row[(NTHREADS + 2) * 3];\n"
"uchar4 val;\n"
"if (x < width)\n"
"val = row[x];\n"
"else\n"
"val = row[width - 2];\n"
"sh_row[tid + 1] = val.x;\n"
"sh_row[tid + 1 + (NTHREADS + 2)] = val.y;\n"
"sh_row[tid + 1 + 2 * (NTHREADS + 2)] = val.z;\n"
"if (tid == 0)\n"
"{\n"
"val = row[max(x - 1, 1)];\n"
"sh_row[0] = val.x;\n"
"sh_row[(NTHREADS + 2)] = val.y;\n"
"sh_row[2 * (NTHREADS + 2)] = val.z;\n"
"}\n"
"if (tid == gSizeX - 1)\n"
"{\n"
"val = row[min(x + 1, width - 2)];\n"
"sh_row[gSizeX + 1] = val.x;\n"
"sh_row[gSizeX + 1 + (NTHREADS + 2)] = val.y;\n"
"sh_row[gSizeX + 1 + 2 * (NTHREADS + 2)] = val.z;\n"
"}\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (x < width)\n"
"{\n"
"float4 a = (float4) (sh_row[tid], sh_row[tid + (NTHREADS + 2)],\n"
"sh_row[tid + 2 * (NTHREADS + 2)], 0);\n"
"float4 b = (float4) (sh_row[tid + 2], sh_row[tid + 2 + (NTHREADS + 2)],\n"
"sh_row[tid + 2 + 2 * (NTHREADS + 2)], 0);\n"
"float4 dx;\n"
"if (correct_gamma == 1)\n"
"dx = sqrt(b) - sqrt(a);\n"
"else\n"
"dx = b - a;\n"
"float4 dy = (float4) 0.f;\n"
"if (gidY > 0 && gidY < height - 1)\n"
"{\n"
"a = convert_float4(img[(gidY - 1) * img_step + x].xyzw);\n"
"b = convert_float4(img[(gidY + 1) * img_step + x].xyzw);\n"
"if (correct_gamma == 1)\n"
"dy = sqrt(b) - sqrt(a);\n"
"else\n"
"dy = b - a;\n"
"}\n"
"float4 mag = hypot(dx, dy);\n"
"float best_dx = dx.x;\n"
"float best_dy = dy.x;\n"
"float mag0 = mag.x;\n"
"if (mag0 < mag.y)\n"
"{\n"
"best_dx = dx.y;\n"
"best_dy = dy.y;\n"
"mag0 = mag.y;\n"
"}\n"
"if (mag0 < mag.z)\n"
"{\n"
"best_dx = dx.z;\n"
"best_dy = dy.z;\n"
"mag0 = mag.z;\n"
"}\n"
"float ang = (atan2(best_dy, best_dx) + CV_PI_F) * angle_scale - 0.5f;\n"
"int hidx = (int)floor(ang);\n"
"ang -= hidx;\n"
"hidx = (hidx + cnbins) % cnbins;\n"
"qangle[(gidY * qangle_step + x) << 1] = hidx;\n"
"qangle[((gidY * qangle_step + x) << 1) + 1] = (hidx + 1) % cnbins;\n"
"grad[(gidY * grad_quadstep + x) << 1] = mag0 * (1.f - ang);\n"
"grad[((gidY * grad_quadstep + x) << 1) + 1] = mag0 * ang;\n"
"}\n"
"}\n"
"__kernel void compute_gradients_8UC1_kernel(\n"
"const int height, const int width,\n"
"const int img_step, const int grad_quadstep, const int qangle_step,\n"
"__global const uchar * img, __global float * grad, __global QANGLE_TYPE * qangle,\n"
"const float angle_scale, const char correct_gamma, const int cnbins)\n"
"{\n"
"const int x = get_global_id(0);\n"
"const int tid = get_local_id(0);\n"
"const int gSizeX = get_local_size(0);\n"
"const int gidY = get_group_id(1);\n"
"__global const uchar* row = img + gidY * img_step;\n"
"__local float sh_row[NTHREADS + 2];\n"
"if (x < width)\n"
"sh_row[tid + 1] = row[x];\n"
"else\n"
"sh_row[tid + 1] = row[width - 2];\n"
"if (tid == 0)\n"
"sh_row[0] = row[max(x - 1, 1)];\n"
"if (tid == gSizeX - 1)\n"
"sh_row[gSizeX + 1] = row[min(x + 1, width - 2)];\n"
"barrier(CLK_LOCAL_MEM_FENCE);\n"
"if (x < width)\n"
"{\n"
"float dx;\n"
"if (correct_gamma == 1)\n"
"dx = sqrt(sh_row[tid + 2]) - sqrt(sh_row[tid]);\n"
"else\n"
"dx = sh_row[tid + 2] - sh_row[tid];\n"
"float dy = 0.f;\n"
"if (gidY > 0 && gidY < height - 1)\n"
"{\n"
"float a = (float) img[ (gidY + 1) * img_step + x ];\n"
"float b = (float) img[ (gidY - 1) * img_step + x ];\n"
"if (correct_gamma == 1)\n"
"dy = sqrt(a) - sqrt(b);\n"
"else\n"
"dy = a - b;\n"
"}\n"
"float mag = hypot(dx, dy);\n"
"float ang = (atan2(dy, dx) + CV_PI_F) * angle_scale - 0.5f;\n"
"int hidx = (int)floor(ang);\n"
"ang -= hidx;\n"
"hidx = (hidx + cnbins) % cnbins;\n"
"qangle[ (gidY * qangle_step + x) << 1 ] = hidx;\n"
"qangle[ ((gidY * qangle_step + x) << 1) + 1 ] = (hidx + 1) % cnbins;\n"
"grad[ (gidY * grad_quadstep + x) << 1 ] = mag * (1.f - ang);\n"
"grad[ ((gidY * grad_quadstep + x) << 1) + 1 ] = mag * ang;\n"
"}\n"
"}\n"
, "bc57f4f75fb81bae73bfe73cc4ca15e4", NULL};
}}}
#endif
|
#include "debug/textDisplay.h"
#include "platform.h"
#include "gl/glError.h"
#include "gl/vertexLayout.h"
#include "gl/renderState.h"
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include <cstdarg>
#define STB_EASY_FONT_IMPLEMENTATION
#include "stb_easy_font.h"
namespace Tangram {
TextDisplay::TextDisplay() : m_textDisplayResolution(350.0), m_initialized(false) {
m_vertexBuffer = new char[VERTEX_BUFFER_SIZE];
}
TextDisplay::~TextDisplay() {
delete[] m_vertexBuffer;
}
void TextDisplay::init() {
if (m_initialized) {
return;
}
std::string vertShaderSrcStr = R"END(
#ifdef GL_ES
precision mediump float;
#define LOWP lowp
#else
#define LOWP
#endif
uniform mat4 u_orthoProj;
attribute vec2 a_position;
void main() {
gl_Position = u_orthoProj * vec4(a_position, 0.0, 1.0);
}
)END";
std::string fragShaderSrcStr = R"END(
#ifdef GL_ES
precision mediump float;
#define LOWP lowp
#else
#define LOWP
#endif
uniform vec3 u_color;
void main(void) {
gl_FragColor = vec4(u_color, 1.0);
}
)END";
m_shader = std::make_unique<ShaderProgram>();
m_shader->setShaderSource(vertShaderSrcStr, fragShaderSrcStr);
m_initialized = true;
}
void TextDisplay::deinit() {
m_shader.reset(nullptr);
m_initialized = false;
}
void TextDisplay::log(const char* fmt, ...) {
static char text[99999];
va_list args;
va_start(args, fmt);
vsprintf(text, fmt, args);
va_end(args);
{
std::lock_guard<std::mutex> lock(m_mutex);
for (int i = LOG_CAPACITY - 1; i >= 1; i--) {
m_log[i] = m_log[i - 1];
}
m_log[0] = std::string(text);
}
}
void TextDisplay::draw(RenderState& rs, const std::string& _text, int _posx, int _posy) {
static VertexLayout vertexLayout({{"a_position", 2, GL_FLOAT, false, 0}});
std::vector<glm::vec2> vertices;
int nquads;
nquads = stb_easy_font_print(_posx, _posy, const_cast<char*>(_text.c_str()), NULL, m_vertexBuffer, VERTEX_BUFFER_SIZE);
float* data = reinterpret_cast<float*>(m_vertexBuffer);
vertices.reserve(nquads * 6);
for (int quad = 0, stride = 0; quad < nquads; ++quad, stride += 16) {
vertices.push_back({data[(0 * 4) + stride], data[(0 * 4) + 1 + stride]});
vertices.push_back({data[(1 * 4) + stride], data[(1 * 4) + 1 + stride]});
vertices.push_back({data[(2 * 4) + stride], data[(2 * 4) + 1 + stride]});
vertices.push_back({data[(2 * 4) + stride], data[(2 * 4) + 1 + stride]});
vertices.push_back({data[(3 * 4) + stride], data[(3 * 4) + 1 + stride]});
vertices.push_back({data[(0 * 4) + stride], data[(0 * 4) + 1 + stride]});
}
vertexLayout.enable(rs, *m_shader, 0, (void*)vertices.data());
GL::drawArrays(GL_TRIANGLES, 0, nquads * 6);
}
void TextDisplay::draw(RenderState& rs, const std::vector<std::string>& _infos) {
GLint boundbuffer = -1;
if (!m_shader->use(rs)) { return; }
rs.culling(GL_FALSE);
rs.blending(GL_FALSE);
rs.depthTest(GL_FALSE);
rs.depthMask(GL_FALSE);
GL::getIntegerv(GL_ARRAY_BUFFER_BINDING, &boundbuffer);
rs.vertexBuffer(0);
glm::mat4 orthoProj = glm::ortho(0.f, (float)m_textDisplayResolution.x, (float)m_textDisplayResolution.y, 0.f, -1.f, 1.f);
m_shader->setUniformMatrix4f(rs, m_uOrthoProj, orthoProj);
// Display Tangram info messages
m_shader->setUniformf(rs, m_uColor, 0.f, 0.f, 0.f);
int offset = 0;
for (auto& text : _infos) {
draw(rs, text, 3, 3 + offset);
offset += 10;
}
// Display screen log
offset = 0;
m_shader->setUniformf(rs, m_uColor, 51 / 255.f, 73 / 255.f, 120 / 255.f);
for (int i = 0; i < LOG_CAPACITY; ++i) {
draw(rs, m_log[i], 3, m_textDisplayResolution.y - 10 + offset);
offset -= 10;
}
rs.culling(GL_TRUE);
rs.vertexBuffer(boundbuffer);
}
}
|
// Copyright 2019 The MWC Developers
//
// 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 "windows/y_selectmode_w.h"
#include "ui_y_selectmode.h"
#include "../state/y_selectmode.h"
#include "../control/messagebox.h"
namespace wnd {
SelectMode::SelectMode(QWidget *parent, state::SelectMode * _state) :
core::NavWnd(parent, _state->getContext() ),
ui(new Ui::SelectMode),
state(_state)
{
ui->setupUi(this);
runMode = state->getWalletRunMode();
switch (runMode) {
case config::WALLET_RUN_MODE::ONLINE_WALLET: {
ui->radioOnlineWallet->setChecked(true);
break;
}
case config::WALLET_RUN_MODE::ONLINE_NODE: {
ui->radioOnlineNode->setChecked(true);
break;
}
case config::WALLET_RUN_MODE::COLD_WALLET: {
ui->radioColdWallet->setChecked(true);
break;
}
default:
Q_ASSERT(false);
}
updateButtons();
}
SelectMode::~SelectMode() {
state->deleteWnd(this);
delete ui;
}
config::WALLET_RUN_MODE SelectMode::getRunMode() const {
if ( ui->radioOnlineWallet->isChecked() )
return config::WALLET_RUN_MODE::ONLINE_WALLET;
if ( ui->radioOnlineNode->isChecked() )
return config::WALLET_RUN_MODE::ONLINE_NODE;
if ( ui->radioColdWallet->isChecked() )
return config::WALLET_RUN_MODE::COLD_WALLET;
Q_ASSERT(false);
return config::WALLET_RUN_MODE::ONLINE_WALLET;
}
void SelectMode::updateButtons() {
ui->applyButton->setEnabled( runMode != getRunMode() );
}
void SelectMode::on_applyButton_clicked() {
if ( control::MessageBox::RETURN_CODE::BTN2 == control::MessageBox::questionText(this, "Waller Run Mode",
"Changing running mode required restart.",
"Cancel", "Continue", false, true) ) {
state->updateWalletRunMode(SelectMode::getRunMode());
}
}
void SelectMode::on_radioOnlineWallet_clicked() {
updateButtons();
}
void SelectMode::on_radioOnlineNode_clicked() {
updateButtons();
}
void SelectMode::on_radioColdWallet_clicked() {
updateButtons();
}
}
|
#include <Processors/Formats/Impl/CSVRowOutputFormat.h>
#include <Formats/FormatFactory.h>
#include <IO/WriteHelpers.h>
namespace DB
{
CSVRowOutputFormat::CSVRowOutputFormat(WriteBuffer & out_, const Block & header_, bool with_names_, FormatFactory::WriteCallback callback, const FormatSettings & format_settings_)
: IRowOutputFormat(header_, out_, callback), with_names(with_names_), format_settings(format_settings_)
{
auto & sample = getPort(PortKind::Main).getHeader();
size_t columns = sample.columns();
data_types.resize(columns);
for (size_t i = 0; i < columns; ++i)
data_types[i] = sample.safeGetByPosition(i).type;
}
void CSVRowOutputFormat::writePrefix()
{
auto & sample = getPort(PortKind::Main).getHeader();
size_t columns = sample.columns();
if (with_names)
{
for (size_t i = 0; i < columns; ++i)
{
writeCSVString(sample.safeGetByPosition(i).name, out);
char delimiter = format_settings.csv.delimiter;
if (i + 1 == columns)
delimiter = '\n';
writeChar(delimiter, out);
}
}
}
void CSVRowOutputFormat::writeField(const IColumn & column, const IDataType & type, size_t row_num)
{
type.serializeAsTextCSV(column, row_num, out, format_settings);
}
void CSVRowOutputFormat::writeFieldDelimiter()
{
writeChar(format_settings.csv.delimiter, out);
}
void CSVRowOutputFormat::writeRowEndDelimiter()
{
writeChar('\n', out);
}
void CSVRowOutputFormat::writeBeforeTotals()
{
writeChar('\n', out);
}
void CSVRowOutputFormat::writeBeforeExtremes()
{
writeChar('\n', out);
}
void registerOutputFormatProcessorCSV(FormatFactory & factory)
{
for (bool with_names : {false, true})
{
factory.registerOutputFormatProcessor(with_names ? "CSVWithNames" : "CSV", [=](
WriteBuffer & buf,
const Block & sample,
const Context &,
FormatFactory::WriteCallback callback,
const FormatSettings & format_settings)
{
return std::make_shared<CSVRowOutputFormat>(buf, sample, with_names, callback, format_settings);
});
}
}
}
|
; A084942: Enneagorials: n-th polygorial for k=9.
; Submitted by Jamie Morken(s3)
; 1,1,9,216,9936,745200,82717200,12738448800,2598643555200,678245967907200,220429939569840000,87290256069656640000,41375581377017247360000,23128949989752641274240000
mov $2,1
mov $4,1
lpb $0
sub $0,1
add $3,$2
add $2,7
mul $4,$3
lpe
mov $0,$4
|
; ------------------------------------------------------------------
; MichalOS Hardware checker
; ------------------------------------------------------------------
BITS 16
%INCLUDE "michalos.inc"
ORG 100h
start:
mov eax, 0 ; Get the maximum parameter for basic CPUID
cpuid
mov [basicid], eax
mov eax, 80000000h ; Get the maximum parameter for extended CPUID
cpuid
mov [extendedid], eax
main_loop:
mov al, 0
mov cx, 64
mov di, p1
rep stosb
call background
mov ax, optionlist
mov bx, optionmsg1
mov cx, optionmsg2
call os_list_dialog
call background
cmp ax, 1
je checkvendor
cmp ax, 2
je checkfeatures
cmp ax, 3
je extendedcpu
cmp ax, 4
je vesa
exit:
call os_clear_screen
ret
background:
pusha
call os_clear_screen
mov ax, welcomemsg
mov bx, footermsg
mov cx, 11110000b
call os_draw_background
mov dl, 0
mov dh, 2
call os_move_cursor
popa
ret
%INCLUDE "hwcheck/basic.asm"
%INCLUDE "hwcheck/features.asm"
%INCLUDE "hwcheck/extended.asm"
%INCLUDE "hwcheck/vesa.asm"
basicid dd 0
extendedid dd 0
unit_kb db ' kB', 0
unit_mhz db ' MHz', 0
unit_hex db 'h', 0
noimp db '<Unavailable>', 0
enabled db 'Enabled', 0
disabled db 'Disabled', 0
welcomemsg db 'MichalOS Hardware Checking Utility', 0
footermsg db 0
optionmsg1 db 'Choose an option...', 0
optionmsg2 db 0
optionlist db 'Basic system specifications,Processor features,Processor specifications,VESA specifications', 0
buffer:
p1 dd 0
p2 dd 0
p3 dd 0
p4 dd 0
p5 dd 0
p6 dd 0
p7 dd 0
p8 dd 0
p9 dd 0
p0 dd 0
p10 dd 0
p11 dd 0
p12 dd 0
p13 dd 0
p14 dd 0
p15 dd 0
p16 dd 0
pfinal db 0
; ------------------------------------------------------------------
|
/**
* Copyright (C) 2022 Xilinx, Inc
* Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may
* not use this file except in compliance with the License. A copy of the
* License is located 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.
*/
// ------ I N C L U D E F I L E S -------------------------------------------
// Local - Include Files
#include "SubCmdConfigure.h"
#include "tools/common/XBUtilitiesCore.h"
#include "tools/common/XBUtilities.h"
#include "core/common/system.h"
#include "core/common/utils.h"
namespace XBU = XBUtilities;
// 3rd Party Library - Include Files
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
namespace po = boost::program_options;
// System - Include Files
#include <iostream>
constexpr const char* config_file = "/etc/msd.conf";
enum class config_type {
security = 0,
clk_scaling,
threshold_power_override,
threshold_temp_override,
reset
};
std::ostream&
operator<<(std::ostream& os, const config_type& value)
{
switch (value) {
case config_type::security:
os << "security";
break;
case config_type::clk_scaling:
os << "runtime clock scaling";
break;
case config_type::threshold_power_override:
os << "threshold power override";
break;
case config_type::threshold_temp_override:
os << "threshold temp override";
break;
case config_type::reset:
os << "clock scaling option reset";
break;
default:
throw std::runtime_error("Configuration missing enumeration conversion");
}
return os;
}
enum class mem_type {
unknown= 0,
ddr,
hbm
};
// Presumably a struct in anticipation of more data
struct config
{
std::string host;
explicit config() {}
friend std::ostream&
operator<<(std::ostream& ostr, const struct config& cfg)
{
ostr << boost::str(boost::format("host=%s") % cfg.host);
return ostr;
}
};
SubCmdConfigure::SubCmdConfigure(bool _isHidden, bool _isDepricated, bool _isPreliminary)
: SubCmd("configure",
"Advanced options for configuring a device")
{
const std::string long_description = "Advanced options for configuring a device";
setLongDescription(long_description);
setExampleSyntax("");
setIsHidden(_isHidden);
setIsDeprecated(_isDepricated);
setIsPreliminary(_isPreliminary);
}
static void load_config(const std::shared_ptr<xrt_core::device>& _dev, const std::string path)
{
boost::property_tree::ptree pt_root;
boost::property_tree::ini_parser::read_ini(path, pt_root);
static boost::property_tree::ptree empty_tree;
const boost::property_tree::ptree& pt_device = pt_root.get_child("Device", empty_tree);
if (pt_device.empty())
throw std::runtime_error(boost::str(boost::format("No [Device] section in the config file. Config File: %s") % path));
for (const auto& key : pt_device) {
if (!key.first.compare("mailbox_channel_disable")) {
xrt_core::device_update<xrt_core::query::config_mailbox_channel_disable>(_dev.get(), key.second.get_value<std::string>());
continue;
}
if (!key.first.compare("mailbox_channel_switch")) {
xrt_core::device_update<xrt_core::query::config_mailbox_channel_switch>(_dev.get(), key.second.get_value<std::string>());
continue;
}
if (!key.first.compare("xclbin_change")) {
xrt_core::device_update<xrt_core::query::config_xclbin_change>(_dev.get(), key.second.get_value<std::string>());
continue;
}
if (!key.first.compare("cache_xclbin")) {
xrt_core::device_update<xrt_core::query::cache_xclbin>(_dev.get(), key.second.get_value<std::string>());
continue;
}
if (!key.first.compare("scaling_enabled")) {
xrt_core::device_update<xrt_core::query::xmc_scaling_enabled>(_dev.get(), key.second.get_value<std::string>());
continue;
}
if (!key.first.compare("scaling_power_override")) {
xrt_core::device_update<xrt_core::query::xmc_scaling_power_override>(_dev.get(), key.second.get_value<std::string>());
continue;
}
if (!key.first.compare("scaling_temp_override")) {
xrt_core::device_update<xrt_core::query::xmc_scaling_temp_override>(_dev.get(), key.second.get_value<std::string>());
continue;
}
throw std::runtime_error(boost::str(boost::format("'%s' is not a supported config entry") % key.first));
}
}
static config
get_daemon_conf()
{
config cfg;
cfg.host = xrt_core::utils::get_hostname();
std::ifstream istr(config_file);
if (!istr)
return cfg;
// Load persistent value, may overwrite default one
std::string line;
while (std::getline(istr, line)) {
auto pos = line.find('=', 0);
if (pos == std::string::npos)
throw xrt_core::system_error(EIO, "Bad daemon config file line '" + line + "'");
auto key = line.substr(0, pos++);
auto value = line.substr(pos);
if (key == "host")
cfg.host = value;
}
return cfg;
}
/*
* helper function for option: showx
* shows daemon config
*/
static void
show_daemon_conf()
{
auto cfg = get_daemon_conf();
std::cout << "Daemon:\n";
std::cout << boost::str(boost::format(" %s\n") % cfg);
}
/*
* helper function for option: showx
* shows device config
*/
static void
show_device_conf(xrt_core::device* device)
{
auto bdf_raw = xrt_core::device_query<xrt_core::query::pcie_bdf>(device);
auto bdf = xrt_core::query::pcie_bdf::to_string(bdf_raw);
std::cout << bdf << "\n";
bool is_mfg = false;
bool is_recovery = false;
try {
is_mfg = xrt_core::device_query<xrt_core::query::is_mfg>(device);
is_recovery = xrt_core::device_query<xrt_core::query::is_recovery>(device);
}
catch (const std::exception& ex) {
std::cerr << ex.what() << "\n";
}
if (is_mfg || is_recovery)
throw xrt_core::error(std::errc::operation_canceled, "This operation is not supported with manufacturing image.\n");
boost::format node_data_format(" %-33s: %s\n");
std::string not_supported = "Not supported";
std::string sec_level = not_supported;
try {
sec_level = std::to_string(xrt_core::device_query<xrt_core::query::sec_level>(device));
}
catch (xrt_core::query::exception&) {
//safe to ignore. These sysfs nodes are not present for vck5000
}
std::cout << node_data_format % "Security level" % sec_level;
std::string scaling_enabled = not_supported;
try {
scaling_enabled = xrt_core::device_query<xrt_core::query::xmc_scaling_enabled>(device);
}
catch (xrt_core::query::exception&) {
//safe to ignore. These sysfs nodes are not present for u30 and vck5000
}
std::cout << node_data_format % "Runtime clock scaling enabled" % scaling_enabled;
std::string scaling_power_override = not_supported;
try {
scaling_power_override = xrt_core::device_query<xrt_core::query::xmc_scaling_power_override>(device);
}
catch (xrt_core::query::exception&) {
//safe to ignore. These sysfs nodes are not present for u30 and vck5000
}
std::cout << node_data_format % "Scaling threshold power override" % scaling_power_override;
std::string scaling_temp_override = not_supported;
try {
scaling_temp_override = xrt_core::device_query<xrt_core::query::xmc_scaling_temp_override>(device);
}
catch (xrt_core::query::exception&) {
//safe to ignore. These sysfs nodes are not present for u30 and vck5000
}
std::cout << node_data_format % "Scaling threshold temp override" % scaling_temp_override;
std::string data_retention_string = not_supported;
try {
auto value = xrt_core::device_query<xrt_core::query::data_retention>(device);
auto data_retention = xrt_core::query::data_retention::to_bool(value);
data_retention_string = (data_retention ? "enabled" : "disabled");
}
catch (xrt_core::query::exception&) {
//safe to ignore. These sysfs nodes are not present for vck5000
}
std::cout << node_data_format % "Data retention" % data_retention_string;
std::cout << std::flush;
}
/*
* helper function for option:purge
* remove the daemon config file
*/
static void
remove_daemon_config()
{
XBU::sudo_or_throw("Removing Daemon configuration file requires sudo");
std::cout << boost::format("Removing Daemon configuration file \"%s\"\n") % config_file;
if(!XBU::can_proceed(XBU::getForce()))
throw xrt_core::error(std::errc::operation_canceled);
try {
if (boost::filesystem::remove(config_file))
std::cout << boost::format("Succesfully removed the Daemon configuration file.\n");
else
std::cout << boost::format("WARNING: Daemon configuration file does not exist.\n");
} catch (const boost::filesystem::filesystem_error &e) {
std::cerr << boost::format("ERROR: %s\n") % e.what();
throw xrt_core::error(std::errc::operation_canceled);
}
}
/*
* helper function for option:daemon
* change host name in config
*/
static void
update_daemon_config(const std::string& host = "")
{
XBU::sudo_or_throw("Updating daemon configuration requires sudo");
auto cfg = get_daemon_conf();
std::ofstream cfile(config_file);
if (!cfile)
throw xrt_core::system_error(std::errc::invalid_argument, "Missing '" + std::string(config_file) + "'. Cannot update");
if(!host.empty())
cfg.host = host;
// update the configuration file
cfile << boost::str(boost::format("%s\n") % cfg);
std::cout << boost::format("Successfully updated the Daemon configuration.\n");
}
/*
* helper function for option:device
* update device configuration
*/
static bool
update_device_conf(xrt_core::device* device, const std::string& value, config_type cfg)
{
XBU::sudo_or_throw("Updating device configuration requires sudo");
try {
switch(cfg) {
case config_type::security:
xrt_core::device_update<xrt_core::query::sec_level>(device, value);
break;
case config_type::clk_scaling:
xrt_core::device_update<xrt_core::query::xmc_scaling_enabled>(device, value);
break;
case config_type::threshold_power_override:
xrt_core::device_update<xrt_core::query::xmc_scaling_power_override>(device, value);
break;
case config_type::threshold_temp_override:
xrt_core::device_update<xrt_core::query::xmc_scaling_temp_override>(device, value);
break;
case config_type::reset:
xrt_core::device_update<xrt_core::query::xmc_scaling_reset>(device, value);
break;
}
} catch (const std::exception&) {
std::cerr << boost::format("ERROR: Device does not support %s\n\n") % cfg;
throw xrt_core::error(std::errc::operation_canceled);
}
return true;
}
/*
* helper function for option:en(dis)able_retention
* set data retention
*/
static void
memory_retention(xrt_core::device* device, bool enable)
{
XBU::sudo_or_throw("Updating memory retention requires sudo");
try {
auto value = xrt_core::query::data_retention::value_type(enable);
xrt_core::device_update<xrt_core::query::data_retention>(device, value);
} catch (const std::exception&) {
std::cerr << boost::format("ERROR: Device does not support memory retention\n\n");
throw xrt_core::error(std::errc::operation_canceled);
}
}
void
SubCmdConfigure::execute(const SubCmdOptions& _options) const
{
XBU::verbose("SubCommand: configure");
// -- Retrieve and parse the subcommand options -----------------------------
// Common options
std::vector<std::string> devices;
std::string path;
std::string retention;
bool help = false;
// Hidden options
bool daemon = false;
bool purge = false;
std::string host;
std::string security;
std::string clk_scale;
std::string power_override;
std::string temp_override;
std::string cs_reset;
bool showx = false;
// Options previously under the load config command
po::options_description loadConfigOptions("Load Config Options");
loadConfigOptions.add_options()
("input", boost::program_options::value<decltype(path)>(&path),"INI file with the memory configuration")
;
// Options previously under the config command
po::options_description configOptions("Config Options");
configOptions.add_options()
("retention", boost::program_options::value<decltype(retention)>(&retention),"Enables / Disables memory retention. Valid values are: [ENABLE | DISABLE]")
;
po::options_description commonOptions("Common Options");
commonOptions.add_options()
("device,d", boost::program_options::value<decltype(devices)>(&devices)->multitoken(), "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest")
("help", boost::program_options::bool_switch(&help), "Help to use this sub-command")
;
commonOptions.add(loadConfigOptions);
commonOptions.add(configOptions);
// Hidden options previously under the config command
po::options_description configHiddenOptions("Hidden Options");
configHiddenOptions.add_options()
("daemon", boost::program_options::bool_switch(&daemon), "Update the device daemon configuration")
("purge", boost::program_options::bool_switch(&purge), "Remove the daemon configuration file")
("host", boost::program_options::value<decltype(host)>(&host), "IP or hostname for device peer")
("security", boost::program_options::value<decltype(security)>(&security), "Update the security level for the device")
("runtime_clk_scale", boost::program_options::value<decltype(clk_scale)>(&clk_scale), "Enable/disable the device runtime clock scaling")
("cs_threshold_power_override", boost::program_options::value<decltype(power_override)>(&power_override), "Update the power threshold in watts")
("cs_threshold_temp_override", boost::program_options::value<decltype(temp_override)>(&temp_override), "Update the temperature threshold in celsius")
("cs_reset", boost::program_options::value<decltype(cs_reset)>(&cs_reset), "Reset all scaling options")
("showx", boost::program_options::bool_switch(&showx), "Display the device configuration settings")
;
// Parse sub-command ...
po::variables_map vm;
process_arguments(vm, _options, commonOptions, configHiddenOptions);
// Ensure mutual exclusion amongst the load config and config options
// TODO Once all of the config options are incorporated into the load config file
// the config options should be removed
for (const auto& loadConfigOption : loadConfigOptions.options()) {
// For common options
for (const auto& configOption : configOptions.options())
conflictingOptions(vm, loadConfigOption->long_name(), configOption->long_name());
// For hidden options
for (const auto& configHiddenOption : configHiddenOptions.options())
conflictingOptions(vm, loadConfigOption->long_name(), configHiddenOption->long_name());
}
// Check the options
// -- process "help" option -----------------------------------------------
if (help) {
printHelp(commonOptions, configHiddenOptions);
return;
}
// Non-device options
// Remove the daemon config file
if (purge) {
XBU::verbose("Sub command: --purge");
remove_daemon_config();
return;
}
// Update daemon
if (daemon) {
XBU::verbose("Sub command: --daemon");
update_daemon_config(host);
return;
}
// -- process "device" option -----------------------------------------------
if(devices.empty()) {
std::cerr << "ERROR: Please specify a single device using --device option" << "\n";
printHelp(commonOptions, configHiddenOptions);
throw xrt_core::error(std::errc::operation_canceled);
}
// Collect all of the devices of interest
std::set<std::string> deviceNames;
xrt_core::device_collection deviceCollection;
for (const auto & deviceName : devices)
deviceNames.insert(boost::algorithm::to_lower_copy(deviceName));
try {
XBU::collect_devices(deviceNames, false /*inUserDomain*/, deviceCollection);
} catch (const std::runtime_error& e) {
// Catch only the exceptions that we have generated earlier
std::cerr << boost::format("ERROR: %s\n") % e.what();
throw xrt_core::error(std::errc::operation_canceled);
}
// enforce 1 device specification
if(deviceCollection.size() != 1) {
std::cerr << "ERROR: Please specify a single device. Multiple devices are not supported" << "\n\n";
printHelp(commonOptions, configHiddenOptions);
throw xrt_core::error(std::errc::operation_canceled);
}
std::shared_ptr<xrt_core::device>& workingDevice = deviceCollection[0];
// If in factory mode the device is not ready for use
if (xrt_core::device_query<xrt_core::query::is_mfg>(workingDevice.get())) {
std::cout << boost::format("ERROR: Device is in factory mode and cannot be configured\n");
throw xrt_core::error(std::errc::operation_canceled);
}
// Load Config commands
// -- process "input" option -----------------------------------------------
if (!path.empty()) {
if (!boost::filesystem::exists(path)) {
std::cerr << boost::format("ERROR: Input file does not exist: '%s'") % path << "\n\n";
throw xrt_core::error(std::errc::operation_canceled);
}
if(boost::filesystem::extension(path).compare(".ini") != 0) {
std::cerr << boost::format("ERROR: Input file should be an INI file: '%s'") % path << "\n\n";
throw xrt_core::error(std::errc::operation_canceled);
}
try {
load_config(workingDevice, path);
std::cout << "Config has been successfully loaded" << std::endl;
return;
} catch (const std::runtime_error& e) {
// Catch only the exceptions that we have generated earlier
std::cout << boost::format("ERROR: %s\n") % e.what();
throw xrt_core::error(std::errc::operation_canceled);
}
}
// Config commands
// Option:showx
if (showx) {
XBU::verbose("Sub command: --showx");
if(daemon)
show_daemon_conf();
show_device_conf(workingDevice.get());
return;
}
// Keeps track if any parameter was updated to prevent no option printout/error
bool is_something_updated = false;
// Update security
if (!security.empty())
is_something_updated = update_device_conf(workingDevice.get(), security, config_type::security);
// Clock scaling
if (!clk_scale.empty())
is_something_updated = update_device_conf(workingDevice.get(), clk_scale, config_type::clk_scaling);
// Update threshold power override
if (!power_override.empty())
is_something_updated = update_device_conf(workingDevice.get(), power_override, config_type::threshold_power_override);
// Update threshold temp override
if (!temp_override.empty())
is_something_updated = update_device_conf(workingDevice.get(), temp_override, config_type::threshold_temp_override);
// cs_reset?? TODO needs better comment
if (!cs_reset.empty())
is_something_updated = update_device_conf(workingDevice.get(), cs_reset, config_type::reset);
// Enable/Disable Retention
if (!retention.empty()) {
// Validate the given retention string
boost::algorithm::to_upper(retention);
bool enableRetention = boost::iequals(retention, "ENABLE");
bool disableRetention = boost::iequals(retention, "DISABLE");
if (!enableRetention && !disableRetention) {
std::cerr << "ERROR: Invalidate '--retention' option: " << retention << std::endl;
printHelp(commonOptions, configHiddenOptions);
throw xrt_core::error(std::errc::operation_canceled);
}
memory_retention(workingDevice.get(), enableRetention);
// Memory retention was updated!
is_something_updated = true;
}
if (!is_something_updated) {
std::cerr << "ERROR: Please specify a valid option to configure the device" << "\n\n";
printHelp(commonOptions, configHiddenOptions);
throw xrt_core::error(std::errc::operation_canceled);
}
}
|
; A228842: Binomial transform of A014448.
; 2,6,28,144,752,3936,20608,107904,564992,2958336,15490048,81106944,424681472,2223661056,11643240448,60964798464,319215828992,1671435780096,8751751364608,45824765067264,239941584945152,1256350449401856,6578336356630528,34444616342175744,180354352626532352,944347650390491136,4944668491836817408,25890620349458939904,135565048129406369792,709827807378602459136,3716706651753989275648,19460928681009525817344,101898745479041197801472,533548758150209083539456,2793697566985089710030848,14627990369309701926027264,76593151947917852716040192,401046950210268308592132096,2099909093469938440688631808,10995266759978557409763262464,57571964185991590695825047552,301450718076035314535897235456,1578416451712245524432083222528,8264695837969331888448910393344,43274509220967009232965129469952,226588271973924727843995135246336,1186431594959680330132110293598208,6212236481862383069416681220603904,32527692511335577095971646149230592,170317209140563930298163152012967936,891792484798041273405092327480885248
mov $1,2
lpb $0
sub $0,1
mul $1,2
sub $1,1
add $2,$1
add $1,$2
mul $2,2
lpe
mov $0,$1
|
#section support_code_apply
// Apply-specific main function
int APPLY_SPECIFIC(factor_rev)(PyArrayObject* input0, PyArrayObject* input1,
PyArrayObject* input2, PyArrayObject* input3,
PyArrayObject* input4, PyArrayObject* input5,
PyArrayObject* input6, PyArrayObject** output0,
PyArrayObject** output1, PyArrayObject** output2,
PyArrayObject** output3) {
using namespace exoplanet;
// Read in U and extract the N and J dimensions
int success = 0;
npy_intp N, J;
auto U_in = get_matrix_input<DTYPE_INPUT_0>(&N, &J, input0, &success);
if (success) return 1;
if (CELERITE_J != Eigen::Dynamic && J != CELERITE_J) {
PyErr_Format(PyExc_ValueError,
"runtime value of J does not match compiled value");
return 1;
}
npy_intp input1_shape[] = {N - 1, J};
npy_intp input2_shape[] = {N};
npy_intp input3_shape[] = {N, J};
npy_intp input4_shape[] = {N, J * J};
npy_intp input5_shape[] = {N};
npy_intp input6_shape[] = {N, J};
auto P_in = get_input<DTYPE_INPUT_1>(2, input1_shape, input1, &success);
auto d_in = get_input<DTYPE_INPUT_2>(1, input2_shape, input2, &success);
auto W_in = get_input<DTYPE_INPUT_3>(2, input3_shape, input3, &success);
auto S_in = get_input<DTYPE_INPUT_4>(2, input4_shape, input4, &success);
auto bd_in = get_input<DTYPE_INPUT_5>(1, input5_shape, input5, &success);
auto bW_in = get_input<DTYPE_INPUT_6>(2, input6_shape, input6, &success);
if (success) return 1;
npy_intp shape0[] = {N};
npy_intp shape1[] = {N, J};
npy_intp shape2[] = {N, J};
npy_intp shape3[] = {N - 1, J};
auto ba_out = allocate_output<DTYPE_OUTPUT_0>(1, shape0, TYPENUM_OUTPUT_0,
output0, &success);
auto bU_out = allocate_output<DTYPE_OUTPUT_1>(2, shape1, TYPENUM_OUTPUT_1,
output1, &success);
auto bV_out = allocate_output<DTYPE_OUTPUT_2>(2, shape2, TYPENUM_OUTPUT_2,
output2, &success);
auto bP_out = allocate_output<DTYPE_OUTPUT_3>(2, shape3, TYPENUM_OUTPUT_3,
output3, &success);
if (success) return 1;
Eigen::Map<Eigen::Matrix<DTYPE_INPUT_0, Eigen::Dynamic, CELERITE_J,
CELERITE_J_ORDER>>
U(U_in, N, J);
Eigen::Map<Eigen::Matrix<DTYPE_INPUT_1, Eigen::Dynamic, CELERITE_J,
CELERITE_J_ORDER>>
P(P_in, N - 1, J);
Eigen::Map<Eigen::Matrix<DTYPE_INPUT_2, Eigen::Dynamic, 1>> d(d_in, N);
Eigen::Map<Eigen::Matrix<DTYPE_INPUT_3, Eigen::Dynamic, CELERITE_J,
CELERITE_J_ORDER>>
W(W_in, N, J);
Eigen::Map<Eigen::Matrix<DTYPE_INPUT_4, Eigen::Dynamic, CELERITE_J2,
CELERITE_J_ORDER>>
S(S_in, N, J * J);
Eigen::Map<Eigen::Matrix<DTYPE_INPUT_5, Eigen::Dynamic, 1>> bd(bd_in, N);
Eigen::Map<Eigen::Matrix<DTYPE_INPUT_6, Eigen::Dynamic, CELERITE_J,
CELERITE_J_ORDER>>
bW(bW_in, N, J);
Eigen::Map<Eigen::Matrix<DTYPE_OUTPUT_0, Eigen::Dynamic, 1>> ba(ba_out, N);
Eigen::Map<Eigen::Matrix<DTYPE_OUTPUT_1, Eigen::Dynamic, CELERITE_J,
CELERITE_J_ORDER>>
bU(bU_out, N, J);
Eigen::Map<Eigen::Matrix<DTYPE_OUTPUT_2, Eigen::Dynamic, CELERITE_J,
CELERITE_J_ORDER>>
bV(bV_out, N, J);
Eigen::Map<Eigen::Matrix<DTYPE_OUTPUT_3, Eigen::Dynamic, CELERITE_J,
CELERITE_J_ORDER>>
bP(bP_out, N - 1, J);
ba = bd;
bU.setZero();
bV = bW;
bP.setZero();
celerite::factor_grad(U, P, d, W, S, bU, bP, ba, bV);
return 0;
}
|
; A142646: Primes congruent to 13 mod 56.
; Submitted by Jon Maiga
; 13,181,293,349,461,797,853,1021,1301,1637,1693,1861,1973,2029,2141,2309,2477,3037,3373,3541,3709,3821,3877,3989,4157,4493,4549,5333,5501,5557,5669,6173,6229,6397,6733,7013,7069,7237,7349,7517,7573,7741,7853,8581,8693,8861,9029,9421,9533,10037,10093,10429,10597,10709,11213,11437,11549,11717,11941,12109,12277,12613,12781,12893,13229,13397,13789,13901,14293,14461,14629,14741,14797,15077,15413,15581,15749,15973,16141,16253,16421,16477,16981,17093,17317,17597,17989,18269,18493,18661,18773,19333
mov $2,$0
add $2,6
pow $2,2
mov $4,12
lpb $2
mov $3,$4
seq $3,10051 ; Characteristic function of primes: 1 if n is prime, else 0.
sub $0,$3
mov $1,$0
max $1,0
cmp $1,$0
mul $2,$1
sub $2,1
add $4,56
lpe
mov $0,$4
add $0,1
|
; A239844: Number of n X 2 0..3 arrays with no element equal to one plus the sum of elements to its left or one plus the sum of elements above it or two plus the sum of the elements diagonally to its northwest, modulo 4.
; 3,8,17,35,64,109,176,272,405,584,819,1121,1502,1975,2554,3254,4091,5082,6245,7599,9164,10961,13012,15340,17969,20924,24231,27917,32010,36539,41534,47026,53047,59630,66809,74619,83096,92277,102200,112904,124429,136816,150107,164345,179574,195839,213186,231662,251315,272194,294349,317831,342692,368985,396764,426084,457001,489572,523855,559909,597794,637571,679302,723050,768879,816854,867041,919507,974320,1031549,1091264,1153536,1218437,1286040,1356419,1429649,1505806,1584967,1667210,1752614,1841259,1933226,2028597,2127455,2229884,2335969,2445796,2559452,2677025,2798604,2924279,3054141,3188282,3326795,3469774,3617314,3769511,3926462,4088265,4255019,4426824,4603781,4785992,4973560,5166589,5365184,5569451,5779497,5995430,6217359,6445394,6679646,6920227,7167250,7420829,7681079,7948116,8222057,8503020,8791124,9086489,9389236,9699487,10017365,10342994,10676499,11018006,11367642,11725535,12091814,12466609,12850051,13242272,13643405,14053584,14472944,14901621,15339752,15787475,16244929,16712254,17189591,17677082,18174870,18683099,19201914,19731461,20271887,20823340,21385969,21959924,22545356,23142417,23751260,24372039,25004909,25650026,26307547,26977630,27660434,28356119,29064846,29786777,30522075,31270904,32033429,32809816,33600232,34404845,35223824,36057339,36905561,37768662,38646815,39540194,40448974,41373331,42313442,43269485,44241639,45230084,46235001,47256572,48294980,49350409,50423044,51513071,52620677,53746050,54889379,56050854,57230666,58429007,59646070,60882049,62137139,63411536,64705437,66019040,67352544,68706149,70080056,71474467,72889585,74325614,75782759,77261226,78761222,80282955,81826634
mov $3,$0
add $3,1
mov $6,$0
lpb $3,1
mov $0,$6
sub $3,1
sub $0,$3
mov $2,$0
pow $2,2
add $2,$0
mov $7,$0
add $0,$2
mov $5,$7
bin $5,3
mov $7,4
add $7,$2
sub $7,2
lpb $0,1
mov $0,$4
add $0,8
add $7,2
add $7,$5
lpe
add $7,1
add $1,$7
lpe
|
; A025793: Expansion of 1/((1-x)(1-x^10)(1-x^11)).
; 1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,4,5,6,6,6,6,6,6,6,6,7,8,9,10,10,10,10,10,10,10,11,12,13,14,15,15,15,15,15,15,16,17,18,19,20,21,21,21,21,21,22,23,24,25,26
mov $16,$0
add $16,1
lpb $16
clr $0,14
sub $16,1
sub $0,$16
mov $7,$0
lpb $7
mov $2,$7
div $2,10
add $4,6
mov $6,$4
mov $7,11
mul $7,$2
lpe
mov $1,10
gcd $1,$6
div $1,8
add $15,$1
lpe
mov $1,$15
|
; $Id: bit_synth_mwr.asm $
;
; void bit_synth(int duration, int frequency1, int frequency2, int frequency3, int frequency4);
;
; 1 bit sound library - version for "memory write" I/O architectures
;
; synthetizer - this is a sort of "quad sound" routine.
; It is based on 4 separate counters and a delay.
; Depending on the parameters being passed it is able to play
; on two audible voices, to generate sound effects and to play
; with a single voice having odd waveforms.
;
; The parameters are passed with a self modifying code trick :o(
; This routine shouldn't stay in contended memory locations !!
;
SECTION smc_clib
PUBLIC bit_synth
PUBLIC _bit_synth
INCLUDE "games/games.inc"
EXTERN bit_open_di
EXTERN bit_close_ei
.bit_synth
._bit_synth
ld ix,2
add ix,sp
ld a,(ix+8)
ld (LEN+1),a
ld a,(ix+6)
and a
jr z,FR1_blank
ld (FR_1+1),a
ld a,sndbit_mask
.FR1_blank
ld (FR1_tick+1),a
ld a,(ix+4)
and a
jr z,FR2_blank
ld (FR_2+1),a
ld a,sndbit_mask
.FR2_blank
ld (FR2_tick+1),a
ld a,(ix+2)
and a
jr z,FR3_blank
ld (FR_3+1),a
ld a,sndbit_mask
.FR3_blank
ld (FR1_tick+1),a
ld a,(ix+0)
and a
jr z,FR4_blank
ld (FR_4+1),a
ld a,sndbit_mask
.FR4_blank
ld (FR1_tick+1),a
call bit_open_di
ld h,1
ld l,h
ld d,h
ld e,h
.LEN
ld b,50
.loop
ld c,4
.loop2
dec h
jr nz,jump
.FR1_tick
xor sndbit_mask
ld (sndbit_port),a
.FR_1
ld h,80
.jump
dec l
jr nz,jump2
.FR2_tick
xor sndbit_mask
ld (sndbit_port),a
.FR_2
ld l,81
.jump2
dec d
jr nz,jump3
.FR3_tick
xor sndbit_mask
ld (sndbit_port),a
.FR_3
ld d,162
.jump3
dec e
jr nz,loop2
.FR4_tick
xor sndbit_mask
ld (sndbit_port),a
.FR_4
ld e,163
dec c
jr nz,loop2
djnz loop
call bit_close_ei
ret
|
// (C) Copyright Jeremy Siek and David Abrahams 2000-2001. Permission to copy,
// use, modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided "as is"
// without express or implied warranty, and with no claim as to its suitability
// for any purpose.
//
// Revision History:
// 11 Feb 2001 Use new iterator_adaptor interface, Fixes for Borland.
// (Dave Abrahams)
// 04 Feb 2001 Support for user-defined iterator categories (Dave Abrahams)
// 30 Jan 2001 Initial Checkin (Dave Abrahams)
#ifndef BOOST_HALF_OPEN_RANGE_HPP_
# define BOOST_HALF_OPEN_RANGE_HPP_
# include <boost/counting_iterator.hpp>
# include <functional>
# include <cassert>
# include <boost/operators.hpp>
# include <string>
# include <stdexcept>
# include <iterator>
namespace boost {
namespace detail {
// Template class choose_finish -- allows us to maintain the invariant that
// start() <= finish() on half_open_range specializations that support random
// access.
#ifdef __MWERKS__
template <class T>
const T& choose_finish(const T&, const T& finish, std::input_iterator_tag)
{
return finish;
}
template <class T>
const T& choose_finish(const T&, const T& finish, std::output_iterator_tag)
{
return finish;
}
template <class T>
const T& choose_finish(const T& start, const T& finish, std::random_access_iterator_tag)
{
return finish < start ? start : finish;
}
#else
template <bool is_random_access> struct finish_chooser;
template <>
struct finish_chooser<false>
{
template <class T>
struct rebind
{
static T choose(const T&, const T& finish)
{ return finish; }
};
};
template <>
struct finish_chooser<true>
{
template <class T>
struct rebind
{
static T choose(const T& start, const T& finish)
{ return finish < start ? start : finish; }
};
};
template <class Category, class Incrementable>
struct choose_finish
{
static const Incrementable choose(const Incrementable& start, const Incrementable& finish)
{
return finish_chooser<(
::boost::is_convertible<Category*,std::random_access_iterator_tag*>::value
)>::template rebind<Incrementable>::choose(start, finish);
}
};
#endif
}
template <class Incrementable>
struct half_open_range
{
typedef typename counting_iterator_generator<Incrementable>::type iterator;
private: // utility type definitions
// Using iter_t prevents compiler confusion with boost::iterator
typedef typename counting_iterator_generator<Incrementable>::type iter_t;
typedef std::less<Incrementable> less_value;
typedef typename iter_t::iterator_category category;
typedef half_open_range<Incrementable> self;
public:
typedef iter_t const_iterator;
typedef typename iterator::value_type value_type;
typedef typename iterator::difference_type difference_type;
typedef typename iterator::reference reference;
typedef typename iterator::reference const_reference;
typedef typename iterator::pointer pointer;
typedef typename iterator::pointer const_pointer;
// It would be nice to select an unsigned type, but this is appropriate
// since the library makes an attempt to select a difference_type which can
// hold the difference between any two iterators.
typedef typename iterator::difference_type size_type;
half_open_range(Incrementable start, Incrementable finish)
: m_start(start),
m_finish(
#ifndef __MWERKS__
detail::choose_finish<category,Incrementable>::choose(start, finish)
#else
detail::choose_finish(start, finish, category())
#endif
)
{}
// Implicit conversion from std::pair<Incrementable,Incrementable> allows us
// to accept the results of std::equal_range(), for example.
half_open_range(const std::pair<Incrementable,Incrementable>& x)
: m_start(x.first),
m_finish(
#ifndef __MWERKS__
detail::choose_finish<category,Incrementable>::choose(x.first, x.second)
#else
detail::choose_finish(x.first, x.second, category())
#endif
)
{}
half_open_range& operator=(const self& x)
{
m_start = x.m_start;
m_finish = x.m_finish;
return *this;
}
half_open_range& operator=(const std::pair<Incrementable,Incrementable>& x)
{
m_start = x.first;
m_finish =
#ifndef __MWERKS__
detail::choose_finish<category,Incrementable>::choose(x.first, x.second);
#else
detail::choose_finish(x.first, x.second, category();
#endif
}
iterator begin() const { return iterator(m_start); }
iterator end() const { return iterator(m_finish); }
Incrementable front() const { assert(!this->empty()); return m_start; }
Incrementable back() const { assert(!this->empty()); return boost::prior(m_finish); }
Incrementable start() const { return m_start; }
Incrementable finish() const { return m_finish; }
size_type size() const { return boost::detail::distance(begin(), end()); }
bool empty() const
{
return m_finish == m_start;
}
void swap(half_open_range& x) {
std::swap(m_start, x.m_start);
std::swap(m_finish, x.m_finish);
}
public: // functions requiring random access elements
// REQUIRES: x is reachable from this->front()
bool contains(const value_type& x) const
{
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
return !less_value()(x, m_start) && less_value()(x, m_finish);
}
bool contains(const half_open_range& x) const
{
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
return x.empty() || !less_value()(x.m_start, m_start) && !less_value()(m_finish, x.m_finish);
}
bool intersects(const half_open_range& x) const
{
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
return less_value()(
less_value()(this->m_start, x.m_start) ? x.m_start : this->m_start,
less_value()(this->m_finish, x.m_finish) ? this->m_finish : x.m_finish);
}
half_open_range& operator&=(const half_open_range& x)
{
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
if (less_value()(this->m_start, x.m_start))
this->m_start = x.m_start;
if (less_value()(x.m_finish, this->m_finish))
this->m_finish = x.m_finish;
if (less_value()(this->m_finish, this->m_start))
this->m_start = this->m_finish;
return *this;
}
half_open_range& operator|=(const half_open_range& x)
{
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
if (!x.empty())
{
if (this->empty())
{
*this = x;
}
else
{
if (less_value()(x.m_start, this->m_start))
this->m_start = x.m_start;
if (less_value()(this->m_finish, x.m_finish))
this->m_finish = x.m_finish;
}
}
return *this;
}
// REQUIRES: x is reachable from this->front()
const_iterator find(const value_type& x) const
{
BOOST_STATIC_ASSERT((boost::is_same<category, std::random_access_iterator_tag>::value));
return const_iterator(this->contains(x) ? x : m_finish);
}
// REQUIRES: index >= 0 && index < size()
value_type operator[](size_type index) const
{
assert(index >= 0 && index < size());
return m_start + index;
}
value_type at(size_type index) const
{
if (index < 0 || index >= size())
throw std::out_of_range(std::string("half_open_range"));
return m_start + index;
}
private: // data members
Incrementable m_start, m_finish;
};
template <class Incrementable>
half_open_range<Incrementable> operator|(
half_open_range<Incrementable> x,
const half_open_range<Incrementable>& y)
{
return x |= y;
}
template <class Incrementable>
half_open_range<Incrementable> operator&(
half_open_range<Incrementable> x,
const half_open_range<Incrementable>& y)
{
return x &= y;
}
template <class Incrementable>
inline bool operator==(
const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
const bool y_empty = y.empty();
return x.empty() ? y_empty : !y_empty && x.start() == y.start() && x.finish() == y.finish();
}
template <class Incrementable>
inline bool operator!=(
const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
return !(x == y);
}
template <class Incrementable>
inline half_open_range<Incrementable>
make_half_open_range(Incrementable first, Incrementable last)
{
return half_open_range<Incrementable>(first, last);
}
template <class Incrementable>
bool intersects(
const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
return x.intersects(y);
}
template <class Incrementable>
bool contains(
const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
return x.contains(y);
}
} // namespace boost
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
namespace std {
template <class Incrementable> struct less<boost::half_open_range<Incrementable> >
: binary_function<
boost::half_open_range<Incrementable>,
boost::half_open_range<Incrementable>,bool>
{
bool operator()(
const boost::half_open_range<Incrementable>& x,
const boost::half_open_range<Incrementable>& y) const
{
less<Incrementable> cmp;
return !y.empty() && (
cmp(x.start(), y.start())
|| !cmp(y.start(), x.start())
&& cmp(x.finish(), y.finish()));
}
};
template <class Incrementable> struct less_equal<boost::half_open_range<Incrementable> >
: binary_function<
boost::half_open_range<Incrementable>,
boost::half_open_range<Incrementable>,bool>
{
bool operator()(
const boost::half_open_range<Incrementable>& x,
const boost::half_open_range<Incrementable>& y) const
{
typedef boost::half_open_range<Incrementable> range;
less<range> cmp;
return !cmp(y,x);
}
};
template <class Incrementable> struct greater<boost::half_open_range<Incrementable> >
: binary_function<
boost::half_open_range<Incrementable>,
boost::half_open_range<Incrementable>,bool>
{
bool operator()(
const boost::half_open_range<Incrementable>& x,
const boost::half_open_range<Incrementable>& y) const
{
typedef boost::half_open_range<Incrementable> range;
less<range> cmp;
return cmp(y,x);
}
};
template <class Incrementable> struct greater_equal<boost::half_open_range<Incrementable> >
: binary_function<
boost::half_open_range<Incrementable>,
boost::half_open_range<Incrementable>,bool>
{
bool operator()(
const boost::half_open_range<Incrementable>& x,
const boost::half_open_range<Incrementable>& y) const
{
typedef boost::half_open_range<Incrementable> range;
less<range> cmp;
return !cmp(x,y);
}
};
} // namespace std
#else
namespace boost {
// Can't partially specialize std::less et al, so we must provide the operators
template <class Incrementable>
bool operator<(const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
return !y.empty() && (
x.empty() || std::less<Incrementable>()(x.start(), y.start())
|| !std::less<Incrementable>()(y.start(), x.start())
&& std::less<Incrementable>()(x.finish(), y.finish()));
}
template <class Incrementable>
bool operator>(const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
return y < x;
}
template <class Incrementable>
bool operator<=(const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
return !(y < x);
}
template <class Incrementable>
bool operator>=(const half_open_range<Incrementable>& x,
const half_open_range<Incrementable>& y)
{
return !(x < y);
}
} // namespace boost
#endif
#endif // BOOST_HALF_OPEN_RANGE_HPP_
|
Route12_h:
db OVERWORLD ; tileset
db ROUTE_12_HEIGHT, ROUTE_12_WIDTH ; dimensions (y, x)
dw Route12Blocks, Route12TextPointers, Route12Script ; blocks, texts, scripts
db NORTH | SOUTH | WEST ; connections
NORTH_MAP_CONNECTION ROUTE_12, LAVENDER_TOWN, 0, 0, LavenderTownBlocks
SOUTH_MAP_CONNECTION ROUTE_12, ROUTE_13, -3, 17, Route13Blocks
WEST_MAP_CONNECTION ROUTE_12, ROUTE_11, 27, 0, Route11Blocks
dw Route12Object ; objects
|
; A024067: a(n) = 6^n - n^5.
; 1,5,4,-27,272,4651,38880,263129,1646848,10018647,60366176,362636005,2176533504,13060322723,78363626272,470184225201,2821108858880,16926658024879,101559954778848,609359737534397,3656158436862976
mov $1,6
pow $1,$0
pow $0,5
add $0,1
sub $1,$0
add $1,1
|
/*
* Copyright (c) 2017-2019 THL A29 Limited, a Tencent company. 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 <tencentcloud/iai/v20200303/model/GroupExDescriptionInfo.h>
using TencentCloud::CoreInternalOutcome;
using namespace TencentCloud::Iai::V20200303::Model;
using namespace std;
GroupExDescriptionInfo::GroupExDescriptionInfo() :
m_groupExDescriptionIndexHasBeenSet(false),
m_groupExDescriptionHasBeenSet(false)
{
}
CoreInternalOutcome GroupExDescriptionInfo::Deserialize(const rapidjson::Value &value)
{
string requestId = "";
if (value.HasMember("GroupExDescriptionIndex") && !value["GroupExDescriptionIndex"].IsNull())
{
if (!value["GroupExDescriptionIndex"].IsUint64())
{
return CoreInternalOutcome(Error("response `GroupExDescriptionInfo.GroupExDescriptionIndex` IsUint64=false incorrectly").SetRequestId(requestId));
}
m_groupExDescriptionIndex = value["GroupExDescriptionIndex"].GetUint64();
m_groupExDescriptionIndexHasBeenSet = true;
}
if (value.HasMember("GroupExDescription") && !value["GroupExDescription"].IsNull())
{
if (!value["GroupExDescription"].IsString())
{
return CoreInternalOutcome(Error("response `GroupExDescriptionInfo.GroupExDescription` IsString=false incorrectly").SetRequestId(requestId));
}
m_groupExDescription = string(value["GroupExDescription"].GetString());
m_groupExDescriptionHasBeenSet = true;
}
return CoreInternalOutcome(true);
}
void GroupExDescriptionInfo::ToJsonObject(rapidjson::Value &value, rapidjson::Document::AllocatorType& allocator) const
{
if (m_groupExDescriptionIndexHasBeenSet)
{
rapidjson::Value iKey(rapidjson::kStringType);
string key = "GroupExDescriptionIndex";
iKey.SetString(key.c_str(), allocator);
value.AddMember(iKey, m_groupExDescriptionIndex, allocator);
}
if (m_groupExDescriptionHasBeenSet)
{
rapidjson::Value iKey(rapidjson::kStringType);
string key = "GroupExDescription";
iKey.SetString(key.c_str(), allocator);
value.AddMember(iKey, rapidjson::Value(m_groupExDescription.c_str(), allocator).Move(), allocator);
}
}
uint64_t GroupExDescriptionInfo::GetGroupExDescriptionIndex() const
{
return m_groupExDescriptionIndex;
}
void GroupExDescriptionInfo::SetGroupExDescriptionIndex(const uint64_t& _groupExDescriptionIndex)
{
m_groupExDescriptionIndex = _groupExDescriptionIndex;
m_groupExDescriptionIndexHasBeenSet = true;
}
bool GroupExDescriptionInfo::GroupExDescriptionIndexHasBeenSet() const
{
return m_groupExDescriptionIndexHasBeenSet;
}
string GroupExDescriptionInfo::GetGroupExDescription() const
{
return m_groupExDescription;
}
void GroupExDescriptionInfo::SetGroupExDescription(const string& _groupExDescription)
{
m_groupExDescription = _groupExDescription;
m_groupExDescriptionHasBeenSet = true;
}
bool GroupExDescriptionInfo::GroupExDescriptionHasBeenSet() const
{
return m_groupExDescriptionHasBeenSet;
}
|
addi r1 r0 100
bltz r1 end
addi r1 r0 -2586
bltz r1 print
halt
print:
addi r10 r0 65
tty r10
end:
halt
#prints A |
MODULE asm_scanf
SECTION code_clib
PUBLIC asm_scanf
PUBLIC __scanf_getchar
PUBLIC __scanf_ungetchar
PUBLIC __scanf_noop
PUBLIC scanf_exit
PUBLIC scanf_loop
PUBLIC __scanf_nextarg
EXTERN __scanf_parse_number
EXTERN __scanf_common_start
EXTERN __scanf_get_number
EXTERN __scanf_format_table
EXTERN __scanf_consume_whitespace
EXTERN asm_isspace
EXTERN asm_isdigit
EXTERN asm_isxdigit
EXTERN asm_isodigit
EXTERN asm_isbdigit
EXTERN asm_toupper
EXTERN l_long_mult
EXTERN l_long_neg
EXTERN atoi
EXTERN atof
EXTERN fa
EXTERN l_cmp
EXTERN fgetc
EXTERN ungetc
; int vfscanf1(FILE *fp, int sccz80, unsigned char *fmt,void *ap)
asm_scanf:
ld ix,0
add ix,sp ; Now the frame pointer
; ix+2, ix+3 = arg pointer
IF __CPU_R2KA__ | __CPU_R3K__
add sp,-50
ELSE
ld hl,-50 ; make some space on the stack
add hl,sp
ld sp,hl
ENDIF
; -1, -2 = conversions done
; -3 = flags [000a*WL0]
; -4 = width
; -5, -6 = bytes read from stream
; -50->-10 = fp number buffer
xor a
ld (ix-1),a
ld (ix-2),a
ld (ix-4),a
ld (ix-5),a
IF __CPU_R2KA__ | __CPU_R3K__
ld hl,(ix+4)
ELSE
ld l,(ix+4) ;format pointer
ld h,(ix+5)
ENDIF
scanf_loop:
__scanf_noop: ;noop destination
ld (ix-3),0 ;reset flags for each loop
ld a,(hl)
and a
jr z,scanf_exit
inc hl
cp '%'
jr z,is_percent
ld c,a ;save character
call asm_isspace
jr nz, scanf_ordinary_char
call __scanf_consume_whitespace
jr scanf_loop
; It's an ordinary char
scanf_ordinary_char:
call __scanf_getchar
jr c,scanf_exit
cp c
jr z,scanf_loop
call __scanf_ungetchar
scanf_exit:
; ISO C has us exit with # conversions done
; or -1 if no chars were read from the input stream
ld e,(ix-6)
ld d,(ix-5)
ld a,d
or e
ld de,-1
jr z,scanf_exit2
ld e,(ix-1)
ld d,0
scanf_exit2:
IF __CPU_R2KA__ | __CPU_R3K__
add sp,50
ELSE
ld hl,50
add hl,sp
ld sp,hl
ENDIF
ex de,hl
ret
is_percent:
; % {flags} [*] [width] [l] "[diouxXeEfFscpPbn"
flagloop:
ld a,(hl)
; cp 'a' ;network byte order
; jr nz,nextflag0
; set 4,(ix-3)
; inc hl
; jr flagloop
nextflag0:
cp '*'
jr nz,width
set 3,(ix-3)
inc hl
jr flagloop
width:
ld a,(hl)
call asm_isdigit
jr c,formatchar
set 2,(ix-3) ;set width flag
call atoi ;exits hl=number, de = non numeric in fmt
ex de,hl
ld (ix-4),e
formatchar:
; Consider those that aren't affected by a long modifier first
ld a,(hl)
inc hl
ld c,a
cp '%' ; %% should match a single %
jr z,scanf_ordinary_char
cp 'h' ; short specifier
jr z,get_next_char
cp 'l'
jr nz, not_long_specifier
set 1,(ix-3)
get_next_char:
ld c,(hl)
inc hl
not_long_specifier:
ld de,__scanf_format_table
ex de,hl
scanf_format_loop:
ld a,(hl)
and a
jr z,format_nomatch
cp c
jr z,format_matched
inc hl
inc hl
inc hl
jr scanf_format_loop
format_matched:
inc hl
ld c,(hl) ;bc = address of formatter
inc hl
ld b,(hl)
ex de,hl ;hl = format string
push bc
ret
format_nomatch:
ex de,hl ;hl = format string
jp scanf_loop
__scanf_nextarg:
push hl ;hl=fmt, save it
IF __CPU_R2KA__ | __CPU_R3K__
ld hl,(ix+2)
ELSE
ld l,(ix+2)
ld h,(ix+3)
ENDIF
ld e,(hl)
inc hl
ld d,(hl) ;de = buffer, hl=ap+1
bit 0,(ix+6) ;sccz80 flag
jr nz,__scanf_nextarg_decrement
inc hl
__scanf_nextarg_exit:
IF __CPU_R2KA__ | __CPU_R3K__
ld (ix+2),hl
ELSE
ld (ix+2),l
ld (ix+3),h
ENDIF
pop hl ;restore fmt
ret
__scanf_nextarg_decrement:
dec hl
dec hl
dec hl
jr __scanf_nextarg_exit
; Exit: a = character
; NB: the supplied function must save ix
__scanf_getchar:
push bc ;save callers
push de ;save dest
push hl ;fmt
IF __CPU_R2KA__ | __CPU_R3K__
ld hl,(ix+8)
ELSE
ld l,(ix+8) ;fp
ld h,(ix+9)
ENDIF
push hl
call fgetc
pop bc
__scanf_getchar_return:
ld a,h
or l
;inc a ; if eof then 0
ld a,l ; set the return value
scf
jr z,__scanf_getchar_return1
and a ;reset carry
inc (ix-6)
jr nz,__scanf_getchar_return1
inc (ix-5)
__scanf_getchar_return1:
pop hl
pop de
pop bc
ret
; a=char to unget
; NB: the supplied function must save ix
__scanf_ungetchar:
push bc
push de
push hl ;fmt
dec (ix-6)
jr nc,__scanf_ungetchar1
dec (ix-5)
__scanf_ungetchar1:
ld l,a ;character to unget
ld h,0
push hl
ld c,(ix+8) ;fp
ld b,(ix+9)
push bc
call ungetc
pop bc
pop bc
jr __scanf_getchar_return1
|
; A226107: Number of strict partitions of n with Cookie Monster number 2.
; 0,0,1,1,2,3,3,4,4,6,5,7,6,9,7,10,8,12,9,13,10,15,11,16,12,18,13,19,14,21,15,22,16,24,17,25,18,27,19,28,20,30,21,31,22,33,23,34,24,36,25,37,26,39,27,40,28,42,29,43,30,45,31,46,32,48,33,49,34,51,35,52,36,54,37,55,38,57,39,58,40,60,41,61,42,63,43,64,44,66,45,67,46,69,47,70,48,72,49,73,50,75,51,76,52,78,53,79,54,81,55,82,56,84,57,85,58,87,59,88,60,90,61,91,62,93,63,94,64,96,65,97,66,99,67,100,68,102,69,103,70,105,71,106,72,108,73,109,74,111,75,112,76,114,77,115,78,117,79,118,80,120,81,121,82,123,83,124,84,126,85,127,86,129,87,130,88,132,89,133,90,135,91,136,92,138,93,139,94,141,95,142,96,144,97,145,98,147,99,148,100,150,101,151,102,153,103,154,104,156,105,157,106,159,107,160,108,162,109,163,110,165,111,166,112,168,113,169,114,171,115,172,116,174,117,175,118,177,119,178,120,180,121,181,122,183,123,184,124,186
mov $1,$0
lpb $0
div $0,2
mul $0,2
div $1,2
mul $1,3
lpe
div $1,2
|
32_Header:
sHeaderInit ; Z80 offset is $C000
sHeaderPatch 32_Patches
sHeaderTick $01
sHeaderCh $01
sHeaderSFX $80, $05, 32_FM5, $00, $05
32_FM5:
sPan spRight
sPatFM $00
dc.b nE5, $05, nG5, $05, nC6, $1B
sStop
32_Patches:
; Patch $00
; $04
; $37, $72, $77, $49, $1F, $1F, $1F, $1F
; $07, $0A, $07, $0D, $00, $0B, $00, $0B
; $1F, $0F, $1F, $0F, $23, $80, $23, $80
spAlgorithm $04
spFeedback $00
spDetune $03, $07, $07, $04
spMultiple $07, $07, $02, $09
spRateScale $00, $00, $00, $00
spAttackRt $1F, $1F, $1F, $1F
spAmpMod $00, $00, $00, $00
spSustainRt $07, $07, $0A, $0D
spSustainLv $01, $01, $00, $00
spDecayRt $00, $00, $0B, $0B
spReleaseRt $0F, $0F, $0F, $0F
spTotalLv $23, $23, $00, $00
|
/*
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. 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.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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 <aws/email/model/VerifyDomainDkimRequest.h>
#include <aws/core/utils/StringUtils.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>
using namespace Aws::SES::Model;
using namespace Aws::Utils;
VerifyDomainDkimRequest::VerifyDomainDkimRequest() :
m_domainHasBeenSet(false)
{
}
Aws::String VerifyDomainDkimRequest::SerializePayload() const
{
Aws::StringStream ss;
ss << "Action=VerifyDomainDkim&";
if(m_domainHasBeenSet)
{
ss << "Domain=" << StringUtils::URLEncode(m_domain.c_str()) << "&";
}
ss << "Version=2010-12-01";
return ss.str();
}
void VerifyDomainDkimRequest::DumpBodyToUrl(Aws::Http::URI& uri ) const
{
uri.SetQueryString(SerializePayload());
}
|
; A214960: Expansion of psi(x^2) - x * psi(x^10) in powers of x where psi() is a Ramanujan theta function.
; Submitted by Jon Maiga
; 1,-1,1,0,0,0,1,0,0,0,0,-1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,-1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0
mov $2,-1
pow $2,$0
seq $0,127693 ; Expansion of psi(x^2) + x * psi(x^10) in powers of x where psi() is a Ramanujan theta function.
mul $0,$2
|
; A020107: Ceiling of GAMMA(n+3/10)/GAMMA(3/10).
; Submitted by Jon Maiga
; 1,1,1,1,3,13,68,426,3103,25751,239484,2466678,27873457,342843515,4559818741,65205407995,997642742322,16261576699845,281325276907304,5148252567403659,99361274550890614,2017033873383079454
mov $2,1
mov $3,$0
mul $3,5
lpb $3
sub $3,4
mov $5,$3
mul $5,2
add $5,1
mul $2,$5
sub $3,1
lpe
mov $4,10
pow $4,$0
add $4,3
div $2,$4
mov $0,$2
add $0,1
|
// Make sure coverage is dumped even if there are reported leaks.
//
// RUN: %clangxx_asan -fsanitize-coverage=func %s -o %t
//
// RUN: rm -rf %T/coverage-and-lsan
//
// RUN: mkdir -p %T/coverage-and-lsan/normal
// RUN: %env_asan_opts=coverage=1:coverage_dir=%T/coverage-and-lsan:verbosity=1 not %run %t 2>&1 | FileCheck %s
// RUN: %sancov print %T/coverage-and-lsan/*.sancov 2>&1
//
// REQUIRES: leak-detection
int *g = new int;
int main(int argc, char **argv) {
g = 0;
return 0;
}
// CHECK: LeakSanitizer: detected memory leaks
// CHECK: CovDump:
|
;
; Copyright (c) 2020 Bitdefender
; SPDX-License-Identifier: Apache-2.0
;
%include "system.nasm"
;
; PrepareAndCallTheKernel(SIZE_T ptrIntermediateCodeData, SIZE_T ptrCpuData)
;
global PrepareAndCallTheKernel
global _PrepareAndCallTheKernel@8
;
; CpustateCaptureGuestState(QWORD GuestInfo)
;
;extern CpustateCaptureGuestState
;CpustateCaptureGuestState dq 0
;
; CpustateSetRIP(QWORD ptrGuestInfo, QWORD ripValue)
;
;extern CpustateSetRIP
;CpustateSetRIP dq 0
;
; CpustateSetRSP(QWORD ptrGuestInfo, QWORD rspValue)
;
;extern CpustateSetRSP
;CpustateSetRSP dq 0
;
; CpustateRestoreGuestState(QWORD ptrGuestInfo)
;
;extern CpustateRestoreGuestState
;CpustateRestoreGuestState dq 0
ONE_KILOBYTE equ (1024)
ONE_MEGABYTE equ (1024 * ONE_KILOBYTE)
ONE_GIGABYTE equ (1024 * ONE_MEGABYTE)
ONE_TERABYTE equ (1024 * ONE_GIGABYTE)
CPU_CONTEXT_DATA_SIZE equ (4 * ONE_KILOBYTE) ;; must be same as the CPU_DATA::context from C code
CPU_STACK_SIZE equ (4 * ONE_KILOBYTE) ;; must be same as the CPU_DATA::stack from C code
IA32_FS_BASE equ 0C0000100H
IA32_GS_BASE equ 0C0000101H
IA32_MTRR_DEF_TYPE equ 2FFH
IA32_PAT_BASE equ 277H
DATA64_SEL equ 10H ;; 64 bit data selector / stack selector
CODE64_SEL equ 20H ;; 64 bit mode code selector
DATA32_SEL equ 08H ;; 32 bit data selector
CODE32_SEL equ 18H ;; 32 bit code selector
TR64_SEL equ 30H ;; TSS (TR) selector
EFER_LME_MASK equ 000000100H
EFER_LMA_MASK equ 000000400H
;;define CPU_DATA64 structure used to save the context of each cpu
struc CPU_DATA64
.cpuStackAddress resq 1
.cpuTempUnloadBufferAddress resq 1
.cpuTempUnloadBufferAddressPA resq 1
.cpuGuestStateDataAddress resq 1
.Status resq 1 ;; status code returned by hv on this CPU
;; os control registers
.OrigCr0 resq 1
.OrigCr3 resq 1
.OrigCr4 resq 1
;; os gdtr, idtr
.OrigGDTRLimit resw 1
.OrigGDTRBase resq 1
.OrigIDTRLimit resw 1
.OrigIDTRBase resq 1
;; segment registers
.OrigFSBase resq 1
.OrigGSBase resq 1
;; segment selectors
.OrigCS resw 1
.OrigDS resw 1
.OrigSS resw 1
.OrigES resw 1
.OrigFS resw 1
.OrigGS resw 1
.OrigTR resw 1
.EFlags resq 1
.PATMsr resq 1
endstruc
;;define CPU_DATA32 structure used to save the context of each cpu
struc CPU_DATA32
.cpuStackAddress32 resd 1
;; os control registers
.OrigCr0 resq 1
.OrigCr3 resq 1
.OrigCr4 resq 1
;; os gdtr, idtr
.OrigGDTRLimit resw 1
.OrigGDTRBase resq 1
.OrigIDTRLimit resw 1
.OrigIDTRBase resq 1
;; segment registers
.OrigFSBase resq 1
.OrigGSBase resq 1
;; segment selectors
.OrigCS resw 1
.OrigDS resw 1
.OrigSS resw 1
.OrigES resw 1
.OrigFS resw 1
.OrigGS resw 1
.OrigTR resw 1
.EFlags resq 1
endstruc
;; the following structure must overlap the INTERMEDIATE_CODE_DATA structure defined in C code
struc INTERMEDIATE_CODE_DATA
.intermediateCodePA resq 1
.intermediatePML4PA resq 1
.intermediatePDP32PA resq 1
.kernelEntryPoint resq 1
;; GDTR stuff - 10bytes for x64 and 6bytes for x32
;; 2 x DWORD(base & baseHigh) + 1 x WORD(Align0) is enough for both
;; Align1 is used to keep the descriptor addresses 8bytes aligned for performance
.gdtrLimit resw 1
.gdtrBase resd 1
.gdtrBaseHigh resd 1
.Align0 resw 1
.Align1 resd 1
.nullDescriptor resq 1
.dataDescriptor32 resq 1
.dataDescriptor64 resq 1
.codeDescriptor32 resq 1
.codeDescriptor64 resq 1
.bootType resq 1
.start resq 1
.loadedFrom32Bit resq 1
.loaderBootContext resq 1
endstruc
[BITS 32]
; fastcall
; PrepareAndCallTheKernel(SIZE_T ptrIntermediateCodeData, SIZE_T ptrCpuData)
;
_PrepareAndCallTheKernel@8:
;; first save regs and flags
pushad
pushfd
;; no more interrupts from now on
cli
;; save parameters
mov esi, edx ;; esi ptr to CPU_DATA32 struct
mov edi, ecx ;; edi ptr to INTERMEDIATE_CODE_DATA struct
;; switch stack and save orig value to new stack
mov eax, esp
mov esp, [esi + CPU_DATA32.cpuStackAddress32]
push eax
;; save partial 32bit context
mov ecx, IA32_FS_BASE
rdmsr
mov [esi + CPU_DATA32.OrigFSBase], eax
mov [esi + CPU_DATA32.OrigFSBase + 4], edx
mov ecx, IA32_GS_BASE
rdmsr
mov [esi + CPU_DATA32.OrigGSBase], eax
mov [esi + CPU_DATA32.OrigGSBase + 4], edx
mov eax, cr0
mov [esi + CPU_DATA32.OrigCr0], eax
mov eax, cr3
mov [esi + CPU_DATA32.OrigCr3], eax
mov eax, cr4
mov [esi + CPU_DATA32.OrigCr4], eax
lea eax, [esi + CPU_DATA32.OrigGDTRLimit]
sgdt [eax]
lea eax, [esi + CPU_DATA32.OrigIDTRLimit]
sidt [eax]
mov ax, cs
mov [esi + CPU_DATA32.OrigCS], ax
mov ax, ds
mov [esi + CPU_DATA32.OrigDS], ax
mov ax, ss
mov [esi + CPU_DATA32.OrigSS], ax
mov ax, es
mov [esi + CPU_DATA32.OrigES], ax
mov ax, fs
mov [esi + CPU_DATA32.OrigFS], ax
mov ax, gs
mov [esi + CPU_DATA32.OrigGS], ax
str ax
mov [esi + CPU_DATA32.OrigTR], ax
;;
;; mark the current task as not being busy (see "sys prog guide a" page 257)
;; before we load id in the tr, or else a GP will be triggered, see ltr instrction
;;
push edi
xor edi, edi
mov di, [esi + CPU_DATA32.OrigTR]
mov eax, [esi + CPU_DATA32.OrigGDTRBase]
shr edi, 3
imul edi, 8 ;; the shr and imul are not needed in this case, written only for clarity
add edi, eax ;; edi now points to the tss descriptor
mov eax, dword [edi + 4] ;; eax now contains the 2'nd dword of the tss descriptor
;; need to set bit 9 to 0 (to mark the task as not busy)
and eax, 0FFFFFDFFH
mov dword [edi + 4], eax ;; and store it in the task descriptor
pop edi
;; load our GDT
lea eax, [edi + INTERMEDIATE_CODE_DATA.gdtrLimit]
lgdt [eax]
;; set selectors
mov ax, DATA32_SEL
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
;; switch to our 32bit code segment
push CODE32_SEL
call $ + 5
add dword [esp], 5
retf
;; save to ebx the PA for PML4 for 64bit
;; !!! do not modify EBX !!!
mov ebx, [edi + INTERMEDIATE_CODE_DATA.intermediatePML4PA]
;; save to ecx the PA of intermediate code
;; !!! do not modify ECX !!!
mov ecx, [edi + INTERMEDIATE_CODE_DATA.intermediateCodePA]
;; save addres of PDP32PA
;; !!! do not modify EBP !!!
mov ebp, [edi + INTERMEDIATE_CODE_DATA.intermediatePDP32PA]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; TODO: (9)
;; 01) switch to 32bit identity mapping
mov eax, [edi + INTERMEDIATE_CODE_DATA.intermediatePDP32PA]
mov cr3, eax
;; save the current virtual address of the page
call $+5
and dword [esp], 0xFFFFF000
;; switch to identity virtual addresses (EIP update)
mov eax, ecx
call $ + 5
aici:
and dword [esp], 0xFFF
add dword [esp], eax
add dword [esp], aici1 - aici
ret
aici1:
;; 02) disable paging
mov eax, cr0
and eax, 0x7FFFFFFF
mov cr0, eax
;; 03) enable PAE
ENABLE_PAE
;; 04) load CR3 with pml4 for 64bit
xor eax, eax
mov eax, ebx
mov cr3, eax
;; 05) set LME in IA32_EFER
ENABLE_LME
;; 05.1) deactivate XD_DISABLE and LIMIT_CPUID in IA32_MISC and, if present, enable XD feature
CONFIGURE_IA32_MISC 0, IA32_MISC_ENABLE.XD_DISABLE | IA32_MISC_ENABLE.LIMIT_CPUID
ENABLE_XD
;; 06) enable paging
ENABLE_PAGING
;; 07) set/check LMA in IA32_EFER
mov ecx, IA32_EFER
rdmsr
bt eax, 10 ;; bit 10 is LMA bit
jc long_mode_ok
int 3 ;; triple fault here if not long mode
long_mode_ok:
;; 08) move to 64bit VA addresses
;; take virtual address from the stack
mov eax, dword [esp]
call $ + 5
and dword [esp], 0xFFF
add dword [esp], eax
add dword [esp], 0x0F
ret
;; switch to 64 bit code selector
push CODE64_SEL
call $ + 5
add dword [esp], 5
retf
[BITS 64]
;; 09) prepare and call: PrepareAndCallTheKernel - 64bit version
;; i need:
;; SIZE_T ptrIntermediateCodeData - this is in EDI
;; SIZE_T ptrCpuData - this is in ESI + sizeof(CPU_DATA32)
xor rcx, rcx
xor rdx, rdx
mov ecx, edi
mov edx, esi
add edx, 0x1000 ;; this is (and MUST be) sizeof(CPU_DATA32)
sub rsp, 0x20
call PrepareAndCallTheKernel
add rsp, 0x20
;;sub esi, 0x1000 ;; this is (and MUST be) sizeof(CPU_DATA32)
;; 10) all the above in reversed order :D
;; switch back to compatiblity mode
push CODE32_SEL
call $ + 5
add qword [rsp], 7
o64 retf
[BITS 32]
;; switch to 32bit identity mapping
mov eax, [edi + INTERMEDIATE_CODE_DATA.intermediateCodePA]
call $ + 5
and dword [esp], 0xFFF
add dword [esp], eax
add dword [esp], 15
ret
;; disable paging
mov eax, cr0
and eax, 0x7FFFFFFF
mov cr0, eax
;; load the pdbr for 32bit paging
mov cr3, ebp
;; disable LME
mov ecx, IA32_EFER
rdmsr
and eax, ~EFER_LME_MASK
wrmsr
;; enable paging in 32bit mode
mov eax, cr0
or eax, 0x80000000
mov cr0, eax
;; 6. a branch instruction must follow the cr0 that enables paging ???
jmp $ + 2
;; revert from identity mapping virtual addresses
pop eax ; restore the virtual address of the flat code from the stack (see above,
; when we switched to physical addresses)
call $ + 5
and dword [esp], 0xFFF
add dword [esp], eax
add dword [esp], 15
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; restore original CR3
mov eax, dword [esi + CPU_DATA32.OrigCr3]
mov cr3, eax
;; restore state
lea eax, [esi + CPU_DATA32.OrigGDTRLimit]
lgdt [eax]
lea eax, [esi + CPU_DATA32.OrigIDTRLimit]
lidt [eax]
mov ax, [esi + CPU_DATA32.OrigDS]
mov ds, ax
mov ax, [esi + CPU_DATA32.OrigSS]
mov ss, ax
mov ax, [esi + CPU_DATA32.OrigES]
mov es, ax
mov ax, [esi + CPU_DATA32.OrigFS]
mov fs, ax
mov ax, [esi + CPU_DATA32.OrigGS]
mov gs, ax
;; restore CS
xor eax, eax
mov ax, [esi + CPU_DATA32.OrigCS]
push eax
call $ + 5
add dword [esp], 5
retf
mov ecx, IA32_FS_BASE
mov eax, [esi + CPU_DATA32.OrigFSBase]
mov edx, [esi + CPU_DATA32.OrigFSBase + 4]
wrmsr
mov ecx, IA32_GS_BASE
mov eax, [esi + CPU_DATA32.OrigGSBase]
mov edx, [esi + CPU_DATA32.OrigGSBase + 4]
wrmsr
mov ax, [esi + CPU_DATA32.OrigTR]
ltr ax
;; revert to windows stack
;;mov eax, [esi + CPU_DATA32.cpuStackAddress32]
pop eax
mov esp, eax
;; restore regs and flags
popfd
popad
ret
%include "..\..\asmlib\loader_interface.nasm"
[BITS 64]
;
; PrepareAndCallTheKernel(SIZE_T ptrIntermediateCodeData, SIZE_T ptrCpuData)
;
PrepareAndCallTheKernel:
;;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;; ret
;;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;; first of all we have to save the registers
;; that we are using localy
push rcx
push rsi
push rdi
push r10
push r11
push rbx
push rbp
push r9
push r8
push r15
;; next save parameters in some indexing registers
mov rsi, rdx ;; rsi pointer to CPU_DATA64 struct
mov rdi, rcx ;; rdi pointer to INTERMEDIATE_CODE_DATA struct
;; save flags
pushfq
pop rax
mov [rsi + CPU_DATA64.EFlags], rax
cli
mov r8, [rdi + INTERMEDIATE_CODE_DATA.start]
mov rcx, [rsi + CPU_DATA64.cpuGuestStateDataAddress]
mov rdx, [rdi + INTERMEDIATE_CODE_DATA.loadedFrom32Bit] ;; use fake tr in this case
push rcx
push r8
sub rsp, 20h ;;make room for callee parameters
call CpustateCaptureGuestState
call start
start:
pop rdx
add rdx, restore_ctx - start
;;sub rsp, 20h
mov rcx, [rsi + CPU_DATA64.cpuGuestStateDataAddress]
call CpustateSetRIP
do_startup:
;; save flags
;; pushfq
;; pop rax
;; mov [rsi + CPU_DATA64.EFlags], rax
;; nobody stops us from now on :D
cli
;; save CPU state (gdtr, idtr, cr3 etc) to CPU_DATA64 structure
lea rax, [rsi + CPU_DATA64.OrigGDTRLimit]
sgdt [rax]
lea rax, [rsi + CPU_DATA64.OrigIDTRLimit]
sidt [rax]
mov rax, cr4
mov [rsi + CPU_DATA64.OrigCr4], rax
mov rax, cr3
mov [rsi + CPU_DATA64.OrigCr3], rax
mov rax, cr0
mov [rsi + CPU_DATA64.OrigCr0], rax
mov rcx, IA32_FS_BASE
rdmsr
shl rdx,32
or rax,rdx
mov [rsi + CPU_DATA64.OrigFSBase], rax
mov rcx, IA32_GS_BASE
rdmsr
shl rdx,32
or rax,rdx
mov [rsi + CPU_DATA64.OrigGSBase], rax
;; save the PAT_MSR
mov rcx, IA32_PAT_BASE
rdmsr
shl rdx,32
or rax, rdx
mov [rsi + CPU_DATA64.PATMsr], rax
[bits 32] ;bits 32 + rsi->edi => same encoding - fool the assembler to avoid 'segment register ignored in 64-bit mode' warnings
mov [esi + CPU_DATA64.OrigCS], cs
mov [esi + CPU_DATA64.OrigDS], ds
mov [esi + CPU_DATA64.OrigES], es
mov [esi + CPU_DATA64.OrigFS], fs
mov [esi + CPU_DATA64.OrigGS], gs
mov [esi + CPU_DATA64.OrigSS], ss
[bits 64]
cmp byte [rdi + INTERMEDIATE_CODE_DATA.loadedFrom32Bit], 1
je load_from_32bit_skip_save_tr
;; save the current tr selector
xor rax, rax
str rax
mov [rsi + CPU_DATA64.OrigTR], ax
mov r10, rax
;; mark the current task as not being busy (see "sys prog guide a" page 257)
mov rax, [rsi + CPU_DATA64.OrigGDTRBase]
shr r10, 3
imul r10, 8 ;; the shr and imul are not needed in this case, written only for clarity
add r10, rax ;; r10 now points to the tss descriptor
mov eax, dword [r10 + 4] ;; eax now contains the 2'nd dword of the tss descriptor
;; need to set bit 9 to 0 (to mark the task as not busy)
and eax, 0FFFFFDFFH
mov dword [r10 + 4], eax ;; and store it in the task descriptor
load_from_32bit_skip_save_tr:
;; switch to our own GDT
lea rax, [rdi + INTERMEDIATE_CODE_DATA.gdtrLimit]
lgdt [rax]
;; switch segment registers to our data / stack segment
mov ax,DATA64_SEL
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
;; update flags in cr0 and cr4
push rbx
mov rax, cr0
or rax, 0000000000010000h ;;CR0.WP (bit 16) = 1
mov rbx, 0xFFFFFFFFFFFFFFF3 ;;EM, TS = 0
and rax, rbx
mov cr0, rax
mov rax, cr4
mov rbx, 0xFFFFFFFFFFFFFB7F ;;PGE = 0, OSXMMEXCPT = 0
mov cr4, rax
pop rbx
;; switch to our code segment
push CODE64_SEL
call $ + 5
add qword [rsp], 7
o64 retf
;; switch to our PML4
xor rax, rax
mov rax, [rdi + INTERMEDIATE_CODE_DATA.intermediatePML4PA]
mov cr3, rax
;; switch to the stack for this cpu
mov rax, rsp
mov rsp, [rsi + CPU_DATA64.cpuStackAddress]
push rax ;;first original rsp
push rsi ;; now address of CPU_DATA64
push rdi ;; address of INTERMEDIATE_CODE_DATA
mov rax, cr3
push rax ;; save our cr3 because kernel entry point will change it
cmp qword [rdi + INTERMEDIATE_CODE_DATA.start], 1
je callKernel
mov rax, 0
mov rbx, 0bdbdbdbdbdbdbdbdh
mov rcx, [rsi + CPU_DATA64.cpuTempUnloadBufferAddress]
mov rdx, [rsi + CPU_DATA64.cpuTempUnloadBufferAddressPA]
vmcall
jmp skip_call_kernel
callKernel:
;; prepare the call into kernel
call label1
label1:
pop rbx
add rbx, (back - label1) ;;address of back (adresa de revenire)
;; loaderBootContext - into RCX
;; entry point - into RAX
mov rcx, qword [rdi + INTERMEDIATE_CODE_DATA.loaderBootContext]
mov rax, [rdi + INTERMEDIATE_CODE_DATA.kernelEntryPoint]
X64ABSCALL_INIT64 rax
back:
;;
;; in RAX we have error code from HV if any
;; we have to preserve this until we can access per cpu data struct
;; and then save it there for further analisys
;; we put this in RBX for now
;;
mov rbx, rax
skip_call_kernel:
pop rax ;; take from stack the saved cr3, which maps both hv (1T - 1T + 4MB) and windows
mov cr3, rax ;; switch to our temporary mappings
pop rdi ;; address of INTERMEDIATE_CODE_DATA
pop rsi ;; address of CPU_DATA64
pop rax ;; restore original stack
mov rsp, rax
;; restore original CR3
xor rax, rax
mov rax, [rsi + CPU_DATA64.OrigCr3]
mov cr3, rax
;; save the status returned by HV on this CPU
;; from now on we can use RBX for whatever else
mov [rsi + CPU_DATA64.Status], rbx
;; restore cr0
xor rax, rax
mov rax, [rsi + CPU_DATA64.OrigCr0]
mov cr0, rax
;; restore cr4
xor rax, rax
mov rax, [rsi + CPU_DATA64.OrigCr4]
mov cr4, rax
;; restore CPU state from CPU_DATA64 structure
lea rax, [rsi + CPU_DATA64.OrigGDTRLimit]
lgdt [rax]
;; restore the original DS
xor rax, rax
mov ax, [rsi + CPU_DATA64.OrigDS]
mov ds, ax
;; restore the original ES
xor rax, rax
mov ax, [rsi + CPU_DATA64.OrigES]
mov es, ax
;; restore the original FS
xor rax, rax
mov ax, [rsi + CPU_DATA64.OrigFS]
mov fs, ax
;; restore the original GS
xor rax, rax
mov ax, [rsi + CPU_DATA64.OrigGS]
mov gs, ax
;; restore the original SS
xor rax, rax
mov ax, [rsi + CPU_DATA64.OrigSS]
mov ss, ax
;; restore the original CS
xor rax, rax
mov ax, [rsi + CPU_DATA64.OrigCS]
push rax
call $ + 5
add qword [rsp], 7
o64 retf
lea rax,[rsi + CPU_DATA64.OrigIDTRLimit]
lidt [rax]
mov rcx, IA32_FS_BASE
mov rax, [rsi + CPU_DATA64.OrigFSBase]
mov rdx, rax
shr rdx, 32
wrmsr
mov rcx, IA32_GS_BASE
mov rax, [rsi + CPU_DATA64.OrigGSBase]
mov rdx, rax
shr rdx, 32
wrmsr
cmp byte [rdi + INTERMEDIATE_CODE_DATA.loadedFrom32Bit], 1
je load_from_32bit_skip_restore_tr
;; restore the tr
xor rax,rax
mov ax, [rsi + CPU_DATA64.OrigTR]
ltr ax
load_from_32bit_skip_restore_tr:
dec QWORD [rsp + 0x20] ; set to 0 the r8 found on stack when unloaded cause of errors
restore_ctx:
add rsp, 20h
pop r8
pop rcx ;; param for CpustateRestoreState
cmp r8, 0x1
je restore_guest_state
mov byte [rcx + CPUSTATE_GUEST_STATE_INFO.UsingFakedTr], 0x01 ;; use fake tr in this case
restore_guest_state:
sub rsp, 20h
call CpustateRestoreGuestState
add rsp, 20h
restore_regs:
;; set interrupts, if needed
bt qword [rsi + CPU_DATA64.EFlags], 9
jnc no_sti1 ;; the IF was 0, we do not need to set it
sti
no_sti1:
mov rax, r10 ;; put the hypervisor return code back into eax
;restore_regs:
pop r15
pop r8
pop r9
pop rbp
pop rbx
pop r11
pop r10
pop rdi
pop rsi
pop rcx
ret
;; add the rest of the code here
%include "kernel\cpu_state_asm.nasm"
|
/**
* Autogenerated by Thrift for src/module.thrift
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
* @generated
*/
#include "thrift/compiler/test/fixtures/basic/gen-cpp2/DbMixedStackArguments.h"
#include "thrift/compiler/test/fixtures/basic/gen-cpp2/DbMixedStackArguments.tcc"
#include "thrift/compiler/test/fixtures/basic/gen-cpp2/module_metadata.h"
#include <thrift/lib/cpp2/gen/service_cpp.h>
namespace cpp2 {
std::unique_ptr<apache::thrift::AsyncProcessor> DbMixedStackArgumentsSvIf::getProcessor() {
return std::make_unique<DbMixedStackArgumentsAsyncProcessor>(this);
}
void DbMixedStackArgumentsSvIf::getDataByKey0(::std::string& /*_return*/, std::unique_ptr<::std::string> /*key*/) {
apache::thrift::detail::si::throw_app_exn_unimplemented("getDataByKey0");
}
folly::SemiFuture<std::unique_ptr<::std::string>> DbMixedStackArgumentsSvIf::semifuture_getDataByKey0(std::unique_ptr<::std::string> p_key) {
auto expected{apache::thrift::detail::si::InvocationType::SemiFuture};
__fbthrift_invocation_getDataByKey0.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::Sync, std::memory_order_relaxed);
auto ret = std::make_unique<::std::string>();
getDataByKey0(*ret, std::move(p_key));
return folly::makeSemiFuture(std::move(ret));
}
folly::Future<std::unique_ptr<::std::string>> DbMixedStackArgumentsSvIf::future_getDataByKey0(std::unique_ptr<::std::string> p_key) {
auto expected{apache::thrift::detail::si::InvocationType::Future};
__fbthrift_invocation_getDataByKey0.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::SemiFuture, std::memory_order_relaxed);
return apache::thrift::detail::si::future(semifuture_getDataByKey0(std::move(p_key)), getInternalKeepAlive());
}
void DbMixedStackArgumentsSvIf::async_tm_getDataByKey0(std::unique_ptr<apache::thrift::HandlerCallback<std::unique_ptr<::std::string>>> callback, std::unique_ptr<::std::string> p_key) {
// It's possible the coroutine versions will delegate to a future-based
// version. If that happens, we need the RequestParams arguments to be
// available to the future through the thread-local backchannel, so we set that up
// for all cases.
apache::thrift::detail::si::async_tm_prep(this, callback.get());
auto invocationType = __fbthrift_invocation_getDataByKey0.load(std::memory_order_relaxed);
try {
switch (invocationType) {
case apache::thrift::detail::si::InvocationType::AsyncTm:
{
__fbthrift_invocation_getDataByKey0.compare_exchange_strong(invocationType, apache::thrift::detail::si::InvocationType::Future, std::memory_order_relaxed);
FOLLY_FALLTHROUGH;
}
case apache::thrift::detail::si::InvocationType::Future:
{
auto fut = future_getDataByKey0(std::move(p_key));
apache::thrift::detail::si::async_tm_future(std::move(callback), std::move(fut));
return;
}
case apache::thrift::detail::si::InvocationType::SemiFuture:
{
auto fut = semifuture_getDataByKey0(std::move(p_key));
apache::thrift::detail::si::async_tm_semifuture(std::move(callback), std::move(fut));
return;
}
case apache::thrift::detail::si::InvocationType::Sync:
{
::std::string _return;
getDataByKey0(_return, std::move(p_key));
callback->result(_return);
return;
}
default:
{
folly::assume_unreachable();
}
}
} catch (...) {
callback->exception(std::current_exception());
}
}
void DbMixedStackArgumentsSvIf::getDataByKey1(::std::string& /*_return*/, std::unique_ptr<::std::string> /*key*/) {
apache::thrift::detail::si::throw_app_exn_unimplemented("getDataByKey1");
}
folly::SemiFuture<std::unique_ptr<::std::string>> DbMixedStackArgumentsSvIf::semifuture_getDataByKey1(std::unique_ptr<::std::string> p_key) {
auto expected{apache::thrift::detail::si::InvocationType::SemiFuture};
__fbthrift_invocation_getDataByKey1.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::Sync, std::memory_order_relaxed);
auto ret = std::make_unique<::std::string>();
getDataByKey1(*ret, std::move(p_key));
return folly::makeSemiFuture(std::move(ret));
}
folly::Future<std::unique_ptr<::std::string>> DbMixedStackArgumentsSvIf::future_getDataByKey1(std::unique_ptr<::std::string> p_key) {
auto expected{apache::thrift::detail::si::InvocationType::Future};
__fbthrift_invocation_getDataByKey1.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::SemiFuture, std::memory_order_relaxed);
return apache::thrift::detail::si::future(semifuture_getDataByKey1(std::move(p_key)), getInternalKeepAlive());
}
void DbMixedStackArgumentsSvIf::async_tm_getDataByKey1(std::unique_ptr<apache::thrift::HandlerCallback<std::unique_ptr<::std::string>>> callback, std::unique_ptr<::std::string> p_key) {
// It's possible the coroutine versions will delegate to a future-based
// version. If that happens, we need the RequestParams arguments to be
// available to the future through the thread-local backchannel, so we set that up
// for all cases.
apache::thrift::detail::si::async_tm_prep(this, callback.get());
auto invocationType = __fbthrift_invocation_getDataByKey1.load(std::memory_order_relaxed);
try {
switch (invocationType) {
case apache::thrift::detail::si::InvocationType::AsyncTm:
{
__fbthrift_invocation_getDataByKey1.compare_exchange_strong(invocationType, apache::thrift::detail::si::InvocationType::Future, std::memory_order_relaxed);
FOLLY_FALLTHROUGH;
}
case apache::thrift::detail::si::InvocationType::Future:
{
auto fut = future_getDataByKey1(std::move(p_key));
apache::thrift::detail::si::async_tm_future(std::move(callback), std::move(fut));
return;
}
case apache::thrift::detail::si::InvocationType::SemiFuture:
{
auto fut = semifuture_getDataByKey1(std::move(p_key));
apache::thrift::detail::si::async_tm_semifuture(std::move(callback), std::move(fut));
return;
}
case apache::thrift::detail::si::InvocationType::Sync:
{
::std::string _return;
getDataByKey1(_return, std::move(p_key));
callback->result(_return);
return;
}
default:
{
folly::assume_unreachable();
}
}
} catch (...) {
callback->exception(std::current_exception());
}
}
void DbMixedStackArgumentsSvNull::getDataByKey0(::std::string& /*_return*/, std::unique_ptr<::std::string> /*key*/) {}
void DbMixedStackArgumentsSvNull::getDataByKey1(::std::string& /*_return*/, std::unique_ptr<::std::string> /*key*/) {}
const char* DbMixedStackArgumentsAsyncProcessor::getServiceName() {
return "DbMixedStackArguments";
}
void DbMixedStackArgumentsAsyncProcessor::getServiceMetadata(apache::thrift::metadata::ThriftServiceMetadataResponse& response) {
::apache::thrift::detail::md::ServiceMetadata<DbMixedStackArgumentsSvIf>::gen(*response.metadata_ref(), *response.context_ref());
}
void DbMixedStackArgumentsAsyncProcessor::processSerializedCompressedRequest(apache::thrift::ResponseChannelRequest::UniquePtr req, apache::thrift::SerializedCompressedRequest&& serializedRequest, apache::thrift::protocol::PROTOCOL_TYPES protType, apache::thrift::Cpp2RequestContext* context, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) {
apache::thrift::detail::ap::process(this, std::move(req), std::move(serializedRequest), protType, context, eb, tm);
}
std::shared_ptr<folly::RequestContext> DbMixedStackArgumentsAsyncProcessor::getBaseContextForRequest() {
return iface_->getBaseContextForRequest();
}
const DbMixedStackArgumentsAsyncProcessor::ProcessMap& DbMixedStackArgumentsAsyncProcessor::getBinaryProtocolProcessMap() {
return binaryProcessMap_;
}
const DbMixedStackArgumentsAsyncProcessor::ProcessMap DbMixedStackArgumentsAsyncProcessor::binaryProcessMap_ {
{"getDataByKey0", &DbMixedStackArgumentsAsyncProcessor::setUpAndProcess_getDataByKey0<apache::thrift::BinaryProtocolReader, apache::thrift::BinaryProtocolWriter>},
{"getDataByKey1", &DbMixedStackArgumentsAsyncProcessor::setUpAndProcess_getDataByKey1<apache::thrift::BinaryProtocolReader, apache::thrift::BinaryProtocolWriter>},
};
const DbMixedStackArgumentsAsyncProcessor::ProcessMap& DbMixedStackArgumentsAsyncProcessor::getCompactProtocolProcessMap() {
return compactProcessMap_;
}
const DbMixedStackArgumentsAsyncProcessor::ProcessMap DbMixedStackArgumentsAsyncProcessor::compactProcessMap_ {
{"getDataByKey0", &DbMixedStackArgumentsAsyncProcessor::setUpAndProcess_getDataByKey0<apache::thrift::CompactProtocolReader, apache::thrift::CompactProtocolWriter>},
{"getDataByKey1", &DbMixedStackArgumentsAsyncProcessor::setUpAndProcess_getDataByKey1<apache::thrift::CompactProtocolReader, apache::thrift::CompactProtocolWriter>},
};
} // cpp2
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %r9
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0x1a70f, %rsi
lea addresses_normal_ht+0x18c5d, %rdi
nop
nop
nop
nop
cmp %r12, %r12
mov $25, %rcx
rep movsb
xor %rbx, %rbx
lea addresses_WC_ht+0x4d0f, %rbx
clflush (%rbx)
nop
nop
nop
nop
nop
add $18040, %rbp
movb (%rbx), %r9b
nop
nop
add $50791, %r9
lea addresses_WC_ht+0x138ff, %rsi
nop
and %rbp, %rbp
mov (%rsi), %r12
xor %rbx, %rbx
lea addresses_A_ht+0x12e7f, %rdi
nop
nop
nop
nop
nop
add %rsi, %rsi
mov (%rdi), %r9w
nop
sub %rcx, %rcx
lea addresses_UC_ht+0x9f0f, %rsi
lea addresses_WC_ht+0x14217, %rdi
clflush (%rsi)
clflush (%rdi)
xor $17569, %rbp
mov $50, %rcx
rep movsw
and $35398, %rdi
lea addresses_A_ht+0x1170f, %rsi
lea addresses_normal_ht+0x19b0f, %rdi
and $56029, %r9
mov $44, %rcx
rep movsw
nop
inc %r9
lea addresses_UC_ht+0xc40f, %rbx
nop
add %r12, %r12
movb (%rbx), %r9b
nop
nop
nop
sub %rdi, %rdi
lea addresses_WC_ht+0x8bc7, %r9
lfence
mov (%r9), %edi
nop
nop
nop
add %r12, %r12
lea addresses_WC_ht+0xa70f, %rbp
sub $29006, %rbx
movb (%rbp), %r9b
nop
dec %rbp
lea addresses_D_ht+0x18c43, %rsi
lea addresses_A_ht+0x9f0f, %rdi
nop
nop
nop
sub $28242, %r11
mov $57, %rcx
rep movsb
nop
nop
nop
nop
add $36211, %r12
lea addresses_D_ht+0x860f, %rsi
lea addresses_WC_ht+0xed1d, %rdi
nop
xor $3337, %r12
mov $17, %rcx
rep movsb
and %rcx, %rcx
lea addresses_D_ht+0xe6df, %rcx
nop
nop
nop
nop
nop
xor $50155, %rbx
movb $0x61, (%rcx)
nop
nop
nop
nop
sub $54331, %rdi
lea addresses_D_ht+0x3c8f, %rsi
lea addresses_WC_ht+0x124f7, %rdi
nop
nop
nop
cmp $31037, %r12
mov $2, %rcx
rep movsw
cmp %r9, %r9
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r9
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r12
push %r13
push %r15
push %rax
push %rbx
push %rcx
// Store
mov $0xf08, %rax
nop
nop
nop
nop
nop
add $63307, %rcx
mov $0x5152535455565758, %rbx
movq %rbx, %xmm3
movups %xmm3, (%rax)
dec %rcx
// Store
lea addresses_PSE+0xdf0f, %r15
nop
nop
xor $32780, %rcx
mov $0x5152535455565758, %r13
movq %r13, %xmm3
vmovups %ymm3, (%r15)
nop
nop
nop
nop
cmp %r12, %r12
// Load
mov $0x41b24f000000018f, %rax
nop
nop
nop
nop
and %r10, %r10
movups (%rax), %xmm1
vpextrq $1, %xmm1, %r13
nop
nop
nop
nop
add $740, %rax
// Store
lea addresses_normal+0x8f0f, %r12
nop
nop
nop
nop
nop
inc %r15
movw $0x5152, (%r12)
xor $739, %rcx
// Store
lea addresses_WT+0x1c70f, %rcx
nop
nop
nop
nop
nop
dec %r15
mov $0x5152535455565758, %r10
movq %r10, %xmm0
vmovups %ymm0, (%rcx)
nop
nop
nop
add $15058, %r10
// Faulty Load
lea addresses_PSE+0xdf0f, %r15
nop
nop
nop
xor %rbx, %rbx
movaps (%r15), %xmm5
vpextrq $1, %xmm5, %r10
lea oracles, %rbx
and $0xff, %r10
shlq $12, %r10
mov (%rbx,%r10,1), %r10
pop %rcx
pop %rbx
pop %rax
pop %r15
pop %r13
pop %r12
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_PSE', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_P', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'same': True, 'type': 'addresses_PSE', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 0}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_NC', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 6}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_normal', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 11}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_WT', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 11}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_PSE', 'NT': False, 'AVXalign': True, 'size': 16, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'same': True, 'congruent': 10, 'type': 'addresses_D_ht'}, 'dst': {'same': False, 'congruent': 1, 'type': 'addresses_normal_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 8}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 4}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 4}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 11, 'type': 'addresses_UC_ht'}, 'dst': {'same': False, 'congruent': 3, 'type': 'addresses_WC_ht'}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 10, 'type': 'addresses_A_ht'}, 'dst': {'same': False, 'congruent': 7, 'type': 'addresses_normal_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_UC_ht', 'NT': True, 'AVXalign': False, 'size': 1, 'congruent': 6}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 3}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 11}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 1, 'type': 'addresses_D_ht'}, 'dst': {'same': False, 'congruent': 11, 'type': 'addresses_A_ht'}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 7, 'type': 'addresses_D_ht'}, 'dst': {'same': False, 'congruent': 1, 'type': 'addresses_WC_ht'}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_D_ht', 'NT': False, 'AVXalign': True, 'size': 1, 'congruent': 4}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 7, 'type': 'addresses_D_ht'}, 'dst': {'same': False, 'congruent': 3, 'type': 'addresses_WC_ht'}}
{'46': 906, '00': 20917, '45': 5, '08': 1}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 46 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 46 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 46 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 46 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 00 00 00 00 00
*/
|
; A133647: A133566 * A000244.
; 1,3,12,27,108,243,972,2187,8748,19683,78732,177147,708588,1594323,6377292,14348907,57395628,129140163,516560652,1162261467,4649045868,10460353203,41841412812,94143178827,376572715308,847288609443,3389154437772,7625597484987,30502389939948,68630377364883,274521509459532,617673396283947,2470693585135788,5559060566555523,22236242266222092,50031545098999707,200126180395998828,450283905890997363,1801135623563989452,4052555153018976267,16210220612075905068,36472996377170786403,145891985508683145612
mov $1,3
pow $1,$0
gcd $0,2
add $0,2
mul $0,$1
div $0,3
|
; 1 2 3 4 5 6 7
;234567890123456789012345678901234567890123456789012345678901234567890
;=====================================================================
;
; *** TEST ***
;
;---------------------------------------------------------------------
;
; AUTHOR: Nik Mohamad Aizuddin bin Nik Azmi
; EMAIL: nickaizuddin93@gmail.com
; DATE CREATED: 13-APR-2015
;
; TEST PURPOSE: Make sure the vec_max_absvalue()
; have no defects.
;
; LANGUAGE: x86 Assembly Language
; ASSEMBLER: NASM
; SYNTAX: Intel
; ARCHITECTURE: x86_64
; KERNEL: Linux x86
; FORMAT: elf32
;
; EXTERNAL FILES: ---
;
;=====================================================================
;Include constant symbols and global variables
%include "include/constants.inc"
%include "include/data.inc"
extern vec_max_absvalue
global _start
section .text
_start:
;B = max( abs(A[:,2]) )
lea eax, [A]
mov ebx, 0b1
mov ecx, 2
call vec_max_absvalue
movss [B], xmm0
;C = max( abs(A[0,:]) )
lea eax, [A]
mov ebx, 0b0
mov ecx, 0
call vec_max_absvalue
movss [C], xmm0
exit:
mov eax, SYSCALL_EXIT
mov ebx, 0
int 0x80
|
; A144328: A002260 preceded by a column of 1's: a (1, 1, 2, 3, 4, 5,...) crescendo triangle by rows.
; Submitted by Christian Krause
; 1,1,1,1,1,2,1,1,2,3,1,1,2,3,4,1,1,2,3,4,5,1,1,2,3,4,5,6,1,1,2,3,4,5,6,7,1,1,2,3,4,5,6,7,8,1,1,2,3,4,5,6,7,8,9,1,1,2,3,4,5,6,7,8,9,10,1,1,2,3,4,5,6,7,8,9,10,11,1,1,2,3,4,5,6,7,8,9,10,11,12,1,1,2,3,4,5,6,7,8
seq $0,25675 ; Exponent of 8 (value of j) in n-th number of form 7^i*8^j.
mul $0,1977326743
div $0,1977326753
add $0,1
|
/* --------------------------------------------------------------------------
*
* ETK++ --- The Easy Toolkit for C++ programing
* Copyright (C) 2004-2006, Anthony Lee, All Rights Reserved
*
* ETK++ library is a freeware; it may be used and distributed according to
* the terms of The MIT License.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* File: Render-SDL.cpp
*
* --------------------------------------------------------------------------*/
#include <stdlib.h>
#include <SDL.h>
#include <etkxx.h>
#define VIDEO_XRES 640
#define VIDEO_YRES 480
#define VIDEO_DEPTH 32
#define REFRESH_INTERVAL 5000
// the user EMessage::what shouldn't contains any upper character or "_"
#define START_REFRESH_MSG 'ssrm'
#define STOP_REFRESH_MSG 'strm'
#define COUNT_MSG 'cout'
#define BTN_FILL_RECTS_MSG 'btn1'
#define BTN_STROKE_POINTS_MSG 'btn2'
#define BTN_STROKE_LINES_MSG 'btn3'
#define BTN_STROKE_ELLIPSES_MSG 'btn4'
#define BTN_FILL_ELLIPSES_MSG 'btn5'
#define BTN_STROKE_ARCS_MSG 'btn6'
#define BTN_FILL_TRIANGLES_MSG 'btn7'
#define BTN_STROKE_POLYGONS_MSG 'btn8'
#define BTN_FILL_POLYGONS_MSG 'btn9'
#ifdef ETK_OS_WIN32
#define random() rand()
#endif // ETK_OS_WIN32
#ifdef ETK_THREAD_IMPL_WIN32
// in order to wake up other thread, like GUI or refreshing-cycle of SDL
#define SNOOZE() (void)(e_snooze(0))
#else
#define SNOOZE() (void)0
#endif
#ifdef ETK_OS_BEOS
// SDL use BApplication on BeOS, the built-in graphics-engine of ETK++ also use BApplication.
// So we spawn the SDL task before ETK++ initalized in order to use BWindow task in ETK++,
// but the application still be blocked when quit, thus should be fixed yet...
//
// If you use another graphics-engine (X11,etc.) of ETK++, comment the line below.
#define RUN_SDL_TASK_FIRST
#endif // ETK_OS_BEOS
EMessenger msgrDrawing;
class TRender : public ERender {
public:
TRender(ELooper *looper);
void StartFresh() {etk_app->PostMessage(START_REFRESH_MSG);}
void StopFresh() {etk_app->PostMessage(STOP_REFRESH_MSG);}
void testFillRects(eint32 count);
void testStrokePoints();
void testStrokeLines(eint32 count);
void testStrokeEllipses(eint32 count);
void testFillEllipses(eint32 count);
void testStrokeArcs(eint32 count);
void testFillTriangles(eint32 count);
void testStrokePolygons(eint32 count);
void testFillPolygons(eint32 count);
private:
e_status_t fStatus;
SDL_Surface *fScreen;
ELooper *fLooper;
virtual e_status_t InitCheck() const;
virtual void GetFrame(eint32 *originX, eint32 *originY, euint32 *width, euint32 *height) const;
virtual void GetPixel(eint32 x, eint32 y, e_rgb_color &color) const;
virtual void PutPixel(eint32 x, eint32 y, e_rgb_color color);
virtual void PutRect(eint32 x, eint32 y, euint32 width, euint32 height, e_rgb_color color);
};
class TDrawingLooper : public ELooper {
public:
TDrawingLooper();
virtual ~TDrawingLooper();
virtual void MessageReceived(EMessage *msg);
private:
TRender *fRender;
eint32 fCount;
};
class TWindow : public EWindow {
public:
TWindow();
virtual void MessageReceived(EMessage *msg);
};
class TApplication : public EApplication {
public:
#ifndef RUN_SDL_TASK_FIRST
TApplication();
#else
TApplication(void *thread);
#endif
virtual ~TApplication();
virtual void ReadyToRun();
virtual bool QuitRequested();
virtual void Pulse();
virtual void MessageReceived(EMessage *msg);
private:
friend class TRender;
void *fSDLThread;
};
TRender::TRender(ELooper *looper)
: ERender(), fScreen(NULL), fLooper(NULL), fStatus(E_NO_INIT)
{
while((fScreen = SDL_GetVideoSurface()) == NULL)
{
if(etk_get_thread_run_state(((TApplication*)etk_app)->fSDLThread) != ETK_THREAD_RUNNING)
{
etk_app->PostMessage(E_QUIT_REQUESTED);
return;
}
e_snooze(1000);
}
fLooper = looper;
fStatus = ((fScreen == NULL || fLooper == NULL) ? E_NO_INIT : E_OK);
}
e_status_t
TRender::InitCheck() const
{
if(fStatus != E_OK) return fStatus;
if(fScreen == NULL) return E_ERROR;
return E_OK;
}
void
TRender::GetFrame(eint32 *originX, eint32 *originY, euint32 *width, euint32 *height) const
{
if(originX) *originX = 0;
if(originY) *originY = 0;
if(width) *width = VIDEO_XRES;
if(height) *height = VIDEO_YRES;
}
void
TRender::GetPixel(eint32 x, eint32 y, e_rgb_color &color) const
{
if(fScreen == NULL || SDL_LockSurface(fScreen) < 0) return;
Uint32 sdlColor = 0;
Uint8 *p = (Uint8*)fScreen->pixels + y * fScreen->pitch + x * fScreen->format->BytesPerPixel;
switch(fScreen->format->BytesPerPixel)
{
case 1: // 8-bpp
sdlColor = *p;
break;
case 2: // 15-bpp or 16-bpp
sdlColor = *((Uint16*)p);
break;
case 3: // 24-bpp
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
sdlColor = (p[0] << 16) | (p[1] << 8) | p[2];
else
sdlColor = p[0] | (p[1] << 8) | (p[2] << 16);
break;
case 4: // 32-bpp
sdlColor = *((Uint32*)p);
break;
default: break;
}
SDL_GetRGB(sdlColor, fScreen->format, &(color.red), &(color.green), &(color.blue));
SDL_UnlockSurface(fScreen);
}
void
TRender::PutPixel(eint32 x, eint32 y, e_rgb_color color)
{
if(fScreen == NULL || SDL_LockSurface(fScreen) < 0) return;
Uint32 sdlColor = SDL_MapRGB(fScreen->format, color.red, color.green, color.blue);
Uint8 *p = (Uint8*)fScreen->pixels + y * fScreen->pitch + x * fScreen->format->BytesPerPixel;
switch(fScreen->format->BytesPerPixel)
{
case 1: // 8-bpp
*p = sdlColor;
break;
case 2: // 15-bpp or 16-bpp
*((Uint16*)p) = sdlColor;
break;
case 3: // 24-bpp
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
{
p[0] = (sdlColor >> 16) & 0xff;
p[1] = (sdlColor >> 8) & 0xff;
p[2] = sdlColor & 0xff;
}
else
{
p[0] = sdlColor & 0xff;
p[1] = (sdlColor >> 8) & 0xff;
p[2] = (sdlColor >> 16) & 0xff;
}
break;
case 4: // 32-bpp
*((Uint32*)p) = sdlColor;
break;
default: break;
}
SDL_UnlockSurface(fScreen);
}
void
TRender::PutRect(eint32 x, eint32 y, euint32 width, euint32 height, e_rgb_color color)
{
if(fScreen == NULL || width == 0 || height == 0 ||
x > E_MAXINT16 || y > E_MAXINT16 || width >= E_MAXUINT16 || height >= E_MAXUINT16 ||
SDL_LockSurface(fScreen) < 0) return;
Uint32 sdlColor = SDL_MapRGB(fScreen->format, color.red, color.green, color.blue);
SDL_UnlockSurface(fScreen);
SDL_Rect sdlRect;
sdlRect.x = (Sint16)x;
sdlRect.y = (Sint16)y;
sdlRect.w = (Uint16)width;
sdlRect.h = (Uint16)height;
SDL_FillRect(fScreen, &sdlRect, sdlColor);
}
void
TRender::testFillRects(eint32 count)
{
#if 1
SetDrawingMode(E_OP_COPY);
SetHighColor(0, 0, 0);
FillRect(0, 0, VIDEO_XRES, VIDEO_YRES);
#else
SetDrawingMode(E_OP_ALPHA);
#endif
StartFresh();
for(eint32 i = 0; i < count; i++)
{
eint32 x = random() % VIDEO_XRES;
eint32 y = random() % VIDEO_YRES;
SetHighColor(x & 0xff, y & 0xff, (x * y) & 0xff, x & 0xff);
FillRect(x, y, VIDEO_XRES - min_c(2 * x, VIDEO_XRES), VIDEO_YRES - min_c(2 * y, VIDEO_YRES));
SNOOZE(); // for user could interrupt this
if(!fLooper) continue;
if(fLooper->MessageQueue()->IsEmpty() == false) break;
}
StopFresh();
}
void
TRender::testStrokePoints()
{
euint8 alpha = 128;
SetDrawingMode(alpha < 255 ? E_OP_ALPHA : E_OP_COPY);
StartFresh();
for(eint32 y = 0; y < VIDEO_YRES; y++)
{
for(eint32 x = 0; x < 128; x++)
{
SetHighColor(x << 1, 0, 0, alpha);
StrokePoint(x, y);
SetHighColor(0, x << 1, 0, alpha);
StrokePoint(128 + x, y);
if(128 * 2 + x >= VIDEO_XRES) continue;
SetHighColor(0, 0, x << 1, alpha);
StrokePoint(128 * 2 + x, y);
if(128 * 3 + x >= VIDEO_XRES) continue;
SetHighColor(x << 1, x << 1, 0, alpha);
StrokePoint(128 * 3 + x, y);
if(128 * 4 + x >= VIDEO_XRES) continue;
SetHighColor(x << 1, 0, x << 1, alpha);
StrokePoint(128 * 4 + x, y);
if(128 * 5 + x >= VIDEO_XRES) continue;
SetHighColor(0, x << 1, x << 1, alpha);
StrokePoint(128 * 5 + x, y);
if(128 * 6 + x >= VIDEO_XRES) continue;
SetHighColor(x << 1, x << 1, x << 1, alpha);
StrokePoint(128 * 6 + x, y);
}
if(!fLooper) continue;
if(fLooper->MessageQueue()->IsEmpty() == false) break;
}
StopFresh();
}
void
TRender::testStrokeLines(eint32 count)
{
#if 1
SetDrawingMode(E_OP_COPY);
SetHighColor(0, 0, 0);
FillRect(0, 0, VIDEO_XRES, VIDEO_YRES);
#else
SetDrawingMode(E_OP_ALPHA);
#endif
StartFresh();
for(eint32 i = 0; i < count; i++)
{
eint32 x = random() % VIDEO_XRES;
eint32 y = random() % VIDEO_YRES;
SetHighColor(x & 0xff, y & 0xff, (x * y) & 0xff, x & 0xff);
StrokeLine(x, y, VIDEO_XRES - x - 1, VIDEO_YRES - y - 1);
SNOOZE(); // for user could interrupt this
if(!fLooper) continue;
if(fLooper->MessageQueue()->IsEmpty() == false) break;
}
StopFresh();
}
void
TRender::testStrokeEllipses(eint32 count)
{
#if 1
SetDrawingMode(E_OP_COPY);
SetHighColor(0, 0, 0);
FillRect(0, 0, VIDEO_XRES, VIDEO_YRES);
#else
SetDrawingMode(E_OP_ALPHA);
#endif
StartFresh();
for(eint32 i = 0; i < count; i++)
{
eint32 x = random() % VIDEO_XRES;
eint32 y = random() % VIDEO_YRES;
eint32 xr = x % 120;
eint32 yr = y % 120;
SetHighColor(x & 0xff, y & 0xff, (x * y) & 0xff, x & 0xff);
StrokeEllipse(x, y, xr, yr);
SNOOZE(); // for user could interrupt this
if(!fLooper) continue;
if(fLooper->MessageQueue()->IsEmpty() == false) break;
}
StopFresh();
}
void
TRender::testFillEllipses(eint32 count)
{
#if 1
SetDrawingMode(E_OP_COPY);
SetHighColor(0, 0, 0);
FillRect(0, 0, VIDEO_XRES, VIDEO_YRES);
#else
SetDrawingMode(E_OP_ALPHA);
#endif
StartFresh();
for(eint32 i = 0; i < count; i++)
{
eint32 x = random() % VIDEO_XRES;
eint32 y = random() % VIDEO_YRES;
eint32 xr = x % 120;
eint32 yr = y % 120;
SetHighColor(x & 0xff, y & 0xff, (x * y) & 0xff, x & 0xff);
FillEllipse(x, y, xr, yr);
SNOOZE(); // for user could interrupt this
if(!fLooper) continue;
if(fLooper->MessageQueue()->IsEmpty() == false) break;
}
StopFresh();
}
void
TRender::testStrokeArcs(eint32 count)
{
#if 1
SetDrawingMode(E_OP_COPY);
SetHighColor(0, 0, 0);
FillRect(0, 0, VIDEO_XRES, VIDEO_YRES);
#else
SetDrawingMode(E_OP_ALPHA);
#endif
StartFresh();
for(eint32 i = 0; i < count; i++)
{
eint32 x = random() % VIDEO_XRES;
eint32 y = random() % VIDEO_YRES;
eint32 xr = x % 120;
eint32 yr = y % 120;
SetHighColor(x & 0xff, y & 0xff, (x * y) & 0xff, x & 0xff);
StrokeArc(ERect(x, y, x + xr, y + yr), (x + y) % 360, (x - y) % 360);
SNOOZE(); // for user could interrupt this
if(!fLooper) continue;
if(fLooper->MessageQueue()->IsEmpty() == false) break;
}
StopFresh();
}
void
TRender::testFillTriangles(eint32 count)
{
#if 1
SetDrawingMode(E_OP_COPY);
SetHighColor(0, 0, 0);
FillRect(0, 0, VIDEO_XRES, VIDEO_YRES);
#else
SetDrawingMode(E_OP_ALPHA);
#endif
StartFresh();
for(eint32 i = 0; i < count; i++)
{
eint32 x0 = random() % VIDEO_XRES;
eint32 y0 = random() % VIDEO_YRES;
eint32 x1 = random() % VIDEO_XRES;
eint32 y1 = random() % VIDEO_YRES;
eint32 x2 = random() % VIDEO_XRES;
eint32 y2 = random() % VIDEO_YRES;
SetHighColor(x0 & 0xff, y0 & 0xff, x1 & 0xff, y1 & 0xff);
FillTriangle(x0, y0, x1, y1, x2, y2);
SNOOZE(); // for user could interrupt this
if(!fLooper) continue;
if(fLooper->MessageQueue()->IsEmpty() == false) break;
}
StopFresh();
}
void
TRender::testStrokePolygons(eint32 count)
{
#if 1
SetDrawingMode(E_OP_COPY);
SetHighColor(0, 0, 0);
FillRect(0, 0, VIDEO_XRES, VIDEO_YRES);
#else
SetDrawingMode(E_OP_ALPHA);
#endif
StartFresh();
for(eint32 i = 0; i < count; i++)
{
eint32 numPts = max_c(random() % 15, 3);
EPolygon aPolygon;
EPoint pt;
for(eint32 k = 0; k < numPts; k++)
{
eint32 x = random() % VIDEO_XRES;
eint32 y = random() % VIDEO_YRES;
pt.Set((float)x + 0.5f, (float)y + 0.5f);
aPolygon.AddPoints(&pt, 1);
}
SetHighColor((eint32)pt.x & 0xff, (eint32)pt.y & 0xff, numPts << 5, (eint32)pt.y & 0xff);
StrokePolygon(&aPolygon);
SNOOZE(); // for user could interrupt this
if(!fLooper) continue;
if(fLooper->MessageQueue()->IsEmpty() == false) break;
}
StopFresh();
}
void
TRender::testFillPolygons(eint32 count)
{
#if 1
SetDrawingMode(E_OP_COPY);
SetHighColor(0, 0, 0);
FillRect(0, 0, VIDEO_XRES, VIDEO_YRES);
#else
SetDrawingMode(E_OP_ALPHA);
#endif
StartFresh();
for(eint32 i = 0; i < count; i++)
{
eint32 numPts = max_c(random() % 15, 3);
EPolygon aPolygon;
EPoint pt;
for(eint32 k = 0; k < numPts; k++)
{
eint32 x = random() % VIDEO_XRES;
eint32 y = random() % VIDEO_YRES;
pt.Set((float)x + 0.5f, (float)y + 0.5f);
aPolygon.AddPoints(&pt, 1);
}
SetHighColor((eint32)pt.x & 0xff, (eint32)pt.y & 0xff, numPts << 5, (eint32)pt.y & 0xff);
FillPolygon(&aPolygon);
SNOOZE(); // for user could interrupt this
if(!fLooper) continue;
if(fLooper->MessageQueue()->IsEmpty() == false) break;
}
StopFresh();
}
TDrawingLooper::TDrawingLooper()
: ELooper(), fCount(2500)
{
fRender = new TRender(this);
}
TDrawingLooper::~TDrawingLooper()
{
if(fRender) delete fRender;
}
void
TDrawingLooper::MessageReceived(EMessage *msg)
{
if(!fRender) return;
if(msg->what == COUNT_MSG)
{
msg->FindInt32("count", &fCount);
return;
}
if(fCount <= 0) return;
if(msg->what == BTN_STROKE_POINTS_MSG) fRender->testStrokePoints();
else if(msg->what == BTN_STROKE_LINES_MSG) fRender->testStrokeLines(fCount);
else if(msg->what == BTN_STROKE_ELLIPSES_MSG) fRender->testStrokeEllipses(fCount);
else if(msg->what == BTN_FILL_ELLIPSES_MSG) fRender->testFillEllipses(fCount);
else if(msg->what == BTN_STROKE_ARCS_MSG) fRender->testStrokeArcs(fCount);
else if(msg->what == BTN_FILL_RECTS_MSG) fRender->testFillRects(fCount);
else if(msg->what == BTN_FILL_TRIANGLES_MSG) fRender->testFillTriangles(fCount);
else if(msg->what == BTN_STROKE_POLYGONS_MSG) fRender->testStrokePolygons(fCount);
else if(msg->what == BTN_FILL_POLYGONS_MSG) fRender->testFillPolygons(fCount);
}
TWindow::TWindow()
: EWindow(ERect(300, 100, 600, 600), "ERender Sample", E_TITLED_WINDOW, E_QUIT_ON_WINDOW_CLOSE)
{
ETextControl *tctrl = new ETextControl(ERect(50, 5, 250, 25), NULL, "Count: ", "2500", NULL);
tctrl->SetModificationMessage(new EMessage(COUNT_MSG));
tctrl->ResizeToPreferred();
AddChild(tctrl);
ERect rect(50, 40, 250, 70);
EButton *btn = new EButton(rect, NULL, "Fill Rectangles", new EMessage(BTN_FILL_RECTS_MSG));
btn->SetTarget(msgrDrawing);
AddChild(btn);
rect.OffsetBy(0, 50);
btn = new EButton(rect, NULL, "Stroke Points", new EMessage(BTN_STROKE_POINTS_MSG));
btn->SetTarget(msgrDrawing);
AddChild(btn);
rect.OffsetBy(0, 50);
btn = new EButton(rect, NULL, "Stroke Lines", new EMessage(BTN_STROKE_LINES_MSG));
btn->SetTarget(msgrDrawing);
AddChild(btn);
rect.OffsetBy(0, 50);
btn = new EButton(rect, NULL, "Stroke Ellipses", new EMessage(BTN_STROKE_ELLIPSES_MSG));
btn->SetTarget(msgrDrawing);
AddChild(btn);
rect.OffsetBy(0, 50);
btn = new EButton(rect, NULL, "Fill Ellipses", new EMessage(BTN_FILL_ELLIPSES_MSG));
btn->SetTarget(msgrDrawing);
AddChild(btn);
rect.OffsetBy(0, 50);
btn = new EButton(rect, NULL, "Stroke Arcs", new EMessage(BTN_STROKE_ARCS_MSG));
btn->SetTarget(msgrDrawing);
AddChild(btn);
rect.OffsetBy(0, 50);
btn = new EButton(rect, NULL, "Fill Triangles", new EMessage(BTN_FILL_TRIANGLES_MSG));
btn->SetTarget(msgrDrawing);
AddChild(btn);
rect.OffsetBy(0, 50);
btn = new EButton(rect, NULL, "Stroke Polygons", new EMessage(BTN_STROKE_POLYGONS_MSG));
btn->SetTarget(msgrDrawing);
AddChild(btn);
rect.OffsetBy(0, 50);
btn = new EButton(rect, NULL, "Fill Polygons", new EMessage(BTN_FILL_POLYGONS_MSG));
btn->SetTarget(msgrDrawing);
AddChild(btn);
}
void
TWindow::MessageReceived(EMessage *msg)
{
if(msg->what == COUNT_MSG)
{
ETextControl *tctrl = NULL;
msg->FindPointer("source", (void**)&tctrl);
if(tctrl == NULL) return;
EString str(tctrl->Text());
eint32 count;
if(str.GetInteger(&count) == false) return;
msg->AddInt32("count", count);
msgrDrawing.SendMessage(msg);
}
EWindow::MessageReceived(msg);
}
static e_status_t sdl_task(void *arg)
{
SDL_Surface *screen;
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
ETK_WARNING("%s --- Couldn't initialize SDL: %s", __PRETTY_FUNCTION__, SDL_GetError());
etk_app->PostMessage(E_QUIT_REQUESTED);
return E_ERROR;
}
if((screen = SDL_SetVideoMode(VIDEO_XRES, VIDEO_YRES, VIDEO_DEPTH, SDL_SWSURFACE | SDL_ASYNCBLIT | SDL_ANYFORMAT)) == NULL)
{
ETK_WARNING("%s --- Couldn't set video mode: %s", __PRETTY_FUNCTION__, SDL_GetError());
etk_app->PostMessage(E_QUIT_REQUESTED);
return E_ERROR;
}
SDL_WM_SetCaption("SDL area", NULL);
SDL_Event event;
do {
SDL_WaitEvent(&event);
if(event.type == SDL_VIDEOEXPOSE) SDL_UpdateRect(screen, 0, 0, 0, 0);
} while(event.type != SDL_QUIT);
etk_app->PostMessage(E_QUIT_REQUESTED);
return E_OK;
}
#ifndef RUN_SDL_TASK_FIRST
TApplication::TApplication()
: EApplication("application/x-vnd.etkxx-render_sample-app")
{
fSDLThread = etk_create_thread(sdl_task, E_NORMAL_PRIORITY, NULL, NULL);
if(fSDLThread == NULL || etk_resume_thread(fSDLThread) != E_OK)
{
if(fSDLThread != NULL) etk_delete_thread(fSDLThread);
fSDLThread = NULL;
ETK_WARNING("%s --- Couldn't create thread for spawning \"sdl_task\"!", __PRETTY_FUNCTION__);
}
}
#else
TApplication::TApplication(void *thread)
: EApplication("application/x-vnd.etkxx-render_sample-app")
{
fSDLThread = thread;
}
#endif
TApplication::~TApplication()
{
if(fSDLThread != NULL)
{
// post the event in order to quit the "sdl_task"
SDL_Event sdlEvent;
sdlEvent.type = SDL_QUIT;
SDL_PushEvent(&sdlEvent);
e_status_t status;
etk_wait_for_thread(fSDLThread, &status);
etk_delete_thread(fSDLThread);
SDL_Quit();
}
}
void
TApplication::ReadyToRun()
{
if(fSDLThread != NULL)
{
TDrawingLooper *drawingLooper = new TDrawingLooper();
msgrDrawing = EMessenger(drawingLooper);
drawingLooper->Run();
TWindow *win = new TWindow();
#if 0
// let "TApplication" handle the events of "TWindow"
Lock();
win->Lock();
win->ProxyBy(this);
win->Unlock();
Unlock();
#endif
// "Show()" isn't MT-Safe, so we call Lock/Unlock
win->Lock();
win->Show();
win->Unlock();
}
else
{
Quit();
}
}
bool
TApplication::QuitRequested()
{
while(msgrDrawing.SendMessage(E_QUIT_REQUESTED) == E_OK) e_snooze(100000);
return true;
}
void
TApplication::Pulse()
{
SDL_Event sdlEvent;
sdlEvent.type = SDL_VIDEOEXPOSE;
SDL_PushEvent(&sdlEvent);
}
void
TApplication::MessageReceived(EMessage *msg)
{
switch(msg->what)
{
case START_REFRESH_MSG:
case STOP_REFRESH_MSG:
SetPulseRate(msg->what == START_REFRESH_MSG ? REFRESH_INTERVAL : 0);
if(msg->what == STOP_REFRESH_MSG) Pulse();
break;
default:
EApplication::MessageReceived(msg);
}
}
int main(int argc, char **argv)
{
#ifndef RUN_SDL_TASK_FIRST
TApplication *myapp = new TApplication();
#else
void *thread = etk_create_thread(sdl_task, E_NORMAL_PRIORITY, NULL, NULL);
if(thread == NULL || etk_resume_thread(thread) != E_OK)
{
if(thread != NULL) etk_delete_thread(thread);
ETK_ERROR("%s --- Couldn't create thread for spawning \"sdl_task\"!", __PRETTY_FUNCTION__);
}
e_snooze(500000);
TApplication *myapp = new TApplication(thread);
#endif
myapp->Run();
delete myapp;
return 0;
}
#if defined(_WIN32) && !(defined(_MSC_VER) && defined(_DEBUG))
#include <windows.h>
int _stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
return main(__argc, __argv);
}
#endif // defined(_WIN32) && !(defined(_MSC_VER) && defined(_DEBUG))
|
; A163714: Number of n X 2 binary arrays with all 1s connected, a path of 1s from top row to bottom row, and no 1 having more than two 1s adjacent.
; 3,7,10,16,26,42,68,110,178,288,466,754,1220,1974,3194,5168,8362,13530,21892,35422,57314,92736,150050,242786,392836,635622,1028458,1664080,2692538,4356618,7049156,11405774,18454930,29860704,48315634,78176338,126491972,204668310,331160282,535828592,866988874,1402817466,2269806340,3672623806,5942430146,9615053952,15557484098,25172538050,40730022148,65902560198,106632582346,172535142544,279167724890,451702867434,730870592324,1182573459758,1913444052082,3096017511840,5009461563922,8105479075762,13114940639684,21220419715446,34335360355130,55555780070576,89891140425706,145446920496282,235338060921988,380784981418270,616123042340258,996908023758528,1613031066098786,2609939089857314,4222970155956100,6832909245813414
mov $1,$0
lpb $0
trn $1,2
add $2,3
mov $3,$1
add $1,1
add $1,$2
trn $3,$0
sub $0,1
add $1,1
mov $2,$3
lpe
trn $1,1
add $1,3
|
;
; Turtle graphics library
; Stefano - 11/2017
;
; $Id: fwd.asm $
;
SECTION code_clib
PUBLIC fwd
PUBLIC _fwd
EXTERN l_mult
EXTERN l_div
EXTERN icos
EXTERN isin
EXTERN move
EXTERN __direction
.fwd
._fwd
; __FASTCALL
push hl
ld hl,(__direction)
call icos
pop de
push de
call l_mult
ld de,256
ex de,hl
call l_div
pop de
push hl
push de
ld hl,(__direction)
call isin
pop de
call l_mult
ld de,256
ex de,hl
call l_div
push hl
call move
pop hl
pop hl
ret
|
lc r4, 0x00000002
lc r5, 0xffffffff
eq r6, r4, r5
halt
#@expected values
#r4 = 0x00000002
#r5 = 0xffffffff
#r6 = 0x00000000
#pc = -2147483632
#e0 = 0
#e1 = 0
#e2 = 0
#e3 = 0
|
ori $1, $0, 8
ori $2, $0, 12
ori $3, $0, 5
ori $4, $0, 0
sw $4, 0($0)
sw $2, 4($0)
sw $3, 8($0)
sw $3, 12($0)
sw $2, 16($0)
sw $2, 20($0)
sw $4, 24($0)
sw $3, 28($0)
sw $1, 32($0)
sw $1, 36($0)
sw $4, 40($0)
sw $3, 44($0)
sw $3, 48($0)
sw $4, 52($0)
sw $2, 56($0)
sw $4, 60($0)
sw $3, 64($0)
sw $3, 68($0)
sw $2, 72($0)
sw $3, 76($0)
sw $1, 80($0)
sw $1, 84($0)
sw $1, 88($0)
sw $3, 92($0)
sw $2, 96($0)
sw $3, 100($0)
sw $1, 104($0)
sw $2, 108($0)
sw $1, 112($0)
sw $1, 116($0)
sw $3, 120($0)
sw $4, 124($0)
srav $2, $2, $2
sb $2, 0($2)
lw $1, 0($2)
bltz $2, TAG1
TAG1:
mflo $1
sllv $1, $1, $1
mfhi $4
sw $1, 0($4)
TAG2:
lb $3, 0($4)
bne $4, $4, TAG3
sltu $4, $4, $4
lbu $2, 0($4)
TAG3:
lh $4, 0($2)
lh $4, 0($4)
and $1, $4, $2
lui $1, 14
TAG4:
beq $1, $1, TAG5
addiu $1, $1, 4
mthi $1
bne $1, $1, TAG5
TAG5:
mtlo $1
sll $0, $0, 0
beq $1, $1, TAG6
sll $0, $0, 0
TAG6:
blez $1, TAG7
subu $3, $1, $1
sh $1, 0($3)
sll $0, $0, 0
TAG7:
mtlo $1
sltiu $4, $1, 14
sll $0, $0, 0
mthi $1
TAG8:
sw $2, 0($2)
mthi $2
bltz $2, TAG9
lui $2, 7
TAG9:
mflo $1
lui $1, 9
mult $1, $2
divu $2, $1
TAG10:
mflo $3
lhu $1, 0($3)
sub $1, $1, $1
lhu $1, 0($1)
TAG11:
lui $4, 1
lui $4, 1
lui $1, 6
mfhi $1
TAG12:
srlv $2, $1, $1
beq $1, $2, TAG13
sllv $2, $1, $1
srl $3, $2, 1
TAG13:
sw $3, 0($3)
or $3, $3, $3
nor $3, $3, $3
xori $2, $3, 13
TAG14:
xori $3, $2, 2
beq $3, $2, TAG15
lhu $3, 16($3)
sra $4, $2, 4
TAG15:
lui $3, 4
lbu $4, 1($4)
multu $3, $4
mflo $1
TAG16:
lui $1, 0
sb $1, 0($1)
mfhi $1
bltz $1, TAG17
TAG17:
mflo $1
multu $1, $1
nor $1, $1, $1
nor $3, $1, $1
TAG18:
mthi $3
mfhi $2
lui $3, 12
addu $4, $3, $2
TAG19:
lui $2, 12
bne $4, $2, TAG20
divu $2, $4
sltu $4, $2, $4
TAG20:
bne $4, $4, TAG21
and $3, $4, $4
lui $3, 0
xor $2, $3, $3
TAG21:
beq $2, $2, TAG22
mtlo $2
blez $2, TAG22
sltiu $4, $2, 10
TAG22:
mflo $3
lui $1, 10
mfhi $1
beq $1, $1, TAG23
TAG23:
mfhi $1
mtlo $1
srav $1, $1, $1
mflo $1
TAG24:
bgez $1, TAG25
mtlo $1
xori $4, $1, 0
lw $2, 0($1)
TAG25:
mflo $4
multu $2, $2
mthi $2
sll $2, $2, 3
TAG26:
lbu $1, 0($2)
lui $4, 6
blez $2, TAG27
subu $3, $1, $1
TAG27:
ori $4, $3, 13
beq $4, $3, TAG28
lui $2, 1
mthi $2
TAG28:
divu $2, $2
srlv $4, $2, $2
sltu $2, $2, $2
sh $2, 0($2)
TAG29:
mfhi $1
bne $2, $1, TAG30
mflo $1
sb $1, 0($2)
TAG30:
andi $1, $1, 6
srlv $4, $1, $1
sb $4, 0($1)
mfhi $2
TAG31:
multu $2, $2
sw $2, 0($2)
mflo $3
multu $3, $3
TAG32:
ori $2, $3, 2
lui $2, 8
lui $1, 1
bltz $1, TAG33
TAG33:
sll $0, $0, 0
mfhi $1
mtlo $3
lb $2, 0($3)
TAG34:
mult $2, $2
bgez $2, TAG35
addu $4, $2, $2
div $2, $2
TAG35:
lui $1, 0
lui $2, 9
mflo $2
lh $3, 0($2)
TAG36:
bltz $3, TAG37
slti $1, $3, 7
lh $4, 0($3)
mthi $3
TAG37:
beq $4, $4, TAG38
mflo $4
mtlo $4
lui $4, 3
TAG38:
multu $4, $4
mflo $1
mtlo $4
mthi $4
TAG39:
mflo $3
lb $4, 0($3)
bltz $1, TAG40
lh $2, 0($4)
TAG40:
lui $4, 3
sltiu $1, $2, 3
beq $1, $1, TAG41
sltiu $3, $1, 0
TAG41:
bltz $3, TAG42
lui $4, 3
blez $4, TAG42
sll $0, $0, 0
TAG42:
mtlo $4
beq $4, $4, TAG43
addiu $3, $4, 13
mthi $3
TAG43:
srlv $1, $3, $3
lui $3, 4
sll $0, $0, 0
beq $1, $1, TAG44
TAG44:
srav $1, $3, $3
bne $3, $1, TAG45
mthi $3
blez $3, TAG45
TAG45:
divu $1, $1
lui $2, 5
multu $1, $1
multu $2, $1
TAG46:
mflo $4
mthi $4
lui $2, 14
mfhi $1
TAG47:
beq $1, $1, TAG48
addi $1, $1, 14
bgtz $1, TAG48
sb $1, 0($1)
TAG48:
mfhi $2
mflo $2
sb $1, 0($2)
divu $2, $1
TAG49:
beq $2, $2, TAG50
lui $1, 10
mtlo $2
xor $1, $1, $1
TAG50:
sll $0, $0, 0
bgtz $1, TAG51
sll $0, $0, 0
bgez $1, TAG51
TAG51:
multu $3, $3
blez $3, TAG52
sll $2, $3, 10
andi $3, $3, 7
TAG52:
multu $3, $3
sll $2, $3, 13
blez $2, TAG53
lui $1, 5
TAG53:
bgez $1, TAG54
sltiu $1, $1, 5
mult $1, $1
sh $1, 0($1)
TAG54:
beq $1, $1, TAG55
addi $1, $1, 1
sllv $4, $1, $1
lh $4, 0($4)
TAG55:
bgez $4, TAG56
mthi $4
mtlo $4
sb $4, 0($4)
TAG56:
lui $2, 10
sll $0, $0, 0
mflo $2
mthi $2
TAG57:
sb $2, 0($2)
mflo $1
lui $4, 9
blez $2, TAG58
TAG58:
mthi $4
addiu $1, $4, 10
beq $1, $4, TAG59
div $4, $1
TAG59:
bgtz $1, TAG60
mfhi $3
bne $3, $3, TAG60
lui $4, 10
TAG60:
beq $4, $4, TAG61
sll $0, $0, 0
sw $4, 0($3)
sw $4, 0($3)
TAG61:
addiu $4, $3, 7
mtlo $3
lui $2, 3
lui $1, 3
TAG62:
ori $1, $1, 6
lui $2, 12
bgez $1, TAG63
mflo $4
TAG63:
lui $2, 9
bgtz $4, TAG64
lui $4, 5
multu $2, $4
TAG64:
srav $3, $4, $4
and $2, $4, $3
blez $4, TAG65
sll $0, $0, 0
TAG65:
mtlo $2
lui $4, 1
div $4, $4
sll $0, $0, 0
TAG66:
slti $2, $4, 10
multu $2, $2
lh $2, 0($2)
multu $2, $2
TAG67:
mthi $2
mtlo $2
lui $3, 7
sll $0, $0, 0
TAG68:
multu $2, $2
sb $2, 0($2)
beq $2, $2, TAG69
lui $1, 4
TAG69:
mthi $1
slt $2, $1, $1
beq $1, $2, TAG70
mthi $2
TAG70:
sra $4, $2, 12
lui $2, 5
subu $2, $2, $2
lui $2, 4
TAG71:
bne $2, $2, TAG72
sll $0, $0, 0
mflo $3
mfhi $3
TAG72:
sb $3, 0($3)
lw $2, 0($3)
mfhi $2
bne $2, $2, TAG73
TAG73:
sh $2, 0($2)
lui $1, 5
slti $4, $1, 6
addi $1, $4, 1
TAG74:
srav $3, $1, $1
bltz $1, TAG75
mtlo $3
sb $1, 0($1)
TAG75:
sb $3, 0($3)
mthi $3
or $3, $3, $3
sra $1, $3, 13
TAG76:
lb $3, 0($1)
sra $3, $1, 1
bne $3, $3, TAG77
multu $1, $1
TAG77:
mtlo $3
mult $3, $3
sh $3, 0($3)
lui $3, 2
TAG78:
bne $3, $3, TAG79
sra $3, $3, 14
mthi $3
mfhi $3
TAG79:
sb $3, 0($3)
slt $2, $3, $3
lui $3, 14
lui $1, 12
TAG80:
srl $3, $1, 15
sh $1, 0($3)
bgez $3, TAG81
mflo $1
TAG81:
bgez $1, TAG82
mfhi $1
mfhi $3
mfhi $4
TAG82:
bltz $4, TAG83
add $3, $4, $4
mult $3, $3
bltz $4, TAG83
TAG83:
sw $3, 0($3)
bltz $3, TAG84
sltu $1, $3, $3
sb $3, 0($1)
TAG84:
mtlo $1
bgtz $1, TAG85
addu $2, $1, $1
mflo $3
TAG85:
addiu $4, $3, 14
sh $3, 0($4)
beq $4, $3, TAG86
and $1, $3, $4
TAG86:
add $2, $1, $1
lui $2, 12
sltu $4, $2, $2
lw $3, 0($4)
TAG87:
lui $1, 11
mtlo $3
lui $3, 3
mtlo $1
TAG88:
lui $3, 5
mult $3, $3
mult $3, $3
sll $0, $0, 0
TAG89:
andi $3, $3, 12
lw $3, 0($3)
mflo $1
mfhi $4
TAG90:
mflo $3
sb $3, 0($4)
srav $3, $3, $3
mfhi $3
TAG91:
lbu $4, 0($3)
beq $3, $4, TAG92
mflo $4
multu $4, $4
TAG92:
mult $4, $4
mflo $3
lhu $1, 0($4)
sw $4, 0($1)
TAG93:
sb $1, 0($1)
multu $1, $1
lui $4, 13
bne $1, $4, TAG94
TAG94:
lui $1, 15
lui $1, 15
mfhi $4
mult $4, $4
TAG95:
sw $4, 0($4)
lui $2, 5
lui $4, 1
addiu $2, $4, 6
TAG96:
mtlo $2
lui $1, 9
subu $3, $1, $2
mthi $1
TAG97:
sll $0, $0, 0
sll $0, $0, 0
bne $3, $3, TAG98
mult $3, $3
TAG98:
and $4, $3, $3
beq $3, $3, TAG99
addu $2, $4, $4
mflo $2
TAG99:
mflo $1
xori $4, $2, 7
beq $4, $1, TAG100
lui $4, 8
TAG100:
mthi $4
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
TAG101:
sll $0, $0, 0
mthi $1
sll $0, $0, 0
srav $2, $1, $1
TAG102:
sll $0, $0, 0
mflo $2
slt $2, $1, $2
bgtz $1, TAG103
TAG103:
lh $4, 0($2)
add $3, $2, $2
bltz $3, TAG104
mtlo $4
TAG104:
mult $3, $3
multu $3, $3
sh $3, 0($3)
bgez $3, TAG105
TAG105:
sw $3, 0($3)
addu $3, $3, $3
mtlo $3
bne $3, $3, TAG106
TAG106:
sb $3, 0($3)
lui $3, 3
srav $4, $3, $3
mtlo $3
TAG107:
mfhi $2
mflo $1
xori $4, $4, 7
srav $1, $4, $4
TAG108:
mtlo $1
mtlo $1
mtlo $1
sllv $1, $1, $1
TAG109:
mflo $4
bltz $1, TAG110
sw $1, -1536($4)
sh $1, -1536($4)
TAG110:
bltz $4, TAG111
or $3, $4, $4
mthi $4
mtlo $4
TAG111:
sra $4, $3, 11
divu $4, $3
sh $4, -1536($3)
sh $4, 0($4)
TAG112:
bltz $4, TAG113
mflo $1
lw $1, 0($1)
sll $1, $1, 8
TAG113:
mtlo $1
multu $1, $1
bltz $1, TAG114
lui $1, 8
TAG114:
mult $1, $1
mflo $2
sll $0, $0, 0
bne $1, $1, TAG115
TAG115:
sra $3, $2, 14
add $3, $2, $2
beq $3, $3, TAG116
mtlo $3
TAG116:
bne $3, $3, TAG117
addi $2, $3, 6
blez $3, TAG117
mthi $2
TAG117:
mflo $1
ori $2, $1, 7
mthi $1
srlv $4, $2, $2
TAG118:
mtlo $4
addiu $1, $4, 7
mthi $1
multu $4, $1
TAG119:
bgez $1, TAG120
lui $1, 8
bgez $1, TAG120
srav $4, $1, $1
TAG120:
bgtz $4, TAG121
ori $1, $4, 4
multu $1, $4
mtlo $4
TAG121:
lb $3, 0($1)
div $3, $3
bgtz $3, TAG122
mtlo $1
TAG122:
mult $3, $3
bgtz $3, TAG123
and $1, $3, $3
mflo $4
TAG123:
sb $4, 0($4)
mflo $3
mflo $1
mflo $3
TAG124:
mthi $3
slti $4, $3, 13
subu $3, $4, $3
multu $4, $4
TAG125:
bgez $3, TAG126
sb $3, 144($3)
lhu $2, 144($3)
divu $3, $2
TAG126:
sh $2, 0($2)
lui $4, 9
div $4, $4
lui $2, 2
TAG127:
mfhi $1
lw $2, 0($1)
mult $1, $1
beq $2, $2, TAG128
TAG128:
divu $2, $2
lui $1, 12
mfhi $3
mthi $2
TAG129:
lw $4, 0($3)
sltiu $2, $4, 5
lb $2, 0($3)
beq $2, $2, TAG130
TAG130:
lh $2, 0($2)
lui $2, 13
sll $0, $0, 0
beq $1, $2, TAG131
TAG131:
sll $0, $0, 0
sltiu $4, $1, 1
lui $3, 4
divu $2, $3
TAG132:
lui $3, 9
sll $0, $0, 0
div $4, $3
or $1, $3, $3
TAG133:
xori $2, $1, 3
xori $3, $1, 3
mthi $2
lui $3, 8
TAG134:
srlv $1, $3, $3
bne $1, $1, TAG135
mtlo $3
xor $3, $1, $1
TAG135:
mult $3, $3
lui $2, 7
lui $1, 6
mult $1, $3
TAG136:
beq $1, $1, TAG137
sll $0, $0, 0
slti $3, $1, 9
lui $3, 10
TAG137:
sb $3, 0($3)
mult $3, $3
srlv $3, $3, $3
sra $1, $3, 3
TAG138:
lbu $4, 0($1)
mthi $1
mtlo $4
mflo $3
TAG139:
or $2, $3, $3
lbu $2, 0($2)
blez $3, TAG140
sw $2, 0($2)
TAG140:
beq $2, $2, TAG141
sub $4, $2, $2
lbu $1, 0($4)
lui $2, 0
TAG141:
bgez $2, TAG142
sb $2, 0($2)
lh $3, 0($2)
mult $3, $3
TAG142:
bgtz $3, TAG143
mflo $1
bgez $3, TAG143
srav $1, $1, $1
TAG143:
multu $1, $1
mfhi $4
sra $3, $4, 10
lui $4, 5
TAG144:
subu $1, $4, $4
bgtz $4, TAG145
sll $0, $0, 0
lhu $4, 0($4)
TAG145:
ori $2, $4, 2
bne $2, $4, TAG146
div $4, $2
srav $1, $2, $2
TAG146:
sllv $2, $1, $1
mthi $1
bltz $2, TAG147
sb $1, 0($1)
TAG147:
beq $2, $2, TAG148
mtlo $2
mult $2, $2
beq $2, $2, TAG148
TAG148:
sb $2, 0($2)
sll $2, $2, 3
sh $2, 0($2)
bne $2, $2, TAG149
TAG149:
srav $3, $2, $2
lui $1, 11
beq $2, $2, TAG150
mflo $4
TAG150:
mfhi $1
bgez $4, TAG151
lw $1, 0($1)
mult $1, $1
TAG151:
bne $1, $1, TAG152
mult $1, $1
lh $4, 0($1)
addi $2, $4, 3
TAG152:
xor $1, $2, $2
blez $1, TAG153
mtlo $2
mtlo $2
TAG153:
mfhi $3
slti $1, $3, 12
lui $4, 11
addu $1, $1, $3
TAG154:
sb $1, 0($1)
sb $1, 0($1)
beq $1, $1, TAG155
multu $1, $1
TAG155:
addu $1, $1, $1
lbu $1, 0($1)
slt $1, $1, $1
mult $1, $1
TAG156:
mthi $1
mflo $4
lui $1, 10
slt $3, $1, $1
TAG157:
ori $3, $3, 2
sra $2, $3, 0
bltz $2, TAG158
divu $2, $3
TAG158:
nor $4, $2, $2
mthi $2
lui $1, 14
multu $4, $4
TAG159:
lui $3, 6
mult $1, $1
bltz $3, TAG160
and $4, $3, $1
TAG160:
mtlo $4
divu $4, $4
sllv $4, $4, $4
multu $4, $4
TAG161:
sll $0, $0, 0
mthi $2
subu $4, $2, $4
beq $4, $4, TAG162
TAG162:
sll $0, $0, 0
mthi $4
bne $4, $4, TAG163
mult $4, $4
TAG163:
sll $0, $0, 0
bne $4, $4, TAG164
divu $4, $4
bgtz $4, TAG164
TAG164:
mtlo $4
sll $0, $0, 0
mflo $4
lui $1, 0
TAG165:
mult $1, $1
blez $1, TAG166
addi $2, $1, 6
lhu $2, 0($1)
TAG166:
mtlo $2
lui $1, 10
mthi $1
sllv $3, $2, $1
TAG167:
divu $3, $3
bne $3, $3, TAG168
mthi $3
mfhi $3
TAG168:
mtlo $3
bltz $3, TAG169
mflo $3
bne $3, $3, TAG169
TAG169:
lh $2, 0($3)
divu $2, $3
srlv $1, $2, $2
sh $3, 0($2)
TAG170:
sw $1, 0($1)
mult $1, $1
multu $1, $1
slti $4, $1, 2
TAG171:
bne $4, $4, TAG172
sb $4, 0($4)
lb $2, 0($4)
bltz $2, TAG172
TAG172:
srav $1, $2, $2
ori $4, $2, 0
and $4, $4, $2
sb $2, 0($4)
TAG173:
mthi $4
bgez $4, TAG174
lb $1, 0($4)
xori $4, $1, 6
TAG174:
lui $4, 1
bgez $4, TAG175
sll $0, $0, 0
and $3, $4, $4
TAG175:
divu $3, $3
blez $3, TAG176
mflo $1
lui $3, 13
TAG176:
andi $2, $3, 0
mthi $3
sh $2, 0($2)
mthi $3
TAG177:
mtlo $2
slti $1, $2, 5
blez $2, TAG178
and $4, $2, $1
TAG178:
mtlo $4
mfhi $1
mfhi $3
divu $1, $3
TAG179:
sll $0, $0, 0
slti $1, $3, 0
bgez $1, TAG180
mflo $1
TAG180:
sb $1, 0($1)
bgez $1, TAG181
mfhi $2
lh $2, 0($1)
TAG181:
beq $2, $2, TAG182
mthi $2
beq $2, $2, TAG182
xor $1, $2, $2
TAG182:
andi $3, $1, 7
mthi $3
lui $4, 4
sll $0, $0, 0
TAG183:
sll $0, $0, 0
mtlo $4
mflo $2
beq $2, $2, TAG184
TAG184:
mthi $2
lui $1, 4
sll $0, $0, 0
div $2, $1
TAG185:
sll $0, $0, 0
lui $1, 5
lui $4, 1
sll $0, $0, 0
TAG186:
sll $0, $0, 0
mflo $2
sll $0, $0, 0
lbu $1, 0($3)
TAG187:
beq $1, $1, TAG188
lbu $3, 0($1)
xor $1, $1, $3
mfhi $4
TAG188:
mtlo $4
sll $0, $0, 0
sll $0, $0, 0
bgez $4, TAG189
TAG189:
xori $3, $4, 7
sll $0, $0, 0
blez $1, TAG190
mtlo $4
TAG190:
bltz $1, TAG191
mflo $2
addiu $2, $2, 8
bne $2, $2, TAG191
TAG191:
subu $3, $2, $2
bne $3, $3, TAG192
addiu $2, $2, 11
divu $3, $2
TAG192:
mthi $2
slti $1, $2, 8
xor $2, $1, $2
multu $1, $2
TAG193:
bne $2, $2, TAG194
mflo $1
multu $1, $1
sll $0, $0, 0
TAG194:
sltu $3, $3, $3
sll $3, $3, 13
mfhi $2
bne $3, $3, TAG195
TAG195:
lb $3, 0($2)
beq $3, $2, TAG196
lui $3, 7
sw $3, 0($3)
TAG196:
lui $1, 3
beq $1, $3, TAG197
mflo $3
sll $0, $0, 0
TAG197:
or $2, $4, $4
sll $0, $0, 0
mflo $1
lui $1, 3
TAG198:
ori $3, $1, 3
mthi $3
sll $0, $0, 0
sll $0, $0, 0
TAG199:
beq $3, $3, TAG200
sll $0, $0, 0
mthi $3
sh $3, 0($3)
TAG200:
lui $4, 11
subu $1, $4, $3
sll $0, $0, 0
sll $0, $0, 0
TAG201:
mtlo $2
bgez $2, TAG202
divu $2, $2
bne $2, $2, TAG202
TAG202:
sll $0, $0, 0
srl $4, $2, 5
beq $2, $4, TAG203
divu $4, $4
TAG203:
sll $0, $0, 0
mfhi $4
lui $4, 5
lui $1, 2
TAG204:
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
TAG205:
beq $2, $2, TAG206
sll $0, $0, 0
nor $2, $2, $2
beq $2, $2, TAG206
TAG206:
srl $4, $2, 1
lui $2, 6
bgez $2, TAG207
ori $3, $4, 9
TAG207:
bne $3, $3, TAG208
lui $3, 6
xori $4, $3, 14
sll $0, $0, 0
TAG208:
sll $0, $0, 0
sll $0, $0, 0
bgtz $2, TAG209
sll $0, $0, 0
TAG209:
beq $4, $4, TAG210
sll $0, $0, 0
mflo $1
mfhi $1
TAG210:
bne $1, $1, TAG211
mtlo $1
lui $1, 9
sll $0, $0, 0
TAG211:
divu $1, $1
mthi $1
lui $1, 3
sll $0, $0, 0
TAG212:
blez $1, TAG213
mthi $1
bne $1, $1, TAG213
srav $1, $1, $1
TAG213:
bgtz $1, TAG214
sltiu $3, $1, 0
bltz $3, TAG214
sub $1, $1, $3
TAG214:
addu $3, $1, $1
mtlo $1
mult $3, $3
sll $0, $0, 0
TAG215:
beq $3, $3, TAG216
divu $3, $3
bltz $3, TAG216
lui $2, 15
TAG216:
mtlo $2
sll $2, $2, 2
sll $0, $0, 0
div $2, $2
TAG217:
lui $4, 0
beq $4, $2, TAG218
sltiu $1, $2, 6
blez $4, TAG218
TAG218:
nor $3, $1, $1
mtlo $3
mthi $1
srlv $4, $3, $3
TAG219:
mflo $3
lw $3, 1($3)
mfhi $3
lw $2, 0($3)
TAG220:
srav $1, $2, $2
mthi $2
bne $1, $1, TAG221
subu $3, $1, $1
TAG221:
beq $3, $3, TAG222
mflo $1
srlv $4, $1, $1
mtlo $1
TAG222:
mtlo $4
beq $4, $4, TAG223
mthi $4
sra $2, $4, 13
TAG223:
bne $2, $2, TAG224
and $4, $2, $2
mthi $4
bltz $4, TAG224
TAG224:
lui $3, 9
mthi $4
mtlo $4
mthi $3
TAG225:
sll $0, $0, 0
xori $4, $3, 4
and $3, $4, $4
bltz $4, TAG226
TAG226:
mtlo $3
lui $2, 3
sll $0, $0, 0
lui $4, 5
TAG227:
bne $4, $4, TAG228
sll $0, $0, 0
sll $0, $0, 0
bgez $3, TAG228
TAG228:
sll $0, $0, 0
srl $3, $1, 15
sll $0, $0, 0
sll $0, $0, 0
TAG229:
lui $1, 13
mfhi $2
xori $4, $1, 2
sltu $3, $1, $1
TAG230:
lui $4, 5
mfhi $1
lui $2, 8
sll $0, $0, 0
TAG231:
sll $0, $0, 0
lui $2, 11
bltz $2, TAG232
sll $0, $0, 0
TAG232:
lui $4, 1
bne $3, $3, TAG233
mfhi $3
ori $3, $4, 5
TAG233:
mtlo $3
lui $3, 2
sll $0, $0, 0
mfhi $2
TAG234:
bltz $2, TAG235
slti $1, $2, 0
lui $4, 10
srlv $2, $2, $4
TAG235:
sll $0, $0, 0
mfhi $1
blez $1, TAG236
sll $0, $0, 0
TAG236:
divu $1, $1
sll $0, $0, 0
mthi $1
sll $0, $0, 0
TAG237:
sll $0, $0, 0
mflo $3
sll $0, $0, 0
blez $2, TAG238
TAG238:
mfhi $3
bne $4, $4, TAG239
nor $4, $4, $4
lui $2, 10
TAG239:
sll $0, $0, 0
lui $1, 8
bne $3, $1, TAG240
sll $0, $0, 0
TAG240:
beq $1, $1, TAG241
and $1, $1, $1
slt $4, $1, $1
sltiu $3, $1, 14
TAG241:
lui $1, 0
div $3, $3
addu $2, $3, $3
sltiu $1, $1, 12
TAG242:
mfhi $1
mult $1, $1
mult $1, $1
beq $1, $1, TAG243
TAG243:
mtlo $1
multu $1, $1
bne $1, $1, TAG244
srlv $1, $1, $1
TAG244:
sb $1, 0($1)
xor $3, $1, $1
mflo $3
sllv $4, $3, $3
TAG245:
beq $4, $4, TAG246
lui $4, 6
beq $4, $4, TAG246
lhu $4, 0($4)
TAG246:
beq $4, $4, TAG247
mthi $4
beq $4, $4, TAG247
sb $4, 0($4)
TAG247:
multu $4, $4
andi $4, $4, 6
bne $4, $4, TAG248
sb $4, 0($4)
TAG248:
lh $3, 0($4)
lh $3, 0($4)
sub $3, $3, $4
mfhi $1
TAG249:
mfhi $1
bgez $1, TAG250
sw $1, 0($1)
mfhi $1
TAG250:
bne $1, $1, TAG251
slt $4, $1, $1
lui $2, 3
div $4, $2
TAG251:
sll $0, $0, 0
bgtz $2, TAG252
mflo $4
ori $4, $2, 10
TAG252:
sllv $3, $4, $4
bne $3, $4, TAG253
mflo $2
multu $2, $2
TAG253:
mflo $4
sh $4, 0($4)
sb $2, 0($2)
mfhi $3
TAG254:
bne $3, $3, TAG255
sltiu $2, $3, 2
andi $2, $3, 7
bltz $2, TAG255
TAG255:
and $3, $2, $2
xor $2, $3, $3
srl $4, $2, 8
beq $4, $4, TAG256
TAG256:
sll $1, $4, 4
sh $4, 0($4)
subu $4, $4, $1
sra $2, $4, 2
TAG257:
add $1, $2, $2
beq $2, $2, TAG258
lb $2, 0($1)
mfhi $3
TAG258:
lui $2, 11
subu $3, $2, $2
multu $3, $3
bne $2, $3, TAG259
TAG259:
mthi $3
sh $3, 0($3)
mfhi $2
slt $3, $2, $3
TAG260:
sh $3, 0($3)
mflo $3
lui $1, 12
srav $2, $1, $3
TAG261:
beq $2, $2, TAG262
addu $1, $2, $2
mfhi $4
bgtz $1, TAG262
TAG262:
addiu $1, $4, 5
mthi $4
mfhi $4
sltu $3, $4, $4
TAG263:
sw $3, 0($3)
bne $3, $3, TAG264
mflo $1
mfhi $1
TAG264:
mfhi $4
lh $4, 0($1)
multu $4, $4
sw $4, 0($4)
TAG265:
multu $4, $4
sltiu $4, $4, 14
beq $4, $4, TAG266
addiu $3, $4, 4
TAG266:
bne $3, $3, TAG267
lui $2, 7
mflo $3
addi $1, $3, 12
TAG267:
mfhi $2
blez $2, TAG268
andi $2, $2, 3
bgez $2, TAG268
TAG268:
andi $1, $2, 13
lui $2, 11
lui $2, 15
mfhi $4
TAG269:
mtlo $4
mthi $4
lb $1, 0($4)
addu $4, $4, $1
TAG270:
lb $2, 0($4)
multu $4, $2
sw $2, 0($4)
mfhi $3
TAG271:
mtlo $3
multu $3, $3
lw $3, 0($3)
xori $4, $3, 7
TAG272:
addu $4, $4, $4
div $4, $4
lui $1, 1
lui $1, 0
TAG273:
andi $4, $1, 5
blez $4, TAG274
mthi $1
sb $4, 0($4)
TAG274:
lhu $1, 0($4)
addi $1, $1, 14
xori $3, $4, 2
mfhi $2
TAG275:
bgez $2, TAG276
lui $1, 2
slti $2, $1, 12
divu $2, $2
TAG276:
beq $2, $2, TAG277
srlv $2, $2, $2
sltiu $4, $2, 7
mult $2, $4
TAG277:
nor $4, $4, $4
lw $4, 1($4)
beq $4, $4, TAG278
addi $1, $4, 4
TAG278:
lhu $1, 0($1)
beq $1, $1, TAG279
lhu $3, 0($1)
srl $3, $1, 13
TAG279:
div $3, $3
mflo $4
xori $4, $4, 15
sra $2, $4, 10
TAG280:
lui $1, 3
beq $2, $2, TAG281
divu $2, $1
mfhi $3
TAG281:
multu $3, $3
mthi $3
multu $3, $3
mflo $3
TAG282:
div $3, $3
div $3, $3
beq $3, $3, TAG283
sb $3, 0($3)
TAG283:
divu $3, $3
divu $3, $3
lbu $3, 0($3)
sb $3, 0($3)
TAG284:
sltu $1, $3, $3
bgez $1, TAG285
srav $3, $1, $1
multu $1, $1
TAG285:
mthi $3
mflo $2
mult $2, $3
mult $2, $3
TAG286:
mult $2, $2
sb $2, 0($2)
andi $2, $2, 6
beq $2, $2, TAG287
TAG287:
sb $2, 0($2)
sw $2, 0($2)
sw $2, 0($2)
lui $2, 15
TAG288:
lui $2, 3
mult $2, $2
xori $1, $2, 4
sll $0, $0, 0
TAG289:
multu $1, $1
mthi $1
mflo $4
blez $4, TAG290
TAG290:
subu $2, $4, $4
or $4, $2, $4
lw $1, 0($2)
sh $4, 0($2)
TAG291:
mfhi $2
bne $1, $1, TAG292
multu $2, $2
beq $2, $2, TAG292
TAG292:
addiu $4, $2, 0
and $3, $2, $2
mtlo $3
mthi $2
TAG293:
mult $3, $3
sra $1, $3, 12
bgtz $1, TAG294
multu $3, $1
TAG294:
lui $4, 15
lui $3, 13
lui $1, 0
and $1, $4, $1
TAG295:
addi $2, $1, 11
mtlo $1
bgtz $1, TAG296
sb $1, 0($2)
TAG296:
mfhi $3
mfhi $1
sb $3, 0($2)
bgtz $1, TAG297
TAG297:
multu $1, $1
beq $1, $1, TAG298
sh $1, 0($1)
xor $4, $1, $1
TAG298:
lui $2, 10
andi $2, $4, 10
or $2, $2, $2
ori $4, $4, 11
TAG299:
bgtz $4, TAG300
sll $0, $0, 0
lui $1, 9
bltz $4, TAG300
TAG300:
lh $2, 0($1)
mfhi $3
bltz $3, TAG301
mfhi $2
TAG301:
lh $2, 0($2)
bne $2, $2, TAG302
mult $2, $2
bgtz $2, TAG302
TAG302:
mtlo $2
lh $1, 0($2)
srav $4, $2, $1
sub $2, $1, $2
TAG303:
mult $2, $2
or $1, $2, $2
bgtz $1, TAG304
mult $2, $1
TAG304:
mflo $1
and $3, $1, $1
mflo $4
sw $4, 0($3)
TAG305:
bne $4, $4, TAG306
multu $4, $4
bgez $4, TAG306
mflo $2
TAG306:
sllv $3, $2, $2
beq $3, $2, TAG307
slti $3, $3, 9
sh $3, 0($3)
TAG307:
lui $3, 3
addiu $4, $3, 5
addiu $4, $4, 8
addiu $4, $4, 15
TAG308:
srav $3, $4, $4
mtlo $4
mtlo $3
mthi $3
TAG309:
sw $3, 0($3)
mthi $3
mult $3, $3
multu $3, $3
TAG310:
lh $3, 0($3)
addi $1, $3, 2
mflo $4
slti $1, $3, 4
TAG311:
mtlo $1
lbu $3, 0($1)
multu $3, $3
lui $4, 12
TAG312:
mthi $4
bltz $4, TAG313
mult $4, $4
sll $0, $0, 0
TAG313:
sra $3, $4, 2
bgtz $3, TAG314
mfhi $4
mflo $2
TAG314:
beq $2, $2, TAG315
sb $2, 0($2)
xori $2, $2, 5
sw $2, 0($2)
TAG315:
mtlo $2
lui $1, 2
mflo $1
addu $3, $1, $2
TAG316:
sb $3, 0($3)
mthi $3
sw $3, 0($3)
srlv $2, $3, $3
TAG317:
mflo $2
mtlo $2
blez $2, TAG318
mult $2, $2
TAG318:
mtlo $2
srav $2, $2, $2
lb $2, 0($2)
bne $2, $2, TAG319
TAG319:
sb $2, 0($2)
bne $2, $2, TAG320
mflo $1
mthi $1
TAG320:
mfhi $3
lw $4, 0($3)
mtlo $1
multu $1, $3
TAG321:
mthi $4
sb $4, 0($4)
lui $1, 10
sw $1, 0($4)
TAG322:
lui $1, 10
sll $0, $0, 0
addiu $1, $1, 11
blez $1, TAG323
TAG323:
sll $0, $0, 0
lui $4, 2
mtlo $4
mflo $3
TAG324:
addiu $3, $3, 2
mult $3, $3
sll $0, $0, 0
sltiu $1, $3, 7
TAG325:
sh $1, 0($1)
sb $1, 0($1)
beq $1, $1, TAG326
or $4, $1, $1
TAG326:
or $3, $4, $4
sb $3, 0($3)
sh $4, 0($4)
mflo $2
TAG327:
mthi $2
bgez $2, TAG328
lui $4, 3
mfhi $2
TAG328:
sll $0, $0, 0
beq $2, $1, TAG329
mflo $3
lui $4, 10
TAG329:
bne $4, $4, TAG330
lui $2, 11
bgtz $4, TAG330
srl $2, $2, 3
TAG330:
sll $0, $0, 0
sll $0, $0, 0
mflo $2
mult $2, $2
TAG331:
sllv $4, $2, $2
lui $1, 4
lui $2, 5
bne $4, $1, TAG332
TAG332:
sll $0, $0, 0
multu $1, $2
mtlo $2
and $2, $1, $2
TAG333:
mtlo $2
lui $4, 3
bgtz $4, TAG334
mflo $4
TAG334:
lui $4, 4
slti $4, $4, 11
srl $3, $4, 9
bne $3, $3, TAG335
TAG335:
nor $4, $3, $3
lh $2, 1($4)
multu $2, $3
bgez $4, TAG336
TAG336:
lw $1, 0($2)
mthi $2
subu $4, $2, $1
mtlo $1
TAG337:
bgtz $4, TAG338
addu $1, $4, $4
beq $4, $1, TAG338
srl $3, $1, 2
TAG338:
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
addu $3, $1, $3
TAG339:
multu $3, $3
mfhi $2
sltiu $1, $2, 1
mfhi $1
TAG340:
bltz $1, TAG341
lui $1, 12
mthi $1
sltu $3, $1, $1
TAG341:
multu $3, $3
lhu $2, 0($3)
mthi $3
lui $3, 8
TAG342:
beq $3, $3, TAG343
slti $4, $3, 15
sb $3, 0($4)
srav $3, $4, $4
TAG343:
bne $3, $3, TAG344
ori $2, $3, 4
multu $2, $3
bne $3, $2, TAG344
TAG344:
sltiu $2, $2, 13
beq $2, $2, TAG345
lui $2, 7
addi $4, $2, 5
TAG345:
nor $3, $4, $4
mtlo $4
slti $4, $3, 13
beq $3, $4, TAG346
TAG346:
mthi $4
bne $4, $4, TAG347
xori $4, $4, 2
mfhi $1
TAG347:
sb $1, 0($1)
lbu $3, 0($1)
sb $3, 0($3)
beq $3, $3, TAG348
TAG348:
sb $3, 0($3)
lb $1, 0($3)
multu $1, $3
lbu $1, 0($3)
TAG349:
lb $4, 0($1)
ori $1, $1, 1
sb $1, 0($1)
sllv $3, $1, $1
TAG350:
srl $1, $3, 15
bgtz $1, TAG351
addiu $3, $3, 9
bltz $3, TAG351
TAG351:
mflo $3
mfhi $3
blez $3, TAG352
sb $3, 0($3)
TAG352:
mfhi $1
bltz $1, TAG353
mthi $3
beq $3, $1, TAG353
TAG353:
add $1, $1, $1
beq $1, $1, TAG354
xori $1, $1, 10
lui $3, 9
TAG354:
xor $1, $3, $3
lh $2, 0($3)
lhu $3, 0($1)
srl $3, $3, 3
TAG355:
sh $3, 0($3)
bgez $3, TAG356
lh $4, 0($3)
sb $3, 0($3)
TAG356:
addiu $4, $4, 10
mflo $1
bgez $1, TAG357
sb $4, 0($4)
TAG357:
andi $1, $1, 9
lbu $1, 0($1)
lb $3, 0($1)
beq $3, $3, TAG358
TAG358:
lb $3, 0($3)
beq $3, $3, TAG359
lbu $3, 0($3)
mthi $3
TAG359:
multu $3, $3
bne $3, $3, TAG360
addiu $4, $3, 3
lb $1, 0($4)
TAG360:
lui $4, 1
mflo $3
sb $3, 0($1)
mtlo $3
TAG361:
bgtz $3, TAG362
lui $4, 12
lui $2, 15
mflo $2
TAG362:
sb $2, -256($2)
multu $2, $2
sh $2, -256($2)
mult $2, $2
TAG363:
sw $2, -256($2)
mfhi $1
multu $1, $2
mfhi $2
TAG364:
mult $2, $2
blez $2, TAG365
sll $3, $2, 3
div $2, $3
TAG365:
lbu $1, 0($3)
sh $1, 0($3)
bltz $3, TAG366
mfhi $4
TAG366:
lw $3, 0($4)
sll $4, $4, 8
beq $4, $4, TAG367
mtlo $4
TAG367:
lui $1, 1
multu $4, $1
div $1, $1
mtlo $4
TAG368:
bne $1, $1, TAG369
sll $0, $0, 0
srav $2, $1, $1
bltz $4, TAG369
TAG369:
mtlo $2
bgez $2, TAG370
sll $0, $0, 0
multu $2, $2
TAG370:
mfhi $2
mtlo $2
lh $3, 0($2)
sb $2, 0($3)
TAG371:
mthi $3
mult $3, $3
or $4, $3, $3
bne $3, $4, TAG372
TAG372:
mfhi $3
beq $4, $4, TAG373
lui $2, 1
mtlo $3
TAG373:
mult $2, $2
sll $0, $0, 0
mflo $4
beq $4, $4, TAG374
TAG374:
mult $4, $4
multu $4, $4
slt $2, $4, $4
sw $2, 0($2)
TAG375:
lh $1, 0($2)
lw $2, 0($1)
sw $1, 0($2)
mult $2, $2
TAG376:
multu $2, $2
mfhi $4
and $3, $4, $2
mfhi $2
TAG377:
lh $4, 0($2)
beq $4, $2, TAG378
lui $2, 5
lbu $3, 0($2)
TAG378:
addi $1, $3, 9
multu $3, $3
beq $1, $1, TAG379
slti $3, $3, 11
TAG379:
lb $2, 0($3)
sb $2, 0($3)
xori $2, $3, 4
mtlo $2
TAG380:
lb $2, 0($2)
mfhi $3
addi $1, $2, 1
bne $1, $1, TAG381
TAG381:
sb $1, 0($1)
sb $1, 0($1)
blez $1, TAG382
lb $3, 0($1)
TAG382:
bne $3, $3, TAG383
mthi $3
lbu $1, 0($3)
beq $1, $1, TAG383
TAG383:
lui $1, 7
mtlo $1
mthi $1
mthi $1
TAG384:
mtlo $1
mult $1, $1
mflo $4
beq $1, $1, TAG385
TAG385:
mthi $4
sh $4, 0($4)
mflo $1
mflo $3
TAG386:
lui $3, 15
bne $3, $3, TAG387
lui $4, 8
blez $3, TAG387
TAG387:
mfhi $2
bne $4, $2, TAG388
slti $4, $2, 8
mthi $4
TAG388:
beq $4, $4, TAG389
sb $4, 0($4)
divu $4, $4
mthi $4
TAG389:
addu $1, $4, $4
nor $3, $1, $4
lui $4, 11
lh $4, 4($3)
TAG390:
sh $4, -256($4)
mfhi $1
mult $1, $1
lw $3, -256($4)
TAG391:
srav $3, $3, $3
mfhi $2
mthi $3
nor $4, $2, $3
TAG392:
multu $4, $4
sh $4, 257($4)
lui $1, 9
sll $0, $0, 0
TAG393:
mtlo $2
xor $4, $2, $2
addi $4, $2, 13
lui $2, 4
TAG394:
andi $3, $2, 4
sh $2, 0($3)
mfhi $2
addu $2, $2, $2
TAG395:
divu $2, $2
bltz $2, TAG396
nor $3, $2, $2
mfhi $1
TAG396:
lui $2, 0
mfhi $4
beq $1, $4, TAG397
mult $2, $4
TAG397:
sra $3, $4, 11
mfhi $2
lui $1, 6
bne $3, $1, TAG398
TAG398:
div $1, $1
mfhi $2
mthi $1
xor $2, $1, $1
TAG399:
bltz $2, TAG400
lui $1, 14
addu $3, $2, $2
subu $2, $2, $2
TAG400:
bltz $2, TAG401
mthi $2
mult $2, $2
mtlo $2
TAG401:
mflo $2
lui $1, 2
blez $2, TAG402
sra $1, $1, 1
TAG402:
sll $0, $0, 0
sllv $2, $1, $1
div $1, $2
multu $1, $1
TAG403:
mtlo $2
mtlo $2
bgez $2, TAG404
lui $1, 2
TAG404:
lui $3, 2
bne $3, $1, TAG405
sll $0, $0, 0
sll $0, $0, 0
TAG405:
sll $0, $0, 0
slt $4, $4, $3
sb $4, 0($4)
sb $4, 0($4)
TAG406:
sb $4, 0($4)
lbu $1, 0($4)
mtlo $4
addiu $3, $4, 8
TAG407:
lb $3, 0($3)
mthi $3
mult $3, $3
multu $3, $3
TAG408:
lui $2, 13
lui $2, 12
blez $2, TAG409
or $1, $2, $2
TAG409:
sll $0, $0, 0
xori $1, $1, 6
addu $1, $1, $1
sll $0, $0, 0
TAG410:
bne $2, $2, TAG411
lui $4, 12
andi $4, $4, 9
sb $2, 0($4)
TAG411:
multu $4, $4
beq $4, $4, TAG412
sh $4, 0($4)
lui $1, 10
TAG412:
andi $2, $1, 7
bgtz $2, TAG413
mflo $3
mult $3, $1
TAG413:
lui $2, 13
nor $2, $3, $2
beq $2, $2, TAG414
sll $0, $0, 0
TAG414:
bgtz $1, TAG415
sll $0, $0, 0
sra $1, $1, 4
bltz $1, TAG415
TAG415:
xori $1, $1, 6
or $3, $1, $1
lui $1, 2
sltu $4, $3, $1
TAG416:
or $1, $4, $4
sb $4, 0($4)
andi $4, $1, 0
blez $4, TAG417
TAG417:
lui $2, 13
sltiu $1, $4, 8
mult $1, $2
mflo $4
TAG418:
bne $4, $4, TAG419
mtlo $4
beq $4, $4, TAG419
lui $1, 1
TAG419:
sll $0, $0, 0
lui $4, 7
sll $0, $0, 0
bgtz $4, TAG420
TAG420:
or $1, $4, $4
bgez $4, TAG421
mfhi $3
multu $3, $1
TAG421:
lbu $1, 0($3)
mfhi $3
lui $2, 13
beq $3, $2, TAG422
TAG422:
and $1, $2, $2
div $2, $1
lui $1, 10
mfhi $1
TAG423:
mthi $1
xor $4, $1, $1
mflo $4
mflo $3
TAG424:
lui $1, 4
sll $0, $0, 0
beq $3, $3, TAG425
lui $4, 14
TAG425:
lui $2, 5
beq $2, $2, TAG426
or $1, $2, $4
sw $2, 0($2)
TAG426:
mtlo $1
multu $1, $1
lui $2, 12
mflo $3
TAG427:
sb $3, 0($3)
mfhi $2
mflo $4
multu $2, $4
TAG428:
blez $4, TAG429
xor $4, $4, $4
mult $4, $4
divu $4, $4
TAG429:
mult $4, $4
andi $3, $4, 15
lui $3, 4
or $2, $3, $4
TAG430:
beq $2, $2, TAG431
mflo $3
beq $3, $2, TAG431
lui $3, 8
TAG431:
multu $3, $3
multu $3, $3
slt $1, $3, $3
lw $1, 0($1)
TAG432:
bne $1, $1, TAG433
lb $3, 0($1)
lui $4, 13
multu $1, $1
TAG433:
mfhi $1
sb $4, 0($1)
mtlo $4
divu $1, $4
TAG434:
lui $1, 4
bgez $1, TAG435
multu $1, $1
div $1, $1
TAG435:
lui $1, 13
sll $0, $0, 0
addu $2, $1, $1
mtlo $2
TAG436:
mult $2, $2
sll $1, $2, 13
sll $0, $0, 0
div $2, $1
TAG437:
beq $1, $1, TAG438
mtlo $1
lui $4, 6
lui $1, 15
TAG438:
mthi $1
mtlo $1
mult $1, $1
sll $0, $0, 0
TAG439:
sll $0, $0, 0
srav $3, $2, $2
beq $2, $2, TAG440
sll $0, $0, 0
TAG440:
beq $3, $3, TAG441
sll $0, $0, 0
lh $3, 0($3)
lui $1, 10
TAG441:
sll $0, $0, 0
ori $1, $3, 6
xori $2, $3, 1
lui $2, 7
TAG442:
sll $0, $0, 0
sll $0, $0, 0
mflo $2
sb $2, 0($2)
TAG443:
bgtz $2, TAG444
lh $1, 0($2)
bne $2, $2, TAG444
lbu $3, 0($1)
TAG444:
addu $1, $3, $3
mult $3, $3
lui $2, 5
lb $4, 0($3)
TAG445:
addi $2, $4, 2
andi $1, $4, 5
sw $1, 0($4)
lb $1, 0($4)
TAG446:
lui $1, 15
srav $3, $1, $1
mthi $1
beq $1, $3, TAG447
TAG447:
xori $4, $3, 8
andi $3, $3, 15
sltu $1, $4, $3
subu $3, $4, $4
TAG448:
addiu $4, $3, 9
beq $4, $4, TAG449
mflo $3
mfhi $3
TAG449:
sh $3, 0($3)
mtlo $3
mthi $3
sb $3, 0($3)
TAG450:
slti $1, $3, 4
mthi $3
addiu $1, $1, 9
mtlo $1
TAG451:
mtlo $1
beq $1, $1, TAG452
subu $4, $1, $1
mfhi $4
TAG452:
mtlo $4
srl $2, $4, 2
multu $2, $4
sllv $1, $4, $4
TAG453:
bgtz $1, TAG454
addi $1, $1, 13
beq $1, $1, TAG454
and $4, $1, $1
TAG454:
subu $3, $4, $4
mtlo $4
mfhi $4
mfhi $1
TAG455:
lhu $2, 0($1)
mult $1, $1
mflo $4
srl $2, $4, 6
TAG456:
andi $3, $2, 4
beq $2, $3, TAG457
lui $4, 0
subu $1, $4, $3
TAG457:
beq $1, $1, TAG458
mult $1, $1
sub $4, $1, $1
addiu $2, $1, 4
TAG458:
lb $1, 0($2)
sub $3, $1, $1
sh $2, 0($1)
bne $3, $2, TAG459
TAG459:
multu $3, $3
addu $2, $3, $3
bgez $2, TAG460
sb $2, 0($3)
TAG460:
multu $2, $2
sll $3, $2, 8
multu $3, $2
beq $3, $3, TAG461
TAG461:
mthi $3
multu $3, $3
lui $1, 10
bne $1, $3, TAG462
TAG462:
mult $1, $1
addiu $1, $1, 13
multu $1, $1
blez $1, TAG463
TAG463:
addiu $1, $1, 3
mfhi $1
mtlo $1
subu $4, $1, $1
TAG464:
bltz $4, TAG465
mthi $4
bgez $4, TAG465
mult $4, $4
TAG465:
bgtz $4, TAG466
lh $4, 0($4)
lbu $2, 0($4)
lui $2, 12
TAG466:
sltiu $2, $2, 2
mtlo $2
mflo $1
srl $2, $2, 8
TAG467:
andi $3, $2, 8
nor $3, $2, $3
bne $2, $3, TAG468
mtlo $3
TAG468:
bne $3, $3, TAG469
sw $3, 1($3)
lw $1, 1($3)
subu $4, $3, $1
TAG469:
mtlo $4
srav $4, $4, $4
bltz $4, TAG470
lui $1, 1
TAG470:
div $1, $1
lui $4, 9
divu $4, $4
sll $0, $0, 0
TAG471:
bgez $4, TAG472
addu $4, $4, $4
multu $4, $4
lw $4, 0($4)
TAG472:
bgtz $4, TAG473
divu $4, $4
bne $4, $4, TAG473
mtlo $4
TAG473:
srav $1, $4, $4
sll $0, $0, 0
lui $2, 11
sll $0, $0, 0
TAG474:
lui $1, 13
sll $0, $0, 0
mfhi $3
lui $4, 8
TAG475:
mfhi $4
bne $4, $4, TAG476
lui $2, 3
mult $4, $4
TAG476:
xori $2, $2, 10
mflo $3
lui $1, 6
bgez $2, TAG477
TAG477:
mthi $1
divu $1, $1
addiu $4, $1, 14
beq $1, $1, TAG478
TAG478:
mthi $4
multu $4, $4
blez $4, TAG479
mult $4, $4
TAG479:
addiu $1, $4, 3
sltu $1, $1, $1
multu $4, $1
mthi $1
TAG480:
mthi $1
lui $1, 11
lui $2, 7
sll $0, $0, 0
TAG481:
mtlo $3
addu $1, $3, $3
bne $1, $1, TAG482
mfhi $1
TAG482:
multu $1, $1
slt $1, $1, $1
lui $4, 6
beq $1, $4, TAG483
TAG483:
mfhi $2
sll $3, $4, 10
multu $3, $2
xor $1, $3, $2
TAG484:
mflo $2
multu $1, $2
sll $0, $0, 0
sll $0, $0, 0
TAG485:
mtlo $1
divu $1, $1
lui $2, 11
mfhi $4
TAG486:
sw $4, 0($4)
mflo $3
mfhi $3
beq $3, $3, TAG487
TAG487:
xori $1, $3, 12
lui $3, 2
div $3, $3
lui $4, 3
TAG488:
multu $4, $4
divu $4, $4
srl $4, $4, 1
beq $4, $4, TAG489
TAG489:
addiu $1, $4, 5
divu $4, $1
sll $0, $0, 0
lui $3, 11
TAG490:
sll $0, $0, 0
bltz $3, TAG491
sll $4, $3, 2
mtlo $3
TAG491:
sltu $3, $4, $4
mult $4, $4
mult $4, $3
mflo $1
TAG492:
bgtz $1, TAG493
sb $1, 0($1)
srlv $1, $1, $1
sh $1, 0($1)
TAG493:
lui $4, 1
nor $2, $4, $1
sllv $1, $2, $4
and $3, $4, $4
TAG494:
ori $1, $3, 7
slt $4, $1, $1
lui $2, 6
addu $3, $3, $3
TAG495:
mtlo $3
bltz $3, TAG496
sll $0, $0, 0
mult $3, $3
TAG496:
mtlo $3
mflo $4
lui $4, 12
sll $0, $0, 0
TAG497:
bne $3, $3, TAG498
sll $0, $0, 0
mflo $3
sll $0, $0, 0
TAG498:
sll $0, $0, 0
lui $2, 4
srav $3, $2, $2
sll $1, $4, 7
TAG499:
sll $0, $0, 0
blez $1, TAG500
mflo $4
sll $0, $0, 0
TAG500:
bne $4, $4, TAG501
or $2, $4, $4
srl $4, $2, 11
sll $0, $0, 0
TAG501:
slti $4, $1, 14
bgez $1, TAG502
mtlo $4
blez $4, TAG502
TAG502:
lh $4, 0($4)
slti $3, $4, 9
sll $2, $4, 1
beq $4, $2, TAG503
TAG503:
multu $2, $2
bltz $2, TAG504
sra $4, $2, 10
mtlo $2
TAG504:
mfhi $1
multu $4, $4
multu $4, $4
multu $1, $4
TAG505:
bltz $1, TAG506
mthi $1
mfhi $4
add $1, $1, $1
TAG506:
mflo $4
sh $4, 0($4)
mtlo $1
mflo $3
TAG507:
lui $4, 7
mflo $3
lh $3, 0($3)
slti $2, $4, 1
TAG508:
multu $2, $2
sb $2, 0($2)
beq $2, $2, TAG509
lhu $3, 0($2)
TAG509:
mflo $2
multu $3, $3
srl $2, $3, 3
lhu $2, 0($2)
TAG510:
slt $1, $2, $2
beq $1, $2, TAG511
sw $1, 0($1)
mflo $4
TAG511:
mfhi $3
sll $0, $0, 0
sltiu $2, $2, 9
bltz $2, TAG512
TAG512:
mflo $1
lh $3, 0($1)
lhu $1, 0($3)
mthi $3
TAG513:
sw $1, 0($1)
lw $2, 0($1)
addu $3, $1, $1
mult $2, $1
TAG514:
lui $3, 3
sll $0, $0, 0
add $1, $2, $2
mtlo $3
TAG515:
mflo $4
mtlo $4
multu $4, $1
multu $4, $1
TAG516:
and $3, $4, $4
blez $4, TAG517
sll $0, $0, 0
addu $4, $4, $3
TAG517:
slti $4, $4, 9
bltz $4, TAG518
multu $4, $4
multu $4, $4
TAG518:
lw $2, 0($4)
lw $2, 0($2)
sw $4, 0($4)
bne $2, $2, TAG519
TAG519:
lhu $2, 0($2)
srl $3, $2, 3
mfhi $4
lui $1, 12
TAG520:
mflo $2
mfhi $1
mfhi $4
addi $2, $1, 1
TAG521:
lbu $3, 0($2)
lui $3, 2
mthi $3
sllv $1, $2, $3
TAG522:
lui $4, 7
mflo $1
sll $0, $0, 0
sw $1, 0($1)
TAG523:
beq $1, $1, TAG524
mult $1, $1
bne $1, $1, TAG524
mult $1, $1
TAG524:
subu $2, $1, $1
blez $2, TAG525
mthi $2
mtlo $1
TAG525:
xor $2, $2, $2
mflo $3
bltz $2, TAG526
multu $2, $2
TAG526:
beq $3, $3, TAG527
lui $2, 4
mthi $3
bltz $3, TAG527
TAG527:
lui $1, 14
mfhi $2
mfhi $3
lh $2, 0($2)
TAG528:
mult $2, $2
mfhi $4
mtlo $2
lh $2, 0($2)
TAG529:
beq $2, $2, TAG530
multu $2, $2
or $2, $2, $2
slt $4, $2, $2
TAG530:
mtlo $4
lb $2, 0($4)
srav $4, $2, $2
mflo $1
TAG531:
sltiu $1, $1, 6
sllv $3, $1, $1
srlv $2, $3, $1
or $4, $1, $1
TAG532:
beq $4, $4, TAG533
lui $4, 10
srl $2, $4, 7
multu $4, $4
TAG533:
beq $2, $2, TAG534
sra $1, $2, 6
xori $2, $1, 14
mfhi $3
TAG534:
beq $3, $3, TAG535
lh $3, 0($3)
sra $3, $3, 13
mflo $1
TAG535:
mflo $2
mtlo $2
bgez $1, TAG536
sh $1, 0($1)
TAG536:
lb $1, 0($2)
bgez $2, TAG537
sh $1, 0($1)
lw $4, 0($1)
TAG537:
srlv $2, $4, $4
slt $3, $4, $4
sll $0, $0, 0
sll $0, $0, 0
TAG538:
sltiu $4, $3, 4
mflo $2
bgtz $2, TAG539
xor $2, $3, $4
TAG539:
divu $2, $2
bne $2, $2, TAG540
lb $2, 0($2)
sll $4, $2, 8
TAG540:
beq $4, $4, TAG541
lui $2, 15
sb $4, 0($2)
subu $1, $2, $4
TAG541:
mflo $1
sb $1, 0($1)
subu $1, $1, $1
lui $3, 2
TAG542:
blez $3, TAG543
sll $0, $0, 0
mtlo $3
sll $0, $0, 0
TAG543:
mfhi $1
blez $1, TAG544
mflo $2
lw $1, 0($1)
TAG544:
multu $1, $1
bltz $1, TAG545
lui $4, 10
bne $4, $1, TAG545
TAG545:
sll $0, $0, 0
sll $0, $0, 0
lui $1, 2
lui $4, 4
TAG546:
nor $4, $4, $4
mult $4, $4
sll $0, $0, 0
lui $2, 11
TAG547:
sltiu $4, $2, 8
addu $1, $2, $4
mthi $2
sll $0, $0, 0
TAG548:
beq $1, $1, TAG549
srlv $1, $1, $1
lhu $1, 0($1)
sltiu $1, $1, 12
TAG549:
bgez $1, TAG550
mfhi $4
lbu $2, 0($1)
sub $3, $4, $2
TAG550:
bne $3, $3, TAG551
xor $3, $3, $3
sh $3, 0($3)
lui $4, 7
TAG551:
blez $4, TAG552
mfhi $1
mfhi $3
sll $0, $0, 0
TAG552:
mthi $4
sll $0, $0, 0
sll $0, $0, 0
addu $4, $4, $4
TAG553:
lui $4, 15
sll $3, $4, 12
mflo $3
mflo $4
TAG554:
subu $3, $4, $4
multu $3, $4
mtlo $3
mflo $2
TAG555:
mthi $2
mfhi $4
lui $1, 15
sw $1, 0($2)
TAG556:
sllv $2, $1, $1
div $1, $2
multu $1, $2
multu $1, $2
TAG557:
mult $2, $2
sll $0, $0, 0
mtlo $2
subu $3, $2, $2
TAG558:
lhu $1, 0($3)
sw $1, 0($3)
blez $1, TAG559
srl $4, $1, 0
TAG559:
sra $4, $4, 14
lui $4, 8
mthi $4
sll $0, $0, 0
TAG560:
multu $4, $4
bne $4, $4, TAG561
mfhi $4
sh $4, 0($4)
TAG561:
mthi $4
addu $1, $4, $4
sw $4, 0($4)
multu $1, $4
TAG562:
lui $4, 8
xor $2, $4, $4
lui $1, 8
bgez $1, TAG563
TAG563:
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
bgtz $1, TAG564
TAG564:
sll $0, $0, 0
mthi $1
mflo $2
mfhi $1
TAG565:
lui $3, 3
divu $3, $1
divu $3, $3
bgez $1, TAG566
TAG566:
mflo $1
sra $2, $3, 8
sb $1, 0($1)
bgez $3, TAG567
TAG567:
lui $4, 12
mult $4, $2
divu $4, $2
div $4, $2
TAG568:
lui $4, 2
bgez $4, TAG569
mflo $1
mfhi $4
TAG569:
sll $0, $0, 0
bne $4, $4, TAG570
mult $4, $4
sll $0, $0, 0
TAG570:
sll $0, $0, 0
sll $0, $0, 0
divu $4, $1
bgez $1, TAG571
TAG571:
lui $2, 1
lh $4, -1024($1)
mthi $1
divu $1, $2
TAG572:
mflo $1
lui $2, 12
srlv $4, $1, $4
multu $1, $2
TAG573:
blez $4, TAG574
sb $4, 0($4)
andi $3, $4, 9
slti $3, $3, 6
TAG574:
beq $3, $3, TAG575
or $2, $3, $3
sub $4, $2, $3
lh $3, 0($2)
TAG575:
sll $0, $0, 0
sll $0, $0, 0
mult $3, $3
bne $3, $3, TAG576
TAG576:
lui $2, 1
sll $0, $0, 0
srl $3, $2, 4
lw $3, -4096($3)
TAG577:
beq $3, $3, TAG578
slt $2, $3, $3
div $3, $3
blez $3, TAG578
TAG578:
lbu $2, 0($2)
sub $1, $2, $2
blez $2, TAG579
slt $4, $1, $2
TAG579:
slt $3, $4, $4
bne $4, $3, TAG580
multu $3, $4
blez $3, TAG580
TAG580:
mthi $3
lui $4, 6
mtlo $4
sh $3, 0($3)
TAG581:
lui $3, 12
andi $4, $4, 12
sb $4, 0($4)
nor $2, $4, $3
TAG582:
beq $2, $2, TAG583
and $1, $2, $2
lw $4, 0($2)
mfhi $2
TAG583:
bgez $2, TAG584
lui $2, 9
mult $2, $2
slti $2, $2, 11
TAG584:
multu $2, $2
andi $1, $2, 10
bltz $1, TAG585
mfhi $2
TAG585:
multu $2, $2
mflo $2
lb $4, 0($2)
lbu $2, 0($4)
TAG586:
mthi $2
lbu $4, 0($2)
lui $3, 10
andi $1, $2, 13
TAG587:
mtlo $1
bltz $1, TAG588
addi $2, $1, 9
bltz $2, TAG588
TAG588:
addu $2, $2, $2
lui $2, 10
blez $2, TAG589
sll $0, $0, 0
TAG589:
lw $3, 0($1)
sw $3, 0($3)
mflo $3
lui $2, 7
TAG590:
div $2, $2
blez $2, TAG591
lui $3, 11
mthi $2
TAG591:
sll $0, $0, 0
divu $3, $3
mflo $2
srlv $1, $3, $2
TAG592:
sll $0, $0, 0
ori $2, $1, 4
sll $0, $0, 0
mflo $1
TAG593:
divu $1, $1
lui $1, 13
div $1, $1
beq $1, $1, TAG594
TAG594:
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
TAG595:
mflo $1
mult $4, $4
and $2, $4, $1
bltz $2, TAG596
TAG596:
mult $2, $2
beq $2, $2, TAG597
mult $2, $2
mflo $3
TAG597:
mtlo $3
lui $4, 5
lui $3, 7
sll $0, $0, 0
TAG598:
sll $0, $0, 0
sh $2, 0($2)
lw $2, 0($2)
bne $3, $2, TAG599
TAG599:
sb $2, 0($2)
lui $2, 5
mfhi $4
slti $3, $2, 13
TAG600:
mult $3, $3
sh $3, 0($3)
lui $2, 3
mfhi $4
TAG601:
mfhi $3
sw $3, 0($4)
subu $2, $3, $4
mfhi $1
TAG602:
mfhi $2
bgez $1, TAG603
mflo $2
sll $3, $2, 8
TAG603:
mfhi $2
sub $4, $3, $2
sra $1, $4, 13
and $4, $2, $2
TAG604:
bltz $4, TAG605
sw $4, 0($4)
bltz $4, TAG605
lh $3, 0($4)
TAG605:
bgez $3, TAG606
mtlo $3
mult $3, $3
lhu $1, 0($3)
TAG606:
sh $1, 0($1)
bltz $1, TAG607
mult $1, $1
lui $1, 15
TAG607:
bgez $1, TAG608
sll $0, $0, 0
lh $1, 0($1)
mthi $1
TAG608:
mthi $1
sll $0, $0, 0
lui $2, 12
sltiu $4, $2, 8
TAG609:
lb $3, 0($4)
sltu $4, $3, $3
mfhi $2
ori $4, $2, 15
TAG610:
mult $4, $4
sltiu $1, $4, 2
mtlo $1
lui $3, 9
TAG611:
lui $2, 5
mfhi $2
bne $2, $2, TAG612
ori $3, $2, 4
TAG612:
multu $3, $3
sb $3, -229($3)
sw $3, -229($3)
sw $3, -229($3)
TAG613:
andi $4, $3, 7
lui $2, 9
lui $1, 1
bgtz $3, TAG614
TAG614:
andi $2, $1, 11
sll $0, $0, 0
beq $2, $1, TAG615
lhu $4, 0($2)
TAG615:
lui $1, 6
mflo $2
mtlo $1
mthi $1
TAG616:
ori $2, $2, 1
sll $0, $0, 0
beq $2, $2, TAG617
sll $0, $0, 0
TAG617:
srav $4, $2, $2
addiu $3, $4, 11
sll $1, $3, 11
lui $1, 14
TAG618:
mult $1, $1
divu $1, $1
sra $3, $1, 11
sll $0, $0, 0
TAG619:
lui $4, 9
mfhi $2
mtlo $2
bgtz $4, TAG620
TAG620:
lh $1, 0($2)
bltz $2, TAG621
multu $1, $2
sh $2, 0($2)
TAG621:
bgtz $1, TAG622
srav $1, $1, $1
mtlo $1
sh $1, 0($1)
TAG622:
beq $1, $1, TAG623
mult $1, $1
mflo $4
sub $3, $1, $4
TAG623:
blez $3, TAG624
div $3, $3
bgez $3, TAG624
lb $1, -448($3)
TAG624:
xori $3, $1, 15
mtlo $1
lui $3, 15
beq $3, $3, TAG625
TAG625:
sll $0, $0, 0
lui $1, 12
sll $0, $0, 0
divu $3, $1
TAG626:
add $4, $2, $2
bltz $2, TAG627
lhu $2, 0($4)
beq $4, $2, TAG627
TAG627:
mthi $2
mflo $4
multu $4, $2
addi $1, $2, 9
TAG628:
sb $1, 0($1)
divu $1, $1
mfhi $3
mthi $3
TAG629:
bgtz $3, TAG630
xori $1, $3, 8
mflo $2
lh $1, 0($3)
TAG630:
mtlo $1
bltz $1, TAG631
mthi $1
sw $1, 0($1)
TAG631:
mult $1, $1
andi $1, $1, 3
sw $1, 0($1)
mthi $1
TAG632:
addi $3, $1, 3
mtlo $3
ori $2, $3, 3
lb $4, 0($2)
TAG633:
beq $4, $4, TAG634
addiu $1, $4, 11
addi $4, $1, 5
beq $4, $1, TAG634
TAG634:
mthi $4
sw $4, 0($4)
bgez $4, TAG635
nor $3, $4, $4
TAG635:
sra $4, $3, 15
bgez $4, TAG636
lui $2, 4
ori $1, $3, 8
TAG636:
beq $1, $1, TAG637
mflo $1
bltz $1, TAG637
divu $1, $1
TAG637:
ori $3, $1, 2
beq $3, $3, TAG638
srlv $1, $3, $3
bltz $3, TAG638
TAG638:
srav $2, $1, $1
lui $4, 9
mfhi $3
srav $3, $4, $2
TAG639:
addu $4, $3, $3
slti $2, $3, 4
sll $0, $0, 0
sll $0, $0, 0
TAG640:
mflo $2
bne $2, $2, TAG641
mflo $4
lb $1, 0($4)
TAG641:
bgez $1, TAG642
multu $1, $1
lui $3, 6
mthi $3
TAG642:
andi $1, $3, 8
bgez $1, TAG643
mult $1, $1
or $2, $1, $3
TAG643:
addiu $4, $2, 10
lui $1, 3
lui $1, 4
sb $1, 0($2)
TAG644:
slti $2, $1, 7
mult $2, $1
bltz $2, TAG645
mtlo $2
TAG645:
blez $2, TAG646
mthi $2
beq $2, $2, TAG646
mtlo $2
TAG646:
lw $1, 0($2)
blez $2, TAG647
lw $2, 0($1)
lw $2, 0($1)
TAG647:
sll $2, $2, 3
bltz $2, TAG648
lui $3, 1
bgez $2, TAG648
TAG648:
mfhi $2
ori $1, $2, 1
sll $0, $0, 0
lui $3, 2
TAG649:
sltiu $4, $3, 2
lui $4, 10
ori $3, $3, 1
mflo $2
TAG650:
beq $2, $2, TAG651
lui $3, 10
mult $3, $2
mtlo $3
TAG651:
sllv $2, $3, $3
bgez $3, TAG652
sll $0, $0, 0
divu $2, $3
TAG652:
lui $3, 5
bne $3, $3, TAG653
mthi $3
bltz $3, TAG653
TAG653:
div $3, $3
sll $0, $0, 0
beq $3, $3, TAG654
sll $0, $0, 0
TAG654:
sll $0, $0, 0
bne $2, $2, TAG655
sll $0, $0, 0
mfhi $3
TAG655:
mthi $3
lui $3, 2
sll $0, $0, 0
lui $1, 14
TAG656:
ori $3, $1, 1
srl $1, $3, 12
sll $0, $0, 0
lui $4, 2
TAG657:
mthi $4
beq $4, $4, TAG658
mflo $2
blez $4, TAG658
TAG658:
srl $1, $2, 6
lbu $4, 0($2)
lh $4, 0($1)
mfhi $4
TAG659:
mtlo $4
ori $2, $4, 11
bne $2, $4, TAG660
mflo $1
TAG660:
divu $1, $1
bgtz $1, TAG661
lui $2, 13
mult $2, $2
TAG661:
sll $0, $0, 0
addu $4, $2, $2
sll $0, $0, 0
bgez $4, TAG662
TAG662:
mfhi $2
lui $1, 14
sll $0, $0, 0
multu $1, $2
TAG663:
srav $3, $2, $2
bgtz $2, TAG664
sw $2, 0($2)
sra $2, $2, 6
TAG664:
bne $2, $2, TAG665
lb $2, 0($2)
bltz $2, TAG665
sw $2, 0($2)
TAG665:
mflo $2
bltz $2, TAG666
sll $2, $2, 2
mfhi $4
TAG666:
mtlo $4
sw $4, 0($4)
lui $3, 1
mflo $1
TAG667:
lw $4, 0($1)
blez $4, TAG668
lui $4, 9
bgtz $1, TAG668
TAG668:
sllv $4, $4, $4
mthi $4
addiu $3, $4, 1
beq $4, $4, TAG669
TAG669:
lui $2, 10
sll $0, $0, 0
ori $4, $3, 11
beq $3, $4, TAG670
TAG670:
mflo $4
mflo $2
mfhi $3
mtlo $2
TAG671:
lui $1, 5
addiu $3, $1, 1
div $1, $1
sll $0, $0, 0
TAG672:
mflo $3
nor $4, $3, $4
nor $1, $4, $4
mflo $3
TAG673:
multu $3, $3
bgtz $3, TAG674
ori $3, $3, 3
lui $2, 3
TAG674:
sltiu $2, $2, 1
bne $2, $2, TAG675
slti $4, $2, 13
sb $2, 0($2)
TAG675:
bne $4, $4, TAG676
lui $3, 7
mult $3, $4
mtlo $4
TAG676:
sll $0, $0, 0
lui $3, 2
bgez $3, TAG677
mflo $4
TAG677:
mfhi $4
mtlo $4
bne $4, $4, TAG678
sw $4, 0($4)
TAG678:
lb $2, 0($4)
lh $4, 0($4)
mflo $3
mflo $2
TAG679:
lb $3, 0($2)
mtlo $3
bgez $3, TAG680
mtlo $2
TAG680:
beq $3, $3, TAG681
sb $3, 0($3)
mfhi $3
multu $3, $3
TAG681:
bltz $3, TAG682
add $4, $3, $3
ori $4, $4, 15
sb $4, 0($4)
TAG682:
multu $4, $4
lb $3, 0($4)
sb $3, 0($4)
and $2, $4, $3
TAG683:
lb $1, 0($2)
mthi $1
mult $1, $1
lbu $1, 0($1)
TAG684:
div $1, $1
sltiu $2, $1, 2
lui $4, 15
xor $3, $1, $4
TAG685:
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
mfhi $3
TAG686:
xori $4, $3, 1
and $3, $4, $3
lui $1, 14
sw $1, 0($3)
TAG687:
mflo $2
lui $1, 10
lui $1, 7
lui $3, 2
TAG688:
addiu $4, $3, 3
mtlo $4
mtlo $3
srlv $2, $3, $3
TAG689:
andi $2, $2, 9
xori $4, $2, 6
multu $2, $2
sh $2, 0($4)
TAG690:
sh $4, 0($4)
mflo $1
srl $4, $1, 15
sw $4, 0($1)
TAG691:
lui $4, 2
srav $1, $4, $4
beq $1, $1, TAG692
srlv $3, $4, $4
TAG692:
nor $3, $3, $3
bne $3, $3, TAG693
sll $0, $0, 0
lui $2, 0
TAG693:
addiu $2, $2, 1
mfhi $2
multu $2, $2
srl $1, $2, 7
TAG694:
mthi $1
multu $1, $1
slti $2, $1, 14
bgtz $2, TAG695
TAG695:
lb $3, 0($2)
blez $2, TAG696
lui $1, 3
multu $1, $1
TAG696:
mtlo $1
sll $0, $0, 0
bne $1, $1, TAG697
mfhi $1
TAG697:
mthi $1
mthi $1
bltz $1, TAG698
mthi $1
TAG698:
lui $2, 7
mtlo $1
mflo $4
mult $1, $2
TAG699:
multu $4, $4
lbu $2, 0($4)
multu $4, $2
blez $4, TAG700
TAG700:
sltiu $2, $2, 2
lhu $3, 0($2)
sh $3, 0($3)
sub $4, $2, $3
TAG701:
addiu $4, $4, 14
andi $3, $4, 7
lui $3, 13
bne $4, $4, TAG702
TAG702:
andi $1, $3, 12
lui $3, 0
lbu $2, 0($3)
mthi $1
TAG703:
mthi $2
bgtz $2, TAG704
sb $2, 0($2)
lui $3, 12
TAG704:
sll $0, $0, 0
mthi $3
mult $3, $1
lui $4, 7
TAG705:
div $4, $4
lui $3, 14
mfhi $1
lui $3, 12
TAG706:
sllv $3, $3, $3
mthi $3
addu $2, $3, $3
mtlo $3
TAG707:
mfhi $2
beq $2, $2, TAG708
lui $4, 7
blez $2, TAG708
TAG708:
sll $0, $0, 0
lui $1, 5
blez $4, TAG709
sll $0, $0, 0
TAG709:
mtlo $1
sllv $3, $1, $1
or $4, $1, $3
mult $1, $4
TAG710:
lui $4, 4
bne $4, $4, TAG711
mfhi $1
lui $2, 1
TAG711:
mflo $2
add $2, $2, $2
bne $2, $2, TAG712
addiu $4, $2, 15
TAG712:
lui $4, 10
srlv $1, $4, $4
beq $4, $1, TAG713
mthi $4
TAG713:
xor $1, $1, $1
mult $1, $1
multu $1, $1
mult $1, $1
TAG714:
mult $1, $1
multu $1, $1
srl $4, $1, 2
mfhi $1
TAG715:
lb $1, 0($1)
mfhi $4
ori $3, $1, 13
mfhi $4
TAG716:
bne $4, $4, TAG717
mult $4, $4
lh $1, 0($4)
slti $2, $1, 9
TAG717:
lbu $4, 0($2)
srlv $1, $2, $2
mtlo $1
mflo $4
TAG718:
ori $2, $4, 3
lui $2, 1
mtlo $2
lui $1, 13
TAG719:
srl $2, $1, 1
mfhi $3
lui $3, 15
sll $0, $0, 0
TAG720:
beq $3, $3, TAG721
sll $0, $0, 0
sh $3, 0($3)
srlv $3, $3, $3
TAG721:
sll $0, $0, 0
sra $3, $3, 9
and $3, $3, $3
sra $3, $3, 2
TAG722:
sll $1, $3, 10
lui $3, 4
mtlo $3
sltiu $1, $1, 3
TAG723:
add $2, $1, $1
lui $2, 3
bgez $2, TAG724
xori $4, $1, 1
TAG724:
mflo $4
mfhi $3
bgtz $3, TAG725
sllv $4, $3, $4
TAG725:
bne $4, $4, TAG726
mtlo $4
lbu $2, 0($4)
blez $2, TAG726
TAG726:
add $4, $2, $2
lbu $4, 0($2)
bne $2, $4, TAG727
mtlo $4
TAG727:
beq $4, $4, TAG728
mtlo $4
lui $1, 1
blez $1, TAG728
TAG728:
sw $1, 0($1)
mult $1, $1
lhu $1, 0($1)
mflo $1
TAG729:
sltiu $3, $1, 14
and $1, $3, $3
sb $3, 0($3)
slti $3, $1, 11
TAG730:
lui $3, 13
or $2, $3, $3
bltz $3, TAG731
mfhi $1
TAG731:
beq $1, $1, TAG732
srav $2, $1, $1
mtlo $2
mult $1, $2
TAG732:
bgez $2, TAG733
and $4, $2, $2
bgtz $4, TAG733
lui $4, 4
TAG733:
mthi $4
beq $4, $4, TAG734
addi $2, $4, 11
mtlo $4
TAG734:
mthi $2
lui $2, 6
mfhi $4
blez $4, TAG735
TAG735:
mfhi $3
bne $4, $4, TAG736
div $4, $3
bne $3, $4, TAG736
TAG736:
srl $2, $3, 8
lui $2, 10
mflo $2
slt $2, $2, $2
TAG737:
lui $2, 3
mflo $4
mflo $2
addu $2, $2, $4
TAG738:
mfhi $1
divu $2, $2
beq $2, $2, TAG739
mult $2, $1
TAG739:
lui $1, 12
sll $0, $0, 0
bne $1, $1, TAG740
sll $0, $0, 0
TAG740:
mtlo $1
mthi $1
bne $1, $1, TAG741
sll $0, $0, 0
TAG741:
sb $2, 0($2)
div $2, $2
lb $1, 0($2)
beq $2, $1, TAG742
TAG742:
lhu $2, 0($1)
beq $2, $1, TAG743
mfhi $3
lui $3, 6
TAG743:
mthi $3
mfhi $4
lui $1, 7
mult $1, $3
TAG744:
srav $3, $1, $1
mfhi $1
slt $2, $3, $3
lbu $3, 0($1)
TAG745:
lb $2, 0($3)
mtlo $3
bltz $3, TAG746
mtlo $3
TAG746:
blez $2, TAG747
mflo $4
xori $1, $2, 9
bgez $4, TAG747
TAG747:
mtlo $1
sh $1, 0($1)
lb $3, 0($1)
mfhi $4
TAG748:
bltz $4, TAG749
mthi $4
andi $1, $4, 14
mult $4, $1
TAG749:
multu $1, $1
sltiu $3, $1, 12
beq $3, $3, TAG750
sll $3, $1, 0
TAG750:
nop
nop
test_end:
beq $0, $0, test_end
nop |
PewterGymObject:
db $3 ; border block
db $2 ; warps
db $d, $4, $2, $ff
db $d, $5, $2, $ff
db $0 ; signs
db $3 ; objects
object SPRITE_BLACK_HAIR_BOY_2, $4, $1, STAY, DOWN, $1, OPP_BROCK, $1
object SPRITE_BLACK_HAIR_BOY_1, $3, $6, STAY, RIGHT, $2, OPP_JR_TRAINER_M, $1
object SPRITE_GYM_HELPER, $7, $a, STAY, DOWN, $3 ; person
; warp-to
EVENT_DISP PEWTER_GYM_WIDTH, $d, $4
EVENT_DISP PEWTER_GYM_WIDTH, $d, $5
|
db "TRANSFORM@" ; species name
dw 100, 90 ; height, weight
db "When it encount-"
next "ers another DITTO,"
next "it will move"
page "faster than normal"
next "to duplicate that"
next "opponent exactly.@"
|
lda {c1},y
sta {m1}
lda {c1}+1,y
sta {m1}+1
lda {c1}+2,y
sta {m1}+2
lda {c1}+3,y
sta {m1}+3
|
; A287657: {0->01, 1->10}-transform of the infinite Fibonacci word A003849.
; 0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,1,0,1,1,0,0,1,1,0
cal $0,187576 ; Rank transform of the sequence 2*floor((n-1)/2)); complement of A187577.
gcd $0,2
mov $1,$0
sub $1,1
|
copyright zengfr site:http://github.com/zengfr/romhack
005EB4 bne $5fe2
005EC2 bne $66da
005F4A bne $5fe2
006086 bne $66da
006150 bne $66da
006170 bne $5fe2
0062F2 bne $5fe2
006302 bne $66da
006324 bne $5fe2
006688 bne $5fe2
01A610 dbra D1, $1a60e
04C7D8 beq $4c802
058F62 beq $58f78
05905C beq $59064
0590D2 beq $590fa
0597FE beq $59838
05E186 beq $5e450
05E7F6 bpl $5e80a
05E868 bpl $5e87c
05E8BA beq $5e8c4
copyright zengfr site:http://github.com/zengfr/romhack
|
; off_t lseek(int fd, off_t offset, int whence)
SECTION code_fcntl
PUBLIC lseek_callee, l0_lseek_callee
EXTERN asm_lseek
lseek_callee:
pop bc
exx
pop bc
ld a,c
pop hl
pop de
pop bc
l0_lseek_callee:
exx
push bc
exx
jp asm_lseek
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.