text
stringlengths
1
1.05M
[bits 16] switch_to_pm: cli ;switch off interupts lgdt [gdt_descriptor] ;load GDT mov eax, cr0 ;set the first bit of CR0 or eax, 0x1 mov cr0, eax jmp CODE_SEGMENT:init_pm ;make a far jump,forces CPU to flush cache and pre-fetched and real-mode instructions [bits 32] init_pm: mov ax, DATA_SEGMENT ;In protected mode old segments are meaningless, point segment registers to the data selector in GDT mov ds, ax mov ss, ax mov es, ax mov fs, ax mov gs, ax mov ebp, 0x90000 ;Update stack position mov esp, ebp call BEGIN_PM
#include <eros/SafetyNode/SafetyNode.h> using namespace eros; using namespace eros_nodes; bool kill_node = false; SafetyNode::SafetyNode() : system_command_action_server( *n.get(), read_robotnamespace() + "SystemCommandAction", boost::bind(&SafetyNode::system_commandAction_Callback, this, _1), false) { system_command_action_server.start(); } SafetyNode::~SafetyNode() { } void SafetyNode::system_commandAction_Callback(const eros::system_commandGoalConstPtr &goal) { (void)goal; eros::system_commandResult system_commandResult_; system_command_action_server.setAborted(system_commandResult_); } void SafetyNode::command_Callback(const eros::command::ConstPtr &t_msg) { process->new_commandmsg(BaseNodeProcess::convert_fromptr(t_msg)); } bool SafetyNode::changenodestate_service(eros::srv_change_nodestate::Request &req, eros::srv_change_nodestate::Response &res) { Node::State req_state = Node::NodeState(req.RequestedNodeState); process->request_statechange(req_state); res.NodeState = Node::NodeStateString(process->get_nodestate()); return true; } bool SafetyNode::start() { initialize_diagnostic(DIAGNOSTIC_SYSTEM, DIAGNOSTIC_SUBSYSTEM, DIAGNOSTIC_COMPONENT); bool status = false; process = new SafetyNodeProcess(); set_basenodename(BASE_NODE_NAME); initialize_firmware( MAJOR_RELEASE_VERSION, MINOR_RELEASE_VERSION, BUILD_NUMBER, FIRMWARE_DESCRIPTION); disable_armedstate_sub(); diagnostic = preinitialize_basenode(); if (diagnostic.level > Level::Type::WARN) { return false; } diagnostic = read_launchparameters(); if (diagnostic.level > Level::Type::WARN) { return false; } process->initialize(get_basenodename(), get_nodename(), get_hostname(), DIAGNOSTIC_SYSTEM, DIAGNOSTIC_SUBSYSTEM, DIAGNOSTIC_COMPONENT, logger); std::vector<Diagnostic::DiagnosticType> diagnostic_types; diagnostic_types.push_back(Diagnostic::DiagnosticType::SOFTWARE); diagnostic_types.push_back(Diagnostic::DiagnosticType::DATA_STORAGE); diagnostic_types.push_back(Diagnostic::DiagnosticType::SYSTEM_RESOURCE); diagnostic_types.push_back(Diagnostic::DiagnosticType::REMOTE_CONTROL); diagnostic_types.push_back(Diagnostic::DiagnosticType::COMMUNICATIONS); process->enable_diagnostics(diagnostic_types); process->finish_initialization(); diagnostic = finish_initialization(); if (diagnostic.level > Level::Type::WARN) { return false; } if (diagnostic.level < Level::Type::WARN) { diagnostic.type = Diagnostic::DiagnosticType::SOFTWARE; diagnostic.level = Level::Type::INFO; diagnostic.message = Diagnostic::Message::NOERROR; diagnostic.description = "Node Configured. Initializing."; get_logger()->log_diagnostic(diagnostic); } if (process->request_statechange(Node::State::INITIALIZED) == false) { logger->log_warn("Unable to Change State to: " + Node::NodeStateString(Node::State::INITIALIZED)); } if (process->request_statechange(Node::State::RUNNING) == false) { logger->log_warn("Unable to Change State to: " + Node::NodeStateString(Node::State::RUNNING)); } logger->log_notice("Node State: " + Node::NodeStateString(process->get_nodestate())); status = true; return status; } Diagnostic::DiagnosticDefinition SafetyNode::read_launchparameters() { Diagnostic::DiagnosticDefinition diag = diagnostic; get_logger()->log_notice("Configuration Files Loaded."); return diag; } Diagnostic::DiagnosticDefinition SafetyNode::finish_initialization() { Diagnostic::DiagnosticDefinition diag = diagnostic; std::string srv_nodestate_topic = node_name + "/srv_nodestate_change"; nodestate_srv = n->advertiseService(srv_nodestate_topic, &SafetyNode::changenodestate_service, this); armedstate_pub = n->advertise<eros::armed_state>(get_robotnamespace() + "/ArmedState", 2); command_sub = n->subscribe<eros::command>( get_robotnamespace() + "SystemCommand", 10, &SafetyNode::command_Callback, this); diag = process->update_diagnostic(Diagnostic::DiagnosticType::SOFTWARE, Level::Type::INFO, Diagnostic::Message::NOERROR, "Running"); diag = process->update_diagnostic(Diagnostic::DiagnosticType::DATA_STORAGE, Level::Type::INFO, Diagnostic::Message::NOERROR, "All Configuration Files Loaded."); // Read Ready To Arm Topics std::vector<std::string> topics; std::vector<ArmDisarmMonitor::Type> types; uint16_t counter = 0; bool valid_arm_topic = true; while (valid_arm_topic == true) { char param_topic[512]; sprintf(param_topic, "%s/ReadyToArm_Topic_%03d", node_name.c_str(), counter); std::string topic; if (n->getParam(param_topic, topic) == true) { logger->log_notice("Subscribing to ReadyToArm Topic: " + topic); topics.push_back(topic); } else { valid_arm_topic = false; break; } char param_type[512]; sprintf(param_type, "%s/ReadyToArm_Type_%03d", node_name.c_str(), counter); std::string type_str; if (n->getParam(param_type, type_str) == true) { ArmDisarmMonitor::Type type = ArmDisarmMonitor::TypeEnum(type_str); if (type != ArmDisarmMonitor::Type::UNKNOWN) { types.push_back(type); } } else { valid_arm_topic = false; break; } counter++; } if (process->initialize_readytoarm_monitors(topics, types) == false) { diag = process->update_diagnostic(Diagnostic::DiagnosticType::DATA_STORAGE, Level::Type::ERROR, Diagnostic::Message::INITIALIZING_ERROR, "Unable to initialize Ready To Arm Monitors."); logger->log_diagnostic(diag); return diag; } if (process->init_ros(n) == false) { diag = process->update_diagnostic(Diagnostic::DiagnosticType::COMMUNICATIONS, Level::Type::ERROR, Diagnostic::Message::INITIALIZING_ERROR, "Unable to initialize ROS in Safety Node Process"); logger->log_diagnostic(diag); return diag; } return diag; } bool SafetyNode::run_loop1() { return true; } bool SafetyNode::run_loop2() { return true; } bool SafetyNode::run_loop3() { return true; } bool SafetyNode::run_001hz() { return true; } bool SafetyNode::run_01hz() { return true; } bool SafetyNode::run_01hz_noisy() { { std::vector<std::string> cannotarm_reasons = process->get_cannotarm_reasons(); for (auto reason : cannotarm_reasons) { logger->log_warn(reason); } } Diagnostic::DiagnosticDefinition diag = diagnostic; logger->log_notice("Node State: " + Node::NodeStateString(process->get_nodestate())); return true; } bool SafetyNode::run_1hz() { std::vector<Diagnostic::DiagnosticDefinition> latest_diagnostics = process->get_latest_diagnostics(); for (std::size_t i = 0; i < latest_diagnostics.size(); ++i) { logger->log_diagnostic(latest_diagnostics.at(i)); diagnostic_pub.publish(process->convert(latest_diagnostics.at(i))); } Diagnostic::DiagnosticDefinition diag = process->get_root_diagnostic(); if (process->get_nodestate() == Node::State::RESET) { base_reset(); process->reset(); logger->log_notice("Node has Reset"); if (process->request_statechange(Node::State::RUNNING) == false) { diag = process->update_diagnostic(Diagnostic::DiagnosticType::SOFTWARE, Level::Type::ERROR, Diagnostic::Message::DEVICE_NOT_AVAILABLE, "Not able to Change Node State to Running."); logger->log_diagnostic(diag); } } return true; } bool SafetyNode::run_10hz() { update_diagnostics(process->get_diagnostics()); Diagnostic::DiagnosticDefinition diag = process->update(0.1, ros::Time::now().toSec()); if (diag.level >= Level::Type::NOTICE) { logger->log_diagnostic(diag); } armedstate_pub.publish(process->convert(process->get_armed_state())); return true; } void SafetyNode::thread_loop() { while (kill_node == false) { ros::Duration(1.0).sleep(); } } void SafetyNode::cleanup() { process->request_statechange(Node::State::FINISHED); process->cleanup(); delete process; base_cleanup(); } void signalinterrupt_handler(int sig) { printf("Killing SafetyNode with Signal: %d\n", sig); kill_node = true; exit(0); } int main(int argc, char **argv) { signal(SIGINT, signalinterrupt_handler); signal(SIGTERM, signalinterrupt_handler); ros::init(argc, argv, "safety_node"); SafetyNode *node = new SafetyNode(); bool status = node->start(); if (status == false) { return EXIT_FAILURE; } std::thread thread(&SafetyNode::thread_loop, node); while ((status == true) and (kill_node == false)) { status = node->update(node->get_process()->get_nodestate()); } node->cleanup(); thread.detach(); delete node; return 0; }
// dear imgui: Renderer for DirectX11 // This needs to be used along with a Platform Binding (e.g. Win32) // Implemented features: // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp // https://github.com/ocornut/imgui // CHANGELOG // (minor and older changes stripped away, please see git history for details) // 2020-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. // 2019-08-01: DirectX11: Fixed code querying the Geometry Shader state (would generally error with Debug layer enabled). // 2019-07-21: DirectX11: Backup, clear and restore Geometry Shader is any is bound when calling ImGui_ImplDX10_RenderDrawData. Clearing Hull/Domain/Compute shaders without backup/restore. // 2019-05-29: DirectX11: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag. // 2019-04-30: DirectX11: Added support for special ImDrawCallback_ResetRenderState callback to reset render state. // 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile(). // 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window. // 2018-08-01: DirectX11: Querying for IDXGIFactory instead of IDXGIFactory1 to increase compatibility. // 2018-07-13: DirectX11: Fixed unreleased resources in Init and Shutdown functions. // 2018-06-08: Misc: Extracted imgui_impl_dx11.cpp/.h away from the old combined DX11+Win32 example. // 2018-06-08: DirectX11: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle. // 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplDX11_RenderDrawData() in the .h file so you can call it yourself. // 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves. // 2016-05-07: DirectX11: Disabling depth-write. #include "imgui.h" #include "imgui_impl_dx11.h" // DirectX #include <stdio.h> #include <d3d11.h> #include <d3dcompiler.h> #ifdef _MSC_VER #pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below. #endif // DirectX data static ID3D11Device* g_pd3dDevice = NULL; static ID3D11DeviceContext* g_pd3dDeviceContext = NULL; static IDXGIFactory* g_pFactory = NULL; static ID3D11Buffer* g_pVB = NULL; static ID3D11Buffer* g_pIB = NULL; static ID3D10Blob* g_pVertexShaderBlob = NULL; static ID3D11VertexShader* g_pVertexShader = NULL; static ID3D11InputLayout* g_pInputLayout = NULL; static ID3D11Buffer* g_pVertexConstantBuffer = NULL; static ID3D10Blob* g_pPixelShaderBlob = NULL; static ID3D11PixelShader* g_pPixelShader = NULL; static ID3D11SamplerState* g_pFontSampler = NULL; static ID3D11ShaderResourceView*g_pFontTextureView = NULL; static ID3D11RasterizerState* g_pRasterizerState = NULL; static ID3D11BlendState* g_pBlendState = NULL; static ID3D11DepthStencilState* g_pDepthStencilState = NULL; static int g_VertexBufferSize = 5000, g_IndexBufferSize = 10000; struct VERTEX_CONSTANT_BUFFER { float mvp[4][4]; }; // Forward Declarations static void ImGui_ImplDX11_InitPlatformInterface(); static void ImGui_ImplDX11_ShutdownPlatformInterface(); static void ImGui_ImplDX11_SetupRenderState(ImDrawData* draw_data, ID3D11DeviceContext* ctx) { // Setup viewport D3D11_VIEWPORT vp; memset(&vp, 0, sizeof(D3D11_VIEWPORT)); vp.Width = draw_data->DisplaySize.x; vp.Height = draw_data->DisplaySize.y; vp.MinDepth = 0.0f; vp.MaxDepth = 1.0f; vp.TopLeftX = vp.TopLeftY = 0; ctx->RSSetViewports(1, &vp); // Setup shader and vertex buffers unsigned int stride = sizeof(ImDrawVert); unsigned int offset = 0; ctx->IASetInputLayout(g_pInputLayout); ctx->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset); ctx->IASetIndexBuffer(g_pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0); ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); ctx->VSSetShader(g_pVertexShader, NULL, 0); ctx->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer); ctx->PSSetShader(g_pPixelShader, NULL, 0); ctx->PSSetSamplers(0, 1, &g_pFontSampler); ctx->GSSetShader(NULL, NULL, 0); ctx->HSSetShader(NULL, NULL, 0); // In theory we should backup and restore this as well.. very infrequently used.. ctx->DSSetShader(NULL, NULL, 0); // In theory we should backup and restore this as well.. very infrequently used.. ctx->CSSetShader(NULL, NULL, 0); // In theory we should backup and restore this as well.. very infrequently used.. // Setup blend state const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f }; ctx->OMSetBlendState(g_pBlendState, blend_factor, 0xffffffff); ctx->OMSetDepthStencilState(g_pDepthStencilState, 0); ctx->RSSetState(g_pRasterizerState); } // Render function // (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop) void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data) { // Avoid rendering when minimized if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f) return; ID3D11DeviceContext* ctx = g_pd3dDeviceContext; // Create and grow vertex/index buffers if needed if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount) { if (g_pVB) { g_pVB->Release(); g_pVB = NULL; } g_VertexBufferSize = draw_data->TotalVtxCount + 5000; D3D11_BUFFER_DESC desc; memset(&desc, 0, sizeof(D3D11_BUFFER_DESC)); desc.Usage = D3D11_USAGE_DYNAMIC; desc.ByteWidth = g_VertexBufferSize * sizeof(ImDrawVert); desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; desc.MiscFlags = 0; if (g_pd3dDevice->CreateBuffer(&desc, NULL, &g_pVB) < 0) return; } if (!g_pIB || g_IndexBufferSize < draw_data->TotalIdxCount) { if (g_pIB) { g_pIB->Release(); g_pIB = NULL; } g_IndexBufferSize = draw_data->TotalIdxCount + 10000; D3D11_BUFFER_DESC desc; memset(&desc, 0, sizeof(D3D11_BUFFER_DESC)); desc.Usage = D3D11_USAGE_DYNAMIC; desc.ByteWidth = g_IndexBufferSize * sizeof(ImDrawIdx); desc.BindFlags = D3D11_BIND_INDEX_BUFFER; desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; if (g_pd3dDevice->CreateBuffer(&desc, NULL, &g_pIB) < 0) return; } // Upload vertex/index data into a single contiguous GPU buffer D3D11_MAPPED_SUBRESOURCE vtx_resource, idx_resource; if (ctx->Map(g_pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &vtx_resource) != S_OK) return; if (ctx->Map(g_pIB, 0, D3D11_MAP_WRITE_DISCARD, 0, &idx_resource) != S_OK) return; ImDrawVert* vtx_dst = (ImDrawVert*)vtx_resource.pData; ImDrawIdx* idx_dst = (ImDrawIdx*)idx_resource.pData; for (int n = 0; n < draw_data->CmdListsCount; n++) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert)); memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); vtx_dst += cmd_list->VtxBuffer.Size; idx_dst += cmd_list->IdxBuffer.Size; } ctx->Unmap(g_pVB, 0); ctx->Unmap(g_pIB, 0); // Setup orthographic projection matrix into our constant buffer // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps. { D3D11_MAPPED_SUBRESOURCE mapped_resource; if (ctx->Map(g_pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK) return; VERTEX_CONSTANT_BUFFER* constant_buffer = (VERTEX_CONSTANT_BUFFER*)mapped_resource.pData; float L = draw_data->DisplayPos.x; float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x; float T = draw_data->DisplayPos.y; float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y; float mvp[4][4] = { { 2.0f/(R-L), 0.0f, 0.0f, 0.0f }, { 0.0f, 2.0f/(T-B), 0.0f, 0.0f }, { 0.0f, 0.0f, 0.5f, 0.0f }, { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f }, }; memcpy(&constant_buffer->mvp, mvp, sizeof(mvp)); ctx->Unmap(g_pVertexConstantBuffer, 0); } // Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and verbose. Close your eyes!) struct BACKUP_DX11_STATE { UINT ScissorRectsCount, ViewportsCount; D3D11_RECT ScissorRects[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; D3D11_VIEWPORT Viewports[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; ID3D11RasterizerState* RS; ID3D11BlendState* BlendState; FLOAT BlendFactor[4]; UINT SampleMask; UINT StencilRef; ID3D11DepthStencilState* DepthStencilState; ID3D11ShaderResourceView* PSShaderResource; ID3D11SamplerState* PSSampler; ID3D11PixelShader* PS; ID3D11VertexShader* VS; ID3D11GeometryShader* GS; UINT PSInstancesCount, VSInstancesCount, GSInstancesCount; ID3D11ClassInstance *PSInstances[256], *VSInstances[256], *GSInstances[256]; // 256 is max according to PSSetShader documentation D3D11_PRIMITIVE_TOPOLOGY PrimitiveTopology; ID3D11Buffer* IndexBuffer, *VertexBuffer, *VSConstantBuffer; UINT IndexBufferOffset, VertexBufferStride, VertexBufferOffset; DXGI_FORMAT IndexBufferFormat; ID3D11InputLayout* InputLayout; }; BACKUP_DX11_STATE old; old.ScissorRectsCount = old.ViewportsCount = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ctx->RSGetScissorRects(&old.ScissorRectsCount, old.ScissorRects); ctx->RSGetViewports(&old.ViewportsCount, old.Viewports); ctx->RSGetState(&old.RS); ctx->OMGetBlendState(&old.BlendState, old.BlendFactor, &old.SampleMask); ctx->OMGetDepthStencilState(&old.DepthStencilState, &old.StencilRef); ctx->PSGetShaderResources(0, 1, &old.PSShaderResource); ctx->PSGetSamplers(0, 1, &old.PSSampler); old.PSInstancesCount = old.VSInstancesCount = old.GSInstancesCount = 256; ctx->PSGetShader(&old.PS, old.PSInstances, &old.PSInstancesCount); ctx->VSGetShader(&old.VS, old.VSInstances, &old.VSInstancesCount); ctx->VSGetConstantBuffers(0, 1, &old.VSConstantBuffer); ctx->GSGetShader(&old.GS, old.GSInstances, &old.GSInstancesCount); ctx->IAGetPrimitiveTopology(&old.PrimitiveTopology); ctx->IAGetIndexBuffer(&old.IndexBuffer, &old.IndexBufferFormat, &old.IndexBufferOffset); ctx->IAGetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); ctx->IAGetInputLayout(&old.InputLayout); // Setup desired DX state ImGui_ImplDX11_SetupRenderState(draw_data, ctx); // Render command lists // (Because we merged all buffers into a single one, we maintain our own offset into them) int global_idx_offset = 0; int global_vtx_offset = 0; ImVec2 clip_off = draw_data->DisplayPos; for (int n = 0; n < draw_data->CmdListsCount; n++) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; if (pcmd->UserCallback != NULL) { // User callback, registered via ImDrawList::AddCallback() // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.) if (pcmd->UserCallback == ImDrawCallback_ResetRenderState) ImGui_ImplDX11_SetupRenderState(draw_data, ctx); else pcmd->UserCallback(cmd_list, pcmd); } else { // Apply scissor/clipping rectangle const D3D11_RECT r = { (LONG)(pcmd->ClipRect.x - clip_off.x), (LONG)(pcmd->ClipRect.y - clip_off.y), (LONG)(pcmd->ClipRect.z - clip_off.x), (LONG)(pcmd->ClipRect.w - clip_off.y) }; ctx->RSSetScissorRects(1, &r); // Bind texture, Draw ID3D11ShaderResourceView* texture_srv = (ID3D11ShaderResourceView*)pcmd->TextureId; ctx->PSSetShaderResources(0, 1, &texture_srv); ctx->DrawIndexed(pcmd->ElemCount, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset); } } global_idx_offset += cmd_list->IdxBuffer.Size; global_vtx_offset += cmd_list->VtxBuffer.Size; } // Restore modified DX state ctx->RSSetScissorRects(old.ScissorRectsCount, old.ScissorRects); ctx->RSSetViewports(old.ViewportsCount, old.Viewports); ctx->RSSetState(old.RS); if (old.RS) old.RS->Release(); ctx->OMSetBlendState(old.BlendState, old.BlendFactor, old.SampleMask); if (old.BlendState) old.BlendState->Release(); ctx->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef); if (old.DepthStencilState) old.DepthStencilState->Release(); ctx->PSSetShaderResources(0, 1, &old.PSShaderResource); if (old.PSShaderResource) old.PSShaderResource->Release(); ctx->PSSetSamplers(0, 1, &old.PSSampler); if (old.PSSampler) old.PSSampler->Release(); ctx->PSSetShader(old.PS, old.PSInstances, old.PSInstancesCount); if (old.PS) old.PS->Release(); for (UINT i = 0; i < old.PSInstancesCount; i++) if (old.PSInstances[i]) old.PSInstances[i]->Release(); ctx->VSSetShader(old.VS, old.VSInstances, old.VSInstancesCount); if (old.VS) old.VS->Release(); ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer); if (old.VSConstantBuffer) old.VSConstantBuffer->Release(); ctx->GSSetShader(old.GS, old.GSInstances, old.GSInstancesCount); if (old.GS) old.GS->Release(); for (UINT i = 0; i < old.VSInstancesCount; i++) if (old.VSInstances[i]) old.VSInstances[i]->Release(); ctx->IASetPrimitiveTopology(old.PrimitiveTopology); ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release(); ctx->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); if (old.VertexBuffer) old.VertexBuffer->Release(); ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release(); } static void ImGui_ImplDX11_CreateFontsTexture() { // Build texture atlas ImGuiIO& io = ImGui::GetIO(); unsigned char* pixels; int width, height; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Upload texture to graphics system { D3D11_TEXTURE2D_DESC desc; ZeroMemory(&desc, sizeof(desc)); desc.Width = width; desc.Height = height; desc.MipLevels = 1; desc.ArraySize = 1; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.SampleDesc.Count = 1; desc.Usage = D3D11_USAGE_DEFAULT; desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; desc.CPUAccessFlags = 0; ID3D11Texture2D *pTexture = NULL; D3D11_SUBRESOURCE_DATA subResource; subResource.pSysMem = pixels; subResource.SysMemPitch = desc.Width * 4; subResource.SysMemSlicePitch = 0; g_pd3dDevice->CreateTexture2D(&desc, &subResource, &pTexture); // Create texture view D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; ZeroMemory(&srvDesc, sizeof(srvDesc)); srvDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MipLevels = desc.MipLevels; srvDesc.Texture2D.MostDetailedMip = 0; g_pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, &g_pFontTextureView); pTexture->Release(); } // Store our identifier io.Fonts->TexID = (ImTextureID)g_pFontTextureView; // Create texture sampler { D3D11_SAMPLER_DESC desc; ZeroMemory(&desc, sizeof(desc)); desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; desc.MipLODBias = 0.f; desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; desc.MinLOD = 0.f; desc.MaxLOD = 0.f; g_pd3dDevice->CreateSamplerState(&desc, &g_pFontSampler); } } bool ImGui_ImplDX11_CreateDeviceObjects() { if (!g_pd3dDevice) return false; if (g_pFontSampler) ImGui_ImplDX11_InvalidateDeviceObjects(); // By using D3DCompile() from <d3dcompiler.h> / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A) // If you would like to use this DX11 sample code but remove this dependency you can: // 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution] // 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL. // See https://github.com/ocornut/imgui/pull/638 for sources and details. // Create the vertex shader { static const char* vertexShader = "cbuffer vertexBuffer : register(b0) \ {\ float4x4 ProjectionMatrix; \ };\ struct VS_INPUT\ {\ float2 pos : POSITION;\ float4 col : COLOR0;\ float2 uv : TEXCOORD0;\ };\ \ struct PS_INPUT\ {\ float4 pos : SV_POSITION;\ float4 col : COLOR0;\ float2 uv : TEXCOORD0;\ };\ \ PS_INPUT main(VS_INPUT input)\ {\ PS_INPUT output;\ output.pos = mul( ProjectionMatrix, float4(input.pos.xy, 0.f, 1.f));\ output.col = input.col;\ output.uv = input.uv;\ return output;\ }"; D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_4_0", 0, 0, &g_pVertexShaderBlob, NULL); if (g_pVertexShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! return false; if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), NULL, &g_pVertexShader) != S_OK) return false; // Create the input layout D3D11_INPUT_ELEMENT_DESC local_layout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->pos), D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->uv), D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((ImDrawVert*)0)->col), D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; if (g_pd3dDevice->CreateInputLayout(local_layout, 3, g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout) != S_OK) return false; // Create the constant buffer { D3D11_BUFFER_DESC desc; desc.ByteWidth = sizeof(VERTEX_CONSTANT_BUFFER); desc.Usage = D3D11_USAGE_DYNAMIC; desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; desc.MiscFlags = 0; g_pd3dDevice->CreateBuffer(&desc, NULL, &g_pVertexConstantBuffer); } } // Create the pixel shader { static const char* pixelShader = "struct PS_INPUT\ {\ float4 pos : SV_POSITION;\ float4 col : COLOR0;\ float2 uv : TEXCOORD0;\ };\ sampler sampler0;\ Texture2D texture0;\ \ float4 main(PS_INPUT input) : SV_Target\ {\ float4 out_col = input.col * texture0.Sample(sampler0, input.uv); \ return out_col; \ }"; D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_4_0", 0, 0, &g_pPixelShaderBlob, NULL); if (g_pPixelShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! return false; if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), NULL, &g_pPixelShader) != S_OK) return false; } // Create the blending setup { D3D11_BLEND_DESC desc; ZeroMemory(&desc, sizeof(desc)); desc.AlphaToCoverageEnable = false; desc.RenderTarget[0].BlendEnable = true; desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; g_pd3dDevice->CreateBlendState(&desc, &g_pBlendState); } // Create the rasterizer state { D3D11_RASTERIZER_DESC desc; ZeroMemory(&desc, sizeof(desc)); desc.FillMode = D3D11_FILL_SOLID; desc.CullMode = D3D11_CULL_NONE; desc.ScissorEnable = true; desc.DepthClipEnable = true; g_pd3dDevice->CreateRasterizerState(&desc, &g_pRasterizerState); } // Create depth-stencil State { D3D11_DEPTH_STENCIL_DESC desc; ZeroMemory(&desc, sizeof(desc)); desc.DepthEnable = false; desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; desc.DepthFunc = D3D11_COMPARISON_ALWAYS; desc.StencilEnable = false; desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; desc.BackFace = desc.FrontFace; g_pd3dDevice->CreateDepthStencilState(&desc, &g_pDepthStencilState); } ImGui_ImplDX11_CreateFontsTexture(); return true; } void ImGui_ImplDX11_InvalidateDeviceObjects() { if (!g_pd3dDevice) return; if (g_pFontSampler) { g_pFontSampler->Release(); g_pFontSampler = NULL; } if (g_pFontTextureView) { g_pFontTextureView->Release(); g_pFontTextureView = NULL; ImGui::GetIO().Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well. if (g_pIB) { g_pIB->Release(); g_pIB = NULL; } if (g_pVB) { g_pVB->Release(); g_pVB = NULL; } if (g_pBlendState) { g_pBlendState->Release(); g_pBlendState = NULL; } if (g_pDepthStencilState) { g_pDepthStencilState->Release(); g_pDepthStencilState = NULL; } if (g_pRasterizerState) { g_pRasterizerState->Release(); g_pRasterizerState = NULL; } if (g_pPixelShader) { g_pPixelShader->Release(); g_pPixelShader = NULL; } if (g_pPixelShaderBlob) { g_pPixelShaderBlob->Release(); g_pPixelShaderBlob = NULL; } if (g_pVertexConstantBuffer) { g_pVertexConstantBuffer->Release(); g_pVertexConstantBuffer = NULL; } if (g_pInputLayout) { g_pInputLayout->Release(); g_pInputLayout = NULL; } if (g_pVertexShader) { g_pVertexShader->Release(); g_pVertexShader = NULL; } if (g_pVertexShaderBlob) { g_pVertexShaderBlob->Release(); g_pVertexShaderBlob = NULL; } } bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context) { // Setup back-end capabilities flags ImGuiIO& io = ImGui::GetIO(); io.BackendRendererName = "imgui_impl_dx11"; io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional) // Get factory from device IDXGIDevice* pDXGIDevice = NULL; IDXGIAdapter* pDXGIAdapter = NULL; IDXGIFactory* pFactory = NULL; if (device->QueryInterface(IID_PPV_ARGS(&pDXGIDevice)) == S_OK) if (pDXGIDevice->GetParent(IID_PPV_ARGS(&pDXGIAdapter)) == S_OK) if (pDXGIAdapter->GetParent(IID_PPV_ARGS(&pFactory)) == S_OK) { g_pd3dDevice = device; g_pd3dDeviceContext = device_context; g_pFactory = pFactory; } if (pDXGIDevice) pDXGIDevice->Release(); if (pDXGIAdapter) pDXGIAdapter->Release(); g_pd3dDevice->AddRef(); g_pd3dDeviceContext->AddRef(); if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) ImGui_ImplDX11_InitPlatformInterface(); return true; } void ImGui_ImplDX11_Shutdown() { ImGui_ImplDX11_ShutdownPlatformInterface(); ImGui_ImplDX11_InvalidateDeviceObjects(); if (g_pFactory) { g_pFactory->Release(); g_pFactory = NULL; } if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; } if (g_pd3dDeviceContext) { g_pd3dDeviceContext->Release(); g_pd3dDeviceContext = NULL; } } void ImGui_ImplDX11_NewFrame() { if (!g_pFontSampler) ImGui_ImplDX11_CreateDeviceObjects(); } //-------------------------------------------------------------------------------------------------------- // MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT // This is an _advanced_ and _optional_ feature, allowing the back-end to create and handle multiple viewports simultaneously. // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first.. //-------------------------------------------------------------------------------------------------------- // Helper structure we store in the void* RenderUserData field of each ImGuiViewport to easily retrieve our backend data. struct ImGuiViewportDataDx11 { IDXGISwapChain* SwapChain; ID3D11RenderTargetView* RTView; ImGuiViewportDataDx11() { SwapChain = NULL; RTView = NULL; } ~ImGuiViewportDataDx11() { IM_ASSERT(SwapChain == NULL && RTView == NULL); } }; static void ImGui_ImplDX11_CreateWindow(ImGuiViewport* viewport) { ImGuiViewportDataDx11* data = IM_NEW(ImGuiViewportDataDx11)(); viewport->RendererUserData = data; // PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*). // Some back-end will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND. HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle; IM_ASSERT(hwnd != 0); // Create swap chain DXGI_SWAP_CHAIN_DESC sd; ZeroMemory(&sd, sizeof(sd)); sd.BufferDesc.Width = (UINT)viewport->Size.x; sd.BufferDesc.Height = (UINT)viewport->Size.y; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; sd.SampleDesc.Count = 1; sd.SampleDesc.Quality = 0; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.BufferCount = 1; sd.OutputWindow = hwnd; sd.Windowed = TRUE; sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; sd.Flags = 0; IM_ASSERT(data->SwapChain == NULL && data->RTView == NULL); g_pFactory->CreateSwapChain(g_pd3dDevice, &sd, &data->SwapChain); // Create the render target if (data->SwapChain) { ID3D11Texture2D* pBackBuffer; data->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &data->RTView); pBackBuffer->Release(); } } static void ImGui_ImplDX11_DestroyWindow(ImGuiViewport* viewport) { // The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it. if (ImGuiViewportDataDx11* data = (ImGuiViewportDataDx11*)viewport->RendererUserData) { if (data->SwapChain) data->SwapChain->Release(); data->SwapChain = NULL; if (data->RTView) data->RTView->Release(); data->RTView = NULL; IM_DELETE(data); } viewport->RendererUserData = NULL; } static void ImGui_ImplDX11_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) { ImGuiViewportDataDx11* data = (ImGuiViewportDataDx11*)viewport->RendererUserData; if (data->RTView) { data->RTView->Release(); data->RTView = NULL; } if (data->SwapChain) { ID3D11Texture2D* pBackBuffer = NULL; data->SwapChain->ResizeBuffers(0, (UINT)size.x, (UINT)size.y, DXGI_FORMAT_UNKNOWN, 0); data->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); if (pBackBuffer == NULL) { fprintf(stderr, "ImGui_ImplDX11_SetWindowSize() failed creating buffers.\n"); return; } g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &data->RTView); pBackBuffer->Release(); } } static void ImGui_ImplDX11_RenderWindow(ImGuiViewport* viewport, void*) { ImGuiViewportDataDx11* data = (ImGuiViewportDataDx11*)viewport->RendererUserData; ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); g_pd3dDeviceContext->OMSetRenderTargets(1, &data->RTView, NULL); if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear)) g_pd3dDeviceContext->ClearRenderTargetView(data->RTView, (float*)&clear_color); ImGui_ImplDX11_RenderDrawData(viewport->DrawData); } static void ImGui_ImplDX11_SwapBuffers(ImGuiViewport* viewport, void*) { ImGuiViewportDataDx11* data = (ImGuiViewportDataDx11*)viewport->RendererUserData; data->SwapChain->Present(0, 0); // Present without vsync } static void ImGui_ImplDX11_InitPlatformInterface() { ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); platform_io.Renderer_CreateWindow = ImGui_ImplDX11_CreateWindow; platform_io.Renderer_DestroyWindow = ImGui_ImplDX11_DestroyWindow; platform_io.Renderer_SetWindowSize = ImGui_ImplDX11_SetWindowSize; platform_io.Renderer_RenderWindow = ImGui_ImplDX11_RenderWindow; platform_io.Renderer_SwapBuffers = ImGui_ImplDX11_SwapBuffers; } static void ImGui_ImplDX11_ShutdownPlatformInterface() { ImGui::DestroyPlatformWindows(); }
; ba_priority_queue_t * ; ba_priority_queue_init(void *p, void *data, size_t capacity, int (*compar)(const void *, const void *)) SECTION code_adt_ba_priority_queue PUBLIC ba_priority_queue_init EXTERN asm_ba_priority_queue_init ba_priority_queue_init: pop af pop ix pop bc pop de pop hl push hl push de push bc push hl push af jp asm_ba_priority_queue_init
; int vscanf_unlocked_callee(const char *format, void *arg) SECTION code_clib SECTION code_stdio PUBLIC _vscanf_unlocked_callee EXTERN asm_vscanf_unlocked _vscanf_unlocked_callee: pop af pop de pop bc push af jp asm_vscanf_unlocked
/*** * Copyright 2019 Alexander Pishchulev (https://github.com/BlasterAlex) * * 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 <QAction> #include <QCloseEvent> #include <QDebug> #include <QDialog> #include <QDir> #include <QFile> #include <QFont> #include <QFormLayout> #include <QGroupBox> #include <QLayout> #include <QMultiMap> #include <QObject> #include <QProgressBar> #include <QResizeEvent> #include <QString> #include <QTextStream> #include <QToolBar> #include <QToolButton> #include <QVBoxLayout> #include <QVector> #include <QWidget> #include <QMessageBox> #include "../../Table/Table.hpp" #include "../../settings/settings.hpp" #include "Coefficients.hpp" Coefficients::Coefficients(QVector<Table> t, QWidget *parent) : QDialog(parent) { tables = t; tablesNum = tables.size(); // Заголовок setWindowTitle("Результаты"); // Основной слой QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setMargin(0); mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setSpacing(0); // Меню setMenu(); mainLayout->addWidget(toolBar, 0, Qt::AlignTop); // Создание поля для вывода результатов createContentBlock(); mainLayout->addWidget(contentBlock, 1, Qt::AlignTop); // Полоска загрузки createLoader(); mainLayout->addWidget(progress); // Вычисление коэффициентов calculation(); } // Вычисление коэффициентов void Coefficients::calculation() { // Вычисление коэффициента Спирмена progress_label->setText("Вычисление коэффициентов корреляции Спирмена..."); for (int i = 0; i < tablesNum - 1; ++i) for (int j = i + 1; j < tablesNum; ++j) { float coeff = getSpearmanCoeff(i, j); Spearman.push_back(Coeff(i, j, QString::number(coeff))); progress_bar->setValue(progress_bar->value() + 1); } writeToCSV(Spearman, "Spearman"); // Вычисление коэффициентов Кендалла progress_label->setText("Вычисление коэффициентов корреляции Кендалла..."); for (int i = 0; i < tablesNum - 1; ++i) for (int j = i + 1; j < tablesNum; ++j) { float coeff = getKendallCoeff(i, j); Kendall.push_back(Coeff(i, j, QString::number(coeff))); progress_bar->setValue(progress_bar->value() + 1); } writeToCSV(Kendall, "Kendall"); // Вычисление коэффициентов методом обмена progress_label->setText("Вычисление коэффициентов корреляции методом обмена..."); for (int i = 0; i < tablesNum - 1; ++i) for (int j = i + 1; j < tablesNum; ++j) { float coeff = getExchange(i, j); Exchange.push_back(Coeff(i, j, QString::number(coeff))); progress_bar->setValue(progress_bar->value() + 1); } writeToCSV(Exchange, "Exchange"); displayResults(); } // Вывод результатов в файл void Coefficients::writeToCSV(QVector<Coeff> coeffs, QString name) { // Создание папок для вывода, если нужно QString path = getSetting("output/dir").toString(); QDir dir(path); if (!dir.exists()) { QDir().mkdir(path); qDebug() << "Создана папка " + path; } path = getSetting("output/coeff").toString(); dir.setPath(path); if (!dir.exists()) { QDir().mkdir(path); qDebug() << "Создана папка " + path; } path += QDir::separator(); QString separator = getSetting("uploads/csvSeparator").toString(); // Запись в файл QFile file(path + name + ".csv"); if (file.open(QFile::WriteOnly | QFile::Truncate)) { QTextStream stream(&file); stream << "x" << separator << "y" << separator << tr("Коэф.") << endl; foreach (Coeff coeff, coeffs) stream << coeff.parents[0] << separator << coeff.parents[1] << separator << coeff.val << endl; file.close(); } } // Событие изменения размера окна void Coefficients::resizeEvent(QResizeEvent *event) { QDialog::resizeEvent(event); table->setFixedHeight(event->size().height() - 85); } // Событие закрытия окна void Coefficients::closeEvent(QCloseEvent *event) { emit shutdown(); event->accept(); } // Подсчет количества итераций алгоритмов int Coefficients::iterationsCol(int N) { if (N == 0) return 0; else return N + iterationsCol(N - 1); }
; A325689: Number of length-3 compositions of n such that no part is the sum of the other two. ; 0,0,0,1,0,6,4,15,12,28,24,45,40,66,60,91,84,120,112,153,144,190,180,231,220,276,264,325,312,378,364,435,420,496,480,561,544,630,612,703,684,780,760,861,840,946,924,1035,1012,1128,1104,1225,1200,1326,1300,1431 mov $1,$0 mov $5,$0 gcd $5,2 sub $1,$5 mov $2,$1 trn $1,$5 mov $3,$2 mul $3,2 mul $1,$3 lpb $1,1 mov $1,$4 add $1,17 fac $1 lpe mul $1,2 div $1,8
#pragma once #define BOOST_SPIRIT_DEBUG #include <boost/config/warning_disable.hpp> #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/qi_repeat.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_fusion.hpp> #include <boost/spirit/include/phoenix_stl.hpp> #include <boost/spirit/include/phoenix_object.hpp> #include <boost/variant/recursive_variant.hpp> namespace Grawitas { template<typename Iterator> struct HtmlCleaningGrammar : boost::spirit::qi::grammar<Iterator, std::string()> { HtmlCleaningGrammar(); boost::spirit::qi::rule<Iterator, std::string()> html_cleaning; boost::spirit::qi::rule<Iterator> html_element; boost::spirit::qi::rule<Iterator> html_comment_text; boost::spirit::qi::rule<Iterator> html_comment; boost::spirit::qi::symbols<char> html_element_name; boost::spirit::qi::rule<Iterator> html_special_characters; boost::spirit::qi::symbols<char> wiki_text_formatting; }; }
; A168180: a(n) = n^3*(n^5 + 1)/2. ; 0,1,132,3294,32800,195375,839916,2882572,8388864,21523725,50000500,107180106,214991712,407866459,737895900,1281447000,2147485696,3487881177,5509983204,8491784950,12800004000,18911434311,27437942092,39155498724,55037664000,76293953125,104413541076,141214778082,188901010144,250123218675,328050013500,426445533616,549755830272,703204327089,892896972100,1125937716750,1410554977056,1756239752287,2173896096684,2676004659900,3276800032000,3992462649021,4841326035252,5844100178554,7024111855200 mov $1,$0 pow $0,8 pow $1,3 add $0,$1 div $0,2
//===--- VerifyDiagnosticsClient.cpp - Verifying Diagnostic Client --------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This is a concrete diagnostic client, which buffers the diagnostic messages. // //===----------------------------------------------------------------------===// #include "clang/Frontend/VerifyDiagnosticsClient.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/TextDiagnosticBuffer.h" #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/Regex.h" #include "llvm/Support/raw_ostream.h" using namespace clang; VerifyDiagnosticsClient::VerifyDiagnosticsClient(Diagnostic &_Diags, DiagnosticClient *_Primary) : Diags(_Diags), PrimaryClient(_Primary), Buffer(new TextDiagnosticBuffer()), CurrentPreprocessor(0) { } VerifyDiagnosticsClient::~VerifyDiagnosticsClient() { CheckDiagnostics(); } // DiagnosticClient interface. void VerifyDiagnosticsClient::BeginSourceFile(const LangOptions &LangOpts, const Preprocessor *PP) { // FIXME: Const hack, we screw up the preprocessor but in practice its ok // because it doesn't get reused. It would be better if we could make a copy // though. CurrentPreprocessor = const_cast<Preprocessor*>(PP); PrimaryClient->BeginSourceFile(LangOpts, PP); } void VerifyDiagnosticsClient::EndSourceFile() { CheckDiagnostics(); PrimaryClient->EndSourceFile(); CurrentPreprocessor = 0; } void VerifyDiagnosticsClient::HandleDiagnostic(Diagnostic::Level DiagLevel, const DiagnosticInfo &Info) { // Send the diagnostic to the buffer, we will check it once we reach the end // of the source file (or are destructed). Buffer->HandleDiagnostic(DiagLevel, Info); } //===----------------------------------------------------------------------===// // Checking diagnostics implementation. //===----------------------------------------------------------------------===// typedef TextDiagnosticBuffer::DiagList DiagList; typedef TextDiagnosticBuffer::const_iterator const_diag_iterator; namespace { /// Directive - Abstract class representing a parsed verify directive. /// class Directive { public: static Directive* Create(bool RegexKind, const SourceLocation &Location, const std::string &Text, unsigned Count); public: SourceLocation Location; const std::string Text; unsigned Count; virtual ~Directive() { } // Returns true if directive text is valid. // Otherwise returns false and populates E. virtual bool isValid(std::string &Error) = 0; // Returns true on match. virtual bool Match(const std::string &S) = 0; protected: Directive(const SourceLocation &Location, const std::string &Text, unsigned Count) : Location(Location), Text(Text), Count(Count) { } private: Directive(const Directive&); // DO NOT IMPLEMENT void operator=(const Directive&); // DO NOT IMPLEMENT }; /// StandardDirective - Directive with string matching. /// class StandardDirective : public Directive { public: StandardDirective(const SourceLocation &Location, const std::string &Text, unsigned Count) : Directive(Location, Text, Count) { } virtual bool isValid(std::string &Error) { // all strings are considered valid; even empty ones return true; } virtual bool Match(const std::string &S) { return S.find(Text) != std::string::npos || Text.find(S) != std::string::npos; } }; /// RegexDirective - Directive with regular-expression matching. /// class RegexDirective : public Directive { public: RegexDirective(const SourceLocation &Location, const std::string &Text, unsigned Count) : Directive(Location, Text, Count), Regex(Text) { } virtual bool isValid(std::string &Error) { if (Regex.isValid(Error)) return true; return false; } virtual bool Match(const std::string &S) { return Regex.match(S); } private: llvm::Regex Regex; }; typedef std::vector<Directive*> DirectiveList; /// ExpectedData - owns directive objects and deletes on destructor. /// struct ExpectedData { DirectiveList Errors; DirectiveList Warnings; DirectiveList Notes; ~ExpectedData() { DirectiveList* Lists[] = { &Errors, &Warnings, &Notes, 0 }; for (DirectiveList **PL = Lists; *PL; ++PL) { DirectiveList * const L = *PL; for (DirectiveList::iterator I = L->begin(), E = L->end(); I != E; ++I) delete *I; } } }; class ParseHelper { public: ParseHelper(const char *Begin, const char *End) : Begin(Begin), End(End), C(Begin), P(Begin), PEnd(NULL) { } // Return true if string literal is next. bool Next(llvm::StringRef S) { P = C; PEnd = C + S.size(); if (PEnd > End) return false; return !memcmp(P, S.data(), S.size()); } // Return true if number is next. // Output N only if number is next. bool Next(unsigned &N) { unsigned TMP = 0; P = C; for (; P < End && P[0] >= '0' && P[0] <= '9'; ++P) { TMP *= 10; TMP += P[0] - '0'; } if (P == C) return false; PEnd = P; N = TMP; return true; } // Return true if string literal is found. // When true, P marks begin-position of S in content. bool Search(llvm::StringRef S) { P = std::search(C, End, S.begin(), S.end()); PEnd = P + S.size(); return P != End; } // Advance 1-past previous next/search. // Behavior is undefined if previous next/search failed. bool Advance() { C = PEnd; return C < End; } // Skip zero or more whitespace. void SkipWhitespace() { for (; C < End && isspace(*C); ++C) ; } // Return true if EOF reached. bool Done() { return !(C < End); } const char * const Begin; // beginning of expected content const char * const End; // end of expected content (1-past) const char *C; // position of next char in content const char *P; private: const char *PEnd; // previous next/search subject end (1-past) }; } // namespace anonymous /// ParseDirective - Go through the comment and see if it indicates expected /// diagnostics. If so, then put them in the appropriate directive list. /// static void ParseDirective(const char *CommentStart, unsigned CommentLen, ExpectedData &ED, Preprocessor &PP, SourceLocation Pos) { // A single comment may contain multiple directives. for (ParseHelper PH(CommentStart, CommentStart+CommentLen); !PH.Done();) { // search for token: expected if (!PH.Search("expected")) break; PH.Advance(); // next token: - if (!PH.Next("-")) continue; PH.Advance(); // next token: { error | warning | note } DirectiveList* DL = NULL; if (PH.Next("error")) DL = &ED.Errors; else if (PH.Next("warning")) DL = &ED.Warnings; else if (PH.Next("note")) DL = &ED.Notes; else continue; PH.Advance(); // default directive kind bool RegexKind = false; const char* KindStr = "string"; // next optional token: - if (PH.Next("-re")) { PH.Advance(); RegexKind = true; KindStr = "regex"; } // skip optional whitespace PH.SkipWhitespace(); // next optional token: positive integer unsigned Count = 1; if (PH.Next(Count)) PH.Advance(); // skip optional whitespace PH.SkipWhitespace(); // next token: {{ if (!PH.Next("{{")) { PP.Diag(Pos.getFileLocWithOffset(PH.C-PH.Begin), diag::err_verify_missing_start) << KindStr; continue; } PH.Advance(); const char* const ContentBegin = PH.C; // mark content begin // search for token: }} if (!PH.Search("}}")) { PP.Diag(Pos.getFileLocWithOffset(PH.C-PH.Begin), diag::err_verify_missing_end) << KindStr; continue; } const char* const ContentEnd = PH.P; // mark content end PH.Advance(); // build directive text; convert \n to newlines std::string Text; llvm::StringRef NewlineStr = "\\n"; llvm::StringRef Content(ContentBegin, ContentEnd-ContentBegin); size_t CPos = 0; size_t FPos; while ((FPos = Content.find(NewlineStr, CPos)) != llvm::StringRef::npos) { Text += Content.substr(CPos, FPos-CPos); Text += '\n'; CPos = FPos + NewlineStr.size(); } if (Text.empty()) Text.assign(ContentBegin, ContentEnd); // construct new directive Directive *D = Directive::Create(RegexKind, Pos, Text, Count); std::string Error; if (D->isValid(Error)) DL->push_back(D); else { PP.Diag(Pos.getFileLocWithOffset(ContentBegin-PH.Begin), diag::err_verify_invalid_content) << KindStr << Error; } } } /// FindExpectedDiags - Lex the main source file to find all of the // expected errors and warnings. static void FindExpectedDiags(Preprocessor &PP, ExpectedData &ED) { // Create a raw lexer to pull all the comments out of the main file. We don't // want to look in #include'd headers for expected-error strings. SourceManager &SM = PP.getSourceManager(); FileID FID = SM.getMainFileID(); if (SM.getMainFileID().isInvalid()) return; // Create a lexer to lex all the tokens of the main file in raw mode. const llvm::MemoryBuffer *FromFile = SM.getBuffer(FID); Lexer RawLex(FID, FromFile, SM, PP.getLangOptions()); // Return comments as tokens, this is how we find expected diagnostics. RawLex.SetCommentRetentionState(true); Token Tok; Tok.setKind(tok::comment); while (Tok.isNot(tok::eof)) { RawLex.Lex(Tok); if (!Tok.is(tok::comment)) continue; std::string Comment = PP.getSpelling(Tok); if (Comment.empty()) continue; // Find all expected errors/warnings/notes. ParseDirective(&Comment[0], Comment.size(), ED, PP, Tok.getLocation()); }; } /// PrintProblem - This takes a diagnostic map of the delta between expected and /// seen diagnostics. If there's anything in it, then something unexpected /// happened. Print the map out in a nice format and return "true". If the map /// is empty and we're not going to print things, then return "false". /// static unsigned PrintProblem(Diagnostic &Diags, SourceManager *SourceMgr, const_diag_iterator diag_begin, const_diag_iterator diag_end, const char *Kind, bool Expected) { if (diag_begin == diag_end) return 0; llvm::SmallString<256> Fmt; llvm::raw_svector_ostream OS(Fmt); for (const_diag_iterator I = diag_begin, E = diag_end; I != E; ++I) { if (I->first.isInvalid() || !SourceMgr) OS << "\n (frontend)"; else OS << "\n Line " << SourceMgr->getPresumedLineNumber(I->first); OS << ": " << I->second; } Diags.Report(diag::err_verify_inconsistent_diags) << Kind << !Expected << OS.str(); return std::distance(diag_begin, diag_end); } static unsigned PrintProblem(Diagnostic &Diags, SourceManager *SourceMgr, DirectiveList &DL, const char *Kind, bool Expected) { if (DL.empty()) return 0; llvm::SmallString<256> Fmt; llvm::raw_svector_ostream OS(Fmt); for (DirectiveList::iterator I = DL.begin(), E = DL.end(); I != E; ++I) { Directive& D = **I; if (D.Location.isInvalid() || !SourceMgr) OS << "\n (frontend)"; else OS << "\n Line " << SourceMgr->getPresumedLineNumber(D.Location); OS << ": " << D.Text; } Diags.Report(diag::err_verify_inconsistent_diags) << Kind << !Expected << OS.str(); return DL.size(); } /// CheckLists - Compare expected to seen diagnostic lists and return the /// the difference between them. /// static unsigned CheckLists(Diagnostic &Diags, SourceManager &SourceMgr, const char *Label, DirectiveList &Left, const_diag_iterator d2_begin, const_diag_iterator d2_end) { DirectiveList LeftOnly; DiagList Right(d2_begin, d2_end); for (DirectiveList::iterator I = Left.begin(), E = Left.end(); I != E; ++I) { Directive& D = **I; unsigned LineNo1 = SourceMgr.getPresumedLineNumber(D.Location); for (unsigned i = 0; i < D.Count; ++i) { DiagList::iterator II, IE; for (II = Right.begin(), IE = Right.end(); II != IE; ++II) { unsigned LineNo2 = SourceMgr.getPresumedLineNumber(II->first); if (LineNo1 != LineNo2) continue; const std::string &RightText = II->second; if (D.Match(RightText)) break; } if (II == IE) { // Not found. LeftOnly.push_back(*I); } else { // Found. The same cannot be found twice. Right.erase(II); } } } // Now all that's left in Right are those that were not matched. return (PrintProblem(Diags, &SourceMgr, LeftOnly, Label, true) + PrintProblem(Diags, &SourceMgr, Right.begin(), Right.end(), Label, false)); } /// CheckResults - This compares the expected results to those that /// were actually reported. It emits any discrepencies. Return "true" if there /// were problems. Return "false" otherwise. /// static unsigned CheckResults(Diagnostic &Diags, SourceManager &SourceMgr, const TextDiagnosticBuffer &Buffer, ExpectedData &ED) { // We want to capture the delta between what was expected and what was // seen. // // Expected \ Seen - set expected but not seen // Seen \ Expected - set seen but not expected unsigned NumProblems = 0; // See if there are error mismatches. NumProblems += CheckLists(Diags, SourceMgr, "error", ED.Errors, Buffer.err_begin(), Buffer.err_end()); // See if there are warning mismatches. NumProblems += CheckLists(Diags, SourceMgr, "warning", ED.Warnings, Buffer.warn_begin(), Buffer.warn_end()); // See if there are note mismatches. NumProblems += CheckLists(Diags, SourceMgr, "note", ED.Notes, Buffer.note_begin(), Buffer.note_end()); return NumProblems; } void VerifyDiagnosticsClient::CheckDiagnostics() { ExpectedData ED; // Ensure any diagnostics go to the primary client. DiagnosticClient *CurClient = Diags.takeClient(); Diags.setClient(PrimaryClient.get()); // If we have a preprocessor, scan the source for expected diagnostic // markers. If not then any diagnostics are unexpected. if (CurrentPreprocessor) { FindExpectedDiags(*CurrentPreprocessor, ED); // Check that the expected diagnostics occurred. NumErrors += CheckResults(Diags, CurrentPreprocessor->getSourceManager(), *Buffer, ED); } else { NumErrors += (PrintProblem(Diags, 0, Buffer->err_begin(), Buffer->err_end(), "error", false) + PrintProblem(Diags, 0, Buffer->warn_begin(), Buffer->warn_end(), "warn", false) + PrintProblem(Diags, 0, Buffer->note_begin(), Buffer->note_end(), "note", false)); } Diags.takeClient(); Diags.setClient(CurClient); // Reset the buffer, we have processed all the diagnostics in it. Buffer.reset(new TextDiagnosticBuffer()); } Directive* Directive::Create(bool RegexKind, const SourceLocation &Location, const std::string &Text, unsigned Count) { if (RegexKind) return new RegexDirective(Location, Text, Count); return new StandardDirective(Location, Text, Count); }
/*========================================================================= Program: Visualization Toolkit Module: vtkImageIdealHighPass.cxx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ #include "vtkImageIdealHighPass.h" #include "vtkImageData.h" #include "vtkInformation.h" #include "vtkInformationVector.h" #include "vtkObjectFactory.h" #include "vtkStreamingDemandDrivenPipeline.h" #include <cmath> vtkStandardNewMacro(vtkImageIdealHighPass); //---------------------------------------------------------------------------- vtkImageIdealHighPass::vtkImageIdealHighPass() { this->CutOff[0] = this->CutOff[1] = this->CutOff[2] = VTK_DOUBLE_MAX; } //---------------------------------------------------------------------------- void vtkImageIdealHighPass::SetXCutOff(double cutOff) { if (cutOff == this->CutOff[0]) { return; } this->CutOff[0] = cutOff; this->Modified(); } //---------------------------------------------------------------------------- void vtkImageIdealHighPass::SetYCutOff(double cutOff) { if (cutOff == this->CutOff[1]) { return; } this->CutOff[1] = cutOff; this->Modified(); } //---------------------------------------------------------------------------- void vtkImageIdealHighPass::SetZCutOff(double cutOff) { if (cutOff == this->CutOff[2]) { return; } this->CutOff[2] = cutOff; this->Modified(); } //---------------------------------------------------------------------------- void vtkImageIdealHighPass::ThreadedRequestData( vtkInformation *vtkNotUsed(request), vtkInformationVector **inputVector, vtkInformationVector *vtkNotUsed(outputVector), vtkImageData ***inData, vtkImageData **outData, int ext[6], int id) { int idx0, idx1, idx2; int min0, max0; double *inPtr; double *outPtr; int wholeExtent[6]; double spacing[3]; vtkIdType inInc0, inInc1, inInc2; vtkIdType outInc0, outInc1, outInc2; double temp0, temp1, temp2, mid0, mid1, mid2; // normalization factors double norm0, norm1, norm2; double sum1, sum0; unsigned long count = 0; unsigned long target; vtkInformation *inInfo = inputVector[0]->GetInformationObject(0); // Error checking if (inData[0][0]->GetNumberOfScalarComponents() != 2) { vtkErrorMacro("Expecting 2 components not " << inData[0][0]->GetNumberOfScalarComponents()); return; } if (inData[0][0]->GetScalarType() != VTK_DOUBLE || outData[0]->GetScalarType() != VTK_DOUBLE) { vtkErrorMacro("Expecting input and output to be of type double"); return; } inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), wholeExtent); inData[0][0]->GetSpacing(spacing); inPtr = static_cast<double *>(inData[0][0]->GetScalarPointerForExtent(ext)); outPtr = static_cast<double *>(outData[0]->GetScalarPointerForExtent(ext)); inData[0][0]->GetContinuousIncrements(ext, inInc0, inInc1, inInc2); outData[0]->GetContinuousIncrements(ext, outInc0, outInc1, outInc2); min0 = ext[0]; max0 = ext[1]; mid0 = static_cast<double>(wholeExtent[0] + wholeExtent[1] + 1) / 2.0; mid1 = static_cast<double>(wholeExtent[2] + wholeExtent[3] + 1) / 2.0; mid2 = static_cast<double>(wholeExtent[4] + wholeExtent[5] + 1) / 2.0; if ( this->CutOff[0] == 0.0) { norm0 = VTK_DOUBLE_MAX; } else { norm0 = 1.0 / ((spacing[0] * 2.0 * mid0) * this->CutOff[0]); } if ( this->CutOff[1] == 0.0) { norm1 = VTK_DOUBLE_MAX; } else { norm1 = 1.0 / ((spacing[1] * 2.0 * mid1) * this->CutOff[1]); } if ( this->CutOff[2] == 0.0) { norm2 = VTK_DOUBLE_MAX; } else { norm2 = 1.0 / ((spacing[2] * 2.0 * mid2) * this->CutOff[2]); } target = static_cast<unsigned long>( (ext[5]-ext[4]+1)*(ext[3]-ext[2]+1)/50.0); target++; // loop over all the pixels (keeping track of normalized distance to origin. for (idx2 = ext[4]; idx2 <= ext[5]; ++idx2) { // distance to min (this axis' contribution) temp2 = static_cast<double>(idx2); // Wrap back to 0. if (temp2 > mid2) { temp2 = mid2 + mid2 - temp2; } // Convert location into normalized cycles/world unit temp2 = temp2 * norm2; for (idx1 = ext[2]; !this->AbortExecute && idx1 <= ext[3]; ++idx1) { if (!id) { if (!(count%target)) { this->UpdateProgress(count/(50.0*target)); } count++; } // distance to min (this axis' contribution) temp1 = static_cast<double>(idx1); // Wrap back to 0. if (temp1 > mid1) { temp1 = mid1 + mid1 - temp1; } // Convert location into cycles / world unit temp1 = temp1 * norm1; sum1 = temp2 * temp2 + temp1 * temp1; for (idx0 = min0; idx0 <= max0; ++idx0) { // distance to min (this axis' contribution) temp0 = static_cast<double>(idx0); // Wrap back to 0. if (temp0 > mid0) { temp0 = mid0 + mid0 - temp0; } // Convert location into cycles / world unit temp0 = temp0 * norm0; sum0 = sum1 + temp0 * temp0; if (sum0 > 1.0) { // real component *outPtr++ = *inPtr++; // imaginary component *outPtr++ = *inPtr++; } else { // real component *outPtr++ = 0.0; ++inPtr; // imaginary component *outPtr++ = 0.0; ++inPtr; } } inPtr += inInc1; outPtr += outInc1; } inPtr += inInc2; outPtr += outInc2; } } void vtkImageIdealHighPass::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os,indent); os << indent << "CutOff: ( " << this->CutOff[0] << ", " << this->CutOff[1] << ", " << this->CutOff[2] << " )\n"; }
;; ;; Copyright (c) 2012-2018, Intel Corporation ;; ;; 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. ;; %include "os.asm" %include "job_aes_hmac.asm" %include "mb_mgr_datastruct.asm" %include "reg_sizes.asm" %include "memcpy.asm" extern sha_256_mult_sse section .data default rel align 16 byteswap: ;ddq 0x0c0d0e0f08090a0b0405060700010203 dq 0x0405060700010203, 0x0c0d0e0f08090a0b section .text %ifndef FUNC %define FUNC submit_job_hmac_sha_256_sse %endif %if 1 %ifdef LINUX %define arg1 rdi %define arg2 rsi %define reg3 rcx %define reg4 rdx %else %define arg1 rcx %define arg2 rdx %define reg3 rdi %define reg4 rsi %endif %define state arg1 %define job arg2 %define len2 arg2 ; idx needs to be in rbx, rbp, r13-r15 %define last_len rbp %define idx rbp %define p r11 %define start_offset r11 %define unused_lanes rbx %define tmp4 rbx %define job_rax rax %define len rax %define size_offset reg3 %define tmp2 reg3 %define lane reg4 %define tmp3 reg4 %define extra_blocks r8 %define tmp r9 %define p2 r9 %define lane_data r10 %endif ; This routine clobbers rbx, rbp, rsi, rdi; called routine also clobbers r12 struc STACK _gpr_save: resq 5 _rsp_save: resq 1 endstruc ; JOB* FUNC(MB_MGR_HMAC_SHA_256_OOO *state, JOB_AES_HMAC *job) ; arg 1 : rcx : state ; arg 2 : rdx : job MKGLOBAL(FUNC,function,internal) FUNC: mov rax, rsp sub rsp, STACK_size and rsp, -16 mov [rsp + _gpr_save + 8*0], rbx mov [rsp + _gpr_save + 8*1], rbp mov [rsp + _gpr_save + 8*2], r12 %ifndef LINUX mov [rsp + _gpr_save + 8*3], rsi mov [rsp + _gpr_save + 8*4], rdi %endif mov [rsp + _rsp_save], rax ; original SP mov unused_lanes, [state + _unused_lanes_sha256] movzx lane, BYTE(unused_lanes) shr unused_lanes, 8 imul lane_data, lane, _HMAC_SHA1_LANE_DATA_size lea lane_data, [state + _ldata_sha256 + lane_data] mov [state + _unused_lanes_sha256], unused_lanes mov len, [job + _msg_len_to_hash_in_bytes] mov tmp, len shr tmp, 6 ; divide by 64, len in terms of blocks mov [lane_data + _job_in_lane], job mov dword [lane_data + _outer_done], 0 mov [state + _lens_sha256 + 2*lane], WORD(tmp) mov last_len, len and last_len, 63 lea extra_blocks, [last_len + 9 + 63] shr extra_blocks, 6 mov [lane_data + _extra_blocks], DWORD(extra_blocks) mov p, [job + _src] add p, [job + _hash_start_src_offset_in_bytes] mov [state + _args_data_ptr_sha256 + 8*lane], p cmp len, 64 jb copy_lt64 fast_copy: add p, len movdqu xmm0, [p - 64 + 0*16] movdqu xmm1, [p - 64 + 1*16] movdqu xmm2, [p - 64 + 2*16] movdqu xmm3, [p - 64 + 3*16] movdqa [lane_data + _extra_block + 0*16], xmm0 movdqa [lane_data + _extra_block + 1*16], xmm1 movdqa [lane_data + _extra_block + 2*16], xmm2 movdqa [lane_data + _extra_block + 3*16], xmm3 end_fast_copy: mov size_offset, extra_blocks shl size_offset, 6 sub size_offset, last_len add size_offset, 64-8 mov [lane_data + _size_offset], DWORD(size_offset) mov start_offset, 64 sub start_offset, last_len mov [lane_data + _start_offset], DWORD(start_offset) lea tmp, [8*64 + 8*len] bswap tmp mov [lane_data + _extra_block + size_offset], tmp mov tmp, [job + _auth_key_xor_ipad] movdqu xmm0, [tmp] movdqu xmm1, [tmp + 4*4] movd [state + _args_digest_sha256 + 4*lane + 0*SHA256_DIGEST_ROW_SIZE], xmm0 pextrd [state + _args_digest_sha256 + 4*lane + 1*SHA256_DIGEST_ROW_SIZE], xmm0, 1 pextrd [state + _args_digest_sha256 + 4*lane + 2*SHA256_DIGEST_ROW_SIZE], xmm0, 2 pextrd [state + _args_digest_sha256 + 4*lane + 3*SHA256_DIGEST_ROW_SIZE], xmm0, 3 movd [state + _args_digest_sha256 + 4*lane + 4*SHA256_DIGEST_ROW_SIZE], xmm1 pextrd [state + _args_digest_sha256 + 4*lane + 5*SHA256_DIGEST_ROW_SIZE], xmm1, 1 pextrd [state + _args_digest_sha256 + 4*lane + 6*SHA256_DIGEST_ROW_SIZE], xmm1, 2 pextrd [state + _args_digest_sha256 + 4*lane + 7*SHA256_DIGEST_ROW_SIZE], xmm1, 3 test len, ~63 jnz ge64_bytes lt64_bytes: mov [state + _lens_sha256 + 2*lane], WORD(extra_blocks) lea tmp, [lane_data + _extra_block + start_offset] mov [state + _args_data_ptr_sha256 + 8*lane], tmp mov dword [lane_data + _extra_blocks], 0 ge64_bytes: cmp unused_lanes, 0xff jne return_null jmp start_loop align 16 start_loop: ; Find min length movdqa xmm0, [state + _lens_sha256] phminposuw xmm1, xmm0 pextrw len2, xmm1, 0 ; min value pextrw idx, xmm1, 1 ; min index (0...3) cmp len2, 0 je len_is_0 pshuflw xmm1, xmm1, 0 psubw xmm0, xmm1 movdqa [state + _lens_sha256], xmm0 ; "state" and "args" are the same address, arg1 ; len is arg2 call sha_256_mult_sse ; state and idx are intact len_is_0: ; process completed job "idx" imul lane_data, idx, _HMAC_SHA1_LANE_DATA_size lea lane_data, [state + _ldata_sha256 + lane_data] mov DWORD(extra_blocks), [lane_data + _extra_blocks] cmp extra_blocks, 0 jne proc_extra_blocks cmp dword [lane_data + _outer_done], 0 jne end_loop proc_outer: mov dword [lane_data + _outer_done], 1 mov DWORD(size_offset), [lane_data + _size_offset] mov qword [lane_data + _extra_block + size_offset], 0 mov word [state + _lens_sha256 + 2*idx], 1 lea tmp, [lane_data + _outer_block] mov job, [lane_data + _job_in_lane] mov [state + _args_data_ptr_sha256 + 8*idx], tmp movd xmm0, [state + _args_digest_sha256 + 4*idx + 0*SHA256_DIGEST_ROW_SIZE] pinsrd xmm0, [state + _args_digest_sha256 + 4*idx + 1*SHA256_DIGEST_ROW_SIZE], 1 pinsrd xmm0, [state + _args_digest_sha256 + 4*idx + 2*SHA256_DIGEST_ROW_SIZE], 2 pinsrd xmm0, [state + _args_digest_sha256 + 4*idx + 3*SHA256_DIGEST_ROW_SIZE], 3 pshufb xmm0, [rel byteswap] movd xmm1, [state + _args_digest_sha256 + 4*idx + 4*SHA256_DIGEST_ROW_SIZE] pinsrd xmm1, [state + _args_digest_sha256 + 4*idx + 5*SHA256_DIGEST_ROW_SIZE], 1 pinsrd xmm1, [state + _args_digest_sha256 + 4*idx + 6*SHA256_DIGEST_ROW_SIZE], 2 %ifndef SHA224 pinsrd xmm1, [state + _args_digest_sha256 + 4*idx + 7*SHA256_DIGEST_ROW_SIZE], 3 %endif pshufb xmm1, [rel byteswap] movdqa [lane_data + _outer_block], xmm0 movdqa [lane_data + _outer_block + 4*4], xmm1 %ifdef SHA224 mov dword [lane_data + _outer_block + 7*4], 0x80 %endif mov tmp, [job + _auth_key_xor_opad] movdqu xmm0, [tmp] movdqu xmm1, [tmp + 4*4] movd [state + _args_digest_sha256 + 4*idx + 0*SHA256_DIGEST_ROW_SIZE], xmm0 pextrd [state + _args_digest_sha256 + 4*idx + 1*SHA256_DIGEST_ROW_SIZE], xmm0, 1 pextrd [state + _args_digest_sha256 + 4*idx + 2*SHA256_DIGEST_ROW_SIZE], xmm0, 2 pextrd [state + _args_digest_sha256 + 4*idx + 3*SHA256_DIGEST_ROW_SIZE], xmm0, 3 movd [state + _args_digest_sha256 + 4*idx + 4*SHA256_DIGEST_ROW_SIZE], xmm1 pextrd [state + _args_digest_sha256 + 4*idx + 5*SHA256_DIGEST_ROW_SIZE], xmm1, 1 pextrd [state + _args_digest_sha256 + 4*idx + 6*SHA256_DIGEST_ROW_SIZE], xmm1, 2 pextrd [state + _args_digest_sha256 + 4*idx + 7*SHA256_DIGEST_ROW_SIZE], xmm1, 3 jmp start_loop align 16 proc_extra_blocks: mov DWORD(start_offset), [lane_data + _start_offset] mov [state + _lens_sha256 + 2*idx], WORD(extra_blocks) lea tmp, [lane_data + _extra_block + start_offset] mov [state + _args_data_ptr_sha256 + 8*idx], tmp mov dword [lane_data + _extra_blocks], 0 jmp start_loop align 16 copy_lt64: ;; less than one message block of data ;; beginning of source block ;; destination extrablock but backwards by len from where 0x80 pre-populated ;; p2 clobbers unused_lanes, undo before exit lea p2, [lane_data + _extra_block + 64] sub p2, len memcpy_sse_64_1 p2, p, len, tmp4, tmp2, xmm0, xmm1, xmm2, xmm3 mov unused_lanes, [state + _unused_lanes_sha256] jmp end_fast_copy return_null: xor job_rax, job_rax jmp return align 16 end_loop: mov job_rax, [lane_data + _job_in_lane] mov unused_lanes, [state + _unused_lanes_sha256] mov qword [lane_data + _job_in_lane], 0 or dword [job_rax + _status], STS_COMPLETED_HMAC shl unused_lanes, 8 or unused_lanes, idx mov [state + _unused_lanes_sha256], unused_lanes mov p, [job_rax + _auth_tag_output] ; copy 14 bytes for SHA224 and 16 bytes for SHA256 mov DWORD(tmp), [state + _args_digest_sha256 + 4*idx + 0*SHA256_DIGEST_ROW_SIZE] mov DWORD(tmp2), [state + _args_digest_sha256 + 4*idx + 1*SHA256_DIGEST_ROW_SIZE] mov DWORD(tmp3), [state + _args_digest_sha256 + 4*idx + 2*SHA256_DIGEST_ROW_SIZE] mov DWORD(tmp4), [state + _args_digest_sha256 + 4*idx + 3*SHA256_DIGEST_ROW_SIZE] bswap DWORD(tmp) bswap DWORD(tmp2) bswap DWORD(tmp3) bswap DWORD(tmp4) mov [p + 0*4], DWORD(tmp) mov [p + 1*4], DWORD(tmp2) mov [p + 2*4], DWORD(tmp3) %ifdef SHA224 mov [p + 3*4], WORD(tmp4) %else mov [p + 3*4], DWORD(tmp4) %endif return: mov rbx, [rsp + _gpr_save + 8*0] mov rbp, [rsp + _gpr_save + 8*1] mov r12, [rsp + _gpr_save + 8*2] %ifndef LINUX mov rsi, [rsp + _gpr_save + 8*3] mov rdi, [rsp + _gpr_save + 8*4] %endif mov rsp, [rsp + _rsp_save] ; original SP ret %ifdef LINUX section .note.GNU-stack noalloc noexec nowrite progbits %endif
; A098601: Expansion of (1+2x)/((1+x)(1-x^2-x^3)). ; Submitted by Christian Krause ; 1,1,0,3,0,4,2,5,5,8,9,14,16,24,29,41,52,71,92,124,162,217,285,380,501,666,880,1168,1545,2049,2712,3595,4760,6308,8354,11069,14661,19424,25729,34086,45152,59816,79237,104969,139052,184207,244020,323260 add $0,2 mov $2,1 lpb $0 sub $0,1 add $5,$1 mov $1,$3 sub $3,$4 add $1,$3 sub $2,$1 mov $4,$2 mov $2,$3 add $5,$4 mov $3,$5 add $4,$2 lpe mov $0,$1
; ; BASIC-DOS Memory Services ; ; @author Jeff Parsons <Jeff@pcjs.org> ; @copyright (c) 2020-2021 Jeff Parsons ; @license MIT <https://basicdos.com/LICENSE.txt> ; ; This file is part of PCjs, a computer emulation software project at pcjs.org ; include macros.inc include dos.inc include dosapi.inc DOS segment word public 'CODE' EXTNEAR <get_psp,scb_release> EXTBYTE <scb_locked> EXTWORD <mcb_head,scb_active> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; mem_alloc (REG_AH = 48h) ; ; Inputs: ; REG_AL = MCBTYPE ; REG_BX = paragraphs requested ; ; Outputs: ; On success, REG_AX = new segment ; On failure, REG_AX = error, REG_BX = max paras available ; DEFPROC mem_alloc,DOS mov bx,[bp].REG_BX ; BX = # paras requested call mcb_alloc jnc ma9 mov [bp].REG_BX,bx ma9: mov [bp].REG_AX,ax ; update REG_AX and return CARRY ret ENDPROC mem_alloc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; mem_free (REG_AH = 49h) ; ; Inputs: ; REG_ES = segment to free ; ; Outputs: ; On success, carry clear ; On failure, carry set, REG_AX = ERR_BADMCB or ERR_BADADDR ; DEFPROC mem_free,DOS mov ax,[bp].REG_ES ; AX = segment to free call mcb_free jnc mf9 mov [bp].REG_AX,ax ; update REG_AX and return CARRY set mf9: ret ENDPROC mem_free ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; mem_realloc (REG_AH = 4Ah) ; ; Inputs: ; REG_ES = segment to realloc ; REG_BX = new size (in paragraphs) ; ; Outputs: ; On success, carry clear ; On failure, carry set, REG_AX = error, REG_BX = max paras available ; ; TODO: ; In some versions of DOS (2.1 and 3.x), this reportedly reallocates the ; block to the largest available size, even though an error is reported. ; Do we care to do the same? I think not. ; DEFPROC mem_realloc,DOS mov dx,[bp].REG_ES ; DX = segment to realloc mov bx,[bp].REG_BX ; BX = # new paras requested call mcb_realloc jnc mr9 mov [bp].REG_BX,bx mov [bp].REG_AX,ax ; update REG_AX and return CARRY set mr9: ret ENDPROC mem_realloc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; mem_query ; ; This utility function simplifies implementation of the MEM /D command. ; ; TODO: While this is a useful function during development, consider dropping ; it (and the MEM /D command) in the final release. ; ; Inputs: ; CX = memory block # (0-based) ; DL = memory block type (0 for any, 1 for free, 2 for used) ; ; Outputs: ; On success, carry clear: ; REG_BX = segment ; REG_AX = owner ID (eg, PSP) ; REG_DX = size (in paragraphs) ; REG_ES:REG_DI -> name of process or type, if any ; On failure, carry set (ie, no more blocks of the requested type) ; ; Modifies: ; AX, BX, CX, DI, ES ; DEFPROC mem_query,DOS LOCK_SCB mov bx,[mcb_head] ; BX tracks ES mov es,bx ASSUME ES:NOTHING q1: mov ax,es:[MCB_OWNER] test dl,dl ; report any block? jz q3 ; yes test ax,ax ; free block? jnz q2 ; no cmp dl,1 ; yes, interested? je q3 ; yes jmp short q4 ; no q2: cmp dl,2 ; interested in used blocks? jne q4 ; no q3: jcxz q7 dec cx q4: cmp es:[MCB_SIG],MCBSIG_LAST stc je q9 add bx,es:[MCB_PARAS] inc bx mov es,bx jmp q1 q7: mov dx,es:[MCB_PARAS] mov [bp].REG_AX,ax mov [bp].REG_DX,dx cmp ax,MCBOWNER_SYSTEM jbe q8 mov di,MCB_NAME cmp byte ptr es:[di],0 jne q7a mov di,MCB_TYPE q7a: mov [bp].REG_DI,di mov [bp].REG_ES,es ; REG_ES:REG_DI -> string q8: inc bx mov [bp].REG_BX,bx clc q9: UNLOCK_SCB ret ENDPROC mem_query ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; mcb_init ; ; Inputs: ; ES:0 -> MCB ; AL = SIG (ie, MCBSIG_NEXT or MCBSIG_LAST) ; DX = OWNER (ie, MCBOWNER_NONE, MCBOWNER_SYSTEM, or a PSP segment) ; CX = PARAS ; ; Outputs: ; Carry clear ; ; Modifies: ; AX, CX, DX, DI ; DEFPROC mcb_init,DOS ASSUME DS:NOTHING, ES:NOTHING sub di,di stosb ; mov es:[MCB_SIG],al xchg ax,dx stosw ; mov es:[MCB_OWNER],dx xchg ax,cx stosw ; mov es:[MCB_PARAS],cx mov cl,size MCB_RESERVED + size MCB_NAME mov al,0 rep stosb ret ENDPROC mcb_init ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; mcb_setname ; ; Inputs: ; ES = segment ; ; Outputs: ; None ; ; Modifies: ; BX, CX, SI, DI ; DEFPROC mcb_setname,DOS ASSUME DS:DOS, ES:NOTHING push es mov di,es dec di mov es,di mov bx,[scb_active] lea si,[bx].SCB_FILENAME + 1 mov cx,size MCB_NAME mov di,offset MCB_NAME rep movsb pop es ret ENDPROC mcb_setname ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; mcb_split ; ; Inputs: ; ES:0 -> MCB ; AL = SIG for new block ; BX = new (smaller) size for block ; CX = original (larger) size of block ; ; Outputs: ; Carry clear ; ; Modifies: ; AX, CX, DX, DI ; DEFPROC mcb_split,DOS ASSUME DS:NOTHING cmp bx,cx ; are the sizes identical? jne sp1 ; no mov es:[MCB_SIG],al ; yes, no actual split required jmp short sp9 sp1: push es mov dx,es add dx,bx inc dx mov es,dx ; ES:0 -> new MCB sub cx,bx ; reduce by # paras requested dec cx ; reduce by 1 for new MCB sub dx,dx ; DX = owner (none) call mcb_init pop es ; ES:0 -> back to found block mov es:[MCB_SIG],MCBSIG_NEXT sp9: mov es:[MCB_PARAS],bx ret ENDPROC mcb_split ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; mcb_alloc ; ; Inputs: ; AL = MCBTYPE ; BX = paragraphs requested (from REG_BX if via INT 21h) ; ; Outputs: ; On success, carry clear, AX = new segment ; On failure, carry set, BX = max paras available ; ; Modifies: ; AX, BX, CX, DX, DI, ES ; DEFPROC mcb_alloc,DOS ASSUME ES:NOTHING LOCK_SCB push ax ; save AX mov es,[mcb_head] sub dx,dx ; DX = largest free block so far a1: mov al,es:[MCB_SIG] cmp al,MCBSIG_NEXT je a2 cmp al,MCBSIG_LAST jne a7 a2: mov cx,es:[MCB_PARAS] ; CX = # paras this block cmp es:[MCB_OWNER],0 ; free block? jne a6 ; no cmp cx,bx ; big enough? je a4 ; just big enough, use as-is ja a3 ; yes cmp dx,cx ; is this largest free block so far? jae a6 ; no mov dx,cx ; yes jmp short a6 ; ; Split the current block; the new MCB at the split point will ; be marked free, and it will have the same MCB_SIG as the found block. ; a3: mov al,es:[MCB_SIG] ; AL = signature for new block call mcb_split a4: call get_psp jnz a5 mov ax,MCBOWNER_SYSTEM ; no active PSP yet, so use this a5: mov es:[MCB_OWNER],ax pop ax ; AL = MCBTYPE again mov es:[MCB_TYPE],al mov ax,es inc ax ; return ES+1 in AX, with CARRY clear clc jmp short a9 a6: cmp es:[MCB_SIG],MCBSIG_LAST; last block? je a8 ; yes, return error mov ax,es ; advance to the next block add ax,cx inc ax mov es,ax jmp a1 a7: mov ax,ERR_BADMCB jmp short a8a a8: mov ax,ERR_NOMEMORY mov bx,dx ; BX = max # paras available a8a: pop dx ; throw away AX stc a9: UNLOCK_SCB ret ENDPROC mcb_alloc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; mcb_realloc ; ; Inputs: ; DX = segment to realloc (from REG_ES if via INT 21h) ; BX = new size (in paragraphs) ; ; Outputs: ; On success, carry clear, AX = new segment ; On failure, carry set, BX = max paras available for segment ; ; Modifies: ; AX, BX, CX, DX, DI, ES ; DEFPROC mcb_realloc,DOS ASSUME ES:NOTHING LOCK_SCB dec dx mov es,dx ; ES:0 -> MCB mov cx,es:[MCB_PARAS] ; CX = # paras in block cmp bx,cx ; any change in size? je r9 ; no, that's easy mov al,es:[MCB_SIG] cmp al,MCBSIG_LAST ; is this the last block? je r2 ; yes add dx,cx inc dx mov ds,dx ; DS:0 -> next MCB ASSUME DS:NOTHING mov al,ds:[MCB_SIG] cmp ds:[MCB_OWNER],0 ; is the next MCB free? jne r2 ; no add cx,ds:[MCB_PARAS] ; yes, include it inc cx ; CX = maximum # of paras r2: cmp bx,cx ; is requested <= avail? ja r8 ; no call mcb_split ; yes, split block into used and free jmp short r9 ; return success r7: mov ax,ERR_BADMCB jmp short r8a r8: mov bx,cx ; BX = maximum # of paras available mov ax,ERR_NOMEMORY r8a: stc r9: UNLOCK_SCB ret ENDPROC mcb_realloc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; mcb_free ; ; When freeing a block, it's important to merge it with any free block that ; immediately precedes or follows it. And since the MCBs are singly-linked, ; we must walk the chain from the head until we find the candidate block. ; ; Inputs: ; AX = segment to free (from REG_ES if via INT 21h) ; ; Outputs: ; On success, carry clear ; On failure, carry set, AX = ERR_BADMCB or ERR_BADADDR ; ; Modifies: ; AX, BX, CX, DX, ES ; DEFPROC mcb_free,DOS ASSUME ES:NOTHING LOCK_SCB mov bx,[mcb_head] ; BX tracks ES dec ax ; AX = candidate MCB sub dx,dx ; DX = previous MCB (0 if not free) f1: mov es,bx cmp bx,ax ; does current MCB match candidate? jne f4 ; no ; ; If the previous block is free, add this block's paras (+1 for its MCB) ; to the previous block's paras. ; test dx,dx ; is the previous block free? jz f3 ; no f2: mov al,es:[MCB_SIG] cmp al,MCBSIG_NEXT je f2a cmp al,MCBSIG_LAST jne f7 f2a: mov cx,es:[MCB_PARAS] ; yes, merge current with previous inc cx mov es,dx ; ES:0 -> previous block add es:[MCB_PARAS],cx ; update its number of paras mov es:[MCB_SIG],al ; propagate the signature as well mov bx,dx sub dx,dx ; ; Mark the candidate block free, and if the next block is NOT free, we're done. ; f3: mov es:[MCB_OWNER],dx ; happily, DX is zero mov es:[MCB_NAME],dl cmp es:[MCB_SIG],MCBSIG_LAST; is there a next block? je f9 ; no (and carry is clear) mov dx,bx ; yes, save this block as new previous add bx,es:[MCB_PARAS] inc bx mov es,bx ; ES:0 -> next block cmp es:[MCB_OWNER],0 ; also free? jne f9 ; no, we're done (and carry is clear) ; ; Otherwise, use the same merge logic as before; the only difference now ; is that the candidate block has become the previous block. ; jmp f2 f4: cmp es:[MCB_SIG],MCBSIG_LAST; continuing search: last block? je f8 ; yes, return error sub dx,dx ; assume block is not free cmp es:[MCB_OWNER],dx ; is it free? jne f5 ; no mov dx,bx ; DX = new previous (and free) MCB f5: add bx,es:[MCB_PARAS] inc bx jmp f1 ; check the next block f7: mov ax,ERR_BADMCB jmp short f8a f8: mov ax,ERR_BADADDR f8a: stc f9: UNLOCK_SCB ret ENDPROC mcb_free ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; mcb_free_all ; ; Used during process termination to free all blocks "owned" by a PSP. ; ; Inputs: ; AX = owner (PSP) ; ; Outputs: ; On success, carry clear ; On failure, carry set, AX = ERR_BADMCB or ERR_BADADDR ; ; Modifies: ; AX, BX, CX, DX, ES ; DEFPROC mcb_free_all,DOS ASSUME ES:NOTHING LOCK_SCB mov bx,[mcb_head] fa1: mov es,bx cmp es:[MCB_OWNER],ax ; MCB owned by PSP? jne fa8 ; no push ax ; save owner mov ax,es ; AX = MCB inc ax ; AX = segment call mcb_free ; free the segment pop ax ; restore owner jc fa9 ; assuming free was successful mov bx,es ; we can pick up where free left off jmp fa1 fa8: cmp es:[MCB_SIG],MCBSIG_LAST je fa9 add bx,es:[MCB_PARAS] inc bx jmp fa1 fa9: UNLOCK_SCB ret ENDPROC mcb_free_all ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; mcb_getsize ; ; Returns the size (in paras) of a segment IFF it's a valid memory block. ; ; It's tempting to simply subtract one from the segment and check for an MCB ; signature; however, it's too easy to be spoofed by a bogus signature. The ; only way to be sure it's valid is by walking the MCB chain. ; ; Inputs: ; DX = segment ; ; Outputs: ; On success, carry clear: ; AX = size of segment, in paragraphs ; CX = owner (zero if free) ; On failure, carry set (not a valid memory block) ; ; Modifies: ; AX, CX ; DEFPROC mcb_getsize,DOS ASSUME ES:NOTHING LOCK_SCB push bx push es mov bx,[mcb_head] ; BX tracks ES dec dx ; DX = candidate MCB gs1: mov es,bx cmp bx,dx ; does current MCB match candidate? je gs8 ; yes cmp es:[MCB_SIG],MCBSIG_LAST; continuing search: last block? stc je gs9 ; yes, return error add bx,es:[MCB_PARAS] inc bx jmp gs1 ; check the next block gs8: mov ax,es:[MCB_PARAS] ; AX = size, in paragraphs mov cx,es:[MCB_OWNER] ; CX = owner (zero if free) gs9: inc dx ; restore DX pop es pop bx UNLOCK_SCB ret ENDPROC mcb_getsize DOS ends end
// File: 2-23.cpp // Author: csh // Date: 2021/3/20 // =================== typedef int ElementType; typedef struct LNode* LinkList; struct LNode { ElementType data; struct LNode* next; }; LinkList DisCreat_1(LinkList &A) { int i = 0; // 记录表A中的结点序号 LinkList B = (LinkList) new struct LNode; B->next = nullptr; LNode *ra = A; LNode *rb = B; LNode *p = A->next; A->next = nullptr; while(p != nullptr) { i++; if(i % 2 == 0) // 序号为偶数时 { rb->next = p; rb = p; } else { ra->next = p; ra = p; } p = p->next; } ra->next = nullptr; rb->next = nullptr; return B; }
; A023454: n-12. ; -12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48 sub $0,12 mul $0,120259084288 mov $1,$0 div $1,120259084288
; undconditional branch LDI #0 ; 00010000 00000000 0x1000 ADI #1 ; 10000000 00000001 0x8001 JMP #0x0 ; 01110000 00000000 0x7000
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r13 push %r15 push %r9 push %rax push %rcx push %rdi push %rsi lea addresses_WC_ht+0x16d92, %rsi clflush (%rsi) nop nop sub %r9, %r9 and $0xffffffffffffffc0, %rsi movaps (%rsi), %xmm4 vpextrq $1, %xmm4, %r11 nop nop nop nop nop cmp $39874, %r15 lea addresses_normal_ht+0x1bba2, %r13 nop nop nop xor $32964, %rax movb $0x61, (%r13) nop nop nop nop add %r11, %r11 lea addresses_WT_ht+0xfbe2, %r15 nop nop nop sub $22932, %rdi movups (%r15), %xmm4 vpextrq $0, %xmm4, %r13 nop nop sub %rax, %rax lea addresses_WC_ht+0xf242, %r15 clflush (%r15) sub $3315, %r11 movw $0x6162, (%r15) nop nop nop nop nop sub $7977, %rsi lea addresses_WC_ht+0xc4d2, %rsi lea addresses_WC_ht+0x1aa42, %rdi nop nop nop nop nop and $25716, %r9 mov $76, %rcx rep movsq nop xor $40306, %r11 lea addresses_UC_ht+0x6242, %r9 nop nop nop nop nop cmp %r13, %r13 mov $0x6162636465666768, %rcx movq %rcx, %xmm2 vmovups %ymm2, (%r9) nop nop nop nop nop inc %rdi lea addresses_D_ht+0x18cc2, %rsi nop nop nop and %r11, %r11 mov (%rsi), %r9w nop nop nop nop add %rcx, %rcx lea addresses_UC_ht+0x14442, %r15 nop nop nop nop nop cmp $29146, %rdi movw $0x6162, (%r15) nop nop nop nop inc %r13 lea addresses_WC_ht+0xec62, %rdi clflush (%rdi) and %r13, %r13 movups (%rdi), %xmm2 vpextrq $0, %xmm2, %r15 nop nop nop nop add $3491, %r11 lea addresses_UC_ht+0x6522, %r9 nop nop nop nop add %r15, %r15 mov (%r9), %rdi nop and %r11, %r11 pop %rsi pop %rdi pop %rcx pop %rax pop %r9 pop %r15 pop %r13 pop %r11 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r12 push %r13 push %r15 push %rax push %rdx // Store mov $0x6da2640000000a42, %rdx nop nop cmp %r15, %r15 movw $0x5152, (%rdx) nop nop nop xor %r15, %r15 // Store lea addresses_US+0x6742, %r13 clflush (%r13) nop nop nop nop add $33072, %r12 mov $0x5152535455565758, %r15 movq %r15, %xmm6 movups %xmm6, (%r13) and $23257, %r11 // Store mov $0x46d1940000000242, %r12 nop and $54662, %r10 mov $0x5152535455565758, %r11 movq %r11, (%r12) nop nop and $47994, %rax // Load lea addresses_US+0x63fb, %rax clflush (%rax) nop cmp %r10, %r10 movb (%rax), %r13b xor $53281, %r11 // Store lea addresses_RW+0x1bab2, %rax nop add %rdx, %rdx movb $0x51, (%rax) add %r15, %r15 // Store lea addresses_A+0xe242, %r11 nop cmp %rdx, %rdx mov $0x5152535455565758, %r13 movq %r13, %xmm7 movaps %xmm7, (%r11) nop nop nop nop add $3073, %r13 // Load lea addresses_RW+0x12242, %r15 cmp $34160, %rax movups (%r15), %xmm3 vpextrq $0, %xmm3, %r12 nop cmp $36963, %r11 // Faulty Load mov $0x6da2640000000a42, %r11 nop nop nop sub %rax, %rax vmovups (%r11), %ymm5 vextracti128 $1, %ymm5, %xmm5 vpextrq $1, %xmm5, %r12 lea oracles, %r11 and $0xff, %r12 shlq $12, %r12 mov (%r11,%r12,1), %r12 pop %rdx pop %rax pop %r15 pop %r13 pop %r12 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': True, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 8, 'size': 16, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 11, 'size': 8, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_US', 'AVXalign': True, 'congruent': 0, 'size': 1, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'AVXalign': False, 'congruent': 2, 'size': 1, 'same': False, 'NT': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_A', 'AVXalign': True, 'congruent': 11, 'size': 16, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'AVXalign': False, 'congruent': 10, 'size': 16, 'same': False, 'NT': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 0, 'size': 32, 'same': True, 'NT': False}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': True, 'congruent': 4, 'size': 16, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': True, 'congruent': 2, 'size': 1, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 5, 'size': 16, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 9, 'size': 2, 'same': False, 'NT': True}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 7, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 10, 'size': 32, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 7, 'size': 2, 'same': True, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 8, 'size': 2, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 2, 'size': 16, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 5, 'size': 8, 'same': False, 'NT': False}} {'79': 1, '2d': 15, '8d': 1, 'a1': 37, 'b3': 7, '9b': 34, 'c5': 12, 'd9': 2, 'd5': 68, '37': 406, '72': 847, '36': 390, '6b': 1, 'a3': 4, 'c7': 5, 'c3': 2, 'fb': 47, '08': 707, '67': 5, 'a5': 11, '51': 1, '11': 37, 'ad': 66, '5f': 1, 'bd': 2, 'd0': 6, '27': 1, 'af': 1, '13': 12, 'eb': 7, '0f': 22, '07': 2, 'b7': 14, '23': 12, '73': 28, 'e1': 8, '43': 1, '99': 23, '61': 1, '3b': 6, '00': 17837, '05': 1, 'e9': 1, 'b5': 96, 'e5': 18, '47': 19, '6d': 1, '01': 5, '48': 254, 'ff': 680, '9f': 17, '17': 1, '39': 30, '49': 5, '7f': 7, '57': 4} 00 00 00 00 00 00 00 00 48 d0 d0 00 00 00 00 00 00 11 d0 00 48 00 48 00 00 00 11 d0 00 11 00 11 00 00 00 00 11 00 00 00 00 11 00 00 00 48 d0 d0 00 00 00 11 00 00 00 00 11 00 11 00 00 00 00 00 00 00 00 11 00 00 00 00 00 00 11 00 00 11 00 00 00 00 48 00 00 00 00 00 00 00 00 00 00 11 00 11 00 00 00 00 00 00 00 00 48 00 11 08 00 00 00 00 00 00 48 00 00 00 00 00 00 48 00 00 00 48 00 48 00 00 11 48 00 11 00 11 48 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 48 00 00 00 11 00 00 00 00 11 00 00 00 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 11 00 00 00 00 00 00 11 08 00 00 00 48 00 00 00 11 00 00 00 00 00 00 00 11 00 00 00 00 00 00 00 00 00 11 00 11 48 00 00 11 00 00 11 00 00 00 00 00 00 00 00 11 00 00 00 00 00 00 00 11 00 00 ff 48 00 11 00 00 00 00 00 00 11 00 48 00 00 00 00 00 11 00 00 00 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 00 00 48 00 00 00 11 00 00 00 00 00 00 11 00 48 00 00 00 00 48 00 11 00 00 00 00 00 00 00 00 00 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 48 00 00 00 00 00 00 00 00 00 00 00 00 00 36 00 00 00 00 00 00 00 00 00 00 00 72 00 00 00 72 00 00 00 00 00 00 00 00 00 00 00 72 36 00 36 00 00 00 36 00 72 00 00 72 00 00 00 72 08 00 00 00 72 00 00 00 36 00 36 36 08 00 00 00 72 00 00 00 00 00 00 00 72 00 00 00 72 00 00 72 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 72 00 00 00 00 00 00 00 00 00 72 00 00 72 00 00 00 00 00 00 00 ff 00 ff 00 00 72 ff 00 72 00 ff ff ff 00 00 00 00 00 00 00 72 00 00 00 00 00 72 00 72 00 00 00 00 00 00 72 08 00 00 00 00 00 72 00 00 00 00 00 00 00 00 00 00 00 00 72 00 72 08 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 72 00 00 00 00 00 00 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 72 00 00 00 00 00 00 72 00 00 72 00 00 00 00 00 00 00 00 72 08 00 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00 72 00 00 72 00 72 00 00 00 00 00 00 72 00 00 72 00 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 72 08 08 00 00 00 00 00 00 00 00 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 72 08 00 00 00 00 00 00 00 00 72 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff 00 00 00 00 00 00 00 00 00 00 00 47 08 00 00 00 00 00 00 00 00 00 00 00 00 00 ff 00 47 08 08 08 00 00 00 ff 00 00 00 00 00 00 00 00 d5 00 47 00 00 00 00 00 d5 08 00 00 d5 47 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 47 08 ff 47 00 00 00 00 00 00 d5 00 00 00 00 00 47 00 00 00 47 00 47 00 00 d5 00 00 00 d5 00 d5 08 00 00 00 00 00 47 00 00 00 00 00 d5 08 ff 00 d5 08 00 00 00 00 47 00 d5 00 00 00 00 00 00 00 00 00 47 00 00 47 00 00 00 00 00 00 00 00 d5 08 00 00 d5 08 00 00 d5 00 00 d5 00 00 00 00 00 00 00 47 00 d5 00 00 00 00 00 00 00 00 00 00 00 00 d5 08 00 00 00 00 00 */
TITLE Data Definitions (DataDef.asm) ; Examples showing how to define data. ; Last update: 2/1/02 INCLUDE Irvine32.inc ; ----------------- Byte Values ---------------- .data value1 BYTE 'A' value2 BYTE 0 value3 BYTE 255 value4 SBYTE -128 value5 SBYTE +127 value6 BYTE ? list1 BYTE 10, 32, 41h, 00100010b list2 BYTE 0Ah, 20h, 'A', 22h array1 BYTE 20 DUP(0) greeting1 BYTE "Good afternoon",0 ; ----------------- Word Values --------------------- word1 WORD 65535 ; largest unsigned value word2 SWORD -32768 ; smallest signed value word3 WORD ? ; uninitialized myList WORD 1,2,3,4,5 ; array of words ; --------------- DoubleWord Values -------------- val1 DWORD 12345678h val2 SDWORD -2147483648 val3 DWORD 20 DUP(?) ; ------- QuadWord and TenByte Values ------------ quad1 DQ 234567812345678h ten1 DT 1000000000123456789Ah ;------------------ Reals -------------------- rVal1 REAL4 -1.2 rVal2 REAL8 3.2E-260 rVal3 REAL10 4.6E4096 ; The following ranges were discovered by trial and error: ShortRealMax REAL4 9.9E+37 ; maximum exponent ShortRealMin REAL4 9.9E-38 ; minimum exponent LongRealMax REAL8 9.0E+307 ; maximum exponent LongRealMin REAL8 9.9E-308 ; minimum exponent ExtRealMax REAL10 9.9E+4931 ; maximum exponent ExtRealMin REAL10 9.9E-5199 ; minimum exponent ShortArray REAL4 20 DUP(0.0) ; ----------------- Pointers --------------------- arrayB BYTE 10,20,30,40 arrayW WORD 1000h,2000h,3000h,4000h ptrB DWORD arrayB ; points to arrayB ptrW DWORD arrayW ; points to arrayW .code main PROC ; (insert instructions here) exit main ENDP END main
/* * Copyright 2011-2020 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ #include <bx/platform.h> #include "bgfx_p.h" #include <bgfx/embedded_shader.h> #include <bx/file.h> #include <bx/mutex.h> #include "topology.h" #include "version.h" #if BX_PLATFORM_OSX || BX_PLATFORM_IOS # include <objc/message.h> #endif // BX_PLATFORM_OSX BX_ERROR_RESULT(BGFX_ERROR_TEXTURE_VALIDATION, BX_MAKEFOURCC('b', 'g', 0, 1) ); #ifdef NMENG extern uint8_t* nmLoadEmeddedShader(const char* pBaseName, uint32_t& size); #endif namespace bgfx { #define BGFX_API_THREAD_MAGIC UINT32_C(0x78666762) #if BGFX_CONFIG_MULTITHREADED # define BGFX_CHECK_API_THREAD() \ BX_CHECK(NULL != s_ctx, "Library is not initialized yet."); \ BX_CHECK(BGFX_API_THREAD_MAGIC == s_threadIndex, "Must be called from main thread.") # define BGFX_CHECK_RENDER_THREAD() \ BX_CHECK( (NULL != s_ctx && s_ctx->m_singleThreaded) \ || ~BGFX_API_THREAD_MAGIC == s_threadIndex \ , "Must be called from render thread." \ ) #else # define BGFX_CHECK_API_THREAD() # define BGFX_CHECK_RENDER_THREAD() #endif // BGFX_CONFIG_MULTITHREADED #define BGFX_CHECK_CAPS(_caps, _msg) \ BX_CHECK(0 != (g_caps.supported & (_caps) ) \ , _msg " Use bgfx::getCaps to check " #_caps " backend renderer capabilities." \ ); #if BGFX_CONFIG_USE_TINYSTL void* TinyStlAllocator::static_allocate(size_t _bytes) { return BX_ALLOC(g_allocator, _bytes); } void TinyStlAllocator::static_deallocate(void* _ptr, size_t /*_bytes*/) { if (NULL != _ptr) { BX_FREE(g_allocator, _ptr); } } #endif // BGFX_CONFIG_USE_TINYSTL struct CallbackStub : public CallbackI { virtual ~CallbackStub() { } virtual void fatal(const char* _filePath, uint16_t _line, Fatal::Enum _code, const char* _str) override { if (Fatal::DebugCheck == _code) { bx::debugBreak(); } else { bgfx::trace(_filePath, _line, "BGFX 0x%08x: %s\n", _code, _str); BX_UNUSED(_code, _str); abort(); } } virtual void traceVargs(const char* _filePath, uint16_t _line, const char* _format, va_list _argList) override { char temp[2048]; char* out = temp; va_list argListCopy; va_copy(argListCopy, _argList); int32_t len = bx::snprintf(out, sizeof(temp), "%s (%d): ", _filePath, _line); int32_t total = len + bx::vsnprintf(out + len, sizeof(temp)-len, _format, argListCopy); va_end(argListCopy); if ( (int32_t)sizeof(temp) < total) { out = (char*)alloca(total+1); bx::memCopy(out, temp, len); bx::vsnprintf(out + len, total-len, _format, _argList); } out[total] = '\0'; bx::debugOutput(out); } virtual void profilerBegin(const char* /*_name*/, uint32_t /*_abgr*/, const char* /*_filePath*/, uint16_t /*_line*/) override { } virtual void profilerBeginLiteral(const char* /*_name*/, uint32_t /*_abgr*/, const char* /*_filePath*/, uint16_t /*_line*/) override { } virtual void profilerEnd() override { } virtual uint32_t cacheReadSize(uint64_t /*_id*/) override { return 0; } virtual bool cacheRead(uint64_t /*_id*/, void* /*_data*/, uint32_t /*_size*/) override { return false; } virtual void cacheWrite(uint64_t /*_id*/, const void* /*_data*/, uint32_t /*_size*/) override { } virtual void screenShot(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data, uint32_t _size, bool _yflip) override { BX_UNUSED(_filePath, _width, _height, _pitch, _data, _size, _yflip); const int32_t len = bx::strLen(_filePath)+5; char* filePath = (char*)alloca(len); bx::strCopy(filePath, len, _filePath); bx::strCat(filePath, len, ".tga"); bx::FileWriter writer; if (bx::open(&writer, filePath) ) { bimg::imageWriteTga(&writer, _width, _height, _pitch, _data, false, _yflip); bx::close(&writer); } } virtual void captureBegin(uint32_t /*_width*/, uint32_t /*_height*/, uint32_t /*_pitch*/, TextureFormat::Enum /*_format*/, bool /*_yflip*/) override { BX_TRACE("Warning: using capture without callback (a.k.a. pointless)."); } virtual void captureEnd() override { } virtual void captureFrame(const void* /*_data*/, uint32_t /*_size*/) override { } }; #ifndef BGFX_CONFIG_MEMORY_TRACKING # define BGFX_CONFIG_MEMORY_TRACKING (BGFX_CONFIG_DEBUG && BX_CONFIG_SUPPORTS_THREADING) #endif // BGFX_CONFIG_MEMORY_TRACKING const size_t kNaturalAlignment = 8; class AllocatorStub : public bx::AllocatorI { public: AllocatorStub() #if BGFX_CONFIG_MEMORY_TRACKING : m_numBlocks(0) , m_maxBlocks(0) #endif // BGFX_CONFIG_MEMORY_TRACKING { } virtual void* realloc(void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line) override { if (0 == _size) { if (NULL != _ptr) { if (kNaturalAlignment >= _align) { #if BGFX_CONFIG_MEMORY_TRACKING { bx::MutexScope scope(m_mutex); BX_CHECK(m_numBlocks > 0, "Number of blocks is 0. Possible alloc/free mismatch?"); --m_numBlocks; } #endif // BGFX_CONFIG_MEMORY_TRACKING ::free(_ptr); } else { bx::alignedFree(this, _ptr, _align, _file, _line); } } return NULL; } else if (NULL == _ptr) { if (kNaturalAlignment >= _align) { #if BGFX_CONFIG_MEMORY_TRACKING { bx::MutexScope scope(m_mutex); ++m_numBlocks; m_maxBlocks = bx::max(m_maxBlocks, m_numBlocks); } #endif // BGFX_CONFIG_MEMORY_TRACKING return ::malloc(_size); } return bx::alignedAlloc(this, _size, _align, _file, _line); } if (kNaturalAlignment >= _align) { #if BGFX_CONFIG_MEMORY_TRACKING if (NULL == _ptr) { bx::MutexScope scope(m_mutex); ++m_numBlocks; m_maxBlocks = bx::max(m_maxBlocks, m_numBlocks); } #endif // BGFX_CONFIG_MEMORY_TRACKING return ::realloc(_ptr, _size); } return bx::alignedRealloc(this, _ptr, _size, _align, _file, _line); } void checkLeaks(); protected: #if BGFX_CONFIG_MEMORY_TRACKING bx::Mutex m_mutex; uint32_t m_numBlocks; uint32_t m_maxBlocks; #endif // BGFX_CONFIG_MEMORY_TRACKING }; static CallbackStub* s_callbackStub = NULL; static AllocatorStub* s_allocatorStub = NULL; static bool s_graphicsDebuggerPresent = false; CallbackI* g_callback = NULL; bx::AllocatorI* g_allocator = NULL; Caps g_caps; #if BGFX_CONFIG_MULTITHREADED && !defined(BX_THREAD_LOCAL) class ThreadData { BX_CLASS(ThreadData , NO_COPY , NO_ASSIGNMENT ); public: ThreadData(uintptr_t _rhs) { union { uintptr_t ui; void* ptr; } cast = { _rhs }; m_tls.set(cast.ptr); } operator uintptr_t() const { union { uintptr_t ui; void* ptr; } cast; cast.ptr = m_tls.get(); return cast.ui; } uintptr_t operator=(uintptr_t _rhs) { union { uintptr_t ui; void* ptr; } cast = { _rhs }; m_tls.set(cast.ptr); return _rhs; } bool operator==(uintptr_t _rhs) const { uintptr_t lhs = *this; return lhs == _rhs; } private: bx::TlsData m_tls; }; static ThreadData s_threadIndex(0); #elif !BGFX_CONFIG_MULTITHREADED static uint32_t s_threadIndex(0); #else static BX_THREAD_LOCAL uint32_t s_threadIndex(0); #endif static Context* s_ctx = NULL; static bool s_renderFrameCalled = false; InternalData g_internalData; PlatformData g_platformData; bool g_platformDataChangedSinceReset = false; const char* getTypeName(Handle _handle) { switch (_handle.type) { case Handle::IndexBuffer: return "IB"; case Handle::Shader: return "S"; case Handle::Texture: return "T"; case Handle::VertexBuffer: return "VB"; default: break; } BX_CHECK(false, "You should not be here."); return "?"; } void AllocatorStub::checkLeaks() { #if BGFX_CONFIG_MEMORY_TRACKING // BK - CallbackStub will be deleted after printing this info, so there is always one // leak if CallbackStub is used. BX_WARN(uint32_t(NULL != s_callbackStub ? 1 : 0) == m_numBlocks , "MEMORY LEAK: %d (max: %d)" , m_numBlocks , m_maxBlocks ); #endif // BGFX_CONFIG_MEMORY_TRACKING } void setPlatformData(const PlatformData& _data) { if (NULL != s_ctx) { BGFX_FATAL(true && g_platformData.ndt == _data.ndt && g_platformData.context == _data.context , Fatal::UnableToInitialize , "Only backbuffer pointer and native window handle can be changed after initialization!" ); } bx::memCopy(&g_platformData, &_data, sizeof(PlatformData) ); g_platformDataChangedSinceReset = true; } const InternalData* getInternalData() { return &g_internalData; } uintptr_t overrideInternal(TextureHandle _handle, uintptr_t _ptr) { BGFX_CHECK_RENDER_THREAD(); RendererContextI* rci = s_ctx->m_renderCtx; if (0 == rci->getInternal(_handle) ) { return 0; } rci->overrideInternal(_handle, _ptr); return rci->getInternal(_handle); } uintptr_t overrideInternal(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint64_t _flags) { BGFX_CHECK_RENDER_THREAD(); RendererContextI* rci = s_ctx->m_renderCtx; if (0 == rci->getInternal(_handle) ) { return 0; } uint32_t size = sizeof(uint32_t) + sizeof(TextureCreate); Memory* mem = const_cast<Memory*>(alloc(size) ); bx::StaticMemoryBlockWriter writer(mem->data, mem->size); uint32_t magic = BGFX_CHUNK_MAGIC_TEX; bx::write(&writer, magic); TextureCreate tc; tc.m_width = _width; tc.m_height = _height; tc.m_depth = 0; tc.m_numLayers = 1; tc.m_numMips = bx::max<uint8_t>(1, _numMips); tc.m_format = _format; tc.m_cubeMap = false; tc.m_mem = NULL; bx::write(&writer, tc); rci->destroyTexture(_handle); rci->createTexture(_handle, mem, _flags, 0); release(mem); return rci->getInternal(_handle); } void setGraphicsDebuggerPresent(bool _present) { BX_TRACE("Graphics debugger is %spresent.", _present ? "" : "not "); s_graphicsDebuggerPresent = _present; } bool isGraphicsDebuggerPresent() { return s_graphicsDebuggerPresent; } void fatal(const char* _filePath, uint16_t _line, Fatal::Enum _code, const char* _format, ...) { va_list argList; va_start(argList, _format); char temp[8192]; char* out = temp; int32_t len = bx::vsnprintf(out, sizeof(temp), _format, argList); if ( (int32_t)sizeof(temp) < len) { out = (char*)alloca(len+1); len = bx::vsnprintf(out, len, _format, argList); } out[len] = '\0'; if (BX_UNLIKELY(NULL == g_callback) ) { bx::debugPrintf("%s(%d): BGFX 0x%08x: %s", _filePath, _line, _code, out); abort(); } else { g_callback->fatal(_filePath, _line, _code, out); } va_end(argList); } void trace(const char* _filePath, uint16_t _line, const char* _format, ...) { va_list argList; va_start(argList, _format); if (BX_UNLIKELY(NULL == g_callback) ) { bx::debugPrintfVargs(_format, argList); } else { g_callback->traceVargs(_filePath, _line, _format, argList); } va_end(argList); } #include "vs_debugfont.bin.h" #include "fs_debugfont.bin.h" #include "vs_clear.bin.h" #include "fs_clear0.bin.h" #include "fs_clear1.bin.h" #include "fs_clear2.bin.h" #include "fs_clear3.bin.h" #include "fs_clear4.bin.h" #include "fs_clear5.bin.h" #include "fs_clear6.bin.h" #include "fs_clear7.bin.h" static EmbeddedShader s_embeddedShaders[] = { BGFX_EMBEDDED_SHADER(fs_clear0), BGFX_EMBEDDED_SHADER(vs_clear), BGFX_EMBEDDED_SHADER(vs_debugfont), BGFX_EMBEDDED_SHADER(fs_debugfont), #if !defined BX_PLATFORM_ORBIS BGFX_EMBEDDED_SHADER(fs_clear1), BGFX_EMBEDDED_SHADER(fs_clear2), BGFX_EMBEDDED_SHADER(fs_clear3), BGFX_EMBEDDED_SHADER(fs_clear4), BGFX_EMBEDDED_SHADER(fs_clear5), BGFX_EMBEDDED_SHADER(fs_clear6), BGFX_EMBEDDED_SHADER(fs_clear7), #endif BGFX_EMBEDDED_SHADER_END() }; static bool bLoadedEmbeddedShaders = false; void loadEmbeddedShaders() { #ifdef NMENG for (EmbeddedShader* es = s_embeddedShaders; NULL != es->name; ++es) { BX_TRACE("%s", es->name); uint32_t size; es->data[0].pDynData = nullptr; auto data = nmLoadEmeddedShader(es->name,size); if (size) { EmbeddedShader *pEs = (EmbeddedShader*)es; pEs->data[0].pDynData = data; pEs->data[0].size = size; } } bLoadedEmbeddedShaders = true; #endif } ShaderHandle createEmbeddedShader(const EmbeddedShader* _es, RendererType::Enum _type, const char* _name) { #if defined NM_PLATFORM_ORBIS if (!bLoadedEmbeddedShaders) { loadEmbeddedShaders(); } #endif for (const EmbeddedShader* es = _es; NULL != es->name; ++es) { if (0 == bx::strCmp(_name, es->name) ) { for (const EmbeddedShader::Data* esd = es->data; RendererType::Count != esd->type; ++esd) { if (_type == esd->type && 1 < esd->size) { auto pData = esd->data; if (esd->pDynData) pData = esd->pDynData; BX_TRACE("createshader %s", es->name); ShaderHandle handle = createShader(makeRef(pData, esd->size) ); if (isValid(handle) ) { setName(handle, _name); } return handle; } } } } ShaderHandle handle = BGFX_INVALID_HANDLE; return handle; } void dump(const VertexLayout& _layout) { if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) { BX_TRACE("vertexlayout %08x (%08x), stride %d" , _layout.m_hash , bx::hash<bx::HashMurmur2A>(_layout.m_attributes) , _layout.m_stride ); for (uint32_t attr = 0; attr < Attrib::Count; ++attr) { if (UINT16_MAX != _layout.m_attributes[attr]) { uint8_t num; AttribType::Enum type; bool normalized; bool asInt; _layout.decode(Attrib::Enum(attr), num, type, normalized, asInt); BX_TRACE("\tattr %d - %s, num %d, type %d, norm %d, asint %d, offset %d" , attr , getAttribName(Attrib::Enum(attr) ) , num , type , normalized , asInt , _layout.m_offset[attr] ); } } } } #include "charset.h" void charsetFillTexture(const uint8_t* _charset, uint8_t* _rgba, uint32_t _height, uint32_t _pitch, uint32_t _bpp) { for (uint32_t ii = 0; ii < 256; ++ii) { uint8_t* pix = &_rgba[ii*8*_bpp]; for (uint32_t yy = 0; yy < _height; ++yy) { for (uint32_t xx = 0; xx < 8; ++xx) { uint8_t bit = 1<<(7-xx); bx::memSet(&pix[xx*_bpp], _charset[ii*_height+yy]&bit ? 255 : 0, _bpp); } pix += _pitch; } } } static uint8_t parseAttrTo(char*& _ptr, char _to, uint8_t _default) { const bx::StringView str = bx::strFind(_ptr, _to); if (!str.isEmpty() && 3 > str.getPtr()-_ptr) { char tmp[4]; int32_t len = int32_t(str.getPtr()-_ptr); bx::strCopy(tmp, sizeof(tmp), _ptr, len); uint32_t attr; bx::fromString(&attr, tmp); _ptr += len+1; return uint8_t(attr); } return _default; } static uint8_t parseAttr(char*& _ptr, uint8_t _default) { char* ptr = _ptr; if (*ptr++ != '[') { return _default; } if (0 == bx::strCmp(ptr, "0m", 2) ) { _ptr = ptr + 2; return _default; } uint8_t fg = parseAttrTo(ptr, ';', _default & 0xf); uint8_t bg = parseAttrTo(ptr, 'm', _default >> 4); uint8_t attr = (bg<<4) | fg; _ptr = ptr; return attr; } void TextVideoMem::printfVargs(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, va_list _argList) { if (_x < m_width && _y < m_height) { va_list argListCopy; va_copy(argListCopy, _argList); uint32_t num = bx::vsnprintf(NULL, 0, _format, argListCopy) + 1; char* temp = (char*)alloca(num); va_copy(argListCopy, _argList); num = bx::vsnprintf(temp, num, _format, argListCopy); uint8_t attr = _attr; MemSlot* mem = &m_mem[_y*m_width+_x]; for (uint32_t ii = 0, xx = _x; ii < num && xx < m_width; ++ii) { char ch = temp[ii]; if (BX_UNLIKELY(ch == '\x1b') ) { char* ptr = &temp[ii+1]; attr = parseAttr(ptr, _attr); ii += uint32_t(ptr - &temp[ii+1]); } else { mem->character = ch; mem->attribute = attr; ++mem; ++xx; } } } } static const uint32_t numCharsPerBatch = 1024; static const uint32_t numBatchVertices = numCharsPerBatch*4; static const uint32_t numBatchIndices = numCharsPerBatch*6; void TextVideoMemBlitter::init() { BGFX_CHECK_API_THREAD(); m_layout .begin() .add(Attrib::Position, 3, AttribType::Float) .add(Attrib::Color0, 4, AttribType::Uint8, true) .add(Attrib::Color1, 4, AttribType::Uint8, true) .add(Attrib::TexCoord0, 2, AttribType::Float) .end(); uint16_t width = 2048; uint16_t height = 24; uint8_t bpp = 1; uint32_t pitch = width*bpp; const Memory* mem; mem = alloc(pitch*height); uint8_t* rgba = mem->data; charsetFillTexture(vga8x8, rgba, 8, pitch, bpp); charsetFillTexture(vga8x16, &rgba[8*pitch], 16, pitch, bpp); m_texture = createTexture2D(width, height, false, 1, TextureFormat::R8 , BGFX_SAMPLER_MIN_POINT | BGFX_SAMPLER_MAG_POINT | BGFX_SAMPLER_MIP_POINT | BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP , mem ); ShaderHandle vsh = createEmbeddedShader(s_embeddedShaders, g_caps.rendererType, "vs_debugfont"); ShaderHandle fsh = createEmbeddedShader(s_embeddedShaders, g_caps.rendererType, "fs_debugfont"); BX_CHECK(isValid(vsh) && isValid(fsh), "Failed to create embedded blit shaders"); m_program = createProgram(vsh, fsh, true); m_vb = s_ctx->createTransientVertexBuffer(numBatchVertices*m_layout.m_stride, &m_layout); m_ib = s_ctx->createTransientIndexBuffer(numBatchIndices*2); } void TextVideoMemBlitter::shutdown() { BGFX_CHECK_API_THREAD(); if (isValid(m_program) ) { destroy(m_program); } destroy(m_texture); s_ctx->destroyTransientVertexBuffer(m_vb); s_ctx->destroyTransientIndexBuffer(m_ib); } static const uint32_t paletteSrgb[] = { 0x0, // Black 0xffa46534, // Blue 0xff069a4e, // Green 0xff9a9806, // Cyan 0xff0000cc, // Red 0xff7b5075, // Magenta 0xff00a0c4, // Brown 0xffcfd7d3, // Light Gray 0xff535755, // Dark Gray 0xffcf9f72, // Light Blue 0xff34e28a, // Light Green 0xffe2e234, // Light Cyan 0xff2929ef, // Light Red 0xffa87fad, // Light Magenta 0xff4fe9fc, // Yellow 0xffeceeee, // White }; BX_STATIC_ASSERT(BX_COUNTOF(paletteSrgb) == 16); static const uint32_t paletteLinear[] = { 0x0, // Black 0xff5e2108, // Blue 0xff005213, // Green 0xff525000, // Cyan 0xff000099, // Red 0xff32142d, // Magenta 0xff00598c, // Brown 0xff9fada6, // Light Gray 0xff161817, // Dark Gray 0xff9f582a, // Light Blue 0xff08c140, // Light Green 0xffc1c108, // Light Cyan 0xff0505dc, // Light Red 0xff63366a, // Light Magenta 0xff13cff8, // Yellow 0xffd5dada // White }; BX_STATIC_ASSERT(BX_COUNTOF(paletteLinear) == 16); void blit(RendererContextI* _renderCtx, TextVideoMemBlitter& _blitter, const TextVideoMem& _mem) { struct Vertex { float m_x; float m_y; float m_z; uint32_t m_fg; uint32_t m_bg; float m_u; float m_v; }; uint32_t yy = 0; uint32_t xx = 0; const float texelWidth = 1.0f/2048.0f; const float texelWidthHalf = RendererType::Direct3D9 == g_caps.rendererType ? 0.0f : texelWidth*0.5f; const float texelHeight = 1.0f/24.0f; const float texelHeightHalf = RendererType::Direct3D9 == g_caps.rendererType ? texelHeight*0.5f : 0.0f; const float utop = (_mem.m_small ? 0.0f : 8.0f)*texelHeight + texelHeightHalf; const float ubottom = (_mem.m_small ? 8.0f : 24.0f)*texelHeight + texelHeightHalf; const float fontHeight = (_mem.m_small ? 8.0f : 16.0f); _renderCtx->blitSetup(_blitter); const uint32_t* palette = 0 != (s_ctx->m_init.resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) ? paletteLinear : paletteSrgb ; for (;yy < _mem.m_height;) { Vertex* vertex = (Vertex*)_blitter.m_vb->data; uint16_t* indices = (uint16_t*)_blitter.m_ib->data; uint32_t startVertex = 0; uint32_t numIndices = 0; for (; yy < _mem.m_height && numIndices < numBatchIndices; ++yy) { xx = xx < _mem.m_width ? xx : 0; const TextVideoMem::MemSlot* line = &_mem.m_mem[yy*_mem.m_width+xx]; for (; xx < _mem.m_width && numIndices < numBatchIndices; ++xx) { uint32_t ch = line->character; const uint8_t attr = line->attribute; if (ch > 0xff) { ch = 0; } if (0 != (ch|attr) && (' ' != ch || 0 != (attr&0xf0) ) ) { const uint32_t fg = palette[attr&0xf]; const uint32_t bg = palette[(attr>>4)&0xf]; Vertex vert[4] = { { (xx )*8.0f, (yy )*fontHeight, 0.0f, fg, bg, (ch )*8.0f*texelWidth - texelWidthHalf, utop }, { (xx+1)*8.0f, (yy )*fontHeight, 0.0f, fg, bg, (ch+1)*8.0f*texelWidth - texelWidthHalf, utop }, { (xx+1)*8.0f, (yy+1)*fontHeight, 0.0f, fg, bg, (ch+1)*8.0f*texelWidth - texelWidthHalf, ubottom }, { (xx )*8.0f, (yy+1)*fontHeight, 0.0f, fg, bg, (ch )*8.0f*texelWidth - texelWidthHalf, ubottom }, }; bx::memCopy(vertex, vert, sizeof(vert) ); vertex += 4; indices[0] = uint16_t(startVertex+0); indices[1] = uint16_t(startVertex+1); indices[2] = uint16_t(startVertex+2); indices[3] = uint16_t(startVertex+2); indices[4] = uint16_t(startVertex+3); indices[5] = uint16_t(startVertex+0); startVertex += 4; indices += 6; numIndices += 6; } line++; } if (numIndices >= numBatchIndices) { break; } } _renderCtx->blitRender(_blitter, numIndices); } } void ClearQuad::init() { BGFX_CHECK_API_THREAD(); if (RendererType::Noop != g_caps.rendererType) { m_layout .begin() .add(Attrib::Position, 2, AttribType::Float) .end(); ShaderHandle vsh = createEmbeddedShader(s_embeddedShaders, g_caps.rendererType, "vs_clear"); BX_CHECK(isValid(vsh), "Failed to create clear quad embedded vertex shader \"vs_clear\""); for (uint32_t ii = 0, num = g_caps.limits.maxFBAttachments; ii < num; ++ii) { char name[32]; bx::snprintf(name, BX_COUNTOF(name), "fs_clear%d", ii); ShaderHandle fsh = createEmbeddedShader(s_embeddedShaders, g_caps.rendererType, name); BX_CHECK(isValid(fsh), "Failed to create clear quad embedded fragment shader \"%s\"", name); m_program[ii] = createProgram(vsh, fsh); BX_CHECK(isValid(m_program[ii]), "Failed to create clear quad program."); destroy(fsh); } destroy(vsh); struct Vertex { float m_x; float m_y; }; const uint16_t stride = m_layout.m_stride; const bgfx::Memory* mem = bgfx::alloc(4 * stride); Vertex* vertex = (Vertex*)mem->data; BX_CHECK(stride == sizeof(Vertex), "Stride/Vertex mismatch (stride %d, sizeof(Vertex) %d)", stride, sizeof(Vertex)); vertex->m_x = -1.0f; vertex->m_y = -1.0f; vertex++; vertex->m_x = 1.0f; vertex->m_y = -1.0f; vertex++; vertex->m_x = -1.0f; vertex->m_y = 1.0f; vertex++; vertex->m_x = 1.0f; vertex->m_y = 1.0f; m_vb = s_ctx->createVertexBuffer(mem, m_layout, 0); } } void ClearQuad::shutdown() { BGFX_CHECK_API_THREAD(); if (RendererType::Noop != g_caps.rendererType) { for (uint32_t ii = 0, num = g_caps.limits.maxFBAttachments; ii < num; ++ii) { if (isValid(m_program[ii]) ) { destroy(m_program[ii]); m_program[ii].idx = kInvalidHandle; } } s_ctx->destroyVertexBuffer(m_vb); } } const char* s_uniformTypeName[] = { "sampler1", NULL, "vec4", "mat3", "mat4", }; BX_STATIC_ASSERT(UniformType::Count == BX_COUNTOF(s_uniformTypeName) ); const char* getUniformTypeName(UniformType::Enum _enum) { BX_CHECK(_enum < UniformType::Count, "%d < UniformType::Count %d", _enum, UniformType::Count); return s_uniformTypeName[_enum]; } UniformType::Enum nameToUniformTypeEnum(const char* _name) { for (uint32_t ii = 0; ii < UniformType::Count; ++ii) { if (NULL != s_uniformTypeName[ii] && 0 == bx::strCmp(_name, s_uniformTypeName[ii]) ) { return UniformType::Enum(ii); } } return UniformType::Count; } static const char* s_predefinedName[PredefinedUniform::Count] = { "u_viewRect", "u_viewTexel", "u_view", "u_invView", "u_proj", "u_invProj", "u_viewProj", "u_invViewProj", "u_model", "u_modelView", "u_modelViewProj", "u_alphaRef4", }; const char* getPredefinedUniformName(PredefinedUniform::Enum _enum) { return s_predefinedName[_enum]; } PredefinedUniform::Enum nameToPredefinedUniformEnum(const char* _name) { for (uint32_t ii = 0; ii < PredefinedUniform::Count; ++ii) { if (0 == bx::strCmp(_name, s_predefinedName[ii]) ) { return PredefinedUniform::Enum(ii); } } return PredefinedUniform::Count; } void srtToMatrix4_x1(void* _dst, const void* _src) { Matrix4* mtx = reinterpret_cast< Matrix4*>(_dst); const Srt* srt = reinterpret_cast<const Srt*>(_src); const float rx = srt->rotate[0]; const float ry = srt->rotate[1]; const float rz = srt->rotate[2]; const float rw = srt->rotate[3]; const float xx2 = 2.0f * rx * rx; const float yy2 = 2.0f * ry * ry; const float zz2 = 2.0f * rz * rz; const float yx2 = 2.0f * ry * rx; const float yz2 = 2.0f * ry * rz; const float yw2 = 2.0f * ry * rw; const float wz2 = 2.0f * rw * rz; const float wx2 = 2.0f * rw * rx; const float xz2 = 2.0f * rx * rz; const float sx = srt->scale[0]; const float sy = srt->scale[1]; const float sz = srt->scale[2]; mtx->un.val[ 0] = (1.0f - yy2 - zz2)*sx; mtx->un.val[ 1] = ( yx2 + wz2)*sx; mtx->un.val[ 2] = ( xz2 - yw2)*sx; mtx->un.val[ 3] = 0.0f; mtx->un.val[ 4] = ( yx2 - wz2)*sy; mtx->un.val[ 5] = (1.0f - xx2 - zz2)*sy; mtx->un.val[ 6] = ( yz2 + wx2)*sy; mtx->un.val[ 7] = 0.0f; mtx->un.val[ 8] = ( xz2 + yw2)*sz; mtx->un.val[ 9] = ( yz2 - wx2)*sz; mtx->un.val[10] = (1.0f - xx2 - yy2)*sz; mtx->un.val[11] = 0.0f; const float tx = srt->translate[0]; const float ty = srt->translate[1]; const float tz = srt->translate[2]; mtx->un.val[12] = tx; mtx->un.val[13] = ty; mtx->un.val[14] = tz; mtx->un.val[15] = 1.0f; } void transpose(void* _dst, uint32_t _dstStride, const void* _src, uint32_t _srcStride = sizeof(bx::simd128_t) ) { uint8_t* dst = reinterpret_cast< uint8_t *>(_dst); const uint8_t* src = reinterpret_cast<const uint8_t *>(_src); using namespace bx; const simd128_t r0 = simd_ld<simd128_t>(src); src += _srcStride; const simd128_t r1 = simd_ld<simd128_t>(src); src += _srcStride; const simd128_t r2 = simd_ld<simd128_t>(src); src += _srcStride; const simd128_t r3 = simd_ld<simd128_t>(src); const simd128_t aibj = simd_shuf_xAyB(r0, r2); // aibj const simd128_t emfn = simd_shuf_xAyB(r1, r3); // emfn const simd128_t ckdl = simd_shuf_zCwD(r0, r2); // ckdl const simd128_t gohp = simd_shuf_zCwD(r1, r3); // gohp const simd128_t aeim = simd_shuf_xAyB(aibj, emfn); // aeim const simd128_t bfjn = simd_shuf_zCwD(aibj, emfn); // bfjn const simd128_t cgko = simd_shuf_xAyB(ckdl, gohp); // cgko const simd128_t dhlp = simd_shuf_zCwD(ckdl, gohp); // dhlp simd_st(dst, aeim); dst += _dstStride; simd_st(dst, bfjn); dst += _dstStride; simd_st(dst, cgko); dst += _dstStride; simd_st(dst, dhlp); } void srtToMatrix4_x4_Ref(void* _dst, const void* _src) { uint8_t* dst = reinterpret_cast< uint8_t*>(_dst); const uint8_t* src = reinterpret_cast<const uint8_t*>(_src); srtToMatrix4_x1(dst + 0*sizeof(Matrix4), src + 0*sizeof(Srt) ); srtToMatrix4_x1(dst + 1*sizeof(Matrix4), src + 1*sizeof(Srt) ); srtToMatrix4_x1(dst + 2*sizeof(Matrix4), src + 2*sizeof(Srt) ); srtToMatrix4_x1(dst + 3*sizeof(Matrix4), src + 3*sizeof(Srt) ); } void srtToMatrix4_x4_Simd(void* _dst, const void* _src) { using namespace bx; simd128_t* dst = reinterpret_cast< simd128_t*>(_dst); const simd128_t* src = reinterpret_cast<const simd128_t*>(_src); simd128_t rotate[4]; simd128_t translate[4]; simd128_t scale[4]; transpose(rotate, sizeof(simd128_t), src + 0, sizeof(Srt) ); transpose(translate, sizeof(simd128_t), src + 1, sizeof(Srt) ); transpose(scale, sizeof(simd128_t), src + 2, sizeof(Srt) ); const simd128_t rx = simd_ld<simd128_t>(rotate + 0); const simd128_t ry = simd_ld<simd128_t>(rotate + 1); const simd128_t rz = simd_ld<simd128_t>(rotate + 2); const simd128_t rw = simd_ld<simd128_t>(rotate + 3); const simd128_t tx = simd_ld<simd128_t>(translate + 0); const simd128_t ty = simd_ld<simd128_t>(translate + 1); const simd128_t tz = simd_ld<simd128_t>(translate + 2); const simd128_t sx = simd_ld<simd128_t>(scale + 0); const simd128_t sy = simd_ld<simd128_t>(scale + 1); const simd128_t sz = simd_ld<simd128_t>(scale + 2); const simd128_t zero = simd_splat(0.0f); const simd128_t one = simd_splat(1.0f); const simd128_t two = simd_splat(2.0f); const simd128_t xx = simd_mul(rx, rx); const simd128_t xx2 = simd_mul(two, xx); const simd128_t yy = simd_mul(ry, ry); const simd128_t yy2 = simd_mul(two, yy); const simd128_t zz = simd_mul(rz, rz); const simd128_t zz2 = simd_mul(two, zz); const simd128_t yx = simd_mul(ry, rx); const simd128_t yx2 = simd_mul(two, yx); const simd128_t yz = simd_mul(ry, rz); const simd128_t yz2 = simd_mul(two, yz); const simd128_t yw = simd_mul(ry, rw); const simd128_t yw2 = simd_mul(two, yw); const simd128_t wz = simd_mul(rw, rz); const simd128_t wz2 = simd_mul(two, wz); const simd128_t wx = simd_mul(rw, rx); const simd128_t wx2 = simd_mul(two, wx); const simd128_t xz = simd_mul(rx, rz); const simd128_t xz2 = simd_mul(two, xz); const simd128_t t0x = simd_sub(one, yy2); const simd128_t r0x = simd_sub(t0x, zz2); const simd128_t r0y = simd_add(yx2, wz2); const simd128_t r0z = simd_sub(xz2, yw2); const simd128_t r1x = simd_sub(yx2, wz2); const simd128_t omxx2 = simd_sub(one, xx2); const simd128_t r1y = simd_sub(omxx2, zz2); const simd128_t r1z = simd_add(yz2, wx2); const simd128_t r2x = simd_add(xz2, yw2); const simd128_t r2y = simd_sub(yz2, wx2); const simd128_t r2z = simd_sub(omxx2, yy2); simd128_t tmp[4]; tmp[0] = simd_mul(r0x, sx); tmp[1] = simd_mul(r0y, sx); tmp[2] = simd_mul(r0z, sx); tmp[3] = zero; transpose(dst + 0, sizeof(Matrix4), tmp); tmp[0] = simd_mul(r1x, sy); tmp[1] = simd_mul(r1y, sy); tmp[2] = simd_mul(r1z, sy); tmp[3] = zero; transpose(dst + 1, sizeof(Matrix4), tmp); tmp[0] = simd_mul(r2x, sz); tmp[1] = simd_mul(r2y, sz); tmp[2] = simd_mul(r2z, sz); tmp[3] = zero; transpose(dst + 2, sizeof(Matrix4), tmp); tmp[0] = tx; tmp[1] = ty; tmp[2] = tz; tmp[3] = one; transpose(dst + 3, sizeof(Matrix4), tmp); } void srtToMatrix4(void* _dst, const void* _src, uint32_t _num) { uint8_t* dst = reinterpret_cast< uint8_t*>(_dst); const uint8_t* src = reinterpret_cast<const uint8_t*>(_src); if (!bx::isAligned(src, 16) ) { for (uint32_t ii = 0, num = _num / 4; ii < num; ++ii) { srtToMatrix4_x4_Ref(dst, src); src += 4*sizeof(Srt); dst += 4*sizeof(Matrix4); } } else { for (uint32_t ii = 0, num = _num / 4; ii < num; ++ii) { srtToMatrix4_x4_Simd(dst, src); src += 4*sizeof(Srt); dst += 4*sizeof(Matrix4); } } for (uint32_t ii = 0, num = _num & 3; ii < num; ++ii) { srtToMatrix4_x1(dst, src); src += sizeof(Srt); dst += sizeof(Matrix4); } } void EncoderImpl::submit(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth, uint8_t _flags) { if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) && (_flags & BGFX_DISCARD_STATE)) { m_uniformSet.clear(); } if (BX_ENABLED(BGFX_CONFIG_DEBUG_OCCLUSION) && isValid(_occlusionQuery) ) { BX_CHECK(m_occlusionQuerySet.end() == m_occlusionQuerySet.find(_occlusionQuery.idx) , "OcclusionQuery %d was already used for this frame." , _occlusionQuery.idx ); m_occlusionQuerySet.insert(_occlusionQuery.idx); } if (m_discard) { discard(_flags); return; } if (0 == m_draw.m_numVertices && 0 == m_draw.m_numIndices) { discard(_flags); ++m_numDropped; return; } const uint32_t renderItemIdx = bx::atomicFetchAndAddsat<uint32_t>(&m_frame->m_numRenderItems, 1, BGFX_CONFIG_MAX_DRAW_CALLS); if (BGFX_CONFIG_MAX_DRAW_CALLS-1 <= renderItemIdx) { discard(_flags); ++m_numDropped; return; } ++m_numSubmitted; UniformBuffer* uniformBuffer = m_frame->m_uniformBuffer[m_uniformIdx]; m_uniformEnd = uniformBuffer->getPos(); m_key.m_program = isValid(_program) ? _program : ProgramHandle{0} ; m_key.m_view = _id; SortKey::Enum type = SortKey::SortProgram; switch (s_ctx->m_view[_id].m_mode) { case ViewMode::Sequential: m_key.m_seq = s_ctx->getSeqIncr(_id); type = SortKey::SortSequence; break; case ViewMode::DepthAscending: m_key.m_depth = _depth; type = SortKey::SortDepth; break; case ViewMode::DepthDescending: m_key.m_depth = UINT32_MAX-_depth; type = SortKey::SortDepth; break; default: break; } uint64_t key = m_key.encodeDraw(type); m_frame->m_sortKeys[renderItemIdx] = key; m_frame->m_sortValues[renderItemIdx] = RenderItemCount(renderItemIdx); m_draw.m_uniformIdx = m_uniformIdx; m_draw.m_uniformBegin = m_uniformBegin; m_draw.m_uniformEnd = m_uniformEnd; if (UINT8_MAX != m_draw.m_streamMask) { uint32_t numVertices = UINT32_MAX; for (uint32_t idx = 0, streamMask = m_draw.m_streamMask ; 0 != streamMask ; streamMask >>= 1, idx += 1 ) { const uint32_t ntz = bx::uint32_cnttz(streamMask); streamMask >>= ntz; idx += ntz; numVertices = bx::min(numVertices, m_numVertices[idx]); } m_draw.m_numVertices = numVertices; } else { m_draw.m_numVertices = m_numVertices[0]; } if (isValid(_occlusionQuery) ) { m_draw.m_stateFlags |= BGFX_STATE_INTERNAL_OCCLUSION_QUERY; m_draw.m_occlusionQuery = _occlusionQuery; } m_frame->m_renderItem[renderItemIdx].draw = m_draw; m_frame->m_renderItemBind[renderItemIdx] = m_bind; m_draw.clear(_flags); m_bind.clear(_flags); if (_flags & BGFX_DISCARD_STATE) { m_uniformBegin = m_uniformEnd; } } void EncoderImpl::dispatch(ViewId _id, ProgramHandle _handle, uint32_t _numX, uint32_t _numY, uint32_t _numZ, uint8_t _flags) { if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) ) { m_uniformSet.clear(); } if (m_discard) { discard(_flags); return; } const uint32_t renderItemIdx = bx::atomicFetchAndAddsat<uint32_t>(&m_frame->m_numRenderItems, 1, BGFX_CONFIG_MAX_DRAW_CALLS); if (BGFX_CONFIG_MAX_DRAW_CALLS-1 <= renderItemIdx) { discard(_flags); ++m_numDropped; return; } ++m_numSubmitted; UniformBuffer* uniformBuffer = m_frame->m_uniformBuffer[m_uniformIdx]; m_uniformEnd = uniformBuffer->getPos(); m_compute.m_startMatrix = m_draw.m_startMatrix; m_compute.m_numMatrices = m_draw.m_numMatrices; m_compute.m_numX = bx::max(_numX, 1u); m_compute.m_numY = bx::max(_numY, 1u); m_compute.m_numZ = bx::max(_numZ, 1u); m_key.m_program = _handle; m_key.m_depth = 0; m_key.m_view = _id; m_key.m_seq = s_ctx->getSeqIncr(_id); uint64_t key = m_key.encodeCompute(); m_frame->m_sortKeys[renderItemIdx] = key; m_frame->m_sortValues[renderItemIdx] = RenderItemCount(renderItemIdx); m_compute.m_uniformIdx = m_uniformIdx; m_compute.m_uniformBegin = m_uniformBegin; m_compute.m_uniformEnd = m_uniformEnd; m_frame->m_renderItem[renderItemIdx].compute = m_compute; m_frame->m_renderItemBind[renderItemIdx] = m_bind; m_compute.clear(_flags); m_bind.clear(_flags); m_uniformBegin = m_uniformEnd; } void EncoderImpl::blit(ViewId _id, TextureHandle _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, TextureHandle _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth) { BX_WARN(m_frame->m_numBlitItems < BGFX_CONFIG_MAX_BLIT_ITEMS , "Exceed number of available blit items per frame. BGFX_CONFIG_MAX_BLIT_ITEMS is %d. Skipping blit." , BGFX_CONFIG_MAX_BLIT_ITEMS ); if (m_frame->m_numBlitItems < BGFX_CONFIG_MAX_BLIT_ITEMS) { uint16_t item = m_frame->m_numBlitItems++; BlitItem& bi = m_frame->m_blitItem[item]; bi.m_srcX = _srcX; bi.m_srcY = _srcY; bi.m_srcZ = _srcZ; bi.m_dstX = _dstX; bi.m_dstY = _dstY; bi.m_dstZ = _dstZ; bi.m_width = _width; bi.m_height = _height; bi.m_depth = _depth; bi.m_srcMip = _srcMip; bi.m_dstMip = _dstMip; bi.m_src = _src; bi.m_dst = _dst; BlitKey key; key.m_view = _id; key.m_item = item; m_frame->m_blitKeys[item] = key.encode(); } } void Frame::sort() { BGFX_PROFILER_SCOPE("bgfx/Sort", 0xff2040ff); ViewId viewRemap[BGFX_CONFIG_MAX_VIEWS]; for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii) { viewRemap[m_viewRemap[ii] ] = ViewId(ii); } for (uint32_t ii = 0, num = m_numRenderItems; ii < num; ++ii) { m_sortKeys[ii] = SortKey::remapView(m_sortKeys[ii], viewRemap); } bx::radixSort(m_sortKeys, s_ctx->m_tempKeys, m_sortValues, s_ctx->m_tempValues, m_numRenderItems); for (uint32_t ii = 0, num = m_numBlitItems; ii < num; ++ii) { m_blitKeys[ii] = BlitKey::remapView(m_blitKeys[ii], viewRemap); } bx::radixSort(m_blitKeys, (uint32_t*)&s_ctx->m_tempKeys, m_numBlitItems); } RenderFrame::Enum renderFrame(int32_t _msecs) { if (BX_ENABLED(BGFX_CONFIG_MULTITHREADED) ) { if (s_renderFrameCalled) { BGFX_CHECK_RENDER_THREAD(); } if (NULL == s_ctx) { s_renderFrameCalled = true; s_threadIndex = ~BGFX_API_THREAD_MAGIC; return RenderFrame::NoContext; } int32_t msecs = -1 == _msecs ? BGFX_CONFIG_API_SEMAPHORE_TIMEOUT : _msecs ; RenderFrame::Enum result = s_ctx->renderFrame(msecs); if (RenderFrame::Exiting == result) { Context* ctx = s_ctx; ctx->apiSemWait(); s_ctx = NULL; ctx->renderSemPost(); } return result; } BX_CHECK(false, "This call only makes sense if used with multi-threaded renderer."); return RenderFrame::NoContext; } const uint32_t g_uniformTypeSize[UniformType::Count+1] = { sizeof(int32_t), 0, 4*sizeof(float), 3*3*sizeof(float), 4*4*sizeof(float), 1, }; void UniformBuffer::writeUniform(UniformType::Enum _type, uint16_t _loc, const void* _value, uint16_t _num) { uint32_t opcode = encodeOpcode(_type, _loc, _num, true); write(opcode); write(_value, g_uniformTypeSize[_type]*_num); } void UniformBuffer::writeUniformHandle(UniformType::Enum _type, uint16_t _loc, UniformHandle _handle, uint16_t _num) { uint32_t opcode = encodeOpcode(_type, _loc, _num, false); write(opcode); write(&_handle, sizeof(UniformHandle) ); } void UniformBuffer::writeMarker(const char* _marker) { uint16_t num = (uint16_t)bx::strLen(_marker)+1; uint32_t opcode = encodeOpcode(bgfx::UniformType::Count, 0, num, true); write(opcode); write(_marker, num); } struct CapsFlags { uint64_t m_flag; const char* m_str; }; static const CapsFlags s_capsFlags[] = { #define CAPS_FLAGS(_x) { _x, #_x } CAPS_FLAGS(BGFX_CAPS_ALPHA_TO_COVERAGE), CAPS_FLAGS(BGFX_CAPS_BLEND_INDEPENDENT), CAPS_FLAGS(BGFX_CAPS_COMPUTE), CAPS_FLAGS(BGFX_CAPS_CONSERVATIVE_RASTER), CAPS_FLAGS(BGFX_CAPS_DRAW_INDIRECT), CAPS_FLAGS(BGFX_CAPS_FRAGMENT_DEPTH), CAPS_FLAGS(BGFX_CAPS_FRAGMENT_ORDERING), CAPS_FLAGS(BGFX_CAPS_GRAPHICS_DEBUGGER), CAPS_FLAGS(BGFX_CAPS_HDR10), CAPS_FLAGS(BGFX_CAPS_HIDPI), CAPS_FLAGS(BGFX_CAPS_INDEX32), CAPS_FLAGS(BGFX_CAPS_INSTANCING), CAPS_FLAGS(BGFX_CAPS_OCCLUSION_QUERY), CAPS_FLAGS(BGFX_CAPS_RENDERER_MULTITHREADED), CAPS_FLAGS(BGFX_CAPS_SWAP_CHAIN), CAPS_FLAGS(BGFX_CAPS_TEXTURE_2D_ARRAY), CAPS_FLAGS(BGFX_CAPS_TEXTURE_3D), CAPS_FLAGS(BGFX_CAPS_TEXTURE_BLIT), CAPS_FLAGS(BGFX_CAPS_TEXTURE_COMPARE_ALL), CAPS_FLAGS(BGFX_CAPS_TEXTURE_COMPARE_LEQUAL), CAPS_FLAGS(BGFX_CAPS_TEXTURE_CUBE_ARRAY), CAPS_FLAGS(BGFX_CAPS_TEXTURE_DIRECT_ACCESS), CAPS_FLAGS(BGFX_CAPS_TEXTURE_READ_BACK), CAPS_FLAGS(BGFX_CAPS_VERTEX_ATTRIB_HALF), CAPS_FLAGS(BGFX_CAPS_VERTEX_ATTRIB_UINT10), CAPS_FLAGS(BGFX_CAPS_VERTEX_ID), #undef CAPS_FLAGS }; static void dumpCaps() { BX_TRACE(""); if (0 < g_caps.numGPUs) { BX_TRACE("Detected GPUs (%d):", g_caps.numGPUs); BX_TRACE("\t +---------------- Index"); BX_TRACE("\t | +------------- Device ID"); BX_TRACE("\t | | +-------- Vendor ID"); for (uint32_t ii = 0; ii < g_caps.numGPUs; ++ii) { const Caps::GPU& gpu = g_caps.gpu[ii]; BX_UNUSED(gpu); BX_TRACE("\t %d: %04x %04x" , ii , gpu.deviceId , gpu.vendorId ); } BX_TRACE(""); } RendererType::Enum renderers[RendererType::Count]; uint8_t num = getSupportedRenderers(BX_COUNTOF(renderers), renderers); BX_TRACE("Supported renderer backends (%d):", num); for (uint32_t ii = 0; ii < num; ++ii) { BX_TRACE("\t - %s", getRendererName(renderers[ii]) ); } BX_TRACE(""); BX_TRACE("Sort key masks:"); BX_TRACE("\t View %016" PRIx64, kSortKeyViewMask); BX_TRACE("\t Draw bit %016" PRIx64, kSortKeyDrawBit); BX_TRACE(""); BX_TRACE("\tD Type %016" PRIx64, kSortKeyDrawTypeMask); BX_TRACE(""); BX_TRACE("\tD0 Blend %016" PRIx64, kSortKeyDraw0BlendMask); BX_TRACE("\tD0 Program %016" PRIx64, kSortKeyDraw0ProgramMask); BX_TRACE("\tD0 Depth %016" PRIx64, kSortKeyDraw0DepthMask); BX_TRACE(""); BX_TRACE("\tD1 Depth %016" PRIx64, kSortKeyDraw1DepthMask); BX_TRACE("\tD1 Blend %016" PRIx64, kSortKeyDraw1BlendMask); BX_TRACE("\tD1 Program %016" PRIx64, kSortKeyDraw1ProgramMask); BX_TRACE(""); BX_TRACE("\tD2 Seq %016" PRIx64, kSortKeyDraw2SeqMask); BX_TRACE("\tD2 Blend %016" PRIx64, kSortKeyDraw2BlendMask); BX_TRACE("\tD2 Program %016" PRIx64, kSortKeyDraw2ProgramMask); BX_TRACE(""); BX_TRACE("\t C Seq %016" PRIx64, kSortKeyComputeSeqMask); BX_TRACE("\t C Program %016" PRIx64, kSortKeyComputeProgramMask); BX_TRACE(""); BX_TRACE("Supported capabilities (renderer %s, vendor 0x%04x, device 0x%04x):" , s_ctx->m_renderCtx->getRendererName() , g_caps.vendorId , g_caps.deviceId ); for (uint32_t ii = 0; ii < BX_COUNTOF(s_capsFlags); ++ii) { if (0 != (g_caps.supported & s_capsFlags[ii].m_flag) ) { BX_TRACE("\t%s", s_capsFlags[ii].m_str); } } BX_TRACE(""); BX_TRACE("Limits:"); #define LIMITS(_x) BX_TRACE("\t%-24s %d", #_x, g_caps.limits._x) LIMITS(maxDrawCalls); LIMITS(maxBlits); LIMITS(maxTextureSize); LIMITS(maxTextureLayers); LIMITS(maxViews); LIMITS(maxFrameBuffers); LIMITS(maxFBAttachments); LIMITS(maxPrograms); LIMITS(maxShaders); LIMITS(maxTextures); LIMITS(maxTextureSamplers); LIMITS(maxComputeBindings); LIMITS(maxVertexLayouts); LIMITS(maxVertexStreams); LIMITS(maxIndexBuffers); LIMITS(maxVertexBuffers); LIMITS(maxDynamicIndexBuffers); LIMITS(maxDynamicVertexBuffers); LIMITS(maxUniforms); LIMITS(maxOcclusionQueries); LIMITS(maxEncoders); LIMITS(transientVbSize); LIMITS(transientIbSize); #undef LIMITS BX_TRACE(""); BX_TRACE("Supported texture formats:"); BX_TRACE("\t +---------------- 2D: x = supported / * = emulated"); BX_TRACE("\t |+--------------- 2D: sRGB format"); BX_TRACE("\t ||+-------------- 3D: x = supported / * = emulated"); BX_TRACE("\t |||+------------- 3D: sRGB format"); BX_TRACE("\t ||||+------------ Cube: x = supported / * = emulated"); BX_TRACE("\t |||||+----------- Cube: sRGB format"); BX_TRACE("\t ||||||+---------- vertex format"); BX_TRACE("\t |||||||+--------- image"); BX_TRACE("\t ||||||||+-------- framebuffer"); BX_TRACE("\t |||||||||+------- MSAA framebuffer"); BX_TRACE("\t ||||||||||+------ MSAA texture"); BX_TRACE("\t |||||||||||+----- Auto-generated mips"); BX_TRACE("\t |||||||||||| +-- name"); for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { if (TextureFormat::Unknown != ii && TextureFormat::UnknownDepth != ii) { uint16_t flags = g_caps.formats[ii]; BX_TRACE("\t[%c%c%c%c%c%c%c%c%c%c%c%c] %s" , flags&BGFX_CAPS_FORMAT_TEXTURE_2D ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED ? '*' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB ? 'l' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_3D ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED ? '*' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB ? 'l' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_CUBE ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED ? '*' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB ? 'l' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_VERTEX ? 'v' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE ? 'i' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER ? 'f' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA ? '+' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_MSAA ? 'm' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN ? 'M' : ' ' , getName(TextureFormat::Enum(ii) ) ); BX_UNUSED(flags); } } BX_TRACE(""); BX_TRACE("NDC depth [%d, 1], origin %s left." , g_caps.homogeneousDepth ? -1 : 0 , g_caps.originBottomLeft ? "bottom" : "top" ); BX_TRACE(""); } TextureFormat::Enum getViableTextureFormat(const bimg::ImageContainer& _imageContainer) { const uint32_t formatCaps = g_caps.formats[_imageContainer.m_format]; bool convert = 0 == formatCaps; if (_imageContainer.m_cubeMap) { convert |= 0 == (formatCaps & BGFX_CAPS_FORMAT_TEXTURE_CUBE) && 0 != (formatCaps & BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED) ; } else if (_imageContainer.m_depth > 1) { convert |= 0 == (formatCaps & BGFX_CAPS_FORMAT_TEXTURE_3D) && 0 != (formatCaps & BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED) ; } else { convert |= 0 == (formatCaps & BGFX_CAPS_FORMAT_TEXTURE_2D) && 0 != (formatCaps & BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED) ; } if (convert) { return TextureFormat::BGRA8; } return TextureFormat::Enum(_imageContainer.m_format); } const char* getName(TextureFormat::Enum _fmt) { return bimg::getName(bimg::TextureFormat::Enum(_fmt)); } const char* getName(UniformHandle _handle) { return s_ctx->m_uniformRef[_handle.idx].m_name.getPtr(); } const char* getName(ShaderHandle _handle) { return s_ctx->m_shaderRef[_handle.idx].m_name.getPtr(); } static const char* s_topologyName[] = { "Triangles", "TriStrip", "Lines", "LineStrip", "Points", }; BX_STATIC_ASSERT(Topology::Count == BX_COUNTOF(s_topologyName) ); const char* getName(Topology::Enum _topology) { return s_topologyName[bx::min(_topology, Topology::PointList)]; } const char* getShaderTypeName(uint32_t _magic) { if (isShaderType(_magic, 'C') ) { return "Compute"; } else if (isShaderType(_magic, 'F') ) { return "Fragment"; } else if (isShaderType(_magic, 'V') ) { return "Vertex"; } BX_CHECK(false, "Invalid shader type!"); return NULL; } static TextureFormat::Enum s_emulatedFormats[] = { TextureFormat::BC1, TextureFormat::BC2, TextureFormat::BC3, TextureFormat::BC4, TextureFormat::BC5, TextureFormat::ETC1, TextureFormat::ETC2, TextureFormat::ETC2A, TextureFormat::ETC2A1, #if !defined NM_PLATFORM_IOS TextureFormat::PTC12, TextureFormat::PTC14, TextureFormat::PTC12A, TextureFormat::PTC14A, #endif TextureFormat::PTC22, TextureFormat::PTC24, TextureFormat::ATC, TextureFormat::ATCE, TextureFormat::ATCI, TextureFormat::ASTC4x4, TextureFormat::ASTC5x5, TextureFormat::ASTC6x6, TextureFormat::ASTC8x5, TextureFormat::ASTC8x6, TextureFormat::ASTC10x5, TextureFormat::BGRA8, // GL doesn't support BGRA8 without extensions. TextureFormat::RGBA8, // D3D9 doesn't support RGBA8 }; bool Context::init(const Init& _init) { BX_CHECK(!m_rendererInitialized, "Already initialized?"); m_init = _init; m_init.resolution.reset &= ~BGFX_RESET_INTERNAL_FORCE; if (g_platformData.ndt == NULL && g_platformData.nwh == NULL && g_platformData.context == NULL && g_platformData.backBuffer == NULL && g_platformData.backBufferDS == NULL) { bx::memCopy(&g_platformData, &m_init.platformData, sizeof(PlatformData) ); } else { bx::memCopy(&m_init.platformData, &g_platformData, sizeof(PlatformData) ); } m_exit = false; m_flipped = true; m_frames = 0; m_debug = BGFX_DEBUG_NONE; m_frameTimeLast = bx::getHPCounter(); m_submit->create(); #if BGFX_CONFIG_MULTITHREADED m_render->create(); if (s_renderFrameCalled) { // When bgfx::renderFrame is called before init render thread // should not be created. BX_TRACE("Application called bgfx::renderFrame directly, not creating render thread."); m_singleThreaded = true && ~BGFX_API_THREAD_MAGIC == s_threadIndex ; } else { BX_TRACE("Creating rendering thread."); m_thread.init(renderThread, this, 0, "bgfx - renderer backend thread"); m_singleThreaded = false; } #else BX_TRACE("Multithreaded renderer is disabled."); m_singleThreaded = true; #endif // BGFX_CONFIG_MULTITHREADED BX_TRACE("Running in %s-threaded mode", m_singleThreaded ? "single" : "multi"); s_threadIndex = BGFX_API_THREAD_MAGIC; for (uint32_t ii = 0; ii < BX_COUNTOF(m_viewRemap); ++ii) { m_viewRemap[ii] = ViewId(ii); } for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii) { resetView(ViewId(ii) ); } for (uint32_t ii = 0; ii < BX_COUNTOF(m_clearColor); ++ii) { m_clearColor[ii][0] = 0.0f; m_clearColor[ii][1] = 0.0f; m_clearColor[ii][2] = 0.0f; m_clearColor[ii][3] = 1.0f; } m_vertexLayoutRef.init(); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::RendererInit); cmdbuf.write(_init); frameNoRenderWait(); m_encoderHandle = bx::createHandleAlloc(g_allocator, _init.limits.maxEncoders); m_encoder = (EncoderImpl*)BX_ALLOC(g_allocator, sizeof(EncoderImpl)*_init.limits.maxEncoders); m_encoderStats = (EncoderStats*)BX_ALLOC(g_allocator, sizeof(EncoderStats)*_init.limits.maxEncoders); for (uint32_t ii = 0, num = _init.limits.maxEncoders; ii < num; ++ii) { BX_PLACEMENT_NEW(&m_encoder[ii], EncoderImpl); } uint16_t idx = m_encoderHandle->alloc(); BX_CHECK(0 == idx, "Internal encoder handle is not 0 (idx %d).", idx); BX_UNUSED(idx); m_encoder[0].begin(m_submit, 0); m_encoder0 = reinterpret_cast<Encoder*>(&m_encoder[0]); // Make sure renderer init is called from render thread. // g_caps is initialized and available after this point. frame(); if (!m_rendererInitialized) { getCommandBuffer(CommandBuffer::RendererShutdownEnd); frame(); frame(); m_vertexLayoutRef.shutdown(m_layoutHandle); m_submit->destroy(); #if BGFX_CONFIG_MULTITHREADED m_render->destroy(); #endif // BGFX_CONFIG_MULTITHREADED return false; } for (uint32_t ii = 0; ii < BX_COUNTOF(s_emulatedFormats); ++ii) { const uint32_t fmt = s_emulatedFormats[ii]; g_caps.formats[fmt] |= 0 == (g_caps.formats[fmt] & BGFX_CAPS_FORMAT_TEXTURE_2D ) ? BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED : 0; g_caps.formats[fmt] |= 0 == (g_caps.formats[fmt] & BGFX_CAPS_FORMAT_TEXTURE_3D ) ? BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED : 0; g_caps.formats[fmt] |= 0 == (g_caps.formats[fmt] & BGFX_CAPS_FORMAT_TEXTURE_CUBE) ? BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED : 0; } for (uint32_t ii = 0; ii < TextureFormat::UnknownDepth; ++ii) { bool convertable = bimg::imageConvert(bimg::TextureFormat::BGRA8, bimg::TextureFormat::Enum(ii) ); g_caps.formats[ii] |= 0 == (g_caps.formats[ii] & BGFX_CAPS_FORMAT_TEXTURE_2D ) && convertable ? BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED : 0; g_caps.formats[ii] |= 0 == (g_caps.formats[ii] & BGFX_CAPS_FORMAT_TEXTURE_3D ) && convertable ? BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED : 0; g_caps.formats[ii] |= 0 == (g_caps.formats[ii] & BGFX_CAPS_FORMAT_TEXTURE_CUBE) && convertable ? BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED : 0; } g_caps.rendererType = m_renderCtx->getRendererType(); initAttribTypeSizeTable(g_caps.rendererType); g_caps.supported |= 0 | (BX_ENABLED(BGFX_CONFIG_MULTITHREADED) && !m_singleThreaded ? BGFX_CAPS_RENDERER_MULTITHREADED : 0) | (isGraphicsDebuggerPresent() ? BGFX_CAPS_GRAPHICS_DEBUGGER : 0) ; dumpCaps(); m_textVideoMemBlitter.init(); m_clearQuad.init(); m_submit->m_transientVb = createTransientVertexBuffer(_init.limits.transientVbSize); m_submit->m_transientIb = createTransientIndexBuffer(_init.limits.transientIbSize); frame(); if (BX_ENABLED(BGFX_CONFIG_MULTITHREADED) ) { m_submit->m_transientVb = createTransientVertexBuffer(_init.limits.transientVbSize); m_submit->m_transientIb = createTransientIndexBuffer(_init.limits.transientIbSize); frame(); } g_internalData.caps = getCaps(); return true; } void Context::shutdown() { getCommandBuffer(CommandBuffer::RendererShutdownBegin); frame(); destroyTransientVertexBuffer(m_submit->m_transientVb); destroyTransientIndexBuffer(m_submit->m_transientIb); m_textVideoMemBlitter.shutdown(); m_clearQuad.shutdown(); frame(); if (BX_ENABLED(BGFX_CONFIG_MULTITHREADED) ) { destroyTransientVertexBuffer(m_submit->m_transientVb); destroyTransientIndexBuffer(m_submit->m_transientIb); frame(); } frame(); // If any VertexLayouts needs to be destroyed. getCommandBuffer(CommandBuffer::RendererShutdownEnd); frame(); m_encoder[0].end(true); m_encoderHandle->free(0); bx::destroyHandleAlloc(g_allocator, m_encoderHandle); m_encoderHandle = NULL; for (uint32_t ii = 0, num = g_caps.limits.maxEncoders; ii < num; ++ii) { m_encoder[ii].~EncoderImpl(); } BX_FREE(g_allocator, m_encoder); BX_FREE(g_allocator, m_encoderStats); m_dynVertexBufferAllocator.compact(); m_dynIndexBufferAllocator.compact(); BX_CHECK( m_layoutHandle.getNumHandles() == m_vertexLayoutRef.m_vertexLayoutMap.getNumElements() , "VertexLayoutRef mismatch, num handles %d, handles in hash map %d." , m_layoutHandle.getNumHandles() , m_vertexLayoutRef.m_vertexLayoutMap.getNumElements() ); m_vertexLayoutRef.shutdown(m_layoutHandle); #if BGFX_CONFIG_MULTITHREADED // Render thread shutdown sequence. renderSemWait(); // Wait for previous frame. apiSemPost(); // OK to set context to NULL. // s_ctx is NULL here. renderSemWait(); // In RenderFrame::Exiting state. if (m_thread.isRunning() ) { m_thread.shutdown(); } m_render->destroy(); #endif // BGFX_CONFIG_MULTITHREADED bx::memSet(&g_internalData, 0, sizeof(InternalData) ); s_ctx = NULL; m_submit->destroy(); if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) { #define CHECK_HANDLE_LEAK(_name, _handleAlloc) \ BX_MACRO_BLOCK_BEGIN \ if (0 != _handleAlloc.getNumHandles() ) \ { \ BX_TRACE("LEAK: %s %d (max: %d)" \ , _name \ , _handleAlloc.getNumHandles() \ , _handleAlloc.getMaxHandles() \ ); \ for (uint16_t ii = 0, num = _handleAlloc.getNumHandles(); ii < num; ++ii) \ { \ BX_TRACE("\t%3d: %4d", ii, _handleAlloc.getHandleAt(ii) ); \ } \ } \ BX_MACRO_BLOCK_END #define CHECK_HANDLE_LEAK_NAME(_name, _handleAlloc, _type, _ref) \ BX_MACRO_BLOCK_BEGIN \ if (0 != _handleAlloc.getNumHandles() ) \ { \ BX_TRACE("LEAK: %s %d (max: %d)" \ , _name \ , _handleAlloc.getNumHandles() \ , _handleAlloc.getMaxHandles() \ ); \ for (uint16_t ii = 0, num = _handleAlloc.getNumHandles(); ii < num; ++ii) \ { \ uint16_t idx = _handleAlloc.getHandleAt(ii); \ const _type& ref = _ref[idx]; BX_UNUSED(ref); \ BX_TRACE("\t%3d: %4d %s" \ , ii \ , idx \ , ref.m_name.getPtr() \ ); \ } \ } \ BX_MACRO_BLOCK_END #define CHECK_HANDLE_LEAK_RC_NAME(_name, _handleAlloc, _type, _ref) \ BX_MACRO_BLOCK_BEGIN \ if (0 != _handleAlloc.getNumHandles() ) \ { \ BX_TRACE("LEAK: %s %d (max: %d)" \ , _name \ , _handleAlloc.getNumHandles() \ , _handleAlloc.getMaxHandles() \ ); \ for (uint16_t ii = 0, num = _handleAlloc.getNumHandles(); ii < num; ++ii) \ { \ uint16_t idx = _handleAlloc.getHandleAt(ii); \ const _type& ref = _ref[idx]; BX_UNUSED(ref); \ BX_TRACE("\t%3d: %4d %s (count %d)" \ , ii \ , idx \ , ref.m_name.getPtr() \ , ref.m_refCount \ ); \ } \ } \ BX_MACRO_BLOCK_END CHECK_HANDLE_LEAK ("DynamicIndexBufferHandle", m_dynamicIndexBufferHandle ); CHECK_HANDLE_LEAK ("DynamicVertexBufferHandle", m_dynamicVertexBufferHandle ); CHECK_HANDLE_LEAK_NAME ("IndexBufferHandle", m_indexBufferHandle, IndexBuffer, m_indexBuffers ); CHECK_HANDLE_LEAK ("VertexLayoutHandle", m_layoutHandle ); CHECK_HANDLE_LEAK_NAME ("VertexBufferHandle", m_vertexBufferHandle, VertexBuffer, m_vertexBuffers ); CHECK_HANDLE_LEAK_RC_NAME("ShaderHandle", m_shaderHandle, ShaderRef, m_shaderRef ); CHECK_HANDLE_LEAK ("ProgramHandle", m_programHandle ); CHECK_HANDLE_LEAK_RC_NAME("TextureHandle", m_textureHandle, TextureRef, m_textureRef ); CHECK_HANDLE_LEAK_NAME ("FrameBufferHandle", m_frameBufferHandle, FrameBufferRef, m_frameBufferRef); CHECK_HANDLE_LEAK_RC_NAME("UniformHandle", m_uniformHandle, UniformRef, m_uniformRef ); CHECK_HANDLE_LEAK ("OcclusionQueryHandle", m_occlusionQueryHandle ); #undef CHECK_HANDLE_LEAK #undef CHECK_HANDLE_LEAK_NAME } } void Context::freeDynamicBuffers() { for (uint16_t ii = 0, num = m_numFreeDynamicIndexBufferHandles; ii < num; ++ii) { destroyDynamicIndexBufferInternal(m_freeDynamicIndexBufferHandle[ii]); } m_numFreeDynamicIndexBufferHandles = 0; for (uint16_t ii = 0, num = m_numFreeDynamicVertexBufferHandles; ii < num; ++ii) { destroyDynamicVertexBufferInternal(m_freeDynamicVertexBufferHandle[ii]); } m_numFreeDynamicVertexBufferHandles = 0; for (uint16_t ii = 0, num = m_numFreeOcclusionQueryHandles; ii < num; ++ii) { m_occlusionQueryHandle.free(m_freeOcclusionQueryHandle[ii].idx); } m_numFreeOcclusionQueryHandles = 0; } void Context::freeAllHandles(Frame* _frame) { for (uint16_t ii = 0, num = _frame->m_freeIndexBuffer.getNumQueued(); ii < num; ++ii) { m_indexBufferHandle.free(_frame->m_freeIndexBuffer.get(ii).idx); } for (uint16_t ii = 0, num = _frame->m_freeVertexBuffer.getNumQueued(); ii < num; ++ii) { destroyVertexBufferInternal(_frame->m_freeVertexBuffer.get(ii)); } for (uint16_t ii = 0, num = _frame->m_freeVertexLayout.getNumQueued(); ii < num; ++ii) { m_layoutHandle.free(_frame->m_freeVertexLayout.get(ii).idx); } for (uint16_t ii = 0, num = _frame->m_freeShader.getNumQueued(); ii < num; ++ii) { m_shaderHandle.free(_frame->m_freeShader.get(ii).idx); } for (uint16_t ii = 0, num = _frame->m_freeProgram.getNumQueued(); ii < num; ++ii) { m_programHandle.free(_frame->m_freeProgram.get(ii).idx); } for (uint16_t ii = 0, num = _frame->m_freeTexture.getNumQueued(); ii < num; ++ii) { m_textureHandle.free(_frame->m_freeTexture.get(ii).idx); } for (uint16_t ii = 0, num = _frame->m_freeFrameBuffer.getNumQueued(); ii < num; ++ii) { m_frameBufferHandle.free(_frame->m_freeFrameBuffer.get(ii).idx); } for (uint16_t ii = 0, num = _frame->m_freeUniform.getNumQueued(); ii < num; ++ii) { m_uniformHandle.free(_frame->m_freeUniform.get(ii).idx); } } Encoder* Context::begin(bool _forThread) { EncoderImpl* encoder = &m_encoder[0]; #if BGFX_CONFIG_MULTITHREADED if (_forThread || BGFX_API_THREAD_MAGIC != s_threadIndex) { bx::MutexScope scopeLock(m_encoderApiLock); uint16_t idx = m_encoderHandle->alloc(); if (kInvalidHandle == idx) { return NULL; } encoder = &m_encoder[idx]; encoder->begin(m_submit, uint8_t(idx) ); } #else BX_UNUSED(_forThread); #endif // BGFX_CONFIG_MULTITHREADED return reinterpret_cast<Encoder*>(encoder); } void Context::end(Encoder* _encoder) { #if BGFX_CONFIG_MULTITHREADED EncoderImpl* encoder = reinterpret_cast<EncoderImpl*>(_encoder); if (encoder != &m_encoder[0]) { encoder->end(true); m_encoderEndSem.post(); } #else BX_UNUSED(_encoder); #endif // BGFX_CONFIG_MULTITHREADED } uint32_t Context::frame(bool _capture) { m_encoder[0].end(true); #if BGFX_CONFIG_MULTITHREADED bx::MutexScope resourceApiScope(m_resourceApiLock); encoderApiWait(); bx::MutexScope encoderApiScope(m_encoderApiLock); #else encoderApiWait(); #endif // BGFX_CONFIG_MULTITHREADED BX_CHECK(m_submit, ""); m_submit->m_capture = _capture; BGFX_PROFILER_SCOPE("bgfx/API thread frame", 0xff2040ff); // wait for render thread to finish renderSemWait(); frameNoRenderWait(); m_encoder[0].begin(m_submit, 0); return m_frames; } void Context::frameNoRenderWait() { swap(); // release render thread apiSemPost(); } void Context::swap() { freeDynamicBuffers(); m_submit->m_resolution = m_init.resolution; m_init.resolution.reset &= ~BGFX_RESET_INTERNAL_FORCE; m_submit->m_debug = m_debug; m_submit->m_perfStats.numViews = 0; bx::memCopy(m_submit->m_viewRemap, m_viewRemap, sizeof(m_viewRemap) ); bx::memCopy(m_submit->m_view, m_view, sizeof(m_view) ); if (m_colorPaletteDirty > 0) { --m_colorPaletteDirty; bx::memCopy(m_submit->m_colorPalette, m_clearColor, sizeof(m_clearColor) ); } freeAllHandles(m_submit); m_submit->resetFreeHandles(); m_submit->finish(); bx::swap(m_render, m_submit); bx::memCopy(m_render->m_occlusion, m_submit->m_occlusion, sizeof(m_submit->m_occlusion) ); if (!BX_ENABLED(BGFX_CONFIG_MULTITHREADED) || m_singleThreaded) { renderFrame(); } m_frames++; m_submit->start(); bx::memSet(m_seq, 0, sizeof(m_seq) ); m_submit->m_textVideoMem->resize( m_render->m_textVideoMem->m_small , m_init.resolution.width , m_init.resolution.height ); int64_t now = bx::getHPCounter(); m_submit->m_perfStats.cpuTimeFrame = now - m_frameTimeLast; m_frameTimeLast = now; } /// RendererContextI* rendererCreate(const Init& _init); /// void rendererDestroy(RendererContextI* _renderCtx); void Context::flip() { if (m_rendererInitialized && !m_flipped) { m_renderCtx->flip(); m_flipped = true; if (m_renderCtx->isDeviceRemoved() ) { // Something horribly went wrong, fallback to noop renderer. rendererDestroy(m_renderCtx); Init init; init.type = RendererType::Noop; m_renderCtx = rendererCreate(init); g_caps.rendererType = RendererType::Noop; } } } #if BX_PLATFORM_OSX || BX_PLATFORM_IOS struct NSAutoreleasePoolScope { NSAutoreleasePoolScope() { id obj = class_createInstance(objc_getClass("NSAutoreleasePool"), 0); typedef id(*objc_msgSend_init)(void*, SEL); pool = ((objc_msgSend_init)objc_msgSend)(obj, sel_getUid("init") ); } ~NSAutoreleasePoolScope() { typedef void(*objc_msgSend_release)(void*, SEL); ((objc_msgSend_release)objc_msgSend)(pool, sel_getUid("release") ); } id pool; }; #endif // BX_PLATFORM_OSX RenderFrame::Enum Context::renderFrame(int32_t _msecs) { BGFX_PROFILER_SCOPE("bgfx::renderFrame", 0xff2040ff); #if BX_PLATFORM_OSX || BX_PLATFORM_IOS NSAutoreleasePoolScope pool; #endif // BX_PLATFORM_OSX if (!m_flipAfterRender) { BGFX_PROFILER_SCOPE("bgfx/flip", 0xff2040ff); flip(); } if (apiSemWait(_msecs) ) { { BGFX_PROFILER_SCOPE("bgfx/Exec commands pre", 0xff2040ff); rendererExecCommands(m_render->m_cmdPre); } if (m_rendererInitialized) { BGFX_PROFILER_SCOPE("bgfx/Render submit", 0xff2040ff); m_renderCtx->submit(m_render, m_clearQuad, m_textVideoMemBlitter); m_flipped = false; } { BGFX_PROFILER_SCOPE("bgfx/Exec commands post", 0xff2040ff); rendererExecCommands(m_render->m_cmdPost); } renderSemPost(); if (m_flipAfterRender) { BGFX_PROFILER_SCOPE("bgfx/flip", 0xff2040ff); flip(); } } else { return RenderFrame::Timeout; } return m_exit ? RenderFrame::Exiting : RenderFrame::Render ; } void rendererUpdateUniforms(RendererContextI* _renderCtx, UniformBuffer* _uniformBuffer, uint32_t _begin, uint32_t _end) { _uniformBuffer->reset(_begin); while (_uniformBuffer->getPos() < _end) { uint32_t opcode = _uniformBuffer->read(); if (UniformType::End == opcode) { break; } UniformType::Enum type; uint16_t loc; uint16_t num; uint16_t copy; UniformBuffer::decodeOpcode(opcode, type, loc, num, copy); uint32_t size = g_uniformTypeSize[type]*num; const char* data = _uniformBuffer->read(size); if (UniformType::Count > type) { if (copy) { _renderCtx->updateUniform(loc, data, size); } else { _renderCtx->updateUniform(loc, *(const char**)(data), size); } } else { _renderCtx->setMarker(data, uint16_t(size)-1); } } } void Context::flushTextureUpdateBatch(CommandBuffer& _cmdbuf) { if (m_textureUpdateBatch.sort() ) { const uint32_t pos = _cmdbuf.m_pos; uint32_t currentKey = UINT32_MAX; for (uint32_t ii = 0, num = m_textureUpdateBatch.m_num; ii < num; ++ii) { _cmdbuf.m_pos = m_textureUpdateBatch.m_values[ii]; TextureHandle handle; _cmdbuf.read(handle); uint8_t side; _cmdbuf.read(side); uint8_t mip; _cmdbuf.read(mip); Rect rect; _cmdbuf.read(rect); uint16_t zz; _cmdbuf.read(zz); uint16_t depth; _cmdbuf.read(depth); uint16_t pitch; _cmdbuf.read(pitch); const Memory* mem; _cmdbuf.read(mem); uint32_t key = m_textureUpdateBatch.m_keys[ii]; if (key != currentKey) { if (currentKey != UINT32_MAX) { m_renderCtx->updateTextureEnd(); } currentKey = key; m_renderCtx->updateTextureBegin(handle, side, mip); } m_renderCtx->updateTexture(handle, side, mip, rect, zz, depth, pitch, mem); release(mem); } if (currentKey != UINT32_MAX) { m_renderCtx->updateTextureEnd(); } m_textureUpdateBatch.reset(); _cmdbuf.m_pos = pos; } } typedef RendererContextI* (*RendererCreateFn)(const Init& _init); typedef void (*RendererDestroyFn)(); #define BGFX_RENDERER_CONTEXT(_namespace) \ namespace _namespace \ { \ extern RendererContextI* rendererCreate(const Init& _init); \ extern void rendererDestroy(); \ } BGFX_RENDERER_CONTEXT(noop); BGFX_RENDERER_CONTEXT(d3d9); BGFX_RENDERER_CONTEXT(d3d11); BGFX_RENDERER_CONTEXT(d3d12); BGFX_RENDERER_CONTEXT(gnm); BGFX_RENDERER_CONTEXT(mtl); BGFX_RENDERER_CONTEXT(nvn); BGFX_RENDERER_CONTEXT(gl); BGFX_RENDERER_CONTEXT(vk); BGFX_RENDERER_CONTEXT(webgpu); #undef BGFX_RENDERER_CONTEXT struct RendererCreator { RendererCreateFn createFn; RendererDestroyFn destroyFn; const char* name; bool supported; }; static RendererCreator s_rendererCreator[] = { { noop::rendererCreate, noop::rendererDestroy, BGFX_RENDERER_NOOP_NAME, true }, // Noop { d3d9::rendererCreate, d3d9::rendererDestroy, BGFX_RENDERER_DIRECT3D9_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D9 }, // Direct3D9 { d3d11::rendererCreate, d3d11::rendererDestroy, BGFX_RENDERER_DIRECT3D11_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D11 }, // Direct3D11 { d3d12::rendererCreate, d3d12::rendererDestroy, BGFX_RENDERER_DIRECT3D12_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D12 }, // Direct3D12 { gnm::rendererCreate, gnm::rendererDestroy, BGFX_RENDERER_GNM_NAME, !!BGFX_CONFIG_RENDERER_GNM }, // GNM #if BX_PLATFORM_OSX || BX_PLATFORM_IOS { mtl::rendererCreate, mtl::rendererDestroy, BGFX_RENDERER_METAL_NAME, !!BGFX_CONFIG_RENDERER_METAL }, // Metal #else { noop::rendererCreate, noop::rendererDestroy, BGFX_RENDERER_NOOP_NAME, false }, // Noop #endif // BX_PLATFORM_OSX || BX_PLATFORM_IOS { nvn::rendererCreate, nvn::rendererDestroy, BGFX_RENDERER_NVN_NAME, !!BGFX_CONFIG_RENDERER_NVN }, // NVN { gl::rendererCreate, gl::rendererDestroy, BGFX_RENDERER_OPENGL_NAME, !!BGFX_CONFIG_RENDERER_OPENGLES }, // OpenGLES { gl::rendererCreate, gl::rendererDestroy, BGFX_RENDERER_OPENGL_NAME, !!BGFX_CONFIG_RENDERER_OPENGL }, // OpenGL { vk::rendererCreate, vk::rendererDestroy, BGFX_RENDERER_VULKAN_NAME, !!BGFX_CONFIG_RENDERER_VULKAN }, // Vulkan { webgpu::rendererCreate, webgpu::rendererDestroy, BGFX_RENDERER_WEBGPU_NAME, !!BGFX_CONFIG_RENDERER_WEBGPU }, // WebGPU }; BX_STATIC_ASSERT(BX_COUNTOF(s_rendererCreator) == RendererType::Count); bool windowsVersionIs(Condition::Enum _op, uint32_t _version) { #if BX_PLATFORM_WINDOWS static const uint8_t s_condition[] = { VER_LESS_EQUAL, VER_GREATER_EQUAL, }; OSVERSIONINFOEXA ovi; bx::memSet(&ovi, 0, sizeof(ovi) ); ovi.dwOSVersionInfoSize = sizeof(ovi); // _WIN32_WINNT_WINBLUE 0x0603 // _WIN32_WINNT_WIN8 0x0602 // _WIN32_WINNT_WIN7 0x0601 // _WIN32_WINNT_VISTA 0x0600 ovi.dwMajorVersion = HIBYTE(_version); ovi.dwMinorVersion = LOBYTE(_version); DWORDLONG cond = 0; VER_SET_CONDITION(cond, VER_MAJORVERSION, s_condition[_op]); VER_SET_CONDITION(cond, VER_MINORVERSION, s_condition[_op]); return !!VerifyVersionInfoA(&ovi, VER_MAJORVERSION | VER_MINORVERSION, cond); #else BX_UNUSED(_op, _version); return false; #endif // BX_PLATFORM_WINDOWS } static int32_t compareDescending(const void* _lhs, const void* _rhs) { return *(const int32_t*)_rhs - *(const int32_t*)_lhs; } RendererContextI* rendererCreate(const Init& _init) { int32_t scores[RendererType::Count]; uint32_t numScores = 0; for (uint32_t ii = 0; ii < RendererType::Count; ++ii) { RendererType::Enum renderer = RendererType::Enum(ii); if (s_rendererCreator[ii].supported) { int32_t score = 0; if (_init.type == renderer) { score += 1000; } score += RendererType::Noop != renderer ? 1 : 0; if (BX_ENABLED(BX_PLATFORM_WINDOWS) ) { if (windowsVersionIs(Condition::GreaterEqual, 0x0602) ) { score += RendererType::Direct3D11 == renderer ? 20 : 0; score += RendererType::Direct3D12 == renderer ? 10 : 0; } else if (windowsVersionIs(Condition::GreaterEqual, 0x0601) ) { score += RendererType::Direct3D11 == renderer ? 20 : 0; score += RendererType::Direct3D9 == renderer ? 10 : 0; score += RendererType::Direct3D12 == renderer ? -100 : 0; } else { score += RendererType::Direct3D12 == renderer ? -100 : 0; } } else if (BX_ENABLED(BX_PLATFORM_LINUX) ) { score += RendererType::OpenGL == renderer ? 20 : 0; score += RendererType::OpenGLES == renderer ? 10 : 0; } else if (BX_ENABLED(BX_PLATFORM_OSX) ) { score += RendererType::Metal == renderer ? 20 : 0; score += RendererType::OpenGL == renderer ? 10 : 0; } else if (BX_ENABLED(BX_PLATFORM_IOS) ) { score += RendererType::Metal == renderer ? 20 : 0; score += RendererType::OpenGLES == renderer ? 10 : 0; } else if (BX_ENABLED(0 || BX_PLATFORM_ANDROID || BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_RPI ) ) { score += RendererType::OpenGLES == renderer ? 20 : 0; } else if (BX_ENABLED(BX_PLATFORM_PS4) ) { score += RendererType::Gnm == renderer ? 20 : 0; } else if (BX_ENABLED(0 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT ) ) { score += RendererType::Direct3D12 == renderer ? 20 : 0; score += RendererType::Direct3D11 == renderer ? 10 : 0; } scores[numScores++] = (score<<8) | uint8_t(renderer); } } bx::quickSort(scores, numScores, sizeof(int32_t), compareDescending); RendererContextI* renderCtx = NULL; for (uint32_t ii = 0; ii < numScores; ++ii) { RendererType::Enum renderer = RendererType::Enum(scores[ii] & 0xff); renderCtx = s_rendererCreator[renderer].createFn(_init); if (NULL != renderCtx) { break; } s_rendererCreator[renderer].supported = false; } return renderCtx; } void rendererDestroy(RendererContextI* _renderCtx) { if (NULL != _renderCtx) { s_rendererCreator[_renderCtx->getRendererType()].destroyFn(); } } void Context::rendererExecCommands(CommandBuffer& _cmdbuf) { _cmdbuf.reset(); bool end = false; if (NULL == m_renderCtx) { uint8_t command; _cmdbuf.read(command); switch (command) { case CommandBuffer::RendererShutdownEnd: m_exit = true; return; case CommandBuffer::End: return; default: { BX_CHECK(CommandBuffer::RendererInit == command , "RendererInit must be the first command in command buffer before initialization. Unexpected command %d?" , command ); BX_CHECK(!m_rendererInitialized, "This shouldn't happen! Bad synchronization?"); Init init; _cmdbuf.read(init); m_renderCtx = rendererCreate(init); m_rendererInitialized = NULL != m_renderCtx; if (!m_rendererInitialized) { _cmdbuf.read(command); BX_CHECK(CommandBuffer::End == command, "Unexpected command %d?" , command ); return; } } break; } } do { uint8_t command; _cmdbuf.read(command); switch (command) { case CommandBuffer::RendererShutdownBegin: { BX_CHECK(m_rendererInitialized, "This shouldn't happen! Bad synchronization?"); m_rendererInitialized = false; } break; case CommandBuffer::RendererShutdownEnd: { BX_CHECK(!m_rendererInitialized && !m_exit, "This shouldn't happen! Bad synchronization?"); rendererDestroy(m_renderCtx); m_renderCtx = NULL; m_exit = true; } BX_FALLTHROUGH; case CommandBuffer::End: end = true; break; case CommandBuffer::CreateIndexBuffer: { BGFX_PROFILER_SCOPE("CreateIndexBuffer", 0xff2040ff); IndexBufferHandle handle; _cmdbuf.read(handle); const Memory* mem; _cmdbuf.read(mem); uint16_t flags; _cmdbuf.read(flags); m_renderCtx->createIndexBuffer(handle, mem, flags); release(mem); } break; case CommandBuffer::DestroyIndexBuffer: { BGFX_PROFILER_SCOPE("DestroyIndexBuffer", 0xff2040ff); IndexBufferHandle handle; _cmdbuf.read(handle); m_renderCtx->destroyIndexBuffer(handle); } break; case CommandBuffer::CreateVertexLayout: { BGFX_PROFILER_SCOPE("CreateVertexLayout", 0xff2040ff); VertexLayoutHandle handle; _cmdbuf.read(handle); VertexLayout layout; _cmdbuf.read(layout); m_renderCtx->createVertexLayout(handle, layout); } break; case CommandBuffer::DestroyVertexLayout: { BGFX_PROFILER_SCOPE("DestroyVertexLayout", 0xff2040ff); VertexLayoutHandle handle; _cmdbuf.read(handle); m_renderCtx->destroyVertexLayout(handle); } break; case CommandBuffer::CreateVertexBuffer: { BGFX_PROFILER_SCOPE("CreateVertexBuffer", 0xff2040ff); VertexBufferHandle handle; _cmdbuf.read(handle); const Memory* mem; _cmdbuf.read(mem); VertexLayoutHandle layoutHandle; _cmdbuf.read(layoutHandle); uint16_t flags; _cmdbuf.read(flags); m_renderCtx->createVertexBuffer(handle, mem, layoutHandle, flags); release(mem); } break; case CommandBuffer::DestroyVertexBuffer: { BGFX_PROFILER_SCOPE("DestroyVertexBuffer", 0xff2040ff); VertexBufferHandle handle; _cmdbuf.read(handle); m_renderCtx->destroyVertexBuffer(handle); } break; case CommandBuffer::CreateDynamicIndexBuffer: { BGFX_PROFILER_SCOPE("CreateDynamicIndexBuffer", 0xff2040ff); IndexBufferHandle handle; _cmdbuf.read(handle); uint32_t size; _cmdbuf.read(size); uint16_t flags; _cmdbuf.read(flags); m_renderCtx->createDynamicIndexBuffer(handle, size, flags); } break; case CommandBuffer::UpdateDynamicIndexBuffer: { BGFX_PROFILER_SCOPE("UpdateDynamicIndexBuffer", 0xff2040ff); IndexBufferHandle handle; _cmdbuf.read(handle); uint32_t offset; _cmdbuf.read(offset); uint32_t size; _cmdbuf.read(size); const Memory* mem; _cmdbuf.read(mem); m_renderCtx->updateDynamicIndexBuffer(handle, offset, size, mem); release(mem); } break; case CommandBuffer::DestroyDynamicIndexBuffer: { BGFX_PROFILER_SCOPE("DestroyDynamicIndexBuffer", 0xff2040ff); IndexBufferHandle handle; _cmdbuf.read(handle); m_renderCtx->destroyDynamicIndexBuffer(handle); } break; case CommandBuffer::CreateDynamicVertexBuffer: { BGFX_PROFILER_SCOPE("CreateDynamicVertexBuffer", 0xff2040ff); VertexBufferHandle handle; _cmdbuf.read(handle); uint32_t size; _cmdbuf.read(size); uint16_t flags; _cmdbuf.read(flags); m_renderCtx->createDynamicVertexBuffer(handle, size, flags); } break; case CommandBuffer::UpdateDynamicVertexBuffer: { BGFX_PROFILER_SCOPE("UpdateDynamicVertexBuffer", 0xff2040ff); VertexBufferHandle handle; _cmdbuf.read(handle); uint32_t offset; _cmdbuf.read(offset); uint32_t size; _cmdbuf.read(size); const Memory* mem; _cmdbuf.read(mem); m_renderCtx->updateDynamicVertexBuffer(handle, offset, size, mem); release(mem); } break; case CommandBuffer::DestroyDynamicVertexBuffer: { BGFX_PROFILER_SCOPE("DestroyDynamicVertexBuffer", 0xff2040ff); VertexBufferHandle handle; _cmdbuf.read(handle); m_renderCtx->destroyDynamicVertexBuffer(handle); } break; case CommandBuffer::CreateShader: { BGFX_PROFILER_SCOPE("CreateShader", 0xff2040ff); ShaderHandle handle; _cmdbuf.read(handle); const Memory* mem; _cmdbuf.read(mem); m_renderCtx->createShader(handle, mem); release(mem); } break; case CommandBuffer::DestroyShader: { BGFX_PROFILER_SCOPE("DestroyShader", 0xff2040ff); ShaderHandle handle; _cmdbuf.read(handle); m_renderCtx->destroyShader(handle); } break; case CommandBuffer::CreateProgram: { BGFX_PROFILER_SCOPE("CreateProgram", 0xff2040ff); ProgramHandle handle; _cmdbuf.read(handle); ShaderHandle vsh; _cmdbuf.read(vsh); ShaderHandle fsh; _cmdbuf.read(fsh); m_renderCtx->createProgram(handle, vsh, fsh); } break; case CommandBuffer::DestroyProgram: { BGFX_PROFILER_SCOPE("DestroyProgram", 0xff2040ff); ProgramHandle handle; _cmdbuf.read(handle); m_renderCtx->destroyProgram(handle); } break; case CommandBuffer::CreateTexture: { BGFX_PROFILER_SCOPE("CreateTexture", 0xff2040ff); TextureHandle handle; _cmdbuf.read(handle); const Memory* mem; _cmdbuf.read(mem); uint64_t flags; _cmdbuf.read(flags); uint8_t skip; _cmdbuf.read(skip); void* ptr = m_renderCtx->createTexture(handle, mem, flags, skip); if (NULL != ptr) { setDirectAccessPtr(handle, ptr); } bx::MemoryReader reader(mem->data, mem->size); uint32_t magic; bx::read(&reader, magic); if (BGFX_CHUNK_MAGIC_TEX == magic) { TextureCreate tc; bx::read(&reader, tc); if (NULL != tc.m_mem) { release(tc.m_mem); } } release(mem); } break; case CommandBuffer::UpdateTexture: { BGFX_PROFILER_SCOPE("UpdateTexture", 0xff2040ff); if (m_textureUpdateBatch.isFull() ) { flushTextureUpdateBatch(_cmdbuf); } uint32_t value = _cmdbuf.m_pos; TextureHandle handle; _cmdbuf.read(handle); uint8_t side; _cmdbuf.read(side); uint8_t mip; _cmdbuf.read(mip); _cmdbuf.skip<Rect>(); _cmdbuf.skip<uint16_t>(); _cmdbuf.skip<uint16_t>(); _cmdbuf.skip<uint16_t>(); _cmdbuf.skip<Memory*>(); uint32_t key = (handle.idx<<16) | (side<<8) | mip ; m_textureUpdateBatch.add(key, value); } break; case CommandBuffer::ReadTexture: { BGFX_PROFILER_SCOPE("ReadTexture", 0xff2040ff); TextureHandle handle; _cmdbuf.read(handle); void* data; _cmdbuf.read(data); uint8_t mip; _cmdbuf.read(mip); m_renderCtx->readTexture(handle, data, mip); } break; case CommandBuffer::ResizeTexture: { BGFX_PROFILER_SCOPE("ResizeTexture", 0xff2040ff); TextureHandle handle; _cmdbuf.read(handle); uint16_t width; _cmdbuf.read(width); uint16_t height; _cmdbuf.read(height); uint8_t numMips; _cmdbuf.read(numMips); uint16_t numLayers; _cmdbuf.read(numLayers); m_renderCtx->resizeTexture(handle, width, height, numMips, numLayers); } break; case CommandBuffer::DestroyTexture: { BGFX_PROFILER_SCOPE("DestroyTexture", 0xff2040ff); TextureHandle handle; _cmdbuf.read(handle); m_renderCtx->destroyTexture(handle); } break; case CommandBuffer::CreateFrameBuffer: { BGFX_PROFILER_SCOPE("CreateFrameBuffer", 0xff2040ff); FrameBufferHandle handle; _cmdbuf.read(handle); bool window; _cmdbuf.read(window); if (window) { void* nwh; _cmdbuf.read(nwh); uint16_t width; _cmdbuf.read(width); uint16_t height; _cmdbuf.read(height); TextureFormat::Enum format; _cmdbuf.read(format); TextureFormat::Enum depthFormat; _cmdbuf.read(depthFormat); m_renderCtx->createFrameBuffer(handle, nwh, width, height, format, depthFormat); } else { uint8_t num; _cmdbuf.read(num); Attachment attachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; _cmdbuf.read(attachment, sizeof(Attachment) * num); m_renderCtx->createFrameBuffer(handle, num, attachment); } } break; case CommandBuffer::DestroyFrameBuffer: { BGFX_PROFILER_SCOPE("DestroyFrameBuffer", 0xff2040ff); FrameBufferHandle handle; _cmdbuf.read(handle); m_renderCtx->destroyFrameBuffer(handle); } break; case CommandBuffer::CreateUniform: { BGFX_PROFILER_SCOPE("CreateUniform", 0xff2040ff); UniformHandle handle; _cmdbuf.read(handle); UniformType::Enum type; _cmdbuf.read(type); uint16_t num; _cmdbuf.read(num); uint8_t len; _cmdbuf.read(len); const char* name = (const char*)_cmdbuf.skip(len); m_renderCtx->createUniform(handle, type, num, name); } break; case CommandBuffer::DestroyUniform: { BGFX_PROFILER_SCOPE("DestroyUniform", 0xff2040ff); UniformHandle handle; _cmdbuf.read(handle); m_renderCtx->destroyUniform(handle); } break; case CommandBuffer::RequestScreenShot: { BGFX_PROFILER_SCOPE("RequestScreenShot", 0xff2040ff); FrameBufferHandle handle; _cmdbuf.read(handle); uint16_t len; _cmdbuf.read(len); const char* filePath = (const char*)_cmdbuf.skip(len); m_renderCtx->requestScreenShot(handle, filePath); } break; case CommandBuffer::UpdateViewName: { BGFX_PROFILER_SCOPE("UpdateViewName", 0xff2040ff); ViewId id; _cmdbuf.read(id); uint16_t len; _cmdbuf.read(len); const char* name = (const char*)_cmdbuf.skip(len); m_renderCtx->updateViewName(id, name); } break; case CommandBuffer::InvalidateOcclusionQuery: { BGFX_PROFILER_SCOPE("InvalidateOcclusionQuery", 0xff2040ff); OcclusionQueryHandle handle; _cmdbuf.read(handle); m_renderCtx->invalidateOcclusionQuery(handle); } break; case CommandBuffer::SetName: { BGFX_PROFILER_SCOPE("SetName", 0xff2040ff); Handle handle; _cmdbuf.read(handle); uint16_t len; _cmdbuf.read(len); const char* name = (const char*)_cmdbuf.skip(len); m_renderCtx->setName(handle, name, len-1); } break; default: BX_CHECK(false, "Invalid command: %d", command); break; } } while (!end); flushTextureUpdateBatch(_cmdbuf); } uint32_t topologyConvert(TopologyConvert::Enum _conversion, void* _dst, uint32_t _dstSize, const void* _indices, uint32_t _numIndices, bool _index32) { return topologyConvert(_conversion, _dst, _dstSize, _indices, _numIndices, _index32, g_allocator); } void topologySortTriList(TopologySort::Enum _sort, void* _dst, uint32_t _dstSize, const float _dir[3], const float _pos[3], const void* _vertices, uint32_t _stride, const void* _indices, uint32_t _numIndices, bool _index32) { topologySortTriList(_sort, _dst, _dstSize, _dir, _pos, _vertices, _stride, _indices, _numIndices, _index32, g_allocator); } uint8_t getSupportedRenderers(uint8_t _max, RendererType::Enum* _enum) { _enum = _max == 0 ? NULL : _enum; uint8_t num = 0; for (uint8_t ii = 0; ii < RendererType::Count; ++ii) { if ( (RendererType::Direct3D11 == ii || RendererType::Direct3D12 == ii) && windowsVersionIs(Condition::LessEqual, 0x0502) ) { continue; } if (NULL == _enum) { num++; } else { if (num < _max && s_rendererCreator[ii].supported) { _enum[num++] = RendererType::Enum(ii); } } } return num; } const char* getRendererName(RendererType::Enum _type) { BX_CHECK(_type < RendererType::Count, "Invalid renderer type %d.", _type); return s_rendererCreator[_type].name; } PlatformData::PlatformData() : ndt(NULL) , nwh(NULL) , context(NULL) , backBuffer(NULL) , backBufferDS(NULL) { } Resolution::Resolution() : format(TextureFormat::RGBA8) , width(1280) , height(720) , reset(BGFX_RESET_NONE) , numBackBuffers(2) , maxFrameLatency(0) { } Init::Limits::Limits() : maxEncoders(BGFX_CONFIG_DEFAULT_MAX_ENCODERS) , transientVbSize(BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE) , transientIbSize(BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE) { } Init::Init() : type(RendererType::Count) , vendorId(BGFX_PCI_ID_NONE) , deviceId(0) , debug(BX_ENABLED(BGFX_CONFIG_DEBUG) ) , profile(BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) , callback(NULL) , allocator(NULL) { } void Attachment::init(TextureHandle _handle, Access::Enum _access, uint16_t _layer, uint16_t _mip, uint8_t _resolve) { access = _access; handle = _handle; mip = _mip; layer = _layer; resolve = _resolve; } bool init(const Init& _init) { if (NULL != s_ctx) { BX_TRACE("bgfx is already initialized."); return false; } if (1 > _init.limits.maxEncoders || 128 < _init.limits.maxEncoders) { BX_TRACE("init.limits.maxEncoders must be between 1 and 128."); return false; } struct ErrorState { enum Enum { Default, ContextAllocated, }; }; ErrorState::Enum errorState = ErrorState::Default; if (NULL != _init.allocator) { g_allocator = _init.allocator; } else { bx::DefaultAllocator allocator; g_allocator = s_allocatorStub = BX_NEW(&allocator, AllocatorStub); } if (NULL != _init.callback) { g_callback = _init.callback; } else { g_callback = s_callbackStub = BX_NEW(g_allocator, CallbackStub); } if (true && !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_PS4) && RendererType::Noop != _init.type && NULL == _init.platformData.ndt && NULL == _init.platformData.nwh && NULL == _init.platformData.context && NULL == _init.platformData.backBuffer && NULL == _init.platformData.backBufferDS ) { BX_TRACE("bgfx platform data like window handle or backbuffer is not set, creating headless device."); } bx::memSet(&g_caps, 0, sizeof(g_caps) ); g_caps.limits.maxDrawCalls = BGFX_CONFIG_MAX_DRAW_CALLS; g_caps.limits.maxBlits = BGFX_CONFIG_MAX_BLIT_ITEMS; g_caps.limits.maxTextureSize = 0; g_caps.limits.maxTextureLayers = 1; g_caps.limits.maxViews = BGFX_CONFIG_MAX_VIEWS; g_caps.limits.maxFrameBuffers = BGFX_CONFIG_MAX_FRAME_BUFFERS; g_caps.limits.maxPrograms = BGFX_CONFIG_MAX_PROGRAMS; g_caps.limits.maxShaders = BGFX_CONFIG_MAX_SHADERS; g_caps.limits.maxTextures = BGFX_CONFIG_MAX_TEXTURES; g_caps.limits.maxTextureSamplers = BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; g_caps.limits.maxComputeBindings = 0; g_caps.limits.maxVertexLayouts = BGFX_CONFIG_MAX_VERTEX_LAYOUTS; g_caps.limits.maxVertexStreams = 1; g_caps.limits.maxIndexBuffers = BGFX_CONFIG_MAX_INDEX_BUFFERS; g_caps.limits.maxVertexBuffers = BGFX_CONFIG_MAX_VERTEX_BUFFERS; g_caps.limits.maxDynamicIndexBuffers = BGFX_CONFIG_MAX_DYNAMIC_INDEX_BUFFERS; g_caps.limits.maxDynamicVertexBuffers = BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS; g_caps.limits.maxUniforms = BGFX_CONFIG_MAX_UNIFORMS; g_caps.limits.maxOcclusionQueries = BGFX_CONFIG_MAX_OCCLUSION_QUERIES; g_caps.limits.maxFBAttachments = 1; g_caps.limits.maxEncoders = (0 != BGFX_CONFIG_MULTITHREADED) ? _init.limits.maxEncoders : 1; g_caps.limits.transientVbSize = _init.limits.transientVbSize; g_caps.limits.transientIbSize = _init.limits.transientIbSize; g_caps.vendorId = _init.vendorId; g_caps.deviceId = _init.deviceId; BX_TRACE("Init..."); // bgfx 1.104.7082 // ^ ^^^ ^^^^ // | | +--- Commit number (https://github.com/bkaradzic/bgfx / git rev-list --count HEAD) // | +------- API version (from https://github.com/bkaradzic/bgfx/blob/master/scripts/bgfx.idl#L4) // +--------- Major revision (always 1) BX_TRACE("Version 1.%d.%d (commit: " BGFX_REV_SHA1 ")", BGFX_API_VERSION, BGFX_REV_NUMBER); errorState = ErrorState::ContextAllocated; s_ctx = BX_ALIGNED_NEW(g_allocator, Context, Context::kAlignment); if (s_ctx->init(_init) ) { BX_TRACE("Init complete."); return true; } BX_TRACE("Init failed."); switch (errorState) { case ErrorState::ContextAllocated: BX_ALIGNED_DELETE(g_allocator, s_ctx, Context::kAlignment); s_ctx = NULL; BX_FALLTHROUGH; case ErrorState::Default: if (NULL != s_callbackStub) { BX_DELETE(g_allocator, s_callbackStub); s_callbackStub = NULL; } if (NULL != s_allocatorStub) { bx::DefaultAllocator allocator; BX_DELETE(&allocator, s_allocatorStub); s_allocatorStub = NULL; } s_threadIndex = 0; g_callback = NULL; g_allocator = NULL; break; } return false; } void shutdown() { BX_TRACE("Shutdown..."); BGFX_CHECK_API_THREAD(); Context* ctx = s_ctx; // it's going to be NULLd inside shutdown. ctx->shutdown(); BX_CHECK(NULL == s_ctx, "bgfx is should be uninitialized here."); BX_ALIGNED_DELETE(g_allocator, ctx, Context::kAlignment); BX_TRACE("Shutdown complete."); if (NULL != s_allocatorStub) { s_allocatorStub->checkLeaks(); } if (NULL != s_callbackStub) { BX_DELETE(g_allocator, s_callbackStub); s_callbackStub = NULL; } if (NULL != s_allocatorStub) { bx::DefaultAllocator allocator; BX_DELETE(&allocator, s_allocatorStub); s_allocatorStub = NULL; } s_threadIndex = 0; g_callback = NULL; g_allocator = NULL; } void reset(uint32_t _width, uint32_t _height, uint32_t _flags, TextureFormat::Enum _format) { BGFX_CHECK_API_THREAD(); BX_CHECK(0 == (_flags&BGFX_RESET_RESERVED_MASK), "Do not set reset reserved flags!"); s_ctx->reset(_width, _height, _flags, _format); } Encoder* begin(bool _forThread) { return s_ctx->begin(_forThread); } #define BGFX_ENCODER(_func) reinterpret_cast<EncoderImpl*>(this)->_func void Encoder::setMarker(const char* _marker) { BGFX_ENCODER(setMarker(_marker) ); } void Encoder::setState(uint64_t _state, uint32_t _rgba) { BX_CHECK(0 == (_state&BGFX_STATE_RESERVED_MASK), "Do not set state reserved flags!"); BGFX_ENCODER(setState(_state, _rgba) ); } void Encoder::setCondition(OcclusionQueryHandle _handle, bool _visible) { BGFX_CHECK_CAPS(BGFX_CAPS_OCCLUSION_QUERY, "Occlusion query is not supported!"); BGFX_ENCODER(setCondition(_handle, _visible) ); } void Encoder::setStencil(uint32_t _fstencil, uint32_t _bstencil) { BGFX_ENCODER(setStencil(_fstencil, _bstencil) ); } uint16_t Encoder::setScissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) { return BGFX_ENCODER(setScissor(_x, _y, _width, _height) ); } void Encoder::setScissor(uint16_t _cache) { BGFX_ENCODER(setScissor(_cache) ); } uint32_t Encoder::setTransform(const void* _mtx, uint16_t _num) { return BGFX_ENCODER(setTransform(_mtx, _num) ); } uint32_t Encoder::allocTransform(Transform* _transform, uint16_t _num) { return BGFX_ENCODER(allocTransform(_transform, _num) ); } void Encoder::setTransform(uint32_t _cache, uint16_t _num) { BGFX_ENCODER(setTransform(_cache, _num) ); } void Encoder::setUniform(UniformHandle _handle, const void* _value, uint16_t _num) { BGFX_CHECK_HANDLE("setUniform", s_ctx->m_uniformHandle, _handle); const UniformRef& uniform = s_ctx->m_uniformRef[_handle.idx]; BX_CHECK(isValid(_handle) && 0 < uniform.m_refCount, "Setting invalid uniform (handle %3d)!", _handle.idx); BX_CHECK(_num == UINT16_MAX || uniform.m_num >= _num, "Truncated uniform update. %d (max: %d)", _num, uniform.m_num); BGFX_ENCODER(setUniform(uniform.m_type, _handle, _value, UINT16_MAX != _num ? _num : uniform.m_num) ); } void Encoder::setIndexBuffer(IndexBufferHandle _handle) { setIndexBuffer(_handle, 0, UINT32_MAX); } void Encoder::setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) { BGFX_CHECK_HANDLE("setIndexBuffer", s_ctx->m_indexBufferHandle, _handle); BGFX_ENCODER(setIndexBuffer(_handle, _firstIndex, _numIndices) ); } void Encoder::setIndexBuffer(DynamicIndexBufferHandle _handle) { setIndexBuffer(_handle, 0, UINT32_MAX); } void Encoder::setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) { BGFX_CHECK_HANDLE("setIndexBuffer", s_ctx->m_dynamicIndexBufferHandle, _handle); const DynamicIndexBuffer& dib = s_ctx->m_dynamicIndexBuffers[_handle.idx]; BGFX_ENCODER(setIndexBuffer(dib, _firstIndex, _numIndices) ); } void Encoder::setIndexBuffer(const TransientIndexBuffer* _tib) { setIndexBuffer(_tib, 0, UINT32_MAX); } void Encoder::setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _firstIndex, uint32_t _numIndices) { BX_CHECK(NULL != _tib, "_tib can't be NULL"); BGFX_CHECK_HANDLE("setIndexBuffer", s_ctx->m_indexBufferHandle, _tib->handle); BGFX_ENCODER(setIndexBuffer(_tib, _firstIndex, _numIndices) ); } void Encoder::setVertexBuffer( uint8_t _stream , VertexBufferHandle _handle , uint32_t _startVertex , uint32_t _numVertices , VertexLayoutHandle _layoutHandle ) { BGFX_CHECK_HANDLE("setVertexBuffer", s_ctx->m_vertexBufferHandle, _handle); BGFX_CHECK_HANDLE_INVALID_OK("setVertexBuffer", s_ctx->m_layoutHandle, _layoutHandle); BGFX_ENCODER(setVertexBuffer(_stream, _handle, _startVertex, _numVertices, _layoutHandle) ); } void Encoder::setVertexBuffer(uint8_t _stream, VertexBufferHandle _handle) { setVertexBuffer(_stream, _handle, 0, UINT32_MAX); } void Encoder::setVertexBuffer( uint8_t _stream , DynamicVertexBufferHandle _handle , uint32_t _startVertex , uint32_t _numVertices , VertexLayoutHandle _layoutHandle ) { BGFX_CHECK_HANDLE("setVertexBuffer", s_ctx->m_dynamicVertexBufferHandle, _handle); BGFX_CHECK_HANDLE_INVALID_OK("setVertexBuffer", s_ctx->m_layoutHandle, _layoutHandle); const DynamicVertexBuffer& dvb = s_ctx->m_dynamicVertexBuffers[_handle.idx]; BGFX_ENCODER(setVertexBuffer(_stream, dvb, _startVertex, _numVertices, _layoutHandle) ); } void Encoder::setVertexBuffer(uint8_t _stream, DynamicVertexBufferHandle _handle) { setVertexBuffer(_stream, _handle, 0, UINT32_MAX); } void Encoder::setVertexBuffer( uint8_t _stream , const TransientVertexBuffer* _tvb , uint32_t _startVertex , uint32_t _numVertices , VertexLayoutHandle _layoutHandle ) { BX_CHECK(NULL != _tvb, "_tvb can't be NULL"); BGFX_CHECK_HANDLE("setVertexBuffer", s_ctx->m_vertexBufferHandle, _tvb->handle); BGFX_CHECK_HANDLE_INVALID_OK("setVertexBuffer", s_ctx->m_layoutHandle, _layoutHandle); BGFX_ENCODER(setVertexBuffer(_stream, _tvb, _startVertex, _numVertices, _layoutHandle) ); } void Encoder::setVertexBuffer(uint8_t _stream, const TransientVertexBuffer* _tvb) { setVertexBuffer(_stream, _tvb, 0, UINT32_MAX); } void Encoder::setVertexCount(uint32_t _numVertices) { BGFX_CHECK_CAPS(BGFX_CAPS_VERTEX_ID, "Auto generated vertices are not supported!"); BGFX_ENCODER(setVertexCount(_numVertices) ); } void Encoder::setInstanceDataBuffer(const InstanceDataBuffer* _idb) { setInstanceDataBuffer(_idb, 0, UINT32_MAX); } void Encoder::setInstanceDataBuffer(const InstanceDataBuffer* _idb, uint32_t _start, uint32_t _num) { BX_CHECK(NULL != _idb, "_idb can't be NULL"); BGFX_ENCODER(setInstanceDataBuffer(_idb, _start, _num) ); } void Encoder::setInstanceDataBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num) { BGFX_CHECK_HANDLE("setInstanceDataBuffer", s_ctx->m_vertexBufferHandle, _handle); const VertexBuffer& vb = s_ctx->m_vertexBuffers[_handle.idx]; BGFX_ENCODER(setInstanceDataBuffer(_handle, _startVertex, _num, vb.m_stride) ); } void Encoder::setInstanceDataBuffer(DynamicVertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num) { BGFX_CHECK_HANDLE("setInstanceDataBuffer", s_ctx->m_dynamicVertexBufferHandle, _handle); const DynamicVertexBuffer& dvb = s_ctx->m_dynamicVertexBuffers[_handle.idx]; BGFX_ENCODER(setInstanceDataBuffer(dvb.m_handle , dvb.m_startVertex + _startVertex , _num , dvb.m_stride ) ); } void Encoder::setInstanceCount(uint32_t _numInstances) { BGFX_CHECK_CAPS(BGFX_CAPS_VERTEX_ID, "Auto generated instances are not supported!"); BGFX_ENCODER(setInstanceCount(_numInstances) ); } void Encoder::setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags) { BGFX_CHECK_HANDLE("setTexture/UniformHandle", s_ctx->m_uniformHandle, _sampler); BGFX_CHECK_HANDLE_INVALID_OK("setTexture/TextureHandle", s_ctx->m_textureHandle, _handle); BX_CHECK(_stage < g_caps.limits.maxTextureSamplers, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxTextureSamplers); BGFX_ENCODER(setTexture(_stage, _sampler, _handle, _flags) ); } void Encoder::touch(ViewId _id) { ProgramHandle handle = BGFX_INVALID_HANDLE; submit(_id, handle); } void Encoder::submit(ViewId _id, ProgramHandle _program, uint32_t _depth, uint8_t _flags) { OcclusionQueryHandle handle = BGFX_INVALID_HANDLE; submit(_id, _program, handle, _depth, _flags); } void Encoder::submit(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth, uint8_t _flags) { BX_CHECK(false || !isValid(_occlusionQuery) || 0 != (g_caps.supported & BGFX_CAPS_OCCLUSION_QUERY) , "Occlusion query is not supported! Use bgfx::getCaps to check BGFX_CAPS_OCCLUSION_QUERY backend renderer capabilities." ); BGFX_CHECK_HANDLE_INVALID_OK("submit", s_ctx->m_programHandle, _program); BGFX_CHECK_HANDLE_INVALID_OK("submit", s_ctx->m_occlusionQueryHandle, _occlusionQuery); BGFX_ENCODER(submit(_id, _program, _occlusionQuery, _depth, _flags) ); } void Encoder::submit(ViewId _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, uint8_t _flags) { BGFX_CHECK_HANDLE_INVALID_OK("submit", s_ctx->m_programHandle, _program); BGFX_CHECK_HANDLE("submit", s_ctx->m_vertexBufferHandle, _indirectHandle); BGFX_CHECK_CAPS(BGFX_CAPS_DRAW_INDIRECT, "Draw indirect is not supported!"); BGFX_ENCODER(submit(_id, _program, _indirectHandle, _start, _num, _depth, _flags) ); } void Encoder::setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access) { BX_CHECK(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); BGFX_CHECK_HANDLE("setBuffer", s_ctx->m_indexBufferHandle, _handle); BGFX_ENCODER(setBuffer(_stage, _handle, _access) ); } void Encoder::setBuffer(uint8_t _stage, VertexBufferHandle _handle, Access::Enum _access) { BX_CHECK(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); BGFX_CHECK_HANDLE("setBuffer", s_ctx->m_vertexBufferHandle, _handle); BGFX_ENCODER(setBuffer(_stage, _handle, _access) ); } void Encoder::setBuffer(uint8_t _stage, DynamicIndexBufferHandle _handle, Access::Enum _access) { BX_CHECK(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); BGFX_CHECK_HANDLE("setBuffer", s_ctx->m_dynamicIndexBufferHandle, _handle); const DynamicIndexBuffer& dib = s_ctx->m_dynamicIndexBuffers[_handle.idx]; BGFX_ENCODER(setBuffer(_stage, dib.m_handle, _access) ); } void Encoder::setBuffer(uint8_t _stage, DynamicVertexBufferHandle _handle, Access::Enum _access) { BX_CHECK(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); BGFX_CHECK_HANDLE("setBuffer", s_ctx->m_dynamicVertexBufferHandle, _handle); const DynamicVertexBuffer& dvb = s_ctx->m_dynamicVertexBuffers[_handle.idx]; BGFX_ENCODER(setBuffer(_stage, dvb.m_handle, _access) ); } void Encoder::setBuffer(uint8_t _stage, IndirectBufferHandle _handle, Access::Enum _access) { BX_CHECK(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); BGFX_CHECK_HANDLE("setBuffer", s_ctx->m_vertexBufferHandle, _handle); VertexBufferHandle handle = { _handle.idx }; BGFX_ENCODER(setBuffer(_stage, handle, _access) ); } void Encoder::setImage(uint8_t _stage, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format) { BX_CHECK(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); BGFX_CHECK_HANDLE_INVALID_OK("setImage/TextureHandle", s_ctx->m_textureHandle, _handle); _format = TextureFormat::Count == _format ? TextureFormat::Enum(s_ctx->m_textureRef[_handle.idx].m_format) : _format ; BX_CHECK(_format != TextureFormat::BGRA8 , "Can't use TextureFormat::BGRA8 with compute, use TextureFormat::RGBA8 instead." ); BGFX_ENCODER(setImage(_stage, _handle, _mip, _access, _format) ); } void Encoder::dispatch(ViewId _id, ProgramHandle _program, uint32_t _numX, uint32_t _numY, uint32_t _numZ, uint8_t _flags) { BGFX_CHECK_CAPS(BGFX_CAPS_COMPUTE, "Compute is not supported!"); BGFX_CHECK_HANDLE_INVALID_OK("dispatch", s_ctx->m_programHandle, _program); BGFX_ENCODER(dispatch(_id, _program, _numX, _numY, _numZ, _flags) ); } void Encoder::dispatch(ViewId _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) { BGFX_CHECK_CAPS(BGFX_CAPS_DRAW_INDIRECT, "Dispatch indirect is not supported!"); BGFX_CHECK_CAPS(BGFX_CAPS_COMPUTE, "Compute is not supported!"); BGFX_CHECK_HANDLE_INVALID_OK("dispatch", s_ctx->m_programHandle, _program); BGFX_CHECK_HANDLE("dispatch", s_ctx->m_vertexBufferHandle, _indirectHandle); BGFX_ENCODER(dispatch(_id, _program, _indirectHandle, _start, _num, _flags) ); } void Encoder::discard(uint8_t _flags) { BGFX_ENCODER(discard(_flags) ); } void Encoder::blit(ViewId _id, TextureHandle _dst, uint16_t _dstX, uint16_t _dstY, TextureHandle _src, uint16_t _srcX, uint16_t _srcY, uint16_t _width, uint16_t _height) { blit(_id, _dst, 0, _dstX, _dstY, 0, _src, 0, _srcX, _srcY, 0, _width, _height, 0); } void Encoder::blit(ViewId _id, TextureHandle _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, TextureHandle _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth) { BGFX_CHECK_CAPS(BGFX_CAPS_TEXTURE_BLIT, "Texture blit is not supported!"); BGFX_CHECK_HANDLE("blit/src TextureHandle", s_ctx->m_textureHandle, _src); BGFX_CHECK_HANDLE("blit/dst TextureHandle", s_ctx->m_textureHandle, _dst); const TextureRef& src = s_ctx->m_textureRef[_src.idx]; const TextureRef& dst = s_ctx->m_textureRef[_dst.idx]; BX_CHECK(src.m_format == dst.m_format , "Texture format must match (src %s, dst %s)." , bimg::getName(bimg::TextureFormat::Enum(src.m_format) ) , bimg::getName(bimg::TextureFormat::Enum(dst.m_format) ) ); BX_UNUSED(src, dst); BGFX_ENCODER(blit(_id, _dst, _dstMip, _dstX, _dstY, _dstZ, _src, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth) ); } #undef BGFX_ENCODER void end(Encoder* _encoder) { s_ctx->end(_encoder); } uint32_t frame(bool _capture) { BGFX_CHECK_API_THREAD(); return s_ctx->frame(_capture); } const Caps* getCaps() { return &g_caps; } const Stats* getStats() { return s_ctx->getPerfStats(); } RendererType::Enum getRendererType() { return g_caps.rendererType; } const Memory* alloc(uint32_t _size) { BX_CHECK(0 < _size, "Invalid memory operation. _size is 0."); Memory* mem = (Memory*)BX_ALLOC(g_allocator, sizeof(Memory) + _size); mem->size = _size; mem->data = (uint8_t*)mem + sizeof(Memory); return mem; } const Memory* copy(const void* _data, uint32_t _size) { BX_CHECK(0 < _size, "Invalid memory operation. _size is 0."); const Memory* mem = alloc(_size); bx::memCopy(mem->data, _data, _size); return mem; } struct MemoryRef { Memory mem; ReleaseFn releaseFn; void* userData; }; const Memory* makeRef(const void* _data, uint32_t _size, ReleaseFn _releaseFn, void* _userData) { MemoryRef* memRef = (MemoryRef*)BX_ALLOC(g_allocator, sizeof(MemoryRef) ); memRef->mem.size = _size; memRef->mem.data = (uint8_t*)_data; memRef->releaseFn = _releaseFn; memRef->userData = _userData; return &memRef->mem; } bool isMemoryRef(const Memory* _mem) { return _mem->data != (uint8_t*)_mem + sizeof(Memory); } void release(const Memory* _mem) { BX_CHECK(NULL != _mem, "_mem can't be NULL"); Memory* mem = const_cast<Memory*>(_mem); if (isMemoryRef(mem) ) { MemoryRef* memRef = reinterpret_cast<MemoryRef*>(mem); if (NULL != memRef->releaseFn) { memRef->releaseFn(mem->data, memRef->userData); } } BX_FREE(g_allocator, mem); } void setDebug(uint32_t _debug) { BGFX_CHECK_API_THREAD(); s_ctx->setDebug(_debug); } void dbgTextClear(uint8_t _attr, bool _small) { BGFX_CHECK_API_THREAD(); s_ctx->dbgTextClear(_attr, _small); } void dbgTextPrintfVargs(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, va_list _argList) { s_ctx->dbgTextPrintfVargs(_x, _y, _attr, _format, _argList); } void dbgTextPrintf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...) { BGFX_CHECK_API_THREAD(); va_list argList; va_start(argList, _format); s_ctx->dbgTextPrintfVargs(_x, _y, _attr, _format, argList); va_end(argList); } void dbgTextImage(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch) { BGFX_CHECK_API_THREAD(); s_ctx->dbgTextImage(_x, _y, _width, _height, _data, _pitch); } IndexBufferHandle createIndexBuffer(const Memory* _mem, uint16_t _flags) { BX_CHECK(NULL != _mem, "_mem can't be NULL"); return s_ctx->createIndexBuffer(_mem, _flags); } void setName(IndexBufferHandle _handle, const char* _name, int32_t _len) { s_ctx->setName(_handle, bx::StringView(_name, _len) ); } void destroy(IndexBufferHandle _handle) { s_ctx->destroyIndexBuffer(_handle); } VertexLayoutHandle createVertexLayout(const VertexLayout& _layout) { return s_ctx->createVertexLayout(_layout); } void destroy(VertexLayoutHandle _handle) { s_ctx->destroyVertexLayout(_handle); } VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexLayout& _layout, uint16_t _flags) { BX_CHECK(NULL != _mem, "_mem can't be NULL"); BX_CHECK(isValid(_layout), "Invalid VertexLayout."); return s_ctx->createVertexBuffer(_mem, _layout, _flags); } void setName(VertexBufferHandle _handle, const char* _name, int32_t _len) { s_ctx->setName(_handle, bx::StringView(_name, _len) ); } void destroy(VertexBufferHandle _handle) { s_ctx->destroyVertexBuffer(_handle); } DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num, uint16_t _flags) { return s_ctx->createDynamicIndexBuffer(_num, _flags); } DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem, uint16_t _flags) { BX_CHECK(NULL != _mem, "_mem can't be NULL"); return s_ctx->createDynamicIndexBuffer(_mem, _flags); } void update(DynamicIndexBufferHandle _handle, uint32_t _startIndex, const Memory* _mem) { BX_CHECK(NULL != _mem, "_mem can't be NULL"); s_ctx->update(_handle, _startIndex, _mem); } void destroy(DynamicIndexBufferHandle _handle) { s_ctx->destroyDynamicIndexBuffer(_handle); } DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexLayout& _layout, uint16_t _flags) { BX_CHECK(isValid(_layout), "Invalid VertexLayout."); return s_ctx->createDynamicVertexBuffer(_num, _layout, _flags); } DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexLayout& _layout, uint16_t _flags) { BX_CHECK(NULL != _mem, "_mem can't be NULL"); BX_CHECK(isValid(_layout), "Invalid VertexLayout."); return s_ctx->createDynamicVertexBuffer(_mem, _layout, _flags); } void update(DynamicVertexBufferHandle _handle, uint32_t _startVertex, const Memory* _mem) { BX_CHECK(NULL != _mem, "_mem can't be NULL"); s_ctx->update(_handle, _startVertex, _mem); } void destroy(DynamicVertexBufferHandle _handle) { s_ctx->destroyDynamicVertexBuffer(_handle); } uint32_t getAvailTransientIndexBuffer(uint32_t _num) { BX_CHECK(0 < _num, "Requesting 0 indices."); return s_ctx->getAvailTransientIndexBuffer(_num); } uint32_t getAvailTransientVertexBuffer(uint32_t _num, const VertexLayout& _layout) { BX_CHECK(0 < _num, "Requesting 0 vertices."); BX_CHECK(isValid(_layout), "Invalid VertexLayout."); return s_ctx->getAvailTransientVertexBuffer(_num, _layout.m_stride); } uint32_t getAvailInstanceDataBuffer(uint32_t _num, uint16_t _stride) { BX_CHECK(0 < _num, "Requesting 0 instances."); return s_ctx->getAvailTransientVertexBuffer(_num, _stride); } void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num) { BX_CHECK(NULL != _tib, "_tib can't be NULL"); BX_CHECK(0 < _num, "Requesting 0 indices."); s_ctx->allocTransientIndexBuffer(_tib, _num); BX_CHECK(_num == _tib->size/2 , "Failed to allocate transient index buffer (requested %d, available %d). " "Use bgfx::getAvailTransient* functions to ensure availability." , _num , _tib->size/2 ); } void allocTransientVertexBuffer(TransientVertexBuffer* _tvb, uint32_t _num, const VertexLayout& _layout) { BX_CHECK(NULL != _tvb, "_tvb can't be NULL"); BX_CHECK(0 < _num, "Requesting 0 vertices."); BX_CHECK(isValid(_layout), "Invalid VertexLayout."); s_ctx->allocTransientVertexBuffer(_tvb, _num, _layout); BX_CHECK(_num == _tvb->size / _layout.m_stride , "Failed to allocate transient vertex buffer (requested %d, available %d). " "Use bgfx::getAvailTransient* functions to ensure availability." , _num , _tvb->size / _layout.m_stride ); } bool allocTransientBuffers(bgfx::TransientVertexBuffer* _tvb, const bgfx::VertexLayout& _layout, uint32_t _numVertices, bgfx::TransientIndexBuffer* _tib, uint32_t _numIndices) { BGFX_MUTEX_SCOPE(s_ctx->m_resourceApiLock); if (_numVertices == getAvailTransientVertexBuffer(_numVertices, _layout) && _numIndices == getAvailTransientIndexBuffer(_numIndices) ) { allocTransientVertexBuffer(_tvb, _numVertices, _layout); allocTransientIndexBuffer(_tib, _numIndices); return true; } return false; } void allocInstanceDataBuffer(InstanceDataBuffer* _idb, uint32_t _num, uint16_t _stride) { BGFX_CHECK_CAPS(BGFX_CAPS_INSTANCING, "Instancing is not supported!"); BX_CHECK(bx::isAligned(_stride, 16), "Stride must be multiple of 16."); BX_CHECK(0 < _num, "Requesting 0 instanced data vertices."); s_ctx->allocInstanceDataBuffer(_idb, _num, _stride); BX_CHECK(_num == _idb->size / _stride , "Failed to allocate instance data buffer (requested %d, available %d). " "Use bgfx::getAvailTransient* functions to ensure availability." , _num , _idb->size / _stride ); } IndirectBufferHandle createIndirectBuffer(uint32_t _num) { return s_ctx->createIndirectBuffer(_num); } void destroy(IndirectBufferHandle _handle) { s_ctx->destroyIndirectBuffer(_handle); } ShaderHandle createShader(const Memory* _mem) { BX_CHECK(NULL != _mem, "_mem can't be NULL"); return s_ctx->createShader(_mem); } uint16_t getShaderUniforms(ShaderHandle _handle, UniformHandle* _uniforms, uint16_t _max) { BX_WARN(NULL == _uniforms || 0 != _max , "Passing uniforms array pointer, but array maximum capacity is set to 0." ); uint16_t num = s_ctx->getShaderUniforms(_handle, _uniforms, _max); BX_WARN(0 == _max || num <= _max , "Shader has more uniforms that capacity of output array. Output is truncated (num %d, max %d)." , num , _max ); return num; } void setName(ShaderHandle _handle, const char* _name, int32_t _len) { s_ctx->setName(_handle, bx::StringView(_name, _len) ); } void destroy(ShaderHandle _handle) { s_ctx->destroyShader(_handle); } ProgramHandle createProgram(ShaderHandle _vsh, ShaderHandle _fsh, bool _destroyShaders) { if (!isValid(_fsh) ) { return createProgram(_vsh, _destroyShaders); } return s_ctx->createProgram(_vsh, _fsh, _destroyShaders); } ProgramHandle createProgram(ShaderHandle _csh, bool _destroyShader) { return s_ctx->createProgram(_csh, _destroyShader); } void destroy(ProgramHandle _handle) { s_ctx->destroyProgram(_handle); } static void isTextureValid(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags, bx::Error* _err) { BX_ERROR_SCOPE(_err); const bool is3DTexture = 1 < _depth; if (_cubeMap && is3DTexture) { _err->setError(BGFX_ERROR_TEXTURE_VALIDATION , "Texture can't be depth and cube map at the same time." ); return; } if (is3DTexture && 0 == (g_caps.supported & BGFX_CAPS_TEXTURE_3D) ) { _err->setError(BGFX_ERROR_TEXTURE_VALIDATION , "Texture3D is not supported! " "Use bgfx::getCaps to check BGFX_CAPS_TEXTURE_3D backend renderer capabilities." ); return; } if (0 != (_flags & BGFX_TEXTURE_RT_MASK) && 0 != (_flags & BGFX_TEXTURE_READ_BACK) ) { _err->setError(BGFX_ERROR_TEXTURE_VALIDATION , "Can't create render target with BGFX_TEXTURE_READ_BACK flag." ); return; } if (1 < _numLayers && 0 == (g_caps.supported & BGFX_CAPS_TEXTURE_2D_ARRAY) ) { _err->setError(BGFX_ERROR_TEXTURE_VALIDATION , "Texture array is not supported! " "Use bgfx::getCaps to check BGFX_CAPS_TEXTURE_2D_ARRAY backend renderer capabilities." ); return; } bool formatSupported; if (0 != (_flags & (BGFX_TEXTURE_RT | BGFX_TEXTURE_RT_WRITE_ONLY)) ) { formatSupported = 0 != (g_caps.formats[_format] & BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER); } else { formatSupported = 0 != (g_caps.formats[_format] & (0 | BGFX_CAPS_FORMAT_TEXTURE_2D | BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED | BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB ) ); } uint16_t srgbCaps = BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB; if (_cubeMap) { formatSupported = 0 != (g_caps.formats[_format] & (0 | BGFX_CAPS_FORMAT_TEXTURE_CUBE | BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED | BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB ) ); srgbCaps = BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB; } else if (is3DTexture) { formatSupported = 0 != (g_caps.formats[_format] & (0 | BGFX_CAPS_FORMAT_TEXTURE_3D | BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED | BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB ) ); srgbCaps = BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB; } if (formatSupported && 0 != (_flags & BGFX_TEXTURE_RT_MASK) ) { formatSupported = 0 != (g_caps.formats[_format] & (0 | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER ) ); } if (!formatSupported) { _err->setError(BGFX_ERROR_TEXTURE_VALIDATION , "Texture format is not supported! " "Use bgfx::isTextureValid to check support for texture format before creating it." ); return; } if (0 != (_flags & BGFX_TEXTURE_MSAA_SAMPLE) && 0 == (g_caps.formats[_format] & BGFX_CAPS_FORMAT_TEXTURE_MSAA) ) { _err->setError(BGFX_ERROR_TEXTURE_VALIDATION , "MSAA sampling for this texture format is not supported." ); return; } if (0 != (_flags & BGFX_TEXTURE_SRGB) && 0 == (g_caps.formats[_format] & srgbCaps & (0 | BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB | BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB | BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB ) ) ) { _err->setError(BGFX_ERROR_TEXTURE_VALIDATION , "sRGB sampling for this texture format is not supported." ); return; } } bool isTextureValid(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags) { bx::Error err; isTextureValid(_depth, _cubeMap, _numLayers, _format, _flags, &err); return err.isOk(); } void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format) { bimg::imageGetSize( (bimg::TextureInfo*)&_info, _width, _height, _depth, _cubeMap, _hasMips, _numLayers, bimg::TextureFormat::Enum(_format) ); } TextureHandle createTexture(const Memory* _mem, uint64_t _flags, uint8_t _skip, TextureInfo* _info) { BX_CHECK(NULL != _mem, "_mem can't be NULL"); return s_ctx->createTexture(_mem, _flags, _skip, _info, BackbufferRatio::Count, false); } void getTextureSizeFromRatio(BackbufferRatio::Enum _ratio, uint16_t& _width, uint16_t& _height) { switch (_ratio) { case BackbufferRatio::Half: _width /= 2; _height /= 2; break; case BackbufferRatio::Quarter: _width /= 4; _height /= 4; break; case BackbufferRatio::Eighth: _width /= 8; _height /= 8; break; case BackbufferRatio::Sixteenth: _width /= 16; _height /= 16; break; case BackbufferRatio::Double: _width *= 2; _height *= 2; break; default: break; } _width = bx::max<uint16_t>(1, _width); _height = bx::max<uint16_t>(1, _height); } static TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags, const Memory* _mem) { bx::Error err; isTextureValid(0, false, _numLayers, _format, _flags, &err); BX_CHECK(err.isOk(), "%s (layers %d, format %s)" , err.getMessage().getPtr() , _numLayers , getName(_format) ); if (BackbufferRatio::Count != _ratio) { _width = uint16_t(s_ctx->m_init.resolution.width); _height = uint16_t(s_ctx->m_init.resolution.height); getTextureSizeFromRatio(_ratio, _width, _height); } const uint8_t numMips = calcNumMips(_hasMips, _width, _height); _numLayers = bx::max<uint16_t>(_numLayers, 1); if (BX_ENABLED(BGFX_CONFIG_DEBUG) && NULL != _mem) { TextureInfo ti; calcTextureSize(ti, _width, _height, 1, false, _hasMips, _numLayers, _format); BX_CHECK(ti.storageSize == _mem->size , "createTexture2D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)" , ti.storageSize , _mem->size ); } uint32_t size = sizeof(uint32_t)+sizeof(TextureCreate); const Memory* mem = alloc(size); bx::StaticMemoryBlockWriter writer(mem->data, mem->size); uint32_t magic = BGFX_CHUNK_MAGIC_TEX; bx::write(&writer, magic); TextureCreate tc; tc.m_width = _width; tc.m_height = _height; tc.m_depth = 0; tc.m_numLayers = _numLayers; tc.m_numMips = numMips; tc.m_format = _format; tc.m_cubeMap = false; tc.m_mem = _mem; bx::write(&writer, tc); return s_ctx->createTexture(mem, _flags, 0, NULL, _ratio, NULL != _mem); } TextureHandle createTexture2D(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags, const Memory* _mem) { BX_CHECK(_width > 0 && _height > 0, "Invalid texture size (width %d, height %d).", _width, _height); return createTexture2D(BackbufferRatio::Count, _width, _height, _hasMips, _numLayers, _format, _flags, _mem); } TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags) { BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio."); return createTexture2D(_ratio, 0, 0, _hasMips, _numLayers, _format, _flags, NULL); } TextureHandle createTexture3D(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, TextureFormat::Enum _format, uint64_t _flags, const Memory* _mem) { bx::Error err; isTextureValid(_depth, false, 1, _format, _flags, &err); BX_CHECK(err.isOk(), "%s", err.getMessage().getPtr() ); const uint8_t numMips = calcNumMips(_hasMips, _width, _height, _depth); if (BX_ENABLED(BGFX_CONFIG_DEBUG) && NULL != _mem) { TextureInfo ti; calcTextureSize(ti, _width, _height, _depth, false, _hasMips, 1, _format); BX_CHECK(ti.storageSize == _mem->size , "createTexture3D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)" , ti.storageSize , _mem->size ); } uint32_t size = sizeof(uint32_t)+sizeof(TextureCreate); const Memory* mem = alloc(size); bx::StaticMemoryBlockWriter writer(mem->data, mem->size); uint32_t magic = BGFX_CHUNK_MAGIC_TEX; bx::write(&writer, magic); TextureCreate tc; tc.m_width = _width; tc.m_height = _height; tc.m_depth = _depth; tc.m_numLayers = 1; tc.m_numMips = numMips; tc.m_format = _format; tc.m_cubeMap = false; tc.m_mem = _mem; bx::write(&writer, tc); return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count, NULL != _mem); } TextureHandle createTextureCube(uint16_t _size, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags, const Memory* _mem) { bx::Error err; isTextureValid(0, true, _numLayers, _format, _flags, &err); BX_CHECK(err.isOk(), "%s", err.getMessage().getPtr() ); const uint8_t numMips = calcNumMips(_hasMips, _size, _size); _numLayers = bx::max<uint16_t>(_numLayers, 1); if (BX_ENABLED(BGFX_CONFIG_DEBUG) && NULL != _mem) { TextureInfo ti; calcTextureSize(ti, _size, _size, 1, true, _hasMips, _numLayers, _format); BX_CHECK(ti.storageSize == _mem->size , "createTextureCube: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)" , ti.storageSize , _mem->size ); } uint32_t size = sizeof(uint32_t)+sizeof(TextureCreate); const Memory* mem = alloc(size); bx::StaticMemoryBlockWriter writer(mem->data, mem->size); uint32_t magic = BGFX_CHUNK_MAGIC_TEX; bx::write(&writer, magic); TextureCreate tc; tc.m_width = _size; tc.m_height = _size; tc.m_depth = 0; tc.m_numLayers = _numLayers; tc.m_numMips = numMips; tc.m_format = _format; tc.m_cubeMap = true; tc.m_mem = _mem; bx::write(&writer, tc); return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count, NULL != _mem); } void setName(TextureHandle _handle, const char* _name, int32_t _len) { s_ctx->setName(_handle, bx::StringView(_name, _len) ); } void* getDirectAccessPtr(TextureHandle _handle) { return s_ctx->getDirectAccessPtr(_handle); } void destroy(TextureHandle _handle) { s_ctx->destroyTexture(_handle); } void updateTexture2D(TextureHandle _handle, uint16_t _layer, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch) { BX_CHECK(NULL != _mem, "_mem can't be NULL"); if (_width == 0 || _height == 0) { release(_mem); } else { s_ctx->updateTexture(_handle, 0, _mip, _x, _y, _layer, _width, _height, 1, _pitch, _mem); } } void updateTexture3D(TextureHandle _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const Memory* _mem) { BX_CHECK(NULL != _mem, "_mem can't be NULL"); BGFX_CHECK_CAPS(BGFX_CAPS_TEXTURE_3D, "Texture3D is not supported!"); if (0 == _width || 0 == _height || 0 == _depth) { release(_mem); } else { s_ctx->updateTexture(_handle, 0, _mip, _x, _y, _z, _width, _height, _depth, UINT16_MAX, _mem); } } void updateTextureCube(TextureHandle _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch) { BX_CHECK(NULL != _mem, "_mem can't be NULL"); BX_CHECK(_side <= 5, "Invalid side %d.", _side); if (0 == _width || 0 == _height) { release(_mem); } else { s_ctx->updateTexture(_handle, _side, _mip, _x, _y, _layer, _width, _height, 1, _pitch, _mem); } } uint32_t readTexture(TextureHandle _handle, void* _data, uint8_t _mip) { BX_CHECK(NULL != _data, "_data can't be NULL"); BGFX_CHECK_CAPS(BGFX_CAPS_TEXTURE_READ_BACK, "Texture read-back is not supported!"); return s_ctx->readTexture(_handle, _data, _mip); } FrameBufferHandle createFrameBuffer(uint16_t _width, uint16_t _height, TextureFormat::Enum _format, uint64_t _textureFlags) { _textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT; TextureHandle th = createTexture2D(_width, _height, false, 1, _format, _textureFlags); return createFrameBuffer(1, &th, true); } FrameBufferHandle createFrameBuffer(BackbufferRatio::Enum _ratio, TextureFormat::Enum _format, uint64_t _textureFlags) { BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio."); _textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT; TextureHandle th = createTexture2D(_ratio, false, 1, _format, _textureFlags); return createFrameBuffer(1, &th, true); } FrameBufferHandle createFrameBuffer(uint8_t _num, const TextureHandle* _handles, bool _destroyTextures) { Attachment attachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; for (uint8_t ii = 0; ii < _num; ++ii) { Attachment& at = attachment[ii]; at.init(_handles[ii], Access::Write, 0, 0, BGFX_RESOLVE_AUTO_GEN_MIPS); } return createFrameBuffer(_num, attachment, _destroyTextures); } FrameBufferHandle createFrameBuffer(uint8_t _num, const Attachment* _attachment, bool _destroyTextures) { BX_CHECK(_num != 0, "Number of frame buffer attachments can't be 0."); BX_CHECK(_num <= BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS , "Number of frame buffer attachments is larger than allowed %d (max: %d)." , _num , BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS ); BX_CHECK(NULL != _attachment, "_attachment can't be NULL"); return s_ctx->createFrameBuffer(_num, _attachment, _destroyTextures); } FrameBufferHandle createFrameBuffer(void* _nwh, uint16_t _width, uint16_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) { BGFX_CHECK_CAPS(BGFX_CAPS_SWAP_CHAIN, "Swap chain is not supported!"); BX_WARN(_width > 0 && _height > 0 , "Invalid frame buffer dimensions (width %d, height %d)." , _width , _height ); BX_CHECK(_format == TextureFormat::Count || bimg::isColor(bimg::TextureFormat::Enum(_format) ) , "Invalid texture format for color (%s)." , bimg::getName(bimg::TextureFormat::Enum(_format) ) ); BX_CHECK(_depthFormat == TextureFormat::Count || bimg::isDepth(bimg::TextureFormat::Enum(_depthFormat) ) , "Invalid texture format for depth (%s)." , bimg::getName(bimg::TextureFormat::Enum(_depthFormat) ) ); return s_ctx->createFrameBuffer( _nwh , bx::max<uint16_t>(_width, 1) , bx::max<uint16_t>(_height, 1) , _format , _depthFormat ); } void setName(FrameBufferHandle _handle, const char* _name, int32_t _len) { s_ctx->setName(_handle, bx::StringView(_name, _len) ); } TextureHandle getTexture(FrameBufferHandle _handle, uint8_t _attachment) { return s_ctx->getTexture(_handle, _attachment); } void destroy(FrameBufferHandle _handle) { s_ctx->destroyFrameBuffer(_handle); } UniformHandle createUniform(const char* _name, UniformType::Enum _type, uint16_t _num) { return s_ctx->createUniform(_name, _type, _num); } void getUniformInfo(UniformHandle _handle, UniformInfo& _info) { s_ctx->getUniformInfo(_handle, _info); } void destroy(UniformHandle _handle) { s_ctx->destroyUniform(_handle); } OcclusionQueryHandle createOcclusionQuery() { BGFX_CHECK_CAPS(BGFX_CAPS_OCCLUSION_QUERY, "Occlusion query is not supported!"); return s_ctx->createOcclusionQuery(); } OcclusionQueryResult::Enum getResult(OcclusionQueryHandle _handle, int32_t* _result) { BGFX_CHECK_CAPS(BGFX_CAPS_OCCLUSION_QUERY, "Occlusion query is not supported!"); return s_ctx->getResult(_handle, _result); } void destroy(OcclusionQueryHandle _handle) { BGFX_CHECK_CAPS(BGFX_CAPS_OCCLUSION_QUERY, "Occlusion query is not supported!"); s_ctx->destroyOcclusionQuery(_handle); } void setPaletteColor(uint8_t _index, uint32_t _rgba) { const uint8_t rr = uint8_t(_rgba>>24); const uint8_t gg = uint8_t(_rgba>>16); const uint8_t bb = uint8_t(_rgba>> 8); const uint8_t aa = uint8_t(_rgba>> 0); const float rgba[4] = { rr * 1.0f/255.0f, gg * 1.0f/255.0f, bb * 1.0f/255.0f, aa * 1.0f/255.0f, }; s_ctx->setPaletteColor(_index, rgba); } void setPaletteColor(uint8_t _index, float _r, float _g, float _b, float _a) { float rgba[4] = { _r, _g, _b, _a }; s_ctx->setPaletteColor(_index, rgba); } void setPaletteColor(uint8_t _index, const float _rgba[4]) { s_ctx->setPaletteColor(_index, _rgba); } bool checkView(ViewId _id) { // workaround GCC 4.9 type-limit check. const uint32_t id = _id; return id < BGFX_CONFIG_MAX_VIEWS; } void setViewName(ViewId _id, const char* _name) { BX_CHECK(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewName(_id, _name); } void setViewRect(ViewId _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) { BX_CHECK(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewRect(_id, _x, _y, _width, _height); } void setViewRect(ViewId _id, uint16_t _x, uint16_t _y, BackbufferRatio::Enum _ratio) { BX_CHECK(checkView(_id), "Invalid view id: %d", _id); uint16_t width = uint16_t(s_ctx->m_init.resolution.width); uint16_t height = uint16_t(s_ctx->m_init.resolution.height); getTextureSizeFromRatio(_ratio, width, height); setViewRect(_id, _x, _y, width, height); } void setViewScissor(ViewId _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) { BX_CHECK(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewScissor(_id, _x, _y, _width, _height); } void setViewClear(ViewId _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) { BX_CHECK(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewClear(_id, _flags, _rgba, _depth, _stencil); } void setViewClear(ViewId _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7) { BX_CHECK(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewClear(_id, _flags, _depth, _stencil, _0, _1, _2, _3, _4, _5, _6, _7); } void setViewMode(ViewId _id, ViewMode::Enum _mode) { BX_CHECK(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewMode(_id, _mode); } void setViewFrameBuffer(ViewId _id, FrameBufferHandle _handle) { BX_CHECK(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewFrameBuffer(_id, _handle); } void setViewTransform(ViewId _id, const void* _view, const void* _proj) { BX_CHECK(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewTransform(_id, _view, _proj); } void setViewOrder(ViewId _id, uint16_t _num, const ViewId* _order) { BX_CHECK(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewOrder(_id, _num, _order); } void resetView(ViewId _id) { BX_CHECK(checkView(_id), "Invalid view id: %d", _id); s_ctx->resetView(_id); } void setMarker(const char* _marker) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setMarker(_marker); } void setState(uint64_t _state, uint32_t _rgba) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setState(_state, _rgba); } void setCondition(OcclusionQueryHandle _handle, bool _visible) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setCondition(_handle, _visible); } void setStencil(uint32_t _fstencil, uint32_t _bstencil) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setStencil(_fstencil, _bstencil); } uint16_t setScissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) { BGFX_CHECK_API_THREAD(); return s_ctx->m_encoder0->setScissor(_x, _y, _width, _height); } void setScissor(uint16_t _cache) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setScissor(_cache); } uint32_t setTransform(const void* _mtx, uint16_t _num) { BGFX_CHECK_API_THREAD(); return s_ctx->m_encoder0->setTransform(_mtx, _num); } uint32_t allocTransform(Transform* _transform, uint16_t _num) { BGFX_CHECK_API_THREAD(); return s_ctx->m_encoder0->allocTransform(_transform, _num); } void setTransform(uint32_t _cache, uint16_t _num) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setTransform(_cache, _num); } void setUniform(UniformHandle _handle, const void* _value, uint16_t _num) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setUniform(_handle, _value, _num); } void setIndexBuffer(IndexBufferHandle _handle) { setIndexBuffer(_handle, 0, UINT32_MAX); } void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setIndexBuffer(_handle, _firstIndex, _numIndices); } void setIndexBuffer(DynamicIndexBufferHandle _handle) { setIndexBuffer(_handle, 0, UINT32_MAX); } void setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setIndexBuffer(_handle, _firstIndex, _numIndices); } void setIndexBuffer(const TransientIndexBuffer* _tib) { setIndexBuffer(_tib, 0, UINT32_MAX); } void setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _firstIndex, uint32_t _numIndices) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setIndexBuffer(_tib, _firstIndex, _numIndices); } void setVertexBuffer( uint8_t _stream , VertexBufferHandle _handle , uint32_t _startVertex , uint32_t _numVertices , VertexLayoutHandle _layoutHandle ) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setVertexBuffer(_stream, _handle, _startVertex, _numVertices, _layoutHandle); } void setVertexBuffer(uint8_t _stream, VertexBufferHandle _handle) { setVertexBuffer(_stream, _handle, 0, UINT32_MAX); } void setVertexBuffer( uint8_t _stream , DynamicVertexBufferHandle _handle , uint32_t _startVertex , uint32_t _numVertices , VertexLayoutHandle _layoutHandle ) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setVertexBuffer(_stream, _handle, _startVertex, _numVertices, _layoutHandle); } void setVertexBuffer(uint8_t _stream, DynamicVertexBufferHandle _handle) { setVertexBuffer(_stream, _handle, 0, UINT32_MAX); } void setVertexBuffer( uint8_t _stream , const TransientVertexBuffer* _tvb , uint32_t _startVertex , uint32_t _numVertices , VertexLayoutHandle _layoutHandle ) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setVertexBuffer(_stream, _tvb, _startVertex, _numVertices, _layoutHandle); } void setVertexBuffer(uint8_t _stream, const TransientVertexBuffer* _tvb) { setVertexBuffer(_stream, _tvb, 0, UINT32_MAX); } void setVertexCount(uint32_t _numVertices) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setVertexCount(_numVertices); } void setInstanceDataBuffer(const InstanceDataBuffer* _idb) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setInstanceDataBuffer(_idb); } void setInstanceDataBuffer(const InstanceDataBuffer* _idb, uint32_t _start, uint32_t _num) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setInstanceDataBuffer(_idb, _start, _num); } void setInstanceDataBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setInstanceDataBuffer(_handle, _startVertex, _num); } void setInstanceDataBuffer(DynamicVertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setInstanceDataBuffer(_handle, _startVertex, _num); } void setInstanceCount(uint32_t _numInstances) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setInstanceCount(_numInstances); } void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setTexture(_stage, _sampler, _handle, _flags); } void touch(ViewId _id) { ProgramHandle handle = BGFX_INVALID_HANDLE; submit(_id, handle); } void submit(ViewId _id, ProgramHandle _program, uint32_t _depth, uint8_t _flags) { OcclusionQueryHandle handle = BGFX_INVALID_HANDLE; submit(_id, _program, handle, _depth, _flags); } void submit(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth, uint8_t _flags) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->submit(_id, _program, _occlusionQuery, _depth, _flags); } void submit(ViewId _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, uint8_t _flags) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->submit(_id, _program, _indirectHandle, _start, _num, _depth, _flags); } void setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setBuffer(_stage, _handle, _access); } void setBuffer(uint8_t _stage, VertexBufferHandle _handle, Access::Enum _access) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setBuffer(_stage, _handle, _access); } void setBuffer(uint8_t _stage, DynamicIndexBufferHandle _handle, Access::Enum _access) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setBuffer(_stage, _handle, _access); } void setBuffer(uint8_t _stage, DynamicVertexBufferHandle _handle, Access::Enum _access) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setBuffer(_stage, _handle, _access); } void setBuffer(uint8_t _stage, IndirectBufferHandle _handle, Access::Enum _access) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setBuffer(_stage, _handle, _access); } void setImage(uint8_t _stage, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->setImage(_stage, _handle, _mip, _access, _format); } void dispatch(ViewId _id, ProgramHandle _handle, uint32_t _numX, uint32_t _numY, uint32_t _numZ, uint8_t _flags) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->dispatch(_id, _handle, _numX, _numY, _numZ, _flags); } void dispatch(ViewId _id, ProgramHandle _handle, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->dispatch(_id, _handle, _indirectHandle, _start, _num, _flags); } void discard(uint8_t _flags) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->discard(_flags); } void blit(ViewId _id, TextureHandle _dst, uint16_t _dstX, uint16_t _dstY, TextureHandle _src, uint16_t _srcX, uint16_t _srcY, uint16_t _width, uint16_t _height) { blit(_id, _dst, 0, _dstX, _dstY, 0, _src, 0, _srcX, _srcY, 0, _width, _height, 0); } void blit(ViewId _id, TextureHandle _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, TextureHandle _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth) { BGFX_CHECK_API_THREAD(); s_ctx->m_encoder0->blit(_id, _dst, _dstMip, _dstX, _dstY, _dstZ, _src, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth); } void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) { BGFX_CHECK_API_THREAD(); s_ctx->requestScreenShot(_handle, _filePath); } } // namespace bgfx #if BX_PLATFORM_WINDOWS extern "C" { // When laptop setup has integrated and discrete GPU, following driver workarounds will // select discrete GPU: // Reference(s): // - https://web.archive.org/web/20180722051003/https://docs.nvidia.com/gameworks/content/technologies/desktop/optimus.htm // __declspec(dllexport) uint32_t NvOptimusEnablement = UINT32_C(1); // Reference(s): // - https://web.archive.org/web/20180722051032/https://gpuopen.com/amdpowerxpressrequesthighperformance/ // __declspec(dllexport) uint32_t AmdPowerXpressRequestHighPerformance = UINT32_C(1); } #endif // BX_PLATFORM_WINDOWS #define BGFX_TEXTURE_FORMAT_BIMG(_fmt) \ BX_STATIC_ASSERT(uint32_t(bgfx::TextureFormat::_fmt) == uint32_t(bimg::TextureFormat::_fmt) ) BGFX_TEXTURE_FORMAT_BIMG(BC1); BGFX_TEXTURE_FORMAT_BIMG(BC2); BGFX_TEXTURE_FORMAT_BIMG(BC3); BGFX_TEXTURE_FORMAT_BIMG(BC4); BGFX_TEXTURE_FORMAT_BIMG(BC5); BGFX_TEXTURE_FORMAT_BIMG(BC6H); BGFX_TEXTURE_FORMAT_BIMG(BC7); BGFX_TEXTURE_FORMAT_BIMG(ETC1); BGFX_TEXTURE_FORMAT_BIMG(ETC2); BGFX_TEXTURE_FORMAT_BIMG(ETC2A); BGFX_TEXTURE_FORMAT_BIMG(ETC2A1); BGFX_TEXTURE_FORMAT_BIMG(PTC12); BGFX_TEXTURE_FORMAT_BIMG(PTC14); BGFX_TEXTURE_FORMAT_BIMG(PTC12A); BGFX_TEXTURE_FORMAT_BIMG(PTC14A); BGFX_TEXTURE_FORMAT_BIMG(PTC22); BGFX_TEXTURE_FORMAT_BIMG(PTC24); BGFX_TEXTURE_FORMAT_BIMG(ATC); BGFX_TEXTURE_FORMAT_BIMG(ATCE); BGFX_TEXTURE_FORMAT_BIMG(ATCI); BGFX_TEXTURE_FORMAT_BIMG(ASTC4x4); BGFX_TEXTURE_FORMAT_BIMG(ASTC5x5); BGFX_TEXTURE_FORMAT_BIMG(ASTC6x6); BGFX_TEXTURE_FORMAT_BIMG(ASTC8x5); BGFX_TEXTURE_FORMAT_BIMG(ASTC8x6); BGFX_TEXTURE_FORMAT_BIMG(ASTC10x5); BGFX_TEXTURE_FORMAT_BIMG(Unknown); BGFX_TEXTURE_FORMAT_BIMG(R1); BGFX_TEXTURE_FORMAT_BIMG(A8); BGFX_TEXTURE_FORMAT_BIMG(R8); BGFX_TEXTURE_FORMAT_BIMG(R8I); BGFX_TEXTURE_FORMAT_BIMG(R8U); BGFX_TEXTURE_FORMAT_BIMG(R8S); BGFX_TEXTURE_FORMAT_BIMG(R16); BGFX_TEXTURE_FORMAT_BIMG(R16I); BGFX_TEXTURE_FORMAT_BIMG(R16U); BGFX_TEXTURE_FORMAT_BIMG(R16F); BGFX_TEXTURE_FORMAT_BIMG(R16S); BGFX_TEXTURE_FORMAT_BIMG(R32I); BGFX_TEXTURE_FORMAT_BIMG(R32U); BGFX_TEXTURE_FORMAT_BIMG(R32F); BGFX_TEXTURE_FORMAT_BIMG(RG8); BGFX_TEXTURE_FORMAT_BIMG(RG8I); BGFX_TEXTURE_FORMAT_BIMG(RG8U); BGFX_TEXTURE_FORMAT_BIMG(RG8S); BGFX_TEXTURE_FORMAT_BIMG(RG16); BGFX_TEXTURE_FORMAT_BIMG(RG16I); BGFX_TEXTURE_FORMAT_BIMG(RG16U); BGFX_TEXTURE_FORMAT_BIMG(RG16F); BGFX_TEXTURE_FORMAT_BIMG(RG16S); BGFX_TEXTURE_FORMAT_BIMG(RG32I); BGFX_TEXTURE_FORMAT_BIMG(RG32U); BGFX_TEXTURE_FORMAT_BIMG(RG32F); BGFX_TEXTURE_FORMAT_BIMG(RGB8); BGFX_TEXTURE_FORMAT_BIMG(RGB8I); BGFX_TEXTURE_FORMAT_BIMG(RGB8U); BGFX_TEXTURE_FORMAT_BIMG(RGB8S); BGFX_TEXTURE_FORMAT_BIMG(RGB9E5F); BGFX_TEXTURE_FORMAT_BIMG(BGRA8); BGFX_TEXTURE_FORMAT_BIMG(RGBA8); BGFX_TEXTURE_FORMAT_BIMG(RGBA8I); BGFX_TEXTURE_FORMAT_BIMG(RGBA8U); BGFX_TEXTURE_FORMAT_BIMG(RGBA8S); BGFX_TEXTURE_FORMAT_BIMG(RGBA16); BGFX_TEXTURE_FORMAT_BIMG(RGBA16I); BGFX_TEXTURE_FORMAT_BIMG(RGBA16U); BGFX_TEXTURE_FORMAT_BIMG(RGBA16F); BGFX_TEXTURE_FORMAT_BIMG(RGBA16S); BGFX_TEXTURE_FORMAT_BIMG(RGBA32I); BGFX_TEXTURE_FORMAT_BIMG(RGBA32U); BGFX_TEXTURE_FORMAT_BIMG(RGBA32F); BGFX_TEXTURE_FORMAT_BIMG(R5G6B5); BGFX_TEXTURE_FORMAT_BIMG(RGBA4); BGFX_TEXTURE_FORMAT_BIMG(RGB5A1); BGFX_TEXTURE_FORMAT_BIMG(RGB10A2); BGFX_TEXTURE_FORMAT_BIMG(RG11B10F); BGFX_TEXTURE_FORMAT_BIMG(UnknownDepth); BGFX_TEXTURE_FORMAT_BIMG(D16); BGFX_TEXTURE_FORMAT_BIMG(D24); BGFX_TEXTURE_FORMAT_BIMG(D24S8); BGFX_TEXTURE_FORMAT_BIMG(D32); BGFX_TEXTURE_FORMAT_BIMG(D16F); BGFX_TEXTURE_FORMAT_BIMG(D24F); BGFX_TEXTURE_FORMAT_BIMG(D32F); BGFX_TEXTURE_FORMAT_BIMG(D0S8); BGFX_TEXTURE_FORMAT_BIMG(Count); #undef BGFX_TEXTURE_FORMAT_BIMG #include <bgfx/c99/bgfx.h> #define FLAGS_MASK_TEST(_flags, _mask) ( (_flags) == ( (_flags) & (_mask) ) ) BX_STATIC_ASSERT(FLAGS_MASK_TEST(0 | BGFX_SAMPLER_INTERNAL_DEFAULT | BGFX_SAMPLER_INTERNAL_SHARED , BGFX_SAMPLER_RESERVED_MASK ) ); BX_STATIC_ASSERT(FLAGS_MASK_TEST(0 | BGFX_RESET_INTERNAL_FORCE , BGFX_RESET_RESERVED_MASK ) ); BX_STATIC_ASSERT(FLAGS_MASK_TEST(0 | BGFX_STATE_INTERNAL_SCISSOR | BGFX_STATE_INTERNAL_OCCLUSION_QUERY , BGFX_STATE_RESERVED_MASK ) ); BX_STATIC_ASSERT(FLAGS_MASK_TEST(0 | BGFX_SUBMIT_INTERNAL_OCCLUSION_VISIBLE , BGFX_SUBMIT_RESERVED_MASK ) ); BX_STATIC_ASSERT( (0 | BGFX_STATE_ALPHA_REF_MASK | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE | BGFX_STATE_BLEND_EQUATION_MASK | BGFX_STATE_BLEND_INDEPENDENT | BGFX_STATE_BLEND_MASK | BGFX_STATE_CONSERVATIVE_RASTER | BGFX_STATE_CULL_MASK | BGFX_STATE_DEPTH_TEST_MASK | BGFX_STATE_FRONT_CCW | BGFX_STATE_LINEAA | BGFX_STATE_MSAA | BGFX_STATE_POINT_SIZE_MASK | BGFX_STATE_PT_MASK | BGFX_STATE_RESERVED_MASK | BGFX_STATE_WRITE_MASK ) == (0 ^ BGFX_STATE_ALPHA_REF_MASK ^ BGFX_STATE_BLEND_ALPHA_TO_COVERAGE ^ BGFX_STATE_BLEND_EQUATION_MASK ^ BGFX_STATE_BLEND_INDEPENDENT ^ BGFX_STATE_BLEND_MASK ^ BGFX_STATE_CONSERVATIVE_RASTER ^ BGFX_STATE_CULL_MASK ^ BGFX_STATE_DEPTH_TEST_MASK ^ BGFX_STATE_FRONT_CCW ^ BGFX_STATE_LINEAA ^ BGFX_STATE_MSAA ^ BGFX_STATE_POINT_SIZE_MASK ^ BGFX_STATE_PT_MASK ^ BGFX_STATE_RESERVED_MASK ^ BGFX_STATE_WRITE_MASK ) ); BX_STATIC_ASSERT(FLAGS_MASK_TEST(BGFX_CAPS_TEXTURE_COMPARE_LEQUAL, BGFX_CAPS_TEXTURE_COMPARE_ALL) ); BX_STATIC_ASSERT( (0 | BGFX_CAPS_ALPHA_TO_COVERAGE | BGFX_CAPS_BLEND_INDEPENDENT | BGFX_CAPS_COMPUTE | BGFX_CAPS_CONSERVATIVE_RASTER | BGFX_CAPS_DRAW_INDIRECT | BGFX_CAPS_FRAGMENT_DEPTH | BGFX_CAPS_FRAGMENT_ORDERING | BGFX_CAPS_GRAPHICS_DEBUGGER | BGFX_CAPS_HDR10 | BGFX_CAPS_HIDPI | BGFX_CAPS_INDEX32 | BGFX_CAPS_INSTANCING | BGFX_CAPS_OCCLUSION_QUERY | BGFX_CAPS_RENDERER_MULTITHREADED | BGFX_CAPS_SWAP_CHAIN | BGFX_CAPS_TEXTURE_2D_ARRAY | BGFX_CAPS_TEXTURE_3D | BGFX_CAPS_TEXTURE_BLIT | BGFX_CAPS_TEXTURE_CUBE_ARRAY | BGFX_CAPS_TEXTURE_DIRECT_ACCESS | BGFX_CAPS_TEXTURE_READ_BACK | BGFX_CAPS_VERTEX_ATTRIB_HALF | BGFX_CAPS_VERTEX_ATTRIB_UINT10 | BGFX_CAPS_VERTEX_ID ) == (0 ^ BGFX_CAPS_ALPHA_TO_COVERAGE ^ BGFX_CAPS_BLEND_INDEPENDENT ^ BGFX_CAPS_COMPUTE ^ BGFX_CAPS_CONSERVATIVE_RASTER ^ BGFX_CAPS_DRAW_INDIRECT ^ BGFX_CAPS_FRAGMENT_DEPTH ^ BGFX_CAPS_FRAGMENT_ORDERING ^ BGFX_CAPS_GRAPHICS_DEBUGGER ^ BGFX_CAPS_HDR10 ^ BGFX_CAPS_HIDPI ^ BGFX_CAPS_INDEX32 ^ BGFX_CAPS_INSTANCING ^ BGFX_CAPS_OCCLUSION_QUERY ^ BGFX_CAPS_RENDERER_MULTITHREADED ^ BGFX_CAPS_SWAP_CHAIN ^ BGFX_CAPS_TEXTURE_2D_ARRAY ^ BGFX_CAPS_TEXTURE_3D ^ BGFX_CAPS_TEXTURE_BLIT ^ BGFX_CAPS_TEXTURE_CUBE_ARRAY ^ BGFX_CAPS_TEXTURE_DIRECT_ACCESS ^ BGFX_CAPS_TEXTURE_READ_BACK ^ BGFX_CAPS_VERTEX_ATTRIB_HALF ^ BGFX_CAPS_VERTEX_ATTRIB_UINT10 ^ BGFX_CAPS_VERTEX_ID ) ); #undef FLAGS_MASK_TEST namespace bgfx { struct CallbackC99 : public CallbackI { virtual ~CallbackC99() { } virtual void fatal(const char* _filePath, uint16_t _line, Fatal::Enum _code, const char* _str) override { m_interface->vtbl->fatal(m_interface, _filePath, _line, (bgfx_fatal_t)_code, _str); } virtual void traceVargs(const char* _filePath, uint16_t _line, const char* _format, va_list _argList) override { m_interface->vtbl->trace_vargs(m_interface, _filePath, _line, _format, _argList); } virtual void profilerBegin(const char* _name, uint32_t _abgr, const char* _filePath, uint16_t _line) override { m_interface->vtbl->profiler_begin(m_interface, _name, _abgr, _filePath, _line); } virtual void profilerBeginLiteral(const char* _name, uint32_t _abgr, const char* _filePath, uint16_t _line) override { m_interface->vtbl->profiler_begin_literal(m_interface, _name, _abgr, _filePath, _line); } virtual void profilerEnd() override { m_interface->vtbl->profiler_end(m_interface); } virtual uint32_t cacheReadSize(uint64_t _id) override { return m_interface->vtbl->cache_read_size(m_interface, _id); } virtual bool cacheRead(uint64_t _id, void* _data, uint32_t _size) override { return m_interface->vtbl->cache_read(m_interface, _id, _data, _size); } virtual void cacheWrite(uint64_t _id, const void* _data, uint32_t _size) override { m_interface->vtbl->cache_write(m_interface, _id, _data, _size); } virtual void screenShot(const char* _filePath, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _data, uint32_t _size, bool _yflip) override { m_interface->vtbl->screen_shot(m_interface, _filePath, _width, _height, _pitch, _data, _size, _yflip); } virtual void captureBegin(uint32_t _width, uint32_t _height, uint32_t _pitch, TextureFormat::Enum _format, bool _yflip) override { m_interface->vtbl->capture_begin(m_interface, _width, _height, _pitch, (bgfx_texture_format_t)_format, _yflip); } virtual void captureEnd() override { m_interface->vtbl->capture_end(m_interface); } virtual void captureFrame(const void* _data, uint32_t _size) override { m_interface->vtbl->capture_frame(m_interface, _data, _size); } bgfx_callback_interface_t* m_interface; }; class AllocatorC99 : public bx::AllocatorI { public: virtual ~AllocatorC99() { } virtual void* realloc(void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line) override { return m_interface->vtbl->realloc(m_interface, _ptr, _size, _align, _file, _line); } bgfx_allocator_interface_t* m_interface; }; } // namespace bgfx #include "bgfx.idl.inl"
; A296442: Initial digit of n-th Mersenne number. ; 3,7,3,1,2,8,1,5,8,5,2,1,2,8,1,9,5,2,1,2,9,6,9,6,1,2,1,1,6,1,1,2,1,6,7,2,1,1,1,1,7,3,3,1,2,8,3,1,2,8,1,8,3,3,2,1,9,3,2,3,1,1,2,4,1,2,4,2,2,1,1,1,3,1,1,1,1,3,5,1,1,5,5,2,1,2,1,3,5,2,3,1,3,6,1,2,1,6,2,7 seq $0,1348 ; Mersenne numbers: 2^p - 1, where p is prime. seq $0,4086 ; Read n backwards (referred to as R(n) in many sequences). mod $0,10
/** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ #include <aws/networkmanager/model/CoreNetworkEdge.h> #include <aws/core/utils/json/JsonSerializer.h> #include <utility> using namespace Aws::Utils::Json; using namespace Aws::Utils; namespace Aws { namespace NetworkManager { namespace Model { CoreNetworkEdge::CoreNetworkEdge() : m_edgeLocationHasBeenSet(false), m_asn(0), m_asnHasBeenSet(false), m_insideCidrBlocksHasBeenSet(false) { } CoreNetworkEdge::CoreNetworkEdge(JsonView jsonValue) : m_edgeLocationHasBeenSet(false), m_asn(0), m_asnHasBeenSet(false), m_insideCidrBlocksHasBeenSet(false) { *this = jsonValue; } CoreNetworkEdge& CoreNetworkEdge::operator =(JsonView jsonValue) { if(jsonValue.ValueExists("EdgeLocation")) { m_edgeLocation = jsonValue.GetString("EdgeLocation"); m_edgeLocationHasBeenSet = true; } if(jsonValue.ValueExists("Asn")) { m_asn = jsonValue.GetInt64("Asn"); m_asnHasBeenSet = true; } if(jsonValue.ValueExists("InsideCidrBlocks")) { Array<JsonView> insideCidrBlocksJsonList = jsonValue.GetArray("InsideCidrBlocks"); for(unsigned insideCidrBlocksIndex = 0; insideCidrBlocksIndex < insideCidrBlocksJsonList.GetLength(); ++insideCidrBlocksIndex) { m_insideCidrBlocks.push_back(insideCidrBlocksJsonList[insideCidrBlocksIndex].AsString()); } m_insideCidrBlocksHasBeenSet = true; } return *this; } JsonValue CoreNetworkEdge::Jsonize() const { JsonValue payload; if(m_edgeLocationHasBeenSet) { payload.WithString("EdgeLocation", m_edgeLocation); } if(m_asnHasBeenSet) { payload.WithInt64("Asn", m_asn); } if(m_insideCidrBlocksHasBeenSet) { Array<JsonValue> insideCidrBlocksJsonList(m_insideCidrBlocks.size()); for(unsigned insideCidrBlocksIndex = 0; insideCidrBlocksIndex < insideCidrBlocksJsonList.GetLength(); ++insideCidrBlocksIndex) { insideCidrBlocksJsonList[insideCidrBlocksIndex].AsString(m_insideCidrBlocks[insideCidrBlocksIndex]); } payload.WithArray("InsideCidrBlocks", std::move(insideCidrBlocksJsonList)); } return payload; } } // namespace Model } // namespace NetworkManager } // namespace Aws
.size 8000 .text@48 jp lstatint .text@100 jp lbegin .data@143 c0 .text@150 lbegin: ld b, 98 call lwaitly_b ld a, 01 ldff(45), a ld a, 40 ldff(41), a ld a, 00 ld(8000), a ld a, 01 ld(c000), a ld a, c0 ldff(51), a xor a, a ldff(52), a ldff(54), a ld a, 80 ldff(53), a xor a, a ldff(0f), a ld a, 02 ldff(ff), a ei ld hl, 8000 ld a, 05 ldff(43), a halt .text@1000 lstatint: ld a, 80 ldff(55), a ld b, 07 .text@1032 xor a, a ldff(55), a .text@1068 ld a, (hl) and a, b jp lprint_a .text@7000 lprint_a: push af ld b, 91 call lwaitly_b xor a, a ldff(40), a pop af ld(9800), a ld bc, 7a00 ld hl, 8000 ld d, a0 lprint_copytiles: ld a, (bc) inc bc ld(hl++), a dec d jrnz lprint_copytiles ld a, c0 ldff(47), a ld a, 80 ldff(68), a ld a, ff ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a xor a, a ldff(69), a ldff(69), a ldff(43), a ld a, 91 ldff(40), a lprint_limbo: jr lprint_limbo .text@7400 lwaitly_b: ld c, 44 lwaitly_b_loop: ldff a, (c) cmp a, b jrnz lwaitly_b_loop ret .data@7a00 00 00 7f 7f 41 41 41 41 41 41 41 41 41 41 7f 7f 00 00 08 08 08 08 08 08 08 08 08 08 08 08 08 08 00 00 7f 7f 01 01 01 01 7f 7f 40 40 40 40 7f 7f 00 00 7f 7f 01 01 01 01 3f 3f 01 01 01 01 7f 7f 00 00 41 41 41 41 41 41 7f 7f 01 01 01 01 01 01 00 00 7f 7f 40 40 40 40 7e 7e 01 01 01 01 7e 7e 00 00 7f 7f 40 40 40 40 7f 7f 41 41 41 41 7f 7f 00 00 7f 7f 01 01 02 02 04 04 08 08 10 10 10 10 00 00 3e 3e 41 41 41 41 3e 3e 41 41 41 41 3e 3e 00 00 7f 7f 41 41 41 41 7f 7f 01 01 01 01 7f 7f
; A255177: Second differences of seventh powers (A001015). ; 1,126,1932,12138,47544,140070,341796,730002,1412208,2531214,4270140,6857466,10572072,15748278,22780884,32130210,44327136,59978142,79770348,104476554,134960280,172180806,217198212,271178418,335398224,411250350,500248476,604032282,724372488,863175894,1022490420,1204510146,1411580352,1646202558,1911039564,2208920490,2542845816,2915992422,3331718628,3793569234,4305280560,4870785486,5494218492,6179920698,6932444904,7756560630,8657259156,9639758562,10709508768,11872196574,13133750700,14500346826 mov $1,1 trn $1,$0 mov $2,14 mov $5,$0 mov $6,$0 lpb $2 add $1,$5 sub $2,1 lpe mov $3,$6 lpb $3 sub $3,1 add $4,$5 lpe mov $3,$6 mov $5,$4 mov $4,0 lpb $3 sub $3,1 add $4,$5 lpe mov $2,70 mov $5,$4 lpb $2 add $1,$5 sub $2,1 lpe mov $3,$6 mov $4,0 lpb $3 sub $3,1 add $4,$5 lpe mov $3,$6 mov $5,$4 mov $4,0 lpb $3 sub $3,1 add $4,$5 lpe mov $2,42 mov $5,$4 lpb $2 add $1,$5 sub $2,1 lpe mov $0,$1
@17 D=A @SP M=M+1 A=M-1 M=D @17 D=A @SP M=M+1 A=M-1 M=D @SP AM=M-1 D=M A=A-1 D=D-M M=-1 @LABEL0 D;JEQ @SP A=M-1 M=0 (LABEL0) @17 D=A @SP M=M+1 A=M-1 M=D @16 D=A @SP M=M+1 A=M-1 M=D @SP AM=M-1 D=M A=A-1 D=D-M M=-1 @LABEL1 D;JEQ @SP A=M-1 M=0 (LABEL1) @16 D=A @SP M=M+1 A=M-1 M=D @17 D=A @SP M=M+1 A=M-1 M=D @SP AM=M-1 D=M A=A-1 D=D-M M=-1 @LABEL2 D;JEQ @SP A=M-1 M=0 (LABEL2) @892 D=A @SP M=M+1 A=M-1 M=D @891 D=A @SP M=M+1 A=M-1 M=D @SP AM=M-1 D=M A=A-1 D=M-D M=-1 @LABEL3 D;JLT @SP A=M-1 M=0 (LABEL3) @891 D=A @SP M=M+1 A=M-1 M=D @892 D=A @SP M=M+1 A=M-1 M=D @SP AM=M-1 D=M A=A-1 D=M-D M=-1 @LABEL4 D;JLT @SP A=M-1 M=0 (LABEL4) @891 D=A @SP M=M+1 A=M-1 M=D @891 D=A @SP M=M+1 A=M-1 M=D @SP AM=M-1 D=M A=A-1 D=M-D M=-1 @LABEL5 D;JLT @SP A=M-1 M=0 (LABEL5) @32767 D=A @SP M=M+1 A=M-1 M=D @32766 D=A @SP M=M+1 A=M-1 M=D @SP AM=M-1 D=M A=A-1 D=M-D M=-1 @LABEL6 D;JGT @SP A=M-1 M=0 (LABEL6) @32766 D=A @SP M=M+1 A=M-1 M=D @32767 D=A @SP M=M+1 A=M-1 M=D @SP AM=M-1 D=M A=A-1 D=M-D M=-1 @LABEL7 D;JGT @SP A=M-1 M=0 (LABEL7) @32766 D=A @SP M=M+1 A=M-1 M=D @32766 D=A @SP M=M+1 A=M-1 M=D @SP AM=M-1 D=M A=A-1 D=M-D M=-1 @LABEL8 D;JGT @SP A=M-1 M=0 (LABEL8) @57 D=A @SP M=M+1 A=M-1 M=D @31 D=A @SP M=M+1 A=M-1 M=D @53 D=A @SP M=M+1 A=M-1 M=D @SP AM=M-1 D=M @SP A=M-1 M=M+D @112 D=A @SP M=M+1 A=M-1 M=D @SP AM=M-1 D=M @SP A=M-1 M=M-D @SP A=M-1 M=-M @SP AM=M-1 D=M @SP A=M-1 M=D&M @82 D=A @SP M=M+1 A=M-1 M=D @SP AM=M-1 D=M @SP A=M-1 M=D|M @SP A=M-1 M=!M
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1989 -- All Rights Reserved PROJECT: PC GEOS MODULE: The GrObj FILE: grobjUI.asm ROUTINES: Name Description ---- ----------- METHODS: Name: Description ---- ----------- REVISION HISTORY: Name Date Description ---- ---- ----------- jon 1 apr 1992 initial revision DESCRIPTION: $Id: grobjUI.asm,v 1.1 97/04/04 18:07:24 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjInitCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjSendUINotification %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Description: GrObj method for MSG_GO_SEND_UI_NOTIFICATION Called by: Pass: *ds:si = GrObj object ds:di = GrObj instance cx - GrObjUINotificationTypes Return: nothing Destroyed: ax Comments: WARNING: This method is not dynamic, so the passed parameters are more limited and you must be careful what you destroy. Revision History: Name Date Description ---- ------------ ----------- jon May 7, 1992 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjSendUINotification method GrObjClass, MSG_GO_SEND_UI_NOTIFICATION uses di .enter GrObjDeref di,ds,si test ds:[di].GOI_optFlags, mask GOOF_GROBJ_INVALID jnz done test ds:[di].GOI_tempState, mask GOTM_EDITED jnz send test ds:[di].GOI_tempState, mask GOTM_SELECTED jz done send: mov ax, MSG_GB_UPDATE_UI_CONTROLLERS mov di, mask MF_FIXUP_DS call GrObjMessageToBody EC < ERROR_Z GROBJ_CANT_SEND_MESSAGE_TO_BODY > done: .leave ret GrObjSendUINotification endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjOptSendUINotification %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Send ui notification for the object taking into account the GrObjMessageOptimizationFlags CALLED BY: INTERNAL UTILITY PASS: *ds:si - grobject cx - GrObjUINotificationTypes RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: This routine should be optimized for SMALL SIZE over SPEED Common cases: opt bit not set REVISION HISTORY: Name Date Description ---- ---- ----------- srs 8/27/92 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjOptSendUINotification proc far class GrObjClass .enter EC < call ECGrObjCheckLMemObject > GrObjDeref di,ds,si test ds:[di].GOI_msgOptFlags, mask GOMOF_SEND_UI_NOTIFICATION jnz send call GrObjSendUINotification done: .leave ret send: push ax mov ax,MSG_GO_SEND_UI_NOTIFICATION call ObjCallInstanceNoLock pop ax jmp done GrObjOptSendUINotification endp GrObjInitCode ends GrObjRequiredExtInteractive2Code segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjCombineGradientNotificationData %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Description: GrObj method for MSG_GO_COMBINE_GRADIENT_NOTIFICATION_DATA Called by: Pass: *ds:si = GrObj object ds:di = GrObj instance ^hcx = GrObjNotifyGradientChange struct Return: carry set if all relevant diff bits are set at the end of this routine Destroyed: ax Comments: Revision History: Name Date Description ---- ------------ ----------- jon Apr 1, 1992 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjCombineGradientNotificationData method dynamic GrObjClass, MSG_GO_COMBINE_GRADIENT_NOTIFICATION_DATA uses cx,dx,bp .enter mov bx, cx ;bx <- struc handle ; ; cx <- gradient attr token ; mov ax, MSG_GO_GET_GROBJ_AREA_TOKEN call ObjCallInstanceNoLock ; ; Get the attrs from the token ; sub sp, size GrObjFullAreaAttrElement mov bp, sp mov ax, MSG_GOAM_GET_FULL_AREA_ATTR_ELEMENT mov di, mask MF_FIXUP_DS or mask MF_CALL call GrObjMessageToGOAM jnc errorFreeFrame cmp ss:[bp].GOBAAE_aaeType, GOAAET_GRADIENT jne errorFreeFrame call MemLock jc errorFreeFrame mov es, ax ; ; If we're the first grobj to get this, then ; just fill the passed frame with our attrs... ; test es:[GONGAC_diffs], mask GGAD_FIRST_RECIPIENT jz notFirst ; ; copy attrs into passed block ; mov al, ss:[bp].GOGAAE_type mov es:[GONGAC_type], al mov al, ss:[bp].GOGAAE_endR mov es:[GONGAC_endR], al mov al, ss:[bp].GOGAAE_endG mov es:[GONGAC_endG], al mov al, ss:[bp].GOGAAE_endB mov es:[GONGAC_endB], al mov ax, ss:[bp].GOGAAE_numIntervals mov es:[GONGAC_numIntervals], ax clr es:[GONGAC_diffs] unlockBlock: call MemUnlock freeFrame: lahf add sp, size GrObjFullAreaAttrElement sahf .leave ret errorFreeFrame: clc jmp freeFrame notFirst: clr ax mov cl, es:[GONGAC_endR] cmp cl, ss:[bp].GOGAAE_endR jne multipleColors mov cl, es:[GONGAC_endG] cmp cl, ss:[bp].GOGAAE_endG jne multipleColors mov cl, es:[GONGAC_endB] cmp cl, ss:[bp].GOGAAE_endB je checkType multipleColors: BitSet ax, GGAD_MULTIPLE_END_COLORS checkType: mov cl, es:[GONGAC_type] cmp cl, ss:[bp].GOGAAE_type je checkIntervals BitSet ax, GGAD_MULTIPLE_TYPES checkIntervals: mov cx, es:[GONGAC_numIntervals] cmp cx, ss:[bp].GOGAAE_numIntervals je checkAllDiffs BitSet ax, GGAD_MULTIPLE_INTERVALS checkAllDiffs: ; ; See if all the diff bits are set; if so, return ; carry set (FIRST_RECIPIENT is guaranteed 0) ; or es:[GONGAC_diffs], al mov al, es:[GONGAC_diffs] andnf ax, mask GGAD_MULTIPLE_END_COLORS or mask GGAD_MULTIPLE_TYPES \ or mask GGAD_MULTIPLE_INTERVALS cmp ax, mask GGAD_MULTIPLE_END_COLORS or mask GGAD_MULTIPLE_TYPES \ or mask GGAD_MULTIPLE_INTERVALS stc jz unlockBlock clc jmp unlockBlock GrObjCombineGradientNotificationData endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjCombineAreaNotificationData %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Description: GrObj method for MSG_GO_COMBINE_AREA_NOTIFICATION_DATA Called by: Pass: *ds:si = GrObj object ds:di = GrObj instance ^hcx = GrObjNotifyAreaAttrChange struct Return: carry set if all relevant diff bits are set at the end of this routine Destroyed: ax Comments: Revision History: Name Date Description ---- ------------ ----------- jon Apr 1, 1992 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjCombineAreaNotificationData method dynamic GrObjClass, MSG_GO_COMBINE_AREA_NOTIFICATION_DATA uses cx,dx,bp .enter mov bx, cx ;bx <- struc handle ; ; cx <- area attr token ; mov ax, MSG_GO_GET_GROBJ_AREA_TOKEN call ObjCallInstanceNoLock ; ; Get the attrs from the token ; sub sp, size GrObjFullAreaAttrElement mov bp, sp mov ax, MSG_GOAM_GET_FULL_AREA_ATTR_ELEMENT mov di, mask MF_FIXUP_DS or mask MF_CALL call GrObjMessageToGOAM jnc freeFrame call MemLock jc errorFreeFrame mov es, ax ; ; If we're the first grobj to get this, then ; just fill the passed frame with our attrs... ; test es:GNAAC_areaAttrDiffs, mask GOBAAD_FIRST_RECIPIENT jz notFirst ; ; copy attrs into passed block ; push ds, si mov cx, size GrObjBaseAreaAttrElement/2 segmov ds, ss mov si, bp clr di ;clear carry CheckEvenSize GrObjBaseAreaAttrElement rep movsw mov es:GNAAC_areaAttrDiffs, cx ;clear diffs pop ds, si unlockBlock: call MemUnlock freeFrame: lahf add sp, size GrObjFullAreaAttrElement sahf .leave ret errorFreeFrame: clc jmp freeFrame notFirst: ; ; Set up the call to GrObjDiffBaseAreaAttrs ; mov dx, es segmov ds, ss clr di mov si, bp push bx mov bx, offset GNAAC_areaAttrDiffs call GrObjDiffBaseAreaAttrs pop bx jmp unlockBlock GrObjCombineAreaNotificationData endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjDiffBaseAreaAttrs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Description: Pass: ds:si - GrObjBaseAreaAttrElement #1 es:di - GrObjBaseAreaAttrElement #2 dx:bx - GrObjBaseAreaAttrDiffs Return: nothing Destroyed: nothing Comments: Revision History: Name Date Description ---- ------------ ----------- jon Apr 20, 1992 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjDiffBaseAreaAttrs proc far uses ax, cx .enter clr ax ;initial diffs mov cl, es:[di].GOBAAE_r cmp cl, ds:[si].GOBAAE_r jne multipleColors mov cl, es:[di].GOBAAE_g cmp cl, ds:[si].GOBAAE_g jne multipleColors mov cl, es:[di].GOBAAE_b cmp cl, ds:[si].GOBAAE_b je checkBackground multipleColors: BitSet ax, GOBAAD_MULTIPLE_COLORS checkBackground: mov cl, es:[di].GOBAAE_backR cmp cl, ds:[si].GOBAAE_backR jne multipleBGColors mov cl, es:[di].GOBAAE_backG cmp cl, ds:[si].GOBAAE_backG jne multipleBGColors mov cl, es:[di].GOBAAE_backB cmp cl, ds:[si].GOBAAE_backB je checkMask multipleBGColors: BitSet ax, GOBAAD_MULTIPLE_BACKGROUND_COLORS checkMask: mov cl, es:[di].GOBAAE_mask cmp cl, ds:[si].GOBAAE_mask je checkElementType BitSet ax, GOBAAD_MULTIPLE_MASKS checkElementType: mov cl, es:[di].GOBAAE_aaeType cmp cl, ds:[si].GOBAAE_aaeType je checkGradientStuff BitSet ax, GOBAAD_MULTIPLE_ELEMENT_TYPES ; ; If either type is GOAAET_GRADIENT, then we have to set all the ; GOBAAD_MULTIPLE_GRADIENT_* bits ; cmp cl, GOAAET_GRADIENT je setGradientDiffs cmp ds:[si].GOBAAE_aaeType, GOAAET_GRADIENT jne checkDrawMode setGradientDiffs: ornf ax, mask GOBAAD_MULTIPLE_GRADIENT_END_COLORS or \ mask GOBAAD_MULTIPLE_GRADIENT_TYPES or \ mask GOBAAD_MULTIPLE_GRADIENT_INTERVALS jmp checkDrawMode checkGradientStuff: cmp cl, GOAAET_GRADIENT jne checkDrawMode ; ; They're both gradients, so diff their gradient stuff ; mov cl, es:[di].GOGAAE_endR cmp cl, ds:[si].GOGAAE_endR jne multipleGradientColors mov cl, es:[di].GOGAAE_endG cmp cl, ds:[si].GOGAAE_endG jne multipleGradientColors mov cl, es:[di].GOGAAE_endB cmp cl, ds:[si].GOGAAE_endB je checkGradientType multipleGradientColors: BitSet ax, GOBAAD_MULTIPLE_GRADIENT_END_COLORS checkGradientType: mov cl, es:[di].GOGAAE_type cmp cl, ds:[si].GOGAAE_type je checkGradientIntervals BitSet ax, GOBAAD_MULTIPLE_GRADIENT_TYPES checkGradientIntervals: mov cx, es:[di].GOGAAE_numIntervals cmp cx, ds:[si].GOGAAE_numIntervals je checkDrawMode BitSet ax, GOBAAD_MULTIPLE_GRADIENT_INTERVALS checkDrawMode: mov cl, es:[di].GOBAAE_drawMode cmp cl, ds:[si].GOBAAE_drawMode je checkPattern BitSet ax, GOBAAD_MULTIPLE_DRAW_MODES checkPattern: mov cx, {word}es:[di].GOBAAE_pattern cmp cx, {word}ds:[si].GOBAAE_pattern je checkInfo BitSet ax, GOBAAD_MULTIPLE_PATTERNS checkInfo: mov cl, es:[di].GOBAAE_areaInfo cmp cl, ds:[si].GOBAAE_areaInfo je checkAllDiffs BitSet ax, GOBAAD_MULTIPLE_INFOS checkAllDiffs: ; ; See if all the diff bits are set; if so, return ; carry set (FIRST_RECIPIENT is guaranteed 0) ; push ds ;save ds mov ds, dx ;ds <- diffs or ds:[bx], ax mov ax, ds:[bx] pop ds ;restore ds ; ; We don't care about the gradient stuff, really, since it's only ; relevant when describing styles, not when updating ; andnf ax, mask GOBAAD_MULTIPLE_COLORS \ or mask GOBAAD_MULTIPLE_MASKS \ or mask GOBAAD_MULTIPLE_INFOS \ or mask GOBAAD_MULTIPLE_PATTERNS \ or mask GOBAAD_MULTIPLE_BACKGROUND_COLORS \ or mask GOBAAD_MULTIPLE_DRAW_MODES \ or mask GOBAAD_MULTIPLE_ELEMENT_TYPES cmp ax, mask GOBAAD_MULTIPLE_COLORS \ or mask GOBAAD_MULTIPLE_MASKS \ or mask GOBAAD_MULTIPLE_INFOS \ or mask GOBAAD_MULTIPLE_PATTERNS \ or mask GOBAAD_MULTIPLE_BACKGROUND_COLORS \ or mask GOBAAD_MULTIPLE_DRAW_MODES \ or mask GOBAAD_MULTIPLE_ELEMENT_TYPES stc jz done clc done: .leave ret GrObjDiffBaseAreaAttrs endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjCombineLineNotificationData %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Description: GrObj method for MSG_GO_COMBINE_LINE_NOTIFICATION_DATA Called by: Pass: *ds:si = GrObj object ds:di = GrObj instance ^hcx = GrObjNotifyLineAttrChange struct Return: carry set if all relevant diff bits are set at the end of this routine Destroyed: bx Comments: Revision History: Name Date Description ---- ------------ ----------- jon Apr 1, 1992 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjCombineLineNotificationData method dynamic GrObjClass, MSG_GO_COMBINE_LINE_NOTIFICATION_DATA uses ax,cx,bp .enter mov bx, cx ;bx <- struc handle ; ; cx <- Line attr token ; mov ax, MSG_GO_GET_GROBJ_LINE_TOKEN call ObjCallInstanceNoLock ; ; Get the attrs from the token ; sub sp, size GrObjFullLineAttrElement mov bp, sp mov ax, MSG_GOAM_GET_FULL_LINE_ATTR_ELEMENT mov di, mask MF_FIXUP_DS or mask MF_CALL call GrObjMessageToGOAM jnc errorFreeFrame call MemLock jc errorFreeFrame mov es, ax ; ; If we're the first grobj to get this, then ; just fill the passed frame with our attrs... ; test es:GNLAC_lineAttrDiffs, mask GOBLAD_FIRST_RECIPIENT jz notFirst ; ; copy attrs into passed block ; push ds, si mov cx, size GrObjBaseLineAttrElement/2 segmov ds, ss mov si, bp clr di ;clear carry CheckEvenSize GrObjBaseLineAttrElement rep movsw mov es:GNLAC_lineAttrDiffs, cx ;clear diffs pop ds, si unlockBlock: call MemUnlock freeFrame: lahf add sp, size GrObjFullLineAttrElement sahf .leave ret errorFreeFrame: clc jmp freeFrame notFirst: ; ; Set up the call to GrObjDiffBaseLineAttrs ; mov dx, es segmov ds, ss clr di mov si, bp push bx mov bx, offset GNLAC_lineAttrDiffs call GrObjDiffBaseLineAttrs pop bx jmp unlockBlock GrObjCombineLineNotificationData endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjDiffBaseLineAttrs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Description: Pass: ds:si - GrObjFullLineAttrElement #1 es:di - GrObjFullLineAttrElement #2 dx:bx - GrObjLineAttrDiffs Return: nothing Destroyed: nothing Comments: Revision History: Name Date Description ---- ------------ ----------- jon Apr 20, 1992 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjDiffBaseLineAttrs proc far uses ax, cx .enter clr ax ;initial diffs mov cl, es:[di].GOBLAE_r cmp cl, ds:[si].GOBLAE_r jne multipleColors mov cl, es:[di].GOBLAE_g cmp cl, ds:[si].GOBLAE_g jne multipleColors mov cl, es:[di].GOBLAE_b cmp cl, ds:[si].GOBLAE_b je checkMask multipleColors: BitSet ax, GOBLAD_MULTIPLE_COLORS checkMask: mov cl, es:[di].GOBLAE_mask cmp cl, ds:[si].GOBLAE_mask je checkArowheadAngle BitSet ax, GOBLAD_MULTIPLE_MASKS checkArowheadAngle: mov cl, es:[di].GOBLAE_arrowheadAngle cmp cl, ds:[si].GOBLAE_arrowheadAngle je checkArowheadLength BitSet ax, GOBLAD_MULTIPLE_ARROWHEAD_ANGLES checkArowheadLength: mov cl, es:[di].GOBLAE_arrowheadLength cmp cl, ds:[si].GOBLAE_arrowheadLength je checkArowheadOnStart BitSet ax, GOBLAD_MULTIPLE_ARROWHEAD_LENGTHS checkArowheadOnStart: mov cl, es:[di].GOBLAE_lineInfo xor cl, ds:[si].GOBLAE_lineInfo test cl, mask GOLAIR_ARROWHEAD_ON_START jz checkArowheadOnEnd BitSet ax, GOBLAD_ARROWHEAD_ON_START checkArowheadOnEnd: mov cl, es:[di].GOBLAE_lineInfo xor cl, ds:[si].GOBLAE_lineInfo test cl, mask GOLAIR_ARROWHEAD_ON_END jz checkArrowheadFilled BitSet ax, GOBLAD_ARROWHEAD_ON_END checkArrowheadFilled: mov cl, es:[di].GOBLAE_lineInfo xor cl, ds:[si].GOBLAE_lineInfo test cl, mask GOLAIR_ARROWHEAD_FILLED jz checkArrowheadFillType BitSet ax, GOBLAD_ARROWHEAD_FILLED checkArrowheadFillType: test cl, mask GOLAIR_ARROWHEAD_FILL_WITH_AREA_ATTRIBUTES jz checkElementType BitSet ax, GOBLAD_ARROWHEAD_FILL_WITH_AREA_ATTRIBUTES checkElementType: mov cl, es:[di].GOBLAE_laeType cmp cl, ds:[si].GOBLAE_laeType je checkWidth BitSet ax, GOBLAD_MULTIPLE_ELEMENT_TYPES checkWidth: mov cx, es:[di].GOBLAE_width.WWF_int cmp cx, ds:[si].GOBLAE_width.WWF_int jne multipleWidths mov cx, es:[di].GOBLAE_width.WWF_frac cmp cx, ds:[si].GOBLAE_width.WWF_frac je checkStyle multipleWidths: BitSet ax, GOBLAD_MULTIPLE_WIDTHS checkStyle: mov cl, es:[di].GOBLAE_style cmp cl, ds:[si].GOBLAE_style je checkAllDiffs BitSet ax, GOBLAD_MULTIPLE_STYLES checkAllDiffs: ; ; See if all the diff bits are set; if so, return ; carry set (FIRST_RECIPIENT is guaranteed 0) ; push ds ;save ds mov ds, dx ;ds <- diffs or ds:[bx], ax mov ax, ds:[bx] pop ds ;restore ds andnf ax, mask GOBLAD_MULTIPLE_COLORS or \ mask GOBLAD_MULTIPLE_MASKS or \ mask GOBLAD_MULTIPLE_WIDTHS or \ mask GOBLAD_MULTIPLE_STYLES or \ mask GOBLAD_MULTIPLE_ELEMENT_TYPES or \ mask GOBLAD_MULTIPLE_ARROWHEAD_ANGLES or \ mask GOBLAD_MULTIPLE_ARROWHEAD_LENGTHS or \ mask GOBLAD_ARROWHEAD_ON_START or \ mask GOBLAD_ARROWHEAD_ON_END or \ mask GOBLAD_ARROWHEAD_FILLED cmp ax, mask GOBLAD_MULTIPLE_COLORS or \ mask GOBLAD_MULTIPLE_MASKS or \ mask GOBLAD_MULTIPLE_WIDTHS or \ mask GOBLAD_MULTIPLE_STYLES or \ mask GOBLAD_MULTIPLE_ELEMENT_TYPES or \ mask GOBLAD_MULTIPLE_ARROWHEAD_ANGLES or \ mask GOBLAD_MULTIPLE_ARROWHEAD_LENGTHS or \ mask GOBLAD_ARROWHEAD_ON_START or \ mask GOBLAD_ARROWHEAD_ON_END or \ mask GOBLAD_ARROWHEAD_FILLED stc jz done clc done: .leave ret GrObjDiffBaseLineAttrs endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjCombineSelectionStateNotificationData %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Description: GrObj method for MSG_GO_COMBINE_SELECTION_STATE_NOTIFICATION_DATA Called by: Pass: *ds:si = GrObj object ds:di = GrObj instance ^hcx = GrObjNotifySelectionStateChange struct Return: carry clear to continue processing. Destroyed: ax Comments: Revision History: Name Date Description ---- ------------ ----------- jon Apr 1, 1992 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjCombineSelectionStateNotificationData method dynamic GrObjClass, MSG_GO_COMBINE_SELECTION_STATE_NOTIFICATION_DATA uses bp .enter mov bx, cx call MemLock jc clcDone GrObjDeref di,ds,si mov es, ax tst es:[GONSSC_selectionState].GSS_numSelected mov bp, ds:[si] jz imFirst ; ; Do the grobj flags diff ; mov ax, ds:[di].GOI_attrFlags xor ax, es:[GONSSC_selectionState].GSS_grObjFlags or es:[GONSSC_grObjFlagsDiffs], ax ; ; Compare the locks to the existing ones ; mov ax, ds:[di].GOI_locks xor ax, es:[GONSSC_selectionState].GSS_locks or es:[GONSSC_locksDiffs], ax ; ; Check class of this object vs. class in notif. block ; mov ax, es:[GONSSC_selectionState].GSS_classSelected.offset cmp ax, ds:[bp].offset jne multipleClasses mov ax, es:[GONSSC_selectionState].GSS_classSelected.segment cmp ax, ds:[bp].segment je unlock multipleClasses: BitSet es:[GONSSC_selectionStateDiffs], GSSD_MULTIPLE_CLASSES unlock: call MemUnlock clcDone: clc ;this thing'll probably never ;abort with all the various diff ;bits, so I don't bother to check .leave ret imFirst: movdw es:[GONSSC_selectionState].GSS_classSelected, ds:[bp], ax mov ax, ds:[di].GOI_locks mov es:[GONSSC_selectionState].GSS_locks, ax mov ax, ds:[di].GOI_attrFlags mov es:[GONSSC_selectionState].GSS_grObjFlags, ax clr ax mov es:[GONSSC_selectionStateDiffs], al mov es:[GONSSC_grObjFlagsDiffs], ax mov es:[GONSSC_locksDiffs], ax ; ; Get the number of selected grobjs ; ; We do it this way (calling the body) instead of ; incrementing the counter each time so that we ; can abort the combine event if multiple classes are ; selected. ; mov ax, MSG_GB_GET_NUM_SELECTED_GROBJS mov di, mask MF_CALL call GrObjMessageToBody EC < ERROR_Z GROBJ_CANT_SEND_MESSAGE_TO_BODY > mov es:[GONSSC_selectionState].GSS_numSelected, bp jmp unlock GrObjCombineSelectionStateNotificationData endm COMMENT @---------------------------------------------------------------------- FUNCTION: GenStyleNotify DESCRIPTION: Generate a notificiation structure CALLED BY: TA_SendNotification PASS: *ds:si - instance data ^hcx - NotifyStyleChange struct RETURN: DESTROYED: ax, bx, cx, dx, si, di, bp, ds, es REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- Tony 12/ 6/91 Initial version ------------------------------------------------------------------------------@ GrObjCombineStyleNotificationData method dynamic GrObjClass, MSG_GO_COMBINE_STYLE_NOTIFICATION_DATA areaAttr local GrObjFullAreaAttrElement lineAttr local GrObjFullLineAttrElement localSCD local StyleChunkDesc .enter ; ; Lock the notification block ; mov bx, cx call MemLock LONG jc done mov es, ax ;es <- notif block push cx ;save block handle ;for later unlocking ; ; areaAttr <- attrs from element token ; push bp ;save local ptr lea bp, areaAttr mov cx, ds:[di].GOI_areaAttrToken mov dx, ds:[di].GOI_lineAttrToken mov ax, MSG_GOAM_GET_FULL_AREA_ATTR_ELEMENT mov di, mask MF_FIXUP_DS or mask MF_CALL call GrObjMessageToGOAM cmp es:[NSC_styleToken], CA_NULL_ELEMENT je imFirst pop bp ;ss:bp <- locals ; ; See if this grobj's attrs match the first grobj's ; cmp cx, es:NSC_attrTokens[0 * (size word)] jne different cmp dx, es:NSC_attrTokens[1 * (size word)] je unlock ;carry clear to cont. different: ; ; OK, we found a different style; we need to mark this update ; as indeterminate, and prohibit redefines ; mov es:[NSC_indeterminate], 0xff clr es:[NSC_canRedefine] ; ; If canReturnToBase style is already set, then there's nothing ; we (or any other grobj) can add to the update. ; tst es:[NSC_canReturnToBase] stc ;carry set to halt jnz unlock ; ; If this grobj can return to it's base style, we want to set ; that flag ; call GrObjTestCanReturnToBaseStyle or al, ah mov es:[NSC_canReturnToBase], al ; ; If we can't return to base, then we have to keep processing ; jz unlock stc unlock: pop bx call MemUnlock done: .leave ret imFirst: ; ; Store our area attribute token away ; mov es:NSC_attrTokens[0], cx ; ; generate checksum for area attrs ; push ds, si ;save grobj ptr segmov ds, ss ;ds:si <- areaAttr mov si, bp mov cx, size GrObjFullAreaAttrElement call StyleSheetGenerateChecksum ;dxax <- checksum pop ds, si ;*ds:si <- grobj pop bp ;bp <- local ptr movdw <es:NSC_attrChecksums[0*(size dword)]>, dxax ; ; localSCD <- StyleChunkDesc ; push bp ;save local ptr lea bp, localSCD call GetSCD mov bx, bp ;ss:bx <- localSCD pop bp ;bp <- local ptr mov ax, areaAttr.GOFAAE_base.GOBAAE_styleElement.SSEH_style mov es:[NSC_styleToken], ax ; ; ax <- element size ; bx <- used index ; cx <- used tool index ; dx <- number of styles ; mov di, offset NSC_style ;es:di <- buffer call StyleSheetGetStyle mov es:[NSC_styleSize], ax mov es:[NSC_usedIndex], bx mov es:[NSC_usedToolIndex], cx GrObjDeref di,ds,si mov cx, ds:[di].GOI_lineAttrToken mov es:NSC_attrTokens[1 * (size word)], cx ; ; lineAttr <- attrs from element token ; push bp ;save local ptr lea bp, lineAttr mov ax, MSG_GOAM_GET_FULL_LINE_ATTR_ELEMENT mov di, mask MF_FIXUP_DS or mask MF_CALL call GrObjMessageToGOAM ; ; generate checksum for line attrs ; push ds, si ;save grobj ptr segmov ds, ss ;ds:si <- areaAttr mov si, bp mov cx, size GrObjFullLineAttrElement call StyleSheetGenerateChecksum ;dxax <- checksum pop ds, si ;*ds:si <- grobj pop bp ;bp <- local ptr movdw <es:NSC_attrChecksums[1*(size dword)]>, dxax call StyleSheetGetNotifyCounter mov es:[NSC_styleCounter], ax ; ; We're first, so no indeterminacy ; clr es:[NSC_indeterminate] ; ; If our style isn't its own base style, then we can redefine ; the style, and return to the base style ; call GrObjTestCanReturnToBaseStyle or al, ah mov es:[NSC_canRedefine], al mov es:[NSC_canReturnToBase], al clc ;keep goin' jmp unlock GrObjCombineStyleNotificationData endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjTestCanReturnToBaseStyle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Description: Tests whether a style is it's own base style Pass: *ds:si - grobj ss:[bp] - GrObjBaseAreaAttrElement (I think a GrObjLineAreaAttrElement might work, too) Return: ax - nonzero if style can return to base Destroyed: nothing Comments: Revision History: Name Date Description ---- ------------ ----------- jon Dec 30, 1992 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjTestCanReturnToBaseStyle proc near class GrObjClass uses cx, dx, di .enter inherit GrObjCombineStyleNotificationData ; ; Suck out the style element ; mov cx, ss:[areaAttr].GOFAAE_base.GOBAAE_styleElement.SSEH_style ; ; Get the area and line elements for the style ; mov ax, MSG_GOAM_GET_AREA_AND_LINE_TOKENS_FROM_STYLE mov di, mask MF_FIXUP_DS or mask MF_CALL call GrObjMessageToGOAM ; ; Compare 'em to our tokens ; GrObjDeref di, ds, si sub ax, ds:[di].GOI_areaAttrToken sub dx, ds:[di].GOI_lineAttrToken or ax, dx .leave ret GrObjTestCanReturnToBaseStyle endp COMMENT @---------------------------------------------------------------------- FUNCTION: GrObjGetStyleArray DESCRIPTION: Load a StyleChunkDesc with a pointer to the style sheet info CALLED BY: INTERNAL PASS: *ds:si - goam ss:bp - StyleChunkDesc to fill RETURN: carry - set if styles exist ss:bp - filled DESTROYED: none REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- Tony 12/27/91 Initial version ------------------------------------------------------------------------------@ GetSCD proc near uses ax, bx, cx, di class GrObjClass .enter mov ss:[bp].SCD_chunk, 0 mov ax, MSG_GOAM_GET_STYLE_ARRAY mov di, mask MF_FIXUP_DS or mask MF_CALL call GrObjMessageToGOAM jnc done call GrObjGlobalGetVMFile ; cx = chunk, bx = file mov ss:[bp].SCD_vmFile, bx mov ss:[bp].SCD_vmBlockOrMemHandle, cx mov ss:[bp].SCD_chunk, VM_ELEMENT_ARRAY_CHUNK stc done: .leave ret GetSCD endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjCombineSelectionStateNotificationData %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Description: GrObj method for MSG_GO_COMBINE_SELECTION_STATE_NOTIFICATION_DATA Called by: Pass: *ds:si = GrObj object ds:di = GrObj instance ^hcx = NotifyStyleSheetChange struct Return: carry set if relevant diff bit(s) are all set Destroyed: nothing Comments: Revision History: Name Date Description ---- ------------ ----------- jon Apr 1, 1992 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjCombineStyleSheetNotificationData method dynamic GrObjClass, MSG_GO_COMBINE_STYLE_SHEET_NOTIFICATION_DATA uses ax, bp .enter sub sp, size StyleChunkDesc mov bp, sp call GetSCD mov bx, cx call MemLock jc adjustSpDone mov es, ax mov ax, ss:[bp].SCD_vmFile mov es:[NSSHC_styleArray].SCD_vmFile, ax mov ax, ss:[bp].SCD_chunk mov es:[NSSHC_styleArray].SCD_chunk, ax mov ax, ss:[bp].SCD_vmBlockOrMemHandle mov es:[NSSHC_styleArray].SCD_vmBlockOrMemHandle, ax call StyleSheetGetNotifyCounter mov es:[NSSHC_counter], ax push bx mov bx, bp call StyleSheetGetStyleCounts mov es:[NSSHC_styleCount], ax mov es:[NSSHC_toolStyleCount], bx pop bx call MemUnlock adjustSpDone: add sp, size StyleChunkDesc stc .leave ret GrObjCombineStyleSheetNotificationData endm GrObjRequiredExtInteractive2Code ends
/* * nghttp2 - HTTP/2 C Library * * Copyright (c) 2012 Tatsuhiro Tsujikawa * * 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 "util.h" #ifdef HAVE_TIME_H #include <time.h> #endif // HAVE_TIME_H #include <sys/types.h> #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif // HAVE_SYS_SOCKET_H #ifdef HAVE_NETDB_H #include <netdb.h> #endif // HAVE_NETDB_H #include <sys/stat.h> #ifdef HAVE_FCNTL_H #include <fcntl.h> #endif // HAVE_FCNTL_H #ifdef HAVE_NETINET_IN_H #include <netinet/in.h> #endif // HAVE_NETINET_IN_H #ifdef _WIN32 #include <ws2tcpip.h> #include <boost/date_time/posix_time/posix_time.hpp> #else // !_WIN32 #include <netinet/tcp.h> #endif // !_WIN32 #ifdef HAVE_ARPA_INET_H #include <arpa/inet.h> #endif // HAVE_ARPA_INET_H #include <cmath> #include <cerrno> #include <cassert> #include <cstdio> #include <cstring> #include <iostream> #include <fstream> #include <openssl/evp.h> #include <nghttp2/nghttp2.h> #include "ssl_compat.h" #include "timegm.h" namespace nghttp2 { namespace util { #ifndef _WIN32 namespace { int nghttp2_inet_pton(int af, const char *src, void *dst) { return inet_pton(af, src, dst); } } // namespace #else // _WIN32 namespace { // inet_pton-wrapper for Windows int nghttp2_inet_pton(int af, const char *src, void *dst) { #if _WIN32_WINNT >= 0x0600 return InetPtonA(af, src, dst); #else // the function takes a 'char*', so we need to make a copy char addr[INET6_ADDRSTRLEN + 1]; strncpy(addr, src, sizeof(addr)); addr[sizeof(addr) - 1] = 0; int size = sizeof(struct in6_addr); if (WSAStringToAddress(addr, af, NULL, (LPSOCKADDR)dst, &size) == 0) return 1; return 0; #endif } } // namespace #endif // _WIN32 const char UPPER_XDIGITS[] = "0123456789ABCDEF"; bool in_rfc3986_unreserved_chars(const char c) { static constexpr char unreserved[] = {'-', '.', '_', '~'}; return is_alpha(c) || is_digit(c) || std::find(std::begin(unreserved), std::end(unreserved), c) != std::end(unreserved); } bool in_rfc3986_sub_delims(const char c) { static constexpr char sub_delims[] = {'!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '='}; return std::find(std::begin(sub_delims), std::end(sub_delims), c) != std::end(sub_delims); } std::string percent_encode(const unsigned char *target, size_t len) { std::string dest; for (size_t i = 0; i < len; ++i) { unsigned char c = target[i]; if (in_rfc3986_unreserved_chars(c)) { dest += c; } else { dest += '%'; dest += UPPER_XDIGITS[c >> 4]; dest += UPPER_XDIGITS[(c & 0x0f)]; } } return dest; } std::string percent_encode(const std::string &target) { return percent_encode(reinterpret_cast<const unsigned char *>(target.c_str()), target.size()); } std::string percent_encode_path(const std::string &s) { std::string dest; for (auto c : s) { if (in_rfc3986_unreserved_chars(c) || in_rfc3986_sub_delims(c) || c == '/') { dest += c; continue; } dest += '%'; dest += UPPER_XDIGITS[(c >> 4) & 0x0f]; dest += UPPER_XDIGITS[(c & 0x0f)]; } return dest; } bool in_token(char c) { static constexpr char extra[] = {'!', '#', '$', '%', '&', '\'', '*', '+', '-', '.', '^', '_', '`', '|', '~'}; return is_alpha(c) || is_digit(c) || std::find(std::begin(extra), std::end(extra), c) != std::end(extra); } bool in_attr_char(char c) { static constexpr char bad[] = {'*', '\'', '%'}; return util::in_token(c) && std::find(std::begin(bad), std::end(bad), c) == std::end(bad); } StringRef percent_encode_token(BlockAllocator &balloc, const StringRef &target) { auto iov = make_byte_ref(balloc, target.size() * 3 + 1); auto p = iov.base; for (auto first = std::begin(target); first != std::end(target); ++first) { uint8_t c = *first; if (c != '%' && in_token(c)) { *p++ = c; continue; } *p++ = '%'; *p++ = UPPER_XDIGITS[c >> 4]; *p++ = UPPER_XDIGITS[(c & 0x0f)]; } *p = '\0'; return StringRef{iov.base, p}; } uint32_t hex_to_uint(char c) { if (c <= '9') { return c - '0'; } if (c <= 'Z') { return c - 'A' + 10; } if (c <= 'z') { return c - 'a' + 10; } return 256; } StringRef quote_string(BlockAllocator &balloc, const StringRef &target) { auto cnt = std::count(std::begin(target), std::end(target), '"'); if (cnt == 0) { return make_string_ref(balloc, target); } auto iov = make_byte_ref(balloc, target.size() + cnt + 1); auto p = iov.base; for (auto c : target) { if (c == '"') { *p++ = '\\'; *p++ = '"'; } else { *p++ = c; } } *p = '\0'; return StringRef{iov.base, p}; } namespace { template <typename Iterator> Iterator cpydig(Iterator d, uint32_t n, size_t len) { auto p = d + len - 1; do { *p-- = (n % 10) + '0'; n /= 10; } while (p >= d); return d + len; } } // namespace namespace { constexpr const char *MONTH[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; constexpr const char *DAY_OF_WEEK[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; } // namespace std::string http_date(time_t t) { /* Sat, 27 Sep 2014 06:31:15 GMT */ std::string res(29, 0); http_date(&res[0], t); return res; } char *http_date(char *res, time_t t) { struct tm tms; #ifdef _WIN32 if (gmtime_s( &tms,&t) !=0) { return res; } #else if (gmtime_r(&t, &tms) == nullptr) { return res; } #endif auto p = res; auto s = DAY_OF_WEEK[tms.tm_wday]; p = std::copy_n(s, 3, p); *p++ = ','; *p++ = ' '; p = cpydig(p, tms.tm_mday, 2); *p++ = ' '; s = MONTH[tms.tm_mon]; p = std::copy_n(s, 3, p); *p++ = ' '; p = cpydig(p, tms.tm_year + 1900, 4); *p++ = ' '; p = cpydig(p, tms.tm_hour, 2); *p++ = ':'; p = cpydig(p, tms.tm_min, 2); *p++ = ':'; p = cpydig(p, tms.tm_sec, 2); s = " GMT"; p = std::copy_n(s, 4, p); return p; } std::string common_log_date(time_t t) { // 03/Jul/2014:00:19:38 +0900 std::string res(26, 0); common_log_date(&res[0], t); return res; } char *common_log_date(char *res, time_t t) { struct tm tms; #ifdef _WIN32 if (localtime_s(&tms, &t) != 0) { return res; } #else if (localtime_r(&t, &tms) == nullptr) { return res; } #endif auto p = res; p = cpydig(p, tms.tm_mday, 2); *p++ = '/'; auto s = MONTH[tms.tm_mon]; p = std::copy_n(s, 3, p); *p++ = '/'; p = cpydig(p, tms.tm_year + 1900, 4); *p++ = ':'; p = cpydig(p, tms.tm_hour, 2); *p++ = ':'; p = cpydig(p, tms.tm_min, 2); *p++ = ':'; p = cpydig(p, tms.tm_sec, 2); *p++ = ' '; #ifdef HAVE_STRUCT_TM_TM_GMTOFF auto gmtoff = tms.tm_gmtoff; #else // !HAVE_STRUCT_TM_TM_GMTOFF auto gmtoff = nghttp2_timegm(&tms) - t; #endif // !HAVE_STRUCT_TM_TM_GMTOFF if (gmtoff >= 0) { *p++ = '+'; } else { *p++ = '-'; gmtoff = -gmtoff; } p = cpydig(p, gmtoff / 3600, 2); p = cpydig(p, (gmtoff % 3600) / 60, 2); return p; } std::string iso8601_date(int64_t ms) { // 2014-11-15T12:58:24.741Z // 2014-11-15T12:58:24.741+09:00 std::string res(29, 0); auto p = iso8601_date(&res[0], ms); res.resize(p - &res[0]); return res; } char *iso8601_date(char *res, int64_t ms) { time_t sec = ms / 1000; tm tms; #ifdef _WIN32 if (localtime_s(&tms, &sec) != 0) { return res; } #else if (localtime_r(&sec, &tms) == nullptr) { return res; } #endif auto p = res; p = cpydig(p, tms.tm_year + 1900, 4); *p++ = '-'; p = cpydig(p, tms.tm_mon + 1, 2); *p++ = '-'; p = cpydig(p, tms.tm_mday, 2); *p++ = 'T'; p = cpydig(p, tms.tm_hour, 2); *p++ = ':'; p = cpydig(p, tms.tm_min, 2); *p++ = ':'; p = cpydig(p, tms.tm_sec, 2); *p++ = '.'; p = cpydig(p, ms % 1000, 3); #ifdef HAVE_STRUCT_TM_TM_GMTOFF auto gmtoff = tms.tm_gmtoff; #else // !HAVE_STRUCT_TM_TM_GMTOFF auto gmtoff = nghttp2_timegm(&tms) - sec; #endif // !HAVE_STRUCT_TM_TM_GMTOFF if (gmtoff == 0) { *p++ = 'Z'; } else { if (gmtoff > 0) { *p++ = '+'; } else { *p++ = '-'; gmtoff = -gmtoff; } p = cpydig(p, gmtoff / 3600, 2); *p++ = ':'; p = cpydig(p, (gmtoff % 3600) / 60, 2); } return p; } #ifdef _WIN32 namespace bt = boost::posix_time; // one-time definition of the locale that is used to parse UTC strings // (note that the time_input_facet is ref-counted and deleted automatically) static const std::locale http_date_locale(std::locale::classic(), new bt::time_input_facet("%a, %d %b %Y %H:%M:%S GMT")); static const std::locale openssl_asn1_locale(std::locale::classic(), new bt::time_input_facet("%b %d %H:%M:%S %Y GMT")); #endif //_WIN32 time_t parse_http_date(const StringRef &s) { #ifdef _WIN32 // there is no strptime - use boost std::stringstream sstr(s.str()); sstr.imbue(http_date_locale); bt::ptime ltime; sstr >> ltime; if (!sstr) return 0; return boost::posix_time::to_time_t(ltime); #else // !_WIN32 tm tm{}; char *r = strptime(s.c_str(), "%a, %d %b %Y %H:%M:%S GMT", &tm); if (r == 0) { return 0; } return nghttp2_timegm_without_yday(&tm); #endif // !_WIN32 } time_t parse_openssl_asn1_time_print(const StringRef &s) { #ifdef _WIN32 // there is no strptime - use boost std::stringstream sstr(s.str()); sstr.imbue(openssl_asn1_locale); bt::ptime ltime; sstr >> ltime; if (!sstr) return 0; return boost::posix_time::to_time_t(ltime); #else // !_WIN32 tm tm{}; auto r = strptime(s.c_str(), "%b %d %H:%M:%S %Y GMT", &tm); if (r == nullptr) { return 0; } return nghttp2_timegm_without_yday(&tm); #endif // !_WIN32 } char upcase(char c) { if ('a' <= c && c <= 'z') { return c - 'a' + 'A'; } else { return c; } } std::string format_hex(const unsigned char *s, size_t len) { std::string res; res.resize(len * 2); for (size_t i = 0; i < len; ++i) { unsigned char c = s[i]; res[i * 2] = LOWER_XDIGITS[c >> 4]; res[i * 2 + 1] = LOWER_XDIGITS[c & 0x0f]; } return res; } StringRef format_hex(BlockAllocator &balloc, const StringRef &s) { auto iov = make_byte_ref(balloc, s.size() * 2 + 1); auto p = iov.base; for (auto cc : s) { uint8_t c = cc; *p++ = LOWER_XDIGITS[c >> 4]; *p++ = LOWER_XDIGITS[c & 0xf]; } *p = '\0'; return StringRef{iov.base, p}; } void to_token68(std::string &base64str) { std::transform(std::begin(base64str), std::end(base64str), std::begin(base64str), [](char c) { switch (c) { case '+': return '-'; case '/': return '_'; default: return c; } }); base64str.erase(std::find(std::begin(base64str), std::end(base64str), '='), std::end(base64str)); } StringRef to_base64(BlockAllocator &balloc, const StringRef &token68str) { // At most 3 padding '=' auto len = token68str.size() + 3; auto iov = make_byte_ref(balloc, len + 1); auto p = iov.base; p = std::transform(std::begin(token68str), std::end(token68str), p, [](char c) { switch (c) { case '-': return '+'; case '_': return '/'; default: return c; } }); auto rem = token68str.size() & 0x3; if (rem) { p = std::fill_n(p, 4 - rem, '='); } *p = '\0'; return StringRef{iov.base, p}; } namespace { // Calculates Damerau–Levenshtein distance between c-string a and b // with given costs. swapcost, subcost, addcost and delcost are cost // to swap 2 adjacent characters, substitute characters, add character // and delete character respectively. int levenshtein(const char *a, int alen, const char *b, int blen, int swapcost, int subcost, int addcost, int delcost) { auto dp = std::vector<std::vector<int>>(3, std::vector<int>(blen + 1)); for (int i = 0; i <= blen; ++i) { dp[1][i] = i; } for (int i = 1; i <= alen; ++i) { dp[0][0] = i; for (int j = 1; j <= blen; ++j) { dp[0][j] = dp[1][j - 1] + (a[i - 1] == b[j - 1] ? 0 : subcost); if (i >= 2 && j >= 2 && a[i - 1] != b[j - 1] && a[i - 2] == b[j - 1] && a[i - 1] == b[j - 2]) { dp[0][j] = std::min(dp[0][j], dp[2][j - 2] + swapcost); } dp[0][j] = std::min(dp[0][j], std::min(dp[1][j] + delcost, dp[0][j - 1] + addcost)); } std::rotate(std::begin(dp), std::begin(dp) + 2, std::end(dp)); } return dp[1][blen]; } } // namespace void show_candidates(const char *unkopt, const option *options) { for (; *unkopt == '-'; ++unkopt) ; if (*unkopt == '\0') { return; } auto unkoptend = unkopt; for (; *unkoptend && *unkoptend != '='; ++unkoptend) ; auto unkoptlen = unkoptend - unkopt; if (unkoptlen == 0) { return; } int prefix_match = 0; auto cands = std::vector<std::pair<int, const char *>>(); for (size_t i = 0; options[i].name != nullptr; ++i) { auto optnamelen = strlen(options[i].name); // Use cost 0 for prefix match if (istarts_with(options[i].name, options[i].name + optnamelen, unkopt, unkopt + unkoptlen)) { if (optnamelen == static_cast<size_t>(unkoptlen)) { // Exact match, then we don't show any condidates. return; } ++prefix_match; cands.emplace_back(0, options[i].name); continue; } // Use cost 0 for suffix match, but match at least 3 characters if (unkoptlen >= 3 && iends_with(options[i].name, options[i].name + optnamelen, unkopt, unkopt + unkoptlen)) { cands.emplace_back(0, options[i].name); continue; } // cost values are borrowed from git, help.c. int sim = levenshtein(unkopt, unkoptlen, options[i].name, optnamelen, 0, 2, 1, 3); cands.emplace_back(sim, options[i].name); } if (prefix_match == 1 || cands.empty()) { return; } std::sort(std::begin(cands), std::end(cands)); int threshold = cands[0].first; // threshold value is a magic value. if (threshold > 6) { return; } std::cerr << "\nDid you mean:\n"; for (auto &item : cands) { if (item.first > threshold) { break; } std::cerr << "\t--" << item.second << "\n"; } } bool has_uri_field(const http_parser_url &u, http_parser_url_fields field) { return u.field_set & (1 << field); } bool fieldeq(const char *uri1, const http_parser_url &u1, const char *uri2, const http_parser_url &u2, http_parser_url_fields field) { if (!has_uri_field(u1, field)) { if (!has_uri_field(u2, field)) { return true; } else { return false; } } else if (!has_uri_field(u2, field)) { return false; } if (u1.field_data[field].len != u2.field_data[field].len) { return false; } return memcmp(uri1 + u1.field_data[field].off, uri2 + u2.field_data[field].off, u1.field_data[field].len) == 0; } bool fieldeq(const char *uri, const http_parser_url &u, http_parser_url_fields field, const char *t) { return fieldeq(uri, u, field, StringRef{t}); } bool fieldeq(const char *uri, const http_parser_url &u, http_parser_url_fields field, const StringRef &t) { if (!has_uri_field(u, field)) { return t.empty(); } auto &f = u.field_data[field]; return StringRef{uri + f.off, f.len} == t; } StringRef get_uri_field(const char *uri, const http_parser_url &u, http_parser_url_fields field) { if (!util::has_uri_field(u, field)) { return StringRef{}; } return StringRef{uri + u.field_data[field].off, u.field_data[field].len}; } uint16_t get_default_port(const char *uri, const http_parser_url &u) { if (util::fieldeq(uri, u, UF_SCHEMA, "https")) { return 443; } else if (util::fieldeq(uri, u, UF_SCHEMA, "http")) { return 80; } else { return 443; } } bool porteq(const char *uri1, const http_parser_url &u1, const char *uri2, const http_parser_url &u2) { uint16_t port1, port2; port1 = util::has_uri_field(u1, UF_PORT) ? u1.port : get_default_port(uri1, u1); port2 = util::has_uri_field(u2, UF_PORT) ? u2.port : get_default_port(uri2, u2); return port1 == port2; } void write_uri_field(std::ostream &o, const char *uri, const http_parser_url &u, http_parser_url_fields field) { if (util::has_uri_field(u, field)) { o.write(uri + u.field_data[field].off, u.field_data[field].len); } } bool numeric_host(const char *hostname) { return numeric_host(hostname, AF_INET) || numeric_host(hostname, AF_INET6); } bool numeric_host(const char *hostname, int family) { int rv; std::array<uint8_t, sizeof(struct in6_addr)> dst; rv = nghttp2_inet_pton(family, hostname, dst.data()); return rv == 1; } std::string numeric_name(const struct sockaddr *sa, socklen_t salen) { std::array<char, NI_MAXHOST> host; auto rv = getnameinfo(sa, salen, host.data(), host.size(), nullptr, 0, NI_NUMERICHOST); if (rv != 0) { return "unknown"; } return host.data(); } std::string to_numeric_addr(const Address *addr) { auto family = addr->su.storage.ss_family; #ifndef _WIN32 if (family == AF_UNIX) { return addr->su.un.sun_path; } #endif // !_WIN32 std::array<char, NI_MAXHOST> host; std::array<char, NI_MAXSERV> serv; auto rv = getnameinfo(&addr->su.sa, addr->len, host.data(), host.size(), serv.data(), serv.size(), NI_NUMERICHOST | NI_NUMERICSERV); if (rv != 0) { return "unknown"; } auto hostlen = strlen(host.data()); auto servlen = strlen(serv.data()); std::string s; char *p; if (family == AF_INET6) { s.resize(hostlen + servlen + 2 + 1); p = &s[0]; *p++ = '['; p = std::copy_n(host.data(), hostlen, p); *p++ = ']'; } else { s.resize(hostlen + servlen + 1); p = &s[0]; p = std::copy_n(host.data(), hostlen, p); } *p++ = ':'; std::copy_n(serv.data(), servlen, p); return s; } void set_port(Address &addr, uint16_t port) { switch (addr.su.storage.ss_family) { case AF_INET: addr.su.in.sin_port = htons(port); break; case AF_INET6: addr.su.in6.sin6_port = htons(port); break; } } std::string ascii_dump(const uint8_t *data, size_t len) { std::string res; for (size_t i = 0; i < len; ++i) { auto c = data[i]; if (c >= 0x20 && c < 0x7f) { res += c; } else { res += '.'; } } return res; } char *get_exec_path(int argc, char **const argv, const char *cwd) { if (argc == 0 || cwd == nullptr) { return nullptr; } auto argv0 = argv[0]; auto len = strlen(argv0); char *path; if (argv0[0] == '/') { path = static_cast<char *>(malloc(len + 1)); if (path == nullptr) { return nullptr; } memcpy(path, argv0, len + 1); } else { auto cwdlen = strlen(cwd); path = static_cast<char *>(malloc(len + 1 + cwdlen + 1)); if (path == nullptr) { return nullptr; } memcpy(path, cwd, cwdlen); path[cwdlen] = '/'; memcpy(path + cwdlen + 1, argv0, len + 1); } return path; } bool check_path(const std::string &path) { // We don't like '\' in path. return !path.empty() && path[0] == '/' && path.find('\\') == std::string::npos && path.find("/../") == std::string::npos && path.find("/./") == std::string::npos && !util::ends_with_l(path, "/..") && !util::ends_with_l(path, "/."); } int64_t to_time64(const timeval &tv) { return tv.tv_sec * 1000000 + tv.tv_usec; } bool check_h2_is_selected(const StringRef &proto) { return streq(NGHTTP2_H2, proto) || streq(NGHTTP2_H2_16, proto) || streq(NGHTTP2_H2_14, proto); } namespace { bool select_proto(const unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, const StringRef &key) { for (auto p = in, end = in + inlen; p + key.size() <= end; p += *p + 1) { if (std::equal(std::begin(key), std::end(key), p)) { *out = p + 1; *outlen = *p; return true; } } return false; } } // namespace bool select_h2(const unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen) { return select_proto(out, outlen, in, inlen, NGHTTP2_H2_ALPN) || select_proto(out, outlen, in, inlen, NGHTTP2_H2_16_ALPN) || select_proto(out, outlen, in, inlen, NGHTTP2_H2_14_ALPN); } bool select_protocol(const unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, std::vector<std::string> proto_list) { for (const auto &proto : proto_list) { if (select_proto(out, outlen, in, inlen, StringRef{proto})) { return true; } } return false; } std::vector<unsigned char> get_default_alpn() { auto res = std::vector<unsigned char>(NGHTTP2_H2_ALPN.size() + NGHTTP2_H2_16_ALPN.size() + NGHTTP2_H2_14_ALPN.size()); auto p = std::begin(res); p = std::copy_n(std::begin(NGHTTP2_H2_ALPN), NGHTTP2_H2_ALPN.size(), p); p = std::copy_n(std::begin(NGHTTP2_H2_16_ALPN), NGHTTP2_H2_16_ALPN.size(), p); p = std::copy_n(std::begin(NGHTTP2_H2_14_ALPN), NGHTTP2_H2_14_ALPN.size(), p); return res; } std::vector<StringRef> split_str(const StringRef &s, char delim) { size_t len = 1; auto last = std::end(s); StringRef::const_iterator d; for (auto first = std::begin(s); (d = std::find(first, last, delim)) != last; ++len, first = d + 1) ; auto list = std::vector<StringRef>(len); len = 0; for (auto first = std::begin(s);; ++len) { auto stop = std::find(first, last, delim); list[len] = StringRef{first, stop}; if (stop == last) { break; } first = stop + 1; } return list; } std::vector<std::string> parse_config_str_list(const StringRef &s, char delim) { auto sublist = split_str(s, delim); auto res = std::vector<std::string>(); res.reserve(sublist.size()); for (const auto &s : sublist) { res.emplace_back(std::begin(s), std::end(s)); } return res; } int make_socket_closeonexec(int fd) { #ifdef _WIN32 (void)fd; return 0; #else // !_WIN32 int flags; int rv; while ((flags = fcntl(fd, F_GETFD)) == -1 && errno == EINTR) ; while ((rv = fcntl(fd, F_SETFD, flags | FD_CLOEXEC)) == -1 && errno == EINTR) ; return rv; #endif // !_WIN32 } int make_socket_nonblocking(int fd) { int rv; #ifdef _WIN32 u_long mode = 1; rv = ioctlsocket(fd, FIONBIO, &mode); #else // !_WIN32 int flags; while ((flags = fcntl(fd, F_GETFL, 0)) == -1 && errno == EINTR) ; while ((rv = fcntl(fd, F_SETFL, flags | O_NONBLOCK)) == -1 && errno == EINTR) ; #endif // !_WIN32 return rv; } int make_socket_nodelay(int fd) { int val = 1; if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&val), sizeof(val)) == -1) { return -1; } return 0; } int create_nonblock_socket(int family) { #ifdef SOCK_NONBLOCK auto fd = socket(family, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); if (fd == -1) { return -1; } #else // !SOCK_NONBLOCK auto fd = socket(family, SOCK_STREAM, 0); if (fd == -1) { return -1; } make_socket_nonblocking(fd); make_socket_closeonexec(fd); #endif // !SOCK_NONBLOCK if (family == AF_INET || family == AF_INET6) { make_socket_nodelay(fd); } return fd; } bool check_socket_connected(int fd) { int error; socklen_t len = sizeof(error); if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&error, &len) != 0) { return false; } return error == 0; } int get_socket_error(int fd) { int error; socklen_t len = sizeof(error); if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&error, &len) != 0) { return -1; } return error; } bool ipv6_numeric_addr(const char *host) { uint8_t dst[16]; return nghttp2_inet_pton(AF_INET6, host, dst) == 1; } namespace { std::pair<int64_t, size_t> parse_uint_digits(const void *ss, size_t len) { const uint8_t *s = static_cast<const uint8_t *>(ss); int64_t n = 0; size_t i; if (len == 0) { return {-1, 0}; } constexpr int64_t max = std::numeric_limits<int64_t>::max(); for (i = 0; i < len; ++i) { if ('0' <= s[i] && s[i] <= '9') { if (n > max / 10) { return {-1, 0}; } n *= 10; if (n > max - (s[i] - '0')) { return {-1, 0}; } n += s[i] - '0'; continue; } break; } if (i == 0) { return {-1, 0}; } return {n, i}; } } // namespace int64_t parse_uint_with_unit(const char *s) { return parse_uint_with_unit(reinterpret_cast<const uint8_t *>(s), strlen(s)); } int64_t parse_uint_with_unit(const StringRef &s) { return parse_uint_with_unit(s.byte(), s.size()); } int64_t parse_uint_with_unit(const uint8_t *s, size_t len) { int64_t n; size_t i; std::tie(n, i) = parse_uint_digits(s, len); if (n == -1) { return -1; } if (i == len) { return n; } if (i + 1 != len) { return -1; } int mul = 1; switch (s[i]) { case 'K': case 'k': mul = 1 << 10; break; case 'M': case 'm': mul = 1 << 20; break; case 'G': case 'g': mul = 1 << 30; break; default: return -1; } constexpr int64_t max = std::numeric_limits<int64_t>::max(); if (n > max / mul) { return -1; } return n * mul; } int64_t parse_uint(const char *s) { return parse_uint(reinterpret_cast<const uint8_t *>(s), strlen(s)); } int64_t parse_uint(const std::string &s) { return parse_uint(reinterpret_cast<const uint8_t *>(s.c_str()), s.size()); } int64_t parse_uint(const StringRef &s) { return parse_uint(s.byte(), s.size()); } int64_t parse_uint(const uint8_t *s, size_t len) { int64_t n; size_t i; std::tie(n, i) = parse_uint_digits(s, len); if (n == -1 || i != len) { return -1; } return n; } double parse_duration_with_unit(const char *s) { return parse_duration_with_unit(reinterpret_cast<const uint8_t *>(s), strlen(s)); } double parse_duration_with_unit(const StringRef &s) { return parse_duration_with_unit(s.byte(), s.size()); } double parse_duration_with_unit(const uint8_t *s, size_t len) { constexpr auto max = std::numeric_limits<int64_t>::max(); int64_t n; size_t i; std::tie(n, i) = parse_uint_digits(s, len); if (n == -1) { goto fail; } if (i == len) { return static_cast<double>(n); } switch (s[i]) { case 'S': case 's': // seconds if (i + 1 != len) { goto fail; } return static_cast<double>(n); case 'M': case 'm': if (i + 1 == len) { // minutes if (n > max / 60) { goto fail; } return static_cast<double>(n) * 60; } if (i + 2 != len || (s[i + 1] != 's' && s[i + 1] != 'S')) { goto fail; } // milliseconds return static_cast<double>(n) / 1000.; case 'H': case 'h': // hours if (i + 1 != len) { goto fail; } if (n > max / 3600) { goto fail; } return static_cast<double>(n) * 3600; } fail: return std::numeric_limits<double>::infinity(); } std::string duration_str(double t) { if (t == 0.) { return "0"; } auto frac = static_cast<int64_t>(t * 1000) % 1000; if (frac > 0) { return utos(static_cast<int64_t>(t * 1000)) + "ms"; } auto v = static_cast<int64_t>(t); if (v % 60) { return utos(v) + "s"; } v /= 60; if (v % 60) { return utos(v) + "m"; } v /= 60; return utos(v) + "h"; } std::string format_duration(const std::chrono::microseconds &u) { const char *unit = "us"; int d = 0; auto t = u.count(); if (t >= 1000000) { d = 1000000; unit = "s"; } else if (t >= 1000) { d = 1000; unit = "ms"; } else { return utos(t) + unit; } return dtos(static_cast<double>(t) / d) + unit; } std::string format_duration(double t) { const char *unit = "us"; if (t >= 1.) { unit = "s"; } else if (t >= 0.001) { t *= 1000.; unit = "ms"; } else { t *= 1000000.; return utos(static_cast<int64_t>(t)) + unit; } return dtos(t) + unit; } std::string dtos(double n) { auto m = llround(100. * n); auto f = utos(m % 100); return utos(m / 100) + "." + (f.size() == 1 ? "0" : "") + f; } StringRef make_http_hostport(BlockAllocator &balloc, const StringRef &host, uint16_t port) { if (port != 80 && port != 443) { return make_hostport(balloc, host, port); } auto ipv6 = ipv6_numeric_addr(host.c_str()); auto iov = make_byte_ref(balloc, host.size() + (ipv6 ? 2 : 0) + 1); auto p = iov.base; if (ipv6) { *p++ = '['; } p = std::copy(std::begin(host), std::end(host), p); if (ipv6) { *p++ = ']'; } *p = '\0'; return StringRef{iov.base, p}; } std::string make_hostport(const StringRef &host, uint16_t port) { auto ipv6 = ipv6_numeric_addr(host.c_str()); auto serv = utos(port); std::string hostport; hostport.resize(host.size() + (ipv6 ? 2 : 0) + 1 + serv.size()); auto p = &hostport[0]; if (ipv6) { *p++ = '['; } p = std::copy_n(host.c_str(), host.size(), p); if (ipv6) { *p++ = ']'; } *p++ = ':'; std::copy_n(serv.c_str(), serv.size(), p); return hostport; } StringRef make_hostport(BlockAllocator &balloc, const StringRef &host, uint16_t port) { auto ipv6 = ipv6_numeric_addr(host.c_str()); auto serv = utos(port); auto iov = make_byte_ref(balloc, host.size() + (ipv6 ? 2 : 0) + 1 + serv.size()); auto p = iov.base; if (ipv6) { *p++ = '['; } p = std::copy(std::begin(host), std::end(host), p); if (ipv6) { *p++ = ']'; } *p++ = ':'; p = std::copy(std::begin(serv), std::end(serv), p); *p = '\0'; return StringRef{iov.base, p}; } namespace { void hexdump8(FILE *out, const uint8_t *first, const uint8_t *last) { auto stop = std::min(first + 8, last); for (auto k = first; k != stop; ++k) { fprintf(out, "%02x ", *k); } // each byte needs 3 spaces (2 hex value and space) for (; stop != first + 8; ++stop) { fputs(" ", out); } // we have extra space after 8 bytes fputc(' ', out); } } // namespace void hexdump(FILE *out, const uint8_t *src, size_t len) { if (len == 0) { return; } size_t buflen = 0; auto repeated = false; std::array<uint8_t, 16> buf{}; auto end = src + len; auto i = src; for (;;) { auto nextlen = std::min(static_cast<size_t>(16), static_cast<size_t>(end - i)); if (nextlen == buflen && std::equal(std::begin(buf), std::begin(buf) + buflen, i)) { // as long as adjacent 16 bytes block are the same, we just // print single '*'. if (!repeated) { repeated = true; fputs("*\n", out); } i += nextlen; continue; } repeated = false; fprintf(out, "%08lx", static_cast<unsigned long>(i - src)); if (i == end) { fputc('\n', out); break; } fputs(" ", out); hexdump8(out, i, end); hexdump8(out, i + 8, std::max(i + 8, end)); fputc('|', out); auto stop = std::min(i + 16, end); buflen = stop - i; auto p = buf.data(); for (; i != stop; ++i) { *p++ = *i; if (0x20 <= *i && *i <= 0x7e) { fputc(*i, out); } else { fputc('.', out); } } fputs("|\n", out); } } void put_uint16be(uint8_t *buf, uint16_t n) { uint16_t x = htons(n); memcpy(buf, &x, sizeof(uint16_t)); } void put_uint32be(uint8_t *buf, uint32_t n) { uint32_t x = htonl(n); memcpy(buf, &x, sizeof(uint32_t)); } uint16_t get_uint16(const uint8_t *data) { uint16_t n; memcpy(&n, data, sizeof(uint16_t)); return ntohs(n); } uint32_t get_uint32(const uint8_t *data) { uint32_t n; memcpy(&n, data, sizeof(uint32_t)); return ntohl(n); } uint64_t get_uint64(const uint8_t *data) { uint64_t n = 0; n += static_cast<uint64_t>(data[0]) << 56; n += static_cast<uint64_t>(data[1]) << 48; n += static_cast<uint64_t>(data[2]) << 40; n += static_cast<uint64_t>(data[3]) << 32; n += static_cast<uint64_t>(data[4]) << 24; n += data[5] << 16; n += data[6] << 8; n += data[7]; return n; } int read_mime_types(std::map<std::string, std::string> &res, const char *filename) { std::ifstream infile(filename); if (!infile) { return -1; } auto delim_pred = [](char c) { return c == ' ' || c == '\t'; }; std::string line; while (std::getline(infile, line)) { if (line.empty() || line[0] == '#') { continue; } auto type_end = std::find_if(std::begin(line), std::end(line), delim_pred); if (type_end == std::begin(line)) { continue; } auto ext_end = type_end; for (;;) { auto ext_start = std::find_if_not(ext_end, std::end(line), delim_pred); if (ext_start == std::end(line)) { break; } ext_end = std::find_if(ext_start, std::end(line), delim_pred); #ifdef HAVE_STD_MAP_EMPLACE res.emplace(std::string(ext_start, ext_end), std::string(std::begin(line), type_end)); #else // !HAVE_STD_MAP_EMPLACE res.insert(std::make_pair(std::string(ext_start, ext_end), std::string(std::begin(line), type_end))); #endif // !HAVE_STD_MAP_EMPLACE } } return 0; } StringRef percent_decode(BlockAllocator &balloc, const StringRef &src) { auto iov = make_byte_ref(balloc, src.size() * 3 + 1); auto p = iov.base; for (auto first = std::begin(src); first != std::end(src); ++first) { if (*first != '%') { *p++ = *first; continue; } if (first + 1 != std::end(src) && first + 2 != std::end(src) && is_hex_digit(*(first + 1)) && is_hex_digit(*(first + 2))) { *p++ = (hex_to_uint(*(first + 1)) << 4) + hex_to_uint(*(first + 2)); first += 2; continue; } *p++ = *first; } *p = '\0'; return StringRef{iov.base, p}; } // Returns x**y double int_pow(double x, size_t y) { auto res = 1.; for (; y; --y) { res *= x; } return res; } uint32_t hash32(const StringRef &s) { /* 32 bit FNV-1a: http://isthe.com/chongo/tech/comp/fnv/ */ uint32_t h = 2166136261u; size_t i; for (i = 0; i < s.size(); ++i) { h ^= s[i]; h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24); } return h; } #if !OPENSSL_1_1_API namespace { EVP_MD_CTX *EVP_MD_CTX_new(void) { return EVP_MD_CTX_create(); } } // namespace namespace { void EVP_MD_CTX_free(EVP_MD_CTX *ctx) { EVP_MD_CTX_destroy(ctx); } } // namespace #endif // !OPENSSL_1_1_API int sha256(uint8_t *res, const StringRef &s) { int rv; auto ctx = EVP_MD_CTX_new(); if (ctx == nullptr) { return -1; } auto ctx_deleter = defer(EVP_MD_CTX_free, ctx); rv = EVP_DigestInit_ex(ctx, EVP_sha256(), nullptr); if (rv != 1) { return -1; } rv = EVP_DigestUpdate(ctx, s.c_str(), s.size()); if (rv != 1) { return -1; } unsigned int mdlen = 32; rv = EVP_DigestFinal_ex(ctx, res, &mdlen); if (rv != 1) { return -1; } return 0; } bool is_hex_string(const StringRef &s) { if (s.size() % 2) { return false; } for (auto c : s) { if (!is_hex_digit(c)) { return false; } } return true; } StringRef decode_hex(BlockAllocator &balloc, const StringRef &s) { auto iov = make_byte_ref(balloc, s.size() + 1); auto p = iov.base; for (auto it = std::begin(s); it != std::end(s); it += 2) { *p++ = (hex_to_uint(*it) << 4) | hex_to_uint(*(it + 1)); } *p = '\0'; return StringRef{iov.base, p}; } StringRef extract_host(const StringRef &hostport) { if (hostport[0] == '[') { // assume this is IPv6 numeric address auto p = std::find(std::begin(hostport), std::end(hostport), ']'); if (p == std::end(hostport)) { return StringRef{}; } if (p + 1 < std::end(hostport) && *(p + 1) != ':') { return StringRef{}; } return StringRef{std::begin(hostport), p + 1}; } auto p = std::find(std::begin(hostport), std::end(hostport), ':'); if (p == std::begin(hostport)) { return StringRef{}; } return StringRef{std::begin(hostport), p}; } std::mt19937 make_mt19937() { std::random_device rd; return std::mt19937(rd()); } } // namespace util } // namespace nghttp2
; A014143: Partial sums of A014138. ; 1,4,12,34,98,294,919,2974,9891,33604,116103,406614,1440025,5147876,18550572,67310938,245716094,901759950,3325066996,12312494462,45766188948,170702447074,638698318850,2396598337950,9016444758502,34003644251206,128524394659914,486793096818982,1847304015629418,7022801436532158 mov $12,$0 mov $14,$0 add $14,1 lpb $14,1 clr $0,12 mov $0,$12 trn $14,1 sub $0,$14 mov $9,$0 mov $11,$0 add $11,1 lpb $11,1 mov $0,$9 trn $11,1 sub $0,$11 mov $7,$0 add $0,1 mov $4,$6 add $4,$0 mov $8,$0 add $8,2 mov $2,$8 add $2,$7 mov $0,$2 bin $2,$4 div $2,$0 add $10,$2 lpe add $13,$10 lpe mov $1,$13
// Test array index pointer rewriting // struct array with 16bit index // Commodore 64 PRG executable file .file [name="index-pointer-rewrite-9.prg", type="prg", segments="Program"] .segmentdef Program [segments="Basic, Code, Data"] .segmentdef Basic [start=$0801] .segmentdef Code [start=$80d] .segmentdef Data [startAfter="Code"] .segment Basic :BasicUpstart(main) .const OFFSET_STRUCT_BALL_VEL = 1 .const OFFSET_STRUCT_BALL_SYM = 2 .segment Code main: { .label __2 = 2 .label __8 = 2 .label i = 4 .label __10 = 2 lda #<0 sta.z i sta.z i+1 __b1: // for(unsigned short i=0;i<NUM_BALLS;i++) lda.z i+1 bne !+ lda.z i cmp #$19 bcc __b2 !: // } rts __b2: // balls[i].pos += balls[i].vel lda.z i asl sta.z __10 lda.z i+1 rol sta.z __10+1 clc lda.z __2 adc.z i sta.z __2 lda.z __2+1 adc.z i+1 sta.z __2+1 lda.z __8 clc adc #<balls sta.z __8 lda.z __8+1 adc #>balls sta.z __8+1 ldy #0 lda (__8),y ldy #OFFSET_STRUCT_BALL_VEL clc adc (__8),y ldy #0 sta (__8),y // balls[i].vel += 10 lda #$a ldy #OFFSET_STRUCT_BALL_VEL clc adc (__8),y sta (__8),y // balls[i].sym ='*' lda #'*' ldy #OFFSET_STRUCT_BALL_SYM sta (__8),y // for(unsigned short i=0;i<NUM_BALLS;i++) inc.z i bne !+ inc.z i+1 !: jmp __b1 } .segment Data balls: .fill 3*$19, 0
SSAnne2FRooms_Script: ld a, $1 ld [wAutoTextBoxDrawingControl], a xor a ld [wDoNotWaitForButtonPressAfterDisplayingText], a ld hl, SSAnne9TrainerHeader0 ld de, SSAnne2FRooms_ScriptPointers ld a, [wSSAnne2FRoomsCurScript] call ExecuteCurMapScriptInTable ld [wSSAnne2FRoomsCurScript], a ret SSAnne2FRooms_ScriptPointers: dw CheckFightingMapTrainers dw DisplayEnemyTrainerTextAndStartBattle dw EndTrainerBattle SSAnne2FRooms_TextPointers: dw SSAnne9Text1 dw SSAnne9Text2 dw SSAnne9Text3 dw SSAnne9Text4 dw SSAnne9Text5 dw PickUpItemText dw SSAnne9Text7 dw SSAnne9Text8 dw PickUpItemText dw SSAnne9Text10 dw SSAnne9Text11 dw SSAnne9Text12 dw SSAnne9Text13 SSAnne9TrainerHeader0: dbEventFlagBit EVENT_BEAT_SS_ANNE_9_TRAINER_0 db ($2 << 4) ; trainer's view range dwEventFlagAddress EVENT_BEAT_SS_ANNE_9_TRAINER_0 dw SSAnne9BattleText1 ; TextBeforeBattle dw SSAnne9AfterBattleText1 ; TextAfterBattle dw SSAnne9EndBattleText1 ; TextEndBattle dw SSAnne9EndBattleText1 ; TextEndBattle SSAnne9TrainerHeader1: dbEventFlagBit EVENT_BEAT_SS_ANNE_9_TRAINER_1 db ($3 << 4) ; trainer's view range dwEventFlagAddress EVENT_BEAT_SS_ANNE_9_TRAINER_1 dw SSAnne9BattleText2 ; TextBeforeBattle dw SSAnne9AfterBattleText2 ; TextAfterBattle dw SSAnne9EndBattleText2 ; TextEndBattle dw SSAnne9EndBattleText2 ; TextEndBattle SSAnne9TrainerHeader2: dbEventFlagBit EVENT_BEAT_SS_ANNE_9_TRAINER_2 db ($3 << 4) ; trainer's view range dwEventFlagAddress EVENT_BEAT_SS_ANNE_9_TRAINER_2 dw SSAnne9BattleText3 ; TextBeforeBattle dw SSAnne9AfterBattleText3 ; TextAfterBattle dw SSAnne9EndBattleText3 ; TextEndBattle dw SSAnne9EndBattleText3 ; TextEndBattle SSAnne9TrainerHeader3: dbEventFlagBit EVENT_BEAT_SS_ANNE_9_TRAINER_3 db ($2 << 4) ; trainer's view range dwEventFlagAddress EVENT_BEAT_SS_ANNE_9_TRAINER_3 dw SSAnne9BattleText4 ; TextBeforeBattle dw SSAnne9AfterBattleText4 ; TextAfterBattle dw SSAnne9EndBattleText4 ; TextEndBattle dw SSAnne9EndBattleText4 ; TextEndBattle db $ff SSAnne9Text1: TX_ASM ld hl, SSAnne9TrainerHeader0 call TalkToTrainer jp TextScriptEnd SSAnne9Text2: TX_ASM ld hl, SSAnne9TrainerHeader1 call TalkToTrainer jp TextScriptEnd SSAnne9Text3: TX_ASM ld hl, SSAnne9TrainerHeader2 call TalkToTrainer jp TextScriptEnd SSAnne9Text4: TX_ASM ld hl, SSAnne9TrainerHeader3 call TalkToTrainer jp TextScriptEnd SSAnne9Text5: TX_ASM call SaveScreenTilesToBuffer1 ld hl, SSAnne9Text_61bf2 call PrintText call LoadScreenTilesFromBuffer1 ld a, SNORLAX call DisplayPokedex jp TextScriptEnd SSAnne9Text_61bf2: TX_FAR _SSAnne9Text_61bf2 db "@" SSAnne9Text7: TX_ASM ld hl, SSAnne9Text_61c01 call PrintText jp TextScriptEnd SSAnne9Text_61c01: TX_FAR _SSAnne9Text_61c01 db "@" SSAnne9Text8: TX_ASM ld hl, SSAnne9Text_61c10 call PrintText jp TextScriptEnd SSAnne9Text_61c10: TX_FAR _SSAnne9Text_61c10 db "@" SSAnne9Text10: TX_ASM ld hl, SSAnne9Text_61c1f call PrintText jp TextScriptEnd SSAnne9Text_61c1f: TX_FAR _SSAnne9Text_61c1f db "@" SSAnne9Text11: TX_ASM ld hl, SSAnne9Text_61c2e call PrintText jp TextScriptEnd SSAnne9Text_61c2e: TX_FAR _SSAnne9Text_61c2e db "@" SSAnne9Text12: TX_ASM ld hl, SSAnne9Text_61c3d call PrintText jp TextScriptEnd SSAnne9Text_61c3d: TX_FAR _SSAnne9Text_61c3d db "@" SSAnne9Text13: TX_ASM ld hl, SSAnne9Text_61c4c call PrintText jp TextScriptEnd SSAnne9Text_61c4c: TX_FAR _SSAnne9Text_61c4c db "@" SSAnne9BattleText1: TX_FAR _SSAnne9BattleText1 db "@" SSAnne9EndBattleText1: TX_FAR _SSAnne9EndBattleText1 db "@" SSAnne9AfterBattleText1: TX_FAR _SSAnne9AfterBattleText1 db "@" SSAnne9BattleText2: TX_FAR _SSAnne9BattleText2 db "@" SSAnne9EndBattleText2: TX_FAR _SSAnne9EndBattleText2 db "@" SSAnne9AfterBattleText2: TX_FAR _SSAnne9AfterBattleText2 db "@" SSAnne9BattleText3: TX_FAR _SSAnne9BattleText3 db "@" SSAnne9EndBattleText3: TX_FAR _SSAnne9EndBattleText3 db "@" SSAnne9AfterBattleText3: TX_FAR _SSAnne9AfterBattleText3 db "@" SSAnne9BattleText4: TX_FAR _SSAnne9BattleText4 db "@" SSAnne9EndBattleText4: TX_FAR _SSAnne9EndBattleText4 db "@" SSAnne9AfterBattleText4: TX_FAR _SSAnne9AfterBattleText4 db "@"
.data x: .word -1 #armazenando o valor de "x" no formato . x = -1 y: .word 0 #armazenando o valor de "y" no formato . y = 0 .text lw $t0, x #carregar o valor de "x" para "f2" add $t1,$zero,32 # Armazenar 32 em t1 div $t0,$t1 # Dividir t0 por t1 mflo $t0 # pegar o restante e armazenar em t0 sw $t0,y # armazenar o valor de "t0" em "y"
; A191402: A000201(n)+A000201(n+1). ; 1,4,7,10,14,17,20,23,26,30,33,36,40,43,46,49,52,56,59,62,65,68,72,75,78,82,85,88,91,94,98,101,104,108,111,114,117,120,124,127,130,133,136,140,143,146,150,153,156,159,162,166,169,172,175,178,182,185,188,192,195,198,201,204,208,211,214,218,221,224 mov $2,1 lpb $2 mov $1,$0 sub $2,1 mov $3,2 lpb $3 mov $0,$1 sub $0,1 mul $0,2 max $0,0 seq $0,187576 ; Rank transform of the sequence 2*floor((n-1)/2)); complement of A187577. add $0,2 sub $3,1 mov $4,$0 lpe min $1,1 mul $1,$4 lpe add $1,1 mov $0,$1
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r13 push %rbp push %rbx push %rcx push %rdi push %rdx push %rsi lea addresses_normal_ht+0x18a71, %rdx clflush (%rdx) nop nop nop dec %rdi movl $0x61626364, (%rdx) nop nop nop nop and $21435, %rbx lea addresses_D_ht+0x12b79, %rbp nop nop nop nop nop add %rsi, %rsi movb $0x61, (%rbp) cmp %rdi, %rdi lea addresses_UC_ht+0x11801, %rsi lea addresses_D_ht+0x1c6b9, %rdi nop and $34532, %r13 mov $116, %rcx rep movsb nop nop dec %rdi lea addresses_D_ht+0x1096e, %r10 nop nop nop xor $6027, %rsi movb $0x61, (%r10) nop dec %rdi lea addresses_A_ht+0x1eee1, %r13 nop nop nop nop cmp $4459, %r10 mov $0x6162636465666768, %rbx movq %rbx, (%r13) nop nop nop nop sub $10783, %rdi lea addresses_WT_ht+0x1acfd, %rsi lea addresses_normal_ht+0x1d2f1, %rdi nop nop nop nop nop cmp %rdx, %rdx mov $80, %rcx rep movsq nop nop nop add $11079, %rbx lea addresses_D_ht+0x10585, %rbp nop nop add %rcx, %rcx mov (%rbp), %dx nop nop nop sub %rsi, %rsi lea addresses_A_ht+0x13f31, %rdx nop nop xor $60785, %rcx mov $0x6162636465666768, %r13 movq %r13, (%rdx) nop nop nop nop sub $28007, %rbx lea addresses_UC_ht+0x16971, %rsi lea addresses_WT_ht+0x9ab5, %rdi nop and $55584, %rbp mov $40, %rcx rep movsq nop cmp $11762, %rsi lea addresses_D_ht+0x13ab, %rbp nop nop cmp $24863, %rsi movw $0x6162, (%rbp) nop nop and $60362, %rbx lea addresses_D_ht+0x1605d, %rsi lea addresses_A_ht+0x12a71, %rdi nop nop nop cmp $51504, %rdx mov $12, %rcx rep movsw nop nop nop nop inc %rcx lea addresses_A_ht+0xeae9, %rsi nop sub $4301, %rbx mov $0x6162636465666768, %rbp movq %rbp, %xmm4 vmovups %ymm4, (%rsi) nop nop nop and %rbp, %rbp lea addresses_WT_ht+0x1ea71, %rbp nop nop nop nop nop add %r10, %r10 movb $0x61, (%rbp) nop nop sub $35351, %rdi pop %rsi pop %rdx pop %rdi pop %rcx pop %rbx pop %rbp pop %r13 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r12 push %r15 push %r8 push %rax push %rbx push %rdx // Store lea addresses_WT+0xe618, %rax nop nop cmp %rbx, %rbx mov $0x5152535455565758, %r15 movq %r15, (%rax) nop nop xor %rdx, %rdx // Store mov $0x271, %r15 nop nop nop xor $38792, %r12 mov $0x5152535455565758, %rdx movq %rdx, (%r15) add $41110, %rbx // Store lea addresses_normal+0xb711, %r10 nop nop nop nop nop sub %rdx, %rdx mov $0x5152535455565758, %r8 movq %r8, %xmm3 vmovups %ymm3, (%r10) nop nop nop xor %r10, %r10 // Store lea addresses_US+0x731, %rax nop nop nop inc %rdx movw $0x5152, (%rax) nop nop nop sub %r12, %r12 // Load lea addresses_A+0x16a71, %r12 nop sub %r15, %r15 movb (%r12), %bl nop add $56214, %rbx // Store lea addresses_WC+0x19bf1, %r10 nop nop nop cmp %rbx, %rbx movb $0x51, (%r10) and %rbx, %rbx // Faulty Load lea addresses_UC+0x1da71, %rdx nop nop nop nop cmp $49605, %r15 movb (%rdx), %r12b lea oracles, %r8 and $0xff, %r12 shlq $12, %r12 mov (%r8,%r12,1), %r12 pop %rdx pop %rbx pop %rax pop %r8 pop %r15 pop %r12 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_UC', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'size': 8, 'AVXalign': False, 'NT': True, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_P', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_US', 'size': 2, 'AVXalign': False, 'NT': True, 'congruent': 6, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 11, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_UC', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 1, 'AVXalign': True, 'NT': False, 'congruent': 3, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 3, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 8, 'AVXalign': True, 'NT': False, 'congruent': 3, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 7, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 11, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}} {'00': 4293} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
;; ;; Copyright (c) 2018, Intel Corporation ;; ;; 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. ;; %include "include/aesni_emu.inc" %define AES_XCBC_X4 aes_xcbc_mac_128_x4_no_aesni %include "sse/aes_xcbc_mac_128_x4.asm"
; Define wallpaper v1.03  1999 Tony Tebby ; 2002 Marcel Kilgus ; ; 2002-02-13 1.01 Adapted for on-the-fly wallpaper (MK) ; 2002-05-30 1.02 Returns last used colour in D1. Fixes mode change issue (MK) ; 2011-03-02 1.03 Save a few registers around mem.rchp for QDOS systems (MK) ; section driver ; xdef pt_wpap xref pt_wchka xref pt_wremv xref pt_mrall xref pt_fillsv xref.s pt.spxlw xref.s pt.rpxlw xref cn_ql_colr xref cn_24b_mcolr ; include dev8_keys_con include dev8_keys_iod include dev8_keys_chn include dev8_keys_err include dev8_keys_qlv include dev8_keys_qdos_sms ;+++ ; This version handles background images (wallpaper) exclusively in the current ; display mode and screen size (D2 must be -1). This also implies that there is ; no real point in specifying a colour if an image is given. ; The colour must either be a 24 bit colour (msbits) or a QL stipple. ; ; D1 cr background colour (or -1) / last set background colour ; D2 c s background image type (0 for native, -1 for none) ; A1 c p background image ;--- pt_wpap ptw.reg reg d2/a0-a1 stk_d2 equ $00 stk_a1 equ $08 movem.l ptw.reg,-(sp) moveq #-1,d4 tst.l d2 ; native mode image? beq.s ptw_colour ; ... yes, set colour cmp.l d4,d2 ; image? bne.l ptw_ipar ; ... yes, wrong mode cmp.l d4,d1 ; colour given? bne.s ptw_colour ; ... yes bsr.l ptw_remove ; remove old background bra.l ptw_redraw ptw_colour cmp.l d4,d1 ; colour given? bne.s ptw_cdef ; ... yes move.l pt_bgcld(a3),d1 ; use old colour ptw_cdef move.l d1,pt_bgcld(a3) ; ... save old colour moveq #0,d3 move.b d1,d3 ; QL colour? beq.s ptw_c24 ; ... no jsr cn_ql_colr bra.s ptw_setcolour ptw_c24 moveq #-1,d6 ; no stipple move.l d1,d3 jsr cn_24b_mcolr ptw_setcolour move.w d6,pt_bgstp(a3) ; set stipple move.l d7,pt_bgclm(a3) ; set colour ; First release existing background (if any) ; It's easier to start from scratch ptw_setup bsr.l ptw_remove tst.l stk_d2(sp) ; image given? bne.s ptw_redraw ; no, don't create wallpaper window moveq #sd.wpapr,d1 ; create a wallpaper window bsr.l ptw_crchan bne.l ptw_exit ; ...oops lea sd_prwlb(a0),a4 move.l pt_tail(a3),a1 ; point to bottom move.l a1,(a4) ; bottom up list move.l a4,pt_tail(a3) addq.l #sd_prwlt-sd_prwlb,a4 move.l a4,sd_prwlt-sd_prwlb(a1) ; link at end of top down list move.l a0,a4 ; keep channel base safe move.l pt_ssize(a3),d4 ; outline area width (pixels) move.l d4,d1 swap d1 moveq #pt.spxlw,d0 add.w #pt.rpxlw,d1 ; round up to... lsr.w d0,d1 ; ...width in long words addq.w #1,d1 ; one spare move.w d1,d6 ; save that mulu d4,d1 ; space required in words asl.l #2,d1 ; space in bytes ; move.l a3,a5 ; allocate common heap moveq #sms.achp,d0 moveq #0,d2 trap #1 move.l a5,a3 tst.l d0 ; OK? bne.s ptw_removexit ; ... no ; move.l a0,sd_wsave(a4) ; set pointer in cdb move.l d1,sd_wssiz(a4) ; set length in cdb st sd_mysav(a4) ; set save area owner move.l a4,a0 move.l stk_d2(sp),d2 move.l stk_a1(sp),a1 jsr pt_fillsv ; fill the save area ptw_redraw moveq #sd.wbprm,d1 bsr.s ptw_crchan ; allocate channel block bne.s ptw_exit ; ...oops move.l a0,-(sp) moveq #1,d3 ; lock all windows jsr pt_wchka move.l (sp),a0 jsr pt_wremv ; remove dummy window moveq #0,d3 ; reset locks jsr pt_wchka jsr pt_mrall move.l (sp)+,a0 ; remove dummy channel block suba.l #sd.extnl,a0 movem.l a2-a3,-(sp) ; save smashed registers on QDOS systems move.w mem.rchp,a1 jsr (a1) movem.l (sp)+,a2-a3 ptw_exok move.l pt_bgcld(a3),d1 ; return last colour set moveq #0,d0 ptw_exit movem.l (sp)+,ptw.reg rts ptw_removexit move.l d0,-(sp) bsr.s ptw_remove move.l (sp)+,d0 bra.s ptw_exit ; ptw_ipar moveq #err.ipar,d0 bra.s ptw_exit ;+++ ; Allocate and fill a channel definition block. ; ; D0 r 0 or error code ; D1 c s window type (sd.wpapr, sd.wbprm) ; A0 r address of block ; A3 c p DDDB ;--- ptw_crchan ptcc.reg reg d1-d3/a1-a3 stk_d1 equ 0 stk_a3 equ 5*4 chblock setnum sd.extnl+sd_keyq+8 movem.l ptcc.reg,-(sp) move.l #[chblock],d1 ; allocate enough space for one block move.w mem.achp,a2 jsr (a2) ; allocate heap tst.l d0 bne.l ptcc_exit ; ...oops move.l stk_a3(sp),a3 lea iod_iolk(a3),a2 move.l a2,chn_drvr(a0) ; set driver add.w #sd.extnl,a0 move.l stk_d1(sp),d1 move.b d1,sd_behav(a0) ; wallpaper move.b pt_dmode(a3),sd_wmode(a0) st sd_wlstt(a0) ; locked clr.l sd_xmin(a0) ; set origin clr.l sd_xouto(a0) clr.l sd_xhito(a0) move.l pt_ssize(a3),d1 move.l d1,sd_xsize(a0) ; set size move.l d1,sd_xouts(a0) move.l d1,sd_xhits(a0) move.l pt_scren(a3),sd_scrb(a0) ; active area is in here move.w pt_scinc(a3),sd_linel(a0) ; and with this row increment moveq #0,d0 ptcc_exit movem.l (sp)+,ptcc.reg rts ptwr.reg reg d2-d3/a0-a3 ptw_remove movem.l ptwr.reg,-(sp) move.l pt_tail(a3),a4 ; point to bottom cmp.b #sd.wpapr,sd_behav-sd_prwlb(a4) ; wallpaper? bne.s ptw_rset ; ... no, set return value move.l (a4),a1 ; next one up move.l a1,pt_tail(a3) ; unlink from bottom up clr.l sd_prwlt-sd_prwlb(a1) move.l sd_wsave-sd_prwlb(a4),d0; save area beq.s ptw_rchn ; ... none move.l d0,a0 moveq #sms.rchp,d0 ; return it trap #1 ptw_rchn lea -sd_prwlb-sd.extnl(a4),a0 move.w mem.rchp,a2 jsr (a2) ; return channel block ptw_rset movem.l (sp)+,ptwr.reg rts end
; A170778: a(n) = n^8*(n^6 + 1)/2. ; 0,1,8320,2394765,134250496,3051953125,39182921856,339114418825,2199031644160,11438417750841,50000050000000,189875023971061,641959447265280,1968688600715005,5556004150673536,14596464294140625,36028799166447616,84188916767579185,187406689301020800,399503351383223581,819200012800000000,1621959985172184021,3110910664151847040,5796418201424867545,10517860116621950976,18626451568603515625,32254987456062107776,54709494706970947845,91029560103872266240,148779116588022938221,239148450328050000000 mov $1,$0 pow $0,8 mov $2,$1 pow $2,6 mul $2,$0 add $0,$2 div $0,2
// Module name: AVS .kernel PL2_TO_PL3 .code #include "VP_Setup.g8a" #include "Set_Layer_0.g8a" #include "Set_AVS_Buf_0123_PL2.g8a" #include "PL2_AVS_Buf_0.g8a" #include "PL2_AVS_Buf_1.g8a" #include "PL2_AVS_Buf_2.g8a" #include "PL2_AVS_Buf_3.g8a" #include "Save_AVS_PL3.g8a" #include "EOT.g8a" .end_code .end_kernel
// Copyright (c) 2011-2014 The Bitcoin developers // Copyright (c) 2014-2015 The Dash developers // Copyright (c) 2015-2017 The PIVX developers // Copyright (c) 2018 The Atheneum developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "transactiondesc.h" #include "bitcoinunits.h" #include "guiutil.h" #include "paymentserver.h" #include "transactionrecord.h" #include "base58.h" #include "db.h" #include "main.h" #include "script/script.h" #include "timedata.h" #include "ui_interface.h" #include "util.h" #include "wallet.h" #include <stdint.h> #include <string> using namespace std; QString TransactionDesc::FormatTxStatus(const CWalletTx& wtx) { AssertLockHeld(cs_main); if (!IsFinalTx(wtx, chainActive.Height() + 1)) { if (wtx.nLockTime < LOCKTIME_THRESHOLD) return tr("Open for %n more block(s)", "", wtx.nLockTime - chainActive.Height()); else return tr("Open until %1").arg(GUIUtil::dateTimeStr(wtx.nLockTime)); } else { int signatures = wtx.GetTransactionLockSignatures(); QString strUsingIX = ""; if (signatures >= 0) { if (signatures >= SWIFTTX_SIGNATURES_REQUIRED) { int nDepth = wtx.GetDepthInMainChain(); if (nDepth < 0) return tr("conflicted"); else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0) return tr("%1/offline (verified via SwiftX)").arg(nDepth); else if (nDepth < 6) return tr("%1/confirmed (verified via SwiftX)").arg(nDepth); else return tr("%1 confirmations (verified via SwiftX)").arg(nDepth); } else { if (!wtx.IsTransactionLockTimedOut()) { int nDepth = wtx.GetDepthInMainChain(); if (nDepth < 0) return tr("conflicted"); else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0) return tr("%1/offline (SwiftX verification in progress - %2 of %3 signatures)").arg(nDepth).arg(signatures).arg(SWIFTTX_SIGNATURES_TOTAL); else if (nDepth < 6) return tr("%1/confirmed (SwiftX verification in progress - %2 of %3 signatures )").arg(nDepth).arg(signatures).arg(SWIFTTX_SIGNATURES_TOTAL); else return tr("%1 confirmations (SwiftX verification in progress - %2 of %3 signatures)").arg(nDepth).arg(signatures).arg(SWIFTTX_SIGNATURES_TOTAL); } else { int nDepth = wtx.GetDepthInMainChain(); if (nDepth < 0) return tr("conflicted"); else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0) return tr("%1/offline (SwiftX verification failed)").arg(nDepth); else if (nDepth < 6) return tr("%1/confirmed (SwiftX verification failed)").arg(nDepth); else return tr("%1 confirmations").arg(nDepth); } } } else { int nDepth = wtx.GetDepthInMainChain(); if (nDepth < 0) return tr("conflicted"); else if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0) return tr("%1/offline").arg(nDepth); else if (nDepth < 6) return tr("%1/unconfirmed").arg(nDepth); else return tr("%1 confirmations").arg(nDepth); } } } QString TransactionDesc::toHTML(CWallet* wallet, CWalletTx& wtx, TransactionRecord* rec, int unit) { QString strHTML; LOCK2(cs_main, wallet->cs_wallet); strHTML.reserve(4000); strHTML += "<html><font face='verdana, arial, helvetica, sans-serif'>"; int64_t nTime = wtx.GetTxTime(); CAmount nCredit = wtx.GetCredit(ISMINE_ALL); CAmount nDebit = wtx.GetDebit(ISMINE_ALL); CAmount nNet = nCredit - nDebit; strHTML += "<b>" + tr("Status") + ":</b> " + FormatTxStatus(wtx); int nRequests = wtx.GetRequestCount(); if (nRequests != -1) { if (nRequests == 0) strHTML += tr(", has not been successfully broadcast yet"); else if (nRequests > 0) strHTML += tr(", broadcast through %n node(s)", "", nRequests); } strHTML += "<br>"; strHTML += "<b>" + tr("Date") + ":</b> " + (nTime ? GUIUtil::dateTimeStr(nTime) : "") + "<br>"; // // From // if (wtx.IsCoinBase()) { strHTML += "<b>" + tr("Source") + ":</b> " + tr("Generated") + "<br>"; } else if (wtx.mapValue.count("from") && !wtx.mapValue["from"].empty()) { // Online transaction strHTML += "<b>" + tr("From") + ":</b> " + GUIUtil::HtmlEscape(wtx.mapValue["from"]) + "<br>"; } else { // Offline transaction if (nNet > 0) { // Credit if (CBitcoinAddress(rec->address).IsValid()) { CTxDestination address = CBitcoinAddress(rec->address).Get(); if (wallet->mapAddressBook.count(address)) { strHTML += "<b>" + tr("From") + ":</b> " + tr("unknown") + "<br>"; strHTML += "<b>" + tr("To") + ":</b> "; strHTML += GUIUtil::HtmlEscape(rec->address); QString addressOwned = (::IsMine(*wallet, address) == ISMINE_SPENDABLE) ? tr("own address") : tr("watch-only"); if (!wallet->mapAddressBook[address].name.empty()) strHTML += " (" + addressOwned + ", " + tr("label") + ": " + GUIUtil::HtmlEscape(wallet->mapAddressBook[address].name) + ")"; else strHTML += " (" + addressOwned + ")"; strHTML += "<br>"; } } } } // // To // if (wtx.mapValue.count("to") && !wtx.mapValue["to"].empty()) { // Online transaction std::string strAddress = wtx.mapValue["to"]; strHTML += "<b>" + tr("To") + ":</b> "; CTxDestination dest = CBitcoinAddress(strAddress).Get(); if (wallet->mapAddressBook.count(dest) && !wallet->mapAddressBook[dest].name.empty()) strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[dest].name) + " "; strHTML += GUIUtil::HtmlEscape(strAddress) + "<br>"; } // // Amount // if (wtx.IsCoinBase() && nCredit == 0) { // // Coinbase // CAmount nUnmatured = 0; BOOST_FOREACH (const CTxOut& txout, wtx.vout) nUnmatured += wallet->GetCredit(txout, ISMINE_ALL); strHTML += "<b>" + tr("Credit") + ":</b> "; if (wtx.IsInMainChain()) strHTML += BitcoinUnits::formatHtmlWithUnit(unit, nUnmatured) + " (" + tr("matures in %n more block(s)", "", wtx.GetBlocksToMaturity()) + ")"; else strHTML += "(" + tr("not accepted") + ")"; strHTML += "<br>"; } else if (nNet > 0) { // // Credit // strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, nNet) + "<br>"; } else { isminetype fAllFromMe = ISMINE_SPENDABLE; BOOST_FOREACH (const CTxIn& txin, wtx.vin) { isminetype mine = wallet->IsMine(txin); if (fAllFromMe > mine) fAllFromMe = mine; } isminetype fAllToMe = ISMINE_SPENDABLE; BOOST_FOREACH (const CTxOut& txout, wtx.vout) { isminetype mine = wallet->IsMine(txout); if (fAllToMe > mine) fAllToMe = mine; } if (fAllFromMe) { if (fAllFromMe == ISMINE_WATCH_ONLY) strHTML += "<b>" + tr("From") + ":</b> " + tr("watch-only") + "<br>"; // // Debit // BOOST_FOREACH (const CTxOut& txout, wtx.vout) { // Ignore change isminetype toSelf = wallet->IsMine(txout); if ((toSelf == ISMINE_SPENDABLE) && (fAllFromMe == ISMINE_SPENDABLE)) continue; if (!wtx.mapValue.count("to") || wtx.mapValue["to"].empty()) { // Offline transaction CTxDestination address; if (ExtractDestination(txout.scriptPubKey, address)) { strHTML += "<b>" + tr("To") + ":</b> "; if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].name.empty()) strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[address].name) + " "; strHTML += GUIUtil::HtmlEscape(CBitcoinAddress(address).ToString()); if (toSelf == ISMINE_SPENDABLE) strHTML += " (own address)"; else if (toSelf == ISMINE_WATCH_ONLY) strHTML += " (watch-only)"; strHTML += "<br>"; } } strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -txout.nValue) + "<br>"; if (toSelf) strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, txout.nValue) + "<br>"; } if (fAllToMe) { // Payment to self CAmount nChange = wtx.GetChange(); CAmount nValue = nCredit - nChange; strHTML += "<b>" + tr("Total debit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -nValue) + "<br>"; strHTML += "<b>" + tr("Total credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, nValue) + "<br>"; } CAmount nTxFee = nDebit - wtx.GetValueOut(); if (nTxFee > 0) strHTML += "<b>" + tr("Transaction fee") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -nTxFee) + "<br>"; } else { // // Mixed debit transaction // BOOST_FOREACH (const CTxIn& txin, wtx.vin) if (wallet->IsMine(txin)) strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -wallet->GetDebit(txin, ISMINE_ALL)) + "<br>"; BOOST_FOREACH (const CTxOut& txout, wtx.vout) if (wallet->IsMine(txout)) strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, wallet->GetCredit(txout, ISMINE_ALL)) + "<br>"; } } strHTML += "<b>" + tr("Net amount") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, nNet, true) + "<br>"; // // Message // if (wtx.mapValue.count("message") && !wtx.mapValue["message"].empty()) strHTML += "<br><b>" + tr("Message") + ":</b><br>" + GUIUtil::HtmlEscape(wtx.mapValue["message"], true) + "<br>"; if (wtx.mapValue.count("comment") && !wtx.mapValue["comment"].empty()) strHTML += "<br><b>" + tr("Comment") + ":</b><br>" + GUIUtil::HtmlEscape(wtx.mapValue["comment"], true) + "<br>"; strHTML += "<b>" + tr("Transaction ID") + ":</b> " + rec->getTxID() + "<br>"; strHTML += "<b>" + tr("Output index") + ":</b> " + QString::number(rec->getOutputIndex()) + "<br>"; // Message from normal atheneum:URI (atheneum:XyZ...?message=example) foreach (const PAIRTYPE(string, string) & r, wtx.vOrderForm) if (r.first == "Message") strHTML += "<br><b>" + tr("Message") + ":</b><br>" + GUIUtil::HtmlEscape(r.second, true) + "<br>"; // // PaymentRequest info: // foreach (const PAIRTYPE(string, string) & r, wtx.vOrderForm) { if (r.first == "PaymentRequest") { PaymentRequestPlus req; req.parse(QByteArray::fromRawData(r.second.data(), r.second.size())); QString merchant; if (req.getMerchant(PaymentServer::getCertStore(), merchant)) strHTML += "<b>" + tr("Merchant") + ":</b> " + GUIUtil::HtmlEscape(merchant) + "<br>"; } } if (wtx.IsCoinBase()) { quint32 numBlocksToMaturity = Params().COINBASE_MATURITY() + 1; strHTML += "<br>" + tr("Generated coins must mature %1 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, its state will change to \"not accepted\" and it won't be spendable. This may occasionally happen if another node generates a block within a few seconds of yours.").arg(QString::number(numBlocksToMaturity)) + "<br>"; } // // Debug view // if (fDebug) { strHTML += "<hr><br>" + tr("Debug information") + "<br><br>"; BOOST_FOREACH (const CTxIn& txin, wtx.vin) if (wallet->IsMine(txin)) strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -wallet->GetDebit(txin, ISMINE_ALL)) + "<br>"; BOOST_FOREACH (const CTxOut& txout, wtx.vout) if (wallet->IsMine(txout)) strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, wallet->GetCredit(txout, ISMINE_ALL)) + "<br>"; strHTML += "<br><b>" + tr("Transaction") + ":</b><br>"; strHTML += GUIUtil::HtmlEscape(wtx.ToString(), true); strHTML += "<br><b>" + tr("Inputs") + ":</b>"; strHTML += "<ul>"; BOOST_FOREACH (const CTxIn& txin, wtx.vin) { COutPoint prevout = txin.prevout; CCoins prev; if (pcoinsTip->GetCoins(prevout.hash, prev)) { if (prevout.n < prev.vout.size()) { strHTML += "<li>"; const CTxOut& vout = prev.vout[prevout.n]; CTxDestination address; if (ExtractDestination(vout.scriptPubKey, address)) { if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].name.empty()) strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[address].name) + " "; strHTML += QString::fromStdString(CBitcoinAddress(address).ToString()); } strHTML = strHTML + " " + tr("Amount") + "=" + BitcoinUnits::formatHtmlWithUnit(unit, vout.nValue); strHTML = strHTML + " IsMine=" + (wallet->IsMine(vout) & ISMINE_SPENDABLE ? tr("true") : tr("false")); strHTML = strHTML + " IsWatchOnly=" + (wallet->IsMine(vout) & ISMINE_WATCH_ONLY ? tr("true") : tr("false")) + "</li>"; } } } strHTML += "</ul>"; } strHTML += "</font></html>"; return strHTML; }
; PROLOGUE(mpn_xor_n) ; Version 1.0.4 ; ; Copyright 2008 Jason Moxham ; ; Windows Conversion Copyright 2008 Brian Gladman ; ; This file is part of the MPIR Library. ; The MPIR Library is free software; you can redistribute it and/or modify ; it under the terms of the GNU Lesser General Public License as published ; by the Free Software Foundation; either version 2.1 of the License, or (at ; your option) any later version. ; The MPIR Library is distributed in the hope that it will be useful, but ; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public ; License for more details. ; You should have received a copy of the GNU Lesser General Public License ; along with the MPIR Library; see the file COPYING.LIB. If not, write ; to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ; Boston, MA 02110-1301, USA. ; ; void mpn_xor_n(mp_ptr, mp_srcptr, mp_srcptr, mp_size_t) ; rdi rsi rdx rcx ; rcx rdx r8 r9 %include "yasm_mac.inc" CPU Core2 BITS 64 %define T3 r10 %define T4 r11 LEAF_PROC mpn_xor_n sub r9, 4 jb .2 xalign 16 .1: mov r10, [r8+r9*8+24] mov r11, [r8+r9*8+16] or r10, r10 or r11, r11 xor r10, [rdx+r9*8+24] xor r11, [rdx+r9*8+16] mov [rcx+r9*8+24], r10 mov [rcx+r9*8+16], r11 mov T3, [r8+r9*8+8] mov T4, [r8+r9*8] or T3, T3 or T4, T4 xor T3, [rdx+r9*8+8] xor T4, [rdx+r9*8] mov [rcx+r9*8+8], T3 mov [rcx+r9*8], T4 sub r9, 4 jnc .1 .2: add r9, 4 jz .3 mov r10, [r8+r9*8-8] or r10, r10 xor r10, [rdx+r9*8-8] mov [rcx+r9*8-8], r10 sub r9, 1 ; *** jz .3 mov r10, [r8+r9*8-8] or r10, r10 xor r10, [rdx+r9*8-8] mov [rcx+r9*8-8], r10 sub r9, 1 ; *** jz .3 mov r10, [r8+r9*8-8] or r10, r10 xor r10, [rdx+r9*8-8] mov [rcx+r9*8-8], r10 .3: ret end
SECTION code_fp_math48 PUBLIC _exp2_fastcall EXTERN cm48_sdcciy_exp2_fastcall defc _exp2_fastcall = cm48_sdcciy_exp2_fastcall
; A017810: Binomial coefficients C(94,n). ; 1,94,4371,134044,3049501,54891018,814216767,10235867928,111315063717,1063677275518,9041256841903,69042324974532,477542747740513,3012192716517082,17427686431277403,92947660966812816,458929076023638279,2105674584108457986,9007607943130625829,36030431772522503316,135114119146959387435,476116419851190222390,1579840847688040283385,4945588740588647843640,14630700024241416537435,40965960067875966304818,108717355564747756732017,273806673274179535473228,655180253906072459882367,1491099888200026977663318 mov $1,94 bin $1,$0 mov $0,$1
==================== Asm code ==================== .section .text .align 8 .globl func1 .type func1, @function func1: _c2: movl $256,%ebx jmp *(%rbp) .size func1, .-func1
org 0x80000000 [BITS 32] start: mov esp,stack_end mov ebp,esp push 0x23 ; ss push esp pushf pop eax or eax,0x200 ; IF push eax push 0x1b ; cs push usermode iret usermode: mov edx,.return mov ecx,esp mov esi,exec mov edi,0 mov eax,1 int 80h .return: jmp $ data: exec db "/initrd/autostart", 0 stack: times 0x1000 db 0 stack_end: times 4 db 0
.386 ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; 将参数列表的顺序翻转 ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> reverseArgs macro arglist:VARARG local txt,count ;TEXTEQU 伪指令,类似于 EQU,创建了文本宏(text macro) txt TEXTEQU <> count = 0 for i,<arglist> count = count + 1 txt TEXTEQU @CatStr(i,<!,>,<%txt>) endm if count GT 0 txt SUBSTR txt,1,@SizeStr(%txt)-1 endif exitm txt endm ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; 建立一个类似于 invoke 的 Macro ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> _invoke macro _Proc,args:VARARG local count count = 0 % for i,< reverseArgs( args ) > count = count + 1 push i endm call _Proc endm
<% import collections import pwnlib.abi import pwnlib.constants import pwnlib.shellcraft import six %> <%docstring>quotactl(cmd, special, id, addr) -> str Invokes the syscall quotactl. See 'man 2 quotactl' for more information. Arguments: cmd(int): cmd special(char*): special id(int): id addr(caddr_t): addr Returns: int </%docstring> <%page args="cmd=0, special=0, id=0, addr=0"/> <% abi = pwnlib.abi.ABI.syscall() stack = abi.stack regs = abi.register_arguments[1:] allregs = pwnlib.shellcraft.registers.current() can_pushstr = ['special'] can_pushstr_array = [] argument_names = ['cmd', 'special', 'id', 'addr'] argument_values = [cmd, special, id, addr] # Load all of the arguments into their destination registers / stack slots. register_arguments = dict() stack_arguments = collections.OrderedDict() string_arguments = dict() dict_arguments = dict() array_arguments = dict() syscall_repr = [] for name, arg in zip(argument_names, argument_values): if arg is not None: syscall_repr.append('%s=%s' % (name, pwnlib.shellcraft.pretty(arg, False))) # If the argument itself (input) is a register... if arg in allregs: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[index] = arg # The argument is not a register. It is a string value, and we # are expecting a string value elif name in can_pushstr and isinstance(arg, (six.binary_type, six.text_type)): if isinstance(arg, six.text_type): arg = arg.encode('utf-8') string_arguments[name] = arg # The argument is not a register. It is a dictionary, and we are # expecting K:V paris. elif name in can_pushstr_array and isinstance(arg, dict): array_arguments[name] = ['%s=%s' % (k,v) for (k,v) in arg.items()] # The arguent is not a register. It is a list, and we are expecting # a list of arguments. elif name in can_pushstr_array and isinstance(arg, (list, tuple)): array_arguments[name] = arg # The argument is not a register, string, dict, or list. # It could be a constant string ('O_RDONLY') for an integer argument, # an actual integer value, or a constant. else: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[target] = arg # Some syscalls have different names on various architectures. # Determine which syscall number to use for the current architecture. for syscall in ['SYS_quotactl']: if hasattr(pwnlib.constants, syscall): break else: raise Exception("Could not locate any syscalls: %r" % syscalls) %> /* quotactl(${', '.join(syscall_repr)}) */ %for name, arg in string_arguments.items(): ${pwnlib.shellcraft.pushstr(arg, append_null=(b'\x00' not in arg))} ${pwnlib.shellcraft.mov(regs[argument_names.index(name)], abi.stack)} %endfor %for name, arg in array_arguments.items(): ${pwnlib.shellcraft.pushstr_array(regs[argument_names.index(name)], arg)} %endfor %for name, arg in stack_arguments.items(): ${pwnlib.shellcraft.push(arg)} %endfor ${pwnlib.shellcraft.setregs(register_arguments)} ${pwnlib.shellcraft.syscall(syscall)}
; int isodigit(int c) SECTION code_ctype PUBLIC _isodigit EXTERN _isodigit_fastcall _isodigit: pop af pop hl push hl push af jp _isodigit_fastcall
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r14 push %r15 push %rbx push %rcx push %rdi push %rdx push %rsi lea addresses_WC_ht+0x1901e, %r14 nop nop nop inc %rdx mov $0x6162636465666768, %rbx movq %rbx, %xmm6 movups %xmm6, (%r14) dec %rbx lea addresses_WT_ht+0x721e, %rsi nop sub $61864, %rdi movb (%rsi), %r14b nop nop nop nop nop add $42660, %rdx lea addresses_WC_ht+0x1261e, %rbx nop nop nop nop add $50234, %r15 mov $0x6162636465666768, %r14 movq %r14, (%rbx) nop nop nop xor %rdi, %rdi lea addresses_WT_ht+0x1c29e, %rdi nop nop xor %r12, %r12 vmovups (%rdi), %ymm4 vextracti128 $1, %ymm4, %xmm4 vpextrq $1, %xmm4, %r15 nop nop nop nop lfence lea addresses_WT_ht+0xfc1e, %r14 nop nop nop nop nop cmp %rdx, %rdx mov (%r14), %rsi nop nop cmp $41801, %r15 lea addresses_D_ht+0x43be, %rsi lea addresses_A_ht+0x1ede, %rdi nop nop nop nop nop inc %r15 mov $127, %rcx rep movsb nop nop nop nop sub $61214, %rdx lea addresses_WT_ht+0x112ce, %rdi nop cmp $35731, %r12 movb (%rdi), %r15b nop nop nop nop cmp $54468, %rdi lea addresses_UC_ht+0x13a1e, %rsi nop nop add %r12, %r12 mov $0x6162636465666768, %rdx movq %rdx, (%rsi) nop nop nop nop sub %rcx, %rcx lea addresses_normal_ht+0xbf1e, %r12 nop cmp $45654, %rcx mov (%r12), %edi nop nop nop nop add $56508, %r15 lea addresses_WC_ht+0x1ea3e, %rsi lea addresses_normal_ht+0x1321e, %rdi cmp $45253, %rdx mov $40, %rcx rep movsq nop nop nop sub $32516, %rcx pop %rsi pop %rdx pop %rdi pop %rcx pop %rbx pop %r15 pop %r14 pop %r12 ret .global s_faulty_load s_faulty_load: push %r11 push %r14 push %r9 push %rax push %rbp push %rbx push %rcx // Store lea addresses_D+0x898e, %r9 nop nop nop nop add %rbp, %rbp movl $0x51525354, (%r9) nop nop nop cmp $20935, %rbx // Store lea addresses_WT+0xe39e, %rax nop nop and $51959, %rcx mov $0x5152535455565758, %rbx movq %rbx, %xmm4 movups %xmm4, (%rax) nop nop nop and %r11, %r11 // Store lea addresses_RW+0x13f4e, %rbp nop cmp %r11, %r11 movb $0x51, (%rbp) nop nop nop nop nop sub %r14, %r14 // Faulty Load lea addresses_A+0x1dc1e, %rax nop nop nop add %r14, %r14 movups (%rax), %xmm5 vpextrq $0, %xmm5, %rbp lea oracles, %r14 and $0xff, %rbp shlq $12, %rbp mov (%r14,%rbp,1), %rbp pop %rcx pop %rbx pop %rbp pop %rax pop %r9 pop %r14 pop %r11 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 32, 'AVXalign': True, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'size': 1, 'AVXalign': True, 'NT': False, 'congruent': 4, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': True}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 6, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 7, 'same': False}} {'00': 7910} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
Results_screen_2p_Header: smpsHeaderStartSong 2 smpsHeaderVoice Results_screen_2p_Voices smpsHeaderChan $06, $03 smpsHeaderTempo $01, $68 smpsHeaderDAC Results_screen_2p_DAC smpsHeaderFM Results_screen_2p_FM1, $F4, $10 smpsHeaderFM Results_screen_2p_FM2, $F4, $0C smpsHeaderFM Results_screen_2p_FM3, $F4, $19 smpsHeaderFM Results_screen_2p_FM4, $F4, $10 smpsHeaderFM Results_screen_2p_FM5, $F4, $11 smpsHeaderPSG Results_screen_2p_PSG1, $D0, $01, $00, $00 smpsHeaderPSG Results_screen_2p_PSG2, $D0, $01, $00, $00 smpsHeaderPSG Results_screen_2p_PSG3, $D0, $01, $00, $00 ; FM1 Data Results_screen_2p_FM1: smpsSetvoice $04 smpsModSet $02, $01, $01, $01 smpsPan panRight, $00 smpsAlterVol $03 dc.b nRst, $02 smpsCall Results_screen_2p_Call03 dc.b nD6, $16 smpsAlterVol $FD smpsSetvoice $05 smpsPan panRight, $00 smpsAlterVol $FB smpsCall Results_screen_2p_Call01 smpsCall Results_screen_2p_Call01 smpsAlterVol $05 smpsPan panCenter, $00 smpsSetvoice $01 smpsCall Results_screen_2p_Call05 dc.b nRst, $18, nD5, $03, nB4, nRst, nD5, nRst, $0C, nRst, $18, nCs5 dc.b $03, nCs5, nRst, nCs5, nA4, $06, nCs5 smpsCall Results_screen_2p_Call05 dc.b nRst, $0C, nB4, nRst, nCs5, nRst, nD5, nRst, nE5, nRst, $18, nD6 dc.b $0C, nCs6 smpsJump Results_screen_2p_FM1 Results_screen_2p_Call03: smpsCall Results_screen_2p_Call0C dc.b nA6, $06, nB6, nA6, $18 smpsCall Results_screen_2p_Call0C dc.b nFs6, $06, nE6 smpsReturn Results_screen_2p_Call0C: dc.b nB6, $0C, nCs7, $06, nD7, nA6, $0C, nFs6, $06, nD6, nG6, $0C smpsReturn Results_screen_2p_Call01: smpsCall Results_screen_2p_Call0B dc.b nE6, nRst, nE6, nRst, nFs6, nFs6, nRst, nD6, nRst, $18 smpsCall Results_screen_2p_Call0B dc.b nRst, $03, nG6, nRst, nFs6, nE6, nRst, nD6, nD6, nRst, $18 smpsReturn Results_screen_2p_Call0B: dc.b nE6, $03, nRst, nE6, nRst, nFs6, nFs6, nRst, nD6, nRst, nD6, nRst dc.b nA5, nB5, $06, nD6, $03, nRst smpsReturn Results_screen_2p_Call05: dc.b nRst, $18, nD5, $03, nB4, nRst, nD5, nRst, $0C, nRst, $18, nCs5 dc.b $03, nA4, nRst, nCs5, nRst, $0C smpsReturn ; FM2 Data Results_screen_2p_FM2: smpsSetvoice $00 Results_screen_2p_Loop01: dc.b nD3, $06, nD4, $03, $03, nD3, $06, nD4 smpsLoop $00, $18, Results_screen_2p_Loop01 smpsCall Results_screen_2p_Call04 Results_screen_2p_Loop02: dc.b nE3, nE4, $03, $03, nE3, $06, nE4 smpsLoop $00, $02, Results_screen_2p_Loop02 Results_screen_2p_Loop03: dc.b nFs3, nFs4, $03, $03, nFs3, $06, nFs4 smpsLoop $00, $02, Results_screen_2p_Loop03 smpsCall Results_screen_2p_Call04 dc.b nE3, nE4, $03, $03, nE3, $06, nE4, nFs3, nFs4, $03, $03, nFs3 dc.b $06, nFs4, nG3, nG4, $03, $03, nG3, $06, nG4, nA3, nA4, $03 dc.b $03, nA3, $06, nA4, nA3, nA4, nA3, nA4, nA3, $0C, $0C smpsJump Results_screen_2p_Loop01 Results_screen_2p_Call04: dc.b nG3, nG4, $03, $03, nG3, $06, nG4 smpsLoop $01, $02, Results_screen_2p_Call04 Results_screen_2p_Loop04: dc.b nFs3, nFs4, $03, $03, nFs3, $06, nFs4 smpsLoop $01, $02, Results_screen_2p_Loop04 smpsReturn ; FM3 Data Results_screen_2p_FM3: smpsSetvoice $02 smpsCall Results_screen_2p_Call00 smpsAlterVol $F9 dc.b nRst, $1E, nA4, $03, nB4, nD5, nRst, $09, nRst, $1E, nE5, $03 dc.b nFs5, nD5, nRst, $09, nRst, $1E, nA4, $03, nB4, nD5, nRst, $09 dc.b nRst, $18, nFs5, $03, nFs5, nRst, nFs5, nE5, $06, nD5, nRst, $1E dc.b nA4, $03, nB4, nD5, nRst, $09, nRst, $1E, nFs5, $06, nD5, $03 dc.b nRst, $09, nRst, $1E, nA4, $03, nB4, nD5, nRst, $09, nRst, $18 dc.b nG5, $03, nFs5, nG5, nAb5, nA5, nRst, nD6, nRst smpsAlterVol $07 smpsSetvoice $01 smpsAlterVol $F2 smpsPan panRight, $00 smpsCall Results_screen_2p_Call02 smpsPan panCenter, $00 smpsAlterVol $0E smpsJump Results_screen_2p_FM3 Results_screen_2p_Call02: dc.b nD6, $1E, nB5, $03, nCs6, nD6, $06, nB5, $03, nRst, nCs6, $1B dc.b nA5, $03, nRst, nB5, nCs6, $06, nA5, nB5, $1E, nA5, $03, nRst dc.b nB5, $06, nA5, nCs6, $0C, nB5, $06, nA5, $12, nB5, $06, nCs6 dc.b nD6, $1E, nB5, $03, nCs6, nD6, nRst, nB5, $06, nCs6, $1E, nA5 dc.b $03, nB5, nCs6, nRst, nA5, $06, nB5, $12, nA5, $03, nB5, nCs6 dc.b $12, nB5, $03, nCs6, nD6, $12, nCs6, $03, nD6, nE6, $30, nFs6 dc.b $0C, nE6 smpsReturn Results_screen_2p_Call00: dc.b nRst, $1E, nA4, $03, nB4, nD5, nRst, $09, nRst, $1E, nE5, $03 dc.b nFs5, nD5, nRst, $09, nRst, $1E, nA4, $03, nB4, nD5, nRst, $09 dc.b nRst, $18, nG5, $03, nFs5, nG5, nAb5, nA5, nD5, nRst, nD5, $03 smpsReturn ; FM5 Data Results_screen_2p_FM5: smpsSetvoice $03 smpsModSet $02, $01, $01, $01 Results_screen_2p_Jump00: smpsPan panLeft, $00 smpsAlterVol $02 smpsCall Results_screen_2p_Call03 dc.b nD6, $18 smpsPan panCenter, $00 smpsAlterVol $FE dc.b nRst, $30, nRst, nRst, nRst, $2A smpsAlterVol $03 dc.b nB5, $03, nCs6, nD6, $18, nCs6, nB5, nA5, nG5, nFs5, nRst, $03 dc.b nB5, $03, nRst, nA5, nG5, nRst, nFs5, nFs5, nRst, $18 smpsAlterVol $FD smpsAlterVol $03 Results_screen_2p_Loop00: dc.b nA6, $03, nG6, nFs6, nE6 smpsLoop $00, $18, Results_screen_2p_Loop00 smpsAlterVol $FD dc.b nRst, $0C, nD6, nRst, nE6, nRst, nFs6, nRst, nG6, $18, nRst, $24 smpsJump Results_screen_2p_Jump00 ; FM4 Data Results_screen_2p_FM4: smpsSetvoice $01 smpsAlterVol $FE smpsAlterNote $02 smpsCall Results_screen_2p_Call00 smpsAlterVol $02 smpsSetvoice $01 smpsPan panLeft, $00 smpsAlterVol $FB smpsCall Results_screen_2p_Call01 smpsCall Results_screen_2p_Call01 smpsAlterVol $05 smpsAlterPitch $F4 smpsAlterVol $FB smpsCall Results_screen_2p_Call02 smpsAlterPitch $0C smpsAlterVol $05 smpsPan panCenter, $00 smpsJump Results_screen_2p_FM4 ; PSG1 Data Results_screen_2p_PSG1: smpsPSGvoice fTone_04 smpsNoteFill $0A Results_screen_2p_Jump03: smpsCall Results_screen_2p_Call09 smpsPSGAlterVol $01 smpsCall Results_screen_2p_Call09 smpsCall Results_screen_2p_Call09 smpsCall Results_screen_2p_Call0A dc.b nRst, $03, nB5, $06, $03, $06, nG5, $09, nB5, $06, $03, $06 dc.b nG5, nRst, $03, nCs6, $06, $03, $06, nA5, $09, nCs6, $06, $09 dc.b nA5, $06 smpsCall Results_screen_2p_Call0A smpsCall Results_screen_2p_Call08 dc.b nCs6, $03, nE6, $0C, $24 smpsPSGAlterVol $FF smpsJump Results_screen_2p_Jump03 Results_screen_2p_Call08: dc.b nB5, $03, nG5, nB5, nG5, nB5, nG5, nB5, nG5, nCs6, nA5, nCs6 dc.b nA5, nCs6, nA5, nCs6, nA5, nD6, nB5, nD6, nB5, nD6, nB5, nD6 dc.b nB5, nE6, nCs6, nE6, nCs6, nE6, nCs6, nE6 smpsReturn Results_screen_2p_Call09: dc.b nB5, $09, $09, nA5, $1E, nG5, $09, $09, nA5, $1E, nB5, $09 dc.b $09, nA5, $1E, nG5, $09, nA5, nFs5, $1E smpsReturn Results_screen_2p_Call0A: dc.b nRst, $03, nD6, $06, $03, $06, nB5, $09, nD6, $06, $03, $06 dc.b nB5, nRst, $03, nCs6, $06, $03, $06, nA5, $09, nCs6, $06, $03 dc.b $06, nA5 smpsReturn ; PSG2 Data Results_screen_2p_PSG2: smpsPSGvoice fTone_04 smpsNoteFill $0A Results_screen_2p_Jump02: smpsCall Results_screen_2p_Call06 smpsPSGAlterVol $01 smpsCall Results_screen_2p_Call06 smpsCall Results_screen_2p_Call06 smpsCall Results_screen_2p_Call07 dc.b nRst, $03, nG5, $06, $03, $06, nE5, $09, nG5, $06, $03, $06 dc.b nE5, nRst, $03, nA5, $06, $03, $06, nFs5, $09, nA5, $06, $09 dc.b nFs5, $06 smpsCall Results_screen_2p_Call07 dc.b nRst, $01 smpsCall Results_screen_2p_Call08 dc.b nCs6, $02, nCs6, $0C, $24 smpsPSGAlterVol $FF smpsJump Results_screen_2p_Jump02 Results_screen_2p_Call06: dc.b nG5, $09, $09, nFs5, $1E, nE5, $09, $09, nFs5, $1E, nG5, $09 dc.b $09, nFs5, $1E, nE5, $09, nFs5, nD5, $1E smpsReturn Results_screen_2p_Call07: dc.b nRst, $03, nB5, $06, $03, $06, nG5, $09, nB5, $06, $03, $06 dc.b nG5, nRst, $03, nA5, $06, $03, $06, nFs5, $09, nA5, $06, $03 dc.b nCs6, $06, nFs5 smpsReturn ; PSG3 Data Results_screen_2p_PSG3: smpsPSGvoice fTone_02 smpsNoteFill $04 Results_screen_2p_Jump01: dc.b nF6, $06, nD6, $03, $03, nF6, nRst, nD6, nRst smpsJump Results_screen_2p_Jump01 ; DAC Data Results_screen_2p_DAC: dc.b dKick, $06, nRst, $03, dKick, dKick, $06, dMidTom, dKick, $06, nRst, $03 dc.b dKick, dKick, $06, dMidTom, dKick, $06, nRst, $03, dKick, dKick, $06, dMidTom dc.b dKick, $03, $06, $03, $06, dMidTom, $06 smpsLoop $00, $0A, Results_screen_2p_DAC dc.b dKick, $06, dMidTom, $06, $06, $06, $0C, $0C smpsJump Results_screen_2p_DAC Results_screen_2p_Voices: ; Voice $00 ; $08 ; $09, $70, $30, $00, $1F, $1F, $5F, $5F, $12, $0E, $0A, $0A ; $00, $04, $04, $03, $2F, $2F, $2F, $2F, $25, $30, $13, $80 smpsVcAlgorithm $00 smpsVcFeedback $01 smpsVcUnusedBits $00 smpsVcDetune $00, $03, $07, $00 smpsVcCoarseFreq $00, $00, $00, $09 smpsVcRateScale $01, $01, $00, $00 smpsVcAttackRate $1F, $1F, $1F, $1F smpsVcAmpMod $00, $00, $00, $00 smpsVcDecayRate1 $0A, $0A, $0E, $12 smpsVcDecayRate2 $03, $04, $04, $00 smpsVcDecayLevel $02, $02, $02, $02 smpsVcReleaseRate $0F, $0F, $0F, $0F smpsVcTotalLevel $00, $13, $30, $25 ; Voice $01 ; $3A ; $01, $07, $01, $01, $8E, $8E, $8D, $53, $0E, $0E, $0E, $03 ; $00, $00, $00, $00, $1F, $FF, $1F, $0F, $17, $28, $27, $80 smpsVcAlgorithm $02 smpsVcFeedback $07 smpsVcUnusedBits $00 smpsVcDetune $00, $00, $00, $00 smpsVcCoarseFreq $01, $01, $07, $01 smpsVcRateScale $01, $02, $02, $02 smpsVcAttackRate $13, $0D, $0E, $0E smpsVcAmpMod $00, $00, $00, $00 smpsVcDecayRate1 $03, $0E, $0E, $0E smpsVcDecayRate2 $00, $00, $00, $00 smpsVcDecayLevel $00, $01, $0F, $01 smpsVcReleaseRate $0F, $0F, $0F, $0F smpsVcTotalLevel $00, $27, $28, $17 ; Voice $02 ; $3A ; $03, $08, $03, $01, $8E, $8E, $8D, $53, $0E, $0E, $0E, $03 ; $00, $00, $00, $00, $1F, $FF, $1F, $0F, $17, $28, $20, $80 smpsVcAlgorithm $02 smpsVcFeedback $07 smpsVcUnusedBits $00 smpsVcDetune $00, $00, $00, $00 smpsVcCoarseFreq $01, $03, $08, $03 smpsVcRateScale $01, $02, $02, $02 smpsVcAttackRate $13, $0D, $0E, $0E smpsVcAmpMod $00, $00, $00, $00 smpsVcDecayRate1 $03, $0E, $0E, $0E smpsVcDecayRate2 $00, $00, $00, $00 smpsVcDecayLevel $00, $01, $0F, $01 smpsVcReleaseRate $0F, $0F, $0F, $0F smpsVcTotalLevel $00, $20, $28, $17 ; Voice $03 ; $3D ; $61, $34, $03, $72, $0E, $0C, $8D, $0D, $08, $05, $05, $05 ; $00, $00, $00, $00, $1F, $2F, $2F, $2F, $19, $99, $9E, $80 smpsVcAlgorithm $05 smpsVcFeedback $07 smpsVcUnusedBits $00 smpsVcDetune $07, $00, $03, $06 smpsVcCoarseFreq $02, $03, $04, $01 smpsVcRateScale $00, $02, $00, $00 smpsVcAttackRate $0D, $0D, $0C, $0E smpsVcAmpMod $00, $00, $00, $00 smpsVcDecayRate1 $05, $05, $05, $08 smpsVcDecayRate2 $00, $00, $00, $00 smpsVcDecayLevel $02, $02, $02, $01 smpsVcReleaseRate $0F, $0F, $0F, $0F smpsVcTotalLevel $00, $1E, $19, $19 ; Voice $04 ; $3C ; $31, $02, $72, $03, $0F, $4D, $0F, $0D, $00, $02, $00, $02 ; $00, $00, $00, $00, $0F, $3F, $0F, $3F, $19, $80, $29, $8A smpsVcAlgorithm $04 smpsVcFeedback $07 smpsVcUnusedBits $00 smpsVcDetune $00, $07, $00, $03 smpsVcCoarseFreq $03, $02, $02, $01 smpsVcRateScale $00, $00, $01, $00 smpsVcAttackRate $0D, $0F, $0D, $0F smpsVcAmpMod $00, $00, $00, $00 smpsVcDecayRate1 $02, $00, $02, $00 smpsVcDecayRate2 $00, $00, $00, $00 smpsVcDecayLevel $03, $00, $03, $00 smpsVcReleaseRate $0F, $0F, $0F, $0F smpsVcTotalLevel $0A, $29, $00, $19 ; Voice $05 ; $3A ; $51, $05, $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, $05, $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
// Copyright (c) 2009 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 "chrome/browser/transport_security_persister.h" #include "base/file_path.h" #include "base/file_util.h" #include "base/message_loop.h" #include "base/path_service.h" #include "chrome/browser/chrome_thread.h" #include "chrome/common/chrome_paths.h" #include "net/base/transport_security_state.h" TransportSecurityPersister::TransportSecurityPersister() : state_is_dirty_(false) { } TransportSecurityPersister::~TransportSecurityPersister() { transport_security_state_->SetDelegate(NULL); } void TransportSecurityPersister::Initialize( net::TransportSecurityState* state, const FilePath& profile_path) { transport_security_state_ = state; state_file_ = profile_path.Append(FILE_PATH_LITERAL("TransportSecurity")); state->SetDelegate(this); Task* task = NewRunnableMethod(this, &TransportSecurityPersister::LoadState); ChromeThread::PostDelayedTask(ChromeThread::FILE, FROM_HERE, task, 1000); } void TransportSecurityPersister::LoadState() { AutoLock locked_(lock_); DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); std::string state; if (!file_util::ReadFileToString(state_file_, &state)) return; transport_security_state_->Deserialise(state); } void TransportSecurityPersister::StateIsDirty( net::TransportSecurityState* state) { // Runs on arbitary thread, may not block nor reenter // |transport_security_state_|. AutoLock locked_(lock_); DCHECK(state == transport_security_state_); if (state_is_dirty_) return; // we already have a serialisation scheduled Task* task = NewRunnableMethod(this, &TransportSecurityPersister::SerialiseState); ChromeThread::PostDelayedTask(ChromeThread::FILE, FROM_HERE, task, 1000); state_is_dirty_ = true; } void TransportSecurityPersister::SerialiseState() { AutoLock locked_(lock_); DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); DCHECK(state_is_dirty_); state_is_dirty_ = false; std::string state; if (!transport_security_state_->Serialise(&state)) return; file_util::WriteFile(state_file_, state.data(), state.size()); }
dnl HP-PA 2.0 32-bit mpn_add_n -- Add two limb vectors of the same length > 0 dnl and store sum in a third limb vector. dnl Copyright 1997, 1998, 2000, 2001, 2002 Free Software Foundation, Inc. dnl This file is part of the GNU MP Library. dnl The GNU MP Library is free software; you can redistribute it and/or modify dnl it under the terms of the GNU Lesser General Public License as published dnl by the Free Software Foundation; either version 3 of the License, or (at dnl your option) any later version. dnl The GNU MP Library is distributed in the hope that it will be useful, but dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public dnl License for more details. dnl You should have received a copy of the GNU Lesser General Public License dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. include(`../config.m4') C INPUT PARAMETERS C res_ptr gr26 C s1_ptr gr25 C s2_ptr gr24 C size gr23 C This runs at 2 cycles/limb on PA8000. ASM_START() PROLOGUE(mpn_add_n) sub %r0,%r23,%r22 zdep %r22,30,3,%r28 C r28 = 2 * (-n & 7) zdep %r22,29,3,%r22 C r22 = 4 * (-n & 7) sub %r25,%r22,%r25 C offset s1_ptr sub %r24,%r22,%r24 C offset s2_ptr sub %r26,%r22,%r26 C offset res_ptr blr %r28,%r0 C branch into loop add %r0,%r0,%r0 C reset carry LDEF(loop) ldw 0(%r25),%r20 ldw 0(%r24),%r31 addc %r20,%r31,%r20 stw %r20,0(%r26) LDEF(7) ldw 4(%r25),%r21 ldw 4(%r24),%r19 addc %r21,%r19,%r21 stw %r21,4(%r26) LDEF(6) ldw 8(%r25),%r20 ldw 8(%r24),%r31 addc %r20,%r31,%r20 stw %r20,8(%r26) LDEF(5) ldw 12(%r25),%r21 ldw 12(%r24),%r19 addc %r21,%r19,%r21 stw %r21,12(%r26) LDEF(4) ldw 16(%r25),%r20 ldw 16(%r24),%r31 addc %r20,%r31,%r20 stw %r20,16(%r26) LDEF(3) ldw 20(%r25),%r21 ldw 20(%r24),%r19 addc %r21,%r19,%r21 stw %r21,20(%r26) LDEF(2) ldw 24(%r25),%r20 ldw 24(%r24),%r31 addc %r20,%r31,%r20 stw %r20,24(%r26) LDEF(1) ldw 28(%r25),%r21 ldo 32(%r25),%r25 ldw 28(%r24),%r19 addc %r21,%r19,%r21 stw %r21,28(%r26) ldo 32(%r24),%r24 addib,> -8,%r23,L(loop) ldo 32(%r26),%r26 bv (%r2) addc %r0,%r0,%r28 EPILOGUE()
db "FIRE HORSE@" ; species name dw 507, 2090 ; height, weight db "It just loves to" next "gallop. The faster" next "it goes, the long-" page "er the swaying" next "flames of its mane" next "will become.@"
<% from pwnlib.shellcraft.i386.linux import dup2 %> <% from pwnlib.shellcraft.i386 import mov %> <% from pwnlib.shellcraft import common %> <%page args="sock = 'ebp'"/> <%docstring> Args: [sock (imm/reg) = ebp] Duplicates sock to stdin, stdout and stderr </%docstring> <% dup = common.label("dup") looplabel = common.label("loop") %> /* dup() file descriptor ${sock} into stdin/stdout/stderr */ ${dup}: ${mov('ebx', sock)} ${mov('ecx', 2)} ${looplabel}: ${dup2('ebx', 'ecx')} loop ${looplabel}
lh $6,16($0) or $3,$4,$3 sb $1,13($0) slti $1,$5,-26694 nor $3,$3,$3 addu $5,$4,$3 or $5,$3,$3 srlv $5,$6,$3 sh $4,6($0) lb $1,4($0) sw $1,4($0) srl $4,$4,16 lbu $1,9($0) andi $1,$4,52768 sllv $6,$3,$3 subu $5,$3,$3 xori $6,$1,43328 andi $3,$4,59432 xori $1,$3,21237 sllv $1,$3,$3 lhu $4,2($0) slti $3,$1,28354 xori $5,$0,13392 sb $4,4($0) addu $3,$3,$3 addu $4,$4,$3 addu $4,$4,$3 sll $6,$6,10 subu $1,$1,$3 and $3,$2,$3 lb $3,8($0) lhu $3,0($0) lb $2,5($0) addiu $5,$0,-31720 slt $5,$3,$3 addiu $1,$3,-19925 addu $3,$5,$3 sltu $5,$3,$3 lhu $4,12($0) lhu $4,6($0) sltiu $3,$4,626 ori $6,$6,55992 sltu $6,$1,$3 subu $4,$4,$3 sllv $3,$3,$3 xor $3,$3,$3 sw $3,8($0) subu $3,$4,$3 addiu $3,$5,-16597 srav $1,$1,$3 addu $3,$5,$3 or $1,$1,$3 or $3,$3,$3 lb $5,4($0) lw $5,16($0) subu $5,$5,$3 sw $5,4($0) addu $5,$4,$3 slti $1,$4,-14488 slt $5,$4,$3 srav $3,$5,$3 nor $3,$5,$3 andi $3,$3,16317 srav $5,$6,$3 sllv $5,$3,$3 addiu $3,$1,-16448 slti $3,$1,22100 sw $3,8($0) sh $6,8($0) sll $5,$5,12 sltu $5,$5,$3 lbu $5,13($0) xori $1,$1,61904 xor $5,$2,$3 andi $3,$1,63699 srl $6,$4,29 subu $6,$1,$3 sh $4,16($0) addu $3,$4,$3 lbu $3,0($0) subu $3,$3,$3 sllv $4,$3,$3 ori $5,$5,41503 sll $3,$3,21 lw $3,16($0) sh $5,4($0) lhu $4,8($0) lh $3,10($0) subu $4,$4,$3 sll $3,$4,22 lh $5,10($0) srav $4,$4,$3 sltu $4,$0,$3 addiu $1,$4,22931 lw $4,0($0) lbu $5,3($0) addu $1,$1,$3 lw $3,4($0) slt $4,$5,$3 and $3,$4,$3 sb $3,2($0) slt $5,$3,$3 andi $5,$3,35545 subu $4,$3,$3 lh $3,16($0) sh $4,6($0) sw $3,16($0) slt $3,$3,$3 andi $3,$3,7051 addiu $3,$3,22268 and $3,$3,$3 sll $5,$5,31 srl $3,$3,25 sb $0,11($0) srlv $3,$4,$3 srl $3,$6,28 or $4,$4,$3 ori $5,$4,2799 lb $6,6($0) lhu $3,12($0) and $4,$5,$3 xor $5,$4,$3 srl $5,$4,25 lw $4,16($0) addu $4,$3,$3 andi $4,$0,7943 addu $5,$3,$3 sll $5,$5,12 andi $3,$6,26945 sltiu $6,$4,-15806 subu $4,$4,$3 subu $0,$4,$3 sltiu $6,$5,21825 lh $4,10($0) sltiu $3,$3,29558 subu $3,$3,$3 xori $4,$6,51595 sltu $5,$5,$3 xor $5,$5,$3 sra $3,$3,4 xori $3,$3,10556 and $3,$5,$3 and $4,$1,$3 sllv $5,$3,$3 lhu $3,6($0) xor $4,$4,$3 lh $4,2($0) xori $1,$1,8561 slt $3,$3,$3 sltiu $0,$0,25992 xor $6,$1,$3 sllv $3,$5,$3 or $0,$2,$3 and $3,$5,$3 srav $4,$4,$3 addu $5,$5,$3 ori $1,$3,49166 addu $4,$3,$3 sb $3,14($0) andi $3,$4,43613 addu $4,$3,$3 xori $3,$3,24020 xor $0,$1,$3 sltu $0,$3,$3 addu $3,$3,$3 or $3,$3,$3 addu $3,$1,$3 addu $3,$5,$3 ori $5,$1,1362 addiu $5,$3,30390 xori $3,$5,45177 sh $5,12($0) slt $3,$3,$3 lhu $3,14($0) xor $0,$6,$3 sltu $3,$3,$3 ori $5,$0,63134 xor $3,$3,$3 subu $1,$4,$3 lh $2,12($0) sb $3,5($0) srl $3,$3,27 lw $3,0($0) lw $3,16($0) srl $3,$3,28 sw $5,12($0) addiu $3,$3,24027 addu $4,$4,$3 srl $3,$3,4 srlv $4,$4,$3 xori $1,$1,64613 xor $3,$1,$3 lw $3,16($0) lw $3,0($0) slt $5,$5,$3 ori $5,$4,13146 sb $6,3($0) nor $5,$0,$3 srlv $0,$6,$3 srav $4,$4,$3 srlv $3,$3,$3 xor $5,$3,$3 lw $3,8($0) lw $0,16($0) nor $1,$0,$3 sll $3,$4,2 andi $3,$3,61636 sltu $0,$4,$3 xori $6,$4,57167 or $6,$5,$3 lh $3,0($0) srav $5,$4,$3 lb $3,14($0) sll $3,$5,9 ori $4,$5,26111 subu $6,$6,$3 sllv $4,$3,$3 sra $5,$2,24 lw $4,12($0) xori $5,$5,30173 srlv $3,$6,$3 slt $3,$3,$3 addu $1,$1,$3 srl $3,$3,16 sra $5,$1,9 xor $1,$3,$3 xor $2,$2,$3 srlv $5,$1,$3 addiu $3,$4,27129 lh $4,14($0) addu $3,$4,$3 sh $3,10($0) srlv $1,$1,$3 slti $5,$3,-2572 slt $1,$3,$3 lw $1,0($0) addu $3,$1,$3 xor $1,$3,$3 srlv $3,$4,$3 slt $5,$3,$3 srl $4,$6,24 addiu $4,$1,-28203 subu $4,$4,$3 nor $4,$4,$3 slt $4,$5,$3 andi $5,$4,62631 or $3,$3,$3 lw $3,4($0) slti $5,$5,19693 sh $5,10($0) addu $4,$3,$3 sllv $5,$5,$3 lb $4,5($0) subu $4,$5,$3 sltiu $4,$5,10316 sltu $3,$0,$3 sllv $6,$3,$3 xori $4,$5,62147 or $5,$5,$3 sll $5,$1,9 xori $6,$1,41501 sra $0,$3,31 subu $5,$0,$3 nor $3,$4,$3 sltiu $3,$3,-4019 srl $4,$4,8 sra $3,$2,24 sb $4,5($0) subu $4,$5,$3 srlv $3,$3,$3 slti $5,$3,-13136 sh $3,16($0) lbu $0,16($0) sh $5,4($0) sw $4,0($0) andi $1,$1,18512 lbu $1,14($0) lw $3,0($0) subu $3,$1,$3 addiu $5,$4,18953 sltu $4,$3,$3 lh $1,0($0) subu $1,$3,$3 subu $1,$1,$3 xor $4,$4,$3 andi $3,$3,26264 slt $6,$5,$3 lbu $3,8($0) or $4,$5,$3 subu $3,$3,$3 lw $3,0($0) srlv $1,$1,$3 sll $3,$3,20 lw $1,16($0) sll $3,$0,30 sb $3,3($0) srav $4,$4,$3 lhu $4,16($0) subu $4,$5,$3 sb $6,4($0) lw $0,12($0) or $3,$4,$3 lhu $1,14($0) srav $1,$1,$3 xori $5,$5,51440 srl $3,$5,5 subu $5,$3,$3 subu $1,$3,$3 srlv $5,$4,$3 subu $4,$2,$3 lh $5,14($0) sltu $5,$1,$3 srl $5,$1,18 lhu $4,10($0) lhu $1,16($0) sltiu $4,$4,20646 subu $3,$1,$3 xori $1,$2,12270 xor $3,$4,$3 sw $4,16($0) lw $0,8($0) sll $4,$6,18 lb $1,7($0) ori $1,$3,49464 lbu $4,14($0) sw $5,8($0) lh $1,10($0) andi $0,$3,28290 slt $1,$3,$3 and $3,$1,$3 addu $5,$4,$3 srlv $3,$6,$3 xor $1,$1,$3 slti $5,$5,-31403 xori $5,$3,2282 sh $4,12($0) subu $6,$6,$3 sra $4,$4,28 nor $1,$5,$3 sll $4,$4,23 subu $6,$3,$3 slti $3,$3,16736 srl $4,$4,19 andi $5,$3,34530 subu $3,$5,$3 slt $0,$0,$3 and $6,$3,$3 addu $3,$3,$3 lhu $0,0($0) lh $6,10($0) subu $1,$1,$3 sw $1,12($0) lw $5,4($0) or $4,$5,$3 lh $3,8($0) sltu $5,$5,$3 slti $3,$3,-23373 addiu $0,$3,28756 lb $5,4($0) srav $3,$4,$3 addu $5,$6,$3 addiu $4,$1,23465 slti $4,$3,-8484 andi $3,$3,12190 xori $4,$5,24444 addu $4,$5,$3 andi $5,$4,61381 xori $4,$6,2681 addu $5,$5,$3 addu $0,$0,$3 and $0,$0,$3 sllv $3,$4,$3 sltu $4,$6,$3 slt $1,$1,$3 sltiu $3,$1,16436 slt $4,$3,$3 sb $0,7($0) sll $3,$3,11 addu $6,$6,$3 sllv $4,$4,$3 or $6,$5,$3 srav $4,$4,$3 lh $4,10($0) sllv $4,$5,$3 lh $1,6($0) sltiu $3,$3,-22080 sb $3,14($0) lhu $1,16($0) addu $1,$1,$3 and $4,$4,$3 lhu $4,2($0) sw $4,16($0) ori $3,$6,53649 lbu $4,0($0) or $6,$4,$3 sw $3,16($0) nor $0,$4,$3 lh $6,10($0) ori $4,$4,18567 lw $6,8($0) addiu $3,$0,-19713 addiu $1,$5,21856 sra $5,$3,6 addu $4,$4,$3 sltu $5,$5,$3 lw $5,8($0) addu $4,$5,$3 srl $4,$5,2 slti $4,$5,4870 lb $6,13($0) sllv $5,$6,$3 slti $1,$1,28634 srlv $1,$3,$3 srlv $0,$5,$3 srlv $0,$4,$3 or $1,$1,$3 addu $1,$3,$3 subu $1,$4,$3 and $3,$3,$3 addu $3,$4,$3 addu $3,$1,$3 srl $3,$6,16 sb $5,16($0) lhu $3,16($0) and $4,$4,$3 subu $4,$4,$3 lbu $1,0($0) sllv $1,$4,$3 sltu $3,$3,$3 sb $3,15($0) nor $3,$3,$3 nor $5,$4,$3 lw $4,4($0) sltiu $1,$5,-31463 slti $4,$4,9374 srl $0,$1,26 sllv $4,$0,$3 subu $1,$1,$3 xor $3,$4,$3 sltiu $5,$4,-17185 addu $3,$3,$3 sltiu $5,$1,-12007 andi $1,$3,62414 lhu $6,16($0) addiu $4,$3,-13594 sllv $3,$3,$3 xori $1,$3,63288 addiu $0,$1,-16882 srlv $0,$1,$3 andi $0,$4,38311 sllv $6,$6,$3 subu $6,$4,$3 slti $3,$6,29568 xori $1,$4,4921 xori $0,$3,30741 xor $1,$5,$3 addu $3,$6,$3 srlv $5,$4,$3 sll $4,$3,3 sra $5,$1,18 lb $4,13($0) sllv $5,$3,$3 subu $3,$3,$3 subu $1,$3,$3 xor $3,$2,$3 lbu $1,14($0) lhu $3,12($0) andi $3,$1,15904 sw $5,0($0) sra $0,$0,23 srlv $3,$5,$3 lhu $1,2($0) srlv $4,$4,$3 xor $1,$4,$3 sltiu $4,$3,31616 xor $1,$3,$3 lbu $3,0($0) ori $3,$4,39370 nor $6,$6,$3 nor $3,$5,$3 sw $1,0($0) lh $4,0($0) addu $1,$1,$3 srlv $3,$4,$3 sw $4,4($0) addu $3,$5,$3 xor $1,$1,$3 sb $1,10($0) or $5,$4,$3 sra $5,$5,13 subu $1,$6,$3 sltiu $1,$4,27405 xor $3,$6,$3 addu $5,$1,$3 nor $1,$3,$3 sw $3,16($0) sw $4,8($0) srl $4,$4,3 lh $6,14($0) subu $3,$3,$3 subu $1,$1,$3 lh $4,2($0) srav $1,$2,$3 sltiu $6,$3,16765 lhu $3,10($0) sltiu $4,$4,-4158 srav $0,$4,$3 ori $6,$3,2911 addu $1,$1,$3 sb $1,4($0) sb $2,11($0) addiu $6,$1,-21958 srl $5,$3,20 slti $5,$3,16817 lh $4,2($0) addu $3,$4,$3 srlv $4,$4,$3 srl $5,$3,24 slti $0,$0,-31278 subu $1,$5,$3 sltu $5,$5,$3 addiu $4,$3,18667 ori $3,$5,50662 srav $3,$1,$3 lhu $4,4($0) sb $6,15($0) ori $3,$6,50164 subu $5,$1,$3 addiu $3,$3,10977 and $5,$1,$3 lw $4,0($0) sh $3,4($0) srl $3,$3,22 lb $6,1($0) subu $5,$5,$3 lb $3,10($0) sw $3,16($0) lh $0,6($0) sra $3,$3,14 xori $3,$5,37045 sb $4,7($0) andi $4,$4,13998 addiu $5,$4,-4986 lb $1,15($0) or $5,$5,$3 sb $1,3($0) sra $3,$5,4 srlv $5,$0,$3 or $3,$3,$3 srlv $6,$4,$3 sw $1,4($0) lb $3,10($0) addu $3,$3,$3 slti $3,$1,21336 andi $1,$3,19038 slt $1,$0,$3 sra $3,$4,10 lh $4,12($0) srlv $5,$4,$3 nor $5,$3,$3 and $0,$0,$3 ori $3,$6,56059 lh $1,16($0) srl $3,$5,10 xori $1,$3,1571 subu $5,$1,$3 sra $6,$3,19 srav $0,$3,$3 sra $4,$5,14 slti $6,$4,22506 sb $1,1($0) srlv $3,$5,$3 lh $4,16($0) sltu $1,$1,$3 or $5,$0,$3 addiu $3,$6,-9219 sll $6,$4,26 lhu $4,14($0) slt $0,$0,$3 srav $4,$4,$3 and $3,$3,$3 lh $2,14($0) srav $1,$4,$3 lw $4,12($0) lh $6,14($0) lhu $3,8($0) slti $4,$3,30212 sra $3,$2,7 nor $0,$5,$3 sltiu $3,$4,-14974 subu $3,$2,$3 sltiu $5,$3,12033 sra $4,$3,2 addiu $5,$6,-29179 slt $0,$6,$3 srlv $0,$0,$3 srav $3,$4,$3 addu $5,$6,$3 addiu $3,$3,5403 subu $0,$6,$3 subu $1,$1,$3 xori $3,$3,30486 addiu $5,$5,10212 nor $3,$3,$3 slt $3,$6,$3 lb $1,7($0) sra $4,$5,0 lh $5,2($0) subu $5,$3,$3 lw $6,0($0) sltu $3,$5,$3 slti $4,$3,28191 slti $4,$0,-5810 sw $3,8($0) subu $6,$3,$3 srlv $3,$1,$3 nor $4,$5,$3 slt $1,$3,$3 srl $0,$4,2 sltu $3,$5,$3 sll $4,$3,30 ori $4,$4,35266 sllv $5,$3,$3 ori $3,$3,7163 sw $1,16($0) srlv $5,$1,$3 and $4,$3,$3 sll $6,$3,7 sb $3,2($0) andi $4,$6,47001 sltu $6,$5,$3 sllv $1,$5,$3 lh $3,4($0) lh $1,12($0) ori $4,$1,38617 srl $1,$3,7 sb $4,15($0) and $0,$3,$3 srl $3,$4,28 addu $1,$1,$3 addu $1,$4,$3 lb $4,0($0) sllv $1,$1,$3 sltiu $3,$3,25120 lh $3,0($0) addiu $3,$4,19813 xor $4,$4,$3 addiu $4,$2,-31004 and $1,$3,$3 or $3,$1,$3 subu $1,$4,$3 sw $4,4($0) sh $3,16($0) sltiu $4,$4,25429 xor $3,$3,$3 xori $1,$3,34424 addiu $3,$4,5004 srlv $3,$3,$3 addiu $5,$1,30485 or $5,$5,$3 ori $1,$0,45241 lhu $1,4($0) sltiu $1,$3,-22260 slti $3,$4,13595 subu $3,$3,$3 srlv $4,$3,$3 and $6,$5,$3 lh $1,10($0) lw $0,16($0) sra $4,$3,28 xor $4,$3,$3 lh $1,6($0) sh $3,6($0) sll $6,$3,20 lbu $3,11($0) lb $3,15($0) lh $4,12($0) subu $3,$0,$3 sltiu $5,$3,-20802 subu $4,$4,$3 xori $1,$3,9635 srl $3,$5,26 sw $4,4($0) sb $1,8($0) addiu $1,$4,-10798 sll $3,$1,6 lhu $4,12($0) sb $1,15($0) nor $5,$3,$3 sltu $6,$3,$3 nor $4,$3,$3 addu $3,$4,$3 sra $4,$3,30 sw $4,8($0) lbu $0,11($0) srlv $4,$3,$3 sllv $6,$3,$3 ori $4,$1,18934 srl $5,$3,23 addu $4,$3,$3 lbu $6,6($0) slt $6,$3,$3 lw $1,16($0) lh $0,8($0) sra $4,$4,20 srav $6,$0,$3 sltu $4,$3,$3 sb $5,11($0) lbu $5,8($0) sllv $3,$3,$3 srav $3,$3,$3 andi $1,$3,8229 sll $5,$5,22 subu $3,$4,$3 lh $1,0($0) sltu $3,$4,$3 addiu $4,$4,-1869 lw $0,16($0) sb $3,16($0) sll $1,$1,0 sw $3,0($0) lhu $6,4($0) addu $1,$0,$3 sltu $3,$3,$3 lw $4,12($0) xor $4,$3,$3 srav $1,$4,$3 sltu $0,$0,$3 subu $5,$3,$3 subu $4,$3,$3 lbu $1,0($0) sra $0,$4,24 lbu $5,12($0) slti $4,$1,31544 ori $3,$4,30412 srl $1,$5,23 lbu $3,12($0) lh $3,0($0) xori $3,$0,62353 srav $1,$5,$3 lbu $4,0($0) addiu $1,$3,-18589 ori $6,$0,37250 xor $0,$3,$3 addu $0,$4,$3 addiu $3,$5,14199 sw $3,0($0) addiu $0,$4,-22495 xori $3,$3,11232 sllv $0,$4,$3 srav $4,$0,$3 addiu $3,$6,26434 sb $3,11($0) sltu $4,$4,$3 slt $5,$5,$3 sb $3,11($0) or $3,$5,$3 srav $1,$4,$3 sra $4,$4,31 and $1,$4,$3 lhu $3,2($0) subu $3,$5,$3 sltiu $4,$0,-22863 lhu $3,4($0) subu $4,$5,$3 lw $3,0($0) lw $1,8($0) slt $1,$1,$3 sra $4,$4,20 subu $1,$3,$3 lhu $5,16($0) sw $5,4($0) and $3,$3,$3 lw $3,12($0) addu $0,$4,$3 lw $1,12($0) lb $5,14($0) sllv $6,$1,$3 srav $3,$1,$3 nor $5,$1,$3 sltu $4,$4,$3 sw $4,12($0) ori $3,$2,26405 sb $0,16($0) sra $3,$0,3 xori $3,$4,15436 lh $6,12($0) srlv $3,$3,$3 and $3,$3,$3 addiu $5,$4,32073 and $3,$2,$3 addiu $4,$3,-7572 nor $0,$0,$3 xori $5,$3,29830 srlv $4,$4,$3 xori $4,$4,41860 addiu $5,$4,2664 sltu $5,$5,$3 sll $4,$5,31 and $3,$4,$3 addu $3,$3,$3 xor $4,$4,$3 lbu $5,4($0) lbu $4,10($0) sb $6,2($0) lb $1,12($0) addiu $3,$1,-19250 xor $1,$5,$3 sllv $0,$0,$3 slti $1,$4,-5686 addu $4,$0,$3 sra $6,$0,8 sra $4,$4,17 slt $4,$4,$3 xor $1,$5,$3 srl $3,$6,30 sllv $2,$2,$3 sb $5,11($0) nor $1,$4,$3 xori $5,$0,18928 or $4,$6,$3 sh $3,10($0) ori $5,$5,6071 and $5,$4,$3 sb $4,8($0) srav $0,$0,$3 lh $3,4($0) sltu $1,$1,$3 nor $4,$5,$3 sltu $3,$3,$3 addu $3,$3,$3 slt $6,$5,$3 sllv $5,$4,$3 srlv $3,$1,$3 lw $4,0($0) sltiu $4,$4,32061 srl $4,$4,0 sb $1,4($0) sw $4,0($0) srlv $4,$3,$3 or $0,$5,$3 ori $5,$1,1050 subu $3,$3,$3 sltiu $4,$5,14408 slti $3,$1,19163 nor $0,$5,$3 sltiu $1,$1,-18347 or $3,$4,$3 sllv $3,$3,$3 sll $6,$3,1 lbu $5,7($0) addu $5,$5,$3 subu $6,$3,$3 sw $4,16($0) sltu $5,$2,$3 xori $5,$5,43555 lbu $3,11($0) addu $5,$3,$3 addu $1,$1,$3 addiu $1,$1,-4345 sb $4,1($0) or $3,$3,$3 sltu $5,$0,$3 lb $1,9($0) xor $3,$5,$3 sh $4,16($0) slti $0,$4,17372 sltiu $5,$3,-9438 sltiu $3,$3,-30265 nor $6,$3,$3 sh $4,2($0) lbu $1,9($0) lb $1,11($0) sll $0,$3,16 sra $3,$3,19 srav $1,$2,$3 sb $6,10($0) or $5,$5,$3 xori $4,$4,10585 sw $0,16($0) sll $3,$1,9 sb $5,0($0) lb $3,14($0) lh $6,10($0) sw $4,4($0) andi $0,$6,22635 addiu $3,$5,-10491 sra $6,$0,1
section .text global isr_wrapper align 4 isr_wrapper: pushad cld call interrupt_handler popad iret
; A157288: a(n) = 10368*n^2 - 288*n + 1. ; 10081,40897,92449,164737,257761,371521,506017,661249,837217,1033921,1251361,1489537,1748449,2028097,2328481,2649601,2991457,3354049,3737377,4141441,4566241,5011777,5478049,5965057,6472801,7001281,7550497,8120449,8711137,9322561,9954721,10607617,11281249,11975617,12690721,13426561,14183137,14960449,15758497,16577281,17416801,18277057,19158049,20059777,20982241,21925441,22889377,23874049,24879457,25905601,26952481,28020097,29108449,30217537,31347361,32497921,33669217,34861249,36074017,37307521 add $0,1 mul $0,36 bin $0,2 sub $0,630 div $0,18 mul $0,288 add $0,10081
%define STDIN 0 %define STDOUT 1 %define STDERR 2 %define SYSCALL_EXIT 1 %define SYSCALL_READ 3 %define SYSCALL_WRITE 4 %define BUFLEN 256 [SECTION .data] ;;; Here we declare initialized data. For example: messages, prompts, ;;; and numbers that we know in advance msg1: db "Enter string: " ; user prompt len1: equ $-msg1 ; length of first message msg2: db "Original string: " ; original string label len2: equ $-msg2 ; length of second message msg3: db "Converted string: " ; converted string label len3: equ $-msg3 [SECTION .bss] ;;; Here we declare uninitialized data. We're reserving space (and ;;; potentially associating names with that space) that our code ;;; will use as it executes. Think of these as "global variables" buf: resb BUFLEN ; buffer for read newstr: resb BUFLEN ; converted string readlen: resb 4 ; storage for the length of string we read [SECTION .text] global _start ; make start global so ld can find it _start: ; the program actually starts here ;; prompt for user input mov eax, SYSCALL_WRITE mov ebx, STDOUT mov ecx, msg1 mov edx, len1 int 80H ;; read user input mov eax, SYSCALL_READ mov ebx, STDIN mov ecx, buf mov edx, BUFLEN int 80H ;; remember how many characters we read mov [readlen], eax ;; loop over all characters mov esi, buf mov edi, newstr .loop: cmp eax, 0 je .done ;; grab the next letter mov bh, [esi] ;; only transform values that are between 'a' and 'z' cmp bh, 'a' jl .lettercomplete cmp bh, 'z' jg .lettercomplete ;; use the offset between lowercase letters and uppercase letters ;; in the ASCII table to shift the letter to uppercase add bh, ('A' - 'a') .lettercomplete: ;; store the letter and go on to the next one mov [edi], bh add esi, 1 add edi, 1 sub eax, 1 jmp .loop .done: ;; print the original string message mov eax, SYSCALL_WRITE mov ebx, STDOUT mov ecx, msg2 mov edx, len2 int 80H ;; print the original string mov eax, SYSCALL_WRITE mov ebx, STDOUT mov ecx, buf mov edx, [readlen] int 80H ;; print the converted string message mov eax, SYSCALL_WRITE mov ebx, STDOUT mov ecx, msg3 mov edx, len3 int 80H ;; print the converted string mov eax, SYSCALL_WRITE mov ebx, STDOUT mov ecx, newstr mov edx, [readlen] int 80H ;; and we're done! jmp .end .end: ;; call sys_exit to finish things off mov eax, SYSCALL_EXIT ; sys_exit syscall mov ebx, 0 ; no error int 80H ; kernel interrupt
copyright zengfr site:http://github.com/zengfr/romhack 001590 lea ($20,A0), A0 0015C6 bne $15e4 [123p+ 28, enemy+28] 00192E bne $1970 [enemy+28] 001966 move.l #$2000604, ($28,A1) [enemy+CD] 00196E rts [enemy+28, enemy+2A] 003C4E move.w #$4, ($28,A0) [enemy+1F] 003C54 rts [enemy+28] 00439E move.w #$600, ($28,A0) 0043A4 rts [enemy+28] 005354 move.l #$2000200, ($28,A0) [enemy+36, enemy+38] 00535C jmp $3e12.w [enemy+28, enemy+2A] 0054E0 rts [enemy+28] 0055FC rts [enemy+28] 0079B0 move.b ($1a,PC,D0.w), ($99,A0) [123p+ 28, 123p+ 2A, enemy+28, enemy+2A] 007B34 move.b #$1e, ($9b,A0) [enemy+28, enemy+2A] 007D12 move.l #$2000000, ($28,A0) 007D1A rts [enemy+28, enemy+2A] 007FFA movea.l #$6db44, A3 [123p+ 28, 123p+ 2A, enemy+28, enemy+2A] 0082DE move.l #$2020000, ($28,A1) [enemy+72] 0082E6 move.b #$2, ($99,A1) [enemy+28, enemy+2A] 0082EC cmpi.w #$202, ($28,A0) [enemy+99] 0082F2 bne $8308 [123p+ 28, enemy+28] 008726 movea.l #$6e754, A3 [123p+ 28, 123p+ 2A, enemy+28, enemy+2A] 008FD8 move.l #$2040000, ($28,A0) [123p+ 96] 008FE0 move.l #$2060000, ($28,A1) [enemy+28, enemy+2A] 0096A0 bhi $9430 [enemy+28] 0096DA move.l #$2060000, ($28,A1) [123p+ 28, 123p+ 2A] 0096E2 move.w A0, ($6a,A1) [enemy+28, enemy+2A] 011AF0 move.l #$2000000, ($28,A0) 011AF8 rts [123p+ 28, 123p+ 2A, enemy+28, enemy+2A] 011F64 jmp $614c.w [enemy+28, enemy+2A] 012260 move.l (A2)+, (A3)+ [enemy+24, enemy+26] 012262 move.l (A2)+, (A3)+ [enemy+28, enemy+2A] 01236E rts [123p+ 28, 123p+ 2A, enemy+28, enemy+2A] 0123DE move.b #$a, ($78,A0) [123p+ 28, 123p+ 2A, enemy+28, enemy+2A] 01A75E dbra D4, $1a75c 01AE0A cmpi.w #$202, ($28,A1) [123p+ 4] 01AE10 beq $1ae16 [123p+ 28, enemy+28] 01B4C4 beq $1b4e2 [enemy+28] 01B520 moveq #$e, D4 [enemy+28, enemy+2A] 01BCA8 cmpi.w #$202, ($28,A1) [123p+ 4] 01BCAE beq $1bcb4 [123p+ 28, enemy+28] 01C130 beq $1c15a [123p+ 28, enemy+28] 01CB4C cmpi.w #$202, ($28,A1) [123p+ 4] 01CB52 beq $1cb58 [123p+ 28, enemy+28] 01D0CE beq $1d0ee [123p+ 28, enemy+28] 01D118 moveq #$c, D4 [enemy+28, enemy+2A] 022C8E bne $22cf0 [enemy+28] 022CC0 cmpi.w #$202, ($28,A0) [enemy+96] 022CC6 beq $22cf0 [enemy+28] 022CCE beq $22cf0 [enemy+28] 022CD8 move.b #$2, ($99,A0) [enemy+28, enemy+2A] 022D76 bne $22d86 [enemy+28] 0251FC move.w ($6,PC,D0.w), D1 [enemy+28] 025332 move.b ($29,A0), D0 [enemy+28, enemy+2A] 026648 move.w ($6,PC,D0.w), D1 [enemy+28] 0266A6 movea.l #$8283e, A4 [enemy+28, enemy+2A] 0266EC clr.w ($32,A0) [enemy+28, enemy+2A] 029022 move.w ($6,PC,D0.w), D1 [enemy+28] 029090 movea.l #$8707c, A4 [enemy+28, enemy+2A] 0290D6 clr.w ($32,A0) [enemy+28, enemy+2A] 02A3E6 move.w ($6,PC,D0.w), D1 [enemy+28] 02A452 movea.l #$89d8c, A4 [enemy+28, enemy+2A] 02A498 clr.w ($32,A0) [enemy+28, enemy+2A] 02B612 move.w ($6,PC,D0.w), D1 [enemy+28] 02B67E movea.l #$88b24, A4 [enemy+28, enemy+2A] 02B6C4 clr.w ($32,A0) [enemy+28, enemy+2A] 0327FE move.w ($6,PC,D0.w), D1 [enemy+28] 03284E bsr $329d0 [enemy+28, enemy+2A] 0331AA move.l #$2080000, ($28,A0) [enemy+A3] 0331B2 jmp $412c.w [enemy+28, enemy+2A] 036618 move.w ($6,PC,D0.w), D1 [enemy+28] 036658 movea.l #$83bec, A4 [enemy+28, enemy+2A] 046734 move.w ($6,PC,D0.w), D1 [enemy+28] 04679A movea.l #$82388, A4 [enemy+28, enemy+2A] 0470FE move.w ($6,PC,D0.w), D1 [enemy+28] 04712C move.l #$2000400, ($28,A0) [enemy+1E] 047134 move.b #$4, ($a3,A0) [enemy+28, enemy+2A] 0494BA move.w ($6,PC,D0.w), D1 [enemy+28] 0494E8 move.l #$2000400, ($28,A0) [enemy+1E] 0494F0 move.b #$4, ($a3,A0) [enemy+28, enemy+2A] 049970 move.w ($6,PC,D0.w), D1 [enemy+28] 04999E move.l #$2000400, ($28,A0) [enemy+1E] 0499A6 move.b #$4, ($a3,A0) [enemy+28, enemy+2A] 05E456 bne $5e4ac [123p+ 28, enemy+28] 05E516 bne $5e5b8 [enemy+28, enemy+2A] copyright zengfr site:http://github.com/zengfr/romhack
PSH 5 PSH 2 MUL PSH 10 PSH 20 ADD ADD HLT
SECTION code_l PUBLIC l_small_utoo PUBLIC l2_small_utoo_lz, l2_small_utoo_nlz PUBLIC l3_small_utoo_lz, l3_small_utoo_nlz l_small_utoo: ; write unsigned octal number to ascii buffer ; ; enter : hl = unsigned integer ; de = char *buffer ; carry set to write leading zeroes ; ; exit : de = char *buffer (one byte past last char written) ; carry set if in write loop ; ; uses : af, b, de, hl ld b,6 jr c, leading_zeroes no_leading_zeroes: xor a jr three_nlz loop_nlz: add hl,hl adc a,a l2_small_utoo_nlz: add hl,hl adc a,a l3_small_utoo_nlz: three_nlz: add hl,hl adc a,a jr nz, write djnz loop_nlz ld a,'0' ld (de),a inc de ret leading_zeroes: xor a jr three_lz loop_lz: add hl,hl adc a,a l2_small_utoo_lz: add hl,hl adc a,a l3_small_utoo_lz: three_lz: add hl,hl adc a,a write: add a,'0' ld (de),a inc de xor a djnz loop_lz scf ret
; A064108: a(n) = (20^n-1)/19. ; 0,1,21,421,8421,168421,3368421,67368421,1347368421,26947368421,538947368421,10778947368421,215578947368421,4311578947368421,86231578947368421,1724631578947368421,34492631578947368421,689852631578947368421,13797052631578947368421,275941052631578947368421,5518821052631578947368421,110376421052631578947368421,2207528421052631578947368421,44150568421052631578947368421,883011368421052631578947368421,17660227368421052631578947368421,353204547368421052631578947368421,7064090947368421052631578947368421 mov $1,20 pow $1,$0 div $1,19 mov $0,$1
; Copyright (c) 2021, Aleksey "introspec" Pichugin, Milos "baze" Bazelides, Pavel "Zilog" Cimbal ; This code is released under the terms of the BSD 2-Clause License. ; E1E1 decoder (28 bytes excluding initialization). ; The decoder assumes reverse order. We can omit the end of stream ; marker if we let the last literal overwrite opcodes after LDDR. ld hl,SrcAddr ld de,DstAddr ld bc,0 ; Ideally, these values should be "reused" ld a,%11000000 ; e.g. by aligning the addresses. EliasLength add a,a rl c ; ret c ; Option to include the end of stream marker. NextBit add a,a jr nz,NoFetch ld a,(hl) dec hl rla NoFetch jr c,EliasLength rla ; Literal or phrase? jr c,CopyBytes push hl ld l,(hl) ld h,b add hl,de ; inc hl ; Option to increase offset to 256. inc c CopyBytes lddr inc c ; Prepare the most-significant bit. jr c,NextBit pop hl dec hl jr NextBit
; A335298: a(n) is the squared distance between the points P(n) and P(0) on a plane, n>=0, such that the distance between P(n) and P(n+1) is n+1 and, going from P(n) to P(n+2), a 90-degree-left-turn is taken in P(n+1). ; 0,1,5,8,8,13,25,32,32,41,61,72,72,85,113,128,128,145,181,200,200,221,265,288,288,313,365,392,392,421,481,512,512,545,613,648,648,685,761,800,800,841,925,968,968,1013,1105,1152,1152,1201,1301,1352,1352,1405,1513 lpb $0 mov $2,$0 sub $0,1 seq $2,7877 ; Period 4 zigzag sequence: repeat [0,1,2,1]. add $3,$2 add $1,$3 lpe mov $0,$1
; A293639: a(n) is the greatest integer k such that k/Fibonacci(n) < 2/5. ; 0,0,0,0,1,2,3,5,8,13,22,35,57,93,150,244,394,638,1033,1672,2706,4378,7084,11462,18547,30010,48557,78567,127124,205691,332816,538507,871323,1409831,2281154,3690986,5972140,9663126,15635267,25298394,40933662,66232056,107165718,173397774,280563493,453961268,734524761,1188486029,1923010790,3111496819,5034507610,8146004429,13180512039,21326516469,34507028508,55833544978,90340573486,146174118464,236514691951,382688810416,619203502368,1001892312784,1621095815152,2622988127936,4244083943089,6867072071026,11111156014115,17978228085141,29089384099256,47067612184397,76156996283654,123224608468051,199381604751705,322606213219757,521987817971462,844594031191220,1366581849162682,2211175880353902,3577757729516585,5788933609870488 mov $1,2 lpb $0 sub $0,1 add $1,$3 mov $3,$2 mov $2,$1 lpe div $1,5
section .text global _start global avg _start: mov eax,20 mov ebx,13 mov ecx,82 add eax,ebx add eax,ecx mov dl,3 div eax
; A204243: Determinant of the n-th principal submatrix of A204242. ; Submitted by Jamie Morken(s4) ; 1,2,11,144,4149,251622,31340799,7913773980,4024015413705,4106387069191890,8395359475529822355,34357677843892688699400,281336437060919094044274525,4608419756389534634440592965950,150992374805715685629827976712244775,9894901405956863744040202320126386512500,1296909464805190089567070882448563085939600625,339972440430130680159635528405221479534621685646250,178242266484861773984576573636523052759352416407354706875,186899931390436339142527305310986380739065723257924437478860000 mov $1,-1 mov $2,1 mov $3,1 lpb $0 sub $0,1 mul $2,2 add $2,1 mul $3,$2 add $3,$1 mul $1,$2 lpe mov $0,$3
class Solution { public: int removeElement(vector<int>& a, int val) { ios_base::sync_with_stdio(false); cin.tie(NULL); int n = a.size(); int cnt=0; for(int i=0; i<n; i++){ while(i < n && a[i] == val){ cnt++; i++; } cout << i << " " << cnt << endl; if(i<n) a[i-cnt] = a[i]; } return n-cnt; } };
; A054684: Sum of digits is odd. ; 1,3,5,7,9,10,12,14,16,18,21,23,25,27,29,30,32,34,36,38,41,43,45,47,49,50,52,54,56,58,61,63,65,67,69,70,72,74,76,78,81,83,85,87,89,90,92,94,96,98,100,102,104,106,108,111,113,115,117,119,120,122,124,126,128,131,133,135,137,139,140,142,144,146,148,151,153,155,157,159,160,162,164,166,168,171,173,175,177,179,180,182,184,186,188,191,193,195,197,199,201,203,205,207,209,210,212,214,216,218,221,223,225,227,229,230,232,234,236,238,241,243,245,247,249,250,252,254,256,258,261,263,265,267,269,270,272,274,276,278,281,283,285,287,289,290,292,294,296,298,300,302,304,306,308,311,313,315,317,319,320,322,324,326,328,331,333,335,337,339,340,342,344,346,348,351,353,355,357,359,360,362,364,366,368,371,373,375,377,379,380,382,384,386,388,391,393,395,397,399,401,403,405,407,409,410,412,414,416,418,421,423,425,427,429,430,432,434,436,438,441,443,445,447,449,450,452,454,456,458,461,463,465,467,469,470,472,474,476,478,481,483,485,487,489,490,492,494,496,498 mov $3,$0 mul $0,2 lpb $0 add $4,$0 div $0,10 lpe gcd $4,2 mov $1,$4 sub $1,1 mov $2,$3 mul $2,2 add $1,$2
.size 8000 .text@48 ei jp lstatint .text@100 jp lbegin .data@143 c0 .text@150 lbegin: ld a, 00 ldff(ff), a ld a, 30 ldff(00), a ld a, 01 ldff(4d), a stop, 00 ld c, 44 ld b, 90 lbegin_waitly90: ldff a, (c) cmp a, b jrnz lbegin_waitly90 xor a, a ldff(40), a ld hl, 9f00 ld b, 20 lbegin_clearvram: dec l ld(hl), a jrnz lbegin_clearvram dec h dec b jrnz lbegin_clearvram ld hl, 8000 ld a, ff ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld(hl++), a ld a, e4 ldff(47), a ld a, ff ldff(48), a ld a, 80 ldff(68), a ld a, ff ld c, 69 ldff(c), a ldff(c), a ld a, aa ldff(c), a ldff(c), a ld a, 55 ldff(c), a ldff(c), a xor a, a ldff(c), a ldff(c), a ld a, 80 ldff(6a), a ld a, 00 ld c, 6b ldff(c), a ldff(c), a ldff(c), a ldff(c), a ldff(c), a ldff(c), a ldff(c), a ldff(c), a ld hl, fea0 xor a, a lbegin_fill_oam: dec l ld(hl), a jrnz lbegin_fill_oam ld a, 10 ld(hl), a inc l ld a, 08 ld(hl), a ld a, 87 ldff(40), a ld c, 41 ld b, 03 lbegin_waitm3: ldff a, (c) and a, b cmp a, b jrnz lbegin_waitm3 ld a, 20 ldff(c), a ld a, 02 ldff(ff), a xor a, a ldff(0f), a ei .text@1000 lstatint: nop .text@102e ld a, 97 ldff(40), a pop hl .text@1065 ld a, 87 ldff(40), a
; CRT0 stub for 64k Mode Multi8 ; ; defc CRT_ORG_CODE = 0x0000 defc TAR__register_sp = 0xffff defc TAR__clib_exit_stack_size = 0 defc VRAM_IN = 0x37; defc VRAM_OUT = 0x2f INCLUDE "crt/classic/crt_rules.inc" EXTERN asm_im1_handler EXTERN asm_nmi_handler org CRT_ORG_CODE if (ASMPC<>$0000) defs CODE_ALIGNMENT_ERROR endif di jp program defs $0008-ASMPC if (ASMPC<>$0008) defs CODE_ALIGNMENT_ERROR endif jp restart08 defs $0010-ASMPC if (ASMPC<>$0010) defs CODE_ALIGNMENT_ERROR endif jp restart10 defs $0018-ASMPC if (ASMPC<>$0018) defs CODE_ALIGNMENT_ERROR endif jp restart18 defs $0020-ASMPC if (ASMPC<>$0020) defs CODE_ALIGNMENT_ERROR endif jp restart20 defs $0028-ASMPC if (ASMPC<>$0028) defs CODE_ALIGNMENT_ERROR endif jp restart28 defs $0030-ASMPC if (ASMPC<>$0030) defs CODE_ALIGNMENT_ERROR endif jp restart30 defs $0038-ASMPC if (ASMPC<>$0038) defs CODE_ALIGNMENT_ERROR endif jp asm_im1_handler defs $0066 - ASMPC if (ASMPC<>$0066) defs CODE_ALIGNMENT_ERROR endif jp asm_nmi_handler restart10: restart08: restart18: restart20: restart28: restart30: ret program: ; Make room for the atexit() stack INCLUDE "crt/classic/crt_init_sp.asm" INCLUDE "crt/classic/crt_init_atexit.asm" call crt0_init_bss ld (exitsp),sp ld a,(SYSVAR_PORT29_COPY) ld (__port29_copy),a ; Optional definition for auto MALLOC init ; it assumes we have free space between the end of ; the compiled program and the stack pointer IF DEFINED_USING_amalloc INCLUDE "crt/classic/crt_init_amalloc.asm" ENDIF im 1 ei ; Entry to the user code call _main cleanup: ; ; Deallocate memory which has been allocated here! ; push hl IF CRT_ENABLE_STDIO = 1 EXTERN closeall call closeall ENDIF endloop: jr endloop
default rel %define XMMWORD %define YMMWORD %define ZMMWORD section .text code align=64 EXTERN OPENSSL_ia32cap_P global RC4 ALIGN 16 RC4: mov QWORD[8+rsp],rdi ;WIN64 prologue mov QWORD[16+rsp],rsi mov rax,rsp $L$SEH_begin_RC4: mov rdi,rcx mov rsi,rdx mov rdx,r8 mov rcx,r9 or rsi,rsi jne NEAR $L$entry mov rdi,QWORD[8+rsp] ;WIN64 epilogue mov rsi,QWORD[16+rsp] DB 0F3h,0C3h ;repret $L$entry: push rbx push r12 push r13 $L$prologue: mov r11,rsi mov r12,rdx mov r13,rcx xor r10,r10 xor rcx,rcx lea rdi,[8+rdi] mov r10b,BYTE[((-8))+rdi] mov cl,BYTE[((-4))+rdi] cmp DWORD[256+rdi],-1 je NEAR $L$RC4_CHAR mov r8d,DWORD[OPENSSL_ia32cap_P] xor rbx,rbx inc r10b sub rbx,r10 sub r13,r12 mov eax,DWORD[r10*4+rdi] test r11,-16 jz NEAR $L$loop1 bt r8d,30 jc NEAR $L$intel and rbx,7 lea rsi,[1+r10] jz NEAR $L$oop8 sub r11,rbx $L$oop8_warmup: add cl,al mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],eax mov DWORD[r10*4+rdi],edx add al,dl inc r10b mov edx,DWORD[rax*4+rdi] mov eax,DWORD[r10*4+rdi] xor dl,BYTE[r12] mov BYTE[r13*1+r12],dl lea r12,[1+r12] dec rbx jnz NEAR $L$oop8_warmup lea rsi,[1+r10] jmp NEAR $L$oop8 ALIGN 16 $L$oop8: add cl,al mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],eax mov ebx,DWORD[rsi*4+rdi] ror r8,8 mov DWORD[r10*4+rdi],edx add dl,al mov r8b,BYTE[rdx*4+rdi] add cl,bl mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],ebx mov eax,DWORD[4+rsi*4+rdi] ror r8,8 mov DWORD[4+r10*4+rdi],edx add dl,bl mov r8b,BYTE[rdx*4+rdi] add cl,al mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],eax mov ebx,DWORD[8+rsi*4+rdi] ror r8,8 mov DWORD[8+r10*4+rdi],edx add dl,al mov r8b,BYTE[rdx*4+rdi] add cl,bl mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],ebx mov eax,DWORD[12+rsi*4+rdi] ror r8,8 mov DWORD[12+r10*4+rdi],edx add dl,bl mov r8b,BYTE[rdx*4+rdi] add cl,al mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],eax mov ebx,DWORD[16+rsi*4+rdi] ror r8,8 mov DWORD[16+r10*4+rdi],edx add dl,al mov r8b,BYTE[rdx*4+rdi] add cl,bl mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],ebx mov eax,DWORD[20+rsi*4+rdi] ror r8,8 mov DWORD[20+r10*4+rdi],edx add dl,bl mov r8b,BYTE[rdx*4+rdi] add cl,al mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],eax mov ebx,DWORD[24+rsi*4+rdi] ror r8,8 mov DWORD[24+r10*4+rdi],edx add dl,al mov r8b,BYTE[rdx*4+rdi] add sil,8 add cl,bl mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],ebx mov eax,DWORD[((-4))+rsi*4+rdi] ror r8,8 mov DWORD[28+r10*4+rdi],edx add dl,bl mov r8b,BYTE[rdx*4+rdi] add r10b,8 ror r8,8 sub r11,8 xor r8,QWORD[r12] mov QWORD[r13*1+r12],r8 lea r12,[8+r12] test r11,-8 jnz NEAR $L$oop8 cmp r11,0 jne NEAR $L$loop1 jmp NEAR $L$exit ALIGN 16 $L$intel: test r11,-32 jz NEAR $L$loop1 and rbx,15 jz NEAR $L$oop16_is_hot sub r11,rbx $L$oop16_warmup: add cl,al mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],eax mov DWORD[r10*4+rdi],edx add al,dl inc r10b mov edx,DWORD[rax*4+rdi] mov eax,DWORD[r10*4+rdi] xor dl,BYTE[r12] mov BYTE[r13*1+r12],dl lea r12,[1+r12] dec rbx jnz NEAR $L$oop16_warmup mov rbx,rcx xor rcx,rcx mov cl,bl $L$oop16_is_hot: lea rsi,[r10*4+rdi] add cl,al mov edx,DWORD[rcx*4+rdi] pxor xmm0,xmm0 mov DWORD[rcx*4+rdi],eax add al,dl mov ebx,DWORD[4+rsi] movzx eax,al mov DWORD[rsi],edx add cl,bl pinsrw xmm0,WORD[rax*4+rdi],0 jmp NEAR $L$oop16_enter ALIGN 16 $L$oop16: add cl,al mov edx,DWORD[rcx*4+rdi] pxor xmm2,xmm0 psllq xmm1,8 pxor xmm0,xmm0 mov DWORD[rcx*4+rdi],eax add al,dl mov ebx,DWORD[4+rsi] movzx eax,al mov DWORD[rsi],edx pxor xmm2,xmm1 add cl,bl pinsrw xmm0,WORD[rax*4+rdi],0 movdqu XMMWORD[r13*1+r12],xmm2 lea r12,[16+r12] $L$oop16_enter: mov edx,DWORD[rcx*4+rdi] pxor xmm1,xmm1 mov DWORD[rcx*4+rdi],ebx add bl,dl mov eax,DWORD[8+rsi] movzx ebx,bl mov DWORD[4+rsi],edx add cl,al pinsrw xmm1,WORD[rbx*4+rdi],0 mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],eax add al,dl mov ebx,DWORD[12+rsi] movzx eax,al mov DWORD[8+rsi],edx add cl,bl pinsrw xmm0,WORD[rax*4+rdi],1 mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],ebx add bl,dl mov eax,DWORD[16+rsi] movzx ebx,bl mov DWORD[12+rsi],edx add cl,al pinsrw xmm1,WORD[rbx*4+rdi],1 mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],eax add al,dl mov ebx,DWORD[20+rsi] movzx eax,al mov DWORD[16+rsi],edx add cl,bl pinsrw xmm0,WORD[rax*4+rdi],2 mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],ebx add bl,dl mov eax,DWORD[24+rsi] movzx ebx,bl mov DWORD[20+rsi],edx add cl,al pinsrw xmm1,WORD[rbx*4+rdi],2 mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],eax add al,dl mov ebx,DWORD[28+rsi] movzx eax,al mov DWORD[24+rsi],edx add cl,bl pinsrw xmm0,WORD[rax*4+rdi],3 mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],ebx add bl,dl mov eax,DWORD[32+rsi] movzx ebx,bl mov DWORD[28+rsi],edx add cl,al pinsrw xmm1,WORD[rbx*4+rdi],3 mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],eax add al,dl mov ebx,DWORD[36+rsi] movzx eax,al mov DWORD[32+rsi],edx add cl,bl pinsrw xmm0,WORD[rax*4+rdi],4 mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],ebx add bl,dl mov eax,DWORD[40+rsi] movzx ebx,bl mov DWORD[36+rsi],edx add cl,al pinsrw xmm1,WORD[rbx*4+rdi],4 mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],eax add al,dl mov ebx,DWORD[44+rsi] movzx eax,al mov DWORD[40+rsi],edx add cl,bl pinsrw xmm0,WORD[rax*4+rdi],5 mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],ebx add bl,dl mov eax,DWORD[48+rsi] movzx ebx,bl mov DWORD[44+rsi],edx add cl,al pinsrw xmm1,WORD[rbx*4+rdi],5 mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],eax add al,dl mov ebx,DWORD[52+rsi] movzx eax,al mov DWORD[48+rsi],edx add cl,bl pinsrw xmm0,WORD[rax*4+rdi],6 mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],ebx add bl,dl mov eax,DWORD[56+rsi] movzx ebx,bl mov DWORD[52+rsi],edx add cl,al pinsrw xmm1,WORD[rbx*4+rdi],6 mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],eax add al,dl mov ebx,DWORD[60+rsi] movzx eax,al mov DWORD[56+rsi],edx add cl,bl pinsrw xmm0,WORD[rax*4+rdi],7 add r10b,16 movdqu xmm2,XMMWORD[r12] mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],ebx add bl,dl movzx ebx,bl mov DWORD[60+rsi],edx lea rsi,[r10*4+rdi] pinsrw xmm1,WORD[rbx*4+rdi],7 mov eax,DWORD[rsi] mov rbx,rcx xor rcx,rcx sub r11,16 mov cl,bl test r11,-16 jnz NEAR $L$oop16 psllq xmm1,8 pxor xmm2,xmm0 pxor xmm2,xmm1 movdqu XMMWORD[r13*1+r12],xmm2 lea r12,[16+r12] cmp r11,0 jne NEAR $L$loop1 jmp NEAR $L$exit ALIGN 16 $L$loop1: add cl,al mov edx,DWORD[rcx*4+rdi] mov DWORD[rcx*4+rdi],eax mov DWORD[r10*4+rdi],edx add al,dl inc r10b mov edx,DWORD[rax*4+rdi] mov eax,DWORD[r10*4+rdi] xor dl,BYTE[r12] mov BYTE[r13*1+r12],dl lea r12,[1+r12] dec r11 jnz NEAR $L$loop1 jmp NEAR $L$exit ALIGN 16 $L$RC4_CHAR: add r10b,1 movzx eax,BYTE[r10*1+rdi] test r11,-8 jz NEAR $L$cloop1 jmp NEAR $L$cloop8 ALIGN 16 $L$cloop8: mov r8d,DWORD[r12] mov r9d,DWORD[4+r12] add cl,al lea rsi,[1+r10] movzx edx,BYTE[rcx*1+rdi] movzx esi,sil movzx ebx,BYTE[rsi*1+rdi] mov BYTE[rcx*1+rdi],al cmp rcx,rsi mov BYTE[r10*1+rdi],dl jne NEAR $L$cmov0 mov rbx,rax $L$cmov0: add dl,al xor r8b,BYTE[rdx*1+rdi] ror r8d,8 add cl,bl lea r10,[1+rsi] movzx edx,BYTE[rcx*1+rdi] movzx r10d,r10b movzx eax,BYTE[r10*1+rdi] mov BYTE[rcx*1+rdi],bl cmp rcx,r10 mov BYTE[rsi*1+rdi],dl jne NEAR $L$cmov1 mov rax,rbx $L$cmov1: add dl,bl xor r8b,BYTE[rdx*1+rdi] ror r8d,8 add cl,al lea rsi,[1+r10] movzx edx,BYTE[rcx*1+rdi] movzx esi,sil movzx ebx,BYTE[rsi*1+rdi] mov BYTE[rcx*1+rdi],al cmp rcx,rsi mov BYTE[r10*1+rdi],dl jne NEAR $L$cmov2 mov rbx,rax $L$cmov2: add dl,al xor r8b,BYTE[rdx*1+rdi] ror r8d,8 add cl,bl lea r10,[1+rsi] movzx edx,BYTE[rcx*1+rdi] movzx r10d,r10b movzx eax,BYTE[r10*1+rdi] mov BYTE[rcx*1+rdi],bl cmp rcx,r10 mov BYTE[rsi*1+rdi],dl jne NEAR $L$cmov3 mov rax,rbx $L$cmov3: add dl,bl xor r8b,BYTE[rdx*1+rdi] ror r8d,8 add cl,al lea rsi,[1+r10] movzx edx,BYTE[rcx*1+rdi] movzx esi,sil movzx ebx,BYTE[rsi*1+rdi] mov BYTE[rcx*1+rdi],al cmp rcx,rsi mov BYTE[r10*1+rdi],dl jne NEAR $L$cmov4 mov rbx,rax $L$cmov4: add dl,al xor r9b,BYTE[rdx*1+rdi] ror r9d,8 add cl,bl lea r10,[1+rsi] movzx edx,BYTE[rcx*1+rdi] movzx r10d,r10b movzx eax,BYTE[r10*1+rdi] mov BYTE[rcx*1+rdi],bl cmp rcx,r10 mov BYTE[rsi*1+rdi],dl jne NEAR $L$cmov5 mov rax,rbx $L$cmov5: add dl,bl xor r9b,BYTE[rdx*1+rdi] ror r9d,8 add cl,al lea rsi,[1+r10] movzx edx,BYTE[rcx*1+rdi] movzx esi,sil movzx ebx,BYTE[rsi*1+rdi] mov BYTE[rcx*1+rdi],al cmp rcx,rsi mov BYTE[r10*1+rdi],dl jne NEAR $L$cmov6 mov rbx,rax $L$cmov6: add dl,al xor r9b,BYTE[rdx*1+rdi] ror r9d,8 add cl,bl lea r10,[1+rsi] movzx edx,BYTE[rcx*1+rdi] movzx r10d,r10b movzx eax,BYTE[r10*1+rdi] mov BYTE[rcx*1+rdi],bl cmp rcx,r10 mov BYTE[rsi*1+rdi],dl jne NEAR $L$cmov7 mov rax,rbx $L$cmov7: add dl,bl xor r9b,BYTE[rdx*1+rdi] ror r9d,8 lea r11,[((-8))+r11] mov DWORD[r13],r8d lea r12,[8+r12] mov DWORD[4+r13],r9d lea r13,[8+r13] test r11,-8 jnz NEAR $L$cloop8 cmp r11,0 jne NEAR $L$cloop1 jmp NEAR $L$exit ALIGN 16 $L$cloop1: add cl,al movzx ecx,cl movzx edx,BYTE[rcx*1+rdi] mov BYTE[rcx*1+rdi],al mov BYTE[r10*1+rdi],dl add dl,al add r10b,1 movzx edx,dl movzx r10d,r10b movzx edx,BYTE[rdx*1+rdi] movzx eax,BYTE[r10*1+rdi] xor dl,BYTE[r12] lea r12,[1+r12] mov BYTE[r13],dl lea r13,[1+r13] sub r11,1 jnz NEAR $L$cloop1 jmp NEAR $L$exit ALIGN 16 $L$exit: sub r10b,1 mov DWORD[((-8))+rdi],r10d mov DWORD[((-4))+rdi],ecx mov r13,QWORD[rsp] mov r12,QWORD[8+rsp] mov rbx,QWORD[16+rsp] add rsp,24 $L$epilogue: mov rdi,QWORD[8+rsp] ;WIN64 epilogue mov rsi,QWORD[16+rsp] DB 0F3h,0C3h ;repret $L$SEH_end_RC4: global RC4_set_key ALIGN 16 RC4_set_key: mov QWORD[8+rsp],rdi ;WIN64 prologue mov QWORD[16+rsp],rsi mov rax,rsp $L$SEH_begin_RC4_set_key: mov rdi,rcx mov rsi,rdx mov rdx,r8 lea rdi,[8+rdi] lea rdx,[rsi*1+rdx] neg rsi mov rcx,rsi xor eax,eax xor r9,r9 xor r10,r10 xor r11,r11 mov r8d,DWORD[OPENSSL_ia32cap_P] bt r8d,20 jc NEAR $L$c1stloop jmp NEAR $L$w1stloop ALIGN 16 $L$w1stloop: mov DWORD[rax*4+rdi],eax add al,1 jnc NEAR $L$w1stloop xor r9,r9 xor r8,r8 ALIGN 16 $L$w2ndloop: mov r10d,DWORD[r9*4+rdi] add r8b,BYTE[rsi*1+rdx] add r8b,r10b add rsi,1 mov r11d,DWORD[r8*4+rdi] cmovz rsi,rcx mov DWORD[r8*4+rdi],r10d mov DWORD[r9*4+rdi],r11d add r9b,1 jnc NEAR $L$w2ndloop jmp NEAR $L$exit_key ALIGN 16 $L$c1stloop: mov BYTE[rax*1+rdi],al add al,1 jnc NEAR $L$c1stloop xor r9,r9 xor r8,r8 ALIGN 16 $L$c2ndloop: mov r10b,BYTE[r9*1+rdi] add r8b,BYTE[rsi*1+rdx] add r8b,r10b add rsi,1 mov r11b,BYTE[r8*1+rdi] jnz NEAR $L$cnowrap mov rsi,rcx $L$cnowrap: mov BYTE[r8*1+rdi],r10b mov BYTE[r9*1+rdi],r11b add r9b,1 jnc NEAR $L$c2ndloop mov DWORD[256+rdi],-1 ALIGN 16 $L$exit_key: xor eax,eax mov DWORD[((-8))+rdi],eax mov DWORD[((-4))+rdi],eax mov rdi,QWORD[8+rsp] ;WIN64 epilogue mov rsi,QWORD[16+rsp] DB 0F3h,0C3h ;repret $L$SEH_end_RC4_set_key: global RC4_options ALIGN 16 RC4_options: lea rax,[$L$opts] mov edx,DWORD[OPENSSL_ia32cap_P] bt edx,20 jc NEAR $L$8xchar bt edx,30 jnc NEAR $L$done add rax,25 DB 0F3h,0C3h ;repret $L$8xchar: add rax,12 $L$done: DB 0F3h,0C3h ;repret ALIGN 64 $L$opts: DB 114,99,52,40,56,120,44,105,110,116,41,0 DB 114,99,52,40,56,120,44,99,104,97,114,41,0 DB 114,99,52,40,49,54,120,44,105,110,116,41,0 DB 82,67,52,32,102,111,114,32,120,56,54,95,54,52,44,32 DB 67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97 DB 112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103 DB 62,0 ALIGN 64 EXTERN __imp_RtlVirtualUnwind ALIGN 16 stream_se_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] lea r10,[$L$prologue] cmp rbx,r10 jb NEAR $L$in_prologue mov rax,QWORD[152+r8] lea r10,[$L$epilogue] cmp rbx,r10 jae NEAR $L$in_prologue lea rax,[24+rax] mov rbx,QWORD[((-8))+rax] mov r12,QWORD[((-16))+rax] mov r13,QWORD[((-24))+rax] mov QWORD[144+r8],rbx mov QWORD[216+r8],r12 mov QWORD[224+r8],r13 $L$in_prologue: 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 jmp NEAR $L$common_seh_exit ALIGN 16 key_se_handler: push rsi push rdi push rbx push rbp push r12 push r13 push r14 push r15 pushfq sub rsp,64 mov rax,QWORD[152+r8] mov rdi,QWORD[8+rax] mov rsi,QWORD[16+rax] mov QWORD[168+r8],rsi mov QWORD[176+r8],rdi $L$common_seh_exit: 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_RC4 wrt ..imagebase DD $L$SEH_end_RC4 wrt ..imagebase DD $L$SEH_info_RC4 wrt ..imagebase DD $L$SEH_begin_RC4_set_key wrt ..imagebase DD $L$SEH_end_RC4_set_key wrt ..imagebase DD $L$SEH_info_RC4_set_key wrt ..imagebase section .xdata rdata align=8 ALIGN 8 $L$SEH_info_RC4: DB 9,0,0,0 DD stream_se_handler wrt ..imagebase $L$SEH_info_RC4_set_key: DB 9,0,0,0 DD key_se_handler wrt ..imagebase
/* ========================================================================= * * * * OpenMesh * * Copyright (c) 2001-2015, RWTH-Aachen University * * Department of Computer Graphics and Multimedia * * All rights reserved. * * www.openmesh.org * * * *---------------------------------------------------------------------------* * This file is part of OpenMesh. * *---------------------------------------------------------------------------* * * * Redistribution and use in source and binary forms, with or without * * modification, are permitted provided that the following conditions * * are met: * * * * 1. Redistributions of source code must retain the above copyright notice, * * this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. Neither the name of the copyright holder nor the names of its * * contributors may be used to endorse or promote products derived from * * this software without specific prior written permission. * * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER * * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * * * ========================================================================= */ /*===========================================================================*\ * * * $Revision$ * * $Date$ * * * \*===========================================================================*/ //============================================================================= // // Helper Functions for binary reading / writing // //============================================================================= #ifndef OPENMESH_STORERESTORE_HH #define OPENMESH_STORERESTORE_HH //== INCLUDES ================================================================= #include <stdexcept> #include <OpenMesh/Core/System/config.h> #include <OpenMesh/Core/IO/SR_binary.hh> #include <OpenMesh/Core/IO/SR_binary_spec.hh> //== NAMESPACES =============================================================== namespace OpenMesh { namespace IO { //============================================================================= /** \name Handling binary input/output. These functions take care of swapping bytes to get the right Endian. */ //@{ //----------------------------------------------------------------------------- // StoreRestore definitions template <typename T> inline bool is_streamable(void) { return binary< T >::is_streamable; } template <typename T> inline bool is_streamable( const T& ) { return binary< T >::is_streamable; } template <typename T> inline size_t size_of( const T& _v ) { return binary< T >::size_of(_v); } template <typename T> inline size_t size_of(void) { return binary< T >::size_of(); } template <typename T> inline size_t store( std::ostream& _os, const T& _v, bool _swap=false) { return binary< T >::store( _os, _v, _swap ); } template <typename T> inline size_t restore( std::istream& _is, T& _v, bool _swap=false) { return binary< T >::restore( _is, _v, _swap ); } //@} //============================================================================= } // namespace IO } // namespace OpenMesh //============================================================================= #endif // OPENMESH_MESHREADER_HH defined //=============================================================================
; A030240: Scaled Chebyshev U-polynomials evaluated at sqrt(7)/2. ; 1,7,42,245,1421,8232,47677,276115,1599066,9260657,53631137,310593360,1798735561,10416995407,60327818922,349375764605,2023335619781,11717718986232,67860683565157,393000752052475,2275980479411226,13180858091511257,76334143284700217,442072996352322720,2560171971473357521,14826692825847243607,85865645980617202602,497272672083389712965,2879849182719407572541,16678035574452125017032,96587304742129022111437,559364884173738279660835,3239443056021264802845786,18760547202932685662294657 mov $1,1 lpb $0 sub $0,1 sub $1,$2 add $2,$1 mul $1,7 lpe mov $0,$1
; ---------------------------------------------------------------- ; Z88DK INTERFACE LIBRARY FOR THE BIFROST* ENGINE - RELEASE 1.2/L ; ; See "bifrost_l.h" for further details ; ---------------------------------------------------------------- ; unsigned char BIFROSTL_getTile(unsigned int px, unsigned int py) SECTION code_clib SECTION code_bifrost_l PUBLIC _BIFROSTL_getTile EXTERN asm_BIFROSTL_getTile _BIFROSTL_getTile: ld hl,2 ld b,h ; B=0 add hl,sp ld e,(hl) ; E=px inc hl inc hl ld c,(hl) ; BC=py ld l,e ; L=px jp asm_BIFROSTL_getTile
/*============================================================================= Copyright (c) 2011-2019 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under the sprout Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.sprout.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef SPROUT_PREDEF_COMPILER_VISUALC_HPP #define SPROUT_PREDEF_COMPILER_VISUALC_HPP #include <sprout/config.hpp> #include <sprout/predef/version_number.hpp> #include <sprout/predef/compiler/clang.hpp> #define SPROUT_COMP_MSVC 0 #if defined(_MSC_VER) # if !defined (_MSC_FULL_VER) # define SPROUT_COMP_MSVC_BUILD 0 # else # if _MSC_FULL_VER / 10000 == _MSC_VER # define SPROUT_COMP_MSVC_BUILD (_MSC_FULL_VER % 10000) # elif _MSC_FULL_VER / 100000 == _MSC_VER # define SPROUT_COMP_MSVC_BUILD (_MSC_FULL_VER % 100000) # else # error "Cannot determine build number from _MSC_FULL_VER" # endif # endif # if (_MSC_VER >= 1900) # define SPROUT_COMP_MSVC_DETECTION \ SPROUT_VERSION_NUMBER(_MSC_VER / 100 - 5, _MSC_VER % 100, SPROUT_COMP_MSVC_BUILD) # else # define SPROUT_COMP_MSVC_DETECTION \ SPROUT_VERSION_NUMBER(_MSC_VER / 100 - 6, _MSC_VER % 100, SPROUT_COMP_MSVC_BUILD) # endif #endif #ifdef SPROUT_COMP_MSVC_DETECTION # if defined(SPROUT_PREDEF_DETAIL_COMP_DETECTED) # define SPROUT_COMP_MSVC_EMULATED SPROUT_COMP_MSVC_DETECTION # else # undef SPROUT_COMP_MSVC # define SPROUT_COMP_MSVC SPROUT_COMP_MSVC_DETECTION # endif # define SPROUT_COMP_MSVC_AVAILABLE # include <sprout/predef/detail/comp_detected.hpp> #endif #define SPROUT_COMP_MSVC_NAME "Microsoft Visual C/C++" #endif //#ifndef SPROUT_PREDEF_COMPILER_VISUALC_HPP
; --------------------------------------------------------------------------- ; Animation script - ring ; --------------------------------------------------------------------------- dc.w byte_9F8C-Ani_obj25 byte_9F8C: dc.b 5, 4, 5, 6, 7, $FC even
; Don't even think of reading this code ; It was automatically generated by sha1-586.pl ; Which is a perl program used to generate the x86 assember for ; any of ELF, a.out, COFF, Win32, ... ; eric <eay@cryptsoft.com> ; ; TITLE sha1-586.asm ; .486 ;.model FLAT ;_TEXT$ SEGMENT PAGE 'CODE' ;PUBLIC _sha1_block_asm_data_order ; void sha1_block_host_order (SHA_CTX *c, const void *p,size_t num); ; void sha1_block_data_order (SHA_CTX *c, const void *p,size_t num); ; see http://weblogs.asp.net/oldnewthing/archive/2004/01/14/58579.aspx ; All registers must be preserved across the call, except for ; rax, rcx, rdx, r8, r9, r10, and r11, which are scratch. ; param on rcx, rdx, r8 and r9 ; 32 bits : num=[esp+12], p=[esp+8], c=[esp+4] .code sha1_block_asm_data_order PROC push rdi push rsi push rbx push rbp push r12 push r13 push r14 push r15 mov r9,rcx ; c = rcx ; p = rdx ; num = r8 shl r8, 6 mov r11,rdx add r8, r11 mov rbp, rcx mov edx, DWORD PTR 12[rbp] sub rsp, 120 mov edi, DWORD PTR 16[rbp] mov ebx, DWORD PTR 8[rbp] mov QWORD PTR 112[rsp],r8 ; First we need to setup the X array $L000start: ; First, load the words onto the stack in network byte order mov r12d, DWORD PTR [r11] mov r13d, DWORD PTR 4[r11] bswap r12d bswap r13d mov r14d, DWORD PTR 8[r11] mov r15d, DWORD PTR 12[r11] bswap r14d bswap r15d mov r10d, DWORD PTR 16[r11] mov r8d, DWORD PTR 20[r11] bswap r10d bswap r8d mov eax, DWORD PTR 24[r11] mov ecx, DWORD PTR 28[r11] bswap eax bswap ecx mov DWORD PTR 24[rsp],eax mov DWORD PTR 28[rsp],ecx mov eax, DWORD PTR 32[r11] mov ecx, DWORD PTR 36[r11] bswap eax bswap ecx mov DWORD PTR 32[rsp],eax mov DWORD PTR 36[rsp],ecx mov eax, DWORD PTR 40[r11] mov ecx, DWORD PTR 44[r11] bswap eax bswap ecx mov DWORD PTR 40[rsp],eax mov DWORD PTR 44[rsp],ecx mov eax, DWORD PTR 48[r11] mov ecx, DWORD PTR 52[r11] bswap eax bswap ecx mov DWORD PTR 48[rsp],eax mov DWORD PTR 52[rsp],ecx mov eax, DWORD PTR 56[r11] mov ecx, DWORD PTR 60[r11] bswap eax bswap ecx mov DWORD PTR 56[rsp],eax mov DWORD PTR 60[rsp],ecx ; We now have the X array on the stack ; starting at sp-4 ;;;;;mov DWORD PTR 132[rsp],esi $L001shortcut:: ; ; Start processing mov eax, DWORD PTR [r9] mov ecx, DWORD PTR 4[r9] ; 00_15 0 mov esi, ebx mov ebp, eax rol ebp, 5 xor esi, edx and esi, ecx add ebp, edi ; mov edi, r12d xor esi, edx ror ecx, 2 lea ebp, DWORD PTR 1518500249[r12d*1+ebp] add ebp, esi ; 00_15 1 mov edi, ecx mov esi, ebp rol ebp, 5 xor edi, ebx and edi, eax add ebp, edx ; mov edx, r13d xor edi, ebx ror eax, 2 lea ebp, DWORD PTR 1518500249[r13d*1+ebp] add ebp, edi ; 00_15 2 mov edx, eax mov edi, ebp rol ebp, 5 xor edx, ecx and edx, esi add ebp, ebx ; mov ebx, r14d xor edx, ecx ror esi, 2 lea ebp, DWORD PTR 1518500249[r14d*1+ebp] add ebp, edx ; 00_15 3 mov ebx, esi mov edx, ebp rol ebp, 5 xor ebx, eax and ebx, edi add ebp, ecx mov ecx, r15d xor ebx, eax ror edi, 2 lea ebp, DWORD PTR 1518500249[ecx*1+ebp] add ebp, ebx ; 00_15 4 mov ecx, edi mov ebx, ebp rol ebp, 5 xor ecx, esi and ecx, edx add ebp, eax mov eax, r10d xor ecx, esi ror edx, 2 lea ebp, DWORD PTR 1518500249[eax*1+ebp] add ebp, ecx ; 00_15 5 mov eax, edx mov ecx, ebp rol ebp, 5 xor eax, edi and eax, ebx add ebp, esi mov esi, r8d xor eax, edi ror ebx, 2 lea ebp, DWORD PTR 1518500249[esi*1+ebp] add ebp, eax ; 00_15 6 mov esi, ebx mov eax, ebp rol ebp, 5 xor esi, edx and esi, ecx add ebp, edi mov edi, DWORD PTR 24[rsp] xor esi, edx ror ecx, 2 lea ebp, DWORD PTR 1518500249[edi*1+ebp] add ebp, esi ; 00_15 7 mov edi, ecx mov esi, ebp rol ebp, 5 xor edi, ebx and edi, eax add ebp, edx mov edx, DWORD PTR 28[rsp] xor edi, ebx ror eax, 2 lea ebp, DWORD PTR 1518500249[edx*1+ebp] add ebp, edi ; 00_15 8 mov edx, eax mov edi, ebp rol ebp, 5 xor edx, ecx and edx, esi add ebp, ebx mov ebx, DWORD PTR 32[rsp] xor edx, ecx ror esi, 2 lea ebp, DWORD PTR 1518500249[ebx*1+ebp] add ebp, edx ; 00_15 9 mov ebx, esi mov edx, ebp rol ebp, 5 xor ebx, eax and ebx, edi add ebp, ecx mov ecx, DWORD PTR 36[rsp] xor ebx, eax ror edi, 2 lea ebp, DWORD PTR 1518500249[ecx*1+ebp] add ebp, ebx ; 00_15 10 mov ecx, edi mov ebx, ebp rol ebp, 5 xor ecx, esi and ecx, edx add ebp, eax mov eax, DWORD PTR 40[rsp] xor ecx, esi ror edx, 2 lea ebp, DWORD PTR 1518500249[eax*1+ebp] add ebp, ecx ; 00_15 11 mov eax, edx mov ecx, ebp rol ebp, 5 xor eax, edi and eax, ebx add ebp, esi mov esi, DWORD PTR 44[rsp] xor eax, edi ror ebx, 2 lea ebp, DWORD PTR 1518500249[esi*1+ebp] add ebp, eax ; 00_15 12 mov esi, ebx mov eax, ebp rol ebp, 5 xor esi, edx and esi, ecx add ebp, edi mov edi, DWORD PTR 48[rsp] xor esi, edx ror ecx, 2 lea ebp, DWORD PTR 1518500249[edi*1+ebp] add ebp, esi ; 00_15 13 mov edi, ecx mov esi, ebp rol ebp, 5 xor edi, ebx and edi, eax add ebp, edx mov edx, DWORD PTR 52[rsp] xor edi, ebx ror eax, 2 lea ebp, DWORD PTR 1518500249[edx*1+ebp] add ebp, edi ; 00_15 14 mov edx, eax mov edi, ebp rol ebp, 5 xor edx, ecx and edx, esi add ebp, ebx mov ebx, DWORD PTR 56[rsp] xor edx, ecx ror esi, 2 lea ebp, DWORD PTR 1518500249[ebx*1+ebp] add ebp, edx ; 00_15 15 mov ebx, esi mov edx, ebp rol ebp, 5 xor ebx, eax and ebx, edi add ebp, ecx mov ecx, DWORD PTR 60[rsp] xor ebx, eax ror edi, 2 lea ebp, DWORD PTR 1518500249[ecx*1+ebp] add ebx, ebp ; 16_19 16 mov ecx, r14d mov ebp, edi xor ecx, r12d xor ebp, esi xor ecx, DWORD PTR 32[rsp] and ebp, edx ror edx, 2 xor ecx, DWORD PTR 52[rsp] rol ecx, 1 xor ebp, esi mov r12d,ecx lea ecx, DWORD PTR 1518500249[eax*1+ecx] mov eax, ebx rol eax, 5 add ecx, ebp add ecx, eax ; 16_19 17 mov eax, r15d mov ebp, edx xor eax, r13d xor ebp, edi xor eax, DWORD PTR 36[rsp] and ebp, ebx ror ebx, 2 xor eax, DWORD PTR 56[rsp] rol eax, 1 xor ebp, edi mov r13d,eax lea eax, DWORD PTR 1518500249[esi*1+eax] mov esi, ecx rol esi, 5 add eax, ebp add eax, esi ; 16_19 18 mov esi, r10d mov ebp, ebx xor esi, r14d xor ebp, edx xor esi, DWORD PTR 40[rsp] and ebp, ecx ror ecx, 2 xor esi, DWORD PTR 60[rsp] rol esi, 1 xor ebp, edx mov r14d,esi lea esi, DWORD PTR 1518500249[edi*1+esi] mov edi, eax rol edi, 5 add esi, ebp add esi, edi ; 16_19 19 mov edi, r8d mov ebp, ecx xor edi, r15d xor ebp, ebx xor edi, DWORD PTR 44[rsp] and ebp, eax ror eax, 2 xor edi, r12d rol edi, 1 xor ebp, ebx mov r15d,edi lea edi, DWORD PTR 1518500249[edx*1+edi] mov edx, esi rol edx, 5 add edi, ebp add edi, edx ; 20_39 20 mov ebp, esi mov edx, r10d ror esi, 2 xor edx, DWORD PTR 24[rsp] xor ebp, eax xor edx, DWORD PTR 48[rsp] xor ebp, ecx xor edx, r13d rol edx, 1 add ebp, ebx mov r10d,edx mov ebx, edi rol ebx, 5 lea edx, DWORD PTR 1859775393[ebp*1+edx] add edx, ebx ; 20_39 21 mov ebp, edi mov ebx, r8d ror edi, 2 xor ebx, DWORD PTR 28[rsp] xor ebp, esi xor ebx, DWORD PTR 52[rsp] xor ebp, eax xor ebx, r14d rol ebx, 1 add ebp, ecx mov r8d,ebx mov ecx, edx rol ecx, 5 lea ebx, DWORD PTR 1859775393[ebp*1+ebx] add ebx, ecx ; 20_39 22 mov ebp, edx mov ecx, DWORD PTR 24[rsp] ror edx, 2 xor ecx, DWORD PTR 32[rsp] xor ebp, edi xor ecx, DWORD PTR 56[rsp] xor ebp, esi xor ecx, r15d rol ecx, 1 add ebp, eax mov DWORD PTR 24[rsp],ecx mov eax, ebx rol eax, 5 lea ecx, DWORD PTR 1859775393[ebp*1+ecx] add ecx, eax ; 20_39 23 mov ebp, ebx mov eax, DWORD PTR 28[rsp] ror ebx, 2 xor eax, DWORD PTR 36[rsp] xor ebp, edx xor eax, DWORD PTR 60[rsp] xor ebp, edi xor eax, r10d rol eax, 1 add ebp, esi mov DWORD PTR 28[rsp],eax mov esi, ecx rol esi, 5 lea eax, DWORD PTR 1859775393[ebp*1+eax] add eax, esi ; 20_39 24 mov ebp, ecx mov esi, DWORD PTR 32[rsp] ror ecx, 2 xor esi, DWORD PTR 40[rsp] xor ebp, ebx xor esi, r12d xor ebp, edx xor esi, r8d rol esi, 1 add ebp, edi mov DWORD PTR 32[rsp],esi mov edi, eax rol edi, 5 lea esi, DWORD PTR 1859775393[ebp*1+esi] add esi, edi ; 20_39 25 mov ebp, eax mov edi, DWORD PTR 36[rsp] ror eax, 2 xor edi, DWORD PTR 44[rsp] xor ebp, ecx xor edi, r13d xor ebp, ebx xor edi, DWORD PTR 24[rsp] rol edi, 1 add ebp, edx mov DWORD PTR 36[rsp],edi mov edx, esi rol edx, 5 lea edi, DWORD PTR 1859775393[ebp*1+edi] add edi, edx ; 20_39 26 mov ebp, esi mov edx, DWORD PTR 40[rsp] ror esi, 2 xor edx, DWORD PTR 48[rsp] xor ebp, eax xor edx, r14d xor ebp, ecx xor edx, DWORD PTR 28[rsp] rol edx, 1 add ebp, ebx mov DWORD PTR 40[rsp],edx mov ebx, edi rol ebx, 5 lea edx, DWORD PTR 1859775393[ebp*1+edx] add edx, ebx ; 20_39 27 mov ebp, edi mov ebx, DWORD PTR 44[rsp] ror edi, 2 xor ebx, DWORD PTR 52[rsp] xor ebp, esi xor ebx, r15d xor ebp, eax xor ebx, DWORD PTR 32[rsp] rol ebx, 1 add ebp, ecx mov DWORD PTR 44[rsp],ebx mov ecx, edx rol ecx, 5 lea ebx, DWORD PTR 1859775393[ebp*1+ebx] add ebx, ecx ; 20_39 28 mov ebp, edx mov ecx, DWORD PTR 48[rsp] ror edx, 2 xor ecx, DWORD PTR 56[rsp] xor ebp, edi xor ecx, r10d xor ebp, esi xor ecx, DWORD PTR 36[rsp] rol ecx, 1 add ebp, eax mov DWORD PTR 48[rsp],ecx mov eax, ebx rol eax, 5 lea ecx, DWORD PTR 1859775393[ebp*1+ecx] add ecx, eax ; 20_39 29 mov ebp, ebx mov eax, DWORD PTR 52[rsp] ror ebx, 2 xor eax, DWORD PTR 60[rsp] xor ebp, edx xor eax, r8d xor ebp, edi xor eax, DWORD PTR 40[rsp] rol eax, 1 add ebp, esi mov DWORD PTR 52[rsp],eax mov esi, ecx rol esi, 5 lea eax, DWORD PTR 1859775393[ebp*1+eax] add eax, esi ; 20_39 30 mov ebp, ecx mov esi, DWORD PTR 56[rsp] ror ecx, 2 xor esi, r12d xor ebp, ebx xor esi, DWORD PTR 24[rsp] xor ebp, edx xor esi, DWORD PTR 44[rsp] rol esi, 1 add ebp, edi mov DWORD PTR 56[rsp],esi mov edi, eax rol edi, 5 lea esi, DWORD PTR 1859775393[ebp*1+esi] add esi, edi ; 20_39 31 mov ebp, eax mov edi, DWORD PTR 60[rsp] ror eax, 2 xor edi, r13d xor ebp, ecx xor edi, DWORD PTR 28[rsp] xor ebp, ebx xor edi, DWORD PTR 48[rsp] rol edi, 1 add ebp, edx mov DWORD PTR 60[rsp],edi mov edx, esi rol edx, 5 lea edi, DWORD PTR 1859775393[ebp*1+edi] add edi, edx ; 20_39 32 mov ebp, esi ; mov edx, r12d ror esi, 2 xor r12d, r14d xor ebp, eax xor r12d, DWORD PTR 32[rsp] xor ebp, ecx xor r12d, DWORD PTR 52[rsp] rol r12d, 1 add ebp, ebx ; mov r12d,edx mov ebx, edi rol ebx, 5 lea edx, DWORD PTR 1859775393[ebp*1+r12d] add edx, ebx ; 20_39 33 mov ebp, edi mov ebx, r13d ror edi, 2 xor ebx, r15d xor ebp, esi xor ebx, DWORD PTR 36[rsp] xor ebp, eax xor ebx, DWORD PTR 56[rsp] rol ebx, 1 add ebp, ecx mov r13d,ebx mov ecx, edx rol ecx, 5 lea ebx, DWORD PTR 1859775393[ebp*1+ebx] add ebx, ecx ; 20_39 34 mov ebp, edx mov ecx, r14d ror edx, 2 xor ecx, r10d xor ebp, edi xor ecx, DWORD PTR 40[rsp] xor ebp, esi xor ecx, DWORD PTR 60[rsp] rol ecx, 1 add ebp, eax mov r14d,ecx mov eax, ebx rol eax, 5 lea ecx, DWORD PTR 1859775393[ebp*1+ecx] add ecx, eax ; 20_39 35 mov ebp, ebx mov eax, r15d ror ebx, 2 xor eax, r8d xor ebp, edx xor eax, DWORD PTR 44[rsp] xor ebp, edi xor eax, r12d rol eax, 1 add ebp, esi mov r15d,eax mov esi, ecx rol esi, 5 lea eax, DWORD PTR 1859775393[ebp*1+eax] add eax, esi ; 20_39 36 mov ebp, ecx mov esi, r10d ror ecx, 2 xor esi, DWORD PTR 24[rsp] xor ebp, ebx xor esi, DWORD PTR 48[rsp] xor ebp, edx xor esi, r13d rol esi, 1 add ebp, edi mov r10d,esi mov edi, eax rol edi, 5 lea esi, DWORD PTR 1859775393[ebp*1+esi] add esi, edi ; 20_39 37 mov ebp, eax mov edi, r8d ror eax, 2 xor edi, DWORD PTR 28[rsp] xor ebp, ecx xor edi, DWORD PTR 52[rsp] xor ebp, ebx xor edi, r14d rol edi, 1 add ebp, edx mov r8d,edi mov edx, esi rol edx, 5 lea edi, DWORD PTR 1859775393[ebp*1+edi] add edi, edx ; 20_39 38 mov ebp, esi mov edx, DWORD PTR 24[rsp] ror esi, 2 xor edx, DWORD PTR 32[rsp] xor ebp, eax xor edx, DWORD PTR 56[rsp] xor ebp, ecx xor edx, r15d rol edx, 1 add ebp, ebx mov DWORD PTR 24[rsp],edx mov ebx, edi rol ebx, 5 lea edx, DWORD PTR 1859775393[ebp*1+edx] add edx, ebx ; 20_39 39 mov ebp, edi mov ebx, DWORD PTR 28[rsp] ror edi, 2 xor ebx, DWORD PTR 36[rsp] xor ebp, esi xor ebx, DWORD PTR 60[rsp] xor ebp, eax xor ebx, r10d rol ebx, 1 add ebp, ecx mov DWORD PTR 28[rsp],ebx mov ecx, edx rol ecx, 5 lea ebx, DWORD PTR 1859775393[ebp*1+ebx] add ebx, ecx ; 40_59 40 mov ecx, DWORD PTR 32[rsp] mov ebp, DWORD PTR 40[rsp] xor ecx, ebp ; mov ebp, r12d xor ecx, r12d ; mov ebp, r8d xor ecx, r8d mov ebp, edx rol ecx, 1 or ebp, edi mov DWORD PTR 32[rsp],ecx and ebp, esi lea ecx, DWORD PTR 2400959708[eax*1+ecx] mov eax, edx ror edx, 2 and eax, edi or ebp, eax mov eax, ebx rol eax, 5 add ecx, ebp add ecx, eax ; 40_59 41 mov eax, DWORD PTR 36[rsp] mov ebp, DWORD PTR 44[rsp] xor eax, ebp ; mov ebp, r13d xor eax, r13d mov ebp, DWORD PTR 24[rsp] xor eax, ebp mov ebp, ebx rol eax, 1 or ebp, edx mov DWORD PTR 36[rsp],eax and ebp, edi lea eax, DWORD PTR 2400959708[esi*1+eax] mov esi, ebx ror ebx, 2 and esi, edx or ebp, esi mov esi, ecx rol esi, 5 add eax, ebp add eax, esi ; 40_59 42 mov esi, DWORD PTR 40[rsp] mov ebp, DWORD PTR 48[rsp] xor esi, ebp ; mov ebp, r14d xor esi, r14d mov ebp, DWORD PTR 28[rsp] xor esi, ebp mov ebp, ecx rol esi, 1 or ebp, ebx mov DWORD PTR 40[rsp],esi and ebp, edx lea esi, DWORD PTR 2400959708[edi*1+esi] mov edi, ecx ror ecx, 2 and edi, ebx or ebp, edi mov edi, eax rol edi, 5 add esi, ebp add esi, edi ; 40_59 43 mov edi, DWORD PTR 44[rsp] mov ebp, DWORD PTR 52[rsp] xor edi, ebp ; mov ebp, r15d xor edi, r15d mov ebp, DWORD PTR 32[rsp] xor edi, ebp mov ebp, eax rol edi, 1 or ebp, ecx mov DWORD PTR 44[rsp],edi and ebp, ebx lea edi, DWORD PTR 2400959708[edx*1+edi] mov edx, eax ror eax, 2 and edx, ecx or ebp, edx mov edx, esi rol edx, 5 add edi, ebp add edi, edx ; 40_59 44 mov edx, DWORD PTR 48[rsp] mov ebp, DWORD PTR 56[rsp] xor edx, ebp ; mov ebp, r10d xor edx, r10d mov ebp, DWORD PTR 36[rsp] xor edx, ebp mov ebp, esi rol edx, 1 or ebp, eax mov DWORD PTR 48[rsp],edx and ebp, ecx lea edx, DWORD PTR 2400959708[ebx*1+edx] mov ebx, esi ror esi, 2 and ebx, eax or ebp, ebx mov ebx, edi rol ebx, 5 add edx, ebp add edx, ebx ; 40_59 45 mov ebx, DWORD PTR 52[rsp] mov ebp, DWORD PTR 60[rsp] xor ebx, ebp ; mov ebp, r8d xor ebx, r8d mov ebp, DWORD PTR 40[rsp] xor ebx, ebp mov ebp, edi rol ebx, 1 or ebp, esi mov DWORD PTR 52[rsp],ebx and ebp, eax lea ebx, DWORD PTR 2400959708[ecx*1+ebx] mov ecx, edi ror edi, 2 and ecx, esi or ebp, ecx mov ecx, edx rol ecx, 5 add ebx, ebp add ebx, ecx ; 40_59 46 mov ecx, DWORD PTR 56[rsp] ; mov ebp, r12d xor ecx, r12d mov ebp, DWORD PTR 24[rsp] xor ecx, ebp mov ebp, DWORD PTR 44[rsp] xor ecx, ebp mov ebp, edx rol ecx, 1 or ebp, edi mov DWORD PTR 56[rsp],ecx and ebp, esi lea ecx, DWORD PTR 2400959708[eax*1+ecx] mov eax, edx ror edx, 2 and eax, edi or ebp, eax mov eax, ebx rol eax, 5 add ecx, ebp add ecx, eax ; 40_59 47 mov eax, DWORD PTR 60[rsp] ; mov ebp, r13d xor eax, r13d mov ebp, DWORD PTR 28[rsp] xor eax, ebp mov ebp, DWORD PTR 48[rsp] xor eax, ebp mov ebp, ebx rol eax, 1 or ebp, edx mov DWORD PTR 60[rsp],eax and ebp, edi lea eax, DWORD PTR 2400959708[esi*1+eax] mov esi, ebx ror ebx, 2 and esi, edx or ebp, esi mov esi, ecx rol esi, 5 add eax, ebp add eax, esi ; 40_59 48 mov esi, r12d ; mov ebp, r14d xor esi, r14d mov ebp, DWORD PTR 32[rsp] xor esi, ebp mov ebp, DWORD PTR 52[rsp] xor esi, ebp mov ebp, ecx rol esi, 1 or ebp, ebx mov r12d,esi and ebp, edx lea esi, DWORD PTR 2400959708[edi*1+esi] mov edi, ecx ror ecx, 2 and edi, ebx or ebp, edi mov edi, eax rol edi, 5 add esi, ebp add esi, edi ; 40_59 49 mov edi, r13d ; mov ebp, r15d xor edi, r15d mov ebp, DWORD PTR 36[rsp] xor edi, ebp mov ebp, DWORD PTR 56[rsp] xor edi, ebp mov ebp, eax rol edi, 1 or ebp, ecx mov r13d,edi and ebp, ebx lea edi, DWORD PTR 2400959708[edx*1+edi] mov edx, eax ror eax, 2 and edx, ecx or ebp, edx mov edx, esi rol edx, 5 add edi, ebp add edi, edx ; 40_59 50 mov edx, r14d ; mov ebp, r10d xor edx, r10d mov ebp, DWORD PTR 40[rsp] xor edx, ebp mov ebp, DWORD PTR 60[rsp] xor edx, ebp mov ebp, esi rol edx, 1 or ebp, eax mov r14d,edx and ebp, ecx lea edx, DWORD PTR 2400959708[ebx*1+edx] mov ebx, esi ror esi, 2 and ebx, eax or ebp, ebx mov ebx, edi rol ebx, 5 add edx, ebp add edx, ebx ; 40_59 51 mov ebx, r15d ; mov ebp, r8d xor ebx, r8d mov ebp, DWORD PTR 44[rsp] xor ebx, ebp ; mov ebp, r12d xor ebx, r12d mov ebp, edi rol ebx, 1 or ebp, esi mov r15d,ebx and ebp, eax lea ebx, DWORD PTR 2400959708[ecx*1+ebx] mov ecx, edi ror edi, 2 and ecx, esi or ebp, ecx mov ecx, edx rol ecx, 5 add ebx, ebp add ebx, ecx ; 40_59 52 mov ecx, r10d mov ebp, DWORD PTR 24[rsp] xor ecx, ebp mov ebp, DWORD PTR 48[rsp] xor ecx, ebp ; mov ebp, r13d xor ecx, r13d mov ebp, edx rol ecx, 1 or ebp, edi mov r10d,ecx and ebp, esi lea ecx, DWORD PTR 2400959708[eax*1+ecx] mov eax, edx ror edx, 2 and eax, edi or ebp, eax mov eax, ebx rol eax, 5 add ecx, ebp add ecx, eax ; 40_59 53 mov eax, r8d mov ebp, DWORD PTR 28[rsp] xor eax, ebp mov ebp, DWORD PTR 52[rsp] xor eax, ebp ; mov ebp, r14d xor eax, r14d mov ebp, ebx rol eax, 1 or ebp, edx mov r8d,eax and ebp, edi lea eax, DWORD PTR 2400959708[esi*1+eax] mov esi, ebx ror ebx, 2 and esi, edx or ebp, esi mov esi, ecx rol esi, 5 add eax, ebp add eax, esi ; 40_59 54 mov esi, DWORD PTR 24[rsp] mov ebp, DWORD PTR 32[rsp] xor esi, ebp mov ebp, DWORD PTR 56[rsp] xor esi, ebp ; mov ebp, r15d xor esi, r15d mov ebp, ecx rol esi, 1 or ebp, ebx mov DWORD PTR 24[rsp],esi and ebp, edx lea esi, DWORD PTR 2400959708[edi*1+esi] mov edi, ecx ror ecx, 2 and edi, ebx or ebp, edi mov edi, eax rol edi, 5 add esi, ebp add esi, edi ; 40_59 55 mov edi, DWORD PTR 28[rsp] mov ebp, DWORD PTR 36[rsp] xor edi, ebp mov ebp, DWORD PTR 60[rsp] xor edi, ebp ; mov ebp, r10d xor edi, r10d mov ebp, eax rol edi, 1 or ebp, ecx mov DWORD PTR 28[rsp],edi and ebp, ebx lea edi, DWORD PTR 2400959708[edx*1+edi] mov edx, eax ror eax, 2 and edx, ecx or ebp, edx mov edx, esi rol edx, 5 add edi, ebp add edi, edx ; 40_59 56 mov edx, DWORD PTR 32[rsp] mov ebp, DWORD PTR 40[rsp] xor edx, ebp ; mov ebp, r12d xor edx, r12d ; mov ebp, r8d xor edx, r8d mov ebp, esi rol edx, 1 or ebp, eax mov DWORD PTR 32[rsp],edx and ebp, ecx lea edx, DWORD PTR 2400959708[ebx*1+edx] mov ebx, esi ror esi, 2 and ebx, eax or ebp, ebx mov ebx, edi rol ebx, 5 add edx, ebp add edx, ebx ; 40_59 57 mov ebx, DWORD PTR 36[rsp] mov ebp, DWORD PTR 44[rsp] xor ebx, ebp ; mov ebp, r13d xor ebx, r13d mov ebp, DWORD PTR 24[rsp] xor ebx, ebp mov ebp, edi rol ebx, 1 or ebp, esi mov DWORD PTR 36[rsp],ebx and ebp, eax lea ebx, DWORD PTR 2400959708[ecx*1+ebx] mov ecx, edi ror edi, 2 and ecx, esi or ebp, ecx mov ecx, edx rol ecx, 5 add ebx, ebp add ebx, ecx ; 40_59 58 mov ecx, DWORD PTR 40[rsp] mov ebp, DWORD PTR 48[rsp] xor ecx, ebp ; mov ebp, r14d xor ecx, r14d mov ebp, DWORD PTR 28[rsp] xor ecx, ebp mov ebp, edx rol ecx, 1 or ebp, edi mov DWORD PTR 40[rsp],ecx and ebp, esi lea ecx, DWORD PTR 2400959708[eax*1+ecx] mov eax, edx ror edx, 2 and eax, edi or ebp, eax mov eax, ebx rol eax, 5 add ecx, ebp add ecx, eax ; 40_59 59 mov eax, DWORD PTR 44[rsp] mov ebp, DWORD PTR 52[rsp] xor eax, ebp ; mov ebp, r15d xor eax, r15d mov ebp, DWORD PTR 32[rsp] xor eax, ebp mov ebp, ebx rol eax, 1 or ebp, edx mov DWORD PTR 44[rsp],eax and ebp, edi lea eax, DWORD PTR 2400959708[esi*1+eax] mov esi, ebx ror ebx, 2 and esi, edx or ebp, esi mov esi, ecx rol esi, 5 add eax, ebp add eax, esi ; 20_39 60 mov ebp, ecx mov esi, DWORD PTR 48[rsp] ror ecx, 2 xor esi, DWORD PTR 56[rsp] xor ebp, ebx xor esi, r10d xor ebp, edx xor esi, DWORD PTR 36[rsp] rol esi, 1 add ebp, edi mov DWORD PTR 48[rsp],esi mov edi, eax rol edi, 5 lea esi, DWORD PTR 3395469782[ebp*1+esi] add esi, edi ; 20_39 61 mov ebp, eax mov edi, DWORD PTR 52[rsp] ror eax, 2 xor edi, DWORD PTR 60[rsp] xor ebp, ecx xor edi, r8d xor ebp, ebx xor edi, DWORD PTR 40[rsp] rol edi, 1 add ebp, edx mov DWORD PTR 52[rsp],edi mov edx, esi rol edx, 5 lea edi, DWORD PTR 3395469782[ebp*1+edi] add edi, edx ; 20_39 62 mov ebp, esi mov edx, DWORD PTR 56[rsp] ror esi, 2 xor edx, r12d xor ebp, eax xor edx, DWORD PTR 24[rsp] xor ebp, ecx xor edx, DWORD PTR 44[rsp] rol edx, 1 add ebp, ebx mov DWORD PTR 56[rsp],edx mov ebx, edi rol ebx, 5 lea edx, DWORD PTR 3395469782[ebp*1+edx] add edx, ebx ; 20_39 63 mov ebp, edi mov ebx, DWORD PTR 60[rsp] ror edi, 2 xor ebx, r13d xor ebp, esi xor ebx, DWORD PTR 28[rsp] xor ebp, eax xor ebx, DWORD PTR 48[rsp] rol ebx, 1 add ebp, ecx mov DWORD PTR 60[rsp],ebx mov ecx, edx rol ecx, 5 lea ebx, DWORD PTR 3395469782[ebp*1+ebx] add ebx, ecx ; 20_39 64 mov ebp, edx mov ecx, r12d ror edx, 2 xor ecx, r14d xor ebp, edi xor ecx, DWORD PTR 32[rsp] xor ebp, esi xor ecx, DWORD PTR 52[rsp] rol ecx, 1 add ebp, eax mov r12d,ecx mov eax, ebx rol eax, 5 lea ecx, DWORD PTR 3395469782[ebp*1+ecx] add ecx, eax ; 20_39 65 mov ebp, ebx mov eax, r13d ror ebx, 2 xor eax, r15d xor ebp, edx xor eax, DWORD PTR 36[rsp] xor ebp, edi xor eax, DWORD PTR 56[rsp] rol eax, 1 add ebp, esi mov r13d,eax mov esi, ecx rol esi, 5 lea eax, DWORD PTR 3395469782[ebp*1+eax] add eax, esi ; 20_39 66 mov ebp, ecx mov esi, r14d ror ecx, 2 xor esi, r10d xor ebp, ebx xor esi, DWORD PTR 40[rsp] xor ebp, edx xor esi, DWORD PTR 60[rsp] rol esi, 1 add ebp, edi mov r14d,esi mov edi, eax rol edi, 5 lea esi, DWORD PTR 3395469782[ebp*1+esi] add esi, edi ; 20_39 67 mov ebp, eax mov edi, r15d ror eax, 2 xor edi, r8d xor ebp, ecx xor edi, DWORD PTR 44[rsp] xor ebp, ebx xor edi, r12d rol edi, 1 add ebp, edx mov r15d,edi mov edx, esi rol edx, 5 lea edi, DWORD PTR 3395469782[ebp*1+edi] add edi, edx ; 20_39 68 mov ebp, esi mov edx, r10d ror esi, 2 xor edx, DWORD PTR 24[rsp] xor ebp, eax xor edx, DWORD PTR 48[rsp] xor ebp, ecx xor edx, r13d rol edx, 1 add ebp, ebx mov r10d,edx mov ebx, edi rol ebx, 5 lea edx, DWORD PTR 3395469782[ebp*1+edx] add edx, ebx ; 20_39 69 mov ebp, edi mov ebx, r8d ror edi, 2 xor ebx, DWORD PTR 28[rsp] xor ebp, esi xor ebx, DWORD PTR 52[rsp] xor ebp, eax xor ebx, r14d rol ebx, 1 add ebp, ecx mov r8d,ebx mov ecx, edx rol ecx, 5 lea ebx, DWORD PTR 3395469782[ebp*1+ebx] add ebx, ecx ; 20_39 70 mov ebp, edx mov ecx, DWORD PTR 24[rsp] ror edx, 2 xor ecx, DWORD PTR 32[rsp] xor ebp, edi xor ecx, DWORD PTR 56[rsp] xor ebp, esi xor ecx, r15d rol ecx, 1 add ebp, eax mov DWORD PTR 24[rsp],ecx mov eax, ebx rol eax, 5 lea ecx, DWORD PTR 3395469782[ebp*1+ecx] add ecx, eax ; 20_39 71 mov ebp, ebx mov eax, DWORD PTR 28[rsp] ror ebx, 2 xor eax, DWORD PTR 36[rsp] xor ebp, edx xor eax, DWORD PTR 60[rsp] xor ebp, edi xor eax, r10d rol eax, 1 add ebp, esi mov DWORD PTR 28[rsp],eax mov esi, ecx rol esi, 5 lea eax, DWORD PTR 3395469782[ebp*1+eax] add eax, esi ; 20_39 72 mov ebp, ecx mov esi, DWORD PTR 32[rsp] ror ecx, 2 xor esi, DWORD PTR 40[rsp] xor ebp, ebx xor esi, r12d xor ebp, edx xor esi, r8d rol esi, 1 add ebp, edi mov DWORD PTR 32[rsp],esi mov edi, eax rol edi, 5 lea esi, DWORD PTR 3395469782[ebp*1+esi] add esi, edi ; 20_39 73 mov ebp, eax mov edi, DWORD PTR 36[rsp] ror eax, 2 xor edi, DWORD PTR 44[rsp] xor ebp, ecx xor edi, r13d xor ebp, ebx xor edi, DWORD PTR 24[rsp] rol edi, 1 add ebp, edx mov DWORD PTR 36[rsp],edi mov edx, esi rol edx, 5 lea edi, DWORD PTR 3395469782[ebp*1+edi] add edi, edx ; 20_39 74 mov ebp, esi mov edx, DWORD PTR 40[rsp] ror esi, 2 xor edx, DWORD PTR 48[rsp] xor ebp, eax xor edx, r14d xor ebp, ecx xor edx, DWORD PTR 28[rsp] rol edx, 1 add ebp, ebx mov DWORD PTR 40[rsp],edx mov ebx, edi rol ebx, 5 lea edx, DWORD PTR 3395469782[ebp*1+edx] add edx, ebx ; 20_39 75 mov ebp, edi mov ebx, DWORD PTR 44[rsp] ror edi, 2 xor ebx, DWORD PTR 52[rsp] xor ebp, esi xor ebx, r15d xor ebp, eax xor ebx, DWORD PTR 32[rsp] rol ebx, 1 add ebp, ecx mov DWORD PTR 44[rsp],ebx mov ecx, edx rol ecx, 5 lea ebx, DWORD PTR 3395469782[ebp*1+ebx] add ebx, ecx ; 20_39 76 mov ebp, edx mov ecx, DWORD PTR 48[rsp] ror edx, 2 xor ecx, DWORD PTR 56[rsp] xor ebp, edi xor ecx, r10d xor ebp, esi xor ecx, DWORD PTR 36[rsp] rol ecx, 1 add ebp, eax mov DWORD PTR 48[rsp],ecx mov eax, ebx rol eax, 5 lea ecx, DWORD PTR 3395469782[ebp*1+ecx] add ecx, eax ; 20_39 77 mov ebp, ebx mov eax, DWORD PTR 52[rsp] ror ebx, 2 xor eax, DWORD PTR 60[rsp] xor ebp, edx xor eax, r8d xor ebp, edi xor eax, DWORD PTR 40[rsp] rol eax, 1 add ebp, esi mov DWORD PTR 52[rsp],eax mov esi, ecx rol esi, 5 lea eax, DWORD PTR 3395469782[ebp*1+eax] add eax, esi ; 20_39 78 mov ebp, ecx mov esi, DWORD PTR 56[rsp] ror ecx, 2 xor esi, r12d xor ebp, ebx xor esi, DWORD PTR 24[rsp] xor ebp, edx xor esi, DWORD PTR 44[rsp] rol esi, 1 add ebp, edi mov DWORD PTR 56[rsp],esi mov edi, eax rol edi, 5 lea esi, DWORD PTR 3395469782[ebp*1+esi] add esi, edi ; 20_39 79 prefetcht1 [r9] mov ebp, eax mov edi, DWORD PTR 60[rsp] ror eax, 2 xor edi, r13d xor ebp, ecx xor edi, DWORD PTR 28[rsp] xor ebp, ebx xor edi, DWORD PTR 48[rsp] rol edi, 1 add ebp, edx mov DWORD PTR 60[rsp],edi mov edx, esi rol edx, 5 lea edi, DWORD PTR 3395469782[ebp*1+edi] add edi, edx ; End processing ; prefetcht1 [r11+64] ; mov ebp, DWORD PTR 128[rsp] ;mov rbp,r9 mov edx, DWORD PTR 12[r9] add edx, ecx mov ecx, DWORD PTR 4[r9] add ecx, esi mov esi, eax mov eax, DWORD PTR [r9] mov DWORD PTR 12[r9],edx add eax, edi mov edi, DWORD PTR 16[r9] add edi, ebx mov ebx, DWORD PTR 8[r9] add ebx, esi mov DWORD PTR [r9],eax add r11, 64 mov DWORD PTR 8[r9],ebx mov DWORD PTR 16[r9],edi cmp r11,QWORD PTR 112[rsp] mov DWORD PTR 4[r9],ecx jb $L000start mov DWORD PTR [rsp],r12d mov DWORD PTR 4[rsp],r13d mov DWORD PTR 8[rsp],r14d mov DWORD PTR 12[rsp],r15d mov DWORD PTR 16[rsp],r10d mov DWORD PTR 20[rsp],r8d add rsp, 120 pop r15 pop r14 pop r13 pop r12 pop rbp pop rbx pop rsi pop rdi ret sha1_block_asm_data_order ENDP ;_TEXT$ ENDS ;_TEXT$ SEGMENT PAGE 'CODE' ;PUBLIC _sha1_block_asm_host_order sha1_block_asm_host_order PROC NEAR push rdi push rsi push rbx push rbp push r12 push r13 push r14 push r15 ; c = rcx ; p = rdx ; num = r8 mov r9,rcx shl r8, 6 mov r11, rdx add r8, r11 mov rbp,rcx mov edx, DWORD PTR 12[rbp] sub rsp, 120 mov edi, DWORD PTR 16[rbp] mov ebx, DWORD PTR 8[rbp] mov QWORD PTR 112[rsp],r8 ; First we need to setup the X array mov eax, DWORD PTR [r11] mov ecx, DWORD PTR 4[r11] mov r12d,eax mov r13d,ecx mov eax, DWORD PTR 8[r11] mov ecx, DWORD PTR 12[r11] mov r14d,eax mov r15d,ecx mov eax, DWORD PTR 16[r11] mov ecx, DWORD PTR 20[r11] mov r10d,eax mov r8d,ecx mov eax, DWORD PTR 24[r11] mov ecx, DWORD PTR 28[r11] mov DWORD PTR 24[rsp],eax mov DWORD PTR 28[rsp],ecx mov eax, DWORD PTR 32[r11] mov ecx, DWORD PTR 36[r11] mov DWORD PTR 32[rsp],eax mov DWORD PTR 36[rsp],ecx mov eax, DWORD PTR 40[r11] mov ecx, DWORD PTR 44[r11] mov DWORD PTR 40[rsp],eax mov DWORD PTR 44[rsp],ecx mov eax, DWORD PTR 48[r11] mov ecx, DWORD PTR 52[r11] mov DWORD PTR 48[rsp],eax mov DWORD PTR 52[rsp],ecx mov eax, DWORD PTR 56[r11] mov ecx, DWORD PTR 60[r11] mov DWORD PTR 56[rsp],eax mov DWORD PTR 60[rsp],ecx jmp $L001shortcut sha1_block_asm_host_order ENDP ;_TEXT$ ENDS END
//////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// /// Copyright 2021 ArangoDB GmbH, Cologne, Germany /// /// 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. /// /// Copyright holder is ArangoDB GmbH, Cologne, Germany /// /// @author Andrey Abramov //////////////////////////////////////////////////////////////////////////////// #include "sparse_bitmap.hpp" #include "search/bitset_doc_iterator.hpp" namespace { using namespace irs; //////////////////////////////////////////////////////////////////////////////// /// @brief we use dense container for blocks having /// more than this number of documents //////////////////////////////////////////////////////////////////////////////// constexpr uint32_t BITSET_THRESHOLD = (1 << 12) - 1; //////////////////////////////////////////////////////////////////////////////// /// @brief we don't use index for blocks located at a distance that is /// closer than this value //////////////////////////////////////////////////////////////////////////////// constexpr uint32_t BLOCK_SCAN_THRESHOLD = 2; //////////////////////////////////////////////////////////////////////////////// /// @enum BlockType //////////////////////////////////////////////////////////////////////////////// enum BlockType : uint32_t { ////////////////////////////////////////////////////////////////////////////// /// @brief dense block is represented as a bitset container ////////////////////////////////////////////////////////////////////////////// BT_DENSE = 0, ////////////////////////////////////////////////////////////////////////////// /// @brief sprase block is represented as an array of values ////////////////////////////////////////////////////////////////////////////// BT_SPARSE }; // BlockType //////////////////////////////////////////////////////////////////////////////// /// @enum AccessType //////////////////////////////////////////////////////////////////////////////// enum AccessType : uint32_t { ////////////////////////////////////////////////////////////////////////////// /// @enum access data via stream API ////////////////////////////////////////////////////////////////////////////// AT_STREAM, ////////////////////////////////////////////////////////////////////////////// /// @enum direct memory access ////////////////////////////////////////////////////////////////////////////// AT_DIRECT, ////////////////////////////////////////////////////////////////////////////// /// @enum aligned direct memory access ////////////////////////////////////////////////////////////////////////////// AT_DIRECT_ALIGNED }; // AccessType constexpr size_t DENSE_BLOCK_INDEX_BLOCK_SIZE = 512; constexpr size_t DENSE_BLOCK_INDEX_NUM_BLOCKS = sparse_bitmap_writer::BLOCK_SIZE / DENSE_BLOCK_INDEX_BLOCK_SIZE; constexpr size_t DENSE_INDEX_BLOCK_SIZE_IN_BYTES = DENSE_BLOCK_INDEX_NUM_BLOCKS * sizeof(uint16_t); constexpr uint32_t DENSE_BLOCK_INDEX_WORDS_PER_BLOCK = DENSE_BLOCK_INDEX_BLOCK_SIZE / bits_required<size_t>(); template<size_t N> void write_block_index(irs::index_output& out, size_t (&bits)[N]) { uint16_t popcnt = 0; uint16_t index[DENSE_BLOCK_INDEX_NUM_BLOCKS]; static_assert(DENSE_INDEX_BLOCK_SIZE_IN_BYTES == sizeof index); auto* block = reinterpret_cast<byte_type*>(std::begin(index)); auto begin = std::begin(bits); for (; begin != std::end(bits); begin += DENSE_BLOCK_INDEX_WORDS_PER_BLOCK) { irs::write<uint16_t>(block, popcnt); for (uint32_t i = 0; i < DENSE_BLOCK_INDEX_WORDS_PER_BLOCK; ++i) { popcnt += math::math_traits<size_t>::pop(begin[i]); } } out.write_bytes( reinterpret_cast<const byte_type*>(std::begin(index)), sizeof index); } } namespace iresearch { // ----------------------------------------------------------------------------- // --SECTION-- sparse_bitmap_writer // ----------------------------------------------------------------------------- void sparse_bitmap_writer::finish() { flush(block_); if (block_index_.size() < BLOCK_SIZE) { add_block(block_ ? block_ + 1 : 0); } // create a sentinel block to issue doc_limits::eof() automatically block_ = doc_limits::eof() / BLOCK_SIZE; set(doc_limits::eof() % BLOCK_SIZE); do_flush(1); } void sparse_bitmap_writer::do_flush(uint32_t popcnt) { assert(popcnt); assert(block_ < BLOCK_SIZE); assert(popcnt <= BLOCK_SIZE); out_->write_short(static_cast<uint16_t>(block_)); out_->write_short(static_cast<uint16_t>(popcnt - 1)); // -1 to fit uint16_t if (popcnt > BITSET_THRESHOLD) { if (popcnt != BLOCK_SIZE) { write_block_index(*out_, bits_); if constexpr (!is_big_endian()) { std::for_each( std::begin(bits_), std::end(bits_), [](auto& v){ v = numeric_utils::numeric_traits<size_t>::hton(v); }); } out_->write_bytes( reinterpret_cast<const byte_type*>(bits_), sizeof bits_); } } else { bitset_doc_iterator it(std::begin(bits_), std::end(bits_)); while (it.next()) { out_->write_short(static_cast<uint16_t>(it.value())); } } } // ----------------------------------------------------------------------------- // --SECTION-- block_iterator // ----------------------------------------------------------------------------- template<uint32_t> struct container_iterator; template<> struct container_iterator<BT_SPARSE> { template<AccessType Access> static bool seek(sparse_bitmap_iterator* self, doc_id_t target) { target &= 0x0000FFFF; auto& ctx = self->ctx_.sparse; const doc_id_t index_max = self->index_max_; for (; self->index_ < index_max; ++self->index_) { doc_id_t doc; if constexpr (AT_STREAM == Access) { doc = self->in_->read_short(); } else if constexpr (is_big_endian()) { if constexpr (AT_DIRECT_ALIGNED == Access) { doc = *ctx.u16data; } else { static_assert(Access == AT_DIRECT); std::memcpy(&doc, ctx.u16data, sizeof(uint16_t)); } ++ctx.u16data; } else { doc = irs::read<uint16_t>(self->ctx_.u8data); } if (doc >= target) { std::get<document>(self->attrs_).value = self->block_ | doc; std::get<value_index>(self->attrs_).value = self->index_++; return true; } } return false; } }; template<> struct container_iterator<BT_DENSE> { template<AccessType Access> static bool seek(sparse_bitmap_iterator* self, doc_id_t target) { auto& ctx = self->ctx_.dense; const int32_t target_word_idx = (target & 0x0000FFFF) / bits_required<size_t>(); assert(target_word_idx >= ctx.word_idx); if (ctx.index.u16data && uint32_t(target_word_idx - ctx.word_idx) >= DENSE_BLOCK_INDEX_WORDS_PER_BLOCK) { const size_t index_block = (target & 0x0000FFFF) / DENSE_BLOCK_INDEX_BLOCK_SIZE; uint16_t popcnt; std::memcpy(&popcnt, &ctx.index.u16data[index_block], sizeof(uint16_t)); if constexpr (!is_big_endian()) { popcnt = (popcnt >> 8) | ((popcnt & 0xFF) << 8); } const auto word_idx = index_block*DENSE_BLOCK_INDEX_WORDS_PER_BLOCK; const auto delta = word_idx - ctx.word_idx; assert(delta > 0); if constexpr (AT_STREAM == Access) { self->in_->seek(self->in_->file_pointer() + (delta-1)*sizeof(size_t)); ctx.word = self->in_->read_long(); } else { ctx.u64data += delta; ctx.word = ctx.u64data[-1]; } ctx.popcnt = ctx.index_base + popcnt + math::math_traits<size_t>::pop(ctx.word); ctx.word_idx = word_idx; } uint32_t word_delta = target_word_idx - ctx.word_idx; if constexpr (AT_STREAM == Access) { for (; word_delta; --word_delta) { ctx.word = self->in_->read_long(); ctx.popcnt += math::math_traits<size_t>::pop(ctx.word); } ctx.word_idx = target_word_idx; } else { if (word_delta) { // FIMXE consider using SSE/avx256/avx512 extensions for large skips const size_t* end = ctx.u64data + word_delta; for (; ctx.u64data < end; ++ctx.u64data) { if constexpr (AT_DIRECT_ALIGNED == Access) { ctx.word = *ctx.u64data; } else { static_assert(AT_DIRECT == Access); std::memcpy(&ctx.word, ctx.u64data, sizeof(size_t)); } ctx.popcnt += math::math_traits<size_t>::pop(ctx.word); } if constexpr (!is_big_endian()) { ctx.word = numeric_utils::numeric_traits<size_t>::ntoh(ctx.word); } ctx.word_idx = target_word_idx; } } const size_t left = ctx.word >> (target % bits_required<size_t>()); if (left) { const doc_id_t offset = math::math_traits<decltype(left)>::ctz(left); std::get<document>(self->attrs_).value = target + offset; std::get<value_index>(self->attrs_).value = ctx.popcnt - math::math_traits<decltype(left)>::pop(left); return true; } constexpr int32_t NUM_BLOCKS = sparse_bitmap_writer::NUM_BLOCKS; ++ctx.word_idx; for (; ctx.word_idx < NUM_BLOCKS; ++ctx.word_idx) { if constexpr (AT_STREAM == Access) { ctx.word = self->in_->read_long(); } else { if constexpr (AT_DIRECT_ALIGNED == Access) { ctx.word = *ctx.u64data; } else { static_assert(AT_DIRECT == Access); std::memcpy(&ctx.word, ctx.u64data, sizeof(size_t)); } ++ctx.u64data; } if (ctx.word) { if constexpr (AT_STREAM != Access && !is_big_endian()) { ctx.word = numeric_utils::numeric_traits<size_t>::ntoh(ctx.word); } const doc_id_t offset = math::math_traits<size_t>::ctz(ctx.word); std::get<document>(self->attrs_).value = self->block_ + ctx.word_idx * bits_required<size_t>() + offset; std::get<value_index>(self->attrs_).value = ctx.popcnt; ctx.popcnt += math::math_traits<size_t>::pop(ctx.word); return true; } } return false; } }; // ----------------------------------------------------------------------------- // --SECTION-- sparse_bitmap_iterator // ----------------------------------------------------------------------------- /*static*/ bool sparse_bitmap_iterator::initial_seek( sparse_bitmap_iterator* self, doc_id_t target) { assert(!doc_limits::valid(self->value())); assert(0 == (target & 0xFFFF0000)); // we can get there iff the very // first block is not yet read self->read_block_header(); self->seek(target); return true; } sparse_bitmap_iterator::sparse_bitmap_iterator( memory::managed_ptr<index_input>&& in, const options& opts) : in_{std::move(in)}, seek_func_{&sparse_bitmap_iterator::initial_seek}, block_index_{opts.blocks}, cont_begin_{in_->file_pointer()}, origin_{cont_begin_}, use_block_index_{opts.use_block_index} { assert(in_); } void sparse_bitmap_iterator::reset() { std::get<document>(attrs_).value = irs::doc_limits::invalid(); seek_func_ = &sparse_bitmap_iterator::initial_seek; cont_begin_ = origin_; index_max_ = 0; in_->seek(cont_begin_); } void sparse_bitmap_iterator::read_block_header() { block_ = (in_->read_short() << 16); const uint32_t popcnt = 1 + static_cast<uint16_t>(in_->read_short()); index_ = index_max_; index_max_ += popcnt; if (popcnt == sparse_bitmap_writer::BLOCK_SIZE) { ctx_.all.missing = block_ - index_; cont_begin_ = in_->file_pointer(); seek_func_ = [](sparse_bitmap_iterator* self, doc_id_t target) { std::get<document>(self->attrs_).value = target; std::get<value_index>(self->attrs_).value = target - self->ctx_.all.missing; return true; }; } else if (popcnt <= BITSET_THRESHOLD) { constexpr BlockType type = BT_SPARSE; const size_t block_size = 2*popcnt; cont_begin_ = in_->file_pointer() + block_size; ctx_.u8data = in_->read_buffer(block_size, BufferHint::NORMAL); // FIXME check alignment seek_func_ = ctx_.u8data ? &container_iterator<type>::seek<AT_DIRECT> : &container_iterator<type>::seek<AT_STREAM>; } else { constexpr BlockType type = BT_DENSE; constexpr size_t block_size = sparse_bitmap_writer::BLOCK_SIZE / bits_required<byte_type>(); ctx_.dense.word_idx = -1; ctx_.dense.popcnt = index_; ctx_.dense.index_base = index_; if (use_block_index_) { ctx_.dense.index.u8data = in_->read_buffer( DENSE_INDEX_BLOCK_SIZE_IN_BYTES, BufferHint::PERSISTENT); if (!ctx_.dense.index.u8data) { if (!block_index_data_) { block_index_data_ = memory::make_unique<byte_type[]>( DENSE_INDEX_BLOCK_SIZE_IN_BYTES); } ctx_.dense.index.u8data = block_index_data_.get(); in_->read_bytes(block_index_data_.get(), DENSE_INDEX_BLOCK_SIZE_IN_BYTES); } } else { ctx_.dense.index.u8data = nullptr; in_->seek(in_->file_pointer() + DENSE_INDEX_BLOCK_SIZE_IN_BYTES); } cont_begin_ = in_->file_pointer() + block_size; ctx_.u8data = in_->read_buffer(block_size, BufferHint::NORMAL); // FIXME check alignment seek_func_ = ctx_.u8data ? &container_iterator<type>::seek<AT_DIRECT> : &container_iterator<type>::seek<AT_STREAM>; } } void sparse_bitmap_iterator::seek_to_block(doc_id_t target) { assert(target / sparse_bitmap_writer::BLOCK_SIZE); if (block_index_.begin()) { assert(!block_index_.empty() && block_index_.end()); const doc_id_t target_block = target / sparse_bitmap_writer::BLOCK_SIZE; if (target_block >= (block_ / sparse_bitmap_writer::BLOCK_SIZE + BLOCK_SCAN_THRESHOLD)) { const auto* block = block_index_.begin() + target_block; if (block >= block_index_.end()) { block = block_index_.end() - 1; } index_max_ = block->index; in_->seek(origin_ + block->offset); read_block_header(); return; } } do { in_->seek(cont_begin_); read_block_header(); } while (block_ < target); } doc_id_t sparse_bitmap_iterator::seek(doc_id_t target) { // FIXME if (target <= value()) { return value(); } const doc_id_t target_block = target & 0xFFFF0000; if (block_ < target_block) { seek_to_block(target_block); } if (block_ == target_block) { assert(seek_func_); if (seek_func_(this, target)) { return value(); } read_block_header(); } assert(seek_func_); seek_func_(this, block_); return value(); } } // iresearch
#include <functional> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <sstream> #include <vector> using namespace std; auto to_binary = [&](auto n) { vector<char> b; while (n != 0) { b.push_back(n & 1 == 1 ? '1' : '0'); n /= 2; } reverse(b.begin(), b.end()); ostringstream bss; std::copy(b.begin(), b.end(), ostream_iterator<char>(bss)); return bss.str(); }; class Solution { public: bool queryString(string str, int N) { for (auto i = 0; i <= N; i++) { if (str.find(to_binary(i)) == string::npos) { return false; } } return true; } };
; A021708: Decimal expansion of 1/704. ; 0,0,1,4,2,0,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4,5,4 add $0,1 mov $1,10 pow $1,$0 mul $1,2 div $1,1408 mod $1,10 mov $0,$1
;------------------------------------------------------------------------------ ; ; Copyright (c) 2014, Intel Corporation. All rights reserved.<BR> ; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: ; ; SecEntry.asm ; ; Abstract: ; ; This is the code that goes from real-mode to protected mode. ; It consumes the reset vector, calls two basic APIs from FSP binary. ; ;------------------------------------------------------------------------------ INCLUDE Fsp.inc .686p .xmm .model small, c EXTRN CallPeiCoreEntryPoint:NEAR EXTRN TempRamInitParams:FAR ; Pcds EXTRN PcdGet32 (PcdFlashFvFspBase):DWORD EXTRN PcdGet32 (PcdFlashFvFspSize):DWORD _TEXT_REALMODE SEGMENT PARA PUBLIC USE16 'CODE' ASSUME CS:_TEXT_REALMODE, DS:_TEXT_REALMODE ;---------------------------------------------------------------------------- ; ; Procedure: _ModuleEntryPoint ; ; Input: None ; ; Output: None ; ; Destroys: Assume all registers ; ; Description: ; ; Transition to non-paged flat-model protected mode from a ; hard-coded GDT that provides exactly two descriptors. ; This is a bare bones transition to protected mode only ; used for a while in PEI and possibly DXE. ; ; After enabling protected mode, a far jump is executed to ; transfer to PEI using the newly loaded GDT. ; ; Return: None ; ; MMX Usage: ; MM0 = BIST State ; MM5 = Save time-stamp counter value high32bit ; MM6 = Save time-stamp counter value low32bit. ; ;---------------------------------------------------------------------------- align 4 _ModuleEntryPoint PROC NEAR C PUBLIC fninit ; clear any pending Floating point exceptions ; ; Store the BIST value in mm0 ; movd mm0, eax ; ; Save time-stamp counter value ; rdtsc load 64bit time-stamp counter to EDX:EAX ; rdtsc movd mm5, edx movd mm6, eax ; ; Load the GDT table in GdtDesc ; mov esi, OFFSET GdtDesc DB 66h lgdt fword ptr cs:[si] ; ; Transition to 16 bit protected mode ; mov eax, cr0 ; Get control register 0 or eax, 00000003h ; Set PE bit (bit #0) & MP bit (bit #1) mov cr0, eax ; Activate protected mode mov eax, cr4 ; Get control register 4 or eax, 00000600h ; Set OSFXSR bit (bit #9) & OSXMMEXCPT bit (bit #10) mov cr4, eax ; ; Now we're in 16 bit protected mode ; Set up the selectors for 32 bit protected mode entry ; mov ax, SYS_DATA_SEL mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax ; ; Transition to Flat 32 bit protected mode ; The jump to a far pointer causes the transition to 32 bit mode ; mov esi, offset ProtectedModeEntryLinearAddress jmp fword ptr cs:[si] _ModuleEntryPoint ENDP _TEXT_REALMODE ENDS _TEXT_PROTECTED_MODE SEGMENT PARA PUBLIC USE32 'CODE' ASSUME CS:_TEXT_PROTECTED_MODE, DS:_TEXT_PROTECTED_MODE ;---------------------------------------------------------------------------- ; ; Procedure: ProtectedModeEntryPoint ; ; Input: None ; ; Output: None ; ; Destroys: Assume all registers ; ; Description: ; ; This function handles: ; Call two basic APIs from FSP binary ; Initializes stack with some early data (BIST, PEI entry, etc) ; ; Return: None ; ;---------------------------------------------------------------------------- align 4 ProtectedModeEntryPoint PROC NEAR PUBLIC ; Find the fsp info header mov edi, PcdGet32 (PcdFlashFvFspBase) mov ecx, PcdGet32 (PcdFlashFvFspSize) mov eax, dword ptr [edi + FVH_SIGINATURE_OFFSET] cmp eax, FVH_SIGINATURE_VALID_VALUE jnz FspHeaderNotFound xor eax, eax mov ax, word ptr [edi + FVH_EXTHEADER_OFFSET_OFFSET] cmp ax, 0 jnz FspFvExtHeaderExist xor eax, eax mov ax, word ptr [edi + FVH_HEADER_LENGTH_OFFSET] ; Bypass Fv Header add edi, eax jmp FspCheckFfsHeader FspFvExtHeaderExist: add edi, eax mov eax, dword ptr [edi + FVH_EXTHEADER_SIZE_OFFSET] ; Bypass Ext Fv Header add edi, eax ; Round up to 8 byte alignment mov eax, edi and al, 07h jz FspCheckFfsHeader and edi, 0FFFFFFF8h add edi, 08h FspCheckFfsHeader: ; Check the ffs guid mov eax, dword ptr [edi] cmp eax, FSP_HEADER_GUID_DWORD1 jnz FspHeaderNotFound mov eax, dword ptr [edi + 4] cmp eax, FSP_HEADER_GUID_DWORD2 jnz FspHeaderNotFound mov eax, dword ptr [edi + 8] cmp eax, FSP_HEADER_GUID_DWORD3 jnz FspHeaderNotFound mov eax, dword ptr [edi + 0Ch] cmp eax, FSP_HEADER_GUID_DWORD4 jnz FspHeaderNotFound add edi, FFS_HEADER_SIZE_VALUE ; Bypass the ffs header ; Check the section type as raw section mov al, byte ptr [edi + SECTION_HEADER_TYPE_OFFSET] cmp al, 019h jnz FspHeaderNotFound add edi, RAW_SECTION_HEADER_SIZE_VALUE ; Bypass the section header jmp FspHeaderFound FspHeaderNotFound: jmp $ FspHeaderFound: ; Get the fsp TempRamInit Api address mov eax, dword ptr [edi + FSP_HEADER_IMAGEBASE_OFFSET] add eax, dword ptr [edi + FSP_HEADER_TEMPRAMINIT_OFFSET] ; Setup the hardcode stack mov esp, OFFSET TempRamInitStack ; Call the fsp TempRamInit Api jmp eax TempRamInitDone: cmp eax, 0 jnz FspApiFailed ; ECX: start of range ; EDX: end of range mov esp, edx push edx push ecx push eax ; zero - no hob list yet call CallPeiCoreEntryPoint FspApiFailed: jmp $ align 10h TempRamInitStack: DD OFFSET TempRamInitDone DD OFFSET TempRamInitParams ProtectedModeEntryPoint ENDP ; ; ROM-based Global-Descriptor Table for the Tiano PEI Phase ; align 16 PUBLIC BootGdtTable ; ; GDT[0]: 0x00: Null entry, never used. ; NULL_SEL EQU $ - GDT_BASE ; Selector [0] GDT_BASE: BootGdtTable DD 0 DD 0 ; ; Linear data segment descriptor ; LINEAR_SEL EQU $ - GDT_BASE ; Selector [0x8] DW 0FFFFh ; limit 0xFFFFF DW 0 ; base 0 DB 0 DB 092h ; present, ring 0, data, expand-up, writable DB 0CFh ; page-granular, 32-bit DB 0 ; ; Linear code segment descriptor ; LINEAR_CODE_SEL EQU $ - GDT_BASE ; Selector [0x10] DW 0FFFFh ; limit 0xFFFFF DW 0 ; base 0 DB 0 DB 09Bh ; present, ring 0, data, expand-up, not-writable DB 0CFh ; page-granular, 32-bit DB 0 ; ; System data segment descriptor ; SYS_DATA_SEL EQU $ - GDT_BASE ; Selector [0x18] DW 0FFFFh ; limit 0xFFFFF DW 0 ; base 0 DB 0 DB 093h ; present, ring 0, data, expand-up, not-writable DB 0CFh ; page-granular, 32-bit DB 0 ; ; System code segment descriptor ; SYS_CODE_SEL EQU $ - GDT_BASE ; Selector [0x20] DW 0FFFFh ; limit 0xFFFFF DW 0 ; base 0 DB 0 DB 09Ah ; present, ring 0, data, expand-up, writable DB 0CFh ; page-granular, 32-bit DB 0 ; ; Spare segment descriptor ; SYS16_CODE_SEL EQU $ - GDT_BASE ; Selector [0x28] DW 0FFFFh ; limit 0xFFFFF DW 0 ; base 0 DB 0Eh ; Changed from F000 to E000. DB 09Bh ; present, ring 0, code, expand-up, writable DB 00h ; byte-granular, 16-bit DB 0 ; ; Spare segment descriptor ; SYS16_DATA_SEL EQU $ - GDT_BASE ; Selector [0x30] DW 0FFFFh ; limit 0xFFFF DW 0 ; base 0 DB 0 DB 093h ; present, ring 0, data, expand-up, not-writable DB 00h ; byte-granular, 16-bit DB 0 ; ; Spare segment descriptor ; SPARE5_SEL EQU $ - GDT_BASE ; Selector [0x38] DW 0 ; limit 0 DW 0 ; base 0 DB 0 DB 0 ; present, ring 0, data, expand-up, writable DB 0 ; page-granular, 32-bit DB 0 GDT_SIZE EQU $ - BootGdtTable ; Size, in bytes ; ; GDT Descriptor ; GdtDesc: ; GDT descriptor DW GDT_SIZE - 1 ; GDT limit DD OFFSET BootGdtTable ; GDT base address ProtectedModeEntryLinearAddress LABEL FWORD ProtectedModeEntryLinearOffset LABEL DWORD DD OFFSET ProtectedModeEntryPoint ; Offset of our 32 bit code DW LINEAR_CODE_SEL _TEXT_PROTECTED_MODE ENDS END
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1991 -- All Rights Reserved PROJECT: PC GEOS MODULE: FILE: tsSmallFind.asm AUTHOR: John Wedgwood, Nov 26, 1991 ROUTINES: Name Description ---- ----------- REVISION HISTORY: Name Date Description ---- ---- ----------- John 11/26/91 Initial revision DESCRIPTION: Code for finding strings in small text objects. $Id: tsSmallFind.asm,v 1.1 97/04/07 11:22:03 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ TextStorageCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SmallFindStringInText %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Find a string in a small text object. CALLED BY: TS_FindStringInText via CallStorageHandler PASS: *ds:si = Instance ptr cx = Offset to char in text object to begin search ax = Offset into text object of last char to include in search es = Segment address of SearchReplaceStruct RETURN: carry set if string not found dx.ax = # chars in match bp.cx = offset to string found DESTROYED: bx PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- atw 12/26/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SmallFindStringInText proc far uses ds, es, si .enter class VisTextClass call TextStorage_DerefVis_DI mov di, ds:[di].VTI_text ; mov di, ds:[di] ;DS:DI <- ptr to start of text chunk mov bx, di ; mov bp, di ;DS:BP <- ptr to start of text chunk DBCS < shl cx, 1 ;char offset -> byte offset > add di, cx ;DS:DI <- ptr to first char to include ; in search DBCS < shl ax, 1 ;char offset -> byte offset > add bx, ax ;DS:BX <- ptr to last char to include ; in search call TS_GetTextSize ;AX <- # chars in this object mov_tr dx, ax ;DX <- # chars to search in in text ; object segxchg es, ds ;ES <- segment of text object ;DS <- segment of SearchReplaceStruct clr cx ;Null terminated string mov si, offset SRS_searchString ;DS:SI <- ptr to string to ; search for mov al, ds:[SRS_params] call TextSearchInString pushf ;Save return code clr dx ;DX.AX <- # chars in match mov ax, cx ; sub di, bp ;DI <- offset from start of text ; that match was found clr bp ; mov cx, di ;BP:CX <- offset to string if found DBCS < shr cx, 1 ;cx: byte offset -> char offset > popf .leave ret SmallFindStringInText endp TextStorageCode ends
_pwd: file format elf32-i386 Disassembly of section .text: 00000000 <main>: exit(); } int main(int argc,char *argv[]) { 0: 8d 4c 24 04 lea 0x4(%esp),%ecx 4: 83 e4 f0 and $0xfffffff0,%esp 7: ff 71 fc pushl -0x4(%ecx) a: 55 push %ebp b: 89 e5 mov %esp,%ebp d: 56 push %esi e: 53 push %ebx f: 51 push %ecx 10: 81 ec 84 00 00 00 sub $0x84,%esp 16: 8b 71 04 mov 0x4(%ecx),%esi char cwd[100]; int logical=0,physical=1; int err=open("/temp.pwd",O_RDONLY); 19: 6a 00 push $0x0 1b: 68 1b 08 00 00 push $0x81b 20: e8 5d 03 00 00 call 382 <open> 25: 89 c3 mov %eax,%ebx if(argv[1][0]=='-') 27: 8b 46 04 mov 0x4(%esi),%eax 2a: 83 c4 10 add $0x10,%esp 2d: 80 38 2d cmpb $0x2d,(%eax) 30: 74 49 je 7b <main+0x7b> { printf(1,"pwd: invalid option %s\nFor help: 'pwd --help'\n",argv[1]); exit(); } } if(err<0) 32: 85 db test %ebx,%ebx 34: 78 32 js 68 <main+0x68> { printf(1,"/\n"); exit(); } int red=read(err,cwd,sizeof(cwd)); 36: 8d 75 84 lea -0x7c(%ebp),%esi 39: 52 push %edx 3a: 6a 64 push $0x64 3c: 56 push %esi 3d: 53 push %ebx 3e: e8 17 03 00 00 call 35a <read> if(red<0) 43: 83 c4 10 add $0x10,%esp 46: 85 c0 test %eax,%eax 48: 78 4a js 94 <main+0x94> { printf(2,"ERROR\n"); exit(); } close(err); 4a: 83 ec 0c sub $0xc,%esp 4d: 53 push %ebx 4e: e8 17 03 00 00 call 36a <close> // di xv6 tidak ada symlink. if(logical==1 || physical==1 || logical==0) printf(1,"%s\n",cwd); 53: 83 c4 0c add $0xc,%esp 56: 56 push %esi 57: 68 36 08 00 00 push $0x836 5c: 6a 01 push $0x1 5e: e8 3d 04 00 00 call 4a0 <printf> exit(); 63: e8 da 02 00 00 call 342 <exit> printf(1,"/\n"); 68: 51 push %ecx 69: 51 push %ecx 6a: 68 2c 08 00 00 push $0x82c 6f: 6a 01 push $0x1 71: e8 2a 04 00 00 call 4a0 <printf> exit(); 76: e8 c7 02 00 00 call 342 <exit> if(strcmp(argv[1],"--help")==0) help(); 7b: 52 push %edx 7c: 52 push %edx 7d: 68 25 08 00 00 push $0x825 82: 50 push %eax 83: e8 98 00 00 00 call 120 <strcmp> 88: 83 c4 10 add $0x10,%esp 8b: 85 c0 test %eax,%eax 8d: 75 18 jne a7 <main+0xa7> 8f: e8 2c 00 00 00 call c0 <help> printf(2,"ERROR\n"); 94: 50 push %eax 95: 50 push %eax 96: 68 2f 08 00 00 push $0x82f 9b: 6a 02 push $0x2 9d: e8 fe 03 00 00 call 4a0 <printf> exit(); a2: e8 9b 02 00 00 call 342 <exit> printf(1,"pwd: invalid option %s\nFor help: 'pwd --help'\n",argv[1]); a7: 53 push %ebx a8: ff 76 04 pushl 0x4(%esi) ab: 68 3c 08 00 00 push $0x83c b0: 6a 01 push $0x1 b2: e8 e9 03 00 00 call 4a0 <printf> exit(); b7: e8 86 02 00 00 call 342 <exit> bc: 66 90 xchg %ax,%ax be: 66 90 xchg %ax,%ax 000000c0 <help>: help(){ c0: 55 push %ebp c1: 89 e5 mov %esp,%ebp c3: 83 ec 10 sub $0x10,%esp printf(1,"Usage:\n"); c6: 68 f8 07 00 00 push $0x7f8 cb: 6a 01 push $0x1 cd: e8 ce 03 00 00 call 4a0 <printf> printf(1,"pwd --help : options list\n"); d2: 58 pop %eax d3: 5a pop %edx d4: 68 00 08 00 00 push $0x800 d9: 6a 01 push $0x1 db: e8 c0 03 00 00 call 4a0 <printf> exit(); e0: e8 5d 02 00 00 call 342 <exit> e5: 66 90 xchg %ax,%ax e7: 66 90 xchg %ax,%ax e9: 66 90 xchg %ax,%ax eb: 66 90 xchg %ax,%ax ed: 66 90 xchg %ax,%ax ef: 90 nop 000000f0 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { f0: 55 push %ebp f1: 89 e5 mov %esp,%ebp f3: 53 push %ebx f4: 8b 45 08 mov 0x8(%ebp),%eax f7: 8b 4d 0c mov 0xc(%ebp),%ecx char *os; os = s; while((*s++ = *t++) != 0) fa: 89 c2 mov %eax,%edx fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 100: 83 c1 01 add $0x1,%ecx 103: 0f b6 59 ff movzbl -0x1(%ecx),%ebx 107: 83 c2 01 add $0x1,%edx 10a: 84 db test %bl,%bl 10c: 88 5a ff mov %bl,-0x1(%edx) 10f: 75 ef jne 100 <strcpy+0x10> ; return os; } 111: 5b pop %ebx 112: 5d pop %ebp 113: c3 ret 114: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 11a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00000120 <strcmp>: int strcmp(const char *p, const char *q) { 120: 55 push %ebp 121: 89 e5 mov %esp,%ebp 123: 53 push %ebx 124: 8b 55 08 mov 0x8(%ebp),%edx 127: 8b 4d 0c mov 0xc(%ebp),%ecx while(*p && *p == *q) 12a: 0f b6 02 movzbl (%edx),%eax 12d: 0f b6 19 movzbl (%ecx),%ebx 130: 84 c0 test %al,%al 132: 75 1c jne 150 <strcmp+0x30> 134: eb 2a jmp 160 <strcmp+0x40> 136: 8d 76 00 lea 0x0(%esi),%esi 139: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi p++, q++; 140: 83 c2 01 add $0x1,%edx while(*p && *p == *q) 143: 0f b6 02 movzbl (%edx),%eax p++, q++; 146: 83 c1 01 add $0x1,%ecx 149: 0f b6 19 movzbl (%ecx),%ebx while(*p && *p == *q) 14c: 84 c0 test %al,%al 14e: 74 10 je 160 <strcmp+0x40> 150: 38 d8 cmp %bl,%al 152: 74 ec je 140 <strcmp+0x20> return (uchar)*p - (uchar)*q; 154: 29 d8 sub %ebx,%eax } 156: 5b pop %ebx 157: 5d pop %ebp 158: c3 ret 159: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 160: 31 c0 xor %eax,%eax return (uchar)*p - (uchar)*q; 162: 29 d8 sub %ebx,%eax } 164: 5b pop %ebx 165: 5d pop %ebp 166: c3 ret 167: 89 f6 mov %esi,%esi 169: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000170 <strlen>: uint strlen(const char *s) { 170: 55 push %ebp 171: 89 e5 mov %esp,%ebp 173: 8b 4d 08 mov 0x8(%ebp),%ecx int n; for(n = 0; s[n]; n++) 176: 80 39 00 cmpb $0x0,(%ecx) 179: 74 15 je 190 <strlen+0x20> 17b: 31 d2 xor %edx,%edx 17d: 8d 76 00 lea 0x0(%esi),%esi 180: 83 c2 01 add $0x1,%edx 183: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1) 187: 89 d0 mov %edx,%eax 189: 75 f5 jne 180 <strlen+0x10> ; return n; } 18b: 5d pop %ebp 18c: c3 ret 18d: 8d 76 00 lea 0x0(%esi),%esi for(n = 0; s[n]; n++) 190: 31 c0 xor %eax,%eax } 192: 5d pop %ebp 193: c3 ret 194: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 19a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 000001a0 <memset>: void* memset(void *dst, int c, uint n) { 1a0: 55 push %ebp 1a1: 89 e5 mov %esp,%ebp 1a3: 57 push %edi 1a4: 8b 55 08 mov 0x8(%ebp),%edx } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : 1a7: 8b 4d 10 mov 0x10(%ebp),%ecx 1aa: 8b 45 0c mov 0xc(%ebp),%eax 1ad: 89 d7 mov %edx,%edi 1af: fc cld 1b0: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 1b2: 89 d0 mov %edx,%eax 1b4: 5f pop %edi 1b5: 5d pop %ebp 1b6: c3 ret 1b7: 89 f6 mov %esi,%esi 1b9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000001c0 <strchr>: char* strchr(const char *s, char c) { 1c0: 55 push %ebp 1c1: 89 e5 mov %esp,%ebp 1c3: 53 push %ebx 1c4: 8b 45 08 mov 0x8(%ebp),%eax 1c7: 8b 5d 0c mov 0xc(%ebp),%ebx for(; *s; s++) 1ca: 0f b6 10 movzbl (%eax),%edx 1cd: 84 d2 test %dl,%dl 1cf: 74 1d je 1ee <strchr+0x2e> if(*s == c) 1d1: 38 d3 cmp %dl,%bl 1d3: 89 d9 mov %ebx,%ecx 1d5: 75 0d jne 1e4 <strchr+0x24> 1d7: eb 17 jmp 1f0 <strchr+0x30> 1d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1e0: 38 ca cmp %cl,%dl 1e2: 74 0c je 1f0 <strchr+0x30> for(; *s; s++) 1e4: 83 c0 01 add $0x1,%eax 1e7: 0f b6 10 movzbl (%eax),%edx 1ea: 84 d2 test %dl,%dl 1ec: 75 f2 jne 1e0 <strchr+0x20> return (char*)s; return 0; 1ee: 31 c0 xor %eax,%eax } 1f0: 5b pop %ebx 1f1: 5d pop %ebp 1f2: c3 ret 1f3: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 1f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000200 <gets>: char* gets(char *buf, int max) { 200: 55 push %ebp 201: 89 e5 mov %esp,%ebp 203: 57 push %edi 204: 56 push %esi 205: 53 push %ebx int i, cc; char c; for(i=0; i+1 < max; ){ 206: 31 f6 xor %esi,%esi 208: 89 f3 mov %esi,%ebx { 20a: 83 ec 1c sub $0x1c,%esp 20d: 8b 7d 08 mov 0x8(%ebp),%edi for(i=0; i+1 < max; ){ 210: eb 2f jmp 241 <gets+0x41> 212: 8d b6 00 00 00 00 lea 0x0(%esi),%esi cc = read(0, &c, 1); 218: 8d 45 e7 lea -0x19(%ebp),%eax 21b: 83 ec 04 sub $0x4,%esp 21e: 6a 01 push $0x1 220: 50 push %eax 221: 6a 00 push $0x0 223: e8 32 01 00 00 call 35a <read> if(cc < 1) 228: 83 c4 10 add $0x10,%esp 22b: 85 c0 test %eax,%eax 22d: 7e 1c jle 24b <gets+0x4b> break; buf[i++] = c; 22f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax 233: 83 c7 01 add $0x1,%edi 236: 88 47 ff mov %al,-0x1(%edi) if(c == '\n' || c == '\r') 239: 3c 0a cmp $0xa,%al 23b: 74 23 je 260 <gets+0x60> 23d: 3c 0d cmp $0xd,%al 23f: 74 1f je 260 <gets+0x60> for(i=0; i+1 < max; ){ 241: 83 c3 01 add $0x1,%ebx 244: 3b 5d 0c cmp 0xc(%ebp),%ebx 247: 89 fe mov %edi,%esi 249: 7c cd jl 218 <gets+0x18> 24b: 89 f3 mov %esi,%ebx break; } buf[i] = '\0'; return buf; } 24d: 8b 45 08 mov 0x8(%ebp),%eax buf[i] = '\0'; 250: c6 03 00 movb $0x0,(%ebx) } 253: 8d 65 f4 lea -0xc(%ebp),%esp 256: 5b pop %ebx 257: 5e pop %esi 258: 5f pop %edi 259: 5d pop %ebp 25a: c3 ret 25b: 90 nop 25c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 260: 8b 75 08 mov 0x8(%ebp),%esi 263: 8b 45 08 mov 0x8(%ebp),%eax 266: 01 de add %ebx,%esi 268: 89 f3 mov %esi,%ebx buf[i] = '\0'; 26a: c6 03 00 movb $0x0,(%ebx) } 26d: 8d 65 f4 lea -0xc(%ebp),%esp 270: 5b pop %ebx 271: 5e pop %esi 272: 5f pop %edi 273: 5d pop %ebp 274: c3 ret 275: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 279: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000280 <stat>: int stat(const char *n, struct stat *st) { 280: 55 push %ebp 281: 89 e5 mov %esp,%ebp 283: 56 push %esi 284: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); 285: 83 ec 08 sub $0x8,%esp 288: 6a 00 push $0x0 28a: ff 75 08 pushl 0x8(%ebp) 28d: e8 f0 00 00 00 call 382 <open> if(fd < 0) 292: 83 c4 10 add $0x10,%esp 295: 85 c0 test %eax,%eax 297: 78 27 js 2c0 <stat+0x40> return -1; r = fstat(fd, st); 299: 83 ec 08 sub $0x8,%esp 29c: ff 75 0c pushl 0xc(%ebp) 29f: 89 c3 mov %eax,%ebx 2a1: 50 push %eax 2a2: e8 f3 00 00 00 call 39a <fstat> close(fd); 2a7: 89 1c 24 mov %ebx,(%esp) r = fstat(fd, st); 2aa: 89 c6 mov %eax,%esi close(fd); 2ac: e8 b9 00 00 00 call 36a <close> return r; 2b1: 83 c4 10 add $0x10,%esp } 2b4: 8d 65 f8 lea -0x8(%ebp),%esp 2b7: 89 f0 mov %esi,%eax 2b9: 5b pop %ebx 2ba: 5e pop %esi 2bb: 5d pop %ebp 2bc: c3 ret 2bd: 8d 76 00 lea 0x0(%esi),%esi return -1; 2c0: be ff ff ff ff mov $0xffffffff,%esi 2c5: eb ed jmp 2b4 <stat+0x34> 2c7: 89 f6 mov %esi,%esi 2c9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000002d0 <atoi>: int atoi(const char *s) { 2d0: 55 push %ebp 2d1: 89 e5 mov %esp,%ebp 2d3: 53 push %ebx 2d4: 8b 4d 08 mov 0x8(%ebp),%ecx int n; n = 0; while('0' <= *s && *s <= '9') 2d7: 0f be 11 movsbl (%ecx),%edx 2da: 8d 42 d0 lea -0x30(%edx),%eax 2dd: 3c 09 cmp $0x9,%al n = 0; 2df: b8 00 00 00 00 mov $0x0,%eax while('0' <= *s && *s <= '9') 2e4: 77 1f ja 305 <atoi+0x35> 2e6: 8d 76 00 lea 0x0(%esi),%esi 2e9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi n = n*10 + *s++ - '0'; 2f0: 8d 04 80 lea (%eax,%eax,4),%eax 2f3: 83 c1 01 add $0x1,%ecx 2f6: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax while('0' <= *s && *s <= '9') 2fa: 0f be 11 movsbl (%ecx),%edx 2fd: 8d 5a d0 lea -0x30(%edx),%ebx 300: 80 fb 09 cmp $0x9,%bl 303: 76 eb jbe 2f0 <atoi+0x20> return n; } 305: 5b pop %ebx 306: 5d pop %ebp 307: c3 ret 308: 90 nop 309: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000310 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { 310: 55 push %ebp 311: 89 e5 mov %esp,%ebp 313: 56 push %esi 314: 53 push %ebx 315: 8b 5d 10 mov 0x10(%ebp),%ebx 318: 8b 45 08 mov 0x8(%ebp),%eax 31b: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 31e: 85 db test %ebx,%ebx 320: 7e 14 jle 336 <memmove+0x26> 322: 31 d2 xor %edx,%edx 324: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi *dst++ = *src++; 328: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx 32c: 88 0c 10 mov %cl,(%eax,%edx,1) 32f: 83 c2 01 add $0x1,%edx while(n-- > 0) 332: 39 d3 cmp %edx,%ebx 334: 75 f2 jne 328 <memmove+0x18> return vdst; } 336: 5b pop %ebx 337: 5e pop %esi 338: 5d pop %ebp 339: c3 ret 0000033a <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 33a: b8 01 00 00 00 mov $0x1,%eax 33f: cd 40 int $0x40 341: c3 ret 00000342 <exit>: SYSCALL(exit) 342: b8 02 00 00 00 mov $0x2,%eax 347: cd 40 int $0x40 349: c3 ret 0000034a <wait>: SYSCALL(wait) 34a: b8 03 00 00 00 mov $0x3,%eax 34f: cd 40 int $0x40 351: c3 ret 00000352 <pipe>: SYSCALL(pipe) 352: b8 04 00 00 00 mov $0x4,%eax 357: cd 40 int $0x40 359: c3 ret 0000035a <read>: SYSCALL(read) 35a: b8 05 00 00 00 mov $0x5,%eax 35f: cd 40 int $0x40 361: c3 ret 00000362 <write>: SYSCALL(write) 362: b8 10 00 00 00 mov $0x10,%eax 367: cd 40 int $0x40 369: c3 ret 0000036a <close>: SYSCALL(close) 36a: b8 15 00 00 00 mov $0x15,%eax 36f: cd 40 int $0x40 371: c3 ret 00000372 <kill>: SYSCALL(kill) 372: b8 06 00 00 00 mov $0x6,%eax 377: cd 40 int $0x40 379: c3 ret 0000037a <exec>: SYSCALL(exec) 37a: b8 07 00 00 00 mov $0x7,%eax 37f: cd 40 int $0x40 381: c3 ret 00000382 <open>: SYSCALL(open) 382: b8 0f 00 00 00 mov $0xf,%eax 387: cd 40 int $0x40 389: c3 ret 0000038a <mknod>: SYSCALL(mknod) 38a: b8 11 00 00 00 mov $0x11,%eax 38f: cd 40 int $0x40 391: c3 ret 00000392 <unlink>: SYSCALL(unlink) 392: b8 12 00 00 00 mov $0x12,%eax 397: cd 40 int $0x40 399: c3 ret 0000039a <fstat>: SYSCALL(fstat) 39a: b8 08 00 00 00 mov $0x8,%eax 39f: cd 40 int $0x40 3a1: c3 ret 000003a2 <link>: SYSCALL(link) 3a2: b8 13 00 00 00 mov $0x13,%eax 3a7: cd 40 int $0x40 3a9: c3 ret 000003aa <mkdir>: SYSCALL(mkdir) 3aa: b8 14 00 00 00 mov $0x14,%eax 3af: cd 40 int $0x40 3b1: c3 ret 000003b2 <chdir>: SYSCALL(chdir) 3b2: b8 09 00 00 00 mov $0x9,%eax 3b7: cd 40 int $0x40 3b9: c3 ret 000003ba <dup>: SYSCALL(dup) 3ba: b8 0a 00 00 00 mov $0xa,%eax 3bf: cd 40 int $0x40 3c1: c3 ret 000003c2 <getpid>: SYSCALL(getpid) 3c2: b8 0b 00 00 00 mov $0xb,%eax 3c7: cd 40 int $0x40 3c9: c3 ret 000003ca <sbrk>: SYSCALL(sbrk) 3ca: b8 0c 00 00 00 mov $0xc,%eax 3cf: cd 40 int $0x40 3d1: c3 ret 000003d2 <sleep>: SYSCALL(sleep) 3d2: b8 0d 00 00 00 mov $0xd,%eax 3d7: cd 40 int $0x40 3d9: c3 ret 000003da <uptime>: SYSCALL(uptime) 3da: b8 0e 00 00 00 mov $0xe,%eax 3df: cd 40 int $0x40 3e1: c3 ret 000003e2 <shutdown>: SYSCALL(shutdown) 3e2: b8 16 00 00 00 mov $0x16,%eax 3e7: cd 40 int $0x40 3e9: c3 ret 000003ea <date>: SYSCALL(date) 3ea: b8 17 00 00 00 mov $0x17,%eax 3ef: cd 40 int $0x40 3f1: c3 ret 000003f2 <cps>: SYSCALL(cps) 3f2: b8 18 00 00 00 mov $0x18,%eax 3f7: cd 40 int $0x40 3f9: c3 ret 3fa: 66 90 xchg %ax,%ax 3fc: 66 90 xchg %ax,%ax 3fe: 66 90 xchg %ax,%ax 00000400 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 400: 55 push %ebp 401: 89 e5 mov %esp,%ebp 403: 57 push %edi 404: 56 push %esi 405: 53 push %ebx 406: 83 ec 3c sub $0x3c,%esp char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ 409: 85 d2 test %edx,%edx { 40b: 89 45 c0 mov %eax,-0x40(%ebp) neg = 1; x = -xx; 40e: 89 d0 mov %edx,%eax if(sgn && xx < 0){ 410: 79 76 jns 488 <printint+0x88> 412: f6 45 08 01 testb $0x1,0x8(%ebp) 416: 74 70 je 488 <printint+0x88> x = -xx; 418: f7 d8 neg %eax neg = 1; 41a: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp) } else { x = xx; } i = 0; 421: 31 f6 xor %esi,%esi 423: 8d 5d d7 lea -0x29(%ebp),%ebx 426: eb 0a jmp 432 <printint+0x32> 428: 90 nop 429: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi do{ buf[i++] = digits[x % base]; 430: 89 fe mov %edi,%esi 432: 31 d2 xor %edx,%edx 434: 8d 7e 01 lea 0x1(%esi),%edi 437: f7 f1 div %ecx 439: 0f b6 92 74 08 00 00 movzbl 0x874(%edx),%edx }while((x /= base) != 0); 440: 85 c0 test %eax,%eax buf[i++] = digits[x % base]; 442: 88 14 3b mov %dl,(%ebx,%edi,1) }while((x /= base) != 0); 445: 75 e9 jne 430 <printint+0x30> if(neg) 447: 8b 45 c4 mov -0x3c(%ebp),%eax 44a: 85 c0 test %eax,%eax 44c: 74 08 je 456 <printint+0x56> buf[i++] = '-'; 44e: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1) 453: 8d 7e 02 lea 0x2(%esi),%edi 456: 8d 74 3d d7 lea -0x29(%ebp,%edi,1),%esi 45a: 8b 7d c0 mov -0x40(%ebp),%edi 45d: 8d 76 00 lea 0x0(%esi),%esi 460: 0f b6 06 movzbl (%esi),%eax write(fd, &c, 1); 463: 83 ec 04 sub $0x4,%esp 466: 83 ee 01 sub $0x1,%esi 469: 6a 01 push $0x1 46b: 53 push %ebx 46c: 57 push %edi 46d: 88 45 d7 mov %al,-0x29(%ebp) 470: e8 ed fe ff ff call 362 <write> while(--i >= 0) 475: 83 c4 10 add $0x10,%esp 478: 39 de cmp %ebx,%esi 47a: 75 e4 jne 460 <printint+0x60> putc(fd, buf[i]); } 47c: 8d 65 f4 lea -0xc(%ebp),%esp 47f: 5b pop %ebx 480: 5e pop %esi 481: 5f pop %edi 482: 5d pop %ebp 483: c3 ret 484: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; 488: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp) 48f: eb 90 jmp 421 <printint+0x21> 491: eb 0d jmp 4a0 <printf> 493: 90 nop 494: 90 nop 495: 90 nop 496: 90 nop 497: 90 nop 498: 90 nop 499: 90 nop 49a: 90 nop 49b: 90 nop 49c: 90 nop 49d: 90 nop 49e: 90 nop 49f: 90 nop 000004a0 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 4a0: 55 push %ebp 4a1: 89 e5 mov %esp,%ebp 4a3: 57 push %edi 4a4: 56 push %esi 4a5: 53 push %ebx 4a6: 83 ec 2c sub $0x2c,%esp int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 4a9: 8b 75 0c mov 0xc(%ebp),%esi 4ac: 0f b6 1e movzbl (%esi),%ebx 4af: 84 db test %bl,%bl 4b1: 0f 84 b3 00 00 00 je 56a <printf+0xca> ap = (uint*)(void*)&fmt + 1; 4b7: 8d 45 10 lea 0x10(%ebp),%eax 4ba: 83 c6 01 add $0x1,%esi state = 0; 4bd: 31 ff xor %edi,%edi ap = (uint*)(void*)&fmt + 1; 4bf: 89 45 d4 mov %eax,-0x2c(%ebp) 4c2: eb 2f jmp 4f3 <printf+0x53> 4c4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 4c8: 83 f8 25 cmp $0x25,%eax 4cb: 0f 84 a7 00 00 00 je 578 <printf+0xd8> write(fd, &c, 1); 4d1: 8d 45 e2 lea -0x1e(%ebp),%eax 4d4: 83 ec 04 sub $0x4,%esp 4d7: 88 5d e2 mov %bl,-0x1e(%ebp) 4da: 6a 01 push $0x1 4dc: 50 push %eax 4dd: ff 75 08 pushl 0x8(%ebp) 4e0: e8 7d fe ff ff call 362 <write> 4e5: 83 c4 10 add $0x10,%esp 4e8: 83 c6 01 add $0x1,%esi for(i = 0; fmt[i]; i++){ 4eb: 0f b6 5e ff movzbl -0x1(%esi),%ebx 4ef: 84 db test %bl,%bl 4f1: 74 77 je 56a <printf+0xca> if(state == 0){ 4f3: 85 ff test %edi,%edi c = fmt[i] & 0xff; 4f5: 0f be cb movsbl %bl,%ecx 4f8: 0f b6 c3 movzbl %bl,%eax if(state == 0){ 4fb: 74 cb je 4c8 <printf+0x28> state = '%'; } else { putc(fd, c); } } else if(state == '%'){ 4fd: 83 ff 25 cmp $0x25,%edi 500: 75 e6 jne 4e8 <printf+0x48> if(c == 'd'){ 502: 83 f8 64 cmp $0x64,%eax 505: 0f 84 05 01 00 00 je 610 <printf+0x170> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 50b: 81 e1 f7 00 00 00 and $0xf7,%ecx 511: 83 f9 70 cmp $0x70,%ecx 514: 74 72 je 588 <printf+0xe8> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 516: 83 f8 73 cmp $0x73,%eax 519: 0f 84 99 00 00 00 je 5b8 <printf+0x118> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 51f: 83 f8 63 cmp $0x63,%eax 522: 0f 84 08 01 00 00 je 630 <printf+0x190> putc(fd, *ap); ap++; } else if(c == '%'){ 528: 83 f8 25 cmp $0x25,%eax 52b: 0f 84 ef 00 00 00 je 620 <printf+0x180> write(fd, &c, 1); 531: 8d 45 e7 lea -0x19(%ebp),%eax 534: 83 ec 04 sub $0x4,%esp 537: c6 45 e7 25 movb $0x25,-0x19(%ebp) 53b: 6a 01 push $0x1 53d: 50 push %eax 53e: ff 75 08 pushl 0x8(%ebp) 541: e8 1c fe ff ff call 362 <write> 546: 83 c4 0c add $0xc,%esp 549: 8d 45 e6 lea -0x1a(%ebp),%eax 54c: 88 5d e6 mov %bl,-0x1a(%ebp) 54f: 6a 01 push $0x1 551: 50 push %eax 552: ff 75 08 pushl 0x8(%ebp) 555: 83 c6 01 add $0x1,%esi } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 558: 31 ff xor %edi,%edi write(fd, &c, 1); 55a: e8 03 fe ff ff call 362 <write> for(i = 0; fmt[i]; i++){ 55f: 0f b6 5e ff movzbl -0x1(%esi),%ebx write(fd, &c, 1); 563: 83 c4 10 add $0x10,%esp for(i = 0; fmt[i]; i++){ 566: 84 db test %bl,%bl 568: 75 89 jne 4f3 <printf+0x53> } } } 56a: 8d 65 f4 lea -0xc(%ebp),%esp 56d: 5b pop %ebx 56e: 5e pop %esi 56f: 5f pop %edi 570: 5d pop %ebp 571: c3 ret 572: 8d b6 00 00 00 00 lea 0x0(%esi),%esi state = '%'; 578: bf 25 00 00 00 mov $0x25,%edi 57d: e9 66 ff ff ff jmp 4e8 <printf+0x48> 582: 8d b6 00 00 00 00 lea 0x0(%esi),%esi printint(fd, *ap, 16, 0); 588: 83 ec 0c sub $0xc,%esp 58b: b9 10 00 00 00 mov $0x10,%ecx 590: 6a 00 push $0x0 592: 8b 7d d4 mov -0x2c(%ebp),%edi 595: 8b 45 08 mov 0x8(%ebp),%eax 598: 8b 17 mov (%edi),%edx 59a: e8 61 fe ff ff call 400 <printint> ap++; 59f: 89 f8 mov %edi,%eax 5a1: 83 c4 10 add $0x10,%esp state = 0; 5a4: 31 ff xor %edi,%edi ap++; 5a6: 83 c0 04 add $0x4,%eax 5a9: 89 45 d4 mov %eax,-0x2c(%ebp) 5ac: e9 37 ff ff ff jmp 4e8 <printf+0x48> 5b1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi s = (char*)*ap; 5b8: 8b 45 d4 mov -0x2c(%ebp),%eax 5bb: 8b 08 mov (%eax),%ecx ap++; 5bd: 83 c0 04 add $0x4,%eax 5c0: 89 45 d4 mov %eax,-0x2c(%ebp) if(s == 0) 5c3: 85 c9 test %ecx,%ecx 5c5: 0f 84 8e 00 00 00 je 659 <printf+0x1b9> while(*s != 0){ 5cb: 0f b6 01 movzbl (%ecx),%eax state = 0; 5ce: 31 ff xor %edi,%edi s = (char*)*ap; 5d0: 89 cb mov %ecx,%ebx while(*s != 0){ 5d2: 84 c0 test %al,%al 5d4: 0f 84 0e ff ff ff je 4e8 <printf+0x48> 5da: 89 75 d0 mov %esi,-0x30(%ebp) 5dd: 89 de mov %ebx,%esi 5df: 8b 5d 08 mov 0x8(%ebp),%ebx 5e2: 8d 7d e3 lea -0x1d(%ebp),%edi 5e5: 8d 76 00 lea 0x0(%esi),%esi write(fd, &c, 1); 5e8: 83 ec 04 sub $0x4,%esp s++; 5eb: 83 c6 01 add $0x1,%esi 5ee: 88 45 e3 mov %al,-0x1d(%ebp) write(fd, &c, 1); 5f1: 6a 01 push $0x1 5f3: 57 push %edi 5f4: 53 push %ebx 5f5: e8 68 fd ff ff call 362 <write> while(*s != 0){ 5fa: 0f b6 06 movzbl (%esi),%eax 5fd: 83 c4 10 add $0x10,%esp 600: 84 c0 test %al,%al 602: 75 e4 jne 5e8 <printf+0x148> 604: 8b 75 d0 mov -0x30(%ebp),%esi state = 0; 607: 31 ff xor %edi,%edi 609: e9 da fe ff ff jmp 4e8 <printf+0x48> 60e: 66 90 xchg %ax,%ax printint(fd, *ap, 10, 1); 610: 83 ec 0c sub $0xc,%esp 613: b9 0a 00 00 00 mov $0xa,%ecx 618: 6a 01 push $0x1 61a: e9 73 ff ff ff jmp 592 <printf+0xf2> 61f: 90 nop write(fd, &c, 1); 620: 83 ec 04 sub $0x4,%esp 623: 88 5d e5 mov %bl,-0x1b(%ebp) 626: 8d 45 e5 lea -0x1b(%ebp),%eax 629: 6a 01 push $0x1 62b: e9 21 ff ff ff jmp 551 <printf+0xb1> putc(fd, *ap); 630: 8b 7d d4 mov -0x2c(%ebp),%edi write(fd, &c, 1); 633: 83 ec 04 sub $0x4,%esp putc(fd, *ap); 636: 8b 07 mov (%edi),%eax write(fd, &c, 1); 638: 6a 01 push $0x1 ap++; 63a: 83 c7 04 add $0x4,%edi putc(fd, *ap); 63d: 88 45 e4 mov %al,-0x1c(%ebp) write(fd, &c, 1); 640: 8d 45 e4 lea -0x1c(%ebp),%eax 643: 50 push %eax 644: ff 75 08 pushl 0x8(%ebp) 647: e8 16 fd ff ff call 362 <write> ap++; 64c: 89 7d d4 mov %edi,-0x2c(%ebp) 64f: 83 c4 10 add $0x10,%esp state = 0; 652: 31 ff xor %edi,%edi 654: e9 8f fe ff ff jmp 4e8 <printf+0x48> s = "(null)"; 659: bb 6c 08 00 00 mov $0x86c,%ebx while(*s != 0){ 65e: b8 28 00 00 00 mov $0x28,%eax 663: e9 72 ff ff ff jmp 5da <printf+0x13a> 668: 66 90 xchg %ax,%ax 66a: 66 90 xchg %ax,%ax 66c: 66 90 xchg %ax,%ax 66e: 66 90 xchg %ax,%ax 00000670 <free>: static Header base; static Header *freep; void free(void *ap) { 670: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 671: a1 3c 0b 00 00 mov 0xb3c,%eax { 676: 89 e5 mov %esp,%ebp 678: 57 push %edi 679: 56 push %esi 67a: 53 push %ebx 67b: 8b 5d 08 mov 0x8(%ebp),%ebx bp = (Header*)ap - 1; 67e: 8d 4b f8 lea -0x8(%ebx),%ecx 681: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 688: 39 c8 cmp %ecx,%eax 68a: 8b 10 mov (%eax),%edx 68c: 73 32 jae 6c0 <free+0x50> 68e: 39 d1 cmp %edx,%ecx 690: 72 04 jb 696 <free+0x26> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 692: 39 d0 cmp %edx,%eax 694: 72 32 jb 6c8 <free+0x58> break; if(bp + bp->s.size == p->s.ptr){ 696: 8b 73 fc mov -0x4(%ebx),%esi 699: 8d 3c f1 lea (%ecx,%esi,8),%edi 69c: 39 fa cmp %edi,%edx 69e: 74 30 je 6d0 <free+0x60> bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; 6a0: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 6a3: 8b 50 04 mov 0x4(%eax),%edx 6a6: 8d 34 d0 lea (%eax,%edx,8),%esi 6a9: 39 f1 cmp %esi,%ecx 6ab: 74 3a je 6e7 <free+0x77> p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; 6ad: 89 08 mov %ecx,(%eax) freep = p; 6af: a3 3c 0b 00 00 mov %eax,0xb3c } 6b4: 5b pop %ebx 6b5: 5e pop %esi 6b6: 5f pop %edi 6b7: 5d pop %ebp 6b8: c3 ret 6b9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 6c0: 39 d0 cmp %edx,%eax 6c2: 72 04 jb 6c8 <free+0x58> 6c4: 39 d1 cmp %edx,%ecx 6c6: 72 ce jb 696 <free+0x26> { 6c8: 89 d0 mov %edx,%eax 6ca: eb bc jmp 688 <free+0x18> 6cc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi bp->s.size += p->s.ptr->s.size; 6d0: 03 72 04 add 0x4(%edx),%esi 6d3: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 6d6: 8b 10 mov (%eax),%edx 6d8: 8b 12 mov (%edx),%edx 6da: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 6dd: 8b 50 04 mov 0x4(%eax),%edx 6e0: 8d 34 d0 lea (%eax,%edx,8),%esi 6e3: 39 f1 cmp %esi,%ecx 6e5: 75 c6 jne 6ad <free+0x3d> p->s.size += bp->s.size; 6e7: 03 53 fc add -0x4(%ebx),%edx freep = p; 6ea: a3 3c 0b 00 00 mov %eax,0xb3c p->s.size += bp->s.size; 6ef: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 6f2: 8b 53 f8 mov -0x8(%ebx),%edx 6f5: 89 10 mov %edx,(%eax) } 6f7: 5b pop %ebx 6f8: 5e pop %esi 6f9: 5f pop %edi 6fa: 5d pop %ebp 6fb: c3 ret 6fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000700 <malloc>: return freep; } void* malloc(uint nbytes) { 700: 55 push %ebp 701: 89 e5 mov %esp,%ebp 703: 57 push %edi 704: 56 push %esi 705: 53 push %ebx 706: 83 ec 0c sub $0xc,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 709: 8b 45 08 mov 0x8(%ebp),%eax if((prevp = freep) == 0){ 70c: 8b 15 3c 0b 00 00 mov 0xb3c,%edx nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 712: 8d 78 07 lea 0x7(%eax),%edi 715: c1 ef 03 shr $0x3,%edi 718: 83 c7 01 add $0x1,%edi if((prevp = freep) == 0){ 71b: 85 d2 test %edx,%edx 71d: 0f 84 9d 00 00 00 je 7c0 <malloc+0xc0> 723: 8b 02 mov (%edx),%eax 725: 8b 48 04 mov 0x4(%eax),%ecx base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ 728: 39 cf cmp %ecx,%edi 72a: 76 6c jbe 798 <malloc+0x98> 72c: 81 ff 00 10 00 00 cmp $0x1000,%edi 732: bb 00 10 00 00 mov $0x1000,%ebx 737: 0f 43 df cmovae %edi,%ebx p = sbrk(nu * sizeof(Header)); 73a: 8d 34 dd 00 00 00 00 lea 0x0(,%ebx,8),%esi 741: eb 0e jmp 751 <malloc+0x51> 743: 90 nop 744: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 748: 8b 02 mov (%edx),%eax if(p->s.size >= nunits){ 74a: 8b 48 04 mov 0x4(%eax),%ecx 74d: 39 f9 cmp %edi,%ecx 74f: 73 47 jae 798 <malloc+0x98> p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) 751: 39 05 3c 0b 00 00 cmp %eax,0xb3c 757: 89 c2 mov %eax,%edx 759: 75 ed jne 748 <malloc+0x48> p = sbrk(nu * sizeof(Header)); 75b: 83 ec 0c sub $0xc,%esp 75e: 56 push %esi 75f: e8 66 fc ff ff call 3ca <sbrk> if(p == (char*)-1) 764: 83 c4 10 add $0x10,%esp 767: 83 f8 ff cmp $0xffffffff,%eax 76a: 74 1c je 788 <malloc+0x88> hp->s.size = nu; 76c: 89 58 04 mov %ebx,0x4(%eax) free((void*)(hp + 1)); 76f: 83 ec 0c sub $0xc,%esp 772: 83 c0 08 add $0x8,%eax 775: 50 push %eax 776: e8 f5 fe ff ff call 670 <free> return freep; 77b: 8b 15 3c 0b 00 00 mov 0xb3c,%edx if((p = morecore(nunits)) == 0) 781: 83 c4 10 add $0x10,%esp 784: 85 d2 test %edx,%edx 786: 75 c0 jne 748 <malloc+0x48> return 0; } } 788: 8d 65 f4 lea -0xc(%ebp),%esp return 0; 78b: 31 c0 xor %eax,%eax } 78d: 5b pop %ebx 78e: 5e pop %esi 78f: 5f pop %edi 790: 5d pop %ebp 791: c3 ret 792: 8d b6 00 00 00 00 lea 0x0(%esi),%esi if(p->s.size == nunits) 798: 39 cf cmp %ecx,%edi 79a: 74 54 je 7f0 <malloc+0xf0> p->s.size -= nunits; 79c: 29 f9 sub %edi,%ecx 79e: 89 48 04 mov %ecx,0x4(%eax) p += p->s.size; 7a1: 8d 04 c8 lea (%eax,%ecx,8),%eax p->s.size = nunits; 7a4: 89 78 04 mov %edi,0x4(%eax) freep = prevp; 7a7: 89 15 3c 0b 00 00 mov %edx,0xb3c } 7ad: 8d 65 f4 lea -0xc(%ebp),%esp return (void*)(p + 1); 7b0: 83 c0 08 add $0x8,%eax } 7b3: 5b pop %ebx 7b4: 5e pop %esi 7b5: 5f pop %edi 7b6: 5d pop %ebp 7b7: c3 ret 7b8: 90 nop 7b9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi base.s.ptr = freep = prevp = &base; 7c0: c7 05 3c 0b 00 00 40 movl $0xb40,0xb3c 7c7: 0b 00 00 7ca: c7 05 40 0b 00 00 40 movl $0xb40,0xb40 7d1: 0b 00 00 base.s.size = 0; 7d4: b8 40 0b 00 00 mov $0xb40,%eax 7d9: c7 05 44 0b 00 00 00 movl $0x0,0xb44 7e0: 00 00 00 7e3: e9 44 ff ff ff jmp 72c <malloc+0x2c> 7e8: 90 nop 7e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi prevp->s.ptr = p->s.ptr; 7f0: 8b 08 mov (%eax),%ecx 7f2: 89 0a mov %ecx,(%edx) 7f4: eb b1 jmp 7a7 <malloc+0xa7>
; A235115: Number of independent vertex subsets of the graph obtained by attaching two pendant edges to each vertex of the star graph S_n (having n vertices; see A235114). ; 5,24,116,564,2756,13524,66596,328884,1628036,8074644,40111076,199506804,993339716,4949921364,24682497956,123144054324,614646529796,3068937681684,15327508539236,76568823219444,382569238190276,1911746679323604,9554335350106916,47754084564490164,238700054078273156,1193218795414655124,5964968077166432996,29820336786204794484,149083669532514490436,745346290068534524244,3726443219966520909476,18631063178327997700404,93150704205621561114116,465735074284034096018964,2328601584443875641888356,11642712774314198856615924,58212383279950276871776196,291057194033268514713667284,1455267080700411094987481636,7276259845638329560613989044,36380996996736744145776268676,181903776057864106099706637204,909514044586042071981834361316,4547550880117096525842376507764,22737677029333027292944701343556,113688075661655315119654781936724,568439140368237290217999010559396,2842190750081029309568895456300084,14210933943364517981760078895512836,71054590488660075644462800933613844,355272635530650321164963630492267876 mov $1,4 mov $2,4 pow $2,$0 lpb $0 sub $0,1 mul $1,5 lpe add $1,$2 add $3,2 mul $1,$3 sub $1,10 div $1,2 add $1,5 mov $0,$1
; A016796: (3n+2)^8. ; 256,390625,16777216,214358881,1475789056,6975757441,25600000000,78310985281,208827064576,500246412961,1099511627776,2251875390625,4347792138496,7984925229121,14048223625216,23811286661761 mul $0,3 add $0,2 pow $0,8
code32 format ELF public _findFirstSet public _findFirstSet64 section '.text' executable align 16 _findFirstSet: cmp r0, #0 bxeq lr lsl r3, r0, #16 lsr r3, #16 cmp r3, #0 lsreq r0, #16 moveq r3, #24 moveq r2, #16 movne r3, #8 movne r2, #0 tst r0, #255 lsreq r0, #8 moveq r2, r3 tst r0, #15 lsreq r0, #4 addeq r2, #4 tst r0, #3 lsreq r0, #2 addeq r2, #2 lsr r3, r0, #1 and r3, #1 rsb r3, #2 mvn r0, r0 ands r0, #1 mvnne r0, #0 and r0, r3 add r0, r2 add r0, #1 bx lr _findFirstSetARMv5: rsb r3, r0, #0 and r0, r3 clz r0, r0 rsb r0, #32 bx lr _findFirstSetARMv7: cmp r0, #0 rbit r0, r0 clz r0, r0 it eq moveq r0, #-1 adds r0, #-1 bx lr _findFirstSetARMv7a: cmp r0, #0 rbit r0, r0 clz r0, r0 mvneq r0, #0 add r0, #1 bx lr _findFirstSet64: cmp r0, #0 bne .lowNot0 cmp r1, #0 beq .ret0 lsl r3, r1, #16 lsr r3, #16 cmp r3, #0 lsreq r1, #16 moveq r2, #57 moveq r3, #49 movne r2, #41 movne r3, #33 tst r1, #255 lsreq r1, #8 moveq r3, r2 tst r1, #15 lsreq r1, #4 addeq r3, #4 tst r1, #3 lsreq r1, #2 addeq r3, #2 lsr r0, r1, #1 and r0, #1 rsb r0, #2 mvn r1, r1 ands r1, #1 mvnne r1, #0 and r0, r1 add r0, r3 mov r1, #0 bx lr .lowNot0: lsl r3, r0, #16 lsr r3, #16 cmp r3, #0 lsreq r0, #16 moveq r3, #24 moveq r2, #16 movne r3, #8 movne r2, #0 tst r0, #255 lsreq r0, #8 moveq r2, r3 tst r0, #15 lsreq r0, #4 addeq r2, #4 tst r0, #3 lsreq r0, #2 addeq r2, #2 lsr r3, r0, #1 and r3, #1 rsb r3, #2 mvn r0, r0 ands r0, #1 mvnne r0, #1 and r0, r3 add r0, r2 add r0, #1 asr r1, r0, #31 bx lr .ret0: mov r0, #0 mov r1, #0 bx lr _findFirstSet64ARMv5: cmp r0, #0 bne .lowNot0 cmp r1, #0 bne .highNot0 mov r0, #0 mov r1, #0 bx lr .highNot0: rsb r0, r1, #0 and r0, r1 clz r0, r0 mov r1, #0 rsb r0, #64 bx lr .lowNot0: rsb r3, r0, #0 and r0, r3 clz r0, r0 rsb r0, #32 asr r1, r0, #31 bx lr
; ; SECTION code_clib PUBLIC conio_map_colour_firmware PUBLIC cpc_set_ansi_palette INCLUDE "target/cpc/def/cpcfirm.def" EXTERN __CLIB_CONIO_NATIVE_COLOUR ; Map ANSI colours to firmware colours conio_map_colour_firmware: ld hl,ansipalette do_mapping: ld c,__CLIB_CONIO_NATIVE_COLOUR rr c ret c and 15 ld c,a ld b,0 add hl,bc ld a,(hl) ret ; Set the CPC palette to the ANSI palette cpc_set_ansi_palette: ld c,__CLIB_CONIO_NATIVE_COLOUR rr c ret c ld hl,ansipalette xor a loop: push af push hl ld c,(hl) ld b,c call firmware defw scr_set_ink pop hl inc hl pop af inc a cp 16 jr nz,loop ret SECTION rodata_clib ; Mapping to firmware colours from ANSI colours ; Colours to map into ANSI colours onto the CPC palette ansipalette: defb 0 ;BLACK -> BLACK defb 2 ;BLUE -> BRIGHT BLUE defb 18 ;GREEN -> BRIGHT GREEN defb 10 ;CYAN -> CYAN defb 6 ;RED -> BRIGHT RED defb 8 ;MAGENTA -> BRIGHT MAGENTA defb 3 ;BROWN -> RED defb 13 ;LIGHTGRAY -> WHITE defb 13 ;DARKGRAY -> WHITE defb 1 ;LIGHTBLUE -> BRIGHT BLUE defb 9 ;LIGHTGREEN -> GREEN defb 20 ;LIGHTCYAN -> BRIGHT CYAN defb 15 ;LIGHTRED -> ORANGE defb 4 ;LIGHTMAGENTA -> BRIGHT MAGENTA defb 24 ;YELLOW -> YELLOW defb 26 ;WHITE -> WHITE
; A005985: Length of longest trail (i.e., path with all distinct edges) on the edges of an n-cube. ; 0,1,4,9,32,65,192,385,1024,2049,5120,10241,24576,49153,114688,229377,524288,1048577,2359296,4718593,10485760,20971521,46137344,92274689,201326592,402653185,872415232,1744830465,3758096384,7516192769,16106127360,32212254721,68719476736,137438953473,292057776128,584115552257,1236950581248,2473901162497,5222680231936,10445360463873,21990232555520,43980465111041,92358976733184,184717953466369,387028092977152,774056185954305,1618481116086272,3236962232172545,6755399441055744 mov $2,$0 lpb $0 sub $0,1 mov $1,$2 div $2,2 mul $2,2 add $2,$1 lpe add $1,4 bin $2,$0 sub $1,$2 sub $1,3
// Copyright (c) 2005-2014 Code Synthesis Tools CC // // This program was generated by CodeSynthesis XSD, an XML Schema to // C++ data binding compiler. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as // published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // // In addition, as a special exception, Code Synthesis Tools CC gives // permission to link this program with the Xerces-C++ library (or with // modified versions of Xerces-C++ that use the same license as Xerces-C++), // and distribute linked combinations including the two. You must obey // the GNU General Public License version 2 in all respects for all of // the code used other than Xerces-C++. If you modify this copy of the // program, you may extend this exception to your version of the program, // but you are not obligated to do so. If you do not wish to do so, delete // this exception statement from your version. // // Furthermore, Code Synthesis Tools CC makes a special exception for // the Free/Libre and Open Source Software (FLOSS) which is described // in the accompanying FLOSSE file. // // Begin prologue. // // // End prologue. #include <xsd/cxx/pre.hxx> #include "SimFlowSegment_Pipe_UndergroundPipeSegment.hxx" namespace schema { namespace simxml { namespace MepModel { // SimFlowSegment_Pipe_UndergroundPipeSegment // const SimFlowSegment_Pipe_UndergroundPipeSegment::SimFlowSeg_XPos_optional& SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSeg_XPos () const { return this->SimFlowSeg_XPos_; } SimFlowSegment_Pipe_UndergroundPipeSegment::SimFlowSeg_XPos_optional& SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSeg_XPos () { return this->SimFlowSeg_XPos_; } void SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSeg_XPos (const SimFlowSeg_XPos_type& x) { this->SimFlowSeg_XPos_.set (x); } void SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSeg_XPos (const SimFlowSeg_XPos_optional& x) { this->SimFlowSeg_XPos_ = x; } const SimFlowSegment_Pipe_UndergroundPipeSegment::SimFlowSeg_YPos_optional& SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSeg_YPos () const { return this->SimFlowSeg_YPos_; } SimFlowSegment_Pipe_UndergroundPipeSegment::SimFlowSeg_YPos_optional& SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSeg_YPos () { return this->SimFlowSeg_YPos_; } void SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSeg_YPos (const SimFlowSeg_YPos_type& x) { this->SimFlowSeg_YPos_.set (x); } void SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSeg_YPos (const SimFlowSeg_YPos_optional& x) { this->SimFlowSeg_YPos_ = x; } const SimFlowSegment_Pipe_UndergroundPipeSegment::SimFlowSeg_FlowDir_optional& SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSeg_FlowDir () const { return this->SimFlowSeg_FlowDir_; } SimFlowSegment_Pipe_UndergroundPipeSegment::SimFlowSeg_FlowDir_optional& SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSeg_FlowDir () { return this->SimFlowSeg_FlowDir_; } void SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSeg_FlowDir (const SimFlowSeg_FlowDir_type& x) { this->SimFlowSeg_FlowDir_.set (x); } void SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSeg_FlowDir (const SimFlowSeg_FlowDir_optional& x) { this->SimFlowSeg_FlowDir_ = x; } void SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSeg_FlowDir (::std::auto_ptr< SimFlowSeg_FlowDir_type > x) { this->SimFlowSeg_FlowDir_.set (x); } } } } #include <xsd/cxx/xml/dom/parsing-source.hxx> #include <xsd/cxx/tree/type-factory-map.hxx> namespace _xsd { static const ::xsd::cxx::tree::type_factory_plate< 0, char > type_factory_plate_init; } namespace schema { namespace simxml { namespace MepModel { // SimFlowSegment_Pipe_UndergroundPipeSegment // SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSegment_Pipe_UndergroundPipeSegment () : ::schema::simxml::MepModel::SimFlowSegment_Pipe (), SimFlowSeg_XPos_ (this), SimFlowSeg_YPos_ (this), SimFlowSeg_FlowDir_ (this) { } SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSegment_Pipe_UndergroundPipeSegment (const RefId_type& RefId) : ::schema::simxml::MepModel::SimFlowSegment_Pipe (RefId), SimFlowSeg_XPos_ (this), SimFlowSeg_YPos_ (this), SimFlowSeg_FlowDir_ (this) { } SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSegment_Pipe_UndergroundPipeSegment (const SimFlowSegment_Pipe_UndergroundPipeSegment& x, ::xml_schema::flags f, ::xml_schema::container* c) : ::schema::simxml::MepModel::SimFlowSegment_Pipe (x, f, c), SimFlowSeg_XPos_ (x.SimFlowSeg_XPos_, f, this), SimFlowSeg_YPos_ (x.SimFlowSeg_YPos_, f, this), SimFlowSeg_FlowDir_ (x.SimFlowSeg_FlowDir_, f, this) { } SimFlowSegment_Pipe_UndergroundPipeSegment:: SimFlowSegment_Pipe_UndergroundPipeSegment (const ::xercesc::DOMElement& e, ::xml_schema::flags f, ::xml_schema::container* c) : ::schema::simxml::MepModel::SimFlowSegment_Pipe (e, f | ::xml_schema::flags::base, c), SimFlowSeg_XPos_ (this), SimFlowSeg_YPos_ (this), SimFlowSeg_FlowDir_ (this) { if ((f & ::xml_schema::flags::base) == 0) { ::xsd::cxx::xml::dom::parser< char > p (e, true, false, true); this->parse (p, f); } } void SimFlowSegment_Pipe_UndergroundPipeSegment:: parse (::xsd::cxx::xml::dom::parser< char >& p, ::xml_schema::flags f) { this->::schema::simxml::MepModel::SimFlowSegment_Pipe::parse (p, f); for (; p.more_content (); p.next_content (false)) { const ::xercesc::DOMElement& i (p.cur_element ()); const ::xsd::cxx::xml::qualified_name< char > n ( ::xsd::cxx::xml::dom::name< char > (i)); // SimFlowSeg_XPos // if (n.name () == "SimFlowSeg_XPos" && n.namespace_ () == "http://d-alchemy.com/schema/simxml/MepModel") { if (!this->SimFlowSeg_XPos_) { this->SimFlowSeg_XPos_.set (SimFlowSeg_XPos_traits::create (i, f, this)); continue; } } // SimFlowSeg_YPos // if (n.name () == "SimFlowSeg_YPos" && n.namespace_ () == "http://d-alchemy.com/schema/simxml/MepModel") { if (!this->SimFlowSeg_YPos_) { this->SimFlowSeg_YPos_.set (SimFlowSeg_YPos_traits::create (i, f, this)); continue; } } // SimFlowSeg_FlowDir // if (n.name () == "SimFlowSeg_FlowDir" && n.namespace_ () == "http://d-alchemy.com/schema/simxml/MepModel") { ::std::auto_ptr< SimFlowSeg_FlowDir_type > r ( SimFlowSeg_FlowDir_traits::create (i, f, this)); if (!this->SimFlowSeg_FlowDir_) { this->SimFlowSeg_FlowDir_.set (r); continue; } } break; } } SimFlowSegment_Pipe_UndergroundPipeSegment* SimFlowSegment_Pipe_UndergroundPipeSegment:: _clone (::xml_schema::flags f, ::xml_schema::container* c) const { return new class SimFlowSegment_Pipe_UndergroundPipeSegment (*this, f, c); } SimFlowSegment_Pipe_UndergroundPipeSegment& SimFlowSegment_Pipe_UndergroundPipeSegment:: operator= (const SimFlowSegment_Pipe_UndergroundPipeSegment& x) { if (this != &x) { static_cast< ::schema::simxml::MepModel::SimFlowSegment_Pipe& > (*this) = x; this->SimFlowSeg_XPos_ = x.SimFlowSeg_XPos_; this->SimFlowSeg_YPos_ = x.SimFlowSeg_YPos_; this->SimFlowSeg_FlowDir_ = x.SimFlowSeg_FlowDir_; } return *this; } SimFlowSegment_Pipe_UndergroundPipeSegment:: ~SimFlowSegment_Pipe_UndergroundPipeSegment () { } } } } #include <istream> #include <xsd/cxx/xml/sax/std-input-source.hxx> #include <xsd/cxx/tree/error-handler.hxx> namespace schema { namespace simxml { namespace MepModel { } } } #include <xsd/cxx/post.hxx> // Begin epilogue. // // // End epilogue.
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r15 push %r9 push %rax push %rcx push %rdi push %rsi lea addresses_UC_ht+0xda8b, %rax nop nop cmp %r15, %r15 movups (%rax), %xmm0 vpextrq $1, %xmm0, %rsi nop nop nop nop dec %r11 lea addresses_normal_ht+0x11adb, %rsi lea addresses_UC_ht+0x1cc8b, %rdi clflush (%rdi) xor $32944, %r9 mov $1, %rcx rep movsw nop nop nop nop dec %rax lea addresses_normal_ht+0x1228b, %rsi nop nop nop nop xor $45720, %r15 movl $0x61626364, (%rsi) nop nop nop nop nop inc %r11 lea addresses_A_ht+0x328b, %rsi lea addresses_normal_ht+0x14f8b, %rdi nop nop nop nop nop and $15866, %r11 mov $39, %rcx rep movsl nop nop and %rsi, %rsi lea addresses_A_ht+0x7a8b, %r11 nop nop nop add %rax, %rax and $0xffffffffffffffc0, %r11 vmovntdqa (%r11), %ymm5 vextracti128 $0, %ymm5, %xmm5 vpextrq $0, %xmm5, %rcx nop nop nop nop xor $58575, %rcx lea addresses_WT_ht+0xd96b, %r9 nop cmp $13686, %r15 mov $0x6162636465666768, %rcx movq %rcx, %xmm2 vmovups %ymm2, (%r9) nop add %r9, %r9 lea addresses_WC_ht+0x1628b, %rdi nop nop nop dec %rsi mov (%rdi), %r15 nop and %rax, %rax pop %rsi pop %rdi pop %rcx pop %rax pop %r9 pop %r15 pop %r11 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r15 push %r9 push %rbp push %rbx // Faulty Load lea addresses_normal+0x1928b, %rbx nop and %r15, %r15 movups (%rbx), %xmm3 vpextrq $0, %xmm3, %r12 lea oracles, %rbx and $0xff, %r12 shlq $12, %r12 mov (%rbx,%r12,1), %r12 pop %rbx pop %rbp pop %r9 pop %r15 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': True}} {'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 9, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 10, 'same': True}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 7, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 32, 'AVXalign': False, 'NT': True, 'congruent': 9, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}} {'34': 21829} 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 */
; size_t obstack_room(struct obstack *ob) SECTION code_alloc_obstack PUBLIC _obstack_room EXTERN asm_obstack_room _obstack_room: pop af pop hl push hl push af jp asm_obstack_room
; ; Galaksija C Library ; ; Print character to the screen ; ; Stefano Bodrato - Apr.2008 ; ; ; $Id: fputc_cons.asm,v 1.3 2016/05/15 20:15:45 dom Exp $ ; SECTION code_clib PUBLIC fputc_cons_native .fputc_cons_native ld hl,2 add hl,sp ld a,(hl) cp 12 jr nz,nocls .nocls ; Some undercase text? Transform in UPPER ! cp 97 jr c,nounder sub 32 jr setout .nounder ; Some more char remapping can stay here... IF STANDARDESCAPECHARS cp 10 jr nz,setout ld a,13 ENDIF .setout rst 20h ret
; ECE 291 Summer 2004 MP4 ; -- Paint291 -- ; ; Completed By: ; Your Name ; ; Ryan Chmiel ; University of Illinois Urbana Champaign ; Dept. of Electrical & Computer Engineering ; ; Ver 1.0 %include "lib291.inc" %include "libmp4.inc" BITS 32 GLOBAL _main ; Define Contstants DOWNARROW EQU 80 RIGHTARROW EQU 77 LEFTARROW EQU 75 UPARROW EQU 72 CANVAS_X EQU 20 CANVAS_Y EQU 20 NUM_MENU_ITEMS EQU 11 BKSP EQU 8 ESC EQU 1 ENTERKEY EQU 13 SPACE EQU 57 LSHIFT EQU 42 RSHIFT EQU 54 SECTION .bss _GraphicsMode resw 1 ; Graphics mode # _kbINT resb 1 ; Keyboard interrupt # _kbIRQ resb 1 ; Keyboard IRQ _kbPort resw 1 ; Keyboard port _MouseSeg resw 1 ; real mode segment for MouseCallback _MouseOff resw 1 ; real mode offset for MouseCallback _MouseX resw 1 ; X coordinate position of mouse on screen _MouseY resw 1 ; Y coordinate position of mouse on screen _ScreenOff resd 1 ; Screen image offset _CanvasOff resd 1 ; Canvas image offset _OverlayOff resd 1 ; Overlay image offset _FontOff resd 1 ; Font image offset _MenuOff resd 1 ; Menu image offset _TitleOff resd 1 ; Title Bar image offset _MPFlags resb 1 ; program flags ; Bit 0 - Exit program ; Bit 1 - Left mouse button (LMB) status: set if down, cleared if up ; Bit 2 - Change in LMB status: set if button status ; moves from pressed->released or vice-versa ; Bit 3 - Right shift key status: set if down, cleared if up ; Bit 4 - Left shift key status: set if down, cleared if up ; Bit 5 - Key other than shift was pressed ; Bit 6 - Not Used Anymore ; Bit 7 - Status of chosen color: set if obtained with user input, ; cleared if obtained with eyedrop (you do not have to deal ; with this - the library code uses it) _MenuItem resb 1 ; selected menu item ; line algorithm variables _x resw 1 _y resw 1 _dx resw 1 _dy resw 1 _lineerror resw 1 _xhorizinc resw 1 _xdiaginc resw 1 _yvertinc resw 1 _ydiaginc resw 1 _errordiaginc resw 1 _errornodiaginc resw 1 ; circle algorithm variables _radius resw 1 _circleerror resw 1 _xdist resw 1 _ydist resw 1 ; flood fill variables _PointQueue resd 1 _QueueHead resd 1 _QueueTail resd 1 _key resb 1 SECTION .data ; Required image files _FontFN db 'font.png',0 _MenuFN db 'menu.png',0 _TitleFN db 'title.png',0 ; Defined color values _CurrentColor dd 0ffff0000h ; current color _ColorBlue dd 0ff0033ffh _ColorWhite dd 0ffffffffh _ColorBlack dd 0ff000000h _ColorHalfBlack dd 0cc000000h _buffer db ' ','$' _ColorString1 db 'Enter numerical values for','$' _ColorString2 db 'each channel (ARGB), and','$' _ColorString3 db 'separate each number by a','$' _ColorString4 db 'space (ex. 127 255 255 0).','$' _QwertyNames db 0 ; filler db 0,'1','2','3','4','5','6','7','8','9','0','-','=',BKSP db 0, 'q','w','e','r','t','y','u','i','o','p','[',']',ENTERKEY db 0,'a','s','d','f','g','h','j','k','l',';',"'","`" db 0,'\','z','x','c','v','b','n','m',",",'.','/',0,'*' db 0, ' ', 0, 0,0,0,0,0,0,0,0,0,0 ; F1-F10 db 0,0 ; numlock, scroll lock db 0, 0, 0, '-' db 0, 0, 0, '+' db 0, 0, 0, 0 db 0, 0; sysrq _QwertyNames_end resb 0 _QwertyShift db 0 ; filler db 0,'!','@','#','$','%','^','&','*','(',')','_','+',BKSP db 0, 'Q','W','E','R','T','Y','U','I','O','P','{','}',ENTERKEY db 0,'A','S','D','F','G','H','J','K','L',':','"','~' db 0,'|','Z','X','C','V','B','N','M',"<",'>','?',0,'*' db 0, ' ', 0, 0,0,0,0,0,0,0,0,0,0 ; F1-F10 db 0,0 ; numlock, scroll lock db 0, 0, 0, '-' db 0, 0, 0, '+' db 0, 0, 0, 0 db 0, 0; sysrq _QwertyShift_end resb 0 _TextInputString times 80 db 0,'$' _ColorInputString times 15 db 0,'$' _RoundingFactor dd 000800080h, 00000080h SECTION .text _main call _LibInit ; Allocate Screen Image buffer invoke _AllocMem, dword 640*480*4 cmp eax, -1 je near .memerror mov [_ScreenOff], eax ; Allocate Canvas Image buffer invoke _AllocMem, dword 480*400*4 cmp eax, -1 je near .memerror mov [_CanvasOff], eax ; Allocate Overlay Image buffer invoke _AllocMem, dword 480*400*4 cmp eax, -1 je near .memerror mov [_OverlayOff], eax ; Allocate Font Image buffer invoke _AllocMem, dword 2048*16*4 cmp eax, -1 je near .memerror mov [_FontOff], eax ; Allocate Menu Image buffer invoke _AllocMem, dword 400*100*4 cmp eax, -1 je near .memerror mov [_MenuOff], eax ; Allocate Title Bar Image buffer invoke _AllocMem, dword 640*20*4 cmp eax, -1 je near .memerror mov [_TitleOff], eax ; Allocate Point Queue invoke _AllocMem, dword 480*400*4*4 cmp eax, -1 je near .memerror mov [_PointQueue], eax ; Load image files invoke _LoadPNG, dword _FontFN, dword [_FontOff], dword 0, dword 0 invoke _LoadPNG, dword _MenuFN, dword [_MenuOff], dword 0, dword 0 invoke _LoadPNG, dword _TitleFN, dword [_TitleOff], dword 0, dword 0 ; Graphics init invoke _InitGraphics, dword _kbINT, dword _kbIRQ, dword _kbPort test eax, eax jnz near .graphicserror ; Find graphics mode: 640x480x32, allow driver-emulated modes invoke _FindGraphicsMode, word 640, word 480, word 32, dword 1 mov [_GraphicsMode], ax ; Keyboard/Mouse init call _InstallKeyboard test eax, eax jnz near .keyboarderror invoke _SetGraphicsMode, word [_GraphicsMode] test eax, eax jnz .setgraphicserror call _InstallMouse test eax, eax jnz .mouseerror ; Show mouse cursor mov dword [DPMI_EAX], 01h mov bx, 33h call DPMI_Int call _MP4Main ; Shutdown and cleanup .mouseerror call _RemoveMouse .setgraphicserror call _UnsetGraphicsMode .keyboarderror call _RemoveKeyboard .graphicserror call _ExitGraphics .memerror call _MP4LibExit call _LibExit ret ;-------------------------------------------------------------- ;-- Replace Library Calls with your Code! -- ;-- Do not forget to add Function Headers -- ;-------------------------------------------------------------- ;-------------------------------------------------------------- ;-- PointInBox() -- ;-------------------------------------------------------------- proc _PointInBox .X arg 2 .Y arg 2 .BoxULCornerX arg 2 .BoxULCornerY arg 2 .BoxLRCornerX arg 2 .BoxLRCornerY arg 2 invoke _libPointInBox, word [ebp+.X], word [ebp+.Y], word [ebp+.BoxULCornerX], word [ebp+.BoxULCornerY], word [ebp+.BoxLRCornerX], word [ebp+.BoxLRCornerY] ret endproc _PointInBox_arglen EQU 12 ;-------------------------------------------------------------- ;-- GetPixel() -- ;-------------------------------------------------------------- proc _GetPixel .DestOff arg 4 .DestWidth arg 2 .DestHeight arg 2 .X arg 2 .Y arg 2 invoke _libGetPixel, dword [ebp+.DestOff], word [ebp+.DestWidth], word [ebp+.DestHeight], word [ebp+.X], word [ebp+.Y] ret endproc _GetPixel_arglen EQU 12 ;-------------------------------------------------------------- ;-- DrawPixel() -- ;-------------------------------------------------------------- proc _DrawPixel .DestOff arg 4 .DestWidth arg 2 .DestHeight arg 2 .X arg 2 .Y arg 2 .Color arg 4 invoke _libDrawPixel, dword [ebp+.DestOff], word [ebp+.DestWidth], word [ebp+.DestHeight], word [ebp+.X], word [ebp+.Y], dword [ebp+.Color] ret endproc _DrawPixel_arglen EQU 16 ;-------------------------------------------------------------- ;-- DrawRect() -- ;-------------------------------------------------------------- proc _DrawRect .DestOff arg 4 .DestWidth arg 2 .DestHeight arg 2 .X1 arg 2 .Y1 arg 2 .X2 arg 2 .Y2 arg 2 .Color arg 4 .FillRectFlag arg 4 invoke _libDrawRect, dword [ebp+.DestOff], word [ebp+.DestWidth], word [ebp+.DestHeight], word [ebp+.X1], word [ebp+.Y1], word [ebp+.X2], word [ebp+.Y2], dword [ebp+.Color], dword [ebp+.FillRectFlag] ret endproc _DrawRect_arglen EQU 24 ;-------------------------------------------------------------- ;-- DrawText() -- ;-------------------------------------------------------------- proc _DrawText .StringOff arg 4 .DestOff arg 4 .DestWidth arg 2 .DestHeight arg 2 .X arg 2 .Y arg 2 .Color arg 4 invoke _libDrawText, dword [ebp+.StringOff], dword [ebp+.DestOff], word [ebp+.DestWidth], word [ebp+.DestHeight], word [ebp+.X], word [ebp+.Y], dword [ebp+.Color] ret endproc _DrawText_arglen EQU 20 ;-------------------------------------------------------------- ;-- ClearBuffer() -- ;-------------------------------------------------------------- proc _ClearBuffer .DestOff arg 4 .DestWidth arg 2 .DestHeight arg 2 .Color arg 4 invoke _libClearBuffer, dword [ebp+.DestOff], word [ebp+.DestWidth], word [ebp+.DestHeight], dword [ebp+.Color] ret endproc _ClearBuffer_arglen EQU 12 ;-------------------------------------------------------------- ;-- CopyBuffer() -- ;-------------------------------------------------------------- proc _CopyBuffer .SrcOff arg 4 .SrcWidth arg 2 .SrcHeight arg 2 .DestOff arg 4 .DestWidth arg 2 .DestHeight arg 2 .X arg 2 .Y arg 2 invoke _libCopyBuffer, dword [ebp+.SrcOff], word [ebp+.SrcWidth], word [ebp+.SrcHeight], dword [ebp+.DestOff], word [ebp+.DestWidth], word [ebp+.DestHeight], word [ebp+.X], word [ebp+.Y] ret endproc _CopyBuffer_arglen EQU 20 ;-------------------------------------------------------------- ;-- ComposeBuffers() -- ;-------------------------------------------------------------- proc _ComposeBuffers .SrcOff arg 4 .SrcWidth arg 2 .SrcHeight arg 2 .DestOff arg 4 .DestWidth arg 2 .DestHeight arg 2 .X arg 2 .Y arg 2 invoke _libComposeBuffers, dword [ebp+.SrcOff], word [ebp+.SrcWidth], word [ebp+.SrcHeight], dword [ebp+.DestOff], word [ebp+.DestWidth], word [ebp+.DestHeight], word [ebp+.X], word [ebp+.Y] ret endproc _ComposeBuffers_arglen EQU 20 ;-------------------------------------------------------------- ;-- FloodFill() -- ;-------------------------------------------------------------- proc _FloodFill .DestOff arg 4 .DestWidth arg 2 .DestHeight arg 2 .X arg 2 .Y arg 2 .Color arg 4 .ComposeFlag arg 4 invoke _libFloodFill, dword [ebp+.DestOff], word [ebp+.DestWidth], word [ebp+.DestHeight], word [ebp+.X], word [ebp+.Y], dword [ebp+.Color], dword [ebp+.ComposeFlag] ret endproc _FloodFill_arglen EQU 20 ;-------------------------------------------------------------- ;-- InstallKeyboard() -- ;-------------------------------------------------------------- _InstallKeyboard call _libInstallKeyboard ret ;-------------------------------------------------------------- ;-- RemoveKeyboard() -- ;-------------------------------------------------------------- _RemoveKeyboard call _libRemoveKeyboard ret ;-------------------------------------------------------------- ;-- KeyboardISR() -- ;-------------------------------------------------------------- _KeyboardISR call _libKeyboardISR ret _KeyboardISR_end ;-------------------------------------------------------------- ;-- InstallMouse() -- ;-------------------------------------------------------------- _InstallMouse call _libInstallMouse ret ;-------------------------------------------------------------- ;-- RemoveMouse() -- ;-------------------------------------------------------------- _RemoveMouse call _libRemoveMouse ret ;-------------------------------------------------------------- ;-- MouseCallback() -- ;-------------------------------------------------------------- proc _MouseCallback .DPMIRegsPtr arg 4 invoke _libMouseCallback, dword [ebp+.DPMIRegsPtr] ret endproc _MouseCallback_end _MouseCallback_arglen EQU 4 ;-------------------------------------------------------------- ;-- Given code - you do not need to write these functions -- ;-------------------------------------------------------------- ;-------------------------------------------------------------- ;-- DrawLine() -- ;-------------------------------------------------------------- proc _DrawLine .DestOff arg 4 .DestWidth arg 2 .DestHeight arg 2 .X1 arg 2 .Y1 arg 2 .X2 arg 2 .Y2 arg 2 .Color arg 4 invoke _libDrawLine, dword [ebp+.DestOff], word [ebp+.DestWidth], word [ebp+.DestHeight], word [ebp+.X1], word [ebp+.Y1], word [ebp+.X2], word [ebp+.Y2], dword [ebp+.Color] ret endproc _DrawLine_arglen EQU 20 ;-------------------------------------------------------------- ;-- DrawCircle() -- ;-------------------------------------------------------------- proc _DrawCircle .DestOff arg 4 .DestWidth arg 2 .DestHeight arg 2 .X arg 2 .Y arg 2 .Radius arg 2 .Color arg 4 .FillCircleFlag arg 4 invoke _libDrawCircle, dword [ebp+.DestOff], word [ebp+.DestWidth], word [ebp+.DestHeight], word [ebp+.X], word [ebp+.Y], word [ebp+.Radius], dword [ebp+.Color], dword [ebp+.FillCircleFlag] ret endproc _DrawCircle_arglen EQU 22 ;-------------------------------------------------------------- ;-- BlurBuffer() -- ;-------------------------------------------------------------- proc _BlurBuffer .SrcOff arg 4 .DestOff arg 4 .DestWidth arg 2 .DestHeight arg 2 invoke _libBlurBuffer, dword [ebp+.SrcOff], dword [ebp+.DestOff], word [ebp+.DestWidth], word [ebp+.DestHeight] ret endproc _BlurBuffer_arglen EQU 12
.data prompt: .asciiz "Enter the number: " oddmsg: .asciiz "The given number is odd." evemsg: .asciiz "The given number is even." .text main: la $a0, prompt li $v0, 4 syscall li $v0, 5 syscall move $t0, $v0 andi $t0, $t0, 1 beqz $t0, even la $a0, oddmsg li $v0, 4 syscall li $v0, 10 syscall even: la $a0, evemsg li $v0, 4 syscall li $v0, 10 syscall
; database.asm WTile proc ::WIDE_IMAGES: ; BTile Best ; FileName Indices Viewed As Notes Ship equ ($-WTile)/Sprites.WTileLen import_bin "..\tiles\ship.wtile" ; 000-016 4 x 2 Ship Blank equ ($-WTile)/Sprites.WTileLen import_bin "..\tiles\blank.wtile" ; 008-008 1 x 1 Blank pend MenuText proc ; Named procedure to keep our print data tidy db At, 7, 13 ; These codes are the same as you would use db Paper, Black, PrBright, 1 ; with Sinclair BASIC's PRINT command db Ink, Red, "Z" db Ink, Yellow, "A" db Ink, Cyan, "L" db Ink, Magenta, "A" db Ink, White, "X" db Ink, Green, "A" db At, 21, 6 db Ink, Yellow, "PRESS " db Ink, White, "SPACE" db Ink, Yellow, " TO START" Length equ $-MenuText ; Let Zeus do the work of calculating the length pend ; ($ means the current address Zeus is assembling to) ClsNirvanaGame proc db 128, BrightWhiteBlackP loop 11 db 255, BrightYellowBlackP lend db 11, BrightYellowBlackP db 0 pend
// { dg-add-options ieee } // 1999-08-23 bkoz // Copyright (C) 1999-2017 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. // 18.2.1.1 template class numeric_limits #include <limits> #include <limits.h> #include <float.h> #include <cwchar> #include <testsuite_hooks.h> // libstdc++/5045 void test03() { VERIFY( std::numeric_limits<bool>::digits10 == 0 ); if (__CHAR_BIT__ == 8) { VERIFY( std::numeric_limits<signed char>::digits10 == 2 ); VERIFY( std::numeric_limits<unsigned char>::digits10 == 2 ); } if (__CHAR_BIT__ * sizeof(short) == 16) { VERIFY( std::numeric_limits<signed short>::digits10 == 4 ); VERIFY( std::numeric_limits<unsigned short>::digits10 == 4 ); } if (__CHAR_BIT__ * sizeof(int) == 32) { VERIFY( std::numeric_limits<signed int>::digits10 == 9 ); VERIFY( std::numeric_limits<unsigned int>::digits10 == 9 ); } if (__CHAR_BIT__ * sizeof(long long) == 64) { VERIFY( std::numeric_limits<signed long long>::digits10 == 18 ); VERIFY( std::numeric_limits<unsigned long long>::digits10 == 19 ); } } int main() { test03(); return 0; }
///////////////////////////////////////////////////////////////////////////// // Name: common/mediactrl.cpp // Purpose: wxMediaCtrl common code // Author: Ryan Norton <wxprojects@comcast.net> // Modified by: // Created: 11/07/04 // RCS-ID: $Id: mediactrlcmn.cpp,v 1.16 2005/09/11 11:03:46 VZ Exp $ // Copyright: (c) Ryan Norton // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// //=========================================================================== // Definitions //=========================================================================== //--------------------------------------------------------------------------- // Pre-compiled header stuff //--------------------------------------------------------------------------- #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "mediactrl.h" #endif #include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif //--------------------------------------------------------------------------- // Includes //--------------------------------------------------------------------------- #include "wx/mediactrl.h" #include "wx/hash.h" //--------------------------------------------------------------------------- // Compilation guard //--------------------------------------------------------------------------- #if wxUSE_MEDIACTRL //=========================================================================== // // Implementation // //=========================================================================== //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // RTTI and Event implementations //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ IMPLEMENT_CLASS(wxMediaCtrl, wxControl); IMPLEMENT_CLASS(wxMediaBackend, wxObject); IMPLEMENT_DYNAMIC_CLASS(wxMediaEvent, wxEvent); DEFINE_EVENT_TYPE(wxEVT_MEDIA_FINISHED); DEFINE_EVENT_TYPE(wxEVT_MEDIA_LOADED); DEFINE_EVENT_TYPE(wxEVT_MEDIA_STOP); //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // // wxMediaCtrl // //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //--------------------------------------------------------------------------- // wxMediaBackend Destructor // // This is here because the DARWIN gcc compiler badly screwed up and // needs the destructor implementation in the source //--------------------------------------------------------------------------- wxMediaBackend::~wxMediaBackend() { } //--------------------------------------------------------------------------- // wxMediaCtrl::Create (file version) // wxMediaCtrl::Create (URL version) // // Searches for a backend that is installed on the system (backends // starting with lower characters in the alphabet are given priority), // and creates the control from it // // This searches by searching the global RTTI hashtable, class by class, // attempting to call CreateControl on each one found that is a derivative // of wxMediaBackend - if it succeeded Create returns true, otherwise // it keeps iterating through the hashmap. //--------------------------------------------------------------------------- bool wxMediaCtrl::Create(wxWindow* parent, wxWindowID id, const wxString& fileName, const wxPoint& pos, const wxSize& size, long style, const wxString& szBackend, const wxValidator& validator, const wxString& name) { if(!szBackend.empty()) { wxClassInfo* pClassInfo = wxClassInfo::FindClass(szBackend); if(!pClassInfo || !DoCreate(pClassInfo, parent, id, pos, size, style, validator, name)) { m_imp = NULL; return false; } if (!fileName.empty()) { if (!Load(fileName)) { delete m_imp; m_imp = NULL; return false; } } SetBestFittingSize(size); return true; } else { wxClassInfo::sm_classTable->BeginFind(); wxClassInfo* classInfo; while((classInfo = NextBackend()) != NULL) { if(!DoCreate(classInfo, parent, id, pos, size, style, validator, name)) continue; if (!fileName.empty()) { if (Load(fileName)) { SetBestFittingSize(size); return true; } else delete m_imp; } else { SetBestFittingSize(size); return true; } } m_imp = NULL; return false; } } bool wxMediaCtrl::Create(wxWindow* parent, wxWindowID id, const wxURI& location, const wxPoint& pos, const wxSize& size, long style, const wxString& szBackend, const wxValidator& validator, const wxString& name) { if(!szBackend.empty()) { wxClassInfo* pClassInfo = wxClassInfo::FindClass(szBackend); if(!pClassInfo || !DoCreate(pClassInfo, parent, id, pos, size, style, validator, name)) { m_imp = NULL; return false; } if (!Load(location)) { delete m_imp; m_imp = NULL; return false; } SetBestFittingSize(size); return true; } else { wxClassInfo::sm_classTable->BeginFind(); wxClassInfo* classInfo; while((classInfo = NextBackend()) != NULL) { if(!DoCreate(classInfo, parent, id, pos, size, style, validator, name)) continue; if (Load(location)) { SetBestFittingSize(size); return true; } else delete m_imp; } m_imp = NULL; return false; } } //--------------------------------------------------------------------------- // wxMediaCtrl::DoCreate // // Attempts to create the control from a backend //--------------------------------------------------------------------------- bool wxMediaCtrl::DoCreate(wxClassInfo* classInfo, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) { m_imp = (wxMediaBackend*)classInfo->CreateObject(); if( m_imp->CreateControl(this, parent, id, pos, size, style, validator, name) ) { return true; } delete m_imp; return false; } //--------------------------------------------------------------------------- // wxMediaCtrl::NextBackend // // // Search through the RTTI hashmap one at a // time, attempting to create each derivative // of wxMediaBackend // // // STL isn't compatible with and will have a compilation error // on a wxNode, however, wxHashTable::compatibility_iterator is // incompatible with the old 2.4 stable version - but since // we're in 2.5 only we don't need to worry about this // static //--------------------------------------------------------------------------- wxClassInfo* wxMediaCtrl::NextBackend() { wxHashTable::compatibility_iterator node = wxClassInfo::sm_classTable->Next(); while (node) { wxClassInfo* classInfo = (wxClassInfo *)node->GetData(); if ( classInfo->IsKindOf(CLASSINFO(wxMediaBackend)) && classInfo != CLASSINFO(wxMediaBackend) ) { return classInfo; } node = wxClassInfo::sm_classTable->Next(); } // // Nope - couldn't successfully find one... fail // return NULL; } //--------------------------------------------------------------------------- // wxMediaCtrl Destructor // // Free up the backend if it exists //--------------------------------------------------------------------------- wxMediaCtrl::~wxMediaCtrl() { if (m_imp) delete m_imp; } //--------------------------------------------------------------------------- // wxMediaCtrl::Load (file version) // wxMediaCtrl::Load (URL version) // wxMediaCtrl::Load (URL & Proxy version) // wxMediaCtrl::Load (wxInputStream version) // // Here we call load of the backend - keeping // track of whether it was successful or not - which // will determine which later method calls work //--------------------------------------------------------------------------- bool wxMediaCtrl::Load(const wxString& fileName) { if(m_imp) return (m_bLoaded = m_imp->Load(fileName)); return false; } bool wxMediaCtrl::Load(const wxURI& location) { if(m_imp) return (m_bLoaded = m_imp->Load(location)); return false; } bool wxMediaCtrl::Load(const wxURI& location, const wxURI& proxy) { if(m_imp) return (m_bLoaded = m_imp->Load(location, proxy)); return false; } //--------------------------------------------------------------------------- // wxMediaCtrl::Play // wxMediaCtrl::Pause // wxMediaCtrl::Stop // wxMediaCtrl::GetPlaybackRate // wxMediaCtrl::SetPlaybackRate // wxMediaCtrl::Seek --> SetPosition // wxMediaCtrl::Tell --> GetPosition // wxMediaCtrl::Length --> GetDuration // wxMediaCtrl::GetState // wxMediaCtrl::DoGetBestSize // wxMediaCtrl::SetVolume // wxMediaCtrl::GetVolume // wxMediaCtrl::ShowInterface // wxMediaCtrl::GetDownloadProgress // wxMediaCtrl::GetDownloadTotal // // 1) Check to see whether the backend exists and is loading // 2) Call the backend's version of the method, returning success // if the backend's version succeeds //--------------------------------------------------------------------------- bool wxMediaCtrl::Play() { if(m_imp && m_bLoaded) return m_imp->Play(); return 0; } bool wxMediaCtrl::Pause() { if(m_imp && m_bLoaded) return m_imp->Pause(); return 0; } bool wxMediaCtrl::Stop() { if(m_imp && m_bLoaded) return m_imp->Stop(); return 0; } double wxMediaCtrl::GetPlaybackRate() { if(m_imp && m_bLoaded) return m_imp->GetPlaybackRate(); return 0; } bool wxMediaCtrl::SetPlaybackRate(double dRate) { if(m_imp && m_bLoaded) return m_imp->SetPlaybackRate(dRate); return false; } wxFileOffset wxMediaCtrl::Seek(wxFileOffset where, wxSeekMode mode) { wxFileOffset offset; switch (mode) { case wxFromStart: offset = where; break; case wxFromEnd: offset = Length() - where; break; // case wxFromCurrent: default: offset = Tell() + where; break; } if(m_imp && m_bLoaded && m_imp->SetPosition(offset)) return offset; return wxInvalidOffset; } wxFileOffset wxMediaCtrl::Tell() { if(m_imp && m_bLoaded) return (wxFileOffset) m_imp->GetPosition().ToLong(); return wxInvalidOffset; } wxFileOffset wxMediaCtrl::Length() { if(m_imp && m_bLoaded) return (wxFileOffset) m_imp->GetDuration().ToLong(); return wxInvalidOffset; } wxMediaState wxMediaCtrl::GetState() { if(m_imp && m_bLoaded) return m_imp->GetState(); return wxMEDIASTATE_STOPPED; } wxSize wxMediaCtrl::DoGetBestSize() const { if(m_imp) return m_imp->GetVideoSize(); return wxSize(0,0); } double wxMediaCtrl::GetVolume() { if(m_imp && m_bLoaded) return m_imp->GetVolume(); return 0.0; } bool wxMediaCtrl::SetVolume(double dVolume) { if(m_imp && m_bLoaded) return m_imp->SetVolume(dVolume); return false; } bool wxMediaCtrl::ShowPlayerControls(wxMediaCtrlPlayerControls flags) { if(m_imp) return m_imp->ShowPlayerControls(flags); return false; } wxFileOffset wxMediaCtrl::GetDownloadProgress() { if(m_imp && m_bLoaded) return (wxFileOffset) m_imp->GetDownloadProgress().ToLong(); return wxInvalidOffset; } wxFileOffset wxMediaCtrl::GetDownloadTotal() { if(m_imp && m_bLoaded) return (wxFileOffset) m_imp->GetDownloadTotal().ToLong(); return wxInvalidOffset; } //--------------------------------------------------------------------------- // wxMediaCtrl::DoMoveWindow // // 1) Call parent's version so that our control's window moves where // it's supposed to // 2) If the backend exists and is loaded, move the video // of the media to where our control's window is now located //--------------------------------------------------------------------------- void wxMediaCtrl::DoMoveWindow(int x, int y, int w, int h) { wxControl::DoMoveWindow(x,y,w,h); if(m_imp) m_imp->Move(x, y, w, h); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // // wxMediaBackendCommonBase // //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void wxMediaBackendCommonBase::NotifyMovieSizeChanged() { // our best size changed after opening a new file m_ctrl->InvalidateBestSize(); m_ctrl->SetSize(m_ctrl->GetSize()); // if the parent of the control has a sizer ask it to refresh our size wxWindow * const parent = m_ctrl->GetParent(); if ( parent->GetSizer() ) { m_ctrl->GetParent()->Layout(); m_ctrl->GetParent()->Refresh(); m_ctrl->GetParent()->Update(); } } void wxMediaBackendCommonBase::NotifyMovieLoaded() { NotifyMovieSizeChanged(); // notify about movie being fully loaded QueueEvent(wxEVT_MEDIA_LOADED); } bool wxMediaBackendCommonBase::SendStopEvent() { wxMediaEvent theEvent(wxEVT_MEDIA_STOP, m_ctrl->GetId()); return !m_ctrl->ProcessEvent(theEvent) || theEvent.IsAllowed(); } void wxMediaBackendCommonBase::QueueEvent(wxEventType evtType) { wxMediaEvent theEvent(evtType, m_ctrl->GetId()); m_ctrl->AddPendingEvent(theEvent); } #include "wx/html/forcelnk.h" FORCE_LINK(basewxmediabackends); //--------------------------------------------------------------------------- // End of compilation guard and of file //--------------------------------------------------------------------------- #endif //wxUSE_MEDIACTRL
#include <iostream> #include <vector> #include <string> #include <queue> using namespace std; struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} }; //invert using BFS class Solution { public: TreeNode* invertTree(TreeNode* root) { if(!root){ return nullptr; } if(!root->left && !root->right){ return root; } queue<TreeNode* >q; q.push(root); while(!q.empty()){ TreeNode* node = q.front(); q.pop(); //swap left & right node swap(node->left,node->right); if(node->left){ q.push(node->left); } if(node->right){ q.push(node->right); } } return root; } }; int main(){ return 0; }
// Example of a struct containing a pointer // Commodore 64 PRG executable file .file [name="struct-ptr-29.prg", type="prg", segments="Program"] .segmentdef Program [segments="Basic, Code, Data"] .segmentdef Basic [start=$0801] .segmentdef Code [start=$80d] .segmentdef Data [startAfter="Code"] .segment Basic :BasicUpstart(main) .const SIZEOF_STRUCT_PERSON = 3 .const OFFSET_STRUCT_PERSON_NAME = 1 .label SCREEN = $400 .segment Code main: { // print_person(&persons[0]) ldx #0 lda #<persons sta.z print_person.person lda #>persons sta.z print_person.person+1 jsr print_person // print_person(&persons[1]) lda #<persons+1*SIZEOF_STRUCT_PERSON sta.z print_person.person lda #>persons+1*SIZEOF_STRUCT_PERSON sta.z print_person.person+1 jsr print_person // } rts } // void print_person(__zp(3) struct Person *person) print_person: { .label i = 2 .label person = 3 // SCREEN[idx++] = DIGIT[person->id] ldy #0 lda (person),y tay lda DIGIT,y sta SCREEN,x // SCREEN[idx++] = DIGIT[person->id]; inx // SCREEN[idx++] = ' ' lda #' ' sta SCREEN,x // SCREEN[idx++] = ' '; inx lda #0 sta.z i __b1: // for(byte i=0; person->name[i]; i++) ldy #OFFSET_STRUCT_PERSON_NAME lda (person),y sta.z $fe iny lda (person),y sta.z $ff ldy.z i lda ($fe),y bne __b2 // SCREEN[idx++] = ' ' lda #' ' sta SCREEN,x // SCREEN[idx++] = ' '; inx // } rts __b2: // SCREEN[idx++] = person->name[i] ldy #OFFSET_STRUCT_PERSON_NAME lda (person),y sta.z $fe iny lda (person),y sta.z $ff ldy.z i lda ($fe),y sta SCREEN,x // SCREEN[idx++] = person->name[i]; inx // for(byte i=0; person->name[i]; i++) inc.z i jmp __b1 } .segment Data persons: .byte 4 .word person_name .byte 7 .word person_name1 DIGIT: .text "0123456789" .byte 0 person_name: .text "jesper" .byte 0 person_name1: .text "repsej" .byte 0
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r13 push %r14 push %rbp push %rbx push %rcx push %rdi push %rsi lea addresses_WC_ht+0x198e4, %rsi lea addresses_WC_ht+0x104e4, %rdi nop nop nop nop add $60978, %r14 mov $44, %rcx rep movsw nop nop nop nop nop sub $8365, %rbx lea addresses_D_ht+0xd824, %rsi lea addresses_A_ht+0xed64, %rdi nop nop add $61444, %rbp mov $37, %rcx rep movsw nop nop nop nop sub $50500, %r14 lea addresses_D_ht+0x68e4, %rdi nop and $20544, %r13 mov (%rdi), %r14w nop and $5210, %rdi lea addresses_normal_ht+0x10ee4, %r14 clflush (%r14) add $48538, %r13 movups (%r14), %xmm5 vpextrq $1, %xmm5, %rbx nop nop nop and %rdi, %rdi lea addresses_UC_ht+0x1c0e4, %r13 nop nop nop sub %rbx, %rbx movb $0x61, (%r13) nop nop nop nop nop and %r14, %r14 lea addresses_WT_ht+0x3be4, %rsi lea addresses_WC_ht+0x1082c, %rdi inc %rbp mov $124, %rcx rep movsw nop nop add $55039, %rsi lea addresses_WT_ht+0xf694, %r14 nop nop sub %r13, %r13 mov $0x6162636465666768, %rbp movq %rbp, %xmm2 movups %xmm2, (%r14) nop nop nop add %rsi, %rsi lea addresses_UC_ht+0xe790, %rsi nop nop nop nop nop sub $16815, %r13 mov (%rsi), %rdi nop nop xor $5765, %rbp lea addresses_normal_ht+0xd042, %rdi clflush (%rdi) nop nop sub $14724, %rbx mov $0x6162636465666768, %rbp movq %rbp, %xmm4 vmovups %ymm4, (%rdi) nop nop nop cmp %rdi, %rdi lea addresses_D_ht+0x15464, %rsi lea addresses_A_ht+0x10e4, %rdi nop nop and $8530, %r10 mov $112, %rcx rep movsl nop nop nop cmp %rsi, %rsi lea addresses_WT_ht+0xa4a4, %rdi clflush (%rdi) nop nop cmp %rcx, %rcx movl $0x61626364, (%rdi) inc %rbp lea addresses_normal_ht+0xba82, %rbx nop nop nop nop xor $5578, %r14 movb (%rbx), %cl nop nop nop nop nop cmp $33527, %r14 lea addresses_WT_ht+0x1c8c4, %rdi nop nop and $21484, %rbp movb (%rdi), %cl nop nop nop nop cmp %rbx, %rbx lea addresses_WT_ht+0xdae4, %r10 nop sub %r13, %r13 movw $0x6162, (%r10) nop nop nop nop and $48706, %r10 lea addresses_UC_ht+0xa8e4, %rsi nop nop dec %rbx mov (%rsi), %r14d nop nop nop nop nop sub %r13, %r13 pop %rsi pop %rdi pop %rcx pop %rbx pop %rbp pop %r14 pop %r13 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r13 push %r15 push %r8 push %rax push %rbp push %rcx push %rdi push %rsi // Store lea addresses_normal+0x1bae4, %r8 nop nop nop nop nop sub %rax, %rax movl $0x51525354, (%r8) xor $28504, %r10 // Store lea addresses_UC+0x3184, %r13 clflush (%r13) nop and $18013, %r8 movl $0x51525354, (%r13) nop sub %rbp, %rbp // Store lea addresses_WT+0x28e4, %rax nop nop nop nop nop inc %r15 movl $0x51525354, (%rax) sub %rbp, %rbp // Store lea addresses_A+0xb0e4, %r10 nop nop nop nop nop xor $26600, %r8 movb $0x51, (%r10) nop and %r15, %r15 // Load lea addresses_RW+0x1dbc4, %r13 nop nop nop and $43459, %rsi movups (%r13), %xmm5 vpextrq $1, %xmm5, %r10 nop nop lfence // Store lea addresses_D+0x3ce4, %rax clflush (%rax) xor %rbp, %rbp movw $0x5152, (%rax) nop nop nop and $32121, %rax // Store lea addresses_normal+0x1e0e4, %rax nop nop sub %r10, %r10 movw $0x5152, (%rax) nop nop nop nop add $64262, %rsi // Store lea addresses_D+0x16d94, %r15 clflush (%r15) nop nop cmp $49693, %r8 mov $0x5152535455565758, %rbp movq %rbp, (%r15) nop and $43158, %r8 // REPMOV lea addresses_WC+0x1d964, %rsi lea addresses_D+0x14f24, %rdi nop nop nop nop nop add %rax, %rax mov $99, %rcx rep movsl nop nop nop nop nop inc %r13 // Faulty Load lea addresses_WT+0x28e4, %rcx cmp %r8, %r8 movups (%rcx), %xmm0 vpextrq $1, %xmm0, %rbp lea oracles, %r15 and $0xff, %rbp shlq $12, %rbp mov (%r15,%rbp,1), %rbp pop %rsi pop %rdi pop %rcx pop %rbp pop %rax pop %r8 pop %r15 pop %r13 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_WT', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'AVXalign': False, 'size': 4, 'NT': True, 'same': False, 'congruent': 7}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'AVXalign': False, 'size': 4, 'NT': False, 'same': False, 'congruent': 4}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'AVXalign': False, 'size': 4, 'NT': True, 'same': True, 'congruent': 0}} {'OP': 'STOR', 'dst': {'type': 'addresses_A', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 8}} {'src': {'type': 'addresses_RW', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 5}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'type': 'addresses_D', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 10}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 11}} {'OP': 'STOR', 'dst': {'type': 'addresses_D', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 2}} {'src': {'type': 'addresses_WC', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_D', 'congruent': 6, 'same': False}} [Faulty Load] {'src': {'type': 'addresses_WT', 'AVXalign': False, 'size': 16, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_WC_ht', 'congruent': 11, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WC_ht', 'congruent': 4, 'same': False}} {'src': {'type': 'addresses_D_ht', 'congruent': 6, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 7, 'same': False}} {'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 10}, 'OP': 'LOAD'} {'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 9}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 11}} {'src': {'type': 'addresses_WT_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 1}} {'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 2}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 32, 'NT': False, 'same': False, 'congruent': 0}} {'src': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 11, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': True, 'size': 4, 'NT': False, 'same': True, 'congruent': 5}} {'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 1}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 5}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 2, 'NT': False, 'same': False, 'congruent': 8}} {'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 4, 'NT': True, 'same': False, 'congruent': 11}, 'OP': 'LOAD'} {'39': 21829} 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 */
; ; Comment ; ; === STACK SEGMENT === MyStack segment stack DB 64 dup('12345678') MyStack endS ; === DATA SEGMENT === MyData segment ; --- Declare your variables here --- blastoff DB "BLASTOFF!",13,10,"$" MyData endS MyCode segment Assume CS:Mycode,DS:MyData ;Includes go here INCLUDE TIME.INC INCLUDE CONIO.INC ;End of includes Main PROC Start: MOV AX, MYDATA MOV DS, AX ;Start of your code MOV AX,1 CALL DelayForSecs MOV DL,3 CALL PrintDecByte CALL PrintNewLine MOV AX,1 CALL DelayForSecs MOV DL,2 CALL PrintDecByte CALL PrintNewLine MOV AX,1 CALL DelayForSecs MOV DL,1 CALL PrintDecByte CALL PrintNewLine MOV AX,1 CALL DelayForSecs MOV AH,9 LEA DX,blastoff INT 21h ;End of your code. XOR AX,AX XOR BX,BX XOR CX,CX XOR DX,DX MOV AH, 4Ch XOR AL, AL INT 21h Main ENDP MyCode endS End Start