text stringlengths 1 1.05M |
|---|
; Troy's HBC-56 - CPU tests (degugging emulator issues)
;
; Copyright (c) 2021 Troy Schrapel
;
; This code is licensed under the MIT license
;
; https://github.com/visrealm/hbc-56
;
!src "hbc56kernel.inc"
hbc56Meta:
+setHbcMetaTitle "CPU UNIT TESTS"
rts
hbc56Main:
sei
jsr kbInit
+tmsSetColorFgBg TMS_LT_GREEN, TMS_BLACK
jsr tmsInitEntireColorTable
+tmsEnableOutput
cli
+tmsEnableInterrupts
jsr overflowTests
jsr decimalTests
jmp success
decimalTests:
sed
clc
lda #$08
adc #$08
cld
cmp #$16
bne FAIL
sed
sec
sbc #$08
cld
cmp #$08
bne FAIL
sed
clc
sbc #$16
;bcc FAIL
cld
cmp #$91
bne FAIL
rts
FAIL:
+tmsPrint "FAILED",2,0
-
jmp -
overflowTests:
clc
lda #$30
adc #$10
bvs FAIL
clc
lda #$50
adc #$50
bvc FAIL
clc
lda #$50
adc #$90
bvs FAIL
clc
lda #$50
adc #$D0
bvs FAIL
clc
lda #$D0
adc #$10
bvs FAIL
clc
lda #$D0
adc #$50
bvs FAIL
clc
lda #$D0
adc #$90
bvc FAIL
clc
lda #$D0
adc #$D0
bvs FAIL
sec
lda #$50
sbc #$F0
bvs FAIL
sec
lda #$50
sbc #$B0
bvc FAIL
sec
lda #$50
sbc #$70
bvs FAIL
sec
lda #$50
sbc #$30
bvs FAIL
sec
lda #$D0
sbc #$F0
bvs FAIL2
sec
lda #$D0
sbc #$B0
bvs FAIL2
sec
lda #$D0
sbc #$70
bvc FAIL2
sec
lda #$D0
sbc #$30
bvs FAIL2
rts
FAIL2:
+tmsPrint "FAILED",2,0
-
jmp -
success:
+tmsPrint "PASSED",2,0
-
jmp -
|
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* 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 "c_ops/primitive_c.h"
#include <memory>
#include <string>
namespace mindspore {
void PrimitiveC::InitIOName(const std::vector<std::string> &inputs_name, const std::vector<std::string> &outputs_name) {
this->AddAttr("input_names", MakeValue(inputs_name));
this->AddAttr("output_names", MakeValue(outputs_name));
}
AbstractBasePtr PrimitiveC::Infer(const AbstractBasePtrList &abstract_list) {
auto infer_map = abstract::GetPrimitiveToEvalImplMap();
auto iter = infer_map.find(std::make_shared<Primitive>(this->name()));
if (iter == infer_map.end()) {
MS_EXCEPTION(NotExistsError) << "Cannot find the " << this->name() << "infer function in the infer map!";
}
auto infer_function = iter->second.impl_;
return infer_function(nullptr, shared_from_base<Primitive>(), abstract_list);
}
OpPrimCRegister &OpPrimCRegister::GetInstance() {
static OpPrimCRegister instance;
return instance;
}
std::map<std::string, OpPrimCDefineFunc> OpPrimCRegister::GetPrimCMap() { return op_primc_fns_; }
void OpPrimCRegister::SetPrimCMap(const std::string &kname, const OpPrimCDefineFunc &fn) { op_primc_fns_[kname] = fn; }
} // namespace mindspore
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r8
push %r9
push %rax
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0x17e, %r12
nop
cmp %rbx, %rbx
mov (%r12), %r9w
nop
nop
nop
nop
nop
and %r12, %r12
lea addresses_UC_ht+0x987e, %rsi
lea addresses_UC_ht+0x1dc7e, %rdi
clflush (%rsi)
nop
nop
add $55979, %rax
mov $113, %rcx
rep movsl
nop
nop
nop
nop
sub %rdi, %rdi
lea addresses_WC_ht+0x607e, %rsi
nop
and %rdi, %rdi
movl $0x61626364, (%rsi)
nop
nop
nop
nop
nop
and %rbx, %rbx
lea addresses_normal_ht+0x607e, %rax
nop
nop
nop
nop
nop
xor %rcx, %rcx
mov $0x6162636465666768, %r9
movq %r9, %xmm0
vmovups %ymm0, (%rax)
nop
nop
nop
nop
inc %rcx
lea addresses_WT_ht+0x1b47e, %rsi
nop
nop
xor $49157, %rdi
mov $0x6162636465666768, %rcx
movq %rcx, %xmm3
and $0xffffffffffffffc0, %rsi
vmovntdq %ymm3, (%rsi)
nop
nop
nop
nop
xor $60707, %rsi
lea addresses_UC_ht+0x15d7e, %rax
nop
inc %rcx
mov (%rax), %si
nop
nop
nop
sub %r9, %r9
lea addresses_UC_ht+0xf2fe, %rax
nop
nop
xor %r9, %r9
movw $0x6162, (%rax)
nop
nop
and $5204, %rdi
lea addresses_UC_ht+0x847e, %rbx
nop
nop
add $12717, %rdi
mov $0x6162636465666768, %rax
movq %rax, (%rbx)
nop
nop
nop
inc %r9
lea addresses_A_ht+0x1157e, %rax
cmp $38900, %rdi
movb (%rax), %cl
nop
nop
dec %rbx
lea addresses_A_ht+0xd658, %rax
nop
nop
nop
nop
sub $37946, %rdi
mov $0x6162636465666768, %rcx
movq %rcx, %xmm6
movups %xmm6, (%rax)
nop
xor %rax, %rax
lea addresses_WC_ht+0x10d0e, %r12
nop
nop
nop
dec %rcx
mov (%r12), %rbx
nop
nop
sub $32685, %rdi
lea addresses_A_ht+0x1269e, %rsi
lea addresses_WT_ht+0x4e7e, %rdi
and %rax, %rax
mov $2, %rcx
rep movsb
nop
nop
nop
nop
nop
dec %r9
lea addresses_WT_ht+0xc6fe, %rsi
lea addresses_WC_ht+0xbbfe, %rdi
nop
nop
nop
nop
add %r8, %r8
mov $84, %rcx
rep movsw
nop
nop
nop
nop
add %rcx, %rcx
lea addresses_D_ht+0x7966, %r8
nop
nop
nop
nop
nop
mfence
and $0xffffffffffffffc0, %r8
vmovaps (%r8), %ymm5
vextracti128 $0, %ymm5, %xmm5
vpextrq $1, %xmm5, %rbx
nop
nop
nop
nop
nop
inc %rbx
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r9
pop %r8
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r14
push %r15
push %r8
push %rbp
push %rcx
push %rdi
// Store
lea addresses_A+0x1512e, %r11
nop
nop
nop
cmp $57099, %rdi
movb $0x51, (%r11)
nop
nop
nop
nop
nop
add $43792, %r11
// Faulty Load
lea addresses_D+0x18c7e, %rcx
nop
nop
nop
sub $62764, %r14
vmovups (%rcx), %ymm5
vextracti128 $0, %ymm5, %xmm5
vpextrq $1, %xmm5, %r11
lea oracles, %rbp
and $0xff, %r11
shlq $12, %r11
mov (%rbp,%r11,1), %r11
pop %rdi
pop %rcx
pop %rbp
pop %r8
pop %r15
pop %r14
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False, 'NT': True, 'congruent': 6, 'same': True}}
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 0, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 5, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 32, 'AVXalign': True, 'NT': False, 'congruent': 3, 'same': False}}
{'36': 903}
36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36
*/
|
/*
* Copyright (C) 2018 João Borrego
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*!
\file utils/DRInterface.cc
\brief Domain randomization interface
\author João Borrego : jsbruglie
*/
#include "DRInterface.hh"
// Constants
const char DRInterface::REQUEST_TOPIC[] = "~/gap/dr";
const char DRInterface::RESPONSE_TOPIC[] = "~/gap/dr/response";
const char DRInterface::VISUAL_TOPIC[] = "~/visual";
const int DRInterface::POSITION = 0;
const int DRInterface::VELOCITY = 1;
//////////////////////////////////////////////////
DRInterface::DRInterface(
const std::string & req_topic_,
const std::string & res_topic_) :
req_topic(req_topic_), res_topic(res_topic_)
{
node = gazebo::transport::NodePtr(new gazebo::transport::Node());
node->Init();
pub = node->Advertise<DRRequest>(req_topic);
pub->WaitForConnection();
pub_visual = node->Advertise<gazebo::msgs::Visual>(VISUAL_TOPIC);
// pub_visual->WaitForConnection();
sub = node->Subscribe(res_topic, &DRInterface::onResponse, this);
debugPrintTrace("DRInterface initialized." << std::endl <<
" Requests topic: " << req_topic << std::endl <<
" Response topic: " << res_topic);
}
//////////////////////////////////////////////////
DRInterface::DRInterface() : DRInterface(REQUEST_TOPIC, RESPONSE_TOPIC)
{
}
//////////////////////////////////////////////////
DRInterface::~DRInterface()
{
this->sub->Unsubscribe();
}
//////////////////////////////////////////////////
DRRequest DRInterface::createRequest()
{
DRRequest msg;
return msg;
}
//////////////////////////////////////////////////
void DRInterface::publish(DRRequest & msg, bool blocking)
{
if (blocking)
{
msg.set_feedback(true);
std::unique_lock<std::mutex> lock(mutex);
pub->Publish(msg);
debugPrintTrace("Waiting for feedback.");
cond_var.wait(lock);
}
else
{
pub->Publish(msg);
}
}
//////////////////////////////////////////////////
void DRInterface::publish(gazebo::msgs::Visual & msg, bool blocking)
{
if (blocking){ /*TODO - Unused */ }
pub_visual->Publish(msg);
}
//////////////////////////////////////////////////
void DRInterface::addGravity(DRRequest & msg,
const ignition::math::Vector3d & gravity)
{
gazebo::msgs::Physics *physics_msg;
gazebo::msgs::Vector3d *gravity_msg;
physics_msg = msg.mutable_physics();
gravity_msg = physics_msg->mutable_gravity();
gazebo::msgs::Set(gravity_msg, gravity);
}
//////////////////////////////////////////////////
void DRInterface::addModelScale(DRRequest & msg,
const std::string & model,
const ignition::math::Vector3d & scale)
{
gazebo::msgs::Model *model_msg;
gazebo::msgs::Vector3d *scale_msg;
model_msg = msg.add_model();
model_msg->set_name(model);
scale_msg = model_msg->mutable_scale();
gazebo::msgs::Set(scale_msg, scale);
}
//////////////////////////////////////////////////
void DRInterface::addLinkMass(DRRequest & msg,
const std::string & model,
const std::string & link,
double mass)
{
gazebo::msgs::Model *model_msg;
gazebo::msgs::Link *link_msg;
gazebo::msgs::Inertial *inertial_msg;
model_msg = msg.add_model();
model_msg->set_name(model);
link_msg = model_msg->add_link();
link_msg->set_name(link);
inertial_msg = link_msg->mutable_inertial();
inertial_msg->set_mass(mass);
}
//////////////////////////////////////////////////
void DRInterface::addInertiaMatrix(DRRequest & msg,
const std::string & model,
const std::string & link,
double ixx, double iyy, double izz,
double ixy, double ixz, double iyz)
{
gazebo::msgs::Model *model_msg;
gazebo::msgs::Link *link_msg;
gazebo::msgs::Inertial *inertial_msg;
model_msg = msg.add_model();
model_msg->set_name(model);
link_msg = model_msg->add_link();
link_msg->set_name(link);
inertial_msg = link_msg->mutable_inertial();
inertial_msg->set_ixx(ixx);
inertial_msg->set_iyy(iyy);
inertial_msg->set_izz(izz);
inertial_msg->set_ixy(ixy);
inertial_msg->set_ixz(ixz);
inertial_msg->set_iyz(iyz);
}
//////////////////////////////////////////////////
void DRInterface::addSurface(DRRequest & msg,
const std::string & model,
const std::string & link,
const std::string & collision,
gazebo::msgs::Surface *surface_ptr)
{
gazebo::msgs::Model *model_msg;
gazebo::msgs::Link *link_msg;
gazebo::msgs::Collision *collision_msg;
model_msg = msg.add_model();
model_msg->set_name(model);
link_msg = model_msg->add_link();
link_msg->set_name(link);
collision_msg = link_msg->add_collision();
collision_msg->set_id(0);
collision_msg->set_name(collision);
collision_msg->set_allocated_surface(surface_ptr);
}
//////////////////////////////////////////////////
void DRInterface::addJoint(DRRequest & msg,
const std::string & model,
const std::string & joint,
double limit_lower,
double limit_upper,
double limit_effort,
double limit_velocity,
double damping,
double friction)
{
gazebo::msgs::Model *model_msg;
gazebo::msgs::Joint *joint_msg;
gazebo::msgs::Axis *axis_msg;
model_msg = msg.add_model();
model_msg->set_name(model);
joint_msg = model_msg->add_joint();
joint_msg->set_name(joint);
axis_msg = joint_msg->mutable_axis1();
axis_msg->set_limit_lower(limit_lower);
axis_msg->set_limit_upper(limit_upper);
axis_msg->set_limit_effort(limit_effort);
axis_msg->set_limit_velocity(limit_velocity);
axis_msg->set_damping(damping);
axis_msg->set_friction(friction);
// Required fields - set to dummy unused values
ignition::math::Vector3d xyz(0,0,0);
gazebo::msgs::Vector3d *xyz_msg;
xyz_msg = axis_msg->mutable_xyz();
gazebo::msgs::Set(xyz_msg, xyz);
axis_msg->set_use_parent_model_frame(true);
}
//////////////////////////////////////////////////
void DRInterface::addModelCmd(DRRequest & msg,
const std::string & model,
const std::string & joint,
int type,
double p_gain,
double i_gain,
double d_gain)
{
ModelCmdMsg *model_cmd;
gazebo::msgs::JointCmd *joint_cmd;
gazebo::msgs::PID *pid;
if (type != POSITION && type != VELOCITY) { return; }
model_cmd = msg.add_model_cmd();
model_cmd->set_model_name(model);
joint_cmd = model_cmd->add_joint_cmd();
joint_cmd->set_name(joint);
if (type == POSITION) { pid = joint_cmd->mutable_position(); }
else { pid = joint_cmd->mutable_velocity(); }
if (p_gain != INFINITY) { pid->set_p_gain(p_gain); }
if (i_gain != INFINITY) { pid->set_i_gain(i_gain); }
if (d_gain != INFINITY) { pid->set_d_gain(d_gain); }
}
//////////////////////////////////////////////////
void DRInterface::addColors(gazebo::msgs::Visual & msg,
const std::string & visual,
const std::string & parent,
const ignition::math::Color & ambient,
const ignition::math::Color & diffuse,
const ignition::math::Color & emissive,
const ignition::math::Color & specular)
{
gazebo::msgs::Material *material_msg;
gazebo::msgs::Color *ambient_msg,
*diffuse_msg, *emissive_msg, *specular_msg;
msg.set_name(visual);
msg.set_parent_name(parent);
material_msg = msg.mutable_material();
ambient_msg = material_msg->mutable_ambient();
diffuse_msg = material_msg->mutable_diffuse();
emissive_msg = material_msg->mutable_emissive();
specular_msg = material_msg->mutable_specular();
gazebo::msgs::Set(ambient_msg, ambient);
gazebo::msgs::Set(diffuse_msg, diffuse);
gazebo::msgs::Set(emissive_msg, emissive);
gazebo::msgs::Set(specular_msg, specular);
}
/////////////////////////////////////////////////
void DRInterface::onResponse(DRResponsePtr & _msg)
{
debugPrintTrace("Received response!");
std::lock_guard<std::mutex> lock(mutex);
cond_var.notify_one();
}
|
; A279079: Maximum starting value of X such that repeated replacement of X with X-ceiling(X/9) requires n steps to reach 0.
; 0,1,2,3,4,5,6,7,8,10,12,14,16,19,22,25,29,33,38,43,49,56,64,73,83,94,106,120,136,154,174,196,221,249,281,317,357,402,453,510,574,646,727,818,921,1037,1167,1313,1478,1663,1871,2105,2369,2666,3000,3376,3799
mov $2,$0
mov $3,3
lpb $2,1
add $4,$1
add $4,1
lpb $4,1
add $1,1
sub $4,$3
trn $4,5
lpe
sub $2,1
lpe
|
class ZFirstClass {
ZFirstClass();
line 1: 0: aload_0
line 1: 1: invokespecial #1 // Method java/lang/Object."<init>":()V
line 1: 4: return
static int square(int);
line 3: 0: iload_0
line 3: 1: iload_0
line 3: 2: imul
line 3: 3: ireturn
}
class ASecondClass {
ASecondClass();
line 7: 0: aload_0
line 7: 1: invokespecial #1 // Method java/lang/Object."<init>":()V
line 7: 4: return
static int square(int);
line 9: 0: iload_0
line 9: 1: iload_0
line 9: 2: imul
line 9: 3: ireturn
} |
/**
* Swaggy Jenkins
* Jenkins API clients generated from Swagger / Open API specification
*
* OpenAPI spec version: 1.1.1
* Contact: blah@cliffano.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "InputStepImpl.h"
namespace org {
namespace openapitools {
namespace server {
namespace model {
InputStepImpl::InputStepImpl()
{
m__class = "";
m__classIsSet = false;
m__linksIsSet = false;
m_Id = "";
m_IdIsSet = false;
m_Message = "";
m_MessageIsSet = false;
m_Ok = "";
m_OkIsSet = false;
m_ParametersIsSet = false;
m_Submitter = "";
m_SubmitterIsSet = false;
}
InputStepImpl::~InputStepImpl()
{
}
void InputStepImpl::validate()
{
// TODO: implement validation
}
nlohmann::json InputStepImpl::toJson() const
{
nlohmann::json val = nlohmann::json::object();
if(m__classIsSet)
{
val["_class"] = ModelBase::toJson(m__class);
}
if(m__linksIsSet)
{
val["_links"] = ModelBase::toJson(m__links);
}
if(m_IdIsSet)
{
val["id"] = ModelBase::toJson(m_Id);
}
if(m_MessageIsSet)
{
val["message"] = ModelBase::toJson(m_Message);
}
if(m_OkIsSet)
{
val["ok"] = ModelBase::toJson(m_Ok);
}
{
nlohmann::json jsonArray;
for( auto& item : m_Parameters )
{
jsonArray.push_back(ModelBase::toJson(item));
}
if(jsonArray.size() > 0)
{
val["parameters"] = jsonArray;
}
}
if(m_SubmitterIsSet)
{
val["submitter"] = ModelBase::toJson(m_Submitter);
}
return val;
}
void InputStepImpl::fromJson(nlohmann::json& val)
{
if(val.find("_class") != val.end())
{
setClass(val.at("_class"));
}
if(val.find("_links") != val.end())
{
if(!val["_links"].is_null())
{
InputStepImpllinks newItem;
newItem.fromJson(val["_links"]);
setLinks( newItem );
}
}
if(val.find("id") != val.end())
{
setId(val.at("id"));
}
if(val.find("message") != val.end())
{
setMessage(val.at("message"));
}
if(val.find("ok") != val.end())
{
setOk(val.at("ok"));
}
{
m_Parameters.clear();
nlohmann::json jsonArray;
if(val.find("parameters") != val.end())
{
for( auto& item : val["parameters"] )
{
if(item.is_null())
{
m_Parameters.push_back( StringParameterDefinition() );
}
else
{
StringParameterDefinition newItem;
newItem.fromJson(item);
m_Parameters.push_back( newItem );
}
}
}
}
if(val.find("submitter") != val.end())
{
setSubmitter(val.at("submitter"));
}
}
std::string InputStepImpl::getClass() const
{
return m__class;
}
void InputStepImpl::setClass(std::string const& value)
{
m__class = value;
m__classIsSet = true;
}
bool InputStepImpl::classIsSet() const
{
return m__classIsSet;
}
void InputStepImpl::unset_class()
{
m__classIsSet = false;
}
InputStepImpllinks InputStepImpl::getLinks() const
{
return m__links;
}
void InputStepImpl::setLinks(InputStepImpllinks const& value)
{
m__links = value;
m__linksIsSet = true;
}
bool InputStepImpl::linksIsSet() const
{
return m__linksIsSet;
}
void InputStepImpl::unset_links()
{
m__linksIsSet = false;
}
std::string InputStepImpl::getId() const
{
return m_Id;
}
void InputStepImpl::setId(std::string const& value)
{
m_Id = value;
m_IdIsSet = true;
}
bool InputStepImpl::idIsSet() const
{
return m_IdIsSet;
}
void InputStepImpl::unsetId()
{
m_IdIsSet = false;
}
std::string InputStepImpl::getMessage() const
{
return m_Message;
}
void InputStepImpl::setMessage(std::string const& value)
{
m_Message = value;
m_MessageIsSet = true;
}
bool InputStepImpl::messageIsSet() const
{
return m_MessageIsSet;
}
void InputStepImpl::unsetMessage()
{
m_MessageIsSet = false;
}
std::string InputStepImpl::getOk() const
{
return m_Ok;
}
void InputStepImpl::setOk(std::string const& value)
{
m_Ok = value;
m_OkIsSet = true;
}
bool InputStepImpl::okIsSet() const
{
return m_OkIsSet;
}
void InputStepImpl::unsetOk()
{
m_OkIsSet = false;
}
std::vector<StringParameterDefinition>& InputStepImpl::getParameters()
{
return m_Parameters;
}
bool InputStepImpl::parametersIsSet() const
{
return m_ParametersIsSet;
}
void InputStepImpl::unsetParameters()
{
m_ParametersIsSet = false;
}
std::string InputStepImpl::getSubmitter() const
{
return m_Submitter;
}
void InputStepImpl::setSubmitter(std::string const& value)
{
m_Submitter = value;
m_SubmitterIsSet = true;
}
bool InputStepImpl::submitterIsSet() const
{
return m_SubmitterIsSet;
}
void InputStepImpl::unsetSubmitter()
{
m_SubmitterIsSet = false;
}
}
}
}
}
|
ori $1, $0, 3
ori $2, $0, 0
ori $3, $0, 5
ori $4, $0, 1
sw $4, 0($0)
sw $2, 4($0)
sw $3, 8($0)
sw $2, 12($0)
sw $1, 16($0)
sw $2, 20($0)
sw $2, 24($0)
sw $2, 28($0)
sw $1, 32($0)
sw $4, 36($0)
sw $1, 40($0)
sw $3, 44($0)
sw $3, 48($0)
sw $3, 52($0)
sw $1, 56($0)
sw $1, 60($0)
sw $3, 64($0)
sw $2, 68($0)
sw $2, 72($0)
sw $3, 76($0)
sw $3, 80($0)
sw $4, 84($0)
sw $1, 88($0)
sw $2, 92($0)
sw $1, 96($0)
sw $3, 100($0)
sw $4, 104($0)
sw $2, 108($0)
sw $3, 112($0)
sw $3, 116($0)
sw $2, 120($0)
sw $3, 124($0)
multu $2, $2
multu $2, $2
mtlo $2
beq $2, $2, TAG1
TAG1:
mfhi $2
lui $3, 8
bne $2, $2, TAG2
sw $2, 0($2)
TAG2:
mtlo $3
and $2, $3, $3
sll $0, $0, 0
sll $0, $0, 0
TAG3:
sll $0, $0, 0
lui $1, 9
sll $0, $0, 0
bne $1, $2, TAG4
TAG4:
sll $0, $0, 0
mfhi $4
div $1, $1
bne $4, $1, TAG5
TAG5:
mult $4, $4
sh $4, 0($4)
sh $4, 0($4)
lui $2, 15
TAG6:
xori $1, $2, 4
div $1, $1
mtlo $2
mthi $2
TAG7:
div $1, $1
divu $1, $1
blez $1, TAG8
mult $1, $1
TAG8:
slti $2, $1, 7
blez $2, TAG9
div $1, $1
mthi $2
TAG9:
lbu $3, 0($2)
mfhi $2
beq $2, $3, TAG10
xor $4, $3, $2
TAG10:
sltu $1, $4, $4
mthi $1
sh $4, 0($1)
srl $3, $1, 6
TAG11:
bne $3, $3, TAG12
lb $3, 0($3)
blez $3, TAG12
sb $3, 0($3)
TAG12:
srav $2, $3, $3
sw $2, 0($3)
sb $2, 0($2)
mult $2, $3
TAG13:
sw $2, 0($2)
srl $1, $2, 15
slti $4, $2, 15
lui $4, 8
TAG14:
xor $4, $4, $4
mfhi $1
lbu $3, 0($4)
mflo $4
TAG15:
lhu $3, 0($4)
sw $3, 0($4)
mult $3, $4
srav $2, $3, $4
TAG16:
mfhi $4
mtlo $4
xor $2, $4, $4
addi $3, $4, 2
TAG17:
sllv $1, $3, $3
blez $1, TAG18
multu $3, $3
sb $1, 0($1)
TAG18:
mthi $1
sb $1, 0($1)
mtlo $1
beq $1, $1, TAG19
TAG19:
lui $2, 7
mflo $4
divu $2, $1
addiu $1, $2, 0
TAG20:
subu $2, $1, $1
beq $1, $2, TAG21
mthi $1
addiu $2, $1, 6
TAG21:
sltu $2, $2, $2
bne $2, $2, TAG22
lui $1, 14
xor $1, $2, $2
TAG22:
blez $1, TAG23
mflo $3
beq $1, $1, TAG23
mflo $1
TAG23:
subu $4, $1, $1
bgez $1, TAG24
mtlo $1
mtlo $4
TAG24:
slti $4, $4, 14
multu $4, $4
mflo $4
addu $1, $4, $4
TAG25:
lui $2, 6
sllv $3, $1, $1
sra $3, $2, 9
lh $3, 0($1)
TAG26:
bltz $3, TAG27
sh $3, 0($3)
sh $3, 0($3)
mthi $3
TAG27:
mfhi $2
beq $3, $3, TAG28
multu $2, $3
lh $3, 0($2)
TAG28:
mflo $4
sb $3, 0($3)
mfhi $4
mtlo $4
TAG29:
beq $4, $4, TAG30
or $3, $4, $4
bne $3, $3, TAG30
lui $3, 8
TAG30:
beq $3, $3, TAG31
andi $2, $3, 2
lh $1, 0($2)
mthi $1
TAG31:
multu $1, $1
bltz $1, TAG32
andi $1, $1, 9
mult $1, $1
TAG32:
sh $1, 0($1)
beq $1, $1, TAG33
lbu $2, 0($1)
lui $4, 10
TAG33:
lui $3, 10
sll $0, $0, 0
beq $3, $3, TAG34
sll $0, $0, 0
TAG34:
sll $0, $0, 0
lui $1, 3
xor $4, $2, $3
mflo $2
TAG35:
xori $1, $2, 12
lui $4, 13
lui $1, 9
bgtz $1, TAG36
TAG36:
sltu $1, $1, $1
beq $1, $1, TAG37
sltiu $1, $1, 12
divu $1, $1
TAG37:
lbu $2, 0($1)
bgtz $1, TAG38
mult $2, $1
lui $2, 11
TAG38:
mtlo $2
mflo $2
ori $2, $2, 3
mfhi $1
TAG39:
sb $1, 0($1)
mult $1, $1
mtlo $1
sb $1, 0($1)
TAG40:
sw $1, 0($1)
mflo $1
bgtz $1, TAG41
sltiu $1, $1, 10
TAG41:
sll $4, $1, 4
mflo $2
mflo $3
sltu $4, $2, $3
TAG42:
multu $4, $4
sw $4, 0($4)
sll $2, $4, 15
ori $1, $2, 1
TAG43:
mtlo $1
addu $3, $1, $1
lui $2, 6
mult $1, $2
TAG44:
mthi $2
bltz $2, TAG45
multu $2, $2
blez $2, TAG45
TAG45:
sll $0, $0, 0
mfhi $1
sra $1, $2, 12
sll $0, $0, 0
TAG46:
mult $4, $4
multu $4, $4
sltiu $1, $4, 11
multu $4, $4
TAG47:
lui $3, 10
divu $1, $3
divu $1, $1
beq $1, $3, TAG48
TAG48:
addiu $3, $3, 15
subu $1, $3, $3
sll $2, $1, 0
slti $2, $2, 3
TAG49:
mult $2, $2
blez $2, TAG50
mfhi $1
mfhi $4
TAG50:
lui $2, 11
subu $3, $4, $2
sll $0, $0, 0
lui $4, 11
TAG51:
xori $3, $4, 2
or $4, $4, $3
or $1, $3, $4
sll $0, $0, 0
TAG52:
sll $0, $0, 0
lui $4, 0
lw $1, 0($4)
lb $4, 0($1)
TAG53:
mfhi $1
lbu $1, 0($4)
lbu $2, 0($1)
nor $1, $1, $1
TAG54:
bne $1, $1, TAG55
sltiu $3, $1, 14
bne $1, $1, TAG55
lhu $3, 1($1)
TAG55:
sh $3, 0($3)
subu $3, $3, $3
lui $1, 9
mflo $3
TAG56:
sb $3, 0($3)
divu $3, $3
lui $1, 0
srl $3, $3, 14
TAG57:
mthi $3
sub $3, $3, $3
sb $3, 0($3)
mtlo $3
TAG58:
mtlo $3
mtlo $3
blez $3, TAG59
mthi $3
TAG59:
beq $3, $3, TAG60
srlv $1, $3, $3
lui $2, 10
lh $1, 0($2)
TAG60:
beq $1, $1, TAG61
lui $1, 2
div $1, $1
mult $1, $1
TAG61:
and $1, $1, $1
mflo $2
bgez $1, TAG62
mtlo $1
TAG62:
mtlo $2
mflo $4
bgez $2, TAG63
sw $2, 0($4)
TAG63:
lbu $1, 0($4)
mflo $4
bgtz $4, TAG64
mtlo $1
TAG64:
beq $4, $4, TAG65
sltu $4, $4, $4
multu $4, $4
lb $1, 0($4)
TAG65:
bne $1, $1, TAG66
lh $3, 0($1)
srl $3, $1, 3
bltz $3, TAG66
TAG66:
mthi $3
beq $3, $3, TAG67
sb $3, 0($3)
sw $3, 0($3)
TAG67:
mfhi $3
mult $3, $3
sub $3, $3, $3
mfhi $3
TAG68:
multu $3, $3
srl $4, $3, 6
lui $3, 8
bne $4, $4, TAG69
TAG69:
subu $4, $3, $3
srav $2, $4, $4
blez $4, TAG70
sb $2, 0($2)
TAG70:
sw $2, 0($2)
xor $2, $2, $2
lb $4, 0($2)
mflo $2
TAG71:
lui $2, 5
mfhi $1
lw $2, 0($1)
multu $2, $2
TAG72:
mthi $2
xori $1, $2, 1
mfhi $2
mtlo $1
TAG73:
mtlo $2
lui $2, 14
sll $0, $0, 0
beq $2, $2, TAG74
TAG74:
srav $1, $2, $2
sll $0, $0, 0
and $4, $1, $3
sll $0, $0, 0
TAG75:
mult $4, $4
mthi $4
div $4, $4
bne $4, $4, TAG76
TAG76:
slti $4, $4, 3
lui $1, 5
mult $1, $4
sub $2, $4, $4
TAG77:
multu $2, $2
lui $3, 0
mflo $3
sw $2, 0($2)
TAG78:
beq $3, $3, TAG79
sra $1, $3, 9
bne $3, $3, TAG79
lhu $4, 0($1)
TAG79:
mtlo $4
ori $4, $4, 8
lui $2, 0
bgez $4, TAG80
TAG80:
mtlo $2
lui $4, 9
mflo $2
sll $0, $0, 0
TAG81:
lui $4, 12
mflo $4
lb $2, 0($4)
lhu $4, 0($4)
TAG82:
addu $2, $4, $4
mfhi $2
mfhi $1
addi $3, $2, 2
TAG83:
multu $3, $3
lhu $2, 0($3)
mflo $1
slt $1, $3, $2
TAG84:
mult $1, $1
lw $4, 0($1)
lh $2, 0($4)
add $1, $4, $1
TAG85:
sw $1, 0($1)
bgez $1, TAG86
mult $1, $1
bne $1, $1, TAG86
TAG86:
lui $2, 11
lui $4, 2
nor $1, $2, $2
multu $1, $4
TAG87:
blez $1, TAG88
sll $0, $0, 0
lui $2, 7
bgtz $3, TAG88
TAG88:
sll $0, $0, 0
lui $2, 9
sll $0, $0, 0
lui $3, 4
TAG89:
sll $0, $0, 0
sll $0, $0, 0
or $1, $3, $1
xori $3, $3, 3
TAG90:
mflo $4
mfhi $3
lui $3, 4
div $3, $3
TAG91:
mfhi $3
sw $3, 0($3)
mflo $1
srl $2, $1, 5
TAG92:
sll $1, $2, 11
sw $1, 0($2)
lui $2, 1
bne $2, $2, TAG93
TAG93:
sll $0, $0, 0
bne $4, $4, TAG94
sll $0, $0, 0
multu $2, $4
TAG94:
div $4, $4
xori $4, $4, 2
beq $4, $4, TAG95
sll $0, $0, 0
TAG95:
sll $0, $0, 0
slti $4, $2, 8
sw $4, 0($4)
sh $2, 0($4)
TAG96:
sllv $2, $4, $4
xori $1, $4, 12
bne $4, $1, TAG97
ori $1, $2, 8
TAG97:
bne $1, $1, TAG98
addu $3, $1, $1
nor $4, $1, $1
multu $1, $1
TAG98:
bgtz $4, TAG99
sh $4, 9($4)
lbu $4, 9($4)
sh $4, -247($4)
TAG99:
sra $3, $4, 11
lui $4, 7
xori $2, $3, 1
xori $1, $2, 8
TAG100:
addiu $3, $1, 1
blez $3, TAG101
sb $1, 0($1)
slti $2, $1, 13
TAG101:
lui $4, 13
div $4, $4
addu $1, $2, $4
sb $1, 0($2)
TAG102:
mtlo $1
mthi $1
multu $1, $1
sltiu $3, $1, 4
TAG103:
sltu $2, $3, $3
multu $3, $2
sllv $1, $2, $2
srav $1, $1, $1
TAG104:
mult $1, $1
lh $3, 0($1)
lui $1, 6
mtlo $1
TAG105:
bltz $1, TAG106
sll $0, $0, 0
lui $2, 2
div $1, $1
TAG106:
sll $0, $0, 0
sll $0, $0, 0
beq $2, $1, TAG107
sll $0, $0, 0
TAG107:
bne $4, $4, TAG108
mult $4, $4
mfhi $1
mfhi $1
TAG108:
sll $0, $0, 0
mult $2, $2
mfhi $1
bltz $2, TAG109
TAG109:
mthi $1
sra $1, $1, 11
mflo $2
bgtz $1, TAG110
TAG110:
sllv $4, $2, $2
nor $2, $4, $2
sw $4, 0($4)
sltu $3, $4, $2
TAG111:
addu $2, $3, $3
lui $3, 2
beq $2, $3, TAG112
sh $3, 0($2)
TAG112:
and $3, $3, $3
mflo $4
mtlo $3
mfhi $3
TAG113:
beq $3, $3, TAG114
lb $2, 0($3)
lui $3, 10
divu $2, $3
TAG114:
beq $3, $3, TAG115
or $1, $3, $3
mflo $4
bgtz $1, TAG115
TAG115:
sw $4, 0($4)
lb $1, 0($4)
sw $4, 0($1)
lh $2, 0($1)
TAG116:
mfhi $4
multu $4, $2
xori $1, $4, 14
sh $1, 0($1)
TAG117:
div $1, $1
mtlo $1
xori $4, $1, 6
beq $4, $1, TAG118
TAG118:
mthi $4
mtlo $4
bne $4, $4, TAG119
slti $2, $4, 14
TAG119:
lb $4, 0($2)
sb $4, 0($2)
mult $2, $4
xor $2, $4, $4
TAG120:
bne $2, $2, TAG121
xor $4, $2, $2
mult $2, $4
sb $2, 0($4)
TAG121:
lui $3, 8
div $4, $3
bne $3, $3, TAG122
mtlo $3
TAG122:
andi $4, $3, 0
div $3, $3
multu $4, $3
multu $3, $4
TAG123:
lb $3, 0($4)
sw $4, 0($3)
multu $3, $4
lhu $1, 0($3)
TAG124:
beq $1, $1, TAG125
mfhi $2
lb $2, 0($1)
sh $1, 0($2)
TAG125:
xor $2, $2, $2
blez $2, TAG126
lui $1, 0
bltz $1, TAG126
TAG126:
mfhi $2
subu $4, $1, $1
nor $3, $4, $4
lhu $1, 1($3)
TAG127:
mult $1, $1
sh $1, 0($1)
addiu $3, $1, 12
lui $2, 5
TAG128:
lui $1, 15
bne $2, $2, TAG129
srl $1, $2, 2
srlv $2, $1, $1
TAG129:
bgez $2, TAG130
mfhi $3
sub $2, $3, $2
srav $4, $2, $2
TAG130:
andi $1, $4, 15
andi $1, $1, 2
addi $3, $4, 3
lw $4, 0($4)
TAG131:
sll $2, $4, 15
mult $4, $4
lui $3, 1
sh $2, 0($4)
TAG132:
lui $3, 5
mthi $3
beq $3, $3, TAG133
mtlo $3
TAG133:
lui $2, 4
bgtz $3, TAG134
sll $0, $0, 0
mfhi $2
TAG134:
mfhi $2
sll $0, $0, 0
srl $1, $2, 11
mthi $1
TAG135:
bgtz $1, TAG136
mult $1, $1
xor $1, $1, $1
sh $1, 0($1)
TAG136:
slti $1, $1, 13
lui $4, 7
bne $4, $1, TAG137
subu $1, $4, $1
TAG137:
div $1, $1
xori $4, $1, 9
bltz $4, TAG138
mfhi $1
TAG138:
mfhi $2
lhu $2, 0($2)
sw $1, 0($2)
mult $2, $2
TAG139:
xori $1, $2, 15
sll $1, $2, 11
bne $2, $1, TAG140
ori $1, $1, 12
TAG140:
div $1, $1
sltu $4, $1, $1
mtlo $4
xori $4, $4, 2
TAG141:
lhu $4, 0($4)
lhu $1, 0($4)
bltz $4, TAG142
lw $4, 0($4)
TAG142:
sllv $3, $4, $4
srlv $3, $3, $4
multu $3, $3
slti $4, $4, 9
TAG143:
mthi $4
mthi $4
lui $4, 15
mthi $4
TAG144:
bne $4, $4, TAG145
addu $1, $4, $4
mflo $2
lui $4, 4
TAG145:
mtlo $4
lui $4, 4
bltz $4, TAG146
mflo $2
TAG146:
mfhi $2
bgtz $2, TAG147
slti $1, $2, 8
lb $3, 0($2)
TAG147:
bltz $3, TAG148
xor $2, $3, $3
mflo $3
bne $2, $3, TAG148
TAG148:
div $3, $3
lui $4, 6
sll $4, $4, 11
beq $4, $3, TAG149
TAG149:
sll $0, $0, 0
mfhi $3
mthi $4
mfhi $2
TAG150:
bgez $2, TAG151
sll $0, $0, 0
mflo $1
mtlo $2
TAG151:
beq $1, $1, TAG152
lbu $2, 0($1)
beq $1, $1, TAG152
mflo $2
TAG152:
mfhi $2
mfhi $4
divu $4, $2
lui $3, 11
TAG153:
sll $0, $0, 0
bltz $3, TAG154
sll $0, $0, 0
sltu $2, $4, $4
TAG154:
mflo $4
div $4, $4
lui $4, 3
mthi $4
TAG155:
sll $0, $0, 0
lui $1, 4
mtlo $4
multu $4, $1
TAG156:
divu $1, $1
mtlo $1
mtlo $1
slti $2, $1, 4
TAG157:
beq $2, $2, TAG158
lh $1, 0($2)
mthi $1
blez $2, TAG158
TAG158:
multu $1, $1
bgtz $1, TAG159
mthi $1
mthi $1
TAG159:
lbu $3, 0($1)
sw $3, 0($3)
multu $3, $3
xor $2, $3, $1
TAG160:
sb $2, 0($2)
lui $1, 4
mflo $2
sll $1, $2, 6
TAG161:
mfhi $3
lui $3, 5
lui $3, 3
mflo $3
TAG162:
mfhi $4
mtlo $3
beq $4, $3, TAG163
lui $1, 12
TAG163:
beq $1, $1, TAG164
mthi $1
mtlo $1
addi $3, $1, 15
TAG164:
mflo $4
mthi $4
mflo $2
bltz $3, TAG165
TAG165:
lb $2, 0($2)
beq $2, $2, TAG166
nor $2, $2, $2
sh $2, 0($2)
TAG166:
sb $2, 1($2)
sh $2, 1($2)
sra $3, $2, 7
multu $2, $2
TAG167:
mfhi $3
lbu $1, 2($3)
sw $3, 2($3)
bltz $1, TAG168
TAG168:
lui $3, 13
divu $1, $3
bltz $1, TAG169
mfhi $2
TAG169:
sll $0, $0, 0
lh $4, -255($2)
bgtz $4, TAG170
sb $1, 2($4)
TAG170:
beq $4, $4, TAG171
mtlo $4
mflo $1
slt $4, $1, $1
TAG171:
addiu $4, $4, 12
lh $3, 0($4)
srav $2, $4, $4
lui $4, 13
TAG172:
bgtz $4, TAG173
lui $2, 15
beq $4, $4, TAG173
lh $1, 0($4)
TAG173:
blez $1, TAG174
addiu $1, $1, 11
bne $1, $1, TAG174
srl $1, $1, 15
TAG174:
lh $4, 0($1)
mult $1, $1
sll $4, $1, 11
lb $1, 0($4)
TAG175:
bltz $1, TAG176
sll $2, $1, 3
mtlo $1
sw $2, 0($1)
TAG176:
lui $2, 4
sra $2, $2, 15
sh $2, 0($2)
div $2, $2
TAG177:
lh $4, 0($2)
mult $2, $2
mult $2, $4
blez $2, TAG178
TAG178:
sll $1, $4, 1
sltiu $4, $4, 0
sw $1, 0($1)
sltiu $4, $1, 11
TAG179:
bne $4, $4, TAG180
mtlo $4
addiu $3, $4, 10
beq $3, $4, TAG180
TAG180:
lui $3, 12
mthi $3
mtlo $3
addiu $4, $3, 4
TAG181:
mult $4, $4
subu $4, $4, $4
bgtz $4, TAG182
mflo $3
TAG182:
ori $2, $3, 15
bgez $3, TAG183
sll $0, $0, 0
beq $3, $2, TAG183
TAG183:
mtlo $1
lui $2, 6
sll $0, $0, 0
sll $0, $0, 0
TAG184:
lui $1, 3
mtlo $1
srlv $2, $1, $1
mthi $2
TAG185:
sll $0, $0, 0
div $2, $2
lui $1, 7
mfhi $4
TAG186:
multu $4, $4
bne $4, $4, TAG187
multu $4, $4
bgtz $4, TAG187
TAG187:
sw $4, 0($4)
sllv $1, $4, $4
sh $1, 0($4)
mfhi $3
TAG188:
sllv $4, $3, $3
sw $4, 0($3)
srav $2, $4, $3
lb $1, 0($2)
TAG189:
blez $1, TAG190
mtlo $1
sltiu $4, $1, 6
mthi $1
TAG190:
mfhi $1
mflo $4
bgez $4, TAG191
lhu $3, 0($4)
TAG191:
lw $2, 0($3)
lui $3, 5
mult $2, $2
bgtz $3, TAG192
TAG192:
addu $1, $3, $3
mtlo $3
sll $0, $0, 0
blez $1, TAG193
TAG193:
lui $1, 5
xor $3, $1, $1
beq $1, $3, TAG194
sh $1, 0($3)
TAG194:
sw $3, 0($3)
bne $3, $3, TAG195
multu $3, $3
andi $3, $3, 14
TAG195:
lw $3, 0($3)
lb $3, 0($3)
lhu $1, 0($3)
lui $3, 14
TAG196:
divu $3, $3
beq $3, $3, TAG197
lui $1, 0
mfhi $2
TAG197:
sh $2, 0($2)
lui $4, 7
lui $1, 0
sb $1, 0($2)
TAG198:
multu $1, $1
mtlo $1
bltz $1, TAG199
addu $1, $1, $1
TAG199:
blez $1, TAG200
xor $2, $1, $1
ori $1, $2, 2
sllv $1, $2, $2
TAG200:
beq $1, $1, TAG201
sh $1, 0($1)
bne $1, $1, TAG201
mfhi $3
TAG201:
mfhi $3
lhu $1, 0($3)
mult $1, $1
mult $1, $3
TAG202:
lui $2, 10
ori $1, $1, 12
lw $1, 0($1)
beq $1, $1, TAG203
TAG203:
multu $1, $1
lui $3, 6
mult $1, $3
lui $1, 9
TAG204:
sll $0, $0, 0
bgez $1, TAG205
sll $0, $0, 0
sllv $4, $1, $1
TAG205:
mtlo $4
mfhi $2
bgtz $4, TAG206
lui $1, 6
TAG206:
sll $0, $0, 0
multu $1, $1
mflo $3
mult $3, $1
TAG207:
mthi $3
sh $3, 0($3)
addiu $1, $3, 6
sh $1, 0($3)
TAG208:
addiu $1, $1, 2
lhu $1, 0($1)
divu $1, $1
srav $1, $1, $1
TAG209:
lui $1, 5
mtlo $1
sll $0, $0, 0
addu $1, $1, $2
TAG210:
divu $1, $1
slti $1, $1, 3
sra $3, $1, 1
blez $3, TAG211
TAG211:
subu $1, $3, $3
lui $1, 15
sllv $1, $1, $1
mfhi $2
TAG212:
mflo $2
multu $2, $2
lb $3, 0($2)
bne $3, $2, TAG213
TAG213:
mthi $3
mflo $3
mflo $1
lbu $2, 0($3)
TAG214:
slti $4, $2, 2
lbu $4, 0($4)
nor $4, $4, $4
mflo $2
TAG215:
lui $3, 9
bne $3, $3, TAG216
lui $4, 2
bltz $3, TAG216
TAG216:
or $4, $4, $4
bgtz $4, TAG217
sll $0, $0, 0
mthi $2
TAG217:
ori $3, $2, 15
srlv $2, $2, $2
slti $2, $2, 12
ori $4, $2, 13
TAG218:
sb $4, 0($4)
mfhi $1
bgtz $4, TAG219
multu $1, $1
TAG219:
bne $1, $1, TAG220
lui $3, 14
mfhi $2
lui $1, 7
TAG220:
lui $2, 8
mult $2, $1
mflo $3
mflo $4
TAG221:
lhu $2, 0($4)
and $2, $2, $2
mtlo $4
beq $2, $2, TAG222
TAG222:
mfhi $2
bltz $2, TAG223
sw $2, 0($2)
lh $3, 0($2)
TAG223:
sw $3, 0($3)
sltu $2, $3, $3
blez $3, TAG224
lui $4, 11
TAG224:
beq $4, $4, TAG225
sll $0, $0, 0
lhu $4, 0($4)
sb $4, 0($4)
TAG225:
bltz $4, TAG226
lui $3, 13
addiu $4, $3, 14
sll $0, $0, 0
TAG226:
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
TAG227:
bgez $4, TAG228
mult $4, $4
sb $4, 0($4)
ori $3, $4, 14
TAG228:
mthi $3
bne $3, $3, TAG229
mflo $3
blez $3, TAG229
TAG229:
lui $1, 2
xori $3, $1, 6
mult $1, $1
mult $1, $3
TAG230:
div $3, $3
sll $0, $0, 0
divu $3, $3
sll $0, $0, 0
TAG231:
and $2, $3, $3
slt $1, $3, $3
beq $3, $2, TAG232
sra $4, $1, 13
TAG232:
mflo $1
subu $2, $4, $1
mthi $4
lhu $3, 1($2)
TAG233:
andi $3, $3, 11
divu $3, $3
multu $3, $3
lb $2, 0($3)
TAG234:
lui $4, 8
mflo $1
lui $2, 9
sll $0, $0, 0
TAG235:
slt $4, $2, $2
bne $4, $4, TAG236
mtlo $4
mthi $2
TAG236:
sltu $1, $4, $4
mult $1, $4
mfhi $4
beq $4, $1, TAG237
TAG237:
srav $2, $4, $4
sb $2, 0($4)
andi $1, $4, 11
mtlo $2
TAG238:
subu $3, $1, $1
beq $3, $3, TAG239
lui $3, 7
mthi $3
TAG239:
blez $3, TAG240
multu $3, $3
bne $3, $3, TAG240
sll $0, $0, 0
TAG240:
lui $3, 11
lui $1, 1
divu $3, $3
sll $0, $0, 0
TAG241:
nor $3, $1, $1
mtlo $3
sllv $4, $1, $1
sll $0, $0, 0
TAG242:
mfhi $2
multu $2, $2
bgtz $2, TAG243
divu $2, $4
TAG243:
bgez $2, TAG244
sh $2, 0($2)
lui $3, 4
sra $2, $3, 10
TAG244:
sb $2, 0($2)
bgez $2, TAG245
slti $3, $2, 6
lui $3, 3
TAG245:
sltu $1, $3, $3
bne $1, $3, TAG246
lui $1, 5
lui $3, 12
TAG246:
sltu $4, $3, $3
subu $3, $4, $4
bgtz $3, TAG247
sra $3, $3, 14
TAG247:
sh $3, 0($3)
mult $3, $3
xor $1, $3, $3
bne $1, $1, TAG248
TAG248:
sb $1, 0($1)
slti $3, $1, 3
bgtz $1, TAG249
sll $4, $3, 1
TAG249:
mfhi $2
subu $1, $4, $2
xori $3, $2, 6
mflo $2
TAG250:
multu $2, $2
xori $2, $2, 11
beq $2, $2, TAG251
mtlo $2
TAG251:
slt $1, $2, $2
beq $1, $1, TAG252
slti $3, $2, 0
add $3, $1, $1
TAG252:
lui $1, 4
bne $1, $1, TAG253
divu $1, $1
mthi $3
TAG253:
mflo $4
mtlo $4
bne $1, $1, TAG254
lui $3, 1
TAG254:
srlv $1, $3, $3
bne $1, $1, TAG255
div $3, $3
bgez $1, TAG255
TAG255:
addiu $2, $1, 11
divu $1, $2
sll $0, $0, 0
sll $0, $0, 0
TAG256:
blez $4, TAG257
lb $3, 0($4)
sb $4, 0($4)
srlv $2, $3, $4
TAG257:
mflo $4
multu $4, $2
beq $4, $2, TAG258
lui $4, 14
TAG258:
mfhi $1
lui $1, 7
bne $1, $1, TAG259
div $4, $4
TAG259:
sll $0, $0, 0
xori $1, $3, 8
bne $1, $3, TAG260
srlv $2, $1, $1
TAG260:
bne $2, $2, TAG261
mflo $2
sb $2, 0($2)
mfhi $4
TAG261:
lui $2, 1
mthi $2
mfhi $3
xori $3, $3, 5
TAG262:
sll $0, $0, 0
and $2, $2, $3
sll $0, $0, 0
sll $0, $0, 0
TAG263:
mtlo $1
bne $1, $1, TAG264
mtlo $1
beq $1, $1, TAG264
TAG264:
sra $4, $1, 7
lui $4, 1
lui $2, 14
mtlo $4
TAG265:
and $4, $2, $2
subu $3, $4, $4
sltu $2, $3, $4
lui $3, 4
TAG266:
lui $3, 14
lui $4, 13
bltz $3, TAG267
and $3, $3, $4
TAG267:
lui $3, 13
divu $3, $3
mthi $3
bne $3, $3, TAG268
TAG268:
mtlo $3
mfhi $4
sllv $4, $4, $4
sll $0, $0, 0
TAG269:
mthi $4
multu $4, $4
bgez $4, TAG270
subu $1, $4, $4
TAG270:
beq $1, $1, TAG271
lbu $3, 0($1)
subu $2, $3, $3
lui $1, 6
TAG271:
lui $4, 9
addiu $4, $4, 2
lui $3, 2
and $2, $4, $4
TAG272:
bltz $2, TAG273
sll $0, $0, 0
mtlo $2
sll $0, $0, 0
TAG273:
sll $0, $0, 0
bne $2, $2, TAG274
mtlo $2
lui $2, 12
TAG274:
mflo $3
sltiu $3, $2, 11
div $3, $2
bgtz $3, TAG275
TAG275:
multu $3, $3
or $4, $3, $3
sb $4, 0($3)
bne $4, $4, TAG276
TAG276:
mtlo $4
addi $2, $4, 2
sb $4, 0($2)
bltz $2, TAG277
TAG277:
sh $2, 0($2)
lh $4, 0($2)
bne $4, $4, TAG278
subu $3, $2, $4
TAG278:
srav $1, $3, $3
mflo $1
subu $3, $1, $3
bne $3, $3, TAG279
TAG279:
andi $4, $3, 9
mfhi $2
multu $2, $4
mfhi $3
TAG280:
lui $4, 3
mtlo $3
lhu $4, 0($3)
sw $4, -256($4)
TAG281:
mflo $3
multu $3, $3
mtlo $4
bne $4, $3, TAG282
TAG282:
addiu $1, $3, 10
ori $4, $3, 5
multu $3, $3
sb $4, 0($3)
TAG283:
bgez $4, TAG284
mthi $4
sb $4, 0($4)
mfhi $1
TAG284:
lui $4, 13
sllv $1, $4, $1
subu $3, $1, $4
sll $0, $0, 0
TAG285:
mthi $3
sra $2, $3, 5
bgtz $3, TAG286
mtlo $2
TAG286:
srlv $4, $2, $2
mthi $2
bne $4, $2, TAG287
sll $0, $0, 0
TAG287:
div $2, $2
mflo $4
mult $4, $2
sb $2, 0($4)
TAG288:
div $4, $4
beq $4, $4, TAG289
sb $4, 0($4)
mfhi $1
TAG289:
mthi $1
sll $0, $0, 0
bne $1, $1, TAG290
lui $4, 14
TAG290:
div $4, $4
divu $4, $4
blez $4, TAG291
divu $4, $4
TAG291:
lui $3, 5
sllv $3, $3, $4
srav $4, $3, $4
sll $0, $0, 0
TAG292:
mflo $3
sll $0, $0, 0
sll $0, $0, 0
bltz $4, TAG293
TAG293:
mtlo $3
div $3, $3
subu $2, $3, $3
mtlo $3
TAG294:
mfhi $3
subu $1, $3, $3
mthi $2
sw $2, 0($3)
TAG295:
sh $1, 0($1)
mfhi $4
beq $4, $1, TAG296
mthi $4
TAG296:
blez $4, TAG297
mfhi $1
bne $4, $4, TAG297
sra $3, $4, 14
TAG297:
slti $3, $3, 13
and $2, $3, $3
mtlo $2
mthi $3
TAG298:
div $2, $2
lb $1, 0($2)
sb $2, 0($2)
slt $2, $1, $1
TAG299:
xori $2, $2, 1
div $2, $2
mflo $4
bltz $4, TAG300
TAG300:
lui $4, 11
sll $2, $4, 1
mtlo $4
beq $4, $2, TAG301
TAG301:
mfhi $2
addu $2, $2, $2
mthi $2
bltz $2, TAG302
TAG302:
subu $3, $2, $2
blez $3, TAG303
andi $3, $2, 12
bne $2, $2, TAG303
TAG303:
multu $3, $3
slti $3, $3, 0
sh $3, 0($3)
srl $1, $3, 9
TAG304:
addiu $1, $1, 6
mthi $1
div $1, $1
nor $4, $1, $1
TAG305:
multu $4, $4
lw $4, 7($4)
lui $2, 15
sh $4, 0($4)
TAG306:
sra $4, $2, 6
mthi $4
mtlo $2
sll $0, $0, 0
TAG307:
lh $1, 0($3)
mfhi $3
xori $4, $3, 13
nor $3, $1, $3
TAG308:
bltz $3, TAG309
mtlo $3
mtlo $3
add $2, $3, $3
TAG309:
mfhi $2
sll $2, $2, 8
mflo $4
sll $0, $0, 0
TAG310:
sll $0, $0, 0
div $4, $4
mthi $3
addu $4, $3, $3
TAG311:
andi $4, $4, 7
sh $4, 0($4)
mthi $4
sll $1, $4, 3
TAG312:
bne $1, $1, TAG313
sw $1, 0($1)
bne $1, $1, TAG313
mfhi $4
TAG313:
nor $3, $4, $4
mthi $4
sllv $3, $3, $3
sll $0, $0, 0
TAG314:
sll $0, $0, 0
sra $1, $1, 12
slt $2, $3, $1
lb $3, 0($2)
TAG315:
beq $3, $3, TAG316
sb $3, 0($3)
lbu $3, 0($3)
bne $3, $3, TAG316
TAG316:
sh $3, 0($3)
mult $3, $3
lh $4, 0($3)
lw $4, 0($3)
TAG317:
sw $4, 0($4)
lbu $4, 0($4)
mtlo $4
bne $4, $4, TAG318
TAG318:
lui $3, 11
mult $4, $3
sll $0, $0, 0
xori $3, $4, 10
TAG319:
xor $4, $3, $3
lui $2, 5
mflo $4
sra $3, $2, 12
TAG320:
bgez $3, TAG321
mfhi $2
divu $2, $3
mfhi $3
TAG321:
addiu $4, $3, 12
addiu $4, $3, 2
lhu $3, 0($4)
sh $3, 0($4)
TAG322:
sh $3, 0($3)
sll $3, $3, 8
sltu $4, $3, $3
sw $3, 0($3)
TAG323:
blez $4, TAG324
lui $2, 14
divu $4, $4
sltu $4, $4, $4
TAG324:
sb $4, 0($4)
mfhi $2
bltz $4, TAG325
srav $3, $2, $4
TAG325:
lui $1, 10
mtlo $3
sltiu $1, $3, 8
beq $1, $1, TAG326
TAG326:
or $3, $1, $1
div $3, $3
lui $1, 13
mflo $3
TAG327:
multu $3, $3
bgtz $3, TAG328
lui $4, 3
sra $1, $4, 1
TAG328:
ori $4, $1, 13
mflo $4
mthi $4
mfhi $2
TAG329:
addiu $3, $2, 15
beq $2, $3, TAG330
mflo $1
bne $1, $3, TAG330
TAG330:
sb $1, 0($1)
mfhi $3
sb $1, 0($3)
nor $4, $1, $3
TAG331:
lui $1, 10
sll $0, $0, 0
mfhi $2
lbu $4, 0($2)
TAG332:
blez $4, TAG333
sb $4, 0($4)
bgez $4, TAG333
lui $4, 10
TAG333:
sll $0, $0, 0
sra $4, $4, 2
mtlo $1
sll $0, $0, 0
TAG334:
div $4, $4
mfhi $2
sll $0, $0, 0
sltu $3, $2, $4
TAG335:
mult $3, $3
beq $3, $3, TAG336
sb $3, 0($3)
bgtz $3, TAG336
TAG336:
lui $4, 2
blez $4, TAG337
mflo $4
mfhi $2
TAG337:
mtlo $2
andi $2, $2, 15
mfhi $3
lhu $3, 0($3)
TAG338:
sll $0, $0, 0
lui $3, 10
lui $2, 13
lui $1, 13
TAG339:
bgtz $1, TAG340
mflo $1
multu $1, $1
bgtz $1, TAG340
TAG340:
and $4, $1, $1
mtlo $4
bne $4, $1, TAG341
mflo $1
TAG341:
sh $1, 0($1)
bne $1, $1, TAG342
sw $1, 0($1)
lb $2, 0($1)
TAG342:
sra $3, $2, 9
mtlo $2
sh $3, 0($3)
bne $3, $3, TAG343
TAG343:
mthi $3
sb $3, 0($3)
sh $3, 0($3)
sltiu $4, $3, 9
TAG344:
sb $4, 0($4)
mult $4, $4
sb $4, 0($4)
bne $4, $4, TAG345
TAG345:
multu $4, $4
mthi $4
bne $4, $4, TAG346
mflo $3
TAG346:
or $3, $3, $3
lbu $2, 0($3)
bltz $2, TAG347
sllv $2, $3, $3
TAG347:
bne $2, $2, TAG348
sltu $3, $2, $2
lb $4, 0($2)
sw $3, 0($4)
TAG348:
sb $4, 0($4)
lb $2, 0($4)
bne $2, $2, TAG349
mflo $4
TAG349:
srl $4, $4, 15
mfhi $4
sb $4, 0($4)
lui $4, 1
TAG350:
div $4, $4
srlv $4, $4, $4
sll $0, $0, 0
mflo $4
TAG351:
lbu $2, 0($4)
slt $2, $4, $4
lui $4, 6
sll $0, $0, 0
TAG352:
srav $2, $4, $4
beq $2, $4, TAG353
xor $4, $4, $2
mtlo $4
TAG353:
beq $4, $4, TAG354
mfhi $2
sw $4, 0($4)
mflo $1
TAG354:
slt $1, $1, $1
mthi $1
lui $3, 12
sltiu $2, $1, 1
TAG355:
multu $2, $2
lui $3, 5
mthi $3
mflo $3
TAG356:
lui $4, 7
sltiu $4, $3, 14
bgtz $3, TAG357
lbu $2, 0($3)
TAG357:
addiu $1, $2, 2
multu $1, $2
lb $4, 0($2)
mflo $2
TAG358:
srl $3, $2, 11
lui $1, 14
srav $1, $1, $2
mtlo $2
TAG359:
sll $0, $0, 0
beq $1, $1, TAG360
mult $1, $1
sw $1, 0($1)
TAG360:
div $1, $1
mflo $1
mthi $1
addiu $2, $1, 3
TAG361:
divu $2, $2
divu $2, $2
mflo $3
lbu $3, 0($3)
TAG362:
bne $3, $3, TAG363
divu $3, $3
xor $3, $3, $3
bne $3, $3, TAG363
TAG363:
mtlo $3
nor $4, $3, $3
sh $3, 1($4)
lui $2, 4
TAG364:
beq $2, $2, TAG365
sll $0, $0, 0
sw $2, 0($2)
blez $2, TAG365
TAG365:
mflo $2
xor $3, $2, $2
sltu $4, $2, $2
mflo $1
TAG366:
mult $1, $1
ori $2, $1, 12
sh $2, 0($1)
mthi $2
TAG367:
lb $3, 0($2)
bgez $3, TAG368
lui $3, 5
lbu $4, 0($2)
TAG368:
mthi $4
sh $4, 0($4)
slti $4, $4, 11
mtlo $4
TAG369:
blez $4, TAG370
sb $4, 0($4)
lbu $3, 0($4)
bgez $3, TAG370
TAG370:
sb $3, 0($3)
div $3, $3
bne $3, $3, TAG371
srav $1, $3, $3
TAG371:
lui $3, 10
lui $2, 15
lui $2, 9
bgtz $2, TAG372
TAG372:
lui $1, 8
mtlo $1
multu $2, $1
lui $3, 3
TAG373:
multu $3, $3
div $3, $3
sll $0, $0, 0
bne $3, $1, TAG374
TAG374:
mult $1, $1
sll $0, $0, 0
addiu $3, $1, 11
lbu $4, 0($4)
TAG375:
slt $1, $4, $4
multu $1, $4
sb $1, 0($4)
sb $4, 0($4)
TAG376:
mtlo $1
sh $1, 0($1)
mflo $4
mtlo $4
TAG377:
mtlo $4
mflo $2
beq $4, $4, TAG378
mult $2, $2
TAG378:
lui $4, 13
mflo $2
lui $4, 4
mflo $3
TAG379:
mfhi $2
addu $2, $3, $2
mflo $1
lui $3, 1
TAG380:
addiu $2, $3, 15
sll $0, $0, 0
or $3, $2, $2
mtlo $2
TAG381:
mflo $1
bne $3, $1, TAG382
sllv $2, $1, $3
bltz $2, TAG382
TAG382:
sllv $3, $2, $2
bgez $3, TAG383
xori $3, $3, 10
srav $2, $2, $2
TAG383:
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
lui $3, 0
TAG384:
mflo $3
lui $3, 7
mtlo $3
blez $3, TAG385
TAG385:
sll $0, $0, 0
beq $2, $3, TAG386
mtlo $2
sll $0, $0, 0
TAG386:
srlv $4, $1, $1
beq $1, $4, TAG387
mtlo $4
mtlo $4
TAG387:
bltz $4, TAG388
ori $3, $4, 4
lbu $3, 0($4)
mtlo $3
TAG388:
sra $1, $3, 6
beq $3, $1, TAG389
mflo $4
sltu $2, $1, $1
TAG389:
sll $0, $0, 0
bne $2, $2, TAG390
sll $0, $0, 0
beq $2, $2, TAG390
TAG390:
multu $2, $2
lui $4, 10
beq $4, $4, TAG391
sll $0, $0, 0
TAG391:
ori $2, $4, 8
lui $4, 9
mfhi $2
bltz $4, TAG392
TAG392:
sll $0, $0, 0
bne $2, $2, TAG393
mthi $2
mtlo $2
TAG393:
multu $2, $2
srl $3, $2, 11
lui $2, 8
mfhi $1
TAG394:
bne $1, $1, TAG395
mthi $1
sll $0, $0, 0
sll $0, $0, 0
TAG395:
mthi $1
mflo $2
addu $1, $1, $1
sll $0, $0, 0
TAG396:
sll $1, $4, 7
blez $4, TAG397
mthi $4
ori $4, $1, 13
TAG397:
mthi $4
mtlo $4
bgez $4, TAG398
mflo $1
TAG398:
ori $3, $1, 1
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
TAG399:
mthi $3
lui $1, 0
lui $2, 7
sll $0, $0, 0
TAG400:
mfhi $2
srlv $3, $3, $2
mflo $4
beq $3, $2, TAG401
TAG401:
lui $4, 13
bne $4, $4, TAG402
mfhi $4
beq $4, $4, TAG402
TAG402:
sll $0, $0, 0
srlv $4, $2, $2
mthi $4
bne $2, $4, TAG403
TAG403:
mfhi $2
mfhi $1
slti $4, $2, 12
bne $4, $1, TAG404
TAG404:
mthi $4
mult $4, $4
lui $4, 13
mflo $3
TAG405:
lbu $3, 0($3)
bne $3, $3, TAG406
sw $3, 0($3)
multu $3, $3
TAG406:
sw $3, 0($3)
lbu $4, 0($3)
mfhi $4
sw $3, 0($4)
TAG407:
mult $4, $4
xori $3, $4, 11
xor $2, $4, $4
blez $3, TAG408
TAG408:
lw $2, 0($2)
mult $2, $2
mthi $2
mtlo $2
TAG409:
lui $4, 6
bne $2, $4, TAG410
multu $2, $2
lbu $2, 0($4)
TAG410:
mtlo $2
bltz $2, TAG411
mtlo $2
addi $4, $2, 1
TAG411:
lui $4, 5
srl $1, $4, 9
mtlo $4
divu $1, $4
TAG412:
lui $2, 14
lui $4, 4
divu $4, $4
mtlo $1
TAG413:
multu $4, $4
subu $4, $4, $4
sw $4, 0($4)
lhu $2, 0($4)
TAG414:
sh $2, 0($2)
mfhi $2
lh $2, 0($2)
lb $4, 0($2)
TAG415:
lb $2, 0($4)
mflo $4
bgtz $4, TAG416
mfhi $3
TAG416:
mfhi $4
mthi $4
lui $1, 6
mfhi $2
TAG417:
sh $2, 0($2)
mflo $4
mtlo $4
lb $4, 0($4)
TAG418:
beq $4, $4, TAG419
sw $4, 0($4)
sb $4, 0($4)
bltz $4, TAG419
TAG419:
mthi $4
lb $3, 0($4)
bltz $3, TAG420
sh $4, 0($4)
TAG420:
sh $3, 0($3)
mflo $1
bgtz $1, TAG421
nor $1, $3, $3
TAG421:
lui $2, 4
subu $1, $1, $1
beq $1, $1, TAG422
lb $2, 0($1)
TAG422:
ori $4, $2, 9
subu $2, $2, $4
mfhi $2
mtlo $2
TAG423:
beq $2, $2, TAG424
mflo $4
sh $2, 0($4)
mflo $2
TAG424:
sw $2, 0($2)
mthi $2
sw $2, 0($2)
bne $2, $2, TAG425
TAG425:
sub $3, $2, $2
lw $3, 0($2)
mtlo $3
xori $4, $2, 4
TAG426:
lui $4, 15
lui $4, 13
slt $2, $4, $4
mthi $2
TAG427:
lb $2, 0($2)
bgtz $2, TAG428
mult $2, $2
lui $2, 10
TAG428:
mult $2, $2
lui $3, 7
lui $4, 1
sll $0, $0, 0
TAG429:
bne $4, $4, TAG430
multu $4, $4
mflo $4
xori $2, $4, 1
TAG430:
sb $2, 0($2)
multu $2, $2
lui $3, 15
mfhi $3
TAG431:
bgez $3, TAG432
multu $3, $3
blez $3, TAG432
xori $2, $3, 15
TAG432:
sb $2, 0($2)
sltiu $1, $2, 0
srav $4, $1, $2
lb $3, 0($1)
TAG433:
sb $3, 0($3)
xor $2, $3, $3
lui $1, 10
mfhi $2
TAG434:
mflo $2
and $2, $2, $2
sw $2, 0($2)
sllv $2, $2, $2
TAG435:
lui $3, 1
xor $2, $3, $2
or $3, $2, $2
mtlo $2
TAG436:
mult $3, $3
slt $1, $3, $3
addi $3, $1, 5
bne $3, $1, TAG437
TAG437:
mflo $2
beq $3, $2, TAG438
mtlo $3
blez $2, TAG438
TAG438:
mthi $2
mult $2, $2
beq $2, $2, TAG439
mthi $2
TAG439:
lbu $1, 0($2)
sb $1, 0($1)
sltu $2, $1, $1
mult $2, $2
TAG440:
lh $4, 0($2)
bgtz $4, TAG441
srl $3, $4, 14
multu $3, $2
TAG441:
sw $3, 0($3)
xori $2, $3, 7
bne $2, $2, TAG442
mtlo $2
TAG442:
bltz $2, TAG443
lui $2, 4
lui $3, 8
sra $2, $3, 2
TAG443:
mtlo $2
bgez $2, TAG444
srav $3, $2, $2
mflo $2
TAG444:
bltz $2, TAG445
mthi $2
slti $1, $2, 15
lw $4, 0($1)
TAG445:
mtlo $4
beq $4, $4, TAG446
mfhi $2
lb $1, 0($2)
TAG446:
lui $1, 6
mfhi $3
bgez $3, TAG447
sll $0, $0, 0
TAG447:
blez $2, TAG448
multu $2, $2
lui $3, 15
divu $3, $2
TAG448:
div $3, $3
bne $3, $3, TAG449
mfhi $4
lbu $1, 0($4)
TAG449:
mult $1, $1
bltz $1, TAG450
mflo $2
addu $1, $2, $2
TAG450:
lw $2, 0($1)
lui $1, 5
sll $3, $1, 11
or $1, $1, $1
TAG451:
mtlo $1
bgtz $1, TAG452
addu $4, $1, $1
lui $2, 13
TAG452:
lui $3, 12
addu $4, $3, $2
sllv $3, $3, $3
lui $3, 15
TAG453:
srlv $3, $3, $3
lui $4, 7
multu $3, $3
lui $1, 13
TAG454:
blez $1, TAG455
mfhi $4
lui $3, 15
bne $4, $4, TAG455
TAG455:
sll $0, $0, 0
sltiu $2, $3, 1
multu $2, $3
sltu $4, $2, $3
TAG456:
sb $4, 0($4)
nor $2, $4, $4
sb $4, 0($4)
sllv $1, $4, $2
TAG457:
lui $3, 8
sll $0, $0, 0
mtlo $1
divu $4, $3
TAG458:
bgtz $4, TAG459
subu $3, $4, $4
srl $2, $3, 1
mtlo $3
TAG459:
sw $2, 2($2)
bgtz $2, TAG460
mult $2, $2
sllv $1, $2, $2
TAG460:
xori $1, $1, 4
sll $0, $0, 0
bne $1, $1, TAG461
mflo $4
TAG461:
bgez $4, TAG462
sra $2, $4, 10
sw $4, 0($4)
lui $2, 2
TAG462:
mthi $2
sh $2, 0($2)
mtlo $2
mult $2, $2
TAG463:
bne $2, $2, TAG464
sw $2, 0($2)
lh $1, 0($2)
sw $1, 0($1)
TAG464:
nor $3, $1, $1
lbu $2, 0($1)
and $3, $2, $1
mflo $2
TAG465:
lui $3, 9
addiu $3, $2, 15
lbu $4, 0($3)
sw $3, 0($2)
TAG466:
bne $4, $4, TAG467
srav $3, $4, $4
srav $2, $3, $4
lui $3, 4
TAG467:
mthi $3
srav $4, $3, $3
beq $3, $3, TAG468
nor $2, $3, $4
TAG468:
mtlo $2
bgtz $2, TAG469
addiu $4, $2, 1
mthi $4
TAG469:
sll $2, $4, 14
mfhi $2
bne $2, $2, TAG470
addiu $3, $2, 4
TAG470:
bne $3, $3, TAG471
mtlo $3
mthi $3
sll $0, $0, 0
TAG471:
mfhi $1
lui $3, 9
sltu $4, $3, $1
lbu $2, 0($4)
TAG472:
lw $2, 0($2)
srav $1, $2, $2
ori $2, $2, 11
mthi $1
TAG473:
mthi $2
bne $2, $2, TAG474
lui $1, 8
bgez $2, TAG474
TAG474:
sll $0, $0, 0
lui $4, 12
bgez $1, TAG475
sltiu $3, $1, 6
TAG475:
bne $3, $3, TAG476
lh $1, 0($3)
mthi $1
lui $3, 9
TAG476:
multu $3, $3
bne $3, $3, TAG477
sll $0, $0, 0
bgtz $1, TAG477
TAG477:
mfhi $4
mult $1, $1
sb $4, 0($4)
or $4, $1, $1
TAG478:
mtlo $4
srl $2, $4, 12
sltu $3, $4, $2
beq $4, $3, TAG479
TAG479:
and $4, $3, $3
beq $3, $4, TAG480
sw $3, 0($3)
and $3, $3, $3
TAG480:
mfhi $4
mfhi $2
mfhi $2
sw $2, 0($2)
TAG481:
multu $2, $2
sll $2, $2, 15
mthi $2
mtlo $2
TAG482:
lb $3, 0($2)
mflo $2
subu $1, $2, $2
mfhi $3
TAG483:
multu $3, $3
blez $3, TAG484
sw $3, 0($3)
mfhi $4
TAG484:
beq $4, $4, TAG485
sub $1, $4, $4
slt $4, $1, $4
sh $1, 0($1)
TAG485:
bgtz $4, TAG486
lui $3, 1
lui $2, 15
bgez $4, TAG486
TAG486:
subu $4, $2, $2
mult $4, $4
mflo $2
multu $4, $2
TAG487:
mthi $2
lui $3, 13
mflo $2
mflo $3
TAG488:
bgtz $3, TAG489
sltiu $2, $3, 1
lbu $2, 0($2)
mult $2, $2
TAG489:
sllv $3, $2, $2
bne $3, $3, TAG490
sb $3, 0($2)
lb $2, 0($3)
TAG490:
bgtz $2, TAG491
mtlo $2
bltz $2, TAG491
sllv $1, $2, $2
TAG491:
lhu $1, 0($1)
lbu $1, 0($1)
multu $1, $1
or $2, $1, $1
TAG492:
lui $1, 0
bne $2, $1, TAG493
mflo $4
mfhi $1
TAG493:
beq $1, $1, TAG494
addiu $1, $1, 0
srlv $4, $1, $1
bgez $1, TAG494
TAG494:
mult $4, $4
mflo $3
mfhi $1
xori $2, $3, 4
TAG495:
mflo $4
multu $4, $4
bne $4, $4, TAG496
multu $4, $4
TAG496:
lbu $3, 0($4)
sllv $4, $4, $4
sw $3, 0($4)
beq $4, $3, TAG497
TAG497:
mfhi $1
sra $2, $4, 2
multu $2, $4
lui $2, 5
TAG498:
sltu $3, $2, $2
mtlo $2
lui $2, 12
sll $0, $0, 0
TAG499:
sll $0, $0, 0
beq $4, $4, TAG500
sh $2, 0($4)
sh $2, 0($4)
TAG500:
beq $4, $4, TAG501
mflo $3
blez $3, TAG501
lui $1, 10
TAG501:
mtlo $1
sltu $4, $1, $1
mfhi $4
lui $2, 13
TAG502:
div $2, $2
mthi $2
bltz $2, TAG503
mthi $2
TAG503:
div $2, $2
sll $1, $2, 3
beq $1, $2, TAG504
sll $0, $0, 0
TAG504:
slti $3, $2, 1
sll $0, $0, 0
mfhi $4
mflo $2
TAG505:
bne $2, $2, TAG506
mtlo $2
mfhi $2
bgtz $2, TAG506
TAG506:
addu $1, $2, $2
sll $1, $1, 12
beq $1, $1, TAG507
sb $1, 0($1)
TAG507:
multu $1, $1
mfhi $1
multu $1, $1
mthi $1
TAG508:
sb $1, 0($1)
bgez $1, TAG509
multu $1, $1
lw $1, 0($1)
TAG509:
lbu $2, 0($1)
mult $2, $1
sub $3, $1, $1
xori $2, $1, 14
TAG510:
mflo $3
or $2, $2, $3
sll $2, $2, 12
mfhi $1
TAG511:
lbu $3, 0($1)
mflo $1
mult $3, $1
lw $3, 0($1)
TAG512:
mult $3, $3
bgtz $3, TAG513
lbu $1, 0($3)
lui $2, 15
TAG513:
mtlo $2
sll $0, $0, 0
div $2, $2
mflo $4
TAG514:
addiu $4, $4, 13
subu $4, $4, $4
sltiu $1, $4, 6
sb $4, 0($1)
TAG515:
lbu $1, 0($1)
beq $1, $1, TAG516
lhu $3, 0($1)
mflo $4
TAG516:
lui $1, 6
lui $4, 2
bne $4, $4, TAG517
andi $2, $4, 14
TAG517:
bgez $2, TAG518
sw $2, 0($2)
mthi $2
xori $1, $2, 12
TAG518:
lui $2, 12
bgez $1, TAG519
lui $3, 7
lui $2, 0
TAG519:
div $2, $2
mthi $2
sll $0, $0, 0
mfhi $3
TAG520:
beq $3, $3, TAG521
srl $3, $3, 12
divu $3, $3
lb $1, 0($3)
TAG521:
sll $0, $0, 0
lui $1, 9
lui $3, 11
sltiu $2, $3, 5
TAG522:
sub $1, $2, $2
bgtz $2, TAG523
mtlo $1
mfhi $4
TAG523:
mfhi $3
lui $2, 3
sll $0, $0, 0
mthi $2
TAG524:
sll $0, $0, 0
lui $4, 1
mthi $4
beq $2, $4, TAG525
TAG525:
sll $0, $0, 0
nor $2, $4, $4
mfhi $4
mult $2, $4
TAG526:
bltz $4, TAG527
mtlo $4
lui $3, 15
sll $0, $0, 0
TAG527:
sll $0, $0, 0
sll $0, $0, 0
mtlo $4
div $3, $3
TAG528:
mfhi $1
divu $4, $4
mtlo $1
mflo $3
TAG529:
sh $3, 0($3)
mflo $1
lui $1, 5
lui $4, 0
TAG530:
bne $4, $4, TAG531
lbu $3, 0($4)
sb $3, 0($3)
sh $3, 0($3)
TAG531:
mthi $3
beq $3, $3, TAG532
ori $3, $3, 5
mflo $3
TAG532:
beq $3, $3, TAG533
multu $3, $3
addu $3, $3, $3
bne $3, $3, TAG533
TAG533:
multu $3, $3
mult $3, $3
sb $3, 0($3)
slti $4, $3, 3
TAG534:
mult $4, $4
srlv $3, $4, $4
bne $3, $3, TAG535
addiu $3, $4, 9
TAG535:
slti $4, $3, 0
mtlo $4
subu $4, $4, $3
mthi $3
TAG536:
blez $4, TAG537
sw $4, 9($4)
addu $1, $4, $4
sra $2, $4, 15
TAG537:
sltu $3, $2, $2
blez $3, TAG538
sll $2, $3, 11
mult $2, $2
TAG538:
blez $2, TAG539
mtlo $2
bne $2, $2, TAG539
addiu $4, $2, 4
TAG539:
sh $4, 9($4)
ori $1, $4, 1
divu $4, $4
bgez $4, TAG540
TAG540:
addiu $4, $1, 15
and $1, $1, $4
srlv $3, $4, $1
bne $4, $1, TAG541
TAG541:
sh $3, 0($3)
lbu $3, 0($3)
bltz $3, TAG542
multu $3, $3
TAG542:
ori $4, $3, 6
lui $1, 10
xori $3, $3, 10
lui $4, 2
TAG543:
bgtz $4, TAG544
sll $0, $0, 0
blez $4, TAG544
sh $4, 0($4)
TAG544:
beq $4, $4, TAG545
subu $3, $4, $4
slt $1, $4, $3
mflo $2
TAG545:
multu $2, $2
mult $2, $2
sh $2, 0($2)
lbu $1, 0($2)
TAG546:
multu $1, $1
mtlo $1
bgtz $1, TAG547
srav $3, $1, $1
TAG547:
mfhi $3
mult $3, $3
sh $3, 0($3)
lui $1, 7
TAG548:
lui $4, 4
mflo $1
sll $0, $0, 0
lui $2, 11
TAG549:
bgez $2, TAG550
mfhi $2
mfhi $2
or $2, $2, $2
TAG550:
multu $2, $2
mult $2, $2
mult $2, $2
bne $2, $2, TAG551
TAG551:
andi $4, $2, 0
lhu $1, 0($2)
lui $1, 6
mtlo $1
TAG552:
sll $0, $0, 0
mult $2, $1
sll $0, $0, 0
mult $2, $2
TAG553:
add $3, $3, $3
srav $1, $3, $3
sw $3, 0($1)
sb $3, 0($3)
TAG554:
mflo $2
sltu $4, $1, $2
sltiu $1, $2, 4
bgez $4, TAG555
TAG555:
addu $4, $1, $1
lbu $4, 0($1)
subu $4, $1, $1
sllv $3, $4, $4
TAG556:
sw $3, 0($3)
mthi $3
srav $2, $3, $3
mthi $2
TAG557:
beq $2, $2, TAG558
mflo $1
slt $4, $2, $2
bltz $4, TAG558
TAG558:
sw $4, 0($4)
bgtz $4, TAG559
mult $4, $4
bgtz $4, TAG559
TAG559:
addi $4, $4, 3
div $4, $4
mtlo $4
nor $1, $4, $4
TAG560:
mflo $1
mthi $1
slt $4, $1, $1
sra $3, $1, 8
TAG561:
or $2, $3, $3
subu $1, $2, $2
sh $1, 0($1)
addiu $2, $3, 13
TAG562:
sll $4, $2, 2
lbu $4, 0($2)
lui $2, 12
lui $1, 7
TAG563:
lui $4, 1
sll $0, $0, 0
mthi $1
sll $0, $0, 0
TAG564:
nor $1, $3, $3
ori $2, $1, 1
bgez $1, TAG565
mflo $2
TAG565:
srl $1, $2, 7
lbu $1, 0($2)
mfhi $1
mthi $1
TAG566:
xori $4, $1, 8
mflo $3
div $3, $1
blez $1, TAG567
TAG567:
lb $2, 0($3)
multu $2, $2
and $3, $3, $2
sb $2, 0($3)
TAG568:
mfhi $4
slt $1, $4, $4
bgez $1, TAG569
lui $1, 5
TAG569:
mflo $2
bltz $2, TAG570
lw $3, 0($2)
lui $3, 9
TAG570:
ori $3, $3, 5
sll $0, $0, 0
mthi $3
sll $0, $0, 0
TAG571:
lui $3, 4
sll $0, $0, 0
sll $1, $3, 7
ori $1, $1, 9
TAG572:
sll $3, $1, 13
mthi $1
mtlo $1
mtlo $1
TAG573:
srav $4, $3, $3
beq $3, $4, TAG574
lui $4, 1
mflo $4
TAG574:
bne $4, $4, TAG575
multu $4, $4
bgez $4, TAG575
sll $0, $0, 0
TAG575:
bne $4, $4, TAG576
mfhi $4
sb $4, 0($4)
lb $4, 0($4)
TAG576:
lui $1, 6
srav $3, $4, $4
mflo $4
sll $1, $4, 12
TAG577:
lb $3, 0($1)
mthi $1
sh $3, 0($1)
bgtz $1, TAG578
TAG578:
sltu $3, $3, $3
lui $4, 10
sltu $2, $4, $3
beq $3, $3, TAG579
TAG579:
sltu $4, $2, $2
mfhi $2
mfhi $1
mtlo $2
TAG580:
lb $1, 0($1)
beq $1, $1, TAG581
mult $1, $1
bne $1, $1, TAG581
TAG581:
sw $1, 0($1)
xor $1, $1, $1
bltz $1, TAG582
multu $1, $1
TAG582:
sb $1, 0($1)
lui $1, 1
div $1, $1
mtlo $1
TAG583:
beq $1, $1, TAG584
sll $0, $0, 0
mtlo $1
lh $1, 0($3)
TAG584:
sll $3, $1, 4
srav $3, $3, $1
andi $3, $1, 13
lhu $2, 0($3)
TAG585:
ori $2, $2, 1
srl $4, $2, 6
multu $4, $2
mtlo $2
TAG586:
bltz $4, TAG587
mult $4, $4
mflo $1
lbu $4, 0($1)
TAG587:
mult $4, $4
and $4, $4, $4
mflo $2
lui $1, 15
TAG588:
srlv $1, $1, $1
mthi $1
lui $2, 7
mfhi $2
TAG589:
mfhi $4
div $4, $2
mtlo $4
bne $4, $2, TAG590
TAG590:
sll $0, $0, 0
lui $1, 11
bne $4, $1, TAG591
sll $0, $0, 0
TAG591:
mfhi $1
sll $0, $0, 0
lh $4, 0($1)
sll $2, $4, 14
TAG592:
multu $2, $2
mult $2, $2
mtlo $2
lui $1, 5
TAG593:
beq $1, $1, TAG594
sll $0, $0, 0
xori $2, $1, 2
mfhi $2
TAG594:
lui $4, 13
bltz $2, TAG595
sll $0, $0, 0
lhu $2, 0($2)
TAG595:
mtlo $2
beq $2, $2, TAG596
mfhi $3
lhu $3, 0($3)
TAG596:
mfhi $3
blez $3, TAG597
mfhi $4
mflo $4
TAG597:
mthi $4
subu $4, $4, $4
lbu $1, 0($4)
addu $2, $1, $4
TAG598:
mflo $3
sh $2, 0($3)
mtlo $3
mthi $3
TAG599:
mult $3, $3
mthi $3
lui $1, 8
mult $1, $3
TAG600:
mtlo $1
lui $4, 8
mflo $3
bgtz $4, TAG601
TAG601:
sll $0, $0, 0
lui $1, 2
bne $3, $1, TAG602
ori $1, $3, 13
TAG602:
sll $0, $0, 0
sb $1, 0($2)
lui $4, 3
mflo $2
TAG603:
subu $1, $2, $2
bgez $2, TAG604
divu $2, $2
xori $3, $2, 6
TAG604:
mflo $2
mthi $3
lui $4, 14
mtlo $4
TAG605:
mthi $4
mthi $4
divu $4, $4
lui $4, 15
TAG606:
lui $3, 9
mtlo $3
sll $0, $0, 0
blez $3, TAG607
TAG607:
sll $0, $0, 0
subu $4, $3, $3
mthi $3
bgtz $4, TAG608
TAG608:
sb $4, 0($4)
multu $4, $4
ori $3, $4, 10
multu $3, $3
TAG609:
lui $1, 4
lui $4, 8
bgtz $1, TAG610
sh $1, 0($3)
TAG610:
bltz $4, TAG611
mflo $4
sb $4, 0($4)
sltiu $1, $4, 2
TAG611:
sra $3, $1, 7
mult $1, $1
bne $1, $3, TAG612
mtlo $1
TAG612:
mthi $3
lui $2, 4
mtlo $2
mthi $3
TAG613:
beq $2, $2, TAG614
div $2, $2
sb $2, 0($2)
mfhi $3
TAG614:
multu $3, $3
mult $3, $3
mfhi $2
multu $3, $2
TAG615:
sltiu $2, $2, 9
multu $2, $2
sra $3, $2, 6
bne $2, $3, TAG616
TAG616:
sw $3, 0($3)
lui $3, 1
bltz $3, TAG617
div $3, $3
TAG617:
bltz $3, TAG618
mfhi $1
bne $3, $3, TAG618
ori $2, $3, 12
TAG618:
lui $3, 10
bgez $2, TAG619
divu $3, $3
mthi $3
TAG619:
bgtz $3, TAG620
and $3, $3, $3
bne $3, $3, TAG620
mflo $2
TAG620:
ori $1, $2, 11
mtlo $1
subu $2, $2, $1
lb $1, 3($2)
TAG621:
blez $1, TAG622
mfhi $3
div $3, $1
subu $1, $1, $1
TAG622:
mult $1, $1
addi $2, $1, 14
mfhi $3
mflo $1
TAG623:
ori $3, $1, 2
mthi $1
sllv $1, $1, $1
multu $1, $1
TAG624:
mtlo $1
bgez $1, TAG625
sltu $2, $1, $1
addiu $3, $1, 2
TAG625:
div $3, $3
addiu $4, $3, 8
mfhi $2
multu $2, $2
TAG626:
lui $2, 12
lui $1, 8
or $4, $2, $2
mthi $2
TAG627:
lui $2, 15
sll $0, $0, 0
bne $4, $4, TAG628
srlv $4, $4, $2
TAG628:
bgez $4, TAG629
mfhi $2
lui $4, 12
slti $2, $4, 13
TAG629:
mthi $2
sll $0, $0, 0
divu $2, $2
sll $0, $0, 0
TAG630:
beq $2, $2, TAG631
sll $0, $0, 0
mfhi $1
addu $4, $2, $2
TAG631:
blez $4, TAG632
lui $4, 5
sll $0, $0, 0
xori $3, $4, 3
TAG632:
mfhi $2
mthi $3
slt $2, $3, $2
sll $0, $0, 0
TAG633:
sll $2, $2, 7
mthi $2
mflo $4
lbu $1, 0($4)
TAG634:
beq $1, $1, TAG635
sw $1, 0($1)
sb $1, 0($1)
lbu $1, 0($1)
TAG635:
mfhi $1
mtlo $1
sb $1, 0($1)
lui $3, 15
TAG636:
lui $1, 7
and $2, $3, $1
mtlo $1
divu $1, $2
TAG637:
bgtz $2, TAG638
lui $3, 12
mfhi $2
sb $3, 0($3)
TAG638:
lui $3, 4
srav $4, $2, $3
nor $1, $4, $2
sll $0, $0, 0
TAG639:
srl $1, $1, 15
div $1, $1
nor $2, $1, $1
sll $0, $0, 0
TAG640:
and $1, $2, $2
sra $4, $1, 3
div $1, $1
sll $0, $0, 0
TAG641:
mflo $2
bne $4, $2, TAG642
mflo $4
div $4, $4
TAG642:
bne $4, $4, TAG643
div $4, $4
lui $4, 8
beq $4, $4, TAG643
TAG643:
lui $1, 13
bltz $1, TAG644
lui $4, 10
mflo $4
TAG644:
bgez $4, TAG645
lb $3, 0($4)
multu $3, $4
lbu $3, 0($3)
TAG645:
sw $3, 0($3)
add $2, $3, $3
mtlo $3
bltz $2, TAG646
TAG646:
lui $1, 8
sub $2, $2, $2
subu $1, $2, $2
mthi $1
TAG647:
sh $1, 0($1)
mthi $1
sb $1, 0($1)
mult $1, $1
TAG648:
mult $1, $1
mthi $1
multu $1, $1
mthi $1
TAG649:
lui $2, 14
lui $4, 11
bne $1, $4, TAG650
srav $3, $2, $4
TAG650:
divu $3, $3
addiu $2, $3, 0
sra $1, $3, 0
bgez $2, TAG651
TAG651:
mflo $4
and $4, $4, $4
bne $1, $4, TAG652
mfhi $1
TAG652:
mthi $1
lhu $4, 0($1)
lui $4, 0
srlv $2, $4, $4
TAG653:
sb $2, 0($2)
bltz $2, TAG654
sw $2, 0($2)
lw $3, 0($2)
TAG654:
mfhi $1
sw $1, 0($1)
mthi $3
lbu $2, 0($1)
TAG655:
lui $3, 15
bne $2, $3, TAG656
mthi $3
lhu $1, 0($2)
TAG656:
bne $1, $1, TAG657
lw $2, 0($1)
sh $1, 0($1)
mfhi $4
TAG657:
sltu $2, $4, $4
addu $3, $4, $4
addiu $3, $4, 7
bgez $3, TAG658
TAG658:
sll $0, $0, 0
subu $3, $3, $3
addi $1, $3, 2
sltiu $4, $3, 15
TAG659:
lbu $3, 0($4)
mult $3, $4
addiu $2, $4, 6
addiu $1, $2, 4
TAG660:
srav $1, $1, $1
mthi $1
or $2, $1, $1
blez $1, TAG661
TAG661:
lui $3, 3
mthi $3
mflo $4
bne $2, $3, TAG662
TAG662:
mtlo $4
mfhi $4
bne $4, $4, TAG663
multu $4, $4
TAG663:
and $4, $4, $4
lui $2, 12
and $4, $4, $4
sll $0, $0, 0
TAG664:
mtlo $4
sll $0, $0, 0
divu $4, $4
slti $1, $4, 4
TAG665:
blez $1, TAG666
xori $2, $1, 12
lw $1, 0($2)
beq $2, $1, TAG666
TAG666:
mthi $1
sb $1, 0($1)
addi $3, $1, 4
bltz $3, TAG667
TAG667:
divu $3, $3
blez $3, TAG668
sll $1, $3, 1
lh $3, 0($3)
TAG668:
lui $2, 9
lui $4, 2
bgez $4, TAG669
xori $1, $3, 8
TAG669:
bne $1, $1, TAG670
divu $1, $1
mthi $1
bltz $1, TAG670
TAG670:
multu $1, $1
divu $1, $1
beq $1, $1, TAG671
lui $1, 11
TAG671:
sll $0, $0, 0
sll $0, $0, 0
mthi $1
subu $1, $1, $1
TAG672:
xori $3, $1, 10
beq $3, $1, TAG673
mtlo $3
div $3, $3
TAG673:
sb $3, 0($3)
beq $3, $3, TAG674
srlv $1, $3, $3
bltz $3, TAG674
TAG674:
multu $1, $1
lb $1, 0($1)
lui $3, 2
bne $1, $3, TAG675
TAG675:
mflo $4
nor $3, $4, $4
sb $3, 0($4)
mfhi $2
TAG676:
lbu $1, 0($2)
blez $1, TAG677
lui $3, 14
mult $3, $3
TAG677:
mflo $3
sw $3, 0($3)
lb $4, 0($3)
mthi $3
TAG678:
beq $4, $4, TAG679
sh $4, 0($4)
slti $2, $4, 6
srav $4, $2, $2
TAG679:
or $4, $4, $4
bltz $4, TAG680
mflo $4
blez $4, TAG680
TAG680:
lw $1, 0($4)
beq $4, $4, TAG681
mtlo $1
sh $1, 0($1)
TAG681:
bltz $1, TAG682
multu $1, $1
mult $1, $1
mthi $1
TAG682:
blez $1, TAG683
sw $1, 0($1)
srl $3, $1, 15
mult $3, $1
TAG683:
mflo $2
beq $3, $3, TAG684
sw $2, 0($2)
beq $2, $2, TAG684
TAG684:
lhu $3, 0($2)
beq $2, $3, TAG685
multu $2, $2
div $3, $3
TAG685:
mthi $3
lb $3, 0($3)
mthi $3
bne $3, $3, TAG686
TAG686:
mtlo $3
lui $3, 14
ori $1, $3, 10
mfhi $1
TAG687:
mflo $1
beq $1, $1, TAG688
sb $1, 0($1)
lui $2, 8
TAG688:
bgez $2, TAG689
mult $2, $2
bne $2, $2, TAG689
sltu $4, $2, $2
TAG689:
sh $4, 0($4)
slt $1, $4, $4
sb $1, 0($1)
beq $1, $1, TAG690
TAG690:
sb $1, 0($1)
and $3, $1, $1
multu $3, $1
bgtz $3, TAG691
TAG691:
multu $3, $3
srav $4, $3, $3
lbu $3, 0($3)
bne $3, $3, TAG692
TAG692:
addi $2, $3, 6
multu $2, $3
lb $1, 0($2)
mfhi $4
TAG693:
sllv $2, $4, $4
ori $1, $4, 8
divu $1, $1
andi $4, $4, 13
TAG694:
srlv $3, $4, $4
bltz $4, TAG695
mflo $1
div $3, $1
TAG695:
bne $1, $1, TAG696
lb $1, 0($1)
lui $1, 7
sll $0, $0, 0
TAG696:
sll $0, $0, 0
bgtz $1, TAG697
sll $0, $0, 0
bgtz $1, TAG697
TAG697:
mult $1, $1
bltz $1, TAG698
slti $2, $1, 0
sll $0, $0, 0
TAG698:
bltz $4, TAG699
lbu $2, 0($4)
mtlo $4
mtlo $4
TAG699:
mthi $2
mult $2, $2
lb $1, 0($2)
lhu $2, 0($2)
TAG700:
mflo $3
lui $4, 4
or $4, $3, $2
mflo $4
TAG701:
mthi $4
beq $4, $4, TAG702
ori $2, $4, 11
sltu $3, $2, $2
TAG702:
bltz $3, TAG703
or $4, $3, $3
lui $4, 12
sltiu $2, $3, 7
TAG703:
bne $2, $2, TAG704
mtlo $2
ori $2, $2, 13
sb $2, 0($2)
TAG704:
bltz $2, TAG705
mtlo $2
mult $2, $2
lui $2, 2
TAG705:
div $2, $2
mtlo $2
addiu $1, $2, 13
subu $2, $1, $1
TAG706:
mthi $2
multu $2, $2
ori $4, $2, 0
mflo $1
TAG707:
lui $1, 13
mtlo $1
mflo $1
sll $0, $0, 0
TAG708:
lb $1, 0($3)
bltz $3, TAG709
and $1, $1, $3
sltiu $3, $1, 15
TAG709:
sllv $2, $3, $3
srav $2, $3, $2
andi $4, $3, 10
nor $4, $2, $4
TAG710:
sllv $4, $4, $4
and $3, $4, $4
bgtz $4, TAG711
lui $2, 14
TAG711:
mflo $1
mtlo $2
sll $0, $0, 0
beq $2, $2, TAG712
TAG712:
mflo $2
beq $2, $2, TAG713
sll $0, $0, 0
sra $2, $2, 4
TAG713:
bltz $2, TAG714
mflo $4
lui $2, 14
bltz $4, TAG714
TAG714:
lui $2, 9
mthi $2
lui $2, 7
lui $4, 1
TAG715:
andi $2, $4, 5
mthi $2
srav $3, $4, $2
mult $2, $2
TAG716:
srlv $3, $3, $3
mtlo $3
mfhi $3
beq $3, $3, TAG717
TAG717:
lui $2, 8
mtlo $3
bltz $2, TAG718
sll $0, $0, 0
TAG718:
sll $0, $0, 0
sra $4, $1, 12
bgtz $2, TAG719
mfhi $3
TAG719:
sh $3, 0($3)
lui $2, 10
mflo $4
mult $4, $3
TAG720:
sub $4, $4, $4
mtlo $4
beq $4, $4, TAG721
mult $4, $4
TAG721:
sw $4, 0($4)
beq $4, $4, TAG722
mult $4, $4
bltz $4, TAG722
TAG722:
mflo $4
mflo $3
lbu $1, 0($4)
slt $4, $3, $3
TAG723:
mfhi $4
beq $4, $4, TAG724
sltiu $1, $4, 14
srlv $2, $4, $4
TAG724:
lui $2, 7
mflo $4
bltz $2, TAG725
srl $4, $2, 1
TAG725:
bne $4, $4, TAG726
subu $2, $4, $4
slt $1, $4, $2
lui $4, 7
TAG726:
and $4, $4, $4
bne $4, $4, TAG727
multu $4, $4
lui $4, 10
TAG727:
sll $4, $4, 4
srl $1, $4, 15
multu $4, $4
or $3, $1, $1
TAG728:
sw $3, -320($3)
beq $3, $3, TAG729
srl $2, $3, 12
bgez $2, TAG729
TAG729:
sh $2, 0($2)
sh $2, 0($2)
sw $2, 0($2)
mthi $2
TAG730:
mfhi $4
mflo $4
bgtz $4, TAG731
lb $2, 0($4)
TAG731:
srav $1, $2, $2
bne $2, $1, TAG732
ori $4, $2, 11
beq $4, $2, TAG732
TAG732:
lui $2, 7
sll $0, $0, 0
beq $4, $3, TAG733
sll $0, $0, 0
TAG733:
bne $2, $2, TAG734
mtlo $2
mthi $2
beq $2, $2, TAG734
TAG734:
addiu $1, $2, 0
mult $2, $2
mthi $1
sll $0, $0, 0
TAG735:
mflo $3
subu $4, $3, $3
addiu $4, $3, 3
srav $1, $1, $4
TAG736:
mfhi $3
sll $0, $0, 0
sll $0, $0, 0
sll $0, $0, 0
TAG737:
multu $4, $4
mthi $4
mfhi $3
bgez $4, TAG738
TAG738:
sb $3, 0($3)
sb $3, 0($3)
andi $3, $3, 8
srl $2, $3, 9
TAG739:
bltz $2, TAG740
sh $2, 0($2)
sllv $4, $2, $2
beq $4, $2, TAG740
TAG740:
subu $1, $4, $4
sw $1, 0($4)
multu $4, $1
lhu $2, 0($4)
TAG741:
mflo $1
blez $1, TAG742
mflo $4
bne $1, $4, TAG742
TAG742:
nor $3, $4, $4
sh $4, 0($4)
mtlo $3
divu $4, $3
TAG743:
sh $3, 1($3)
bltz $3, TAG744
sra $3, $3, 4
beq $3, $3, TAG744
TAG744:
sll $0, $0, 0
lhu $2, 0($4)
mfhi $2
sw $3, 0($2)
TAG745:
multu $2, $2
bgez $2, TAG746
mthi $2
lhu $1, 0($2)
TAG746:
lbu $4, 0($1)
bgez $4, TAG747
mflo $2
lhu $1, 0($4)
TAG747:
lui $1, 13
mflo $3
lui $2, 4
lui $2, 13
TAG748:
mthi $2
xor $1, $2, $2
addiu $1, $1, 2
mtlo $2
TAG749:
slti $1, $1, 6
sb $1, 0($1)
mtlo $1
mtlo $1
TAG750:
nop
nop
test_end:
beq $0, $0, test_end
nop |
; A267482: Triangle of coefficients of Gaussian polynomials [2n+1,1]_q represented as finite sum of terms (1+q^2)^k*q^(g-k), where k = 0,1,...,g with g=n.
; Submitted by Jon Maiga
; 1,1,1,-1,1,1,-1,-2,1,1,1,-2,-3,1,1,1,3,-3,-4,1,1,-1,3,6,-4,-5,1,1,-1,-4,6,10,-5,-6,1,1,1,-4,-10,10,15,-6,-7,1,1,1,5,-10,-20,15,21,-7,-8,1,1,-1,5,15,-20,-35,21,28,-8,-9,1,1,-1,-6,15,35,-35,-56,28,36,-9,-10,1,1,1,-6,-21,35,70,-56,-84,36,45,-10,-11,1,1,1,7,-21,-56,70,126,-84,-120,45
mov $1,$0
seq $0,2262 ; Triangle read by rows: T(n,k), 0 <= k <= n, in which row n lists the first n+1 nonnegative integers.
add $0,1
seq $1,2024 ; n appears n times; a(n) = floor(sqrt(2n) + 1/2).
sub $1,$0
mul $0,-1
div $1,2
bin $0,$1
|
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "lite/operators/read_from_array_op.h"
#include "lite/core/op_registry.h"
namespace paddle {
namespace lite {
namespace operators {
bool ReadFromArrayOp::CheckShape() const { return true; }
bool ReadFromArrayOp::InferShape() const {
auto in_dims = (*param_.X)[0].dims();
param_.Out->Resize(in_dims);
return true;
}
bool ReadFromArrayOp::AttachImpl(const cpp::OpDesc &opdesc,
lite::Scope *scope) {
auto in = opdesc.Input("X").front();
param_.X = scope->FindVar(in)->GetMutable<std::vector<lite::Tensor>>();
param_.I =
scope->FindVar(opdesc.Input("I").front())->GetMutable<lite::Tensor>();
param_.Out =
scope->FindVar(opdesc.Output("Out").front())->GetMutable<lite::Tensor>();
return true;
}
} // namespace operators
} // namespace lite
} // namespace paddle
REGISTER_LITE_OP(read_from_array, paddle::lite::operators::ReadFromArrayOp);
|
; A145362: Lower triangular array, called S1hat(-1), related to partition number array A145361.
; Submitted by Jamie Morken(w3)
; 1,1,1,0,1,1,0,1,1,1,0,0,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1
seq $0,127948 ; Triangle, A004736 * A127899.
add $0,1
lpb $0
mul $0,$1
mov $2,1
lpe
mov $0,$2
|
_wc: file format elf32-i386
Disassembly of section .text:
00000000 <wc>:
char buf[512];
void
wc(int fd, char *name)
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 28 sub $0x28,%esp
int i, n;
int l, w, c, inword;
l = w = c = 0;
6: c7 45 e8 00 00 00 00 movl $0x0,-0x18(%ebp)
d: 8b 45 e8 mov -0x18(%ebp),%eax
10: 89 45 ec mov %eax,-0x14(%ebp)
13: 8b 45 ec mov -0x14(%ebp),%eax
16: 89 45 f0 mov %eax,-0x10(%ebp)
inword = 0;
19: c7 45 e4 00 00 00 00 movl $0x0,-0x1c(%ebp)
while((n = read(fd, buf, sizeof(buf))) > 0){
20: eb 69 jmp 8b <wc+0x8b>
for(i=0; i<n; i++){
22: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
29: eb 58 jmp 83 <wc+0x83>
c++;
2b: 83 45 e8 01 addl $0x1,-0x18(%ebp)
if(buf[i] == '\n')
2f: 8b 45 f4 mov -0xc(%ebp),%eax
32: 05 20 0e 00 00 add $0xe20,%eax
37: 0f b6 00 movzbl (%eax),%eax
3a: 3c 0a cmp $0xa,%al
3c: 75 04 jne 42 <wc+0x42>
l++;
3e: 83 45 f0 01 addl $0x1,-0x10(%ebp)
if(strchr(" \r\t\n\v", buf[i]))
42: 8b 45 f4 mov -0xc(%ebp),%eax
45: 05 20 0e 00 00 add $0xe20,%eax
4a: 0f b6 00 movzbl (%eax),%eax
4d: 0f be c0 movsbl %al,%eax
50: 83 ec 08 sub $0x8,%esp
53: 50 push %eax
54: 68 dc 0a 00 00 push $0xadc
59: e8 35 02 00 00 call 293 <strchr>
5e: 83 c4 10 add $0x10,%esp
61: 85 c0 test %eax,%eax
63: 74 09 je 6e <wc+0x6e>
inword = 0;
65: c7 45 e4 00 00 00 00 movl $0x0,-0x1c(%ebp)
6c: eb 11 jmp 7f <wc+0x7f>
else if(!inword){
6e: 83 7d e4 00 cmpl $0x0,-0x1c(%ebp)
72: 75 0b jne 7f <wc+0x7f>
w++;
74: 83 45 ec 01 addl $0x1,-0x14(%ebp)
inword = 1;
78: c7 45 e4 01 00 00 00 movl $0x1,-0x1c(%ebp)
int l, w, c, inword;
l = w = c = 0;
inword = 0;
while((n = read(fd, buf, sizeof(buf))) > 0){
for(i=0; i<n; i++){
7f: 83 45 f4 01 addl $0x1,-0xc(%ebp)
83: 8b 45 f4 mov -0xc(%ebp),%eax
86: 3b 45 e0 cmp -0x20(%ebp),%eax
89: 7c a0 jl 2b <wc+0x2b>
int i, n;
int l, w, c, inword;
l = w = c = 0;
inword = 0;
while((n = read(fd, buf, sizeof(buf))) > 0){
8b: 83 ec 04 sub $0x4,%esp
8e: 68 00 02 00 00 push $0x200
93: 68 20 0e 00 00 push $0xe20
98: ff 75 08 pushl 0x8(%ebp)
9b: e8 26 05 00 00 call 5c6 <read>
a0: 83 c4 10 add $0x10,%esp
a3: 89 45 e0 mov %eax,-0x20(%ebp)
a6: 83 7d e0 00 cmpl $0x0,-0x20(%ebp)
aa: 0f 8f 72 ff ff ff jg 22 <wc+0x22>
w++;
inword = 1;
}
}
}
if(n < 0){
b0: 83 7d e0 00 cmpl $0x0,-0x20(%ebp)
b4: 79 17 jns cd <wc+0xcd>
printf(1, "wc: read error\n");
b6: 83 ec 08 sub $0x8,%esp
b9: 68 e2 0a 00 00 push $0xae2
be: 6a 01 push $0x1
c0: e8 60 06 00 00 call 725 <printf>
c5: 83 c4 10 add $0x10,%esp
exit();
c8: e8 e1 04 00 00 call 5ae <exit>
}
printf(1, "%d %d %d %s\n", l, w, c, name);
cd: 83 ec 08 sub $0x8,%esp
d0: ff 75 0c pushl 0xc(%ebp)
d3: ff 75 e8 pushl -0x18(%ebp)
d6: ff 75 ec pushl -0x14(%ebp)
d9: ff 75 f0 pushl -0x10(%ebp)
dc: 68 f2 0a 00 00 push $0xaf2
e1: 6a 01 push $0x1
e3: e8 3d 06 00 00 call 725 <printf>
e8: 83 c4 20 add $0x20,%esp
}
eb: 90 nop
ec: c9 leave
ed: c3 ret
000000ee <main>:
int
main(int argc, char *argv[])
{
ee: 8d 4c 24 04 lea 0x4(%esp),%ecx
f2: 83 e4 f0 and $0xfffffff0,%esp
f5: ff 71 fc pushl -0x4(%ecx)
f8: 55 push %ebp
f9: 89 e5 mov %esp,%ebp
fb: 53 push %ebx
fc: 51 push %ecx
fd: 83 ec 10 sub $0x10,%esp
100: 89 cb mov %ecx,%ebx
int fd, i;
if(argc <= 1){
102: 83 3b 01 cmpl $0x1,(%ebx)
105: 7f 17 jg 11e <main+0x30>
wc(0, "");
107: 83 ec 08 sub $0x8,%esp
10a: 68 ff 0a 00 00 push $0xaff
10f: 6a 00 push $0x0
111: e8 ea fe ff ff call 0 <wc>
116: 83 c4 10 add $0x10,%esp
exit();
119: e8 90 04 00 00 call 5ae <exit>
}
for(i = 1; i < argc; i++){
11e: c7 45 f4 01 00 00 00 movl $0x1,-0xc(%ebp)
125: e9 83 00 00 00 jmp 1ad <main+0xbf>
if((fd = open(argv[i], 0)) < 0){
12a: 8b 45 f4 mov -0xc(%ebp),%eax
12d: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx
134: 8b 43 04 mov 0x4(%ebx),%eax
137: 01 d0 add %edx,%eax
139: 8b 00 mov (%eax),%eax
13b: 83 ec 08 sub $0x8,%esp
13e: 6a 00 push $0x0
140: 50 push %eax
141: e8 a8 04 00 00 call 5ee <open>
146: 83 c4 10 add $0x10,%esp
149: 89 45 f0 mov %eax,-0x10(%ebp)
14c: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
150: 79 29 jns 17b <main+0x8d>
printf(1, "wc: cannot open %s\n", argv[i]);
152: 8b 45 f4 mov -0xc(%ebp),%eax
155: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx
15c: 8b 43 04 mov 0x4(%ebx),%eax
15f: 01 d0 add %edx,%eax
161: 8b 00 mov (%eax),%eax
163: 83 ec 04 sub $0x4,%esp
166: 50 push %eax
167: 68 00 0b 00 00 push $0xb00
16c: 6a 01 push $0x1
16e: e8 b2 05 00 00 call 725 <printf>
173: 83 c4 10 add $0x10,%esp
exit();
176: e8 33 04 00 00 call 5ae <exit>
}
wc(fd, argv[i]);
17b: 8b 45 f4 mov -0xc(%ebp),%eax
17e: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx
185: 8b 43 04 mov 0x4(%ebx),%eax
188: 01 d0 add %edx,%eax
18a: 8b 00 mov (%eax),%eax
18c: 83 ec 08 sub $0x8,%esp
18f: 50 push %eax
190: ff 75 f0 pushl -0x10(%ebp)
193: e8 68 fe ff ff call 0 <wc>
198: 83 c4 10 add $0x10,%esp
close(fd);
19b: 83 ec 0c sub $0xc,%esp
19e: ff 75 f0 pushl -0x10(%ebp)
1a1: e8 30 04 00 00 call 5d6 <close>
1a6: 83 c4 10 add $0x10,%esp
if(argc <= 1){
wc(0, "");
exit();
}
for(i = 1; i < argc; i++){
1a9: 83 45 f4 01 addl $0x1,-0xc(%ebp)
1ad: 8b 45 f4 mov -0xc(%ebp),%eax
1b0: 3b 03 cmp (%ebx),%eax
1b2: 0f 8c 72 ff ff ff jl 12a <main+0x3c>
exit();
}
wc(fd, argv[i]);
close(fd);
}
exit();
1b8: e8 f1 03 00 00 call 5ae <exit>
000001bd <stosb>:
"cc");
}
static inline void
stosb(void *addr, int data, int cnt)
{
1bd: 55 push %ebp
1be: 89 e5 mov %esp,%ebp
1c0: 57 push %edi
1c1: 53 push %ebx
asm volatile("cld; rep stosb" :
1c2: 8b 4d 08 mov 0x8(%ebp),%ecx
1c5: 8b 55 10 mov 0x10(%ebp),%edx
1c8: 8b 45 0c mov 0xc(%ebp),%eax
1cb: 89 cb mov %ecx,%ebx
1cd: 89 df mov %ebx,%edi
1cf: 89 d1 mov %edx,%ecx
1d1: fc cld
1d2: f3 aa rep stos %al,%es:(%edi)
1d4: 89 ca mov %ecx,%edx
1d6: 89 fb mov %edi,%ebx
1d8: 89 5d 08 mov %ebx,0x8(%ebp)
1db: 89 55 10 mov %edx,0x10(%ebp)
"=D" (addr), "=c" (cnt) :
"0" (addr), "1" (cnt), "a" (data) :
"memory", "cc");
}
1de: 90 nop
1df: 5b pop %ebx
1e0: 5f pop %edi
1e1: 5d pop %ebp
1e2: c3 ret
000001e3 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
1e3: 55 push %ebp
1e4: 89 e5 mov %esp,%ebp
1e6: 83 ec 10 sub $0x10,%esp
char *os;
os = s;
1e9: 8b 45 08 mov 0x8(%ebp),%eax
1ec: 89 45 fc mov %eax,-0x4(%ebp)
while((*s++ = *t++) != 0)
1ef: 90 nop
1f0: 8b 45 08 mov 0x8(%ebp),%eax
1f3: 8d 50 01 lea 0x1(%eax),%edx
1f6: 89 55 08 mov %edx,0x8(%ebp)
1f9: 8b 55 0c mov 0xc(%ebp),%edx
1fc: 8d 4a 01 lea 0x1(%edx),%ecx
1ff: 89 4d 0c mov %ecx,0xc(%ebp)
202: 0f b6 12 movzbl (%edx),%edx
205: 88 10 mov %dl,(%eax)
207: 0f b6 00 movzbl (%eax),%eax
20a: 84 c0 test %al,%al
20c: 75 e2 jne 1f0 <strcpy+0xd>
;
return os;
20e: 8b 45 fc mov -0x4(%ebp),%eax
}
211: c9 leave
212: c3 ret
00000213 <strcmp>:
int
strcmp(const char *p, const char *q)
{
213: 55 push %ebp
214: 89 e5 mov %esp,%ebp
while(*p && *p == *q)
216: eb 08 jmp 220 <strcmp+0xd>
p++, q++;
218: 83 45 08 01 addl $0x1,0x8(%ebp)
21c: 83 45 0c 01 addl $0x1,0xc(%ebp)
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
220: 8b 45 08 mov 0x8(%ebp),%eax
223: 0f b6 00 movzbl (%eax),%eax
226: 84 c0 test %al,%al
228: 74 10 je 23a <strcmp+0x27>
22a: 8b 45 08 mov 0x8(%ebp),%eax
22d: 0f b6 10 movzbl (%eax),%edx
230: 8b 45 0c mov 0xc(%ebp),%eax
233: 0f b6 00 movzbl (%eax),%eax
236: 38 c2 cmp %al,%dl
238: 74 de je 218 <strcmp+0x5>
p++, q++;
return (uchar)*p - (uchar)*q;
23a: 8b 45 08 mov 0x8(%ebp),%eax
23d: 0f b6 00 movzbl (%eax),%eax
240: 0f b6 d0 movzbl %al,%edx
243: 8b 45 0c mov 0xc(%ebp),%eax
246: 0f b6 00 movzbl (%eax),%eax
249: 0f b6 c0 movzbl %al,%eax
24c: 29 c2 sub %eax,%edx
24e: 89 d0 mov %edx,%eax
}
250: 5d pop %ebp
251: c3 ret
00000252 <strlen>:
uint
strlen(char *s)
{
252: 55 push %ebp
253: 89 e5 mov %esp,%ebp
255: 83 ec 10 sub $0x10,%esp
int n;
for(n = 0; s[n]; n++)
258: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
25f: eb 04 jmp 265 <strlen+0x13>
261: 83 45 fc 01 addl $0x1,-0x4(%ebp)
265: 8b 55 fc mov -0x4(%ebp),%edx
268: 8b 45 08 mov 0x8(%ebp),%eax
26b: 01 d0 add %edx,%eax
26d: 0f b6 00 movzbl (%eax),%eax
270: 84 c0 test %al,%al
272: 75 ed jne 261 <strlen+0xf>
;
return n;
274: 8b 45 fc mov -0x4(%ebp),%eax
}
277: c9 leave
278: c3 ret
00000279 <memset>:
void*
memset(void *dst, int c, uint n)
{
279: 55 push %ebp
27a: 89 e5 mov %esp,%ebp
stosb(dst, c, n);
27c: 8b 45 10 mov 0x10(%ebp),%eax
27f: 50 push %eax
280: ff 75 0c pushl 0xc(%ebp)
283: ff 75 08 pushl 0x8(%ebp)
286: e8 32 ff ff ff call 1bd <stosb>
28b: 83 c4 0c add $0xc,%esp
return dst;
28e: 8b 45 08 mov 0x8(%ebp),%eax
}
291: c9 leave
292: c3 ret
00000293 <strchr>:
char*
strchr(const char *s, char c)
{
293: 55 push %ebp
294: 89 e5 mov %esp,%ebp
296: 83 ec 04 sub $0x4,%esp
299: 8b 45 0c mov 0xc(%ebp),%eax
29c: 88 45 fc mov %al,-0x4(%ebp)
for(; *s; s++)
29f: eb 14 jmp 2b5 <strchr+0x22>
if(*s == c)
2a1: 8b 45 08 mov 0x8(%ebp),%eax
2a4: 0f b6 00 movzbl (%eax),%eax
2a7: 3a 45 fc cmp -0x4(%ebp),%al
2aa: 75 05 jne 2b1 <strchr+0x1e>
return (char*)s;
2ac: 8b 45 08 mov 0x8(%ebp),%eax
2af: eb 13 jmp 2c4 <strchr+0x31>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
2b1: 83 45 08 01 addl $0x1,0x8(%ebp)
2b5: 8b 45 08 mov 0x8(%ebp),%eax
2b8: 0f b6 00 movzbl (%eax),%eax
2bb: 84 c0 test %al,%al
2bd: 75 e2 jne 2a1 <strchr+0xe>
if(*s == c)
return (char*)s;
return 0;
2bf: b8 00 00 00 00 mov $0x0,%eax
}
2c4: c9 leave
2c5: c3 ret
000002c6 <gets>:
char*
gets(char *buf, int max)
{
2c6: 55 push %ebp
2c7: 89 e5 mov %esp,%ebp
2c9: 83 ec 18 sub $0x18,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
2cc: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
2d3: eb 42 jmp 317 <gets+0x51>
cc = read(0, &c, 1);
2d5: 83 ec 04 sub $0x4,%esp
2d8: 6a 01 push $0x1
2da: 8d 45 ef lea -0x11(%ebp),%eax
2dd: 50 push %eax
2de: 6a 00 push $0x0
2e0: e8 e1 02 00 00 call 5c6 <read>
2e5: 83 c4 10 add $0x10,%esp
2e8: 89 45 f0 mov %eax,-0x10(%ebp)
if(cc < 1)
2eb: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
2ef: 7e 33 jle 324 <gets+0x5e>
break;
buf[i++] = c;
2f1: 8b 45 f4 mov -0xc(%ebp),%eax
2f4: 8d 50 01 lea 0x1(%eax),%edx
2f7: 89 55 f4 mov %edx,-0xc(%ebp)
2fa: 89 c2 mov %eax,%edx
2fc: 8b 45 08 mov 0x8(%ebp),%eax
2ff: 01 c2 add %eax,%edx
301: 0f b6 45 ef movzbl -0x11(%ebp),%eax
305: 88 02 mov %al,(%edx)
if(c == '\n' || c == '\r')
307: 0f b6 45 ef movzbl -0x11(%ebp),%eax
30b: 3c 0a cmp $0xa,%al
30d: 74 16 je 325 <gets+0x5f>
30f: 0f b6 45 ef movzbl -0x11(%ebp),%eax
313: 3c 0d cmp $0xd,%al
315: 74 0e je 325 <gets+0x5f>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
317: 8b 45 f4 mov -0xc(%ebp),%eax
31a: 83 c0 01 add $0x1,%eax
31d: 3b 45 0c cmp 0xc(%ebp),%eax
320: 7c b3 jl 2d5 <gets+0xf>
322: eb 01 jmp 325 <gets+0x5f>
cc = read(0, &c, 1);
if(cc < 1)
break;
324: 90 nop
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
325: 8b 55 f4 mov -0xc(%ebp),%edx
328: 8b 45 08 mov 0x8(%ebp),%eax
32b: 01 d0 add %edx,%eax
32d: c6 00 00 movb $0x0,(%eax)
return buf;
330: 8b 45 08 mov 0x8(%ebp),%eax
}
333: c9 leave
334: c3 ret
00000335 <stat>:
int
stat(char *n, struct stat *st)
{
335: 55 push %ebp
336: 89 e5 mov %esp,%ebp
338: 83 ec 18 sub $0x18,%esp
int fd;
int r;
fd = open(n, O_RDONLY);
33b: 83 ec 08 sub $0x8,%esp
33e: 6a 00 push $0x0
340: ff 75 08 pushl 0x8(%ebp)
343: e8 a6 02 00 00 call 5ee <open>
348: 83 c4 10 add $0x10,%esp
34b: 89 45 f4 mov %eax,-0xc(%ebp)
if(fd < 0)
34e: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
352: 79 07 jns 35b <stat+0x26>
return -1;
354: b8 ff ff ff ff mov $0xffffffff,%eax
359: eb 25 jmp 380 <stat+0x4b>
r = fstat(fd, st);
35b: 83 ec 08 sub $0x8,%esp
35e: ff 75 0c pushl 0xc(%ebp)
361: ff 75 f4 pushl -0xc(%ebp)
364: e8 9d 02 00 00 call 606 <fstat>
369: 83 c4 10 add $0x10,%esp
36c: 89 45 f0 mov %eax,-0x10(%ebp)
close(fd);
36f: 83 ec 0c sub $0xc,%esp
372: ff 75 f4 pushl -0xc(%ebp)
375: e8 5c 02 00 00 call 5d6 <close>
37a: 83 c4 10 add $0x10,%esp
return r;
37d: 8b 45 f0 mov -0x10(%ebp),%eax
}
380: c9 leave
381: c3 ret
00000382 <atoi>:
int
atoi(const char *s)
{
382: 55 push %ebp
383: 89 e5 mov %esp,%ebp
385: 83 ec 10 sub $0x10,%esp
int n;
n = 0;
388: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
while('0' <= *s && *s <= '9')
38f: eb 25 jmp 3b6 <atoi+0x34>
n = n*10 + *s++ - '0';
391: 8b 55 fc mov -0x4(%ebp),%edx
394: 89 d0 mov %edx,%eax
396: c1 e0 02 shl $0x2,%eax
399: 01 d0 add %edx,%eax
39b: 01 c0 add %eax,%eax
39d: 89 c1 mov %eax,%ecx
39f: 8b 45 08 mov 0x8(%ebp),%eax
3a2: 8d 50 01 lea 0x1(%eax),%edx
3a5: 89 55 08 mov %edx,0x8(%ebp)
3a8: 0f b6 00 movzbl (%eax),%eax
3ab: 0f be c0 movsbl %al,%eax
3ae: 01 c8 add %ecx,%eax
3b0: 83 e8 30 sub $0x30,%eax
3b3: 89 45 fc mov %eax,-0x4(%ebp)
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
3b6: 8b 45 08 mov 0x8(%ebp),%eax
3b9: 0f b6 00 movzbl (%eax),%eax
3bc: 3c 2f cmp $0x2f,%al
3be: 7e 0a jle 3ca <atoi+0x48>
3c0: 8b 45 08 mov 0x8(%ebp),%eax
3c3: 0f b6 00 movzbl (%eax),%eax
3c6: 3c 39 cmp $0x39,%al
3c8: 7e c7 jle 391 <atoi+0xf>
n = n*10 + *s++ - '0';
return n;
3ca: 8b 45 fc mov -0x4(%ebp),%eax
}
3cd: c9 leave
3ce: c3 ret
000003cf <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
3cf: 55 push %ebp
3d0: 89 e5 mov %esp,%ebp
3d2: 83 ec 10 sub $0x10,%esp
char *dst, *src;
dst = vdst;
3d5: 8b 45 08 mov 0x8(%ebp),%eax
3d8: 89 45 fc mov %eax,-0x4(%ebp)
src = vsrc;
3db: 8b 45 0c mov 0xc(%ebp),%eax
3de: 89 45 f8 mov %eax,-0x8(%ebp)
while(n-- > 0)
3e1: eb 17 jmp 3fa <memmove+0x2b>
*dst++ = *src++;
3e3: 8b 45 fc mov -0x4(%ebp),%eax
3e6: 8d 50 01 lea 0x1(%eax),%edx
3e9: 89 55 fc mov %edx,-0x4(%ebp)
3ec: 8b 55 f8 mov -0x8(%ebp),%edx
3ef: 8d 4a 01 lea 0x1(%edx),%ecx
3f2: 89 4d f8 mov %ecx,-0x8(%ebp)
3f5: 0f b6 12 movzbl (%edx),%edx
3f8: 88 10 mov %dl,(%eax)
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
3fa: 8b 45 10 mov 0x10(%ebp),%eax
3fd: 8d 50 ff lea -0x1(%eax),%edx
400: 89 55 10 mov %edx,0x10(%ebp)
403: 85 c0 test %eax,%eax
405: 7f dc jg 3e3 <memmove+0x14>
*dst++ = *src++;
return vdst;
407: 8b 45 08 mov 0x8(%ebp),%eax
}
40a: c9 leave
40b: c3 ret
0000040c <historyAdd>:
void
historyAdd(char *buf1){
40c: 55 push %ebp
40d: 89 e5 mov %esp,%ebp
40f: 53 push %ebx
410: 81 ec f4 07 00 00 sub $0x7f4,%esp
int fd;
char hist[10]={'h','\0'};
416: c7 45 e6 00 00 00 00 movl $0x0,-0x1a(%ebp)
41d: c7 45 ea 00 00 00 00 movl $0x0,-0x16(%ebp)
424: 66 c7 45 ee 00 00 movw $0x0,-0x12(%ebp)
42a: c6 45 e6 68 movb $0x68,-0x1a(%ebp)
//printf(1,"here\n");
char buf[1000],buf2[1000];
if((fd = open(hist, 0)) < 0){
42e: 83 ec 08 sub $0x8,%esp
431: 6a 00 push $0x0
433: 8d 45 e6 lea -0x1a(%ebp),%eax
436: 50 push %eax
437: e8 b2 01 00 00 call 5ee <open>
43c: 83 c4 10 add $0x10,%esp
43f: 89 45 f0 mov %eax,-0x10(%ebp)
442: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
446: 79 1b jns 463 <historyAdd+0x57>
printf(1, "History: cannot open %s\n", hist);
448: 83 ec 04 sub $0x4,%esp
44b: 8d 45 e6 lea -0x1a(%ebp),%eax
44e: 50 push %eax
44f: 68 14 0b 00 00 push $0xb14
454: 6a 01 push $0x1
456: e8 ca 02 00 00 call 725 <printf>
45b: 83 c4 10 add $0x10,%esp
exit();
45e: e8 4b 01 00 00 call 5ae <exit>
}
int i=0;
463: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
while(buf1[i]!=0)
46a: eb 1c jmp 488 <historyAdd+0x7c>
{ //printf(1,"%d has %d\n",i,buf1[i]);
buf[i]=buf1[i];
46c: 8b 55 f4 mov -0xc(%ebp),%edx
46f: 8b 45 08 mov 0x8(%ebp),%eax
472: 01 d0 add %edx,%eax
474: 0f b6 00 movzbl (%eax),%eax
477: 8d 8d fe fb ff ff lea -0x402(%ebp),%ecx
47d: 8b 55 f4 mov -0xc(%ebp),%edx
480: 01 ca add %ecx,%edx
482: 88 02 mov %al,(%edx)
i++;
484: 83 45 f4 01 addl $0x1,-0xc(%ebp)
printf(1, "History: cannot open %s\n", hist);
exit();
}
int i=0;
while(buf1[i]!=0)
488: 8b 55 f4 mov -0xc(%ebp),%edx
48b: 8b 45 08 mov 0x8(%ebp),%eax
48e: 01 d0 add %edx,%eax
490: 0f b6 00 movzbl (%eax),%eax
493: 84 c0 test %al,%al
495: 75 d5 jne 46c <historyAdd+0x60>
{ //printf(1,"%d has %d\n",i,buf1[i]);
buf[i]=buf1[i];
i++;
}
buf[i]=0;
497: 8d 95 fe fb ff ff lea -0x402(%ebp),%edx
49d: 8b 45 f4 mov -0xc(%ebp),%eax
4a0: 01 d0 add %edx,%eax
4a2: c6 00 00 movb $0x0,(%eax)
// int n;
while((read(fd, buf2, 1000)) > 0){
4a5: eb 5a jmp 501 <historyAdd+0xf5>
//printf(1,"%d %d\n",strlen(buf),strlen(buf2));
while(i<strlen(buf2)+strlen(buf1)){
//printf(1,"%c\n",buf2[i]);
buf[i]=buf2[i-strlen(buf1)];
4a7: 8b 5d f4 mov -0xc(%ebp),%ebx
4aa: 83 ec 0c sub $0xc,%esp
4ad: ff 75 08 pushl 0x8(%ebp)
4b0: e8 9d fd ff ff call 252 <strlen>
4b5: 83 c4 10 add $0x10,%esp
4b8: 29 c3 sub %eax,%ebx
4ba: 89 d8 mov %ebx,%eax
4bc: 0f b6 84 05 16 f8 ff movzbl -0x7ea(%ebp,%eax,1),%eax
4c3: ff
4c4: 8d 8d fe fb ff ff lea -0x402(%ebp),%ecx
4ca: 8b 55 f4 mov -0xc(%ebp),%edx
4cd: 01 ca add %ecx,%edx
4cf: 88 02 mov %al,(%edx)
i++;
4d1: 83 45 f4 01 addl $0x1,-0xc(%ebp)
//buf[1001]=0;
//int i=0;
//printf(1,"%d %d\n",strlen(buf),strlen(buf2));
while(i<strlen(buf2)+strlen(buf1)){
4d5: 83 ec 0c sub $0xc,%esp
4d8: 8d 85 16 f8 ff ff lea -0x7ea(%ebp),%eax
4de: 50 push %eax
4df: e8 6e fd ff ff call 252 <strlen>
4e4: 83 c4 10 add $0x10,%esp
4e7: 89 c3 mov %eax,%ebx
4e9: 83 ec 0c sub $0xc,%esp
4ec: ff 75 08 pushl 0x8(%ebp)
4ef: e8 5e fd ff ff call 252 <strlen>
4f4: 83 c4 10 add $0x10,%esp
4f7: 8d 14 03 lea (%ebx,%eax,1),%edx
4fa: 8b 45 f4 mov -0xc(%ebp),%eax
4fd: 39 c2 cmp %eax,%edx
4ff: 77 a6 ja 4a7 <historyAdd+0x9b>
buf[i]=buf1[i];
i++;
}
buf[i]=0;
// int n;
while((read(fd, buf2, 1000)) > 0){
501: 83 ec 04 sub $0x4,%esp
504: 68 e8 03 00 00 push $0x3e8
509: 8d 85 16 f8 ff ff lea -0x7ea(%ebp),%eax
50f: 50 push %eax
510: ff 75 f0 pushl -0x10(%ebp)
513: e8 ae 00 00 00 call 5c6 <read>
518: 83 c4 10 add $0x10,%esp
51b: 85 c0 test %eax,%eax
51d: 7f b6 jg 4d5 <historyAdd+0xc9>
}
//printf(1,"strlen: %d %s\n",strlen(buf),buf);
}
//history(fd);
close(fd);
51f: 83 ec 0c sub $0xc,%esp
522: ff 75 f0 pushl -0x10(%ebp)
525: e8 ac 00 00 00 call 5d6 <close>
52a: 83 c4 10 add $0x10,%esp
if((fd = open(hist,O_CREATE|O_RDWR)) < 0){
52d: 83 ec 08 sub $0x8,%esp
530: 68 02 02 00 00 push $0x202
535: 8d 45 e6 lea -0x1a(%ebp),%eax
538: 50 push %eax
539: e8 b0 00 00 00 call 5ee <open>
53e: 83 c4 10 add $0x10,%esp
541: 89 45 f0 mov %eax,-0x10(%ebp)
544: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
548: 79 1b jns 565 <historyAdd+0x159>
printf(1, "History: cannot open %s\n", hist);
54a: 83 ec 04 sub $0x4,%esp
54d: 8d 45 e6 lea -0x1a(%ebp),%eax
550: 50 push %eax
551: 68 14 0b 00 00 push $0xb14
556: 6a 01 push $0x1
558: e8 c8 01 00 00 call 725 <printf>
55d: 83 c4 10 add $0x10,%esp
exit();
560: e8 49 00 00 00 call 5ae <exit>
}
if(write(fd, buf, 1000) != 1000){
565: 83 ec 04 sub $0x4,%esp
568: 68 e8 03 00 00 push $0x3e8
56d: 8d 85 fe fb ff ff lea -0x402(%ebp),%eax
573: 50 push %eax
574: ff 75 f0 pushl -0x10(%ebp)
577: e8 52 00 00 00 call 5ce <write>
57c: 83 c4 10 add $0x10,%esp
57f: 3d e8 03 00 00 cmp $0x3e8,%eax
584: 74 1a je 5a0 <historyAdd+0x194>
printf(1, "error: write aa %d new file failed\n", i);
586: 83 ec 04 sub $0x4,%esp
589: ff 75 f4 pushl -0xc(%ebp)
58c: 68 30 0b 00 00 push $0xb30
591: 6a 01 push $0x1
593: e8 8d 01 00 00 call 725 <printf>
598: 83 c4 10 add $0x10,%esp
exit();
59b: e8 0e 00 00 00 call 5ae <exit>
}
}
5a0: 90 nop
5a1: 8b 5d fc mov -0x4(%ebp),%ebx
5a4: c9 leave
5a5: c3 ret
000005a6 <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
5a6: b8 01 00 00 00 mov $0x1,%eax
5ab: cd 40 int $0x40
5ad: c3 ret
000005ae <exit>:
SYSCALL(exit)
5ae: b8 02 00 00 00 mov $0x2,%eax
5b3: cd 40 int $0x40
5b5: c3 ret
000005b6 <wait>:
SYSCALL(wait)
5b6: b8 03 00 00 00 mov $0x3,%eax
5bb: cd 40 int $0x40
5bd: c3 ret
000005be <pipe>:
SYSCALL(pipe)
5be: b8 04 00 00 00 mov $0x4,%eax
5c3: cd 40 int $0x40
5c5: c3 ret
000005c6 <read>:
SYSCALL(read)
5c6: b8 05 00 00 00 mov $0x5,%eax
5cb: cd 40 int $0x40
5cd: c3 ret
000005ce <write>:
SYSCALL(write)
5ce: b8 10 00 00 00 mov $0x10,%eax
5d3: cd 40 int $0x40
5d5: c3 ret
000005d6 <close>:
SYSCALL(close)
5d6: b8 15 00 00 00 mov $0x15,%eax
5db: cd 40 int $0x40
5dd: c3 ret
000005de <kill>:
SYSCALL(kill)
5de: b8 06 00 00 00 mov $0x6,%eax
5e3: cd 40 int $0x40
5e5: c3 ret
000005e6 <exec>:
SYSCALL(exec)
5e6: b8 07 00 00 00 mov $0x7,%eax
5eb: cd 40 int $0x40
5ed: c3 ret
000005ee <open>:
SYSCALL(open)
5ee: b8 0f 00 00 00 mov $0xf,%eax
5f3: cd 40 int $0x40
5f5: c3 ret
000005f6 <mknod>:
SYSCALL(mknod)
5f6: b8 11 00 00 00 mov $0x11,%eax
5fb: cd 40 int $0x40
5fd: c3 ret
000005fe <unlink>:
SYSCALL(unlink)
5fe: b8 12 00 00 00 mov $0x12,%eax
603: cd 40 int $0x40
605: c3 ret
00000606 <fstat>:
SYSCALL(fstat)
606: b8 08 00 00 00 mov $0x8,%eax
60b: cd 40 int $0x40
60d: c3 ret
0000060e <link>:
SYSCALL(link)
60e: b8 13 00 00 00 mov $0x13,%eax
613: cd 40 int $0x40
615: c3 ret
00000616 <mkdir>:
SYSCALL(mkdir)
616: b8 14 00 00 00 mov $0x14,%eax
61b: cd 40 int $0x40
61d: c3 ret
0000061e <chdir>:
SYSCALL(chdir)
61e: b8 09 00 00 00 mov $0x9,%eax
623: cd 40 int $0x40
625: c3 ret
00000626 <dup>:
SYSCALL(dup)
626: b8 0a 00 00 00 mov $0xa,%eax
62b: cd 40 int $0x40
62d: c3 ret
0000062e <getpid>:
SYSCALL(getpid)
62e: b8 0b 00 00 00 mov $0xb,%eax
633: cd 40 int $0x40
635: c3 ret
00000636 <sbrk>:
SYSCALL(sbrk)
636: b8 0c 00 00 00 mov $0xc,%eax
63b: cd 40 int $0x40
63d: c3 ret
0000063e <sleep>:
SYSCALL(sleep)
63e: b8 0d 00 00 00 mov $0xd,%eax
643: cd 40 int $0x40
645: c3 ret
00000646 <uptime>:
SYSCALL(uptime)
646: b8 0e 00 00 00 mov $0xe,%eax
64b: cd 40 int $0x40
64d: c3 ret
0000064e <putc>:
#include "stat.h"
#include "user.h"
static void
putc(int fd, char c)
{
64e: 55 push %ebp
64f: 89 e5 mov %esp,%ebp
651: 83 ec 18 sub $0x18,%esp
654: 8b 45 0c mov 0xc(%ebp),%eax
657: 88 45 f4 mov %al,-0xc(%ebp)
write(fd, &c, 1);
65a: 83 ec 04 sub $0x4,%esp
65d: 6a 01 push $0x1
65f: 8d 45 f4 lea -0xc(%ebp),%eax
662: 50 push %eax
663: ff 75 08 pushl 0x8(%ebp)
666: e8 63 ff ff ff call 5ce <write>
66b: 83 c4 10 add $0x10,%esp
}
66e: 90 nop
66f: c9 leave
670: c3 ret
00000671 <printint>:
static void
printint(int fd, int xx, int base, int sgn)
{
671: 55 push %ebp
672: 89 e5 mov %esp,%ebp
674: 53 push %ebx
675: 83 ec 24 sub $0x24,%esp
static char digits[] = "0123456789ABCDEF";
char buf[16];
int i, neg;
uint x;
neg = 0;
678: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
if(sgn && xx < 0){
67f: 83 7d 14 00 cmpl $0x0,0x14(%ebp)
683: 74 17 je 69c <printint+0x2b>
685: 83 7d 0c 00 cmpl $0x0,0xc(%ebp)
689: 79 11 jns 69c <printint+0x2b>
neg = 1;
68b: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp)
x = -xx;
692: 8b 45 0c mov 0xc(%ebp),%eax
695: f7 d8 neg %eax
697: 89 45 ec mov %eax,-0x14(%ebp)
69a: eb 06 jmp 6a2 <printint+0x31>
} else {
x = xx;
69c: 8b 45 0c mov 0xc(%ebp),%eax
69f: 89 45 ec mov %eax,-0x14(%ebp)
}
i = 0;
6a2: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
do{
buf[i++] = digits[x % base];
6a9: 8b 4d f4 mov -0xc(%ebp),%ecx
6ac: 8d 41 01 lea 0x1(%ecx),%eax
6af: 89 45 f4 mov %eax,-0xc(%ebp)
6b2: 8b 5d 10 mov 0x10(%ebp),%ebx
6b5: 8b 45 ec mov -0x14(%ebp),%eax
6b8: ba 00 00 00 00 mov $0x0,%edx
6bd: f7 f3 div %ebx
6bf: 89 d0 mov %edx,%eax
6c1: 0f b6 80 ec 0d 00 00 movzbl 0xdec(%eax),%eax
6c8: 88 44 0d dc mov %al,-0x24(%ebp,%ecx,1)
}while((x /= base) != 0);
6cc: 8b 5d 10 mov 0x10(%ebp),%ebx
6cf: 8b 45 ec mov -0x14(%ebp),%eax
6d2: ba 00 00 00 00 mov $0x0,%edx
6d7: f7 f3 div %ebx
6d9: 89 45 ec mov %eax,-0x14(%ebp)
6dc: 83 7d ec 00 cmpl $0x0,-0x14(%ebp)
6e0: 75 c7 jne 6a9 <printint+0x38>
if(neg)
6e2: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
6e6: 74 2d je 715 <printint+0xa4>
buf[i++] = '-';
6e8: 8b 45 f4 mov -0xc(%ebp),%eax
6eb: 8d 50 01 lea 0x1(%eax),%edx
6ee: 89 55 f4 mov %edx,-0xc(%ebp)
6f1: c6 44 05 dc 2d movb $0x2d,-0x24(%ebp,%eax,1)
while(--i >= 0)
6f6: eb 1d jmp 715 <printint+0xa4>
putc(fd, buf[i]);
6f8: 8d 55 dc lea -0x24(%ebp),%edx
6fb: 8b 45 f4 mov -0xc(%ebp),%eax
6fe: 01 d0 add %edx,%eax
700: 0f b6 00 movzbl (%eax),%eax
703: 0f be c0 movsbl %al,%eax
706: 83 ec 08 sub $0x8,%esp
709: 50 push %eax
70a: ff 75 08 pushl 0x8(%ebp)
70d: e8 3c ff ff ff call 64e <putc>
712: 83 c4 10 add $0x10,%esp
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
715: 83 6d f4 01 subl $0x1,-0xc(%ebp)
719: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
71d: 79 d9 jns 6f8 <printint+0x87>
putc(fd, buf[i]);
}
71f: 90 nop
720: 8b 5d fc mov -0x4(%ebp),%ebx
723: c9 leave
724: c3 ret
00000725 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
725: 55 push %ebp
726: 89 e5 mov %esp,%ebp
728: 83 ec 28 sub $0x28,%esp
char *s;
int c, i, state;
uint *ap;
state = 0;
72b: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp)
ap = (uint*)(void*)&fmt + 1;
732: 8d 45 0c lea 0xc(%ebp),%eax
735: 83 c0 04 add $0x4,%eax
738: 89 45 e8 mov %eax,-0x18(%ebp)
for(i = 0; fmt[i]; i++){
73b: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
742: e9 59 01 00 00 jmp 8a0 <printf+0x17b>
c = fmt[i] & 0xff;
747: 8b 55 0c mov 0xc(%ebp),%edx
74a: 8b 45 f0 mov -0x10(%ebp),%eax
74d: 01 d0 add %edx,%eax
74f: 0f b6 00 movzbl (%eax),%eax
752: 0f be c0 movsbl %al,%eax
755: 25 ff 00 00 00 and $0xff,%eax
75a: 89 45 e4 mov %eax,-0x1c(%ebp)
if(state == 0){
75d: 83 7d ec 00 cmpl $0x0,-0x14(%ebp)
761: 75 2c jne 78f <printf+0x6a>
if(c == '%'){
763: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp)
767: 75 0c jne 775 <printf+0x50>
state = '%';
769: c7 45 ec 25 00 00 00 movl $0x25,-0x14(%ebp)
770: e9 27 01 00 00 jmp 89c <printf+0x177>
} else {
putc(fd, c);
775: 8b 45 e4 mov -0x1c(%ebp),%eax
778: 0f be c0 movsbl %al,%eax
77b: 83 ec 08 sub $0x8,%esp
77e: 50 push %eax
77f: ff 75 08 pushl 0x8(%ebp)
782: e8 c7 fe ff ff call 64e <putc>
787: 83 c4 10 add $0x10,%esp
78a: e9 0d 01 00 00 jmp 89c <printf+0x177>
}
} else if(state == '%'){
78f: 83 7d ec 25 cmpl $0x25,-0x14(%ebp)
793: 0f 85 03 01 00 00 jne 89c <printf+0x177>
if(c == 'd'){
799: 83 7d e4 64 cmpl $0x64,-0x1c(%ebp)
79d: 75 1e jne 7bd <printf+0x98>
printint(fd, *ap, 10, 1);
79f: 8b 45 e8 mov -0x18(%ebp),%eax
7a2: 8b 00 mov (%eax),%eax
7a4: 6a 01 push $0x1
7a6: 6a 0a push $0xa
7a8: 50 push %eax
7a9: ff 75 08 pushl 0x8(%ebp)
7ac: e8 c0 fe ff ff call 671 <printint>
7b1: 83 c4 10 add $0x10,%esp
ap++;
7b4: 83 45 e8 04 addl $0x4,-0x18(%ebp)
7b8: e9 d8 00 00 00 jmp 895 <printf+0x170>
} else if(c == 'x' || c == 'p'){
7bd: 83 7d e4 78 cmpl $0x78,-0x1c(%ebp)
7c1: 74 06 je 7c9 <printf+0xa4>
7c3: 83 7d e4 70 cmpl $0x70,-0x1c(%ebp)
7c7: 75 1e jne 7e7 <printf+0xc2>
printint(fd, *ap, 16, 0);
7c9: 8b 45 e8 mov -0x18(%ebp),%eax
7cc: 8b 00 mov (%eax),%eax
7ce: 6a 00 push $0x0
7d0: 6a 10 push $0x10
7d2: 50 push %eax
7d3: ff 75 08 pushl 0x8(%ebp)
7d6: e8 96 fe ff ff call 671 <printint>
7db: 83 c4 10 add $0x10,%esp
ap++;
7de: 83 45 e8 04 addl $0x4,-0x18(%ebp)
7e2: e9 ae 00 00 00 jmp 895 <printf+0x170>
} else if(c == 's'){
7e7: 83 7d e4 73 cmpl $0x73,-0x1c(%ebp)
7eb: 75 43 jne 830 <printf+0x10b>
s = (char*)*ap;
7ed: 8b 45 e8 mov -0x18(%ebp),%eax
7f0: 8b 00 mov (%eax),%eax
7f2: 89 45 f4 mov %eax,-0xc(%ebp)
ap++;
7f5: 83 45 e8 04 addl $0x4,-0x18(%ebp)
if(s == 0)
7f9: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
7fd: 75 25 jne 824 <printf+0xff>
s = "(null)";
7ff: c7 45 f4 54 0b 00 00 movl $0xb54,-0xc(%ebp)
while(*s != 0){
806: eb 1c jmp 824 <printf+0xff>
putc(fd, *s);
808: 8b 45 f4 mov -0xc(%ebp),%eax
80b: 0f b6 00 movzbl (%eax),%eax
80e: 0f be c0 movsbl %al,%eax
811: 83 ec 08 sub $0x8,%esp
814: 50 push %eax
815: ff 75 08 pushl 0x8(%ebp)
818: e8 31 fe ff ff call 64e <putc>
81d: 83 c4 10 add $0x10,%esp
s++;
820: 83 45 f4 01 addl $0x1,-0xc(%ebp)
} else if(c == 's'){
s = (char*)*ap;
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
824: 8b 45 f4 mov -0xc(%ebp),%eax
827: 0f b6 00 movzbl (%eax),%eax
82a: 84 c0 test %al,%al
82c: 75 da jne 808 <printf+0xe3>
82e: eb 65 jmp 895 <printf+0x170>
putc(fd, *s);
s++;
}
} else if(c == 'c'){
830: 83 7d e4 63 cmpl $0x63,-0x1c(%ebp)
834: 75 1d jne 853 <printf+0x12e>
putc(fd, *ap);
836: 8b 45 e8 mov -0x18(%ebp),%eax
839: 8b 00 mov (%eax),%eax
83b: 0f be c0 movsbl %al,%eax
83e: 83 ec 08 sub $0x8,%esp
841: 50 push %eax
842: ff 75 08 pushl 0x8(%ebp)
845: e8 04 fe ff ff call 64e <putc>
84a: 83 c4 10 add $0x10,%esp
ap++;
84d: 83 45 e8 04 addl $0x4,-0x18(%ebp)
851: eb 42 jmp 895 <printf+0x170>
} else if(c == '%'){
853: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp)
857: 75 17 jne 870 <printf+0x14b>
putc(fd, c);
859: 8b 45 e4 mov -0x1c(%ebp),%eax
85c: 0f be c0 movsbl %al,%eax
85f: 83 ec 08 sub $0x8,%esp
862: 50 push %eax
863: ff 75 08 pushl 0x8(%ebp)
866: e8 e3 fd ff ff call 64e <putc>
86b: 83 c4 10 add $0x10,%esp
86e: eb 25 jmp 895 <printf+0x170>
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
870: 83 ec 08 sub $0x8,%esp
873: 6a 25 push $0x25
875: ff 75 08 pushl 0x8(%ebp)
878: e8 d1 fd ff ff call 64e <putc>
87d: 83 c4 10 add $0x10,%esp
putc(fd, c);
880: 8b 45 e4 mov -0x1c(%ebp),%eax
883: 0f be c0 movsbl %al,%eax
886: 83 ec 08 sub $0x8,%esp
889: 50 push %eax
88a: ff 75 08 pushl 0x8(%ebp)
88d: e8 bc fd ff ff call 64e <putc>
892: 83 c4 10 add $0x10,%esp
}
state = 0;
895: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp)
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
89c: 83 45 f0 01 addl $0x1,-0x10(%ebp)
8a0: 8b 55 0c mov 0xc(%ebp),%edx
8a3: 8b 45 f0 mov -0x10(%ebp),%eax
8a6: 01 d0 add %edx,%eax
8a8: 0f b6 00 movzbl (%eax),%eax
8ab: 84 c0 test %al,%al
8ad: 0f 85 94 fe ff ff jne 747 <printf+0x22>
putc(fd, c);
}
state = 0;
}
}
}
8b3: 90 nop
8b4: c9 leave
8b5: c3 ret
000008b6 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
8b6: 55 push %ebp
8b7: 89 e5 mov %esp,%ebp
8b9: 83 ec 10 sub $0x10,%esp
Header *bp, *p;
bp = (Header*)ap - 1;
8bc: 8b 45 08 mov 0x8(%ebp),%eax
8bf: 83 e8 08 sub $0x8,%eax
8c2: 89 45 f8 mov %eax,-0x8(%ebp)
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
8c5: a1 08 0e 00 00 mov 0xe08,%eax
8ca: 89 45 fc mov %eax,-0x4(%ebp)
8cd: eb 24 jmp 8f3 <free+0x3d>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
8cf: 8b 45 fc mov -0x4(%ebp),%eax
8d2: 8b 00 mov (%eax),%eax
8d4: 3b 45 fc cmp -0x4(%ebp),%eax
8d7: 77 12 ja 8eb <free+0x35>
8d9: 8b 45 f8 mov -0x8(%ebp),%eax
8dc: 3b 45 fc cmp -0x4(%ebp),%eax
8df: 77 24 ja 905 <free+0x4f>
8e1: 8b 45 fc mov -0x4(%ebp),%eax
8e4: 8b 00 mov (%eax),%eax
8e6: 3b 45 f8 cmp -0x8(%ebp),%eax
8e9: 77 1a ja 905 <free+0x4f>
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
8eb: 8b 45 fc mov -0x4(%ebp),%eax
8ee: 8b 00 mov (%eax),%eax
8f0: 89 45 fc mov %eax,-0x4(%ebp)
8f3: 8b 45 f8 mov -0x8(%ebp),%eax
8f6: 3b 45 fc cmp -0x4(%ebp),%eax
8f9: 76 d4 jbe 8cf <free+0x19>
8fb: 8b 45 fc mov -0x4(%ebp),%eax
8fe: 8b 00 mov (%eax),%eax
900: 3b 45 f8 cmp -0x8(%ebp),%eax
903: 76 ca jbe 8cf <free+0x19>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
break;
if(bp + bp->s.size == p->s.ptr){
905: 8b 45 f8 mov -0x8(%ebp),%eax
908: 8b 40 04 mov 0x4(%eax),%eax
90b: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx
912: 8b 45 f8 mov -0x8(%ebp),%eax
915: 01 c2 add %eax,%edx
917: 8b 45 fc mov -0x4(%ebp),%eax
91a: 8b 00 mov (%eax),%eax
91c: 39 c2 cmp %eax,%edx
91e: 75 24 jne 944 <free+0x8e>
bp->s.size += p->s.ptr->s.size;
920: 8b 45 f8 mov -0x8(%ebp),%eax
923: 8b 50 04 mov 0x4(%eax),%edx
926: 8b 45 fc mov -0x4(%ebp),%eax
929: 8b 00 mov (%eax),%eax
92b: 8b 40 04 mov 0x4(%eax),%eax
92e: 01 c2 add %eax,%edx
930: 8b 45 f8 mov -0x8(%ebp),%eax
933: 89 50 04 mov %edx,0x4(%eax)
bp->s.ptr = p->s.ptr->s.ptr;
936: 8b 45 fc mov -0x4(%ebp),%eax
939: 8b 00 mov (%eax),%eax
93b: 8b 10 mov (%eax),%edx
93d: 8b 45 f8 mov -0x8(%ebp),%eax
940: 89 10 mov %edx,(%eax)
942: eb 0a jmp 94e <free+0x98>
} else
bp->s.ptr = p->s.ptr;
944: 8b 45 fc mov -0x4(%ebp),%eax
947: 8b 10 mov (%eax),%edx
949: 8b 45 f8 mov -0x8(%ebp),%eax
94c: 89 10 mov %edx,(%eax)
if(p + p->s.size == bp){
94e: 8b 45 fc mov -0x4(%ebp),%eax
951: 8b 40 04 mov 0x4(%eax),%eax
954: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx
95b: 8b 45 fc mov -0x4(%ebp),%eax
95e: 01 d0 add %edx,%eax
960: 3b 45 f8 cmp -0x8(%ebp),%eax
963: 75 20 jne 985 <free+0xcf>
p->s.size += bp->s.size;
965: 8b 45 fc mov -0x4(%ebp),%eax
968: 8b 50 04 mov 0x4(%eax),%edx
96b: 8b 45 f8 mov -0x8(%ebp),%eax
96e: 8b 40 04 mov 0x4(%eax),%eax
971: 01 c2 add %eax,%edx
973: 8b 45 fc mov -0x4(%ebp),%eax
976: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
979: 8b 45 f8 mov -0x8(%ebp),%eax
97c: 8b 10 mov (%eax),%edx
97e: 8b 45 fc mov -0x4(%ebp),%eax
981: 89 10 mov %edx,(%eax)
983: eb 08 jmp 98d <free+0xd7>
} else
p->s.ptr = bp;
985: 8b 45 fc mov -0x4(%ebp),%eax
988: 8b 55 f8 mov -0x8(%ebp),%edx
98b: 89 10 mov %edx,(%eax)
freep = p;
98d: 8b 45 fc mov -0x4(%ebp),%eax
990: a3 08 0e 00 00 mov %eax,0xe08
}
995: 90 nop
996: c9 leave
997: c3 ret
00000998 <morecore>:
static Header*
morecore(uint nu)
{
998: 55 push %ebp
999: 89 e5 mov %esp,%ebp
99b: 83 ec 18 sub $0x18,%esp
char *p;
Header *hp;
if(nu < 4096)
99e: 81 7d 08 ff 0f 00 00 cmpl $0xfff,0x8(%ebp)
9a5: 77 07 ja 9ae <morecore+0x16>
nu = 4096;
9a7: c7 45 08 00 10 00 00 movl $0x1000,0x8(%ebp)
p = sbrk(nu * sizeof(Header));
9ae: 8b 45 08 mov 0x8(%ebp),%eax
9b1: c1 e0 03 shl $0x3,%eax
9b4: 83 ec 0c sub $0xc,%esp
9b7: 50 push %eax
9b8: e8 79 fc ff ff call 636 <sbrk>
9bd: 83 c4 10 add $0x10,%esp
9c0: 89 45 f4 mov %eax,-0xc(%ebp)
if(p == (char*)-1)
9c3: 83 7d f4 ff cmpl $0xffffffff,-0xc(%ebp)
9c7: 75 07 jne 9d0 <morecore+0x38>
return 0;
9c9: b8 00 00 00 00 mov $0x0,%eax
9ce: eb 26 jmp 9f6 <morecore+0x5e>
hp = (Header*)p;
9d0: 8b 45 f4 mov -0xc(%ebp),%eax
9d3: 89 45 f0 mov %eax,-0x10(%ebp)
hp->s.size = nu;
9d6: 8b 45 f0 mov -0x10(%ebp),%eax
9d9: 8b 55 08 mov 0x8(%ebp),%edx
9dc: 89 50 04 mov %edx,0x4(%eax)
free((void*)(hp + 1));
9df: 8b 45 f0 mov -0x10(%ebp),%eax
9e2: 83 c0 08 add $0x8,%eax
9e5: 83 ec 0c sub $0xc,%esp
9e8: 50 push %eax
9e9: e8 c8 fe ff ff call 8b6 <free>
9ee: 83 c4 10 add $0x10,%esp
return freep;
9f1: a1 08 0e 00 00 mov 0xe08,%eax
}
9f6: c9 leave
9f7: c3 ret
000009f8 <malloc>:
void*
malloc(uint nbytes)
{
9f8: 55 push %ebp
9f9: 89 e5 mov %esp,%ebp
9fb: 83 ec 18 sub $0x18,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
9fe: 8b 45 08 mov 0x8(%ebp),%eax
a01: 83 c0 07 add $0x7,%eax
a04: c1 e8 03 shr $0x3,%eax
a07: 83 c0 01 add $0x1,%eax
a0a: 89 45 ec mov %eax,-0x14(%ebp)
if((prevp = freep) == 0){
a0d: a1 08 0e 00 00 mov 0xe08,%eax
a12: 89 45 f0 mov %eax,-0x10(%ebp)
a15: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
a19: 75 23 jne a3e <malloc+0x46>
base.s.ptr = freep = prevp = &base;
a1b: c7 45 f0 00 0e 00 00 movl $0xe00,-0x10(%ebp)
a22: 8b 45 f0 mov -0x10(%ebp),%eax
a25: a3 08 0e 00 00 mov %eax,0xe08
a2a: a1 08 0e 00 00 mov 0xe08,%eax
a2f: a3 00 0e 00 00 mov %eax,0xe00
base.s.size = 0;
a34: c7 05 04 0e 00 00 00 movl $0x0,0xe04
a3b: 00 00 00
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
a3e: 8b 45 f0 mov -0x10(%ebp),%eax
a41: 8b 00 mov (%eax),%eax
a43: 89 45 f4 mov %eax,-0xc(%ebp)
if(p->s.size >= nunits){
a46: 8b 45 f4 mov -0xc(%ebp),%eax
a49: 8b 40 04 mov 0x4(%eax),%eax
a4c: 3b 45 ec cmp -0x14(%ebp),%eax
a4f: 72 4d jb a9e <malloc+0xa6>
if(p->s.size == nunits)
a51: 8b 45 f4 mov -0xc(%ebp),%eax
a54: 8b 40 04 mov 0x4(%eax),%eax
a57: 3b 45 ec cmp -0x14(%ebp),%eax
a5a: 75 0c jne a68 <malloc+0x70>
prevp->s.ptr = p->s.ptr;
a5c: 8b 45 f4 mov -0xc(%ebp),%eax
a5f: 8b 10 mov (%eax),%edx
a61: 8b 45 f0 mov -0x10(%ebp),%eax
a64: 89 10 mov %edx,(%eax)
a66: eb 26 jmp a8e <malloc+0x96>
else {
p->s.size -= nunits;
a68: 8b 45 f4 mov -0xc(%ebp),%eax
a6b: 8b 40 04 mov 0x4(%eax),%eax
a6e: 2b 45 ec sub -0x14(%ebp),%eax
a71: 89 c2 mov %eax,%edx
a73: 8b 45 f4 mov -0xc(%ebp),%eax
a76: 89 50 04 mov %edx,0x4(%eax)
p += p->s.size;
a79: 8b 45 f4 mov -0xc(%ebp),%eax
a7c: 8b 40 04 mov 0x4(%eax),%eax
a7f: c1 e0 03 shl $0x3,%eax
a82: 01 45 f4 add %eax,-0xc(%ebp)
p->s.size = nunits;
a85: 8b 45 f4 mov -0xc(%ebp),%eax
a88: 8b 55 ec mov -0x14(%ebp),%edx
a8b: 89 50 04 mov %edx,0x4(%eax)
}
freep = prevp;
a8e: 8b 45 f0 mov -0x10(%ebp),%eax
a91: a3 08 0e 00 00 mov %eax,0xe08
return (void*)(p + 1);
a96: 8b 45 f4 mov -0xc(%ebp),%eax
a99: 83 c0 08 add $0x8,%eax
a9c: eb 3b jmp ad9 <malloc+0xe1>
}
if(p == freep)
a9e: a1 08 0e 00 00 mov 0xe08,%eax
aa3: 39 45 f4 cmp %eax,-0xc(%ebp)
aa6: 75 1e jne ac6 <malloc+0xce>
if((p = morecore(nunits)) == 0)
aa8: 83 ec 0c sub $0xc,%esp
aab: ff 75 ec pushl -0x14(%ebp)
aae: e8 e5 fe ff ff call 998 <morecore>
ab3: 83 c4 10 add $0x10,%esp
ab6: 89 45 f4 mov %eax,-0xc(%ebp)
ab9: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
abd: 75 07 jne ac6 <malloc+0xce>
return 0;
abf: b8 00 00 00 00 mov $0x0,%eax
ac4: eb 13 jmp ad9 <malloc+0xe1>
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
ac6: 8b 45 f4 mov -0xc(%ebp),%eax
ac9: 89 45 f0 mov %eax,-0x10(%ebp)
acc: 8b 45 f4 mov -0xc(%ebp),%eax
acf: 8b 00 mov (%eax),%eax
ad1: 89 45 f4 mov %eax,-0xc(%ebp)
return (void*)(p + 1);
}
if(p == freep)
if((p = morecore(nunits)) == 0)
return 0;
}
ad4: e9 6d ff ff ff jmp a46 <malloc+0x4e>
}
ad9: c9 leave
ada: c3 ret
|
npctrade: MACRO
; dialog set, requested mon, offered mon, nickname, dvs, item, OT ID, OT name, gender requested
db \1, \2, \3, \4, \5, \6, \7
shift
dw \7
db \8, \9, 0
ENDM
NPCTrades:
; entries correspond to NPCTRADE_* constants
npctrade TRADE_DIALOGSET_COLLECTOR, PIKACHU, ELEKID, "KIDDO@@@@@@", $37, $66, GOLD_BERRY, 37460, "MIKE@@@@@@@", TRADE_GENDER_EITHER ; Pewter Museum
npctrade TRADE_DIALOGSET_COLLECTOR, KANGASKHAN, SCYTHER, "CUTTER@@@@@", $96, $66, BITTER_BERRY, 48926, "KYLE@@@@@@@", TRADE_GENDER_EITHER ; Cerulean City
npctrade TRADE_DIALOGSET_HAPPY, KRABBY, VOLTORB, "VOLTY@@@@@@", $98, $88, PRZCUREBERRY, 29189, "TIM@@@@@@@@", TRADE_GENDER_EITHER
npctrade TRADE_DIALOGSET_GIRL, DRAGONAIR, DODRIO, "DORIS@@@@@@", $77, $66, SMOKE_BALL, 00283, "EMY@@@@@@@@", TRADE_GENDER_FEMALE
npctrade TRADE_DIALOGSET_NEWBIE, HAUNTER, XATU, "PAUL@@@@@@@", $96, $86, MYSTERYBERRY, 15616, "CHRIS@@@@@@", TRADE_GENDER_EITHER
npctrade TRADE_DIALOGSET_GIRL, CHANSEY, AERODACTYL, "AEROY@@@@@@", $96, $66, GOLD_BERRY, 26491, "KIM@@@@@@@@", TRADE_GENDER_EITHER
npctrade TRADE_DIALOGSET_COLLECTOR, DUGTRIO, MAGNETON, "MAGGIE@@@@@", $96, $66, METAL_COAT, 50082, "FOREST@@@@@", TRADE_GENDER_EITHER
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %r15
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_D_ht+0x8156, %r15
nop
nop
dec %r11
mov $0x6162636465666768, %rax
movq %rax, %xmm6
vmovups %ymm6, (%r15)
nop
nop
nop
inc %rdi
lea addresses_normal_ht+0x144ee, %rsi
lea addresses_WC_ht+0x8e36, %rdi
clflush (%rdi)
nop
nop
and $2143, %rdx
mov $20, %rcx
rep movsq
nop
nop
nop
dec %rsi
lea addresses_UC_ht+0xf4e2, %rsi
nop
nop
dec %r11
and $0xffffffffffffffc0, %rsi
vmovaps (%rsi), %ymm6
vextracti128 $0, %ymm6, %xmm6
vpextrq $0, %xmm6, %r15
nop
nop
nop
nop
nop
cmp $1573, %r11
lea addresses_normal_ht+0x1a076, %rsi
lea addresses_D_ht+0x1be82, %rdi
nop
nop
cmp %r12, %r12
mov $52, %rcx
rep movsl
add %rcx, %rcx
lea addresses_D_ht+0xa2d3, %rsi
lea addresses_normal_ht+0x2b56, %rdi
nop
nop
nop
xor $30245, %r15
mov $122, %rcx
rep movsb
nop
nop
add %rax, %rax
lea addresses_D_ht+0x4cf6, %rdx
nop
nop
nop
sub $17057, %rcx
movups (%rdx), %xmm3
vpextrq $0, %xmm3, %r11
nop
xor %r12, %r12
lea addresses_D_ht+0x13756, %rsi
nop
nop
nop
and %r12, %r12
movb (%rsi), %r11b
nop
nop
xor $15955, %r15
lea addresses_A_ht+0x1d856, %rdi
nop
nop
cmp %rcx, %rcx
mov (%rdi), %r11d
nop
nop
nop
nop
nop
sub %rdi, %rdi
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r15
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r13
push %r14
push %r9
push %rax
push %rbp
push %rsi
// Faulty Load
lea addresses_normal+0x756, %r13
nop
nop
nop
nop
nop
xor $51016, %r9
movb (%r13), %al
lea oracles, %rbp
and $0xff, %rax
shlq $12, %rax
mov (%rbp,%rax,1), %rax
pop %rsi
pop %rbp
pop %rax
pop %r9
pop %r14
pop %r13
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'size': 8, 'NT': False, 'type': 'addresses_normal', 'same': False, 'AVXalign': False, 'congruent': 0}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'size': 1, 'NT': False, 'type': 'addresses_normal', 'same': True, 'AVXalign': False, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'size': 32, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 9}}
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_normal_ht', 'congruent': 3}, 'dst': {'same': False, 'type': 'addresses_WC_ht', 'congruent': 2}}
{'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_UC_ht', 'same': False, 'AVXalign': True, 'congruent': 1}}
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_normal_ht', 'congruent': 5}, 'dst': {'same': False, 'type': 'addresses_D_ht', 'congruent': 2}}
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_D_ht', 'congruent': 0}, 'dst': {'same': True, 'type': 'addresses_normal_ht', 'congruent': 8}}
{'OP': 'LOAD', 'src': {'size': 16, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 5}}
{'OP': 'LOAD', 'src': {'size': 1, 'NT': True, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 11}}
{'OP': 'LOAD', 'src': {'size': 4, 'NT': False, 'type': 'addresses_A_ht', 'same': False, 'AVXalign': False, 'congruent': 7}}
{'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
*/
|
//------------------------------------------------------------------------------
//
// Copyright 2018-2019 Fetch.AI Limited
//
// 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 "oef-core/tasks/IMtCoreCommsTask.hpp"
// std::ostream& operator<<(std::ostream& os, const IMtCoreCommsTask &output) {}
|
// ATM this class does several things:
// - It connects the YMF278b chip to specific I/O ports in the MSX machine
// - It glues the YMF262 (FM-part) and YMF278 (Wave-part) classes together in a
// full model of a YMF278b chip. IOW part of the logic of the YM278b is
// modeled here instead of in a chip-specific class.
// TODO it would be nice to move the functionality of the 2nd point to a
// different class, but until there's a 2nd user of this chip, this is
// low priority.
#include "MSXMoonSound.hh"
#include "Clock.hh"
#include "serialize.hh"
#include "unreachable.hh"
namespace openmsx {
// The master clock, running at 33.8MHz.
using MasterClock = Clock<33868800>;
// Required delay between register select and register read/write.
constexpr auto FM_REG_SELECT_DELAY = MasterClock::duration(56);
// Required delay after register write.
constexpr auto FM_REG_WRITE_DELAY = MasterClock::duration(56);
// Datasheet doesn't mention any delay for reads from the FM registers. In fact
// it says reads from FM registers are not possible while tests on a real
// YMF278 show they do work (value of the NEW2 bit doesn't matter).
// Required delay between register select and register read/write.
constexpr auto WAVE_REG_SELECT_DELAY = MasterClock::duration(88);
// Required delay after register write.
constexpr auto WAVE_REG_WRITE_DELAY = MasterClock::duration(88);
// Datasheet doesn't mention any delay for register reads (except for reads
// from register 6, see below). I also couldn't measure any delay on a real
// YMF278.
// Required delay after memory read.
constexpr auto MEM_READ_DELAY = MasterClock::duration(38);
// Required delay after memory write (instead of register write delay).
constexpr auto MEM_WRITE_DELAY = MasterClock::duration(28);
// Required delay after instrument load.
// We pick 10000 cycles, this is approximately 300us (the number given in the
// datasheet). The exact number of cycles is unknown. But I did some (very
// rough) tests on real HW, and this number is not too bad (slightly too high
// but within 2%-4% of real value, needs more detailed tests).
constexpr auto LOAD_DELAY = MasterClock::duration(10000);
MSXMoonSound::MSXMoonSound(const DeviceConfig& config)
: MSXDevice(config)
, ymf262(getName() + " FM", config, true)
, ymf278(getName() + " wave",
config.getChildDataAsInt("sampleram", 512), // size in kb
config)
, ymf278LoadTime(getCurrentTime())
, ymf278BusyTime(getCurrentTime())
{
powerUp(getCurrentTime());
}
void MSXMoonSound::powerUp(EmuTime::param time)
{
ymf278.clearRam();
reset(time);
}
void MSXMoonSound::reset(EmuTime::param time)
{
ymf262.reset(time);
ymf278.reset(time);
opl4latch = 0; // TODO check
opl3latch = 0; // TODO check
ymf278BusyTime = time;
ymf278LoadTime = time;
}
byte MSXMoonSound::readIO(word port, EmuTime::param time)
{
if ((port & 0xFF) < 0xC0) {
// WAVE part 0x7E-0x7F
switch (port & 0x01) {
case 0: // read latch, not supported
return 255;
case 1: // read wave register
// Verified on real YMF278:
// Even if NEW2=0 reads happen normally. Also reads
// from sample memory (and thus the internal memory
// pointer gets increased).
if ((3 <= opl4latch) && (opl4latch <= 6)) {
// This time is so small that on a MSX you can
// never see BUSY=1. So I also couldn't test
// whether this timing applies to registers 3-6
// (like for write) or only to register 6. I
// also couldn't test how the other registers
// behave.
// TODO Should we comment out this code? It
// doesn't have any measurable effect on MSX.
ymf278BusyTime = time + MEM_READ_DELAY;
}
return ymf278.readReg(opl4latch);
default: // unreachable, avoid warning
UNREACHABLE; return 255;
}
} else {
// FM part 0xC4-0xC7
switch (port & 0x03) {
case 0: // read status
case 2:
return ymf262.readStatus() | readYMF278Status(time);
case 1:
case 3: // read fm register
return ymf262.readReg(opl3latch);
default: // unreachable, avoid warning
UNREACHABLE; return 255;
}
}
}
byte MSXMoonSound::peekIO(word port, EmuTime::param time) const
{
if ((port & 0xFF) < 0xC0) {
// WAVE part 0x7E-0x7F
switch (port & 0x01) {
case 0: // read latch, not supported
return 255;
case 1: // read wave register
return ymf278.peekReg(opl4latch);
default: // unreachable, avoid warning
UNREACHABLE; return 255;
}
} else {
// FM part 0xC4-0xC7
switch (port & 0x03) {
case 0: // read status
case 2:
return ymf262.peekStatus() | readYMF278Status(time);
case 1:
case 3: // read fm register
return ymf262.peekReg(opl3latch);
default: // unreachable, avoid warning
UNREACHABLE; return 255;
}
}
}
void MSXMoonSound::writeIO(word port, byte value, EmuTime::param time)
{
if ((port & 0xFF) < 0xC0) {
// WAVE part 0x7E-0x7F
if (getNew2()) {
switch (port & 0x01) {
case 0: // select register
ymf278BusyTime = time + WAVE_REG_SELECT_DELAY;
opl4latch = value;
break;
case 1:
if ((0x08 <= opl4latch) && (opl4latch <= 0x1F)) {
ymf278LoadTime = time + LOAD_DELAY;
}
if ((3 <= opl4latch) && (opl4latch <= 6)) {
// Note: this time is so small that on
// MSX you never see BUSY=1 for these
// registers. Confirmed on real HW that
// also registers 3-5 are faster.
ymf278BusyTime = time + MEM_WRITE_DELAY;
} else {
// For the other registers it is
// possible to see BUSY=1, but only
// very briefly and only on R800.
ymf278BusyTime = time + WAVE_REG_WRITE_DELAY;
}
if (opl4latch == 0xf8) {
ymf262.setMixLevel(value, time);
} else if (opl4latch == 0xf9) {
ymf278.setMixLevel(value, time);
}
ymf278.writeReg(opl4latch, value, time);
break;
default:
UNREACHABLE;
}
} else {
// Verified on real YMF278:
// Writes are ignored when NEW2=0 (both register select
// and register write).
}
} else {
// FM part 0xC4-0xC7
switch (port & 0x03) {
case 0: // select register bank 0
opl3latch = value;
ymf278BusyTime = time + FM_REG_SELECT_DELAY;
break;
case 2: // select register bank 1
opl3latch = value | 0x100;
ymf278BusyTime = time + FM_REG_SELECT_DELAY;
break;
case 1:
case 3: // write fm register
ymf278BusyTime = time + FM_REG_WRITE_DELAY;
ymf262.writeReg(opl3latch, value, time);
break;
default:
UNREACHABLE;
}
}
}
bool MSXMoonSound::getNew2() const
{
return (ymf262.peekReg(0x105) & 0x02) != 0;
}
byte MSXMoonSound::readYMF278Status(EmuTime::param time) const
{
byte result = 0;
if (time < ymf278BusyTime) result |= 0x01;
if (time < ymf278LoadTime) result |= 0x02;
return result;
}
// version 1: initial version
// version 2: added alreadyReadID
// version 3: moved loadTime and busyTime from YMF278 to here
// removed alreadyReadID
template<typename Archive>
void MSXMoonSound::serialize(Archive& ar, unsigned version)
{
ar.template serializeBase<MSXDevice>(*this);
ar.serialize("ymf262", ymf262,
"ymf278", ymf278,
"opl3latch", opl3latch,
"opl4latch", opl4latch);
if (ar.versionAtLeast(version, 3)) {
ar.serialize("loadTime", ymf278LoadTime,
"busyTime", ymf278BusyTime);
} else {
assert(ar.isLoader());
// For 100% backwards compatibility we should restore these two
// from the (old) YMF278 class. Though that's a lot of extra
// work for very little gain.
ymf278LoadTime = getCurrentTime();
ymf278BusyTime = getCurrentTime();
}
}
INSTANTIATE_SERIALIZE_METHODS(MSXMoonSound);
REGISTER_MSXDEVICE(MSXMoonSound, "MoonSound");
} // namespace openmsx
|
*= $0801
.byte $4c,$16,$08,$00,$97,$32
.byte $2c,$30,$3a,$9e,$32,$30
.byte $37,$30,$00,$00,$00,$a9
.byte $01,$85,$02
jsr print
.byte 13
.text "(up)oraz"
.byte 0
lda #%00011011
sta db
lda #%11000110
sta ab
lda #%10110001
sta xb
lda #%01101100
sta yb
lda #0
sta pb
tsx
stx sb
lda #0
sta db
sta ab
next lda db
sta 172
sta dr
eor #$ff
sta cmdr+1
lda ab
eor #$ff
cmdr and #0
eor #$ff
sta ar
lda xb
sta xr
lda yb
sta yr
lda pb
ora #%00110000
and #%01111101
tax
lda ar
cmp #0
bne nozero
txa
ora #%00000010
tax
nozero lda ar
bpl noneg
txa
ora #%10000000
tax
noneg stx pr
lda sb
sta sr
ldx sb
txs
lda pb
pha
lda ab
ldx xb
ldy yb
plp
cmd ora 172
php
cld
sta aa
stx xa
sty ya
pla
sta pa
tsx
stx sa
lda 172
sta da
jsr check
clc
lda db
adc #17
sta db
bcc jmpnext
lda #0
sta db
clc
lda ab
adc #17
sta ab
bcc jmpnext
lda #0
sta ab
inc pb
beq nonext
jmpnext jmp next
nonext
jsr print
.text " - ok"
.byte 13,0
lda 2
beq load
wait jsr $ffe4
beq wait
jmp $8000
load jsr print
name .text "orazx"
namelen = *-name
.byte 0
lda #0
sta $0a
sta $b9
lda #namelen
sta $b7
lda #<name
sta $bb
lda #>name
sta $bc
pla
pla
jmp $e16f
db .byte 0
ab .byte 0
xb .byte 0
yb .byte 0
pb .byte 0
sb .byte 0
da .byte 0
aa .byte 0
xa .byte 0
ya .byte 0
pa .byte 0
sa .byte 0
dr .byte 0
ar .byte 0
xr .byte 0
yr .byte 0
pr .byte 0
sr .byte 0
check
.block
lda da
cmp dr
bne error
lda aa
cmp ar
bne error
lda xa
cmp xr
bne error
lda ya
cmp yr
bne error
lda pa
cmp pr
bne error
lda sa
cmp sr
bne error
rts
error jsr print
.byte 13
.null "before "
ldx #<db
ldy #>db
jsr showregs
jsr print
.byte 13
.null "after "
ldx #<da
ldy #>da
jsr showregs
jsr print
.byte 13
.null "right "
ldx #<dr
ldy #>dr
jsr showregs
lda #13
jsr $ffd2
wait jsr $ffe4
beq wait
cmp #3
beq stop
rts
stop lda 2
beq basic
jmp $8000
basic jmp ($a002)
showregs stx 172
sty 173
ldy #0
lda (172),y
jsr hexb
lda #32
jsr $ffd2
lda #32
jsr $ffd2
iny
lda (172),y
jsr hexb
lda #32
jsr $ffd2
iny
lda (172),y
jsr hexb
lda #32
jsr $ffd2
iny
lda (172),y
jsr hexb
lda #32
jsr $ffd2
iny
lda (172),y
ldx #"n"
asl a
bcc ok7
ldx #"N"
ok7 pha
txa
jsr $ffd2
pla
ldx #"v"
asl a
bcc ok6
ldx #"V"
ok6 pha
txa
jsr $ffd2
pla
ldx #"0"
asl a
bcc ok5
ldx #"1"
ok5 pha
txa
jsr $ffd2
pla
ldx #"b"
asl a
bcc ok4
ldx #"B"
ok4 pha
txa
jsr $ffd2
pla
ldx #"d"
asl a
bcc ok3
ldx #"D"
ok3 pha
txa
jsr $ffd2
pla
ldx #"i"
asl a
bcc ok2
ldx #"I"
ok2 pha
txa
jsr $ffd2
pla
ldx #"z"
asl a
bcc ok1
ldx #"Z"
ok1 pha
txa
jsr $ffd2
pla
ldx #"c"
asl a
bcc ok0
ldx #"C"
ok0 pha
txa
jsr $ffd2
pla
lda #32
jsr $ffd2
iny
lda (172),y
.bend
hexb pha
lsr a
lsr a
lsr a
lsr a
jsr hexn
pla
and #$0f
hexn ora #$30
cmp #$3a
bcc hexn0
adc #6
hexn0 jmp $ffd2
print pla
.block
sta print0+1
pla
sta print0+2
ldx #1
print0 lda !*,x
beq print1
jsr $ffd2
inx
bne print0
print1 sec
txa
adc print0+1
sta print2+1
lda #0
adc print0+2
sta print2+2
print2 jmp !*
.bend
|
; A012781: Take every 5th term of Padovan sequence A000931, beginning with the second term.
; 0,1,4,16,65,265,1081,4410,17991,73396,299426,1221537,4983377,20330163,82938844,338356945,1380359512,5631308624,22973462017,93722435101,382349636061,1559831901918,6363483400447,25960439030624,105908093453250,432062194544201,1762639037938629,7190854504969591,29335778567637640,119678113856248465,488238309515661356,1991814870720950560,8125799229398355841,33149974973623638321,135238492821245718801,551718363441132396562,2250787820894302745927,9182304143528229862188,37460087797505070723794,152822010234306736916145,623452004125041631547737,2543432067485486280797899,10376174331161571614714692,42330595389990954581929601,172691711692793972731587136,704512351235167616944931968,2874125504794653148380240897,11725269830725389246853063749,47834359485683501257689287125,195144843610310602449414421526,796112049939544396463168022879,3247815234742163073775871715416,13249772817562948385476100907090,54053715198785634028740185696665,220517299958418539675572396570381,899621411814513110648377340972335,3670091574437677028568337304276816,14972489524888751239923749554065121,61081702738507561195993775894190676,249188647167420478048842218558969712
lpb $0
sub $0,1
add $2,1
add $1,$2
sub $2,1
add $3,$1
add $2,$3
add $2,$1
lpe
mov $0,$1
|
include stdapp.def
include vm.def
include Objects/gCtrlC.def
include library.def
include resource.def ; idata/udata, ProcCallFixedOrMovable etc.
include gstring.def
UseLib math.def
include Internal/heapInt.def
ErrorHandlerContext struct
EHC_ss word
EHC_ds word
EHC_es word
EHC_di word
EHC_si word
EHC_cs word
EHC_ip word
EHC_sp word
EHC_bp word
EHC_stackBot word
ErrorHandlerContext ends
global _set_error_handler:far
SetDefaultConvention
; WARNING: THIS ROUTINE MUST BE LOCATED IN A FIXED RESOURCE! RCI WILL SCREW
; UP THE ALGORITHM IF IT OCCURS BETWEEN THIS ROUTINE AND ITS CALLER!
; Thanks for your cooperation. -Dave
ASM_FIXED segment resource
_set_error_handler proc far errorContextP:fptr.word
uses es, di
.enter
mov ax, size ErrorHandlerContext
mov cx, ALLOC_DYNAMIC_LOCK
call MemAlloc
tst bx
jz returnMem
mov cx, es ; original ES
mov es, ax
clr ax
mov es:[EHC_ss], ss
mov es:[EHC_ds], ds
mov es:[EHC_es], cx
mov es:[EHC_di], di
mov es:[EHC_si], si
mov ax, ss:[bp] ; caller's BP
mov es:[EHC_bp], ax
mov ax, ss:[bp]+2 ; return off
mov es:[EHC_ip], ax
mov ax, ss:[bp]+4 ; return seg
mov es:[EHC_cs], ax
mov ax, bp
add ax, 2 ; SP to return to caller
mov es:[EHC_sp], ax
mov ax, ss:[TPD_stackBot]
mov es:[EHC_stackBot], ax
call MemUnlock
returnMem:
mov es, errorContextP.segment
mov di, errorContextP.offset
mov es:[di], bx
mov ax, 0 ; error handler set
.leave
ret
_set_error_handler endp
SetGeosConvention
ASM_FIXED ends
|
MAIN: PUSH BYTE 72
OUT
EXIT
|
; void SMS_loadTiles(void *src, unsigned int tilefrom, unsigned int size)
SECTION code_clib
SECTION code_SMSlib
PUBLIC SMS_loadTiles
EXTERN asm_SMSlib_loadTiles
SMS_loadTiles:
pop af
pop bc
pop hl
pop de
push de
push hl
push bc
push af
jp asm_SMSlib_loadTiles
|
; Copyright 2021 Google LLC
;
; 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
;
; https://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.
; Microsoft x64 calling convention:
; https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention
; Arguments:
; RCX, RDX, R8, R9, [stack]...
; Results:
; RAX
; Non-volatile:
; RBX, RBP, RDI, RSI, RSP, R12, R13, R14, R15, and XMM6-XMM15
;
; System V AMD64 ABI (used in IREE):
; https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf
; Arguments:
; RDI, RSI, RDX, RCX, R8, R9, [stack]...
; Results:
; RAX, RDX
; Total size of non-volatile XMM registers.
_SYSV_INTEROP_STACK_SIZE = 10 * 10h
; Function prolog that saves registers that we may clobber while in code
; following the SYS-V x64 ABI.
;
; This also encodes unwind table information (.xdata/.pdata) that is used by
; debuggers/backtrace/etc to be able to look through the function on the stack.
; Though they debugger will be totally confused by the function we call into
; (it'll be expecting the Microsoft conventions and won't find them) it'll at
; least let us see the leaf guest function instead of just a bunch of our
; iree_elf_call_* thunks.
; Docs suck but we are in black magic territory so it's expected:
; https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=msvc-160#unwind-helpers-for-masm
_sysv_interop_prolog MACRO
; Save volatile general purpose registers to the stack.
push rbp
.pushreg rbp
mov rbp, rsp
.setframe rbp, 0
push rbx
.pushreg rbx
push rdi
.pushreg rdi
push rsi
.pushreg rsi
push r12
.pushreg r12
push r13
.pushreg r13
push r14
.pushreg r14
push r15
.pushreg r15
; Setup stack space for storing the SIMD registers.
; NOTE: we adjust this by 8 bytes to get on a 16-byte alignment so we can
; use the aligned movaps instruction.
sub rsp, _SYSV_INTEROP_STACK_SIZE + 8
.allocstack _SYSV_INTEROP_STACK_SIZE + 8
; Save volatile SIMD registers to the stack.
movaps [rsp + 00h], xmm6
.savexmm128 xmm6, 00h
movaps [rsp + 10h], xmm7
.savexmm128 xmm7, 10h
movaps [rsp + 20h], xmm8
.savexmm128 xmm8, 20h
movaps [rsp + 30h], xmm9
.savexmm128 xmm9, 30h
movaps [rsp + 40h], xmm10
.savexmm128 xmm10, 40h
movaps [rsp + 50h], xmm11
.savexmm128 xmm11, 50h
movaps [rsp + 60h], xmm12
.savexmm128 xmm12, 60h
movaps [rsp + 70h], xmm13
.savexmm128 xmm13, 70h
movaps [rsp + 80h], xmm14
.savexmm128 xmm14, 80h
movaps [rsp + 90h], xmm15
.savexmm128 xmm15, 90h
.endprolog
ENDM
; Function epilog that restores registers that we may have clobbered while in
; code following the SYS-V x64 ABI.
_sysv_interop_epilog MACRO
; Restore volatile SIMD registers from the stack.
movaps xmm6, [rsp + 00h]
movaps xmm7, [rsp + 10h]
movaps xmm8, [rsp + 20h]
movaps xmm9, [rsp + 30h]
movaps xmm10, [rsp + 40h]
movaps xmm11, [rsp + 50h]
movaps xmm12, [rsp + 60h]
movaps xmm13, [rsp + 70h]
movaps xmm14, [rsp + 80h]
movaps xmm15, [rsp + 90h]
add rsp, _SYSV_INTEROP_STACK_SIZE + 8
; Restore volatile general purpose registers from the stack.
pop r15
pop r14
pop r13
pop r12
pop rsi
pop rdi
pop rbx
leave ; mov rsp, rbp + pop ebp
ENDM
_TEXT SEGMENT
ALIGN 16
; void iree_elf_call_v_v(const void* symbol_ptr)
iree_elf_call_v_v PROC FRAME
_sysv_interop_prolog
; RCX = symbol_ptr
call rcx
_sysv_interop_epilog
ret
iree_elf_call_v_v ENDP
; void* iree_elf_call_p_i(const void* symbol_ptr, int a0)
iree_elf_call_p_i PROC FRAME
_sysv_interop_prolog
; RCX = symbol_ptr
; RDX = a0
mov rdi, rdx
call rcx
_sysv_interop_epilog
ret
iree_elf_call_p_i ENDP
; int iree_elf_call_i_pp(const void* symbol_ptr, void* a0, void* a1)
iree_elf_call_i_pp PROC FRAME
_sysv_interop_prolog
; RCX = symbol_ptr
; RDX = a0
; R8 = a1
mov rdi, rdx
mov rsi, r8
call rcx
_sysv_interop_epilog
ret
iree_elf_call_i_pp ENDP
_TEXT ENDS
END
|
; loop指令: 使用 cx 设置循环次数, 会自动将 cx 减一
; 标号:
; (循环体)...
; loop 标号
; 设定循环次数
mov cx, 100
; 初始化 ax
mov ax, 0x0000
; 循环
sum:
add ax, cx
loop sum
jmp $
times 510-($-$$) db 0
db 0x55, 0xaa |
; A125128: a(n) = 2^(n+1) - n - 2, or partial sums of main diagonal of array A125127 of k-step Lucas numbers.
; 1,4,11,26,57,120,247,502,1013,2036,4083,8178,16369,32752,65519,131054,262125,524268,1048555,2097130,4194281,8388584,16777191,33554406,67108837,134217700,268435427,536870882,1073741793,2147483616,4294967263,8589934558,17179869149,34359738332,68719476699,137438953434,274877906905,549755813848,1099511627735,2199023255510,4398046511061,8796093022164,17592186044371,35184372088786,70368744177617,140737488355280,281474976710607,562949953421262,1125899906842573,2251799813685196,4503599627370443
add $0,2
mov $1,2
pow $1,$0
sub $1,$0
sub $1,1
mov $0,$1
|
;;
;; (c) 2020 iomonad <clement@trosa.io>
;; This is part of the KFS Project
;; See: https://github.com/iomonad/KFS
;;
bits 32
;; Global Interrupt Table
;; assembly routine
global _idt_commit
_idt_commit:
mov eax, [esp+4] ; Load memory pointer
lidt [eax] ; Store IDT pointer on
ret
;;
;; Interrups implementations
;;
extern interrupt_handler ; High level Handler
;; IRQ Stub:
;; - Save processor state
;; - Setup kernel mode segment
;; - Call Highlevel C Handler
;; - Restore the stackframe
;;
interrupt_stub:
pusha ; Push all general purpose registers
mov ax, ds ; low 16bits eax
push eax ; save data segment descriptor
mov ax, 0x10 ; load the kernel data segment descriptor
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
call interrupt_handler ; C Implementations
pop eax ; Reload data segment descriptor
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
popa ; Pop all gener purpose registers
add esp, 8 ; Clean parameters
sti
;;
;; See: https://www.felixcloutier.com/x86/iret:iretd
;;
;; See the section titled “Task Linking” in Chapter 7 of
;; the Intel® 64 and IA-32 Architectures Software
;; Developer’s Manual, Volume 3A.
;;
iret ; Interrupt Return
;;
;; Routine Implementation
;;
%macro IRQ_NO_ERR 1
global irq%1
irq%1:
cli ; Clean Interrupt Flag
push byte 0
push byte %1 ; Push ID
jmp interrupt_stub
%endmacro
%macro IRQ_ERR 1
global irq%1
irq%1:
cli ; Clean Interrupt Flag
push byte %1 ; Push ID
jmp interrupt_stub
%endmacro
;; Create Interrupt here
IRQ_NO_ERR 0
IRQ_NO_ERR 1
IRQ_NO_ERR 2
IRQ_NO_ERR 3
IRQ_NO_ERR 4
IRQ_NO_ERR 5
IRQ_NO_ERR 6
IRQ_NO_ERR 7
IRQ_ERR 8
IRQ_NO_ERR 9
IRQ_ERR 10
IRQ_ERR 11
IRQ_ERR 12
IRQ_ERR 13
IRQ_ERR 14
IRQ_NO_ERR 15
IRQ_NO_ERR 16
|
TITLE DISPLAYING_STRING
.MODEL SMALL
.STACK 100H
.DATA
MSG DB 'THIS IS ASSEMBLY LANGUAGE BITCH!$'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX ;initialize DS
LEA DX, MSG ;get message by putting offset address of MSG into DX
MOV AH, 9 ;prepare to display, as it's a string output, we use 9
;for this routine
INT 021H ;display the message
MOV AH, 4CH ;after executing the program, control should return to DOS
;this is done by "INT 021H", function 4CH
INT 021H
MAIN ENDP
END MAIN |
; A170379: Number of reduced words of length n in Coxeter group on 34 generators S_i with relations (S_i)^2 = (S_i S_j)^43 = I.
; 1,34,1122,37026,1221858,40321314,1330603362,43909910946,1449027061218,47817893020194,1577990469666402,52073685498991266,1718431621466711778,56708243508401488674,1871372035777249126242,61755277180649221165986
add $0,1
mov $3,1
lpb $0
sub $0,1
add $2,$3
div $3,$2
mul $2,33
lpe
mov $0,$2
div $0,33
|
////////////////////////////////////////////////////////////////////////////
// Name: PromotedSilver.cpp
// Description: Implementation for a class that represents a Promoted Silver
// Created: May 1, 2004 08:32:17 PM
// Author: John Weathers
// Email: hotanguish@hotmail.com
// Copyright: (c) 2004 John Weathers
////////////////////////////////////////////////////////////////////////////
// mShogi header files
#include "PromotedSilver.hpp"
#include "Piece.hpp"
#include "Move.hpp"
#include "Board.hpp"
using std::vector;
using std::string;
//--------------------------------------------------------------------------
// Class: PromotedSilver
// Method: PromotedSilver
// Description: Constructs an instance of a promoted silver
//--------------------------------------------------------------------------
PromotedSilver::PromotedSilver(Board* board, int value, int typevalue)
{
mpBoard = board;
mValue = value;
mTypeValue = typevalue;
mSize = mpBoard->GetSize();
mNotation = "+S";
mNames[0] = "Promoted Silver"; mNames[1] = "Narigin";
mDescription =
"Moves 1 square in any direction except diagonally backwards";
int finish;
// Initialize the promoted silver's attack patterns
for (int color = 0; color < 2; color++) {
mAttackBitboards[color] = new Bitboard [mSize];
for (int start = 0; start < mSize; start++) {
mAttackBitboards[color][start].resize(mSize);
// northwest
finish = mpBoard->NorthWest(color, start);
if (finish != Board::OFF_BOARD) {
mAttackBitboards[color][start].set(finish);
}
// north
finish = mpBoard->North(color, start);
if (finish != Board::OFF_BOARD) {
mAttackBitboards[color][start].set(finish);
}
// northeast
finish = mpBoard->NorthEast(color, start);
if (finish != Board::OFF_BOARD) {
mAttackBitboards[color][start].set(finish);
}
// west
finish = mpBoard->West(color, start);
if (finish != Board::OFF_BOARD) {
mAttackBitboards[color][start].set(finish);
}
// east
finish = mpBoard->East(color, start);
if (finish != Board::OFF_BOARD) {
mAttackBitboards[color][start].set(finish);
}
// south
finish = mpBoard->South(color, start);
if (finish != Board::OFF_BOARD) {
mAttackBitboards[color][start].set(finish);
}
}
}
}
|
/// Json-cpp amalgamated source (http://jsoncpp.sourceforge.net/).
/// It is intended to be used with #include "json/json.h"
// //////////////////////////////////////////////////////////////////////
// Beginning of content of file: LICENSE
// //////////////////////////////////////////////////////////////////////
/*
The JsonCpp library's source code, including accompanying documentation,
tests and demonstration applications, are licensed under the following
conditions...
Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all
jurisdictions which recognize such a disclaimer. In such jurisdictions,
this software is released into the Public Domain.
In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and
The JsonCpp Authors, and is released under the terms of the MIT License (see below).
In jurisdictions which recognize Public Domain property, the user of this
software may choose to accept it either as 1) Public Domain, 2) under the
conditions of the MIT License (see below), or 3) under the terms of dual
Public Domain/MIT License conditions described here, as they choose.
The MIT License is about as close to Public Domain as a license can get, and is
described in clear, concise terms at:
http://en.wikipedia.org/wiki/MIT_License
The full text of the MIT License follows:
========================================================================
Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
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.
========================================================================
(END LICENSE TEXT)
The MIT license is compatible with both the GPL and commercial
software, affording one all of the rights of Public Domain with the
minor nuisance of being required to keep the above copyright notice
and license text in the source code. Note also that by accepting the
Public Domain "license" you can re-license your copy using whatever
license you like.
*/
// //////////////////////////////////////////////////////////////////////
// End of content of file: LICENSE
// //////////////////////////////////////////////////////////////////////
#include "json/json.h"
#ifndef JSON_IS_AMALGAMATION
#error "Compile with -I PATH_TO_JSON_DIRECTORY"
#endif
// //////////////////////////////////////////////////////////////////////
// Beginning of content of file: src/lib_json/json_tool.h
// //////////////////////////////////////////////////////////////////////
// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
#ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED
#define LIB_JSONCPP_JSON_TOOL_H_INCLUDED
#if !defined(JSON_IS_AMALGAMATION)
#include <json/config.h>
#endif
// Also support old flag NO_LOCALE_SUPPORT
#ifdef NO_LOCALE_SUPPORT
#define JSONCPP_NO_LOCALE_SUPPORT
#endif
#ifndef JSONCPP_NO_LOCALE_SUPPORT
#include <clocale>
#endif
/* This header provides common string manipulation support, such as UTF-8,
* portable conversion from/to string...
*
* It is an internal header that must not be exposed.
*/
namespace Json {
static inline char getDecimalPoint() {
#ifdef JSONCPP_NO_LOCALE_SUPPORT
return '\0';
#else
struct lconv* lc = localeconv();
return lc ? *(lc->decimal_point) : '\0';
#endif
}
/// Converts a unicode code-point to UTF-8.
static inline String codePointToUTF8(unsigned int cp) {
String result;
// based on description from http://en.wikipedia.org/wiki/UTF-8
if (cp <= 0x7f) {
result.resize(1);
result[0] = static_cast<char>(cp);
} else if (cp <= 0x7FF) {
result.resize(2);
result[1] = static_cast<char>(0x80 | (0x3f & cp));
result[0] = static_cast<char>(0xC0 | (0x1f & (cp >> 6)));
} else if (cp <= 0xFFFF) {
result.resize(3);
result[2] = static_cast<char>(0x80 | (0x3f & cp));
result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
result[0] = static_cast<char>(0xE0 | (0xf & (cp >> 12)));
} else if (cp <= 0x10FFFF) {
result.resize(4);
result[3] = static_cast<char>(0x80 | (0x3f & cp));
result[2] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 12)));
result[0] = static_cast<char>(0xF0 | (0x7 & (cp >> 18)));
}
return result;
}
enum {
/// Constant that specify the size of the buffer that must be passed to
/// uintToString.
uintToStringBufferSize = 3 * sizeof(LargestUInt) + 1
};
// Defines a char buffer for use with uintToString().
using UIntToStringBuffer = char[uintToStringBufferSize];
/** Converts an unsigned integer to string.
* @param value Unsigned integer to convert to string
* @param current Input/Output string buffer.
* Must have at least uintToStringBufferSize chars free.
*/
static inline void uintToString(LargestUInt value, char*& current) {
*--current = 0;
do {
*--current = static_cast<char>(value % 10U + static_cast<unsigned>('0'));
value /= 10;
} while (value != 0);
}
/** Change ',' to '.' everywhere in buffer.
*
* We had a sophisticated way, but it did not work in WinCE.
* @see https://github.com/open-source-parsers/jsoncpp/pull/9
*/
template <typename Iter> Iter fixNumericLocale(Iter begin, Iter end) {
for (; begin != end; ++begin) {
if (*begin == ',') {
*begin = '.';
}
}
return begin;
}
template <typename Iter> void fixNumericLocaleInput(Iter begin, Iter end) {
char decimalPoint = getDecimalPoint();
if (decimalPoint == '\0' || decimalPoint == '.') {
return;
}
for (; begin != end; ++begin) {
if (*begin == '.') {
*begin = decimalPoint;
}
}
}
/**
* Return iterator that would be the new end of the range [begin,end), if we
* were to delete zeros in the end of string, but not the last zero before '.'.
*/
template <typename Iter> Iter fixZerosInTheEnd(Iter begin, Iter end) {
for (; begin != end; --end) {
if (*(end - 1) != '0') {
return end;
}
// Don't delete the last zero before the decimal point.
if (begin != (end - 1) && *(end - 2) == '.') {
return end;
}
}
return end;
}
} // namespace Json
#endif // LIB_JSONCPP_JSON_TOOL_H_INCLUDED
// //////////////////////////////////////////////////////////////////////
// End of content of file: src/lib_json/json_tool.h
// //////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////
// Beginning of content of file: src/lib_json/json_reader.cpp
// //////////////////////////////////////////////////////////////////////
// Copyright 2007-2011 Baptiste Lepilleur and The JsonCpp Authors
// Copyright (C) 2016 InfoTeCS JSC. All rights reserved.
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
#if !defined(JSON_IS_AMALGAMATION)
#include "json_tool.h"
#include <json/assertions.h>
#include <json/reader.h>
#include <json/value.h>
#endif // if !defined(JSON_IS_AMALGAMATION)
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <istream>
#include <limits>
#include <memory>
#include <set>
#include <sstream>
#include <utility>
#include <cstdio>
#if __cplusplus >= 201103L
#if !defined(sscanf)
#define sscanf std::sscanf
#endif
#endif //__cplusplus
#if defined(_MSC_VER)
#if !defined(_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#endif //_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#endif //_MSC_VER
#if defined(_MSC_VER)
// Disable warning about strdup being deprecated.
#pragma warning(disable : 4996)
#endif
// Define JSONCPP_DEPRECATED_STACK_LIMIT as an appropriate integer at compile
// time to change the stack limit
#if !defined(JSONCPP_DEPRECATED_STACK_LIMIT)
#define JSONCPP_DEPRECATED_STACK_LIMIT 1000
#endif
static size_t const stackLimit_g =
JSONCPP_DEPRECATED_STACK_LIMIT; // see readValue()
namespace Json {
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
using CharReaderPtr = std::unique_ptr<CharReader>;
#else
using CharReaderPtr = std::auto_ptr<CharReader>;
#endif
// Implementation of class Features
// ////////////////////////////////
Features::Features() = default;
Features Features::all() { return {}; }
Features Features::strictMode() {
Features features;
features.allowComments_ = false;
features.strictRoot_ = true;
features.allowDroppedNullPlaceholders_ = false;
features.allowNumericKeys_ = false;
return features;
}
// Implementation of class Reader
// ////////////////////////////////
bool Reader::containsNewLine(Reader::Location begin, Reader::Location end) {
return std::any_of(begin, end, [](char b) { return b == '\n' || b == '\r'; });
}
// Class Reader
// //////////////////////////////////////////////////////////////////
Reader::Reader() : features_(Features::all()) {}
Reader::Reader(const Features& features) : features_(features) {}
bool Reader::parse(const std::string& document, Value& root,
bool collectComments) {
document_.assign(document.begin(), document.end());
const char* begin = document_.c_str();
const char* end = begin + document_.length();
return parse(begin, end, root, collectComments);
}
bool Reader::parse(std::istream& is, Value& root, bool collectComments) {
// std::istream_iterator<char> begin(is);
// std::istream_iterator<char> end;
// Those would allow streamed input from a file, if parse() were a
// template function.
// Since String is reference-counted, this at least does not
// create an extra copy.
String doc;
std::getline(is, doc, static_cast<char> EOF);
return parse(doc.data(), doc.data() + doc.size(), root, collectComments);
}
bool Reader::parse(const char* beginDoc, const char* endDoc, Value& root,
bool collectComments) {
if (!features_.allowComments_) {
collectComments = false;
}
begin_ = beginDoc;
end_ = endDoc;
collectComments_ = collectComments;
current_ = begin_;
lastValueEnd_ = nullptr;
lastValue_ = nullptr;
commentsBefore_.clear();
errors_.clear();
while (!nodes_.empty())
nodes_.pop();
nodes_.push(&root);
bool successful = readValue();
Token token;
skipCommentTokens(token);
if (collectComments_ && !commentsBefore_.empty())
root.setComment(commentsBefore_, commentAfter);
if (features_.strictRoot_) {
if (!root.isArray() && !root.isObject()) {
// Set error location to start of doc, ideally should be first token found
// in doc
token.type_ = tokenError;
token.start_ = beginDoc;
token.end_ = endDoc;
addError(
"A valid JSON document must be either an array or an object value.",
token);
return false;
}
}
return successful;
}
bool Reader::readValue() {
// readValue() may call itself only if it calls readObject() or ReadArray().
// These methods execute nodes_.push() just before and nodes_.pop)() just
// after calling readValue(). parse() executes one nodes_.push(), so > instead
// of >=.
if (nodes_.size() > stackLimit_g)
throwRuntimeError("Exceeded stackLimit in readValue().");
Token token;
skipCommentTokens(token);
bool successful = true;
if (collectComments_ && !commentsBefore_.empty()) {
currentValue().setComment(commentsBefore_, commentBefore);
commentsBefore_.clear();
}
switch (token.type_) {
case tokenObjectBegin:
successful = readObject(token);
currentValue().setOffsetLimit(current_ - begin_);
break;
case tokenArrayBegin:
successful = readArray(token);
currentValue().setOffsetLimit(current_ - begin_);
break;
case tokenNumber:
successful = decodeNumber(token);
break;
case tokenString:
successful = decodeString(token);
break;
case tokenTrue: {
Value v(true);
currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
} break;
case tokenFalse: {
Value v(false);
currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
} break;
case tokenNull: {
Value v;
currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
} break;
case tokenArraySeparator:
case tokenObjectEnd:
case tokenArrayEnd:
if (features_.allowDroppedNullPlaceholders_) {
// "Un-read" the current token and mark the current value as a null
// token.
current_--;
Value v;
currentValue().swapPayload(v);
currentValue().setOffsetStart(current_ - begin_ - 1);
currentValue().setOffsetLimit(current_ - begin_);
break;
} // Else, fall through...
default:
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
return addError("Syntax error: value, object or array expected.", token);
}
if (collectComments_) {
lastValueEnd_ = current_;
lastValue_ = ¤tValue();
}
return successful;
}
void Reader::skipCommentTokens(Token& token) {
if (features_.allowComments_) {
do {
readToken(token);
} while (token.type_ == tokenComment);
} else {
readToken(token);
}
}
bool Reader::readToken(Token& token) {
skipSpaces();
token.start_ = current_;
Char c = getNextChar();
bool ok = true;
switch (c) {
case '{':
token.type_ = tokenObjectBegin;
break;
case '}':
token.type_ = tokenObjectEnd;
break;
case '[':
token.type_ = tokenArrayBegin;
break;
case ']':
token.type_ = tokenArrayEnd;
break;
case '"':
token.type_ = tokenString;
ok = readString();
break;
case '/':
token.type_ = tokenComment;
ok = readComment();
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
token.type_ = tokenNumber;
readNumber();
break;
case 't':
token.type_ = tokenTrue;
ok = match("rue", 3);
break;
case 'f':
token.type_ = tokenFalse;
ok = match("alse", 4);
break;
case 'n':
token.type_ = tokenNull;
ok = match("ull", 3);
break;
case ',':
token.type_ = tokenArraySeparator;
break;
case ':':
token.type_ = tokenMemberSeparator;
break;
case 0:
token.type_ = tokenEndOfStream;
break;
default:
ok = false;
break;
}
if (!ok)
token.type_ = tokenError;
token.end_ = current_;
return ok;
}
void Reader::skipSpaces() {
while (current_ != end_) {
Char c = *current_;
if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
++current_;
else
break;
}
}
bool Reader::match(const Char* pattern, int patternLength) {
if (end_ - current_ < patternLength)
return false;
int index = patternLength;
while (index--)
if (current_[index] != pattern[index])
return false;
current_ += patternLength;
return true;
}
bool Reader::readComment() {
Location commentBegin = current_ - 1;
Char c = getNextChar();
bool successful = false;
if (c == '*')
successful = readCStyleComment();
else if (c == '/')
successful = readCppStyleComment();
if (!successful)
return false;
if (collectComments_) {
CommentPlacement placement = commentBefore;
if (lastValueEnd_ && !containsNewLine(lastValueEnd_, commentBegin)) {
if (c != '*' || !containsNewLine(commentBegin, current_))
placement = commentAfterOnSameLine;
}
addComment(commentBegin, current_, placement);
}
return true;
}
String Reader::normalizeEOL(Reader::Location begin, Reader::Location end) {
String normalized;
normalized.reserve(static_cast<size_t>(end - begin));
Reader::Location current = begin;
while (current != end) {
char c = *current++;
if (c == '\r') {
if (current != end && *current == '\n')
// convert dos EOL
++current;
// convert Mac EOL
normalized += '\n';
} else {
normalized += c;
}
}
return normalized;
}
void Reader::addComment(Location begin, Location end,
CommentPlacement placement) {
assert(collectComments_);
const String& normalized = normalizeEOL(begin, end);
if (placement == commentAfterOnSameLine) {
assert(lastValue_ != nullptr);
lastValue_->setComment(normalized, placement);
} else {
commentsBefore_ += normalized;
}
}
bool Reader::readCStyleComment() {
while ((current_ + 1) < end_) {
Char c = getNextChar();
if (c == '*' && *current_ == '/')
break;
}
return getNextChar() == '/';
}
bool Reader::readCppStyleComment() {
while (current_ != end_) {
Char c = getNextChar();
if (c == '\n')
break;
if (c == '\r') {
// Consume DOS EOL. It will be normalized in addComment.
if (current_ != end_ && *current_ == '\n')
getNextChar();
// Break on Moc OS 9 EOL.
break;
}
}
return true;
}
void Reader::readNumber() {
Location p = current_;
char c = '0'; // stopgap for already consumed character
// integral part
while (c >= '0' && c <= '9')
c = (current_ = p) < end_ ? *p++ : '\0';
// fractional part
if (c == '.') {
c = (current_ = p) < end_ ? *p++ : '\0';
while (c >= '0' && c <= '9')
c = (current_ = p) < end_ ? *p++ : '\0';
}
// exponential part
if (c == 'e' || c == 'E') {
c = (current_ = p) < end_ ? *p++ : '\0';
if (c == '+' || c == '-')
c = (current_ = p) < end_ ? *p++ : '\0';
while (c >= '0' && c <= '9')
c = (current_ = p) < end_ ? *p++ : '\0';
}
}
bool Reader::readString() {
Char c = '\0';
while (current_ != end_) {
c = getNextChar();
if (c == '\\')
getNextChar();
else if (c == '"')
break;
}
return c == '"';
}
bool Reader::readObject(Token& token) {
Token tokenName;
String name;
Value init(objectValue);
currentValue().swapPayload(init);
currentValue().setOffsetStart(token.start_ - begin_);
while (readToken(tokenName)) {
bool initialTokenOk = true;
while (tokenName.type_ == tokenComment && initialTokenOk)
initialTokenOk = readToken(tokenName);
if (!initialTokenOk)
break;
if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object
return true;
name.clear();
if (tokenName.type_ == tokenString) {
if (!decodeString(tokenName, name))
return recoverFromError(tokenObjectEnd);
} else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) {
Value numberName;
if (!decodeNumber(tokenName, numberName))
return recoverFromError(tokenObjectEnd);
name = numberName.asString();
} else {
break;
}
Token colon;
if (!readToken(colon) || colon.type_ != tokenMemberSeparator) {
return addErrorAndRecover("Missing ':' after object member name", colon,
tokenObjectEnd);
}
Value& value = currentValue()[name];
nodes_.push(&value);
bool ok = readValue();
nodes_.pop();
if (!ok) // error already set
return recoverFromError(tokenObjectEnd);
Token comma;
if (!readToken(comma) ||
(comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator &&
comma.type_ != tokenComment)) {
return addErrorAndRecover("Missing ',' or '}' in object declaration",
comma, tokenObjectEnd);
}
bool finalizeTokenOk = true;
while (comma.type_ == tokenComment && finalizeTokenOk)
finalizeTokenOk = readToken(comma);
if (comma.type_ == tokenObjectEnd)
return true;
}
return addErrorAndRecover("Missing '}' or object member name", tokenName,
tokenObjectEnd);
}
bool Reader::readArray(Token& token) {
Value init(arrayValue);
currentValue().swapPayload(init);
currentValue().setOffsetStart(token.start_ - begin_);
skipSpaces();
if (current_ != end_ && *current_ == ']') // empty array
{
Token endArray;
readToken(endArray);
return true;
}
int index = 0;
for (;;) {
Value& value = currentValue()[index++];
nodes_.push(&value);
bool ok = readValue();
nodes_.pop();
if (!ok) // error already set
return recoverFromError(tokenArrayEnd);
Token currentToken;
// Accept Comment after last item in the array.
ok = readToken(currentToken);
while (currentToken.type_ == tokenComment && ok) {
ok = readToken(currentToken);
}
bool badTokenType = (currentToken.type_ != tokenArraySeparator &&
currentToken.type_ != tokenArrayEnd);
if (!ok || badTokenType) {
return addErrorAndRecover("Missing ',' or ']' in array declaration",
currentToken, tokenArrayEnd);
}
if (currentToken.type_ == tokenArrayEnd)
break;
}
return true;
}
bool Reader::decodeNumber(Token& token) {
Value decoded;
if (!decodeNumber(token, decoded))
return false;
currentValue().swapPayload(decoded);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
return true;
}
bool Reader::decodeNumber(Token& token, Value& decoded) {
// Attempts to parse the number as an integer. If the number is
// larger than the maximum supported value of an integer then
// we decode the number as a double.
Location current = token.start_;
bool isNegative = *current == '-';
if (isNegative)
++current;
// TODO: Help the compiler do the div and mod at compile time or get rid of
// them.
Value::LargestUInt maxIntegerValue =
isNegative ? Value::LargestUInt(Value::maxLargestInt) + 1
: Value::maxLargestUInt;
Value::LargestUInt threshold = maxIntegerValue / 10;
Value::LargestUInt value = 0;
while (current < token.end_) {
Char c = *current++;
if (c < '0' || c > '9')
return decodeDouble(token, decoded);
auto digit(static_cast<Value::UInt>(c - '0'));
if (value >= threshold) {
// We've hit or exceeded the max value divided by 10 (rounded down). If
// a) we've only just touched the limit, b) this is the last digit, and
// c) it's small enough to fit in that rounding delta, we're okay.
// Otherwise treat this number as a double to avoid overflow.
if (value > threshold || current != token.end_ ||
digit > maxIntegerValue % 10) {
return decodeDouble(token, decoded);
}
}
value = value * 10 + digit;
}
if (isNegative && value == maxIntegerValue)
decoded = Value::minLargestInt;
else if (isNegative)
decoded = -Value::LargestInt(value);
else if (value <= Value::LargestUInt(Value::maxInt))
decoded = Value::LargestInt(value);
else
decoded = value;
return true;
}
bool Reader::decodeDouble(Token& token) {
Value decoded;
if (!decodeDouble(token, decoded))
return false;
currentValue().swapPayload(decoded);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
return true;
}
bool Reader::decodeDouble(Token& token, Value& decoded) {
double value = 0;
String buffer(token.start_, token.end_);
IStringStream is(buffer);
if (!(is >> value))
return addError(
"'" + String(token.start_, token.end_) + "' is not a number.", token);
decoded = value;
return true;
}
bool Reader::decodeString(Token& token) {
String decoded_string;
if (!decodeString(token, decoded_string))
return false;
Value decoded(decoded_string);
currentValue().swapPayload(decoded);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
return true;
}
bool Reader::decodeString(Token& token, String& decoded) {
decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
Location current = token.start_ + 1; // skip '"'
Location end = token.end_ - 1; // do not include '"'
while (current != end) {
Char c = *current++;
if (c == '"')
break;
if (c == '\\') {
if (current == end)
return addError("Empty escape sequence in string", token, current);
Char escape = *current++;
switch (escape) {
case '"':
decoded += '"';
break;
case '/':
decoded += '/';
break;
case '\\':
decoded += '\\';
break;
case 'b':
decoded += '\b';
break;
case 'f':
decoded += '\f';
break;
case 'n':
decoded += '\n';
break;
case 'r':
decoded += '\r';
break;
case 't':
decoded += '\t';
break;
case 'u': {
unsigned int unicode;
if (!decodeUnicodeCodePoint(token, current, end, unicode))
return false;
decoded += codePointToUTF8(unicode);
} break;
default:
return addError("Bad escape sequence in string", token, current);
}
} else {
decoded += c;
}
}
return true;
}
bool Reader::decodeUnicodeCodePoint(Token& token, Location& current,
Location end, unsigned int& unicode) {
if (!decodeUnicodeEscapeSequence(token, current, end, unicode))
return false;
if (unicode >= 0xD800 && unicode <= 0xDBFF) {
// surrogate pairs
if (end - current < 6)
return addError(
"additional six characters expected to parse unicode surrogate pair.",
token, current);
if (*(current++) == '\\' && *(current++) == 'u') {
unsigned int surrogatePair;
if (decodeUnicodeEscapeSequence(token, current, end, surrogatePair)) {
unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF);
} else
return false;
} else
return addError("expecting another \\u token to begin the second half of "
"a unicode surrogate pair",
token, current);
}
return true;
}
bool Reader::decodeUnicodeEscapeSequence(Token& token, Location& current,
Location end,
unsigned int& ret_unicode) {
if (end - current < 4)
return addError(
"Bad unicode escape sequence in string: four digits expected.", token,
current);
int unicode = 0;
for (int index = 0; index < 4; ++index) {
Char c = *current++;
unicode *= 16;
if (c >= '0' && c <= '9')
unicode += c - '0';
else if (c >= 'a' && c <= 'f')
unicode += c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
unicode += c - 'A' + 10;
else
return addError(
"Bad unicode escape sequence in string: hexadecimal digit expected.",
token, current);
}
ret_unicode = static_cast<unsigned int>(unicode);
return true;
}
bool Reader::addError(const String& message, Token& token, Location extra) {
ErrorInfo info;
info.token_ = token;
info.message_ = message;
info.extra_ = extra;
errors_.push_back(info);
return false;
}
bool Reader::recoverFromError(TokenType skipUntilToken) {
size_t const errorCount = errors_.size();
Token skip;
for (;;) {
if (!readToken(skip))
errors_.resize(errorCount); // discard errors caused by recovery
if (skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream)
break;
}
errors_.resize(errorCount);
return false;
}
bool Reader::addErrorAndRecover(const String& message, Token& token,
TokenType skipUntilToken) {
addError(message, token);
return recoverFromError(skipUntilToken);
}
Value& Reader::currentValue() { return *(nodes_.top()); }
Reader::Char Reader::getNextChar() {
if (current_ == end_)
return 0;
return *current_++;
}
void Reader::getLocationLineAndColumn(Location location, int& line,
int& column) const {
Location current = begin_;
Location lastLineStart = current;
line = 0;
while (current < location && current != end_) {
Char c = *current++;
if (c == '\r') {
if (*current == '\n')
++current;
lastLineStart = current;
++line;
} else if (c == '\n') {
lastLineStart = current;
++line;
}
}
// column & line start at 1
column = int(location - lastLineStart) + 1;
++line;
}
String Reader::getLocationLineAndColumn(Location location) const {
int line, column;
getLocationLineAndColumn(location, line, column);
char buffer[18 + 16 + 16 + 1];
jsoncpp_snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column);
return buffer;
}
// Deprecated. Preserved for backward compatibility
String Reader::getFormatedErrorMessages() const {
return getFormattedErrorMessages();
}
String Reader::getFormattedErrorMessages() const {
String formattedMessage;
for (const auto& error : errors_) {
formattedMessage +=
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
formattedMessage += " " + error.message_ + "\n";
if (error.extra_)
formattedMessage +=
"See " + getLocationLineAndColumn(error.extra_) + " for detail.\n";
}
return formattedMessage;
}
std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
std::vector<Reader::StructuredError> allErrors;
for (const auto& error : errors_) {
Reader::StructuredError structured;
structured.offset_start = error.token_.start_ - begin_;
structured.offset_limit = error.token_.end_ - begin_;
structured.message = error.message_;
allErrors.push_back(structured);
}
return allErrors;
}
bool Reader::pushError(const Value& value, const String& message) {
ptrdiff_t const length = end_ - begin_;
if (value.getOffsetStart() > length || value.getOffsetLimit() > length)
return false;
Token token;
token.type_ = tokenError;
token.start_ = begin_ + value.getOffsetStart();
token.end_ = begin_ + value.getOffsetLimit();
ErrorInfo info;
info.token_ = token;
info.message_ = message;
info.extra_ = nullptr;
errors_.push_back(info);
return true;
}
bool Reader::pushError(const Value& value, const String& message,
const Value& extra) {
ptrdiff_t const length = end_ - begin_;
if (value.getOffsetStart() > length || value.getOffsetLimit() > length ||
extra.getOffsetLimit() > length)
return false;
Token token;
token.type_ = tokenError;
token.start_ = begin_ + value.getOffsetStart();
token.end_ = begin_ + value.getOffsetLimit();
ErrorInfo info;
info.token_ = token;
info.message_ = message;
info.extra_ = begin_ + extra.getOffsetStart();
errors_.push_back(info);
return true;
}
bool Reader::good() const { return errors_.empty(); }
// Originally copied from the Features class (now deprecated), used internally
// for features implementation.
class OurFeatures {
public:
static OurFeatures all();
bool allowComments_;
bool allowTrailingCommas_;
bool strictRoot_;
bool allowDroppedNullPlaceholders_;
bool allowNumericKeys_;
bool allowSingleQuotes_;
bool failIfExtra_;
bool rejectDupKeys_;
bool allowSpecialFloats_;
bool skipBom_;
size_t stackLimit_;
}; // OurFeatures
OurFeatures OurFeatures::all() { return {}; }
// Implementation of class Reader
// ////////////////////////////////
// Originally copied from the Reader class (now deprecated), used internally
// for implementing JSON reading.
class OurReader {
public:
using Char = char;
using Location = const Char*;
struct StructuredError {
ptrdiff_t offset_start;
ptrdiff_t offset_limit;
String message;
};
explicit OurReader(OurFeatures const& features);
bool parse(const char* beginDoc, const char* endDoc, Value& root,
bool collectComments = true);
String getFormattedErrorMessages() const;
std::vector<StructuredError> getStructuredErrors() const;
private:
OurReader(OurReader const&); // no impl
void operator=(OurReader const&); // no impl
enum TokenType {
tokenEndOfStream = 0,
tokenObjectBegin,
tokenObjectEnd,
tokenArrayBegin,
tokenArrayEnd,
tokenString,
tokenNumber,
tokenTrue,
tokenFalse,
tokenNull,
tokenNaN,
tokenPosInf,
tokenNegInf,
tokenArraySeparator,
tokenMemberSeparator,
tokenComment,
tokenError
};
class Token {
public:
TokenType type_;
Location start_;
Location end_;
};
class ErrorInfo {
public:
Token token_;
String message_;
Location extra_;
};
using Errors = std::deque<ErrorInfo>;
bool readToken(Token& token);
void skipSpaces();
void skipBom(bool skipBom);
bool match(const Char* pattern, int patternLength);
bool readComment();
bool readCStyleComment(bool* containsNewLineResult);
bool readCppStyleComment();
bool readString();
bool readStringSingleQuote();
bool readNumber(bool checkInf);
bool readValue();
bool readObject(Token& token);
bool readArray(Token& token);
bool decodeNumber(Token& token);
bool decodeNumber(Token& token, Value& decoded);
bool decodeString(Token& token);
bool decodeString(Token& token, String& decoded);
bool decodeDouble(Token& token);
bool decodeDouble(Token& token, Value& decoded);
bool decodeUnicodeCodePoint(Token& token, Location& current, Location end,
unsigned int& unicode);
bool decodeUnicodeEscapeSequence(Token& token, Location& current,
Location end, unsigned int& unicode);
bool addError(const String& message, Token& token, Location extra = nullptr);
bool recoverFromError(TokenType skipUntilToken);
bool addErrorAndRecover(const String& message, Token& token,
TokenType skipUntilToken);
void skipUntilSpace();
Value& currentValue();
Char getNextChar();
void getLocationLineAndColumn(Location location, int& line,
int& column) const;
String getLocationLineAndColumn(Location location) const;
void addComment(Location begin, Location end, CommentPlacement placement);
void skipCommentTokens(Token& token);
static String normalizeEOL(Location begin, Location end);
static bool containsNewLine(Location begin, Location end);
using Nodes = std::stack<Value*>;
Nodes nodes_{};
Errors errors_{};
String document_{};
Location begin_ = nullptr;
Location end_ = nullptr;
Location current_ = nullptr;
Location lastValueEnd_ = nullptr;
Value* lastValue_ = nullptr;
bool lastValueHasAComment_ = false;
String commentsBefore_{};
OurFeatures const features_;
bool collectComments_ = false;
}; // OurReader
// complete copy of Read impl, for OurReader
bool OurReader::containsNewLine(OurReader::Location begin,
OurReader::Location end) {
return std::any_of(begin, end, [](char b) { return b == '\n' || b == '\r'; });
}
OurReader::OurReader(OurFeatures const& features) : features_(features) {}
bool OurReader::parse(const char* beginDoc, const char* endDoc, Value& root,
bool collectComments) {
if (!features_.allowComments_) {
collectComments = false;
}
begin_ = beginDoc;
end_ = endDoc;
collectComments_ = collectComments;
current_ = begin_;
lastValueEnd_ = nullptr;
lastValue_ = nullptr;
commentsBefore_.clear();
errors_.clear();
while (!nodes_.empty())
nodes_.pop();
nodes_.push(&root);
// skip byte order mark if it exists at the beginning of the UTF-8 text.
skipBom(features_.skipBom_);
bool successful = readValue();
nodes_.pop();
Token token;
skipCommentTokens(token);
if (features_.failIfExtra_ && (token.type_ != tokenEndOfStream)) {
addError("Extra non-whitespace after JSON value.", token);
return false;
}
if (collectComments_ && !commentsBefore_.empty())
root.setComment(commentsBefore_, commentAfter);
if (features_.strictRoot_) {
if (!root.isArray() && !root.isObject()) {
// Set error location to start of doc, ideally should be first token found
// in doc
token.type_ = tokenError;
token.start_ = beginDoc;
token.end_ = endDoc;
addError(
"A valid JSON document must be either an array or an object value.",
token);
return false;
}
}
return successful;
}
bool OurReader::readValue() {
// To preserve the old behaviour we cast size_t to int.
if (nodes_.size() > features_.stackLimit_)
throwRuntimeError("Exceeded stackLimit in readValue().");
Token token;
skipCommentTokens(token);
bool successful = true;
if (collectComments_ && !commentsBefore_.empty()) {
currentValue().setComment(commentsBefore_, commentBefore);
commentsBefore_.clear();
}
switch (token.type_) {
case tokenObjectBegin:
successful = readObject(token);
currentValue().setOffsetLimit(current_ - begin_);
break;
case tokenArrayBegin:
successful = readArray(token);
currentValue().setOffsetLimit(current_ - begin_);
break;
case tokenNumber:
successful = decodeNumber(token);
break;
case tokenString:
successful = decodeString(token);
break;
case tokenTrue: {
Value v(true);
currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
} break;
case tokenFalse: {
Value v(false);
currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
} break;
case tokenNull: {
Value v;
currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
} break;
case tokenNaN: {
Value v(std::numeric_limits<double>::quiet_NaN());
currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
} break;
case tokenPosInf: {
Value v(std::numeric_limits<double>::infinity());
currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
} break;
case tokenNegInf: {
Value v(-std::numeric_limits<double>::infinity());
currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
} break;
case tokenArraySeparator:
case tokenObjectEnd:
case tokenArrayEnd:
if (features_.allowDroppedNullPlaceholders_) {
// "Un-read" the current token and mark the current value as a null
// token.
current_--;
Value v;
currentValue().swapPayload(v);
currentValue().setOffsetStart(current_ - begin_ - 1);
currentValue().setOffsetLimit(current_ - begin_);
break;
} // else, fall through ...
default:
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
return addError("Syntax error: value, object or array expected.", token);
}
if (collectComments_) {
lastValueEnd_ = current_;
lastValueHasAComment_ = false;
lastValue_ = ¤tValue();
}
return successful;
}
void OurReader::skipCommentTokens(Token& token) {
if (features_.allowComments_) {
do {
readToken(token);
} while (token.type_ == tokenComment);
} else {
readToken(token);
}
}
bool OurReader::readToken(Token& token) {
skipSpaces();
token.start_ = current_;
Char c = getNextChar();
bool ok = true;
switch (c) {
case '{':
token.type_ = tokenObjectBegin;
break;
case '}':
token.type_ = tokenObjectEnd;
break;
case '[':
token.type_ = tokenArrayBegin;
break;
case ']':
token.type_ = tokenArrayEnd;
break;
case '"':
token.type_ = tokenString;
ok = readString();
break;
case '\'':
if (features_.allowSingleQuotes_) {
token.type_ = tokenString;
ok = readStringSingleQuote();
} else {
// If we don't allow single quotes, this is a failure case.
ok = false;
}
break;
case '/':
token.type_ = tokenComment;
ok = readComment();
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
token.type_ = tokenNumber;
readNumber(false);
break;
case '-':
if (readNumber(true)) {
token.type_ = tokenNumber;
} else {
token.type_ = tokenNegInf;
ok = features_.allowSpecialFloats_ && match("nfinity", 7);
}
break;
case '+':
if (readNumber(true)) {
token.type_ = tokenNumber;
} else {
token.type_ = tokenPosInf;
ok = features_.allowSpecialFloats_ && match("nfinity", 7);
}
break;
case 't':
token.type_ = tokenTrue;
ok = match("rue", 3);
break;
case 'f':
token.type_ = tokenFalse;
ok = match("alse", 4);
break;
case 'n':
token.type_ = tokenNull;
ok = match("ull", 3);
break;
case 'N':
if (features_.allowSpecialFloats_) {
token.type_ = tokenNaN;
ok = match("aN", 2);
} else {
ok = false;
}
break;
case 'I':
if (features_.allowSpecialFloats_) {
token.type_ = tokenPosInf;
ok = match("nfinity", 7);
} else {
ok = false;
}
break;
case ',':
token.type_ = tokenArraySeparator;
break;
case ':':
token.type_ = tokenMemberSeparator;
break;
case 0:
token.type_ = tokenEndOfStream;
break;
default:
ok = false;
break;
}
if (!ok)
token.type_ = tokenError;
token.end_ = current_;
return ok;
}
void OurReader::skipSpaces() {
while (current_ != end_) {
Char c = *current_;
if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
++current_;
else
break;
}
}
void OurReader::skipBom(bool skipBom) {
// The default behavior is to skip BOM.
if (skipBom) {
if ((end_ - begin_) >= 3 && strncmp(begin_, "\xEF\xBB\xBF", 3) == 0) {
begin_ += 3;
current_ = begin_;
}
}
}
bool OurReader::match(const Char* pattern, int patternLength) {
if (end_ - current_ < patternLength)
return false;
int index = patternLength;
while (index--)
if (current_[index] != pattern[index])
return false;
current_ += patternLength;
return true;
}
bool OurReader::readComment() {
const Location commentBegin = current_ - 1;
const Char c = getNextChar();
bool successful = false;
bool cStyleWithEmbeddedNewline = false;
const bool isCStyleComment = (c == '*');
const bool isCppStyleComment = (c == '/');
if (isCStyleComment) {
successful = readCStyleComment(&cStyleWithEmbeddedNewline);
} else if (isCppStyleComment) {
successful = readCppStyleComment();
}
if (!successful)
return false;
if (collectComments_) {
CommentPlacement placement = commentBefore;
if (!lastValueHasAComment_) {
if (lastValueEnd_ && !containsNewLine(lastValueEnd_, commentBegin)) {
if (isCppStyleComment || !cStyleWithEmbeddedNewline) {
placement = commentAfterOnSameLine;
lastValueHasAComment_ = true;
}
}
}
addComment(commentBegin, current_, placement);
}
return true;
}
String OurReader::normalizeEOL(OurReader::Location begin,
OurReader::Location end) {
String normalized;
normalized.reserve(static_cast<size_t>(end - begin));
OurReader::Location current = begin;
while (current != end) {
char c = *current++;
if (c == '\r') {
if (current != end && *current == '\n')
// convert dos EOL
++current;
// convert Mac EOL
normalized += '\n';
} else {
normalized += c;
}
}
return normalized;
}
void OurReader::addComment(Location begin, Location end,
CommentPlacement placement) {
assert(collectComments_);
const String& normalized = normalizeEOL(begin, end);
if (placement == commentAfterOnSameLine) {
assert(lastValue_ != nullptr);
lastValue_->setComment(normalized, placement);
} else {
commentsBefore_ += normalized;
}
}
bool OurReader::readCStyleComment(bool* containsNewLineResult) {
*containsNewLineResult = false;
while ((current_ + 1) < end_) {
Char c = getNextChar();
if (c == '*' && *current_ == '/')
break;
if (c == '\n')
*containsNewLineResult = true;
}
return getNextChar() == '/';
}
bool OurReader::readCppStyleComment() {
while (current_ != end_) {
Char c = getNextChar();
if (c == '\n')
break;
if (c == '\r') {
// Consume DOS EOL. It will be normalized in addComment.
if (current_ != end_ && *current_ == '\n')
getNextChar();
// Break on Moc OS 9 EOL.
break;
}
}
return true;
}
bool OurReader::readNumber(bool checkInf) {
Location p = current_;
if (checkInf && p != end_ && *p == 'I') {
current_ = ++p;
return false;
}
char c = '0'; // stopgap for already consumed character
// integral part
while (c >= '0' && c <= '9')
c = (current_ = p) < end_ ? *p++ : '\0';
// fractional part
if (c == '.') {
c = (current_ = p) < end_ ? *p++ : '\0';
while (c >= '0' && c <= '9')
c = (current_ = p) < end_ ? *p++ : '\0';
}
// exponential part
if (c == 'e' || c == 'E') {
c = (current_ = p) < end_ ? *p++ : '\0';
if (c == '+' || c == '-')
c = (current_ = p) < end_ ? *p++ : '\0';
while (c >= '0' && c <= '9')
c = (current_ = p) < end_ ? *p++ : '\0';
}
return true;
}
bool OurReader::readString() {
Char c = 0;
while (current_ != end_) {
c = getNextChar();
if (c == '\\')
getNextChar();
else if (c == '"')
break;
}
return c == '"';
}
bool OurReader::readStringSingleQuote() {
Char c = 0;
while (current_ != end_) {
c = getNextChar();
if (c == '\\')
getNextChar();
else if (c == '\'')
break;
}
return c == '\'';
}
bool OurReader::readObject(Token& token) {
Token tokenName;
String name;
Value init(objectValue);
currentValue().swapPayload(init);
currentValue().setOffsetStart(token.start_ - begin_);
while (readToken(tokenName)) {
bool initialTokenOk = true;
while (tokenName.type_ == tokenComment && initialTokenOk)
initialTokenOk = readToken(tokenName);
if (!initialTokenOk)
break;
if (tokenName.type_ == tokenObjectEnd &&
(name.empty() ||
features_.allowTrailingCommas_)) // empty object or trailing comma
return true;
name.clear();
if (tokenName.type_ == tokenString) {
if (!decodeString(tokenName, name))
return recoverFromError(tokenObjectEnd);
} else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) {
Value numberName;
if (!decodeNumber(tokenName, numberName))
return recoverFromError(tokenObjectEnd);
name = numberName.asString();
} else {
break;
}
if (name.length() >= (1U << 30))
throwRuntimeError("keylength >= 2^30");
if (features_.rejectDupKeys_ && currentValue().isMember(name)) {
String msg = "Duplicate key: '" + name + "'";
return addErrorAndRecover(msg, tokenName, tokenObjectEnd);
}
Token colon;
if (!readToken(colon) || colon.type_ != tokenMemberSeparator) {
return addErrorAndRecover("Missing ':' after object member name", colon,
tokenObjectEnd);
}
Value& value = currentValue()[name];
nodes_.push(&value);
bool ok = readValue();
nodes_.pop();
if (!ok) // error already set
return recoverFromError(tokenObjectEnd);
Token comma;
if (!readToken(comma) ||
(comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator &&
comma.type_ != tokenComment)) {
return addErrorAndRecover("Missing ',' or '}' in object declaration",
comma, tokenObjectEnd);
}
bool finalizeTokenOk = true;
while (comma.type_ == tokenComment && finalizeTokenOk)
finalizeTokenOk = readToken(comma);
if (comma.type_ == tokenObjectEnd)
return true;
}
return addErrorAndRecover("Missing '}' or object member name", tokenName,
tokenObjectEnd);
}
bool OurReader::readArray(Token& token) {
Value init(arrayValue);
currentValue().swapPayload(init);
currentValue().setOffsetStart(token.start_ - begin_);
int index = 0;
for (;;) {
skipSpaces();
if (current_ != end_ && *current_ == ']' &&
(index == 0 ||
(features_.allowTrailingCommas_ &&
!features_.allowDroppedNullPlaceholders_))) // empty array or trailing
// comma
{
Token endArray;
readToken(endArray);
return true;
}
Value& value = currentValue()[index++];
nodes_.push(&value);
bool ok = readValue();
nodes_.pop();
if (!ok) // error already set
return recoverFromError(tokenArrayEnd);
Token currentToken;
// Accept Comment after last item in the array.
ok = readToken(currentToken);
while (currentToken.type_ == tokenComment && ok) {
ok = readToken(currentToken);
}
bool badTokenType = (currentToken.type_ != tokenArraySeparator &&
currentToken.type_ != tokenArrayEnd);
if (!ok || badTokenType) {
return addErrorAndRecover("Missing ',' or ']' in array declaration",
currentToken, tokenArrayEnd);
}
if (currentToken.type_ == tokenArrayEnd)
break;
}
return true;
}
bool OurReader::decodeNumber(Token& token) {
Value decoded;
if (!decodeNumber(token, decoded))
return false;
currentValue().swapPayload(decoded);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
return true;
}
bool OurReader::decodeNumber(Token& token, Value& decoded) {
// Attempts to parse the number as an integer. If the number is
// larger than the maximum supported value of an integer then
// we decode the number as a double.
Location current = token.start_;
const bool isNegative = *current == '-';
if (isNegative) {
++current;
}
// We assume we can represent the largest and smallest integer types as
// unsigned integers with separate sign. This is only true if they can fit
// into an unsigned integer.
static_assert(Value::maxLargestInt <= Value::maxLargestUInt,
"Int must be smaller than UInt");
// We need to convert minLargestInt into a positive number. The easiest way
// to do this conversion is to assume our "threshold" value of minLargestInt
// divided by 10 can fit in maxLargestInt when absolute valued. This should
// be a safe assumption.
static_assert(Value::minLargestInt <= -Value::maxLargestInt,
"The absolute value of minLargestInt must be greater than or "
"equal to maxLargestInt");
static_assert(Value::minLargestInt / 10 >= -Value::maxLargestInt,
"The absolute value of minLargestInt must be only 1 magnitude "
"larger than maxLargest Int");
static constexpr Value::LargestUInt positive_threshold =
Value::maxLargestUInt / 10;
static constexpr Value::UInt positive_last_digit = Value::maxLargestUInt % 10;
// For the negative values, we have to be more careful. Since typically
// -Value::minLargestInt will cause an overflow, we first divide by 10 and
// then take the inverse. This assumes that minLargestInt is only a single
// power of 10 different in magnitude, which we check above. For the last
// digit, we take the modulus before negating for the same reason.
static constexpr auto negative_threshold =
Value::LargestUInt(-(Value::minLargestInt / 10));
static constexpr auto negative_last_digit =
Value::UInt(-(Value::minLargestInt % 10));
const Value::LargestUInt threshold =
isNegative ? negative_threshold : positive_threshold;
const Value::UInt max_last_digit =
isNegative ? negative_last_digit : positive_last_digit;
Value::LargestUInt value = 0;
while (current < token.end_) {
Char c = *current++;
if (c < '0' || c > '9')
return decodeDouble(token, decoded);
const auto digit(static_cast<Value::UInt>(c - '0'));
if (value >= threshold) {
// We've hit or exceeded the max value divided by 10 (rounded down). If
// a) we've only just touched the limit, meaing value == threshold,
// b) this is the last digit, or
// c) it's small enough to fit in that rounding delta, we're okay.
// Otherwise treat this number as a double to avoid overflow.
if (value > threshold || current != token.end_ ||
digit > max_last_digit) {
return decodeDouble(token, decoded);
}
}
value = value * 10 + digit;
}
if (isNegative) {
// We use the same magnitude assumption here, just in case.
const auto last_digit = static_cast<Value::UInt>(value % 10);
decoded = -Value::LargestInt(value / 10) * 10 - last_digit;
} else if (value <= Value::LargestUInt(Value::maxLargestInt)) {
decoded = Value::LargestInt(value);
} else {
decoded = value;
}
return true;
}
bool OurReader::decodeDouble(Token& token) {
Value decoded;
if (!decodeDouble(token, decoded))
return false;
currentValue().swapPayload(decoded);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
return true;
}
bool OurReader::decodeDouble(Token& token, Value& decoded) {
double value = 0;
const String buffer(token.start_, token.end_);
IStringStream is(buffer);
if (!(is >> value)) {
return addError(
"'" + String(token.start_, token.end_) + "' is not a number.", token);
}
decoded = value;
return true;
}
bool OurReader::decodeString(Token& token) {
String decoded_string;
if (!decodeString(token, decoded_string))
return false;
Value decoded(decoded_string);
currentValue().swapPayload(decoded);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
return true;
}
bool OurReader::decodeString(Token& token, String& decoded) {
decoded.reserve(static_cast<size_t>(token.end_ - token.start_ - 2));
Location current = token.start_ + 1; // skip '"'
Location end = token.end_ - 1; // do not include '"'
while (current != end) {
Char c = *current++;
if (c == '"')
break;
if (c == '\\') {
if (current == end)
return addError("Empty escape sequence in string", token, current);
Char escape = *current++;
switch (escape) {
case '"':
decoded += '"';
break;
case '/':
decoded += '/';
break;
case '\\':
decoded += '\\';
break;
case 'b':
decoded += '\b';
break;
case 'f':
decoded += '\f';
break;
case 'n':
decoded += '\n';
break;
case 'r':
decoded += '\r';
break;
case 't':
decoded += '\t';
break;
case 'u': {
unsigned int unicode;
if (!decodeUnicodeCodePoint(token, current, end, unicode))
return false;
decoded += codePointToUTF8(unicode);
} break;
default:
return addError("Bad escape sequence in string", token, current);
}
} else {
decoded += c;
}
}
return true;
}
bool OurReader::decodeUnicodeCodePoint(Token& token, Location& current,
Location end, unsigned int& unicode) {
if (!decodeUnicodeEscapeSequence(token, current, end, unicode))
return false;
if (unicode >= 0xD800 && unicode <= 0xDBFF) {
// surrogate pairs
if (end - current < 6)
return addError(
"additional six characters expected to parse unicode surrogate pair.",
token, current);
if (*(current++) == '\\' && *(current++) == 'u') {
unsigned int surrogatePair;
if (decodeUnicodeEscapeSequence(token, current, end, surrogatePair)) {
unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF);
} else
return false;
} else
return addError("expecting another \\u token to begin the second half of "
"a unicode surrogate pair",
token, current);
}
return true;
}
bool OurReader::decodeUnicodeEscapeSequence(Token& token, Location& current,
Location end,
unsigned int& ret_unicode) {
if (end - current < 4)
return addError(
"Bad unicode escape sequence in string: four digits expected.", token,
current);
int unicode = 0;
for (int index = 0; index < 4; ++index) {
Char c = *current++;
unicode *= 16;
if (c >= '0' && c <= '9')
unicode += c - '0';
else if (c >= 'a' && c <= 'f')
unicode += c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
unicode += c - 'A' + 10;
else
return addError(
"Bad unicode escape sequence in string: hexadecimal digit expected.",
token, current);
}
ret_unicode = static_cast<unsigned int>(unicode);
return true;
}
bool OurReader::addError(const String& message, Token& token, Location extra) {
ErrorInfo info;
info.token_ = token;
info.message_ = message;
info.extra_ = extra;
errors_.push_back(info);
return false;
}
bool OurReader::recoverFromError(TokenType skipUntilToken) {
size_t errorCount = errors_.size();
Token skip;
for (;;) {
if (!readToken(skip))
errors_.resize(errorCount); // discard errors caused by recovery
if (skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream)
break;
}
errors_.resize(errorCount);
return false;
}
bool OurReader::addErrorAndRecover(const String& message, Token& token,
TokenType skipUntilToken) {
addError(message, token);
return recoverFromError(skipUntilToken);
}
Value& OurReader::currentValue() { return *(nodes_.top()); }
OurReader::Char OurReader::getNextChar() {
if (current_ == end_)
return 0;
return *current_++;
}
void OurReader::getLocationLineAndColumn(Location location, int& line,
int& column) const {
Location current = begin_;
Location lastLineStart = current;
line = 0;
while (current < location && current != end_) {
Char c = *current++;
if (c == '\r') {
if (*current == '\n')
++current;
lastLineStart = current;
++line;
} else if (c == '\n') {
lastLineStart = current;
++line;
}
}
// column & line start at 1
column = int(location - lastLineStart) + 1;
++line;
}
String OurReader::getLocationLineAndColumn(Location location) const {
int line, column;
getLocationLineAndColumn(location, line, column);
char buffer[18 + 16 + 16 + 1];
jsoncpp_snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column);
return buffer;
}
String OurReader::getFormattedErrorMessages() const {
String formattedMessage;
for (const auto& error : errors_) {
formattedMessage +=
"* " + getLocationLineAndColumn(error.token_.start_) + "\n";
formattedMessage += " " + error.message_ + "\n";
if (error.extra_)
formattedMessage +=
"See " + getLocationLineAndColumn(error.extra_) + " for detail.\n";
}
return formattedMessage;
}
std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
std::vector<OurReader::StructuredError> allErrors;
for (const auto& error : errors_) {
OurReader::StructuredError structured;
structured.offset_start = error.token_.start_ - begin_;
structured.offset_limit = error.token_.end_ - begin_;
structured.message = error.message_;
allErrors.push_back(structured);
}
return allErrors;
}
class OurCharReader : public CharReader {
bool const collectComments_;
OurReader reader_;
public:
OurCharReader(bool collectComments, OurFeatures const& features)
: collectComments_(collectComments), reader_(features) {}
bool parse(char const* beginDoc, char const* endDoc, Value* root,
String* errs) override {
bool ok = reader_.parse(beginDoc, endDoc, *root, collectComments_);
if (errs) {
*errs = reader_.getFormattedErrorMessages();
}
return ok;
}
};
CharReaderBuilder::CharReaderBuilder() { setDefaults(&settings_); }
CharReaderBuilder::~CharReaderBuilder() = default;
CharReader* CharReaderBuilder::newCharReader() const {
bool collectComments = settings_["collectComments"].asBool();
OurFeatures features = OurFeatures::all();
features.allowComments_ = settings_["allowComments"].asBool();
features.allowTrailingCommas_ = settings_["allowTrailingCommas"].asBool();
features.strictRoot_ = settings_["strictRoot"].asBool();
features.allowDroppedNullPlaceholders_ =
settings_["allowDroppedNullPlaceholders"].asBool();
features.allowNumericKeys_ = settings_["allowNumericKeys"].asBool();
features.allowSingleQuotes_ = settings_["allowSingleQuotes"].asBool();
// Stack limit is always a size_t, so we get this as an unsigned int
// regardless of it we have 64-bit integer support enabled.
features.stackLimit_ = static_cast<size_t>(settings_["stackLimit"].asUInt());
features.failIfExtra_ = settings_["failIfExtra"].asBool();
features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool();
features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool();
features.skipBom_ = settings_["skipBom"].asBool();
return new OurCharReader(collectComments, features);
}
bool CharReaderBuilder::validate(Json::Value* invalid) const {
static const auto& valid_keys = *new std::set<String>{
"collectComments",
"allowComments",
"allowTrailingCommas",
"strictRoot",
"allowDroppedNullPlaceholders",
"allowNumericKeys",
"allowSingleQuotes",
"stackLimit",
"failIfExtra",
"rejectDupKeys",
"allowSpecialFloats",
"skipBom",
};
for (auto si = settings_.begin(); si != settings_.end(); ++si) {
auto key = si.name();
if (valid_keys.count(key))
continue;
if (invalid)
(*invalid)[std::move(key)] = *si;
else
return false;
}
return invalid ? invalid->empty() : true;
}
Value& CharReaderBuilder::operator[](const String& key) {
return settings_[key];
}
// static
void CharReaderBuilder::strictMode(Json::Value* settings) {
//! [CharReaderBuilderStrictMode]
(*settings)["allowComments"] = false;
(*settings)["allowTrailingCommas"] = false;
(*settings)["strictRoot"] = true;
(*settings)["allowDroppedNullPlaceholders"] = false;
(*settings)["allowNumericKeys"] = false;
(*settings)["allowSingleQuotes"] = false;
(*settings)["stackLimit"] = 1000;
(*settings)["failIfExtra"] = true;
(*settings)["rejectDupKeys"] = true;
(*settings)["allowSpecialFloats"] = false;
(*settings)["skipBom"] = true;
//! [CharReaderBuilderStrictMode]
}
// static
void CharReaderBuilder::setDefaults(Json::Value* settings) {
//! [CharReaderBuilderDefaults]
(*settings)["collectComments"] = true;
(*settings)["allowComments"] = true;
(*settings)["allowTrailingCommas"] = true;
(*settings)["strictRoot"] = false;
(*settings)["allowDroppedNullPlaceholders"] = false;
(*settings)["allowNumericKeys"] = false;
(*settings)["allowSingleQuotes"] = false;
(*settings)["stackLimit"] = 1000;
(*settings)["failIfExtra"] = false;
(*settings)["rejectDupKeys"] = false;
(*settings)["allowSpecialFloats"] = false;
(*settings)["skipBom"] = true;
//! [CharReaderBuilderDefaults]
}
//////////////////////////////////
// global functions
bool parseFromStream(CharReader::Factory const& fact, IStream& sin, Value* root,
String* errs) {
OStringStream ssin;
ssin << sin.rdbuf();
String doc = ssin.str();
char const* begin = doc.data();
char const* end = begin + doc.size();
// Note that we do not actually need a null-terminator.
CharReaderPtr const reader(fact.newCharReader());
return reader->parse(begin, end, root, errs);
}
IStream& operator>>(IStream& sin, Value& root) {
CharReaderBuilder b;
String errs;
bool ok = parseFromStream(b, sin, &root, &errs);
if (!ok) {
throwRuntimeError(errs);
}
return sin;
}
} // namespace Json
// //////////////////////////////////////////////////////////////////////
// End of content of file: src/lib_json/json_reader.cpp
// //////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////
// Beginning of content of file: src/lib_json/json_valueiterator.inl
// //////////////////////////////////////////////////////////////////////
// Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
// included by json_value.cpp
namespace Json {
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// class ValueIteratorBase
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
ValueIteratorBase::ValueIteratorBase() : current_() {}
ValueIteratorBase::ValueIteratorBase(
const Value::ObjectValues::iterator& current)
: current_(current), isNull_(false) {}
Value& ValueIteratorBase::deref() { return current_->second; }
const Value& ValueIteratorBase::deref() const { return current_->second; }
void ValueIteratorBase::increment() { ++current_; }
void ValueIteratorBase::decrement() { --current_; }
ValueIteratorBase::difference_type
ValueIteratorBase::computeDistance(const SelfType& other) const {
// Iterator for null value are initialized using the default
// constructor, which initialize current_ to the default
// std::map::iterator. As begin() and end() are two instance
// of the default std::map::iterator, they can not be compared.
// To allow this, we handle this comparison specifically.
if (isNull_ && other.isNull_) {
return 0;
}
// Usage of std::distance is not portable (does not compile with Sun Studio 12
// RogueWave STL,
// which is the one used by default).
// Using a portable hand-made version for non random iterator instead:
// return difference_type( std::distance( current_, other.current_ ) );
difference_type myDistance = 0;
for (Value::ObjectValues::iterator it = current_; it != other.current_;
++it) {
++myDistance;
}
return myDistance;
}
bool ValueIteratorBase::isEqual(const SelfType& other) const {
if (isNull_) {
return other.isNull_;
}
return current_ == other.current_;
}
void ValueIteratorBase::copy(const SelfType& other) {
current_ = other.current_;
isNull_ = other.isNull_;
}
Value ValueIteratorBase::key() const {
const Value::CZString czstring = (*current_).first;
if (czstring.data()) {
if (czstring.isStaticString())
return Value(StaticString(czstring.data()));
return Value(czstring.data(), czstring.data() + czstring.length());
}
return Value(czstring.index());
}
UInt ValueIteratorBase::index() const {
const Value::CZString czstring = (*current_).first;
if (!czstring.data())
return czstring.index();
return Value::UInt(-1);
}
String ValueIteratorBase::name() const {
char const* keey;
char const* end;
keey = memberName(&end);
if (!keey)
return String();
return String(keey, end);
}
char const* ValueIteratorBase::memberName() const {
const char* cname = (*current_).first.data();
return cname ? cname : "";
}
char const* ValueIteratorBase::memberName(char const** end) const {
const char* cname = (*current_).first.data();
if (!cname) {
*end = nullptr;
return nullptr;
}
*end = cname + (*current_).first.length();
return cname;
}
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// class ValueConstIterator
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
ValueConstIterator::ValueConstIterator() = default;
ValueConstIterator::ValueConstIterator(
const Value::ObjectValues::iterator& current)
: ValueIteratorBase(current) {}
ValueConstIterator::ValueConstIterator(ValueIterator const& other)
: ValueIteratorBase(other) {}
ValueConstIterator& ValueConstIterator::
operator=(const ValueIteratorBase& other) {
copy(other);
return *this;
}
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// class ValueIterator
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
ValueIterator::ValueIterator() = default;
ValueIterator::ValueIterator(const Value::ObjectValues::iterator& current)
: ValueIteratorBase(current) {}
ValueIterator::ValueIterator(const ValueConstIterator& other)
: ValueIteratorBase(other) {
throwRuntimeError("ConstIterator to Iterator should never be allowed.");
}
ValueIterator::ValueIterator(const ValueIterator& other) = default;
ValueIterator& ValueIterator::operator=(const SelfType& other) {
copy(other);
return *this;
}
} // namespace Json
// //////////////////////////////////////////////////////////////////////
// End of content of file: src/lib_json/json_valueiterator.inl
// //////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////
// Beginning of content of file: src/lib_json/json_value.cpp
// //////////////////////////////////////////////////////////////////////
// Copyright 2011 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
#if !defined(JSON_IS_AMALGAMATION)
#include <json/assertions.h>
#include <json/value.h>
#include <json/writer.h>
#endif // if !defined(JSON_IS_AMALGAMATION)
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <cstring>
#include <iostream>
#include <sstream>
#include <utility>
// Provide implementation equivalent of std::snprintf for older _MSC compilers
#if defined(_MSC_VER) && _MSC_VER < 1900
#include <stdarg.h>
static int msvc_pre1900_c99_vsnprintf(char* outBuf, size_t size,
const char* format, va_list ap) {
int count = -1;
if (size != 0)
count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
if (count == -1)
count = _vscprintf(format, ap);
return count;
}
int JSON_API msvc_pre1900_c99_snprintf(char* outBuf, size_t size,
const char* format, ...) {
va_list ap;
va_start(ap, format);
const int count = msvc_pre1900_c99_vsnprintf(outBuf, size, format, ap);
va_end(ap);
return count;
}
#endif
// Disable warning C4702 : unreachable code
#if defined(_MSC_VER)
#pragma warning(disable : 4702)
#endif
#define JSON_ASSERT_UNREACHABLE assert(false)
namespace Json {
template <typename T>
static std::unique_ptr<T> cloneUnique(const std::unique_ptr<T>& p) {
std::unique_ptr<T> r;
if (p) {
r = std::unique_ptr<T>(new T(*p));
}
return r;
}
// This is a walkaround to avoid the static initialization of Value::null.
// kNull must be word-aligned to avoid crashing on ARM. We use an alignment of
// 8 (instead of 4) as a bit of future-proofing.
#if defined(__ARMEL__)
#define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
#else
#define ALIGNAS(byte_alignment)
#endif
// static
Value const& Value::nullSingleton() {
static Value const nullStatic;
return nullStatic;
}
#if JSON_USE_NULLREF
// for backwards compatibility, we'll leave these global references around, but
// DO NOT use them in JSONCPP library code any more!
// static
Value const& Value::null = Value::nullSingleton();
// static
Value const& Value::nullRef = Value::nullSingleton();
#endif
#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
template <typename T, typename U>
static inline bool InRange(double d, T min, U max) {
// The casts can lose precision, but we are looking only for
// an approximate range. Might fail on edge cases though. ~cdunn
return d >= static_cast<double>(min) && d <= static_cast<double>(max);
}
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
static inline double integerToDouble(Json::UInt64 value) {
return static_cast<double>(Int64(value / 2)) * 2.0 +
static_cast<double>(Int64(value & 1));
}
template <typename T> static inline double integerToDouble(T value) {
return static_cast<double>(value);
}
template <typename T, typename U>
static inline bool InRange(double d, T min, U max) {
return d >= integerToDouble(min) && d <= integerToDouble(max);
}
#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
/** Duplicates the specified string value.
* @param value Pointer to the string to duplicate. Must be zero-terminated if
* length is "unknown".
* @param length Length of the value. if equals to unknown, then it will be
* computed using strlen(value).
* @return Pointer on the duplicate instance of string.
*/
static inline char* duplicateStringValue(const char* value, size_t length) {
// Avoid an integer overflow in the call to malloc below by limiting length
// to a sane value.
if (length >= static_cast<size_t>(Value::maxInt))
length = Value::maxInt - 1;
auto newString = static_cast<char*>(malloc(length + 1));
if (newString == nullptr) {
throwRuntimeError("in Json::Value::duplicateStringValue(): "
"Failed to allocate string value buffer");
}
memcpy(newString, value, length);
newString[length] = 0;
return newString;
}
/* Record the length as a prefix.
*/
static inline char* duplicateAndPrefixStringValue(const char* value,
unsigned int length) {
// Avoid an integer overflow in the call to malloc below by limiting length
// to a sane value.
JSON_ASSERT_MESSAGE(length <= static_cast<unsigned>(Value::maxInt) -
sizeof(unsigned) - 1U,
"in Json::Value::duplicateAndPrefixStringValue(): "
"length too big for prefixing");
size_t actualLength = sizeof(length) + length + 1;
auto newString = static_cast<char*>(malloc(actualLength));
if (newString == nullptr) {
throwRuntimeError("in Json::Value::duplicateAndPrefixStringValue(): "
"Failed to allocate string value buffer");
}
*reinterpret_cast<unsigned*>(newString) = length;
memcpy(newString + sizeof(unsigned), value, length);
newString[actualLength - 1U] =
0; // to avoid buffer over-run accidents by users later
return newString;
}
inline static void decodePrefixedString(bool isPrefixed, char const* prefixed,
unsigned* length, char const** value) {
if (!isPrefixed) {
*length = static_cast<unsigned>(strlen(prefixed));
*value = prefixed;
} else {
*length = *reinterpret_cast<unsigned const*>(prefixed);
*value = prefixed + sizeof(unsigned);
}
}
/** Free the string duplicated by
* duplicateStringValue()/duplicateAndPrefixStringValue().
*/
#if JSONCPP_USING_SECURE_MEMORY
static inline void releasePrefixedStringValue(char* value) {
unsigned length = 0;
char const* valueDecoded;
decodePrefixedString(true, value, &length, &valueDecoded);
size_t const size = sizeof(unsigned) + length + 1U;
memset(value, 0, size);
free(value);
}
static inline void releaseStringValue(char* value, unsigned length) {
// length==0 => we allocated the strings memory
size_t size = (length == 0) ? strlen(value) : length;
memset(value, 0, size);
free(value);
}
#else // !JSONCPP_USING_SECURE_MEMORY
static inline void releasePrefixedStringValue(char* value) { free(value); }
static inline void releaseStringValue(char* value, unsigned) { free(value); }
#endif // JSONCPP_USING_SECURE_MEMORY
} // namespace Json
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// ValueInternals...
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
#if !defined(JSON_IS_AMALGAMATION)
#include "json_valueiterator.inl"
#endif // if !defined(JSON_IS_AMALGAMATION)
namespace Json {
#if JSON_USE_EXCEPTION
Exception::Exception(String msg) : msg_(std::move(msg)) {}
Exception::~Exception() noexcept = default;
char const* Exception::what() const noexcept { return msg_.c_str(); }
RuntimeError::RuntimeError(String const& msg) : Exception(msg) {}
LogicError::LogicError(String const& msg) : Exception(msg) {}
JSONCPP_NORETURN void throwRuntimeError(String const& msg) {
throw RuntimeError(msg);
}
JSONCPP_NORETURN void throwLogicError(String const& msg) {
throw LogicError(msg);
}
#else // !JSON_USE_EXCEPTION
JSONCPP_NORETURN void throwRuntimeError(String const& msg) {
std::cerr << msg << std::endl;
abort();
}
JSONCPP_NORETURN void throwLogicError(String const& msg) {
std::cerr << msg << std::endl;
abort();
}
#endif
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// class Value::CZString
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// Notes: policy_ indicates if the string was allocated when
// a string is stored.
Value::CZString::CZString(ArrayIndex index) : cstr_(nullptr), index_(index) {}
Value::CZString::CZString(char const* str, unsigned length,
DuplicationPolicy allocate)
: cstr_(str) {
// allocate != duplicate
storage_.policy_ = allocate & 0x3;
storage_.length_ = length & 0x3FFFFFFF;
}
Value::CZString::CZString(const CZString& other) {
cstr_ = (other.storage_.policy_ != noDuplication && other.cstr_ != nullptr
? duplicateStringValue(other.cstr_, other.storage_.length_)
: other.cstr_);
storage_.policy_ =
static_cast<unsigned>(
other.cstr_
? (static_cast<DuplicationPolicy>(other.storage_.policy_) ==
noDuplication
? noDuplication
: duplicate)
: static_cast<DuplicationPolicy>(other.storage_.policy_)) &
3U;
storage_.length_ = other.storage_.length_;
}
Value::CZString::CZString(CZString&& other)
: cstr_(other.cstr_), index_(other.index_) {
other.cstr_ = nullptr;
}
Value::CZString::~CZString() {
if (cstr_ && storage_.policy_ == duplicate) {
releaseStringValue(const_cast<char*>(cstr_),
storage_.length_ + 1U); // +1 for null terminating
// character for sake of
// completeness but not actually
// necessary
}
}
void Value::CZString::swap(CZString& other) {
std::swap(cstr_, other.cstr_);
std::swap(index_, other.index_);
}
Value::CZString& Value::CZString::operator=(const CZString& other) {
cstr_ = other.cstr_;
index_ = other.index_;
return *this;
}
Value::CZString& Value::CZString::operator=(CZString&& other) {
cstr_ = other.cstr_;
index_ = other.index_;
other.cstr_ = nullptr;
return *this;
}
bool Value::CZString::operator<(const CZString& other) const {
if (!cstr_)
return index_ < other.index_;
// return strcmp(cstr_, other.cstr_) < 0;
// Assume both are strings.
unsigned this_len = this->storage_.length_;
unsigned other_len = other.storage_.length_;
unsigned min_len = std::min<unsigned>(this_len, other_len);
JSON_ASSERT(this->cstr_ && other.cstr_);
int comp = memcmp(this->cstr_, other.cstr_, min_len);
if (comp < 0)
return true;
if (comp > 0)
return false;
return (this_len < other_len);
}
bool Value::CZString::operator==(const CZString& other) const {
if (!cstr_)
return index_ == other.index_;
// return strcmp(cstr_, other.cstr_) == 0;
// Assume both are strings.
unsigned this_len = this->storage_.length_;
unsigned other_len = other.storage_.length_;
if (this_len != other_len)
return false;
JSON_ASSERT(this->cstr_ && other.cstr_);
int comp = memcmp(this->cstr_, other.cstr_, this_len);
return comp == 0;
}
ArrayIndex Value::CZString::index() const { return index_; }
// const char* Value::CZString::c_str() const { return cstr_; }
const char* Value::CZString::data() const { return cstr_; }
unsigned Value::CZString::length() const { return storage_.length_; }
bool Value::CZString::isStaticString() const {
return storage_.policy_ == noDuplication;
}
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// class Value::Value
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
/*! \internal Default constructor initialization must be equivalent to:
* memset( this, 0, sizeof(Value) )
* This optimization is used in ValueInternalMap fast allocator.
*/
Value::Value(ValueType type) {
static char const emptyString[] = "";
initBasic(type);
switch (type) {
case nullValue:
break;
case intValue:
case uintValue:
value_.int_ = 0;
break;
case realValue:
value_.real_ = 0.0;
break;
case stringValue:
// allocated_ == false, so this is safe.
value_.string_ = const_cast<char*>(static_cast<char const*>(emptyString));
break;
case arrayValue:
case objectValue:
value_.map_ = new ObjectValues();
break;
case booleanValue:
value_.bool_ = false;
break;
default:
JSON_ASSERT_UNREACHABLE;
}
}
Value::Value(Int value) {
initBasic(intValue);
value_.int_ = value;
}
Value::Value(UInt value) {
initBasic(uintValue);
value_.uint_ = value;
}
#if defined(JSON_HAS_INT64)
Value::Value(Int64 value) {
initBasic(intValue);
value_.int_ = value;
}
Value::Value(UInt64 value) {
initBasic(uintValue);
value_.uint_ = value;
}
#endif // defined(JSON_HAS_INT64)
Value::Value(double value) {
initBasic(realValue);
value_.real_ = value;
}
Value::Value(const char* value) {
initBasic(stringValue, true);
JSON_ASSERT_MESSAGE(value != nullptr,
"Null Value Passed to Value Constructor");
value_.string_ = duplicateAndPrefixStringValue(
value, static_cast<unsigned>(strlen(value)));
}
Value::Value(const char* begin, const char* end) {
initBasic(stringValue, true);
value_.string_ =
duplicateAndPrefixStringValue(begin, static_cast<unsigned>(end - begin));
}
Value::Value(const String& value) {
initBasic(stringValue, true);
value_.string_ = duplicateAndPrefixStringValue(
value.data(), static_cast<unsigned>(value.length()));
}
Value::Value(const StaticString& value) {
initBasic(stringValue);
value_.string_ = const_cast<char*>(value.c_str());
}
Value::Value(bool value) {
initBasic(booleanValue);
value_.bool_ = value;
}
Value::Value(const Value& other) {
dupPayload(other);
dupMeta(other);
}
Value::Value(Value&& other) {
initBasic(nullValue);
swap(other);
}
Value::~Value() {
releasePayload();
value_.uint_ = 0;
}
Value& Value::operator=(const Value& other) {
Value(other).swap(*this);
return *this;
}
Value& Value::operator=(Value&& other) {
other.swap(*this);
return *this;
}
void Value::swapPayload(Value& other) {
std::swap(bits_, other.bits_);
std::swap(value_, other.value_);
}
void Value::copyPayload(const Value& other) {
releasePayload();
dupPayload(other);
}
void Value::swap(Value& other) {
swapPayload(other);
std::swap(comments_, other.comments_);
std::swap(start_, other.start_);
std::swap(limit_, other.limit_);
}
void Value::copy(const Value& other) {
copyPayload(other);
dupMeta(other);
}
ValueType Value::type() const {
return static_cast<ValueType>(bits_.value_type_);
}
int Value::compare(const Value& other) const {
if (*this < other)
return -1;
if (*this > other)
return 1;
return 0;
}
bool Value::operator<(const Value& other) const {
int typeDelta = type() - other.type();
if (typeDelta)
return typeDelta < 0;
switch (type()) {
case nullValue:
return false;
case intValue:
return value_.int_ < other.value_.int_;
case uintValue:
return value_.uint_ < other.value_.uint_;
case realValue:
return value_.real_ < other.value_.real_;
case booleanValue:
return value_.bool_ < other.value_.bool_;
case stringValue: {
if ((value_.string_ == nullptr) || (other.value_.string_ == nullptr)) {
return other.value_.string_ != nullptr;
}
unsigned this_len;
unsigned other_len;
char const* this_str;
char const* other_str;
decodePrefixedString(this->isAllocated(), this->value_.string_, &this_len,
&this_str);
decodePrefixedString(other.isAllocated(), other.value_.string_, &other_len,
&other_str);
unsigned min_len = std::min<unsigned>(this_len, other_len);
JSON_ASSERT(this_str && other_str);
int comp = memcmp(this_str, other_str, min_len);
if (comp < 0)
return true;
if (comp > 0)
return false;
return (this_len < other_len);
}
case arrayValue:
case objectValue: {
auto thisSize = value_.map_->size();
auto otherSize = other.value_.map_->size();
if (thisSize != otherSize)
return thisSize < otherSize;
return (*value_.map_) < (*other.value_.map_);
}
default:
JSON_ASSERT_UNREACHABLE;
}
return false; // unreachable
}
bool Value::operator<=(const Value& other) const { return !(other < *this); }
bool Value::operator>=(const Value& other) const { return !(*this < other); }
bool Value::operator>(const Value& other) const { return other < *this; }
bool Value::operator==(const Value& other) const {
if (type() != other.type())
return false;
switch (type()) {
case nullValue:
return true;
case intValue:
return value_.int_ == other.value_.int_;
case uintValue:
return value_.uint_ == other.value_.uint_;
case realValue:
return value_.real_ == other.value_.real_;
case booleanValue:
return value_.bool_ == other.value_.bool_;
case stringValue: {
if ((value_.string_ == nullptr) || (other.value_.string_ == nullptr)) {
return (value_.string_ == other.value_.string_);
}
unsigned this_len;
unsigned other_len;
char const* this_str;
char const* other_str;
decodePrefixedString(this->isAllocated(), this->value_.string_, &this_len,
&this_str);
decodePrefixedString(other.isAllocated(), other.value_.string_, &other_len,
&other_str);
if (this_len != other_len)
return false;
JSON_ASSERT(this_str && other_str);
int comp = memcmp(this_str, other_str, this_len);
return comp == 0;
}
case arrayValue:
case objectValue:
return value_.map_->size() == other.value_.map_->size() &&
(*value_.map_) == (*other.value_.map_);
default:
JSON_ASSERT_UNREACHABLE;
}
return false; // unreachable
}
bool Value::operator!=(const Value& other) const { return !(*this == other); }
const char* Value::asCString() const {
JSON_ASSERT_MESSAGE(type() == stringValue,
"in Json::Value::asCString(): requires stringValue");
if (value_.string_ == nullptr)
return nullptr;
unsigned this_len;
char const* this_str;
decodePrefixedString(this->isAllocated(), this->value_.string_, &this_len,
&this_str);
return this_str;
}
#if JSONCPP_USING_SECURE_MEMORY
unsigned Value::getCStringLength() const {
JSON_ASSERT_MESSAGE(type() == stringValue,
"in Json::Value::asCString(): requires stringValue");
if (value_.string_ == 0)
return 0;
unsigned this_len;
char const* this_str;
decodePrefixedString(this->isAllocated(), this->value_.string_, &this_len,
&this_str);
return this_len;
}
#endif
bool Value::getString(char const** begin, char const** end) const {
if (type() != stringValue)
return false;
if (value_.string_ == nullptr)
return false;
unsigned length;
decodePrefixedString(this->isAllocated(), this->value_.string_, &length,
begin);
*end = *begin + length;
return true;
}
String Value::asString() const {
switch (type()) {
case nullValue:
return "";
case stringValue: {
if (value_.string_ == nullptr)
return "";
unsigned this_len;
char const* this_str;
decodePrefixedString(this->isAllocated(), this->value_.string_, &this_len,
&this_str);
return String(this_str, this_len);
}
case booleanValue:
return value_.bool_ ? "true" : "false";
case intValue:
return valueToString(value_.int_);
case uintValue:
return valueToString(value_.uint_);
case realValue:
return valueToString(value_.real_);
default:
JSON_FAIL_MESSAGE("Type is not convertible to string");
}
}
Value::Int Value::asInt() const {
switch (type()) {
case intValue:
JSON_ASSERT_MESSAGE(isInt(), "LargestInt out of Int range");
return Int(value_.int_);
case uintValue:
JSON_ASSERT_MESSAGE(isInt(), "LargestUInt out of Int range");
return Int(value_.uint_);
case realValue:
JSON_ASSERT_MESSAGE(InRange(value_.real_, minInt, maxInt),
"double out of Int range");
return Int(value_.real_);
case nullValue:
return 0;
case booleanValue:
return value_.bool_ ? 1 : 0;
default:
break;
}
JSON_FAIL_MESSAGE("Value is not convertible to Int.");
}
Value::UInt Value::asUInt() const {
switch (type()) {
case intValue:
JSON_ASSERT_MESSAGE(isUInt(), "LargestInt out of UInt range");
return UInt(value_.int_);
case uintValue:
JSON_ASSERT_MESSAGE(isUInt(), "LargestUInt out of UInt range");
return UInt(value_.uint_);
case realValue:
JSON_ASSERT_MESSAGE(InRange(value_.real_, 0, maxUInt),
"double out of UInt range");
return UInt(value_.real_);
case nullValue:
return 0;
case booleanValue:
return value_.bool_ ? 1 : 0;
default:
break;
}
JSON_FAIL_MESSAGE("Value is not convertible to UInt.");
}
#if defined(JSON_HAS_INT64)
Value::Int64 Value::asInt64() const {
switch (type()) {
case intValue:
return Int64(value_.int_);
case uintValue:
JSON_ASSERT_MESSAGE(isInt64(), "LargestUInt out of Int64 range");
return Int64(value_.uint_);
case realValue:
JSON_ASSERT_MESSAGE(InRange(value_.real_, minInt64, maxInt64),
"double out of Int64 range");
return Int64(value_.real_);
case nullValue:
return 0;
case booleanValue:
return value_.bool_ ? 1 : 0;
default:
break;
}
JSON_FAIL_MESSAGE("Value is not convertible to Int64.");
}
Value::UInt64 Value::asUInt64() const {
switch (type()) {
case intValue:
JSON_ASSERT_MESSAGE(isUInt64(), "LargestInt out of UInt64 range");
return UInt64(value_.int_);
case uintValue:
return UInt64(value_.uint_);
case realValue:
JSON_ASSERT_MESSAGE(InRange(value_.real_, 0, maxUInt64),
"double out of UInt64 range");
return UInt64(value_.real_);
case nullValue:
return 0;
case booleanValue:
return value_.bool_ ? 1 : 0;
default:
break;
}
JSON_FAIL_MESSAGE("Value is not convertible to UInt64.");
}
#endif // if defined(JSON_HAS_INT64)
LargestInt Value::asLargestInt() const {
#if defined(JSON_NO_INT64)
return asInt();
#else
return asInt64();
#endif
}
LargestUInt Value::asLargestUInt() const {
#if defined(JSON_NO_INT64)
return asUInt();
#else
return asUInt64();
#endif
}
double Value::asDouble() const {
switch (type()) {
case intValue:
return static_cast<double>(value_.int_);
case uintValue:
#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
return static_cast<double>(value_.uint_);
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
return integerToDouble(value_.uint_);
#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
case realValue:
return value_.real_;
case nullValue:
return 0.0;
case booleanValue:
return value_.bool_ ? 1.0 : 0.0;
default:
break;
}
JSON_FAIL_MESSAGE("Value is not convertible to double.");
}
float Value::asFloat() const {
switch (type()) {
case intValue:
return static_cast<float>(value_.int_);
case uintValue:
#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
return static_cast<float>(value_.uint_);
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
// This can fail (silently?) if the value is bigger than MAX_FLOAT.
return static_cast<float>(integerToDouble(value_.uint_));
#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
case realValue:
return static_cast<float>(value_.real_);
case nullValue:
return 0.0;
case booleanValue:
return value_.bool_ ? 1.0F : 0.0F;
default:
break;
}
JSON_FAIL_MESSAGE("Value is not convertible to float.");
}
bool Value::asBool() const {
switch (type()) {
case booleanValue:
return value_.bool_;
case nullValue:
return false;
case intValue:
return value_.int_ != 0;
case uintValue:
return value_.uint_ != 0;
case realValue: {
// According to JavaScript language zero or NaN is regarded as false
const auto value_classification = std::fpclassify(value_.real_);
return value_classification != FP_ZERO && value_classification != FP_NAN;
}
default:
break;
}
JSON_FAIL_MESSAGE("Value is not convertible to bool.");
}
bool Value::isConvertibleTo(ValueType other) const {
switch (other) {
case nullValue:
return (isNumeric() && asDouble() == 0.0) ||
(type() == booleanValue && !value_.bool_) ||
(type() == stringValue && asString().empty()) ||
(type() == arrayValue && value_.map_->empty()) ||
(type() == objectValue && value_.map_->empty()) ||
type() == nullValue;
case intValue:
return isInt() ||
(type() == realValue && InRange(value_.real_, minInt, maxInt)) ||
type() == booleanValue || type() == nullValue;
case uintValue:
return isUInt() ||
(type() == realValue && InRange(value_.real_, 0, maxUInt)) ||
type() == booleanValue || type() == nullValue;
case realValue:
return isNumeric() || type() == booleanValue || type() == nullValue;
case booleanValue:
return isNumeric() || type() == booleanValue || type() == nullValue;
case stringValue:
return isNumeric() || type() == booleanValue || type() == stringValue ||
type() == nullValue;
case arrayValue:
return type() == arrayValue || type() == nullValue;
case objectValue:
return type() == objectValue || type() == nullValue;
}
JSON_ASSERT_UNREACHABLE;
return false;
}
/// Number of values in array or object
ArrayIndex Value::size() const {
switch (type()) {
case nullValue:
case intValue:
case uintValue:
case realValue:
case booleanValue:
case stringValue:
return 0;
case arrayValue: // size of the array is highest index + 1
if (!value_.map_->empty()) {
ObjectValues::const_iterator itLast = value_.map_->end();
--itLast;
return (*itLast).first.index() + 1;
}
return 0;
case objectValue:
return ArrayIndex(value_.map_->size());
}
JSON_ASSERT_UNREACHABLE;
return 0; // unreachable;
}
bool Value::empty() const {
if (isNull() || isArray() || isObject())
return size() == 0U;
return false;
}
Value::operator bool() const { return !isNull(); }
void Value::clear() {
JSON_ASSERT_MESSAGE(type() == nullValue || type() == arrayValue ||
type() == objectValue,
"in Json::Value::clear(): requires complex value");
start_ = 0;
limit_ = 0;
switch (type()) {
case arrayValue:
case objectValue:
value_.map_->clear();
break;
default:
break;
}
}
void Value::resize(ArrayIndex newSize) {
JSON_ASSERT_MESSAGE(type() == nullValue || type() == arrayValue,
"in Json::Value::resize(): requires arrayValue");
if (type() == nullValue)
*this = Value(arrayValue);
ArrayIndex oldSize = size();
if (newSize == 0)
clear();
else if (newSize > oldSize)
this->operator[](newSize - 1);
else {
for (ArrayIndex index = newSize; index < oldSize; ++index) {
value_.map_->erase(index);
}
JSON_ASSERT(size() == newSize);
}
}
Value& Value::operator[](ArrayIndex index) {
JSON_ASSERT_MESSAGE(
type() == nullValue || type() == arrayValue,
"in Json::Value::operator[](ArrayIndex): requires arrayValue");
if (type() == nullValue)
*this = Value(arrayValue);
CZString key(index);
auto it = value_.map_->lower_bound(key);
if (it != value_.map_->end() && (*it).first == key)
return (*it).second;
ObjectValues::value_type defaultValue(key, nullSingleton());
it = value_.map_->insert(it, defaultValue);
return (*it).second;
}
Value& Value::operator[](int index) {
JSON_ASSERT_MESSAGE(
index >= 0,
"in Json::Value::operator[](int index): index cannot be negative");
return (*this)[ArrayIndex(index)];
}
const Value& Value::operator[](ArrayIndex index) const {
JSON_ASSERT_MESSAGE(
type() == nullValue || type() == arrayValue,
"in Json::Value::operator[](ArrayIndex)const: requires arrayValue");
if (type() == nullValue)
return nullSingleton();
CZString key(index);
ObjectValues::const_iterator it = value_.map_->find(key);
if (it == value_.map_->end())
return nullSingleton();
return (*it).second;
}
const Value& Value::operator[](int index) const {
JSON_ASSERT_MESSAGE(
index >= 0,
"in Json::Value::operator[](int index) const: index cannot be negative");
return (*this)[ArrayIndex(index)];
}
void Value::initBasic(ValueType type, bool allocated) {
setType(type);
setIsAllocated(allocated);
comments_ = Comments{};
start_ = 0;
limit_ = 0;
}
void Value::dupPayload(const Value& other) {
setType(other.type());
setIsAllocated(false);
switch (type()) {
case nullValue:
case intValue:
case uintValue:
case realValue:
case booleanValue:
value_ = other.value_;
break;
case stringValue:
if (other.value_.string_ && other.isAllocated()) {
unsigned len;
char const* str;
decodePrefixedString(other.isAllocated(), other.value_.string_, &len,
&str);
value_.string_ = duplicateAndPrefixStringValue(str, len);
setIsAllocated(true);
} else {
value_.string_ = other.value_.string_;
}
break;
case arrayValue:
case objectValue:
value_.map_ = new ObjectValues(*other.value_.map_);
break;
default:
JSON_ASSERT_UNREACHABLE;
}
}
void Value::releasePayload() {
switch (type()) {
case nullValue:
case intValue:
case uintValue:
case realValue:
case booleanValue:
break;
case stringValue:
if (isAllocated())
releasePrefixedStringValue(value_.string_);
break;
case arrayValue:
case objectValue:
delete value_.map_;
break;
default:
JSON_ASSERT_UNREACHABLE;
}
}
void Value::dupMeta(const Value& other) {
comments_ = other.comments_;
start_ = other.start_;
limit_ = other.limit_;
}
// Access an object value by name, create a null member if it does not exist.
// @pre Type of '*this' is object or null.
// @param key is null-terminated.
Value& Value::resolveReference(const char* key) {
JSON_ASSERT_MESSAGE(
type() == nullValue || type() == objectValue,
"in Json::Value::resolveReference(): requires objectValue");
if (type() == nullValue)
*this = Value(objectValue);
CZString actualKey(key, static_cast<unsigned>(strlen(key)),
CZString::noDuplication); // NOTE!
auto it = value_.map_->lower_bound(actualKey);
if (it != value_.map_->end() && (*it).first == actualKey)
return (*it).second;
ObjectValues::value_type defaultValue(actualKey, nullSingleton());
it = value_.map_->insert(it, defaultValue);
Value& value = (*it).second;
return value;
}
// @param key is not null-terminated.
Value& Value::resolveReference(char const* key, char const* end) {
JSON_ASSERT_MESSAGE(
type() == nullValue || type() == objectValue,
"in Json::Value::resolveReference(key, end): requires objectValue");
if (type() == nullValue)
*this = Value(objectValue);
CZString actualKey(key, static_cast<unsigned>(end - key),
CZString::duplicateOnCopy);
auto it = value_.map_->lower_bound(actualKey);
if (it != value_.map_->end() && (*it).first == actualKey)
return (*it).second;
ObjectValues::value_type defaultValue(actualKey, nullSingleton());
it = value_.map_->insert(it, defaultValue);
Value& value = (*it).second;
return value;
}
Value Value::get(ArrayIndex index, const Value& defaultValue) const {
const Value* value = &((*this)[index]);
return value == &nullSingleton() ? defaultValue : *value;
}
bool Value::isValidIndex(ArrayIndex index) const { return index < size(); }
Value const* Value::find(char const* begin, char const* end) const {
JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue,
"in Json::Value::find(begin, end): requires "
"objectValue or nullValue");
if (type() == nullValue)
return nullptr;
CZString actualKey(begin, static_cast<unsigned>(end - begin),
CZString::noDuplication);
ObjectValues::const_iterator it = value_.map_->find(actualKey);
if (it == value_.map_->end())
return nullptr;
return &(*it).second;
}
Value* Value::demand(char const* begin, char const* end) {
JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue,
"in Json::Value::demand(begin, end): requires "
"objectValue or nullValue");
return &resolveReference(begin, end);
}
const Value& Value::operator[](const char* key) const {
Value const* found = find(key, key + strlen(key));
if (!found)
return nullSingleton();
return *found;
}
Value const& Value::operator[](const String& key) const {
Value const* found = find(key.data(), key.data() + key.length());
if (!found)
return nullSingleton();
return *found;
}
Value& Value::operator[](const char* key) {
return resolveReference(key, key + strlen(key));
}
Value& Value::operator[](const String& key) {
return resolveReference(key.data(), key.data() + key.length());
}
Value& Value::operator[](const StaticString& key) {
return resolveReference(key.c_str());
}
Value& Value::append(const Value& value) { return append(Value(value)); }
Value& Value::append(Value&& value) {
JSON_ASSERT_MESSAGE(type() == nullValue || type() == arrayValue,
"in Json::Value::append: requires arrayValue");
if (type() == nullValue) {
*this = Value(arrayValue);
}
return this->value_.map_->emplace(size(), std::move(value)).first->second;
}
bool Value::insert(ArrayIndex index, const Value& newValue) {
return insert(index, Value(newValue));
}
bool Value::insert(ArrayIndex index, Value&& newValue) {
JSON_ASSERT_MESSAGE(type() == nullValue || type() == arrayValue,
"in Json::Value::insert: requires arrayValue");
ArrayIndex length = size();
if (index > length) {
return false;
}
for (ArrayIndex i = length; i > index; i--) {
(*this)[i] = std::move((*this)[i - 1]);
}
(*this)[index] = std::move(newValue);
return true;
}
Value Value::get(char const* begin, char const* end,
Value const& defaultValue) const {
Value const* found = find(begin, end);
return !found ? defaultValue : *found;
}
Value Value::get(char const* key, Value const& defaultValue) const {
return get(key, key + strlen(key), defaultValue);
}
Value Value::get(String const& key, Value const& defaultValue) const {
return get(key.data(), key.data() + key.length(), defaultValue);
}
bool Value::removeMember(const char* begin, const char* end, Value* removed) {
if (type() != objectValue) {
return false;
}
CZString actualKey(begin, static_cast<unsigned>(end - begin),
CZString::noDuplication);
auto it = value_.map_->find(actualKey);
if (it == value_.map_->end())
return false;
if (removed)
*removed = std::move(it->second);
value_.map_->erase(it);
return true;
}
bool Value::removeMember(const char* key, Value* removed) {
return removeMember(key, key + strlen(key), removed);
}
bool Value::removeMember(String const& key, Value* removed) {
return removeMember(key.data(), key.data() + key.length(), removed);
}
void Value::removeMember(const char* key) {
JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue,
"in Json::Value::removeMember(): requires objectValue");
if (type() == nullValue)
return;
CZString actualKey(key, unsigned(strlen(key)), CZString::noDuplication);
value_.map_->erase(actualKey);
}
void Value::removeMember(const String& key) { removeMember(key.c_str()); }
bool Value::removeIndex(ArrayIndex index, Value* removed) {
if (type() != arrayValue) {
return false;
}
CZString key(index);
auto it = value_.map_->find(key);
if (it == value_.map_->end()) {
return false;
}
if (removed)
*removed = it->second;
ArrayIndex oldSize = size();
// shift left all items left, into the place of the "removed"
for (ArrayIndex i = index; i < (oldSize - 1); ++i) {
CZString keey(i);
(*value_.map_)[keey] = (*this)[i + 1];
}
// erase the last one ("leftover")
CZString keyLast(oldSize - 1);
auto itLast = value_.map_->find(keyLast);
value_.map_->erase(itLast);
return true;
}
bool Value::isMember(char const* begin, char const* end) const {
Value const* value = find(begin, end);
return nullptr != value;
}
bool Value::isMember(char const* key) const {
return isMember(key, key + strlen(key));
}
bool Value::isMember(String const& key) const {
return isMember(key.data(), key.data() + key.length());
}
Value::Members Value::getMemberNames() const {
JSON_ASSERT_MESSAGE(
type() == nullValue || type() == objectValue,
"in Json::Value::getMemberNames(), value must be objectValue");
if (type() == nullValue)
return Value::Members();
Members members;
members.reserve(value_.map_->size());
ObjectValues::const_iterator it = value_.map_->begin();
ObjectValues::const_iterator itEnd = value_.map_->end();
for (; it != itEnd; ++it) {
members.push_back(String((*it).first.data(), (*it).first.length()));
}
return members;
}
static bool IsIntegral(double d) {
double integral_part;
return modf(d, &integral_part) == 0.0;
}
bool Value::isNull() const { return type() == nullValue; }
bool Value::isBool() const { return type() == booleanValue; }
bool Value::isInt() const {
switch (type()) {
case intValue:
#if defined(JSON_HAS_INT64)
return value_.int_ >= minInt && value_.int_ <= maxInt;
#else
return true;
#endif
case uintValue:
return value_.uint_ <= UInt(maxInt);
case realValue:
return value_.real_ >= minInt && value_.real_ <= maxInt &&
IsIntegral(value_.real_);
default:
break;
}
return false;
}
bool Value::isUInt() const {
switch (type()) {
case intValue:
#if defined(JSON_HAS_INT64)
return value_.int_ >= 0 && LargestUInt(value_.int_) <= LargestUInt(maxUInt);
#else
return value_.int_ >= 0;
#endif
case uintValue:
#if defined(JSON_HAS_INT64)
return value_.uint_ <= maxUInt;
#else
return true;
#endif
case realValue:
return value_.real_ >= 0 && value_.real_ <= maxUInt &&
IsIntegral(value_.real_);
default:
break;
}
return false;
}
bool Value::isInt64() const {
#if defined(JSON_HAS_INT64)
switch (type()) {
case intValue:
return true;
case uintValue:
return value_.uint_ <= UInt64(maxInt64);
case realValue:
// Note that maxInt64 (= 2^63 - 1) is not exactly representable as a
// double, so double(maxInt64) will be rounded up to 2^63. Therefore we
// require the value to be strictly less than the limit.
return value_.real_ >= double(minInt64) &&
value_.real_ < double(maxInt64) && IsIntegral(value_.real_);
default:
break;
}
#endif // JSON_HAS_INT64
return false;
}
bool Value::isUInt64() const {
#if defined(JSON_HAS_INT64)
switch (type()) {
case intValue:
return value_.int_ >= 0;
case uintValue:
return true;
case realValue:
// Note that maxUInt64 (= 2^64 - 1) is not exactly representable as a
// double, so double(maxUInt64) will be rounded up to 2^64. Therefore we
// require the value to be strictly less than the limit.
return value_.real_ >= 0 && value_.real_ < maxUInt64AsDouble &&
IsIntegral(value_.real_);
default:
break;
}
#endif // JSON_HAS_INT64
return false;
}
bool Value::isIntegral() const {
switch (type()) {
case intValue:
case uintValue:
return true;
case realValue:
#if defined(JSON_HAS_INT64)
// Note that maxUInt64 (= 2^64 - 1) is not exactly representable as a
// double, so double(maxUInt64) will be rounded up to 2^64. Therefore we
// require the value to be strictly less than the limit.
return value_.real_ >= double(minInt64) &&
value_.real_ < maxUInt64AsDouble && IsIntegral(value_.real_);
#else
return value_.real_ >= minInt && value_.real_ <= maxUInt &&
IsIntegral(value_.real_);
#endif // JSON_HAS_INT64
default:
break;
}
return false;
}
bool Value::isDouble() const {
return type() == intValue || type() == uintValue || type() == realValue;
}
bool Value::isNumeric() const { return isDouble(); }
bool Value::isString() const { return type() == stringValue; }
bool Value::isArray() const { return type() == arrayValue; }
bool Value::isObject() const { return type() == objectValue; }
Value::Comments::Comments(const Comments& that)
: ptr_{cloneUnique(that.ptr_)} {}
Value::Comments::Comments(Comments&& that) : ptr_{std::move(that.ptr_)} {}
Value::Comments& Value::Comments::operator=(const Comments& that) {
ptr_ = cloneUnique(that.ptr_);
return *this;
}
Value::Comments& Value::Comments::operator=(Comments&& that) {
ptr_ = std::move(that.ptr_);
return *this;
}
bool Value::Comments::has(CommentPlacement slot) const {
return ptr_ && !(*ptr_)[slot].empty();
}
String Value::Comments::get(CommentPlacement slot) const {
if (!ptr_)
return {};
return (*ptr_)[slot];
}
void Value::Comments::set(CommentPlacement slot, String comment) {
if (!ptr_) {
ptr_ = std::unique_ptr<Array>(new Array());
}
// check comments array boundry.
if (slot < CommentPlacement::numberOfCommentPlacement) {
(*ptr_)[slot] = std::move(comment);
}
}
void Value::setComment(String comment, CommentPlacement placement) {
if (!comment.empty() && (comment.back() == '\n')) {
// Always discard trailing newline, to aid indentation.
comment.pop_back();
}
JSON_ASSERT(!comment.empty());
JSON_ASSERT_MESSAGE(
comment[0] == '\0' || comment[0] == '/',
"in Json::Value::setComment(): Comments must start with /");
comments_.set(placement, std::move(comment));
}
bool Value::hasComment(CommentPlacement placement) const {
return comments_.has(placement);
}
String Value::getComment(CommentPlacement placement) const {
return comments_.get(placement);
}
void Value::setOffsetStart(ptrdiff_t start) { start_ = start; }
void Value::setOffsetLimit(ptrdiff_t limit) { limit_ = limit; }
ptrdiff_t Value::getOffsetStart() const { return start_; }
ptrdiff_t Value::getOffsetLimit() const { return limit_; }
String Value::toStyledString() const {
StreamWriterBuilder builder;
String out = this->hasComment(commentBefore) ? "\n" : "";
out += Json::writeString(builder, *this);
out += '\n';
return out;
}
Value::const_iterator Value::begin() const {
switch (type()) {
case arrayValue:
case objectValue:
if (value_.map_)
return const_iterator(value_.map_->begin());
break;
default:
break;
}
return {};
}
Value::const_iterator Value::end() const {
switch (type()) {
case arrayValue:
case objectValue:
if (value_.map_)
return const_iterator(value_.map_->end());
break;
default:
break;
}
return {};
}
Value::iterator Value::begin() {
switch (type()) {
case arrayValue:
case objectValue:
if (value_.map_)
return iterator(value_.map_->begin());
break;
default:
break;
}
return iterator();
}
Value::iterator Value::end() {
switch (type()) {
case arrayValue:
case objectValue:
if (value_.map_)
return iterator(value_.map_->end());
break;
default:
break;
}
return iterator();
}
// class PathArgument
// //////////////////////////////////////////////////////////////////
PathArgument::PathArgument() = default;
PathArgument::PathArgument(ArrayIndex index)
: index_(index), kind_(kindIndex) {}
PathArgument::PathArgument(const char* key) : key_(key), kind_(kindKey) {}
PathArgument::PathArgument(String key) : key_(std::move(key)), kind_(kindKey) {}
// class Path
// //////////////////////////////////////////////////////////////////
Path::Path(const String& path, const PathArgument& a1, const PathArgument& a2,
const PathArgument& a3, const PathArgument& a4,
const PathArgument& a5) {
InArgs in;
in.reserve(5);
in.push_back(&a1);
in.push_back(&a2);
in.push_back(&a3);
in.push_back(&a4);
in.push_back(&a5);
makePath(path, in);
}
void Path::makePath(const String& path, const InArgs& in) {
const char* current = path.c_str();
const char* end = current + path.length();
auto itInArg = in.begin();
while (current != end) {
if (*current == '[') {
++current;
if (*current == '%')
addPathInArg(path, in, itInArg, PathArgument::kindIndex);
else {
ArrayIndex index = 0;
for (; current != end && *current >= '0' && *current <= '9'; ++current)
index = index * 10 + ArrayIndex(*current - '0');
args_.push_back(index);
}
if (current == end || *++current != ']')
invalidPath(path, int(current - path.c_str()));
} else if (*current == '%') {
addPathInArg(path, in, itInArg, PathArgument::kindKey);
++current;
} else if (*current == '.' || *current == ']') {
++current;
} else {
const char* beginName = current;
while (current != end && !strchr("[.", *current))
++current;
args_.push_back(String(beginName, current));
}
}
}
void Path::addPathInArg(const String& /*path*/, const InArgs& in,
InArgs::const_iterator& itInArg,
PathArgument::Kind kind) {
if (itInArg == in.end()) {
// Error: missing argument %d
} else if ((*itInArg)->kind_ != kind) {
// Error: bad argument type
} else {
args_.push_back(**itInArg++);
}
}
void Path::invalidPath(const String& /*path*/, int /*location*/) {
// Error: invalid path.
}
const Value& Path::resolve(const Value& root) const {
const Value* node = &root;
for (const auto& arg : args_) {
if (arg.kind_ == PathArgument::kindIndex) {
if (!node->isArray() || !node->isValidIndex(arg.index_)) {
// Error: unable to resolve path (array value expected at position... )
return Value::nullSingleton();
}
node = &((*node)[arg.index_]);
} else if (arg.kind_ == PathArgument::kindKey) {
if (!node->isObject()) {
// Error: unable to resolve path (object value expected at position...)
return Value::nullSingleton();
}
node = &((*node)[arg.key_]);
if (node == &Value::nullSingleton()) {
// Error: unable to resolve path (object has no member named '' at
// position...)
return Value::nullSingleton();
}
}
}
return *node;
}
Value Path::resolve(const Value& root, const Value& defaultValue) const {
const Value* node = &root;
for (const auto& arg : args_) {
if (arg.kind_ == PathArgument::kindIndex) {
if (!node->isArray() || !node->isValidIndex(arg.index_))
return defaultValue;
node = &((*node)[arg.index_]);
} else if (arg.kind_ == PathArgument::kindKey) {
if (!node->isObject())
return defaultValue;
node = &((*node)[arg.key_]);
if (node == &Value::nullSingleton())
return defaultValue;
}
}
return *node;
}
Value& Path::make(Value& root) const {
Value* node = &root;
for (const auto& arg : args_) {
if (arg.kind_ == PathArgument::kindIndex) {
if (!node->isArray()) {
// Error: node is not an array at position ...
}
node = &((*node)[arg.index_]);
} else if (arg.kind_ == PathArgument::kindKey) {
if (!node->isObject()) {
// Error: node is not an object at position...
}
node = &((*node)[arg.key_]);
}
}
return *node;
}
} // namespace Json
// //////////////////////////////////////////////////////////////////////
// End of content of file: src/lib_json/json_value.cpp
// //////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////
// Beginning of content of file: src/lib_json/json_writer.cpp
// //////////////////////////////////////////////////////////////////////
// Copyright 2011 Baptiste Lepilleur and The JsonCpp Authors
// Distributed under MIT license, or public domain if desired and
// recognized in your jurisdiction.
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
#if !defined(JSON_IS_AMALGAMATION)
#include "json_tool.h"
#include <json/writer.h>
#endif // if !defined(JSON_IS_AMALGAMATION)
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <memory>
#include <set>
#include <sstream>
#include <utility>
#if __cplusplus >= 201103L
#include <cmath>
#include <cstdio>
#if !defined(isnan)
#define isnan std::isnan
#endif
#if !defined(isfinite)
#define isfinite std::isfinite
#endif
#else
#include <cmath>
#include <cstdio>
#if defined(_MSC_VER)
#if !defined(isnan)
#include <float.h>
#define isnan _isnan
#endif
#if !defined(isfinite)
#include <float.h>
#define isfinite _finite
#endif
#if !defined(_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES)
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#endif //_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#endif //_MSC_VER
#if defined(__sun) && defined(__SVR4) // Solaris
#if !defined(isfinite)
#include <ieeefp.h>
#define isfinite finite
#endif
#endif
#if defined(__hpux)
#if !defined(isfinite)
#if defined(__ia64) && !defined(finite)
#define isfinite(x) \
((sizeof(x) == sizeof(float) ? _Isfinitef(x) : _IsFinite(x)))
#endif
#endif
#endif
#if !defined(isnan)
// IEEE standard states that NaN values will not compare to themselves
#define isnan(x) (x != x)
#endif
#if !defined(__APPLE__)
#if !defined(isfinite)
#define isfinite finite
#endif
#endif
#endif
#if defined(_MSC_VER)
// Disable warning about strdup being deprecated.
#pragma warning(disable : 4996)
#endif
namespace Json {
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
using StreamWriterPtr = std::unique_ptr<StreamWriter>;
#else
using StreamWriterPtr = std::auto_ptr<StreamWriter>;
#endif
String valueToString(LargestInt value) {
UIntToStringBuffer buffer;
char* current = buffer + sizeof(buffer);
if (value == Value::minLargestInt) {
uintToString(LargestUInt(Value::maxLargestInt) + 1, current);
*--current = '-';
} else if (value < 0) {
uintToString(LargestUInt(-value), current);
*--current = '-';
} else {
uintToString(LargestUInt(value), current);
}
assert(current >= buffer);
return current;
}
String valueToString(LargestUInt value) {
UIntToStringBuffer buffer;
char* current = buffer + sizeof(buffer);
uintToString(value, current);
assert(current >= buffer);
return current;
}
#if defined(JSON_HAS_INT64)
String valueToString(Int value) { return valueToString(LargestInt(value)); }
String valueToString(UInt value) { return valueToString(LargestUInt(value)); }
#endif // # if defined(JSON_HAS_INT64)
namespace {
String valueToString(double value, bool useSpecialFloats,
unsigned int precision, PrecisionType precisionType) {
// Print into the buffer. We need not request the alternative representation
// that always has a decimal point because JSON doesn't distinguish the
// concepts of reals and integers.
if (!isfinite(value)) {
static const char* const reps[2][3] = {{"NaN", "-Infinity", "Infinity"},
{"null", "-1e+9999", "1e+9999"}};
return reps[useSpecialFloats ? 0 : 1]
[isnan(value) ? 0 : (value < 0) ? 1 : 2];
}
String buffer(size_t(36), '\0');
while (true) {
int len = jsoncpp_snprintf(
&*buffer.begin(), buffer.size(),
(precisionType == PrecisionType::significantDigits) ? "%.*g" : "%.*f",
precision, value);
assert(len >= 0);
auto wouldPrint = static_cast<size_t>(len);
if (wouldPrint >= buffer.size()) {
buffer.resize(wouldPrint + 1);
continue;
}
buffer.resize(wouldPrint);
break;
}
buffer.erase(fixNumericLocale(buffer.begin(), buffer.end()), buffer.end());
// strip the zero padding from the right
if (precisionType == PrecisionType::decimalPlaces) {
buffer.erase(fixZerosInTheEnd(buffer.begin(), buffer.end()), buffer.end());
}
// try to ensure we preserve the fact that this was given to us as a double on
// input
if (buffer.find('.') == buffer.npos && buffer.find('e') == buffer.npos) {
buffer += ".0";
}
return buffer;
}
} // namespace
String valueToString(double value, unsigned int precision,
PrecisionType precisionType) {
return valueToString(value, false, precision, precisionType);
}
String valueToString(bool value) { return value ? "true" : "false"; }
static bool doesAnyCharRequireEscaping(char const* s, size_t n) {
assert(s || !n);
return std::any_of(s, s + n, [](unsigned char c) {
return c == '\\' || c == '"' || c < 0x20 || c > 0x7F;
});
}
static unsigned int utf8ToCodepoint(const char*& s, const char* e) {
const unsigned int REPLACEMENT_CHARACTER = 0xFFFD;
unsigned int firstByte = static_cast<unsigned char>(*s);
if (firstByte < 0x80)
return firstByte;
if (firstByte < 0xE0) {
if (e - s < 2)
return REPLACEMENT_CHARACTER;
unsigned int calculated =
((firstByte & 0x1F) << 6) | (static_cast<unsigned int>(s[1]) & 0x3F);
s += 1;
// oversized encoded characters are invalid
return calculated < 0x80 ? REPLACEMENT_CHARACTER : calculated;
}
if (firstByte < 0xF0) {
if (e - s < 3)
return REPLACEMENT_CHARACTER;
unsigned int calculated = ((firstByte & 0x0F) << 12) |
((static_cast<unsigned int>(s[1]) & 0x3F) << 6) |
(static_cast<unsigned int>(s[2]) & 0x3F);
s += 2;
// surrogates aren't valid codepoints itself
// shouldn't be UTF-8 encoded
if (calculated >= 0xD800 && calculated <= 0xDFFF)
return REPLACEMENT_CHARACTER;
// oversized encoded characters are invalid
return calculated < 0x800 ? REPLACEMENT_CHARACTER : calculated;
}
if (firstByte < 0xF8) {
if (e - s < 4)
return REPLACEMENT_CHARACTER;
unsigned int calculated = ((firstByte & 0x07) << 18) |
((static_cast<unsigned int>(s[1]) & 0x3F) << 12) |
((static_cast<unsigned int>(s[2]) & 0x3F) << 6) |
(static_cast<unsigned int>(s[3]) & 0x3F);
s += 3;
// oversized encoded characters are invalid
return calculated < 0x10000 ? REPLACEMENT_CHARACTER : calculated;
}
return REPLACEMENT_CHARACTER;
}
static const char hex2[] = "000102030405060708090a0b0c0d0e0f"
"101112131415161718191a1b1c1d1e1f"
"202122232425262728292a2b2c2d2e2f"
"303132333435363738393a3b3c3d3e3f"
"404142434445464748494a4b4c4d4e4f"
"505152535455565758595a5b5c5d5e5f"
"606162636465666768696a6b6c6d6e6f"
"707172737475767778797a7b7c7d7e7f"
"808182838485868788898a8b8c8d8e8f"
"909192939495969798999a9b9c9d9e9f"
"a0a1a2a3a4a5a6a7a8a9aaabacadaeaf"
"b0b1b2b3b4b5b6b7b8b9babbbcbdbebf"
"c0c1c2c3c4c5c6c7c8c9cacbcccdcecf"
"d0d1d2d3d4d5d6d7d8d9dadbdcdddedf"
"e0e1e2e3e4e5e6e7e8e9eaebecedeeef"
"f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff";
static String toHex16Bit(unsigned int x) {
const unsigned int hi = (x >> 8) & 0xff;
const unsigned int lo = x & 0xff;
String result(4, ' ');
result[0] = hex2[2 * hi];
result[1] = hex2[2 * hi + 1];
result[2] = hex2[2 * lo];
result[3] = hex2[2 * lo + 1];
return result;
}
static void appendRaw(String& result, unsigned ch) {
result += static_cast<char>(ch);
}
static void appendHex(String& result, unsigned ch) {
result.append("\\u").append(toHex16Bit(ch));
}
static String valueToQuotedStringN(const char* value, unsigned length,
bool emitUTF8 = false) {
if (value == nullptr)
return "";
if (!doesAnyCharRequireEscaping(value, length))
return String("\"") + value + "\"";
// We have to walk value and escape any special characters.
// Appending to String is not efficient, but this should be rare.
// (Note: forward slashes are *not* rare, but I am not escaping them.)
String::size_type maxsize = length * 2 + 3; // allescaped+quotes+NULL
String result;
result.reserve(maxsize); // to avoid lots of mallocs
result += "\"";
char const* end = value + length;
for (const char* c = value; c != end; ++c) {
switch (*c) {
case '\"':
result += "\\\"";
break;
case '\\':
result += "\\\\";
break;
case '\b':
result += "\\b";
break;
case '\f':
result += "\\f";
break;
case '\n':
result += "\\n";
break;
case '\r':
result += "\\r";
break;
case '\t':
result += "\\t";
break;
// case '/':
// Even though \/ is considered a legal escape in JSON, a bare
// slash is also legal, so I see no reason to escape it.
// (I hope I am not misunderstanding something.)
// blep notes: actually escaping \/ may be useful in javascript to avoid </
// sequence.
// Should add a flag to allow this compatibility mode and prevent this
// sequence from occurring.
default: {
if (emitUTF8) {
unsigned codepoint = static_cast<unsigned char>(*c);
if (codepoint < 0x20) {
appendHex(result, codepoint);
} else {
appendRaw(result, codepoint);
}
} else {
unsigned codepoint = utf8ToCodepoint(c, end); // modifies `c`
if (codepoint < 0x20) {
appendHex(result, codepoint);
} else if (codepoint < 0x80) {
appendRaw(result, codepoint);
} else if (codepoint < 0x10000) {
// Basic Multilingual Plane
appendHex(result, codepoint);
} else {
// Extended Unicode. Encode 20 bits as a surrogate pair.
codepoint -= 0x10000;
appendHex(result, 0xd800 + ((codepoint >> 10) & 0x3ff));
appendHex(result, 0xdc00 + (codepoint & 0x3ff));
}
}
} break;
}
}
result += "\"";
return result;
}
String valueToQuotedString(const char* value) {
return valueToQuotedStringN(value, static_cast<unsigned int>(strlen(value)));
}
// Class Writer
// //////////////////////////////////////////////////////////////////
Writer::~Writer() = default;
// Class FastWriter
// //////////////////////////////////////////////////////////////////
FastWriter::FastWriter()
= default;
void FastWriter::enableYAMLCompatibility() { yamlCompatibilityEnabled_ = true; }
void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; }
void FastWriter::omitEndingLineFeed() { omitEndingLineFeed_ = true; }
String FastWriter::write(const Value& root) {
document_.clear();
writeValue(root);
if (!omitEndingLineFeed_)
document_ += '\n';
return document_;
}
void FastWriter::writeValue(const Value& value) {
switch (value.type()) {
case nullValue:
if (!dropNullPlaceholders_)
document_ += "null";
break;
case intValue:
document_ += valueToString(value.asLargestInt());
break;
case uintValue:
document_ += valueToString(value.asLargestUInt());
break;
case realValue:
document_ += valueToString(value.asDouble());
break;
case stringValue: {
// Is NULL possible for value.string_? No.
char const* str;
char const* end;
bool ok = value.getString(&str, &end);
if (ok)
document_ += valueToQuotedStringN(str, static_cast<unsigned>(end - str));
break;
}
case booleanValue:
document_ += valueToString(value.asBool());
break;
case arrayValue: {
document_ += '[';
ArrayIndex size = value.size();
for (ArrayIndex index = 0; index < size; ++index) {
if (index > 0)
document_ += ',';
writeValue(value[index]);
}
document_ += ']';
} break;
case objectValue: {
Value::Members members(value.getMemberNames());
document_ += '{';
for (auto it = members.begin(); it != members.end(); ++it) {
const String& name = *it;
if (it != members.begin())
document_ += ',';
document_ += valueToQuotedStringN(name.data(),
static_cast<unsigned>(name.length()));
document_ += yamlCompatibilityEnabled_ ? ": " : ":";
writeValue(value[name]);
}
document_ += '}';
} break;
}
}
// Class StyledWriter
// //////////////////////////////////////////////////////////////////
StyledWriter::StyledWriter() = default;
String StyledWriter::write(const Value& root) {
document_.clear();
addChildValues_ = false;
indentString_.clear();
writeCommentBeforeValue(root);
writeValue(root);
writeCommentAfterValueOnSameLine(root);
document_ += '\n';
return document_;
}
void StyledWriter::writeValue(const Value& value) {
switch (value.type()) {
case nullValue:
pushValue("null");
break;
case intValue:
pushValue(valueToString(value.asLargestInt()));
break;
case uintValue:
pushValue(valueToString(value.asLargestUInt()));
break;
case realValue:
pushValue(valueToString(value.asDouble()));
break;
case stringValue: {
// Is NULL possible for value.string_? No.
char const* str;
char const* end;
bool ok = value.getString(&str, &end);
if (ok)
pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end - str)));
else
pushValue("");
break;
}
case booleanValue:
pushValue(valueToString(value.asBool()));
break;
case arrayValue:
writeArrayValue(value);
break;
case objectValue: {
Value::Members members(value.getMemberNames());
if (members.empty())
pushValue("{}");
else {
writeWithIndent("{");
indent();
auto it = members.begin();
for (;;) {
const String& name = *it;
const Value& childValue = value[name];
writeCommentBeforeValue(childValue);
writeWithIndent(valueToQuotedString(name.c_str()));
document_ += " : ";
writeValue(childValue);
if (++it == members.end()) {
writeCommentAfterValueOnSameLine(childValue);
break;
}
document_ += ',';
writeCommentAfterValueOnSameLine(childValue);
}
unindent();
writeWithIndent("}");
}
} break;
}
}
void StyledWriter::writeArrayValue(const Value& value) {
unsigned size = value.size();
if (size == 0)
pushValue("[]");
else {
bool isArrayMultiLine = isMultilineArray(value);
if (isArrayMultiLine) {
writeWithIndent("[");
indent();
bool hasChildValue = !childValues_.empty();
unsigned index = 0;
for (;;) {
const Value& childValue = value[index];
writeCommentBeforeValue(childValue);
if (hasChildValue)
writeWithIndent(childValues_[index]);
else {
writeIndent();
writeValue(childValue);
}
if (++index == size) {
writeCommentAfterValueOnSameLine(childValue);
break;
}
document_ += ',';
writeCommentAfterValueOnSameLine(childValue);
}
unindent();
writeWithIndent("]");
} else // output on a single line
{
assert(childValues_.size() == size);
document_ += "[ ";
for (unsigned index = 0; index < size; ++index) {
if (index > 0)
document_ += ", ";
document_ += childValues_[index];
}
document_ += " ]";
}
}
}
bool StyledWriter::isMultilineArray(const Value& value) {
ArrayIndex const size = value.size();
bool isMultiLine = size * 3 >= rightMargin_;
childValues_.clear();
for (ArrayIndex index = 0; index < size && !isMultiLine; ++index) {
const Value& childValue = value[index];
isMultiLine = ((childValue.isArray() || childValue.isObject()) &&
!childValue.empty());
}
if (!isMultiLine) // check if line length > max line length
{
childValues_.reserve(size);
addChildValues_ = true;
ArrayIndex lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]'
for (ArrayIndex index = 0; index < size; ++index) {
if (hasCommentForValue(value[index])) {
isMultiLine = true;
}
writeValue(value[index]);
lineLength += static_cast<ArrayIndex>(childValues_[index].length());
}
addChildValues_ = false;
isMultiLine = isMultiLine || lineLength >= rightMargin_;
}
return isMultiLine;
}
void StyledWriter::pushValue(const String& value) {
if (addChildValues_)
childValues_.push_back(value);
else
document_ += value;
}
void StyledWriter::writeIndent() {
if (!document_.empty()) {
char last = document_[document_.length() - 1];
if (last == ' ') // already indented
return;
if (last != '\n') // Comments may add new-line
document_ += '\n';
}
document_ += indentString_;
}
void StyledWriter::writeWithIndent(const String& value) {
writeIndent();
document_ += value;
}
void StyledWriter::indent() { indentString_ += String(indentSize_, ' '); }
void StyledWriter::unindent() {
assert(indentString_.size() >= indentSize_);
indentString_.resize(indentString_.size() - indentSize_);
}
void StyledWriter::writeCommentBeforeValue(const Value& root) {
if (!root.hasComment(commentBefore))
return;
document_ += '\n';
writeIndent();
const String& comment = root.getComment(commentBefore);
String::const_iterator iter = comment.begin();
while (iter != comment.end()) {
document_ += *iter;
if (*iter == '\n' && ((iter + 1) != comment.end() && *(iter + 1) == '/'))
writeIndent();
++iter;
}
// Comments are stripped of trailing newlines, so add one here
document_ += '\n';
}
void StyledWriter::writeCommentAfterValueOnSameLine(const Value& root) {
if (root.hasComment(commentAfterOnSameLine))
document_ += " " + root.getComment(commentAfterOnSameLine);
if (root.hasComment(commentAfter)) {
document_ += '\n';
document_ += root.getComment(commentAfter);
document_ += '\n';
}
}
bool StyledWriter::hasCommentForValue(const Value& value) {
return value.hasComment(commentBefore) ||
value.hasComment(commentAfterOnSameLine) ||
value.hasComment(commentAfter);
}
// Class StyledStreamWriter
// //////////////////////////////////////////////////////////////////
StyledStreamWriter::StyledStreamWriter(String indentation)
: document_(nullptr), indentation_(std::move(indentation)),
addChildValues_(), indented_(false) {}
void StyledStreamWriter::write(OStream& out, const Value& root) {
document_ = &out;
addChildValues_ = false;
indentString_.clear();
indented_ = true;
writeCommentBeforeValue(root);
if (!indented_)
writeIndent();
indented_ = true;
writeValue(root);
writeCommentAfterValueOnSameLine(root);
*document_ << "\n";
document_ = nullptr; // Forget the stream, for safety.
}
void StyledStreamWriter::writeValue(const Value& value) {
switch (value.type()) {
case nullValue:
pushValue("null");
break;
case intValue:
pushValue(valueToString(value.asLargestInt()));
break;
case uintValue:
pushValue(valueToString(value.asLargestUInt()));
break;
case realValue:
pushValue(valueToString(value.asDouble()));
break;
case stringValue: {
// Is NULL possible for value.string_? No.
char const* str;
char const* end;
bool ok = value.getString(&str, &end);
if (ok)
pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end - str)));
else
pushValue("");
break;
}
case booleanValue:
pushValue(valueToString(value.asBool()));
break;
case arrayValue:
writeArrayValue(value);
break;
case objectValue: {
Value::Members members(value.getMemberNames());
if (members.empty())
pushValue("{}");
else {
writeWithIndent("{");
indent();
auto it = members.begin();
for (;;) {
const String& name = *it;
const Value& childValue = value[name];
writeCommentBeforeValue(childValue);
writeWithIndent(valueToQuotedString(name.c_str()));
*document_ << " : ";
writeValue(childValue);
if (++it == members.end()) {
writeCommentAfterValueOnSameLine(childValue);
break;
}
*document_ << ",";
writeCommentAfterValueOnSameLine(childValue);
}
unindent();
writeWithIndent("}");
}
} break;
}
}
void StyledStreamWriter::writeArrayValue(const Value& value) {
unsigned size = value.size();
if (size == 0)
pushValue("[]");
else {
bool isArrayMultiLine = isMultilineArray(value);
if (isArrayMultiLine) {
writeWithIndent("[");
indent();
bool hasChildValue = !childValues_.empty();
unsigned index = 0;
for (;;) {
const Value& childValue = value[index];
writeCommentBeforeValue(childValue);
if (hasChildValue)
writeWithIndent(childValues_[index]);
else {
if (!indented_)
writeIndent();
indented_ = true;
writeValue(childValue);
indented_ = false;
}
if (++index == size) {
writeCommentAfterValueOnSameLine(childValue);
break;
}
*document_ << ",";
writeCommentAfterValueOnSameLine(childValue);
}
unindent();
writeWithIndent("]");
} else // output on a single line
{
assert(childValues_.size() == size);
*document_ << "[ ";
for (unsigned index = 0; index < size; ++index) {
if (index > 0)
*document_ << ", ";
*document_ << childValues_[index];
}
*document_ << " ]";
}
}
}
bool StyledStreamWriter::isMultilineArray(const Value& value) {
ArrayIndex const size = value.size();
bool isMultiLine = size * 3 >= rightMargin_;
childValues_.clear();
for (ArrayIndex index = 0; index < size && !isMultiLine; ++index) {
const Value& childValue = value[index];
isMultiLine = ((childValue.isArray() || childValue.isObject()) &&
!childValue.empty());
}
if (!isMultiLine) // check if line length > max line length
{
childValues_.reserve(size);
addChildValues_ = true;
ArrayIndex lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]'
for (ArrayIndex index = 0; index < size; ++index) {
if (hasCommentForValue(value[index])) {
isMultiLine = true;
}
writeValue(value[index]);
lineLength += static_cast<ArrayIndex>(childValues_[index].length());
}
addChildValues_ = false;
isMultiLine = isMultiLine || lineLength >= rightMargin_;
}
return isMultiLine;
}
void StyledStreamWriter::pushValue(const String& value) {
if (addChildValues_)
childValues_.push_back(value);
else
*document_ << value;
}
void StyledStreamWriter::writeIndent() {
// blep intended this to look at the so-far-written string
// to determine whether we are already indented, but
// with a stream we cannot do that. So we rely on some saved state.
// The caller checks indented_.
*document_ << '\n' << indentString_;
}
void StyledStreamWriter::writeWithIndent(const String& value) {
if (!indented_)
writeIndent();
*document_ << value;
indented_ = false;
}
void StyledStreamWriter::indent() { indentString_ += indentation_; }
void StyledStreamWriter::unindent() {
assert(indentString_.size() >= indentation_.size());
indentString_.resize(indentString_.size() - indentation_.size());
}
void StyledStreamWriter::writeCommentBeforeValue(const Value& root) {
if (!root.hasComment(commentBefore))
return;
if (!indented_)
writeIndent();
const String& comment = root.getComment(commentBefore);
String::const_iterator iter = comment.begin();
while (iter != comment.end()) {
*document_ << *iter;
if (*iter == '\n' && ((iter + 1) != comment.end() && *(iter + 1) == '/'))
// writeIndent(); // would include newline
*document_ << indentString_;
++iter;
}
indented_ = false;
}
void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value& root) {
if (root.hasComment(commentAfterOnSameLine))
*document_ << ' ' << root.getComment(commentAfterOnSameLine);
if (root.hasComment(commentAfter)) {
writeIndent();
*document_ << root.getComment(commentAfter);
}
indented_ = false;
}
bool StyledStreamWriter::hasCommentForValue(const Value& value) {
return value.hasComment(commentBefore) ||
value.hasComment(commentAfterOnSameLine) ||
value.hasComment(commentAfter);
}
//////////////////////////
// BuiltStyledStreamWriter
/// Scoped enums are not available until C++11.
struct CommentStyle {
/// Decide whether to write comments.
enum Enum {
None, ///< Drop all comments.
Most, ///< Recover odd behavior of previous versions (not implemented yet).
All ///< Keep all comments.
};
};
struct BuiltStyledStreamWriter : public StreamWriter {
BuiltStyledStreamWriter(String indentation, CommentStyle::Enum cs,
String colonSymbol, String nullSymbol,
String endingLineFeedSymbol, bool useSpecialFloats,
bool emitUTF8, unsigned int precision,
PrecisionType precisionType);
int write(Value const& root, OStream* sout) override;
private:
void writeValue(Value const& value);
void writeArrayValue(Value const& value);
bool isMultilineArray(Value const& value);
void pushValue(String const& value);
void writeIndent();
void writeWithIndent(String const& value);
void indent();
void unindent();
void writeCommentBeforeValue(Value const& root);
void writeCommentAfterValueOnSameLine(Value const& root);
static bool hasCommentForValue(const Value& value);
using ChildValues = std::vector<String>;
ChildValues childValues_;
String indentString_;
unsigned int rightMargin_;
String indentation_;
CommentStyle::Enum cs_;
String colonSymbol_;
String nullSymbol_;
String endingLineFeedSymbol_;
bool addChildValues_ : 1;
bool indented_ : 1;
bool useSpecialFloats_ : 1;
bool emitUTF8_ : 1;
unsigned int precision_;
PrecisionType precisionType_;
};
BuiltStyledStreamWriter::BuiltStyledStreamWriter(
String indentation, CommentStyle::Enum cs, String colonSymbol,
String nullSymbol, String endingLineFeedSymbol, bool useSpecialFloats,
bool emitUTF8, unsigned int precision, PrecisionType precisionType)
: rightMargin_(74), indentation_(std::move(indentation)), cs_(cs),
colonSymbol_(std::move(colonSymbol)), nullSymbol_(std::move(nullSymbol)),
endingLineFeedSymbol_(std::move(endingLineFeedSymbol)),
addChildValues_(false), indented_(false),
useSpecialFloats_(useSpecialFloats), emitUTF8_(emitUTF8),
precision_(precision), precisionType_(precisionType) {}
int BuiltStyledStreamWriter::write(Value const& root, OStream* sout) {
sout_ = sout;
addChildValues_ = false;
indented_ = true;
indentString_.clear();
writeCommentBeforeValue(root);
if (!indented_)
writeIndent();
indented_ = true;
writeValue(root);
writeCommentAfterValueOnSameLine(root);
*sout_ << endingLineFeedSymbol_;
sout_ = nullptr;
return 0;
}
void BuiltStyledStreamWriter::writeValue(Value const& value) {
switch (value.type()) {
case nullValue:
pushValue(nullSymbol_);
break;
case intValue:
pushValue(valueToString(value.asLargestInt()));
break;
case uintValue:
pushValue(valueToString(value.asLargestUInt()));
break;
case realValue:
pushValue(valueToString(value.asDouble(), useSpecialFloats_, precision_,
precisionType_));
break;
case stringValue: {
// Is NULL is possible for value.string_? No.
char const* str;
char const* end;
bool ok = value.getString(&str, &end);
if (ok)
pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end - str),
emitUTF8_));
else
pushValue("");
break;
}
case booleanValue:
pushValue(valueToString(value.asBool()));
break;
case arrayValue:
writeArrayValue(value);
break;
case objectValue: {
Value::Members members(value.getMemberNames());
if (members.empty())
pushValue("{}");
else {
writeWithIndent("{");
indent();
auto it = members.begin();
for (;;) {
String const& name = *it;
Value const& childValue = value[name];
writeCommentBeforeValue(childValue);
writeWithIndent(valueToQuotedStringN(
name.data(), static_cast<unsigned>(name.length()), emitUTF8_));
*sout_ << colonSymbol_;
writeValue(childValue);
if (++it == members.end()) {
writeCommentAfterValueOnSameLine(childValue);
break;
}
*sout_ << ",";
writeCommentAfterValueOnSameLine(childValue);
}
unindent();
writeWithIndent("}");
}
} break;
}
}
void BuiltStyledStreamWriter::writeArrayValue(Value const& value) {
unsigned size = value.size();
if (size == 0)
pushValue("[]");
else {
bool isMultiLine = (cs_ == CommentStyle::All) || isMultilineArray(value);
if (isMultiLine) {
writeWithIndent("[");
indent();
bool hasChildValue = !childValues_.empty();
unsigned index = 0;
for (;;) {
Value const& childValue = value[index];
writeCommentBeforeValue(childValue);
if (hasChildValue)
writeWithIndent(childValues_[index]);
else {
if (!indented_)
writeIndent();
indented_ = true;
writeValue(childValue);
indented_ = false;
}
if (++index == size) {
writeCommentAfterValueOnSameLine(childValue);
break;
}
*sout_ << ",";
writeCommentAfterValueOnSameLine(childValue);
}
unindent();
writeWithIndent("]");
} else // output on a single line
{
assert(childValues_.size() == size);
*sout_ << "[";
if (!indentation_.empty())
*sout_ << " ";
for (unsigned index = 0; index < size; ++index) {
if (index > 0)
*sout_ << ((!indentation_.empty()) ? ", " : ",");
*sout_ << childValues_[index];
}
if (!indentation_.empty())
*sout_ << " ";
*sout_ << "]";
}
}
}
bool BuiltStyledStreamWriter::isMultilineArray(Value const& value) {
ArrayIndex const size = value.size();
bool isMultiLine = size * 3 >= rightMargin_;
childValues_.clear();
for (ArrayIndex index = 0; index < size && !isMultiLine; ++index) {
Value const& childValue = value[index];
isMultiLine = ((childValue.isArray() || childValue.isObject()) &&
!childValue.empty());
}
if (!isMultiLine) // check if line length > max line length
{
childValues_.reserve(size);
addChildValues_ = true;
ArrayIndex lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]'
for (ArrayIndex index = 0; index < size; ++index) {
if (hasCommentForValue(value[index])) {
isMultiLine = true;
}
writeValue(value[index]);
lineLength += static_cast<ArrayIndex>(childValues_[index].length());
}
addChildValues_ = false;
isMultiLine = isMultiLine || lineLength >= rightMargin_;
}
return isMultiLine;
}
void BuiltStyledStreamWriter::pushValue(String const& value) {
if (addChildValues_)
childValues_.push_back(value);
else
*sout_ << value;
}
void BuiltStyledStreamWriter::writeIndent() {
// blep intended this to look at the so-far-written string
// to determine whether we are already indented, but
// with a stream we cannot do that. So we rely on some saved state.
// The caller checks indented_.
if (!indentation_.empty()) {
// In this case, drop newlines too.
*sout_ << '\n' << indentString_;
}
}
void BuiltStyledStreamWriter::writeWithIndent(String const& value) {
if (!indented_)
writeIndent();
*sout_ << value;
indented_ = false;
}
void BuiltStyledStreamWriter::indent() { indentString_ += indentation_; }
void BuiltStyledStreamWriter::unindent() {
assert(indentString_.size() >= indentation_.size());
indentString_.resize(indentString_.size() - indentation_.size());
}
void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) {
if (cs_ == CommentStyle::None)
return;
if (!root.hasComment(commentBefore))
return;
if (!indented_)
writeIndent();
const String& comment = root.getComment(commentBefore);
String::const_iterator iter = comment.begin();
while (iter != comment.end()) {
*sout_ << *iter;
if (*iter == '\n' && ((iter + 1) != comment.end() && *(iter + 1) == '/'))
// writeIndent(); // would write extra newline
*sout_ << indentString_;
++iter;
}
indented_ = false;
}
void BuiltStyledStreamWriter::writeCommentAfterValueOnSameLine(
Value const& root) {
if (cs_ == CommentStyle::None)
return;
if (root.hasComment(commentAfterOnSameLine))
*sout_ << " " + root.getComment(commentAfterOnSameLine);
if (root.hasComment(commentAfter)) {
writeIndent();
*sout_ << root.getComment(commentAfter);
}
}
// static
bool BuiltStyledStreamWriter::hasCommentForValue(const Value& value) {
return value.hasComment(commentBefore) ||
value.hasComment(commentAfterOnSameLine) ||
value.hasComment(commentAfter);
}
///////////////
// StreamWriter
StreamWriter::StreamWriter() : sout_(nullptr) {}
StreamWriter::~StreamWriter() = default;
StreamWriter::Factory::~Factory() = default;
StreamWriterBuilder::StreamWriterBuilder() { setDefaults(&settings_); }
StreamWriterBuilder::~StreamWriterBuilder() = default;
StreamWriter* StreamWriterBuilder::newStreamWriter() const {
const String indentation = settings_["indentation"].asString();
const String cs_str = settings_["commentStyle"].asString();
const String pt_str = settings_["precisionType"].asString();
const bool eyc = settings_["enableYAMLCompatibility"].asBool();
const bool dnp = settings_["dropNullPlaceholders"].asBool();
const bool usf = settings_["useSpecialFloats"].asBool();
const bool emitUTF8 = settings_["emitUTF8"].asBool();
unsigned int pre = settings_["precision"].asUInt();
CommentStyle::Enum cs = CommentStyle::All;
if (cs_str == "All") {
cs = CommentStyle::All;
} else if (cs_str == "None") {
cs = CommentStyle::None;
} else {
throwRuntimeError("commentStyle must be 'All' or 'None'");
}
PrecisionType precisionType(significantDigits);
if (pt_str == "significant") {
precisionType = PrecisionType::significantDigits;
} else if (pt_str == "decimal") {
precisionType = PrecisionType::decimalPlaces;
} else {
throwRuntimeError("precisionType must be 'significant' or 'decimal'");
}
String colonSymbol = " : ";
if (eyc) {
colonSymbol = ": ";
} else if (indentation.empty()) {
colonSymbol = ":";
}
String nullSymbol = "null";
if (dnp) {
nullSymbol.clear();
}
if (pre > 17)
pre = 17;
String endingLineFeedSymbol;
return new BuiltStyledStreamWriter(indentation, cs, colonSymbol, nullSymbol,
endingLineFeedSymbol, usf, emitUTF8, pre,
precisionType);
}
bool StreamWriterBuilder::validate(Json::Value* invalid) const {
static const auto& valid_keys = *new std::set<String>{
"indentation",
"commentStyle",
"enableYAMLCompatibility",
"dropNullPlaceholders",
"useSpecialFloats",
"emitUTF8",
"precision",
"precisionType",
};
for (auto si = settings_.begin(); si != settings_.end(); ++si) {
auto key = si.name();
if (valid_keys.count(key))
continue;
if (invalid)
(*invalid)[std::move(key)] = *si;
else
return false;
}
return invalid ? invalid->empty() : true;
}
Value& StreamWriterBuilder::operator[](const String& key) {
return settings_[key];
}
// static
void StreamWriterBuilder::setDefaults(Json::Value* settings) {
//! [StreamWriterBuilderDefaults]
(*settings)["commentStyle"] = "All";
(*settings)["indentation"] = "\t";
(*settings)["enableYAMLCompatibility"] = false;
(*settings)["dropNullPlaceholders"] = false;
(*settings)["useSpecialFloats"] = false;
(*settings)["emitUTF8"] = false;
(*settings)["precision"] = 17;
(*settings)["precisionType"] = "significant";
//! [StreamWriterBuilderDefaults]
}
String writeString(StreamWriter::Factory const& factory, Value const& root) {
OStringStream sout;
StreamWriterPtr const writer(factory.newStreamWriter());
writer->write(root, &sout);
return sout.str();
}
OStream& operator<<(OStream& sout, Value const& root) {
StreamWriterBuilder builder;
StreamWriterPtr const writer(builder.newStreamWriter());
writer->write(root, &sout);
return sout;
}
} // namespace Json
// //////////////////////////////////////////////////////////////////////
// End of content of file
// //////////////////////////////////////////////////////////////////////
|
;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 3.5.0 #9253 (Mar 28 2016) (Linux)
; This file was generated Wed Jan 2 15:12:32 2019
;--------------------------------------------------------
.module stm8s_gpio
.optsdcc -mstm8
;--------------------------------------------------------
; Public variables in this module
;--------------------------------------------------------
.globl _assert_failed
.globl _GPIO_DeInit
.globl _GPIO_Init
.globl _GPIO_Write
.globl _GPIO_WriteHigh
.globl _GPIO_WriteLow
.globl _GPIO_WriteReverse
.globl _GPIO_ReadOutputData
.globl _GPIO_ReadInputData
.globl _GPIO_ReadInputPin
.globl _GPIO_ExternalPullUpConfig
;--------------------------------------------------------
; ram data
;--------------------------------------------------------
.area DATA
;--------------------------------------------------------
; ram data
;--------------------------------------------------------
.area INITIALIZED
;--------------------------------------------------------
; absolute external ram data
;--------------------------------------------------------
.area DABS (ABS)
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
.area HOME
.area GSINIT
.area GSFINAL
.area GSINIT
;--------------------------------------------------------
; Home
;--------------------------------------------------------
.area HOME
.area HOME
;--------------------------------------------------------
; code
;--------------------------------------------------------
.area CODE
; ../src/stm8s_gpio.c: 53: void GPIO_DeInit(GPIO_TypeDef* GPIOx)
; -----------------------------------------
; function GPIO_DeInit
; -----------------------------------------
_GPIO_DeInit:
pushw x
; ../src/stm8s_gpio.c: 55: GPIOx->ODR = GPIO_ODR_RESET_VALUE; /* Reset Output Data Register */
ldw y, (0x05, sp)
ldw (0x01, sp), y
ldw x, (0x01, sp)
clr (x)
; ../src/stm8s_gpio.c: 56: GPIOx->DDR = GPIO_DDR_RESET_VALUE; /* Reset Data Direction Register */
ldw x, (0x01, sp)
incw x
incw x
clr (x)
; ../src/stm8s_gpio.c: 57: GPIOx->CR1 = GPIO_CR1_RESET_VALUE; /* Reset Control Register 1 */
ldw x, (0x01, sp)
addw x, #0x0003
clr (x)
; ../src/stm8s_gpio.c: 58: GPIOx->CR2 = GPIO_CR2_RESET_VALUE; /* Reset Control Register 2 */
ldw x, (0x01, sp)
addw x, #0x0004
clr (x)
popw x
ret
; ../src/stm8s_gpio.c: 71: void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, GPIO_Mode_TypeDef GPIO_Mode)
; -----------------------------------------
; function GPIO_Init
; -----------------------------------------
_GPIO_Init:
sub sp, #5
; ../src/stm8s_gpio.c: 77: assert_param(IS_GPIO_MODE_OK(GPIO_Mode));
tnz (0x0b, sp)
jreq 00116$
ld a, (0x0b, sp)
cp a, #0x40
jreq 00116$
ld a, (0x0b, sp)
cp a, #0x20
jreq 00116$
ld a, (0x0b, sp)
cp a, #0x60
jreq 00116$
ld a, (0x0b, sp)
cp a, #0xa0
jreq 00116$
ld a, (0x0b, sp)
cp a, #0xe0
jreq 00116$
ld a, (0x0b, sp)
cp a, #0x80
jreq 00116$
ld a, (0x0b, sp)
cp a, #0xc0
jreq 00116$
ld a, (0x0b, sp)
cp a, #0xb0
jreq 00116$
ld a, (0x0b, sp)
cp a, #0xf0
jreq 00116$
ld a, (0x0b, sp)
cp a, #0x90
jreq 00116$
ld a, (0x0b, sp)
cp a, #0xd0
jreq 00116$
ldw y, #___str_0+0
push #0x4d
clrw x
pushw x
push #0x00
pushw y
call _assert_failed
addw sp, #6
00116$:
; ../src/stm8s_gpio.c: 78: assert_param(IS_GPIO_PIN_OK(GPIO_Pin));
tnz (0x0a, sp)
jrne 00151$
ldw y, #___str_0+0
push #0x4e
clrw x
pushw x
push #0x00
pushw y
call _assert_failed
addw sp, #6
00151$:
; ../src/stm8s_gpio.c: 81: GPIOx->CR2 &= (uint8_t)(~(GPIO_Pin));
ldw y, (0x08, sp)
ldw (0x01, sp), y
ldw x, (0x01, sp)
addw x, #0x0004
ldw (0x03, sp), x
ldw x, (0x03, sp)
ld a, (x)
ld xh, a
ld a, (0x0a, sp)
cpl a
ld (0x05, sp), a
ld a, xh
and a, (0x05, sp)
ldw x, (0x03, sp)
ld (x), a
; ../src/stm8s_gpio.c: 98: GPIOx->DDR |= (uint8_t)GPIO_Pin;
ldw x, (0x01, sp)
incw x
incw x
; ../src/stm8s_gpio.c: 87: if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x80) != (uint8_t)0x00) /* Output mode */
tnz (0x0b, sp)
jrpl 00105$
; ../src/stm8s_gpio.c: 91: GPIOx->ODR |= (uint8_t)GPIO_Pin;
ldw y, (0x01, sp)
ld a, (y)
; ../src/stm8s_gpio.c: 89: if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x10) != (uint8_t)0x00) /* High level */
push a
ld a, (0x0c, sp)
bcp a, #0x10
pop a
jreq 00102$
; ../src/stm8s_gpio.c: 91: GPIOx->ODR |= (uint8_t)GPIO_Pin;
or a, (0x0a, sp)
ldw y, (0x01, sp)
ld (y), a
jra 00103$
00102$:
; ../src/stm8s_gpio.c: 95: GPIOx->ODR &= (uint8_t)(~(GPIO_Pin));
and a, (0x05, sp)
ldw y, (0x01, sp)
ld (y), a
00103$:
; ../src/stm8s_gpio.c: 98: GPIOx->DDR |= (uint8_t)GPIO_Pin;
ld a, (x)
or a, (0x0a, sp)
ld (x), a
jra 00106$
00105$:
; ../src/stm8s_gpio.c: 103: GPIOx->DDR &= (uint8_t)(~(GPIO_Pin));
ld a, (x)
and a, (0x05, sp)
ld (x), a
00106$:
; ../src/stm8s_gpio.c: 112: GPIOx->CR1 |= (uint8_t)GPIO_Pin;
ldw x, (0x01, sp)
addw x, #0x0003
; ../src/stm8s_gpio.c: 110: if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x40) != (uint8_t)0x00) /* Pull-Up or Push-Pull */
ld a, (0x0b, sp)
bcp a, #0x40
jreq 00108$
; ../src/stm8s_gpio.c: 112: GPIOx->CR1 |= (uint8_t)GPIO_Pin;
ld a, (x)
or a, (0x0a, sp)
ld (x), a
jra 00109$
00108$:
; ../src/stm8s_gpio.c: 116: GPIOx->CR1 &= (uint8_t)(~(GPIO_Pin));
ld a, (x)
and a, (0x05, sp)
ld (x), a
00109$:
; ../src/stm8s_gpio.c: 123: if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x20) != (uint8_t)0x00) /* Interrupt or Slow slope */
ld a, (0x0b, sp)
bcp a, #0x20
jreq 00111$
; ../src/stm8s_gpio.c: 125: GPIOx->CR2 |= (uint8_t)GPIO_Pin;
ldw x, (0x03, sp)
ld a, (x)
or a, (0x0a, sp)
ldw x, (0x03, sp)
ld (x), a
jra 00113$
00111$:
; ../src/stm8s_gpio.c: 129: GPIOx->CR2 &= (uint8_t)(~(GPIO_Pin));
ldw x, (0x03, sp)
ld a, (x)
and a, (0x05, sp)
ldw x, (0x03, sp)
ld (x), a
00113$:
addw sp, #5
ret
; ../src/stm8s_gpio.c: 141: void GPIO_Write(GPIO_TypeDef* GPIOx, uint8_t PortVal)
; -----------------------------------------
; function GPIO_Write
; -----------------------------------------
_GPIO_Write:
; ../src/stm8s_gpio.c: 143: GPIOx->ODR = PortVal;
ldw x, (0x03, sp)
ld a, (0x05, sp)
ld (x), a
ret
; ../src/stm8s_gpio.c: 154: void GPIO_WriteHigh(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins)
; -----------------------------------------
; function GPIO_WriteHigh
; -----------------------------------------
_GPIO_WriteHigh:
; ../src/stm8s_gpio.c: 156: GPIOx->ODR |= (uint8_t)PortPins;
ldw x, (0x03, sp)
ld a, (x)
or a, (0x05, sp)
ld (x), a
ret
; ../src/stm8s_gpio.c: 167: void GPIO_WriteLow(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins)
; -----------------------------------------
; function GPIO_WriteLow
; -----------------------------------------
_GPIO_WriteLow:
push a
; ../src/stm8s_gpio.c: 169: GPIOx->ODR &= (uint8_t)(~PortPins);
ldw x, (0x04, sp)
ld a, (x)
ld (0x01, sp), a
ld a, (0x06, sp)
cpl a
and a, (0x01, sp)
ld (x), a
pop a
ret
; ../src/stm8s_gpio.c: 180: void GPIO_WriteReverse(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins)
; -----------------------------------------
; function GPIO_WriteReverse
; -----------------------------------------
_GPIO_WriteReverse:
; ../src/stm8s_gpio.c: 182: GPIOx->ODR ^= (uint8_t)PortPins;
ldw x, (0x03, sp)
ld a, (x)
xor a, (0x05, sp)
ld (x), a
ret
; ../src/stm8s_gpio.c: 191: uint8_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
; -----------------------------------------
; function GPIO_ReadOutputData
; -----------------------------------------
_GPIO_ReadOutputData:
; ../src/stm8s_gpio.c: 193: return ((uint8_t)GPIOx->ODR);
ldw x, (0x03, sp)
ld a, (x)
ret
; ../src/stm8s_gpio.c: 202: uint8_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
; -----------------------------------------
; function GPIO_ReadInputData
; -----------------------------------------
_GPIO_ReadInputData:
; ../src/stm8s_gpio.c: 204: return ((uint8_t)GPIOx->IDR);
ldw x, (0x03, sp)
ld a, (0x1, x)
ret
; ../src/stm8s_gpio.c: 213: BitStatus GPIO_ReadInputPin(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin)
; -----------------------------------------
; function GPIO_ReadInputPin
; -----------------------------------------
_GPIO_ReadInputPin:
; ../src/stm8s_gpio.c: 215: return ((BitStatus)(GPIOx->IDR & (uint8_t)GPIO_Pin));
ldw x, (0x03, sp)
ld a, (0x1, x)
and a, (0x05, sp)
ret
; ../src/stm8s_gpio.c: 225: void GPIO_ExternalPullUpConfig(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, FunctionalState NewState)
; -----------------------------------------
; function GPIO_ExternalPullUpConfig
; -----------------------------------------
_GPIO_ExternalPullUpConfig:
push a
; ../src/stm8s_gpio.c: 228: assert_param(IS_GPIO_PIN_OK(GPIO_Pin));
tnz (0x06, sp)
jrne 00107$
ldw y, #___str_0+0
push #0xe4
clrw x
pushw x
push #0x00
pushw y
call _assert_failed
addw sp, #6
00107$:
; ../src/stm8s_gpio.c: 229: assert_param(IS_FUNCTIONALSTATE_OK(NewState));
tnz (0x07, sp)
jreq 00109$
ld a, (0x07, sp)
cp a, #0x01
jreq 00109$
ldw y, #___str_0+0
push #0xe5
clrw x
pushw x
push #0x00
pushw y
call _assert_failed
addw sp, #6
00109$:
; ../src/stm8s_gpio.c: 233: GPIOx->CR1 |= (uint8_t)GPIO_Pin;
ldw x, (0x04, sp)
addw x, #0x0003
; ../src/stm8s_gpio.c: 231: if (NewState != DISABLE) /* External Pull-Up Set*/
tnz (0x07, sp)
jreq 00102$
; ../src/stm8s_gpio.c: 233: GPIOx->CR1 |= (uint8_t)GPIO_Pin;
ld a, (x)
or a, (0x06, sp)
ld (x), a
jra 00104$
00102$:
; ../src/stm8s_gpio.c: 236: GPIOx->CR1 &= (uint8_t)(~(GPIO_Pin));
ld a, (x)
ld (0x01, sp), a
ld a, (0x06, sp)
cpl a
and a, (0x01, sp)
ld (x), a
00104$:
pop a
ret
.area CODE
___str_0:
.ascii "../src/stm8s_gpio.c"
.db 0x00
.area INITIALIZER
.area CABS (ABS)
|
BITS 64
;TEST_FILE_META_BEGIN
;TEST_TYPE=TEST_F
;TEST_IGNOREFLAGS=
;TEST_FILE_META_END
; SUB8ri
mov ah, 0xdd
;TEST_BEGIN_RECORDING
sub ah, 0x3
;TEST_END_RECORDING
|
I_ED equ 1
I_NET equ 0
I_AKEY equ 0
include 'dev8_sbsext_tk2_procs_asm'
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2015 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "policy/fees.h"
#include "policy/policy.h"
#include "amount.h"
#include "primitives/transaction.h"
#include "streams.h"
#include "txmempool.h"
#include "util.h"
void TxConfirmStats::Initialize(std::vector<double>& defaultBuckets,
unsigned int maxConfirms, double _decay, std::string _dataTypeString)
{
decay = _decay;
dataTypeString = _dataTypeString;
for (unsigned int i = 0; i < defaultBuckets.size(); i++) {
buckets.push_back(defaultBuckets[i]);
bucketMap[defaultBuckets[i]] = i;
}
confAvg.resize(maxConfirms);
curBlockConf.resize(maxConfirms);
unconfTxs.resize(maxConfirms);
for (unsigned int i = 0; i < maxConfirms; i++) {
confAvg[i].resize(buckets.size());
curBlockConf[i].resize(buckets.size());
unconfTxs[i].resize(buckets.size());
}
oldUnconfTxs.resize(buckets.size());
curBlockTxCt.resize(buckets.size());
txCtAvg.resize(buckets.size());
curBlockVal.resize(buckets.size());
avg.resize(buckets.size());
}
// Zero out the data for the current block
void TxConfirmStats::ClearCurrent(unsigned int nBlockHeight)
{
for (unsigned int j = 0; j < buckets.size(); j++) {
oldUnconfTxs[j] += unconfTxs[nBlockHeight%unconfTxs.size()][j];
unconfTxs[nBlockHeight%unconfTxs.size()][j] = 0;
for (unsigned int i = 0; i < curBlockConf.size(); i++)
curBlockConf[i][j] = 0;
curBlockTxCt[j] = 0;
curBlockVal[j] = 0;
}
}
void TxConfirmStats::Record(int blocksToConfirm, double val)
{
// blocksToConfirm is 1-based
if (blocksToConfirm < 1)
return;
unsigned int bucketindex = bucketMap.lower_bound(val)->second;
for (size_t i = blocksToConfirm; i <= curBlockConf.size(); i++) {
curBlockConf[i - 1][bucketindex]++;
}
curBlockTxCt[bucketindex]++;
curBlockVal[bucketindex] += val;
}
void TxConfirmStats::UpdateMovingAverages()
{
for (unsigned int j = 0; j < buckets.size(); j++) {
for (unsigned int i = 0; i < confAvg.size(); i++)
confAvg[i][j] = confAvg[i][j] * decay + curBlockConf[i][j];
avg[j] = avg[j] * decay + curBlockVal[j];
txCtAvg[j] = txCtAvg[j] * decay + curBlockTxCt[j];
}
}
// returns -1 on error conditions
double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal,
double successBreakPoint, bool requireGreater,
unsigned int nBlockHeight)
{
// Counters for a bucket (or range of buckets)
double nConf = 0; // Number of tx's confirmed within the confTarget
double totalNum = 0; // Total number of tx's that were ever confirmed
int extraNum = 0; // Number of tx's still in mempool for confTarget or longer
int maxbucketindex = buckets.size() - 1;
// requireGreater means we are looking for the lowest fee/priority such that all higher
// values pass, so we start at maxbucketindex (highest fee) and look at succesively
// smaller buckets until we reach failure. Otherwise, we are looking for the highest
// fee/priority such that all lower values fail, and we go in the opposite direction.
unsigned int startbucket = requireGreater ? maxbucketindex : 0;
int step = requireGreater ? -1 : 1;
// We'll combine buckets until we have enough samples.
// The near and far variables will define the range we've combined
// The best variables are the last range we saw which still had a high
// enough confirmation rate to count as success.
// The cur variables are the current range we're counting.
unsigned int curNearBucket = startbucket;
unsigned int bestNearBucket = startbucket;
unsigned int curFarBucket = startbucket;
unsigned int bestFarBucket = startbucket;
bool foundAnswer = false;
unsigned int bins = unconfTxs.size();
// Start counting from highest(default) or lowest fee/pri transactions
for (int bucket = startbucket; bucket >= 0 && bucket <= maxbucketindex; bucket += step) {
curFarBucket = bucket;
nConf += confAvg[confTarget - 1][bucket];
totalNum += txCtAvg[bucket];
for (unsigned int confct = confTarget; confct < GetMaxConfirms(); confct++)
extraNum += unconfTxs[(nBlockHeight - confct)%bins][bucket];
extraNum += oldUnconfTxs[bucket];
// If we have enough transaction data points in this range of buckets,
// we can test for success
// (Only count the confirmed data points, so that each confirmation count
// will be looking at the same amount of data and same bucket breaks)
if (totalNum >= sufficientTxVal / (1 - decay)) {
double curPct = nConf / (totalNum + extraNum);
// Check to see if we are no longer getting confirmed at the success rate
if (requireGreater && curPct < successBreakPoint)
break;
if (!requireGreater && curPct > successBreakPoint)
break;
// Otherwise update the cumulative stats, and the bucket variables
// and reset the counters
else {
foundAnswer = true;
nConf = 0;
totalNum = 0;
extraNum = 0;
bestNearBucket = curNearBucket;
bestFarBucket = curFarBucket;
curNearBucket = bucket + step;
}
}
}
double median = -1;
double txSum = 0;
// Calculate the "average" fee of the best bucket range that met success conditions
// Find the bucket with the median transaction and then report the average fee from that bucket
// This is a compromise between finding the median which we can't since we don't save all tx's
// and reporting the average which is less accurate
unsigned int minBucket = bestNearBucket < bestFarBucket ? bestNearBucket : bestFarBucket;
unsigned int maxBucket = bestNearBucket > bestFarBucket ? bestNearBucket : bestFarBucket;
for (unsigned int j = minBucket; j <= maxBucket; j++) {
txSum += txCtAvg[j];
}
if (foundAnswer && txSum != 0) {
txSum = txSum / 2;
for (unsigned int j = minBucket; j <= maxBucket; j++) {
if (txCtAvg[j] < txSum)
txSum -= txCtAvg[j];
else { // we're in the right bucket
median = avg[j] / txCtAvg[j];
break;
}
}
}
LogPrint("estimatefee", "%3d: For conf success %s %4.2f need %s %s: %12.5g from buckets %8g - %8g Cur Bucket stats %6.2f%% %8.1f/(%.1f+%d mempool)\n",
confTarget, requireGreater ? ">" : "<", successBreakPoint, dataTypeString,
requireGreater ? ">" : "<", median, buckets[minBucket], buckets[maxBucket],
100 * nConf / (totalNum + extraNum), nConf, totalNum, extraNum);
return median;
}
void TxConfirmStats::Write(CAutoFile& fileout)
{
fileout << decay;
fileout << buckets;
fileout << avg;
fileout << txCtAvg;
fileout << confAvg;
}
void TxConfirmStats::Read(CAutoFile& filein)
{
// Read data file into temporary variables and do some very basic sanity checking
std::vector<double> fileBuckets;
std::vector<double> fileAvg;
std::vector<std::vector<double> > fileConfAvg;
std::vector<double> fileTxCtAvg;
double fileDecay;
size_t maxConfirms;
size_t numBuckets;
filein >> fileDecay;
if (fileDecay <= 0 || fileDecay >= 1)
throw std::runtime_error("Corrupt estimates file. Decay must be between 0 and 1 (non-inclusive)");
filein >> fileBuckets;
numBuckets = fileBuckets.size();
if (numBuckets <= 1 || numBuckets > 1000)
throw std::runtime_error("Corrupt estimates file. Must have between 2 and 1000 fee/pri buckets");
filein >> fileAvg;
if (fileAvg.size() != numBuckets)
throw std::runtime_error("Corrupt estimates file. Mismatch in fee/pri average bucket count");
filein >> fileTxCtAvg;
if (fileTxCtAvg.size() != numBuckets)
throw std::runtime_error("Corrupt estimates file. Mismatch in tx count bucket count");
filein >> fileConfAvg;
maxConfirms = fileConfAvg.size();
if (maxConfirms <= 0 || maxConfirms > 6 * 24 * 7) // one week
throw std::runtime_error("Corrupt estimates file. Must maintain estimates for between 1 and 1008 (one week) confirms");
for (unsigned int i = 0; i < maxConfirms; i++) {
if (fileConfAvg[i].size() != numBuckets)
throw std::runtime_error("Corrupt estimates file. Mismatch in fee/pri conf average bucket count");
}
// Now that we've processed the entire fee estimate data file and not
// thrown any errors, we can copy it to our data structures
decay = fileDecay;
buckets = fileBuckets;
avg = fileAvg;
confAvg = fileConfAvg;
txCtAvg = fileTxCtAvg;
bucketMap.clear();
// Resize the current block variables which aren't stored in the data file
// to match the number of confirms and buckets
curBlockConf.resize(maxConfirms);
for (unsigned int i = 0; i < maxConfirms; i++) {
curBlockConf[i].resize(buckets.size());
}
curBlockTxCt.resize(buckets.size());
curBlockVal.resize(buckets.size());
unconfTxs.resize(maxConfirms);
for (unsigned int i = 0; i < maxConfirms; i++) {
unconfTxs[i].resize(buckets.size());
}
oldUnconfTxs.resize(buckets.size());
for (unsigned int i = 0; i < buckets.size(); i++)
bucketMap[buckets[i]] = i;
LogPrint("estimatefee", "Reading estimates: %u %s buckets counting confirms up to %u blocks\n",
numBuckets, dataTypeString, maxConfirms);
}
unsigned int TxConfirmStats::NewTx(unsigned int nBlockHeight, double val)
{
unsigned int bucketindex = bucketMap.lower_bound(val)->second;
unsigned int blockIndex = nBlockHeight % unconfTxs.size();
unconfTxs[blockIndex][bucketindex]++;
LogPrint("estimatefee", "adding to %s", dataTypeString);
return bucketindex;
}
void TxConfirmStats::removeTx(unsigned int entryHeight, unsigned int nBestSeenHeight, unsigned int bucketindex)
{
//nBestSeenHeight is not updated yet for the new block
int blocksAgo = nBestSeenHeight - entryHeight;
if (nBestSeenHeight == 0) // the BlockPolicyEstimator hasn't seen any blocks yet
blocksAgo = 0;
if (blocksAgo < 0) {
LogPrint("estimatefee", "Blockpolicy error, blocks ago is negative for mempool tx\n");
return; //This can't happen because we call this with our best seen height, no entries can have higher
}
if (blocksAgo >= (int)unconfTxs.size()) {
if (oldUnconfTxs[bucketindex] > 0)
oldUnconfTxs[bucketindex]--;
else
LogPrint("estimatefee", "Blockpolicy error, mempool tx removed from >25 blocks,bucketIndex=%u already\n",
bucketindex);
}
else {
unsigned int blockIndex = entryHeight % unconfTxs.size();
if (unconfTxs[blockIndex][bucketindex] > 0)
unconfTxs[blockIndex][bucketindex]--;
else
LogPrint("estimatefee", "Blockpolicy error, mempool tx removed from blockIndex=%u,bucketIndex=%u already\n",
blockIndex, bucketindex);
}
}
void CBlockPolicyEstimator::removeTx(uint256 hash)
{
std::map<uint256, TxStatsInfo>::iterator pos = mapMemPoolTxs.find(hash);
if (pos == mapMemPoolTxs.end()) {
LogPrint("estimatefee", "Blockpolicy error mempool tx %s not found for removeTx\n",
hash.ToString().c_str());
return;
}
TxConfirmStats *stats = pos->second.stats;
unsigned int entryHeight = pos->second.blockHeight;
unsigned int bucketIndex = pos->second.bucketIndex;
if (stats != NULL)
stats->removeTx(entryHeight, nBestSeenHeight, bucketIndex);
mapMemPoolTxs.erase(hash);
}
CBlockPolicyEstimator::CBlockPolicyEstimator(const CFeeRate& _minRelayFee)
: nBestSeenHeight(0)
{
minTrackedFee = _minRelayFee < CFeeRate(MIN_FEERATE) ? CFeeRate(MIN_FEERATE) : _minRelayFee;
std::vector<double> vfeelist;
for (double bucketBoundary = minTrackedFee.GetFeePerK(); bucketBoundary <= MAX_FEERATE; bucketBoundary *= FEE_SPACING) {
vfeelist.push_back(bucketBoundary);
}
vfeelist.push_back(INF_FEERATE);
feeStats.Initialize(vfeelist, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY, "FeeRate");
minTrackedPriority = AllowFreeThreshold() < MIN_PRIORITY ? MIN_PRIORITY : AllowFreeThreshold();
std::vector<double> vprilist;
for (double bucketBoundary = minTrackedPriority; bucketBoundary <= MAX_PRIORITY; bucketBoundary *= PRI_SPACING) {
vprilist.push_back(bucketBoundary);
}
vprilist.push_back(INF_PRIORITY);
priStats.Initialize(vprilist, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY, "Priority");
feeUnlikely = CFeeRate(0);
feeLikely = CFeeRate(INF_FEERATE);
priUnlikely = 0;
priLikely = INF_PRIORITY;
}
bool CBlockPolicyEstimator::isFeeDataPoint(const CFeeRate &fee, double pri)
{
if ((pri < minTrackedPriority && fee >= minTrackedFee) ||
(pri < priUnlikely && fee > feeLikely)) {
return true;
}
return false;
}
bool CBlockPolicyEstimator::isPriDataPoint(const CFeeRate &fee, double pri)
{
if ((fee < minTrackedFee && pri >= minTrackedPriority) ||
(fee < feeUnlikely && pri > priLikely)) {
return true;
}
return false;
}
void CBlockPolicyEstimator::processTransaction(const CTxMemPoolEntry& entry, bool fCurrentEstimate)
{
unsigned int txHeight = entry.GetHeight();
uint256 hash = entry.GetTx().GetHash();
if (mapMemPoolTxs[hash].stats != NULL) {
LogPrint("estimatefee", "Blockpolicy error mempool tx %s already being tracked\n",
hash.ToString().c_str());
return;
}
if (txHeight < nBestSeenHeight) {
// Ignore side chains and re-orgs; assuming they are random they don't
// affect the estimate. We'll potentially double count transactions in 1-block reorgs.
return;
}
// Only want to be updating estimates when our blockchain is synced,
// otherwise we'll miscalculate how many blocks its taking to get included.
if (!fCurrentEstimate)
return;
if (!entry.WasClearAtEntry()) {
// This transaction depends on other transactions in the mempool to
// be included in a block before it will be able to be included, so
// we shouldn't include it in our calculations
return;
}
// Fees are stored and reported as NTG-per-kb:
CFeeRate feeRate(entry.GetFee(), entry.GetTxSize());
// Want the priority of the tx at confirmation. However we don't know
// what that will be and its too hard to continue updating it
// so use starting priority as a proxy
double curPri = entry.GetPriority(txHeight);
mapMemPoolTxs[hash].blockHeight = txHeight;
LogPrint("estimatefee", "Blockpolicy mempool tx %s ", hash.ToString().substr(0,10));
// Record this as a priority estimate
if (entry.GetFee() == 0 || isPriDataPoint(feeRate, curPri)) {
mapMemPoolTxs[hash].stats = &priStats;
mapMemPoolTxs[hash].bucketIndex = priStats.NewTx(txHeight, curPri);
}
// Record this as a fee estimate
else if (isFeeDataPoint(feeRate, curPri)) {
mapMemPoolTxs[hash].stats = &feeStats;
mapMemPoolTxs[hash].bucketIndex = feeStats.NewTx(txHeight, (double)feeRate.GetFeePerK());
}
else {
LogPrint("estimatefee", "not adding");
}
LogPrint("estimatefee", "\n");
}
void CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, const CTxMemPoolEntry& entry)
{
if (!entry.WasClearAtEntry()) {
// This transaction depended on other transactions in the mempool to
// be included in a block before it was able to be included, so
// we shouldn't include it in our calculations
return;
}
// How many blocks did it take for miners to include this transaction?
// blocksToConfirm is 1-based, so a transaction included in the earliest
// possible block has confirmation count of 1
int blocksToConfirm = nBlockHeight - entry.GetHeight();
if (blocksToConfirm <= 0) {
// This can't happen because we don't process transactions from a block with a height
// lower than our greatest seen height
LogPrint("estimatefee", "Blockpolicy error Transaction had negative blocksToConfirm\n");
return;
}
// Fees are stored and reported as NTG-per-kb:
CFeeRate feeRate(entry.GetFee(), entry.GetTxSize());
// Want the priority of the tx at confirmation. The priority when it
// entered the mempool could easily be very small and change quickly
double curPri = entry.GetPriority(nBlockHeight);
// Record this as a priority estimate
if (entry.GetFee() == 0 || isPriDataPoint(feeRate, curPri)) {
priStats.Record(blocksToConfirm, curPri);
}
// Record this as a fee estimate
else if (isFeeDataPoint(feeRate, curPri)) {
feeStats.Record(blocksToConfirm, (double)feeRate.GetFeePerK());
}
}
void CBlockPolicyEstimator::processBlock(unsigned int nBlockHeight,
std::vector<CTxMemPoolEntry>& entries, bool fCurrentEstimate)
{
if (nBlockHeight <= nBestSeenHeight) {
// Ignore side chains and re-orgs; assuming they are random
// they don't affect the estimate.
// And if an attacker can re-org the chain at will, then
// you've got much bigger problems than "attacker can influence
// transaction fees."
return;
}
nBestSeenHeight = nBlockHeight;
// Only want to be updating estimates when our blockchain is synced,
// otherwise we'll miscalculate how many blocks its taking to get included.
if (!fCurrentEstimate)
return;
// Update the dynamic cutoffs
// a fee/priority is "likely" the reason your tx was included in a block if >85% of such tx's
// were confirmed in 2 blocks and is "unlikely" if <50% were confirmed in 10 blocks
LogPrint("estimatefee", "Blockpolicy recalculating dynamic cutoffs:\n");
priLikely = priStats.EstimateMedianVal(2, SUFFICIENT_PRITXS, MIN_SUCCESS_PCT, true, nBlockHeight);
if (priLikely == -1)
priLikely = INF_PRIORITY;
double feeLikelyEst = feeStats.EstimateMedianVal(2, SUFFICIENT_FEETXS, MIN_SUCCESS_PCT, true, nBlockHeight);
if (feeLikelyEst == -1)
feeLikely = CFeeRate(INF_FEERATE);
else
feeLikely = CFeeRate(feeLikelyEst);
priUnlikely = priStats.EstimateMedianVal(10, SUFFICIENT_PRITXS, UNLIKELY_PCT, false, nBlockHeight);
if (priUnlikely == -1)
priUnlikely = 0;
double feeUnlikelyEst = feeStats.EstimateMedianVal(10, SUFFICIENT_FEETXS, UNLIKELY_PCT, false, nBlockHeight);
if (feeUnlikelyEst == -1)
feeUnlikely = CFeeRate(0);
else
feeUnlikely = CFeeRate(feeUnlikelyEst);
// Clear the current block states
feeStats.ClearCurrent(nBlockHeight);
priStats.ClearCurrent(nBlockHeight);
// Repopulate the current block states
for (unsigned int i = 0; i < entries.size(); i++)
processBlockTx(nBlockHeight, entries[i]);
// Update all exponential averages with the current block states
feeStats.UpdateMovingAverages();
priStats.UpdateMovingAverages();
LogPrint("estimatefee", "Blockpolicy after updating estimates for %u confirmed entries, new mempool map size %u\n",
entries.size(), mapMemPoolTxs.size());
}
CFeeRate CBlockPolicyEstimator::estimateFee(int confTarget)
{
// Return failure if trying to analyze a target we're not tracking
if (confTarget <= 0 || (unsigned int)confTarget > feeStats.GetMaxConfirms())
return CFeeRate(0);
double median = feeStats.EstimateMedianVal(confTarget, SUFFICIENT_FEETXS, MIN_SUCCESS_PCT, true, nBestSeenHeight);
if (median < 0)
return CFeeRate(0);
return CFeeRate(median);
}
CFeeRate CBlockPolicyEstimator::estimateSmartFee(int confTarget, int *answerFoundAtTarget, const CTxMemPool& pool)
{
if (answerFoundAtTarget)
*answerFoundAtTarget = confTarget;
// Return failure if trying to analyze a target we're not tracking
if (confTarget <= 0 || (unsigned int)confTarget > feeStats.GetMaxConfirms())
return CFeeRate(0);
double median = -1;
while (median < 0 && (unsigned int)confTarget <= feeStats.GetMaxConfirms()) {
median = feeStats.EstimateMedianVal(confTarget++, SUFFICIENT_FEETXS, MIN_SUCCESS_PCT, true, nBestSeenHeight);
}
if (answerFoundAtTarget)
*answerFoundAtTarget = confTarget - 1;
// If mempool is limiting txs , return at least the min fee from the mempool
CAmount minPoolFee = pool.GetMinFee(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
if (minPoolFee > 0 && minPoolFee > median)
return CFeeRate(minPoolFee);
if (median < 0)
return CFeeRate(0);
return CFeeRate(median);
}
double CBlockPolicyEstimator::estimatePriority(int confTarget)
{
// Return failure if trying to analyze a target we're not tracking
if (confTarget <= 0 || (unsigned int)confTarget > priStats.GetMaxConfirms())
return -1;
return priStats.EstimateMedianVal(confTarget, SUFFICIENT_PRITXS, MIN_SUCCESS_PCT, true, nBestSeenHeight);
}
double CBlockPolicyEstimator::estimateSmartPriority(int confTarget, int *answerFoundAtTarget, const CTxMemPool& pool)
{
if (answerFoundAtTarget)
*answerFoundAtTarget = confTarget;
// Return failure if trying to analyze a target we're not tracking
if (confTarget <= 0 || (unsigned int)confTarget > priStats.GetMaxConfirms())
return -1;
// If mempool is limiting txs, no priority txs are allowed
CAmount minPoolFee = pool.GetMinFee(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000).GetFeePerK();
if (minPoolFee > 0)
return INF_PRIORITY;
double median = -1;
while (median < 0 && (unsigned int)confTarget <= priStats.GetMaxConfirms()) {
median = priStats.EstimateMedianVal(confTarget++, SUFFICIENT_PRITXS, MIN_SUCCESS_PCT, true, nBestSeenHeight);
}
if (answerFoundAtTarget)
*answerFoundAtTarget = confTarget - 1;
return median;
}
void CBlockPolicyEstimator::Write(CAutoFile& fileout)
{
fileout << nBestSeenHeight;
feeStats.Write(fileout);
priStats.Write(fileout);
}
void CBlockPolicyEstimator::Read(CAutoFile& filein)
{
int nFileBestSeenHeight;
filein >> nFileBestSeenHeight;
feeStats.Read(filein);
priStats.Read(filein);
nBestSeenHeight = nFileBestSeenHeight;
}
|
#pragma once
#include <cmath> // isfinite
#include <cstdint> // uint8_t
#include <functional> // function
#include <string> // string
#include <utility> // move
#include <vector> // vector
#include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/input/input_adapters.hpp>
#include <nlohmann/detail/input/json_sax.hpp>
#include <nlohmann/detail/input/lexer.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/is_sax.hpp>
#include <nlohmann/detail/value_t.hpp>
namespace nlohmann
{
namespace detail
{
////////////
// parser //
////////////
enum class parse_event_t : uint8_t
{
/// the parser read `{` and started to process a JSON object
object_start,
/// the parser read `}` and finished processing a JSON object
object_end,
/// the parser read `[` and started to process a JSON array
array_start,
/// the parser read `]` and finished processing a JSON array
array_end,
/// the parser read a key of a value in an object
key,
/// the parser finished reading a JSON value
value
};
template<typename BasicJsonType>
using parser_callback_t =
std::function<bool(int depth, parse_event_t event, BasicJsonType& parsed)>;
/*!
@brief syntax analysis
This class implements a recursive descent parser.
*/
template<typename BasicJsonType, typename InputAdapterType>
class parser
{
using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
using lexer_t = lexer<BasicJsonType, InputAdapterType>;
using token_type = typename lexer_t::token_type;
public:
/// a parser reading from an input adapter
explicit parser(InputAdapterType&& adapter,
const parser_callback_t<BasicJsonType> cb = nullptr,
const bool allow_exceptions_ = true,
const bool skip_comments = false)
: callback(cb)
, m_lexer(std::move(adapter), skip_comments)
, allow_exceptions(allow_exceptions_)
{
// read first token
get_token();
}
/*!
@brief public parser interface
@param[in] strict whether to expect the last token to be EOF
@param[in,out] result parsed JSON value
@throw parse_error.101 in case of an unexpected token
@throw parse_error.102 if to_unicode fails or surrogate error
@throw parse_error.103 if to_unicode fails
*/
void parse(const bool strict, BasicJsonType& result)
{
if (callback)
{
json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions);
sax_parse_internal(&sdp);
result.assert_invariant();
// in strict mode, input must be completely read
if (strict && (get_token() != token_type::end_of_input))
{
sdp.parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_of_input, "value")));
}
// in case of an error, return discarded value
if (sdp.is_errored())
{
result = value_t::discarded;
return;
}
// set top-level value to null if it was discarded by the callback
// function
if (result.is_discarded())
{
result = nullptr;
}
}
else
{
json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions);
sax_parse_internal(&sdp);
result.assert_invariant();
// in strict mode, input must be completely read
if (strict && (get_token() != token_type::end_of_input))
{
sdp.parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_of_input, "value")));
}
// in case of an error, return discarded value
if (sdp.is_errored())
{
result = value_t::discarded;
return;
}
}
}
/*!
@brief public accept interface
@param[in] strict whether to expect the last token to be EOF
@return whether the input is a proper JSON text
*/
bool accept(const bool strict = true)
{
json_sax_acceptor<BasicJsonType> sax_acceptor;
return sax_parse(&sax_acceptor, strict);
}
template<typename SAX>
JSON_HEDLEY_NON_NULL(2)
bool sax_parse(SAX* sax, const bool strict = true)
{
(void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
const bool result = sax_parse_internal(sax);
// strict mode: next byte must be EOF
if (result && strict && (get_token() != token_type::end_of_input))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_of_input, "value")));
}
return result;
}
private:
template<typename SAX>
JSON_HEDLEY_NON_NULL(2)
bool sax_parse_internal(SAX* sax)
{
// stack to remember the hierarchy of structured values we are parsing
// true = array; false = object
std::vector<bool> states;
// value to avoid a goto (see comment where set to true)
bool skip_to_state_evaluation = false;
while (true)
{
if (!skip_to_state_evaluation)
{
// invariant: get_token() was called before each iteration
switch (last_token)
{
case token_type::begin_object:
{
if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
{
return false;
}
// closing } -> we are done
if (get_token() == token_type::end_object)
{
if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
{
return false;
}
break;
}
// parse key
if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::value_string, "object key")));
}
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
{
return false;
}
// parse separator (:)
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::name_separator, "object separator")));
}
// remember we are now inside an object
states.push_back(false);
// parse values
get_token();
continue;
}
case token_type::begin_array:
{
if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
{
return false;
}
// closing ] -> we are done
if (get_token() == token_type::end_array)
{
if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
{
return false;
}
break;
}
// remember we are now inside an array
states.push_back(true);
// parse values (no need to call get_token)
continue;
}
case token_type::value_float:
{
const auto res = m_lexer.get_number_float();
if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'"));
}
if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
{
return false;
}
break;
}
case token_type::literal_false:
{
if (JSON_HEDLEY_UNLIKELY(!sax->boolean(false)))
{
return false;
}
break;
}
case token_type::literal_null:
{
if (JSON_HEDLEY_UNLIKELY(!sax->null()))
{
return false;
}
break;
}
case token_type::literal_true:
{
if (JSON_HEDLEY_UNLIKELY(!sax->boolean(true)))
{
return false;
}
break;
}
case token_type::value_integer:
{
if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
{
return false;
}
break;
}
case token_type::value_string:
{
if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
{
return false;
}
break;
}
case token_type::value_unsigned:
{
if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
{
return false;
}
break;
}
case token_type::parse_error:
{
// using "uninitialized" to avoid "expected" message
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::uninitialized, "value")));
}
default: // the last token was unexpected
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::literal_or_value, "value")));
}
}
}
else
{
skip_to_state_evaluation = false;
}
// we reached this line after we successfully parsed a value
if (states.empty())
{
// empty stack: we reached the end of the hierarchy: done
return true;
}
if (states.back()) // array
{
// comma -> next value
if (get_token() == token_type::value_separator)
{
// parse a new value
get_token();
continue;
}
// closing ]
if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
{
if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
{
return false;
}
// We are done with this array. Before we can parse a
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
JSON_ASSERT(!states.empty());
states.pop_back();
skip_to_state_evaluation = true;
continue;
}
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_array, "array")));
}
else // object
{
// comma -> next value
if (get_token() == token_type::value_separator)
{
// parse key
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::value_string, "object key")));
}
if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
{
return false;
}
// parse separator (:)
if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
{
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::name_separator, "object separator")));
}
// parse values
get_token();
continue;
}
// closing }
if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
{
if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
{
return false;
}
// We are done with this object. Before we can parse a
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
JSON_ASSERT(!states.empty());
states.pop_back();
skip_to_state_evaluation = true;
continue;
}
return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_object, "object")));
}
}
}
/// get next token from lexer
token_type get_token()
{
return last_token = m_lexer.scan();
}
std::string exception_message(const token_type expected, const std::string& context)
{
std::string error_msg = "syntax error ";
if (!context.empty())
{
error_msg += "while parsing " + context + " ";
}
error_msg += "- ";
if (last_token == token_type::parse_error)
{
error_msg += std::string(m_lexer.get_error_message()) + "; last read: '" +
m_lexer.get_token_string() + "'";
}
else
{
error_msg += "unexpected " + std::string(lexer_t::token_type_name(last_token));
}
if (expected != token_type::uninitialized)
{
error_msg += "; expected " + std::string(lexer_t::token_type_name(expected));
}
return error_msg;
}
private:
/// callback function
const parser_callback_t<BasicJsonType> callback = nullptr;
/// the type of the last read token
token_type last_token = token_type::uninitialized;
/// the lexer
lexer_t m_lexer;
/// whether to throw exceptions in case of errors
const bool allow_exceptions = true;
};
} // namespace detail
} // namespace nlohmann
|
; A245871: Number of length 2+2 0..n arrays with some pair in every consecutive three terms totalling exactly n.
; 10,45,100,193,318,493,712,993,1330,1741,2220,2785,3430,4173,5008,5953,7002,8173,9460,10881,12430,14125,15960,17953,20098,22413,24892,27553,30390,33421,36640,40065,43690,47533,51588,55873,60382,65133,70120,75361,80850,86605,92620,98913,105478,112333,119472,126913,134650,142701,151060,159745,168750,178093,187768,197793,208162,218893,229980,241441,253270,265485,278080,291073,304458,318253,332452,347073,362110,377581,393480,409825,426610,443853,461548,479713,498342,517453,537040,557121,577690
mov $1,$0
mul $0,3
mod $0,6
add $0,10
mov $2,$1
mul $2,21
add $0,$2
mov $3,$1
mul $3,$1
mov $2,$3
mul $2,10
add $0,$2
mul $3,$1
add $0,$3
|
/****************************************************************************
Copyright (C) 2013 Henry van Merode. All rights reserved.
Copyright (c) 2015 Chukong Technologies Inc.
http://www.cocos2d-x.org
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 "CCPUParticleFollowerTranslator.h"
#include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
#include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
#include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
NS_CC_BEGIN
PUParticleFollowerTranslator::PUParticleFollowerTranslator()
{
}
//-------------------------------------------------------------------------
bool PUParticleFollowerTranslator::translateChildProperty( PUScriptCompiler* compiler, PUAbstractNode *node )
{
PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>(node);
PUAffector* af = static_cast<PUAffector*>(prop->parent->context);
PUParticleFollower* affector = static_cast<PUParticleFollower*>(af);
if (prop->name == token[TOKEN_MIN_DISTANCE])
{
// Property: min_distance
if (passValidateProperty(compiler, prop, token[TOKEN_MIN_DISTANCE], VAL_REAL))
{
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
affector->setMinDistance(val);
return true;
}
}
}
else if (prop->name == token[TOKEN_FOLLOW_MIN_DISTANCE])
{
// Property: follower_min_distance (deprecated and replaced by 'min_distance')
if (passValidateProperty(compiler, prop, token[TOKEN_FOLLOW_MIN_DISTANCE], VAL_REAL))
{
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
affector->setMinDistance(val);
return true;
}
}
}
else if (prop->name == token[TOKEN_MAX_DISTANCE])
{
// Property: max_distance
if (passValidateProperty(compiler, prop, token[TOKEN_MAX_DISTANCE], VAL_REAL))
{
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
affector->setMaxDistance(val);
return true;
}
}
}
else if (prop->name == token[TOKEN_FOLLOW_MAX_DISTANCE])
{
// Property: follower_max_distance (deprecated and replaced by 'TOKEN_MAX_DISTANCE')
if (passValidateProperty(compiler, prop, token[TOKEN_FOLLOW_MAX_DISTANCE], VAL_REAL))
{
float val = 0.0f;
if(getFloat(*prop->values.front(), &val))
{
affector->setMaxDistance(val);
return true;
}
}
}
return false;
}
bool PUParticleFollowerTranslator::translateChildObject( PUScriptCompiler* compiler, PUAbstractNode *node )
{
// No objects
return false;
}
NS_CC_END |
###############################################################################
# Copyright 2018 Intel Corporation
# All Rights Reserved.
#
# If this software was obtained under the Intel Simplified Software License,
# the following terms apply:
#
# The source code, information and material ("Material") contained herein is
# owned by Intel Corporation or its suppliers or licensors, and title to such
# Material remains with Intel Corporation or its suppliers or licensors. The
# Material contains proprietary information of Intel or its suppliers and
# licensors. The Material is protected by worldwide copyright laws and treaty
# provisions. No part of the Material may be used, copied, reproduced,
# modified, published, uploaded, posted, transmitted, distributed or disclosed
# in any way without Intel's prior express written permission. No license under
# any patent, copyright or other intellectual property rights in the Material
# is granted to or conferred upon you, either expressly, by implication,
# inducement, estoppel or otherwise. Any license under such intellectual
# property rights must be express and approved by Intel in writing.
#
# Unless otherwise agreed by Intel in writing, you may not remove or alter this
# notice or any other notice embedded in Materials by Intel or Intel's
# suppliers or licensors in any way.
#
#
# If this software was obtained under the Apache License, Version 2.0 (the
# "License"), the following terms apply:
#
# You may not use this file except in compliance with the License. You may
# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
.text
.p2align 5, 0x90
.globl _e9_DecryptCFB_RIJ128pipe_AES_NI
_e9_DecryptCFB_RIJ128pipe_AES_NI:
push %r13
push %r14
push %r15
sub $(144), %rsp
mov (176)(%rsp), %rax
movdqu (%rax), %xmm4
movdqa %xmm4, (%rsp)
mov %rdi, %r13
mov %rsi, %r14
mov %rcx, %r15
movslq %r8d, %r8
movslq %r9d, %r9
sub $(4), %r8
jl .Lshort_inputgas_1
lea (,%r9,4), %r10
.Lblks_loopgas_1:
xor %rcx, %rcx
.L__000Agas_1:
movl (%r13,%rcx), %r11d
movl %r11d, (16)(%rsp,%rcx)
add $(4), %rcx
cmp %r10, %rcx
jl .L__000Agas_1
movdqa (%r15), %xmm4
lea (%r9,%r9,2), %r10
movdqa (%rsp), %xmm0
movdqu (%rsp,%r9), %xmm1
movdqu (%rsp,%r9,2), %xmm2
movdqu (%rsp,%r10), %xmm3
mov %r15, %r10
pxor %xmm4, %xmm0
pxor %xmm4, %xmm1
pxor %xmm4, %xmm2
pxor %xmm4, %xmm3
movdqa (16)(%r10), %xmm4
add $(16), %r10
mov %rdx, %r11
sub $(1), %r11
.Lcipher_loopgas_1:
aesenc %xmm4, %xmm0
aesenc %xmm4, %xmm1
aesenc %xmm4, %xmm2
aesenc %xmm4, %xmm3
movdqa (16)(%r10), %xmm4
add $(16), %r10
dec %r11
jnz .Lcipher_loopgas_1
aesenclast %xmm4, %xmm0
aesenclast %xmm4, %xmm1
aesenclast %xmm4, %xmm2
aesenclast %xmm4, %xmm3
lea (%r9,%r9,2), %r10
movdqa (16)(%rsp), %xmm4
movdqu (16)(%rsp,%r9), %xmm5
movdqu (16)(%rsp,%r9,2), %xmm6
movdqu (16)(%rsp,%r10), %xmm7
pxor %xmm4, %xmm0
movdqa %xmm0, (80)(%rsp)
pxor %xmm5, %xmm1
movdqu %xmm1, (80)(%rsp,%r9)
pxor %xmm6, %xmm2
movdqu %xmm2, (80)(%rsp,%r9,2)
pxor %xmm7, %xmm3
movdqu %xmm3, (80)(%rsp,%r10)
lea (,%r9,4), %r10
xor %rcx, %rcx
.L__000Bgas_1:
movl (80)(%rsp,%rcx), %r11d
movl %r11d, (%r14,%rcx)
add $(4), %rcx
cmp %r10, %rcx
jl .L__000Bgas_1
movdqu (%rsp,%r10), %xmm0
movdqu %xmm0, (%rsp)
add %r10, %r13
add %r10, %r14
sub $(4), %r8
jge .Lblks_loopgas_1
.Lshort_inputgas_1:
add $(4), %r8
jz .Lquitgas_1
lea (,%r9,2), %r10
lea (%r9,%r9,2), %r11
cmp $(2), %r8
cmovl %r9, %r10
cmovg %r11, %r10
xor %rcx, %rcx
.L__000Cgas_1:
movb (%r13,%rcx), %al
movb %al, (16)(%rsp,%rcx)
add $(1), %rcx
cmp %r10, %rcx
jl .L__000Cgas_1
lea (,%rdx,4), %rax
lea (-144)(%r15,%rax,4), %rax
xor %r11, %r11
.Lsingle_blk_loopgas_1:
movdqu (%rsp,%r11), %xmm0
pxor (%r15), %xmm0
cmp $(12), %rdx
jl .Lkey_128_sgas_1
jz .Lkey_192_sgas_1
.Lkey_256_sgas_1:
aesenc (-64)(%rax), %xmm0
aesenc (-48)(%rax), %xmm0
.Lkey_192_sgas_1:
aesenc (-32)(%rax), %xmm0
aesenc (-16)(%rax), %xmm0
.Lkey_128_sgas_1:
aesenc (%rax), %xmm0
aesenc (16)(%rax), %xmm0
aesenc (32)(%rax), %xmm0
aesenc (48)(%rax), %xmm0
aesenc (64)(%rax), %xmm0
aesenc (80)(%rax), %xmm0
aesenc (96)(%rax), %xmm0
aesenc (112)(%rax), %xmm0
aesenc (128)(%rax), %xmm0
aesenclast (144)(%rax), %xmm0
movdqu (16)(%rsp,%r11), %xmm1
pxor %xmm1, %xmm0
movdqu %xmm0, (80)(%rsp,%r11)
add %r9, %r11
dec %r8
jnz .Lsingle_blk_loopgas_1
xor %rcx, %rcx
.L__000Dgas_1:
movb (80)(%rsp,%rcx), %al
movb %al, (%r14,%rcx)
add $(1), %rcx
cmp %r10, %rcx
jl .L__000Dgas_1
.Lquitgas_1:
add $(144), %rsp
vzeroupper
pop %r15
pop %r14
pop %r13
ret
.p2align 5, 0x90
.globl _e9_DecryptCFB32_RIJ128pipe_AES_NI
_e9_DecryptCFB32_RIJ128pipe_AES_NI:
push %r13
push %r14
push %r15
sub $(144), %rsp
mov (176)(%rsp), %rax
movdqu (%rax), %xmm4
movdqa %xmm4, (%rsp)
mov %rdi, %r13
mov %rsi, %r14
mov %rcx, %r15
movslq %r8d, %r8
movslq %r9d, %r9
sub $(4), %r8
jl .Lshort_inputgas_2
lea (,%r9,4), %r10
.Lblks_loopgas_2:
xor %rcx, %rcx
.L__0020gas_2:
movdqu (%r13,%rcx), %xmm0
movdqu %xmm0, (16)(%rsp,%rcx)
add $(16), %rcx
cmp %r10, %rcx
jl .L__0020gas_2
movdqa (%r15), %xmm4
lea (%r9,%r9,2), %r10
movdqa (%rsp), %xmm0
movdqu (%rsp,%r9), %xmm1
movdqu (%rsp,%r9,2), %xmm2
movdqu (%rsp,%r10), %xmm3
mov %r15, %r10
pxor %xmm4, %xmm0
pxor %xmm4, %xmm1
pxor %xmm4, %xmm2
pxor %xmm4, %xmm3
movdqa (16)(%r10), %xmm4
add $(16), %r10
mov %rdx, %r11
sub $(1), %r11
.Lcipher_loopgas_2:
aesenc %xmm4, %xmm0
aesenc %xmm4, %xmm1
aesenc %xmm4, %xmm2
aesenc %xmm4, %xmm3
movdqa (16)(%r10), %xmm4
add $(16), %r10
dec %r11
jnz .Lcipher_loopgas_2
aesenclast %xmm4, %xmm0
aesenclast %xmm4, %xmm1
aesenclast %xmm4, %xmm2
aesenclast %xmm4, %xmm3
lea (%r9,%r9,2), %r10
movdqa (16)(%rsp), %xmm4
movdqu (16)(%rsp,%r9), %xmm5
movdqu (16)(%rsp,%r9,2), %xmm6
movdqu (16)(%rsp,%r10), %xmm7
pxor %xmm4, %xmm0
movdqa %xmm0, (80)(%rsp)
pxor %xmm5, %xmm1
movdqu %xmm1, (80)(%rsp,%r9)
pxor %xmm6, %xmm2
movdqu %xmm2, (80)(%rsp,%r9,2)
pxor %xmm7, %xmm3
movdqu %xmm3, (80)(%rsp,%r10)
lea (,%r9,4), %r10
xor %rcx, %rcx
.L__0021gas_2:
movdqu (80)(%rsp,%rcx), %xmm0
movdqu %xmm0, (%r14,%rcx)
add $(16), %rcx
cmp %r10, %rcx
jl .L__0021gas_2
movdqu (%rsp,%r10), %xmm0
movdqu %xmm0, (%rsp)
add %r10, %r13
add %r10, %r14
sub $(4), %r8
jge .Lblks_loopgas_2
.Lshort_inputgas_2:
add $(4), %r8
jz .Lquitgas_2
lea (,%r9,2), %r10
lea (%r9,%r9,2), %r11
cmp $(2), %r8
cmovl %r9, %r10
cmovg %r11, %r10
xor %rcx, %rcx
.L__0022gas_2:
movl (%r13,%rcx), %eax
movl %eax, (16)(%rsp,%rcx)
add $(4), %rcx
cmp %r10, %rcx
jl .L__0022gas_2
lea (,%rdx,4), %rax
lea (-144)(%r15,%rax,4), %rax
xor %r11, %r11
.Lsingle_blk_loopgas_2:
movdqu (%rsp,%r11), %xmm0
pxor (%r15), %xmm0
cmp $(12), %rdx
jl .Lkey_128_sgas_2
jz .Lkey_192_sgas_2
.Lkey_256_sgas_2:
aesenc (-64)(%rax), %xmm0
aesenc (-48)(%rax), %xmm0
.Lkey_192_sgas_2:
aesenc (-32)(%rax), %xmm0
aesenc (-16)(%rax), %xmm0
.Lkey_128_sgas_2:
aesenc (%rax), %xmm0
aesenc (16)(%rax), %xmm0
aesenc (32)(%rax), %xmm0
aesenc (48)(%rax), %xmm0
aesenc (64)(%rax), %xmm0
aesenc (80)(%rax), %xmm0
aesenc (96)(%rax), %xmm0
aesenc (112)(%rax), %xmm0
aesenc (128)(%rax), %xmm0
aesenclast (144)(%rax), %xmm0
movdqu (16)(%rsp,%r11), %xmm1
pxor %xmm1, %xmm0
movdqu %xmm0, (80)(%rsp,%r11)
add %r9, %r11
dec %r8
jnz .Lsingle_blk_loopgas_2
xor %rcx, %rcx
.L__0023gas_2:
movl (80)(%rsp,%rcx), %eax
movl %eax, (%r14,%rcx)
add $(4), %rcx
cmp %r10, %rcx
jl .L__0023gas_2
.Lquitgas_2:
add $(144), %rsp
vzeroupper
pop %r15
pop %r14
pop %r13
ret
.p2align 5, 0x90
.globl _e9_DecryptCFB128_RIJ128pipe_AES_NI
_e9_DecryptCFB128_RIJ128pipe_AES_NI:
movdqu (%r9), %xmm0
movslq %r8d, %r8
sub $(64), %r8
jl .Lshort_inputgas_3
.Lblks_loopgas_3:
movdqa (%rcx), %xmm7
mov %rcx, %r10
movdqu (%rdi), %xmm1
movdqu (16)(%rdi), %xmm2
movdqu (32)(%rdi), %xmm3
pxor %xmm7, %xmm0
pxor %xmm7, %xmm1
pxor %xmm7, %xmm2
pxor %xmm7, %xmm3
movdqa (16)(%r10), %xmm7
add $(16), %r10
mov %rdx, %r11
sub $(1), %r11
.Lcipher_loopgas_3:
aesenc %xmm7, %xmm0
aesenc %xmm7, %xmm1
aesenc %xmm7, %xmm2
aesenc %xmm7, %xmm3
movdqa (16)(%r10), %xmm7
add $(16), %r10
dec %r11
jnz .Lcipher_loopgas_3
aesenclast %xmm7, %xmm0
movdqu (%rdi), %xmm4
aesenclast %xmm7, %xmm1
movdqu (16)(%rdi), %xmm5
aesenclast %xmm7, %xmm2
movdqu (32)(%rdi), %xmm6
aesenclast %xmm7, %xmm3
movdqu (48)(%rdi), %xmm7
add $(64), %rdi
pxor %xmm4, %xmm0
movdqu %xmm0, (%rsi)
pxor %xmm5, %xmm1
movdqu %xmm1, (16)(%rsi)
pxor %xmm6, %xmm2
movdqu %xmm2, (32)(%rsi)
pxor %xmm7, %xmm3
movdqu %xmm3, (48)(%rsi)
add $(64), %rsi
movdqa %xmm7, %xmm0
sub $(64), %r8
jge .Lblks_loopgas_3
.Lshort_inputgas_3:
add $(64), %r8
jz .Lquitgas_3
lea (,%rdx,4), %rax
lea (-144)(%rcx,%rax,4), %rax
.Lsingle_blk_loopgas_3:
pxor (%rcx), %xmm0
cmp $(12), %rdx
jl .Lkey_128_sgas_3
jz .Lkey_192_sgas_3
.Lkey_256_sgas_3:
aesenc (-64)(%rax), %xmm0
aesenc (-48)(%rax), %xmm0
.Lkey_192_sgas_3:
aesenc (-32)(%rax), %xmm0
aesenc (-16)(%rax), %xmm0
.Lkey_128_sgas_3:
aesenc (%rax), %xmm0
aesenc (16)(%rax), %xmm0
aesenc (32)(%rax), %xmm0
aesenc (48)(%rax), %xmm0
aesenc (64)(%rax), %xmm0
aesenc (80)(%rax), %xmm0
aesenc (96)(%rax), %xmm0
aesenc (112)(%rax), %xmm0
aesenc (128)(%rax), %xmm0
aesenclast (144)(%rax), %xmm0
movdqu (%rdi), %xmm1
add $(16), %rdi
pxor %xmm1, %xmm0
movdqu %xmm0, (%rsi)
add $(16), %rsi
movdqa %xmm1, %xmm0
sub $(16), %r8
jnz .Lsingle_blk_loopgas_3
.Lquitgas_3:
vzeroupper
ret
|
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
* Copyright (c) 2020, the SerenityOS developers
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "HackStudioWidget.h"
#include "CursorTool.h"
#include "Debugger/DebugInfoWidget.h"
#include "Debugger/Debugger.h"
#include "Debugger/DisassemblyWidget.h"
#include "Editor.h"
#include "EditorWrapper.h"
#include "FindInFilesWidget.h"
#include "FormEditorWidget.h"
#include "FormWidget.h"
#include "Git/DiffViewer.h"
#include "Git/GitWidget.h"
#include "HackStudio.h"
#include "HackStudioWidget.h"
#include "Locator.h"
#include "Project.h"
#include "TerminalWrapper.h"
#include "WidgetTool.h"
#include "WidgetTreeModel.h"
#include <AK/StringBuilder.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/Event.h>
#include <LibCore/EventLoop.h>
#include <LibCore/File.h>
#include <LibDebug/DebugSession.h>
#include <LibGUI/AboutDialog.h>
#include <LibGUI/Action.h>
#include <LibGUI/ActionGroup.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
#include <LibGUI/FilePicker.h>
#include <LibGUI/InputBox.h>
#include <LibGUI/Label.h>
#include <LibGUI/Menu.h>
#include <LibGUI/MenuBar.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/Splitter.h>
#include <LibGUI/StackWidget.h>
#include <LibGUI/TabWidget.h>
#include <LibGUI/TableView.h>
#include <LibGUI/TextBox.h>
#include <LibGUI/TextEditor.h>
#include <LibGUI/ToolBar.h>
#include <LibGUI/ToolBarContainer.h>
#include <LibGUI/TreeView.h>
#include <LibGUI/Widget.h>
#include <LibGUI/Window.h>
#include <LibThread/Lock.h>
#include <LibThread/Thread.h>
#include <LibVT/TerminalWidget.h>
#include <fcntl.h>
#include <spawn.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
namespace HackStudio {
HackStudioWidget::HackStudioWidget(const String& path_to_project)
{
set_fill_with_background_color(true);
set_layout<GUI::VerticalBoxLayout>();
layout()->set_spacing(2);
open_project(path_to_project);
auto& toolbar_container = add<GUI::ToolBarContainer>();
auto& outer_splitter = add<GUI::HorizontalSplitter>();
create_project_tree_view(outer_splitter);
m_project_tree_view_context_menu = create_project_tree_view_context_menu();
m_right_hand_splitter = outer_splitter.add<GUI::VerticalSplitter>();
m_right_hand_stack = m_right_hand_splitter->add<GUI::StackWidget>();
create_form_editor(*m_right_hand_stack);
m_diff_viewer = m_right_hand_stack->add<DiffViewer>();
m_editors_splitter = m_right_hand_stack->add<GUI::VerticalSplitter>();
m_editors_splitter->layout()->set_margins({ 0, 3, 0, 0 });
add_new_editor(*m_editors_splitter);
m_switch_to_next_editor = create_switch_to_next_editor_action();
m_switch_to_previous_editor = create_switch_to_previous_editor_action();
m_remove_current_editor_action = create_remove_current_editor_action();
m_open_action = create_open_action();
m_save_action = create_save_action();
create_action_tab(*m_right_hand_splitter);
m_add_editor_action = create_add_editor_action();
m_add_terminal_action = create_add_terminal_action();
m_remove_current_terminal_action = create_remove_current_terminal_action();
m_locator = add<Locator>();
m_terminal_wrapper->on_command_exit = [this] {
m_stop_action->set_enabled(false);
};
m_build_action = create_build_action();
m_run_action = create_run_action();
m_stop_action = create_stop_action();
m_debug_action = create_debug_action();
initialize_debugger();
create_toolbar(toolbar_container);
}
void HackStudioWidget::update_actions()
{
auto is_remove_terminal_enabled = [this]() {
auto widget = m_action_tab_widget->active_widget();
if (!widget)
return false;
if (StringView { "TerminalWrapper" } != widget->class_name())
return false;
if (!reinterpret_cast<TerminalWrapper*>(widget)->user_spawned())
return false;
return true;
};
m_remove_current_editor_action->set_enabled(m_all_editor_wrappers.size() > 1);
m_remove_current_terminal_action->set_enabled(is_remove_terminal_enabled());
}
void HackStudioWidget::on_action_tab_change()
{
update_actions();
auto git_widget = m_action_tab_widget->active_widget();
if (!git_widget)
return;
if (StringView { "GitWidget" } != git_widget->class_name())
return;
reinterpret_cast<GitWidget*>(git_widget)->refresh();
}
void HackStudioWidget::open_project(String filename)
{
LexicalPath lexical_path(filename);
if (chdir(lexical_path.dirname().characters()) < 0) {
perror("chdir");
exit(1);
}
m_project = Project::load_from_file(filename);
ASSERT(m_project);
if (m_project_tree_view) {
m_project_tree_view->set_model(m_project->model());
m_project_tree_view->toggle_index(m_project_tree_view->model()->index(0, 0));
m_project_tree_view->update();
}
if (Debugger::is_initialized()) {
Debugger::the().reset_breakpoints();
}
}
Vector<String> HackStudioWidget::selected_file_names() const
{
Vector<String> files;
m_project_tree_view->selection().for_each_index([&](const GUI::ModelIndex& index) {
files.append(index.data().as_string());
});
return files;
}
void HackStudioWidget::open_file(const String& filename)
{
auto project_file = m_project->get_file(filename);
if (project_file) {
current_editor().set_document(const_cast<GUI::TextDocument&>(project_file->document()));
current_editor().set_mode(GUI::TextEditor::Editable);
} else {
auto external_file = ProjectFile::construct_with_name(filename);
current_editor().set_document(const_cast<GUI::TextDocument&>(external_file->document()));
current_editor().set_mode(GUI::TextEditor::ReadOnly);
}
if (filename.ends_with(".frm")) {
set_edit_mode(EditMode::Form);
} else {
set_edit_mode(EditMode::Text);
}
m_currently_open_file = filename;
window()->set_title(String::formatted("{} - HackStudio", m_currently_open_file));
m_project_tree_view->update();
current_editor_wrapper().filename_label().set_text(filename);
current_editor().set_focus(true);
}
EditorWrapper& HackStudioWidget::current_editor_wrapper()
{
ASSERT(m_current_editor_wrapper);
return *m_current_editor_wrapper;
}
GUI::TextEditor& HackStudioWidget::current_editor()
{
return current_editor_wrapper().editor();
}
void HackStudioWidget::set_edit_mode(EditMode mode)
{
if (mode == EditMode::Text) {
m_right_hand_stack->set_active_widget(m_editors_splitter);
} else if (mode == EditMode::Form) {
m_right_hand_stack->set_active_widget(m_form_inner_container);
} else if (mode == EditMode::Diff) {
m_right_hand_stack->set_active_widget(m_diff_viewer);
} else {
ASSERT_NOT_REACHED();
}
m_right_hand_stack->active_widget()->update();
}
NonnullRefPtr<GUI::Menu> HackStudioWidget::create_project_tree_view_context_menu()
{
m_open_selected_action = create_open_selected_action();
m_new_action = create_new_action();
m_add_existing_file_action = create_add_existing_file_action();
m_delete_action = create_delete_action();
auto project_tree_view_context_menu = GUI::Menu::construct("Project Files");
project_tree_view_context_menu->add_action(*m_open_selected_action);
// TODO: Rename, cut, copy, duplicate with new name, show containing folder ...
project_tree_view_context_menu->add_separator();
project_tree_view_context_menu->add_action(*m_new_action);
project_tree_view_context_menu->add_action(*m_add_existing_file_action);
project_tree_view_context_menu->add_action(*m_delete_action);
return project_tree_view_context_menu;
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_new_action()
{
return GUI::Action::create("Add new file to project...", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [this](const GUI::Action&) {
String filename;
if (GUI::InputBox::show(filename, window(), "Enter name of new file:", "Add new file to project") != GUI::InputBox::ExecOK)
return;
auto file = Core::File::construct(filename);
if (!file->open((Core::IODevice::OpenMode)(Core::IODevice::WriteOnly | Core::IODevice::MustBeNew))) {
GUI::MessageBox::show(window(), String::formatted("Failed to create '{}'", filename), "Error", GUI::MessageBox::Type::Error);
return;
}
if (!m_project->add_file(filename)) {
GUI::MessageBox::show(window(), String::formatted("Failed to add '{}' to project", filename), "Error", GUI::MessageBox::Type::Error);
// FIXME: Should we unlink the file here maybe?
return;
}
m_project_tree_view->toggle_index(m_project_tree_view->model()->index(0, 0));
open_file(filename);
});
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_open_selected_action()
{
auto open_selected_action = GUI::Action::create("Open", [this](const GUI::Action&) {
auto files = selected_file_names();
for (auto& file : files)
open_file(file);
});
open_selected_action->set_enabled(true);
return open_selected_action;
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_add_existing_file_action()
{
return GUI::Action::create("Add existing file to project...", Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"), [this](auto&) {
auto result = GUI::FilePicker::get_open_filepath(window(), "Add existing file to project");
if (!result.has_value())
return;
auto& filename = result.value();
if (!m_project->add_file(filename)) {
GUI::MessageBox::show(window(), String::formatted("Failed to add '{}' to project", filename), "Error", GUI::MessageBox::Type::Error);
return;
}
m_project_tree_view->toggle_index(m_project_tree_view->model()->index(0, 0));
open_file(filename);
});
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_delete_action()
{
auto delete_action = GUI::CommonActions::make_delete_action([this](const GUI::Action&) {
auto files = selected_file_names();
if (files.is_empty())
return;
String message;
if (files.size() == 1) {
message = String::formatted("Really remove {} from the project?", LexicalPath(files[0]).basename());
} else {
message = String::formatted("Really remove {} files from the project?", files.size());
}
auto result = GUI::MessageBox::show(window(),
message,
"Confirm deletion",
GUI::MessageBox::Type::Warning,
GUI::MessageBox::InputType::OKCancel);
if (result == GUI::MessageBox::ExecCancel)
return;
for (auto& file : files) {
if (!m_project->remove_file(file)) {
GUI::MessageBox::show(window(),
String::formatted("Removing file {} from the project failed.", file),
"Removal failed",
GUI::MessageBox::Type::Error);
break;
}
}
});
delete_action->set_enabled(false);
return delete_action;
}
void HackStudioWidget::add_new_editor(GUI::Widget& parent)
{
auto wrapper = EditorWrapper::construct();
if (m_action_tab_widget) {
parent.insert_child_before(wrapper, *m_action_tab_widget);
} else {
parent.add_child(wrapper);
}
m_current_editor_wrapper = wrapper;
m_all_editor_wrappers.append(wrapper);
wrapper->editor().set_focus(true);
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_switch_to_next_editor_action()
{
return GUI::Action::create("Switch to next editor", { Mod_Ctrl, Key_E }, [this](auto&) {
if (m_all_editor_wrappers.size() <= 1)
return;
Vector<EditorWrapper*> wrappers;
m_editors_splitter->for_each_child_of_type<EditorWrapper>([this, &wrappers](auto& child) {
wrappers.append(&child);
return IterationDecision::Continue;
});
for (size_t i = 0; i < wrappers.size(); ++i) {
if (m_current_editor_wrapper.ptr() == wrappers[i]) {
if (i == wrappers.size() - 1)
wrappers[0]->editor().set_focus(true);
else
wrappers[i + 1]->editor().set_focus(true);
}
}
});
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_switch_to_previous_editor_action()
{
return GUI::Action::create("Switch to previous editor", { Mod_Ctrl | Mod_Shift, Key_E }, [this](auto&) {
if (m_all_editor_wrappers.size() <= 1)
return;
Vector<EditorWrapper*> wrappers;
m_editors_splitter->for_each_child_of_type<EditorWrapper>([this, &wrappers](auto& child) {
wrappers.append(&child);
return IterationDecision::Continue;
});
for (int i = wrappers.size() - 1; i >= 0; --i) {
if (m_current_editor_wrapper.ptr() == wrappers[i]) {
if (i == 0)
wrappers.last()->editor().set_focus(true);
else
wrappers[i - 1]->editor().set_focus(true);
}
}
});
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_remove_current_editor_action()
{
return GUI::Action::create("Remove current editor", { Mod_Alt | Mod_Shift, Key_E }, [this](auto&) {
if (m_all_editor_wrappers.size() <= 1)
return;
auto wrapper = m_current_editor_wrapper;
m_switch_to_next_editor->activate();
m_editors_splitter->remove_child(*wrapper);
m_all_editor_wrappers.remove_first_matching([&wrapper](auto& entry) { return entry == wrapper.ptr(); });
update_actions();
});
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_open_action()
{
return GUI::Action::create("Open project...", { Mod_Ctrl | Mod_Shift, Key_O }, Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"), [this](auto&) {
auto open_path = GUI::FilePicker::get_open_filepath(window(), "Open project");
if (!open_path.has_value())
return;
open_project(open_path.value());
open_file(m_project->default_file());
update_actions();
});
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_save_action()
{
return GUI::Action::create("Save", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [this](auto&) {
if (m_currently_open_file.is_empty())
return;
current_editor().write_to_file(m_currently_open_file);
if (m_git_widget->initialized())
m_git_widget->refresh();
});
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_remove_current_terminal_action()
{
return GUI::Action::create("Remove current Terminal", { Mod_Alt | Mod_Shift, Key_T }, [this](auto&) {
auto widget = m_action_tab_widget->active_widget();
if (!widget)
return;
if (strcmp(widget->class_name(), "TerminalWrapper") != 0)
return;
auto terminal = reinterpret_cast<TerminalWrapper*>(widget);
if (!terminal->user_spawned())
return;
m_action_tab_widget->remove_tab(*terminal);
update_actions();
});
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_add_editor_action()
{
return GUI::Action::create("Add new editor", { Mod_Ctrl | Mod_Alt, Key_E },
Gfx::Bitmap::load_from_file("/res/icons/16x16/app-text-editor.png"),
[this](auto&) {
add_new_editor(*m_editors_splitter);
update_actions();
});
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_add_terminal_action()
{
return GUI::Action::create("Add new Terminal", { Mod_Ctrl | Mod_Alt, Key_T },
Gfx::Bitmap::load_from_file("/res/icons/16x16/app-terminal.png"),
[this](auto&) {
auto& terminal = m_action_tab_widget->add_tab<TerminalWrapper>("Terminal");
reveal_action_tab(terminal);
update_actions();
terminal.terminal()->set_focus(true);
});
}
void HackStudioWidget::reveal_action_tab(GUI::Widget& widget)
{
if (m_action_tab_widget->preferred_size().height() < 200)
m_action_tab_widget->set_preferred_size(0, 200);
m_action_tab_widget->set_active_widget(&widget);
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_debug_action()
{
return GUI::Action::create("Debug", Gfx::Bitmap::load_from_file("/res/icons/16x16/debug-run.png"), [this](auto&) {
if (m_project->type() != ProjectType::Cpp) {
GUI::MessageBox::show(window(), "Cannot debug current project type", "Error", GUI::MessageBox::Type::Error);
return;
}
if (!GUI::FilePicker::file_exists(get_project_executable_path())) {
GUI::MessageBox::show(window(), String::formatted("Could not find file: {}. (did you build the project?)", get_project_executable_path()), "Error", GUI::MessageBox::Type::Error);
return;
}
if (Debugger::the().session()) {
GUI::MessageBox::show(window(), "Debugger is already running", "Error", GUI::MessageBox::Type::Error);
return;
}
Debugger::the().set_executable_path(get_project_executable_path());
m_debugger_thread = adopt(*new LibThread::Thread(Debugger::start_static));
m_debugger_thread->start();
});
}
void HackStudioWidget::initialize_debugger()
{
Debugger::initialize(
[this](const PtraceRegisters& regs) {
ASSERT(Debugger::the().session());
const auto& debug_session = *Debugger::the().session();
auto source_position = debug_session.debug_info().get_source_position(regs.eip);
if (!source_position.has_value()) {
dbgln("Could not find source position for address: {:p}", regs.eip);
return Debugger::HasControlPassedToUser::No;
}
Core::EventLoop::main().post_event(
*window(),
make<Core::DeferredInvocationEvent>(
[this, source_position, ®s](auto&) {
m_current_editor_in_execution = get_editor_of_file(source_position.value().file_path);
m_current_editor_in_execution->editor().set_execution_position(source_position.value().line_number - 1);
m_debug_info_widget->update_state(*Debugger::the().session(), regs);
m_debug_info_widget->set_debug_actions_enabled(true);
m_disassembly_widget->update_state(*Debugger::the().session(), regs);
HackStudioWidget::reveal_action_tab(*m_debug_info_widget);
}));
Core::EventLoop::wake();
return Debugger::HasControlPassedToUser::Yes;
},
[this]() {
Core::EventLoop::main().post_event(*window(), make<Core::DeferredInvocationEvent>([this](auto&) {
m_debug_info_widget->set_debug_actions_enabled(false);
if (m_current_editor_in_execution) {
m_current_editor_in_execution->editor().clear_execution_position();
}
}));
Core::EventLoop::wake();
},
[this]() {
Core::EventLoop::main().post_event(*window(), make<Core::DeferredInvocationEvent>([this](auto&) {
m_debug_info_widget->program_stopped();
m_disassembly_widget->program_stopped();
HackStudioWidget::hide_action_tabs();
GUI::MessageBox::show(window(), "Program Exited", "Debugger", GUI::MessageBox::Type::Information);
}));
Core::EventLoop::wake();
});
}
String HackStudioWidget::get_full_path_of_serenity_source(const String& file)
{
auto path_parts = LexicalPath(file).parts();
ASSERT(path_parts[0] == "..");
path_parts.remove(0);
StringBuilder relative_path_builder;
relative_path_builder.join("/", path_parts);
constexpr char SERENITY_LIBS_PREFIX[] = "/usr/src/serenity";
LexicalPath serenity_sources_base(SERENITY_LIBS_PREFIX);
return String::formatted("{}/{}", serenity_sources_base, relative_path_builder.to_string());
}
NonnullRefPtr<EditorWrapper> HackStudioWidget::get_editor_of_file(const String& file_name)
{
String file_path = file_name;
// TODO: We can probably do a more specific condition here, something like
// "if (file.starts_with("../Libraries/") || file.starts_with("../AK/"))"
if (file_name.starts_with("../")) {
file_path = get_full_path_of_serenity_source(file_name);
}
open_file(file_path);
return current_editor_wrapper();
}
String HackStudioWidget::get_project_executable_path() const
{
// e.g /my/project.hsp => /my/project
// TODO: Perhaps a Makefile rule for getting the value of $(PROGRAM) would be better?
return m_project->path().substring(0, m_project->path().index_of(".").value());
}
void HackStudioWidget::build(TerminalWrapper& wrapper)
{
if (m_project->type() == ProjectType::JavaScript && m_currently_open_file.ends_with(".js"))
wrapper.run_command(String::formatted("js -A {}", m_currently_open_file));
else
wrapper.run_command("make");
}
void HackStudioWidget::run(TerminalWrapper& wrapper)
{
if (m_project->type() == ProjectType::JavaScript && m_currently_open_file.ends_with(".js"))
wrapper.run_command(String::formatted("js {}", m_currently_open_file));
else
wrapper.run_command("make run");
}
void HackStudioWidget::hide_action_tabs()
{
m_action_tab_widget->set_preferred_size(0, 24);
};
Project& HackStudioWidget::project()
{
return *m_project;
}
void HackStudioWidget::set_current_editor_wrapper(RefPtr<EditorWrapper> editor_wrapper)
{
m_current_editor_wrapper = editor_wrapper;
}
void HackStudioWidget::create_project_tree_view(GUI::Widget& parent)
{
m_project_tree_view = parent.add<GUI::TreeView>();
m_project_tree_view->set_model(m_project->model());
m_project_tree_view->set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
m_project_tree_view->set_preferred_size(140, 0);
m_project_tree_view->toggle_index(m_project_tree_view->model()->index(0, 0));
m_project_tree_view->on_context_menu_request = [this](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) {
if (index.is_valid()) {
m_project_tree_view_context_menu->popup(event.screen_position(), m_open_selected_action);
}
};
m_project_tree_view->on_selection_change = [this] {
m_open_selected_action->set_enabled(!m_project_tree_view->selection().is_empty());
m_delete_action->set_enabled(!m_project_tree_view->selection().is_empty());
};
m_project_tree_view->on_activation = [this](auto& index) {
auto filename = index.data(GUI::ModelRole::Custom).to_string();
open_file(filename);
};
}
void HackStudioWidget::create_form_editor(GUI::Widget& parent)
{
m_form_inner_container = parent.add<GUI::Widget>();
m_form_inner_container->set_layout<GUI::HorizontalBoxLayout>();
auto& form_widgets_toolbar = m_form_inner_container->add<GUI::ToolBar>(Orientation::Vertical, 26);
form_widgets_toolbar.set_preferred_size(38, 0);
GUI::ActionGroup tool_actions;
tool_actions.set_exclusive(true);
auto cursor_tool_action = GUI::Action::create_checkable("Cursor", Gfx::Bitmap::load_from_file("/res/icons/hackstudio/Cursor.png"), [this](auto&) {
m_form_editor_widget->set_tool(make<CursorTool>(*m_form_editor_widget));
});
cursor_tool_action->set_checked(true);
tool_actions.add_action(cursor_tool_action);
form_widgets_toolbar.add_action(cursor_tool_action);
GUI::WidgetClassRegistration::for_each([&, this](const GUI::WidgetClassRegistration& reg) {
constexpr size_t gui_namespace_prefix_length = sizeof("GUI::") - 1;
auto icon_path = String::formatted("/res/icons/hackstudio/G{}.png",
reg.class_name().substring(gui_namespace_prefix_length, reg.class_name().length() - gui_namespace_prefix_length));
if (!Core::File::exists(icon_path))
return;
auto action = GUI::Action::create_checkable(reg.class_name(), Gfx::Bitmap::load_from_file(icon_path), [®, this](auto&) {
m_form_editor_widget->set_tool(make<WidgetTool>(*m_form_editor_widget, reg));
auto widget = reg.construct();
m_form_editor_widget->form_widget().add_child(widget);
widget->set_relative_rect(30, 30, 30, 30);
m_form_editor_widget->model().update();
});
action->set_checked(false);
tool_actions.add_action(action);
form_widgets_toolbar.add_action(move(action));
});
auto& form_editor_inner_splitter = m_form_inner_container->add<GUI::HorizontalSplitter>();
m_form_editor_widget = form_editor_inner_splitter.add<FormEditorWidget>();
auto& form_editing_pane_container = form_editor_inner_splitter.add<GUI::VerticalSplitter>();
form_editing_pane_container.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
form_editing_pane_container.set_preferred_size(190, 0);
form_editing_pane_container.set_layout<GUI::VerticalBoxLayout>();
auto add_properties_pane = [&](auto& text, auto& pane_widget) {
auto& wrapper = form_editing_pane_container.add<GUI::Widget>();
wrapper.set_layout<GUI::VerticalBoxLayout>();
auto& label = wrapper.add<GUI::Label>(text);
label.set_fill_with_background_color(true);
label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
label.set_font(Gfx::Font::default_bold_font());
label.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
label.set_preferred_size(0, 16);
wrapper.add_child(pane_widget);
};
m_form_widget_tree_view = GUI::TreeView::construct();
m_form_widget_tree_view->set_model(m_form_editor_widget->model());
m_form_widget_tree_view->on_selection_change = [this] {
m_form_editor_widget->selection().disable_hooks();
m_form_editor_widget->selection().clear();
m_form_widget_tree_view->selection().for_each_index([this](auto& index) {
// NOTE: Make sure we don't add the FormWidget itself to the selection,
// since that would allow you to drag-move the FormWidget.
if (index.internal_data() != &m_form_editor_widget->form_widget())
m_form_editor_widget->selection().add(*(GUI::Widget*)index.internal_data());
});
m_form_editor_widget->update();
m_form_editor_widget->selection().enable_hooks();
};
m_form_editor_widget->selection().on_add = [this](auto& widget) {
m_form_widget_tree_view->selection().add(m_form_editor_widget->model().index_for_widget(widget));
};
m_form_editor_widget->selection().on_remove = [this](auto& widget) {
m_form_widget_tree_view->selection().remove(m_form_editor_widget->model().index_for_widget(widget));
};
m_form_editor_widget->selection().on_clear = [this] {
m_form_widget_tree_view->selection().clear();
};
add_properties_pane("Form widget tree:", *m_form_widget_tree_view);
add_properties_pane("Widget properties:", *GUI::TableView::construct());
}
void HackStudioWidget::create_toolbar(GUI::Widget& parent)
{
auto& toolbar = parent.add<GUI::ToolBar>();
toolbar.add_action(*m_new_action);
toolbar.add_action(*m_add_existing_file_action);
toolbar.add_action(*m_save_action);
toolbar.add_action(*m_delete_action);
toolbar.add_separator();
toolbar.add_action(GUI::CommonActions::make_cut_action([this](auto&) { current_editor().cut_action().activate(); }));
toolbar.add_action(GUI::CommonActions::make_copy_action([this](auto&) { current_editor().copy_action().activate(); }));
toolbar.add_action(GUI::CommonActions::make_paste_action([this](auto&) { current_editor().paste_action().activate(); }));
toolbar.add_separator();
toolbar.add_action(GUI::CommonActions::make_undo_action([this](auto&) { current_editor().undo_action().activate(); }));
toolbar.add_action(GUI::CommonActions::make_redo_action([this](auto&) { current_editor().redo_action().activate(); }));
toolbar.add_separator();
toolbar.add_action(*m_build_action);
toolbar.add_separator();
toolbar.add_action(*m_run_action);
toolbar.add_action(*m_stop_action);
toolbar.add_separator();
toolbar.add_action(*m_debug_action);
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_build_action()
{
return GUI::Action::create("Build", { Mod_Ctrl, Key_B }, Gfx::Bitmap::load_from_file("/res/icons/16x16/build.png"), [this](auto&) {
reveal_action_tab(*m_terminal_wrapper);
build(*m_terminal_wrapper);
m_stop_action->set_enabled(true);
});
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_run_action()
{
return GUI::Action::create("Run", { Mod_Ctrl, Key_R }, Gfx::Bitmap::load_from_file("/res/icons/16x16/program-run.png"), [this](auto&) {
reveal_action_tab(*m_terminal_wrapper);
run(*m_terminal_wrapper);
m_stop_action->set_enabled(true);
});
}
void HackStudioWidget::create_action_tab(GUI::Widget& parent)
{
m_action_tab_widget = parent.add<GUI::TabWidget>();
m_action_tab_widget->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
m_action_tab_widget->set_preferred_size(0, 24);
m_action_tab_widget->on_change = [this](auto&) {
on_action_tab_change();
static bool first_time = true;
if (!first_time)
m_action_tab_widget->set_preferred_size(0, 200);
first_time = false;
};
m_find_in_files_widget = m_action_tab_widget->add_tab<FindInFilesWidget>("Find in files");
m_terminal_wrapper = m_action_tab_widget->add_tab<TerminalWrapper>("Build", false);
m_debug_info_widget = m_action_tab_widget->add_tab<DebugInfoWidget>("Debug");
m_disassembly_widget = m_action_tab_widget->add_tab<DisassemblyWidget>("Disassembly");
m_git_widget = m_action_tab_widget->add_tab<GitWidget>("Git", LexicalPath(m_project->root_directory()));
m_git_widget->set_view_diff_callback([this](const auto& original_content, const auto& diff) {
m_diff_viewer->set_content(original_content, diff);
set_edit_mode(EditMode::Diff);
});
}
void HackStudioWidget::create_app_menubar(GUI::MenuBar& menubar)
{
auto& app_menu = menubar.add_menu("HackStudio");
app_menu.add_action(*m_open_action);
app_menu.add_action(*m_save_action);
app_menu.add_separator();
app_menu.add_action(GUI::CommonActions::make_quit_action([this](auto&) {
GUI::Application::the()->quit();
}));
}
void HackStudioWidget::create_project_menubar(GUI::MenuBar& menubar)
{
auto& project_menu = menubar.add_menu("Project");
project_menu.add_action(*m_new_action);
project_menu.add_action(*m_add_existing_file_action);
}
void HackStudioWidget::create_edit_menubar(GUI::MenuBar& menubar)
{
auto& edit_menu = menubar.add_menu("Edit");
edit_menu.add_action(GUI::Action::create("Find in files...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find.png"), [this](auto&) {
reveal_action_tab(*m_find_in_files_widget);
m_find_in_files_widget->focus_textbox_and_select_all();
}));
}
void HackStudioWidget::create_build_menubar(GUI::MenuBar& menubar)
{
auto& build_menu = menubar.add_menu("Build");
build_menu.add_action(*m_build_action);
build_menu.add_separator();
build_menu.add_action(*m_run_action);
build_menu.add_action(*m_stop_action);
build_menu.add_separator();
build_menu.add_action(*m_debug_action);
}
void HackStudioWidget::create_view_menubar(GUI::MenuBar& menubar)
{
auto hide_action_tabs_action = GUI::Action::create("Hide action tabs", { Mod_Ctrl | Mod_Shift, Key_X }, [this](auto&) {
hide_action_tabs();
});
auto open_locator_action = GUI::Action::create("Open Locator...", { Mod_Ctrl, Key_K }, [this](auto&) {
m_locator->open();
});
auto& view_menu = menubar.add_menu("View");
view_menu.add_action(hide_action_tabs_action);
view_menu.add_action(open_locator_action);
view_menu.add_separator();
view_menu.add_action(*m_add_editor_action);
view_menu.add_action(*m_remove_current_editor_action);
view_menu.add_action(*m_add_terminal_action);
view_menu.add_action(*m_remove_current_terminal_action);
}
void HackStudioWidget::create_help_menubar(GUI::MenuBar& menubar)
{
auto& help_menu = menubar.add_menu("Help");
help_menu.add_action(GUI::Action::create("About", [this](auto&) {
GUI::AboutDialog::show("HackStudio", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-hack-studio.png"), window());
}));
}
NonnullRefPtr<GUI::Action> HackStudioWidget::create_stop_action()
{
auto action = GUI::Action::create("Stop", Gfx::Bitmap::load_from_file("/res/icons/16x16/program-stop.png"), [this](auto&) {
m_terminal_wrapper->kill_running_command();
});
action->set_enabled(false);
return action;
}
void HackStudioWidget::initialize_menubar(GUI::MenuBar& menubar)
{
create_app_menubar(menubar);
create_project_menubar(menubar);
create_edit_menubar(menubar);
create_build_menubar(menubar);
create_view_menubar(menubar);
create_help_menubar(menubar);
}
HackStudioWidget::~HackStudioWidget()
{
if (!m_debugger_thread.is_null()) {
Debugger::the().set_requested_debugger_action(Debugger::DebuggerAction::Exit);
void* retval;
dbgln("Waiting for debugger thread to terminate");
int rc = pthread_join(m_debugger_thread->tid(), &retval);
if (rc < 0) {
perror("pthread_join");
dbgln("error joining debugger thread");
}
}
}
}
|
IF !DEF(SECOND)
ATTRS equs ",ALIGN[2]"
ELSE
ATTRS equs "[$CAFE]"
ENDC
SECTION UNION "conflicting alignment", WRAM0 ATTRS
db
PURGE ATTRS
|
Name: ys_w69.asm
Type: file
Size: 17489
Last-Modified: '2016-05-13T04:50:34Z'
SHA-1: 16E5E2ECA190013521C778B09D55B4A03275A3AE
Description: null
|
// A raster IRQ that opens the top/bottom border.
/// @file
/// Commodore 64 Registers and Constants
/// @file
/// The MOS 6526 Complex Interface Adapter (CIA)
///
/// http://archive.6502.org/datasheets/mos_6526_cia_recreated.pdf
// Commodore 64 PRG executable file
.file [name="irq-hyperscreen.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)
/// Value that disables all CIA interrupts when stored to the CIA Interrupt registers
.const CIA_INTERRUPT_CLEAR = $7f
/// $D011 Control Register #1 Bit#3: RSEL Switch betweem 25 or 24 visible rows
/// RSEL| Display window height | First line | Last line
/// ----+--------------------------+-------------+----------
/// 0 | 24 text lines/192 pixels | 55 ($37) | 246 ($f6)
/// 1 | 25 text lines/200 pixels | 51 ($33) | 250 ($fa)
.const VICII_RSEL = 8
/// VICII IRQ Status/Enable Raster
// @see #IRQ_ENABLE #IRQ_STATUS
/// 0 | RST| Reaching a certain raster line. The line is specified by writing
/// | | to register 0xd012 and bit 7 of $d011 and internally stored by
/// | | the VIC for the raster compare. The test for reaching the
/// | | interrupt raster line is done in cycle 0 of every line (for line
/// | | 0, in cycle 1).
.const IRQ_RASTER = 1
/// Mask for PROCESSOR_PORT_DDR which allows only memory configuration to be written
.const PROCPORT_DDR_MEMORY_MASK = 7
/// RAM in 0xA000, 0xE000 I/O in 0xD000
.const PROCPORT_RAM_IO = 5
.const WHITE = 1
.const RED = 2
.const OFFSET_STRUCT_MOS6526_CIA_INTERRUPT = $d
.const OFFSET_STRUCT_MOS6569_VICII_CONTROL1 = $11
.const OFFSET_STRUCT_MOS6569_VICII_RASTER = $12
.const OFFSET_STRUCT_MOS6569_VICII_IRQ_ENABLE = $1a
.const OFFSET_STRUCT_MOS6569_VICII_BORDER_COLOR = $20
.const OFFSET_STRUCT_MOS6569_VICII_IRQ_STATUS = $19
/// Processor port data direction register
.label PROCPORT_DDR = 0
/// Processor Port Register controlling RAM/ROM configuration and the datasette
.label PROCPORT = 1
/// The VIC-II MOS 6567/6569
.label VICII = $d000
/// The CIA#1: keyboard matrix, joystick #1/#2
.label CIA1 = $dc00
/// The vector used when the HARDWARE serves IRQ interrupts
.label HARDWARE_IRQ = $fffe
.label GHOST_BYTE = $3fff
.segment Code
// Interrupt Routine 2
irq_bottom_2: {
sta rega+1
// VICII->BORDER_COLOR = WHITE
lda #WHITE
sta VICII+OFFSET_STRUCT_MOS6569_VICII_BORDER_COLOR
// VICII->CONTROL1 |= VICII_RSEL
// Set screen height back to 25 lines (preparing for the next screen)
lda #VICII_RSEL
ora VICII+OFFSET_STRUCT_MOS6569_VICII_CONTROL1
sta VICII+OFFSET_STRUCT_MOS6569_VICII_CONTROL1
// VICII->IRQ_STATUS = IRQ_RASTER
// Acknowledge the IRQ
lda #IRQ_RASTER
sta VICII+OFFSET_STRUCT_MOS6569_VICII_IRQ_STATUS
// VICII->RASTER = 0xfa
// Trigger IRQ 1 at line 0xfa
lda #$fa
sta VICII+OFFSET_STRUCT_MOS6569_VICII_RASTER
// *HARDWARE_IRQ = &irq_bottom_1
lda #<irq_bottom_1
sta HARDWARE_IRQ
lda #>irq_bottom_1
sta HARDWARE_IRQ+1
// VICII->BORDER_COLOR = RED
lda #RED
sta VICII+OFFSET_STRUCT_MOS6569_VICII_BORDER_COLOR
// }
rega:
lda #0
rti
}
// Interrupt Routine 1
irq_bottom_1: {
sta rega+1
// VICII->BORDER_COLOR = WHITE
lda #WHITE
sta VICII+OFFSET_STRUCT_MOS6569_VICII_BORDER_COLOR
// VICII->CONTROL1 &= (0xff^VICII_RSEL)
// Set screen height to 24 lines - this is done after the border should have started drawing - so it wont start
lda #$ff^VICII_RSEL
and VICII+OFFSET_STRUCT_MOS6569_VICII_CONTROL1
sta VICII+OFFSET_STRUCT_MOS6569_VICII_CONTROL1
// VICII->IRQ_STATUS = IRQ_RASTER
// Acknowledge the IRQ
lda #IRQ_RASTER
sta VICII+OFFSET_STRUCT_MOS6569_VICII_IRQ_STATUS
// VICII->RASTER = 0xfd
// Trigger IRQ 2 at line 0xfd
lda #$fd
sta VICII+OFFSET_STRUCT_MOS6569_VICII_RASTER
// *HARDWARE_IRQ = &irq_bottom_2
lda #<irq_bottom_2
sta HARDWARE_IRQ
lda #>irq_bottom_2
sta HARDWARE_IRQ+1
// VICII->BORDER_COLOR = RED
lda #RED
sta VICII+OFFSET_STRUCT_MOS6569_VICII_BORDER_COLOR
// }
rega:
lda #0
rti
}
main: {
// *GHOST_BYTE = 0
lda #0
sta GHOST_BYTE
// asm
sei
// CIA1->INTERRUPT = CIA_INTERRUPT_CLEAR
// Disable CIA 1 Timer IRQ
lda #CIA_INTERRUPT_CLEAR
sta CIA1+OFFSET_STRUCT_MOS6526_CIA_INTERRUPT
// VICII->CONTROL1 &= 0x7f
// Set raster line to 0xfa
lda #$7f
and VICII+OFFSET_STRUCT_MOS6569_VICII_CONTROL1
sta VICII+OFFSET_STRUCT_MOS6569_VICII_CONTROL1
// VICII->RASTER = 0xfa
lda #$fa
sta VICII+OFFSET_STRUCT_MOS6569_VICII_RASTER
// VICII->IRQ_ENABLE = IRQ_RASTER
// Enable Raster Interrupt
lda #IRQ_RASTER
sta VICII+OFFSET_STRUCT_MOS6569_VICII_IRQ_ENABLE
// *HARDWARE_IRQ = &irq_bottom_1
// Set the IRQ routine
lda #<irq_bottom_1
sta HARDWARE_IRQ
lda #>irq_bottom_1
sta HARDWARE_IRQ+1
// *PROCPORT_DDR = PROCPORT_DDR_MEMORY_MASK
// no kernal or BASIC rom visible
lda #PROCPORT_DDR_MEMORY_MASK
sta.z PROCPORT_DDR
// *PROCPORT = PROCPORT_RAM_IO
lda #PROCPORT_RAM_IO
sta.z PROCPORT
// asm
cli
__b1:
jmp __b1
}
|
; CALLER linkage for function pointers
PUBLIC stricmp
EXTERN stricmp1
.stricmp
pop bc
pop de
pop hl
push hl
push de
push bc
jp stricmp1
|
/*
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "core/css/FontFaceSetLoadEvent.h"
namespace blink {
FontFaceSetLoadEvent::FontFaceSetLoadEvent()
{
}
FontFaceSetLoadEvent::FontFaceSetLoadEvent(const AtomicString& type, const FontFaceArray& fontfaces)
: Event(type, false, false)
, m_fontfaces(fontfaces)
{
}
FontFaceSetLoadEvent::FontFaceSetLoadEvent(const AtomicString& type, const FontFaceSetLoadEventInit& initializer)
: Event(type, initializer)
, m_fontfaces(initializer.fontfaces())
{
}
FontFaceSetLoadEvent::~FontFaceSetLoadEvent()
{
}
const AtomicString& FontFaceSetLoadEvent::interfaceName() const
{
return EventNames::FontFaceSetLoadEvent;
}
DEFINE_TRACE(FontFaceSetLoadEvent)
{
visitor->trace(m_fontfaces);
Event::trace(visitor);
}
} // namespace blink
|
/*==========================================================================
* Copyright (c) 2005 University of Massachusetts. All Rights Reserved.
*
* Use of the Lemur Toolkit for Language Modeling and Information Retrieval
* is subject to the terms of the software license set forth in the LICENSE
* file included with this software, and also available at
* http://www.lemurproject.org/license.html
*
*==========================================================================
*/
// dmf
// C++ thread safe implementation of the Krovetz stemmer.
// requires no external data files.
// 07/29/2005
#ifndef _KROVETZ_STEMMER_H_
#define _KROVETZ_STEMMER_H_
#include <iostream>
#include <cstring>
#ifdef WIN32
#include <hash_map>
#else
#include <unordered_map>
#endif
// 3.3 does not use __gnu_cxx, 3.4+ does.
//using namespace __gnu_cxx;
namespace stem {
class KrovetzStemmer {
public:
KrovetzStemmer();
~KrovetzStemmer();
/// maximum number of characters in a word to be stemmed.
static const int MAX_WORD_LENGTH=25;
/*!
\brief stem a term using the Krovetz algorithm.
The stem returned may be longer than the input term.
May return a pointer
to the private attribute stem. Performs case normalization on its
input argument. Return values should be copied before
calling the method again.
@param term the term to stem
@return the stemmed term or the original term if no stemming was
performed.
*/
char * kstem_stemmer(char *term);
/*!
\brief stem a term using the Krovetz algorithm into the specified
buffer.
The stem returned may be longer than the input term.
Performs case normalization on its input argument.
@param term the term to stem
@param buffer the buffer to hold the stemmed term. The buffer should
be at MAX_WORD_LENGTH or larger.
@return the number of characters written to the buffer, including
the terminating '\\0'. If 0, the caller should use the value in term.
*/
int kstem_stem_tobuffer(char *term, char *buffer);
/*!
\brief Add an entry to the stemmer's dictionary table.
@param variant the spelling for the entry.
@param word the stem to use for the variant. If "", the variant
stems to itself.
@param exc Is the word an exception to the spelling rules.
*/
void kstem_add_table_entry(const char* variant, const char* word,
bool exc=false);
private:
/// Dictionary table entry
typedef struct dictEntry {
/// is the word an exception to stemming rules?
bool exception;
/// stem to use for this entry.
const char *root;
} dictEntry;
/// Two term hashtable entry for caching across calls
typedef struct cacheEntry {
/// flag for first or second entry most recently used.
char flag;
/// first entry variant
char word1[MAX_WORD_LENGTH];
/// first entry stem
char stem1[MAX_WORD_LENGTH];
/// second entry variant
char word2[MAX_WORD_LENGTH];
/// second entry stem
char stem2[MAX_WORD_LENGTH];
} cacheEntry;
// operates on atribute word.
bool ends(const char *s, int sufflen);
void setsuff(const char *str, int length);
dictEntry *getdep(char *word);
bool lookup(char *word);
bool cons(int i);
bool vowelinstem();
bool vowel(int i);
bool doublec(int i);
void plural();
void past_tense();
void aspect();
void ion_endings();
void er_and_or_endings ();
void ly_endings ();
void al_endings() ;
void ive_endings() ;
void ize_endings() ;
void ment_endings() ;
void ity_endings() ;
void ble_endings() ;
void ness_endings() ;
void ism_endings();
void ic_endings();
void ncy_endings();
void nce_endings();
// maint.
void loadTables();
#ifdef WIN32
struct ltstr {
bool operator()(const char* s1, const char* s2) const {
return strcmp(s1, s2) < 0;
}
};
//studio 7 hash_map provides hash_compare, rather than hash
// needing an < predicate, rather than an == predicate.
typedef stdext::hash_map<const char *, dictEntry, stdext::hash_compare<const char *, ltstr> > dictTable;
#else
struct eqstr {
bool operator()(const char* s1, const char* s2) const {
return strcmp(s1, s2) == 0;
}
};
typedef std::unordered_map<const char *, dictEntry, std::hash<std::string>, eqstr> dictTable;
#endif
dictTable dictEntries;
// this needs to be a bounded size cache.
// kstem.cpp uses size 30013 entries.
cacheEntry *stemCache;
// size
int stemhtsize;
// state
// k = wordlength - 1
int k;
// j is stemlength - 1
int j;
// pointer to the output buffer
char *word;
// used by kstem_stemmer to return a safe value.
char stem[MAX_WORD_LENGTH];
};
}
#endif /* _KROVETZ_STEMMER_H_*/
|
#include "AnimationStateConnection.h"
#include "AnimationStateCondition.h"
#include "AnimationStateBase.h"
#include <algorithm>
AnimationStateConnection::AnimationStateConnection()
:_conditions(), _targetState(nullptr),_blendTime(0.f)
{
}
void AnimationStateConnection::createAnimationStateConnection(AnimationStateBase* state, float blendTime)
{
_targetState = state;
_blendTime = blendTime;
}
void AnimationStateConnection::destroyAnimationStateConnection()
{
for (auto iter = _conditions.begin(); iter != _conditions.end(); ++iter)
{
(*iter)->destroyAnimationStateCondition();
delete (*iter);
}
}
void AnimationStateConnection::addCondition(AnimationStateVariable* variable, StateConditions type)
{
auto condition = new AnimationStateCondition;
condition->createAnimationStateCondition(variable, type);
addCondition(condition);
}
void AnimationStateConnection::addCondition(AnimationStateCondition* condition)
{
_conditions.push_back(condition);
}
void AnimationStateConnection::deleteCondition(size_t index)
{
_conditions.erase(_conditions.begin() + index);
}
const std::vector<AnimationStateCondition*>& AnimationStateConnection::getConditions()
{
return _conditions;
}
AnimationStateBase* AnimationStateConnection::getTargetState()
{
return _targetState;
}
float AnimationStateConnection::getBlendTime()
{
return _blendTime;
}
bool AnimationStateConnection::isEmpty()
{
return _conditions.size() == 0;
}
bool AnimationStateConnection::isMeet()
{
for (auto iter = _conditions.begin(); iter != _conditions.end(); ++iter)
{
if ((*iter)->isMeet() == false)
return false;
}
return true;
}
|
MOV AL,09H ; Load immediate data 09H to register AL
MOV BL,06H ; Load immediate data to register BL
SUB AL, BL ; AL=AL-BL |
; A133585: Expansion of x - x^2*(2*x+1)*(x^2-2) / ( (x^2-x-1)*(x^2+x-1) ).
; Submitted by Jamie Morken(s4)
; 1,2,4,5,10,13,26,34,68,89,178,233,466,610,1220,1597,3194,4181,8362,10946,21892,28657,57314,75025,150050,196418,392836,514229,1028458,1346269,2692538,3524578,7049156,9227465,18454930,24157817
sub $1,$0
mov $2,1
mov $5,-2
lpb $0
mov $3,$2
lpb $3
add $2,1
mov $4,$1
gcd $4,$2
add $2,$5
add $3,$2
cmp $4,1
cmp $4,0
sub $3,$4
lpe
sub $0,1
mov $2,$4
add $2,1
add $4,$3
lpe
mov $0,$4
add $0,1
|
SECTION code_clib
SECTION code_fp_math48
PUBLIC mlib2d
EXTERN cm48_sccz80_m482d
defc mlib2d = cm48_sccz80_m482d
|
object_const_def ; object_event constants
OreburghApartmentE1F_MapScripts:
db 0 ; scene scripts
db 0 ; callbacks
OreburghApartmentE1F_FirstMonGuyScript:
jumptextfaceplayer .Text
.Text:
text "You remind me so"
line "much of the time"
cont "I got my first"
cont "#MON."
done
OreburghApartmentE1F_WhichMovesGuyScript:
jumptextfaceplayer .Text
.Text:
text "I always have a"
line "rotten time trying"
cont "to decide which"
cont "moves my #MON"
cont "should learn."
done
OreburghApartmentE1F_TrainingGuyScript:
jumptextfaceplayer .Text
.Text:
text "Hiya! Your #MON"
line "could use some"
cont "toughening up."
para "Why not try"
line "training in the"
cont "OREBURGH MINE?"
done
OreburghApartmentE1F_MapEvents:
db 0, 0 ; filler
db 3 ; warp events
warp_event 6, 7, OREBURGH_CITY, 10
warp_event 7, 7, OREBURGH_CITY, 10
warp_event 8, 1, OREBURGH_APARTMENT_E_2F, 1
db 0 ; coord events
db 0 ; bg events
db 3 ; object events
object_event 4, 5, SPRITE_COOLTRAINER_M, SPRITEMOVEDATA_WANDER, 1, 1, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, OreburghApartmentE1F_FirstMonGuyScript, -1
object_event 7, 3, SPRITE_FISHER, SPRITEMOVEDATA_WANDER, 1, 1, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, OreburghApartmentE1F_WhichMovesGuyScript, -1
object_event 9, 5, SPRITE_POKEFAN_M, SPRITEMOVEDATA_WANDER, 1, 1, -1, -1, 0, OBJECTTYPE_SCRIPT, 0, OreburghApartmentE1F_TrainingGuyScript, -1
|
_ls: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
close(fd);
}
int
main(int argc, char *argv[])
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 57 push %edi
4: 56 push %esi
5: 53 push %ebx
int i;
if(argc < 2){
6: bb 01 00 00 00 mov $0x1,%ebx
{
b: 83 e4 f0 and $0xfffffff0,%esp
e: 83 ec 10 sub $0x10,%esp
11: 8b 75 08 mov 0x8(%ebp),%esi
14: 8b 7d 0c mov 0xc(%ebp),%edi
if(argc < 2){
17: 83 fe 01 cmp $0x1,%esi
1a: 7e 1b jle 37 <main+0x37>
1c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
ls(".");
exit();
}
for(i=1; i<argc; i++)
ls(argv[i]);
20: 8b 04 9f mov (%edi,%ebx,4),%eax
for(i=1; i<argc; i++)
23: 83 c3 01 add $0x1,%ebx
ls(argv[i]);
26: 89 04 24 mov %eax,(%esp)
29: e8 c2 00 00 00 call f0 <ls>
for(i=1; i<argc; i++)
2e: 39 f3 cmp %esi,%ebx
30: 75 ee jne 20 <main+0x20>
exit();
32: e8 6b 05 00 00 call 5a2 <exit>
ls(".");
37: c7 04 24 9e 0a 00 00 movl $0xa9e,(%esp)
3e: e8 ad 00 00 00 call f0 <ls>
exit();
43: e8 5a 05 00 00 call 5a2 <exit>
48: 66 90 xchg %ax,%ax
4a: 66 90 xchg %ax,%ax
4c: 66 90 xchg %ax,%ax
4e: 66 90 xchg %ax,%ax
00000050 <fmtname>:
{
50: 55 push %ebp
51: 89 e5 mov %esp,%ebp
53: 56 push %esi
54: 53 push %ebx
55: 83 ec 10 sub $0x10,%esp
58: 8b 5d 08 mov 0x8(%ebp),%ebx
for(p=path+strlen(path); p >= path && *p != '/'; p--)
5b: 89 1c 24 mov %ebx,(%esp)
5e: e8 9d 03 00 00 call 400 <strlen>
63: 01 d8 add %ebx,%eax
65: 73 10 jae 77 <fmtname+0x27>
67: eb 13 jmp 7c <fmtname+0x2c>
69: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
70: 83 e8 01 sub $0x1,%eax
73: 39 c3 cmp %eax,%ebx
75: 77 05 ja 7c <fmtname+0x2c>
77: 80 38 2f cmpb $0x2f,(%eax)
7a: 75 f4 jne 70 <fmtname+0x20>
p++;
7c: 8d 58 01 lea 0x1(%eax),%ebx
if(strlen(p) >= DIRSIZ)
7f: 89 1c 24 mov %ebx,(%esp)
82: e8 79 03 00 00 call 400 <strlen>
87: 83 f8 0d cmp $0xd,%eax
8a: 77 53 ja df <fmtname+0x8f>
memmove(buf, p, strlen(p));
8c: 89 1c 24 mov %ebx,(%esp)
8f: e8 6c 03 00 00 call 400 <strlen>
94: 89 5c 24 04 mov %ebx,0x4(%esp)
98: c7 04 24 88 0d 00 00 movl $0xd88,(%esp)
9f: 89 44 24 08 mov %eax,0x8(%esp)
a3: e8 c8 04 00 00 call 570 <memmove>
memset(buf+strlen(p), ' ', DIRSIZ-strlen(p));
a8: 89 1c 24 mov %ebx,(%esp)
ab: e8 50 03 00 00 call 400 <strlen>
b0: 89 1c 24 mov %ebx,(%esp)
return buf;
b3: bb 88 0d 00 00 mov $0xd88,%ebx
memset(buf+strlen(p), ' ', DIRSIZ-strlen(p));
b8: 89 c6 mov %eax,%esi
ba: e8 41 03 00 00 call 400 <strlen>
bf: ba 0e 00 00 00 mov $0xe,%edx
c4: 29 f2 sub %esi,%edx
c6: 89 54 24 08 mov %edx,0x8(%esp)
ca: c7 44 24 04 20 00 00 movl $0x20,0x4(%esp)
d1: 00
d2: 05 88 0d 00 00 add $0xd88,%eax
d7: 89 04 24 mov %eax,(%esp)
da: e8 51 03 00 00 call 430 <memset>
}
df: 83 c4 10 add $0x10,%esp
e2: 89 d8 mov %ebx,%eax
e4: 5b pop %ebx
e5: 5e pop %esi
e6: 5d pop %ebp
e7: c3 ret
e8: 90 nop
e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000000f0 <ls>:
{
f0: 55 push %ebp
f1: 89 e5 mov %esp,%ebp
f3: 57 push %edi
f4: 56 push %esi
f5: 53 push %ebx
f6: 81 ec 6c 02 00 00 sub $0x26c,%esp
fc: 8b 7d 08 mov 0x8(%ebp),%edi
if((fd = open(path, 0)) < 0){
ff: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
106: 00
107: 89 3c 24 mov %edi,(%esp)
10a: e8 d3 04 00 00 call 5e2 <open>
10f: 85 c0 test %eax,%eax
111: 89 c3 mov %eax,%ebx
113: 0f 88 c7 01 00 00 js 2e0 <ls+0x1f0>
if(fstat(fd, &st) < 0){
119: 8d b5 d4 fd ff ff lea -0x22c(%ebp),%esi
11f: 89 74 24 04 mov %esi,0x4(%esp)
123: 89 04 24 mov %eax,(%esp)
126: e8 cf 04 00 00 call 5fa <fstat>
12b: 85 c0 test %eax,%eax
12d: 0f 88 f5 01 00 00 js 328 <ls+0x238>
switch(st.type){
133: 0f b7 85 d4 fd ff ff movzwl -0x22c(%ebp),%eax
13a: 66 83 f8 01 cmp $0x1,%ax
13e: 74 68 je 1a8 <ls+0xb8>
140: 66 83 f8 02 cmp $0x2,%ax
144: 75 48 jne 18e <ls+0x9e>
printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size);
146: 8b 95 e4 fd ff ff mov -0x21c(%ebp),%edx
14c: 89 3c 24 mov %edi,(%esp)
14f: 8b b5 dc fd ff ff mov -0x224(%ebp),%esi
155: 89 95 b4 fd ff ff mov %edx,-0x24c(%ebp)
15b: e8 f0 fe ff ff call 50 <fmtname>
160: 8b 95 b4 fd ff ff mov -0x24c(%ebp),%edx
166: 89 74 24 10 mov %esi,0x10(%esp)
16a: c7 44 24 0c 02 00 00 movl $0x2,0xc(%esp)
171: 00
172: c7 44 24 04 7e 0a 00 movl $0xa7e,0x4(%esp)
179: 00
17a: 89 54 24 14 mov %edx,0x14(%esp)
17e: c7 04 24 01 00 00 00 movl $0x1,(%esp)
185: 89 44 24 08 mov %eax,0x8(%esp)
189: e8 62 05 00 00 call 6f0 <printf>
close(fd);
18e: 89 1c 24 mov %ebx,(%esp)
191: e8 34 04 00 00 call 5ca <close>
}
196: 81 c4 6c 02 00 00 add $0x26c,%esp
19c: 5b pop %ebx
19d: 5e pop %esi
19e: 5f pop %edi
19f: 5d pop %ebp
1a0: c3 ret
1a1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){
1a8: 89 3c 24 mov %edi,(%esp)
1ab: e8 50 02 00 00 call 400 <strlen>
1b0: 83 c0 10 add $0x10,%eax
1b3: 3d 00 02 00 00 cmp $0x200,%eax
1b8: 0f 87 4a 01 00 00 ja 308 <ls+0x218>
strcpy(buf, path);
1be: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax
1c4: 89 7c 24 04 mov %edi,0x4(%esp)
1c8: 8d bd c4 fd ff ff lea -0x23c(%ebp),%edi
1ce: 89 04 24 mov %eax,(%esp)
1d1: e8 aa 01 00 00 call 380 <strcpy>
p = buf+strlen(buf);
1d6: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax
1dc: 89 04 24 mov %eax,(%esp)
1df: e8 1c 02 00 00 call 400 <strlen>
1e4: 8d 8d e8 fd ff ff lea -0x218(%ebp),%ecx
1ea: 01 c8 add %ecx,%eax
*p++ = '/';
1ec: 8d 48 01 lea 0x1(%eax),%ecx
p = buf+strlen(buf);
1ef: 89 85 a8 fd ff ff mov %eax,-0x258(%ebp)
*p++ = '/';
1f5: 89 8d a4 fd ff ff mov %ecx,-0x25c(%ebp)
1fb: c6 00 2f movb $0x2f,(%eax)
1fe: 66 90 xchg %ax,%ax
while(read(fd, &de, sizeof(de)) == sizeof(de)){
200: c7 44 24 08 10 00 00 movl $0x10,0x8(%esp)
207: 00
208: 89 7c 24 04 mov %edi,0x4(%esp)
20c: 89 1c 24 mov %ebx,(%esp)
20f: e8 a6 03 00 00 call 5ba <read>
214: 83 f8 10 cmp $0x10,%eax
217: 0f 85 71 ff ff ff jne 18e <ls+0x9e>
if(de.inum == 0)
21d: 66 83 bd c4 fd ff ff cmpw $0x0,-0x23c(%ebp)
224: 00
225: 74 d9 je 200 <ls+0x110>
memmove(p, de.name, DIRSIZ);
227: 8d 85 c6 fd ff ff lea -0x23a(%ebp),%eax
22d: 89 44 24 04 mov %eax,0x4(%esp)
231: 8b 85 a4 fd ff ff mov -0x25c(%ebp),%eax
237: c7 44 24 08 0e 00 00 movl $0xe,0x8(%esp)
23e: 00
23f: 89 04 24 mov %eax,(%esp)
242: e8 29 03 00 00 call 570 <memmove>
p[DIRSIZ] = 0;
247: 8b 85 a8 fd ff ff mov -0x258(%ebp),%eax
24d: c6 40 0f 00 movb $0x0,0xf(%eax)
if(stat(buf, &st) < 0){
251: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax
257: 89 74 24 04 mov %esi,0x4(%esp)
25b: 89 04 24 mov %eax,(%esp)
25e: e8 8d 02 00 00 call 4f0 <stat>
263: 85 c0 test %eax,%eax
265: 0f 88 e5 00 00 00 js 350 <ls+0x260>
printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
26b: 0f bf 95 d4 fd ff ff movswl -0x22c(%ebp),%edx
272: 8b 8d e4 fd ff ff mov -0x21c(%ebp),%ecx
278: 8b 85 dc fd ff ff mov -0x224(%ebp),%eax
27e: 89 95 b0 fd ff ff mov %edx,-0x250(%ebp)
284: 8d 95 e8 fd ff ff lea -0x218(%ebp),%edx
28a: 89 14 24 mov %edx,(%esp)
28d: 89 8d ac fd ff ff mov %ecx,-0x254(%ebp)
293: 89 85 b4 fd ff ff mov %eax,-0x24c(%ebp)
299: e8 b2 fd ff ff call 50 <fmtname>
29e: 8b 8d ac fd ff ff mov -0x254(%ebp),%ecx
2a4: 8b 95 b0 fd ff ff mov -0x250(%ebp),%edx
2aa: c7 44 24 04 7e 0a 00 movl $0xa7e,0x4(%esp)
2b1: 00
2b2: c7 04 24 01 00 00 00 movl $0x1,(%esp)
2b9: 89 4c 24 14 mov %ecx,0x14(%esp)
2bd: 8b 8d b4 fd ff ff mov -0x24c(%ebp),%ecx
2c3: 89 54 24 0c mov %edx,0xc(%esp)
2c7: 89 44 24 08 mov %eax,0x8(%esp)
2cb: 89 4c 24 10 mov %ecx,0x10(%esp)
2cf: e8 1c 04 00 00 call 6f0 <printf>
2d4: e9 27 ff ff ff jmp 200 <ls+0x110>
2d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
printf(2, "ls: cannot open %s\n", path);
2e0: 89 7c 24 08 mov %edi,0x8(%esp)
2e4: c7 44 24 04 56 0a 00 movl $0xa56,0x4(%esp)
2eb: 00
2ec: c7 04 24 02 00 00 00 movl $0x2,(%esp)
2f3: e8 f8 03 00 00 call 6f0 <printf>
}
2f8: 81 c4 6c 02 00 00 add $0x26c,%esp
2fe: 5b pop %ebx
2ff: 5e pop %esi
300: 5f pop %edi
301: 5d pop %ebp
302: c3 ret
303: 90 nop
304: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
printf(1, "ls: path too long\n");
308: c7 44 24 04 8b 0a 00 movl $0xa8b,0x4(%esp)
30f: 00
310: c7 04 24 01 00 00 00 movl $0x1,(%esp)
317: e8 d4 03 00 00 call 6f0 <printf>
break;
31c: e9 6d fe ff ff jmp 18e <ls+0x9e>
321: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
printf(2, "ls: cannot stat %s\n", path);
328: 89 7c 24 08 mov %edi,0x8(%esp)
32c: c7 44 24 04 6a 0a 00 movl $0xa6a,0x4(%esp)
333: 00
334: c7 04 24 02 00 00 00 movl $0x2,(%esp)
33b: e8 b0 03 00 00 call 6f0 <printf>
close(fd);
340: 89 1c 24 mov %ebx,(%esp)
343: e8 82 02 00 00 call 5ca <close>
return;
348: e9 49 fe ff ff jmp 196 <ls+0xa6>
34d: 8d 76 00 lea 0x0(%esi),%esi
printf(1, "ls: cannot stat %s\n", buf);
350: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax
356: 89 44 24 08 mov %eax,0x8(%esp)
35a: c7 44 24 04 6a 0a 00 movl $0xa6a,0x4(%esp)
361: 00
362: c7 04 24 01 00 00 00 movl $0x1,(%esp)
369: e8 82 03 00 00 call 6f0 <printf>
continue;
36e: e9 8d fe ff ff jmp 200 <ls+0x110>
373: 66 90 xchg %ax,%ax
375: 66 90 xchg %ax,%ax
377: 66 90 xchg %ax,%ax
379: 66 90 xchg %ax,%ax
37b: 66 90 xchg %ax,%ax
37d: 66 90 xchg %ax,%ax
37f: 90 nop
00000380 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
380: 55 push %ebp
381: 89 e5 mov %esp,%ebp
383: 8b 45 08 mov 0x8(%ebp),%eax
386: 8b 4d 0c mov 0xc(%ebp),%ecx
389: 53 push %ebx
char *os;
os = s;
while((*s++ = *t++) != 0)
38a: 89 c2 mov %eax,%edx
38c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
390: 83 c1 01 add $0x1,%ecx
393: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
397: 83 c2 01 add $0x1,%edx
39a: 84 db test %bl,%bl
39c: 88 5a ff mov %bl,-0x1(%edx)
39f: 75 ef jne 390 <strcpy+0x10>
;
return os;
}
3a1: 5b pop %ebx
3a2: 5d pop %ebp
3a3: c3 ret
3a4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
3aa: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
000003b0 <strcmp>:
int
strcmp(const char *p, const char *q)
{
3b0: 55 push %ebp
3b1: 89 e5 mov %esp,%ebp
3b3: 8b 55 08 mov 0x8(%ebp),%edx
3b6: 53 push %ebx
3b7: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
3ba: 0f b6 02 movzbl (%edx),%eax
3bd: 84 c0 test %al,%al
3bf: 74 2d je 3ee <strcmp+0x3e>
3c1: 0f b6 19 movzbl (%ecx),%ebx
3c4: 38 d8 cmp %bl,%al
3c6: 74 0e je 3d6 <strcmp+0x26>
3c8: eb 2b jmp 3f5 <strcmp+0x45>
3ca: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
3d0: 38 c8 cmp %cl,%al
3d2: 75 15 jne 3e9 <strcmp+0x39>
p++, q++;
3d4: 89 d9 mov %ebx,%ecx
3d6: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
3d9: 0f b6 02 movzbl (%edx),%eax
p++, q++;
3dc: 8d 59 01 lea 0x1(%ecx),%ebx
while(*p && *p == *q)
3df: 0f b6 49 01 movzbl 0x1(%ecx),%ecx
3e3: 84 c0 test %al,%al
3e5: 75 e9 jne 3d0 <strcmp+0x20>
3e7: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
3e9: 29 c8 sub %ecx,%eax
}
3eb: 5b pop %ebx
3ec: 5d pop %ebp
3ed: c3 ret
3ee: 0f b6 09 movzbl (%ecx),%ecx
while(*p && *p == *q)
3f1: 31 c0 xor %eax,%eax
3f3: eb f4 jmp 3e9 <strcmp+0x39>
3f5: 0f b6 cb movzbl %bl,%ecx
3f8: eb ef jmp 3e9 <strcmp+0x39>
3fa: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
00000400 <strlen>:
uint
strlen(const char *s)
{
400: 55 push %ebp
401: 89 e5 mov %esp,%ebp
403: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
406: 80 39 00 cmpb $0x0,(%ecx)
409: 74 12 je 41d <strlen+0x1d>
40b: 31 d2 xor %edx,%edx
40d: 8d 76 00 lea 0x0(%esi),%esi
410: 83 c2 01 add $0x1,%edx
413: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
417: 89 d0 mov %edx,%eax
419: 75 f5 jne 410 <strlen+0x10>
;
return n;
}
41b: 5d pop %ebp
41c: c3 ret
for(n = 0; s[n]; n++)
41d: 31 c0 xor %eax,%eax
}
41f: 5d pop %ebp
420: c3 ret
421: eb 0d jmp 430 <memset>
423: 90 nop
424: 90 nop
425: 90 nop
426: 90 nop
427: 90 nop
428: 90 nop
429: 90 nop
42a: 90 nop
42b: 90 nop
42c: 90 nop
42d: 90 nop
42e: 90 nop
42f: 90 nop
00000430 <memset>:
void*
memset(void *dst, int c, uint n)
{
430: 55 push %ebp
431: 89 e5 mov %esp,%ebp
433: 8b 55 08 mov 0x8(%ebp),%edx
436: 57 push %edi
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
437: 8b 4d 10 mov 0x10(%ebp),%ecx
43a: 8b 45 0c mov 0xc(%ebp),%eax
43d: 89 d7 mov %edx,%edi
43f: fc cld
440: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
442: 89 d0 mov %edx,%eax
444: 5f pop %edi
445: 5d pop %ebp
446: c3 ret
447: 89 f6 mov %esi,%esi
449: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000450 <strchr>:
char*
strchr(const char *s, char c)
{
450: 55 push %ebp
451: 89 e5 mov %esp,%ebp
453: 8b 45 08 mov 0x8(%ebp),%eax
456: 53 push %ebx
457: 8b 55 0c mov 0xc(%ebp),%edx
for(; *s; s++)
45a: 0f b6 18 movzbl (%eax),%ebx
45d: 84 db test %bl,%bl
45f: 74 1d je 47e <strchr+0x2e>
if(*s == c)
461: 38 d3 cmp %dl,%bl
463: 89 d1 mov %edx,%ecx
465: 75 0d jne 474 <strchr+0x24>
467: eb 17 jmp 480 <strchr+0x30>
469: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
470: 38 ca cmp %cl,%dl
472: 74 0c je 480 <strchr+0x30>
for(; *s; s++)
474: 83 c0 01 add $0x1,%eax
477: 0f b6 10 movzbl (%eax),%edx
47a: 84 d2 test %dl,%dl
47c: 75 f2 jne 470 <strchr+0x20>
return (char*)s;
return 0;
47e: 31 c0 xor %eax,%eax
}
480: 5b pop %ebx
481: 5d pop %ebp
482: c3 ret
483: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
489: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000490 <gets>:
char*
gets(char *buf, int max)
{
490: 55 push %ebp
491: 89 e5 mov %esp,%ebp
493: 57 push %edi
494: 56 push %esi
int i, cc;
char c;
for(i=0; i+1 < max; ){
495: 31 f6 xor %esi,%esi
{
497: 53 push %ebx
498: 83 ec 2c sub $0x2c,%esp
cc = read(0, &c, 1);
49b: 8d 7d e7 lea -0x19(%ebp),%edi
for(i=0; i+1 < max; ){
49e: eb 31 jmp 4d1 <gets+0x41>
cc = read(0, &c, 1);
4a0: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
4a7: 00
4a8: 89 7c 24 04 mov %edi,0x4(%esp)
4ac: c7 04 24 00 00 00 00 movl $0x0,(%esp)
4b3: e8 02 01 00 00 call 5ba <read>
if(cc < 1)
4b8: 85 c0 test %eax,%eax
4ba: 7e 1d jle 4d9 <gets+0x49>
break;
buf[i++] = c;
4bc: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
for(i=0; i+1 < max; ){
4c0: 89 de mov %ebx,%esi
buf[i++] = c;
4c2: 8b 55 08 mov 0x8(%ebp),%edx
if(c == '\n' || c == '\r')
4c5: 3c 0d cmp $0xd,%al
buf[i++] = c;
4c7: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
4cb: 74 0c je 4d9 <gets+0x49>
4cd: 3c 0a cmp $0xa,%al
4cf: 74 08 je 4d9 <gets+0x49>
for(i=0; i+1 < max; ){
4d1: 8d 5e 01 lea 0x1(%esi),%ebx
4d4: 3b 5d 0c cmp 0xc(%ebp),%ebx
4d7: 7c c7 jl 4a0 <gets+0x10>
break;
}
buf[i] = '\0';
4d9: 8b 45 08 mov 0x8(%ebp),%eax
4dc: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
4e0: 83 c4 2c add $0x2c,%esp
4e3: 5b pop %ebx
4e4: 5e pop %esi
4e5: 5f pop %edi
4e6: 5d pop %ebp
4e7: c3 ret
4e8: 90 nop
4e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000004f0 <stat>:
int
stat(const char *n, struct stat *st)
{
4f0: 55 push %ebp
4f1: 89 e5 mov %esp,%ebp
4f3: 56 push %esi
4f4: 53 push %ebx
4f5: 83 ec 10 sub $0x10,%esp
int fd;
int r;
fd = open(n, O_RDONLY);
4f8: 8b 45 08 mov 0x8(%ebp),%eax
4fb: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
502: 00
503: 89 04 24 mov %eax,(%esp)
506: e8 d7 00 00 00 call 5e2 <open>
if(fd < 0)
50b: 85 c0 test %eax,%eax
fd = open(n, O_RDONLY);
50d: 89 c3 mov %eax,%ebx
if(fd < 0)
50f: 78 27 js 538 <stat+0x48>
return -1;
r = fstat(fd, st);
511: 8b 45 0c mov 0xc(%ebp),%eax
514: 89 1c 24 mov %ebx,(%esp)
517: 89 44 24 04 mov %eax,0x4(%esp)
51b: e8 da 00 00 00 call 5fa <fstat>
close(fd);
520: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
523: 89 c6 mov %eax,%esi
close(fd);
525: e8 a0 00 00 00 call 5ca <close>
return r;
52a: 89 f0 mov %esi,%eax
}
52c: 83 c4 10 add $0x10,%esp
52f: 5b pop %ebx
530: 5e pop %esi
531: 5d pop %ebp
532: c3 ret
533: 90 nop
534: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
return -1;
538: b8 ff ff ff ff mov $0xffffffff,%eax
53d: eb ed jmp 52c <stat+0x3c>
53f: 90 nop
00000540 <atoi>:
int
atoi(const char *s)
{
540: 55 push %ebp
541: 89 e5 mov %esp,%ebp
543: 8b 4d 08 mov 0x8(%ebp),%ecx
546: 53 push %ebx
int n;
n = 0;
while('0' <= *s && *s <= '9')
547: 0f be 11 movsbl (%ecx),%edx
54a: 8d 42 d0 lea -0x30(%edx),%eax
54d: 3c 09 cmp $0x9,%al
n = 0;
54f: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
554: 77 17 ja 56d <atoi+0x2d>
556: 66 90 xchg %ax,%ax
n = n*10 + *s++ - '0';
558: 83 c1 01 add $0x1,%ecx
55b: 8d 04 80 lea (%eax,%eax,4),%eax
55e: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
while('0' <= *s && *s <= '9')
562: 0f be 11 movsbl (%ecx),%edx
565: 8d 5a d0 lea -0x30(%edx),%ebx
568: 80 fb 09 cmp $0x9,%bl
56b: 76 eb jbe 558 <atoi+0x18>
return n;
}
56d: 5b pop %ebx
56e: 5d pop %ebp
56f: c3 ret
00000570 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
570: 55 push %ebp
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
571: 31 d2 xor %edx,%edx
{
573: 89 e5 mov %esp,%ebp
575: 56 push %esi
576: 8b 45 08 mov 0x8(%ebp),%eax
579: 53 push %ebx
57a: 8b 5d 10 mov 0x10(%ebp),%ebx
57d: 8b 75 0c mov 0xc(%ebp),%esi
while(n-- > 0)
580: 85 db test %ebx,%ebx
582: 7e 12 jle 596 <memmove+0x26>
584: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
588: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
58c: 88 0c 10 mov %cl,(%eax,%edx,1)
58f: 83 c2 01 add $0x1,%edx
while(n-- > 0)
592: 39 da cmp %ebx,%edx
594: 75 f2 jne 588 <memmove+0x18>
return vdst;
}
596: 5b pop %ebx
597: 5e pop %esi
598: 5d pop %ebp
599: c3 ret
0000059a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
59a: b8 01 00 00 00 mov $0x1,%eax
59f: cd 40 int $0x40
5a1: c3 ret
000005a2 <exit>:
SYSCALL(exit)
5a2: b8 02 00 00 00 mov $0x2,%eax
5a7: cd 40 int $0x40
5a9: c3 ret
000005aa <wait>:
SYSCALL(wait)
5aa: b8 03 00 00 00 mov $0x3,%eax
5af: cd 40 int $0x40
5b1: c3 ret
000005b2 <pipe>:
SYSCALL(pipe)
5b2: b8 04 00 00 00 mov $0x4,%eax
5b7: cd 40 int $0x40
5b9: c3 ret
000005ba <read>:
SYSCALL(read)
5ba: b8 05 00 00 00 mov $0x5,%eax
5bf: cd 40 int $0x40
5c1: c3 ret
000005c2 <write>:
SYSCALL(write)
5c2: b8 10 00 00 00 mov $0x10,%eax
5c7: cd 40 int $0x40
5c9: c3 ret
000005ca <close>:
SYSCALL(close)
5ca: b8 15 00 00 00 mov $0x15,%eax
5cf: cd 40 int $0x40
5d1: c3 ret
000005d2 <kill>:
SYSCALL(kill)
5d2: b8 06 00 00 00 mov $0x6,%eax
5d7: cd 40 int $0x40
5d9: c3 ret
000005da <exec>:
SYSCALL(exec)
5da: b8 07 00 00 00 mov $0x7,%eax
5df: cd 40 int $0x40
5e1: c3 ret
000005e2 <open>:
SYSCALL(open)
5e2: b8 0f 00 00 00 mov $0xf,%eax
5e7: cd 40 int $0x40
5e9: c3 ret
000005ea <mknod>:
SYSCALL(mknod)
5ea: b8 11 00 00 00 mov $0x11,%eax
5ef: cd 40 int $0x40
5f1: c3 ret
000005f2 <unlink>:
SYSCALL(unlink)
5f2: b8 12 00 00 00 mov $0x12,%eax
5f7: cd 40 int $0x40
5f9: c3 ret
000005fa <fstat>:
SYSCALL(fstat)
5fa: b8 08 00 00 00 mov $0x8,%eax
5ff: cd 40 int $0x40
601: c3 ret
00000602 <link>:
SYSCALL(link)
602: b8 13 00 00 00 mov $0x13,%eax
607: cd 40 int $0x40
609: c3 ret
0000060a <mkdir>:
SYSCALL(mkdir)
60a: b8 14 00 00 00 mov $0x14,%eax
60f: cd 40 int $0x40
611: c3 ret
00000612 <chdir>:
SYSCALL(chdir)
612: b8 09 00 00 00 mov $0x9,%eax
617: cd 40 int $0x40
619: c3 ret
0000061a <dup>:
SYSCALL(dup)
61a: b8 0a 00 00 00 mov $0xa,%eax
61f: cd 40 int $0x40
621: c3 ret
00000622 <getpid>:
SYSCALL(getpid)
622: b8 0b 00 00 00 mov $0xb,%eax
627: cd 40 int $0x40
629: c3 ret
0000062a <sbrk>:
SYSCALL(sbrk)
62a: b8 0c 00 00 00 mov $0xc,%eax
62f: cd 40 int $0x40
631: c3 ret
00000632 <sleep>:
SYSCALL(sleep)
632: b8 0d 00 00 00 mov $0xd,%eax
637: cd 40 int $0x40
639: c3 ret
0000063a <uptime>:
SYSCALL(uptime)
63a: b8 0e 00 00 00 mov $0xe,%eax
63f: cd 40 int $0x40
641: c3 ret
642: 66 90 xchg %ax,%ax
644: 66 90 xchg %ax,%ax
646: 66 90 xchg %ax,%ax
648: 66 90 xchg %ax,%ax
64a: 66 90 xchg %ax,%ax
64c: 66 90 xchg %ax,%ax
64e: 66 90 xchg %ax,%ax
00000650 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
650: 55 push %ebp
651: 89 e5 mov %esp,%ebp
653: 57 push %edi
654: 56 push %esi
655: 89 c6 mov %eax,%esi
657: 53 push %ebx
658: 83 ec 4c sub $0x4c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
65b: 8b 5d 08 mov 0x8(%ebp),%ebx
65e: 85 db test %ebx,%ebx
660: 74 09 je 66b <printint+0x1b>
662: 89 d0 mov %edx,%eax
664: c1 e8 1f shr $0x1f,%eax
667: 84 c0 test %al,%al
669: 75 75 jne 6e0 <printint+0x90>
neg = 1;
x = -xx;
} else {
x = xx;
66b: 89 d0 mov %edx,%eax
neg = 0;
66d: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
674: 89 75 c0 mov %esi,-0x40(%ebp)
}
i = 0;
677: 31 ff xor %edi,%edi
679: 89 ce mov %ecx,%esi
67b: 8d 5d d7 lea -0x29(%ebp),%ebx
67e: eb 02 jmp 682 <printint+0x32>
do{
buf[i++] = digits[x % base];
680: 89 cf mov %ecx,%edi
682: 31 d2 xor %edx,%edx
684: f7 f6 div %esi
686: 8d 4f 01 lea 0x1(%edi),%ecx
689: 0f b6 92 a7 0a 00 00 movzbl 0xaa7(%edx),%edx
}while((x /= base) != 0);
690: 85 c0 test %eax,%eax
buf[i++] = digits[x % base];
692: 88 14 0b mov %dl,(%ebx,%ecx,1)
}while((x /= base) != 0);
695: 75 e9 jne 680 <printint+0x30>
if(neg)
697: 8b 55 c4 mov -0x3c(%ebp),%edx
buf[i++] = digits[x % base];
69a: 89 c8 mov %ecx,%eax
69c: 8b 75 c0 mov -0x40(%ebp),%esi
if(neg)
69f: 85 d2 test %edx,%edx
6a1: 74 08 je 6ab <printint+0x5b>
buf[i++] = '-';
6a3: 8d 4f 02 lea 0x2(%edi),%ecx
6a6: c6 44 05 d8 2d movb $0x2d,-0x28(%ebp,%eax,1)
while(--i >= 0)
6ab: 8d 79 ff lea -0x1(%ecx),%edi
6ae: 66 90 xchg %ax,%ax
6b0: 0f b6 44 3d d8 movzbl -0x28(%ebp,%edi,1),%eax
6b5: 83 ef 01 sub $0x1,%edi
write(fd, &c, 1);
6b8: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
6bf: 00
6c0: 89 5c 24 04 mov %ebx,0x4(%esp)
6c4: 89 34 24 mov %esi,(%esp)
6c7: 88 45 d7 mov %al,-0x29(%ebp)
6ca: e8 f3 fe ff ff call 5c2 <write>
while(--i >= 0)
6cf: 83 ff ff cmp $0xffffffff,%edi
6d2: 75 dc jne 6b0 <printint+0x60>
putc(fd, buf[i]);
}
6d4: 83 c4 4c add $0x4c,%esp
6d7: 5b pop %ebx
6d8: 5e pop %esi
6d9: 5f pop %edi
6da: 5d pop %ebp
6db: c3 ret
6dc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
x = -xx;
6e0: 89 d0 mov %edx,%eax
6e2: f7 d8 neg %eax
neg = 1;
6e4: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
6eb: eb 87 jmp 674 <printint+0x24>
6ed: 8d 76 00 lea 0x0(%esi),%esi
000006f0 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
6f0: 55 push %ebp
6f1: 89 e5 mov %esp,%ebp
6f3: 57 push %edi
char *s;
int c, i, state;
uint *ap;
state = 0;
6f4: 31 ff xor %edi,%edi
{
6f6: 56 push %esi
6f7: 53 push %ebx
6f8: 83 ec 3c sub $0x3c,%esp
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
6fb: 8b 5d 0c mov 0xc(%ebp),%ebx
ap = (uint*)(void*)&fmt + 1;
6fe: 8d 45 10 lea 0x10(%ebp),%eax
{
701: 8b 75 08 mov 0x8(%ebp),%esi
ap = (uint*)(void*)&fmt + 1;
704: 89 45 d4 mov %eax,-0x2c(%ebp)
for(i = 0; fmt[i]; i++){
707: 0f b6 13 movzbl (%ebx),%edx
70a: 83 c3 01 add $0x1,%ebx
70d: 84 d2 test %dl,%dl
70f: 75 39 jne 74a <printf+0x5a>
711: e9 c2 00 00 00 jmp 7d8 <printf+0xe8>
716: 66 90 xchg %ax,%ax
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
718: 83 fa 25 cmp $0x25,%edx
71b: 0f 84 bf 00 00 00 je 7e0 <printf+0xf0>
write(fd, &c, 1);
721: 8d 45 e2 lea -0x1e(%ebp),%eax
724: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
72b: 00
72c: 89 44 24 04 mov %eax,0x4(%esp)
730: 89 34 24 mov %esi,(%esp)
state = '%';
} else {
putc(fd, c);
733: 88 55 e2 mov %dl,-0x1e(%ebp)
write(fd, &c, 1);
736: e8 87 fe ff ff call 5c2 <write>
73b: 83 c3 01 add $0x1,%ebx
for(i = 0; fmt[i]; i++){
73e: 0f b6 53 ff movzbl -0x1(%ebx),%edx
742: 84 d2 test %dl,%dl
744: 0f 84 8e 00 00 00 je 7d8 <printf+0xe8>
if(state == 0){
74a: 85 ff test %edi,%edi
c = fmt[i] & 0xff;
74c: 0f be c2 movsbl %dl,%eax
if(state == 0){
74f: 74 c7 je 718 <printf+0x28>
}
} else if(state == '%'){
751: 83 ff 25 cmp $0x25,%edi
754: 75 e5 jne 73b <printf+0x4b>
if(c == 'd'){
756: 83 fa 64 cmp $0x64,%edx
759: 0f 84 31 01 00 00 je 890 <printf+0x1a0>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
75f: 25 f7 00 00 00 and $0xf7,%eax
764: 83 f8 70 cmp $0x70,%eax
767: 0f 84 83 00 00 00 je 7f0 <printf+0x100>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
76d: 83 fa 73 cmp $0x73,%edx
770: 0f 84 a2 00 00 00 je 818 <printf+0x128>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
776: 83 fa 63 cmp $0x63,%edx
779: 0f 84 35 01 00 00 je 8b4 <printf+0x1c4>
putc(fd, *ap);
ap++;
} else if(c == '%'){
77f: 83 fa 25 cmp $0x25,%edx
782: 0f 84 e0 00 00 00 je 868 <printf+0x178>
write(fd, &c, 1);
788: 8d 45 e6 lea -0x1a(%ebp),%eax
78b: 83 c3 01 add $0x1,%ebx
78e: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
795: 00
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
796: 31 ff xor %edi,%edi
write(fd, &c, 1);
798: 89 44 24 04 mov %eax,0x4(%esp)
79c: 89 34 24 mov %esi,(%esp)
79f: 89 55 d0 mov %edx,-0x30(%ebp)
7a2: c6 45 e6 25 movb $0x25,-0x1a(%ebp)
7a6: e8 17 fe ff ff call 5c2 <write>
putc(fd, c);
7ab: 8b 55 d0 mov -0x30(%ebp),%edx
write(fd, &c, 1);
7ae: 8d 45 e7 lea -0x19(%ebp),%eax
7b1: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
7b8: 00
7b9: 89 44 24 04 mov %eax,0x4(%esp)
7bd: 89 34 24 mov %esi,(%esp)
putc(fd, c);
7c0: 88 55 e7 mov %dl,-0x19(%ebp)
write(fd, &c, 1);
7c3: e8 fa fd ff ff call 5c2 <write>
for(i = 0; fmt[i]; i++){
7c8: 0f b6 53 ff movzbl -0x1(%ebx),%edx
7cc: 84 d2 test %dl,%dl
7ce: 0f 85 76 ff ff ff jne 74a <printf+0x5a>
7d4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
}
}
}
7d8: 83 c4 3c add $0x3c,%esp
7db: 5b pop %ebx
7dc: 5e pop %esi
7dd: 5f pop %edi
7de: 5d pop %ebp
7df: c3 ret
state = '%';
7e0: bf 25 00 00 00 mov $0x25,%edi
7e5: e9 51 ff ff ff jmp 73b <printf+0x4b>
7ea: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
printint(fd, *ap, 16, 0);
7f0: 8b 45 d4 mov -0x2c(%ebp),%eax
7f3: b9 10 00 00 00 mov $0x10,%ecx
state = 0;
7f8: 31 ff xor %edi,%edi
printint(fd, *ap, 16, 0);
7fa: c7 04 24 00 00 00 00 movl $0x0,(%esp)
801: 8b 10 mov (%eax),%edx
803: 89 f0 mov %esi,%eax
805: e8 46 fe ff ff call 650 <printint>
ap++;
80a: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
80e: e9 28 ff ff ff jmp 73b <printf+0x4b>
813: 90 nop
814: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
s = (char*)*ap;
818: 8b 45 d4 mov -0x2c(%ebp),%eax
ap++;
81b: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
s = (char*)*ap;
81f: 8b 38 mov (%eax),%edi
s = "(null)";
821: b8 a0 0a 00 00 mov $0xaa0,%eax
826: 85 ff test %edi,%edi
828: 0f 44 f8 cmove %eax,%edi
while(*s != 0){
82b: 0f b6 07 movzbl (%edi),%eax
82e: 84 c0 test %al,%al
830: 74 2a je 85c <printf+0x16c>
832: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
838: 88 45 e3 mov %al,-0x1d(%ebp)
write(fd, &c, 1);
83b: 8d 45 e3 lea -0x1d(%ebp),%eax
s++;
83e: 83 c7 01 add $0x1,%edi
write(fd, &c, 1);
841: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
848: 00
849: 89 44 24 04 mov %eax,0x4(%esp)
84d: 89 34 24 mov %esi,(%esp)
850: e8 6d fd ff ff call 5c2 <write>
while(*s != 0){
855: 0f b6 07 movzbl (%edi),%eax
858: 84 c0 test %al,%al
85a: 75 dc jne 838 <printf+0x148>
state = 0;
85c: 31 ff xor %edi,%edi
85e: e9 d8 fe ff ff jmp 73b <printf+0x4b>
863: 90 nop
864: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
write(fd, &c, 1);
868: 8d 45 e5 lea -0x1b(%ebp),%eax
state = 0;
86b: 31 ff xor %edi,%edi
write(fd, &c, 1);
86d: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
874: 00
875: 89 44 24 04 mov %eax,0x4(%esp)
879: 89 34 24 mov %esi,(%esp)
87c: c6 45 e5 25 movb $0x25,-0x1b(%ebp)
880: e8 3d fd ff ff call 5c2 <write>
885: e9 b1 fe ff ff jmp 73b <printf+0x4b>
88a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
printint(fd, *ap, 10, 1);
890: 8b 45 d4 mov -0x2c(%ebp),%eax
893: b9 0a 00 00 00 mov $0xa,%ecx
state = 0;
898: 66 31 ff xor %di,%di
printint(fd, *ap, 10, 1);
89b: c7 04 24 01 00 00 00 movl $0x1,(%esp)
8a2: 8b 10 mov (%eax),%edx
8a4: 89 f0 mov %esi,%eax
8a6: e8 a5 fd ff ff call 650 <printint>
ap++;
8ab: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
8af: e9 87 fe ff ff jmp 73b <printf+0x4b>
putc(fd, *ap);
8b4: 8b 45 d4 mov -0x2c(%ebp),%eax
state = 0;
8b7: 31 ff xor %edi,%edi
putc(fd, *ap);
8b9: 8b 00 mov (%eax),%eax
write(fd, &c, 1);
8bb: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
8c2: 00
8c3: 89 34 24 mov %esi,(%esp)
putc(fd, *ap);
8c6: 88 45 e4 mov %al,-0x1c(%ebp)
write(fd, &c, 1);
8c9: 8d 45 e4 lea -0x1c(%ebp),%eax
8cc: 89 44 24 04 mov %eax,0x4(%esp)
8d0: e8 ed fc ff ff call 5c2 <write>
ap++;
8d5: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
8d9: e9 5d fe ff ff jmp 73b <printf+0x4b>
8de: 66 90 xchg %ax,%ax
000008e0 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
8e0: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
8e1: a1 98 0d 00 00 mov 0xd98,%eax
{
8e6: 89 e5 mov %esp,%ebp
8e8: 57 push %edi
8e9: 56 push %esi
8ea: 53 push %ebx
8eb: 8b 5d 08 mov 0x8(%ebp),%ebx
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
8ee: 8b 08 mov (%eax),%ecx
bp = (Header*)ap - 1;
8f0: 8d 53 f8 lea -0x8(%ebx),%edx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
8f3: 39 d0 cmp %edx,%eax
8f5: 72 11 jb 908 <free+0x28>
8f7: 90 nop
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
8f8: 39 c8 cmp %ecx,%eax
8fa: 72 04 jb 900 <free+0x20>
8fc: 39 ca cmp %ecx,%edx
8fe: 72 10 jb 910 <free+0x30>
900: 89 c8 mov %ecx,%eax
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
902: 39 d0 cmp %edx,%eax
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
904: 8b 08 mov (%eax),%ecx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
906: 73 f0 jae 8f8 <free+0x18>
908: 39 ca cmp %ecx,%edx
90a: 72 04 jb 910 <free+0x30>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
90c: 39 c8 cmp %ecx,%eax
90e: 72 f0 jb 900 <free+0x20>
break;
if(bp + bp->s.size == p->s.ptr){
910: 8b 73 fc mov -0x4(%ebx),%esi
913: 8d 3c f2 lea (%edx,%esi,8),%edi
916: 39 cf cmp %ecx,%edi
918: 74 1e je 938 <free+0x58>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
91a: 89 4b f8 mov %ecx,-0x8(%ebx)
if(p + p->s.size == bp){
91d: 8b 48 04 mov 0x4(%eax),%ecx
920: 8d 34 c8 lea (%eax,%ecx,8),%esi
923: 39 f2 cmp %esi,%edx
925: 74 28 je 94f <free+0x6f>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
927: 89 10 mov %edx,(%eax)
freep = p;
929: a3 98 0d 00 00 mov %eax,0xd98
}
92e: 5b pop %ebx
92f: 5e pop %esi
930: 5f pop %edi
931: 5d pop %ebp
932: c3 ret
933: 90 nop
934: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
bp->s.size += p->s.ptr->s.size;
938: 03 71 04 add 0x4(%ecx),%esi
93b: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
93e: 8b 08 mov (%eax),%ecx
940: 8b 09 mov (%ecx),%ecx
942: 89 4b f8 mov %ecx,-0x8(%ebx)
if(p + p->s.size == bp){
945: 8b 48 04 mov 0x4(%eax),%ecx
948: 8d 34 c8 lea (%eax,%ecx,8),%esi
94b: 39 f2 cmp %esi,%edx
94d: 75 d8 jne 927 <free+0x47>
p->s.size += bp->s.size;
94f: 03 4b fc add -0x4(%ebx),%ecx
freep = p;
952: a3 98 0d 00 00 mov %eax,0xd98
p->s.size += bp->s.size;
957: 89 48 04 mov %ecx,0x4(%eax)
p->s.ptr = bp->s.ptr;
95a: 8b 53 f8 mov -0x8(%ebx),%edx
95d: 89 10 mov %edx,(%eax)
}
95f: 5b pop %ebx
960: 5e pop %esi
961: 5f pop %edi
962: 5d pop %ebp
963: c3 ret
964: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
96a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000970 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
970: 55 push %ebp
971: 89 e5 mov %esp,%ebp
973: 57 push %edi
974: 56 push %esi
975: 53 push %ebx
976: 83 ec 1c sub $0x1c,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
979: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
97c: 8b 1d 98 0d 00 00 mov 0xd98,%ebx
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
982: 8d 48 07 lea 0x7(%eax),%ecx
985: c1 e9 03 shr $0x3,%ecx
if((prevp = freep) == 0){
988: 85 db test %ebx,%ebx
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
98a: 8d 71 01 lea 0x1(%ecx),%esi
if((prevp = freep) == 0){
98d: 0f 84 9b 00 00 00 je a2e <malloc+0xbe>
993: 8b 13 mov (%ebx),%edx
995: 8b 7a 04 mov 0x4(%edx),%edi
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){
998: 39 fe cmp %edi,%esi
99a: 76 64 jbe a00 <malloc+0x90>
99c: 8d 04 f5 00 00 00 00 lea 0x0(,%esi,8),%eax
if(nu < 4096)
9a3: bb 00 80 00 00 mov $0x8000,%ebx
9a8: 89 45 e4 mov %eax,-0x1c(%ebp)
9ab: eb 0e jmp 9bb <malloc+0x4b>
9ad: 8d 76 00 lea 0x0(%esi),%esi
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
9b0: 8b 02 mov (%edx),%eax
if(p->s.size >= nunits){
9b2: 8b 78 04 mov 0x4(%eax),%edi
9b5: 39 fe cmp %edi,%esi
9b7: 76 4f jbe a08 <malloc+0x98>
9b9: 89 c2 mov %eax,%edx
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
9bb: 3b 15 98 0d 00 00 cmp 0xd98,%edx
9c1: 75 ed jne 9b0 <malloc+0x40>
if(nu < 4096)
9c3: 8b 45 e4 mov -0x1c(%ebp),%eax
9c6: 81 fe 00 10 00 00 cmp $0x1000,%esi
9cc: bf 00 10 00 00 mov $0x1000,%edi
9d1: 0f 43 fe cmovae %esi,%edi
9d4: 0f 42 c3 cmovb %ebx,%eax
p = sbrk(nu * sizeof(Header));
9d7: 89 04 24 mov %eax,(%esp)
9da: e8 4b fc ff ff call 62a <sbrk>
if(p == (char*)-1)
9df: 83 f8 ff cmp $0xffffffff,%eax
9e2: 74 18 je 9fc <malloc+0x8c>
hp->s.size = nu;
9e4: 89 78 04 mov %edi,0x4(%eax)
free((void*)(hp + 1));
9e7: 83 c0 08 add $0x8,%eax
9ea: 89 04 24 mov %eax,(%esp)
9ed: e8 ee fe ff ff call 8e0 <free>
return freep;
9f2: 8b 15 98 0d 00 00 mov 0xd98,%edx
if((p = morecore(nunits)) == 0)
9f8: 85 d2 test %edx,%edx
9fa: 75 b4 jne 9b0 <malloc+0x40>
return 0;
9fc: 31 c0 xor %eax,%eax
9fe: eb 20 jmp a20 <malloc+0xb0>
if(p->s.size >= nunits){
a00: 89 d0 mov %edx,%eax
a02: 89 da mov %ebx,%edx
a04: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
if(p->s.size == nunits)
a08: 39 fe cmp %edi,%esi
a0a: 74 1c je a28 <malloc+0xb8>
p->s.size -= nunits;
a0c: 29 f7 sub %esi,%edi
a0e: 89 78 04 mov %edi,0x4(%eax)
p += p->s.size;
a11: 8d 04 f8 lea (%eax,%edi,8),%eax
p->s.size = nunits;
a14: 89 70 04 mov %esi,0x4(%eax)
freep = prevp;
a17: 89 15 98 0d 00 00 mov %edx,0xd98
return (void*)(p + 1);
a1d: 83 c0 08 add $0x8,%eax
}
}
a20: 83 c4 1c add $0x1c,%esp
a23: 5b pop %ebx
a24: 5e pop %esi
a25: 5f pop %edi
a26: 5d pop %ebp
a27: c3 ret
prevp->s.ptr = p->s.ptr;
a28: 8b 08 mov (%eax),%ecx
a2a: 89 0a mov %ecx,(%edx)
a2c: eb e9 jmp a17 <malloc+0xa7>
base.s.ptr = freep = prevp = &base;
a2e: c7 05 98 0d 00 00 9c movl $0xd9c,0xd98
a35: 0d 00 00
base.s.size = 0;
a38: ba 9c 0d 00 00 mov $0xd9c,%edx
base.s.ptr = freep = prevp = &base;
a3d: c7 05 9c 0d 00 00 9c movl $0xd9c,0xd9c
a44: 0d 00 00
base.s.size = 0;
a47: c7 05 a0 0d 00 00 00 movl $0x0,0xda0
a4e: 00 00 00
a51: e9 46 ff ff ff jmp 99c <malloc+0x2c>
|
; Aula 07 - Controle de Fluxo de Execucao
; arquivo: a07e04.asm
; objetivo: the evil lowercase papagali code!
; verifica entrada
; se length < 25
; converte string de entrada para lowercase
; apresenta conversao
; senao
; msg de erro e encerra
; nasm -f elf64 a07e04.asm ; ld a07e04.o -o a07e04.x
%define maxChars 26
section .data
strOla : db "Hello? (max 25 caracteres)", 10, 0
strOlaL: equ $ - strOla
strBye : db "Voce digitou: ", 0
strByeL: equ $ - strBye
strErro : db "Voce digitou mais do que 25 caracteres", 10, "Programa encerrado", 10, 0
strErroL: equ $ - strErro
strLF : db 10 ; quebra de linha
strLFL : db 1
section .bss
strLida : resb maxChars
strLidaL : resd 1
section .text
global _start
_start:
mov rax, 1
mov rdi, 1 ; std_file
lea rsi, [strOla]
mov edx, strOlaL
syscall
leitura:
mov rax, 0 ; READ
mov rdi, 1
lea rsi, [strLida]
mov edx, maxChars
syscall
mov [strLidaL], eax
verificacaoDeEntrada:
; [strLida + eax-1] aponta para ultimo lido
; se ultimo for enter
; laco para lowercase
cmp byte [strLida + eax-1], 10
je entradaFor
; senao
; msg de erro e encerra.
mov rax, 1 ; WRITE
mov rdi, 1
mov rsi, strErro
mov rdx, strErroL
syscall
jmp fim
; for(ecx = 0; ecx < strLidaL; ecx++){ ... }
entradaFor:
mov ecx, 0 ; ecx = 0
mov r8d, [strLidaL] ; reg eh rapido
dec r8d
preBloco:
cmp ecx, r8d ; ecx < strLidaL
jge saidaFor
blocoFor:
; acessa String e aplica lowercase byte-a-byte
or byte [strLida + ecx], 0x20
inc ecx ; ecx++
jmp preBloco
saidaFor:
resposta:
mov rax, 1 ; WRITE
mov rdi, 1
lea rsi, [strBye]
mov edx, strByeL
syscall
mov rax, 1 ; WRITE
mov ebx, 1
lea rsi, [strLida]
mov edx, [strLidaL]
syscall
fim:
mov rax, 60
mov rdi, 0
syscall
|
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "TextureReshaper.h"
#include "DataReshaper.h"
#include <utils/Panic.h>
namespace filament {
namespace backend {
static void freeDeleter(void* buffer, size_t, void*) {
free(buffer);
}
TextureReshaper::TextureReshaper(TextureFormat requestedFormat) noexcept {
mReshapedFormat = requestedFormat;
mNeedsReshaping = false;
if (requestedFormat == TextureFormat::RGB16F) {
mReshapedFormat = TextureFormat::RGBA16F;
mNeedsReshaping = true;
mReshapeFunction = [](PixelBufferDescriptor& p) {
const size_t reshapedSize = p.size / 6 * 8; // reshaping from 6 to 8 bytes per pixel
void* reshapeBuffer = malloc(reshapedSize);
ASSERT_POSTCONDITION(reshapeBuffer, "Could not allocate memory to reshape pixels.");
DataReshaper::reshape<uint16_t, 3, 4>(reshapeBuffer, p.buffer, p.size);
PixelBufferDescriptor reshaped(reshapeBuffer, reshapedSize,
PixelBufferDescriptor::PixelDataFormat::RGBA,
PixelBufferDescriptor::PixelDataType::HALF, 1, p.left, p.top, p.stride,
freeDeleter);
return reshaped;
};
};
if (requestedFormat == TextureFormat::RGB8) {
mReshapedFormat = TextureFormat::RGBA8;
mNeedsReshaping = true;
mReshapeFunction = [](PixelBufferDescriptor& p) {
const size_t reshapedSize = p.size / 3 * 4; // reshaping from 3 to 4 bytes per pixel
void* reshapeBuffer = malloc(reshapedSize);
ASSERT_POSTCONDITION(reshapeBuffer, "Could not allocate memory to reshape pixels.");
DataReshaper::reshape<uint8_t, 3, 4>(reshapeBuffer, p.buffer, p.size);
PixelBufferDescriptor reshaped(reshapeBuffer, reshapedSize,
PixelBufferDescriptor::PixelDataFormat::RGBA,
PixelBufferDescriptor::PixelDataType::UBYTE, 1, p.left, p.top, p.stride,
freeDeleter);
return reshaped;
};
}
}
TextureFormat TextureReshaper::getReshapedFormat() const noexcept {
return mReshapedFormat;
}
PixelBufferDescriptor TextureReshaper::reshape(PixelBufferDescriptor& p) const {
assert(mReshapeFunction);
return mReshapeFunction(p);
}
bool TextureReshaper::canReshapeTextureFormat(TextureFormat format) noexcept {
return format == TextureFormat::RGB16F || format == TextureFormat::RGB8;
}
} // namespace backend
} // namespace filament
|
; A240523: a(n) = floor(4^n/((1+sqrt(5))/2)^(2*n)).
; Submitted by Jon Maiga
; 1,1,2,3,5,8,12,19,29,45,69,105,161,247,377,577,881,1347,2058,3144,4805,7341,11216,17137,26183,40005,61122,93387,142682,218000,333074,508892,777518,1187942,1815014,2773095,4236913,6473427,9890517,15111365,23088112,35275497,53896163,82346010,125813509,192225937,293695098,448726180,685592597,1047492279,1600425790,2445233022,3735983616,5708075040,8721162620,13324750798,20358407653,31104879067,47524026351,72610251136,110938592010,169499085935,258971559061,395673333767,604535060228,923647382465
mul $0,2
mov $1,2
pow $1,$0
seq $0,32 ; Lucas numbers beginning at 2: L(n) = L(n-1) + L(n-2), L(0) = 2, L(1) = 1.
sub $1,$0
div $1,$0
mov $0,$1
add $0,1
|
# File: add_ascii_numbers.asm
# Author: K. Reek
# Contributors: P. White, W. Carithers
# Alexander Kellermann Nieves (akn1736)
#
# Updates:
# 3/2004 M. Reek, named constants
# 10/2007 W. Carithers, alignment
# 09/2009 W. Carithers, separate assembly
#
# Description: Add two ASCII numbers and store the result in ASCII.
#
# Arguments: a0: address of parameter block. The block consists of
# four words that contain (in this order):
#
# address of first input string
# address of second input string
# address where result should be stored
# length of the strings and result buffer
#
# (There is actually other data after this in the
# parameter block, but it is not relevant to this routine.)
#
# Returns: The result of the addition, in the buffer specified by
# the parameter block.
#
.globl add_ascii_numbers
add_ascii_numbers:
A_FRAMESIZE = 40
#
# Save registers ra and s0 - s7 on the stack.
#
addi $sp, $sp, -A_FRAMESIZE
sw $ra, -4+A_FRAMESIZE($sp)
sw $s7, 28($sp)
sw $s6, 24($sp)
sw $s5, 20($sp)
sw $s4, 16($sp)
sw $s3, 12($sp)
sw $s2, 8($sp)
sw $s1, 4($sp)
sw $s0, 0($sp)
# ##### BEGIN STUDENT CODE BLOCK 1 #####
.data
.align 0
testing:
.word 9 # set up a data segment for testing
.word 23
.word 34
.word 49
wordz:
.ascii "7"
.text
.align 2
else:
# I want to test the program by writing nonsense results to the result. But I
# can't seem to get the result to change. This makes debugging the program
# difficult.
lw $s0, 0($a0) # This stores the first string
lw $s1, 4($a0) # This stores the second string
lw $s2, 8($a0) # This stores the addr of where 2 put result.
lw $s3, 12($a0) # Length of the string
lw $s4, 16($a0) # Result (This is only a string)
la $s5, wordz
lw $s6, 0($s5) # s6 should now contain ascii 7
sw $s5, 16($a0)
li $t0, 0 # This will be the counter for the loop
addloop:
beq $t0, $s3, endLoop # When t0==s3, exit
addi $t0, $t0, 1
j addloop
endLoop:
## Attempting to write to the word block
# ###### END STUDENT CODE BLOCK 1 ######
#
# Restore registers ra and s0 - s7 from the stack.
#
lw $ra, -4+A_FRAMESIZE($sp)
lw $s7, 28($sp)
lw $s6, 24($sp)
lw $s5, 20($sp)
lw $s4, 16($sp)
lw $s3, 12($sp)
lw $s2, 8($sp)
lw $s1, 4($sp)
lw $s0, 0($sp)
addi $sp, $sp, A_FRAMESIZE
jr $ra # Return to the caller.
|
<%
import collections
import pwnlib.abi
import pwnlib.constants
import pwnlib.shellcraft
import six
%>
<%docstring>getsid(pid) -> str
Invokes the syscall getsid.
See 'man 2 getsid' for more information.
Arguments:
pid(pid_t): pid
Returns:
pid_t
</%docstring>
<%page args="pid=0"/>
<%
abi = pwnlib.abi.ABI.syscall()
stack = abi.stack
regs = abi.register_arguments[1:]
allregs = pwnlib.shellcraft.registers.current()
can_pushstr = []
can_pushstr_array = []
argument_names = ['pid']
argument_values = [pid]
# 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_getsid']:
if hasattr(pwnlib.constants, syscall):
break
else:
raise Exception("Could not locate any syscalls: %r" % syscalls)
%>
/* getsid(${', '.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)}
|
%ifdef CONFIG
{
"RegData": {
"RAX": "0x3ff0000000000000",
"RBX": "0x0000000000000000",
"RCX": "0x3ff0000000000000"
},
"Env": { "FEX_X87REDUCEDPRECISION" : "1" }
}
%endif
mov rdx, 0xe0000000
mov eax, 0x3f800000 ; 1.0
mov [rdx + 8 * 0], eax
fld1
fldz
mov eax, 1
cmp eax, 1
fcmovne st0, st1
fldz
cmp eax, 0
fcmovne st0, st2
fstp qword [rdx]
mov rax, [rdx]
fstp qword [rdx]
mov rbx, [rdx]
fstp qword [rdx]
mov rcx, [rdx]
hlt
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r8
push %rax
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_WT_ht+0x82b0, %rax
clflush (%rax)
nop
nop
nop
nop
xor %r8, %r8
vmovups (%rax), %ymm1
vextracti128 $1, %ymm1, %xmm1
vpextrq $1, %xmm1, %rbx
nop
cmp %r12, %r12
lea addresses_normal_ht+0x167f0, %rsi
lea addresses_WT_ht+0x17582, %rdi
clflush (%rsi)
clflush (%rdi)
nop
cmp $14228, %rbx
mov $105, %rcx
rep movsw
nop
nop
nop
add %rax, %rax
lea addresses_UC_ht+0xe2a9, %rcx
nop
nop
nop
cmp $29455, %r12
mov (%rcx), %rsi
nop
nop
nop
nop
cmp $3434, %rax
lea addresses_UC_ht+0x166c0, %r12
nop
nop
nop
add $18759, %rbx
movl $0x61626364, (%r12)
nop
nop
and %rbx, %rbx
lea addresses_UC_ht+0x33b0, %rsi
lea addresses_A_ht+0x41b0, %rdi
nop
nop
dec %rax
mov $59, %rcx
rep movsq
nop
nop
xor $38668, %rax
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r8
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r15
push %rax
push %rbp
push %rdx
push %rsi
// Load
mov $0x910, %r10
nop
add %rax, %rax
mov (%r10), %edx
nop
nop
nop
nop
cmp %r11, %r11
// Store
lea addresses_WC+0x7bb0, %r11
nop
nop
nop
nop
dec %r10
mov $0x5152535455565758, %rsi
movq %rsi, %xmm5
vmovups %ymm5, (%r11)
nop
nop
nop
sub %rdx, %rdx
// Faulty Load
lea addresses_WC+0x7bb0, %rdx
nop
nop
nop
nop
nop
dec %r15
movb (%rdx), %r10b
lea oracles, %rdx
and $0xff, %r10
shlq $12, %r10
mov (%rdx,%r10,1), %r10
pop %rsi
pop %rdx
pop %rbp
pop %rax
pop %r15
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'congruent': 0, 'AVXalign': True, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_WC'}, 'OP': 'LOAD'}
{'src': {'congruent': 2, 'AVXalign': False, 'same': False, 'size': 4, 'NT': False, 'type': 'addresses_P'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 32, 'NT': False, 'type': 'addresses_WC'}}
[Faulty Load]
{'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 1, 'NT': False, 'type': 'addresses_WC'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'congruent': 6, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_WT_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 5, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'congruent': 1, 'same': False, 'type': 'addresses_WT_ht'}}
{'src': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 8, 'NT': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 1, 'AVXalign': False, 'same': False, 'size': 4, 'NT': False, 'type': 'addresses_UC_ht'}}
{'src': {'congruent': 10, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 9, 'same': False, 'type': 'addresses_A_ht'}}
{'00': 1, '5f': 4, '58': 21824}
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
*/
|
/*
* * Copyright (C) 2018 Intel Corporation.All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/**
* @file IasIDebug.hpp
* @date 2016
* @brief
*/
#ifndef IASIDEBUG_HPP_
#define IASIDEBUG_HPP_
#include "avbaudiomodules/audio/common/IasAudioCommonTypes.hpp"
namespace IasAudio {
/**
* @brief The debug interface class
*
* This class is used for debug purposes. See chapter @ref probing for more details.
*/
class IAS_AUDIO_PUBLIC IasIDebug
{
public:
/**
* @brief The result type for the IasIDebug methods
*/
enum IasResult
{
eIasOk, //!< Operation successful
eIasFailed, //!< Operation failed
};
/**
* @brief Destructor.
*/
virtual ~IasIDebug() {}
/**
* @brief Inject data from wave files at a certain audio port/pin.
* Every channel of the audio port/pin must be fed with a separate
* wav file.
*
* @param[in] fileNamePrefix The prefix for wav file names, without directory. For injecting, the wav files need to be present in /tmp.
* The naming convention is #fileNamePrefix_chx.wav ,e.g. for a stereo port/pin inject, the following files must be present
* (assuming fileNamePrefix="test"):
* /tmp/test_ch0.wav
* /tmp/test_ch1.wav
* @param[in] name the name of the port/pin to inject data
* @param[in] numSeconds the number of seconds to be injected
*
* @return The result of the inject operation
* @retval IasIDebug::eIasOk All went well, inject started
* @retval IasIDebug::eIasFailed Failed to start injection
*/
virtual IasResult startInject(const std::string &fileNamePrefix, const std::string &name, uint32_t numSeconds)=0;
/**
* @brief Record data of an audio port/pin to wave files.
* Every channel of the audio port/pin will be recorded to a separate wav file
*
*
* @param[in] fileNamePrefix the prefix for wav file names, without directory. For recording, the wav files will be stored /tmp.
* The naming convention is #fileNamePrefix_chx.wav, e.g. for a stereo port/pin record, the following files will be stored
* (assuming fileNamePrefix="test"):
* /tmp/test_ch0.wav
* /tmp/test_ch1.wav
* @param[in] name the name of the port/pin
* @param[in] numSeconds the number of seconds to be recorded
*
* @return The result of the record operation
* @retval IasIDebug::eIasOk All went well, record started
* @retval IasIDebug::eIasFailed Failed to start recording
*/
virtual IasResult startRecord(const std::string &fileNamePrefix, const std::string &name, uint32_t numSeconds)=0;
/**
* @brief Stops any inject or recording operation for a given audio port/pin
*
* @param[in] name The name of the audio port/pin
*
* @return The result of the stop
* @retval IasIDebug::eIasOk All went well
* @retval IasIDebug::eIasFailed Failed to stop probing
*/
virtual IasResult stopProbing(const std::string &name)=0;
};
/**
* @brief Function to get a IasIDebug::IasResult as string.
*
* @param[in] type The IasIDebug::IasResult value
*
* @return Enum Member as string
*/
std::string toString(const IasIDebug::IasResult& type);
} //namespace IasAudio
#endif /* IASIDEBUG_HPP_ */
|
;************************************************************************
; *
; Copyright (C) 1991 by Trace Center (just kidding) *
; *
; FILTER.ASM *
; *
;************************************************************************
TITLE FilterKeys
INCLUDE keyboard.inc
EXTRN shift_tbl:byte ; in Handicap.asm
EXTRN shift_tbl_len:abs
EXTRN real_states:byte
EXTRN prev_real_states:byte
EXTRN current_shift:byte
EXTRN beep_high:PROC
EXTRN beep_low:PROC
EXTRN no_beep:PROC
EXTRN beep_turn_on:PROC
EXTRN beep_turn_off:PROC
EXTRN click:PROC
EXTRN _comp_id:byte
EXTRN fsilent_click:byte
EXTRN fbios_called_timing:byte
EXTRN _vector:byte
EXTRN fswitching_video:byte
EXTRN faccess_sound:byte
EXTRN fsecond_cue:byte
EXTRN SticKeys:PROC ; in StickeyKeys.asm
EXTRN TimeOut_Reset:PROC ; in ToggleKeys.asm
EXTRN fFilterKeysOn:byte ; from Param.asm
EXTRN fFK_On_Off_Feedback:byte
EXTRN fUser_SetUp_Option1:byte
EXTRN fUser_SetUp_Option2:byte
EXTRN wait_ticks:word
EXTRN delay_ticks:word
EXTRN repeat_ticks:word
EXTRN fmax_default:byte
EXTRN fclick_on:byte
EXTRN fDialog_Filter_off:byte
EXTRN fRecovery_On:byte
EXTRN recovery_ticks:word
PUBLIC FilterKeys ; in FilterKeys.asm
PUBLIC FilterKeys_timer
PUBLIC FilterKeys_TurnOff
PUBLIC FilterKeys_dialog
PUBLIC fshift_click
PUBLIC on_repeat_ticks
PUBLIC on_wait_ticks
IFDEF BUG
EXTRN HexCharsOut:PROC
EXTRN portid:byte
EXTRN portout:byte
ENDIF; BUG
;----------------------------------------------------------------------------
_TEXT segment word public 'CODE'
assume CS:_TEXT
assume DS:NOTHING
assume ES:NOTHING
assume SS:NOTHING
;----------------------------------------------------------------------------
; R E S I D E N T D A T A A R E A
;
; The below area defines the resident data area.
repeating? DB false ; beginning repeat
hot_key_only? DB false ; only hot key is down
previous_code DW 0 ; holds previous code
prior_code DW 0 ; holds code before previous code
tick_count DW 0 ; holds the actual count that gets dec
toggle_time DW reset_cnt ; holds count for toggle time
fshift_click DB false ; holds a flag such that a modifier only clicks once
frecovery_timing DB false ; flag used to tell us that recovery_ticks is counting out by timer
on_wait_ticks DW 0 ; holds wait tick count while running
on_delay_ticks DW 0 ; holds delay tick count while running
on_repeat_ticks DW 0 ; holds repeat tick count while running
on_recovery_ticks DW 0 ; holds recovery tick count while running
on_delay_ticks_adj DW 0 ; holds adjusted value for delay ticks assuming recovery keys is on
;----------------------------------------------------------------------------
; FilterKeys
;
; This routine does typeamatic rate adjustment and acceptance key timing and
; the recovery keys routine.
; It is called by the hardware interrupt routine keybd_int in the file, "handicap.asm".
; FilterKeys does not depend on any register to be saved, but
; we must save whatever we use since we are in an interrupt routine.
;
; Expects: AX = extended scan code
;
; Changes: Nothing
;-----------------------------------------------------------------------------
FilterKeys proc
assume DS:_TEXT
assume ES:_TEXT
jmp filter_begin
;----------------------------------------------------------------------------
; FilterKeys_timer
;
; Increments the counts used in the turn on/off of FilterKeys and the
; acceptance, delay until repeat, and key repeat time out options.
FilterKeys_timer proc
assume DS:_TEXT
;----------------------------------------------------------------------------
; first check to see if we are manually being turned off or on. To toggle
; it on or off, we have it set so that the persom must hold down the
; carriage return key for at least eight seconds. The person receives a 3 warning
; beeps after 4 seconds.
;
FKT_10:
cmp hot_key_only?,false ; hot key not down?
jne FKT_12
jmp start_cnt_over ; no, it is down -->
FKT_12:
mov ax,toggle_time ; get current count
cmp ax,0 ; are we at no repeat amount = 0?
je set_max_default ; yes -->
jg FKT_15
jmp begin_FilterKeys_timer ; less than, so already done
; Now check for toggle on/off of FilterKeys
FKT_15:
dec toggle_time ; no, decrement count
cmp ax,warning_cnt ; are we at the warning count ?
je warning_cnt_sub
cmp ax,toggle_dflt_cnt ; are we at toggle amount?
je turn_filter
cmp ax,no_accept_cnt ; are we at User setup option 1??
je no_accept_cnt_sub ; yes
jmp begin_FilterKeys_timer ; no -->
; Reached on/off time limit so toggle.
turn_filter:
cmp fFilterKeysOn,false ; are we off?
je turn_filter_on ; yes -->
call fk_turn_off_fb
mov toggle_time,to_dflt_cnt ; make toggle_time very large so if user
; cont. to hold rshift key after FilterK/eys turns
; off, it will not just turn back on. After the user
; finally releases the rshift key, then the correct count
; is restored to toggle_time
jmp hot_key_end
turn_filter_on:
call fk_turn_on_fb
jmp hot_key_end
set_max_default:
dec toggle_time
cmp fswitching_video,false
jne set_max_default_5
mov faccess_sound,true
mov fsecond_cue,24 ; up arrow for up siren
set_max_default_5:
cmp fFK_On_Off_Feedback,false
je set_max_default_10
call beep_turn_on
call no_beep
call beep_turn_on
call no_beep
call beep_turn_on
set_max_default_10:
mov on_wait_ticks,max_dflt_wait_cnt
;; mov on_delay_ticks,32760 ; put on_delay_ticks at maximum
mov fUser_SetUp_Option2,true ; set user option 2 true
mov fUser_SetUp_Option1,false ;reset flag
jmp hot_key_end
warning_cnt_sub:
cmp fswitching_video,false
jne warning_cnt_sub_5
mov faccess_sound,true
mov fsecond_cue,7 ; filled circle for high beep
warning_cnt_sub_5:
call beep_high
call no_beep
call beep_high
call no_beep
call beep_high
jmp hot_key_end
no_accept_cnt_sub:
cmp fswitching_video,false
jne no_accept_cnt_sub_5
mov faccess_sound,true
mov fsecond_cue,24
no_accept_cnt_sub_5:
cmp fFK_On_Off_Feedback,false
je no_accept_cnt_sub_10
call beep_turn_on
call no_beep
call beep_turn_on
no_accept_cnt_sub_10:
mov fUser_SetUp_Option1,true ; set user option 1 true
mov fUser_SetUp_Option2,false ; set user option 2 false
mov on_wait_ticks,0 ; in User_SetUp_Option1, the is no acceptance delay
mov on_delay_ticks,18 ; default User_SetUp_Option1 BounceKeys of 1 second
mov on_delay_ticks,32760 ; put on_delay_ticks at maximum
hot_key_end:
jmp FilterKeys_timer_end
;----------------------------------------------------------------------------
; NOT Hot Key down by itself.
;
start_cnt_over:
mov toggle_time,reset_cnt
;----------------------------------------------------------------------------
; check and see if it is time to send a key through, both delayed acceptance
; and repeat.
begin_FilterKeys_timer:
cmp fFilterKeysOn,false
jne check_time
jmp FilterKeys_timer_end ; if not on, quit
check_time:
mov ax,tick_count
or ax,ax ; are we at 0?
jz generate_key ; yes, then time to pass on key -->
dec ax ; no, decrement count
jmp set_ticks ; save value -->
generate_key:
cmp frecovery_timing,true ; is RecoveryKeys On, and a key already passed
jne generate_key_15 ; if not, cont as before
mov frecovery_timing,false ; incase RecoveryKeys is On, we elapsed the timer
jmp short FKT_35 ; reset counter to next delay (ie on_delay_ticks)
generate_key_15:
mov ax,previous_code ; get key to pass
or ax,ax ; is a key down?
jnz go_ahead
jmp FilterKeys_timer_end ;
go_ahead:
;***********
; We do not expect any registers to be saved upon return from SticKeys
; Added call to Click for whenever SlowKeys is on.
;
; cmp _comp_id,1 ; IBM PC or PC/XT ?
; jne FKT_25 ; if so, we will click later in pass_to_computer
; push ax ; temp save
; in al,kb_data ; read in data from keyboard port
; cmp al,0 ; was byte a 0??
; jne FKT_20 ; if not, okay to click if on
; pop ax ; restore ax
;
;;; cmp fclick_on,true ; is click sound turned on
;;; jne FKT_16
;;; call click
;;; jmp short FKT_18
;;;FKT_16:
; mov fsilent_click,true ; flag to allow time for PC /XT
; call click
;FKT_18:
; call SticKeys ; pass on actual code
; cmp fsilent_click,true ; if we return from call to Stickeys, and fsilent_click
; je FilterKeys_timer_end ; is true, then al=0 here in Filters or in handicap (pass_to_computer)
; ; meaning no scan code was passed, so we need to jump to the end without
; ; changing the current delay we are in, and the next timer int. will try
; ; once again to pass this same scan code along
;
; cmp fclick_on,true ; if we get here, we passed a key, is click sound turned on
; jne FKT_19
; call click
;FKT_19:
; jmp short FKT_35
;
;FKT_20:
; pop ax ; restore ax
;***********
FKT_25:
;* cmp fclick_on,true ; is click sound turned on
;* jne FKT_30
;; suggestion was made to not have the repeat of modifier keys cause a click, so added short check here to
;; do this, but not to the PC or PC/XT (ax [al] has the scan code at this point)
;* cmp fshift_click,true ; was at least one modifier key passed with a click ?
;* je FKT_30 ; is so, cont. on., if not, calll click and then set flag true
;*
;* cmp current_shift,0
;* jne FKT_30
;* mov fshift_click,true ; if we clicked once, alway set true, as any non modifier key will clear
;* cmp on_wait_ticks,0 ; is there an acceptance delay ?
;* je FKT_30 ; if not, don't click the modifier key at all
;*
;*
;***********
;FKT_27:
; cmp _vector,15h ; are we on a computer which supports int 15h
; je FKT_30 ; if yes, save click for when key is actually pased int kybd int15
; call click ; audible feedback that SlowKeys is on
;***********
;*
;*
;*FKT_30:
mov fbios_called_timing,true ; tell kybd_int 15h that timer passed a key
; and do it before we call StickeyKeys, in case
; MouseKeys cancels it (i.e. MouseKeys not sent on)
call SticKeys ; pass on actual code
FKT_35:
mov ax,on_repeat_ticks ; get on_repeat_ticks value
cmp repeating?,true ; are in typematic?
je set_ticks ; yes -->
mov repeating?,true ; no, then say we are repeating
cmp fRecovery_On,true ; is RecoveryKEys On ?
jne FKT_40 ; if not, cont.
mov ax,on_delay_ticks_adj ; use value of on_delay_ticks_adj instead
jmp short set_ticks
FKT_40:
mov ax,on_delay_ticks ; get on_delay_ticks
set_ticks:
mov tick_count,ax
FilterKeys_timer_end:
ret
FilterKeys_timer endp
;---------------------------------------------------------------------------
; the following routines provide the sound feedback.
fk_turn_off_fb proc near
assume DS:_TEXT
cmp fFK_On_Off_Feedback,false
je FilterKeys_TurnOff
call beep_turn_off
FilterKeys_TurnOff:
cmp fswitching_video,false
jne FilterKeys_TurnOff_5
mov faccess_sound,true
mov fsecond_cue,25 ; down arrow for falling siren
FilterKeys_TurnOff_5:
mov fFilterKeysOn,false ; turn off
fk_Restart:
mov toggle_time,reset_cnt ; reset count down
mov previous_code,0 ; clear previous code
mov prior_code,0 ; clear as well
mov repeating?,false ; reset flag
mov fUser_SetUp_Option1,false ; reset flag
mov fUser_SetUp_Option2,false ; reset flag
ret
fk_turn_off_fb endp
;----------------------------------------------------------------------------
fk_turn_on_fb proc near
assume DS:_TEXT
cmp fFK_On_Off_Feedback,false
je FilterKeys_TurnOn
call beep_turn_on
FilterKeys_TurnOn:
;; call TimeOut_Reset
cmp fswitching_video,false
jne FilterKeys_TurnOn_5
mov faccess_sound,true
mov fsecond_cue,24
FilterKeys_TurnOn_5:
mov fFilterKeysOn,true ; turn on
push ax
mov ax,delay_ticks
mov on_delay_ticks,ax
mov ax,repeat_ticks
mov on_repeat_ticks,ax
mov ax,recovery_ticks
mov on_recovery_ticks,ax
mov ax,wait_ticks
mov on_wait_ticks,ax
;******** DO NOT ALLOW RecoveryKeys to be on, if Acceptance Delay is NOT zero *****************
cmp ax,0 ; is wait_ticks zero?
je FKTO_15 ; if yes, then don't affect fRecovery_On flag, may be On or Off
mov fRecovery_On,false ; if no, then be sure to NOT allow fRecovery_On to be ON
FKTO_15:
pop ax
cmp fRecovery_On,true ; if RecoveryKeys is On, setup on_delay_ticks_adj
jne FKTO_50
cmp on_delay_ticks,32760 ; is delay_ticks "off" (i.ei no repeats)
jne FKTO_18 ; if delay_ticks is not off, adjust it for RecoveryTicks
mov on_delay_ticks_adj,32760 ; if it was off, also make on_delay_ticks_adj off
jmp short FKTO_50 ; and exit
FKTO_18:
push ax
push bx
mov ax,on_delay_ticks
;IFDEF BUG
; mov portid,0ddh
; mov portout,ah
; call HexCharsOut
; mov portout,al
; call HexCharsOut
;ENDIF; BUG
mov bx,on_recovery_ticks
;IFDEF BUG
; mov portid,0deh
; mov portout,bh
; call HexCharsOut
; mov portout,bl
; call HexCharsOut
;ENDIF; BUG
cmp ax,bx ; be sure delay ticks is greater than recovery ticks
jg FKTO_20
mov on_delay_ticks_adj,0 ; if not greater, force on_delay_ticks_adj to 0
jmp short FKTO_30
FKTO_20:
sub ax,bx ; subtract on_recoveryticks from on_delay_ticks
mov on_delay_ticks_adj,ax ; store that value in on_delay_ticks_adj
;IFDEF BUG
; mov portid,0dfh
; mov portout,ah
; call HexCharsOut
; mov portout,al
; call HexCharsOut
;ENDIF; BUG
FKTO_30:
pop bx
pop ax
FKTO_50:
ret
fk_turn_on_fb endp
;----------------------------------------------------------------------------
; FilterKeys_dialog
;
; Checks a single flag from Dialog box to see if FilterKeys was turned
; on/off. If it was, this routine makes a call to FilterKeys_TurnOn/Off so the realstates
; can be updated to match the computer. Upon exit the flag that was set by
; Dialog box is cleared.(returned to false)
FilterKeys_dialog proc
assume DS:_TEXT
cmp fFilterKeysOn,true ; was FilterKeys turned on
jne Fd_25
call FilterKeys_TurnOn_5 ; yes it was a 1, so turn on
jmp short Fd_50
Fd_25:
call FilterKeys_TurnOff_5 ; fFilterKeysOn was false, so turn off
Fd_50:
mov fDialog_Filter_off,false ; reset flag to false
ret
FilterKeys_dialog endp
;----------------------------------------------------------------------------
filter_begin:
push ds ; save the world away
push es
push di
push si
push dx
push cx
push bx
push ax
;----------------------------------------------------------------------------
; first thing to do is to check for the right shift key or other modifier key
; (shift, control, and alternate keys) and keep track of the real
; states. This is needed by the timer routine to determine if the
; fFilterKeysOn is being manually toggled on and off and by
; the next routine in line, StickeyKeys.
mov bx,ax ; save copy in bx
mov current_shift,0 ; assume not a shift key
and al,not break_bit ; get make scan code in al
mov cx,shift_tbl_len ; search for a modifier key
mov di,offset shift_tbl ; when done, cl will hold modifier
cld ; count to get modifier flag
repne scasw ; ne=not found e=found
jne FK_30 ; not a modifier (shift, ctrl, alt) key -->
mov al,1
shl al,cl ; get modifier key flag
mov current_shift,al ; set current modifier to flag
;----------------------------------------------------------------------------
;
; Now set real states
;
mov ah,real_states ; get real current state
test bl,break_bit ; is it a break of a shift?
jz FK_10 ; no -->
not al ; yes, clear flag
and ah,al
jmp short FK_20
FK_10:
or ah,al ; set flag
FK_20:
mov real_states,ah ; save
cmp bl,RShift ; is it a make of the right shift key ?
jne FK_32 ; if not, jump around hot key setting
;----------------------------------------------------------------------------
;
; Now see if only the turn on hot key is down
; changed hot key to carriage return key to match T-TAM
;
FK_25:
; not sure if I need this next test any more either
test ah,fNotToggles ; any ctl, alt keys down?
jnz FK_30 ; yes -->
mov hot_key_only?,true ; no, then set hot_key_only to true
jmp short FK_100
FK_30:
mov fshift_click,false ; reset fshift_click flag for any non modifier keys
FK_32:
mov hot_key_only?,false
;----------------------------------------------------------------------------
; We now start the logic for the Filter features
;
FK_100:
mov ax,bx ; restore extended scan
and bl,not break_bit ; get make in bl
cmp fFilterKeysOn,false ; are we to filter?
jne FK_105 ; yes, cont on
jmp FK_800 ; no -->pass around
FK_105:
test al,break_bit ; is it a break?
jz FK_200 ; no, it is a make -->
;----------------------------------------------------------------------------
; BREAK CODE HANDLING
;----------------------------------------------------------------------------
; must let all break keys go through immediately since they are only sent
; once. Check to see if break of current down key. To be true to the
; function of FilterKeys, we should only let the break codes get passed
; on through if a make of the same code has been sent. However, due to
; n-key roll over and single keys which send multiple makes and breaks, this
; is a complicated (i.e. more lines of code) to check for.
mov fshift_click,false ; reset fshift_click flag for any non modifier keys
cmp previous_code,bx ; break of previous make?
je FK_110 ; yes, cont. on
jmp FK_800 ; no -->pass around
FK_110:
cmp fRecovery_On,true ; is RecoveryKeys On ?
jne FK_130
mov bx,on_recovery_ticks ; if it did time out, load or reeload counter
mov tick_count,bx
mov repeating?,false ; fake out FilterKeys timer, it will think it's doing acceptance delay
mov frecovery_timing,true ; set to true because we are going to pass this key press on
FK_130:
mov previous_code,0 ; yes clear previous code
mov repeating?,false ; reset flag
jmp FK_800 ; pass key on -->
;----------------------------------------------------------------------------
; MAKE CODE HANDLING
;----------------------------------------------------------------------------
; Must make exception for fake keys that are only ever sent once since they
; are part of a sequence of keystrokes. These keys are the left shift key
; that is preceded by E0 (e02ah or e0aah), or the left ctrl that is preceded
; by E1 (e11dh or e19dh).
FK_200:
cmp ax,0e02ah ; left shift make (keys 75-89)
je FK_230 ; yes, pass on -->
FK_210:
cmp ax,0e036h ; right shift make (keys 75-89)
je FK_230 ; yes, pass on -->
FK_220:
cmp ax,0e11dh ; key 126 PAUSE ?
je FK_230 ; yes, pass on -->
;----------------------------------------------------------------------------
; Check for the special sequence caused by the key 126 (Pause). The keyboard
; sends this sequence straight as shown. It does not wait to the actual
; release of the key to send the up codes sequence. So we need to pass on
; the down stroke right away. The up strokes will get sent right away since
; they are break keys.
;
; e0 46 e0 c6 or (e1 1d) 45 (e1 9d) c5
cmp ax,0e046h ; is it the pause key?
je FK_230 ; yes, send on -->
cmp previous_code,0e11dh ; previous one a 0e1dh ?
jne FK_300 ; no, go on -->
cmp al,45h ; is current key a 45h?
jne FK_300 ; yes, then pass on -->
FK_230:
jmp FK_800
;----------------------------------------------------------------------------
; we will always inhibit a code that is identical to previous one since
; the initial key and repeat will always be done via the timer routine since
; this gives better resolution then depending on the keyboard.
;
FK_300:
cmp ax,previous_code ; equal to previous code?
; previous code set to 0 on a break
jne FK_300A
jmp filter_ret ; bypass all typematic makes of a key
;-----------------------------------------------------------------------------
; Check if RecoveryKeys is On, if it is On, we will not pass a key along (make code)
; if that key is determined to be the same as the previous key (check prior key), and the
; on_recovery_ticks counter has not elapsed. If the on_recovery_ticks counter has elapsed,
; we will pass the make code along, and reset the frecovery_timing variable
FK_300A:
cmp fRecovery_On,true ; check if RecoveryKeys is On ?
; jne FK_300B ; if not, cont here
jne FK_306 ; if not, cont here
mov bx,prior_code ; check make code against pre-previous code
cmp ax,bx ; same key after a tremor
; je FK_300B ; yes, allow recovery_timing to elapse
je FK_306 ; yes, allow recovery_timing to elapse
; If not the same as the prior code, elapse frecovery_timing flag
mov frecovery_timing,false ; if user targetted a new key, reset this counter
;------------------------------------------------------------------------------
; Now determine if we should send the key on right away, and what value to set
; the tick_count, but first make sure that if fUser_SetUp_Option is set or checked,that we
; keep the settings for each. i.e. Don't allow thses settings to change unless operator
; leaves the User_SetUp_Option mode
;******************
; REMOVE DUE TO REMOVAL FROM DIALOG BOX
;******************
;;
;;
;;FK_300B:
;; cmp fUser_SetUp_Option1,true ; if set reset on_wait_ticks and on_delay_ticks
;; je FK_302
;; cmp fUser_SetUp_Option2,true ; if set reset on_wait_ticks and on_delay_ticks
;; je FK_304
;; jmp short FK_306 ; not equal to either User SetUp Option
;;
;;FK_302:
;; mov on_wait_ticks,0 ; in User_SetUp_Option1, the is no acceptance delay
;; mov on_delay_ticks,32760 ; put on_delay_ticks at maximum, i.e. do repeat keys
;; jmp short FK_306 ; cont. on
;;FK_304:
;; mov on_wait_ticks,max_dflt_wait_cnt ; put at maximum
;; mov on_delay_ticks,32760 ; put on_delay_ticks at maximum, i.e. do repeat keys
FK_306:
mov bx,on_wait_ticks ; reset count
FK_310:
; Now test to see if we have an acceptance delay time
or bx,bx ; any wait tick value?
jz FK_318
; Yes, have Acceptance delay time. Let timer routine pass the initial make
; as well as the repeats.
; Added call to Click for whenever SlowKeys is on with an acceptance delay.
cmp fclick_on,true ; is click sound turned on
jne FK_315 ; no, jump around
call click ; audible feedback that SlowKeys is on
FK_315:
mov tick_count,bx ; yes, just set count
mov repeating?,false ; not repeating yet
mov previous_code,ax ; no, update previous code to new one
jmp short filter_ret ; let timer send on the key
; No, we do not have an acceptance delay time. Pass current make right now
; and let timer do the repeats. But also check for RecoveryKeys since we do not
; have any acceptance delay
FK_318:
cmp fRecovery_On,true ; check if RecoveryKeys is On ?
jne FK_320 ; if not, cont here
cmp frecovery_timing,true ; if RecoveryKeys is On, has an earlier count timed out ?
jne FK_318A ; if yes, start a new count
mov bx,on_recovery_ticks ; if it did not time out, reeload counter again
mov tick_count,bx
mov previous_code,ax ; save as previous code
mov prior_code,ax ; save code previous to
jmp short filter_ret
FK_318A:
mov bx,on_recovery_ticks ; if it did time out, load or reeload counter
mov tick_count,bx
mov repeating?,false ; fake out FilterKeys timer, it will think it's doing acceptance delay
mov frecovery_timing,true ; set to true because we are going to pass this key press on
cmp fclick_on,true ; is click sound turned on
jne FK_319 ; no, jump around
call click ; click if flag set
FK_319:
jmp short FK_700
FK_320:
mov bx,on_delay_ticks ; get on_delay_ticks
mov tick_count,bx ; set count
mov repeating?,true ; repeating after this count
;----------------------------------------------------------------------------
; pass on the extended scan code in AX, but save as previous code if needed.
FK_700:
mov previous_code,ax ; save as previous code
mov prior_code,ax ; save code previous to previous code
; We do not expect any registers to be saved upon return from SticKeys
FK_800:
call SticKeys ; pass on actual code
filter_ret:
pop ax ; restore the world
pop bx
pop cx
pop dx
pop si
pop di
pop es
pop ds
ret
FilterKeys endp
_TEXT ends
end
|
db DEX_PINSIR ; pokedex id
db 65, 125, 100, 85, 55
; hp atk def spd spc
db BUG, BUG ; type
db 45 ; catch rate
db 200 ; base exp
INCBIN "gfx/pokemon/front/pinsir.pic", 0, 1 ; sprite dimensions
dw PinsirPicFront, PinsirPicBack
db VICEGRIP, NO_MOVE, NO_MOVE, NO_MOVE ; level 1 learnset
db GROWTH_SLOW ; growth rate
; tm/hm learnset
tmhm SWORDS_DANCE, TOXIC, BODY_SLAM, TAKE_DOWN, DOUBLE_EDGE, \
HYPER_BEAM, SUBMISSION, SEISMIC_TOSS, RAGE, MIMIC, \
DOUBLE_TEAM, BIDE, REST, SUBSTITUTE, CUT, \
STRENGTH
; end
db 0 ; padding
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r12
push %r9
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_UC_ht+0xd36c, %r10
nop
nop
nop
nop
nop
and %r9, %r9
movb $0x61, (%r10)
nop
nop
nop
nop
nop
dec %rcx
lea addresses_WC_ht+0x822c, %rdx
nop
nop
nop
nop
xor %r12, %r12
mov $0x6162636465666768, %rsi
movq %rsi, %xmm1
movups %xmm1, (%rdx)
and $52648, %rcx
lea addresses_D_ht+0x21dc, %r10
nop
nop
nop
nop
inc %rdi
movups (%r10), %xmm2
vpextrq $1, %xmm2, %rsi
nop
nop
sub %r9, %r9
lea addresses_UC_ht+0x1a5ac, %r9
nop
nop
nop
nop
nop
add %r10, %r10
movb (%r9), %cl
nop
nop
nop
nop
nop
and %r10, %r10
lea addresses_A_ht+0x1d96c, %rsi
lea addresses_D_ht+0x6c5c, %rdi
nop
nop
nop
nop
nop
add $38549, %rax
mov $111, %rcx
rep movsw
nop
nop
nop
nop
nop
and %rdx, %rdx
lea addresses_WC_ht+0x7c6c, %rsi
lea addresses_normal_ht+0x1c838, %rdi
nop
xor $54390, %rax
mov $80, %rcx
rep movsl
nop
nop
nop
nop
sub $36055, %r12
lea addresses_D_ht+0xfac4, %rsi
lea addresses_normal_ht+0x18c95, %rdi
and $56051, %r9
mov $5, %rcx
rep movsb
nop
nop
nop
sub %rsi, %rsi
lea addresses_UC_ht+0x13a28, %rax
nop
sub %rcx, %rcx
movb (%rax), %r12b
nop
and %r10, %r10
lea addresses_A_ht+0x1b40c, %r12
sub $47467, %rdx
mov $0x6162636465666768, %r10
movq %r10, %xmm5
and $0xffffffffffffffc0, %r12
movaps %xmm5, (%r12)
nop
nop
nop
nop
xor $11503, %rcx
lea addresses_UC_ht+0xa65d, %rax
nop
nop
nop
nop
nop
and $36052, %rdi
mov (%rax), %r10
xor %rdx, %rdx
lea addresses_A_ht+0xf7ac, %rsi
lea addresses_A_ht+0x1eac, %rdi
clflush (%rsi)
nop
nop
nop
nop
sub $64494, %r12
mov $32, %rcx
rep movsw
nop
nop
dec %r12
lea addresses_WT_ht+0xf46c, %rdi
nop
nop
nop
add %rdx, %rdx
mov $0x6162636465666768, %rcx
movq %rcx, %xmm0
and $0xffffffffffffffc0, %rdi
vmovaps %ymm0, (%rdi)
nop
nop
nop
nop
sub $65349, %rdx
lea addresses_D_ht+0x442c, %rsi
lea addresses_D_ht+0xa56c, %rdi
nop
nop
cmp %r9, %r9
mov $89, %rcx
rep movsb
nop
xor $46255, %r9
lea addresses_WC_ht+0x1ec1c, %rdx
and %rcx, %rcx
movb $0x61, (%rdx)
nop
nop
nop
nop
nop
xor %rax, %rax
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r9
pop %r12
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %rbx
push %rcx
push %rdx
// Faulty Load
lea addresses_normal+0xdc6c, %rbx
nop
nop
add $20178, %rcx
movb (%rbx), %r11b
lea oracles, %rdx
and $0xff, %r11
shlq $12, %r11
mov (%rdx,%r11,1), %r11
pop %rdx
pop %rcx
pop %rbx
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 0, 'same': False, 'type': 'addresses_normal'}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 0, 'same': True, 'type': 'addresses_normal'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'dst': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 5, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'STOR'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 5, 'same': True, 'type': 'addresses_WC_ht'}, 'OP': 'STOR'}
{'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 3, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'}
{'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 5, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 7, 'same': False, 'type': 'addresses_A_ht'}, 'dst': {'congruent': 3, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'REPM'}
{'src': {'congruent': 9, 'same': False, 'type': 'addresses_WC_ht'}, 'dst': {'congruent': 0, 'same': True, 'type': 'addresses_normal_ht'}, 'OP': 'REPM'}
{'src': {'congruent': 3, 'same': False, 'type': 'addresses_D_ht'}, 'dst': {'congruent': 0, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'REPM'}
{'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 2, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': True, 'size': 16, 'congruent': 5, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'STOR'}
{'src': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 0, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 2, 'same': False, 'type': 'addresses_A_ht'}, 'dst': {'congruent': 6, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'REPM'}
{'dst': {'NT': False, 'AVXalign': True, 'size': 32, 'congruent': 10, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'STOR'}
{'src': {'congruent': 6, 'same': False, 'type': 'addresses_D_ht'}, 'dst': {'congruent': 8, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'REPM'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 4, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'STOR'}
{'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
*/
|
; char *_memlwr__callee(void *p, size_t n)
SECTION code_string
PUBLIC __memlwr__callee
EXTERN asm__memlwr
__memlwr_:
pop af
pop hl
pop bc
push af
jp asm__memlwr
|
/* ========================================
* File Name : C.cpp
* Creation Date : 19-03-2021
* Last Modified : Fri 19 Mar 2021 09:43:57 PM CET
* Created By : Karel Ha <mathemage@gmail.com>
* URL : https://atcoder.jp/contests/abc193/tasks/abc193_c
* Points/Time :
* 33m40s
* +
*
* Total/ETA :
* Status :
==========================================*/
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ALL(A) (A).begin(), (A).end()
#define REVALL(A) (A).rbegin(), (A).rend()
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MTP make_tuple
#define MINUPDATE(A,B) A = min((A), (B));
#define MAXUPDATE(A,B) A = max((A), (B));
#define SGN(X) ((X) ? ( (X)>0?1:-1 ) : 0)
#define CONTAINS(S,E) ((S).find(E) != (S).end())
#define SZ(x) ((int) (x).size())
#ifdef ONLINE_JUDGE
#undef MATHEMAGE_DEBUG
#endif
#ifdef MATHEMAGE_DEBUG
#define MSG(a) cerr << "> " << (#a) << ": " << (a) << endl;
#define MSG_VEC(v) print_vector((v), (#v));
#define MSG_VEC_PAIRS(v) print_vector_pairs((v), (#v));
#define LINESEP1 cerr << "----------------------------------------------- " << endl;
#define LINESEP2 cerr << "_________________________________________________________________" << endl;
#else
#define MSG(a)
#define MSG_VEC(v)
#define MSG_VEC_PAIRS(v)
#define LINESEP1
#define LINESEP2
#endif
template<typename T>
void print_vector(const vector<T> & vec, const string & name) {
cerr << "> " << name << ": ";
for (const auto & x: vec) cerr << x << " ";
cerr << endl;
}
template<typename T1, typename T2>
void print_vector_pairs(const vector<pair<T1, T2>> & vec, const string & name) {
cerr << "> " << name << ": ";
for (const auto & x: vec) cerr << "(" << x.F << ", " << x.S << ")\t";
cerr << endl;
}
template<typename T>
inline bool bounded(const T & x, const T & u, const T & l=0) {
return min(l,u)<=x && x<max(l,u);
}
const int CLEAN = -1;
const int UNDEF = -42;
const long long MOD = 1000000007;
const int INF = INT_MAX;
const long long INF_LL = LLONG_MAX;
const long long INF_ULL = ULLONG_MAX;
const vector<int> DX4 = { 0, 0, -1, 1};
const vector<int> DY4 = {-1, 1, 0, 0};
const vector<pair<int,int>> DXY4 = { {0,-1}, {0,1}, {-1,0}, {1,0} };
const vector<int> DX8 = {-1, -1, -1, 0, 0, 1, 1, 1};
const vector<int> DY8 = {-1, 0, 1, -1, 1, -1, 0, 1};
const vector<pair<int,int>> DXY8 = {
{-1,-1}, {-1,0}, {-1,1},
{ 0,-1}, { 0,1},
{ 1,-1}, { 1,0}, { 1,1}
};
vector<long long> sieve(long long maxN) {
vector<bool> isPrime(maxN+1,true);
vector<long long> primes={2};
long long n;
for (n = 3; n*n <= maxN; n += 2) {
// MSG(n);
if (isPrime[n]) {
primes.PB(n);
for (long long k = n*n; k <= maxN; k += n) {
// MSG(k);
isPrime[k]=false;
}
}
// LINESEP1;
}
while (n<=maxN) {
// MSG(n);
if (isPrime[n]) primes.PB(n);
n+=2;
}
return primes;
}
void solve() {
long long n;
cin >> n;
vector<long long> primes = sieve(1e5+10);
MSG(primes.size());
long long result = 0LL;
for (auto & p: primes) {
if (p*p > n) {
break;
}
int k=p*p;
while (k<=n) {
result++;
k*=p;
}
}
cout << n-result << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// MSG_VEC(sieve(52));
// MSG_VEC(sieve(53));
// MSG_VEC(sieve(54));
// MSG_VEC(sieve(100));
// MSG_VEC(sieve(1000));
int cases = 1;
while (cases--) {
solve();
LINESEP2;
}
return 0;
}
|
; int vsprintf(char *s, const char *format, void *arg)
SECTION code_stdio
PUBLIC _vsprintf
EXTERN asm_vsprintf
_vsprintf:
pop af
exx
pop de
exx
pop de
pop bc
push bc
push de
push de
push af
jp asm_vsprintf
|
SECTION code_clib
SECTION code_fp_math48
PUBLIC ___fs2uchar
EXTERN cm48_sdcciyp_ds2uchar
defc ___fs2uchar = cm48_sdcciyp_ds2uchar
|
; div 除法指令
; 1、除数:分为8位和16位,在一个reg或者内存单元中
; 2、被除数:默认放在AX或DX和AX中,如果除数是8位那么被除数
; 则放在AX中,如果除数是16位,那么被除数的高16位放在DX中,低
; 16位则放在AX中
; 结果:如果除数是8位,那么AL中存放商,AH中存放余数,如果除数
; 是16位,那么AX中存放商,DX中存放余数。
assume cs:code
code segment
start:
; 计算100001 / 100 ,100001大于65535,所以必须存放在32位中
; 100001 = 186A1H, 所以需要DX存放1,AX存放86A1H
; 所以除数使用16位寄存器
mov dx, 1H
mov ax, 86A1H
mov bx, 100
div bx
; 计算 1001 / 100 ,因为 1001 16位寄存器完全可以处理
; 所以除数100只需要放在 8 位寄存器即可
mov ax, 1001
mov bl, 100
div bl
mov ax, 4c00H
int 21H
code ends
end start |
; A313894: Coordination sequence Gal.5.133.2 where G.u.t.v denotes the coordination sequence for a vertex of type v in tiling number t in the Galebach list of u-uniform tilings.
; 1,5,10,16,21,27,32,38,43,48,53,58,64,69,75,80,86,91,96,101,106,112,117,123,128,134,139,144,149,154,160,165,171,176,182,187,192,197,202,208,213,219,224,230,235,240,245,250,256,261
mov $11,$0
mov $13,$0
add $13,1
mov $14,$0
lpb $13
clr $0,11
mov $0,$11
sub $13,1
sub $0,$13
mul $0,2
mov $3,$0
add $8,$0
add $1,$8
add $3,1
add $3,$0
mov $0,$3
mov $5,1
sub $7,7
sub $5,$7
mov $9,$1
mov $1,1
add $1,$8
sub $3,1
mul $3,5
sub $5,$7
mul $5,$9
sub $5,$9
add $1,$5
mov $5,4
mov $6,$3
add $3,2
mul $6,$8
mov $7,2
lpb $0
mov $3,$7
add $5,2
mov $0,$5
div $6,$1
mul $3,$6
lpe
gcd $3,$5
add $4,$0
add $4,5
add $3,$4
mov $1,$3
sub $1,7
div $1,3
add $1,1
add $12,$1
lpe
mov $1,$12
mov $16,$14
mul $16,2
add $1,$16
|
; A088633: P-n where P = smallest prime > 2n.
; 2,2,3,4,7,6,7,10,9,10,13,12,17,16,15,16,21,20,19,22,21,22,25,24,29,28,27,32,31,30,31,36,35,34,37,36,37,42,41,40,43,42,47,46,45,52,51,50,49,52,51,52,55,54,55,58,57,70,69,68,67,66,65,64,67,66,71,70,69,70,79,78,77,76
mov $1,1
add $1,$0
mov $0,$1
sub $0,1
cal $0,60264 ; First prime after 2n.
sub $0,$1
mov $1,$0
add $1,1
|
/*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include "itkVersion.h"
#include "itkImage.h"
#include <list>
#define CHECK_FOR_VALUE(a,b) \
{ \
if( a != b ) \
{ \
std::cerr << "Error in "#a << " expected " << b << " but got " << a << std::endl; \
return EXIT_FAILURE; \
} \
}
template<class TPixel, unsigned int VImageDimension=2>
class TestImage : public itk::Image< TPixel, VImageDimension >
{
public:
/** Standard class typedefs. */
typedef TestImage Self;
typedef itk::Image< TPixel, VImageDimension > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(TestImage);
/** Run-time type information (and related methods). */
itkTypeMacro(TestImage, Image);
// Methods from itkObject
virtual ~TestImage()
{
}
TestImage()
{
}
private:
TestImage(const TestImage&);
void operator=(const TestImage&);
};
template<class TPixel, unsigned int VImageDimension=3>
class TestImage2 : public itk::Image< TPixel, VImageDimension >
{
public:
/** Standard class typedefs. */
typedef TestImage2 Self;
typedef itk::Image< TPixel, VImageDimension > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(TestImage2);
/** Run-time type information (and related methods). */
itkTypeMacro(TestImage2, Image);
// Methods from itkObject
virtual ~TestImage2()
{
}
TestImage2()
{
}
private:
TestImage2(const TestImage2&);
void operator=(const TestImage2&);
};
class TestFactory : public itk::ObjectFactoryBase
{
public:
typedef TestFactory Self;
typedef itk::ObjectFactoryBase Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Class methods used to interface with the registered factories. */
virtual const char* GetITKSourceVersion() const { return ITK_SOURCE_VERSION; }
const char* GetDescription() const { return "A Test Factory"; }
/** Method for class instantiation. */
itkFactorylessNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(TestFactory, itk::ObjectFactoryBase);
/** Register one factory of this type */
static void RegisterOneFactory(void)
{
TestFactory::Pointer factory = TestFactory::New();
itk::ObjectFactoryBase::RegisterFactory(factory);
}
private:
TestFactory(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
TestFactory()
{
this->RegisterOverride(typeid(itk::Image<short,2>).name(),
typeid(TestImage<short,2>).name(),
"Test image factory override",
true,
itk::CreateObjectFunction<TestImage<short,2> >::New());
this->RegisterOverride(typeid(itk::Image<short,2>).name(),
typeid(TestImage2<short,2>).name(),
"Test image factory override 2",
false,
itk::CreateObjectFunction<TestImage2<short,2> >::New());
}
};
typedef itk::Image<short,2>::Pointer myPointer;
bool TestNewImage(myPointer v, const char* expectedClassName)
{
std::cout << "v->GetNameOfClass(): " << v->GetNameOfClass();
std::cout << ", expectedClassName: " << expectedClassName << std::endl;
if(strcmp(v->GetNameOfClass(), expectedClassName) != 0)
{
std::cout << "Test Failed" << std::endl;
return false;
}
return true;
}
int itkObjectFactoryTest(int, char *[])
{
TestFactory::Pointer factory = TestFactory::New();
itk::ObjectFactoryBase::RegisterFactory(factory);
// List all registered factories
std::list<itk::ObjectFactoryBase *> factories =
itk::ObjectFactoryBase::GetRegisteredFactories();
std::cout << "----- Registered factories -----" << std::endl;
for ( std::list<itk::ObjectFactoryBase*>::iterator
f = factories.begin();
f != factories.end(); ++f )
{
std::cout << " Factory version: "
<< (*f)->GetITKSourceVersion() << std::endl
<< " Factory description: "
<< (*f)->GetDescription() << std::endl;
std::list<std::string> overrides = (*f)->GetClassOverrideNames();
std::list<std::string> names = (*f)->GetClassOverrideWithNames();
std::list<std::string> descriptions = (*f)->GetClassOverrideDescriptions();
std::list<bool> enableflags = (*f)->GetEnableFlags();
std::list<std::string>::const_iterator n = names.begin();
std::list<std::string>::const_iterator d = descriptions.begin();
std::list<bool>::const_iterator e = enableflags.begin();
for ( std::list<std::string>::const_iterator o = overrides.begin();
o != overrides.end(); ++o, ++n, ++d, e++ )
{
std::cout << " Override " << *o
<< " with " << *n << std::endl
<< " described as \"" << *d << "\"" << std::endl
<< " enabled " << *e << std::endl;
}
}
std::cout << "----- -----" << std::endl;
itk::Image<short,2>::Pointer v = itk::Image<short,2>::New();
factory->Print(std::cout);
int status = EXIT_SUCCESS;
if (!TestNewImage(v, "TestImage"))
{
status = EXIT_FAILURE;
}
// disable all itk::Image creation with the
factory->Disable(typeid(itk::Image<short,2>).name());
v = itk::Image<short,2>::New();
if (!TestNewImage(v, "Image"))
{
status = EXIT_FAILURE;
}
factory->SetEnableFlag(true,
typeid(itk::Image<short,2>).name(),
typeid(TestImage2<short,2>).name());
std::cout << typeid(itk::Image<short,2>).name()
<< " overridden by "
<< typeid(TestImage2<short,2>).name() << std::endl
<< " EnableFlag is "
<< factory->GetEnableFlag(
typeid(itk::Image<short,2>).name(),
typeid(TestImage2<short,2>).name()) << std::endl;
v = itk::Image<short,2>::New();
if (!TestNewImage(v, "TestImage2"))
{
status = EXIT_FAILURE;
}
factory->SetEnableFlag(false,
typeid(itk::Image<short,2>).name(),
typeid(TestImage2<short,2>).name());
factory->SetEnableFlag(true,
typeid(itk::Image<short,2>).name(),
typeid(TestImage<short,2>).name());
v = itk::Image<short,2>::New();
if (!TestNewImage(v, "TestImage"))
{
status = EXIT_FAILURE;
}
itk::ObjectFactoryBase::UnRegisterFactory(factory);
v = itk::Image<short,2>::New();
if (!TestNewImage(v, "Image"))
{
status = EXIT_FAILURE;
}
TestFactory::RegisterOneFactory();
v = itk::Image<short,2>::New();
if (!TestNewImage(v, "TestImage"))
{
status = EXIT_FAILURE;
}
itk::ObjectFactoryBase::SetStrictVersionChecking( false );
CHECK_FOR_VALUE( itk::ObjectFactoryBase::GetStrictVersionChecking() , false );
itk::ObjectFactoryBase::SetStrictVersionChecking( true );
CHECK_FOR_VALUE( itk::ObjectFactoryBase::GetStrictVersionChecking() , true );
itk::ObjectFactoryBase::StrictVersionCheckingOff();
CHECK_FOR_VALUE( itk::ObjectFactoryBase::GetStrictVersionChecking() , false );
itk::ObjectFactoryBase::StrictVersionCheckingOn();
CHECK_FOR_VALUE( itk::ObjectFactoryBase::GetStrictVersionChecking() , true );
return status;
}
|
Ghost1DRAW_GLYPH:
//MAKE ARI LOCATION ADDRESS IN r2
//ARI GHOST IS IN 12800
//LUI 200 AND ORI 0
LUI 200 r2
ORI 0 r2
//MAKE GHOST STATE ADDRESS IN r3
LUI 51 r3
ORI 145 r3
//load location of pacman INTO r0
LOAD r0 r2
//CHECK IF STATE UP0
drawUP0:
load r5 r3
CMPI 16 r5
BNE drawUP1 //else check if in state UP1
//check the condition of the mouth
//if open
CMPI 1 R4
BNE CLOSED_STATE_UP0
LUI 1 r1 //load PACMAN_OPEN_UP_0
ORI 8 r1
STOR r1 r0
ADDI -53 r0 //get location below pacman
MOVI 0 r1 //LOAD BLANK
STOR r1 r0
RETX
CLOSED_STATE_UP0:
LUI 0 r1 //load PACMAN_CLOSED_UP_0
ORI 212 r1
STOR r1 r0
ADDI -53 r0 //get location below pacman
MOVI 0 r1 //LOAD BLANK
STOR r1 r0
RETX
//CHECK IF STATE UP1
drawUP1:
LOAD R5 R3
CMPI 17 r5
BNE drawUP2 //else check if in state UP2
//CHECK CONDITION OF MOUTH
//IF OPEN
CMPI 1 R4
BNE CLOSED_STATE_UP1
//GET PACMAN_OPEN_6...GLYPH NUM 270
MOVI 255 r1
ADDI 15 R1 //R1 SHOULD BE 270 NOW
STOR R1 R0 //LOAD GLYPH INTO POSITION
ADDI 53 R0 // GET POSITION ABOVE PACMAN
//NOW NEED TO LOAD PACMAN_OPEN_UP5
//IT IS GLPYH NUM 269
MOVI 255 R1
ADDI 14 R1
STOR r1 r0 //STORE POSITION ABOVE PACMAN
RETX
CLOSED_STATE_UP1:
//LOAD PACMAN_CLOSED_UP6
//IT'S GLYPH 218
MOVI 218 R1
STOR R1 R0 //LOAD INTO POSITION
ADDI 53 R0 // GET POSITION ABOVE PACMAN //fixed this, was negative, needed positive
//NOW NEED TO LOAD PMANCLOSED_UP_5
//IT'S GLYPH 217
MOVI 217 R1
STOR R1 R0 //LOAD INTO POSITION
RETX
//CHECK IF STATE UP2
drawUP2:
LOAD R5 R3
CMPI 18 r5
BNE drawUP3 //else check if in state UP3
//CHECK CONDITION OF MOUTH
//IF OPEN
CMPI 1 R4
BNE CLOSED_STATE_UP2
//GET PMANOPEN_UP_4
//THIS IS GLYPH 268
MOVI 255 r1
ADDI 13 R1 //R1 SHOULD BE 268 NOW
STOR R1 R0 //LOAD INTO POSITION
ADDI 53 R0 // GET POSITION ABOVE PACMAN
//NOW NEED TO LOAD PMANOPEN_Up_3
//ITS IN LOCATION 267
MOVI 255 R1
ADDI 12 R1
STOR r1 r0 //STORE POSITION ABOVE PACMAN
RETX
CLOSED_STATE_UP2:
//LOAD PMANCLOSED_Up_4 //are these right?
//IT'S GLYPH 216
MOVI 216 R1
STOR R1 R0 //LOAD INTO POSITION
ADDI 53 R0 // GET POSITION ABOVE PACMAN
//NOW NEED TO LOAD PMANCLOSED_Up_3
//IT'S GLYPH 215
MOVI 215 R1 ///wait what?
STOR R1 R0 //LOAD INTO POSITION
RETX
//CHECK IF STATE UP3
drawUP3:
LOAD R5 R3
CMPI 19 r5
BNE drawDOWN0 //else check if in state drawDOWN0
//CHECK CONDITION OF MOUTH
//IF OPEN
CMPI 1 R4
BNE CLOSED_STATE_UP3
//GET PMANOPEN_Up_1
//THIS IS GLYPH 265
MOVI 255 r1
ADDI 10 R1 //R1 SHOULD BE 265 NOW
STOR R1 R0 //LOAD POSITION
ADDI -53 R0 // GET POSITION BELOW PACMAN
//NOW NEED TO PMANOPEN_Up_2
//ITS IN LOCATION 266
MOVI 255 R1
ADDI 11 R1 //R1 SHOULD BE 266
STOR r1 r0 //STORE POSITION BELOW PACMAN
RETX
CLOSED_STATE_UP3:
//LOAD PMANCLOSED_Up_1
//IT'S GLYPH 213
MOVI 213 R1 //wait what?
STOR R1 R0 //LOAD INTO POSITION
ADDI -53 R0 // GET POSITION BELOW PACMAN
//NOW NEED TO LOAD PMANCLOSED_Up_2
//IT'S GLYPH 266
MOVI 255 r1
ADDI 11 r1 //R1 should be 266
STOR r1 r0 //STORE POSITION BELOW PACMAN
RETX
//COPY AND PASTING FROM STATE 1
//CHECK IF STATE DOWN0
drawDOWN0:
LOAD R5 R3
CMPI 32 r5
BNE drawDOWN1 //else check if in state UP1
//check the condition of the mouth
//if open
CMPI 1 R4
BNE CLOSED_STATE_DOWN0
//load PMANOPEN_DOWN_0
//GLYPH 219
MOVI 219 R1
STOR r1 r0
ADDI 53 r0 //get location ABOVE pacman
MOVI 0 r1 //LOAD BLANK
STOR r1 r0
RETX
CLOSED_STATE_DOWN0:
LUI 0 r1 //load PMANCLOSED_DOWN_0
// GLYPH 179
MOVI 179 R1
STOR r1 r0
ADDI 53 r0 //get location ABOVE pacman
MOVI 0 r1 //LOAD BLANK
STOR r1 r0
RETX
//CHECK IF STATE DOWN1
drawDOWN1:
LOAD R5 R3
CMPI 33 r5
BNE drawDOWN2 //else check if in state DOWN2
//CHECK CONDITION OF MOUTH
//IF OPEN
CMPI 1 R4
BNE CLOSED_STATE_DOWN1
//GET PMANOPEN_Down_1...in GLYPH 220
MOVI 220 r1
STOR R1 R0 //LOAD POSITION
ADDI -53 R0 // GET POSITION BELOW PACMAN
//NOW NEED TO LOAD PMANOPEN_Down_2
//ITS IN LOCATION 221
MOVI 221 R1
STOR r1 r0 //STORE POSITION BELOW PACMAN
RETX
CLOSED_STATE_DOWN1:
//LOAD PMANCLOSED_Down_1
//IT'S GLYPH 180
MOVI 180 R1
STOR R1 R0 //LOAD INTO POSITION
ADDI -53 R0 // GET POSITION BELOW PACMAN
//NOW NEED TO LOAD PMANCLOSED_Down_2
//IT'S GLYPH 181
MOVI 181 R1
STOR R1 R0 //LOAD INTO POSITION
RETX
//CHECK IF STATE DOWN2
drawDOWN2:
LOAD R5 R3
CMPI 34 r5
BNE drawDOWN3 //else check if in state DOWN2
//CHECK CONDITION OF MOUTH
//IF OPEN
CMPI 1 R4
BNE CLOSED_STATE_DOWN2
//GET PMANOPEN_DOWN_3
//THIS IS GLYPH 222
MOVI 222 r1
STOR R1 R0 //LOAD POSITION
ADDI -53 R0 // GET POSITION BELOW PACMAN
//NOW NEED TO LOAD PMANOPEN_Down_4
//ITS IN LOCATION 223
MOVI 223 R1
STOR r1 r0 //STORE POSITION ABOVE PACMAN
RETX
CLOSED_STATE_DOWN2:
//LOAD PMANCLOSED_DOWN_3
//IT'S GLYPH 182
MOVI 182 R1
STOR R1 R0 //LOAD INTO POSITION
ADDI -53 R0 // GET POSITION BELOW PACMAN
//NOW NEED TO LOAD PMANCLOSE_Down_4
//IT'S GLYPH 183
MOVI 183 R1
STOR R1 R0 //LOAD INTO POSITION
RETX
//CHECK IF STATE DOWN3
drawDOWN3:
LOAD R5 R3
CMPI 35 r5
BNE drawLEFT0 //else check if in state drawDOWN0
//CHECK CONDITION OF MOUTH
//IF OPEN
CMPI 1 R4
BNE CLOSED_STATE_DOWN3
//GET PMANOPEN_Down_6
//THIS IS GLYPH 225
MOVI 225 r1
STOR R1 R0 //LOAD POSITION
ADDI 53 R0 // GET POSITION ABOVE PACMAN
//NOW NEED TO PMANOPEN_Down_5
//ITS IN LOCATION 224
MOVI 224 R1
STOR r1 r0 //STORE POSITION ABOVE PACMAN
RETX
CLOSED_STATE_DOWN3:
//LOAD PMANCLOSED_Down_6
//IT'S GLYPH 185
MOVI 185 R1
STOR R1 R0 //LOAD INTO POSITION
ADDI 53 R0 // GET POSITION ABOVE PACMAN
//NOW NEED TO LOAD PMANOPEN_Down_5 (SAME AS PMANCLOSED)
//IT'S GLYPH 224
MOVI 224 R1 //is this right? i guess its same as pmanclosed?
STOR r1 r0 //STORE POSITION ABOVE PACMAN
RETX
// COPY AND PASTED FROM DOWN STATES
//CHECK IF STATE LEFT0
drawLEFT0:
LOAD R5 R3
CMPI 48 r5
BNE drawLEFT1 //else check if in state LEFT1
//check the condition of the mouth
//if open
CMPI 1 R4
BNE CLOSED_STATE_LEFT0
//load PMANOPEN_LEFT_0
//GLYPH 226
MOVI 226 R1
STOR r1 r0
ADDI -1 r0 //get location TO THE RIGHT
MOVI 0 r1 //LOAD BLANK
STOR r1 r0
RETX
CLOSED_STATE_LEFT0:
LUI 0 r1 //load PMANCLOSED_LEFT_0
// GLYPH 186
MOVI 186 R1
STOR r1 r0
ADDI -1 r0 //get location TO THE RIGHT
MOVI 0 r1 //LOAD BLANK
STOR r1 r0
RETX
//CHECK IF STATE LEFT1
drawLEFT1:
LOAD R5 R3
CMPI 49 r5
BNE drawLEFT2 //else check if in state LEFT2
//CHECK CONDITION OF MOUTH
//IF OPEN
CMPI 1 R4
BNE CLOSED_STATE_LEFT1
//GET PMANOPEN_Left_6...in GLYPH 232
MOVI 232 r1
STOR R1 R0 //LOAD POSITION
ADDI 1 R0 // GET POSITION TO THE LEFT OF PACMAN
//NOW NEED TO PMANOPEN_Left_5
//ITS IN LOCATION 231
MOVI 231 R1
STOR r1 r0 //STORE POSITION BELOW PACMAN
RETX
CLOSED_STATE_LEFT1:
//LOAD PMANCLOSED_Left_6
//IT'S GLYPH 192
MOVI 192 R1
STOR R1 R0 //LOAD INTO POSITION
ADDI 1 R0 // GET POSITION TO THE LEFT OF PACMAN
//NOW NEED TO LOAD PMANCLOSED_Left_5
//IT'S GLYPH 191
MOVI 191 R1
STOR R1 R0 //LOAD INTO POSITION
RETX
//CHECK IF STATE LEFT2
drawLEFT2:
LOAD R5 R3
CMPI 50 r5
BNE drawLEFT3 //else check if in state LEFT2
//CHECK CONDITION OF MOUTH
//IF OPEN
CMPI 1 R4
BNE CLOSED_STATE_LEFT2
//GET PMANOPEN_Left_4
//THIS IS GLYPH 230
MOVI 230 r1
STOR R1 R0 //LOAD POSITION
ADDI 1 R0 // GET POSITION TO THE LEFT OF PACMAN
//NOW NEED TO LOAD PMANOPEN_Left_3
//ITS IN LOCATION 229
MOVI 229 R1
STOR r1 r0 //STORE POSITION ABOVE PACMAN
RETX
CLOSED_STATE_LEFT2:
//LOAD PMANCLOSED_Left_4
//IT'S GLYPH 190
MOVI 190 R1
STOR R1 R0 //LOAD INTO POSITION
ADDI 1 R0 // GET POSITION BELOW PACMAN
//NOW NEED TO LOAD PMANCLOSED_Left_3
//IT'S GLYPH 189
MOVI 189 R1
STOR R1 R0 //LOAD INTO POSITION
RETX
//CHECK IF STATE LEFT3
drawLEFT3:
LOAD R5 R3
CMPI 51 r5
BNE drawRIGHT0 //else check if in state drawRIGHT0
//CHECK CONDITION OF MOUTH
//IF OPEN
CMPI 1 R4
BNE CLOSED_STATE_LEFT3
//GET PMANOPEN_Left_1
//THIS IS GLYPH 227
MOVI 227 r1
STOR R1 R0 //LOAD POSITION
ADDI -1 R0 // GET POSITION TO THE RIGHT OF PACMAN
//NOW NEED TO PMANOPEN_Left_2
//ITS IN LOCATION 228
MOVI 228 R1
STOR r1 r0 //STORE POSITION ABOVE PACMAN
RETX
CLOSED_STATE_LEFT3:
//LOAD PMANCLOSED_Left_1
//IT'S GLYPH 187
MOVI 187 R1
STOR R1 R0 //LOAD INTO POSITION
ADDI -1 R0 // GET POSITION TO THE RIGHT PACMAN
//NOW NEED TO LOAD PMANCLOSED_Left_2 (SAME AS PMANCLOSED)
//IT'S GLYPH 188
MOVI 188 R1
STOR r1 r0 //STORE POSITION ABOVE PACMAN
RETX
// COPY AND PASTE FROM LEFT
//CHECK IF STATE RIGHT0
drawRIGHT0:
LOAD R5 R3
CMPI 64 r5
BNE drawRIGHT1 //else check if in state RIGHT1
//check the condition of the mouth
//if open
CMPI 1 R4
BNE CLOSED_STATE_RIGHT0
//load PMANOPEN_RIGHT_0
//GLYPH 245
MOVI 245 R1
STOR r1 r0
ADDI 1 r0 //get location TO THE LEFT
MOVI 0 r1 //LOAD BLANK
STOR r1 r0
RETX
CLOSED_STATE_RIGHT0:
LUI 0 r1 //load PMANCLOSED_RIGHT_0
// GLYPH 205
MOVI 205 R1
STOR r1 r0
ADDI 1 r0 //get location TO THE LEFT
MOVI 0 r1 //LOAD BLANK
STOR r1 r0
RETX
//CHECK IF STATE RIGHT1
drawRIGHT1:
LOAD R5 R3
CMPI 65 r5
BNE drawRIGHT2 //else check if in state RIGHT2
//CHECK CONDITION OF MOUTH
//IF OPEN
CMPI 1 R4
BNE CLOSED_STATE_RIGHT1
//GET PMANOPEN_Right_1...in GLYPH 246
MOVI 246 r1
STOR R1 R0 //LOAD POSITION
ADDI -1 R0 // GET POSITION TO THE RIGHT OF PACMAN
//NOW NEED TO PMANOPEN_Right_2
//ITS IN LOCATION 247
MOVI 247 R1
STOR r1 r0 //STORE POSITION BELOW PACMAN
RETX
CLOSED_STATE_RIGHT1:
//LOAD PMANCLOSED_Right_1
//IT'S GLYPH 206
MOVI 206 R1
STOR R1 R0 //LOAD INTO POSITION
ADDI -1 R0 // GET POSITION TO THE RIGHT OF PACMAN
//NOW NEED TO LOAD PMANCLOSED_Right_2
//IT'S GLYPH 207
MOVI 207 R1
STOR R1 R0 //LOAD INTO POSITION
RETX
//CHECK IF STATE RIGHT2
drawRIGHT2:
LOAD R5 R3
CMPI 66 r5
BNE drawRIGHT3 //else check if in state RIGHT2
//CHECK CONDITION OF MOUTH
//IF OPEN
CMPI 1 R4
BNE CLOSED_STATE_RIGHT2
//GET PMANOPEN_Right_3
//THIS IS GLYPH 248
MOVI 248 r1
STOR R1 R0 //LOAD POSITION
ADDI -1 R0 // GET POSITION TO THE RIGHT OF PACMAN
//NOW NEED TO LOAD PMANOPEN_Right_4
//ITS IN LOCATION 249
MOVI 249 R1
STOR r1 r0 //STORE POSITION ABOVE PACMAN
RETX
CLOSED_STATE_RIGHT2:
//LOAD PMANCLOSED_Right_3
//IT'S GLYPH 208
MOVI 208 R1
STOR R1 R0 //LOAD INTO POSITION
ADDI -1 R0 // GET POSITION TO THE RIGHT PACMAN
//NOW NEED TO LOAD PMANCLOSED_Right_4
//IT'S GLYPH 209
MOVI 209 R1
STOR R1 R0 //LOAD INTO POSITION
RETX
//CHECK IF STATE RIGHT3
drawRIGHT3:
LOAD R5 R3
CMPI 67 r5
BNE drawDEAD1 //else check if in state drawRIGHT0
//CHECK CONDITION OF MOUTH
//IF OPEN
CMPI 1 R4
BNE CLOSED_STATE_RIGHT3
//GET PMANOPEN_Right_6
//THIS IS GLYPH 251
MOVI 251 r1
STOR R1 R0 //LOAD POSITION
ADDI 1 R0 // GET POSITION TO THE LEFT OF PACMAN
//NOW NEED TO PMANOPEN_Right_5
//ITS IN LOCATION 250
MOVI 250 R1
STOR r1 r0 //STORE POSITION ABOVE PACMAN
RETX
CLOSED_STATE_RIGHT3:
//LOAD PMANCLOSED_Right_6
//IT'S GLYPH 211
MOVI 211 R1
STOR R1 R0 //LOAD INTO POSITION
ADDI 1 R0 // GET POSITION TO THE LEFT PACMAN
//NOW NEED TO LOAD PMANCLOSED_Right_5 (SAME AS PMANCLOSED)
//IT'S GLYPH 210
MOVI 210 R1
STOR r1 r0 //STORE POSITION ABOVE PACMAN
RETX
|
; SMSQ_LANG_KBD_SETT SMSQ KBD set keyboard table 1994 Tony Tebby
xdef kbd_sett
xdef kbd_table
xdef kbd_thing
xdef kbd_tnam
xref ut_gxli1
xref ut_gxnm1
xref cv_upcas
include 'dev8_keys_err'
include 'dev8_keys_ldm'
include 'dev8_keys_sys'
include 'dev8_keys_iod'
include 'dev8_keys_qdos_sms'
include 'dev8_keys_thg'
include 'dev8_smsq_kbd_keys'
include 'dev8_mac_thg'
section exten
kbd_tnam dc.b 0,3,'KBD',$a
kbd_2olw dc.w thp.opt+thp.ulng ; optional long word
dc.w thp.opt+thp.ulng ; optional long word
dc.w 0
;+++
; This is the Thing with all the KBD extensions
;
; a1 c p parameter stack pointer
; a2 c p thing linkage block
;
;---
kbd_thing
KBDT thg_extn KBDT,,kbd_2olw
kbdt.reg reg d1/d2/d3/a0/a1/a3
movem.l kbdt.reg,-(sp)
move.l (a1),d0 ; table
lea -kb_thgl(a2),a3 ; linkage
bsr.s kbd_sett ; set table
movem.l (sp)+,kbdt.reg
rts
kbs_ipar
moveq #err.ipar,d0
bra.s kbs_rts
;+++
; KBD_TABLE lang
;---
kbd_table
jsr ut_gxli1 ; try to get an integer
bne.s kbt_car ; must be a car registration
moveq #0,d2
move.l (a6,a1.l),d1 ; is it unset (=0)
bne.s kbt_link ; ... no, set this
kbt_car
jsr ut_gxnm1 ; try to get name or string
bne.s kbs_rts
move.w (a6,a1.l),d0 ; number of characters
ble.s kbs_ipar ; ... oops
cmp.w #4,d0 ; more than 4
bhi.s kbs_ipar ; ... oops
move.l #' ',-(sp)
move.l sp,a0
kbt_copy
move.b 2(a6,a1.l),d1
jsr cv_upcas
move.b d1,(a0)+ ; an upper case character
addq.l #1,a1
subq.w #1,d0
bgt.s kbt_copy
move.l (sp)+,d2 ; car reg code
moveq #0,d1
kbt_link
moveq #sms.xtop,d0
trap #do.sms2
move.l sys_klnk(a6),a3 ; get keyboard linkage
;+++
; Sets the pointers to the appropriate keyboard table.
;
; d1 c p language number or pointer to table or 0
; d2 c p car registration code if d1=0
; d3 s
; a0 s
; a1 s
; a3 c p pointer to kbd linkage
;---
kbd_sett
move.w d1,a1
cmp.l d1,a1 ; sensible address?
beq.s kbs_loc ; ... no
move.l d1,a1
asr.w #1,d1 ; ... odd?
bcs.s kbs_ipar
bra.s kbs_puta1
kbs_loc
moveq #sms.fprm,d0
moveq #ldm.kbdt,d3
trap #do.sms2 ; look in OS lists!!
kbs_put
addq.l #2,a1 ; skip language code
kbs_puta1
move.l a1,a0
add.w (a1)+,a0
add.w (a1),a1 ; table addresses
move.l a0,kb_ktab(a3) ; keyboard table
move.l a1,kb_nstab(a3)
moveq #0,d0
kbs_rts
rts
end
|
; A022354: Fibonacci sequence beginning 0, 20.
; Submitted by Jon Maiga
; 0,20,20,40,60,100,160,260,420,680,1100,1780,2880,4660,7540,12200,19740,31940,51680,83620,135300,218920,354220,573140,927360,1500500,2427860,3928360,6356220,10284580,16640800,26925380,43566180,70491560,114057740,184549300,298607040,483156340,781763380,1264919720,2046683100,3311602820,5358285920,8669888740,14028174660,22698063400,36726238060,59424301460,96150539520,155574840980,251725380500,407300221480,659025601980,1066325823460,1725351425440,2791677248900,4517028674340,7308705923240
mov $3,1
lpb $0
sub $0,1
mov $2,$3
add $3,$1
mov $1,$2
lpe
mov $0,$1
mul $0,20
|
;
; jccolss2.asm - colorspace conversion (SSE2)
;
; x86 SIMD extension for IJG JPEG library
; Copyright (C) 1999-2006, MIYASAKA Masaru.
; Copyright (C) 2009, D. R. Commander.
; For conditions of distribution and use, see copyright notice in jsimdext.inc
;
; This file should be assembled with NASM (Netwide Assembler),
; can *not* be assembled with Microsoft's MASM or any compatible
; assembler (including Borland's Turbo Assembler).
; NASM is available from http://nasm.sourceforge.net/ or
; http://sourceforge.net/project/showfiles.php?group_id=6208
;
; [TAB8]
%include "jsimdext.inc"
; --------------------------------------------------------------------------
%define SCALEBITS 16
F_0_081 equ 5329 ; FIX(0.08131)
F_0_114 equ 7471 ; FIX(0.11400)
F_0_168 equ 11059 ; FIX(0.16874)
F_0_250 equ 16384 ; FIX(0.25000)
F_0_299 equ 19595 ; FIX(0.29900)
F_0_331 equ 21709 ; FIX(0.33126)
F_0_418 equ 27439 ; FIX(0.41869)
F_0_587 equ 38470 ; FIX(0.58700)
F_0_337 equ (F_0_587 - F_0_250) ; FIX(0.58700) - FIX(0.25000)
; --------------------------------------------------------------------------
SECTION SEG_CONST
alignz 16
global EXTN(jconst_rgb_ycc_convert_sse2) PRIVATE
EXTN(jconst_rgb_ycc_convert_sse2):
PW_F0299_F0337 times 4 dw F_0_299, F_0_337
PW_F0114_F0250 times 4 dw F_0_114, F_0_250
PW_MF016_MF033 times 4 dw -F_0_168,-F_0_331
PW_MF008_MF041 times 4 dw -F_0_081,-F_0_418
PD_ONEHALFM1_CJ times 4 dd (1 << (SCALEBITS-1)) - 1 + (CENTERJSAMPLE << SCALEBITS)
PD_ONEHALF times 4 dd (1 << (SCALEBITS-1))
alignz 16
; --------------------------------------------------------------------------
SECTION SEG_TEXT
BITS 32
%include "jcclrss2.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_RGB_RED
%define RGB_GREEN EXT_RGB_GREEN
%define RGB_BLUE EXT_RGB_BLUE
%define RGB_PIXELSIZE EXT_RGB_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgb_ycc_convert_sse2
%include "jcclrss2.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_RGBX_RED
%define RGB_GREEN EXT_RGBX_GREEN
%define RGB_BLUE EXT_RGBX_BLUE
%define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extrgbx_ycc_convert_sse2
%include "jcclrss2.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_BGR_RED
%define RGB_GREEN EXT_BGR_GREEN
%define RGB_BLUE EXT_BGR_BLUE
%define RGB_PIXELSIZE EXT_BGR_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgr_ycc_convert_sse2
%include "jcclrss2.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_BGRX_RED
%define RGB_GREEN EXT_BGRX_GREEN
%define RGB_BLUE EXT_BGRX_BLUE
%define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extbgrx_ycc_convert_sse2
%include "jcclrss2.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_XBGR_RED
%define RGB_GREEN EXT_XBGR_GREEN
%define RGB_BLUE EXT_XBGR_BLUE
%define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extxbgr_ycc_convert_sse2
%include "jcclrss2.asm"
%undef RGB_RED
%undef RGB_GREEN
%undef RGB_BLUE
%undef RGB_PIXELSIZE
%define RGB_RED EXT_XRGB_RED
%define RGB_GREEN EXT_XRGB_GREEN
%define RGB_BLUE EXT_XRGB_BLUE
%define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE
%define jsimd_rgb_ycc_convert_sse2 jsimd_extxrgb_ycc_convert_sse2
%include "jcclrss2.asm"
|
// Copyright 2017 Johan Paulsson
// This file is part of the Water C++ Library. It is licensed under the MIT License.
// See the license.txt file in this distribution or https://watercpp.com/license.txt
//\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_
#ifndef WATER_THREADS_WINDOWS_THREAD_HPP
#define WATER_THREADS_WINDOWS_THREAD_HPP
#include <water/threads/windows/bits.hpp>
#if \
defined(__MINGW32__) && \
!defined(WATER_THREADS_USE_BEGINTHREADEX) && \
!defined(WATER_THREADS_NO_BEGINTHREADEX)
#define WATER_THREADS_NO_BEGINTHREADEX
#endif
#ifndef WATER_THREADS_NO_BEGINTHREADEX
#include <process.h> // _beginthreadex
#endif
namespace water { namespace threads {
bool constexpr
priority_exists = true,
stack_size_exists = true,
qos_exists = false;
using thread_t = dword_t;
// 0 is not a valid thread id because GetThreadId(handle) returns 0 if it fails
struct join_t {
void *handle;
void* underlying() const noexcept { return handle; }
};
inline thread_t thread() noexcept {
return GetCurrentThreadId();
}
inline thread_t thread(join_t a) noexcept {
return GetThreadId(a.handle);
}
inline bool equal(thread_t a, thread_t b) noexcept {
// this exists because water::posix::threads::equal,
return a == b;
}
inline bool dont_join(join_t a) noexcept {
return CloseHandle(a.handle) != 0;
}
inline bool join(join_t a) noexcept {
___water_debug(trace() << "water::threads::join thread=" << thread(a) << " from thread=" << thread();)
if(!handle_wait(a.handle)) {
___water_debug(trace() << "water::threads::join thread=" << thread(a) << " from thread=" << thread() << " joined!";)
CloseHandle(a.handle);
return true;
}
___water_debug(trace() << "water::threads::join thread=" << thread(a) << " from thread=" << thread() << " failed!";)
return false;
}
// priority
//
// SetThreadPriority will not succeed for any priority between
// THREAD_PRIORITY_IDLE and THREAD_PRIORITY_TIME_CRITICAL
// - test it with water/threads/windows/!tests/priority.hpp
//
// when process is REALTIME_PRIORITY_CLASS:
//
// -15 THREAD_PRIORITY_IDLE
// -7 -6 -5 -4 -3
// -2 THREAD_PRIORITY_LOWEST
// -1 THREAD_PRIORITY_BELOW_NORMAL
// 0 THREAD_PRIORITY_NORMAL
// 1 THREAD_PRIORITY_ABOVE_NORMAL
// 2 THREAD_PRIORITY_HIGHEST
// 3 4 5 6
// 15 THREAD_PRIORITY_TIME_CRITICAL
//
// when process is any other class:
//
// -15 THREAD_PRIORITY_IDLE
// -2 THREAD_PRIORITY_LOWEST
// -1 THREAD_PRIORITY_BELOW_NORMAL
// 0 THREAD_PRIORITY_NORMAL
// 1 THREAD_PRIORITY_ABOVE_NORMAL
// 2 THREAD_PRIORITY_HIGHEST
// 15 THREAD_PRIORITY_TIME_CRITICAL
//
// water range is
// - realtime 1 - 16, default is 9
// - not realtime 1 - 7, default is 4
//
static_assert(thread_priority_time_critical == 15, "");
static_assert(thread_priority_normal == 0, "");
static_assert(thread_priority_idle == -15, "");
inline unsigned priority_water_from_windows(int p, unsigned max) noexcept {
if(!max || p < thread_priority_idle || thread_priority_time_critical < p)
return 0;
if(p <= (max == 16 ? -8 : -3))
return 1;
if(p >= (max == 16 ? 7 : 3))
return max;
return static_cast<unsigned>(p + (max == 16 ? 9 : 4));
}
inline int priority_windows_from_water(unsigned p, unsigned max) noexcept {
int r = numeric_limits<int>::min();
if(max && p && p <= max) {
if(p == 1)
r = thread_priority_idle;
else if(p == max)
r = thread_priority_time_critical;
else if(max == 7)
r = static_cast<int>(p) - 4;
else
r = static_cast<int>(p) - 9;
}
return r;
}
inline unsigned priority_default() noexcept {
dword_t p = GetPriorityClass(GetCurrentProcess());
return
p == realtime_priority_class ? 9 :
p ? 4 :
0;
}
inline unsigned priority_max() noexcept {
dword_t p = GetPriorityClass(GetCurrentProcess());
return
p == realtime_priority_class ? 16 :
p ? 7 :
0;
}
class priority
{
unsigned
my,
my_max;
void *myhandle;
thread_t myid;
public:
explicit priority(thread_t a = 0) noexcept :
my(0),
my_max(priority_max()),
myhandle(0),
myid(a)
{
a = thread();
if(!myid || myid == a) {
myid = a;
myhandle = GetCurrentThread();
}
else
myhandle = OpenThread(thread_query_information, 0, myid);
if(myhandle) {
my = priority_water_from_windows(GetThreadPriority(myhandle), my_max);
if(myid != a)
CloseHandle(myhandle);
}
myhandle = 0;
}
explicit priority(join_t a) noexcept :
my_max(priority_max()),
myhandle(a.handle),
myid(0)
{
my = priority_water_from_windows(GetThreadPriority(myhandle), my_max);
}
operator unsigned() const noexcept {
return my;
}
unsigned get() const noexcept {
return my;
}
unsigned max() const noexcept {
return my ? my_max : 0;
}
unsigned min() const noexcept {
return my ? 1 : 0;
}
bool set(unsigned a) noexcept {
bool r = false;
int p;
if(my && (p = priority_windows_from_water(a, my_max)) != numeric_limits<int>::min()) {
bool close = false;
void *h = myhandle;
if(myid) {
if(myid == thread())
h = GetCurrentThread();
else
close = (h = OpenThread(thread_set_information, 0, myid)) != 0;
}
if(h && SetThreadPriority(h, p)) {
r = true;
my = a;
}
if(close)
CloseHandle(h);
}
return r;
}
};
enum qos_t {
qos_error = 0,
qos_user_interactive = 1,
qos_user_initiated = 1,
qos_default = 1,
qos_utility = 1,
qos_background = 1,
qos_unspecified = 1
};
inline qos_t qos(thread_t) noexcept {
return qos_error;
}
inline qos_t qos(join_t) noexcept {
return qos_error;
}
inline qos_t qos() noexcept {
return qos_error;
}
inline bool qos(qos_t) noexcept {
return false;
}
template<typename call_>
#ifdef WATER_THREADS_NO_BEGINTHREADEX
dword_t WATER_WINDOWS_CALLTYPE
#else
unsigned __stdcall
#endif
thread(void* pointer) {
___water_debug(trace() << "water::threads thread=" << GetCurrentThreadId() << " begin";)
call_()(static_cast<typename call_::pointer>(pointer));
___water_debug(trace() << "water::threads thread=" << GetCurrentThreadId() << " end";)
return 0; // never return STILL_ACTIVE, 259
}
inline void* run_pointer(void* a) { return a; }
inline void* run_pointer(void const* a) { return const_cast<void*>(a); }
template<typename call_>
void* run(dword_t& id, typename call_::pointer pointer, security_attributes_t *security, size_t stack_size, dword_t creation_flags, int priority) noexcept {
id = 0; // GetThreadId returns 0 on error
void *r = 0;
if(thread_priority_idle <= priority && priority <= thread_priority_time_critical) {
#ifdef WATER_THREADS_NO_BEGINTHREADEX
dword_t id2 = 0;
r = CreateThread(security, static_cast<windows_size_t>(stack_size), &thread<call_>, run_pointer(pointer), creation_flags | (priority ? thread_create_suspended : 0), &id2);
#else
unsigned id2 = 0;
r = reinterpret_cast<void*>(
_beginthreadex(security, static_cast<unsigned>(stack_size), &thread<call_>, run_pointer(pointer), creation_flags | (priority ? thread_create_suspended : 0), &id2)
);
#endif
if(r) {
id = id2;
___water_debug(trace() << "water::threads::run() started thread=" << id;)
// if priority was not 0, the threads was created suspended. there is
// no nice way to kill a suspended thread, and if something fails now
// it is horrible
// - if SetThreadPriority fails, it will run with the default. the
// error is not visible to who ever called run()
// - if ResumeThread fails, the thread leaks
if(priority) {
___water_debug(bool error = 0 == ) SetThreadPriority(r, priority);
___water_assert(!error && "SetThreadPriority failed!");
if(!(creation_flags & thread_create_suspended)) {
// ResumeThread returns previous suspend-count, 0 means not suspended, dword_t(-1) if error
dword_t resume;
while((resume = ResumeThread(r)) > 1 && resume != static_cast<dword_t>(-1));
___water_assert(resume <= 1 && "ResumeThread failed!");
if(resume > 1) {
r = 0;
id = 0;
}
}
}
}
}
___water_assert(r && "thread start failed");
return r;
}
class run_options
{
dword_t myflags = 0;
int mypriority = thread_priority_normal; // is 0
security_attributes_t *mysecurity = 0;
size_t mysize = 0;
public:
dword_t flags() const noexcept {
return myflags;
}
run_options& flags(dword_t f) noexcept {
myflags = f;
return *this;
}
run_options& priority(unsigned a) noexcept {
mypriority = priority_windows_from_water(a, priority_max());
return *this;
}
run_options& qos(qos_t) noexcept {
return *this;
}
int priority_windows() const noexcept {
// returns the windows priority, or int-min if error
return mypriority;
}
run_options& priority_windows(int a) noexcept {
mypriority = a;
return *this;
}
security_attributes_t* security() const noexcept {
return mysecurity;
}
run_options& security(security_attributes_t* a) noexcept {
mysecurity = a;
return *this;
}
size_t stack_size() const noexcept {
return mysize;
}
run_options& stack_size(size_t a) noexcept {
mysize = a;
return *this;
}
};
template<typename call_>
bool run(typename call_::pointer p, join_t& j, run_options const& o = run_options()) noexcept {
thread_t id;
return (j.handle = run<call_>(id, p, o.security(), o.stack_size(), o.flags(), o.priority_windows())) != 0;
}
template<typename call_>
bool run(typename call_::pointer p, thread_t& t, run_options const& o = run_options()) noexcept {
if(void *h = run<call_>(t, p, o.security(), o.stack_size(), o.flags(), o.priority_windows())) {
CloseHandle(h);
return true;
}
return false;
}
template<typename call_>
bool run(typename call_::pointer p, run_options const& o = {}) noexcept {
thread_t t;
return run<call_>(p, t, o);
}
template<typename function_>
struct run_function {
using pointer = function_*;
void operator()(pointer p) { (*p)(); }
};
template<typename function_>
bool run(function_& f, join_t& j, run_options const& o = {}) noexcept {
return run<run_function<function_>>(&f, j, o);
}
template<typename function_>
bool run(function_& f, thread_t& t, run_options const& o = {}) noexcept {
return run<run_function<function_>>(&f, t, o);
}
template<typename function_>
bool run(function_& f, run_options const& o = {}) noexcept {
return run<run_function<function_>>(&f, o);
}
}}
#endif
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %r13
push %r15
push %r8
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_D_ht+0x90d7, %r11
nop
nop
nop
nop
nop
and $38345, %rsi
movl $0x61626364, (%r11)
nop
nop
and $5493, %r11
lea addresses_A_ht+0x1ccc1, %rsi
nop
nop
nop
nop
inc %r8
movl $0x61626364, (%rsi)
nop
and $58943, %rdx
lea addresses_UC_ht+0x1ef4e, %r13
nop
nop
cmp $38816, %r12
movl $0x61626364, (%r13)
nop
nop
xor %rdx, %rdx
lea addresses_WT_ht+0x1907, %rdx
mfence
movw $0x6162, (%rdx)
nop
nop
sub $45381, %r13
lea addresses_A_ht+0x15753, %r8
sub $55919, %r11
mov $0x6162636465666768, %rsi
movq %rsi, %xmm4
and $0xffffffffffffffc0, %r8
movntdq %xmm4, (%r8)
nop
nop
add %r12, %r12
lea addresses_UC_ht+0x7c8b, %r8
nop
nop
nop
dec %rdx
movb (%r8), %r12b
nop
dec %r13
lea addresses_WC_ht+0x1b847, %r13
nop
add $7861, %r8
mov $0x6162636465666768, %rsi
movq %rsi, (%r13)
nop
nop
nop
nop
nop
and %rdx, %rdx
lea addresses_A_ht+0x1ba07, %rsi
lea addresses_D_ht+0x19e07, %rdi
nop
nop
nop
nop
nop
add $3077, %r12
mov $53, %rcx
rep movsl
nop
nop
nop
nop
nop
sub $43716, %r8
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %r8
pop %r15
pop %r13
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r14
push %r8
push %rbp
push %rcx
push %rdi
push %rdx
push %rsi
// Store
lea addresses_UC+0x4887, %rbp
nop
nop
nop
and $50563, %r14
movb $0x51, (%rbp)
nop
nop
nop
nop
xor $61629, %rdx
// REPMOV
lea addresses_normal+0x19107, %rsi
lea addresses_PSE+0x191d4, %rdi
clflush (%rsi)
nop
nop
nop
nop
nop
add %rdx, %rdx
mov $34, %rcx
rep movsw
nop
nop
nop
nop
dec %rdi
// Store
lea addresses_US+0x18947, %r8
clflush (%r8)
nop
nop
xor %rsi, %rsi
mov $0x5152535455565758, %rcx
movq %rcx, %xmm3
vmovups %ymm3, (%r8)
nop
nop
nop
nop
nop
add %rbp, %rbp
// Store
mov $0x5949cb0000000507, %rdi
inc %rcx
mov $0x5152535455565758, %r13
movq %r13, %xmm5
movntdq %xmm5, (%rdi)
nop
nop
nop
cmp $5216, %r13
// Store
lea addresses_D+0x11a07, %r14
nop
nop
nop
nop
nop
cmp %rsi, %rsi
movb $0x51, (%r14)
nop
nop
dec %rsi
// Store
lea addresses_A+0x1eb07, %r13
nop
nop
xor %rcx, %rcx
movb $0x51, (%r13)
nop
cmp %rcx, %rcx
// Store
lea addresses_D+0xa607, %rsi
nop
nop
nop
nop
sub %rdi, %rdi
mov $0x5152535455565758, %r14
movq %r14, %xmm3
movups %xmm3, (%rsi)
nop
nop
nop
nop
sub $6064, %r8
// Store
lea addresses_A+0x1d07, %r14
nop
nop
nop
sub $18619, %r13
movw $0x5152, (%r14)
nop
nop
nop
xor %rbp, %rbp
// Faulty Load
lea addresses_normal+0x19107, %rcx
clflush (%rcx)
nop
nop
nop
nop
nop
xor %r14, %r14
vmovaps (%rcx), %ymm7
vextracti128 $0, %ymm7, %xmm7
vpextrq $1, %xmm7, %rdx
lea oracles, %r13
and $0xff, %rdx
shlq $12, %rdx
mov (%r13,%rdx,1), %rdx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbp
pop %r8
pop %r14
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_normal', 'size': 16, 'AVXalign': False}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 5, 'NT': False, 'type': 'addresses_UC', 'size': 1, 'AVXalign': False}}
{'src': {'type': 'addresses_normal', 'congruent': 0, 'same': True}, 'OP': 'REPM', 'dst': {'type': 'addresses_PSE', 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 5, 'NT': False, 'type': 'addresses_US', 'size': 32, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 6, 'NT': True, 'type': 'addresses_NC', 'size': 16, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 4, 'NT': False, 'type': 'addresses_D', 'size': 1, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_A', 'size': 1, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_D', 'size': 16, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_A', 'size': 2, 'AVXalign': False}}
[Faulty Load]
{'src': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_normal', 'size': 32, 'AVXalign': True}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 4, 'NT': False, 'type': 'addresses_D_ht', 'size': 4, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 1, 'NT': False, 'type': 'addresses_A_ht', 'size': 4, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_UC_ht', 'size': 4, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False}}
{'OP': 'STOR', 'dst': {'same': False, 'congruent': 1, 'NT': True, 'type': 'addresses_A_ht', 'size': 16, 'AVXalign': False}}
{'src': {'same': False, 'congruent': 2, 'NT': False, 'type': 'addresses_UC_ht', 'size': 1, 'AVXalign': False}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'same': True, 'congruent': 6, 'NT': False, 'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': False}}
{'src': {'type': 'addresses_A_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_D_ht', 'congruent': 6, 'same': False}}
{'45': 184, '34': 4935}
34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 45 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 45 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 45 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 45 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 45 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 45 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 45 34 34 34 34 34 34 34 34 34 34 45 34 34 34 45 34 34 34 34 34 34 34 34 45 45 45 34 34 34 34 34 34 34 34 34 34 34 34 45 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 45 34 34 34 34 45 34 34 34 34 34 34 34 34 34 45 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 45 34 34 34 34 34 34 34 34 34 45 34 34 34 34 34 34 34 34 34 45 34 34 34 34 45 45 45 34 45 34 34 34 34 34 34 34 34 34 45 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 45 34 34 34 34 45 34 34 34 34 34 34 34 34 34 45 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34
*/
|
;==================================================================================================
; Settings and tables which the front-end may write
;==================================================================================================
; Initial Save Data table:
;
; This table describes what extra data should be written when a new save file is created. It must be terminated with
; four 0x00 bytes (which will happen by default as long as you don't fill the allotted space).
;
; Row format (4 bytes):
; AAAATTVV
; AAAA = Offset from the start of the save data
; TT = Type (0x00 = or value with current value, 0x01 = set the byte to the given value)
; VV = Value to write to the save
.area 0x400, 0
INITIAL_SAVE_DATA:
.endarea
BOMBCHUS_IN_LOGIC:
.word 0x00
RAINBOW_BRIDGE_CONDITION:
.word 0x00
; 0 = Open
; 1 = Medallions
; 2 = Dungeons
; 3 = Stones
; 4 = Vanilla
; 5 = Tokens
GOSSIP_HINT_CONDITION:
.word 0x00
; 0 = Mask of Truth
; 1 = Stone of Agony
; 2 = No Requirements
FREE_SCARECROW_ENABLED:
.word 0x00
JABU_ELEVATOR_ENABLE:
.byte 0x00
OCARINAS_SHUFFLED:
.byte 0x00
FAST_CHESTS:
.byte 0x01
.align 4
|
build/custom_csr.elf: file format elf32-littleriscv
Disassembly of section .crt_section:
00000000 <_start>:
0: 00100e13 li t3,1
4: b04020f3 csrr ra,mhpmcounter4
8: b0402173 csrr sp,mhpmcounter4
c: b04021f3 csrr gp,mhpmcounter4
10: 06114863 blt sp,ra,80 <fail>
14: 0621c663 blt gp,sp,80 <fail>
18: 00200e13 li t3,2
1c: 005dc0b7 lui ra,0x5dc
20: 98a08093 addi ra,ra,-1654 # 5db98a <pass+0x5db8fe>
24: b0409073 csrw mhpmcounter4,ra
28: b0402173 csrr sp,mhpmcounter4
2c: 04114a63 blt sp,ra,80 <fail>
30: 00300e13 li t3,3
34: b05020f3 csrr ra,mhpmcounter5
38: b0502173 csrr sp,mhpmcounter5
3c: b05021f3 csrr gp,mhpmcounter5
40: 0420d063 ble sp,ra,80 <fail>
44: 02315e63 ble gp,sp,80 <fail>
48: 00400e13 li t3,4
4c: b0609073 csrw mhpmcounter6,ra
50: b04020f3 csrr ra,mhpmcounter4
54: 10000113 li sp,256
58: 0220f463 bleu sp,ra,80 <fail>
5c: 00500e13 li t3,5
60: b07020f3 csrr ra,mhpmcounter7
64: b04020f3 csrr ra,mhpmcounter4
68: 40000137 lui sp,0x40000
6c: 10010113 addi sp,sp,256 # 40000100 <pass+0x40000074>
70: 400001b7 lui gp,0x40000
74: 0020f663 bleu sp,ra,80 <fail>
78: 0030e463 bltu ra,gp,80 <fail>
7c: 0100006f j 8c <pass>
00000080 <fail>:
80: f0100137 lui sp,0xf0100
84: f2410113 addi sp,sp,-220 # f00fff24 <pass+0xf00ffe98>
88: 01c12023 sw t3,0(sp)
0000008c <pass>:
8c: f0100137 lui sp,0xf0100
90: f2010113 addi sp,sp,-224 # f00fff20 <pass+0xf00ffe94>
94: 00012023 sw zero,0(sp)
98: 00000013 nop
9c: 00000013 nop
a0: 00000013 nop
a4: 00000013 nop
a8: 00000013 nop
ac: 00000013 nop
|
// FIBONACCI SERIES GENERATION
START: MVI C,09 // Counter
LXI H,C050 // Memory Pointer
X: MOV A,M
INX H
MOV B,M
INX H
ADD B
DAA
MOV M,A
DCX H
DCR C
JNZ X
RST 1
// To run the Program simply load at memory location C050=01,C051=01
# ORG C050
# DB 01H,01H
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (C) 2022 Intel Corporation
;
; SPDX-License-Identifier: MIT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
default rel
[bits 64]
%include "reg_sizes.asm"
extern crc32_iscsi_00
extern crc32_iscsi_01
extern crc32_iscsi_base
extern crc32_ieee_01
extern crc32_ieee_by4 ;; Optimized for SLM
extern crc32_ieee_02
extern crc32_ieee_base
extern crc16_t10dif_01
extern crc16_t10dif_by4 ;; Optimized for SLM
extern crc16_t10dif_02
extern crc16_t10dif_base
extern crc32_gzip_refl_by8
extern crc32_gzip_refl_by8_02
extern crc32_gzip_refl_base
extern crc16_t10dif_copy_by4
extern crc16_t10dif_copy_by4_02
extern crc16_t10dif_copy_base
%if (AS_FEATURE_LEVEL) >= 10
extern crc32_gzip_refl_by16_10
extern crc32_ieee_by16_10
extern crc32_iscsi_by16_10
extern crc16_t10dif_by16_10
%endif
%include "multibinary.asm"
section .data
;;; *_mbinit are initial values for *_dispatched; is updated on first call.
;;; Therefore, *_dispatch_init is only executed on first call.
crc32_iscsi_dispatched:
dq crc32_iscsi_mbinit
crc32_ieee_dispatched:
dq crc32_ieee_mbinit
%ifndef QPL_LIB
crc16_t10dif_dispatched:
dq crc16_t10dif_mbinit
%endif ; %ifndef QPL_LIB
section .text
;;;;
; crc32_iscsi multibinary function
;;;;
mk_global crc32_iscsi, function
crc32_iscsi_mbinit:
endbranch
call crc32_iscsi_dispatch_init
crc32_iscsi:
endbranch
jmp qword [crc32_iscsi_dispatched]
crc32_iscsi_dispatch_init:
push rax
push rbx
push rcx
push rdx
push rsi
push rdi
lea rsi, [crc32_iscsi_base WRT_OPT] ; Default
mov eax, 1
cpuid
mov ebx, ecx ; save cpuid1.ecx
test ecx, FLAG_CPUID1_ECX_SSE4_2
jz .crc_iscsi_init_done ; use iscsi_base
lea rsi, [crc32_iscsi_00 WRT_OPT]
test ecx, FLAG_CPUID1_ECX_CLMUL
jz .crc_iscsi_init_done ; use ieee_base
lea rsi, [crc32_iscsi_01 WRT_OPT]
;; Test for XMM_YMM support/AVX
test ecx, FLAG_CPUID1_ECX_OSXSAVE
je .crc_iscsi_init_done
xor ecx, ecx
xgetbv ; xcr -> edx:eax
mov edi, eax ; save xgetvb.eax
and eax, FLAG_XGETBV_EAX_XMM_YMM
cmp eax, FLAG_XGETBV_EAX_XMM_YMM
jne .crc_iscsi_init_done
test ebx, FLAG_CPUID1_ECX_AVX
je .crc_iscsi_init_done
;; AVX/02 opt if available
%if AS_FEATURE_LEVEL >= 10
;; Test for AVX2
xor ecx, ecx
mov eax, 7
cpuid
test ebx, FLAG_CPUID7_EBX_AVX2
je .crc_iscsi_init_done ; No AVX2 possible
;; Test for AVX512
and edi, FLAG_XGETBV_EAX_ZMM_OPM
cmp edi, FLAG_XGETBV_EAX_ZMM_OPM
jne .crc_iscsi_init_done ; No AVX512 possible
and ebx, FLAGS_CPUID7_EBX_AVX512_G1
cmp ebx, FLAGS_CPUID7_EBX_AVX512_G1
jne .crc_iscsi_init_done
and ecx, FLAGS_CPUID7_ECX_AVX512_G2
cmp ecx, FLAGS_CPUID7_ECX_AVX512_G2
lea rbx, [crc32_iscsi_by16_10 WRT_OPT] ; AVX512/10 opt
cmove rsi, rbx
%endif
.crc_iscsi_init_done:
mov [crc32_iscsi_dispatched], rsi
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
ret
;;;;
; crc32_ieee multibinary function
;;;;
mk_global crc32_ieee, function
crc32_ieee_mbinit:
endbranch
call crc32_ieee_dispatch_init
crc32_ieee:
endbranch
jmp qword [crc32_ieee_dispatched]
crc32_ieee_dispatch_init:
push rax
push rbx
push rcx
push rdx
push rsi
push rdi
lea rsi, [crc32_ieee_base WRT_OPT] ; Default
mov eax, 1
cpuid
mov ebx, ecx ; save cpuid1.ecx
test ecx, FLAG_CPUID1_ECX_SSE3
jz .crc_ieee_init_done ; use ieee_base
test ecx, FLAG_CPUID1_ECX_CLMUL
jz .crc_ieee_init_done ; use ieee_base
lea rsi, [crc32_ieee_01 WRT_OPT]
;; Extra Avoton test
lea rdx, [crc32_ieee_by4 WRT_OPT]
and eax, FLAG_CPUID1_EAX_STEP_MASK
cmp eax, FLAG_CPUID1_EAX_AVOTON
cmove rsi, rdx
;; Test for XMM_YMM support/AVX
test ecx, FLAG_CPUID1_ECX_OSXSAVE
je .crc_ieee_init_done
xor ecx, ecx
xgetbv ; xcr -> edx:eax
mov edi, eax ; save xgetvb.eax
and eax, FLAG_XGETBV_EAX_XMM_YMM
cmp eax, FLAG_XGETBV_EAX_XMM_YMM
jne .crc_ieee_init_done
test ebx, FLAG_CPUID1_ECX_AVX
je .crc_ieee_init_done
lea rsi, [crc32_ieee_02 WRT_OPT] ; AVX/02 opt
%if AS_FEATURE_LEVEL >= 10
;; Test for AVX2
xor ecx, ecx
mov eax, 7
cpuid
test ebx, FLAG_CPUID7_EBX_AVX2
je .crc_ieee_init_done ; No AVX2 possible
;; Test for AVX512
and edi, FLAG_XGETBV_EAX_ZMM_OPM
cmp edi, FLAG_XGETBV_EAX_ZMM_OPM
jne .crc_ieee_init_done ; No AVX512 possible
and ebx, FLAGS_CPUID7_EBX_AVX512_G1
cmp ebx, FLAGS_CPUID7_EBX_AVX512_G1
jne .crc_ieee_init_done
and ecx, FLAGS_CPUID7_ECX_AVX512_G2
cmp ecx, FLAGS_CPUID7_ECX_AVX512_G2
lea rbx, [crc32_ieee_by16_10 WRT_OPT] ; AVX512/10 opt
cmove rsi, rbx
%endif
.crc_ieee_init_done:
mov [crc32_ieee_dispatched], rsi
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
ret
%ifndef QPL_LIB
;;;;
; crc16_t10dif multibinary function
;;;;
mk_global crc16_t10dif, function
crc16_t10dif_mbinit:
endbranch
call crc16_t10dif_dispatch_init
crc16_t10dif:
endbranch
jmp qword [crc16_t10dif_dispatched]
crc16_t10dif_dispatch_init:
push rax
push rbx
push rcx
push rdx
push rsi
push rdi
lea rsi, [crc16_t10dif_base WRT_OPT] ; Default
mov eax, 1
cpuid
mov ebx, ecx ; save cpuid1.ecx
test ecx, FLAG_CPUID1_ECX_SSE3
jz .t10dif_init_done ; use t10dif_base
test ecx, FLAG_CPUID1_ECX_CLMUL
jz .t10dif_init_done ; use t10dif_base
lea rsi, [crc16_t10dif_01 WRT_OPT]
;; Extra Avoton test
lea rdx, [crc16_t10dif_by4 WRT_OPT]
and eax, FLAG_CPUID1_EAX_STEP_MASK
cmp eax, FLAG_CPUID1_EAX_AVOTON
cmove rsi, rdx
;; Test for XMM_YMM support/AVX
test ecx, FLAG_CPUID1_ECX_OSXSAVE
je .t10dif_init_done
xor ecx, ecx
xgetbv ; xcr -> edx:eax
mov edi, eax ; save xgetvb.eax
and eax, FLAG_XGETBV_EAX_XMM_YMM
cmp eax, FLAG_XGETBV_EAX_XMM_YMM
jne .t10dif_init_done
test ebx, FLAG_CPUID1_ECX_AVX
je .t10dif_init_done
lea rsi, [crc16_t10dif_02 WRT_OPT] ; AVX/02 opt
%if AS_FEATURE_LEVEL >= 10
;; Test for AVX2
xor ecx, ecx
mov eax, 7
cpuid
test ebx, FLAG_CPUID7_EBX_AVX2
je .t10dif_init_done ; No AVX2 possible
;; Test for AVX512
and edi, FLAG_XGETBV_EAX_ZMM_OPM
cmp edi, FLAG_XGETBV_EAX_ZMM_OPM
jne .t10dif_init_done ; No AVX512 possible
and ebx, FLAGS_CPUID7_EBX_AVX512_G1
cmp ebx, FLAGS_CPUID7_EBX_AVX512_G1
jne .t10dif_init_done
and ecx, FLAGS_CPUID7_ECX_AVX512_G2
cmp ecx, FLAGS_CPUID7_ECX_AVX512_G2
lea rbx, [crc16_t10dif_by16_10 WRT_OPT] ; AVX512/10 opt
cmove rsi, rbx
%endif
.t10dif_init_done:
mov [crc16_t10dif_dispatched], rsi
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
ret
%endif ; %ifndef QPL_LIB
mbin_interface crc32_gzip_refl
mbin_dispatch_init_clmul crc32_gzip_refl, crc32_gzip_refl_base, crc32_gzip_refl_by8, crc32_gzip_refl_by8_02, crc32_gzip_refl_by16_10
%ifndef QPL_LIB
mbin_interface crc16_t10dif_copy
mbin_dispatch_init_clmul crc16_t10dif_copy, crc16_t10dif_copy_base, crc16_t10dif_copy_by4, crc16_t10dif_copy_by4_02, crc16_t10dif_copy_by4_02
%endif; %ifndef QPL_LIB
;;; func core, ver, snum
slversion crc16_t10dif, 00, 03, 011a
slversion crc32_ieee, 00, 03, 011b
slversion crc32_iscsi, 00, 03, 011c
slversion crc32_gzip_refl, 00, 00, 002a
|
; int wv_priority_queue_resize(wv_priority_queue_t *q, size_t n)
SECTION code_clib
SECTION code_adt_wv_priority_queue
PUBLIC wv_priority_queue_resize
EXTERN wa_priority_queue_resize
defc wv_priority_queue_resize = wa_priority_queue_resize
; SDCC bridge for Classic
IF __CLASSIC
PUBLIC _wv_priority_queue_resize
defc _wv_priority_queue_resize = wv_priority_queue_resize
ENDIF
|
; A269223: Factorial of the sum of digits of n in base 3.
; 1,1,2,1,2,6,2,6,24,1,2,6,2,6,24,6,24,120,2,6,24,6,24,120,24,120,720,1,2,6,2,6,24,6,24,120,2,6,24,6,24,120,24,120,720,6,24,120,24,120,720,120,720,5040,2,6,24,6,24,120,24,120,720,6,24,120,24,120,720,120,720
seq $0,53735 ; Sum of digits of (n written in base 3).
seq $0,142 ; Factorial numbers: n! = 1*2*3*4*...*n (order of symmetric group S_n, number of permutations of n letters).
|
%macro nwln 0
mov eax,0x4
mov ebx,0x1
mov ecx,NewLine
mov edx,0x1
int 0x80
%endmacro
SECTION .data
NewLine db 0xA
Snippet db "KANGAROO"
SnippetLen equ $-Snippet
TestDb dw "Hi?"
TestDd db "Hi :P"
TestDdLen equ $-TestDd
SaveBits db 11111111b,1b
SaveHex dw 0ff01h
SaveHex1 db 0FFH,01H
float1 dd 1.234
real1 dq 123.456
marks times 8 db 0f2h
; var1: db 05h
; message: db "O_o -> XD",0ah
; message2: db "Second message",0ah
SECTION .bss
buffer resw 100000
SECTION .text
global _start
_start:
nop
; mov esi,[TestDb]
; mov esi,TestDb
; mov byte [esi],100
; inc dword [SaveHex]
mov eax,0x0
sub eax,1
inc edi
do:
inc al
jmp do
add eax,1
sub eax,1
inc eax
dec eax
mov ecx,1
mov ebx,TestDb
mov eax,[ebx+ecx]
mov eax,[TestDb+ecx]
lea eax,[TestDb]
mov ecx,TestDb
mov esi,0x0
mov ebx,[Snippet+esi]
mov ebx,Snippet
mov eax,[ebx+esi+3]
; mov eax,[ebx+ecx+edx] ; Invalid Effective Address
;
; ; --------------------------------------
;
; mov eax,0x4 ; Specify sys_write call
; mov ebx,0x1 ; Specify File Descriptor 1: Standard Output
; mov ecx,Snippet ; Pass offset of the message
; mov edx,SnippetLen ; Pass the length of the message
; int 0x80 ; Make kernel call
;
; nwln ; New Line
;
; mov ebx,Snippet
; mov eax,SnippetLen
; DoMore: add byte [ebx],32
; inc ebx
; dec eax
; jnz DoMore
;
; mov eax,0x4 ; Specify sys_write call
; mov ebx,0x1 ; Specify File Descriptor 1: Standard Output
; mov ecx,Snippet ; Pass offset of the message
; mov edx,SnippetLen ; Pass the length of the message
; int 0x80 ; Make kernel call
;
; nwln ; New Line
;
; mov eax,0x1 ; Code for Exit Syscall
; mov ebx,0x0 ; Return a code of zero
; int 0x80 ; Make kernel call
;
; ; --------------------------------------
;
; dec byte [var1]
; jnz _start
; mov eax,0ff5h
; add eax,0bh
; add eax,1
; inc eax
; mov bx,0ffffh
; add bx,1
; mov dx,0ffffh
; dec dx
; mov eax,1
; add eax,2
; mov ebx,1
; add bl,0ffh
; mov ecx,eax
; mov eax,1
; mov ebx,1
; neg ebx
; add eax,ebx
; add eax,1
; mov eax,10b
; add eax,1
; mov edx,07FFFFFFFh
; add edx,1
; add edx,1
; add edx,0fffffffeh
; mov eax,80000000h
; mov ebx,7fffffffh
; mov edx,message
; mov [message2],byte 67h
; mov ax,067FEh
; mov bx,ax
; mov cl,bh
; mov ch,bl
;
; xchg cl,ch
;
; xor cl,ch
; xor ch,cl
; xor cl,ch
;
; shr bx,1
;
; mov eax,12345678h
; mov edx,'wxyz'
;
; mov bx,ax
; add di,ax
; add di,ax
;
; mov [ebp],edi
nop
|
; A198974: 2*11^n-1.
; 1,21,241,2661,29281,322101,3543121,38974341,428717761,4715895381,51874849201,570623341221,6276856753441,69045424287861,759499667166481,8354496338831301,91899459727144321,1010894056998587541,11119834626984462961,122318180896829092581,1345499989865120018401,14800499888516320202421,162805498773679522226641,1790860486510474744493061,19699465351615222189423681,216694118867767444083660501,2383635307545441884920265521,26219988382999860734122920741,288419872212998468075352128161,3172618594342983148828873409781,34898804537772814637117607507601,383886849915500961008293682583621,4222755349070510571091230508419841,46450308839775616282003535592618261,510953397237531779102038891518800881
mov $1,11
pow $1,$0
sub $1,1
mul $1,2
add $1,1
mov $0,$1
|
; AMD64 mpn_mul_1
; Copyright 2016 Jens Nurmann and Alexander Kruppa
; 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.
; (rdi,rdx) = rcx*(rsi,rdx)
; rax = high word of product
; mp_limb_t mpn_mul_1(mp_ptr, mp_ptr, mp_size_t, mp_limb_t)
; mp_limb_t mpn_mul_1c(mp_ptr, mp_ptr, mp_size_t, mp_limb_t, mp_limb_t)
; rax rdi rsi rdx rcx r8
; rax rcx rdx r8 r9 [rsp+40]
%include 'yasm_mac.inc'
BITS 64
; the following register allocation scheme is valid for Linux
%define RP RDI
%define S1P RSI
%define Size RCX
%define S2 RDX
%define MulLo0 R8
%define MulHi0 R9
%define MulLo1 R10
%define MulHi1 R11
%define MulLo2 R12
%define MulHi2 R13
%define MulLo3 R14
%define MulHi3 RBX
%define reg_save_list rsi, rdi, rbx, r12, r13, r14
align 32
FRAME_PROC mpn_mul_1, 0, reg_save_list
mov rdi, rcx
mov rsi, rdx
mov rcx, r8
mov rdx, r9
mov r8, [rsp + stack_use + 40]
xor MulHi3, MulHi3
mov RAX, Size ; may be increased by 1 at the end
sub Size, 4
jc .Post ; separate handling of remaining max. 3 limb =>
; prepare a quadlimb for main-loop entry
mulx MulHi0, MulLo0, [S1P]
mulx MulHi1, MulLo1, [S1P+8]
mulx MulHi2, MulLo2, [S1P+16]
mulx MulHi3, MulLo3, [S1P+24]
add S1P, 32
add MulLo1, MulHi0
adc MulLo2, MulHi1
adc MulLo3, MulHi2
adc MulHi3, 0
jmp .Check ; enter main loop =>
; main loop (unloaded operands)
; - 1.25 cycles per limb in L1D$
; - 1.25 cycles per limb in L2D$
; - 1.60-1.72 cycles per limb in L3D$
align 32
.Loop:
mov [RP], MulLo0
mov [RP+8], MulLo1
mov [RP+16], MulLo2
mov [RP+24], MulLo3
mulx MulHi0, MulLo0, [S1P]
mulx MulHi1, MulLo1, [S1P+8]
mulx MulHi2, MulLo2, [S1P+16]
add MulLo0, MulHi3
mov [RP+32], MulLo0
adc MulLo1, MulHi0
mov [RP+40], MulLo1
adc MulLo2, MulHi1
mov [RP+48], MulLo2
mulx MulHi3, MulLo3, [S1P+24]
mulx MulHi0, MulLo0, [S1P+32]
mulx MulHi1, MulLo1, [S1P+40]
adc MulLo3, MulHi2 ; no carry-out here
adc MulLo0, MulHi3
adc MulLo1, MulHi0
mulx MulHi2, MulLo2, [S1P+48]
adc MulLo2, MulHi1
mov [RP+56], MulLo3
mulx MulHi3, MulLo3, [S1P+56]
adc MulLo3, MulHi2
adc MulHi3, 0
add S1P, 64
add RP, 64
.Check:
sub Size, 8
jnc .Loop
; core loop roll-out 8 can generate dangling quad-limb
test Size, 4
je .Store ; no dangling quad-limb =>
mov [RP], MulLo0
mulx MulHi0, MulLo0, [S1P]
mov [RP+8], MulLo1
mulx MulHi1, MulLo1, [S1P+8]
mov [RP+16], MulLo2
mulx MulHi2, MulLo2, [S1P+16]
add MulLo0, MulHi3
mov [RP+24], MulLo3
mulx MulHi3, MulLo3, [S1P+24]
adc MulLo1, MulHi0
adc MulLo2, MulHi1
adc MulLo3, MulHi2
adc MulHi3, 0
add S1P, 32
add RP, 32
; store remaining quad-limb from main loop
.Store:
mov [RP], MulLo0
mov [RP+8], MulLo1
mov [RP+16], MulLo2
mov [RP+24], MulLo3
add RP, 32
; handle final 0-3 single limb of S1P
.Post:
and Size, 3
je .Post0
cmp Size, 2
ja .Post3
je .Post2
.Post1:
mulx MulHi0, MulLo0, [S1P]
add MulLo0, MulHi3
adc MulHi0, 0
mov [RP], MulLo0
mov rax, MulHi0
jmp .Exit
.Post2:
mulx MulHi0, MulLo0, [S1P]
mulx MulHi1, MulLo1, [S1P+8]
add MulLo0, MulHi3
adc MulLo1, MulHi0
adc MulHi1, 0
mov [RP], MulLo0
mov [RP+8], MulLo1
mov rax, MulHi1
jmp .Exit
.Post3:
mulx MulHi0, MulLo0, [S1P]
mulx MulHi1, MulLo1, [S1P+8]
mulx MulHi2, MulLo2, [S1P+16]
add MulLo0, MulHi3
adc MulLo1, MulHi0
adc MulLo2, MulHi1
adc MulHi2, 0
mov [RP], MulLo0
mov [RP+8], MulLo1
mov [RP+16], MulLo2
mov rax, MulHi2
jmp .Exit
.Post0:
mov rax, MulHi3
.Exit:
END_PROC reg_save_list
|
%include "TiberianSun.inc"
%include "macros/patch.inc"
%include "macros/datatypes.inc"
cextern SpawnerActive
gbool RunAutoSS, 0
gint DoingAutoSS, 0
sstring str_AutoSSDir, "AutoSS"
sstring str_AutoSSFileNameFormat, "AutoSS/AutoSS-%d-%d_%d.PCX"
sstring str_AutoSSFileNamePng, "AutoSS/AutoSS-%d-%d_%d.png"
sstring str_AutoSSFileNameJpg, "AutoSS/AutoSS-%d-%d_%d.jpg"
sstring str_SCRN_png, "SCRN%04d.png"
hack 0x004EAC39
_ScreenCaptureCommand__Activate_AutoSS_File_Name:
lea ecx, [esp+0x114]
cmp dword [SessionType], 3
jne .Normal_Code
cmp byte[RunAutoSS], 1
jnz .Normal_Code
.AutoSS_File_Name:
push 0
push str_AutoSSDir
call [0x006CA0D0] ; CreateDirectoryA
lea ecx, [esp+0x114]
push esi
push dword [Frame]
push dword [GameIDNumber]
cmp byte[RunAutoSS], 1 ;Always use png format with autoss
je .jpg
cmp byte[UsePNG], 1
jne .pcx
.png:
push str_AutoSSFileNamePng
jmp .past_pcx
.jpg:
push str_AutoSSFileNameJpg
jmp .past_pcx
.pcx:
push str_AutoSSFileNameFormat ; "AutoSS\\AutoSS-%d-%d_%d.PCX"
.past_pcx:
push ecx
call _sprintf
add esp, 0x14 ; AFTER PUSHING
jmp 0x004EAC4F
.Normal_Code:
cmp byte[UsePNG], 1
jne .Reg_pcx
push esi
push str_SCRN_png
jmp 0x004EAC46
.Reg_pcx
jmp 0x004EAC40
; DoingAutoSS
|
/*============================================================================
The Medical Imaging Interaction Toolkit (MITK)
Copyright (c) German Cancer Research Center (DKFZ)
All rights reserved.
Use of this source code is governed by a 3-clause BSD license that can be
found in the LICENSE file.
============================================================================*/
// Qmitk
#include "QmitkXnatSimpleSearchView.h"
// Standard
#include <iostream>
#include <string>
// Blueberry
#include <berryISelectionService.h>
#include <berryIWorkbenchWindow.h>
// Qt
#include <QMessageBox>
#include <QTreeView>
#include <QAbstractItemModel>
#include <QStandardItemModel>
#include <QStandardItem>
#include <QString>
#include <QBrush>
#include <QListView>
// ctkXnatCore
#include "ctkXnatProject.h"
const std::string QmitkXnatSimpleSearchView::VIEW_ID = "org.mitk.views.qmitkxnatsimplesearchview";
QmitkXnatSimpleSearchView::QmitkXnatSimpleSearchView() :
m_Session(0),
m_TreeModel(new ctkXnatTreeModel())
{
}
QmitkXnatSimpleSearchView::~QmitkXnatSimpleSearchView()
{
delete m_TreeModel;
}
void QmitkXnatSimpleSearchView::SetFocus()
{
m_Controls.buttonStartSearch->setFocus();
}
void QmitkXnatSimpleSearchView::CreateQtPartControl( QWidget *parent )
{
// create GUI widgets from the Qt Designer's .ui file
m_Controls.setupUi( parent );
m_Controls.treeView->setModel(m_TreeModel);
connect( m_Controls.buttonStartSearch, SIGNAL(clicked()), this, SLOT(StartSearch()) );
}
void QmitkXnatSimpleSearchView::StartSearch()
{
int type;
switch(m_Controls.objectComboBox->currentIndex())
{
case QmitkXnatSimpleSearchView::PROJECT:
type = QmitkXnatSimpleSearchView::PROJECT;
break;
case QmitkXnatSimpleSearchView::SUBJECT:
type = QmitkXnatSimpleSearchView::SUBJECT;
break;
case QmitkXnatSimpleSearchView::EXPERIMENT:
type = QmitkXnatSimpleSearchView::EXPERIMENT;
break;
default:
type = QmitkXnatSimpleSearchView::EMPTY;
MITK_INFO << "You did something weird or chose nothing!";
break;
}
//m_TreeModel->setMatchingObject( type );
//m_TreeModel->setSearchTerm( m_Controls.termLineEdit->text() );
//m_TreeModel->setIsStartOfSearch( true );
// create ctkXnatConnection
//m_Connection = m_ConnectionFactory->makeConnection(m_Controls.inHostAddress->text(), m_Controls.inUser->text(), m_Controls.inPassword->text());
//ctkXnatServer* server = m_Connection->server();
//m_TreeModel->addServer(server);
//m_Controls.treeView->reset();
}
void QmitkXnatSimpleSearchView::SetSelectionProvider()
{
GetSite()->SetSelectionProvider(m_SelectionProvider);
}
|
; A212836: Number of 0..n arrays of length 3 with 0 never adjacent to n.
; 2,17,50,107,194,317,482,695,962,1289,1682,2147,2690,3317,4034,4847,5762,6785,7922,9179,10562,12077,13730,15527,17474,19577,21842,24275,26882,29669,32642,35807,39170,42737,46514,50507,54722,59165,63842,68759,73922,79337,85010,90947,97154,103637,110402,117455,124802,132449,140402,148667,157250,166157,175394,184967,194882,205145,215762,226739,238082,249797,261890,274367,287234,300497,314162,328235,342722,357629,372962,388727,404930,421577,438674,456227,474242,492725,511682,531119,551042,571457,592370,613787,635714,658157,681122,704615,728642,753209,778322,803987,830210,856997,884354,912287,940802,969905,999602,1029899,1060802,1092317,1124450,1157207,1190594,1224617,1259282,1294595,1330562,1367189,1404482,1442447,1481090,1520417,1560434,1601147,1642562,1684685,1727522,1771079,1815362,1860377,1906130,1952627,1999874,2047877,2096642,2146175,2196482,2247569,2299442,2352107,2405570,2459837,2514914,2570807,2627522,2685065,2743442,2802659,2862722,2923637,2985410,3048047,3111554,3175937,3241202,3307355,3374402,3442349,3511202,3580967,3651650,3723257,3795794,3869267,3943682,4019045,4095362,4172639,4250882,4330097,4410290,4491467,4573634,4656797,4740962,4826135,4912322,4999529,5087762,5177027,5267330,5358677,5451074,5544527,5639042,5734625,5831282,5929019,6027842,6127757,6228770,6330887,6434114,6538457,6643922,6750515,6858242,6967109,7077122,7188287,7300610,7414097,7528754,7644587,7761602,7879805,7999202,8119799,8241602,8364617,8488850,8614307,8740994,8868917,8998082,9128495,9260162,9393089
add $0,3
mov $2,1
sub $2,$0
bin $0,3
mul $0,2
add $0,$2
mov $1,$0
mul $1,3
add $1,2
|
COMMENT }%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) GeoWorks 1989 -- All Rights Reserved
PROJECT: PC GEOS
MODULE: Video driver
FILE: clr8Color.asm
AUTHOR: Jim DeFrisco
ROUTINES:
Name Description
---- -----------
GBL VidSetPalEntry Set a new palette entry
REVISION HISTORY:
Name Date Description
---- ---- -----------
Jim 12/91 initial version
DESCRIPTION:
$Id: clr8Color.asm,v 1.1 97/04/18 11:42:59 newdeal Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
VidSetPalEntry
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Set a single palette entry
CALLED BY: GLOBAL, INTERNAL
PASS: ah - index to set
al - red component
bl - green component
bh - blue component
RETURN: ah - index just set
al - red component (value actually set by device)
bl - green component (value actually set by device)
bh - blue component (value actually set by device)
DESTROYED: dx, di
PSEUDO CODE/STRATEGY:
set the new entry;
KNOWN BUGS/SIDE EFFECTS/IDEAS:
none
REVISION HISTORY:
Name Date Description
---- ---- -----------
Jim 07/89 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
VidSetPalEntry proc near
uses cx
.enter
; now have valid RGB color, store to shadowed palette
mov dl, ah ; get index into word
clr dh ;
mov di, dx ;
shl dx, 1 ; mul by three
add di, dx
mov ss:palCurRGBValues[di].RGB_red, al ;
mov ss:palCurRGBValues[di].RGB_green, bl
mov ss:palCurRGBValues[di].RGB_blue, bh
.leave
ret
VidSetPalEntry endp
|
; A234933: The number of binary sequences that contain at least two consecutive 1's and contain at least two consecutive 0's.
; 0,0,0,0,2,8,24,62,148,336,738,1584,3344,6974,14412,29576,60370,122712,248616,502398,1013156,2039840,4101570,8238560,16534432,33161598,66473244,133189272,266771378,534178376,1069385208,2140434494,4283561524,8571479664,17150008482,34311422736,68641300400,137312461502,274673238636,549424653608,1098975799186,2198156266680,4396643693640,8793823215870,17588513420612,35178429658688,70359129123714,140721930871232,281449804172608,562909223399166,1125834004282428,2251693181102904,4503427092227954,9006920087016104
sub $0,1
cal $0,232580 ; Number of binary sequences of length n that contain at least one contiguous subsequence 011.
mov $1,$0
mul $1,2
|
;
; BIGDVRM.ASM
;
; Implementation for for signed and unsigned division of a 64 bit integer
; by a 32 bit integer, returning the result and remainder.
;
; Copyright (c) 2017 Malcolm J. Smith
;
; 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.
;
.386
.MODEL FLAT, C
.CODE
externdef _aulldiv:near
externdef _aullrem:near
externdef _alldiv:near
externdef _allrem:near
; LARGE_INTEGER Result [High EDX, Low EAX]
; LARGE_INTEGER Remainder [High EBX, Low ECX]
; _aulldvrm(
; LARGE_INTEGER Dividend, [High ESP + 8, Low ESP + 4],
; LARGE_INTEGER Divisor [High ESP + 16, Low ESP + 12]
; );
public _aulldvrm
_aulldvrm proc
; Push the arguments for the next function
mov edx, [esp + 16]
mov eax, [esp + 12]
push edx
push eax
mov edx, [esp + 16]
mov eax, [esp + 12]
push edx
push eax
; Get the remainder
call _aullrem
; Save the remainder into registers that will be preserved
mov ebx, edx
mov esi, eax
; Push the arguments for the next function
mov edx, [esp + 16]
mov eax, [esp + 12]
push edx
push eax
mov edx, [esp + 16]
mov eax, [esp + 12]
push edx
push eax
; Get the result
call _aulldiv
mov ecx, esi
ret 16
_aulldvrm endp
; LARGE_INTEGER Result [High EDX, Low EAX]
; LARGE_INTEGER Remainder [High EBX, Low ECX]
; _alldvrm(
; LARGE_INTEGER Dividend, [High ESP + 8, Low ESP + 4],
; LARGE_INTEGER Divisor [High ESP + 16, Low ESP + 12]
; );
public _alldvrm
_alldvrm proc
; Push the arguments for the next function
mov edx, [esp + 16]
mov eax, [esp + 12]
push edx
push eax
mov edx, [esp + 16]
mov eax, [esp + 12]
push edx
push eax
; Get the remainder
call _allrem
; Save the remainder into registers that will be preserved
mov ebx, edx
mov esi, eax
; Push the arguments for the next function
mov edx, [esp + 16]
mov eax, [esp + 12]
push edx
push eax
mov edx, [esp + 16]
mov eax, [esp + 12]
push edx
push eax
; Get the result
call _alldiv
mov ecx, esi
ret 16
_alldvrm endp
END
|
; A056155: Positive integer k, 1 <= k <= n, which maximizes k^(n+1-k).
; 1,2,2,3,3,3,4,4,4,4,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,11,11,11,11,12,12,12,12,12,13,13,13,13,14,14,14,14,14,15,15,15,15,16,16,16,16,16,17,17,17,17,17,18,18,18,18,18,19,19,19,19,19,20,20,20
mul $0,8
sub $0,1
lpb $0
add $1,6
add $2,$0
add $3,$2
lpb $3
sub $0,4
mov $2,$4
div $3,2
lpe
trn $0,$2
lpe
div $1,6
add $1,1
mov $0,$1
|
; A122653: a(n) = 10*a(n-1) - a(n-2) with a(0)=0, a(1)=6.
; 0,6,60,594,5880,58206,576180,5703594,56459760,558894006,5532480300,54765908994,542126609640,5366500187406,53122875264420,525862252456794,5205499649303520
mov $2,2
lpb $0,1
add $1,$2
add $2,$1
add $1,$2
add $2,$1
sub $0,1
add $2,$1
lpe
|
copyright zengfr site:http://github.com/zengfr/romhack
00042A move.l D1, (A0)+
00042C dbra D0, $42a
004D3E move.l D0, (A4)+
004D40 dbra D1, $4d38
010A5E sub.w D1, ($6c,A3)
010A62 bgt $10a6a [enemy+6C]
010A66 clr.w ($6c,A3)
010A6A move.b (A4)+, D0 [enemy+6C]
0110DE sub.w D1, ($6c,A3)
0110E2 bgt $110ea [enemy+6C]
0110E6 clr.w ($6c,A3)
0110EA move.b (A4)+, D0 [enemy+6C]
0111D6 sub.w D1, ($6c,A3)
0111DA bgt $111e4 [enemy+6C]
0111DE move.w #$1, ($6c,A3)
0111E4 move.b (A4)+, D0 [enemy+6C]
01142A sub.w D1, ($6c,A3)
01142E bgt $11436 [enemy+6C]
011432 clr.w ($6c,A3)
011436 move.b (A4)+, D0
01150C sub.w D1, ($6c,A3)
011510 bgt $1151a [enemy+6C]
011912 sub.w D1, ($6c,A3)
011916 bgt $1191e [enemy+6C]
01191A clr.w ($6c,A3)
01191E move.b (A4)+, D0 [enemy+6C]
011BCA sub.w D1, ($6c,A3)
011BCE bgt $11bd6 [enemy+6C]
011BD2 clr.w ($6c,A3)
011BD6 move.b (A4)+, D0 [enemy+6C]
011F20 sub.w D1, ($6c,A3)
011F24 bgt $11f3a [enemy+6C]
011F28 clr.w ($6c,A3)
011F2C tst.b ($7d,A3) [enemy+6C]
01227A sub.w D1, ($6c,A3)
01227E bgt $12286 [enemy+6C]
012282 clr.w ($6c,A3)
012286 move.b (A4)+, D0
0123E4 sub.w D1, ($6c,A3)
0123E8 bgt $123f0 [enemy+6C]
0123EC clr.w ($6c,A3)
0123F0 move.b (A4)+, D0 [enemy+6C]
01256A sub.w D1, ($6c,A3)
01256E bgt $1257e [enemy+6C]
01257A clr.w ($6c,A3) [enemy+ 4, enemy+ 6]
01257E move.b (A4)+, D0 [enemy+6C]
016B6E move.w ($6c,A6), (A4)+ [123p+ 6E, enemy+6E]
016B72 move.l A6, (A4) [123p+ 6C, enemy+6C]
016BA2 move.w ($6c,A6), (A4)+ [123p+ 6E, enemy+6E]
016BA6 move.l A6, (A4) [123p+ 6C, enemy+6C]
016BD6 move.w ($6c,A6), (A4)+ [123p+ 6E, enemy+6E]
016BDA move.l A6, (A4) [123p+ 6C, enemy+6C]
017204 move.w ($6c,A3), (A4)+ [enemy+6E]
017208 move.l A3, (A4) [enemy+6C]
01720A tst.w ($6c,A3)
01720E bne $17216 [enemy+6C]
02A646 tst.w ($6c,A6)
02A64A beq $2a6c2 [enemy+6C]
02A688 tst.w ($6c,A6)
02A68C beq $2a84c [enemy+6C]
02A714 tst.w ($6c,A6) [enemy+1C]
02A718 bne $2a75e [enemy+6C]
02A7CC tst.w ($6c,A6)
02A7D0 bne $2a7d8 [enemy+6C]
02A824 tst.w ($6c,A6)
02A828 bne $2a832 [enemy+6C]
02A89E tst.w ($6c,A6) [enemy+1C]
02A8A2 bne $2a8e8 [enemy+6C]
02A956 tst.w ($6c,A6)
02A95A bne $2a962 [enemy+6C]
02A988 tst.w ($6c,A6)
02A98C bne $2a9c6 [enemy+6C]
02AAC6 tst.w ($6c,A6)
02AACA bne $2aae6 [enemy+6C]
02AB42 tst.w ($6c,A6)
02AB46 bne $2ab50 [enemy+6C]
02ABD0 tst.w ($6c,A6)
02ABD4 bne $2abe4 [enemy+6C]
02AC28 tst.w ($6c,A6)
02AC2C bne $2ac6e [enemy+6C]
02ACA6 tst.w ($6c,A6) [enemy+1C]
02ACAA bne $2acec [enemy+6C]
02AD58 tst.w ($6c,A6)
02AD5C bne $2ad64 [enemy+6C]
02ADF2 tst.w ($6c,A6)
02ADF6 beq $2a6c2 [enemy+6C]
02AEC6 tst.w ($6c,A6)
02AECA beq $2a84c [enemy+6C]
02AF86 tst.w ($6c,A6)
02AF8A bne $2afd0 [enemy+6C]
02B080 move.w ($6c,A6), D0
02B084 move.w ($6a,A6), D1 [enemy+6C]
02B4BA tst.w ($6c,A6)
02B4BE beq $2b4fe [enemy+6C]
02B9B2 move.w ($6c,A3), D3
02B9B6 moveq #$0, D2 [enemy+6C]
02BAE4 move.w ($6c,A3), D3
02BAE8 moveq #$0, D2 [enemy+6C]
03144A move.w D0, ($6c,A6) [enemy+6A]
03144E move.w D0, ($6e,A6) [enemy+6C]
031E48 move.w D0, ($6c,A6) [enemy+6A]
031E4C move.w D0, ($6e,A6) [enemy+6C]
03263E sub.w ($6c,A6), D0 [enemy+6E]
032642 tst.b ($518,A5) [enemy+6C]
032660 tst.w ($6c,A6) [123p+10C]
032664 beq $3266c [enemy+6C]
032702 tst.w ($6c,A6)
032706 beq $3273e [enemy+6C]
03270A clr.w ($6c,A6)
03270E move.l #$2020000, ($4,A6) [enemy+6C]
033E08 tst.w ($6c,A6) [enemy+80]
033E0C bne $33e16 [enemy+6C]
042B5E cmp.w ($6c,A6), D0
042B62 bge $42b76 [enemy+6C]
042B6E cmp.w ($6c,A6), D0
042B72 bge $42b76 [enemy+6C]
043868 move.w ($6c,A6), D0
04386C bne $4388a [enemy+6C]
044ED8 cmp.w ($6c,A6), D0
044EDC blt $44ee8 [enemy+6C]
048D38 tst.w ($6c,A6)
048D3C beq $48d6e [enemy+6C]
048E2C tst.w ($6c,A6) [enemy+ 6]
048E30 beq $48c06 [enemy+6C]
04D932 move.w #$1, ($6c,A6) [enemy+6A]
04D938 move.w #$1, ($6e,A6) [enemy+6C]
04D9E0 clr.w ($6c,A6)
04D9E4 jmp $2a606.l
04EDCA tst.w ($6c,A6)
04EDCE beq $4ee00 [enemy+6C]
04EF12 tst.w ($6c,A6) [enemy+ 6]
04EF16 beq $4ebec [enemy+6C]
050352 move.w ($6c,A6), D0
050356 bne $50374 [enemy+6C]
050374 tst.w ($6c,A6)
050378 beq $5037e [enemy+6C]
05058A tst.w ($6c,A6)
05058E beq $5061a [enemy+6C]
050B80 cmp.w ($6c,A6), D2
050B84 bge $50b8e [enemy+6C]
051022 tst.w ($6c,A0) [enemy+A0]
051026 beq $5103a [enemy+6C]
0538AE clr.w ($6c,A6)
0538B2 move.w #$4, ($a0,A6) [enemy+6C]
0538E6 tst.w ($6c,A6)
0538EA beq $5396e
0578CA move.w #$1, ($6c,A6) [enemy+6A]
0578D0 move.w #$1, ($6e,A6) [enemy+6C]
058658 tst.w ($6c,A6) [enemy+ 8]
05865C bne $5869c [enemy+6C]
058A08 move.w ($6c,A6), D1 [enemy+6A]
058A0C asr.w #2, D0 [enemy+6C]
058AE4 move.w ($6c,A6), D1 [enemy+C8]
058AE8 asr.w #2, D0 [enemy+6C]
05A35E move.w ($6c,A6), D0
05A362 bne $5a374 [enemy+6C]
05B076 move.w #$14, ($6c,A6) [enemy+6A]
05B07C move.w #$14, ($6e,A6) [enemy+6C]
05B0A0 move.w #$14, ($6c,A6) [enemy+6A]
05B0A6 move.w #$14, ($6e,A6) [enemy+6C]
05B958 move.w D0, ($6c,A6)
05B95C move.w D0, ($6e,A6) [enemy+6C]
05C406 move.w D0, ($6c,A6)
05C40A move.w D0, ($6e,A6) [enemy+6C]
07BF82 tst.w ($6c,A0)
07BF86 beq $7c0ce [enemy+6C]
0AAACA move.l (A0), D2
0AAACC move.w D0, (A0) [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
0AAACE move.w D0, ($2,A0)
0AAAD2 cmp.l (A0), D0
0AAAD4 bne $aaafc
0AAAD8 move.l D2, (A0)+
0AAADA cmpa.l A0, A1 [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
0AAAE6 move.l (A0), D2
0AAAE8 move.w D0, (A0) [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
0AAAF4 move.l D2, (A0)+
0AAAF6 cmpa.l A0, A1 [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
copyright zengfr site:http://github.com/zengfr/romhack
|
; A094856: E.g.f.: exp(4x)/(1-4x)^(1/4).
; Submitted by Christian Krause
; 1,5,29,217,2297,34349,674965,16276481,461527793,14993138773,548258687501,22272738733865,994870668959209,48451779617935997,2554818339078836357,144990720049391354449,8811240401831517313505,570857963393730507892901,39275973938444154366908413,2859842899802805499978792313,219707378806740222570742019801,17759977470636021158519858142925,1506816315607541168324498056067189,133882405281837449206379329147938977,12432084908194657423075379642717355217,1204229732099434819235363681521644309749
mov $2,1
lpb $0
sub $0,1
add $1,$2
mul $2,4
add $2,$1
mul $1,4
mul $1,$0
lpe
mov $0,$2
|
; A139175: a(n) = (n! - 5)/5.
; Submitted by Jon Maiga
; 23,143,1007,8063,72575,725759,7983359,95800319,1245404159,17435658239,261534873599,4184557977599,71137485619199,1280474741145599,24329020081766399,486580401635327999,10218188434341887999,224800145555521535999,5170403347776995327999,124089680346647887871999,3102242008666197196799999,80658292225321127116799999,2177773890083670432153599999,60977668922342772100300799999,1768352398747940390908723199999,53050571962438211727261695999999,1644567730835584563545112575999999
mov $1,$0
add $0,5
add $1,4
lpb $1
mul $0,$1
sub $1,1
lpe
sub $0,120
div $0,5
add $0,23
|
/*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkPathToChainCodePathFilter_hxx
#define itkPathToChainCodePathFilter_hxx
#include "itkPathToChainCodePathFilter.h"
namespace itk
{
template< typename TInputPath, typename TOutputChainCodePath >
PathToChainCodePathFilter< TInputPath, TOutputChainCodePath >
::PathToChainCodePathFilter() :
m_MaximallyConnected( false )
{
this->SetNumberOfRequiredInputs(1);
}
template< typename TInputPath, typename TOutputChainCodePath >
void
PathToChainCodePathFilter< TInputPath, TOutputChainCodePath >
::GenerateData()
{
OffsetType offset;
OffsetType tempOffset;
OffsetType zeroOffset;
zeroOffset.Fill(0);
InputPathInputType inputPathInput;
int dimension = OffsetType::GetOffsetDimension();
typename Superclass::InputPathConstPointer inputPtr = this->GetInput();
typename Superclass::OutputPathPointer outputPtr = this->GetOutput(0);
//outputPtr->SetRequestedRegion( inputPtr->GetRequestedRegion() );
//outputPtr->SetBufferedRegion( inputPtr->GetBufferedRegion() );
//outputPtr->SetLargestPossibleRegion( inputPtr->GetLargestPossibleRegion() );
//outputPtr->Allocate(); // Allocate() is an Image function
outputPtr->Clear();
inputPathInput = inputPtr->StartOfInput();
outputPtr->SetStart( inputPtr->EvaluateToIndex(inputPathInput) );
for ( OutputPathInputType outputPathInput = 0;; )
{
offset = inputPtr->IncrementInput(inputPathInput);
if ( zeroOffset == offset ) { break; }
if ( !m_MaximallyConnected )
{
outputPtr->InsertStep(outputPathInput++, offset);
}
else
{
for ( int d = 0; d < dimension; d++ )
{
if ( offset[d] )
{
tempOffset.Fill(0);
tempOffset[d] = offset[d];
outputPtr->InsertStep(outputPathInput++, tempOffset);
}
}
}
}
}
template< typename TInputPath, typename TOutputChainCodePath >
void
PathToChainCodePathFilter< TInputPath, TOutputChainCodePath >
::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "MaximallyConnected: " << m_MaximallyConnected << std::endl;
}
} // end namespace itk
#endif
|
/**
* @file random.hpp
*
* Miscellaneous math random-related routines.
*
* mlpack is free software; you may redistribute it and/or modify it under the
* terms of the 3-clause BSD license. You should have received a copy of the
* 3-clause BSD license along with mlpack. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef MLPACK_CORE_MATH_RANDOM_HPP
#define MLPACK_CORE_MATH_RANDOM_HPP
#include <mlpack/prereqs.hpp>
#include <mlpack/mlpack_export.hpp>
#include <random>
namespace mlpack {
namespace math /** Miscellaneous math routines. */ {
/**
* MLPACK_EXPORT is required for global variables; it exports the symbols
* correctly on Windows.
*/
// Global random object.
extern MLPACK_EXPORT std::mt19937 randGen;
// Global uniform distribution.
extern MLPACK_EXPORT std::uniform_real_distribution<> randUniformDist;
// Global normal distribution.
extern MLPACK_EXPORT std::normal_distribution<> randNormalDist;
/**
* Set the random seed used by the random functions (Random() and RandInt()).
* The seed is casted to a 32-bit integer before being given to the random
* number generator, but a size_t is taken as a parameter for API consistency.
*
* @param seed Seed for the random number generator.
*/
inline void RandomSeed(const size_t seed)
{
randGen.seed((uint32_t) seed);
srand((unsigned int) seed);
#if ARMA_VERSION_MAJOR > 3 || \
(ARMA_VERSION_MAJOR == 3 && ARMA_VERSION_MINOR >= 930)
// Armadillo >= 3.930 has its own random number generator internally that we
// need to set the seed for also.
arma::arma_rng::set_seed(seed);
#endif
}
/**
* Generates a uniform random number between 0 and 1.
*/
inline double Random()
{
return randUniformDist(randGen);
}
/**
* Generates a uniform random number in the specified range.
*/
inline double Random(const double lo, const double hi)
{
return lo + (hi - lo) * randUniformDist(randGen);
}
/**
* Generates a uniform random integer.
*/
inline int RandInt(const int hiExclusive)
{
return (int) std::floor((double) hiExclusive * randUniformDist(randGen));
}
/**
* Generates a uniform random integer.
*/
inline int RandInt(const int lo, const int hiExclusive)
{
return lo + (int) std::floor((double) (hiExclusive - lo)
* randUniformDist(randGen));
}
/**
* Generates a normally distributed random number with mean 0 and variance 1.
*/
inline double RandNormal()
{
return randNormalDist(randGen);
}
/**
* Generates a normally distributed random number with specified mean and
* variance.
*
* @param mean Mean of distribution.
* @param variance Variance of distribution.
*/
inline double RandNormal(const double mean, const double variance)
{
return variance * randNormalDist(randGen) + mean;
}
/**
* Obtains no more than maxNumSamples distinct samples. Each sample belongs to
* [loInclusive, hiExclusive).
*
* @param loInclusive The lower bound (inclusive).
* @param hiExclusive The high bound (exclusive).
* @param maxNumSamples The maximum number of samples to obtain.
* @param distinctSamples The samples that will be obtained.
*/
inline void ObtainDistinctSamples(const size_t loInclusive,
const size_t hiExclusive,
const size_t maxNumSamples,
arma::uvec& distinctSamples)
{
const size_t samplesRangeSize = hiExclusive - loInclusive;
if (samplesRangeSize > maxNumSamples)
{
arma::Col<size_t> samples;
samples.zeros(samplesRangeSize);
for (size_t i = 0; i < maxNumSamples; i++)
samples [ (size_t) math::RandInt(samplesRangeSize) ]++;
distinctSamples = arma::find(samples > 0);
if (loInclusive > 0)
distinctSamples += loInclusive;
}
else
{
distinctSamples.set_size(samplesRangeSize);
for (size_t i = 0; i < samplesRangeSize; i++)
distinctSamples[i] = loInclusive + i;
}
}
} // namespace math
} // namespace mlpack
#endif // MLPACK_CORE_MATH_MATH_LIB_HPP
|
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) Berkeley Softworks 1990 -- All Rights Reserved
PROJECT: PC GEOS
MODULE: Epson 48-jet printer driver
FILE: epson48bj220Info.asm
AUTHOR: Tsutomu Owa
REVISION HISTORY:
Name Date Description
---- ---- -----------
Owa 1/94 Initial revision
DESCRIPTION:
This file contains the device information for the Epson BJ220 printer
Other Printers Supported by this resource:
$Id: epson48bj220Info.asm,v 1.1 97/04/18 11:54:45 newdeal Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
;----------------------------------------------------------------------------
; Canon BJ-220 printer
;----------------------------------------------------------------------------
bj220Info segment resource
; info blocks
PrinterInfo < ; ---- PrinterType -------------
< PT_RASTER,
BMF_MONO >,
; ---- PrinterConnections ------
< IC_NO_IEEE488,
CC_NO_CUSTOM,
SC_NO_SCSI,
RC_NO_RS232C,
CC_CENTRONICS,
FC_FILE,
AC_NO_APPLETALK >,
; ---- PrinterSmarts -----------
PS_DUMB_RASTER,
;-------Custom Entry Routine-------
NULL,
;-------Custom Exit Routine-------
NULL,
; ---- Mode Info Offsets -------
offset bj220lowRes,
offset bj220medRes,
offset bj220hiRes,
offset printerFontInfo:lq850draft,
offset printerFontInfo:lq850nlq,
; ---- Font Geometry -----------
offset bj220fontGeometries,
; ---- Symbol Set list -----------
NULL,
; ---- PaperMargins ------------
< 10, ; Tractor Margins
10, ;
12, ;
32>, ;
<10, ; ASF Margins, 3.4mm
10, ; 3mm
12, ; 1.5mm (A3 portrait 4mm)
32>, ; 8mm (6.4mm), + 5mm
; ---- PaperInputOptions -------
< MF_MANUAL1,
TF_NO_TRACTOR,
ASF_TRAY1 >,
; ---- PaperOutputOptions ------
< OC_NO_COPIES,
PS_REVERSE,
OD_SIMPLEX,
SO_NO_STAPLER,
OS_NO_SORTER,
OB_NO_OUTPUTBIN >,
;
842, ; paper width (points). A3
NULL, ; Main UI
ASF1BinOnlyOptionsDialogBox, ; Options UI
PrintEvalASF1BinOnly ; eval routine address
>
;----------------------------------------------------------------------------
; Graphics modes info
;----------------------------------------------------------------------------
bj220lowRes GraphicsProperties < LO_RES_X_RES, ; xres
LO_RES_Y_RES, ; yres
LO_RES_BAND_HEIGHT, ; band height
LO_RES_BUFF_HEIGHT, ; buffer height
LO_RES_INTERLEAVE_FACTOR, ;#interleaves
BMF_MONO, ;color format
NULL > ; color format
bj220medRes GraphicsProperties < MED_RES_X_RES, ; xres
MED_RES_Y_RES, ; yres
MED_RES_BAND_HEIGHT, ; band height
MED_RES_BUFF_HEIGHT, ; buffer height
MED_RES_INTERLEAVE_FACTOR, ;#interleaves
BMF_MONO, ;color format
handle gamma175 > ; color format
bj220hiRes GraphicsProperties < HI_RES_X_RES, ; xres
HI_RES_Y_RES, ; yres
HI_RES_BAND_HEIGHT, ; band height
HI_RES_BUFF_HEIGHT, ; buffer height
HI_RES_INTERLEAVE_FACTOR, ;#interleaves
BMF_MONO, ;color format
handle gamma20 > ; color format
;----------------------------------------------------------------------------
; Text modes info
;----------------------------------------------------------------------------
;need to add geometries in ascending pointsize, grouped by font
bj220fontGeometries FontGeometry \
< FID_DTC_URW_ROMAN,
8,
offset bj220_8ptpitchTab >,
< FID_DTC_URW_ROMAN,
12,
offset bj220_12ptpitchTab >,
< FID_DTC_URW_ROMAN,
24,
offset bj220_24ptpitchTab >,
< FID_DTC_URW_SANS,
8,
offset bj220_8ptpitchTab >,
< FID_DTC_URW_SANS,
12,
offset bj220_12ptpitchTab >,
< FID_DTC_URW_SANS,
24,
offset bj220_24ptpitchTab >
word FID_INVALID ;table terminator
bj220_8ptpitchTab label byte
byte TP_15_PITCH
byte TP_PROPORTIONAL ;"table Terminator"
bj220_12ptpitchTab label byte
byte TP_20_PITCH
byte TP_17_PITCH
byte TP_12_PITCH
byte TP_10_PITCH
byte TP_6_PITCH
byte TP_5_PITCH
byte TP_PROPORTIONAL ;"table Terminator"
bj220_24ptpitchTab label byte
byte TP_12_PITCH
byte TP_10_PITCH
byte TP_6_PITCH
byte TP_5_PITCH
byte TP_PROPORTIONAL ;"table Terminator"
bj220Info ends
|
; A001570: Numbers k such that k^2 is centered hexagonal.
; Submitted by Jon Maiga
; 1,13,181,2521,35113,489061,6811741,94875313,1321442641,18405321661,256353060613,3570537526921,49731172316281,692665874901013,9647591076297901,134373609193269601,1871582937629476513,26067787517619401581,363077442309042145621,5057016404808970637113,70435152225016546773961,981035114745422684198341,13664056454210901032002813,190315755244207191763841041,2650756516964689783661771761,36920275482261449779500963613,514233100234695607129351718821,7162343127803477050031423099881
mov $3,1
lpb $0
sub $0,1
add $2,$3
add $2,$3
add $3,$2
lpe
pow $3,2
mov $0,$3
div $0,8
mul $0,12
add $0,1
|
copyright zengfr site:http://github.com/zengfr/romhack
07500E move.b (A0)+, ($a5,A6) [etc+A4]
075012 move.b (A0)+, ($a6,A6) [etc+A5]
08BE86 move.b D0, ($a5,A6) [etc+A4]
08BE8A move.b D0, ($a6,A6) [etc+A5]
08C0FE move.b D0, ($a5,A6)
08C102 move.b D0, ($a6,A6) [etc+A5]
08C64A move.b ($3,A6), ($a5,A6) [etc+A8]
08C650 lea ($3274,A5), A0
copyright zengfr site:http://github.com/zengfr/romhack
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.