text stringlengths 1 1.05M |
|---|
// This file has been generated by Py++.
#ifndef CompositeDragger_hpp__pyplusplus_wrapper
#define CompositeDragger_hpp__pyplusplus_wrapper
void register_CompositeDragger_class();
#endif//CompositeDragger_hpp__pyplusplus_wrapper
|
//
// Copyright 2013 Timothy John Giese
//
#ifndef _tdbsc_fft_hpp_
#define _tdbsc_fft_hpp_
void tdbsc_renormalize
( int const order,
int const * dimsize,
double const * minmax,
double * data );
#endif
|
;extcodecopy(0x027F633732930a97FEF86051db2b5790d63373F6, 0, 1, 20)
;log1(0, 32, codesize());
;return(0, 32)
codecopy(0, $contract, #contract)
return(0, #contract)
@contract{
mstore(0, 0x42434546)
return(0, 31)
}
|
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// test_const.cpp
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// compile only
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/tracking.hpp>
using namespace boost::archive;
struct A {
template<class Archive>
void serialize(Archive & ar, unsigned int version) {
}
};
void f1(text_oarchive & oa, A & a){
oa << BOOST_SERIALIZATION_NVP(a);
}
|
// MESSAGE TRAJECTORY_REPRESENTATION_WAYPOINTS support class
#pragma once
namespace mavlink {
namespace common {
namespace msg {
/**
* @brief TRAJECTORY_REPRESENTATION_WAYPOINTS message
*
* Describe a trajectory using an array of up-to 5 waypoints in the local frame.
*/
struct TRAJECTORY_REPRESENTATION_WAYPOINTS : mavlink::Message {
static constexpr msgid_t MSG_ID = 332;
static constexpr size_t LENGTH = 229;
static constexpr size_t MIN_LENGTH = 229;
static constexpr uint8_t CRC_EXTRA = 91;
static constexpr auto NAME = "TRAJECTORY_REPRESENTATION_WAYPOINTS";
uint64_t time_usec; /*< [us] Timestamp (UNIX Epoch time or time since system boot). The receiving end can infer timestamp format (since 1.1.1970 or since system boot) by checking for the magnitude the number. */
uint8_t valid_points; /*< Number of valid points (up-to 5 waypoints are possible) */
std::array<float, 5> pos_x; /*< [m] X-coordinate of waypoint, set to NaN if not being used */
std::array<float, 5> pos_y; /*< [m] Y-coordinate of waypoint, set to NaN if not being used */
std::array<float, 5> pos_z; /*< [m] Z-coordinate of waypoint, set to NaN if not being used */
std::array<float, 5> vel_x; /*< [m/s] X-velocity of waypoint, set to NaN if not being used */
std::array<float, 5> vel_y; /*< [m/s] Y-velocity of waypoint, set to NaN if not being used */
std::array<float, 5> vel_z; /*< [m/s] Z-velocity of waypoint, set to NaN if not being used */
std::array<float, 5> acc_x; /*< [m/s/s] X-acceleration of waypoint, set to NaN if not being used */
std::array<float, 5> acc_y; /*< [m/s/s] Y-acceleration of waypoint, set to NaN if not being used */
std::array<float, 5> acc_z; /*< [m/s/s] Z-acceleration of waypoint, set to NaN if not being used */
std::array<float, 5> pos_yaw; /*< [rad] Yaw angle, set to NaN if not being used */
std::array<float, 5> vel_yaw; /*< [rad/s] Yaw rate, set to NaN if not being used */
inline std::string get_name(void) const override
{
return NAME;
}
inline Info get_message_info(void) const override
{
return { MSG_ID, LENGTH, MIN_LENGTH, CRC_EXTRA };
}
inline std::string to_yaml(void) const override
{
std::stringstream ss;
ss << NAME << ":" << std::endl;
ss << " time_usec: " << time_usec << std::endl;
ss << " valid_points: " << +valid_points << std::endl;
ss << " pos_x: [" << to_string(pos_x) << "]" << std::endl;
ss << " pos_y: [" << to_string(pos_y) << "]" << std::endl;
ss << " pos_z: [" << to_string(pos_z) << "]" << std::endl;
ss << " vel_x: [" << to_string(vel_x) << "]" << std::endl;
ss << " vel_y: [" << to_string(vel_y) << "]" << std::endl;
ss << " vel_z: [" << to_string(vel_z) << "]" << std::endl;
ss << " acc_x: [" << to_string(acc_x) << "]" << std::endl;
ss << " acc_y: [" << to_string(acc_y) << "]" << std::endl;
ss << " acc_z: [" << to_string(acc_z) << "]" << std::endl;
ss << " pos_yaw: [" << to_string(pos_yaw) << "]" << std::endl;
ss << " vel_yaw: [" << to_string(vel_yaw) << "]" << std::endl;
return ss.str();
}
inline void serialize(mavlink::MsgMap &map) const override
{
map.reset(MSG_ID, LENGTH);
map << time_usec; // offset: 0
map << pos_x; // offset: 8
map << pos_y; // offset: 28
map << pos_z; // offset: 48
map << vel_x; // offset: 68
map << vel_y; // offset: 88
map << vel_z; // offset: 108
map << acc_x; // offset: 128
map << acc_y; // offset: 148
map << acc_z; // offset: 168
map << pos_yaw; // offset: 188
map << vel_yaw; // offset: 208
map << valid_points; // offset: 228
}
inline void deserialize(mavlink::MsgMap &map) override
{
map >> time_usec; // offset: 0
map >> pos_x; // offset: 8
map >> pos_y; // offset: 28
map >> pos_z; // offset: 48
map >> vel_x; // offset: 68
map >> vel_y; // offset: 88
map >> vel_z; // offset: 108
map >> acc_x; // offset: 128
map >> acc_y; // offset: 148
map >> acc_z; // offset: 168
map >> pos_yaw; // offset: 188
map >> vel_yaw; // offset: 208
map >> valid_points; // offset: 228
}
};
} // namespace msg
} // namespace common
} // namespace mavlink
|
; Listing generated by Microsoft (R) Optimizing Compiler Version 19.21.27702.2
; Generated by VC++ for Common Language Runtime
.file "C:\Users\gavra\AppData\Local\Temp\.NETFramework,Version=v4.7.2.AssemblyAttributes.cpp"
|
; A186681: Total number of n-digit numbers requiring 17 positive biquadrates in their representation as sum of biquadrates.
; 0,3,30,30,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
sub $0,1
mul $0,2
mov $1,1
mov $3,2
lpb $0
mov $2,6
mov $3,$0
mov $0,0
bin $2,$3
mov $1,$2
mov $3,$2
lpe
sub $0,$3
sub $1,$0
|
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#define SITK_TEMPLATE_EXPLICIT_EXPLICITITK
#include "sitkExplicitITKVectorImage.h"
#undef SITK_TEMPLATE_EXPLICIT_EXPLICITITK
#include "sitkExplicitITK.h"
template class SITKExplicit_EXPORT itk::VectorImage<double, 2u>;
template class SITKExplicit_EXPORT itk::VectorImage<double, 3u>;
template class SITKExplicit_EXPORT itk::VectorImage<float, 2u>;
template class SITKExplicit_EXPORT itk::VectorImage<float, 3u>;
template class SITKExplicit_EXPORT itk::VectorImage<int, 2u>;
template class SITKExplicit_EXPORT itk::VectorImage<int, 3u>;
template class SITKExplicit_EXPORT itk::VectorImage<long, 2u>;
template class SITKExplicit_EXPORT itk::VectorImage<long, 3u>;
template class SITKExplicit_EXPORT itk::VectorImage<long long, 2u>;
template class SITKExplicit_EXPORT itk::VectorImage<long long, 3u>;
template class SITKExplicit_EXPORT itk::VectorImage<short, 2u>;
template class SITKExplicit_EXPORT itk::VectorImage<short, 3u>;
template class SITKExplicit_EXPORT itk::VectorImage<signed char, 2u>;
template class SITKExplicit_EXPORT itk::VectorImage<signed char, 3u>;
template class SITKExplicit_EXPORT itk::VectorImage<unsigned char, 2u>;
template class SITKExplicit_EXPORT itk::VectorImage<unsigned char, 3u>;
template class SITKExplicit_EXPORT itk::VectorImage<unsigned int, 2u>;
template class SITKExplicit_EXPORT itk::VectorImage<unsigned int, 3u>;
template class SITKExplicit_EXPORT itk::VectorImage<unsigned long, 2u>;
template class SITKExplicit_EXPORT itk::VectorImage<unsigned long, 3u>;
template class SITKExplicit_EXPORT itk::VectorImage<unsigned long long, 2u>;
template class SITKExplicit_EXPORT itk::VectorImage<unsigned long long, 3u>;
template class SITKExplicit_EXPORT itk::VectorImage<unsigned short, 2u>;
template class SITKExplicit_EXPORT itk::VectorImage<unsigned short, 3u>;
|
/*
* This file is part of cryptopp-bindings-api.
*
* (c) Stephen Berquet <stephen.berquet@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
#include "src/exception/api_exception.h"
#include "src/symmetric/cipher/authenticated/api_authenticated_symmetric_cipher_ccm.h"
#include "src/symmetric/cipher/block/api_block_cipher_aes.h"
#include "src/utils/api_hex_utils.h"
#include "tests/test_api_assertions.h"
#include <gtest/gtest.h>
TEST(AuthenticatedSymmetricCipherCcmTest, inheritance) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
EXPECT_TRUE(0 != dynamic_cast<CryptoppApi::SymmetricCipherInterface*>(&mode));
EXPECT_TRUE(0 != dynamic_cast<CryptoppApi::SymmetricTransformationInterface*>(&mode));
EXPECT_TRUE(0 != dynamic_cast<CryptoppApi::AuthenticatedSymmetricCipherInterface*>(&mode));
EXPECT_TRUE(0 != dynamic_cast<CryptoppApi::AuthenticatedSymmetricCipherAbstract*>(&mode));
EXPECT_TRUE(0 != dynamic_cast<CryptoppApi::SymmetricKeyAbstract*>(&mode));
EXPECT_TRUE(0 != dynamic_cast<CryptoppApi::SymmetricIvAbstract*>(&mode));
}
TEST(AuthenticatedSymmetricCipherCcmTest, infos) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
EXPECT_STREQ("ccm(aes)", mode.getName());
EXPECT_EQ(1, mode.getBlockSize());
EXPECT_EQ(16, mode.getDigestSize());
}
TEST(AuthenticatedSymmetricCipherCcmTest, isValidKeyLength) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
EXPECT_TRUE(mode.isValidKeyLength(16));
EXPECT_FALSE(mode.isValidKeyLength(15));
EXPECT_FALSE(mode.isValidKeyLength(17));
EXPECT_TRUE(mode.isValidKeyLength(24));
EXPECT_FALSE(mode.isValidKeyLength(23));
EXPECT_FALSE(mode.isValidKeyLength(25));
EXPECT_TRUE(mode.isValidKeyLength(32));
EXPECT_FALSE(mode.isValidKeyLength(31));
EXPECT_FALSE(mode.isValidKeyLength(33));
}
TEST(AuthenticatedSymmetricCipherCcmTest, isValidIvLength) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
EXPECT_FALSE(mode.isValidIvLength(0));
EXPECT_FALSE(mode.isValidIvLength(2));
EXPECT_TRUE(mode.isValidIvLength(7));
EXPECT_TRUE(mode.isValidIvLength(13));
EXPECT_FALSE(mode.isValidIvLength(15));
}
TEST(AuthenticatedSymmetricCipherCcmTest, setGetKey) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
// build keys
byte *key128;
byte *key192;
byte *key256;
size_t key128Length = 0;
size_t key192Length = 0;
size_t key256Length = 0;
CryptoppApi::HexUtils::hex2bin("0102030405060708090a0b0c0d0e0f10", 32, &key128, key128Length);
CryptoppApi::HexUtils::hex2bin("0102030405060708090a0b0c0d0e0f101112131415161718", 48, &key192, key192Length);
CryptoppApi::HexUtils::hex2bin("0102030405060708090a0b0c0d0e0f1011121314151617181901020304050607", 64, &key256, key256Length);
// set/get keys
size_t key0Length = mode.getKeyLength();
mode.setKey(key128, key128Length);
size_t key128GetLength = mode.getKeyLength();
byte key128Get[key128GetLength];
mode.getKey(key128Get);
mode.setKey(key192, key192Length);
size_t key192GetLength = mode.getKeyLength();
byte key192Get[key192GetLength];
mode.getKey(key192Get);
mode.setKey(key256, key256Length);
size_t key256GetLength = mode.getKeyLength();
byte key256Get[key256GetLength];
mode.getKey(key256Get);
// test keys
EXPECT_EQ(0, key0Length);
EXPECT_BYTE_ARRAY_EQ(key128, key128Length, key128Get, key128GetLength);
EXPECT_BYTE_ARRAY_EQ(key192, key192Length, key192Get, key192GetLength);
EXPECT_BYTE_ARRAY_EQ(key256, key256Length, key256Get, key256GetLength);
delete[] key128;
delete[] key192;
delete[] key256;
}
TEST(AuthenticatedSymmetricCipherCcmTest, setGetIv) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
// build iv
byte *iv;
size_t ivLength = 0;
CryptoppApi::HexUtils::hex2bin("0102030405060708090a0b0c0d", 26, &iv, ivLength);
// set/get iv
size_t iv0Length = mode.getIvLength();
mode.setIv(iv, ivLength);
size_t ivGetLength = mode.getIvLength();
byte ivGet[ivGetLength];
mode.getIv(ivGet);
// test ivs
EXPECT_EQ(0, iv0Length);
EXPECT_BYTE_ARRAY_EQ(iv, ivLength, ivGet, ivGetLength);
delete[] iv;
}
TEST(AuthenticatedSymmetricCipherCcmTest, encrypt) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
// build key
byte *key;
size_t keyLength = 0;
CryptoppApi::HexUtils::hex2bin("c0c1c2c3c4c5c6c7c8c9cacbcccdcecf", 32, &key, keyLength);
// build iv
byte *iv;
size_t ivLength;
CryptoppApi::HexUtils::hex2bin("00000003020100a0a1a2a3a4a5", 26, &iv, ivLength);
mode.setIv(iv, ivLength);
// build blocks
byte *block1;
byte *block2;
size_t block1Length = 0;
size_t block2Length = 0;
CryptoppApi::HexUtils::hex2bin("08090a0b0c0d0e0f101112", 22, &block1, block1Length);
CryptoppApi::HexUtils::hex2bin("131415161718191a1b1c1d1e", 24, &block2, block2Length);
// aes128
size_t digestLength = 0;
byte *expected1;
byte *expected2;
byte *expected3;
CryptoppApi::HexUtils::hex2bin("588c979a61c663d2f066d0", 22, &expected1, block1Length);
CryptoppApi::HexUtils::hex2bin("c2c0f989806d5f6b61dac384", 24, &expected2, block2Length);
CryptoppApi::HexUtils::hex2bin("7c2051a7ae200bcf", 16, &expected3, digestLength);
byte output1[block1Length];
byte output2[block2Length];
byte output3[digestLength];
mode.setDigestSize(digestLength);
mode.specifyDataSize(23, 0);
mode.setKey(key, keyLength);
mode.encrypt(block1, output1, block1Length);
mode.encrypt(block2, output2, block2Length);
mode.finalizeEncryption(output3);
EXPECT_BYTE_ARRAY_EQ(expected1, block1Length, output1, block1Length);
EXPECT_BYTE_ARRAY_EQ(expected2, block2Length, output2, block2Length);
EXPECT_BYTE_ARRAY_EQ(expected3, digestLength, output3, digestLength);
delete[] expected1;
delete[] expected2;
delete[] expected3;
delete[] iv;
delete[] key;
delete[] block1;
delete[] block2;
}
TEST(AuthenticatedSymmetricCipherCcmTest, decrypt) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
// build key
byte *key;
size_t keyLength = 0;
CryptoppApi::HexUtils::hex2bin("c0c1c2c3c4c5c6c7c8c9cacbcccdcecf", 32, &key, keyLength);
// build iv
byte *iv;
size_t ivLength;
CryptoppApi::HexUtils::hex2bin("00000003020100a0a1a2a3a4a5", 26, &iv, ivLength);
mode.setIv(iv, ivLength);
// build expected data
byte *expected1;
byte *expected2;
byte *expected3;
size_t block1Length = 0;
size_t block2Length = 0;
size_t digestLength = 0;
CryptoppApi::HexUtils::hex2bin("08090a0b0c0d0e0f101112", 22, &expected1, block1Length);
CryptoppApi::HexUtils::hex2bin("131415161718191a1b1c1d1e", 24, &expected2, block2Length);
CryptoppApi::HexUtils::hex2bin("7c2051a7ae200bcf", 16, &expected3, digestLength);
// aes128
byte *block1;
byte *block2;
byte output1[block1Length];
byte output2[block2Length];
byte output3[digestLength];
CryptoppApi::HexUtils::hex2bin("588c979a61c663d2f066d0", 22, &block1, block1Length);
CryptoppApi::HexUtils::hex2bin("c2c0f989806d5f6b61dac384", 24, &block2, block2Length);
mode.setDigestSize(digestLength);
mode.specifyDataSize(23, 0);
mode.setKey(key, keyLength);
mode.decrypt(block1, output1, block1Length);
mode.decrypt(block2, output2, block2Length);
mode.finalizeDecryption(output3);
EXPECT_BYTE_ARRAY_EQ(expected1, block1Length, output1, block1Length);
EXPECT_BYTE_ARRAY_EQ(expected2, block2Length, output2, block2Length);
EXPECT_BYTE_ARRAY_EQ(expected3, digestLength, output3, digestLength);
delete[] block1;
delete[] block2;
delete[] iv;
delete[] key;
delete[] expected1;
delete[] expected2;
delete[] expected3;
}
TEST(AuthenticatedSymmetricCipherCcmTest, restartEncryption) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
// build key
byte *key;
size_t keyLength = 0;
CryptoppApi::HexUtils::hex2bin("c0c1c2c3c4c5c6c7c8c9cacbcccdcecf", 32, &key, keyLength);
// build iv
byte *iv;
size_t ivLength;
CryptoppApi::HexUtils::hex2bin("00000003020100a0a1a2a3a4a5", 26, &iv, ivLength);
mode.setIv(iv, ivLength);
// build blocks
byte *block1;
byte *block2;
size_t block1Length = 0;
size_t block2Length = 0;
CryptoppApi::HexUtils::hex2bin("08090a0b0c0d0e0f101112", 22, &block1, block1Length);
CryptoppApi::HexUtils::hex2bin("131415161718191a1b1c1d1e", 24, &block2, block2Length);
// calculate actual data
size_t digestLength = 0;
byte *expected1;
byte *expected2;
byte *expected3;
CryptoppApi::HexUtils::hex2bin("588c979a61c663d2f066d0", 22, &expected1, block1Length);
CryptoppApi::HexUtils::hex2bin("439188877ad374c7fb6bdfcf", 24, &expected2, block2Length);
CryptoppApi::HexUtils::hex2bin("e8599abbfb0fa24247ceb346d0e68532", 32, &expected3, digestLength);
byte output1[block1Length];
byte output2[block2Length];
byte output3[digestLength];
mode.setKey(key, keyLength);
mode.specifyDataSize(11, 0);
mode.encrypt(block1, output1, block1Length);
mode.restart();
mode.specifyDataSize(12, 0);
mode.encrypt(block2, output2, block2Length);
mode.finalizeEncryption(output3);
EXPECT_BYTE_ARRAY_EQ(expected1, block1Length, output1, block1Length);
EXPECT_BYTE_ARRAY_EQ(expected2, block2Length, output2, block2Length);
EXPECT_BYTE_ARRAY_EQ(expected3, digestLength, output3, digestLength);
delete[] expected1;
delete[] expected2;
delete[] expected3;
delete[] key;
delete[] iv;
delete[] block1;
delete[] block2;
}
TEST(AuthenticatedSymmetricCipherCcmTest, restartDecryption) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
// build key
byte *key;
size_t keyLength = 0;
CryptoppApi::HexUtils::hex2bin("c0c1c2c3c4c5c6c7c8c9cacbcccdcecf", 32, &key, keyLength);
// build iv
byte *iv;
size_t ivLength;
CryptoppApi::HexUtils::hex2bin("00000003020100a0a1a2a3a4a5", 26, &iv, ivLength);
mode.setIv(iv, ivLength);
// build blocks
byte *block1;
byte *block2;
size_t block1Length = 0;
size_t block2Length = 0;
size_t digestLength = 0;
CryptoppApi::HexUtils::hex2bin("588c979a61c663d2f066d0", 22, &block1, block1Length);
CryptoppApi::HexUtils::hex2bin("c2c0f989806d5f6b61dac384", 24, &block2, block2Length);
// calculate actual data
byte *expected1;
byte *expected2;
byte *expected3;
CryptoppApi::HexUtils::hex2bin("08090a0b0c0d0e0f101112", 22, &expected1, block1Length);
CryptoppApi::HexUtils::hex2bin("92456418eda632b681ad0155", 24, &expected2, block2Length);
CryptoppApi::HexUtils::hex2bin("dab641c7493a27b8127514bd5f423b23", 32, &expected3, digestLength);
byte output1[block1Length];
byte output2[block2Length];
byte output3[digestLength];
mode.setKey(key, keyLength);
mode.specifyDataSize(11, 0);
mode.decrypt(block1, output1, block1Length);
mode.restart();
mode.specifyDataSize(12, 0);
mode.decrypt(block2, output2, block2Length);
mode.finalizeDecryption(output3);
EXPECT_BYTE_ARRAY_EQ(expected1, block1Length, output1, block1Length);
EXPECT_BYTE_ARRAY_EQ(expected2, block2Length, output2, block2Length);
EXPECT_BYTE_ARRAY_EQ(expected3, digestLength, output3, digestLength);
delete[] expected1;
delete[] expected2;
delete[] expected3;
delete[] key;
delete[] iv;
delete[] block1;
delete[] block2;
}
TEST(AuthenticatedSymmetricCipherCcmTest, encryptWithAad) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
// build key
byte *key;
size_t keyLength = 0;
CryptoppApi::HexUtils::hex2bin("c0c1c2c3c4c5c6c7c8c9cacbcccdcecf", 32, &key, keyLength);
// build iv
byte *iv;
size_t ivLength;
CryptoppApi::HexUtils::hex2bin("00000003020100a0a1a2a3a4a5", 26, &iv, ivLength);
mode.setIv(iv, ivLength);
// build blocks
byte *block1;
byte *block2;
byte *aad;
size_t block1Length = 0;
size_t block2Length = 0;
size_t aadLength = 0;
CryptoppApi::HexUtils::hex2bin("d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a72", 64, &block1, block1Length);
CryptoppApi::HexUtils::hex2bin("1c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39", 56, &block2, block2Length);
CryptoppApi::HexUtils::hex2bin("feedfacedeadbeeffeedfacedeadbeefabaddad2", 40, &aad, aadLength);
// aes128
byte *expected1;
byte *expected2;
byte *expected3;
size_t digestLength = 0;
CryptoppApi::HexUtils::hex2bin("89b4afb4954f6b38452ecb147b19b90df3e1d829d3ea6d254a40ac3b545c87fd", 64, &expected1, block1Length);
CryptoppApi::HexUtils::hex2bin("021e99bf795762d89d611c7bbe452d49ddde077fff1c34366f875232", 56, &expected2, block2Length);
CryptoppApi::HexUtils::hex2bin("fc738cbb02a4a7a8972fc20d", 24, &expected3, digestLength);
byte output1[block1Length];
byte output2[block2Length];
byte output3[digestLength];
mode.setKey(key, keyLength);
mode.specifyDataSize(60, 20);
mode.setDigestSize(digestLength);
mode.addEncryptionAdditionalData(aad, aadLength);
mode.encrypt(block1, output1, block1Length);
mode.encrypt(block2, output2, block2Length);
mode.finalizeEncryption(output3);
EXPECT_BYTE_ARRAY_EQ(expected1, block1Length, output1, block1Length);
EXPECT_BYTE_ARRAY_EQ(expected2, block2Length, output2, block2Length);
EXPECT_BYTE_ARRAY_EQ(expected3, digestLength, output3, digestLength);
delete[] expected1;
delete[] expected2;
delete[] expected3;
delete[] iv;
delete[] key;
delete[] block1;
delete[] block2;
delete[] aad;
}
TEST(AuthenticatedSymmetricCipherCcmTest, decryptWithAad) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
// build key
byte *key;
size_t keyLength = 0;
CryptoppApi::HexUtils::hex2bin("c0c1c2c3c4c5c6c7c8c9cacbcccdcecf", 32, &key, keyLength);
// build iv
byte *iv;
size_t ivLength;
CryptoppApi::HexUtils::hex2bin("00000003020100a0a1a2a3a4a5", 26, &iv, ivLength);
mode.setIv(iv, ivLength);
// build expected data
byte *expected1;
byte *expected2;
byte *expected3;
size_t block1Length = 0;
size_t block2Length = 0;
size_t digestLength = 0;
CryptoppApi::HexUtils::hex2bin("d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a72", 64, &expected1, block1Length);
CryptoppApi::HexUtils::hex2bin("1c3c0c95956809532fcf0e2449a6b525b16aedf5aa0de657ba637b39", 56, &expected2, block2Length);
CryptoppApi::HexUtils::hex2bin("fc738cbb02a4a7a8972fc20d", 24, &expected3, digestLength);
// aes128
size_t aadLength = 0;
byte *block1;
byte *block2;
byte *aad;
CryptoppApi::HexUtils::hex2bin("89b4afb4954f6b38452ecb147b19b90df3e1d829d3ea6d254a40ac3b545c87fd", 64, &block1, block1Length);
CryptoppApi::HexUtils::hex2bin("021e99bf795762d89d611c7bbe452d49ddde077fff1c34366f875232", 56, &block2, block2Length);
CryptoppApi::HexUtils::hex2bin("feedfacedeadbeeffeedfacedeadbeefabaddad2", 40, &aad, aadLength);
byte output1[block1Length];
byte output2[block2Length];
byte output3[digestLength];
mode.setKey(key, keyLength);
mode.specifyDataSize(60, 20);
mode.setDigestSize(digestLength);
mode.addDecryptionAdditionalData(aad, aadLength);
mode.decrypt(block1, output1, block1Length);
mode.decrypt(block2, output2, block2Length);
mode.finalizeDecryption(output3);
EXPECT_BYTE_ARRAY_EQ(expected1, block1Length, output1, block1Length);
EXPECT_BYTE_ARRAY_EQ(expected2, block2Length, output2, block2Length);
EXPECT_BYTE_ARRAY_EQ(expected3, digestLength, output3, digestLength);
delete[] block1;
delete[] block2;
delete[] aad;
delete[] iv;
delete[] key;
delete[] expected1;
delete[] expected2;
delete[] expected3;
}
TEST(AuthenticatedSymmetricCipherCcmTest, encryptAadOnly) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
// build key
byte *key;
size_t keyLength = 0;
CryptoppApi::HexUtils::hex2bin("77be63708971c4e240d1cb79e8d77feb", 32, &key, keyLength);
// build iv
byte *iv;
size_t ivLength;
CryptoppApi::HexUtils::hex2bin("e0e00f19fed7ba0136a797f3", 24, &iv, ivLength);
mode.setIv(iv, ivLength);
// build aad
byte *aad;
size_t aadLength = 0;
CryptoppApi::HexUtils::hex2bin("7a43ec1d9c0a5a78a0b16533a6213cab", 32, &aad, aadLength);
// aes128
size_t digestLength = 0;
byte *expected;
CryptoppApi::HexUtils::hex2bin("b07790c26ada0c6b28576fc70234", 28, &expected, digestLength);
byte output[digestLength];
mode.setKey(key, keyLength);
mode.setDigestSize(digestLength);
mode.specifyDataSize(0, aadLength);
mode.addEncryptionAdditionalData(aad, aadLength);
mode.finalizeEncryption(output);
EXPECT_BYTE_ARRAY_EQ(expected, digestLength, output, digestLength);
delete[] expected;
delete[] iv;
delete[] key;
delete[] aad;
}
TEST(AuthenticatedSymmetricCipherCcmTest, decryptAadOnly) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
// build key
byte *key;
size_t keyLength = 0;
CryptoppApi::HexUtils::hex2bin("77be63708971c4e240d1cb79e8d77feb", 32, &key, keyLength);
// build iv
byte *iv;
size_t ivLength;
CryptoppApi::HexUtils::hex2bin("e0e00f19fed7ba0136a797f3", 24, &iv, ivLength);
mode.setIv(iv, ivLength);
// build aad
byte *aad;
size_t aadLength = 0;
CryptoppApi::HexUtils::hex2bin("7a43ec1d9c0a5a78a0b16533a6213cab", 32, &aad, aadLength);
// aes128
size_t digestLength = 0;
byte *expected;
CryptoppApi::HexUtils::hex2bin("b07790c26ada0c6b28576fc70234", 28, &expected, digestLength);
byte output[digestLength];
mode.setKey(key, keyLength);
mode.setDigestSize(digestLength);
mode.specifyDataSize(0, aadLength);
mode.addDecryptionAdditionalData(aad, aadLength);
mode.finalizeDecryption(output);
EXPECT_BYTE_ARRAY_EQ(expected, digestLength, output, digestLength);
delete[] expected;
delete[] iv;
delete[] key;
delete[] aad;
}
TEST(AuthenticatedSymmetricCipherCcmTest, largeData) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
std::string key("1234567890123456");
std::string iv("123456789012");
mode.setKey(reinterpret_cast<const byte*>(key.c_str()), key.length());
mode.setIv(reinterpret_cast<const byte*>(iv.c_str()), iv.length());
size_t dataSize = 10485760;
byte *input = new byte[dataSize];
byte *output = new byte[dataSize];
memset(input, 125, dataSize);
mode.specifyDataSize(dataSize, dataSize);
mode.addEncryptionAdditionalData(input, dataSize);
mode.addDecryptionAdditionalData(input, dataSize);
mode.encrypt(input, output, dataSize);
mode.decrypt(input, output, dataSize);
delete[] input;
delete[] output;
}
TEST(AuthenticatedSymmetricCipherCcmTest, badSpecifiedLength) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
std::string key("1234567890123456");
std::string iv("123456789012");
mode.setKey(reinterpret_cast<const byte*>(key.c_str()), key.length());
mode.setIv(reinterpret_cast<const byte*>(iv.c_str()), iv.length());
std::string dataStr("12345678901234567");
std::string data2Str("1234567890");
const byte *data = reinterpret_cast<const byte*>(dataStr.c_str());
const byte *data2 = reinterpret_cast<const byte*>(data2Str.c_str());
size_t dataLength = dataStr.length();
size_t data2Length = data2Str.length();
byte output[dataLength];
mode.specifyDataSize(data2Length, data2Length);
EXPECT_THROW_MSG(mode.addEncryptionAdditionalData(data, dataLength), CryptoppApi::Exception, "AAD length doesn't match that given in specifyDataSize (10 expected, 17 given)");
EXPECT_THROW_MSG(mode.addDecryptionAdditionalData(data, dataLength), CryptoppApi::Exception, "AAD length doesn't match that given in specifyDataSize (10 expected, 17 given)");
mode.restart();
mode.addEncryptionAdditionalData(data2, data2Length);
mode.addDecryptionAdditionalData(data2, data2Length);
EXPECT_THROW_MSG(mode.encrypt(data, output, dataLength), CryptoppApi::Exception, "message length doesn't match that given in specifyDataSize (10 expected, 17 given)");
EXPECT_THROW_MSG(mode.decrypt(data, output, dataLength), CryptoppApi::Exception, "message length doesn't match that given in specifyDataSize (10 expected, 17 given)");
}
TEST(AuthenticatedSymmetricCipherCcmTest, invalidKey) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
byte key1[] = {45, 12, 14};
byte key2[0];
EXPECT_THROW_MSG(mode.setKey(key1, 3), CryptoppApi::Exception, "3 is not a valid key length");
EXPECT_THROW_MSG(mode.setKey(key2, 0), CryptoppApi::Exception, "a key is required");
}
TEST(AuthenticatedSymmetricCipherCcmTest, invalidIv) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
byte iv[0];
EXPECT_THROW_MSG(mode.setIv(iv, 0), CryptoppApi::Exception, "an initialization vector is required");
}
TEST(AuthenticatedSymmetricCipherCcmTest, cryptWithoutKey) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
size_t inputLength = mode.getBlockSize();
byte input[inputLength];
byte output[inputLength];
mode.specifyDataSize(inputLength, 0);
EXPECT_THROW_MSG(mode.encrypt(input, output, inputLength), CryptoppApi::Exception, "a key is required");
EXPECT_THROW_MSG(mode.decrypt(input, output, inputLength), CryptoppApi::Exception, "a key is required");
}
TEST(AuthenticatedSymmetricCipherCcmTest, cryptWithoutIv) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
std::string key("1234567890123456");
mode.setKey(reinterpret_cast<const byte*>(key.c_str()), key.length());
size_t inputLength = mode.getBlockSize();
byte input[inputLength];
byte output[inputLength];
mode.specifyDataSize(inputLength, 0);
EXPECT_THROW_MSG(mode.encrypt(input, output, inputLength), CryptoppApi::Exception, "an initialization vector is required");
EXPECT_THROW_MSG(mode.decrypt(input, output, inputLength), CryptoppApi::Exception, "an initialization vector is required");
}
TEST(AuthenticatedSymmetricCipherCcmTest, cryptAadWithoutKey) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
byte input[10];
mode.specifyDataSize(0, 10);
EXPECT_THROW_MSG(mode.addEncryptionAdditionalData(input, 10), CryptoppApi::Exception, "a key is required");
EXPECT_THROW_MSG(mode.addDecryptionAdditionalData(input, 10), CryptoppApi::Exception, "a key is required");
}
TEST(AuthenticatedSymmetricCipherCcmTest, finalizeWithoutKey) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
byte output[mode.getDigestSize()];
EXPECT_THROW_MSG(mode.finalizeEncryption(output), CryptoppApi::Exception, "a key is required");
EXPECT_THROW_MSG(mode.finalizeDecryption(output), CryptoppApi::Exception, "a key is required");
}
TEST(AuthenticatedSymmetricCipherCcmTest, cryptBeforeAad) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode(&cipher);
std::string key("1234567890123456");
std::string iv("123456789012");
mode.setKey(reinterpret_cast<const byte*>(key.c_str()), key.length());
mode.setIv(reinterpret_cast<const byte*>(iv.c_str()), iv.length());
size_t inputLength = mode.getBlockSize();
byte input[inputLength];
byte output[inputLength];
mode.specifyDataSize(inputLength, inputLength);
EXPECT_THROW_MSG(mode.encrypt(input, output, inputLength), CryptoppApi::Exception, "AAD length doesn't match that given in specifyDataSize (1 expected, 0 given)");
EXPECT_THROW_MSG(mode.decrypt(input, output, inputLength), CryptoppApi::Exception, "AAD length doesn't match that given in specifyDataSize (1 expected, 0 given)");
}
TEST(AuthenticatedSymmetricCipherCcmTest, keyNotMatchingUnderlyingOne) {
CryptoppApi::BlockCipherAes cipher;
CryptoppApi::AuthenticatedSymmetricCipherCcm mode1(&cipher);
CryptoppApi::AuthenticatedSymmetricCipherCcm mode2(&cipher);
std::string iv("123456789012");
mode1.setIv(reinterpret_cast<const byte*>(iv.c_str()), iv.length());
std::string key1("1234567890123456");
std::string key2("azertyuiopqwerty");
std::string key3("wxcvbnqsdfghjklm");
mode1.setKey(reinterpret_cast<const byte*>(key1.c_str()), key1.length());
size_t inputLength = mode1.getBlockSize();
byte input[inputLength];
byte output[inputLength];
mode1.specifyDataSize(inputLength, 0);
mode2.specifyDataSize(inputLength, 0);
mode2.setKey(reinterpret_cast<const byte*>(key2.c_str()), key2.length());
EXPECT_THROW_MSG(mode1.encrypt(input, output, inputLength), CryptoppApi::Exception, "key is not matching the one owned by the underlying cipher object");
cipher.setKey(reinterpret_cast<const byte*>(key3.c_str()), key3.length());
EXPECT_THROW_MSG(mode1.encrypt(input, output, inputLength), CryptoppApi::Exception, "key is not matching the one owned by the underlying cipher object");
}
|
-- HUMAN RESOURCE MACHINE PROGRAM --
a:
INBOX
COPYTO 0
INBOX
COPYTO 1
INBOX
COPYTO 2
COMMENT 2
SUB 1
JUMPN b
COMMENT 1
JUMP c
b:
COMMENT 0
COPYFROM 2
COPYTO 3
COPYFROM 1
COPYTO 2
COPYFROM 3
COPYTO 1
c:
COMMENT 4
COPYFROM 2
SUB 0
JUMPN e
COMMENT 6
COMMENT 7
COPYFROM 0
SUB 1
JUMPN d
COPYFROM 0
COPYTO 3
COPYFROM 1
COPYTO 0
COPYFROM 3
COPYTO 1
d:
JUMP f
e:
COMMENT 5
COPYFROM 0
COPYTO 3
COPYFROM 1
COPYTO 0
COPYFROM 2
COPYTO 1
COPYFROM 3
COPYTO 2
f:
COMMENT 3
COPYFROM 0
OUTBOX
COPYFROM 1
OUTBOX
COPYFROM 2
OUTBOX
JUMP a
DEFINE COMMENT 0
eJzTZWBg2Cxvn6uvKJh8QK0udIPONf9qky1+YWaSQaesdmY02BVOvG/HMv+QrdHK59Z/1q+1bNriaJS7
h19373EbjYCrHdZbbyiHHnyoH3PwIdAohrb4rjj27M/V2aWFEzXLtkzWLJOcXhj9Zz1IrqC+0Ke1+bW7
cddJN76e1+6p/df8HSaqRc+fuKTgZW9E/faOk93zJwZMqJpcN6tq8pol0pNDVjlMtN/U1ft8+/aO3D2C
9T6751Yd3cYwCkbBKKAaAADikVFE;
DEFINE COMMENT 1
eJxTZWBg2Cz/KKJPMSbkl0ahD7+unle3XqGPp757TLdeSOoGnYS8q1oR9Tp6qR1HDbZMdjR6PHeBUciq
ZkPZjTp6HDufqmjtMpdbshVoDMN1R5aoVW5dcUdCnhdtjuqv4Avk7StwyVwEkptRoBbtVv494HrNNf/g
urrQTXUJeVNrtUoVK+81+5W87mnOUVvwp+r9MsZWwRUMo2AUjAK6AQCwrjs8;
DEFINE COMMENT 2
eJxzYGBgKFRgiTqhLBmUqLbF7676Fr8dmjEhG3Smp+fpPi/K093bZKI9eZKNxuO5Qgo717qo/lm/QefP
+u+mTVuAWhkifK2DGb0eRcy1v1S1y6GqQc+1rXO777UpIDlOd46SS0VapSD2hvS6UJ3MutDnZUYpz8v+
ZIkUtXVaFsyfDZLrbYiwMu7SMvDo0zJQntBnPH+imaXDxC1+R/pZogK6/2TtmWSfGzpVq1R4mlndlql6
/bGTuhZ79JWudm6Zvgakf8bqCKtLazeYLN30XNduK4f+rm0RVru2Ffq8X/e8aMK6z9V+6yPqQerC1hzd
9n31rXUT1u1c+36d7MawNUu2MoyCUTDCAQDJN2yB;
DEFINE COMMENT 3
eJyzYmBgSJGcPOmDCG/fD8HXPU94efvecFnP0ONSW6DHZb/pDZfPbme+eydKhJVOd4rfO3FYMuKIvXT/
3t0ya5bslrlUdVgy1whoBEOkJm/fXfW6WXXqgivKtLR26eht2PfdtH/vVjOf3SLmTVtEzNcs+W4aM3Ov
ccCEs7ptnRt0VnRt0NHrB+mda9+/d6799DVTnfT6z7swtHK6VzXIee9tMvY/2f0ySHL6kZCuxUdCcveA
1H6pld0oUmS/iT27dDV/RtfiHSkBE34lVzUEpj8vUslpyt+bt6SguOhztWFxVYNhcVvn3rzJk85mWM9g
GAWjYBRgBQBHSmNL;
DEFINE COMMENT 4
eJyzYWBgcJd4n6ivGODtoyQZxKUsmJyoptgmr35tygG1vceB0gyVsrOPNRveOwFiO3veytzkrFXKYqvY
9tz6dY+i3ZbJgi4s8xd5vl82yd9+E0hNsLNze1cQQ+vL3nvNIL5ew86M9d1N+VWTlxRsmcpR8m8ib9+R
/rpZy/sOzgHJpy177b5ghbPT99WKjn7rT7ppbpzsq7lxfhjPhq64uJWfq7euYWjN3jB5kubGmJmaG9cs
ObVBcEXx2p1rAxfdWgfSf3xvqjPjgVTnOwdPuokdiQkRO5KQt2i/Wd3xvW2dx/dumbxo//zZIHW1B0UP
MYyCUTAKUAAAJi1lAw;
DEFINE COMMENT 5
eJyTYWBgiDNOdf5vpHQayGTgirMOfpSjVdqc87n6bEZqx4HEg3OYEt0Xvo0xWgmSf9J80u1KJ4ODdi+D
g8PEQp/YSfPDYiedTWiaYJ97pke0dn13RP2/iXr9NydLTr852X3hnkmCK4y7OHa2NmvtKqhv2sIwCkbB
KBhUAAAb+i9n;
DEFINE COMMENT 6
eJxTYGBgeG8haqFpvcFkrn2uUa23t2GEb5+xmF+E1XbfVOc3rpJBm5zVooOdBZPlvPsrtvvubTL2P9k9
yf/HVGufg3NYbENWVZv8WQ80hqG46FHE9ZqQ1C+109O/1MrmzCh4PHdvXuYix9yuxSB53xlaBgbTzSwv
TlvhenFaf8W76QytDKNgFIyCAQUAiBgzog;
DEFINE COMMENT 7
eJyzY2BgaJRicDihvMHkgBqHfqJayKq3iqWrD0ueW3pWN3HzVrPEzUAlDGJ+K1x3OUxPt7OXzbGzX1Iw
1WlD5XH32Y3rA1Z0nQls6wSpOe5un6sdFJI6L8woZVNdSCpIrKOMx5OlgsdTrdk6mLG1LnR/66OIjCb7
XO/GS1XejYptIDW+Mz6bLZ7NoV83l0O/bMFsm08LJYNMFhqllC34k3VgTn/FxWnO7coT9PqVJ2yZ3D+d
ZX73kpBVzctDVoH0Pt8422bu1g0mZjsumQbvNLMU3MXjKbhrftjUHaVpu7Y9L3LbJFr7fGNVw/ONbZ1L
NwVMAOmZu5VjJ8MoGAWjAAwAn5dk6A;
DEFINE LABEL 0
eJzjYWBg6BR/FDFPen6YuoqeV5vK47nqKu4LfZTcF1bK1s2yl54/u1JWbYG+YtdiHb1zSxlGwSgYBcMK
AABfEBDz;
DEFINE LABEL 1
eJwTZGBgCExnierOlAxSyZnsG1b42v198Wv37FLJILdy2RyWiktVS8vbOouL5s/em5e5KDFRduPq2KPb
fiUf3dZRZn5YsVL0EMMoGAWjYMgCAOEsHbE;
DEFINE LABEL 2
eJwTZWBgeOIx2TfBa4Xr8mAzywehVdYx4YqOm6MyYzdH5ZZPizSrUw5N7bjip9efGxgwYVrkmiWbo3au
DYnq37s7POLI8mCl086ezmcy3JVOb3IWPbTL4eg2hlEwCkbBkAEAtvAkow;
DEFINE LABEL 3
eJyzZWBgmChyzT9c6F7zNqF7J4BchgLOyZN6uQIm/BA82T1PekXXW0W9fpD4K73S1Y5Gt9ZpWv9Zf98u
ZFWFI8v8Csf5s3msePuqTXj7mg0LJ57VPTiHXzdz0SdtrV2ftCOObNBhOPVK7+QFRyO9K1vNAq7uctC7
AjLL2id3zx1v94VifjEz1wdcm+IRvGXy37DHc79GNm0Rik7cvDr24Jyn8Xr9v5JXdImnnuw2SSuc+Cpz
59oVWbIbj2bbbwKZYVar129X9fmAXdXJC4qVVUcPVdhvsquqm1VRs6JrU51im3OLc/udNr3+We0H5yxq
EVzR22C0Mrp6zRKGUTAKRgEcAADovW4T;
|
<%
import collections
import pwnlib.abi
import pwnlib.constants
import pwnlib.shellcraft
%>
<%docstring>setdomainname(name, length) -> str
Invokes the syscall setdomainname.
See 'man 2 setdomainname' for more information.
Arguments:
name(char*): name
len(size_t): len
Returns:
int
</%docstring>
<%page args="name=0, length=0"/>
<%
abi = pwnlib.abi.ABI.syscall()
stack = abi.stack
regs = abi.register_arguments[1:]
allregs = pwnlib.shellcraft.registers.current()
can_pushstr = ['name']
can_pushstr_array = []
argument_names = ['name', 'length']
argument_values = [name, length]
# Load all of the arguments into their destination registers / stack slots.
register_arguments = dict()
stack_arguments = collections.OrderedDict()
string_arguments = dict()
dict_arguments = dict()
array_arguments = dict()
syscall_repr = []
for name, arg in zip(argument_names, argument_values):
if arg is not None:
syscall_repr.append('%s=%r' % (name, arg))
# If the argument itself (input) is a register...
if arg in allregs:
index = argument_names.index(name)
if index < len(regs):
target = regs[index]
register_arguments[target] = arg
elif arg is not None:
stack_arguments[index] = arg
# The argument is not a register. It is a string value, and we
# are expecting a string value
elif name in can_pushstr and isinstance(arg, str):
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_setdomainname']:
if hasattr(pwnlib.constants, syscall):
break
else:
raise Exception("Could not locate any syscalls: %r" % syscalls)
%>
/* setdomainname(${', '.join(syscall_repr)}) */
%for name, arg in string_arguments.items():
${pwnlib.shellcraft.pushstr(arg, append_null=('\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)} |
global load_gdt
load_gdt:
mov eax, [esp + 4] ; get the pointer (the struct's size is 4)
lgdt [eax] ; load the pointer
; new data segment offset
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
; jump to flush the code segment register
jmp 0x08:.flush
.flush:
ret
|
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
L0:
mov (1|M0) f0.0<1>:uw r24.24<0;1,0>:ub
add (4|M0) a0.0<1>:uw r22.0<4;4,1>:w 0x600:uw
|
; Listing generated by Microsoft (R) Optimizing Compiler Version 19.00.24213.1
; Generated by VC++ for Common Language Runtime
.file "C:\Users\roman\AppData\Local\Temp\.NETFramework,Version=v4.5.2.AssemblyAttributes.cpp"
|
; Generated at 6/14/2016 12:11:29 PM
DebugStub_ComAddr dd 1016
%ifndef Exclude_IOPort_Based_Serial
DebugStub_WriteRegister:
push dword EDX
add word DX, 0x3F8
out DX, AL
pop dword EDX
DebugStub_WriteRegister_Exit:
mov dword [static_field__Cosmos_Core_INTs_mLastKnownAddress], DebugStub_WriteRegister_Exit
Ret
DebugStub_ReadRegister:
push dword EDX
add word DX, 0x3F8
in byte AL, DX
pop dword EDX
DebugStub_ReadRegister_Exit:
mov dword [static_field__Cosmos_Core_INTs_mLastKnownAddress], DebugStub_ReadRegister_Exit
Ret
%endif
|
mov r1, $(signed(-5))
abs r1
eq r1, $(signed(5))
add r1, .0
out r1
mov r1, $(signed(5))
abs r1
eq r1, $(signed(5))
add r1, .0
out r1
mov r1, $(signed(0))
abs r1
eq r1, $(signed(0))
add r1, .0
out r1
|
_lotteryTest2: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "types.h"
#include "stat.h"
#include "user.h"
int main(int argc, char *argv[])
{
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 51 push %ecx
e: 83 ec 10 sub $0x10,%esp
settickets(20); // write your own function here
11: 6a 14 push $0x14
13: e8 02 03 00 00 call 31a <settickets>
for(k=0;k<loop;k++)
{
//asm(nop);
}
}
exit();
18: e8 55 02 00 00 call 272 <exit>
1d: 66 90 xchg %ax,%ax
1f: 90 nop
00000020 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
20: 55 push %ebp
21: 89 e5 mov %esp,%ebp
23: 53 push %ebx
24: 8b 45 08 mov 0x8(%ebp),%eax
27: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
2a: 89 c2 mov %eax,%edx
2c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
30: 83 c1 01 add $0x1,%ecx
33: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
37: 83 c2 01 add $0x1,%edx
3a: 84 db test %bl,%bl
3c: 88 5a ff mov %bl,-0x1(%edx)
3f: 75 ef jne 30 <strcpy+0x10>
;
return os;
}
41: 5b pop %ebx
42: 5d pop %ebp
43: c3 ret
44: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
4a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000050 <strcmp>:
int
strcmp(const char *p, const char *q)
{
50: 55 push %ebp
51: 89 e5 mov %esp,%ebp
53: 53 push %ebx
54: 8b 55 08 mov 0x8(%ebp),%edx
57: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
5a: 0f b6 02 movzbl (%edx),%eax
5d: 0f b6 19 movzbl (%ecx),%ebx
60: 84 c0 test %al,%al
62: 75 1c jne 80 <strcmp+0x30>
64: eb 2a jmp 90 <strcmp+0x40>
66: 8d 76 00 lea 0x0(%esi),%esi
69: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
70: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
73: 0f b6 02 movzbl (%edx),%eax
p++, q++;
76: 83 c1 01 add $0x1,%ecx
79: 0f b6 19 movzbl (%ecx),%ebx
while(*p && *p == *q)
7c: 84 c0 test %al,%al
7e: 74 10 je 90 <strcmp+0x40>
80: 38 d8 cmp %bl,%al
82: 74 ec je 70 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
84: 29 d8 sub %ebx,%eax
}
86: 5b pop %ebx
87: 5d pop %ebp
88: c3 ret
89: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
90: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
92: 29 d8 sub %ebx,%eax
}
94: 5b pop %ebx
95: 5d pop %ebp
96: c3 ret
97: 89 f6 mov %esi,%esi
99: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000000a0 <strlen>:
uint
strlen(const char *s)
{
a0: 55 push %ebp
a1: 89 e5 mov %esp,%ebp
a3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
a6: 80 39 00 cmpb $0x0,(%ecx)
a9: 74 15 je c0 <strlen+0x20>
ab: 31 d2 xor %edx,%edx
ad: 8d 76 00 lea 0x0(%esi),%esi
b0: 83 c2 01 add $0x1,%edx
b3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
b7: 89 d0 mov %edx,%eax
b9: 75 f5 jne b0 <strlen+0x10>
;
return n;
}
bb: 5d pop %ebp
bc: c3 ret
bd: 8d 76 00 lea 0x0(%esi),%esi
for(n = 0; s[n]; n++)
c0: 31 c0 xor %eax,%eax
}
c2: 5d pop %ebp
c3: c3 ret
c4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
ca: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
000000d0 <memset>:
void*
memset(void *dst, int c, uint n)
{
d0: 55 push %ebp
d1: 89 e5 mov %esp,%ebp
d3: 57 push %edi
d4: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
d7: 8b 4d 10 mov 0x10(%ebp),%ecx
da: 8b 45 0c mov 0xc(%ebp),%eax
dd: 89 d7 mov %edx,%edi
df: fc cld
e0: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
e2: 89 d0 mov %edx,%eax
e4: 5f pop %edi
e5: 5d pop %ebp
e6: c3 ret
e7: 89 f6 mov %esi,%esi
e9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000000f0 <strchr>:
char*
strchr(const char *s, char c)
{
f0: 55 push %ebp
f1: 89 e5 mov %esp,%ebp
f3: 53 push %ebx
f4: 8b 45 08 mov 0x8(%ebp),%eax
f7: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
fa: 0f b6 10 movzbl (%eax),%edx
fd: 84 d2 test %dl,%dl
ff: 74 1d je 11e <strchr+0x2e>
if(*s == c)
101: 38 d3 cmp %dl,%bl
103: 89 d9 mov %ebx,%ecx
105: 75 0d jne 114 <strchr+0x24>
107: eb 17 jmp 120 <strchr+0x30>
109: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
110: 38 ca cmp %cl,%dl
112: 74 0c je 120 <strchr+0x30>
for(; *s; s++)
114: 83 c0 01 add $0x1,%eax
117: 0f b6 10 movzbl (%eax),%edx
11a: 84 d2 test %dl,%dl
11c: 75 f2 jne 110 <strchr+0x20>
return (char*)s;
return 0;
11e: 31 c0 xor %eax,%eax
}
120: 5b pop %ebx
121: 5d pop %ebp
122: c3 ret
123: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
129: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000130 <gets>:
char*
gets(char *buf, int max)
{
130: 55 push %ebp
131: 89 e5 mov %esp,%ebp
133: 57 push %edi
134: 56 push %esi
135: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
136: 31 f6 xor %esi,%esi
138: 89 f3 mov %esi,%ebx
{
13a: 83 ec 1c sub $0x1c,%esp
13d: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
140: eb 2f jmp 171 <gets+0x41>
142: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
148: 8d 45 e7 lea -0x19(%ebp),%eax
14b: 83 ec 04 sub $0x4,%esp
14e: 6a 01 push $0x1
150: 50 push %eax
151: 6a 00 push $0x0
153: e8 32 01 00 00 call 28a <read>
if(cc < 1)
158: 83 c4 10 add $0x10,%esp
15b: 85 c0 test %eax,%eax
15d: 7e 1c jle 17b <gets+0x4b>
break;
buf[i++] = c;
15f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
163: 83 c7 01 add $0x1,%edi
166: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
169: 3c 0a cmp $0xa,%al
16b: 74 23 je 190 <gets+0x60>
16d: 3c 0d cmp $0xd,%al
16f: 74 1f je 190 <gets+0x60>
for(i=0; i+1 < max; ){
171: 83 c3 01 add $0x1,%ebx
174: 3b 5d 0c cmp 0xc(%ebp),%ebx
177: 89 fe mov %edi,%esi
179: 7c cd jl 148 <gets+0x18>
17b: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
17d: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
180: c6 03 00 movb $0x0,(%ebx)
}
183: 8d 65 f4 lea -0xc(%ebp),%esp
186: 5b pop %ebx
187: 5e pop %esi
188: 5f pop %edi
189: 5d pop %ebp
18a: c3 ret
18b: 90 nop
18c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
190: 8b 75 08 mov 0x8(%ebp),%esi
193: 8b 45 08 mov 0x8(%ebp),%eax
196: 01 de add %ebx,%esi
198: 89 f3 mov %esi,%ebx
buf[i] = '\0';
19a: c6 03 00 movb $0x0,(%ebx)
}
19d: 8d 65 f4 lea -0xc(%ebp),%esp
1a0: 5b pop %ebx
1a1: 5e pop %esi
1a2: 5f pop %edi
1a3: 5d pop %ebp
1a4: c3 ret
1a5: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
1a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000001b0 <stat>:
int
stat(const char *n, struct stat *st)
{
1b0: 55 push %ebp
1b1: 89 e5 mov %esp,%ebp
1b3: 56 push %esi
1b4: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
1b5: 83 ec 08 sub $0x8,%esp
1b8: 6a 00 push $0x0
1ba: ff 75 08 pushl 0x8(%ebp)
1bd: e8 f0 00 00 00 call 2b2 <open>
if(fd < 0)
1c2: 83 c4 10 add $0x10,%esp
1c5: 85 c0 test %eax,%eax
1c7: 78 27 js 1f0 <stat+0x40>
return -1;
r = fstat(fd, st);
1c9: 83 ec 08 sub $0x8,%esp
1cc: ff 75 0c pushl 0xc(%ebp)
1cf: 89 c3 mov %eax,%ebx
1d1: 50 push %eax
1d2: e8 f3 00 00 00 call 2ca <fstat>
close(fd);
1d7: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
1da: 89 c6 mov %eax,%esi
close(fd);
1dc: e8 b9 00 00 00 call 29a <close>
return r;
1e1: 83 c4 10 add $0x10,%esp
}
1e4: 8d 65 f8 lea -0x8(%ebp),%esp
1e7: 89 f0 mov %esi,%eax
1e9: 5b pop %ebx
1ea: 5e pop %esi
1eb: 5d pop %ebp
1ec: c3 ret
1ed: 8d 76 00 lea 0x0(%esi),%esi
return -1;
1f0: be ff ff ff ff mov $0xffffffff,%esi
1f5: eb ed jmp 1e4 <stat+0x34>
1f7: 89 f6 mov %esi,%esi
1f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000200 <atoi>:
int
atoi(const char *s)
{
200: 55 push %ebp
201: 89 e5 mov %esp,%ebp
203: 53 push %ebx
204: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
207: 0f be 11 movsbl (%ecx),%edx
20a: 8d 42 d0 lea -0x30(%edx),%eax
20d: 3c 09 cmp $0x9,%al
n = 0;
20f: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
214: 77 1f ja 235 <atoi+0x35>
216: 8d 76 00 lea 0x0(%esi),%esi
219: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
220: 8d 04 80 lea (%eax,%eax,4),%eax
223: 83 c1 01 add $0x1,%ecx
226: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
while('0' <= *s && *s <= '9')
22a: 0f be 11 movsbl (%ecx),%edx
22d: 8d 5a d0 lea -0x30(%edx),%ebx
230: 80 fb 09 cmp $0x9,%bl
233: 76 eb jbe 220 <atoi+0x20>
return n;
}
235: 5b pop %ebx
236: 5d pop %ebp
237: c3 ret
238: 90 nop
239: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000240 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
240: 55 push %ebp
241: 89 e5 mov %esp,%ebp
243: 56 push %esi
244: 53 push %ebx
245: 8b 5d 10 mov 0x10(%ebp),%ebx
248: 8b 45 08 mov 0x8(%ebp),%eax
24b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
24e: 85 db test %ebx,%ebx
250: 7e 14 jle 266 <memmove+0x26>
252: 31 d2 xor %edx,%edx
254: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
258: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
25c: 88 0c 10 mov %cl,(%eax,%edx,1)
25f: 83 c2 01 add $0x1,%edx
while(n-- > 0)
262: 39 d3 cmp %edx,%ebx
264: 75 f2 jne 258 <memmove+0x18>
return vdst;
}
266: 5b pop %ebx
267: 5e pop %esi
268: 5d pop %ebp
269: c3 ret
0000026a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
26a: b8 01 00 00 00 mov $0x1,%eax
26f: cd 40 int $0x40
271: c3 ret
00000272 <exit>:
SYSCALL(exit)
272: b8 02 00 00 00 mov $0x2,%eax
277: cd 40 int $0x40
279: c3 ret
0000027a <wait>:
SYSCALL(wait)
27a: b8 03 00 00 00 mov $0x3,%eax
27f: cd 40 int $0x40
281: c3 ret
00000282 <pipe>:
SYSCALL(pipe)
282: b8 04 00 00 00 mov $0x4,%eax
287: cd 40 int $0x40
289: c3 ret
0000028a <read>:
SYSCALL(read)
28a: b8 05 00 00 00 mov $0x5,%eax
28f: cd 40 int $0x40
291: c3 ret
00000292 <write>:
SYSCALL(write)
292: b8 10 00 00 00 mov $0x10,%eax
297: cd 40 int $0x40
299: c3 ret
0000029a <close>:
SYSCALL(close)
29a: b8 15 00 00 00 mov $0x15,%eax
29f: cd 40 int $0x40
2a1: c3 ret
000002a2 <kill>:
SYSCALL(kill)
2a2: b8 06 00 00 00 mov $0x6,%eax
2a7: cd 40 int $0x40
2a9: c3 ret
000002aa <exec>:
SYSCALL(exec)
2aa: b8 07 00 00 00 mov $0x7,%eax
2af: cd 40 int $0x40
2b1: c3 ret
000002b2 <open>:
SYSCALL(open)
2b2: b8 0f 00 00 00 mov $0xf,%eax
2b7: cd 40 int $0x40
2b9: c3 ret
000002ba <mknod>:
SYSCALL(mknod)
2ba: b8 11 00 00 00 mov $0x11,%eax
2bf: cd 40 int $0x40
2c1: c3 ret
000002c2 <unlink>:
SYSCALL(unlink)
2c2: b8 12 00 00 00 mov $0x12,%eax
2c7: cd 40 int $0x40
2c9: c3 ret
000002ca <fstat>:
SYSCALL(fstat)
2ca: b8 08 00 00 00 mov $0x8,%eax
2cf: cd 40 int $0x40
2d1: c3 ret
000002d2 <link>:
SYSCALL(link)
2d2: b8 13 00 00 00 mov $0x13,%eax
2d7: cd 40 int $0x40
2d9: c3 ret
000002da <mkdir>:
SYSCALL(mkdir)
2da: b8 14 00 00 00 mov $0x14,%eax
2df: cd 40 int $0x40
2e1: c3 ret
000002e2 <chdir>:
SYSCALL(chdir)
2e2: b8 09 00 00 00 mov $0x9,%eax
2e7: cd 40 int $0x40
2e9: c3 ret
000002ea <dup>:
SYSCALL(dup)
2ea: b8 0a 00 00 00 mov $0xa,%eax
2ef: cd 40 int $0x40
2f1: c3 ret
000002f2 <getpid>:
SYSCALL(getpid)
2f2: b8 0b 00 00 00 mov $0xb,%eax
2f7: cd 40 int $0x40
2f9: c3 ret
000002fa <sbrk>:
SYSCALL(sbrk)
2fa: b8 0c 00 00 00 mov $0xc,%eax
2ff: cd 40 int $0x40
301: c3 ret
00000302 <sleep>:
SYSCALL(sleep)
302: b8 0d 00 00 00 mov $0xd,%eax
307: cd 40 int $0x40
309: c3 ret
0000030a <uptime>:
SYSCALL(uptime)
30a: b8 0e 00 00 00 mov $0xe,%eax
30f: cd 40 int $0x40
311: c3 ret
00000312 <info>:
SYSCALL(info)
312: b8 16 00 00 00 mov $0x16,%eax
317: cd 40 int $0x40
319: c3 ret
0000031a <settickets>:
SYSCALL(settickets)
31a: b8 17 00 00 00 mov $0x17,%eax
31f: cd 40 int $0x40
321: c3 ret
322: 66 90 xchg %ax,%ax
324: 66 90 xchg %ax,%ax
326: 66 90 xchg %ax,%ax
328: 66 90 xchg %ax,%ax
32a: 66 90 xchg %ax,%ax
32c: 66 90 xchg %ax,%ax
32e: 66 90 xchg %ax,%ax
00000330 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
330: 55 push %ebp
331: 89 e5 mov %esp,%ebp
333: 57 push %edi
334: 56 push %esi
335: 53 push %ebx
336: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
339: 85 d2 test %edx,%edx
{
33b: 89 45 c0 mov %eax,-0x40(%ebp)
neg = 1;
x = -xx;
33e: 89 d0 mov %edx,%eax
if(sgn && xx < 0){
340: 79 76 jns 3b8 <printint+0x88>
342: f6 45 08 01 testb $0x1,0x8(%ebp)
346: 74 70 je 3b8 <printint+0x88>
x = -xx;
348: f7 d8 neg %eax
neg = 1;
34a: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
} else {
x = xx;
}
i = 0;
351: 31 f6 xor %esi,%esi
353: 8d 5d d7 lea -0x29(%ebp),%ebx
356: eb 0a jmp 362 <printint+0x32>
358: 90 nop
359: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
do{
buf[i++] = digits[x % base];
360: 89 fe mov %edi,%esi
362: 31 d2 xor %edx,%edx
364: 8d 7e 01 lea 0x1(%esi),%edi
367: f7 f1 div %ecx
369: 0f b6 92 30 07 00 00 movzbl 0x730(%edx),%edx
}while((x /= base) != 0);
370: 85 c0 test %eax,%eax
buf[i++] = digits[x % base];
372: 88 14 3b mov %dl,(%ebx,%edi,1)
}while((x /= base) != 0);
375: 75 e9 jne 360 <printint+0x30>
if(neg)
377: 8b 45 c4 mov -0x3c(%ebp),%eax
37a: 85 c0 test %eax,%eax
37c: 74 08 je 386 <printint+0x56>
buf[i++] = '-';
37e: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1)
383: 8d 7e 02 lea 0x2(%esi),%edi
386: 8d 74 3d d7 lea -0x29(%ebp,%edi,1),%esi
38a: 8b 7d c0 mov -0x40(%ebp),%edi
38d: 8d 76 00 lea 0x0(%esi),%esi
390: 0f b6 06 movzbl (%esi),%eax
write(fd, &c, 1);
393: 83 ec 04 sub $0x4,%esp
396: 83 ee 01 sub $0x1,%esi
399: 6a 01 push $0x1
39b: 53 push %ebx
39c: 57 push %edi
39d: 88 45 d7 mov %al,-0x29(%ebp)
3a0: e8 ed fe ff ff call 292 <write>
while(--i >= 0)
3a5: 83 c4 10 add $0x10,%esp
3a8: 39 de cmp %ebx,%esi
3aa: 75 e4 jne 390 <printint+0x60>
putc(fd, buf[i]);
}
3ac: 8d 65 f4 lea -0xc(%ebp),%esp
3af: 5b pop %ebx
3b0: 5e pop %esi
3b1: 5f pop %edi
3b2: 5d pop %ebp
3b3: c3 ret
3b4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
3b8: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
3bf: eb 90 jmp 351 <printint+0x21>
3c1: eb 0d jmp 3d0 <printf>
3c3: 90 nop
3c4: 90 nop
3c5: 90 nop
3c6: 90 nop
3c7: 90 nop
3c8: 90 nop
3c9: 90 nop
3ca: 90 nop
3cb: 90 nop
3cc: 90 nop
3cd: 90 nop
3ce: 90 nop
3cf: 90 nop
000003d0 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
3d0: 55 push %ebp
3d1: 89 e5 mov %esp,%ebp
3d3: 57 push %edi
3d4: 56 push %esi
3d5: 53 push %ebx
3d6: 83 ec 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
3d9: 8b 75 0c mov 0xc(%ebp),%esi
3dc: 0f b6 1e movzbl (%esi),%ebx
3df: 84 db test %bl,%bl
3e1: 0f 84 b3 00 00 00 je 49a <printf+0xca>
ap = (uint*)(void*)&fmt + 1;
3e7: 8d 45 10 lea 0x10(%ebp),%eax
3ea: 83 c6 01 add $0x1,%esi
state = 0;
3ed: 31 ff xor %edi,%edi
ap = (uint*)(void*)&fmt + 1;
3ef: 89 45 d4 mov %eax,-0x2c(%ebp)
3f2: eb 2f jmp 423 <printf+0x53>
3f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
3f8: 83 f8 25 cmp $0x25,%eax
3fb: 0f 84 a7 00 00 00 je 4a8 <printf+0xd8>
write(fd, &c, 1);
401: 8d 45 e2 lea -0x1e(%ebp),%eax
404: 83 ec 04 sub $0x4,%esp
407: 88 5d e2 mov %bl,-0x1e(%ebp)
40a: 6a 01 push $0x1
40c: 50 push %eax
40d: ff 75 08 pushl 0x8(%ebp)
410: e8 7d fe ff ff call 292 <write>
415: 83 c4 10 add $0x10,%esp
418: 83 c6 01 add $0x1,%esi
for(i = 0; fmt[i]; i++){
41b: 0f b6 5e ff movzbl -0x1(%esi),%ebx
41f: 84 db test %bl,%bl
421: 74 77 je 49a <printf+0xca>
if(state == 0){
423: 85 ff test %edi,%edi
c = fmt[i] & 0xff;
425: 0f be cb movsbl %bl,%ecx
428: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
42b: 74 cb je 3f8 <printf+0x28>
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
42d: 83 ff 25 cmp $0x25,%edi
430: 75 e6 jne 418 <printf+0x48>
if(c == 'd'){
432: 83 f8 64 cmp $0x64,%eax
435: 0f 84 05 01 00 00 je 540 <printf+0x170>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
43b: 81 e1 f7 00 00 00 and $0xf7,%ecx
441: 83 f9 70 cmp $0x70,%ecx
444: 74 72 je 4b8 <printf+0xe8>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
446: 83 f8 73 cmp $0x73,%eax
449: 0f 84 99 00 00 00 je 4e8 <printf+0x118>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
44f: 83 f8 63 cmp $0x63,%eax
452: 0f 84 08 01 00 00 je 560 <printf+0x190>
putc(fd, *ap);
ap++;
} else if(c == '%'){
458: 83 f8 25 cmp $0x25,%eax
45b: 0f 84 ef 00 00 00 je 550 <printf+0x180>
write(fd, &c, 1);
461: 8d 45 e7 lea -0x19(%ebp),%eax
464: 83 ec 04 sub $0x4,%esp
467: c6 45 e7 25 movb $0x25,-0x19(%ebp)
46b: 6a 01 push $0x1
46d: 50 push %eax
46e: ff 75 08 pushl 0x8(%ebp)
471: e8 1c fe ff ff call 292 <write>
476: 83 c4 0c add $0xc,%esp
479: 8d 45 e6 lea -0x1a(%ebp),%eax
47c: 88 5d e6 mov %bl,-0x1a(%ebp)
47f: 6a 01 push $0x1
481: 50 push %eax
482: ff 75 08 pushl 0x8(%ebp)
485: 83 c6 01 add $0x1,%esi
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
488: 31 ff xor %edi,%edi
write(fd, &c, 1);
48a: e8 03 fe ff ff call 292 <write>
for(i = 0; fmt[i]; i++){
48f: 0f b6 5e ff movzbl -0x1(%esi),%ebx
write(fd, &c, 1);
493: 83 c4 10 add $0x10,%esp
for(i = 0; fmt[i]; i++){
496: 84 db test %bl,%bl
498: 75 89 jne 423 <printf+0x53>
}
}
}
49a: 8d 65 f4 lea -0xc(%ebp),%esp
49d: 5b pop %ebx
49e: 5e pop %esi
49f: 5f pop %edi
4a0: 5d pop %ebp
4a1: c3 ret
4a2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
state = '%';
4a8: bf 25 00 00 00 mov $0x25,%edi
4ad: e9 66 ff ff ff jmp 418 <printf+0x48>
4b2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
printint(fd, *ap, 16, 0);
4b8: 83 ec 0c sub $0xc,%esp
4bb: b9 10 00 00 00 mov $0x10,%ecx
4c0: 6a 00 push $0x0
4c2: 8b 7d d4 mov -0x2c(%ebp),%edi
4c5: 8b 45 08 mov 0x8(%ebp),%eax
4c8: 8b 17 mov (%edi),%edx
4ca: e8 61 fe ff ff call 330 <printint>
ap++;
4cf: 89 f8 mov %edi,%eax
4d1: 83 c4 10 add $0x10,%esp
state = 0;
4d4: 31 ff xor %edi,%edi
ap++;
4d6: 83 c0 04 add $0x4,%eax
4d9: 89 45 d4 mov %eax,-0x2c(%ebp)
4dc: e9 37 ff ff ff jmp 418 <printf+0x48>
4e1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
s = (char*)*ap;
4e8: 8b 45 d4 mov -0x2c(%ebp),%eax
4eb: 8b 08 mov (%eax),%ecx
ap++;
4ed: 83 c0 04 add $0x4,%eax
4f0: 89 45 d4 mov %eax,-0x2c(%ebp)
if(s == 0)
4f3: 85 c9 test %ecx,%ecx
4f5: 0f 84 8e 00 00 00 je 589 <printf+0x1b9>
while(*s != 0){
4fb: 0f b6 01 movzbl (%ecx),%eax
state = 0;
4fe: 31 ff xor %edi,%edi
s = (char*)*ap;
500: 89 cb mov %ecx,%ebx
while(*s != 0){
502: 84 c0 test %al,%al
504: 0f 84 0e ff ff ff je 418 <printf+0x48>
50a: 89 75 d0 mov %esi,-0x30(%ebp)
50d: 89 de mov %ebx,%esi
50f: 8b 5d 08 mov 0x8(%ebp),%ebx
512: 8d 7d e3 lea -0x1d(%ebp),%edi
515: 8d 76 00 lea 0x0(%esi),%esi
write(fd, &c, 1);
518: 83 ec 04 sub $0x4,%esp
s++;
51b: 83 c6 01 add $0x1,%esi
51e: 88 45 e3 mov %al,-0x1d(%ebp)
write(fd, &c, 1);
521: 6a 01 push $0x1
523: 57 push %edi
524: 53 push %ebx
525: e8 68 fd ff ff call 292 <write>
while(*s != 0){
52a: 0f b6 06 movzbl (%esi),%eax
52d: 83 c4 10 add $0x10,%esp
530: 84 c0 test %al,%al
532: 75 e4 jne 518 <printf+0x148>
534: 8b 75 d0 mov -0x30(%ebp),%esi
state = 0;
537: 31 ff xor %edi,%edi
539: e9 da fe ff ff jmp 418 <printf+0x48>
53e: 66 90 xchg %ax,%ax
printint(fd, *ap, 10, 1);
540: 83 ec 0c sub $0xc,%esp
543: b9 0a 00 00 00 mov $0xa,%ecx
548: 6a 01 push $0x1
54a: e9 73 ff ff ff jmp 4c2 <printf+0xf2>
54f: 90 nop
write(fd, &c, 1);
550: 83 ec 04 sub $0x4,%esp
553: 88 5d e5 mov %bl,-0x1b(%ebp)
556: 8d 45 e5 lea -0x1b(%ebp),%eax
559: 6a 01 push $0x1
55b: e9 21 ff ff ff jmp 481 <printf+0xb1>
putc(fd, *ap);
560: 8b 7d d4 mov -0x2c(%ebp),%edi
write(fd, &c, 1);
563: 83 ec 04 sub $0x4,%esp
putc(fd, *ap);
566: 8b 07 mov (%edi),%eax
write(fd, &c, 1);
568: 6a 01 push $0x1
ap++;
56a: 83 c7 04 add $0x4,%edi
putc(fd, *ap);
56d: 88 45 e4 mov %al,-0x1c(%ebp)
write(fd, &c, 1);
570: 8d 45 e4 lea -0x1c(%ebp),%eax
573: 50 push %eax
574: ff 75 08 pushl 0x8(%ebp)
577: e8 16 fd ff ff call 292 <write>
ap++;
57c: 89 7d d4 mov %edi,-0x2c(%ebp)
57f: 83 c4 10 add $0x10,%esp
state = 0;
582: 31 ff xor %edi,%edi
584: e9 8f fe ff ff jmp 418 <printf+0x48>
s = "(null)";
589: bb 28 07 00 00 mov $0x728,%ebx
while(*s != 0){
58e: b8 28 00 00 00 mov $0x28,%eax
593: e9 72 ff ff ff jmp 50a <printf+0x13a>
598: 66 90 xchg %ax,%ax
59a: 66 90 xchg %ax,%ax
59c: 66 90 xchg %ax,%ax
59e: 66 90 xchg %ax,%ax
000005a0 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
5a0: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5a1: a1 d4 09 00 00 mov 0x9d4,%eax
{
5a6: 89 e5 mov %esp,%ebp
5a8: 57 push %edi
5a9: 56 push %esi
5aa: 53 push %ebx
5ab: 8b 5d 08 mov 0x8(%ebp),%ebx
bp = (Header*)ap - 1;
5ae: 8d 4b f8 lea -0x8(%ebx),%ecx
5b1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5b8: 39 c8 cmp %ecx,%eax
5ba: 8b 10 mov (%eax),%edx
5bc: 73 32 jae 5f0 <free+0x50>
5be: 39 d1 cmp %edx,%ecx
5c0: 72 04 jb 5c6 <free+0x26>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5c2: 39 d0 cmp %edx,%eax
5c4: 72 32 jb 5f8 <free+0x58>
break;
if(bp + bp->s.size == p->s.ptr){
5c6: 8b 73 fc mov -0x4(%ebx),%esi
5c9: 8d 3c f1 lea (%ecx,%esi,8),%edi
5cc: 39 fa cmp %edi,%edx
5ce: 74 30 je 600 <free+0x60>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
5d0: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
5d3: 8b 50 04 mov 0x4(%eax),%edx
5d6: 8d 34 d0 lea (%eax,%edx,8),%esi
5d9: 39 f1 cmp %esi,%ecx
5db: 74 3a je 617 <free+0x77>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
5dd: 89 08 mov %ecx,(%eax)
freep = p;
5df: a3 d4 09 00 00 mov %eax,0x9d4
}
5e4: 5b pop %ebx
5e5: 5e pop %esi
5e6: 5f pop %edi
5e7: 5d pop %ebp
5e8: c3 ret
5e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5f0: 39 d0 cmp %edx,%eax
5f2: 72 04 jb 5f8 <free+0x58>
5f4: 39 d1 cmp %edx,%ecx
5f6: 72 ce jb 5c6 <free+0x26>
{
5f8: 89 d0 mov %edx,%eax
5fa: eb bc jmp 5b8 <free+0x18>
5fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
bp->s.size += p->s.ptr->s.size;
600: 03 72 04 add 0x4(%edx),%esi
603: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
606: 8b 10 mov (%eax),%edx
608: 8b 12 mov (%edx),%edx
60a: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
60d: 8b 50 04 mov 0x4(%eax),%edx
610: 8d 34 d0 lea (%eax,%edx,8),%esi
613: 39 f1 cmp %esi,%ecx
615: 75 c6 jne 5dd <free+0x3d>
p->s.size += bp->s.size;
617: 03 53 fc add -0x4(%ebx),%edx
freep = p;
61a: a3 d4 09 00 00 mov %eax,0x9d4
p->s.size += bp->s.size;
61f: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
622: 8b 53 f8 mov -0x8(%ebx),%edx
625: 89 10 mov %edx,(%eax)
}
627: 5b pop %ebx
628: 5e pop %esi
629: 5f pop %edi
62a: 5d pop %ebp
62b: c3 ret
62c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000630 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
630: 55 push %ebp
631: 89 e5 mov %esp,%ebp
633: 57 push %edi
634: 56 push %esi
635: 53 push %ebx
636: 83 ec 0c sub $0xc,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
639: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
63c: 8b 15 d4 09 00 00 mov 0x9d4,%edx
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
642: 8d 78 07 lea 0x7(%eax),%edi
645: c1 ef 03 shr $0x3,%edi
648: 83 c7 01 add $0x1,%edi
if((prevp = freep) == 0){
64b: 85 d2 test %edx,%edx
64d: 0f 84 9d 00 00 00 je 6f0 <malloc+0xc0>
653: 8b 02 mov (%edx),%eax
655: 8b 48 04 mov 0x4(%eax),%ecx
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
658: 39 cf cmp %ecx,%edi
65a: 76 6c jbe 6c8 <malloc+0x98>
65c: 81 ff 00 10 00 00 cmp $0x1000,%edi
662: bb 00 10 00 00 mov $0x1000,%ebx
667: 0f 43 df cmovae %edi,%ebx
p = sbrk(nu * sizeof(Header));
66a: 8d 34 dd 00 00 00 00 lea 0x0(,%ebx,8),%esi
671: eb 0e jmp 681 <malloc+0x51>
673: 90 nop
674: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
678: 8b 02 mov (%edx),%eax
if(p->s.size >= nunits){
67a: 8b 48 04 mov 0x4(%eax),%ecx
67d: 39 f9 cmp %edi,%ecx
67f: 73 47 jae 6c8 <malloc+0x98>
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
681: 39 05 d4 09 00 00 cmp %eax,0x9d4
687: 89 c2 mov %eax,%edx
689: 75 ed jne 678 <malloc+0x48>
p = sbrk(nu * sizeof(Header));
68b: 83 ec 0c sub $0xc,%esp
68e: 56 push %esi
68f: e8 66 fc ff ff call 2fa <sbrk>
if(p == (char*)-1)
694: 83 c4 10 add $0x10,%esp
697: 83 f8 ff cmp $0xffffffff,%eax
69a: 74 1c je 6b8 <malloc+0x88>
hp->s.size = nu;
69c: 89 58 04 mov %ebx,0x4(%eax)
free((void*)(hp + 1));
69f: 83 ec 0c sub $0xc,%esp
6a2: 83 c0 08 add $0x8,%eax
6a5: 50 push %eax
6a6: e8 f5 fe ff ff call 5a0 <free>
return freep;
6ab: 8b 15 d4 09 00 00 mov 0x9d4,%edx
if((p = morecore(nunits)) == 0)
6b1: 83 c4 10 add $0x10,%esp
6b4: 85 d2 test %edx,%edx
6b6: 75 c0 jne 678 <malloc+0x48>
return 0;
}
}
6b8: 8d 65 f4 lea -0xc(%ebp),%esp
return 0;
6bb: 31 c0 xor %eax,%eax
}
6bd: 5b pop %ebx
6be: 5e pop %esi
6bf: 5f pop %edi
6c0: 5d pop %ebp
6c1: c3 ret
6c2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
if(p->s.size == nunits)
6c8: 39 cf cmp %ecx,%edi
6ca: 74 54 je 720 <malloc+0xf0>
p->s.size -= nunits;
6cc: 29 f9 sub %edi,%ecx
6ce: 89 48 04 mov %ecx,0x4(%eax)
p += p->s.size;
6d1: 8d 04 c8 lea (%eax,%ecx,8),%eax
p->s.size = nunits;
6d4: 89 78 04 mov %edi,0x4(%eax)
freep = prevp;
6d7: 89 15 d4 09 00 00 mov %edx,0x9d4
}
6dd: 8d 65 f4 lea -0xc(%ebp),%esp
return (void*)(p + 1);
6e0: 83 c0 08 add $0x8,%eax
}
6e3: 5b pop %ebx
6e4: 5e pop %esi
6e5: 5f pop %edi
6e6: 5d pop %ebp
6e7: c3 ret
6e8: 90 nop
6e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
base.s.ptr = freep = prevp = &base;
6f0: c7 05 d4 09 00 00 d8 movl $0x9d8,0x9d4
6f7: 09 00 00
6fa: c7 05 d8 09 00 00 d8 movl $0x9d8,0x9d8
701: 09 00 00
base.s.size = 0;
704: b8 d8 09 00 00 mov $0x9d8,%eax
709: c7 05 dc 09 00 00 00 movl $0x0,0x9dc
710: 00 00 00
713: e9 44 ff ff ff jmp 65c <malloc+0x2c>
718: 90 nop
719: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
prevp->s.ptr = p->s.ptr;
720: 8b 08 mov (%eax),%ecx
722: 89 0a mov %ecx,(%edx)
724: eb b1 jmp 6d7 <malloc+0xa7>
|
global memset
memset:
push ebp
mov ebp,esp
mov edi,[ebp+8] ; dest
movzx eax,byte [ebp+12] ; ch
mov ecx,[ebp+16] ; count
rep stosb
pop ebp
ret
|
######################################################################
# SNAKE!!!! #
######################################################################
# Programmed by Shane Shafferman and Eric Deas #
######################################################################
# This program requires the Keyboard and Display MMIO #
# and the Bitmap Display to be connected to MIPS. #
# #
# Bitmap Display Settings: #
# Unit Width: 8 #
# Unit Height: 8 #
# Display Width: 512 #
# Display Height: 512 #
# Base Address for Display: 0x10008000 ($gp) #
######################################################################
.data
#Game Core information
#Screen
screenWidth: .word 64
screenHeight: .word 64
#Colors
snakeColor: .word 0x0066cc # blue
backgroundColor:.word 0x000000 # black
borderColor: .word 0x00ff00 # green
fruitColor: .word 0xcc6611 # orange
#score variable
score: .word 0
#stores how many points are recieved for eating a fruit
#increases as program gets harder
scoreGain: .word 10
#speed the snake moves at, increases as game progresses
gameSpeed: .word 200
#array to store the scores in which difficulty should increase
scoreMilestones: .word 100, 250, 500, 1000, 5000, 10000
scoreArrayPosition: .word 0
#end game message
lostMessage: .asciiz "You have died.... Your score was: "
replayMessage: .asciiz "Would you like to replay?"
#Snake Information
snakeHeadX: .word 31
snakeHeadY: .word 31
snakeTailX: .word 31
snakeTailY: .word 37
direction: .word 119 #initially moving up
tailDirection: .word 119
# direction variable
# 119 - moving up - W
# 115 - moving down - S
# 97 - moving left - A
# 100 - moving right - D
# numbers are selected due to ASCII characters
#this array stores the screen coordinates of a direction change
#once the tail hits a position in this array, its direction is changed
#this is used to have the tail follow the head correctly
directionChangeAddressArray: .word 0:100
#this stores the new direction for the tail to move once it hits
#an address in the above array
newDirectionChangeArray: .word 0:100
#stores the position of the end of the array (multiple of 4)
arrayPosition: .word 0
locationInArray: .word 0
#Fruit Information
fruitPositionX: .word
fruitPositionY: .word
.text
main:
######################################################
# Fill Screen to Black, for reset
######################################################
lw $a0, screenWidth
lw $a1, backgroundColor
mul $a2, $a0, $a0 #total number of pixels on screen
mul $a2, $a2, 4 #align addresses
add $a2, $a2, $gp #add base of gp
add $a0, $gp, $zero #loop counter
FillLoop:
beq $a0, $a2, Init
sw $a1, 0($a0) #store color
addiu $a0, $a0, 4 #increment counter
j FillLoop
######################################################
# Initialize Variables
######################################################
Init:
li $t0, 31
sw $t0, snakeHeadX
sw $t0, snakeHeadY
sw $t0, snakeTailX
li $t0, 37
sw $t0, snakeTailY
li $t0, 119
sw $t0, direction
sw $t0, tailDirection
li $t0, 10
sw $t0, scoreGain
li $t0, 200
sw $t0, gameSpeed
sw $zero, arrayPosition
sw $zero, locationInArray
sw $zero, scoreArrayPosition
sw $zero, score
ClearRegisters:
li $v0, 0
li $a0, 0
li $a1, 0
li $a2, 0
li $a3, 0
li $t0, 0
li $t1, 0
li $t2, 0
li $t3, 0
li $t4, 0
li $t5, 0
li $t6, 0
li $t7, 0
li $t8, 0
li $t9, 0
li $s0, 0
li $s1, 0
li $s2, 0
li $s3, 0
li $s4, 0
######################################################
# Draw Border
######################################################
DrawBorder:
li $t1, 0 #load Y coordinate for the left border
LeftLoop:
move $a1, $t1 #move y coordinate into $a1
li $a0, 0 # load x direction to 0, doesnt change
jal CoordinateToAddress #get screen coordinates
move $a0, $v0 # move screen coordinates into $a0
lw $a1, borderColor #move color code into $a1
jal DrawPixel #draw the color at the screen location
add $t1, $t1, 1 #increment y coordinate
bne $t1, 64, LeftLoop #loop through to draw entire left border
li $t1, 0 #load Y coordinate for right border
RightLoop:
move $a1, $t1 #move y coordinate into $a1
li $a0, 63 #set x coordinate to 63 (right side of screen)
jal CoordinateToAddress #convert to screen coordinates
move $a0, $v0 # move coordinates into $a0
lw $a1, borderColor #move color data into $a1
jal DrawPixel #draw color at screen coordinates
add $t1, $t1, 1 #increment y coordinate
bne $t1, 64, RightLoop #loop through to draw entire right border
li $t1, 0 #load X coordinate for top border
TopLoop:
move $a0, $t1 # move x coordinate into $a0
li $a1, 0 # set y coordinate to zero for top of screen
jal CoordinateToAddress #get screen coordinate
move $a0, $v0 # move screen coordinates to $a0
lw $a1, borderColor # store color data to $a1
jal DrawPixel #draw color at screen coordinates
add $t1, $t1, 1 #increment X position
bne $t1, 64, TopLoop #loop through to draw entire top border
li $t1, 0 #load X coordinate for bottom border
BottomLoop:
move $a0, $t1 # move x coordinate to $a0
li $a1, 63 # load Y coordinate for bottom of screen
jal CoordinateToAddress #get screen coordinates
move $a0, $v0 #move screen coordinates to $a0
lw $a1, borderColor #put color data into $a1
jal DrawPixel #draw color at screen position
add $t1, $t1, 1 #increment X coordinate
bne $t1, 64, BottomLoop # loop through to draw entire bottom border
######################################################
# Draw Initial Snake Position
######################################################
#draw snake head
lw $a0, snakeHeadX #load x coordinate
lw $a1, snakeHeadY #load y coordinate
jal CoordinateToAddress #get screen coordinates
move $a0, $v0 #copy coordinates to $a0
lw $a1, snakeColor #store color into $a1
jal DrawPixel #draw color at pixel
#draw middle portion
lw $a0, snakeHeadX #load x coordinate
lw $a1, snakeHeadY #load y coordinate
add $a1, $a1, 1
jal CoordinateToAddress #get screen coordinates
move $a0, $v0 #copy coordinates to $a0
lw $a1, snakeColor #store color into $a1
jal DrawPixel #draw color at pixel
#TEST 8 PIXELS
lw $a0, snakeHeadX #load x coordinate
lw $a1, snakeHeadY #load y coordinate
add $a1, $a1, 2
jal CoordinateToAddress #get screen coordinates
move $a0, $v0 #copy coordinates to $a0
lw $a1, snakeColor #store color into $a1
jal DrawPixel #draw color at pixel
lw $a0, snakeHeadX #load x coordinate
lw $a1, snakeHeadY #load y coordinate
add $a1, $a1, 3
jal CoordinateToAddress #get screen coordinates
move $a0, $v0 #copy coordinates to $a0
lw $a1, snakeColor #store color into $a1
jal DrawPixel #draw color at pixel
lw $a0, snakeHeadX #load x coordinate
lw $a1, snakeHeadY #load y coordinate
add $a1, $a1, 4
jal CoordinateToAddress #get screen coordinates
move $a0, $v0 #copy coordinates to $a0
lw $a1, snakeColor #store color into $a1
jal DrawPixel #draw color at pixel
lw $a0, snakeHeadX #load x coordinate
lw $a1, snakeHeadY #load y coordinate
add $a1, $a1, 5
jal CoordinateToAddress #get screen coordinates
move $a0, $v0 #copy coordinates to $a0
lw $a1, snakeColor #store color into $a1
jal DrawPixel #draw color at pixel
lw $a0, snakeHeadX #load x coordinate
lw $a1, snakeHeadY #load y coordinate
add $a1, $a1, 6
jal CoordinateToAddress #get screen coordinates
move $a0, $v0 #copy coordinates to $a0
lw $a1, snakeColor #store color into $a1
jal DrawPixel #draw color at pixel
#draw snake tail
lw $a0, snakeTailX #load x coordinate
lw $a1, snakeTailY #load y coordinate
jal CoordinateToAddress #get screen coordinates
move $a0, $v0 #copy coordinates to $a0
lw $a1, snakeColor #store color into $a1
jal DrawPixel #draw color at pixel
######################################################
# Spawn Fruit
######################################################
SpawnFruit:
#syscall for random int with a upper bound
li $v0, 42
#upper bound 61 (0 <= $a0 < $a1)
li $a1, 62
syscall
#increment the X position so it doesnt draw on a border
addiu $a0, $a0, 1
#store X position
sw $a0, fruitPositionX
syscall
#increment the Y position so it doesnt draw on a border
addiu $a0, $a0, 1
#store Y position
sw $a0, fruitPositionY
jal IncreaseDifficulty
######################################################
# Check for Direction Change
######################################################
InputCheck:
lw $a0, gameSpeed
jal Pause
#get the coordinates for direction change if needed
lw $a0, snakeHeadX
lw $a1, snakeHeadY
jal CoordinateToAddress
add $a2, $v0, $zero
#get the input from the keyboard
li $t0, 0xffff0000
lw $t1, ($t0)
andi $t1, $t1, 0x0001
beqz $t1, SelectDrawDirection #if no new input, draw in same direction
lw $a1, 4($t0) #store direction based on input
DirectionCheck:
lw $a0, direction # load current direction into #a0
jal CheckDirection #check to see if the direction is valid
beqz $v0, InputCheck #if input is not valid, get new input
sw $a1, direction #store the new direction if valid
lw $t7, direction #store the direction into $t7
######################################################
# Update Snake Head position
######################################################
SelectDrawDirection:
#check to see which direction to draw
beq $t7, 119, DrawUpLoop
beq $t7, 115, DrawDownLoop
beq $t7, 97, DrawLeftLoop
beq $t7, 100, DrawRightLoop
#jump back to get input if an unsupported key was pressed
j InputCheck
DrawUpLoop:
#check for collision before moving to next pixel
lw $a0, snakeHeadX
lw $a1, snakeHeadY
lw $a2, direction
jal CheckGameEndingCollision
#draw head in new position, move Y position up
lw $t0, snakeHeadX
lw $t1, snakeHeadY
addiu $t1, $t1, -1
add $a0, $t0, $zero
add $a1, $t1, $zero
jal CoordinateToAddress
add $a0, $v0, $zero
lw $a1, snakeColor
jal DrawPixel
sw $t1, snakeHeadY
j UpdateTailPosition #head updated, update tail
DrawDownLoop:
#check for collision before moving to next pixel
lw $a0, snakeHeadX
lw $a1, snakeHeadY
lw $a2, direction
jal CheckGameEndingCollision
#draw head in new position, move Y position down
lw $t0, snakeHeadX
lw $t1, snakeHeadY
addiu $t1, $t1, 1
add $a0, $t0, $zero
add $a1, $t1, $zero
jal CoordinateToAddress
add $a0, $v0, $zero
lw $a1, snakeColor
jal DrawPixel
sw $t1, snakeHeadY
j UpdateTailPosition #head updated, update tail
DrawLeftLoop:
#check for collision before moving to next pixel
lw $a0, snakeHeadX
lw $a1, snakeHeadY
lw $a2, direction
jal CheckGameEndingCollision
#draw head in new position, move X position left
lw $t0, snakeHeadX
lw $t1, snakeHeadY
addiu $t0, $t0, -1
add $a0, $t0, $zero
add $a1, $t1, $zero
jal CoordinateToAddress
add $a0, $v0, $zero
lw $a1, snakeColor
jal DrawPixel
sw $t0, snakeHeadX
j UpdateTailPosition #head updated, update tail
DrawRightLoop:
#check for collision before moving to next pixel
lw $a0, snakeHeadX
lw $a1, snakeHeadY
lw $a2, direction
jal CheckGameEndingCollision
#draw head in new position, move X position right
lw $t0, snakeHeadX
lw $t1, snakeHeadY
addiu $t0, $t0, 1
add $a0, $t0, $zero
add $a1, $t1, $zero
jal CoordinateToAddress
add $a0, $v0, $zero
lw $a1, snakeColor
jal DrawPixel
sw $t0, snakeHeadX
j UpdateTailPosition #head updated, update tail
######################################################
# Update Snake Tail Position
######################################################
UpdateTailPosition:
lw $t2, tailDirection
#branch based on which direction tail is moving
beq $t2, 119, MoveTailUp
beq $t2, 115, MoveTailDown
beq $t2, 97, MoveTailLeft
beq $t2, 100, MoveTailRight
MoveTailUp:
#get the screen coordinates of the next direction change
lw $t8, locationInArray
la $t0, directionChangeAddressArray #get direction change coordinate
add $t0, $t0, $t8
lw $t9, 0($t0)
lw $a0, snakeTailX #get snake tail position
lw $a1, snakeTailY
#if the index is out of bounds, set back to zero
beq $s1, 1, IncreaseLengthUp #branch if length should be increased
addiu $a1, $a1, -1 #change tail position if no length change
sw $a1, snakeTailY
IncreaseLengthUp:
li $s1, 0 #set flag back to false
jal CoordinateToAddress
add $a0, $v0, $zero
bne $t9, $a0, DrawTailUp #change direction if needed
la $t3, newDirectionChangeArray #update direction
add $t3, $t3, $t8
lw $t9, 0($t3)
sw $t9, tailDirection
addiu $t8,$t8,4
#if the index is out of bounds, set back to zero
bne $t8, 396, StoreLocationUp
li $t8, 0
StoreLocationUp:
sw $t8, locationInArray
DrawTailUp:
lw $a1, snakeColor
jal DrawPixel
#erase behind the snake
lw $t0, snakeTailX
lw $t1, snakeTailY
addiu $t1, $t1, 1
add $a0, $t0, $zero
add $a1, $t1, $zero
jal CoordinateToAddress
add $a0, $v0, $zero
lw $a1, backgroundColor
jal DrawPixel
j DrawFruit #finished updating snake, update fruit
MoveTailDown:
#get the screen coordinates of the next direction change
lw $t8, locationInArray
la $t0, directionChangeAddressArray #get direction change coordinate
add $t0, $t0, $t8
lw $t9, 0($t0)
lw $a0, snakeTailX #get snake tail position
lw $a1, snakeTailY
beq $s1, 1, IncreaseLengthDown #branch if length should be increased
addiu $a1, $a1, 1 #change tail position if no length change
sw $a1, snakeTailY
IncreaseLengthDown:
li $s1, 0 #set flag back to false
jal CoordinateToAddress
add $a0, $v0, $zero
bne $t9, $a0, DrawTailDown #change direction if needed
la $t3, newDirectionChangeArray #update direction
add $t3, $t3, $t8
lw $t9, 0($t3)
sw $t9, tailDirection
addiu $t8,$t8,4
#if the index is out of bounds, set back to zero
bne $t8, 396, StoreLocationDown
li $t8, 0
StoreLocationDown:
sw $t8, locationInArray
DrawTailDown:
lw $a1, snakeColor
jal DrawPixel
#erase behind the snake
lw $t0, snakeTailX
lw $t1, snakeTailY
addiu $t1, $t1, -1
add $a0, $t0, $zero
add $a1, $t1, $zero
jal CoordinateToAddress
add $a0, $v0, $zero
lw $a1, backgroundColor
jal DrawPixel
j DrawFruit #finished updating snake, update fruit
MoveTailLeft:
#update the tail position when moving left
lw $t8, locationInArray
la $t0, directionChangeAddressArray #get direction change coordinate
add $t0, $t0, $t8
lw $t9, 0($t0)
lw $a0, snakeTailX #get snake tail position
lw $a1, snakeTailY
beq $s1, 1, IncreaseLengthLeft #branch if length should be increased
addiu $a0, $a0, -1 #change tail position if no length change
sw $a0, snakeTailX
IncreaseLengthLeft:
li $s1, 0 #set flag back to false
jal CoordinateToAddress
add $a0, $v0, $zero
bne $t9, $a0, DrawTailLeft #change direction if needed
la $t3, newDirectionChangeArray #update direction
add $t3, $t3, $t8
lw $t9, 0($t3)
sw $t9, tailDirection
addiu $t8,$t8,4
#if the index is out of bounds, set back to zero
bne $t8, 396, StoreLocationLeft
li $t8, 0
StoreLocationLeft:
sw $t8, locationInArray
DrawTailLeft:
lw $a1, snakeColor
jal DrawPixel
#erase behind the snake
lw $t0, snakeTailX
lw $t1, snakeTailY
addiu $t0, $t0, 1
add $a0, $t0, $zero
add $a1, $t1, $zero
jal CoordinateToAddress
add $a0, $v0, $zero
lw $a1, backgroundColor
jal DrawPixel
j DrawFruit #finished updating snake, update fruit
MoveTailRight:
#get the screen coordinates of the next direction change
lw $t8, locationInArray
#get the base address of the coordinate array
la $t0, directionChangeAddressArray
#go to the correct index of array
add $t0, $t0, $t8
#get the data from the array
lw $t9, 0($t0)
#get current tail position
lw $a0, snakeTailX
lw $a1, snakeTailY
#if the length needs to be increased
#do not change coordinates
beq $s1, 1, IncreaseLengthRight
#change tail position
addiu $a0, $a0, 1
#store new tail position
sw $a0, snakeTailX
IncreaseLengthRight:
li $s1, 0 #set flag back to false
#get screen coordinates
jal CoordinateToAddress
#store coordinates in $a0
add $a0, $v0, $zero
#if the coordinates is a position change
#continue drawing tail in same direction
bne $t9, $a0, DrawTailRight
#get the base address of the direction change array
la $t3, newDirectionChangeArray
#move to correct index in array
add $t3, $t3, $t8
#get data from array
lw $t9, 0($t3)
#store new direction
sw $t9, tailDirection
#increment position in array
addiu $t8,$t8,4
#if the index is out of bounds, set back to zero
bne $t8, 396, StoreLocationRight
li $t8, 0
StoreLocationRight:
sw $t8, locationInArray
DrawTailRight:
lw $a1, snakeColor
jal DrawPixel
#erase behind the snake
lw $t0, snakeTailX
lw $t1, snakeTailY
addiu $t0, $t0, -1
add $a0, $t0, $zero
add $a1, $t1, $zero
jal CoordinateToAddress
add $a0, $v0, $zero
lw $a1, backgroundColor
jal DrawPixel
j DrawFruit #finished updating snake, update fruit
######################################################
# Draw Fruit
######################################################
DrawFruit:
#check collision with fruit
lw $a0, snakeHeadX
lw $a1, snakeHeadY
jal CheckFruitCollision
beq $v0, 1, AddLength #if fruit was eaten, add length
#draw the fruit
lw $a0, fruitPositionX
lw $a1, fruitPositionY
jal CoordinateToAddress
add $a0, $v0, $zero
lw $a1, fruitColor
jal DrawPixel
j InputCheck
AddLength:
li $s1, 1 #flag to increase snake length
j SpawnFruit
j InputCheck #shouldn't need, but there in case of errors
##################################################################
#CoordinatesToAddress Function
# $a0 -> x coordinate
# $a1 -> y coordinate
##################################################################
# returns $v0 -> the address of the coordinates for bitmap display
##################################################################
CoordinateToAddress:
lw $v0, screenWidth #Store screen width into $v0
mul $v0, $v0, $a1 #multiply by y position
add $v0, $v0, $a0 #add the x position
mul $v0, $v0, 4 #multiply by 4
add $v0, $v0, $gp #add global pointerfrom bitmap display
jr $ra # return $v0
##################################################################
#Draw Function
# $a0 -> Address position to draw at
# $a1 -> Color the pixel should be drawn
##################################################################
# no return value
##################################################################
DrawPixel:
sw $a1, ($a0) #fill the coordinate with specified color
jr $ra #return
##################################################################
# Check Acceptable Direction
# $a0 - current direction
# $a1 - input
# $a2 - coordinates of direction change if acceptable
##################################################################
# return $v0 = 0 - direction unacceptable
# $v0 = 1 - direction is acceptable
##################################################################
CheckDirection:
beq $a0, $a1, Same #if the input is the same as current direction
#continue moving in the direction
beq $a0, 119, checkIsDownPressed #if moving up, check to see if down is pressed
beq $a0, 115, checkIsUpPressed #if moving down, check to see if up is pressed
beq $a0, 97, checkIsRightPressed #if moving left, check to see if right is pressed
beq $a0, 100, checkIsLeftPressed #if moving right, check to see if left is pressed
j DirectionCheckFinished # if input is incorrect, get new input
checkIsDownPressed:
beq $a1, 115, unacceptable #if down is pressed while moving up
#prevent snake from moving into itself
j acceptable
checkIsUpPressed:
beq $a1, 119, unacceptable #if up is pressed while moving down
#prevent snake from moving into itself
j acceptable
checkIsRightPressed:
beq $a1, 100, unacceptable #if right is pressed while moving left
#prevent snake from moving into itself
j acceptable
checkIsLeftPressed:
beq $a1, 97, unacceptable #if left is pressed while moving right
#prevent snake from moving into itself
j acceptable
acceptable:
li $v0, 1
beq $a1, 119, storeUpDirection #store the location of up direction change
beq $a1, 115, storeDownDirection #store the location of down direction change
beq $a1, 97, storeLeftDirection #store the location of left direction change
beq $a1, 100, storeRightDirection #store the location of right direction change
j DirectionCheckFinished
storeUpDirection:
lw $t4, arrayPosition #get the array index
la $t2, directionChangeAddressArray #get the address for the coordinate for direction change
la $t3, newDirectionChangeArray #get address for new direction
add $t2, $t2, $t4 #add the index to the base
add $t3, $t3, $t4
sw $a2, 0($t2) #store the coordinates in that index
li $t5, 119
sw $t5, 0($t3) #store the direction in that index
addiu $t4, $t4, 4 #increment the array index
#if the array will go out of bounds, start it back at 0
bne $t4, 396, UpStop
li $t4, 0
UpStop:
sw $t4, arrayPosition
j DirectionCheckFinished
storeDownDirection:
lw $t4, arrayPosition #get the array index
la $t2, directionChangeAddressArray #get the address for the coordinate for direction change
la $t3, newDirectionChangeArray #get address for new direction
add $t2, $t2, $t4 #add the index to the base
add $t3, $t3, $t4
sw $a2, 0($t2) #store the coordinates in that index
li $t5, 115
sw $t5, 0($t3) #store the direction in that index
addiu $t4, $t4, 4 #increment the array index
#if the array will go out of bounds, start it back at 0
bne $t4, 396, DownStop
li $t4, 0
DownStop:
sw $t4, arrayPosition
j DirectionCheckFinished
storeLeftDirection:
lw $t4, arrayPosition #get the array index
la $t2, directionChangeAddressArray #get the address for the coordinate for direction change
la $t3, newDirectionChangeArray #get address for new direction
add $t2, $t2, $t4 #add the index to the base
add $t3, $t3, $t4
sw $a2, 0($t2) #store the coordinates in that index
li $t5, 97
sw $t5, 0($t3) #store the direction in that index
addiu $t4, $t4, 4 #increment the array index
#if the array will go out of bounds, start it back at 0
bne $t4, 396, LeftStop
li $t4, 0
LeftStop:
sw $t4, arrayPosition
j DirectionCheckFinished
storeRightDirection:
lw $t4, arrayPosition #get the array index
la $t2, directionChangeAddressArray #get the address for the coordinate for direction change
la $t3, newDirectionChangeArray #get address for new direction
add $t2, $t2, $t4 #add the index to the base
add $t3, $t3, $t4
sw $a2, 0($t2) #store the coordinates in that index
li $t5, 100
sw $t5, 0($t3) #store the direction in that index
addiu $t4, $t4, 4 #increment the array index
#if the array will go out of bounds, start it back at 0
bne $t4, 396, RightStop
li $t4, 0
RightStop:
#store array position
sw $t4, arrayPosition
j DirectionCheckFinished
unacceptable:
li $v0, 0 #direction is not acceptable
j DirectionCheckFinished
Same:
li $v0, 1
DirectionCheckFinished:
jr $ra
##################################################################
# Pause Function
# $a0 - amount to pause
##################################################################
# no return values
##################################################################
Pause:
li $v0, 32 #syscall value for sleep
syscall
jr $ra
##################################################################
# Check Fruit Collision
# $a0 - snakeHeadPositionX
# $a1 - snakeHeadPositionY
##################################################################
# returns $v0:
# 0 - does not hit fruit
# 1 - does hit fruit
##################################################################
CheckFruitCollision:
#get fruit coordinates
lw $t0, fruitPositionX
lw $t1, fruitPositionY
#set $v0 to zero, to default to no collision
add $v0, $zero, $zero
#check first to see if x is equal
beq $a0, $t0, XEqualFruit
#if not equal end function
j ExitCollisionCheck
XEqualFruit:
#check to see if the y is equal
beq $a1, $t1, YEqualFruit
#if not eqaul end function
j ExitCollisionCheck
YEqualFruit:
#update the score as fruit has been eaten
lw $t5, score
lw $t6, scoreGain
add $t5, $t5, $t6
sw $t5, score
# play sound to signify score update
li $v0, 31
li $a0, 79
li $a1, 150
li $a2, 7
li $a3, 127
syscall
li $a0, 96
li $a1, 250
li $a2, 7
li $a3, 127
syscall
li $v0, 1 #set return value to 1 for collision
ExitCollisionCheck:
jr $ra
##################################################################
# Check Snake Body Collision
# $a0 - snakeHeadPositionX
# $a1 - snakeHeadPositionY
# $a2 - snakeHeadDirection
##################################################################
# returns $v0:
# 0 - does not hit body
# 1 - does hit body
##################################################################
CheckGameEndingCollision:
#save head coordinates
add $s3, $a0, $zero
add $s4, $a1, $zero
#save return address
sw $ra, 0($sp)
beq $a2, 119, CheckUp
beq $a2, 115, CheckDown
beq $a2, 97, CheckLeft
beq $a2, 100, CheckRight
j BodyCollisionDone #for error?
CheckUp:
#look above the current position
addiu $a1, $a1, -1
jal CoordinateToAddress
#get color at screen address
lw $t1, 0($v0)
#add $s6, $t1, $zero
lw $t2, snakeColor
lw $t3, borderColor
beq $t1, $t2, Exit #If colors are equal - YOU LOST!
beq $t1, $t3, Exit #If you hit the border - YOU LOST!
j BodyCollisionDone # if not, leave function
CheckDown:
#look below the current position
addiu $a1, $a1, 1
jal CoordinateToAddress
#get color at screen address
lw $t1, 0($v0)
#add $s6, $t1, $zero
lw $t2, snakeColor
lw $t3, borderColor
beq $t1, $t2, Exit #If colors are equal - YOU LOST!
beq $t1, $t3, Exit #If you hit the border - YOU LOST!
j BodyCollisionDone # if not, leave function
CheckLeft:
#look to the left of the current position
addiu $a0, $a0, -1
jal CoordinateToAddress
#get color at screen address
lw $t1, 0($v0)
#add $s6, $t1, $zero
lw $t2, snakeColor
lw $t3, borderColor
beq $t1, $t2, Exit #If colors are equal - YOU LOST!
beq $t1, $t3, Exit #If you hit the border - YOU LOST!
j BodyCollisionDone # if not, leave function
CheckRight:
#look to the right of the current position
addiu $a0, $a0, 1
jal CoordinateToAddress
#get color at screen address
lw $t1, 0($v0)
#add $s6, $t1, $zero
lw $t2, snakeColor
lw $t3, borderColor
beq $t1, $t2, Exit #If colors are equal - YOU LOST!
beq $t1, $t3, Exit #If you hit the border - YOU LOST!
j BodyCollisionDone # if not, leave function
BodyCollisionDone:
lw $ra, 0($sp) #restore return address
jr $ra
##################################################################
# Increase Difficulty Function
# no parameters
##################################################################
# no return values
##################################################################
IncreaseDifficulty:
lw $t0, score #get the player's score
la $t1, scoreMilestones #get the milestones base address
lw $t2, scoreArrayPosition #get the array position
add $t1, $t1, $t2 #move to position in array
lw $t3, 0($t1) #get the value at the array index
#if the player score is not equal to the current milestone
#exit the function, if they are equal increase difficulty
bne $t3, $t0, FinishedDiff
#increase the index for the milestones array
addiu $t2, $t2, 4
#store new position
sw $t2, scoreArrayPosition
#load the scoreGain variable to increase the
#points awarded for eating fruit
lw $t0, scoreGain
#multiply gain by 2
sll $t0, $t0, 1
#load the game speed
lw $t1, gameSpeed
#subtract 25 from the move speed
addiu $t1, $t1, -25
#store new speed
sw $t1, gameSpeed
FinishedDiff:
jr $ra
Exit:
#play a sound tune to signify game over
li $v0, 31
li $a0, 28
li $a1, 250
li $a2, 32
li $a3, 127
syscall
li $a0, 33
li $a1, 250
li $a2, 32
li $a3, 127
syscall
li $a0, 47
li $a1, 1000
li $a2, 32
li $a3, 127
syscall
li $v0, 56 #syscall value for dialog
la $a0, lostMessage #get message
lw $a1, score #get score
syscall
li $v0, 50 #syscall for yes/no dialog
la $a0, replayMessage #get message
syscall
beqz $a0, main#jump back to start of program
#end program
li $v0, 10
syscall |
;---------------------------Module-Header------------------------------;
; Module Name: lines.asm
;
; ASM version of the line DDA calculator.
;
; Copyright (c) 1992-1994 Microsoft Corporation
;-----------------------------------------------------------------------;
.386
.model small,c
assume cs:FLAT,ds:FLAT,es:FLAT,ss:FLAT
assume fs:nothing,gs:nothing
.xlist
include stdcall.inc ;calling convention cmacros
include i386\strucs.inc
include i386\lines.inc
.list
.data
public gaflRoundTable
gaflRoundTable label dword
dd FL_H_ROUND_DOWN + FL_V_ROUND_DOWN ; no flips
dd FL_H_ROUND_DOWN + FL_V_ROUND_DOWN ; D flip
dd FL_H_ROUND_DOWN ; V flip
dd FL_V_ROUND_DOWN ; D & V flip
dd FL_V_ROUND_DOWN ; slope one
dd 0baadf00dh
dd FL_H_ROUND_DOWN ; slope one & V flip
dd 0baadf00dh
.code
;--------------------------------Macro----------------------------------;
; testb ebx, <mask>
;
; Substitutes a byte compare if the mask is entirely in the lo-byte or
; hi-byte (thus saving 3 bytes of code space).
;
;-----------------------------------------------------------------------;
TESTB macro targ,mask,thirdarg
local mask2,delta
ifnb <thirdarg>
.err TESTB mask must be enclosed in brackets!
endif
delta = 0
mask2 = mask
if mask2 AND 0ffff0000h
test targ,mask ; If bit set in hi-word,
exitm ; test entire dword
endif
if mask2 AND 0ff00h
if mask2 AND 0ffh ; If bit set in lo-byte and
test targ,mask ; hi-byte, test entire dword
exitm
endif
mask2 = mask2 SHR 8
delta = 1
endif
ifidni <targ>,<EBX>
if delta
test bh,mask2
else
test bl,mask2
endif
exitm
endif
.err Too bad TESTB doesn't support targets other than ebx!
endm
;---------------------------Public-Routine------------------------------;
; bLines(ppdev, pptfxFirst, pptfxBuf, prun, cptfx, pls,
; prclClip, apfn[], flStart)
;
; Handles lines with trivial or simple clipping.
;
;-----------------------------------------------------------------------;
cProc bLines,36,< \
uses esi edi ebx, \
ppdev: ptr, \
pptfxFirst: ptr, \
pptfxBuf: ptr, \
prun: ptr, \
cptfx: dword, \
pls: ptr, \
prclClip: ptr, \
apfn: ptr, \
flStart: dword >
local pptfxBufEnd: ptr ; Last point in pptfxBuf
local M0: dword ; Normalized x0 in device coords
local dM: dword ; Delta-x in device coords
local N0: dword ; Normalized y0 in device coords
local dN: dword ; Delta-y in device coords
local fl: dword ; Flags for current line
local x: dword ; Normalized start pixel x-coord
local y: dword ; Normalized start pixel y-coord
local eqGamma_lo: dword ; Upper 32 bits of Gamma
local eqGamma_hi: dword ; Lower 32 bits of Gamma
local x0: dword ; Start pixel x-offset
local y0: dword ; Start pixel y-offset
local ulSlopeOneAdjustment: dword ; Special offset if line of slope 1
local cStylePels: dword ; # of pixels in line (before clip)
local xStart: dword ; Start pixel x-offset before clip
local pfn: ptr ; Pointer to strip drawing function
local cPels: dword ; # pixels to be drawn (after clip)
local i: dword ; # pixels in strip
local r: dword ; Remainder (or "error") term
local d_I: dword ; Delta-I
local d_R: dword ; Delta-R
local plStripEnd: ptr ; Last strip in buffer
local ptlStart[size POINTL]: byte ; Unnormalized start coord
local dN_Original: dword ; dN before half-flip
local xClipLeft: dword ; Left side of clip rectangle
local xClipRight: dword ; Right side of clip rectangle
local strip[size STRIPS]: byte ; Our strip buffer
mov ecx, cptfx
mov edx, pptfxBuf
lea eax, [edx + ecx * (size POINTL) - (size POINTL)]
mov pptfxBufEnd, eax ; pptfxBufEnd is inclusive of end point
mov eax, [edx].ptl_x ; Load up end point (M1, N1)
mov edi, [edx].ptl_y
mov edx, pptfxFirst ; Load up start point (M0, N0)
mov esi, [edx].ptl_x
mov ecx, [edx].ptl_y
mov ebx, flStart
;-----------------------------------------------------------------------;
; Flip to the first octant. ;
;-----------------------------------------------------------------------;
; Register state: esi = M0
; ecx = N0
; eax = dM (M1)
; edi = dN (N1)
; ebx = fl
; Make sure we go left to right:
the_main_loop:
cmp esi, eax
jle short is_left_to_right ; skip if M0 <= M1
xchg esi, eax ; swap M0, M1
xchg ecx, edi ; swap N0, N1
or ebx, FL_FLIP_H
is_left_to_right:
; Compute the deltas, remembering that the DDI says we should get
; deltas less than 2^31. If we get more, we ensure we don't crash
; later on by simply skipping the line:
sub eax, esi ; eax = dM
jo next_line ; dM must be less than 2^31
sub edi, ecx ; edi = dN
jo next_line ; dN must be less than 2^31
jge short is_top_to_bottom ; skip if dN >= 0
neg ecx ; N0 = -N0
neg edi ; N1 = -N1
or ebx, FL_FLIP_V
is_top_to_bottom:
cmp edi, eax
jb short done_flips ; skip if dN < dM
jne short slope_more_than_one
; We must special case slopes of one:
or ebx, FL_FLIP_SLOPE_ONE
jmp short done_flips
slope_more_than_one:
xchg eax, edi ; swap dM, dN
xchg esi, ecx ; swap M0, N0
or ebx, FL_FLIP_D
done_flips:
mov edx, ebx
and edx, FL_ROUND_MASK
.errnz FL_ROUND_SHIFT - 2
or ebx, [gaflRoundTable + edx] ; get our rounding flags
mov dM, eax ; save some info
mov dN, edi
mov fl, ebx
mov edx, esi ; x = LFLOOR(M0)
sar edx, FLOG2
mov x, edx
mov edx, ecx ; y = LFLOOR(N0)
sar edx, FLOG2
mov y, edx
;-----------------------------------------------------------------------;
; Compute the fractional remainder term ;
;-----------------------------------------------------------------------;
public compute_fractional
compute_fractional::
and esi, F - 1 ; M0 = FXFRAC(M0)
and ecx, F - 1 ; N0 = FXFRAC(N0)
mov M0, esi ; save M0, N0 for later
mov N0, ecx
lea edx, [ecx + F/2]
mul edx ; [edx:eax] = dM * (N0 + F/2)
xchg eax, edi
mov ecx, edx ; [ecx:edi] = dM * (N0 + F/2)
; (we just nuked N0)
mul esi ; [edx:eax] = dN * M0
; Now gamma = dM * (N0 + F/2) - dN * M0 - bRoundDown
.errnz FL_V_ROUND_DOWN - 8000h
ror bh, 8
sbb edi, eax
sbb ecx, edx
shrd edi, ecx, FLOG2
sar ecx, FLOG2 ; gamma = [ecx:edi] >>= 4
mov eqGamma_hi, ecx
mov eqGamma_lo, edi
mov eax, N0
; Register state:
; eax = N0
; ebx = fl
; ecx = eqGamma_hi
; edx = garbage
; esi = M0
; edi = eqGamma_lo
testb ebx, FL_FLIP_H
jnz line_runs_right_to_left
;-----------------------------------------------------------------------;
; Figure out which pixels are at the ends of a left-to-right line. ;
; --------> ;
;-----------------------------------------------------------------------;
public line_runs_left_to_right
line_runs_left_to_right::
or esi, esi
jz short LtoR_check_slope_one
; skip ahead if M0 == 0
; (in that case, x0 = 0 which is to be
; kept in esi, and is already
; conventiently zero)
or eax, eax
jnz short LtoR_N0_not_zero
.errnz FL_H_ROUND_DOWN - 80h
ror bl, 8
sbb esi, -F/2
shr esi, FLOG2
jmp short LtoR_check_slope_one
; esi = x0 = rounded M0
LtoR_N0_not_zero:
sub eax, F/2
sbb edx, edx
xor eax, edx
sub eax, edx
cmp esi, eax
sbb esi, esi
inc esi ; esi = x0 = (abs(N0 - F/2) <= M0)
public LtoR_check_slope_one
LtoR_check_slope_one::
mov ulSlopeOneAdjustment, 0
mov eax, ebx
and eax, FL_FLIP_SLOPE_ONE + FL_H_ROUND_DOWN
cmp eax, FL_FLIP_SLOPE_ONE + FL_H_ROUND_DOWN
jne short LtoR_compute_y0_from_x0
; We have to special case lines that are exactly of slope 1 or -1:
;
; if (M1 > 0) AMD (N1 == M1 + 8)
;
mov eax, N0
add eax, dN
and eax, F - 1 ; eax = N1
mov edx, M0
add edx, dM
and edx, F - 1 ; edx = M1
jz short LtoR_slope_one_check_start_point
add edx, F/2 ; M1 + 8
cmp edx, eax ; cmp N1, M1 + 8
jne short LtoR_slope_one_check_start_point
mov ulSlopeOneAdjustment, -1
LtoR_slope_one_check_start_point:
;
; if (M0 > 0) AMD (N0 == M0 + 8)
;
mov eax, M0
or eax, eax
jz short LtoR_compute_y0_from_x0
add eax, F/2
cmp eax, N0 ; cmp M0 + 8, N0
jne short LtoR_compute_y0_from_x0
xor esi, esi ; x0 = 0
LtoR_compute_y0_from_x0:
; ecx = eqGamma_hi
; esi = x0
; edi = eqGamma_lo
mov eax, dN
mov edx, dM
mov x0, esi
mov y0, 0
cmp ecx, 0
jl short LtoR_compute_x1
neg esi
and esi, eax
sub edx, esi
cmp edi, edx
mov edx, dM
jb short LtoR_compute_x1 ; Bug fix: Must be unsigned!
mov y0, 1 ; y0 = floor((dN * x0 + eqGamma) / dM)
LtoR_compute_x1:
; Register state:
; eax = dN
; ebx = fl
; ecx = garbage
; edx = dM
; esi = garbage
; edi = garbage
mov esi, M0
add esi, edx
mov ecx, esi
shr esi, FLOG2
dec esi ; x1 = ((M0 + dM) >> 4) - 1
add esi, ulSlopeOneAdjustment
and ecx, F-1 ; M1 = (M0 + dM) & 15
jz done_first_pel_last_pel
add eax, N0
and eax, F-1 ; N1 = (N0 + dN) & 15
jnz short LtoR_N1_not_zero
.errnz FL_H_ROUND_DOWN - 80h
ror bl, 8
sbb ecx, -F/2
shr ecx, FLOG2 ; ecx = LROUND(M1, fl & FL_ROUND_DOWN)
add esi, ecx
jmp done_first_pel_last_pel
LtoR_N1_not_zero:
sub eax, F/2
sbb edx, edx
xor eax, edx
sub eax, edx
cmp eax, ecx
jg done_first_pel_last_pel
inc esi
jmp done_first_pel_last_pel
;-----------------------------------------------------------------------;
; Figure out which pixels are at the ends of a right-to-left line. ;
; <-------- ;
;-----------------------------------------------------------------------;
; Compute x0:
public line_runs_right_to_left
line_runs_right_to_left::
mov x0, 1 ; x0 = 1
or eax, eax
jnz short RtoL_N0_not_zero
xor edx, edx ; ulDelta = 0
.errnz FL_H_ROUND_DOWN - 80h
ror bl, 8
sbb esi, -F/2
shr esi, FLOG2 ; esi = LROUND(M0, fl & FL_H_ROUND_DOWN)
jz short RtoL_check_slope_one
mov x0, 2
mov edx, dN
jmp short RtoL_check_slope_one
RtoL_N0_not_zero:
sub eax, F/2
sbb edx, edx
xor eax, edx
sub eax, edx
add eax, esi ; eax = ABS(N0 - F/2) + M0
xor edx, edx ; ulDelta = 0
cmp eax, F
jle short RtoL_check_slope_one
mov x0, 2 ; x0 = 2
mov edx, dN ; ulDelta = dN
public RtoL_check_slope_one
RtoL_check_slope_one::
mov ulSlopeOneAdjustment, 0
mov eax, ebx
and eax, FL_FLIP_SLOPE_ONE + FL_H_ROUND_DOWN
cmp eax, FL_FLIP_SLOPE_ONE
jne short RtoL_compute_y0_from_x0
; We have to special case lines that are exactly of slope 1 or -1:
;
; if ((N1 > 0) && (M1 == N1 + 8))
;
mov eax, N0
add eax, dN
and eax, F - 1 ; eax = N1
jz short RtoL_slope_one_check_start_point
mov esi, M0
add esi, dM
and esi, F - 1 ; esi = M1
add eax, F/2 ; N1 + 8
cmp esi, eax ; cmp M1, N1 + 8
jne short RtoL_slope_one_check_start_point
mov ulSlopeOneAdjustment, 1
RtoL_slope_one_check_start_point:
;
; if ((N0 > 0) && (M0 == N0 + 8))
;
mov eax,N0 ; eax = N0
or eax,eax ; check for N0 == 0
jz short RtoL_compute_y0_from_x0
mov esi, M0 ; esi = M0
add eax, F/2 ; N0 + 8
cmp eax, esi ; cmp M0 , N0 + 8
jne short RtoL_compute_y0_from_x0
mov x0, 2 ; x0 = 2
mov edx, dN ; ulDelta = dN
RtoL_compute_y0_from_x0:
; eax = garbage
; ebx = fl
; ecx = eqGamma_hi
; edx = ulDelta
; esi = garbage
; edi = eqGamma_lo
mov eax, dN ; eax = dN
mov y0, 0 ; y0 = 0
add edi, edx
adc ecx, 0 ; eqGamma += ulDelta
; NOTE: Setting flags here!
mov edx, dM ; edx = dM
jl short RtoL_compute_x1 ; NOTE: Looking at the flags here!
jg short RtoL_y0_is_2
lea ecx, [edx + edx]
sub ecx, eax ; ecx = 2 * dM - dN
cmp edi, ecx
jae short RtoL_y0_is_2 ; Bug fix: Must be unsigned!
sub ecx, edx ; ecx = dM - dN
cmp edi, ecx
jb short RtoL_compute_x1 ; Bug fix: Must be unsigned!
mov y0, 1
jmp short RtoL_compute_x1
RtoL_y0_is_2:
mov y0, 2
RtoL_compute_x1:
; Register state:
; eax = dN
; ebx = fl
; ecx = garbage
; edx = dM
; esi = garbage
; edi = garbage
mov esi, M0
add esi, edx
mov ecx, esi
shr esi, FLOG2 ; x1 = (M0 + dM) >> 4
add esi, ulSlopeOneAdjustment
and ecx, F-1 ; M1 = (M0 + dM) & 15
add eax, N0
and eax, F-1 ; N1 = (N0 + dN) & 15
jnz short RtoL_N1_not_zero
.errnz FL_H_ROUND_DOWN - 80h
ror bl, 8
sbb ecx, -F/2
shr ecx, FLOG2 ; ecx = LROUND(M1, fl & FL_ROUND_DOWN)
add esi, ecx
jmp done_first_pel_last_pel
RtoL_N1_not_zero:
sub eax, F/2
sbb edx, edx
xor eax, edx
sub eax, edx
add eax, ecx ; eax = ABS(N1 - F/2) + M1
cmp eax, F+1
sbb esi, -1
done_first_pel_last_pel:
; Register state:
; eax = garbage
; ebx = fl
; ecx = garbage
; edx = garbage
; esi = x1
; edi = garbage
mov ecx, x0
lea edx, [esi + 1]
sub edx, ecx ; edx = x1 - x0 + 1
jle next_line
mov cStylePels, edx
mov xStart, ecx
;-----------------------------------------------------------------------;
; See if clipping or styling needs to be done. ;
;-----------------------------------------------------------------------;
testb ebx, FL_CLIP
jnz do_some_clipping
; Register state:
; eax = garbage
; ebx = fl
; ecx = x0
; edx = garbage
; esi = x1
; edi = garbage
done_clipping:
mov eax, y0
sub esi, ecx
inc esi ; esi = cPels = x1 - x0 + 1
mov cPels, esi
add ecx, x ; ecx = ptlStart.ptl_x
add eax, y ; eax = ptlStart.ptl_y
testb ebx, FL_FLIP_D
jz short do_v_unflip
xchg ecx, eax
do_v_unflip:
testb ebx, FL_FLIP_V
jz short done_unflips
neg eax
done_unflips:
testb ebx, FL_STYLED
jnz do_some_styling
done_styling:
lea edx, [strip.ST_alStrips + (STRIP_MAX * 4)]
mov plStripEnd, edx
;-----------------------------------------------------------------------;
; Setup to do DDA. ;
;-----------------------------------------------------------------------;
; Register state:
; eax = ptlStart.ptl_y
; ebx = fl
; ecx = ptlStart.ptl_x
; edx = garbage
; esi = garbage
; edi = garbage
mov strip.ST_ptlStart.ptl_x, ecx
mov strip.ST_ptlStart.ptl_y, eax
mov eax, dM
mov ecx, dN
mov esi, eqGamma_lo
mov edi, eqGamma_hi
; Register state:
; eax = dM
; ebx = fl
; ecx = dN
; edx = garbage
; esi = eqGamma_lo
; edi = eqGamma_hi
lea edx, [ecx + ecx] ; if (2 * dN > dM)
cmp edx, eax
mov edx, y0 ; Load y0 again
jbe short after_half_flip
test ebx, (FL_STYLED + FL_DONT_DO_HALF_FLIP)
jnz short after_half_flip
or ebx, FL_FLIP_HALF
mov fl, ebx
; Do a half flip!
not esi
not edi
add esi, eax
adc edi, 0 ; eqGamma = -eqGamma - 1 + dM
neg ecx
add ecx, eax ; dN = dM - dN
neg edx
add edx, x0 ; y0 = x0 - y0
after_half_flip:
mov strip.ST_flFlips, ebx
mov eax, dM
; Register state:
; eax = dM
; ebx = fl
; ecx = dN
; edx = y0
; esi = eqGamma_lo
; edi = eqGamma_hi
or ecx, ecx
jz short zero_slope
compute_dda_stuff:
inc edx
mul edx
stc ; set the carry to accomplish -1
sbb eax, esi
sbb edx, edi ; (y0 + 1) * dM - eqGamma - 1
div ecx
mov esi, eax ; esi = i
mov edi, edx ; edi = r
xor edx, edx
mov eax, dM
div ecx ; edx = d_R, eax = d_I
mov d_I, eax
sub esi, x0
inc esi
done_dda_stuff:
; Register state:
; eax = d_I
; ebx = fl
; ecx = dN
; edx = d_R
; esi = i
; edi = r
; We're going to decide if we can call the short-vector routines. They
; can only take strips that have a maximum length of 15 pixels each.
; We happen to know that the longest strip in our line could be is d_I + 1.
and ebx, FL_STRIP_MASK
mov eax, apfn
.errnz FL_STRIP_SHIFT
lea eax, [eax + ebx * 4]
cmp d_I, MAX_SHORT_STROKE_LENGTH
sbb ebx, ebx ; ffffffffh when < 15, 0 when >= 15
and ebx, NUM_STRIP_DRAW_DIRECTIONS * 4
; Look four entries further into table
mov eax, [eax + ebx]
mov pfn, eax
lea eax, [strip.ST_alStrips]
mov ebx, cPels
;-----------------------------------------------------------------------;
; Do our main DDA loop. ;
;-----------------------------------------------------------------------;
; Register state:
; eax = plStrip
; ebx = cPels
; ecx = dN
; edx = d_R
; esi = i
; edi = r
dda_loop:
sub ebx, esi
jle final_strip
mov [eax], esi
add eax, 4
cmp plStripEnd, eax
jbe short output_strips
done_output_strips:
mov esi, d_I
add edi, edx
cmp edi, ecx
jb short dda_loop
sub edi, ecx
inc esi
jmp short dda_loop
zero_slope:
mov esi, 7fffffffh ; Make run maximum length (cPels
; actually decideds how long the line
; is)
mov d_I, 7fffffffh ; Make delta maximum length so that
; we don't try to do short vectors
mov eax, cPels ; We need this when we decide if to do
dec eax ; short strip routines.
jmp short done_dda_stuff
;-----------------------------------------------------------------------;
; Empty strips buffer. ;
;-----------------------------------------------------------------------;
output_strips:
mov d_R, edx
mov cPels, ebx
mov i, esi
mov r, edi
mov dN, ecx
lea edx, [strip.ST_alStrips]
sub eax, edx
shr eax, 2
mov strip.ST_cStrips, eax
mov eax, ppdev
lea edx, [strip]
mov ecx, pls
ptrCall <dword ptr pfn>, \
<eax, edx, ecx>
mov esi, i
mov edi, r
mov ebx, cPels
mov edx, d_R
mov ecx, dN
lea eax, [strip.ST_alStrips]
jmp done_output_strips
;-----------------------------------------------------------------------;
; Empty strips buffer and go on to next line. ;
;-----------------------------------------------------------------------;
final_strip:
add ebx, esi
mov [eax], ebx
add eax, 4
very_final_strip:
lea edx, [strip.ST_alStrips]
sub eax, edx
shr eax, 2
mov strip.ST_cStrips, eax
mov eax, ppdev
lea edx, [strip]
mov ecx, pls
ptrCall <dword ptr pfn>, \
<eax, edx, ecx>
next_line:
mov ebx, flStart
testb ebx, FL_COMPLEX_CLIP
jnz short see_if_done_complex_clipping
mov edx, pptfxBuf
cmp edx, pptfxBufEnd
je short all_done
mov esi, [edx].ptl_x
mov ecx, [edx].ptl_y
add edx, size POINTL
mov pptfxBuf, edx
mov eax, [edx].ptl_x
mov edi, [edx].ptl_y
jmp the_main_loop
all_done:
mov eax, 1
cRet bLines
see_if_done_complex_clipping:
mov ebx, fl
dec cptfx
jz short all_done
jmp continue_complex_clipping
;---------------------------Private-Routine-----------------------------;
; do_some_styling
;
; Inputs:
; eax = ptlStart.ptl_y
; ebx = fl
; ecx = ptlStart.ptl_x
; Preserves:
; eax, ebx, ecx
; Output:
; Exits to done_styling.
;
;-----------------------------------------------------------------------;
do_some_styling:
mov ptlStart.ptl_x, ecx
mov esi, pls
mov edi, [esi].LS_spNext ; spThis
mov edx, edi
add edx, cStylePels ; spNext
; For styles, we don't bother to keep the style position normalized.
; (we do ensure that it's positive, though). If a figure is over 2
; billion pels long, we'll be a pel off in our style state (oops!).
and edx, 7fffffffh
mov [esi].LS_spNext, edx
mov ptlStart.ptl_y, eax
; Do arbitrary styles:
do_arbitrary_style:
testb ebx, FL_FLIP_H
jz short arbitrary_left_to_right
sub edx, x0
add edx, xStart
mov eax, edx
xor edx, edx
div [esi].LS_spTotal
neg edx
jge short continue_right_to_left
add edx, [esi].LS_spTotal
not eax
continue_right_to_left:
mov edi, dword ptr [esi].LS_jStartMask
not edi
mov ecx, [esi].LS_aspRtoL
jmp short compute_arbitrary_stuff
arbitrary_left_to_right:
add edi, x0
sub edi, xStart
mov eax, edi
xor edx, edx
div [esi].LS_spTotal
mov edi, dword ptr [esi].LS_jStartMask
mov ecx, [esi].LS_aspLtoR
compute_arbitrary_stuff:
; eax = sp / spTotal
; ebx = fl
; ecx = pspStart
; edx = sp % spTotal
; esi = pla
; edi = jStyleMask
and eax, [esi].LS_cStyle ; if odd length style and second run
and al, 1 ; through style array, flip the
jz short odd_style_array_done ; meaning of the elements
not edi
odd_style_array_done:
mov [esi].LS_pspStart, ecx
mov eax, [esi].LS_cStyle
lea eax, [ecx + eax * 4 - 4]
mov [esi].LS_pspEnd, eax
find_psp:
sub edx, [ecx]
jl short found_psp
add ecx, 4
jmp short find_psp
found_psp:
mov [esi].LS_psp, ecx
neg edx
mov [esi].LS_spRemaining, edx
sub ecx, [esi].LS_pspStart
test ecx, 4 ; size STYLEPOS
jz short done_arbitrary
not edi
done_arbitrary:
mov dword ptr [esi].LS_jStyleMask, edi
mov eax, ptlStart.ptl_y
mov ecx, ptlStart.ptl_x
jmp done_styling
;---------------------------Private-Routine-----------------------------;
; do_some_clipping
;
; Inputs:
; eax = garbage
; ebx = fl
; ecx = x0
; edx = garbage
; esi = x1
; edi = garbage
;
; Decides whether to do simple or complex clipping.
;
;-----------------------------------------------------------------------;
align 4
public do_some_clipping
do_some_clipping::
testb ebx, FL_COMPLEX_CLIP
jnz initialize_complex_clipping
;-----------------------------------------------------------------------;
; simple_clipping
;
; Inputs:
; ebx = fl
; ecx = x0
; esi = x1
; Output:
; ebx = fl
; ecx = new x0 (stack variable updated too)
; esi = new x1
; y0 stack variable updated
; Uses:
; All registers
; Exits:
; to done_clipping
;
; This routine handles clipping the line to the clip rectangle (it's
; faster to handle this case in the driver than to call the engine to
; clip for us).
;
; Fractional end-point lines complicate our lives a bit when doing
; clipping:
;
; 1) For styling, we must know the unclipped line's length in pels, so
; that we can correctly update the styling state when the line is
; clipped. For this reason, I do clipping after doing the hard work
; of figuring out which pixels are at the ends of the line (this is
; wasted work if the line is not styled and is completely clipped,
; but I think it's simpler this way). Another reason is that we'll
; have calculated eqGamma already, which we use for the intercept
; calculations.
;
; With the assumption that most lines will not be completely clipped
; away, this strategy isn't too painful.
;
; 2) x0, y0 are not necessarily zero, where (x0, y0) is the start pel of
; the line.
;
; 3) We know x0, y0 and x1, but not y1. We haven't needed to calculate
; y1 until now. We'll need the actual value, and not an upper bound
; like y1 = LFLOOR(dM) + 2 because we have to be careful when
; calculating x(y) that y0 <= y <= y1, otherwise we can cause an
; overflow on the divide (which, needless to say, is bad).
;
;-----------------------------------------------------------------------;
public simple_clipping
simple_clipping::
mov edi, prclClip ; get pointer to normalized clip rect
and ebx, FL_RECTLCLIP_MASK ; (it's lower-right exclusive)
.errnz (FL_RECTLCLIP_SHIFT - 2); ((ebx AND FL_RECTLCLIP_MASK) shr
.errnz (size RECTL) - 16 ; FL_RECTLCLIP_SHIFT) is our index
lea edi, [edi + ebx*4] ; into the array of rectangles
mov edx, [edi].xRight ; load the rect coordinates
mov eax, [edi].xLeft
mov ebx, [edi].yBottom
mov edi, [edi].yTop
; Translate to our origin and so some quick completely clipped tests:
sub edx, x
cmp ecx, edx
jge totally_clipped ; totally clipped if x0 >= xRight
sub eax, x
cmp esi, eax
jl totally_clipped ; totally clipped if x1 < xLeft
sub ebx, y
cmp y0, ebx
jge totally_clipped ; totally clipped if y0 >= yBottom
sub edi, y
; Save some state:
mov xClipRight, edx
mov xClipLeft, eax
cmp esi, edx ; if (x1 >= xRight) x1 = xRight - 1
jl short calculate_y1
lea esi, [edx - 1]
calculate_y1:
mov eax, esi ; y1 = (x1 * dN + eqGamma) / dM
mul dN
add eax, eqGamma_lo
adc edx, eqGamma_hi
div dM
cmp edi, eax ; if (yTop > y1) clipped
jg short totally_clipped
cmp ebx, eax ; if (yBottom > y1) know x1
jg short x1_computed
mov eax, ebx ; x1 = (yBottom * dM + eqBeta) / dN
mul dM
stc
sbb eax, eqGamma_lo
sbb edx, eqGamma_hi
div dN
mov esi, eax
; At this point, we've taken care of calculating the intercepts with the
; right and bottom edges. Now we work on the left and top edges:
x1_computed:
mov edx, y0
mov eax, xClipLeft ; don't have to compute y intercept
cmp eax, ecx ; at left edge if line starts to
jle short top_intercept ; right of left edge
mov ecx, eax ; x0 = xLeft
mul dN ; y0 = (xLeft * dN + eqGamma) / dM
add eax, eqGamma_lo
adc edx, eqGamma_hi
div dM
cmp ebx, eax ; if (yBottom <= y0) clipped
jle short totally_clipped
mov edx, eax
mov y0, eax
top_intercept:
mov ebx, fl ; get ready to leave
mov x0, ecx
cmp edi, edx ; if (yTop <= y0) done clipping
jle done_clipping
mov eax, edi ; x0 = (yTop * dM + eqBeta) / dN + 1
mul dM
stc
sbb eax, eqGamma_lo
sbb edx, eqGamma_hi
div dN
lea ecx, [eax + 1]
cmp xClipRight, ecx ; if (xRight <= x0) clipped
jle short totally_clipped
mov y0, edi ; y0 = yTop
mov x0, ecx
jmp done_clipping ; all done!
totally_clipped:
; The line is completely clipped. See if we have to update our style state:
mov ebx, fl
testb ebx, FL_STYLED
jz next_line
; Adjust our style state:
mov esi, pls
mov eax, [esi].LS_spNext
add eax, cStylePels
mov [esi].LS_spNext, eax
cmp eax, [esi].LS_spTotal2
jb next_line
; Have to normalize first:
xor edx, edx
div [esi].LS_spTotal2
mov [esi].LS_spNext, edx
jmp next_line
;-----------------------------------------------------------------------;
initialize_complex_clipping:
mov eax, dN ; save a copy of original dN
mov dN_Original, eax
;---------------------------Private-Routine-----------------------------;
; continue_complex_clipping
;
; Inputs:
; ebx = fl
; Output:
; ebx = fl
; ecx = x0
; esi = x1
; Uses:
; All registers.
; Exits:
; to done_clipping
;
; This routine handles the necessary initialization for the next
; run in the CLIPLINE structure.
;
; NOTE: This routine is jumped to from two places!
;-----------------------------------------------------------------------;
public continue_complex_clipping
continue_complex_clipping::
mov edi, prun
mov ecx, xStart
testb ebx, FL_FLIP_H
jz short complex_left_to_right
complex_right_to_left:
; Figure out x0 and x1 for right-to-left lines:
add ecx, cStylePels
dec ecx
mov esi, ecx ; esi = ecx = xStart + cStylePels - 1
sub ecx, [edi].RUN_iStop ; New x0
sub esi, [edi].RUN_iStart ; New x1
jmp short complex_reset_variables
complex_left_to_right:
; Figure out x0 and x1 for left-to-right lines:
mov esi, ecx ; esi = ecx = xStart
add ecx, [edi].RUN_iStart ; New x0
add esi, [edi].RUN_iStop ; New x1
complex_reset_variables:
mov x0, ecx
; The half flip mucks with some of our variables, and we have to reset
; them every pass. We would have to reset eqGamma too, but it never
; got saved to memory in its modified form.
add edi, size RUN
mov prun, edi ; Increment run pointer for next time
mov edi, pls
mov eax, [edi].LS_spComplex
mov [edi].LS_spNext, eax ; pls->spNext = pls->spComplex
mov eax, dN_Original ; dN = dN_Original
mov dN, eax
mul ecx
add eax, eqGamma_lo
adc edx, eqGamma_hi ; [edx:eax] = dN*x0 + eqGamma
div dM
mov y0, eax
jmp done_clipping
endProc bLines
end
|
# PACKAGE foo
.data # Data section starts here, strings first
_NL: .asciiz "\n" # NEWLINE STRING
.align 2 # start all global variable aligned
y: .word 7 # global var initialized
Z: .space 4 # global var uninitialized
A: .space 400 # global var uninitialized
x: .word 1 # global var initialized
.text # start of text segment (code)
.globl main # Force MIPS to start at main label
main: # MAIN METHOD LABEL
subu $t0 $sp 8 #set up $t0 to be the new spot for SP
sw $ra ($t0) #Store the return address in offset 0
sw $sp 4($t0) #Store the old stack pointer in offset 4
move $sp $t0 #set the stack pointer to the new value
li $v0 0 #return NULL zero (0)
lw $ra ($sp) #reset return address
lw $ra 4($sp) #reset stack pointer
li $v0, 10 #Main function ends
syscall #MAIN FUNCTION EXIT
|
; A190505: n+[nr/s]+[nt/s]+[nu/s]; r=golden ratio, s=r+1, t=r+2, u=r+3.
; 3,8,13,18,22,27,32,37,41,46,51,56,60,65,70,75,79,84,89,94,99,103,108,113,118,122,127,132,137,141,146,151,156,160,165,170,175,180,184,189,194,199,203,208,213,218,222,227,232,237,241,246,251,256,261,265,270,275,280,284,289,294,299,303,308,313,318,322,327,332,337
mov $3,$0
mul $0,2
mov $1,$0
mov $0,6
mov $2,3
add $2,$1
add $1,1
sub $2,1
add $0,$2
sub $0,5
mul $0,2
add $1,1
mov $4,1
lpb $0
sub $0,17
trn $0,1
add $0,1
sub $1,$4
lpe
lpb $3
add $1,3
sub $3,1
lpe
add $1,2
|
// Copyright Lin Min 2014
#include <iostream>
#include <stdint.h>
#include <fcntl.h>
#include <string>
#include <algorithm>
#include <vector>
#include <fstream> // NOLINT(readability/streams)
#include <glog/logging.h>
#include <cstdlib>
#include <sys/syscall.h>
#include <glog/logging.h>
#include <mpi.h>
#include "common/common.hpp"
using std::fstream;
using std::ios;
using std::string;
using namespace std;
namespace purine {
string mpi_strerror(int errorcode) {
int len;
char estring[MPI_MAX_ERROR_STRING];
MPI_Error_string(errorcode, estring, &len);
return string(estring, len);
}
string get_env(const string& env) {
const char* env_value = getenv(env.c_str());
CHECK(env_value) << "Environment Variable " << env << " is not defined";
return env_value;
}
int64_t cluster_seedgen(void) {
int64_t s, seed, pid, tid;
FILE* f = fopen("/dev/urandom", "rb");
if (f && fread(&seed, 1, sizeof(seed), f) == sizeof(seed)) {
fclose(f);
return seed;
}
LOG(INFO) << "System entropy source not available, "
"using fallback algorithm to generate seed instead.";
if (f)
fclose(f);
pid = getpid();
tid = syscall(SYS_gettid);
s = time(NULL);
// TODO: how to hash with tid
seed = abs(((s * 181) * ((pid + tid - 83) * 359)) % 104729);
return seed;
}
rng_t* caffe_rng() {
static thread_local rng_t rng_(cluster_seedgen());
return &rng_;
}
int current_rank() {
int rank;
MPI_CHECK(MPI_Comm_rank(MPI_COMM_WORLD, &rank));
return rank;
}
void print_graph(const vector<vector<string> >& print_out) {
for (const vector<string>& ss : print_out) {
for (vector<string>::const_iterator it = ss.begin(); it != ss.end(); it++) {
if (it == ss.begin()) {
cout << *it;
} else {
cout << "\033[1;37m --> \033[0m" << *it;
}
if (it == ss.end() - 1) {
cout << endl;
}
}
}
}
}
|
; ==================================================================================================
; Change flags used to spawn Mido outside Deku and inside his house as child.
; Now requires the flags for showing Mido a sword/shield, Mido talking to you after Deku Tree's death,
; as well as either Obtained Zelda's Letter or beating Deku Tree to move Mido to his house.
; ==================================================================================================
.orga 0xE62948
sw a0, 0(sp)
lh v0, 0x00A4(a1) ; Current Scene
lui v1, 0x8012 ; Save Context (upper half)
li at, 0x0055 ; Scene ID for Kokiri Forest
addiu v1, v1, 0xA5D0 ; Save Context (lower half)
lhu t0, 0x0ED4(v1) ; event_chk_inf[0]
andi t1, t0, 0x0080 ; "Obtained Kokiri Emerald & Deku Tree Dead"
andi t2, t0, 0x0010 ; "Showed Mido Sword & Shield"
lhu t0, 0x0EDC(v1) ; event_chk_inf[4]
andi t3, t0, 0x0001 ; "Obtained Zelda's Letter"
lhu t0, 0x0ED6(v1) ; event_chk_inf[1]
andi t5, t0, 0x1000 ; "Spoke to Mido After Deku Tree's Death"
or t6, t1, t3 ; Composite of "Obtained Kokiri Emerald & Deku Tree Dead" and "Obtained Zelda's Letter"
or t7, t2, t5 ; Composite of "Showed Mido Sword & Shield" and "Spoke to Mido After Deku Tree's Death"
bne v0, at, @@midos_house ; If the current scene isn't Kokiri Forest, move to the Mido's House section.
li t8, 0x1010 ; This is the hex value of t7 if both its flags are set.
beqz t6, @@success ; If neither flag in t6 are set, spawn Mido.
nop
beq t7, t8, @@failure ; If both flags in t7 are set, don't spawn Mido.
nop
@@success:
jr ra ; Return (spawn Mido).
li v0, 1
@@midos_house:
li at, 0x0028 ; Scene ID for Mido's House
bne v0, at, @@lost_woods ; If current scene isn't Mido's House, move to the Lost Woods section.
nop
beqz t6, @@failure ; If neither flag in t6 are set, don't spawn Mido.
nop
bne t7, t8, @@failure ; If both flags in t7 aren't set, don't spawn Mido.
nop
lw t4, 0x0004(v1) ; Link's Current Age
bnez t4, @@success ; If Link is a child, spawn Mido.
nop
@@lost_woods:
li at, 0x005B ; Scene ID for Lost Woods.
beq v0, at, @@success ; If current scene is Lost Woods, spawn Mido.
nop
@@failure:
jr ra ; Return (don't spawn Mido).
move v0, zero
; This block consisted of 41 instructions, below are nop instructions to make this 41 instructions long.
nop
nop
nop
nop
; ==================================================================================================
; Changes Mido's conversation flow in Kokiri. By default, he prioritizes talking about
; Deku Tree's death instead of asking for you to get a Sword and Shield. This doesn't
; matter normally but is a major issue for entrance randomizer.
; ==================================================================================================
.orga 0xE62630
sh zero, 0x01F8(a0)
addiu v1, v1, 0xA5D0
lhu t9, 0x0ED4(v1) ; If this is t9, it saves setting it later for the next branch.
li t7, 0x0090 ; Mask for "Showed Mido Sword & Shield" and "Obtained Kokiri Emerald & Deku Tree Dead"
and t8, t9, t7
bne t8, t7, 0x00E62660
nop
b 0x00E626DC
li v0, 0x1045 ; Mido complaining about Deku Tree's death.
nop
nop
nop
|
ldy #0
sta ({z1}),y
tya
iny
sta ({z1}),y |
; int vsscanf_callee(const char *s, const char *format, va_list arg)
SECTION code_clib
SECTION code_stdio
PUBLIC _vsscanf_callee, l0_vsscanf_callee
EXTERN asm_vsscanf
_vsscanf_callee:
pop af
pop hl
pop de
pop bc
push af
l0_vsscanf_callee:
push ix
call asm_vsscanf
pop ix
ret
|
; A072894: Let c(k) be defined as follows: c(1)=1, c(2)=n, c(k+2) = c(k+1)/2 + c(k)/2 if c(k+1) and c(k) have the same parity; c(k+2) = c(k+1)/2 + c(k)/2 + 1/2 otherwise; a(n) = limit_{ k -> infinity} c(k).
; 1,2,3,4,4,5,6,7,7,8,9,10,10,11,11,12,12,13,14,15,15,16,17,18,18,19,20,21,21,22,22,23,23,24,25,26,26,27,28,29,29,30,31,32,32,33,33,34,34,35,36,37,37,38,38,39,39,40,41,42,42,43,43,44,44,45,46,47,47,48,49,50,50
mul $0,2
mov $1,2
mov $2,1
mov $3,1
lpb $0
add $0,$2
div $0,2
add $2,$0
sub $0,1
add $1,$3
div $2,2
lpe
sub $1,1
|
; A014925: Number of zeros in numbers 1 to 111...1 (n+1 digits).
; 1,21,321,4321,54321,654321,7654321,87654321,987654321,10987654321,120987654321,1320987654321,14320987654321,154320987654321,1654320987654321,17654320987654321,187654320987654321
add $0,1
lpb $0
add $2,$0
sub $0,1
mul $2,10
mov $1,$2
lpe
div $1,10
mov $0,$1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r13
push %r14
push %r8
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_UC_ht+0x1db9b, %r10
nop
nop
nop
nop
nop
sub %r13, %r13
mov $0x6162636465666768, %rsi
movq %rsi, %xmm1
movups %xmm1, (%r10)
add $8691, %r14
lea addresses_normal_ht+0x3acb, %r13
nop
nop
nop
nop
add %rdx, %rdx
movb $0x61, (%r13)
cmp %rdx, %rdx
lea addresses_WT_ht+0x770b, %rsi
lea addresses_D_ht+0x63ab, %rdi
nop
nop
dec %r10
mov $58, %rcx
rep movsw
nop
nop
nop
nop
and %r14, %r14
lea addresses_WC_ht+0x88b, %rcx
nop
nop
nop
inc %rdx
mov $0x6162636465666768, %r10
movq %r10, %xmm4
vmovups %ymm4, (%rcx)
nop
nop
nop
cmp $38055, %r14
lea addresses_UC_ht+0x3ffb, %rsi
lea addresses_UC_ht+0x1a6cb, %rdi
nop
cmp $25571, %rdx
mov $27, %rcx
rep movsl
nop
xor $9808, %rdi
lea addresses_WC_ht+0x164cb, %rsi
lea addresses_UC_ht+0x24cb, %rdi
cmp %r8, %r8
mov $124, %rcx
rep movsl
and $27664, %r10
lea addresses_A_ht+0x14367, %r10
nop
nop
nop
inc %r8
mov (%r10), %edi
nop
nop
nop
nop
nop
inc %r14
lea addresses_A_ht+0xccdb, %r14
nop
nop
and %rdi, %rdi
mov $0x6162636465666768, %rdx
movq %rdx, %xmm2
vmovups %ymm2, (%r14)
nop
nop
nop
nop
nop
cmp $9242, %rdx
lea addresses_WT_ht+0x15ecb, %rsi
lea addresses_WC_ht+0x4ccb, %rdi
clflush (%rdi)
nop
nop
add %r14, %r14
mov $114, %rcx
rep movsl
nop
nop
nop
nop
cmp %r13, %r13
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %r8
pop %r14
pop %r13
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r14
push %r9
push %rbp
push %rcx
push %rdi
push %rdx
// Load
lea addresses_RW+0x137e7, %rdx
nop
add %rbp, %rbp
mov (%rdx), %r9w
nop
inc %rcx
// Store
lea addresses_PSE+0x34cb, %r13
clflush (%r13)
nop
sub $60923, %rdi
mov $0x5152535455565758, %rbp
movq %rbp, %xmm5
movups %xmm5, (%r13)
nop
nop
xor $45411, %r9
// Store
lea addresses_A+0xd44b, %r9
nop
dec %rcx
mov $0x5152535455565758, %r13
movq %r13, %xmm1
movups %xmm1, (%r9)
nop
nop
nop
nop
nop
sub $55481, %rbp
// Store
lea addresses_WT+0x64cb, %r9
nop
sub $33787, %r13
movb $0x51, (%r9)
nop
nop
nop
xor $20044, %r13
// Store
lea addresses_WC+0x6ccb, %rcx
nop
nop
add %rdi, %rdi
movl $0x51525354, (%rcx)
nop
nop
nop
nop
dec %r13
// Store
lea addresses_PSE+0xafcb, %rcx
clflush (%rcx)
add %r14, %r14
mov $0x5152535455565758, %r13
movq %r13, %xmm5
vmovups %ymm5, (%rcx)
nop
nop
nop
nop
and $24084, %rdx
// Faulty Load
lea addresses_PSE+0x34cb, %r9
nop
nop
nop
nop
nop
sub $3778, %r14
mov (%r9), %edx
lea oracles, %r13
and $0xff, %rdx
shlq $12, %rdx
mov (%r13,%rdx,1), %rdx
pop %rdx
pop %rdi
pop %rcx
pop %rbp
pop %r9
pop %r14
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': True, 'AVXalign': False, 'size': 1, 'congruent': 0, 'same': True, 'type': 'addresses_PSE'}, 'OP': 'LOAD'}
{'src': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 2, 'same': False, 'type': 'addresses_RW'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0, 'same': True, 'type': 'addresses_PSE'}, 'OP': 'STOR'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 5, 'same': False, 'type': 'addresses_A'}, 'OP': 'STOR'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 9, 'same': False, 'type': 'addresses_WT'}, 'OP': 'STOR'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 11, 'same': False, 'type': 'addresses_WC'}, 'OP': 'STOR'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 7, 'same': False, 'type': 'addresses_PSE'}, 'OP': 'STOR'}
[Faulty Load]
{'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0, 'same': True, 'type': 'addresses_PSE'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'dst': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 3, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'STOR'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 9, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'STOR'}
{'src': {'congruent': 6, 'same': False, 'type': 'addresses_WT_ht'}, 'dst': {'congruent': 4, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'REPM'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 5, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'STOR'}
{'src': {'congruent': 3, 'same': False, 'type': 'addresses_UC_ht'}, 'dst': {'congruent': 8, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'REPM'}
{'src': {'congruent': 11, 'same': False, 'type': 'addresses_WC_ht'}, 'dst': {'congruent': 11, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'REPM'}
{'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 2, 'same': True, 'type': 'addresses_A_ht'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 4, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'STOR'}
{'src': {'congruent': 9, 'same': False, 'type': 'addresses_WT_ht'}, 'dst': {'congruent': 11, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM'}
{'58': 21829}
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
*/
|
# Test27 - IsEq Test
pushi 3
pushi 3
isEq
halt |
/*
Copyright 2002, 2005 Daryle Walker
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_IO_IOS_STATE_HPP
#define BOOST_IO_IOS_STATE_HPP
#include <boost/config.hpp>
#include <boost/io_fwd.hpp>
#include <ios>
#ifndef BOOST_NO_STD_LOCALE
#include <locale>
#endif
#include <ostream>
#include <streambuf>
#include <string>
namespace lslboost {
namespace io {
class ios_flags_saver {
public:
typedef std::ios_base state_type;
typedef std::ios_base::fmtflags aspect_type;
explicit ios_flags_saver(state_type& s)
: s_save_(s)
, a_save_(s.flags()) { }
ios_flags_saver(state_type& s, aspect_type a)
: s_save_(s)
, a_save_(s.flags(a)) { }
~ios_flags_saver() {
this->restore();
}
void restore() {
s_save_.flags(a_save_);
}
private:
ios_flags_saver(const ios_flags_saver&);
ios_flags_saver& operator=(const ios_flags_saver&);
state_type& s_save_;
aspect_type a_save_;
};
class ios_precision_saver {
public:
typedef std::ios_base state_type;
typedef std::streamsize aspect_type;
explicit ios_precision_saver(state_type& s)
: s_save_(s)
, a_save_(s.precision()) { }
ios_precision_saver(state_type& s, aspect_type a)
: s_save_(s)
, a_save_(s.precision(a)) { }
~ios_precision_saver() {
this->restore();
}
void restore() {
s_save_.precision(a_save_);
}
private:
ios_precision_saver(const ios_precision_saver&);
ios_precision_saver& operator=(const ios_precision_saver&);
state_type& s_save_;
aspect_type a_save_;
};
class ios_width_saver {
public:
typedef std::ios_base state_type;
typedef std::streamsize aspect_type;
explicit ios_width_saver(state_type& s)
: s_save_(s)
, a_save_(s.width()) { }
ios_width_saver(state_type& s, aspect_type a)
: s_save_(s)
, a_save_(s.width(a)) { }
~ios_width_saver() {
this->restore();
}
void restore() {
s_save_.width(a_save_);
}
private:
ios_width_saver(const ios_width_saver&);
ios_width_saver& operator=(const ios_width_saver&);
state_type& s_save_;
aspect_type a_save_;
};
template<class Ch, class Tr>
class basic_ios_iostate_saver {
public:
typedef std::basic_ios<Ch, Tr> state_type;
typedef std::ios_base::iostate aspect_type;
explicit basic_ios_iostate_saver(state_type& s)
: s_save_(s)
, a_save_(s.rdstate()) { }
basic_ios_iostate_saver(state_type& s, aspect_type a)
: s_save_(s)
, a_save_(s.rdstate()) {
s.clear(a);
}
~basic_ios_iostate_saver() {
this->restore();
}
void restore() {
s_save_.clear(a_save_);
}
private:
basic_ios_iostate_saver(const basic_ios_iostate_saver&);
basic_ios_iostate_saver& operator=(const basic_ios_iostate_saver&);
state_type& s_save_;
aspect_type a_save_;
};
template<class Ch, class Tr>
class basic_ios_exception_saver {
public:
typedef std::basic_ios<Ch, Tr> state_type;
typedef std::ios_base::iostate aspect_type;
explicit basic_ios_exception_saver(state_type& s)
: s_save_(s)
, a_save_(s.exceptions()) { }
basic_ios_exception_saver(state_type& s, aspect_type a)
: s_save_(s)
, a_save_(s.exceptions()) {
s.exceptions(a);
}
~basic_ios_exception_saver() {
this->restore();
}
void restore() {
s_save_.exceptions(a_save_);
}
private:
basic_ios_exception_saver(const basic_ios_exception_saver&);
basic_ios_exception_saver& operator=(const basic_ios_exception_saver&);
state_type& s_save_;
aspect_type a_save_;
};
template<class Ch, class Tr>
class basic_ios_tie_saver {
public:
typedef std::basic_ios<Ch, Tr> state_type;
typedef std::basic_ostream<Ch, Tr>* aspect_type;
explicit basic_ios_tie_saver(state_type& s)
: s_save_(s)
, a_save_(s.tie()) { }
basic_ios_tie_saver(state_type& s, aspect_type a)
: s_save_(s)
, a_save_(s.tie(a)) { }
~basic_ios_tie_saver() {
this->restore();
}
void restore() {
s_save_.tie(a_save_);
}
private:
basic_ios_tie_saver(const basic_ios_tie_saver&);
basic_ios_tie_saver& operator=(const basic_ios_tie_saver&);
state_type& s_save_;
aspect_type a_save_;
};
template<class Ch, class Tr>
class basic_ios_rdbuf_saver {
public:
typedef std::basic_ios<Ch, Tr> state_type;
typedef std::basic_streambuf<Ch, Tr>* aspect_type;
explicit basic_ios_rdbuf_saver(state_type& s)
: s_save_(s)
, a_save_(s.rdbuf()) { }
basic_ios_rdbuf_saver(state_type& s, aspect_type a)
: s_save_(s)
, a_save_(s.rdbuf(a)) { }
~basic_ios_rdbuf_saver() {
this->restore();
}
void restore() {
s_save_.rdbuf(a_save_);
}
private:
basic_ios_rdbuf_saver(const basic_ios_rdbuf_saver&);
basic_ios_rdbuf_saver& operator=(const basic_ios_rdbuf_saver&);
state_type& s_save_;
aspect_type a_save_;
};
template<class Ch, class Tr>
class basic_ios_fill_saver {
public:
typedef std::basic_ios<Ch, Tr> state_type;
typedef typename state_type::char_type aspect_type;
explicit basic_ios_fill_saver(state_type& s)
: s_save_(s)
, a_save_(s.fill()) { }
basic_ios_fill_saver(state_type& s, aspect_type a)
: s_save_(s)
, a_save_(s.fill(a)) { }
~basic_ios_fill_saver() {
this->restore();
}
void restore() {
s_save_.fill(a_save_);
}
private:
basic_ios_fill_saver(const basic_ios_fill_saver&);
basic_ios_fill_saver& operator=(const basic_ios_fill_saver&);
state_type& s_save_;
aspect_type a_save_;
};
#ifndef BOOST_NO_STD_LOCALE
template<class Ch, class Tr>
class basic_ios_locale_saver {
public:
typedef std::basic_ios<Ch, Tr> state_type;
typedef std::locale aspect_type;
explicit basic_ios_locale_saver(state_type& s)
: s_save_(s)
, a_save_(s.getloc()) { }
basic_ios_locale_saver(state_type& s, const aspect_type& a)
: s_save_(s)
, a_save_(s.imbue(a)) { }
~basic_ios_locale_saver() {
this->restore();
}
void restore() {
s_save_.imbue(a_save_);
}
private:
basic_ios_locale_saver(const basic_ios_locale_saver&);
basic_ios_locale_saver& operator=(const basic_ios_locale_saver&);
state_type& s_save_;
aspect_type a_save_;
};
#endif
class ios_iword_saver {
public:
typedef std::ios_base state_type;
typedef int index_type;
typedef long aspect_type;
explicit ios_iword_saver(state_type& s, index_type i)
: s_save_(s)
, a_save_(s.iword(i))
, i_save_(i) { }
ios_iword_saver(state_type& s, index_type i, aspect_type a)
: s_save_(s)
, a_save_(s.iword(i))
, i_save_(i) {
s.iword(i) = a;
}
~ios_iword_saver() {
this->restore();
}
void restore() {
s_save_.iword(i_save_) = a_save_;
}
private:
ios_iword_saver(const ios_iword_saver&);
ios_iword_saver& operator=(const ios_iword_saver&);
state_type& s_save_;
aspect_type a_save_;
index_type i_save_;
};
class ios_pword_saver {
public:
typedef std::ios_base state_type;
typedef int index_type;
typedef void* aspect_type;
explicit ios_pword_saver(state_type& s, index_type i)
: s_save_(s)
, a_save_(s.pword(i))
, i_save_(i) { }
ios_pword_saver(state_type& s, index_type i, aspect_type a)
: s_save_(s)
, a_save_(s.pword(i))
, i_save_(i) {
s.pword(i) = a;
}
~ios_pword_saver() {
this->restore();
}
void restore() {
s_save_.pword(i_save_) = a_save_;
}
private:
ios_pword_saver(const ios_pword_saver&);
ios_pword_saver operator=(const ios_pword_saver&);
state_type& s_save_;
aspect_type a_save_;
index_type i_save_;
};
class ios_base_all_saver {
public:
typedef std::ios_base state_type;
explicit ios_base_all_saver(state_type& s)
: s_save_(s)
, a1_save_(s.flags())
, a2_save_(s.precision())
, a3_save_(s.width()) { }
~ios_base_all_saver() {
this->restore();
}
void restore() {
s_save_.width(a3_save_);
s_save_.precision(a2_save_);
s_save_.flags(a1_save_);
}
private:
ios_base_all_saver(const ios_base_all_saver&);
ios_base_all_saver& operator=(const ios_base_all_saver&);
state_type& s_save_;
state_type::fmtflags a1_save_;
std::streamsize a2_save_;
std::streamsize a3_save_;
};
template<class Ch, class Tr>
class basic_ios_all_saver {
public:
typedef std::basic_ios<Ch, Tr> state_type;
explicit basic_ios_all_saver(state_type& s)
: s_save_(s)
, a1_save_(s.flags())
, a2_save_(s.precision())
, a3_save_(s.width())
, a4_save_(s.rdstate())
, a5_save_(s.exceptions())
, a6_save_(s.tie())
, a7_save_(s.rdbuf())
, a8_save_(s.fill())
#ifndef BOOST_NO_STD_LOCALE
, a9_save_(s.getloc())
#endif
{ }
~basic_ios_all_saver() {
this->restore();
}
void restore() {
#ifndef BOOST_NO_STD_LOCALE
s_save_.imbue(a9_save_);
#endif
s_save_.fill(a8_save_);
s_save_.rdbuf(a7_save_);
s_save_.tie(a6_save_);
s_save_.exceptions(a5_save_);
s_save_.clear(a4_save_);
s_save_.width(a3_save_);
s_save_.precision(a2_save_);
s_save_.flags(a1_save_);
}
private:
basic_ios_all_saver(const basic_ios_all_saver&);
basic_ios_all_saver& operator=(const basic_ios_all_saver&);
state_type& s_save_;
typename state_type::fmtflags a1_save_;
std::streamsize a2_save_;
std::streamsize a3_save_;
typename state_type::iostate a4_save_;
typename state_type::iostate a5_save_;
std::basic_ostream<Ch, Tr>* a6_save_;
std::basic_streambuf<Ch, Tr>* a7_save_;
typename state_type::char_type a8_save_;
#ifndef BOOST_NO_STD_LOCALE
std::locale a9_save_;
#endif
};
class ios_all_word_saver {
public:
typedef std::ios_base state_type;
typedef int index_type;
ios_all_word_saver(state_type& s, index_type i)
: s_save_(s)
, i_save_(i)
, a1_save_(s.iword(i))
, a2_save_(s.pword(i)) { }
~ios_all_word_saver() {
this->restore();
}
void restore() {
s_save_.pword(i_save_) = a2_save_;
s_save_.iword(i_save_) = a1_save_;
}
private:
ios_all_word_saver(const ios_all_word_saver&);
ios_all_word_saver& operator=(const ios_all_word_saver&);
state_type& s_save_;
index_type i_save_;
long a1_save_;
void* a2_save_;
};
} /* io */
} /* boost */
#endif
|
#include "hzpch.h"
#include "Buffer.h"
#include "Renderer.h"
#include "Platform/OpenGL/OpenGLBuffer.h"
namespace Hazel {
VertexBuffer* VertexBuffer::Create(float* vertices, uint32_t size)
{
switch (Renderer::GetAPI())
{
case RendererAPI::API::None: HZ_CORE_ASSERT(false, "RendererAPI::None is currently not supported"); return nullptr;
case RendererAPI::API::OpenGL: return new OpenGLVertexBuffer(vertices, size);
}
HZ_CORE_ASSERT(false, "Unknown RendererAPI");
return nullptr;
}
IndexBuffer* IndexBuffer::Create(uint32_t* indices, uint32_t size)
{
switch (Renderer::GetAPI())
{
case RendererAPI::API::None: HZ_CORE_ASSERT(false, "RendererAPI::None is currently not supported"); return nullptr;
case RendererAPI::API::OpenGL: return new OpenGLIndexBuffer(indices, size);
}
HZ_CORE_ASSERT(false, "Unknown RendererAPI");
return nullptr;
}
} |
DrawHP:
; Draws the HP bar in the stats screen
call GetPredefRegisters
ld a, $1
jr DrawHP_
DrawHP2:
; Draws the HP bar in the party screen
call GetPredefRegisters
ld a, $2
DrawHP_:
ld [wHPBarType], a
push hl
ld a, [wLoadedMonHP]
ld b, a
ld a, [wLoadedMonHP + 1]
ld c, a
or b
jr nz, .nonzeroHP
xor a
ld c, a
ld e, a
ld a, $6
ld d, a
jp .drawHPBarAndPrintFraction
.nonzeroHP
ld a, [wLoadedMonMaxHP]
ld d, a
ld a, [wLoadedMonMaxHP + 1]
ld e, a
predef HPBarLength
ld a, $6
ld d, a
ld c, a
.drawHPBarAndPrintFraction
pop hl
push de
push hl
push hl
call DrawHPBar
pop hl
ld a, [hFlags_0xFFF6]
bit 0, a
jr z, .printFractionBelowBar
ld bc, $9 ; right of bar
jr .printFraction
.printFractionBelowBar
ld bc, SCREEN_WIDTH + 1 ; below bar
.printFraction
add hl, bc
ld de, wLoadedMonHP
lb bc, 2, 3
call PrintNumber
ld a, "/"
ld [hli], a
ld de, wLoadedMonMaxHP
lb bc, 2, 3
call PrintNumber
pop hl
pop de
ret
; Predef 0x37
StatusScreen:
call LoadMonData
ld a, [wMonDataLocation]
cp BOX_DATA
jr c, .DontRecalculate
; mon is in a box or daycare
ld a, [wLoadedMonBoxLevel]
ld [wLoadedMonLevel], a
ld [wCurEnemyLVL], a
ld hl, wLoadedMonHPExp - 1
ld de, wLoadedMonStats
ld b, $1
call CalcStats ; Recalculate stats
.DontRecalculate
ld hl, wd72c
set 1, [hl]
ld a, $33
ld [rNR50], a ; Reduce the volume
call GBPalWhiteOutWithDelay3
call ClearScreen
call UpdateSprites
call LoadHpBarAndStatusTilePatterns
ld de, BattleHudTiles1 ; source
ld hl, vChars2 + $6d0 ; dest
lb bc, BANK(BattleHudTiles1), $03
call CopyVideoDataDouble ; ·│ :L and halfarrow line end
ld de, BattleHudTiles2
ld hl, vChars2 + $780
lb bc, BANK(BattleHudTiles2), $01
call CopyVideoDataDouble ; │
ld de, BattleHudTiles3
ld hl, vChars2 + $760
lb bc, BANK(BattleHudTiles3), $02
call CopyVideoDataDouble ; ─┘
ld a, [hTilesetType]
push af
xor a
ld [hTilesetType], a
coord hl, 19, 3
lb bc, 2, 8
call DrawLineBox ; Draws the box around name, HP and status
coord hl, 3, 7
nop
ld [hl], "⠄" ; . after No ("." is a different one)
dec hl
ld [hl], "№"
coord hl, 19, 9
lb bc, 8, 8
call DrawLineBox ; Draws the box around types, ID No. and OT
coord hl, 10, 9
ld de, Type1Text
call PlaceString ; "TYPE1:"
coord hl, 11, 3
predef DrawHP
ld hl, wStatusScreenHPBarColor
call GetHealthBarColor
ld b, SET_PAL_STATUS_SCREEN
call StatusScreenHook
coord hl, 12, 2
ld de, wLoadedMonStatus
call PrintStatusCondition
; jr nz, .StatusWritten
; coord hl, 11, 7
; ld de, OKText
; call PlaceString ; "OK"
.StatusWritten
; coord hl, 10, 6
; ld de, StatusText
; call PlaceString ; "STATUS:"
coord hl, 15, 2
call PrintLevel ; Pokémon level
ld a, [wMonHIndex]
ld [wd11e], a
ld [wd0b5], a
coord hl, 4, 7
ld de, wd11e
lb bc, LEADING_ZEROES | 1, 3
call PrintNumber ; Pokémon no.
coord hl, 11, 10
predef PrintMonType
ld hl, NamePointers2
call .GetStringPointer
ld d, h
ld e, l
coord hl, 9, 1
call PlaceString ; Pokémon name
ld hl, OTPointers
call .GetStringPointer
ld d, h
ld e, l
coord hl, 11, 16
call PlaceString ; OT
coord hl, 11, 14
ld de, wLoadedMonOTID
lb bc, LEADING_ZEROES | 2, 5
call PrintNumber ; ID Number
ld d, $0
call PrintStatsBox
call Delay3
call GBPalNormal
coord hl, 1, 0
call LoadFlippedFrontSpriteByMonIndex ; draw Pokémon picture
ld a, [wcf91]
call PlayCry ; play Pokémon cry
call WaitForTextScrollButtonPress ; wait for button
pop af
ld [hTilesetType], a
ret
.GetStringPointer
ld a, [wMonDataLocation]
add a
ld c, a
ld b, 0
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wMonDataLocation]
cp DAYCARE_DATA
ret z
ld a, [wWhichPokemon]
jp SkipFixedLengthTextEntries
OTPointers:
dw wPartyMonOT
dw wEnemyMonOT
dw wBoxMonOT
dw wDayCareMonOT
NamePointers2:
dw wPartyMonNicks
dw wEnemyMonNicks
dw wBoxMonNicks
dw wDayCareMonName
Type1Text:
db "TYPE1:", $4e
Type2Text:
db "TYPE2:", $4e
IDNoText:
db $73, "№⠄", $4e
OTText:
db "OT:"
next "@"
StatusText:
db "STATUS @"
OKText:
db "OK@"
; Draws a line starting from hl high b and wide c
DrawLineBox:
ld de, SCREEN_WIDTH ; New line
.PrintVerticalLine
ld [hl], $78 ; │
add hl, de
dec b
jr nz, .PrintVerticalLine
ld [hl], $77 ; ┘
dec hl
.PrintHorizLine
ld [hl], $76 ; ─
dec hl
dec c
jr nz, .PrintHorizLine
ld [hl], $6f ; ← (halfarrow ending)
ret
PrintStatsBox:
ld a, d
and a ; a is 0 from the status screen
jr nz, .DifferentBox
coord hl, 0, 8
ld b, 8
ld c, 8
call TextBoxBorder ; Draws the box
coord hl, 1, 9 ; Start printing stats from here
ld bc, $0019 ; Number offset
jr .PrintStats
.DifferentBox
coord hl, 9, 2
ld b, 8
ld c, 9
call TextBoxBorder
coord hl, 11, 3
ld bc, $0018
.PrintStats
push bc
push hl
ld de, StatsText
call PlaceString
pop hl
pop bc
add hl, bc
ld de, wLoadedMonAttack
lb bc, 2, 3
call PrintStat
ld de, wLoadedMonDefense
call PrintStat
ld de, wLoadedMonSpeed
call PrintStat
ld de, wLoadedMonSpecial
jp PrintNumber
PrintStat:
push hl
call PrintNumber
pop hl
ld de, SCREEN_WIDTH * 2
add hl, de
ret
StatsText:
db "ATTACK"
next "DEFENSE"
next "SPEED"
next "SPECIAL@"
StatusScreen2:
ld a, [hTilesetType]
push af
xor a
ld [hTilesetType], a
ld [H_AUTOBGTRANSFERENABLED], a
ld bc, NUM_MOVES + 1
ld hl, wMoves
call FillMemory
ld hl, wLoadedMonMoves
ld de, wMoves
ld bc, NUM_MOVES
call CopyData
callab FormatMovesString
coord hl, 9, 2
lb bc, 5, 10
call ClearScreenArea ; Clear under name
call StatusScreen2Hook
nop
nop
coord hl, 0, 8
ld b, 8
ld c, 18
call TextBoxBorder ; Draw move container
coord hl, 2, 9
ld de, wMovesString
call PlaceString ; Print moves
ld a, [wNumMovesMinusOne]
inc a
ld c, a
ld a, $4
sub c
ld b, a ; Number of moves ?
coord hl, 11, 10
ld de, SCREEN_WIDTH * 2
ld a, "𝗣" ; special P tile id
call StatusScreen_PrintPP ; Print "PP"
ld a, b
and a
jr z, .InitPP
ld c, a
ld a, "-"
call StatusScreen_PrintPP ; Fill the rest with --
.InitPP
ld hl, wLoadedMonMoves
coord de, 14, 10
ld b, 0
.PrintPP
ld a, [hli]
and a
jr z, .PPDone
push bc
push hl
push de
ld hl, wCurrentMenuItem
ld a, [hl]
push af
ld a, b
ld [hl], a
push hl
callab GetMaxPP
pop hl
pop af
ld [hl], a
pop de
pop hl
push hl
ld bc, wPartyMon1PP - wPartyMon1Moves - 1
add hl, bc
ld a, [hl]
and $3f
ld [wStatusScreenCurrentPP], a
ld h, d
ld l, e
push hl
ld de, wStatusScreenCurrentPP
lb bc, 1, 2
call PrintNumber
ld a, "/"
ld [hli], a
ld de, wMaxPP
lb bc, 1, 2
call PrintNumber
pop hl
ld de, SCREEN_WIDTH * 2
add hl, de
ld d, h
ld e, l
pop hl
pop bc
inc b
ld a, b
cp $4
jr nz, .PrintPP
.PPDone
coord hl, 9, 3
ld de, StatusScreenExpText
call PlaceString
ld a, [wLoadedMonLevel]
push af
cp MAX_LEVEL
jr z, .Level100
inc a
ld [wLoadedMonLevel], a ; Increase temporarily if not 100
.Level100
coord hl, 14, 6
ld [hl], $70 ; 1-tile "to"
inc hl
inc hl
call PrintLevel
pop af
ld [wLoadedMonLevel], a
ld de, wLoadedMonExp
coord hl, 12, 4
lb bc, 3, 7
call PrintNumber ; exp
call CalcExpToLevelUp
ld de, wLoadedMonExp
coord hl, 7, 6
lb bc, 3, 7
call PrintNumber ; exp needed to level up
coord hl, 9, 0
call StatusScreen_ClearName
coord hl, 9, 1
call StatusScreen_ClearName
ld a, [wMonHIndex]
ld [wd11e], a
call GetMonName
coord hl, 9, 1
call PlaceString
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a
call Delay3
call WaitForTextScrollButtonPress ; wait for button
pop af
ld [hTilesetType], a
ld hl, wd72c
res 1, [hl]
ld a, $77
ld [rNR50], a
call GBPalWhiteOut
jp ClearScreen
CalcExpToLevelUp:
ld a, [wLoadedMonLevel]
cp MAX_LEVEL
jr z, .atMaxLevel
inc a
ld d, a
callab CalcExperience
ld hl, wLoadedMonExp + 2
ld a, [hExperience + 2]
sub [hl]
ld [hld], a
ld a, [hExperience + 1]
sbc [hl]
ld [hld], a
ld a, [hExperience]
sbc [hl]
ld [hld], a
ret
.atMaxLevel
ld hl, wLoadedMonExp
xor a
ld [hli], a
ld [hli], a
ld [hl], a
ret
StatusScreenExpText:
db "EXP POINTS"
next "LEVEL UP@"
StatusScreen_ClearName:
ld bc, 10
ld a, " "
jp FillMemory
StatusScreen_PrintPP:
; print PP or -- c times, going down two rows each time
ld [hli], a
ld [hld], a
add hl, de
dec c
jr nz, StatusScreen_PrintPP
ret
|
; A176323: Decimal expansion of (10+sqrt(110))/4.
; Submitted by Christian Krause
; 5,1,2,2,0,2,2,1,2,0,4,2,5,3,7,8,8,6,7,4,7,8,6,3,3,7,8,4,1,9,9,8,4,3,9,9,6,1,8,8,1,7,9,6,4,4,2,0,3,7,5,9,9,6,2,1,8,9,3,8,9,4,0,8,9,5,0,0,1,4,8,1,3,7,5,2,7,5,1,7,2,8,5,4,8,4,6,3,2,2,2,3,3,2,9,8,6,0,4,4
mov $1,1
mov $3,$0
mul $3,4
lpb $3
mul $1,40
add $1,$2
div $2,-1
add $2,$1
sub $3,1
lpe
mul $1,5
mov $4,10
pow $4,$0
div $2,$4
cmp $5,0
add $2,$5
div $1,$2
mod $1,10
mov $0,$1
|
stx $ff
cpy $ff
bcs {la1} |
#start=simple.exe#
#start=stepper_motor.exe#
#start=traffic_lights.exe#
JMP BEGIN
PORT_THERMOPILE EQU 112 ;TEMPERATURE INPUT
PORT_CAMERA EQU 110 ;FACE_MASK INPUT
PORT_CMD1 EQU 003H ;FIRST PPI
PORT_LED EQU 004 ;LED OUTPUT
PORT_STEPPER EQU 007 ;STEPPER MOTOR OUTPUT
PORT_CMD2 EQU 008H ;SECOND PPI (supposed to be 007H, but in conflict with virtual traffic light port of EMU8086)
MAX_HALF_STEPS EQU 16 ;limit stepper motor rotation to 180 degrees (16 X 11.25 degrees)
DATCW_HS DB 00000110B ;data to rotate stepper motor clockwise
DB 00000100B
DB 00000011B
DB 00000010B
DATCCW_HS DB 00000011B ;data to rotate stepper motor counterclocwise
DB 00000001B
DB 00000110B
DB 00000010B
BEGIN: MOV AL, 10011011B ;configure the 2 82C55s
OUT PORT_CMD1, AL ;mode 00 input for all ports
MOV AL, 10000000B
OUT PORT_CMD2, AL ;mode 00 output for all ports
MOV AX, 0800H ;set ES at 0800H for segment override in SRAM memory addressing
MOV ES, AX
MOV AL, 0
OUT PORT_LED, AL ;turn off all LEDs
TEMPERATURE: IN AL, PORT_THERMOPILE
CMP AL, 170 ;correspond to 35 degrees Celcius
JB TEMPERATURE
MOV ES:[0000H], AL ;copy thermopile data to memory address 8000H
MOV AX, 0
FACE_MASK: IN AL, PORT_CAMERA
MOV ES:[0001H], AL ;copy camera data to memory address 8001H
MOV AX, 0
LED_RED: MOV BL, ES:[0000H] ;copy thermopile data from memory address 8000H to BL
CMP BL, 221 ;correspond to 38 degrees Celcius
JB LED_AMBER ;skip next instruction if < 38 degrees Celcius
ADD AL, 1 ;activate bit for red light (>= 38 degrees Celcius)
LED_AMBER: MOV BL, ES:[0001H] ;copy camera data from memory address 8001H to BL
TEST BL, 1
JNZ LED_OUTPUT ;skip next instruction if face mask present (= 1)
ADD AL, 2 ;activate bit for amber light (no face mask)
LED_OUTPUT: OUT PORT_LED, AL ;send LEDs' data in AL to LEDs' port
LED_CHECK: CMP AL, 0 ;detect red and amber LEDs
JE LED_GREEN ;skip next few instructions if no red and amber LEDs
MOV CX, 4CH
MOV DX, 4B40H ;004C4B40H = 5000000 X 1 us = 5 s
MOV AH, 86H
INT 15H ;wait for 5 seconds
MOV AL, 0
OUT PORT_LED, AL ;turn off all LEDs
JMP TEMPERATURE ;return to temperature sensing
LED_GREEN: MOV AX, 0
ADD AL, 4 ;activate bit for green light
OUT PORT_LED, AL ;send LEDs' data in AL to LEDs' port
CALL STEPPER_MOTOR_OPEN
MOTION: MOV AH, 1H
INT 21H ;receive PIR motion sensor input via keyboard
TEST AL, 1 ;check if person has passed through the gate (= 1?)
JZ MOTION ;loop if person hasn't passed through the gate (= 0)
CALL STEPPER_MOTOR_CLOSE
MOV AL, 0
OUT PORT_LED, AL ;turn off all LEDs
JMP TEMPERATURE ;return to temperature sensing
PROC STEPPER_MOTOR_OPEN
MOV BX, OFFSET DATCW_HS ;copy clockwise rotation data's offset addresses to BX
MOV SI, 0 ;address first byte in DATCW_HS
MOV CX, 0
WAIT1: IN AL, 7
TEST AL, 10000000B ;test if stepper motor is ready to receive input
JZ WAIT1
MOV AL, [BX][SI]
OUT PORT_STEPPER, AL ;rotate stepper motor clockwise by 1 half-step (11.25 degrees)
INC SI ;address next byte in DATCW_HS
INC CX ;increase count for no. of half-steps executed
CMP CX, MAX_HALF_STEPS ;check if CX reached count limit
JAE EXIT_PROC1 ;exit procedure if CX reached count limit
CMP SI, 4 ;check if SI is out of bounds of DATCW_HS
JB WAIT1
MOV SI, 0 ;reset back to first byte of DATCW_HS
JMP WAIT1
EXIT_PROC1: RET ;return to main program
ENDP STEPPER_MOTOR_OPEN
PROC STEPPER_MOTOR_CLOSE
MOV BX, OFFSET DATCCW_HS ;copy counterclockwise rotation data's offset addresses to BX
MOV SI, 0 ;address first byte in DATCCW_HS
MOV CX, 0
WAIT2: IN AL, 7
TEST AL, 10000000B ;test if stepper motor is ready to receive input
JZ WAIT2
MOV AL, [BX][SI]
OUT PORT_STEPPER, AL ;rotate stepper motor counterclockwise by 1 half-step (11.25 degrees)
INC SI ;address next byte in DATCCW_HS
INC CX ;increase count for no. of half-steps executed
CMP CX, MAX_HALF_STEPS ;check if CX reached count limit
JAE EXIT_PROC2 ;exit procedure if CX reached count limit
CMP SI, 4 ;check if SI is out of bounds of DATCCW_HS
JB WAIT2
MOV SI, 0 ;reset back to first byte of DATCW_HS
JMP WAIT2
EXIT_PROC2: RET ;return to main program
ENDP STEPPER_MOTOR_CLOSE |
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at http://eclipse.org/legal/epl-2.0
* or the Apache License, Version 2.0 which accompanies this distribution
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public
* License, version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
#ifndef TR_IO_INCL
#define TR_IO_INCL
#include "env/OMRIO.hpp"
#include "infra/Annotations.hpp"
namespace TR
{
class OMR_EXTENSIBLE IO : public OMR::IOConnector
{
};
}
#endif
|
#include "FontWord.hpp"
namespace acid
{
FontWord::FontWord() :
m_characters(std::vector<FontCharacter>()),
m_width(0.0)
{
}
bool FontWord::AddCharacter(const FontCharacter &character, const float &kerning)
{
m_characters.emplace_back(character);
m_width += kerning + character.GetAdvanceX();
return true;
}
}
|
/*
Copyright (c) 2007-2019 Contributors as noted in the AUTHORS file
This file is part of libzmq, the ZeroMQ core engine in C++.
libzmq is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
As a special exception, the Contributors give you permission to link
this library with independent modules to produce an executable,
regardless of the license terms of these independent modules, and to
copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the
terms and conditions of the license of that module. An independent
module is a module which is not derived from or based on this library.
If you modify this library, you must extend this exception to your
version of the library.
libzmq 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "precompiled.hpp"
#ifdef ZMQ_USE_NSS
#include <secoid.h>
#include <sechash.h>
#define SHA_DIGEST_LENGTH 20
#else
#include "../external/sha1/sha1.h"
#endif
#if !defined ZMQ_HAVE_WINDOWS
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#ifdef ZMQ_HAVE_VXWORKS
#include <sockLib.h>
#endif
#endif
#include "tcp.hpp"
#include "ws_engine.hpp"
#include "session_base.hpp"
#include "err.hpp"
#include "ip.hpp"
#include "random.hpp"
#include "ws_decoder.hpp"
#include "ws_encoder.hpp"
#ifdef ZMQ_HAVE_WINDOWS
#define strcasecmp _stricmp
#endif
// OSX uses a different name for this socket option
#ifndef IPV6_ADD_MEMBERSHIP
#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
#endif
#ifdef __APPLE__
#include <TargetConditionals.h>
#endif
static int
encode_base64 (const unsigned char *in, int in_len, char *out, int out_len);
static void compute_accept_key (char *key,
unsigned char output[SHA_DIGEST_LENGTH]);
zmq::ws_engine_t::ws_engine_t (fd_t fd_,
const options_t &options_,
const endpoint_uri_pair_t &endpoint_uri_pair_,
ws_address_t &address_,
bool client_) :
stream_engine_base_t (fd_, options_, endpoint_uri_pair_),
_client (client_),
_address (address_),
_client_handshake_state (client_handshake_initial),
_server_handshake_state (handshake_initial),
_header_name_position (0),
_header_value_position (0),
_header_upgrade_websocket (false),
_header_connection_upgrade (false)
{
memset (_websocket_key, 0, MAX_HEADER_VALUE_LENGTH + 1);
memset (_websocket_accept, 0, MAX_HEADER_VALUE_LENGTH + 1);
memset (_websocket_protocol, 0, MAX_HEADER_VALUE_LENGTH + 1);
_next_msg = static_cast<int (stream_engine_base_t::*) (msg_t *)> (
&ws_engine_t::routing_id_msg);
_process_msg = static_cast<int (stream_engine_base_t::*) (msg_t *)> (
&ws_engine_t::process_routing_id_msg);
}
zmq::ws_engine_t::~ws_engine_t ()
{
}
void zmq::ws_engine_t::plug_internal ()
{
if (_client) {
unsigned char nonce[16];
int *p = (int *) nonce;
// The nonce doesn't have to be secure one, it is just use to avoid proxy cache
*p = zmq::generate_random ();
*(p + 1) = zmq::generate_random ();
*(p + 2) = zmq::generate_random ();
*(p + 3) = zmq::generate_random ();
int size =
encode_base64 (nonce, 16, _websocket_key, MAX_HEADER_VALUE_LENGTH);
assert (size > 0);
size = snprintf ((char *) _write_buffer, WS_BUFFER_SIZE,
"GET %s HTTP/1.1\r\n"
"Host: %s\r\n"
"Upgrade: websocket\r\n"
"Connection: Upgrade\r\n"
"Sec-WebSocket-Key: %s\r\n"
"Sec-WebSocket-Protocol: ZWS2.0\r\n"
"Sec-WebSocket-Version: 13\r\n\r\n",
_address.path (), _address.host (), _websocket_key);
assert (size > 0 && size < WS_BUFFER_SIZE);
_outpos = _write_buffer;
_outsize = size;
set_pollout ();
}
set_pollin ();
in_event ();
}
int zmq::ws_engine_t::routing_id_msg (msg_t *msg_)
{
int rc = msg_->init_size (_options.routing_id_size);
errno_assert (rc == 0);
if (_options.routing_id_size > 0)
memcpy (msg_->data (), _options.routing_id, _options.routing_id_size);
_next_msg = &ws_engine_t::pull_msg_from_session;
return 0;
}
int zmq::ws_engine_t::process_routing_id_msg (msg_t *msg_)
{
if (_options.recv_routing_id) {
msg_->set_flags (msg_t::routing_id);
int rc = session ()->push_msg (msg_);
errno_assert (rc == 0);
} else {
int rc = msg_->close ();
errno_assert (rc == 0);
rc = msg_->init ();
errno_assert (rc == 0);
}
_process_msg = &ws_engine_t::push_msg_to_session;
return 0;
}
bool zmq::ws_engine_t::handshake ()
{
bool complete;
if (_client)
complete = client_handshake ();
else
complete = server_handshake ();
if (complete) {
_encoder =
new (std::nothrow) ws_encoder_t (_options.out_batch_size, _client);
alloc_assert (_encoder);
_decoder = new (std::nothrow)
ws_decoder_t (_options.in_batch_size, _options.maxmsgsize,
_options.zero_copy, !_client);
alloc_assert (_decoder);
socket ()->event_handshake_succeeded (_endpoint_uri_pair, 0);
set_pollout ();
}
return complete;
}
bool zmq::ws_engine_t::server_handshake ()
{
int nbytes = tcp_read (_read_buffer, WS_BUFFER_SIZE);
if (nbytes == 0) {
errno = EPIPE;
error (zmq::i_engine::connection_error);
return false;
} else if (nbytes == -1) {
if (errno != EAGAIN)
error (zmq::i_engine::connection_error);
return false;
}
_inpos = _read_buffer;
_insize = nbytes;
while (_insize > 0) {
char c = (char) *_inpos;
switch (_server_handshake_state) {
case handshake_initial:
if (c == 'G')
_server_handshake_state = request_line_G;
else
_server_handshake_state = handshake_error;
break;
case request_line_G:
if (c == 'E')
_server_handshake_state = request_line_GE;
else
_server_handshake_state = handshake_error;
break;
case request_line_GE:
if (c == 'T')
_server_handshake_state = request_line_GET;
else
_server_handshake_state = handshake_error;
break;
case request_line_GET:
if (c == ' ')
_server_handshake_state = request_line_GET_space;
else
_server_handshake_state = handshake_error;
break;
case request_line_GET_space:
if (c == '\r' || c == '\n')
_server_handshake_state = handshake_error;
// TODO: instead of check what is not allowed check what is allowed
if (c != ' ')
_server_handshake_state = request_line_resource;
else
_server_handshake_state = request_line_GET_space;
break;
case request_line_resource:
if (c == '\r' || c == '\n')
_server_handshake_state = handshake_error;
else if (c == ' ')
_server_handshake_state = request_line_resource_space;
else
_server_handshake_state = request_line_resource;
break;
case request_line_resource_space:
if (c == 'H')
_server_handshake_state = request_line_H;
else
_server_handshake_state = handshake_error;
break;
case request_line_H:
if (c == 'T')
_server_handshake_state = request_line_HT;
else
_server_handshake_state = handshake_error;
break;
case request_line_HT:
if (c == 'T')
_server_handshake_state = request_line_HTT;
else
_server_handshake_state = handshake_error;
break;
case request_line_HTT:
if (c == 'P')
_server_handshake_state = request_line_HTTP;
else
_server_handshake_state = handshake_error;
break;
case request_line_HTTP:
if (c == '/')
_server_handshake_state = request_line_HTTP_slash;
else
_server_handshake_state = handshake_error;
break;
case request_line_HTTP_slash:
if (c == '1')
_server_handshake_state = request_line_HTTP_slash_1;
else
_server_handshake_state = handshake_error;
break;
case request_line_HTTP_slash_1:
if (c == '.')
_server_handshake_state = request_line_HTTP_slash_1_dot;
else
_server_handshake_state = handshake_error;
break;
case request_line_HTTP_slash_1_dot:
if (c == '1')
_server_handshake_state = request_line_HTTP_slash_1_dot_1;
else
_server_handshake_state = handshake_error;
break;
case request_line_HTTP_slash_1_dot_1:
if (c == '\r')
_server_handshake_state = request_line_cr;
else
_server_handshake_state = handshake_error;
break;
case request_line_cr:
if (c == '\n')
_server_handshake_state = header_field_begin_name;
else
_server_handshake_state = handshake_error;
break;
case header_field_begin_name:
switch (c) {
case '\r':
_server_handshake_state = handshake_end_line_cr;
break;
case '\n':
_server_handshake_state = handshake_error;
break;
default:
_header_name[0] = (char) c;
_header_name_position = 1;
_server_handshake_state = header_field_name;
break;
}
break;
case header_field_name:
if (c == '\r' || c == '\n')
_server_handshake_state = handshake_error;
else if (c == ':') {
_header_name[_header_name_position] = '\0';
_server_handshake_state = header_field_colon;
} else if (_header_name_position + 1 > MAX_HEADER_NAME_LENGTH)
_server_handshake_state = handshake_error;
else {
_header_name[_header_name_position] = c;
_header_name_position++;
_server_handshake_state = header_field_name;
}
break;
case header_field_colon:
case header_field_value_trailing_space:
if (c == '\n')
_server_handshake_state = handshake_error;
else if (c == '\r')
_server_handshake_state = header_field_cr;
else if (c == ' ')
_server_handshake_state = header_field_value_trailing_space;
else {
_header_value[0] = c;
_header_value_position = 1;
_server_handshake_state = header_field_value;
}
break;
case header_field_value:
if (c == '\n')
_server_handshake_state = handshake_error;
else if (c == '\r') {
_header_value[_header_value_position] = '\0';
if (strcasecmp ("upgrade", _header_name) == 0)
_header_upgrade_websocket =
strcasecmp ("websocket", _header_value) == 0;
else if (strcasecmp ("connection", _header_name) == 0)
_header_connection_upgrade =
strcasecmp ("upgrade", _header_value) == 0;
else if (strcasecmp ("Sec-WebSocket-Key", _header_name)
== 0)
strcpy (_websocket_key, _header_value);
else if (strcasecmp ("Sec-WebSocket-Protocol", _header_name)
== 0) {
// Currently only the ZWS2.0 is supported
// Sec-WebSocket-Protocol can appear multiple times or be a comma separated list
// if _websocket_protocol is already set we skip the check
if (_websocket_protocol[0] == '\0') {
char *p = strtok (_header_value, ",");
while (p != NULL) {
if (*p == ' ')
p++;
if (strcmp ("ZWS2.0", p) == 0) {
strcpy (_websocket_protocol, p);
break;
}
p = strtok (NULL, ",");
}
}
}
_server_handshake_state = header_field_cr;
} else if (_header_value_position + 1 > MAX_HEADER_VALUE_LENGTH)
_server_handshake_state = handshake_error;
else {
_header_value[_header_value_position] = c;
_header_value_position++;
_server_handshake_state = header_field_value;
}
break;
case header_field_cr:
if (c == '\n')
_server_handshake_state = header_field_begin_name;
else
_server_handshake_state = handshake_error;
break;
case handshake_end_line_cr:
if (c == '\n') {
if (_header_connection_upgrade && _header_upgrade_websocket
&& _websocket_protocol[0] != '\0'
&& _websocket_key[0] != '\0') {
_server_handshake_state = handshake_complete;
unsigned char hash[SHA_DIGEST_LENGTH];
compute_accept_key (_websocket_key, hash);
int accept_key_len = encode_base64 (
hash, SHA_DIGEST_LENGTH, _websocket_accept,
MAX_HEADER_VALUE_LENGTH);
assert (accept_key_len > 0);
_websocket_accept[accept_key_len] = '\0';
int written =
snprintf ((char *) _write_buffer, WS_BUFFER_SIZE,
"HTTP/1.1 101 Switching Protocols\r\n"
"Upgrade: websocket\r\n"
"Connection: Upgrade\r\n"
"Sec-WebSocket-Accept: %s\r\n"
"Sec-WebSocket-Protocol: %s\r\n"
"\r\n",
_websocket_accept, _websocket_protocol);
assert (written >= 0 && written < WS_BUFFER_SIZE);
_outpos = _write_buffer;
_outsize = written;
_inpos++;
_insize--;
return true;
} else
_server_handshake_state = handshake_error;
} else
_server_handshake_state = handshake_error;
break;
default:
assert (false);
}
_inpos++;
_insize--;
if (_server_handshake_state == handshake_error) {
// TODO: send bad request
socket ()->event_handshake_failed_protocol (
_endpoint_uri_pair, ZMQ_PROTOCOL_ERROR_WS_UNSPECIFIED);
error (zmq::i_engine::protocol_error);
return false;
}
}
return false;
}
bool zmq::ws_engine_t::client_handshake ()
{
int nbytes = tcp_read (_read_buffer, WS_BUFFER_SIZE);
if (nbytes == 0) {
errno = EPIPE;
error (zmq::i_engine::connection_error);
return false;
} else if (nbytes == -1) {
if (errno != EAGAIN)
error (zmq::i_engine::connection_error);
return false;
}
_inpos = _read_buffer;
_insize = nbytes;
while (_insize > 0) {
char c = (char) *_inpos;
switch (_client_handshake_state) {
case client_handshake_initial:
if (c == 'H')
_client_handshake_state = response_line_H;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_H:
if (c == 'T')
_client_handshake_state = response_line_HT;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_HT:
if (c == 'T')
_client_handshake_state = response_line_HTT;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_HTT:
if (c == 'P')
_client_handshake_state = response_line_HTTP;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_HTTP:
if (c == '/')
_client_handshake_state = response_line_HTTP_slash;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_HTTP_slash:
if (c == '1')
_client_handshake_state = response_line_HTTP_slash_1;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_HTTP_slash_1:
if (c == '.')
_client_handshake_state = response_line_HTTP_slash_1_dot;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_HTTP_slash_1_dot:
if (c == '1')
_client_handshake_state = response_line_HTTP_slash_1_dot_1;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_HTTP_slash_1_dot_1:
if (c == ' ')
_client_handshake_state =
response_line_HTTP_slash_1_dot_1_space;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_HTTP_slash_1_dot_1_space:
if (c == ' ')
_client_handshake_state =
response_line_HTTP_slash_1_dot_1_space;
else if (c == '1')
_client_handshake_state = response_line_status_1;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_status_1:
if (c == '0')
_client_handshake_state = response_line_status_10;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_status_10:
if (c == '1')
_client_handshake_state = response_line_status_101;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_status_101:
if (c == ' ')
_client_handshake_state = response_line_status_101_space;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_status_101_space:
if (c == ' ')
_client_handshake_state = response_line_status_101_space;
else if (c == 'S')
_client_handshake_state = response_line_s;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_s:
if (c == 'w')
_client_handshake_state = response_line_sw;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_sw:
if (c == 'i')
_client_handshake_state = response_line_swi;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_swi:
if (c == 't')
_client_handshake_state = response_line_swit;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_swit:
if (c == 'c')
_client_handshake_state = response_line_switc;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_switc:
if (c == 'h')
_client_handshake_state = response_line_switch;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_switch:
if (c == 'i')
_client_handshake_state = response_line_switchi;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_switchi:
if (c == 'n')
_client_handshake_state = response_line_switchin;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_switchin:
if (c == 'g')
_client_handshake_state = response_line_switching;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_switching:
if (c == ' ')
_client_handshake_state = response_line_switching_space;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_switching_space:
if (c == 'P')
_client_handshake_state = response_line_p;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_p:
if (c == 'r')
_client_handshake_state = response_line_pr;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_pr:
if (c == 'o')
_client_handshake_state = response_line_pro;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_pro:
if (c == 't')
_client_handshake_state = response_line_prot;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_prot:
if (c == 'o')
_client_handshake_state = response_line_proto;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_proto:
if (c == 'c')
_client_handshake_state = response_line_protoc;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_protoc:
if (c == 'o')
_client_handshake_state = response_line_protoco;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_protoco:
if (c == 'l')
_client_handshake_state = response_line_protocol;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_protocol:
if (c == 's')
_client_handshake_state = response_line_protocols;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_protocols:
if (c == '\r')
_client_handshake_state = response_line_cr;
else
_client_handshake_state = client_handshake_error;
break;
case response_line_cr:
if (c == '\n')
_client_handshake_state = client_header_field_begin_name;
else
_client_handshake_state = client_handshake_error;
break;
case client_header_field_begin_name:
switch (c) {
case '\r':
_client_handshake_state = client_handshake_end_line_cr;
break;
case '\n':
_client_handshake_state = client_handshake_error;
break;
default:
_header_name[0] = (char) c;
_header_name_position = 1;
_client_handshake_state = client_header_field_name;
break;
}
break;
case client_header_field_name:
if (c == '\r' || c == '\n')
_client_handshake_state = client_handshake_error;
else if (c == ':') {
_header_name[_header_name_position] = '\0';
_client_handshake_state = client_header_field_colon;
} else if (_header_name_position + 1 > MAX_HEADER_NAME_LENGTH)
_client_handshake_state = client_handshake_error;
else {
_header_name[_header_name_position] = c;
_header_name_position++;
_client_handshake_state = client_header_field_name;
}
break;
case client_header_field_colon:
case client_header_field_value_trailing_space:
if (c == '\n')
_client_handshake_state = client_handshake_error;
else if (c == '\r')
_client_handshake_state = client_header_field_cr;
else if (c == ' ')
_client_handshake_state =
client_header_field_value_trailing_space;
else {
_header_value[0] = c;
_header_value_position = 1;
_client_handshake_state = client_header_field_value;
}
break;
case client_header_field_value:
if (c == '\n')
_client_handshake_state = client_handshake_error;
else if (c == '\r') {
_header_value[_header_value_position] = '\0';
if (strcasecmp ("upgrade", _header_name) == 0)
_header_upgrade_websocket =
strcasecmp ("websocket", _header_value) == 0;
else if (strcasecmp ("connection", _header_name) == 0)
_header_connection_upgrade =
strcasecmp ("upgrade", _header_value) == 0;
else if (strcasecmp ("Sec-WebSocket-Accept", _header_name)
== 0)
strcpy (_websocket_accept, _header_value);
else if (strcasecmp ("Sec-WebSocket-Protocol", _header_name)
== 0) {
if (strcmp ("ZWS2.0", _header_value) == 0)
strcpy (_websocket_protocol, _header_value);
}
_client_handshake_state = client_header_field_cr;
} else if (_header_value_position + 1 > MAX_HEADER_VALUE_LENGTH)
_client_handshake_state = client_handshake_error;
else {
_header_value[_header_value_position] = c;
_header_value_position++;
_client_handshake_state = client_header_field_value;
}
break;
case client_header_field_cr:
if (c == '\n')
_client_handshake_state = client_header_field_begin_name;
else
_client_handshake_state = client_handshake_error;
break;
case client_handshake_end_line_cr:
if (c == '\n') {
if (_header_connection_upgrade && _header_upgrade_websocket
&& _websocket_protocol[0] != '\0'
&& _websocket_accept[0] != '\0') {
_client_handshake_state = client_handshake_complete;
// TODO: validate accept key
_inpos++;
_insize--;
return true;
} else
_client_handshake_state = client_handshake_error;
} else
_client_handshake_state = client_handshake_error;
break;
default:
assert (false);
}
_inpos++;
_insize--;
if (_client_handshake_state == client_handshake_error) {
socket ()->event_handshake_failed_protocol (
_endpoint_uri_pair, ZMQ_PROTOCOL_ERROR_WS_UNSPECIFIED);
error (zmq::i_engine::protocol_error);
return false;
}
}
return false;
}
static int
encode_base64 (const unsigned char *in, int in_len, char *out, int out_len)
{
static const unsigned char base64enc_tab[65] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int ii, io;
uint32_t v;
int rem;
for (io = 0, ii = 0, v = 0, rem = 0; ii < in_len; ii++) {
unsigned char ch;
ch = in[ii];
v = (v << 8) | ch;
rem += 8;
while (rem >= 6) {
rem -= 6;
if (io >= out_len)
return -1; /* truncation is failure */
out[io++] = base64enc_tab[(v >> rem) & 63];
}
}
if (rem) {
v <<= (6 - rem);
if (io >= out_len)
return -1; /* truncation is failure */
out[io++] = base64enc_tab[v & 63];
}
while (io & 3) {
if (io >= out_len)
return -1; /* truncation is failure */
out[io++] = '=';
}
if (io >= out_len)
return -1; /* no room for null terminator */
out[io] = 0;
return io;
}
static void compute_accept_key (char *key, unsigned char *hash)
{
const char *magic_string = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
#ifdef ZMQ_USE_NSS
unsigned int len;
HASH_HashType type = HASH_GetHashTypeByOidTag (SEC_OID_SHA1);
HASHContext *ctx = HASH_Create (type);
assert (ctx);
HASH_Begin (ctx);
HASH_Update (ctx, (unsigned char *) key, (unsigned int) strlen (key));
HASH_Update (ctx, (unsigned char *) magic_string,
(unsigned int) strlen (magic_string));
HASH_End (ctx, hash, &len, SHA_DIGEST_LENGTH);
HASH_Destroy (ctx);
#else
sha1_ctxt ctx;
SHA1_Init (&ctx);
SHA1_Update (&ctx, (unsigned char *) key, strlen (key));
SHA1_Update (&ctx, (unsigned char *) magic_string, strlen (magic_string));
SHA1_Final (hash, &ctx);
#endif
}
|
// adsr envelope example
#include "daisysp.h"
#include "daisy_seed.h"
// Shortening long macro for sample rate
#ifndef sample_rate
#endif
// Interleaved audio definitions
#define LEFT (i)
#define RIGHT (i + 1)
using namespace daisysp;
using namespace daisy;
static DaisySeed hw;
static Adsr env;
static Oscillator osc;
static Metro tick;
bool gate;
static void AudioCallback(AudioHandle::InterleavingInputBuffer in,
AudioHandle::InterleavingOutputBuffer out,
size_t size)
{
float osc_out, env_out;
for(size_t i = 0; i < size; i += 2)
{
// When the metro ticks, trigger the envelope to start.
if(tick.Process())
{
gate = !gate;
}
// Use envelope to control the amplitude of the oscillator.
env_out = env.Process(gate);
osc.SetAmp(env_out);
osc_out = osc.Process();
out[LEFT] = osc_out;
out[RIGHT] = osc_out;
}
}
int main(void)
{
// initialize seed hardware and daisysp modules
float sample_rate;
hw.Configure();
hw.Init();
hw.SetAudioBlockSize(4);
sample_rate = hw.AudioSampleRate();
env.Init(sample_rate);
osc.Init(sample_rate);
// Set up metro to pulse every second
tick.Init(1.0f, sample_rate);
//Set envelope parameters
env.SetTime(ADSR_SEG_ATTACK, .1);
env.SetTime(ADSR_SEG_DECAY, .1);
env.SetTime(ADSR_SEG_RELEASE, .01);
env.SetSustainLevel(.25);
// Set parameters for oscillator
osc.SetWaveform(osc.WAVE_TRI);
osc.SetFreq(220);
osc.SetAmp(0.25);
// start callback
hw.StartAudio(AudioCallback);
while(1) {}
}
|
/*
* Copyright (c) 2017-2020 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
* 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 <algorithm>
#include "arm_compute/runtime/OffsetMemoryPool.h"
#include "arm_compute/core/Error.h"
#include "arm_compute/runtime/IAllocator.h"
#include "arm_compute/runtime/IMemoryPool.h"
#include "arm_compute/runtime/MemoryRegion.h"
#include "arm_compute/runtime/Types.h"
namespace arm_compute
{
OffsetMemoryPool::OffsetMemoryPool(IAllocator *allocator, BlobInfo blob_info)
: _allocator(allocator), _blob(), _blob_info(blob_info)
{
ARM_COMPUTE_ERROR_ON(!allocator);
_blob = _allocator->make_region(blob_info.size, blob_info.alignment);
}
const BlobInfo &OffsetMemoryPool::info() const
{
return _blob_info;
}
void OffsetMemoryPool::acquire(MemoryMappings &handles)
{
ARM_COMPUTE_ERROR_ON(_blob == nullptr);
// Set memory to handlers
for(auto &handle : handles)
{
ARM_COMPUTE_ERROR_ON(handle.first == nullptr);
handle.first->set_owned_region(_blob->extract_subregion(handle.second, _blob_info.size - handle.second));
}
}
void OffsetMemoryPool::release(MemoryMappings &handles)
{
for(auto &handle : handles)
{
ARM_COMPUTE_ERROR_ON(handle.first == nullptr);
handle.first->set_region(nullptr);
}
}
MappingType OffsetMemoryPool::mapping_type() const
{
return MappingType::OFFSETS;
}
std::unique_ptr<IMemoryPool> OffsetMemoryPool::duplicate()
{
ARM_COMPUTE_ERROR_ON(!_allocator);
return std::make_unique<OffsetMemoryPool>(_allocator, _blob_info);
}
} // namespace arm_compute
|
/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*
*************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sc.hxx"
// System - Includes ---------------------------------------------------------
// INCLUDE -------------------------------------------------------------------
#include <vcl/morebtn.hxx>
#include <svtools/stdctrl.hxx>
#include "anyrefdg.hxx"
#include "rangeutl.hxx"
#include "dbcolect.hxx"
#include "viewdata.hxx"
#include "document.hxx"
#include "queryparam.hxx"
#define _FOPTMGR_CXX
#include "foptmgr.hxx"
#undef _FOPTMGR_CXX
//----------------------------------------------------------------------------
ScFilterOptionsMgr::ScFilterOptionsMgr(
Dialog* ptrDlg,
ScViewData* ptrViewData,
const ScQueryParam& refQueryData,
MoreButton& refBtnMore,
CheckBox& refBtnCase,
CheckBox& refBtnRegExp,
CheckBox& refBtnHeader,
CheckBox& refBtnUnique,
CheckBox& refBtnCopyResult,
CheckBox& refBtnDestPers,
ListBox& refLbCopyArea,
Edit& refEdCopyArea,
formula::RefButton& refRbCopyArea,
FixedText& refFtDbAreaLabel,
FixedInfo& refFtDbArea,
FixedLine& refFlOptions,
const String& refStrNoName,
const String& refStrUndefined )
: pDlg ( ptrDlg ),
pViewData ( ptrViewData ),
pDoc ( ptrViewData ? ptrViewData->GetDocument() : NULL ),
rBtnMore ( refBtnMore ),
rBtnCase ( refBtnCase ),
rBtnRegExp ( refBtnRegExp ),
rBtnHeader ( refBtnHeader ),
rBtnUnique ( refBtnUnique ),
rBtnCopyResult ( refBtnCopyResult ),
rBtnDestPers ( refBtnDestPers ),
rLbCopyPos ( refLbCopyArea ),
rEdCopyPos ( refEdCopyArea ),
rRbCopyPos ( refRbCopyArea ),
rFtDbAreaLabel ( refFtDbAreaLabel ),
rFtDbArea ( refFtDbArea ),
rFlOptions ( refFlOptions ),
rStrNoName ( refStrNoName ),
rStrUndefined ( refStrUndefined ),
rQueryData ( refQueryData )
{
Init();
}
//----------------------------------------------------------------------------
ScFilterOptionsMgr::~ScFilterOptionsMgr()
{
sal_uInt16 nEntries = rLbCopyPos.GetEntryCount();
sal_uInt16 i;
for ( i=2; i<nEntries; i++ )
delete (String*)rLbCopyPos.GetEntryData( i );
}
//----------------------------------------------------------------------------
void ScFilterOptionsMgr::Init()
{
DBG_ASSERT( pViewData && pDoc, "Init failed :-/" );
rLbCopyPos.SetSelectHdl ( LINK( this, ScFilterOptionsMgr, LbPosSelHdl ) );
rEdCopyPos.SetModifyHdl ( LINK( this, ScFilterOptionsMgr, EdPosModifyHdl ) );
rBtnCopyResult.SetClickHdl( LINK( this, ScFilterOptionsMgr, BtnCopyResultHdl ) );
rBtnMore.AddWindow( &rBtnCase );
rBtnMore.AddWindow( &rBtnRegExp );
rBtnMore.AddWindow( &rBtnHeader );
rBtnMore.AddWindow( &rBtnUnique );
rBtnMore.AddWindow( &rBtnCopyResult );
rBtnMore.AddWindow( &rBtnDestPers );
rBtnMore.AddWindow( &rLbCopyPos );
rBtnMore.AddWindow( &rEdCopyPos );
rBtnMore.AddWindow( &rRbCopyPos );
rBtnMore.AddWindow( &rFtDbAreaLabel );
rBtnMore.AddWindow( &rFtDbArea );
rBtnMore.AddWindow( &rFlOptions );
rBtnCase .Check( rQueryData.bCaseSens );
rBtnHeader .Check( rQueryData.bHasHeader );
rBtnRegExp .Check( rQueryData.bRegExp );
rBtnUnique .Check( !rQueryData.bDuplicate );
if ( pViewData && pDoc )
{
String theAreaStr;
ScRange theCurArea ( ScAddress( rQueryData.nCol1,
rQueryData.nRow1,
pViewData->GetTabNo() ),
ScAddress( rQueryData.nCol2,
rQueryData.nRow2,
pViewData->GetTabNo() ) );
ScDBCollection* pDBColl = pDoc->GetDBCollection();
String theDbArea;
String theDbName = rStrNoName;
const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
theCurArea.Format( theAreaStr, SCR_ABS_3D, pDoc, eConv );
// Zielbereichsliste fuellen
rLbCopyPos.Clear();
rLbCopyPos.InsertEntry( rStrUndefined, 0 );
ScAreaNameIterator aIter( pDoc );
String aName;
ScRange aRange;
String aRefStr;
while ( aIter.Next( aName, aRange ) )
{
sal_uInt16 nInsert = rLbCopyPos.InsertEntry( aName );
aRange.aStart.Format( aRefStr, SCA_ABS_3D, pDoc, eConv );
rLbCopyPos.SetEntryData( nInsert, new String( aRefStr ) );
}
rBtnDestPers.Check( sal_True ); // beim Aufruf immer an
rLbCopyPos.SelectEntryPos( 0 );
rEdCopyPos.SetText( EMPTY_STRING );
/*
* Ueberpruefen, ob es sich bei dem uebergebenen
* Bereich um einen Datenbankbereich handelt:
*/
theDbArea = theAreaStr;
if ( pDBColl )
{
ScAddress& rStart = theCurArea.aStart;
ScAddress& rEnd = theCurArea.aEnd;
ScDBData* pDBData = pDBColl->GetDBAtArea(
rStart.Tab(), rStart.Col(), rStart.Row(), rEnd.Col(), rEnd.Row() );
if ( pDBData )
{
rBtnHeader.Check( pDBData->HasHeader() );
pDBData->GetName( theDbName );
if ( !pDBData->IsInternalUnnamed()
&& !pDBData->IsInternalForAutoFilter() )
{
rBtnHeader.Disable();
}
}
}
theDbArea.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
theDbArea += theDbName;
theDbArea += ')';
rFtDbArea.SetText( theDbArea );
//------------------------------------------------------
// Kopierposition:
if ( !rQueryData.bInplace )
{
String aString;
ScAddress( rQueryData.nDestCol,
rQueryData.nDestRow,
rQueryData.nDestTab
).Format( aString, SCA_ABS_3D, pDoc, eConv );
rBtnCopyResult.Check( sal_True );
rEdCopyPos.SetText( aString );
EdPosModifyHdl( &rEdCopyPos );
rLbCopyPos.Enable();
rEdCopyPos.Enable();
rRbCopyPos.Enable();
rBtnDestPers.Enable();
}
else
{
rBtnCopyResult.Check( sal_False );
rEdCopyPos.SetText( EMPTY_STRING );
rLbCopyPos.Disable();
rEdCopyPos.Disable();
rRbCopyPos.Disable();
rBtnDestPers.Disable();
}
}
else
rEdCopyPos.SetText( EMPTY_STRING );
}
//----------------------------------------------------------------------------
sal_Bool ScFilterOptionsMgr::VerifyPosStr( const String& rPosStr ) const
{
String aPosStr( rPosStr );
xub_StrLen nColonPos = aPosStr.Search( ':' );
if ( STRING_NOTFOUND != nColonPos )
aPosStr.Erase( nColonPos );
sal_uInt16 nResult = ScAddress().Parse( aPosStr, pDoc, pDoc->GetAddressConvention() );
return ( SCA_VALID == (nResult & SCA_VALID) );
}
//----------------------------------------------------------------------------
// Handler:
//----------------------------------------------------------------------------
IMPL_LINK( ScFilterOptionsMgr, LbPosSelHdl, ListBox*, pLb )
{
if ( pLb == &rLbCopyPos )
{
String aString;
sal_uInt16 nSelPos = rLbCopyPos.GetSelectEntryPos();
if ( nSelPos > 0 )
aString = *(String*)rLbCopyPos.GetEntryData( nSelPos );
rEdCopyPos.SetText( aString );
}
return 0;
}
//----------------------------------------------------------------------------
IMPL_LINK( ScFilterOptionsMgr, EdPosModifyHdl, Edit*, pEd )
{
if ( pEd == &rEdCopyPos )
{
String theCurPosStr = pEd->GetText();
sal_uInt16 nResult = ScAddress().Parse( theCurPosStr, pDoc, pDoc->GetAddressConvention() );
if ( SCA_VALID == (nResult & SCA_VALID) )
{
String* pStr = NULL;
sal_Bool bFound = sal_False;
sal_uInt16 i = 0;
sal_uInt16 nCount = rLbCopyPos.GetEntryCount();
for ( i=2; i<nCount && !bFound; i++ )
{
pStr = (String*)rLbCopyPos.GetEntryData( i );
bFound = (theCurPosStr == *pStr);
}
if ( bFound )
rLbCopyPos.SelectEntryPos( --i );
else
rLbCopyPos.SelectEntryPos( 0 );
}
else
rLbCopyPos.SelectEntryPos( 0 );
}
return 0;
}
//----------------------------------------------------------------------------
IMPL_LINK( ScFilterOptionsMgr, BtnCopyResultHdl, CheckBox*, pBox )
{
if ( pBox == &rBtnCopyResult )
{
if ( pBox->IsChecked() )
{
rBtnDestPers.Enable();
rLbCopyPos.Enable();
rEdCopyPos.Enable();
rRbCopyPos.Enable();
rEdCopyPos.GrabFocus();
}
else
{
rBtnDestPers.Disable();
rLbCopyPos.Disable();
rEdCopyPos.Disable();
rRbCopyPos.Disable();
}
}
return 0;
}
|
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/06/rect/Rect.asm
// Draws a rectangle at the top-left corner of the screen.
// The rectangle is 16 pixels wide and R0 pixels high.
@0
D=M
@INFINITE_LOOP
D;JLE
@counter
M=D
@SCREEN
D=A
@address
M=D
(LOOP)
@address
A=M
M=-1
@address
D=M
@32
D=D+A
@address
M=D
@counter
MD=M-1
@LOOP
D;JGT
(INFINITE_LOOP)
@INFINITE_LOOP
0;JMP |
; A133212: a(n) = 4a(n-1) - 6a(n-2) + 4a(n-3), n > 3; a(0) = 1, a(1) = 4, a(2) = 12, a(3) = 32.
; Submitted by Christian Krause
; 1,4,12,32,72,144,272,512,992,1984,4032,8192,16512,33024,65792,131072,261632,523264,1047552,2097152,4196352,8392704,16781312,33554432,67100672,134201344,268419072,536870912,1073774592,2147549184
lpb $0
sub $0,1
mov $1,1
mul $2,2
add $2,$3
add $2,2
add $3,$2
add $4,1
mul $4,2
add $2,$4
sub $2,$3
lpe
add $1,$3
mov $0,$1
add $0,1
|
#include "lbv2isolver.h"
#include "assert.h"
#include "smt-switch/cvc4_factory.h"
#include "smt-switch/smt.h"
#include "smt-switch/result.h"
using namespace lbv2i;
using namespace smt;
using namespace std;
int main() {
SmtSolver underlying_solver = smt::CVC4SolverFactory::create(false);
underlying_solver->set_logic("QF_NIA");
Sort int_sort = underlying_solver->make_sort(INT);
Term two = underlying_solver->make_term(2, int_sort);
Term x = underlying_solver->make_symbol("x", int_sort);
Term x_div_2 = underlying_solver->make_term(IntDiv, x, two);
cout << "panda " << x_div_2 << endl;;
}
|
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_CONTAINER_MAP_HPP
#define BOOST_CONTAINER_MAP_HPP
#ifndef BOOST_CONFIG_HPP
# include <boost/config.hpp>
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/detail/workaround.hpp>
// container
#include <boost/container/container_fwd.hpp>
#include <boost/container/new_allocator.hpp> //new_allocator
#include <boost/container/throw_exception.hpp>
// container/detail
#include <boost/container/detail/mpl.hpp>
#include <boost/container/detail/tree.hpp>
#include <boost/container/detail/type_traits.hpp>
#include <boost/container/detail/value_init.hpp>
#include <boost/container/detail/pair.hpp>
// move
#include <boost/move/traits.hpp>
#include <boost/move/utility_core.hpp>
// move/detail
#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#include <boost/move/detail/fwd_macros.hpp>
#endif
#include <boost/move/detail/move_helpers.hpp>
// intrusive/detail
#include <boost/intrusive/detail/minimal_pair_header.hpp> //pair
#include <boost/intrusive/detail/minimal_less_equal_header.hpp>//less, equal
// other
#include <boost/static_assert.hpp>
#include <boost/core/no_exceptions_support.hpp>
// std
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
#include <initializer_list>
#endif
namespace boost {
namespace container {
///@cond
template<class Key, class Mapped>
struct pair_key_mapped_of_value
{
typedef Key key_type;
typedef Mapped mapped_type;
template<class Pair>
const key_type & key_of_value(const Pair &p) const
{ return p.first; }
template<class Pair>
const mapped_type & mapped_of_value(const Pair &p) const
{ return p.second; }
template<class Pair>
key_type & key_of_value(Pair &p) const
{ return const_cast<key_type&>(p.first); }
template<class Pair>
mapped_type & mapped_of_value(Pair &p) const
{ return p.second; }
};
///@endcond
#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
//! A map is a kind of associative container that supports unique keys (contains at
//! most one of each key value) and provides for fast retrieval of values of another
//! type T based on the keys. The map class supports bidirectional iterators.
//!
//! A map satisfies all of the requirements of a container and of a reversible
//! container and of an associative container. The <code>value_type</code> stored
//! by this container is the value_type is std::pair<const Key, T>.
//!
//! \tparam Key is the key_type of the map
//! \tparam T is the <code>mapped_type</code>
//! \tparam Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
//! \tparam Allocator is the allocator to allocate the <code>value_type</code>s
//! (e.g. <i>allocator< std::pair<const Key, T> > </i>).
//! \tparam Options is an packed option type generated using using boost::container::tree_assoc_options.
template < class Key, class T, class Compare = std::less<Key>
, class Allocator = new_allocator< std::pair< const Key, T> >, class Options = tree_assoc_defaults >
#else
template <class Key, class T, class Compare, class Allocator, class Options>
#endif
class map
///@cond
: public container_detail::tree
< std::pair<const Key, T>
, container_detail::select1st<Key>
, Compare, Allocator, Options>
///@endcond
{
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
private:
BOOST_COPYABLE_AND_MOVABLE(map)
typedef container_detail::select1st<Key> select_1st_t;
typedef std::pair<const Key, T> value_type_impl;
typedef container_detail::tree
<value_type_impl, select_1st_t, Compare, Allocator, Options> base_t;
typedef container_detail::pair <Key, T> movable_value_type_impl;
typedef typename base_t::value_compare value_compare_impl;
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
public:
//////////////////////////////////////////////
//
// types
//
//////////////////////////////////////////////
typedef Key key_type;
typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type;
typedef T mapped_type;
typedef std::pair<const Key, T> value_type;
typedef typename boost::container::allocator_traits<Allocator>::pointer pointer;
typedef typename boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
typedef typename boost::container::allocator_traits<Allocator>::reference reference;
typedef typename boost::container::allocator_traits<Allocator>::const_reference const_reference;
typedef typename boost::container::allocator_traits<Allocator>::size_type size_type;
typedef typename boost::container::allocator_traits<Allocator>::difference_type difference_type;
typedef Allocator allocator_type;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::stored_allocator_type) stored_allocator_type;
typedef BOOST_CONTAINER_IMPDEF(value_compare_impl) value_compare;
typedef Compare key_compare;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::iterator) iterator;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_iterator) const_iterator;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::reverse_iterator) reverse_iterator;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_reverse_iterator) const_reverse_iterator;
typedef std::pair<key_type, mapped_type> nonconst_value_type;
typedef BOOST_CONTAINER_IMPDEF(movable_value_type_impl) movable_value_type;
typedef BOOST_CONTAINER_IMPDEF(node_handle<
typename base_t::node_type::container_node_type
BOOST_MOVE_I value_type
BOOST_MOVE_I allocator_type
BOOST_MOVE_I pair_key_mapped_of_value
<key_type BOOST_MOVE_I mapped_type> >) node_type;
typedef BOOST_CONTAINER_IMPDEF
(insert_return_type_base<iterator BOOST_MOVE_I node_type>) insert_return_type;
//////////////////////////////////////////////
//
// construct/copy/destroy
//
//////////////////////////////////////////////
//! <b>Effects</b>: Default constructs an empty map.
//!
//! <b>Complexity</b>: Constant.
BOOST_CONTAINER_FORCEINLINE
map() BOOST_NOEXCEPT_IF(container_detail::is_nothrow_default_constructible<Allocator>::value &&
container_detail::is_nothrow_default_constructible<Compare>::value)
: base_t()
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Constructs an empty map using the specified comparison object
//! and allocator.
//!
//! <b>Complexity</b>: Constant.
BOOST_CONTAINER_FORCEINLINE
explicit map(const Compare& comp, const allocator_type& a = allocator_type())
: base_t(comp, a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Constructs an empty map using the specified allocator.
//!
//! <b>Complexity</b>: Constant.
BOOST_CONTAINER_FORCEINLINE
explicit map(const allocator_type& a)
: base_t(a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Constructs an empty map using the specified comparison object and
//! allocator, and inserts elements from the range [first ,last ).
//!
//! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
//! comp and otherwise N logN, where N is last - first.
template <class InputIterator>
BOOST_CONTAINER_FORCEINLINE
map(InputIterator first, InputIterator last, const Compare& comp = Compare(),
const allocator_type& a = allocator_type())
: base_t(true, first, last, comp, a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Constructs an empty map using the specified
//! allocator, and inserts elements from the range [first ,last ).
//!
//! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
//! comp and otherwise N logN, where N is last - first.
template <class InputIterator>
BOOST_CONTAINER_FORCEINLINE
map(InputIterator first, InputIterator last, const allocator_type& a)
: base_t(true, first, last, Compare(), a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Constructs an empty map using the specified comparison object and
//! allocator, and inserts elements from the ordered unique range [first ,last). This function
//! is more efficient than the normal range creation for ordered ranges.
//!
//! <b>Requires</b>: [first ,last) must be ordered according to the predicate and must be
//! unique values.
//!
//! <b>Complexity</b>: Linear in N.
//!
//! <b>Note</b>: Non-standard extension.
template <class InputIterator>
BOOST_CONTAINER_FORCEINLINE
map( ordered_unique_range_t, InputIterator first, InputIterator last
, const Compare& comp = Compare(), const allocator_type& a = allocator_type())
: base_t(ordered_range, first, last, comp, a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
//! <b>Effects</b>: Constructs an empty map using the specified comparison object and
//! allocator, and inserts elements from the range [il.begin(), il.end()).
//!
//! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
//! comp and otherwise N logN, where N is il.first() - il.end().
BOOST_CONTAINER_FORCEINLINE
map(std::initializer_list<value_type> il, const Compare& comp = Compare(), const allocator_type& a = allocator_type())
: base_t(true, il.begin(), il.end(), comp, a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Constructs an empty map using the specified
//! allocator, and inserts elements from the range [il.begin(), il.end()).
//!
//! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
//! comp and otherwise N logN, where N is il.first() - il.end().
BOOST_CONTAINER_FORCEINLINE
map(std::initializer_list<value_type> il, const allocator_type& a)
: base_t(true, il.begin(), il.end(), Compare(), a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Constructs an empty set using the specified comparison object and
//! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function
//! is more efficient than the normal range creation for ordered ranges.
//!
//! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate and must be
//! unique values.
//!
//! <b>Complexity</b>: Linear in N.
//!
//! <b>Note</b>: Non-standard extension.
BOOST_CONTAINER_FORCEINLINE
map(ordered_unique_range_t, std::initializer_list<value_type> il, const Compare& comp = Compare(),
const allocator_type& a = allocator_type())
: base_t(ordered_range, il.begin(), il.end(), comp, a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
#endif
//! <b>Effects</b>: Copy constructs a map.
//!
//! <b>Complexity</b>: Linear in x.size().
BOOST_CONTAINER_FORCEINLINE
map(const map& x)
: base_t(static_cast<const base_t&>(x))
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Move constructs a map. Constructs *this using x's resources.
//!
//! <b>Complexity</b>: Constant.
//!
//! <b>Postcondition</b>: x is emptied.
BOOST_CONTAINER_FORCEINLINE
map(BOOST_RV_REF(map) x)
BOOST_NOEXCEPT_IF(boost::container::container_detail::is_nothrow_move_constructible<Compare>::value)
: base_t(BOOST_MOVE_BASE(base_t, x))
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Copy constructs a map using the specified allocator.
//!
//! <b>Complexity</b>: Linear in x.size().
BOOST_CONTAINER_FORCEINLINE
map(const map& x, const allocator_type &a)
: base_t(static_cast<const base_t&>(x), a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Move constructs a map using the specified allocator.
//! Constructs *this using x's resources.
//!
//! <b>Complexity</b>: Constant if x == x.get_allocator(), linear otherwise.
//!
//! <b>Postcondition</b>: x is emptied.
BOOST_CONTAINER_FORCEINLINE
map(BOOST_RV_REF(map) x, const allocator_type &a)
: base_t(BOOST_MOVE_BASE(base_t, x), a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Makes *this a copy of x.
//!
//! <b>Complexity</b>: Linear in x.size().
BOOST_CONTAINER_FORCEINLINE
map& operator=(BOOST_COPY_ASSIGN_REF(map) x)
{ return static_cast<map&>(this->base_t::operator=(static_cast<const base_t&>(x))); }
//! <b>Effects</b>: this->swap(x.get()).
//!
//! <b>Throws</b>: If allocator_traits_type::propagate_on_container_move_assignment
//! is false and (allocation throws or value_type's move constructor throws)
//!
//! <b>Complexity</b>: Constant if allocator_traits_type::
//! propagate_on_container_move_assignment is true or
//! this->get>allocator() == x.get_allocator(). Linear otherwise.
BOOST_CONTAINER_FORCEINLINE
map& operator=(BOOST_RV_REF(map) x)
BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
allocator_traits_type::is_always_equal::value) &&
boost::container::container_detail::is_nothrow_move_assignable<Compare>::value)
{ return static_cast<map&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
//! <b>Effects</b>: Assign content of il to *this.
//!
BOOST_CONTAINER_FORCEINLINE
map& operator=(std::initializer_list<value_type> il)
{
this->clear();
insert(il.begin(), il.end());
return *this;
}
#endif
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! <b>Effects</b>: Returns a copy of the allocator that
//! was passed to the object's constructor.
//!
//! <b>Complexity</b>: Constant.
allocator_type get_allocator() const;
//! <b>Effects</b>: Returns a reference to the internal allocator.
//!
//! <b>Throws</b>: Nothing
//!
//! <b>Complexity</b>: Constant.
//!
//! <b>Note</b>: Non-standard extension.
stored_allocator_type &get_stored_allocator() BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns a reference to the internal allocator.
//!
//! <b>Throws</b>: Nothing
//!
//! <b>Complexity</b>: Constant.
//!
//! <b>Note</b>: Non-standard extension.
const stored_allocator_type &get_stored_allocator() const BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns an iterator to the first element contained in the container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
iterator begin() BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
const_iterator begin() const BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns a const_iterator to the first element contained in the container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
const_iterator cbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns an iterator to the end of the container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
iterator end() BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns a const_iterator to the end of the container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns a const_iterator to the end of the container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns a reverse_iterator pointing to the beginning
//! of the reversed container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
//! of the reversed container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the beginning
//! of the reversed container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns a reverse_iterator pointing to the end
//! of the reversed container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
//! of the reversed container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns a const_reverse_iterator pointing to the end
//! of the reversed container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns true if the container contains no elements.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
bool empty() const BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns the number of the elements contained in the container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
size_type size() const BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns the largest possible size of the container.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW;
#endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! <b>Effects</b>: If there is no key equivalent to x in the map, inserts
//! value_type(x, T()) into the map.
//!
//! <b>Returns</b>: A reference to the mapped_type corresponding to x in *this.
//!
//! <b>Complexity</b>: Logarithmic.
mapped_type& operator[](const key_type &k);
//! <b>Effects</b>: If there is no key equivalent to x in the map, inserts
//! value_type(boost::move(x), T()) into the map (the key is move-constructed)
//!
//! <b>Returns</b>: A reference to the mapped_type corresponding to x in *this.
//!
//! <b>Complexity</b>: Logarithmic.
mapped_type& operator[](key_type &&k);
#elif defined(BOOST_MOVE_HELPERS_RETURN_SFINAE_BROKEN)
//in compilers like GCC 3.4, we can't catch temporaries
BOOST_CONTAINER_FORCEINLINE mapped_type& operator[](const key_type &k) { return this->priv_subscript(k); }
BOOST_CONTAINER_FORCEINLINE mapped_type& operator[](BOOST_RV_REF(key_type) k) { return this->priv_subscript(::boost::move(k)); }
#else
BOOST_MOVE_CONVERSION_AWARE_CATCH( operator[] , key_type, mapped_type&, this->priv_subscript)
#endif
//! <b>Effects</b>: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
//! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
//! as if by insert, constructing it from value_type(k, forward<M>(obj)).
//!
//! No iterators or references are invalidated. If the insertion is successful, pointers and references
//! to the element obtained while it is held in the node handle are invalidated, and pointers and
//! references obtained to that element before it was extracted become valid.
//!
//! <b>Returns</b>: The bool component is true if the insertion took place and false if the assignment
//! took place. The iterator component is pointing at the element that was inserted or updated.
//!
//! <b>Complexity</b>: Logarithmic in the size of the container.
template <class M>
BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> insert_or_assign(const key_type& k, BOOST_FWD_REF(M) obj)
{ return this->base_t::insert_or_assign(const_iterator(), k, ::boost::forward<M>(obj)); }
//! <b>Effects</b>: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
//! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
//! as if by insert, constructing it from value_type(k, move(obj)).
//!
//! No iterators or references are invalidated. If the insertion is successful, pointers and references
//! to the element obtained while it is held in the node handle are invalidated, and pointers and
//! references obtained to that element before it was extracted become valid.
//!
//! <b>Returns</b>: The bool component is true if the insertion took place and false if the assignment
//! took place. The iterator component is pointing at the element that was inserted or updated.
//!
//! <b>Complexity</b>: Logarithmic in the size of the container.
template <class M>
BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> insert_or_assign(BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj)
{ return this->base_t::insert_or_assign(const_iterator(), ::boost::move(k), ::boost::forward<M>(obj)); }
//! <b>Effects</b>: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
//! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
//! as if by insert, constructing it from value_type(k, forward<M>(obj)) and the new element
//! to the container as close as possible to the position just before hint.
//!
//! No iterators or references are invalidated. If the insertion is successful, pointers and references
//! to the element obtained while it is held in the node handle are invalidated, and pointers and
//! references obtained to that element before it was extracted become valid.
//!
//! <b>Returns</b>: The bool component is true if the insertion took place and false if the assignment
//! took place. The iterator component is pointing at the element that was inserted or updated.
//!
//! <b>Complexity</b>: Logarithmic in the size of the container in general, but amortized constant if
//! the new element is inserted just before hint.
template <class M>
BOOST_CONTAINER_FORCEINLINE iterator insert_or_assign(const_iterator hint, const key_type& k, BOOST_FWD_REF(M) obj)
{ return this->base_t::insert_or_assign(hint, k, ::boost::forward<M>(obj)); }
//! <b>Effects</b>: If a key equivalent to k already exists in the container, assigns forward<M>(obj)
//! to the mapped_type corresponding to the key k. If the key does not exist, inserts the new value
//! as if by insert, constructing it from value_type(k, move(obj)) and the new element
//! to the container as close as possible to the position just before hint.
//!
//! No iterators or references are invalidated. If the insertion is successful, pointers and references
//! to the element obtained while it is held in the node handle are invalidated, and pointers and
//! references obtained to that element before it was extracted become valid.
//!
//! <b>Returns</b>: The bool component is true if the insertion took place and false if the assignment
//! took place. The iterator component is pointing at the element that was inserted or updated.
//!
//! <b>Complexity</b>: Logarithmic in the size of the container in general, but amortized constant if
//! the new element is inserted just before hint.
template <class M>
BOOST_CONTAINER_FORCEINLINE iterator insert_or_assign(const_iterator hint, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(M) obj)
{ return this->base_t::insert_or_assign(hint, ::boost::move(k), ::boost::forward<M>(obj)); }
//! <b>Returns</b>: A reference to the element whose key is equivalent to x.
//! Throws: An exception object of type out_of_range if no such element is present.
//! <b>Complexity</b>: logarithmic.
T& at(const key_type& k)
{
iterator i = this->find(k);
if(i == this->end()){
throw_out_of_range("map::at key not found");
}
return i->second;
}
//! <b>Returns</b>: A reference to the element whose key is equivalent to x.
//! Throws: An exception object of type out_of_range if no such element is present.
//! <b>Complexity</b>: logarithmic.
const T& at(const key_type& k) const
{
const_iterator i = this->find(k);
if(i == this->end()){
throw_out_of_range("map::at key not found");
}
return i->second;
}
//////////////////////////////////////////////
//
// modifiers
//
//////////////////////////////////////////////
//! <b>Effects</b>: Inserts x if and only if there is no element in the container
//! with key equivalent to the key of x.
//!
//! <b>Returns</b>: The bool component of the returned pair is true if and only
//! if the insertion takes place, and the iterator component of the pair
//! points to the element with key equivalent to the key of x.
//!
//! <b>Complexity</b>: Logarithmic.
BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(const value_type& x)
{ return this->base_t::insert_unique(x); }
//! <b>Effects</b>: Inserts a new value_type created from the pair if and only if
//! there is no element in the container with key equivalent to the key of x.
//!
//! <b>Returns</b>: The bool component of the returned pair is true if and only
//! if the insertion takes place, and the iterator component of the pair
//! points to the element with key equivalent to the key of x.
//!
//! <b>Complexity</b>: Logarithmic.
BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(const nonconst_value_type& x)
{ return this->try_emplace(x.first, x.second); }
//! <b>Effects</b>: Inserts a new value_type move constructed from the pair if and
//! only if there is no element in the container with key equivalent to the key of x.
//!
//! <b>Returns</b>: The bool component of the returned pair is true if and only
//! if the insertion takes place, and the iterator component of the pair
//! points to the element with key equivalent to the key of x.
//!
//! <b>Complexity</b>: Logarithmic.
BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(BOOST_RV_REF(nonconst_value_type) x)
{ return this->try_emplace(boost::move(x.first), boost::move(x.second)); }
//! <b>Effects</b>: Inserts a new value_type move constructed from the pair if and
//! only if there is no element in the container with key equivalent to the key of x.
//!
//! <b>Returns</b>: The bool component of the returned pair is true if and only
//! if the insertion takes place, and the iterator component of the pair
//! points to the element with key equivalent to the key of x.
//!
//! <b>Complexity</b>: Logarithmic.
BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(BOOST_RV_REF(movable_value_type) x)
{ return this->try_emplace(boost::move(x.first), boost::move(x.second)); }
//! <b>Effects</b>: Move constructs a new value from x if and only if there is
//! no element in the container with key equivalent to the key of x.
//!
//! <b>Returns</b>: The bool component of the returned pair is true if and only
//! if the insertion takes place, and the iterator component of the pair
//! points to the element with key equivalent to the key of x.
//!
//! <b>Complexity</b>: Logarithmic.
BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> insert(BOOST_RV_REF(value_type) x)
{ return this->base_t::insert_unique(boost::move(x)); }
//! <b>Effects</b>: Inserts a copy of x in the container if and only if there is
//! no element in the container with key equivalent to the key of x.
//! p is a hint pointing to where the insert should start to search.
//!
//! <b>Returns</b>: An iterator pointing to the element with key equivalent
//! to the key of x.
//!
//! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
//! is inserted right before p.
BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, const value_type& x)
{ return this->base_t::insert_unique(p, x); }
//! <b>Effects</b>: Move constructs a new value from x if and only if there is
//! no element in the container with key equivalent to the key of x.
//! p is a hint pointing to where the insert should start to search.
//!
//! <b>Returns</b>: An iterator pointing to the element with key equivalent
//! to the key of x.
//!
//! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
//! is inserted right before p.
iterator insert(const_iterator p, BOOST_RV_REF(nonconst_value_type) x)
{ return this->try_emplace(p, boost::move(x.first), boost::move(x.second)); }
//! <b>Effects</b>: Move constructs a new value from x if and only if there is
//! no element in the container with key equivalent to the key of x.
//! p is a hint pointing to where the insert should start to search.
//!
//! <b>Returns</b>: An iterator pointing to the element with key equivalent
//! to the key of x.
//!
//! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
//! is inserted right before p.
iterator insert(const_iterator p, BOOST_RV_REF(movable_value_type) x)
{ return this->try_emplace(p, boost::move(x.first), boost::move(x.second)); }
//! <b>Effects</b>: Inserts a copy of x in the container.
//! p is a hint pointing to where the insert should start to search.
//!
//! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
//!
//! <b>Complexity</b>: Logarithmic.
iterator insert(const_iterator p, const nonconst_value_type& x)
{ return this->try_emplace(p, x.first, x.second); }
//! <b>Effects</b>: Inserts an element move constructed from x in the container.
//! p is a hint pointing to where the insert should start to search.
//!
//! <b>Returns</b>: An iterator pointing to the element with key equivalent to the key of x.
//!
//! <b>Complexity</b>: Logarithmic.
iterator insert(const_iterator p, BOOST_RV_REF(value_type) x)
{ return this->base_t::insert_unique(p, boost::move(x)); }
//! <b>Requires</b>: first, last are not iterators into *this.
//!
//! <b>Effects</b>: inserts each element from the range [first,last) if and only
//! if there is no element with key equivalent to the key of that element.
//!
//! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
template <class InputIterator>
BOOST_CONTAINER_FORCEINLINE void insert(InputIterator first, InputIterator last)
{ this->base_t::insert_unique(first, last); }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
//! <b>Effects</b>: inserts each element from the range [il.begin(), il.end()) if and only
//! if there is no element with key equivalent to the key of that element.
//!
//! <b>Complexity</b>: At most N log(size()+N) (N is the distance from il.begin() to il.end())
BOOST_CONTAINER_FORCEINLINE void insert(std::initializer_list<value_type> il)
{ this->base_t::insert_unique(il.begin(), il.end()); }
#endif
//! <b>Requires</b>: nh is empty or this->get_allocator() == nh.get_allocator().
//!
//! <b>Effects</b>: If nh is empty, has no effect. Otherwise, inserts the element owned
//! by nh if and only if there is no element in the container with a key equivalent to nh.key().
//!
//! <b>Returns</b>: If nh is empty, insert_return_type.inserted is false, insert_return_type.position
//! is end(), and insert_return_type.node is empty. Otherwise if the insertion took place,
//! insert_return_type.inserted is true, insert_return_type.position points to the inserted element,
//! and insert_return_type.node is empty; if the insertion failed, insert_return_type.inserted is
//! false, insert_return_type.node has the previous value of nh, and insert_return_type.position
//! points to an element with a key equivalent to nh.key().
//!
//! <b>Complexity</b>: Logarithmic
insert_return_type insert(BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
{
typename base_t::node_type n(boost::move(nh));
typename base_t::insert_return_type base_ret(this->base_t::insert_unique_node(boost::move(n)));
return insert_return_type (base_ret.inserted, base_ret.position, boost::move(base_ret.node));
}
//! <b>Effects</b>: Same as `insert(node_type && nh)` but the element is inserted as close as possible
//! to the position just prior to "hint".
//!
//! <b>Complexity</b>: logarithmic in general, but amortized constant if the element is inserted
//! right before "hint".
insert_return_type insert(const_iterator hint, BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
{
typename base_t::node_type n(boost::move(nh));
typename base_t::insert_return_type base_ret(this->base_t::insert_unique_node(hint, boost::move(n)));
return insert_return_type (base_ret.inserted, base_ret.position, boost::move(base_ret.node));
}
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! <b>Effects</b>: Inserts an object x of type T constructed with
//! std::forward<Args>(args)... in the container if and only if there is
//! no element in the container with an equivalent key.
//! p is a hint pointing to where the insert should start to search.
//!
//! <b>Returns</b>: The bool component of the returned pair is true if and only
//! if the insertion takes place, and the iterator component of the pair
//! points to the element with key equivalent to the key of x.
//!
//! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
//! is inserted right before p.
template <class... Args>
BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> emplace(BOOST_FWD_REF(Args)... args)
{ return this->base_t::emplace_unique(boost::forward<Args>(args)...); }
//! <b>Effects</b>: Inserts an object of type T constructed with
//! std::forward<Args>(args)... in the container if and only if there is
//! no element in the container with an equivalent key.
//! p is a hint pointing to where the insert should start to search.
//!
//! <b>Returns</b>: An iterator pointing to the element with key equivalent
//! to the key of x.
//!
//! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
//! is inserted right before p.
template <class... Args>
BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator p, BOOST_FWD_REF(Args)... args)
{ return this->base_t::emplace_hint_unique(p, boost::forward<Args>(args)...); }
//! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
//! forward_as_tuple(k), forward_as_tuple(forward<Args>(args)...).
//!
//! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
//! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(k),
//! forward_as_tuple(forward<Args>(args)...).
//!
//! <b>Returns</b>: The bool component of the returned pair is true if and only if the
//! insertion took place. The returned iterator points to the map element whose key is equivalent to k.
//!
//! <b>Complexity</b>: Logarithmic.
template <class... Args>
BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(const key_type& k, BOOST_FWD_REF(Args)... args)
{ return this->base_t::try_emplace(const_iterator(), k, boost::forward<Args>(args)...); }
//! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
//! forward_as_tuple(k), forward_as_tuple(forward<Args>(args)...).
//!
//! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
//! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(k),
//! forward_as_tuple(forward<Args>(args)...).
//!
//! <b>Returns</b>: The returned iterator points to the map element whose key is equivalent to k.
//!
//! <b>Complexity</b>: Logarithmic in general, but amortized constant if value
//! is inserted right before p.
template <class... Args>
BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, const key_type &k, BOOST_FWD_REF(Args)... args)
{ return this->base_t::try_emplace(hint, k, boost::forward<Args>(args)...).first; }
//! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
//! forward_as_tuple(move(k)), forward_as_tuple(forward<Args>(args)...).
//!
//! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
//! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(move(k)),
//! forward_as_tuple(forward<Args>(args)...).
//!
//! <b>Returns</b>: The bool component of the returned pair is true if and only if the
//! insertion took place. The returned iterator points to the map element whose key is equivalent to k.
//!
//! <b>Complexity</b>: Logarithmic.
template <class... Args>
BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(BOOST_RV_REF(key_type) k, BOOST_FWD_REF(Args)... args)
{ return this->base_t::try_emplace(const_iterator(), boost::move(k), boost::forward<Args>(args)...); }
//! <b>Requires</b>: value_type shall be EmplaceConstructible into map from piecewise_construct,
//! forward_as_tuple(move(k)), forward_as_tuple(forward<Args>(args)...).
//!
//! <b>Effects</b>: If the map already contains an element whose key is equivalent to k, there is no effect. Otherwise
//! inserts an object of type value_type constructed with piecewise_construct, forward_as_tuple(move(k)),
//! forward_as_tuple(forward<Args>(args)...).
//!
//! <b>Returns</b>: The returned iterator points to the map element whose key is equivalent to k.
//!
//! <b>Complexity</b>: Logarithmic in general, but amortized constant if value
//! is inserted right before p.
template <class... Args>
BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, BOOST_RV_REF(key_type) k, BOOST_FWD_REF(Args)... args)
{ return this->base_t::try_emplace(hint, boost::move(k), boost::forward<Args>(args)...).first; }
#else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#define BOOST_CONTAINER_MAP_EMPLACE_CODE(N) \
BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
BOOST_CONTAINER_FORCEINLINE std::pair<iterator,bool> emplace(BOOST_MOVE_UREF##N)\
{ return this->base_t::emplace_unique(BOOST_MOVE_FWD##N); }\
\
BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
{ return this->base_t::emplace_hint_unique(hint BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
\
BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(const key_type& k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
{ return this->base_t::try_emplace(const_iterator(), k BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
\
BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, const key_type &k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
{ return this->base_t::try_emplace(hint, k BOOST_MOVE_I##N BOOST_MOVE_FWD##N).first; }\
\
BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
BOOST_CONTAINER_FORCEINLINE std::pair<iterator, bool> try_emplace(BOOST_RV_REF(key_type) k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
{ return this->base_t::try_emplace(const_iterator(), boost::move(k) BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
\
BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
BOOST_CONTAINER_FORCEINLINE iterator try_emplace(const_iterator hint, BOOST_RV_REF(key_type) k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
{ return this->base_t::try_emplace(hint, boost::move(k) BOOST_MOVE_I##N BOOST_MOVE_FWD##N).first; }\
//
BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_MAP_EMPLACE_CODE)
#undef BOOST_CONTAINER_MAP_EMPLACE_CODE
#endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! <b>Effects</b>: Erases the element pointed to by p.
//!
//! <b>Returns</b>: Returns an iterator pointing to the element immediately
//! following q prior to the element being erased. If no such element exists,
//! returns end().
//!
//! <b>Complexity</b>: Amortized constant time
iterator erase(const_iterator p) BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Erases all elements in the container with key equivalent to x.
//!
//! <b>Returns</b>: Returns the number of erased elements.
//!
//! <b>Complexity</b>: log(size()) + count(k)
size_type erase(const key_type& x) BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Erases all the elements in the range [first, last).
//!
//! <b>Returns</b>: Returns last.
//!
//! <b>Complexity</b>: log(size())+N where N is the distance from first to last.
iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW;
#endif
//! <b>Effects</b>: Removes the first element in the container with key equivalent to k.
//!
//! <b>Returns</b>: A node_type owning the element if found, otherwise an empty node_type.
//!
//! <b>Complexity</b>: log(a.size()).
node_type extract(const key_type& k)
{
typename base_t::node_type base_nh(this->base_t::extract(k));
node_type nh(boost::move(base_nh));
return BOOST_MOVE_RET(node_type, nh);
}
//! <b>Effects</b>: Removes the element pointed to by "position".
//!
//! <b>Returns</b>: A node_type owning the element, otherwise an empty node_type.
//!
//! <b>Complexity</b>: Amortized constant.
node_type extract(const_iterator position)
{
typename base_t::node_type base_nh(this->base_t::extract(position));
node_type nh(boost::move(base_nh));
return BOOST_MOVE_RET(node_type, nh);
}
//! <b>Requires</b>: this->get_allocator() == source.get_allocator().
//!
//! <b>Effects</b>: Attempts to extract each element in source and insert it into a using
//! the comparison object of *this. If there is an element in a with key equivalent to the
//! key of an element from source, then that element is not extracted from source.
//!
//! <b>Postcondition</b>: Pointers and references to the transferred elements of source refer
//! to those same elements but as members of *this. Iterators referring to the transferred
//! elements will continue to refer to their elements, but they now behave as iterators into *this,
//! not into source.
//!
//! <b>Throws</b>: Nothing unless the comparison object throws.
//!
//! <b>Complexity</b>: N log(a.size() + N) (N has the value source.size())
template<class C2>
BOOST_CONTAINER_FORCEINLINE void merge(map<Key, T, C2, Allocator, Options>& source)
{
typedef container_detail::tree
<value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
this->merge_unique(static_cast<base2_t&>(source));
}
//! @copydoc ::boost::container::map::merge(map<Key, T, C2, Allocator, Options>&)
template<class C2>
BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG map<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
{ return this->merge(static_cast<map<Key, T, C2, Allocator, Options>&>(source)); }
//! @copydoc ::boost::container::map::merge(map<Key, T, C2, Allocator, Options>&)
template<class C2>
BOOST_CONTAINER_FORCEINLINE void merge(multimap<Key, T, C2, Allocator, Options>& source)
{
typedef container_detail::tree
<value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
this->base_t::merge_unique(static_cast<base2_t&>(source));
}
//! @copydoc ::boost::container::map::merge(map<Key, T, C2, Allocator, Options>&)
template<class C2>
BOOST_CONTAINER_FORCEINLINE void merge(BOOST_RV_REF_BEG multimap<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
{ return this->merge(static_cast<multimap<Key, T, C2, Allocator, Options>&>(source)); }
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! <b>Effects</b>: Swaps the contents of *this and x.
//!
//! <b>Throws</b>: Nothing.
//!
//! <b>Complexity</b>: Constant.
void swap(map& x)
BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_swappable<Compare>::value )
//! <b>Effects</b>: erase(a.begin(),a.end()).
//!
//! <b>Postcondition</b>: size() == 0.
//!
//! <b>Complexity</b>: linear in size().
void clear() BOOST_NOEXCEPT_OR_NOTHROW;
//! <b>Effects</b>: Returns the comparison object out
//! of which a was constructed.
//!
//! <b>Complexity</b>: Constant.
key_compare key_comp() const;
//! <b>Effects</b>: Returns an object of value_compare constructed out
//! of the comparison object.
//!
//! <b>Complexity</b>: Constant.
value_compare value_comp() const;
//! <b>Returns</b>: An iterator pointing to an element with the key
//! equivalent to x, or end() if such an element is not found.
//!
//! <b>Complexity</b>: Logarithmic.
iterator find(const key_type& x);
//! <b>Returns</b>: A const_iterator pointing to an element with the key
//! equivalent to x, or end() if such an element is not found.
//!
//! <b>Complexity</b>: Logarithmic.
const_iterator find(const key_type& x) const;
#endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! <b>Returns</b>: The number of elements with key equivalent to x.
//!
//! <b>Complexity</b>: log(size())+count(k)
BOOST_CONTAINER_FORCEINLINE size_type count(const key_type& x) const
{ return static_cast<size_type>(this->find(x) != this->cend()); }
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! <b>Returns</b>: An iterator pointing to the first element with key not less
//! than k, or a.end() if such an element is not found.
//!
//! <b>Complexity</b>: Logarithmic
iterator lower_bound(const key_type& x);
//! <b>Returns</b>: A const iterator pointing to the first element with key not
//! less than k, or a.end() if such an element is not found.
//!
//! <b>Complexity</b>: Logarithmic
const_iterator lower_bound(const key_type& x) const;
//! <b>Returns</b>: An iterator pointing to the first element with key not less
//! than x, or end() if such an element is not found.
//!
//! <b>Complexity</b>: Logarithmic
iterator upper_bound(const key_type& x);
//! <b>Returns</b>: A const iterator pointing to the first element with key not
//! less than x, or end() if such an element is not found.
//!
//! <b>Complexity</b>: Logarithmic
const_iterator upper_bound(const key_type& x) const;
//! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
//!
//! <b>Complexity</b>: Logarithmic
std::pair<iterator,iterator> equal_range(const key_type& x);
//! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
//!
//! <b>Complexity</b>: Logarithmic
std::pair<const_iterator,const_iterator> equal_range(const key_type& x) const;
//! <b>Effects</b>: Rebalances the tree. It's a no-op for Red-Black and AVL trees.
//!
//! <b>Complexity</b>: Linear
void rebalance();
//! <b>Effects</b>: Returns true if x and y are equal
//!
//! <b>Complexity</b>: Linear to the number of elements in the container.
friend bool operator==(const map& x, const map& y);
//! <b>Effects</b>: Returns true if x and y are unequal
//!
//! <b>Complexity</b>: Linear to the number of elements in the container.
friend bool operator!=(const map& x, const map& y);
//! <b>Effects</b>: Returns true if x is less than y
//!
//! <b>Complexity</b>: Linear to the number of elements in the container.
friend bool operator<(const map& x, const map& y);
//! <b>Effects</b>: Returns true if x is greater than y
//!
//! <b>Complexity</b>: Linear to the number of elements in the container.
friend bool operator>(const map& x, const map& y);
//! <b>Effects</b>: Returns true if x is equal or less than y
//!
//! <b>Complexity</b>: Linear to the number of elements in the container.
friend bool operator<=(const map& x, const map& y);
//! <b>Effects</b>: Returns true if x is equal or greater than y
//!
//! <b>Complexity</b>: Linear to the number of elements in the container.
friend bool operator>=(const map& x, const map& y);
//! <b>Effects</b>: x.swap(y)
//!
//! <b>Complexity</b>: Constant.
friend void swap(map& x, map& y);
#endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
private:
template<class KeyConvertible>
BOOST_CONTAINER_FORCEINLINE mapped_type& priv_subscript(BOOST_FWD_REF(KeyConvertible) k)
{
return this->try_emplace(boost::forward<KeyConvertible>(k)).first->second;
}
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
};
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
} //namespace container {
//!has_trivial_destructor_after_move<> == true_type
//!specialization for optimizations
template <class Key, class T, class Compare, class Allocator>
struct has_trivial_destructor_after_move<boost::container::map<Key, T, Compare, Allocator> >
{
typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
::boost::has_trivial_destructor_after_move<pointer>::value &&
::boost::has_trivial_destructor_after_move<Compare>::value;
};
namespace container {
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
//! A multimap is a kind of associative container that supports equivalent keys
//! (possibly containing multiple copies of the same key value) and provides for
//! fast retrieval of values of another type T based on the keys. The multimap class
//! supports bidirectional iterators.
//!
//! A multimap satisfies all of the requirements of a container and of a reversible
//! container and of an associative container. The <code>value_type</code> stored
//! by this container is the value_type is std::pair<const Key, T>.
//!
//! \tparam Key is the key_type of the map
//! \tparam Value is the <code>mapped_type</code>
//! \tparam Compare is the ordering function for Keys (e.g. <i>std::less<Key></i>).
//! \tparam Allocator is the allocator to allocate the <code>value_type</code>s
//! (e.g. <i>allocator< std::pair<const Key, T> > </i>).
//! \tparam Options is an packed option type generated using using boost::container::tree_assoc_options.
template < class Key, class T, class Compare = std::less<Key>
, class Allocator = new_allocator< std::pair< const Key, T> >, class Options = tree_assoc_defaults>
#else
template <class Key, class T, class Compare, class Allocator, class Options>
#endif
class multimap
///@cond
: public container_detail::tree
< std::pair<const Key, T>
, container_detail::select1st<Key>
, Compare, Allocator, Options>
///@endcond
{
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
private:
BOOST_COPYABLE_AND_MOVABLE(multimap)
typedef container_detail::select1st<Key> select_1st_t;
typedef std::pair<const Key, T> value_type_impl;
typedef container_detail::tree
<value_type_impl, select_1st_t, Compare, Allocator, Options> base_t;
typedef container_detail::pair <Key, T> movable_value_type_impl;
typedef typename base_t::value_compare value_compare_impl;
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type;
public:
//////////////////////////////////////////////
//
// types
//
//////////////////////////////////////////////
typedef Key key_type;
typedef T mapped_type;
typedef std::pair<const Key, T> value_type;
typedef typename boost::container::allocator_traits<Allocator>::pointer pointer;
typedef typename boost::container::allocator_traits<Allocator>::const_pointer const_pointer;
typedef typename boost::container::allocator_traits<Allocator>::reference reference;
typedef typename boost::container::allocator_traits<Allocator>::const_reference const_reference;
typedef typename boost::container::allocator_traits<Allocator>::size_type size_type;
typedef typename boost::container::allocator_traits<Allocator>::difference_type difference_type;
typedef Allocator allocator_type;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::stored_allocator_type) stored_allocator_type;
typedef BOOST_CONTAINER_IMPDEF(value_compare_impl) value_compare;
typedef Compare key_compare;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::iterator) iterator;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_iterator) const_iterator;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::reverse_iterator) reverse_iterator;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_reverse_iterator) const_reverse_iterator;
typedef std::pair<key_type, mapped_type> nonconst_value_type;
typedef BOOST_CONTAINER_IMPDEF(movable_value_type_impl) movable_value_type;
typedef BOOST_CONTAINER_IMPDEF(node_handle<
typename base_t::node_type::container_node_type
BOOST_MOVE_I value_type
BOOST_MOVE_I allocator_type
BOOST_MOVE_I pair_key_mapped_of_value
<key_type BOOST_MOVE_I mapped_type> >) node_type;
//////////////////////////////////////////////
//
// construct/copy/destroy
//
//////////////////////////////////////////////
//! <b>Effects</b>: Default constructs an empty multimap.
//!
//! <b>Complexity</b>: Constant.
BOOST_CONTAINER_FORCEINLINE
multimap() BOOST_NOEXCEPT_IF(container_detail::is_nothrow_default_constructible<Allocator>::value &&
container_detail::is_nothrow_default_constructible<Compare>::value)
: base_t()
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Constructs an empty multimap using the specified allocator.
//!
//! <b>Complexity</b>: Constant.
BOOST_CONTAINER_FORCEINLINE
explicit multimap(const Compare& comp, const allocator_type& a = allocator_type())
: base_t(comp, a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Constructs an empty multimap using the specified comparison
//! object and allocator.
//!
//! <b>Complexity</b>: Constant.
BOOST_CONTAINER_FORCEINLINE
explicit multimap(const allocator_type& a)
: base_t(a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Constructs an empty multimap using the specified comparison object
//! and allocator, and inserts elements from the range [first ,last ).
//!
//! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
//! comp and otherwise N logN, where N is last - first.
template <class InputIterator>
BOOST_CONTAINER_FORCEINLINE
multimap(InputIterator first, InputIterator last,
const Compare& comp = Compare(),
const allocator_type& a = allocator_type())
: base_t(false, first, last, comp, a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Constructs an empty multimap using the specified
//! allocator, and inserts elements from the range [first ,last ).
//!
//! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
//! comp and otherwise N logN, where N is last - first.
template <class InputIterator>
BOOST_CONTAINER_FORCEINLINE multimap(InputIterator first, InputIterator last, const allocator_type& a)
: base_t(false, first, last, Compare(), a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
//! allocator, and inserts elements from the ordered range [first ,last). This function
//! is more efficient than the normal range creation for ordered ranges.
//!
//! <b>Requires</b>: [first ,last) must be ordered according to the predicate.
//!
//! <b>Complexity</b>: Linear in N.
//!
//! <b>Note</b>: Non-standard extension.
template <class InputIterator>
BOOST_CONTAINER_FORCEINLINE multimap(ordered_range_t, InputIterator first, InputIterator last, const Compare& comp = Compare(),
const allocator_type& a = allocator_type())
: base_t(ordered_range, first, last, comp, a)
{}
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
//! <b>Effects</b>: Constructs an empty multimap using the specified comparison object and
//! allocator, and inserts elements from the range [il.begin(), il.end()).
//!
//! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
//! comp and otherwise N logN, where N is il.first() - il.end().
BOOST_CONTAINER_FORCEINLINE
multimap(std::initializer_list<value_type> il, const Compare& comp = Compare(),
const allocator_type& a = allocator_type())
: base_t(false, il.begin(), il.end(), comp, a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Constructs an empty multimap using the specified
//! allocator, and inserts elements from the range [il.begin(), il.end()).
//!
//! <b>Complexity</b>: Linear in N if the range [first ,last ) is already sorted using
//! comp and otherwise N logN, where N is il.first() - il.end().
BOOST_CONTAINER_FORCEINLINE
multimap(std::initializer_list<value_type> il, const allocator_type& a)
: base_t(false, il.begin(), il.end(), Compare(), a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Constructs an empty set using the specified comparison object and
//! allocator, and inserts elements from the ordered range [il.begin(), il.end()). This function
//! is more efficient than the normal range creation for ordered ranges.
//!
//! <b>Requires</b>: [il.begin(), il.end()) must be ordered according to the predicate.
//!
//! <b>Complexity</b>: Linear in N.
//!
//! <b>Note</b>: Non-standard extension.
BOOST_CONTAINER_FORCEINLINE
multimap(ordered_range_t, std::initializer_list<value_type> il, const Compare& comp = Compare(),
const allocator_type& a = allocator_type())
: base_t(ordered_range, il.begin(), il.end(), comp, a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
#endif
//! <b>Effects</b>: Copy constructs a multimap.
//!
//! <b>Complexity</b>: Linear in x.size().
BOOST_CONTAINER_FORCEINLINE multimap(const multimap& x)
: base_t(static_cast<const base_t&>(x))
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Move constructs a multimap. Constructs *this using x's resources.
//!
//! <b>Complexity</b>: Constant.
//!
//! <b>Postcondition</b>: x is emptied.
BOOST_CONTAINER_FORCEINLINE multimap(BOOST_RV_REF(multimap) x)
BOOST_NOEXCEPT_IF(boost::container::container_detail::is_nothrow_move_constructible<Compare>::value)
: base_t(BOOST_MOVE_BASE(base_t, x))
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Copy constructs a multimap.
//!
//! <b>Complexity</b>: Linear in x.size().
BOOST_CONTAINER_FORCEINLINE multimap(const multimap& x, const allocator_type &a)
: base_t(static_cast<const base_t&>(x), a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Move constructs a multimap using the specified allocator.
//! Constructs *this using x's resources.
//! <b>Complexity</b>: Constant if a == x.get_allocator(), linear otherwise.
//!
//! <b>Postcondition</b>: x is emptied.
BOOST_CONTAINER_FORCEINLINE multimap(BOOST_RV_REF(multimap) x, const allocator_type &a)
: base_t(BOOST_MOVE_BASE(base_t, x), a)
{
//A type must be std::pair<CONST Key, T>
BOOST_STATIC_ASSERT((container_detail::is_same<std::pair<const Key, T>, typename Allocator::value_type>::value));
}
//! <b>Effects</b>: Makes *this a copy of x.
//!
//! <b>Complexity</b>: Linear in x.size().
BOOST_CONTAINER_FORCEINLINE multimap& operator=(BOOST_COPY_ASSIGN_REF(multimap) x)
{ return static_cast<multimap&>(this->base_t::operator=(static_cast<const base_t&>(x))); }
//! <b>Effects</b>: this->swap(x.get()).
//!
//! <b>Complexity</b>: Constant.
BOOST_CONTAINER_FORCEINLINE multimap& operator=(BOOST_RV_REF(multimap) x)
BOOST_NOEXCEPT_IF( (allocator_traits_type::propagate_on_container_move_assignment::value ||
allocator_traits_type::is_always_equal::value) &&
boost::container::container_detail::is_nothrow_move_assignable<Compare>::value)
{ return static_cast<multimap&>(this->base_t::operator=(BOOST_MOVE_BASE(base_t, x))); }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
//! <b>Effects</b>: Assign content of il to *this.
//!
BOOST_CONTAINER_FORCEINLINE multimap& operator=(std::initializer_list<value_type> il)
{
this->clear();
insert(il.begin(), il.end());
return *this;
}
#endif
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! @copydoc ::boost::container::set::get_allocator()
allocator_type get_allocator() const;
//! @copydoc ::boost::container::set::get_stored_allocator()
stored_allocator_type &get_stored_allocator();
//! @copydoc ::boost::container::set::get_stored_allocator() const
const stored_allocator_type &get_stored_allocator() const;
//! @copydoc ::boost::container::set::begin()
iterator begin();
//! @copydoc ::boost::container::set::begin() const
const_iterator begin() const;
//! @copydoc ::boost::container::set::cbegin() const
const_iterator cbegin() const;
//! @copydoc ::boost::container::set::end()
iterator end() BOOST_NOEXCEPT_OR_NOTHROW;
//! @copydoc ::boost::container::set::end() const
const_iterator end() const BOOST_NOEXCEPT_OR_NOTHROW;
//! @copydoc ::boost::container::set::cend() const
const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW;
//! @copydoc ::boost::container::set::rbegin()
reverse_iterator rbegin() BOOST_NOEXCEPT_OR_NOTHROW;
//! @copydoc ::boost::container::set::rbegin() const
const_reverse_iterator rbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
//! @copydoc ::boost::container::set::crbegin() const
const_reverse_iterator crbegin() const BOOST_NOEXCEPT_OR_NOTHROW;
//! @copydoc ::boost::container::set::rend()
reverse_iterator rend() BOOST_NOEXCEPT_OR_NOTHROW;
//! @copydoc ::boost::container::set::rend() const
const_reverse_iterator rend() const BOOST_NOEXCEPT_OR_NOTHROW;
//! @copydoc ::boost::container::set::crend() const
const_reverse_iterator crend() const BOOST_NOEXCEPT_OR_NOTHROW;
//! @copydoc ::boost::container::set::empty() const
bool empty() const;
//! @copydoc ::boost::container::set::size() const
size_type size() const;
//! @copydoc ::boost::container::set::max_size() const
size_type max_size() const;
#endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! <b>Effects</b>: Inserts an object of type T constructed with
//! std::forward<Args>(args)... in the container.
//! p is a hint pointing to where the insert should start to search.
//!
//! <b>Returns</b>: An iterator pointing to the element with key equivalent
//! to the key of x.
//!
//! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
//! is inserted right before p.
template <class... Args>
BOOST_CONTAINER_FORCEINLINE iterator emplace(BOOST_FWD_REF(Args)... args)
{ return this->base_t::emplace_equal(boost::forward<Args>(args)...); }
//! <b>Effects</b>: Inserts an object of type T constructed with
//! std::forward<Args>(args)... in the container.
//! p is a hint pointing to where the insert should start to search.
//!
//! <b>Returns</b>: An iterator pointing to the element with key equivalent
//! to the key of x.
//!
//! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
//! is inserted right before p.
template <class... Args>
BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator p, BOOST_FWD_REF(Args)... args)
{ return this->base_t::emplace_hint_equal(p, boost::forward<Args>(args)...); }
#else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#define BOOST_CONTAINER_MULTIMAP_EMPLACE_CODE(N) \
BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
BOOST_CONTAINER_FORCEINLINE iterator emplace(BOOST_MOVE_UREF##N)\
{ return this->base_t::emplace_equal(BOOST_MOVE_FWD##N); }\
\
BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
BOOST_CONTAINER_FORCEINLINE iterator emplace_hint(const_iterator hint BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
{ return this->base_t::emplace_hint_equal(hint BOOST_MOVE_I##N BOOST_MOVE_FWD##N); }\
//
BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_MULTIMAP_EMPLACE_CODE)
#undef BOOST_CONTAINER_MULTIMAP_EMPLACE_CODE
#endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
//! <b>Effects</b>: Inserts x and returns the iterator pointing to the
//! newly inserted element.
//!
//! <b>Complexity</b>: Logarithmic.
BOOST_CONTAINER_FORCEINLINE iterator insert(const value_type& x)
{ return this->base_t::insert_equal(x); }
//! <b>Effects</b>: Inserts a new value constructed from x and returns
//! the iterator pointing to the newly inserted element.
//!
//! <b>Complexity</b>: Logarithmic.
BOOST_CONTAINER_FORCEINLINE iterator insert(const nonconst_value_type& x)
{ return this->base_t::emplace_equal(x); }
//! <b>Effects</b>: Inserts a new value move-constructed from x and returns
//! the iterator pointing to the newly inserted element.
//!
//! <b>Complexity</b>: Logarithmic.
BOOST_CONTAINER_FORCEINLINE iterator insert(BOOST_RV_REF(nonconst_value_type) x)
{ return this->base_t::emplace_equal(boost::move(x)); }
//! <b>Effects</b>: Inserts a new value move-constructed from x and returns
//! the iterator pointing to the newly inserted element.
//!
//! <b>Complexity</b>: Logarithmic.
iterator insert(BOOST_RV_REF(movable_value_type) x)
{ return this->base_t::emplace_equal(boost::move(x)); }
//! <b>Effects</b>: Inserts a copy of x in the container.
//! p is a hint pointing to where the insert should start to search.
//!
//! <b>Returns</b>: An iterator pointing to the element with key equivalent
//! to the key of x.
//!
//! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
//! is inserted right before p.
BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, const value_type& x)
{ return this->base_t::insert_equal(p, x); }
//! <b>Effects</b>: Inserts a new value constructed from x in the container.
//! p is a hint pointing to where the insert should start to search.
//!
//! <b>Returns</b>: An iterator pointing to the element with key equivalent
//! to the key of x.
//!
//! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
//! is inserted right before p.
BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, const nonconst_value_type& x)
{ return this->base_t::emplace_hint_equal(p, x); }
//! <b>Effects</b>: Inserts a new value move constructed from x in the container.
//! p is a hint pointing to where the insert should start to search.
//!
//! <b>Returns</b>: An iterator pointing to the element with key equivalent
//! to the key of x.
//!
//! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
//! is inserted right before p.
BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(nonconst_value_type) x)
{ return this->base_t::emplace_hint_equal(p, boost::move(x)); }
//! <b>Effects</b>: Inserts a new value move constructed from x in the container.
//! p is a hint pointing to where the insert should start to search.
//!
//! <b>Returns</b>: An iterator pointing to the element with key equivalent
//! to the key of x.
//!
//! <b>Complexity</b>: Logarithmic in general, but amortized constant if t
//! is inserted right before p.
BOOST_CONTAINER_FORCEINLINE iterator insert(const_iterator p, BOOST_RV_REF(movable_value_type) x)
{ return this->base_t::emplace_hint_equal(p, boost::move(x)); }
//! <b>Requires</b>: first, last are not iterators into *this.
//!
//! <b>Effects</b>: inserts each element from the range [first,last) .
//!
//! <b>Complexity</b>: At most N log(size()+N) (N is the distance from first to last)
template <class InputIterator>
BOOST_CONTAINER_FORCEINLINE void insert(InputIterator first, InputIterator last)
{ this->base_t::insert_equal(first, last); }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
//! <b>Effects</b>: inserts each element from the range [il.begin(), il.end().
//!
//! <b>Complexity</b>: At most N log(size()+N) (N is the distance from il.begin() to il.end())
BOOST_CONTAINER_FORCEINLINE void insert(std::initializer_list<value_type> il)
{ this->base_t::insert_equal(il.begin(), il.end()); }
#endif
//! <b>Requires</b>: nh is empty or this->get_allocator() == nh.get_allocator().
//!
//! <b>Effects/Returns</b>: If nh is empty, has no effect and returns end(). Otherwise, inserts
//! the element owned by nh and returns an iterator pointing to the newly inserted element.
//! If a range containing elements with keys equivalent to nh.key() exists,
//! the element is inserted at the end of that range. nh is always emptied.
//!
//! <b>Complexity</b>: Logarithmic
iterator insert(BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
{
typename base_t::node_type n(boost::move(nh));
return this->base_t::insert_equal_node(boost::move(n));
}
//! <b>Effects</b>: Same as `insert(node_type && nh)` but the element is inserted as close as possible
//! to the position just prior to "hint".
//!
//! <b>Complexity</b>: logarithmic in general, but amortized constant if the element is inserted
//! right before "hint".
iterator insert(const_iterator hint, BOOST_RV_REF_BEG_IF_CXX11 node_type BOOST_RV_REF_END_IF_CXX11 nh)
{
typename base_t::node_type n(boost::move(nh));
return this->base_t::insert_equal_node(hint, boost::move(n));
}
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! @copydoc ::boost::container::set::erase(const_iterator)
iterator erase(const_iterator p);
//! @copydoc ::boost::container::set::erase(const key_type&)
size_type erase(const key_type& x);
//! @copydoc ::boost::container::set::erase(const_iterator,const_iterator)
iterator erase(const_iterator first, const_iterator last);
#endif
//! @copydoc ::boost::container::map::extract(const key_type&)
node_type extract(const key_type& k)
{
typename base_t::node_type base_nh(this->base_t::extract(k));
return node_type(boost::move(base_nh));
}
//! @copydoc ::boost::container::map::extract(const_iterator)
node_type extract(const_iterator position)
{
typename base_t::node_type base_nh(this->base_t::extract(position));
return node_type (boost::move(base_nh));
}
//! <b>Requires</b>: this->get_allocator() == source.get_allocator().
//!
//! <b>Effects</b>: Extracts each element in source and insert it into a using
//! the comparison object of *this.
//!
//! <b>Postcondition</b>: Pointers and references to the transferred elements of source refer
//! to those same elements but as members of *this. Iterators referring to the transferred
//! elements will continue to refer to their elements, but they now behave as iterators into *this,
//! not into source.
//!
//! <b>Throws</b>: Nothing unless the comparison object throws.
//!
//! <b>Complexity</b>: N log(a.size() + N) (N has the value source.size())
template<class C2>
void merge(multimap<Key, T, C2, Allocator, Options>& source)
{
typedef container_detail::tree
<value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
this->base_t::merge_equal(static_cast<base2_t&>(source));
}
//! @copydoc ::boost::container::multimap::merge(multimap<Key, T, C2, Allocator, Options>&)
template<class C2>
void merge(BOOST_RV_REF_BEG multimap<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
{ return this->merge(static_cast<multimap<Key, T, C2, Allocator, Options>&>(source)); }
//! @copydoc ::boost::container::multimap::merge(multimap<Key, T, C2, Allocator, Options>&)
template<class C2>
void merge(map<Key, T, C2, Allocator, Options>& source)
{
typedef container_detail::tree
<value_type_impl, select_1st_t, C2, Allocator, Options> base2_t;
this->base_t::merge_equal(static_cast<base2_t&>(source));
}
//! @copydoc ::boost::container::multimap::merge(multimap<Key, T, C2, Allocator, Options>&)
template<class C2>
void merge(BOOST_RV_REF_BEG map<Key, T, C2, Allocator, Options> BOOST_RV_REF_END source)
{ return this->merge(static_cast<map<Key, T, C2, Allocator, Options>&>(source)); }
#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
//! @copydoc ::boost::container::set::swap
void swap(multiset& x)
BOOST_NOEXCEPT_IF( allocator_traits_type::is_always_equal::value
&& boost::container::container_detail::is_nothrow_swappable<Compare>::value );
//! @copydoc ::boost::container::set::clear
void clear() BOOST_NOEXCEPT_OR_NOTHROW;
//! @copydoc ::boost::container::set::key_comp
key_compare key_comp() const;
//! @copydoc ::boost::container::set::value_comp
value_compare value_comp() const;
//! <b>Returns</b>: An iterator pointing to an element with the key
//! equivalent to x, or end() if such an element is not found.
//!
//! <b>Complexity</b>: Logarithmic.
iterator find(const key_type& x);
//! <b>Returns</b>: A const iterator pointing to an element with the key
//! equivalent to x, or end() if such an element is not found.
//!
//! <b>Complexity</b>: Logarithmic.
const_iterator find(const key_type& x) const;
//! <b>Returns</b>: The number of elements with key equivalent to x.
//!
//! <b>Complexity</b>: log(size())+count(k)
size_type count(const key_type& x) const;
//! <b>Returns</b>: An iterator pointing to the first element with key not less
//! than k, or a.end() if such an element is not found.
//!
//! <b>Complexity</b>: Logarithmic
iterator lower_bound(const key_type& x);
//! <b>Returns</b>: A const iterator pointing to the first element with key not
//! less than k, or a.end() if such an element is not found.
//!
//! <b>Complexity</b>: Logarithmic
const_iterator lower_bound(const key_type& x) const;
//! <b>Returns</b>: An iterator pointing to the first element with key not less
//! than x, or end() if such an element is not found.
//!
//! <b>Complexity</b>: Logarithmic
iterator upper_bound(const key_type& x);
//! <b>Returns</b>: A const iterator pointing to the first element with key not
//! less than x, or end() if such an element is not found.
//!
//! <b>Complexity</b>: Logarithmic
const_iterator upper_bound(const key_type& x) const;
//! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
//!
//! <b>Complexity</b>: Logarithmic
std::pair<iterator,iterator> equal_range(const key_type& x);
//! <b>Effects</b>: Equivalent to std::make_pair(this->lower_bound(k), this->upper_bound(k)).
//!
//! <b>Complexity</b>: Logarithmic
std::pair<const_iterator,const_iterator> equal_range(const key_type& x) const;
//! <b>Effects</b>: Rebalances the tree. It's a no-op for Red-Black and AVL trees.
//!
//! <b>Complexity</b>: Linear
void rebalance();
//! <b>Effects</b>: Returns true if x and y are equal
//!
//! <b>Complexity</b>: Linear to the number of elements in the container.
friend bool operator==(const multimap& x, const multimap& y);
//! <b>Effects</b>: Returns true if x and y are unequal
//!
//! <b>Complexity</b>: Linear to the number of elements in the container.
friend bool operator!=(const multimap& x, const multimap& y);
//! <b>Effects</b>: Returns true if x is less than y
//!
//! <b>Complexity</b>: Linear to the number of elements in the container.
friend bool operator<(const multimap& x, const multimap& y);
//! <b>Effects</b>: Returns true if x is greater than y
//!
//! <b>Complexity</b>: Linear to the number of elements in the container.
friend bool operator>(const multimap& x, const multimap& y);
//! <b>Effects</b>: Returns true if x is equal or less than y
//!
//! <b>Complexity</b>: Linear to the number of elements in the container.
friend bool operator<=(const multimap& x, const multimap& y);
//! <b>Effects</b>: Returns true if x is equal or greater than y
//!
//! <b>Complexity</b>: Linear to the number of elements in the container.
friend bool operator>=(const multimap& x, const multimap& y);
//! <b>Effects</b>: x.swap(y)
//!
//! <b>Complexity</b>: Constant.
friend void swap(multimap& x, multimap& y);
#endif //#if defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
};
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
} //namespace container {
//!has_trivial_destructor_after_move<> == true_type
//!specialization for optimizations
template <class Key, class T, class Compare, class Allocator>
struct has_trivial_destructor_after_move<boost::container::multimap<Key, T, Compare, Allocator> >
{
typedef typename ::boost::container::allocator_traits<Allocator>::pointer pointer;
static const bool value = ::boost::has_trivial_destructor_after_move<Allocator>::value &&
::boost::has_trivial_destructor_after_move<pointer>::value &&
::boost::has_trivial_destructor_after_move<Compare>::value;
};
namespace container {
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
}}
#include <boost/container/detail/config_end.hpp>
#endif // BOOST_CONTAINER_MAP_HPP
|
MODULE scanf
SECTION code_clib
PUBLIC scanf
EXTERN asm_scanf
EXTERN __sgoioblk
; sccz80 version
;void scanf(char *fmt,...)
;{
; asm_scanf(fp, ungetc, getc, sccz80_delta, *ct,ct-1);
;}
scanf:
ld l,a
ld h,0
add hl,hl
add hl,sp ;&fmt
push ix ;save callers
ld bc,__sgoioblk ;stdin
push bc ;fp
ld bc,1 ;sccz80
push bc
ld c,(hl) ;fmt
inc hl
ld b,(hl)
push bc
dec hl
dec hl
dec hl
push hl ;&ap
call asm_scanf
pop bc
pop bc
pop bc
pop bc
pop ix
ret
|
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2014-2019, Lawrence Livermore National Security, LLC.
// Produced at the Lawrence Livermore National Laboratory.
// Written by the LBANN Research Team (B. Van Essen, et al.) listed in
// the CONTRIBUTORS file. <lbann-dev@llnl.gov>
//
// LLNL-CODE-697807.
// All rights reserved.
//
// This file is part of LBANN: Livermore Big Artificial Neural Network
// Toolkit. For details, see http://software.llnl.gov/LBANN or
// https://github.com/LLNL/LBANN.
//
// Licensed under the Apache License, Version 2.0 (the "Licensee"); 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 "lbann/layers/math/clamp.hpp"
namespace lbann {
namespace {
/** Local forward prop computation. */
void local_fp(DataType min,
DataType max,
const AbsMat& input,
AbsMat& output) {
const auto& height = input.Height();
const auto& width = input.Width();
LBANN_OMP_PARALLEL_FOR_COLLAPSE2
for (El::Int col = 0; col < width; ++col) {
for (El::Int row = 0; row < height; ++row) {
const auto& x = input(row, col);
auto& y = output(row, col);
if (x <= min) { y = min; }
else if (x >= max) { y = max; }
else { y = x; }
}
}
}
/** Local backprop computation. */
void local_bp(DataType min,
DataType max,
const AbsMat& input,
const AbsMat& gradient_wrt_output,
AbsMat& gradient_wrt_input) {
const auto& height = input.Height();
const auto& width = input.Width();
LBANN_OMP_PARALLEL_FOR_COLLAPSE2
for (El::Int col = 0; col < width; ++col) {
for (El::Int row = 0; row < height; ++row) {
const auto& x = input(row, col);
const auto& dy = gradient_wrt_output(row, col);
auto& dx = gradient_wrt_input(row, col);
dx = (x <= min || x >= max) ? DataType(0) : dy;
}
}
}
} // namespace
template <>
void clamp_layer<data_layout::DATA_PARALLEL, El::Device::CPU>
::fp_compute() {
local_fp(m_min, m_max,
get_local_prev_activations(),
get_local_activations());
}
template <>
void clamp_layer<data_layout::DATA_PARALLEL, El::Device::CPU>
::bp_compute() {
local_bp(m_min, m_max,
get_local_prev_activations(),
get_local_prev_error_signals(),
get_local_error_signals());
}
template <>
void clamp_layer<data_layout::MODEL_PARALLEL, El::Device::CPU>
::fp_compute() {
local_fp(m_min, m_max,
get_local_prev_activations(),
get_local_activations());
}
template <>
void clamp_layer<data_layout::MODEL_PARALLEL, El::Device::CPU>
::bp_compute() {
local_bp(m_min, m_max,
get_local_prev_activations(),
get_local_prev_error_signals(),
get_local_error_signals());
}
} // namespace lbann
|
copyright zengfr site:http://github.com/zengfr/romhack
00042A move.l D1, (A0)+
00042C dbra D0, $42a
09CFCC clr.l (A1)+
09CFCE dbra D0, $9cfcc
09D4C6 move.b ($2,A0), D1
09D4CA lsl.b #1, D1 [base+47C]
09D51E move.b D1, ($2,A0)
09D522 tst.b ($0,A0) [base+47C, base+48C, base+49C]
09D542 move.b ($2,A0), D0
09D546 beq $9d59e [base+47C, base+48C, base+49C]
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
|
Mansion1_h:
db FACILITY ; tileset
db MANSION_1_HEIGHT, MANSION_1_WIDTH ; dimensions (y, x)
dw Mansion1Blocks, Mansion1TextPointers, Mansion1Script ; blocks, texts, scripts
db $00 ; connections
dw Mansion1Object ; objects
|
/*
===========================================================================
This software is licensed under the Apache 2 license, quoted below.
Copyright (C) 2013 Andrey Budnik <budnik27@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
===========================================================================
*/
#define BOOST_SPIRIT_THREADSAFE
#include <sstream>
#include <stdint.h> // boost/atomic/atomic.hpp:202:16: error: ‘uintptr_t’ was not declared in this scope
#include <boost/property_tree/json_parser.hpp>
#include "protocol.h"
namespace common {
std::string Protocol::CreateHeader( const std::string &msg ) const
{
std::string header( GetProtocolType() );
header += '\n';
header += GetProtocolVersion();
header += '\n';
const size_t size = header.size() + msg.size();
return std::to_string( size ) + '\n' + header;
}
bool Protocol::ParseMsg( const std::string &msg, std::string &protocol, int &version,
std::string &header, std::string &body )
{
int size;
try
{
std::istringstream ss( msg );
ss >> size >> protocol >> version >> header >> body;
}
catch( std::exception &e )
{
PLOG_ERR( "ProtocolJson::ParseMsg: " << e.what() );
return false;
}
return true;
}
bool ProtocolJson::Serialize( std::string &msg, const char *method, const Marshaller &marshaller )
{
std::ostringstream ss;
try
{
boost::property_tree::write_json( ss, marshaller.GetProperties(), false );
}
catch( std::exception &e )
{
PLOG_ERR( "ProtocolJson::Serialize: " << e.what() );
return false;
}
msg = std::string( "{\"type\":\"" ) + std::string( method ) + std::string( "\"}\n" );
msg += ss.str();
msg = CreateHeader( msg ) + msg;
return true;
}
bool ProtocolJson::ParseBody( const std::string &msg, Demarshaller::Properties &ptree )
{
try
{
std::istringstream ss( msg );
boost::property_tree::read_json( ss, ptree );
}
catch( std::exception &e )
{
PLOG_ERR( "ProtocolJson::ParseBody: " << e.what() );
return false;
}
return true;
}
bool ProtocolJson::SendCommand( std::string &msg, const std::string &masterId, const std::string &command,
const std::list< std::pair< std::string, std::string > > ¶ms )
{
std::ostringstream ss;
boost::property_tree::ptree ptree;
try
{
ptree.put( "master_id", masterId );
for( const auto ¶m : params )
{
ptree.put( param.first, param.second );
}
boost::property_tree::write_json( ss, ptree, false );
}
catch( std::exception &e )
{
PLOG_ERR( "ProtocolJson::SendCommand: " << e.what() );
return false;
}
msg = std::string( "{\"type\":\"" ) + command + std::string( "\"}\n" );
msg += ss.str();
msg = CreateHeader( msg ) + msg;
return true;
}
bool ProtocolJson::ParseMsgType( const std::string &msg, std::string &type )
{
std::istringstream ss( msg );
boost::property_tree::ptree ptree;
try
{
boost::property_tree::read_json( ss, ptree );
type = ptree.get<std::string>( "type" );
}
catch( std::exception &e )
{
PLOG_ERR( "ProtocolJson::ParseMsgType: " << e.what() );
return false;
}
return true;
}
} // namespace common
|
// Tests that casting inside constants in the output handles precedence between cast and + correctly - should generate the following KA-expression ($ff & sumw>>1)+1
// Commodore 64 PRG executable file
.file [name="cast-precedence-problem.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)
.segment Code
main: {
.const min = $a
.const max = $c8
.const sumw = min+max
.const sumb = min+max
.const midw = (sumw>>1)+1
.const midb = (sumb>>1)+1
.label SCREEN = $400
.label BG_COLOR = $d021
// SCREEN[0] = midw
lda #midw
sta SCREEN
// SCREEN[1] = midb
lda #midb
sta SCREEN+1
// if(SCREEN[0]==SCREEN[1])
lda SCREEN
cmp SCREEN+1
beq __b1
// *BG_COLOR = 2
lda #2
sta BG_COLOR
// }
rts
__b1:
// *BG_COLOR = 5
lda #5
sta BG_COLOR
rts
}
|
#include "Platform.inc"
#include "TailCalls.inc"
#include "../ShiftRegister.inc"
#include "../Motor.inc"
#include "Lcd.inc"
#include "States.inc"
radix decimal
defineLcdState LCD_STATE_ENABLE_WAITFORSHIFTREGISTER
fcall isShiftRegisterEnabled
andlw 0xff
btfsc STATUS, Z
goto endOfState
clearShiftRegister:
.setBankFor shiftRegisterBuffer
movlw NON_LCD_BITS_MASK
andwf shiftRegisterBuffer
fcall shiftOut
enableLcdPowerSupply:
fcall enableMotorVdd
setLcdState LCD_STATE_ENABLE_WAITFORMORETHAN40MS
endOfState:
returnFromLcdState
end
|
; DV3 Date routine V3.00 1992 Tony Tebby
section dv3
xdef dv3_date
include 'dev8_keys_qdos_sms'
;+++
; DV3 date
;
; d1 r (long) date
;
; status return arbitrary
;---
dv3_date
ddt.reg reg d2/a0
movem.l ddt.reg,-(sp)
moveq #sms.rrtc,d0
trap #do.sms2
movem.l (sp)+,ddt.reg
rts
end
|
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2015 Natale Patriciello, <natale.patriciello@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "ns3/test.h"
#include "ns3/log.h"
#include "ns3/tcp-congestion-ops.h"
#include "ns3/tcp-socket-base.h"
#include "ns3/tcp-bic.h"
namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("TcpBicTestSuite");
/**
* \brief Testing the congestion avoidance increment on TcpBic
*/
class TcpBicIncrementTest : public TestCase
{
public:
TcpBicIncrementTest (uint32_t cWnd,
uint32_t segmentSize,
uint32_t ssThresh,
uint32_t segmentsAcked,
uint32_t lastMaxCwnd,
const std::string &name);
private:
virtual void DoRun (void);
uint32_t Update (Ptr<TcpSocketState> tcb);
void ExecuteTest (void);
uint32_t m_cWnd;
uint32_t m_segmentSize;
uint32_t m_ssThresh;
uint32_t m_segmentsAcked;
uint32_t m_lastMaxCwnd;
Ptr<TcpSocketState> m_state;
};
TcpBicIncrementTest::TcpBicIncrementTest (uint32_t cWnd,
uint32_t segmentSize,
uint32_t ssThresh,
uint32_t segmentsAcked,
uint32_t lastMaxCwnd,
const std::string &name)
: TestCase (name),
m_cWnd (cWnd),
m_segmentSize (segmentSize),
m_ssThresh (ssThresh),
m_segmentsAcked (segmentsAcked),
m_lastMaxCwnd (lastMaxCwnd)
{
}
void
TcpBicIncrementTest::DoRun ()
{
m_state = CreateObject<TcpSocketState> ();
m_state->m_cWnd = m_cWnd;
m_state->m_segmentSize = m_segmentSize;
m_state->m_ssThresh = m_ssThresh;
Simulator::Schedule (Seconds (0.0), &TcpBicIncrementTest::ExecuteTest, this);
Simulator::Run ();
Simulator::Destroy ();
}
void
TcpBicIncrementTest::ExecuteTest ()
{
uint32_t segCwnd = m_cWnd / m_segmentSize;
uint32_t ackCnt = Update (m_state);
if (m_segmentsAcked > ackCnt)
{
NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), segCwnd * m_segmentSize + m_segmentSize,
"Bic has not increment cWnd");
/* NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), 27000,
"Bic has not increment cWnd");*/
}
else
{
NS_TEST_ASSERT_MSG_EQ (m_state->m_cWnd.Get (), segCwnd * m_segmentSize,
"Bic has modified cWnd");
}
}
uint32_t
TcpBicIncrementTest::Update (Ptr<TcpSocketState> tcb)
{
uint32_t segCwnd = tcb->m_cWnd / tcb->m_segmentSize;
Ptr<TcpBic> cong = CreateObject <TcpBic> ();
cong->m_lastMaxCwnd = m_lastMaxCwnd;
UintegerValue lowWindow, bsCoeff, wMax;
IntegerValue smoothPart;
cong->GetAttribute ("LowWnd", lowWindow);
cong->GetAttribute ("BinarySearchCoefficient", bsCoeff);
cong->GetAttribute ("MaxIncr", wMax);
cong->GetAttribute ("SmoothPart", smoothPart);
cong->IncreaseWindow (m_state, m_segmentsAcked);
uint32_t ackCnt = 0;
if (segCwnd < lowWindow.Get ())
{
ackCnt = segCwnd;
return ackCnt;
}
if (segCwnd < m_lastMaxCwnd)
{
double midPt = (m_lastMaxCwnd - segCwnd) / bsCoeff.Get ();
if (midPt > wMax.Get ())
{
//Linear increase
ackCnt = segCwnd / wMax.Get ();
}
else if (midPt <= 1)
{
ackCnt = (segCwnd * smoothPart.Get ()) / bsCoeff.Get ();
}
else
{
//Binary search increase
ackCnt = segCwnd / midPt;
}
}
else
{
if (segCwnd < m_lastMaxCwnd + bsCoeff.Get ())
{
/* slow start AMD linear increase */
ackCnt = (segCwnd * smoothPart.Get ()) / bsCoeff.Get ();
}
else if (segCwnd < m_lastMaxCwnd + wMax.Get () * (bsCoeff.Get () - 1))
{
/* slow start */
ackCnt = (segCwnd * (bsCoeff.Get () - 1)) / (segCwnd - m_lastMaxCwnd);
}
else
{
/* linear increase */
ackCnt = segCwnd / wMax.Get ();
}
}
return ackCnt;
}
/**
* \brief Testing the congestion avoidance increment on TcpBic
*/
class TcpBicDecrementTest : public TestCase
{
public:
TcpBicDecrementTest (uint32_t cWnd,
uint32_t segmentSize,
BooleanValue fastConvergence,
uint32_t lastMaxCwnd,
const std::string &name);
private:
virtual void DoRun (void);
void ExecuteTest (void);
uint32_t m_cWnd;
uint32_t m_segmentSize;
BooleanValue m_fastConvergence;
uint32_t m_lastMaxCwnd;
Ptr<TcpSocketState> m_state;
};
TcpBicDecrementTest::TcpBicDecrementTest (uint32_t cWnd,
uint32_t segmentSize,
BooleanValue fastConvergence,
uint32_t lastMaxCwnd,
const std::string &name)
: TestCase (name),
m_cWnd (cWnd),
m_segmentSize (segmentSize),
m_fastConvergence (fastConvergence),
m_lastMaxCwnd (lastMaxCwnd)
{
}
void
TcpBicDecrementTest::DoRun ()
{
m_state = CreateObject<TcpSocketState> ();
m_state->m_cWnd = m_cWnd;
m_state->m_segmentSize = m_segmentSize;
Simulator::Schedule (Seconds (0.0), &TcpBicDecrementTest::ExecuteTest, this);
Simulator::Run ();
Simulator::Destroy ();
}
void
TcpBicDecrementTest::ExecuteTest ()
{
Ptr<TcpBic> cong = CreateObject <TcpBic> ();
cong->m_lastMaxCwnd = m_lastMaxCwnd;
cong->SetAttribute ("FastConvergence", m_fastConvergence);
uint32_t segCwnd = m_cWnd / m_segmentSize;
uint32_t retSsThresh = cong->GetSsThresh (m_state, m_state->m_cWnd);
uint32_t retLastMaxCwnd = cong->m_lastMaxCwnd;
DoubleValue beta;
UintegerValue lowWindow;
cong->GetAttribute ("Beta", beta);
cong->GetAttribute ("LowWnd", lowWindow);
uint32_t lastMaxCwnd, ssThresh;
if (segCwnd < m_lastMaxCwnd && m_fastConvergence.Get ())
{
lastMaxCwnd = beta.Get () * segCwnd;
NS_TEST_ASSERT_MSG_EQ (retLastMaxCwnd, lastMaxCwnd,
"Bic has not updated lastMaxCwnd during fast convergence");
}
else
{
lastMaxCwnd = segCwnd;
NS_TEST_ASSERT_MSG_EQ (retLastMaxCwnd, lastMaxCwnd,
"Bic has not reset lastMaxCwnd to current cwnd (in segments)");
}
if (segCwnd < lowWindow.Get ())
{
ssThresh = std::max (2 * m_segmentSize, m_cWnd / 2);
NS_TEST_ASSERT_MSG_EQ (retSsThresh, ssThresh,
"Bic has not updated ssThresh when cWnd less than lowWindow");
}
else
{
ssThresh = std::max (segCwnd * beta.Get (), 2.0) * m_segmentSize;
NS_TEST_ASSERT_MSG_EQ (retSsThresh, ssThresh,
"Bic has not updated ssThresh when cWnd greater than lowWindow");
}
}
// -------------------------------------------------------------------
static class TcpBicTestSuite : public TestSuite
{
public:
TcpBicTestSuite () : TestSuite ("tcp-bic-test", UNIT)
{
AddTestCase (new TcpBicIncrementTest (10 * 536, 536, 9 * 536, 11, 0,
"Bic increment test: under lowCwnd & enough ACKs received"),
TestCase::QUICK);
AddTestCase (new TcpBicIncrementTest (10 * 536, 536, 9 * 536, 8, 0,
"Bic increment test: under lowCwnd but not enough ACKs received"),
TestCase::QUICK);
AddTestCase (new TcpBicIncrementTest (18 * 1446, 1446, 15 * 1446, 5, 90,
"Bic increment test: linear increase when distance exceeds S_max"),
TestCase::QUICK);
AddTestCase (new TcpBicIncrementTest (18 * 1446, 1446, 15 * 1446, 24, 20,
"Bic increment test: binary search increase with smooth part"),
TestCase::QUICK);
AddTestCase (new TcpBicIncrementTest (19 * 1, 1, 17 * 1, 2, 83,
"Bic increment test: binary search increase"),
TestCase::QUICK);
AddTestCase (new TcpBicIncrementTest (15 * 536, 536, 9 * 536, 19, 13,
"Bic increment test: slow start AMD linear increase"),
TestCase::QUICK);
AddTestCase (new TcpBicIncrementTest (22 * 1000, 1000, 9 * 1000, 9, 16,
"Bic increment test: slow start but not enough ACKs received"),
TestCase::QUICK);
AddTestCase (new TcpBicIncrementTest (65 * 1000, 1000, 9 * 1000, 2, 16,
"Bic increment test: linear incrase but not enough ACKs received"),
TestCase::QUICK);
AddTestCase (new TcpBicDecrementTest (5 * 1446, 1446, true, 10,
"Bic decrement test: fast convergence & cwnd less than lowWindow"),
TestCase::QUICK);
AddTestCase (new TcpBicDecrementTest (5 * 1446, 1446, false, 10,
"Bic decrement test: not in fast convergence & cwnd less than lowWindow"),
TestCase::QUICK);
AddTestCase (new TcpBicDecrementTest (15 * 1446, 1446, false, 10,
"Bic decrement test: not in fast convergence & cwnd greater than lowWindow"),
TestCase::QUICK);
}
} g_tcpBicTest;
} // namespace ns3
|
_echo: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "stat.h"
#include "user.h"
int
main(int argc, char *argv[])
{
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 57 push %edi
e: 56 push %esi
f: 53 push %ebx
10: 51 push %ecx
11: 83 ec 08 sub $0x8,%esp
14: 8b 31 mov (%ecx),%esi
16: 8b 79 04 mov 0x4(%ecx),%edi
int i;
for(i = 1; i < argc; i++)
19: 83 fe 01 cmp $0x1,%esi
1c: 7e 41 jle 5f <main+0x5f>
1e: bb 01 00 00 00 mov $0x1,%ebx
23: eb 1b jmp 40 <main+0x40>
25: 8d 76 00 lea 0x0(%esi),%esi
printf(1, "%s%s", argv[i], i+1 < argc ? " " : "\n");
28: 68 20 07 00 00 push $0x720
2d: ff 74 9f fc pushl -0x4(%edi,%ebx,4)
31: 68 22 07 00 00 push $0x722
36: 6a 01 push $0x1
38: e8 c3 03 00 00 call 400 <printf>
3d: 83 c4 10 add $0x10,%esp
40: 83 c3 01 add $0x1,%ebx
43: 39 de cmp %ebx,%esi
45: 75 e1 jne 28 <main+0x28>
47: 68 27 07 00 00 push $0x727
4c: ff 74 b7 fc pushl -0x4(%edi,%esi,4)
50: 68 22 07 00 00 push $0x722
55: 6a 01 push $0x1
57: e8 a4 03 00 00 call 400 <printf>
5c: 83 c4 10 add $0x10,%esp
exit();
5f: e8 4e 02 00 00 call 2b2 <exit>
64: 66 90 xchg %ax,%ax
66: 66 90 xchg %ax,%ax
68: 66 90 xchg %ax,%ax
6a: 66 90 xchg %ax,%ax
6c: 66 90 xchg %ax,%ax
6e: 66 90 xchg %ax,%ax
00000070 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
70: 55 push %ebp
71: 89 e5 mov %esp,%ebp
73: 53 push %ebx
74: 8b 45 08 mov 0x8(%ebp),%eax
77: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
7a: 89 c2 mov %eax,%edx
7c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
80: 83 c1 01 add $0x1,%ecx
83: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
87: 83 c2 01 add $0x1,%edx
8a: 84 db test %bl,%bl
8c: 88 5a ff mov %bl,-0x1(%edx)
8f: 75 ef jne 80 <strcpy+0x10>
;
return os;
}
91: 5b pop %ebx
92: 5d pop %ebp
93: c3 ret
94: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
9a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
000000a0 <strcmp>:
int
strcmp(const char *p, const char *q)
{
a0: 55 push %ebp
a1: 89 e5 mov %esp,%ebp
a3: 56 push %esi
a4: 53 push %ebx
a5: 8b 55 08 mov 0x8(%ebp),%edx
a8: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
ab: 0f b6 02 movzbl (%edx),%eax
ae: 0f b6 19 movzbl (%ecx),%ebx
b1: 84 c0 test %al,%al
b3: 75 1e jne d3 <strcmp+0x33>
b5: eb 29 jmp e0 <strcmp+0x40>
b7: 89 f6 mov %esi,%esi
b9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
c0: 83 c2 01 add $0x1,%edx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
c3: 0f b6 02 movzbl (%edx),%eax
p++, q++;
c6: 8d 71 01 lea 0x1(%ecx),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
c9: 0f b6 59 01 movzbl 0x1(%ecx),%ebx
cd: 84 c0 test %al,%al
cf: 74 0f je e0 <strcmp+0x40>
d1: 89 f1 mov %esi,%ecx
d3: 38 d8 cmp %bl,%al
d5: 74 e9 je c0 <strcmp+0x20>
p++, q++;
return (uchar)*p - (uchar)*q;
d7: 29 d8 sub %ebx,%eax
}
d9: 5b pop %ebx
da: 5e pop %esi
db: 5d pop %ebp
dc: c3 ret
dd: 8d 76 00 lea 0x0(%esi),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
e0: 31 c0 xor %eax,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
e2: 29 d8 sub %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 <strlen>:
uint
strlen(char *s)
{
f0: 55 push %ebp
f1: 89 e5 mov %esp,%ebp
f3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
f6: 80 39 00 cmpb $0x0,(%ecx)
f9: 74 12 je 10d <strlen+0x1d>
fb: 31 d2 xor %edx,%edx
fd: 8d 76 00 lea 0x0(%esi),%esi
100: 83 c2 01 add $0x1,%edx
103: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
107: 89 d0 mov %edx,%eax
109: 75 f5 jne 100 <strlen+0x10>
;
return n;
}
10b: 5d pop %ebp
10c: c3 ret
uint
strlen(char *s)
{
int n;
for(n = 0; s[n]; n++)
10d: 31 c0 xor %eax,%eax
;
return n;
}
10f: 5d pop %ebp
110: c3 ret
111: eb 0d jmp 120 <memset>
113: 90 nop
114: 90 nop
115: 90 nop
116: 90 nop
117: 90 nop
118: 90 nop
119: 90 nop
11a: 90 nop
11b: 90 nop
11c: 90 nop
11d: 90 nop
11e: 90 nop
11f: 90 nop
00000120 <memset>:
void*
memset(void *dst, int c, uint n)
{
120: 55 push %ebp
121: 89 e5 mov %esp,%ebp
123: 57 push %edi
124: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
127: 8b 4d 10 mov 0x10(%ebp),%ecx
12a: 8b 45 0c mov 0xc(%ebp),%eax
12d: 89 d7 mov %edx,%edi
12f: fc cld
130: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
132: 89 d0 mov %edx,%eax
134: 5f pop %edi
135: 5d pop %ebp
136: c3 ret
137: 89 f6 mov %esi,%esi
139: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000140 <strchr>:
char*
strchr(const char *s, char c)
{
140: 55 push %ebp
141: 89 e5 mov %esp,%ebp
143: 53 push %ebx
144: 8b 45 08 mov 0x8(%ebp),%eax
147: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
14a: 0f b6 10 movzbl (%eax),%edx
14d: 84 d2 test %dl,%dl
14f: 74 1d je 16e <strchr+0x2e>
if(*s == c)
151: 38 d3 cmp %dl,%bl
153: 89 d9 mov %ebx,%ecx
155: 75 0d jne 164 <strchr+0x24>
157: eb 17 jmp 170 <strchr+0x30>
159: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
160: 38 ca cmp %cl,%dl
162: 74 0c je 170 <strchr+0x30>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
164: 83 c0 01 add $0x1,%eax
167: 0f b6 10 movzbl (%eax),%edx
16a: 84 d2 test %dl,%dl
16c: 75 f2 jne 160 <strchr+0x20>
if(*s == c)
return (char*)s;
return 0;
16e: 31 c0 xor %eax,%eax
}
170: 5b pop %ebx
171: 5d pop %ebp
172: c3 ret
173: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
179: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000180 <gets>:
char*
gets(char *buf, int max)
{
180: 55 push %ebp
181: 89 e5 mov %esp,%ebp
183: 57 push %edi
184: 56 push %esi
185: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
186: 31 f6 xor %esi,%esi
cc = read(0, &c, 1);
188: 8d 7d e7 lea -0x19(%ebp),%edi
return 0;
}
char*
gets(char *buf, int max)
{
18b: 83 ec 1c sub $0x1c,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
18e: eb 29 jmp 1b9 <gets+0x39>
cc = read(0, &c, 1);
190: 83 ec 04 sub $0x4,%esp
193: 6a 01 push $0x1
195: 57 push %edi
196: 6a 00 push $0x0
198: e8 2d 01 00 00 call 2ca <read>
if(cc < 1)
19d: 83 c4 10 add $0x10,%esp
1a0: 85 c0 test %eax,%eax
1a2: 7e 1d jle 1c1 <gets+0x41>
break;
buf[i++] = c;
1a4: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
1a8: 8b 55 08 mov 0x8(%ebp),%edx
1ab: 89 de mov %ebx,%esi
if(c == '\n' || c == '\r')
1ad: 3c 0a cmp $0xa,%al
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
1af: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
1b3: 74 1b je 1d0 <gets+0x50>
1b5: 3c 0d cmp $0xd,%al
1b7: 74 17 je 1d0 <gets+0x50>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
1b9: 8d 5e 01 lea 0x1(%esi),%ebx
1bc: 3b 5d 0c cmp 0xc(%ebp),%ebx
1bf: 7c cf jl 190 <gets+0x10>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
1c1: 8b 45 08 mov 0x8(%ebp),%eax
1c4: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
1c8: 8d 65 f4 lea -0xc(%ebp),%esp
1cb: 5b pop %ebx
1cc: 5e pop %esi
1cd: 5f pop %edi
1ce: 5d pop %ebp
1cf: c3 ret
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
1d0: 8b 45 08 mov 0x8(%ebp),%eax
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
1d3: 89 de mov %ebx,%esi
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
1d5: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
1d9: 8d 65 f4 lea -0xc(%ebp),%esp
1dc: 5b pop %ebx
1dd: 5e pop %esi
1de: 5f pop %edi
1df: 5d pop %ebp
1e0: c3 ret
1e1: eb 0d jmp 1f0 <stat>
1e3: 90 nop
1e4: 90 nop
1e5: 90 nop
1e6: 90 nop
1e7: 90 nop
1e8: 90 nop
1e9: 90 nop
1ea: 90 nop
1eb: 90 nop
1ec: 90 nop
1ed: 90 nop
1ee: 90 nop
1ef: 90 nop
000001f0 <stat>:
int
stat(char *n, struct stat *st)
{
1f0: 55 push %ebp
1f1: 89 e5 mov %esp,%ebp
1f3: 56 push %esi
1f4: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
1f5: 83 ec 08 sub $0x8,%esp
1f8: 6a 00 push $0x0
1fa: ff 75 08 pushl 0x8(%ebp)
1fd: e8 f0 00 00 00 call 2f2 <open>
if(fd < 0)
202: 83 c4 10 add $0x10,%esp
205: 85 c0 test %eax,%eax
207: 78 27 js 230 <stat+0x40>
return -1;
r = fstat(fd, st);
209: 83 ec 08 sub $0x8,%esp
20c: ff 75 0c pushl 0xc(%ebp)
20f: 89 c3 mov %eax,%ebx
211: 50 push %eax
212: e8 f3 00 00 00 call 30a <fstat>
217: 89 c6 mov %eax,%esi
close(fd);
219: 89 1c 24 mov %ebx,(%esp)
21c: e8 b9 00 00 00 call 2da <close>
return r;
221: 83 c4 10 add $0x10,%esp
224: 89 f0 mov %esi,%eax
}
226: 8d 65 f8 lea -0x8(%ebp),%esp
229: 5b pop %ebx
22a: 5e pop %esi
22b: 5d pop %ebp
22c: c3 ret
22d: 8d 76 00 lea 0x0(%esi),%esi
int fd;
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
230: b8 ff ff ff ff mov $0xffffffff,%eax
235: eb ef jmp 226 <stat+0x36>
237: 89 f6 mov %esi,%esi
239: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000240 <atoi>:
return r;
}
int
atoi(const char *s)
{
240: 55 push %ebp
241: 89 e5 mov %esp,%ebp
243: 53 push %ebx
244: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
247: 0f be 11 movsbl (%ecx),%edx
24a: 8d 42 d0 lea -0x30(%edx),%eax
24d: 3c 09 cmp $0x9,%al
24f: b8 00 00 00 00 mov $0x0,%eax
254: 77 1f ja 275 <atoi+0x35>
256: 8d 76 00 lea 0x0(%esi),%esi
259: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
260: 8d 04 80 lea (%eax,%eax,4),%eax
263: 83 c1 01 add $0x1,%ecx
266: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
26a: 0f be 11 movsbl (%ecx),%edx
26d: 8d 5a d0 lea -0x30(%edx),%ebx
270: 80 fb 09 cmp $0x9,%bl
273: 76 eb jbe 260 <atoi+0x20>
n = n*10 + *s++ - '0';
return n;
}
275: 5b pop %ebx
276: 5d pop %ebp
277: c3 ret
278: 90 nop
279: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000280 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
280: 55 push %ebp
281: 89 e5 mov %esp,%ebp
283: 56 push %esi
284: 53 push %ebx
285: 8b 5d 10 mov 0x10(%ebp),%ebx
288: 8b 45 08 mov 0x8(%ebp),%eax
28b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
28e: 85 db test %ebx,%ebx
290: 7e 14 jle 2a6 <memmove+0x26>
292: 31 d2 xor %edx,%edx
294: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
298: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
29c: 88 0c 10 mov %cl,(%eax,%edx,1)
29f: 83 c2 01 add $0x1,%edx
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
2a2: 39 da cmp %ebx,%edx
2a4: 75 f2 jne 298 <memmove+0x18>
*dst++ = *src++;
return vdst;
}
2a6: 5b pop %ebx
2a7: 5e pop %esi
2a8: 5d pop %ebp
2a9: c3 ret
000002aa <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
2aa: b8 01 00 00 00 mov $0x1,%eax
2af: cd 40 int $0x40
2b1: c3 ret
000002b2 <exit>:
SYSCALL(exit)
2b2: b8 02 00 00 00 mov $0x2,%eax
2b7: cd 40 int $0x40
2b9: c3 ret
000002ba <wait>:
SYSCALL(wait)
2ba: b8 03 00 00 00 mov $0x3,%eax
2bf: cd 40 int $0x40
2c1: c3 ret
000002c2 <pipe>:
SYSCALL(pipe)
2c2: b8 04 00 00 00 mov $0x4,%eax
2c7: cd 40 int $0x40
2c9: c3 ret
000002ca <read>:
SYSCALL(read)
2ca: b8 05 00 00 00 mov $0x5,%eax
2cf: cd 40 int $0x40
2d1: c3 ret
000002d2 <write>:
SYSCALL(write)
2d2: b8 10 00 00 00 mov $0x10,%eax
2d7: cd 40 int $0x40
2d9: c3 ret
000002da <close>:
SYSCALL(close)
2da: b8 15 00 00 00 mov $0x15,%eax
2df: cd 40 int $0x40
2e1: c3 ret
000002e2 <kill>:
SYSCALL(kill)
2e2: b8 06 00 00 00 mov $0x6,%eax
2e7: cd 40 int $0x40
2e9: c3 ret
000002ea <exec>:
SYSCALL(exec)
2ea: b8 07 00 00 00 mov $0x7,%eax
2ef: cd 40 int $0x40
2f1: c3 ret
000002f2 <open>:
SYSCALL(open)
2f2: b8 0f 00 00 00 mov $0xf,%eax
2f7: cd 40 int $0x40
2f9: c3 ret
000002fa <mknod>:
SYSCALL(mknod)
2fa: b8 11 00 00 00 mov $0x11,%eax
2ff: cd 40 int $0x40
301: c3 ret
00000302 <unlink>:
SYSCALL(unlink)
302: b8 12 00 00 00 mov $0x12,%eax
307: cd 40 int $0x40
309: c3 ret
0000030a <fstat>:
SYSCALL(fstat)
30a: b8 08 00 00 00 mov $0x8,%eax
30f: cd 40 int $0x40
311: c3 ret
00000312 <link>:
SYSCALL(link)
312: b8 13 00 00 00 mov $0x13,%eax
317: cd 40 int $0x40
319: c3 ret
0000031a <mkdir>:
SYSCALL(mkdir)
31a: b8 14 00 00 00 mov $0x14,%eax
31f: cd 40 int $0x40
321: c3 ret
00000322 <chdir>:
SYSCALL(chdir)
322: b8 09 00 00 00 mov $0x9,%eax
327: cd 40 int $0x40
329: c3 ret
0000032a <dup>:
SYSCALL(dup)
32a: b8 0a 00 00 00 mov $0xa,%eax
32f: cd 40 int $0x40
331: c3 ret
00000332 <getpid>:
SYSCALL(getpid)
332: b8 0b 00 00 00 mov $0xb,%eax
337: cd 40 int $0x40
339: c3 ret
0000033a <sbrk>:
SYSCALL(sbrk)
33a: b8 0c 00 00 00 mov $0xc,%eax
33f: cd 40 int $0x40
341: c3 ret
00000342 <sleep>:
SYSCALL(sleep)
342: b8 0d 00 00 00 mov $0xd,%eax
347: cd 40 int $0x40
349: c3 ret
0000034a <uptime>:
SYSCALL(uptime)
34a: b8 0e 00 00 00 mov $0xe,%eax
34f: cd 40 int $0x40
351: c3 ret
00000352 <adress>:
SYSCALL(adress)
352: b8 16 00 00 00 mov $0x16,%eax
357: cd 40 int $0x40
359: c3 ret
35a: 66 90 xchg %ax,%ax
35c: 66 90 xchg %ax,%ax
35e: 66 90 xchg %ax,%ax
00000360 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
360: 55 push %ebp
361: 89 e5 mov %esp,%ebp
363: 57 push %edi
364: 56 push %esi
365: 53 push %ebx
366: 89 c6 mov %eax,%esi
368: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
36b: 8b 5d 08 mov 0x8(%ebp),%ebx
36e: 85 db test %ebx,%ebx
370: 74 7e je 3f0 <printint+0x90>
372: 89 d0 mov %edx,%eax
374: c1 e8 1f shr $0x1f,%eax
377: 84 c0 test %al,%al
379: 74 75 je 3f0 <printint+0x90>
neg = 1;
x = -xx;
37b: 89 d0 mov %edx,%eax
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
37d: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
x = -xx;
384: f7 d8 neg %eax
386: 89 75 c0 mov %esi,-0x40(%ebp)
} else {
x = xx;
}
i = 0;
389: 31 ff xor %edi,%edi
38b: 8d 5d d7 lea -0x29(%ebp),%ebx
38e: 89 ce mov %ecx,%esi
390: eb 08 jmp 39a <printint+0x3a>
392: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
do{
buf[i++] = digits[x % base];
398: 89 cf mov %ecx,%edi
39a: 31 d2 xor %edx,%edx
39c: 8d 4f 01 lea 0x1(%edi),%ecx
39f: f7 f6 div %esi
3a1: 0f b6 92 30 07 00 00 movzbl 0x730(%edx),%edx
}while((x /= base) != 0);
3a8: 85 c0 test %eax,%eax
x = xx;
}
i = 0;
do{
buf[i++] = digits[x % base];
3aa: 88 14 0b mov %dl,(%ebx,%ecx,1)
}while((x /= base) != 0);
3ad: 75 e9 jne 398 <printint+0x38>
if(neg)
3af: 8b 45 c4 mov -0x3c(%ebp),%eax
3b2: 8b 75 c0 mov -0x40(%ebp),%esi
3b5: 85 c0 test %eax,%eax
3b7: 74 08 je 3c1 <printint+0x61>
buf[i++] = '-';
3b9: c6 44 0d d8 2d movb $0x2d,-0x28(%ebp,%ecx,1)
3be: 8d 4f 02 lea 0x2(%edi),%ecx
3c1: 8d 7c 0d d7 lea -0x29(%ebp,%ecx,1),%edi
3c5: 8d 76 00 lea 0x0(%esi),%esi
3c8: 0f b6 07 movzbl (%edi),%eax
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
3cb: 83 ec 04 sub $0x4,%esp
3ce: 83 ef 01 sub $0x1,%edi
3d1: 6a 01 push $0x1
3d3: 53 push %ebx
3d4: 56 push %esi
3d5: 88 45 d7 mov %al,-0x29(%ebp)
3d8: e8 f5 fe ff ff call 2d2 <write>
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
3dd: 83 c4 10 add $0x10,%esp
3e0: 39 df cmp %ebx,%edi
3e2: 75 e4 jne 3c8 <printint+0x68>
putc(fd, buf[i]);
}
3e4: 8d 65 f4 lea -0xc(%ebp),%esp
3e7: 5b pop %ebx
3e8: 5e pop %esi
3e9: 5f pop %edi
3ea: 5d pop %ebp
3eb: c3 ret
3ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
} else {
x = xx;
3f0: 89 d0 mov %edx,%eax
static char digits[] = "0123456789ABCDEF";
char buf[16];
int i, neg;
uint x;
neg = 0;
3f2: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
3f9: eb 8b jmp 386 <printint+0x26>
3fb: 90 nop
3fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000400 <printf>:
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
400: 55 push %ebp
401: 89 e5 mov %esp,%ebp
403: 57 push %edi
404: 56 push %esi
405: 53 push %ebx
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
406: 8d 45 10 lea 0x10(%ebp),%eax
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
409: 83 ec 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
40c: 8b 75 0c mov 0xc(%ebp),%esi
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
40f: 8b 7d 08 mov 0x8(%ebp),%edi
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
412: 89 45 d0 mov %eax,-0x30(%ebp)
415: 0f b6 1e movzbl (%esi),%ebx
418: 83 c6 01 add $0x1,%esi
41b: 84 db test %bl,%bl
41d: 0f 84 b0 00 00 00 je 4d3 <printf+0xd3>
423: 31 d2 xor %edx,%edx
425: eb 39 jmp 460 <printf+0x60>
427: 89 f6 mov %esi,%esi
429: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
430: 83 f8 25 cmp $0x25,%eax
433: 89 55 d4 mov %edx,-0x2c(%ebp)
state = '%';
436: ba 25 00 00 00 mov $0x25,%edx
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
43b: 74 18 je 455 <printf+0x55>
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
43d: 8d 45 e2 lea -0x1e(%ebp),%eax
440: 83 ec 04 sub $0x4,%esp
443: 88 5d e2 mov %bl,-0x1e(%ebp)
446: 6a 01 push $0x1
448: 50 push %eax
449: 57 push %edi
44a: e8 83 fe ff ff call 2d2 <write>
44f: 8b 55 d4 mov -0x2c(%ebp),%edx
452: 83 c4 10 add $0x10,%esp
455: 83 c6 01 add $0x1,%esi
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
458: 0f b6 5e ff movzbl -0x1(%esi),%ebx
45c: 84 db test %bl,%bl
45e: 74 73 je 4d3 <printf+0xd3>
c = fmt[i] & 0xff;
if(state == 0){
460: 85 d2 test %edx,%edx
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
462: 0f be cb movsbl %bl,%ecx
465: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
468: 74 c6 je 430 <printf+0x30>
if(c == '%'){
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
46a: 83 fa 25 cmp $0x25,%edx
46d: 75 e6 jne 455 <printf+0x55>
if(c == 'd'){
46f: 83 f8 64 cmp $0x64,%eax
472: 0f 84 f8 00 00 00 je 570 <printf+0x170>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
478: 81 e1 f7 00 00 00 and $0xf7,%ecx
47e: 83 f9 70 cmp $0x70,%ecx
481: 74 5d je 4e0 <printf+0xe0>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
483: 83 f8 73 cmp $0x73,%eax
486: 0f 84 84 00 00 00 je 510 <printf+0x110>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
48c: 83 f8 63 cmp $0x63,%eax
48f: 0f 84 ea 00 00 00 je 57f <printf+0x17f>
putc(fd, *ap);
ap++;
} else if(c == '%'){
495: 83 f8 25 cmp $0x25,%eax
498: 0f 84 c2 00 00 00 je 560 <printf+0x160>
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
49e: 8d 45 e7 lea -0x19(%ebp),%eax
4a1: 83 ec 04 sub $0x4,%esp
4a4: c6 45 e7 25 movb $0x25,-0x19(%ebp)
4a8: 6a 01 push $0x1
4aa: 50 push %eax
4ab: 57 push %edi
4ac: e8 21 fe ff ff call 2d2 <write>
4b1: 83 c4 0c add $0xc,%esp
4b4: 8d 45 e6 lea -0x1a(%ebp),%eax
4b7: 88 5d e6 mov %bl,-0x1a(%ebp)
4ba: 6a 01 push $0x1
4bc: 50 push %eax
4bd: 57 push %edi
4be: 83 c6 01 add $0x1,%esi
4c1: e8 0c fe ff ff call 2d2 <write>
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
4c6: 0f b6 5e ff movzbl -0x1(%esi),%ebx
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
4ca: 83 c4 10 add $0x10,%esp
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
4cd: 31 d2 xor %edx,%edx
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
4cf: 84 db test %bl,%bl
4d1: 75 8d jne 460 <printf+0x60>
putc(fd, c);
}
state = 0;
}
}
}
4d3: 8d 65 f4 lea -0xc(%ebp),%esp
4d6: 5b pop %ebx
4d7: 5e pop %esi
4d8: 5f pop %edi
4d9: 5d pop %ebp
4da: c3 ret
4db: 90 nop
4dc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
4e0: 83 ec 0c sub $0xc,%esp
4e3: b9 10 00 00 00 mov $0x10,%ecx
4e8: 6a 00 push $0x0
4ea: 8b 5d d0 mov -0x30(%ebp),%ebx
4ed: 89 f8 mov %edi,%eax
4ef: 8b 13 mov (%ebx),%edx
4f1: e8 6a fe ff ff call 360 <printint>
ap++;
4f6: 89 d8 mov %ebx,%eax
4f8: 83 c4 10 add $0x10,%esp
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
4fb: 31 d2 xor %edx,%edx
if(c == 'd'){
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
ap++;
4fd: 83 c0 04 add $0x4,%eax
500: 89 45 d0 mov %eax,-0x30(%ebp)
503: e9 4d ff ff ff jmp 455 <printf+0x55>
508: 90 nop
509: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
} else if(c == 's'){
s = (char*)*ap;
510: 8b 45 d0 mov -0x30(%ebp),%eax
513: 8b 18 mov (%eax),%ebx
ap++;
515: 83 c0 04 add $0x4,%eax
518: 89 45 d0 mov %eax,-0x30(%ebp)
if(s == 0)
s = "(null)";
51b: b8 29 07 00 00 mov $0x729,%eax
520: 85 db test %ebx,%ebx
522: 0f 44 d8 cmove %eax,%ebx
while(*s != 0){
525: 0f b6 03 movzbl (%ebx),%eax
528: 84 c0 test %al,%al
52a: 74 23 je 54f <printf+0x14f>
52c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
530: 88 45 e3 mov %al,-0x1d(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
533: 8d 45 e3 lea -0x1d(%ebp),%eax
536: 83 ec 04 sub $0x4,%esp
539: 6a 01 push $0x1
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
53b: 83 c3 01 add $0x1,%ebx
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
53e: 50 push %eax
53f: 57 push %edi
540: e8 8d fd ff ff call 2d2 <write>
} else if(c == 's'){
s = (char*)*ap;
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
545: 0f b6 03 movzbl (%ebx),%eax
548: 83 c4 10 add $0x10,%esp
54b: 84 c0 test %al,%al
54d: 75 e1 jne 530 <printf+0x130>
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
54f: 31 d2 xor %edx,%edx
551: e9 ff fe ff ff jmp 455 <printf+0x55>
556: 8d 76 00 lea 0x0(%esi),%esi
559: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
560: 83 ec 04 sub $0x4,%esp
563: 88 5d e5 mov %bl,-0x1b(%ebp)
566: 8d 45 e5 lea -0x1b(%ebp),%eax
569: 6a 01 push $0x1
56b: e9 4c ff ff ff jmp 4bc <printf+0xbc>
} else {
putc(fd, c);
}
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
570: 83 ec 0c sub $0xc,%esp
573: b9 0a 00 00 00 mov $0xa,%ecx
578: 6a 01 push $0x1
57a: e9 6b ff ff ff jmp 4ea <printf+0xea>
57f: 8b 5d d0 mov -0x30(%ebp),%ebx
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
582: 83 ec 04 sub $0x4,%esp
585: 8b 03 mov (%ebx),%eax
587: 6a 01 push $0x1
589: 88 45 e4 mov %al,-0x1c(%ebp)
58c: 8d 45 e4 lea -0x1c(%ebp),%eax
58f: 50 push %eax
590: 57 push %edi
591: e8 3c fd ff ff call 2d2 <write>
596: e9 5b ff ff ff jmp 4f6 <printf+0xf6>
59b: 66 90 xchg %ax,%ax
59d: 66 90 xchg %ax,%ax
59f: 90 nop
000005a0 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
5a0: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5a1: a1 d4 09 00 00 mov 0x9d4,%eax
static Header base;
static Header *freep;
void
free(void *ap)
{
5a6: 89 e5 mov %esp,%ebp
5a8: 57 push %edi
5a9: 56 push %esi
5aa: 53 push %ebx
5ab: 8b 5d 08 mov 0x8(%ebp),%ebx
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5ae: 8b 10 mov (%eax),%edx
void
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
5b0: 8d 4b f8 lea -0x8(%ebx),%ecx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5b3: 39 c8 cmp %ecx,%eax
5b5: 73 19 jae 5d0 <free+0x30>
5b7: 89 f6 mov %esi,%esi
5b9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
5c0: 39 d1 cmp %edx,%ecx
5c2: 72 1c jb 5e0 <free+0x40>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5c4: 39 d0 cmp %edx,%eax
5c6: 73 18 jae 5e0 <free+0x40>
static Header base;
static Header *freep;
void
free(void *ap)
{
5c8: 89 d0 mov %edx,%eax
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5ca: 39 c8 cmp %ecx,%eax
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5cc: 8b 10 mov (%eax),%edx
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
5ce: 72 f0 jb 5c0 <free+0x20>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
5d0: 39 d0 cmp %edx,%eax
5d2: 72 f4 jb 5c8 <free+0x28>
5d4: 39 d1 cmp %edx,%ecx
5d6: 73 f0 jae 5c8 <free+0x28>
5d8: 90 nop
5d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
break;
if(bp + bp->s.size == p->s.ptr){
5e0: 8b 73 fc mov -0x4(%ebx),%esi
5e3: 8d 3c f1 lea (%ecx,%esi,8),%edi
5e6: 39 d7 cmp %edx,%edi
5e8: 74 19 je 603 <free+0x63>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
5ea: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
5ed: 8b 50 04 mov 0x4(%eax),%edx
5f0: 8d 34 d0 lea (%eax,%edx,8),%esi
5f3: 39 f1 cmp %esi,%ecx
5f5: 74 23 je 61a <free+0x7a>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
5f7: 89 08 mov %ecx,(%eax)
freep = p;
5f9: a3 d4 09 00 00 mov %eax,0x9d4
}
5fe: 5b pop %ebx
5ff: 5e pop %esi
600: 5f pop %edi
601: 5d pop %ebp
602: c3 ret
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
break;
if(bp + bp->s.size == p->s.ptr){
bp->s.size += p->s.ptr->s.size;
603: 03 72 04 add 0x4(%edx),%esi
606: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
609: 8b 10 mov (%eax),%edx
60b: 8b 12 mov (%edx),%edx
60d: 89 53 f8 mov %edx,-0x8(%ebx)
} else
bp->s.ptr = p->s.ptr;
if(p + p->s.size == bp){
610: 8b 50 04 mov 0x4(%eax),%edx
613: 8d 34 d0 lea (%eax,%edx,8),%esi
616: 39 f1 cmp %esi,%ecx
618: 75 dd jne 5f7 <free+0x57>
p->s.size += bp->s.size;
61a: 03 53 fc add -0x4(%ebx),%edx
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
freep = p;
61d: a3 d4 09 00 00 mov %eax,0x9d4
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
if(p + p->s.size == bp){
p->s.size += bp->s.size;
622: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
625: 8b 53 f8 mov -0x8(%ebx),%edx
628: 89 10 mov %edx,(%eax)
} else
p->s.ptr = bp;
freep = p;
}
62a: 5b pop %ebx
62b: 5e pop %esi
62c: 5f pop %edi
62d: 5d pop %ebp
62e: c3 ret
62f: 90 nop
00000630 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
630: 55 push %ebp
631: 89 e5 mov %esp,%ebp
633: 57 push %edi
634: 56 push %esi
635: 53 push %ebx
636: 83 ec 0c sub $0xc,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
639: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
63c: 8b 15 d4 09 00 00 mov 0x9d4,%edx
malloc(uint nbytes)
{
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
642: 8d 78 07 lea 0x7(%eax),%edi
645: c1 ef 03 shr $0x3,%edi
648: 83 c7 01 add $0x1,%edi
if((prevp = freep) == 0){
64b: 85 d2 test %edx,%edx
64d: 0f 84 a3 00 00 00 je 6f6 <malloc+0xc6>
653: 8b 02 mov (%edx),%eax
655: 8b 48 04 mov 0x4(%eax),%ecx
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
658: 39 cf cmp %ecx,%edi
65a: 76 74 jbe 6d0 <malloc+0xa0>
65c: 81 ff 00 10 00 00 cmp $0x1000,%edi
662: be 00 10 00 00 mov $0x1000,%esi
667: 8d 1c fd 00 00 00 00 lea 0x0(,%edi,8),%ebx
66e: 0f 43 f7 cmovae %edi,%esi
671: ba 00 80 00 00 mov $0x8000,%edx
676: 81 ff ff 0f 00 00 cmp $0xfff,%edi
67c: 0f 46 da cmovbe %edx,%ebx
67f: eb 10 jmp 691 <malloc+0x61>
681: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
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){
688: 8b 02 mov (%edx),%eax
if(p->s.size >= nunits){
68a: 8b 48 04 mov 0x4(%eax),%ecx
68d: 39 cf cmp %ecx,%edi
68f: 76 3f jbe 6d0 <malloc+0xa0>
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
691: 39 05 d4 09 00 00 cmp %eax,0x9d4
697: 89 c2 mov %eax,%edx
699: 75 ed jne 688 <malloc+0x58>
char *p;
Header *hp;
if(nu < 4096)
nu = 4096;
p = sbrk(nu * sizeof(Header));
69b: 83 ec 0c sub $0xc,%esp
69e: 53 push %ebx
69f: e8 96 fc ff ff call 33a <sbrk>
if(p == (char*)-1)
6a4: 83 c4 10 add $0x10,%esp
6a7: 83 f8 ff cmp $0xffffffff,%eax
6aa: 74 1c je 6c8 <malloc+0x98>
return 0;
hp = (Header*)p;
hp->s.size = nu;
6ac: 89 70 04 mov %esi,0x4(%eax)
free((void*)(hp + 1));
6af: 83 ec 0c sub $0xc,%esp
6b2: 83 c0 08 add $0x8,%eax
6b5: 50 push %eax
6b6: e8 e5 fe ff ff call 5a0 <free>
return freep;
6bb: 8b 15 d4 09 00 00 mov 0x9d4,%edx
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
if((p = morecore(nunits)) == 0)
6c1: 83 c4 10 add $0x10,%esp
6c4: 85 d2 test %edx,%edx
6c6: 75 c0 jne 688 <malloc+0x58>
return 0;
6c8: 31 c0 xor %eax,%eax
6ca: eb 1c jmp 6e8 <malloc+0xb8>
6cc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
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){
if(p->s.size == nunits)
6d0: 39 cf cmp %ecx,%edi
6d2: 74 1c je 6f0 <malloc+0xc0>
prevp->s.ptr = p->s.ptr;
else {
p->s.size -= nunits;
6d4: 29 f9 sub %edi,%ecx
6d6: 89 48 04 mov %ecx,0x4(%eax)
p += p->s.size;
6d9: 8d 04 c8 lea (%eax,%ecx,8),%eax
p->s.size = nunits;
6dc: 89 78 04 mov %edi,0x4(%eax)
}
freep = prevp;
6df: 89 15 d4 09 00 00 mov %edx,0x9d4
return (void*)(p + 1);
6e5: 83 c0 08 add $0x8,%eax
}
if(p == freep)
if((p = morecore(nunits)) == 0)
return 0;
}
}
6e8: 8d 65 f4 lea -0xc(%ebp),%esp
6eb: 5b pop %ebx
6ec: 5e pop %esi
6ed: 5f pop %edi
6ee: 5d pop %ebp
6ef: c3 ret
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
if(p->s.size == nunits)
prevp->s.ptr = p->s.ptr;
6f0: 8b 08 mov (%eax),%ecx
6f2: 89 0a mov %ecx,(%edx)
6f4: eb e9 jmp 6df <malloc+0xaf>
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
6f6: c7 05 d4 09 00 00 d8 movl $0x9d8,0x9d4
6fd: 09 00 00
700: c7 05 d8 09 00 00 d8 movl $0x9d8,0x9d8
707: 09 00 00
base.s.size = 0;
70a: b8 d8 09 00 00 mov $0x9d8,%eax
70f: c7 05 dc 09 00 00 00 movl $0x0,0x9dc
716: 00 00 00
719: e9 3e ff ff ff jmp 65c <malloc+0x2c>
|
; A032613: Concatenation of n and n + 8 or {n,n+8}.
; 19,210,311,412,513,614,715,816,917,1018,1119,1220,1321,1422,1523,1624,1725,1826,1927,2028,2129,2230,2331,2432,2533,2634,2735,2836,2937,3038,3139,3240,3341,3442,3543,3644,3745,3846,3947,4048,4149
pow $1,$0
gcd $1,2
mul $1,90
sub $1,71
mov $2,$0
mul $2,101
add $1,$2
mov $0,$1
|
;******************************************************************
;xtone - 6ch beeper engine
;by utz 09'2015
;******************************************************************
org #8000
di
init
ei ;detect kempston
halt
in a,(#1f)
inc a
jr nz,_skip
ld (maskKempston),a
_skip
di
exx
push hl ;preserve HL' for return to BASIC
ld iyl,0
ld (oldSP),sp
ld hl,musicdata
ld (seqpntr),hl
;******************************************************************
rdseq
seqpntr equ $+1
ld sp,0
xor a
pop hl ;pattern pointer to HL
or h
ld (seqpntr),sp
jr nz,rdptn0
;jp exit ;uncomment to disable looping
ld sp,loop ;get loop point
jr rdseq+3
;******************************************************************
rdptn0
ld sp,hl
rdptn
in a,(#1f) ;read joystick
maskKempston equ $+1
and #1f
ld c,a
in a,(#fe) ;read kbd
cpl
or c
and #1f
jp nz,exit
pop af
jr z,rdseq
ld iyh,a ;IY = timer
jp c,drums
drumret
ld l,#f0
pop de
ld a,d
and l
ld (duty1),a
ld a,d
add a,a
add a,a
add a,a
add a,a
ld (duty2),a
ld a,e
and l
ld (duty3),a
ld a,e
add a,a
add a,a
add a,a
add a,a
ld (duty4),a
pop de
ld a,d
ld (duty5),a
ld a,e
ld (duty6),a
ld (fstack),sp ;pattern data serves as buffer for loading freq. values during play loop
ld bc,#18fe
ld d,b
ld e,b
ld h,b
ld l,b
exx
ld bc,#18fe
ld hl,0
ld (cnt1),hl
ld (cnt2),hl
ld (cnt3),hl
ld (cnt4),hl
ld (cnt5),hl
ld (cnt6),hl
jp play
;****************************************frame6end
out (c),h ;12
;-34
exx ;4
play
;****************************************frame1
cnt1 equ $+1
ld hl,0 ;10
pop de ;10
out (c),b ;12
;-32 (+exx -36)
add hl,de ;11
dec de ;6 ;waste some time
ld a,h ;4
exx ;4
out (c),b ;12
;-37
exx ;4
ld (cnt1),hl ;16
exx ;4
out (c),d ;12
;-36
exx ;4
duty1 equ $+1
cp #80 ;7
sbc a,a ;4
and #18 ;7
exx ;4
out (c),e ;12
;-38
exx ;4
ld b,a ;4
exx ;4
ld a,r ;9
out (c),l ;12
;-35
ld a,r ;9 ;waste 18t for dec iyl, jp nz, play-3 resp ld sp,xxxx
ld a,r ;9
nop ;4
out (c),h ;12
;-34
exx ;4
;216
;****************************************frame2
cnt2 equ $+1
ld hl,0 ;10
pop de ;10
out (c),b ;12
;-32 (+exx -36)
add hl,de ;11
dec de
ld a,h ;4
exx ;4
out (c),b ;12
;-31
exx ;4
ld (cnt2),hl ;16
exx ;4
out (c),d ;12
;-36
exx ;4
duty2 equ $+1
cp #80 ;7
sbc a,a ;4
and #18 ;7
exx ;4
out (c),e ;12
;-38
nop ;4
nop ;4
ld b,a ;4
ld a,r ;9
out (c),l ;12
;-33
ld a,r ;9 ;waste 18t for dec iyl, jp nz, play-3 resp ld sp,xxxx
ld a,r ;9
nop
out (c),h ;12
;-34
exx ;4
;****************************************frame3
cnt3 equ $+1
ld hl,0 ;10
pop de ;10
out (c),b ;12
;-32 (+exx -36)
add hl,de ;11
dec de
ld a,h ;4
exx ;4
out (c),b ;12
;-31
exx ;4
ld (cnt3),hl ;16
exx ;4
out (c),d ;12
;-36
exx ;4
duty3 equ $+1
cp #80 ;7
sbc a,a ;4
and #18 ;7
exx ;4
out (c),e ;12
;-38
nop ;4
nop ;4
ld d,a ;4
ld a,r ;9
out (c),l ;12
;-33
ld a,r ;9 ;waste 18t for dec iyl, jp nz, play-3 resp ld sp,xxxx
ld a,r ;9
nop
out (c),h ;12
;-34
exx ;4
;****************************************frame4
cnt4 equ $+1
ld hl,0 ;10
pop de ;10
out (c),b ;12
;-32 (+exx -36)
add hl,de ;11
dec de
ld a,h ;4
exx ;4
out (c),b ;12
;-31
exx ;4
ld (cnt4),hl ;16
exx ;4
out (c),d ;12
;-36
exx ;4
duty4 equ $+1
cp #80 ;7
sbc a,a ;4
and #18 ;7
exx ;4
out (c),e ;12
;-38
dec iyl ;8
ld e,a ;4
ld a,r ;9
out (c),l ;12
;-33
ld a,r ;9 ;waste 18t for dec iyl, jp nz, play-3 resp ld sp,xxxx
ld a,r ;9
nop
out (c),h ;12
;-34
exx ;4
;****************************************frame5
cnt5 equ $+1
ld hl,0 ;10
pop de ;10
out (c),b ;12
;-32 (+exx -36)
add hl,de ;11
dec de
ld a,h ;4
exx ;4
out (c),b ;12
;-31
exx ;4
ld (cnt5),hl ;16
exx ;4
out (c),d ;12
;-36
exx ;4
duty5 equ $+1
cp #80 ;7
sbc a,a ;4
and #18 ;7
exx ;4
out (c),e ;12
;-38
dec iyl ;8
ld h,a ;4
ld a,r ;9
out (c),l ;12
;-33
ld a,r ;9 ;waste 18t for dec iyl, jp nz, play-3 resp ld sp,xxxx
ld a,r ;9
nop
out (c),h ;12
;-34
exx ;4
;****************************************frame6
cnt6 equ $+1
ld hl,0 ;10
pop de ;10
out (c),b ;12
;-32 (+exx -36)
add hl,de ;11
dec de
ld a,h ;4
exx ;4
out (c),b ;12
;-31
exx ;4
ld (cnt6),hl ;16
exx ;4
out (c),d ;12
;-36
exx ;4
duty6 equ $+1
cp #80 ;7
sbc a,a ;4
and #18 ;7
exx ;4
out (c),e ;12
;-38
dec iyl ;8
ld l,a ;4
fstack equ $+1
ld sp,0 ;10 ;reload frequency pointer
out (#fe),a ;11
;-35
dec iyl ;8
nop
jp nz,play-3 ;10
dec iyh
jp nz,play-3
ld hl,12
add hl,sp
;ld sp,hl
jp rdptn0
;******************************************************************
exit
xor a
out (#fe),a
oldSP equ $+1
ld sp,0
pop hl
exx
ei
ret
;******************************************************************
drums
jp pe,drum2
jp m,drum3
drum1 ;k(l)ick
xor a ;1
ld b,a ;1
ld c,a ;1
_druml
out (#fe),a ;2
djnz _druml ;2
ld b,#20 ;2 ;b = length, ~ #2-#20 but if bit 4 not set then must use
xor #10 ;1 ;xor #10/#18 ;2
_xx
inc c ;1 ;dec c is also possible for different sound
jr z,dx ;1
djnz _xx ;2
ld b,c ;1
jr _druml ;2
drum2 ;noise, self-contained, customizable ***
ld de,#7710 ;3 ;d = frequency
xor a ;1
ld bc,#d0 ;3 ;bc = length
_druml
out (#fe),a ;2 ;11
add hl,de ;1 ;11
jr nc,_yy ;2 ;12/7
xor e ;1 ;4
_yy
rlc h ;2 ;8
cpi ;2 ;16
jp pe,_druml
dx
ld ixl,#a0
jp drumret
drum3
ld de,#5510
jr drum2+3
musicdata
include "music.asm"
|
; A048050: Chowla's function: sum of divisors of n except 1 and n.
; 0,0,0,2,0,5,0,6,3,7,0,15,0,9,8,14,0,20,0,21,10,13,0,35,5,15,12,27,0,41,0,30,14,19,12,54,0,21,16,49,0,53,0,39,32,25,0,75,7,42,20,45,0,65,16,63,22,31,0,107,0,33,40,62,18,77,0,57,26,73,0,122,0,39,48,63,18,89,0,105,39,43,0,139,22,45,32,91,0,143,20,75,34,49,24,155,0,72,56,116,0,113,0,105,86,55,0,171,0,105,40,135,0,125,28,93,64,61,24,239,11,63,44,99,30,185,0,126,46,121,0,203,26,69,104,133,0,149,0,195,50,73,24,258,34,75,80,117,0,221,0,147,80,133,36,235,0,81,56,217,30,200,0,129,122,85,0,311,13,153,88,135,0,185,72,195,62,91,0,365,0,153,64,175,42,197,28,147,130,169,0,315,0,99,140,202,0,269,0,264,70,103,36,299,46,105,104,225,30,365,0,165,74,109,48,383,38,111,76,283,30,233,0,279,177,115,0,331,0,201,152,217,0,311,52,183,82,193,0,503,0,156,120,189,96,257,32,231,86,217
mov $3,2
mov $5,$0
lpb $3
mov $0,$5
sub $3,1
add $0,$3
sub $0,1
cal $0,244049 ; Sum of all proper divisors of all positive integers <= n.
mov $2,$3
mov $4,$0
mul $4,2
mov $6,$4
lpb $2
mov $1,$6
sub $2,1
lpe
lpe
lpb $5
sub $1,$6
mov $5,0
lpe
div $1,2
|
/*
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
#include <aws/config/model/DeleteEvaluationResultsRequest.h>
#include <aws/core/utils/json/JsonSerializer.h>
#include <utility>
using namespace Aws::ConfigService::Model;
using namespace Aws::Utils::Json;
using namespace Aws::Utils;
DeleteEvaluationResultsRequest::DeleteEvaluationResultsRequest() :
m_configRuleNameHasBeenSet(false)
{
}
Aws::String DeleteEvaluationResultsRequest::SerializePayload() const
{
JsonValue payload;
if(m_configRuleNameHasBeenSet)
{
payload.WithString("ConfigRuleName", m_configRuleName);
}
return payload.View().WriteReadable();
}
Aws::Http::HeaderValueCollection DeleteEvaluationResultsRequest::GetRequestSpecificHeaders() const
{
Aws::Http::HeaderValueCollection headers;
headers.insert(Aws::Http::HeaderValuePair("X-Amz-Target", "StarlingDoveService.DeleteEvaluationResults"));
return headers;
}
|
; A218748: a(n) = (45^n-1)/44.
; 0,1,46,2071,93196,4193821,188721946,8492487571,382161940696,17197287331321,773877929909446,34824506845925071,1567102808066628196,70519626362998268821,3173383186334922096946,142802243385071494362571,6426100952328217246315696,289174542854769776084206321,13012854428464639923789284446,585578449280908796570517800071,26351030217640895845673301003196,1185796359793840313055298545143821,53360836190722814087488434531471946,2401237628582526633936979553916237571,108055693286213698527164079926230690696
mov $1,45
pow $1,$0
div $1,44
mov $0,$1
|
; A021189: Decimal expansion of 1/185.
; 0,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5,4,0,5
mul $0,8
sub $0,1
cal $0,21226 ; Decimal expansion of 1/222.
mov $1,$0
|
MODULE UrlEncoder
; HL - pointer to line in gopher page
; C - flag set when it's file
isFile:
.findServerLoop
ld a, (hl) : and a : jr z, .notFile : inc hl
cp 13 : jr z, .notFile
cp 9 : jr z, .skipPath
jr .findServerLoop
.skipPath
ld a, (hl) : and a : jr z, .notFile : inc hl
cp 13 : jr z, .notFile
cp 9 : jr z, .compareServer
jr .skipPath
.compareServer
ld a, (hl) : cp "f" : jr nz, .notFile : inc hl
ld a, (hl) : cp "i" : jr nz, .notFile : inc hl
ld a, (hl) : cp "l" : jr nz, .notFile : inc hl
ld a, (hl) : cp "e" : jr nz, .notFile : inc hl
ld a, (hl) : cp 9 : jr nz, .notFile : inc hl
ld a, 1
ret
.notFile
xor a
ret
; Is enough fields to encode
; HL - pointer to line in gopher page
; C - flag set when there is enough fields
isValidGopherRow:
ld a, (hl) : and a : jr z, isFile.notFile : inc hl
cp 13 : jr z, isFile.notFile
cp 9 : jr z, .skipPath
jr isValidGopherRow
.skipPath
ld a, (hl) : and a : jr z, isFile.notFile : inc hl
cp 13 : jr z, isFile.notFile
cp 9 : jr z, .skipHost
jr .skipPath
.skipHost
ld a, (hl) : and a : jr z, isFile.notFile : inc hl
cp 13 : jr z, isFile.notFile
cp 9 : jr z, .isValid
jr .skipHost
.isValid:
scf
ret
extractPath:
ld hl, historyBlock.locator, de, nameBuffer, bc, #ff : ldir
ret
extractHostName:
ld hl, historyBlock.host, de, hostName, bc, 64 : ldir
ret
ENDMODULE
nameBuffer ds #ff, 0
db 0
hostName ds 64 |
icl '../os/symbols.asm'
org BOOTADDR
lda #1
sta ROS7
lda #0
ldx #OS_SET_VIDEO_MODE
jsr OS_CALL
mwa SUBPAL_START VRAM_TO_RAM
jsr lib_vram_to_ram
; use first 16 entries as subpal
ldy #0
set_subpal:
tya
sta (RAM_TO_VRAM), y
iny
cpy #16
bne set_subpal
; reset all attributes to $0F
mwa ATTRIB_START VRAM_TO_RAM
jsr lib_vram_to_ram
mwa RAM_TO_VRAM DST_ADDR
mwa SCREEN_SIZE SIZE
lda #$0F
jsr lib_vram_set_bytes
; copy test attrbutes
mwa ATTRIB_START VRAM_TO_RAM
jsr lib_vram_to_ram
ldy #0
copy_attribs:
lda attribs, y
beq display_message
sta (RAM_TO_VRAM), y
iny
bne copy_attribs
display_message:
mwa DISPLAY_START VRAM_TO_RAM
jsr lib_vram_to_ram
ldy #0
copy:
lda message, y
cmp #255
beq stop
sta (RAM_TO_VRAM), y
iny
bne copy
stop:
jmp stop
message:
.byte 40, 101, 108, 108, 111, 0, 55, 111, 114, 108, 100, 1, 1, 1, 1, 255
attribs:
.byte $0F, $01, $1E, $E1, $01, $02, $03, $04, $21, $22, $23, $24
.byte $1F, $2F, $3F, $4F, $5F, $00
icl '../os/stdlib.asm'
|
;
;
; Z88 Maths Routines
;
; C Interface for Small C+ Compiler
;
; 7/12/98 djm
;double tan(double)
;Number in FA..
INCLUDE "fpp.def"
XLIB tan
LIB fsetup
LIB stkequ2
.tan
call fsetup
fpp(FP_TAN)
jp stkequ2
|
; A136516: a(n) = (2^n+1)^n.
; 1,3,25,729,83521,39135393,75418890625,594467302491009,19031147999601100801,2460686496619787545743873,1280084544196357822418212890625,2672769719437237714909813214827010049,22366167213460480200139104627873703828439041,749477178512218249053016816019761862837541531656193,100519481571931211181172992296376877622903548859918212890625,53944581176123904718549937206478637080114505064862207097263020802049,115820362025776631693689603365018915167340735378361777628776982500522972938241
mov $1,2
pow $1,$0
add $1,1
pow $1,$0
mov $0,$1
|
; Arquivo: Pow.nasm
; Curso: Elementos de Sistemas
; Criado por: Luciano Soares
; Data: 27/03/2017
; Eleva ao quadrado o valor da RAM[1] e armazena o resultado na RAM[0].
; Só funciona com números positivos
leaw $1, %A
movw (%A), %D
leaw $2, %A
movw %D, (%A)
leaw $0, %A
movw %D, (%A)
leaw $2, %A
movw (%A), %D
decw %D
movw %D, (%A)
LOOP:
leaw $1, %A
movw (%A), %D
leaw $0, %A
addw (%A), %D, %D
movw %D, (%A)
leaw $2, %A
movw (%A), %D
decw %D
movw %D, (%A)
leaw $LOOP, (%A)
jg
nop |
; Listing generated by Microsoft (R) Optimizing Compiler Version 19.24.28117.0
TITLE C:\Users\libit\source\repos\L025\L025\L025.cpp
.686P
.XMM
include listing.inc
.model flat
INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES
CONST SEGMENT
$SG5557 DB '1,2,7,10', 00H
ORG $+3
$SG5559 DB '3', 0a1H, 0a2H, '4', 0a1H, 0a2H, '100', 00H
ORG $+2
$SG5561 DB '5,6', 00H
$SG5563 DB '8', 0a1H, 0a2H, '9', 0a1H, 0a2H, '20', 0a1H, 0a2H, '21', 00H
ORG $+3
$SG5565 DB '22', 00H
ORG $+1
$SG5567 DB 'default', 00H
$SG5570 DB 'Hello World!', 0aH, 00H
CONST ENDS
PUBLIC ___local_stdio_printf_options
PUBLIC __vfprintf_l
PUBLIC _printf
PUBLIC ?f@@YAXH@Z ; f
PUBLIC _main
PUBLIC ?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA ; `__local_stdio_printf_options'::`2'::_OptionsStorage
EXTRN ___acrt_iob_func:PROC
EXTRN ___stdio_common_vfprintf:PROC
; COMDAT ?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA
_BSS SEGMENT
?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA DQ 01H DUP (?) ; `__local_stdio_printf_options'::`2'::_OptionsStorage
_BSS ENDS
; Function compile flags: /Ogtpy
_TEXT SEGMENT
_main PROC
; File C:\Users\libit\source\repos\L025\L025\L025.cpp
; Line 42
push OFFSET $SG5570
call _printf
; Line 44
push OFFSET $SG5557
call _printf
add esp, 8
xor eax, eax
ret 0
_main ENDP
_TEXT ENDS
; Function compile flags: /Ogtpy
_TEXT SEGMENT
_a$ = 8 ; size = 4
?f@@YAXH@Z PROC ; f
; File C:\Users\libit\source\repos\L025\L025\L025.cpp
; Line 8
mov eax, DWORD PTR _a$[esp-4]
dec eax
cmp eax, 99 ; 00000063H
ja SHORT $LN9@f
movzx eax, BYTE PTR $LN11@f[eax]
jmp DWORD PTR $LN12@f[eax*4]
$LN4@f:
; Line 14
mov eax, OFFSET $SG5557
; Line 38
mov DWORD PTR _a$[esp-4], eax
jmp _printf
$LN5@f:
; Line 19
mov eax, OFFSET $SG5559
; Line 38
mov DWORD PTR _a$[esp-4], eax
jmp _printf
$LN6@f:
; Line 23
mov eax, OFFSET $SG5561
; Line 38
mov DWORD PTR _a$[esp-4], eax
jmp _printf
$LN7@f:
; Line 29
mov eax, OFFSET $SG5563
; Line 38
mov DWORD PTR _a$[esp-4], eax
jmp _printf
$LN8@f:
; Line 32
mov eax, OFFSET $SG5565
; Line 38
mov DWORD PTR _a$[esp-4], eax
jmp _printf
$LN9@f:
; Line 35
mov eax, OFFSET $SG5567
; Line 38
mov DWORD PTR _a$[esp-4], eax
jmp _printf
$LN12@f:
DD $LN4@f
DD $LN5@f
DD $LN6@f
DD $LN7@f
DD $LN8@f
DD $LN9@f
$LN11@f:
DB 0
DB 0
DB 1
DB 1
DB 2
DB 2
DB 0
DB 3
DB 3
DB 0
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 3
DB 3
DB 4
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 5
DB 1
?f@@YAXH@Z ENDP ; f
_TEXT ENDS
; Function compile flags: /Ogtpy
; COMDAT _printf
_TEXT SEGMENT
__Format$ = 8 ; size = 4
_printf PROC ; COMDAT
; File C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\stdio.h
; Line 954
push esi
; Line 958
mov esi, DWORD PTR __Format$[esp]
push 1
call ___acrt_iob_func
add esp, 4
; Line 643
lea ecx, DWORD PTR __Format$[esp+4]
push ecx
push 0
push esi
push eax
call ___local_stdio_printf_options
push DWORD PTR [eax+4]
push DWORD PTR [eax]
call ___stdio_common_vfprintf
add esp, 24 ; 00000018H
; Line 960
pop esi
; Line 961
ret 0
_printf ENDP
_TEXT ENDS
; Function compile flags: /Ogtpy
; COMDAT __vfprintf_l
_TEXT SEGMENT
__Stream$ = 8 ; size = 4
__Format$ = 12 ; size = 4
__Locale$ = 16 ; size = 4
__ArgList$ = 20 ; size = 4
__vfprintf_l PROC ; COMDAT
; File C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\stdio.h
; Line 643
push DWORD PTR __ArgList$[esp-4]
push DWORD PTR __Locale$[esp]
push DWORD PTR __Format$[esp+4]
push DWORD PTR __Stream$[esp+8]
call ___local_stdio_printf_options
push DWORD PTR [eax+4]
push DWORD PTR [eax]
call ___stdio_common_vfprintf
add esp, 24 ; 00000018H
; Line 644
ret 0
__vfprintf_l ENDP
_TEXT ENDS
; Function compile flags: /Ogtpy
; COMDAT ___local_stdio_printf_options
_TEXT SEGMENT
___local_stdio_printf_options PROC ; COMDAT
; File C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt\corecrt_stdio_config.h
; Line 88
mov eax, OFFSET ?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA ; `__local_stdio_printf_options'::`2'::_OptionsStorage
; Line 89
ret 0
___local_stdio_printf_options ENDP
_TEXT ENDS
END
|
; ----------------------------------------------------------------------------------------
; Writes "Hello, World" to the console using only system calls. Runs on 64-bit Linux only.
; To assemble and run:
;
; nasm -felf64 hello.asm && ld hello.o && ./a.out
; ----------------------------------------------------------------------------------------
section .text
global _start
_start: mov rax, 1 ; system call for write
mov rdi, 1 ; file handle 1 is stdout
mov rsi, message ; address of string to output
mov rdx, 13 ; number of bytes
syscall ; invoke operating system to do the write
mov rax, 60 ; system call for exit
xor rdi, rdi ; exit code 0
syscall ; invoke operating system to exit
section .data
message: db "Hello, World", 10 ; note the newline at the end
|
; A048703: Numbers which in base 4 are palindromes and have an even number of digits.
; 0,5,10,15,65,85,105,125,130,150,170,190,195,215,235,255,1025,1105,1185,1265,1285,1365,1445,1525,1545,1625,1705,1785,1805,1885,1965,2045,2050,2130,2210,2290,2310,2390,2470,2550,2570,2650,2730,2810,2830,2910,2990,3070,3075,3155,3235,3315,3335,3415,3495,3575,3595,3675,3755,3835,3855,3935,4015,4095,16385,16705,17025,17345,17425,17745,18065,18385,18465,18785,19105,19425,19505,19825,20145,20465,20485,20805,21125,21445,21525,21845,22165,22485,22565,22885,23205,23525,23605,23925,24245,24565,24585,24905,25225,25545,25625,25945,26265,26585,26665,26985,27305,27625,27705,28025,28345,28665,28685,29005,29325,29645,29725,30045,30365,30685,30765,31085,31405,31725,31805,32125,32445,32765,32770,33090,33410,33730,33810,34130,34450,34770,34850,35170,35490,35810,35890,36210,36530,36850,36870,37190,37510,37830,37910,38230,38550,38870,38950,39270,39590,39910,39990,40310,40630,40950,40970,41290,41610,41930,42010,42330,42650,42970,43050,43370,43690,44010,44090,44410,44730,45050,45070,45390,45710,46030,46110,46430,46750,47070,47150,47470,47790,48110,48190,48510,48830,49150,49155,49475,49795,50115,50195,50515,50835,51155,51235,51555,51875,52195,52275,52595,52915,53235,53255,53575,53895,54215,54295,54615,54935,55255,55335,55655,55975,56295,56375,56695,57015,57335,57355,57675,57995,58315,58395,58715,59035,59355,59435,59755,60075,60395,60475,60795,61115,61435,61455,61775,62095,62415,62495,62815,63135,63455,63535,63855
lpb $0,1
trn $1,$0
mul $1,4
mov $2,$0
mul $0,2
div $0,8
add $1,$2
lpe
mul $1,5
|
; A158546: a(n) = 144*n^2 + 12.
; 12,156,588,1308,2316,3612,5196,7068,9228,11676,14412,17436,20748,24348,28236,32412,36876,41628,46668,51996,57612,63516,69708,76188,82956,90012,97356,104988,112908,121116,129612,138396,147468,156828,166476,176412,186636,197148,207948,219036,230412,242076,254028,266268,278796,291612,304716,318108,331788,345756,360012,374556,389388,404508,419916,435612,451596,467868,484428,501276,518412,535836,553548,571548,589836,608412,627276,646428,665868,685596,705612,725916,746508,767388,788556,810012,831756,853788,876108,898716,921612,944796,968268,992028,1016076,1040412,1065036,1089948,1115148,1140636,1166412,1192476,1218828,1245468,1272396,1299612,1327116,1354908,1382988,1411356
pow $0,2
mul $0,144
add $0,12
|
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/audio_coding/neteq/test/result_sink.h"
#include <string>
#include "absl/strings/string_view.h"
#include "rtc_base/ignore_wundef.h"
#include "rtc_base/message_digest.h"
#include "rtc_base/string_encode.h"
#include "test/gtest.h"
#ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT
RTC_PUSH_IGNORING_WUNDEF()
#ifdef WEBRTC_ANDROID_PLATFORM_BUILD
#include "external/webrtc/webrtc/modules/audio_coding/neteq/neteq_unittest.pb.h"
#else
#include "modules/audio_coding/neteq/neteq_unittest.pb.h"
#endif
RTC_POP_IGNORING_WUNDEF()
#endif
namespace webrtc {
#ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT
void Convert(const webrtc::NetEqNetworkStatistics& stats_raw,
webrtc::neteq_unittest::NetEqNetworkStatistics* stats) {
stats->set_current_buffer_size_ms(stats_raw.current_buffer_size_ms);
stats->set_preferred_buffer_size_ms(stats_raw.preferred_buffer_size_ms);
stats->set_jitter_peaks_found(stats_raw.jitter_peaks_found);
stats->set_expand_rate(stats_raw.expand_rate);
stats->set_speech_expand_rate(stats_raw.speech_expand_rate);
stats->set_preemptive_rate(stats_raw.preemptive_rate);
stats->set_accelerate_rate(stats_raw.accelerate_rate);
stats->set_secondary_decoded_rate(stats_raw.secondary_decoded_rate);
stats->set_secondary_discarded_rate(stats_raw.secondary_discarded_rate);
stats->set_mean_waiting_time_ms(stats_raw.mean_waiting_time_ms);
stats->set_median_waiting_time_ms(stats_raw.median_waiting_time_ms);
stats->set_min_waiting_time_ms(stats_raw.min_waiting_time_ms);
stats->set_max_waiting_time_ms(stats_raw.max_waiting_time_ms);
}
void AddMessage(FILE* file,
rtc::MessageDigest* digest,
const std::string& message) {
int32_t size = message.length();
if (file)
ASSERT_EQ(1u, fwrite(&size, sizeof(size), 1, file));
digest->Update(&size, sizeof(size));
if (file)
ASSERT_EQ(static_cast<size_t>(size),
fwrite(message.data(), sizeof(char), size, file));
digest->Update(message.data(), sizeof(char) * size);
}
#endif // WEBRTC_NETEQ_UNITTEST_BITEXACT
ResultSink::ResultSink(const std::string& output_file)
: output_fp_(nullptr),
digest_(rtc::MessageDigestFactory::Create(rtc::DIGEST_SHA_1)) {
if (!output_file.empty()) {
output_fp_ = fopen(output_file.c_str(), "wb");
EXPECT_TRUE(output_fp_ != NULL);
}
}
ResultSink::~ResultSink() {
if (output_fp_)
fclose(output_fp_);
}
void ResultSink::AddResult(const NetEqNetworkStatistics& stats_raw) {
#ifdef WEBRTC_NETEQ_UNITTEST_BITEXACT
neteq_unittest::NetEqNetworkStatistics stats;
Convert(stats_raw, &stats);
std::string stats_string;
ASSERT_TRUE(stats.SerializeToString(&stats_string));
AddMessage(output_fp_, digest_.get(), stats_string);
#else
FAIL() << "Writing to reference file requires Proto Buffer.";
#endif // WEBRTC_NETEQ_UNITTEST_BITEXACT
}
void ResultSink::VerifyChecksum(const std::string& checksum) {
std::string buffer;
buffer.resize(digest_->Size());
digest_->Finish(buffer.data(), buffer.size());
const std::string result = rtc::hex_encode(buffer);
if (checksum.size() == result.size()) {
EXPECT_EQ(checksum, result);
} else {
// Check result is one the '|'-separated checksums.
EXPECT_NE(checksum.find(result), std::string::npos)
<< result << " should be one of these:\n"
<< checksum;
}
}
} // namespace webrtc
|
; A094114: a(n) = -Sum_{i=1..n-1} (-1)^i*2^valuation(i,3).
; Submitted by Jon Maiga
; 0,1,0,2,1,2,0,1,0,4,3,4,2,3,2,4,3,4,0,1,0,2,1,2,0,1,0,8,7,8,6,7,6,8,7,8,4,5,4,6,5,6,4,5,4,8,7,8,6,7,6,8,7,8,0,1,0,2,1,2,0,1,0,4,3,4,2,3,2,4,3,4,0,1,0,2,1,2,0,1,0,16,15,16,14,15,14,16,15,16,12,13,12,14,13,14,12,13,12,16
seq $0,332497 ; a(n) = x(w+1) where x(0) = 0 and x(k+1) = 2^(k+1)-1-x(k) (resp. x(k)) when d_k = 1 (resp. d_k <> 1) and Sum_{k=0..w} d_k*3^k is the ternary representation of n. Sequence A332498 gives corresponding y's.
add $0,1
div $0,2
|
; Copyright © 2021, VideoLAN and dav1d authors
; Copyright © 2021, Two Orioles, LLC
; Copyright © 2021, Matthias Dressel
; All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
;
; 1. Redistributions of source code must retain the above copyright notice, this
; list of conditions and the following disclaimer.
;
; 2. Redistributions in binary form must reproduce the above copyright notice,
; this list of conditions and the following disclaimer in the documentation
; and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%include "config.asm"
%include "ext/x86/x86inc.asm"
%if ARCH_X86_64
SECTION_RODATA 32
pd_1321_2482: dd 1321, 1321, 1321, 1321, 2482, 2482, 2482, 2482
itx4_shuf: dd 0x50401600, 0xd0c09284, 0x70603422, 0xf0e0b0a6
dd 0x50401701, 0xd0c09385, 0x70603523, 0xf0e0b1a7
idct4_12_shuf: dd 0, 2, 4, 6, 1, 3, 5, 7
idct4_12_shuf2: dd 2, 0, 6, 4, 3, 1, 7, 5
iadst8_12_shuf: dd 0, 4, 1, 5, 2, 6, 3, 7
idct16_12_shuf: dd 0, 4, 1, 5, 3, 7, 2, 6
iadst16_12_shuf: dd 3, 7, 0, 4, 2, 6, 1, 5
pw_2048_m2048: dw 2048, 2048, 2048, 2048, -2048, -2048, -2048, -2048
iadst4_dconly2a: dw 10568, 10568, 10568, 10568, 19856, 19856, 19856, 19856
idct4_shuf: db 0, 1, 4, 5, 12, 13, 8, 9, 2, 3, 6, 7, 14, 15, 10, 11
idct32_shuf: db 0, 1, 8, 9, 4, 5, 12, 13, 2, 3, 10, 11, 6, 7, 14, 15
%macro COEF_PAIR 2
pd_%1_%2: dd %1, %1, %2, %2
%define pd_%1 (pd_%1_%2 + 4*0)
%define pd_%2 (pd_%1_%2 + 4*2)
%endmacro
COEF_PAIR 201, 995
COEF_PAIR 401, 1931
COEF_PAIR 799, 3406
COEF_PAIR 1380, 601
COEF_PAIR 1751, 2440
COEF_PAIR 2598, 1189
COEF_PAIR 2751, 2106
COEF_PAIR 2896, 1567
COEF_PAIR 2896, 3784
COEF_PAIR 3035, 3513
COEF_PAIR 3166, 3920
COEF_PAIR 3703, 3290
COEF_PAIR 3857, 4052
COEF_PAIR 4017, 2276
COEF_PAIR 4076, 3612
COEF_PAIR 4091, 3973
%define pd_1321 (pd_1321_2482 + 4*0)
%define pd_2482 (pd_1321_2482 + 4*4)
pd_8: dd 8
pd_m601: dd -601
pd_m1189: dd -1189
pd_m1380: dd -1380
pd_m2106: dd -2106
pd_m2598: dd -2598
pd_m2751: dd -2751
pd_m3344: dd -3344
pd_3803: dd 3803
pd_5793: dd 5793
pd_6144: dd 6144 ; 2048 + 4096
pd_10239: dd 10239 ; 2048 + 8192 - 1
pd_10240: dd 10240 ; 2048 + 8192
pd_11586: dd 11586 ; 5793 * 2
pd_34816: dd 34816 ; 2048 + 32768
pd_38912: dd 38912 ; 2048 + 4096 + 32768
pixel_10bpc_max: times 2 dw 0x03ff
pixel_12bpc_max: times 2 dw 0x0fff
clip_18b_min: dd -0x20000
clip_18b_max: dd 0x1ffff
clip_20b_min: dd -0x80000
clip_20b_max: dd 0x7ffff
idct64_mul_16bpc:
dd 4095, 101, 2967, -2824, 3745, 1660, 3822, -1474, 401, 4076, 799, 4017
dd -700, 4036, 2359, 3349, -2191, 3461, 897, 3996, -2598, -3166, -4017, -799
dd 4065, 501, 3229, -2520, 3564, 2019, 3948, -1092, 1931, 3612, 3406, 2276
dd -301, 4085, 2675, 3102, -1842, 3659, 1285, 3889, -1189, -3920, -2276, -3406
cextern deint_shuf
cextern idct64_mul
cextern pw_1697x8
cextern pw_1697x16
cextern pw_1567_3784
cextern pw_m1567_m3784
cextern pw_m3784_1567
cextern pw_2896_2896
cextern pw_m2896_2896
cextern pw_5
cextern pw_2048
cextern pw_4096
cextern pw_8192
cextern pw_16384
cextern pw_2896x8
cextern pd_2048
cextern idct_4x8_internal_8bpc_avx2.main
cextern idct_4x16_internal_8bpc_avx2.main
cextern idct_8x8_internal_8bpc_avx2.main
cextern idct_8x16_internal_8bpc_avx2.main
cextern idct_16x4_internal_8bpc_avx2.main
cextern idct_16x8_internal_8bpc_avx2.main
cextern idct_16x16_internal_8bpc_avx2.main
cextern inv_txfm_add_dct_dct_8x32_8bpc_avx2.main
cextern inv_txfm_add_dct_dct_8x32_8bpc_avx2.main_fast
cextern inv_txfm_add_dct_dct_16x32_8bpc_avx2.main_oddhalf
cextern inv_txfm_add_dct_dct_16x32_8bpc_avx2.main_oddhalf_fast
cextern inv_txfm_add_dct_dct_16x64_8bpc_avx2.main_part1
cextern inv_txfm_add_dct_dct_16x64_8bpc_avx2.main_part2_internal
cextern iadst_4x4_internal_8bpc_avx2.main
cextern iadst_4x8_internal_8bpc_avx2.main_pass2
cextern iadst_4x16_internal_8bpc_avx2.main2
cextern iadst_8x4_internal_8bpc_avx2.main
cextern iadst_8x8_internal_8bpc_avx2.main_pass2
cextern iadst_8x16_internal_8bpc_avx2.main
cextern iadst_8x16_internal_8bpc_avx2.main_pass2_end
cextern iadst_16x4_internal_8bpc_avx2.main
cextern iadst_16x8_internal_8bpc_avx2.main
cextern iadst_16x8_internal_8bpc_avx2.main_pass2_end
cextern iadst_16x16_internal_8bpc_avx2.main
cextern iadst_16x16_internal_8bpc_avx2.main_pass2_end
SECTION .text
%define m(x) mangle(private_prefix %+ _ %+ x %+ SUFFIX)
%macro WRAP_XMM 1+
INIT_XMM cpuname
%1
INIT_YMM cpuname
%endmacro
%macro IWHT4_1D_PACKED 0
; m0 = in0 in2, m1 = in1 in3
psubd m2, m0, m1 ; t2
paddd xm0, xm1 ; t0
vpermq m2, m2, q3322
vpermq m0, m0, q1100
vpermq m1, m1, q3120
psubd m3, m0, m2
psrad m3, 1
psubd m3, m1 ; t1 t3
psubd m0, m3 ; ____ out0
paddd m2, m3 ; out3 ____
%endmacro
INIT_YMM avx2
cglobal inv_txfm_add_wht_wht_4x4_16bpc, 3, 7, 6, dst, stride, c, eob, bdmax
mova xm0, [cq+16*0]
vinserti128 m0, [cq+16*2], 1
mova xm1, [cq+16*1]
vinserti128 m1, [cq+16*3], 1
pxor m4, m4
mova [cq+32*0], m4
mova [cq+32*1], m4
lea r6, [dstq+strideq*2]
psrad m0, 2
psrad m1, 2
IWHT4_1D_PACKED
punpckhdq m0, m3
punpckldq m3, m2
punpckhqdq m1, m0, m3
punpcklqdq m0, m3
IWHT4_1D_PACKED
vpblendd m0, m2, 0x33
packssdw m0, m3
vextracti128 xm2, m0, 1
punpckhdq xm1, xm0, xm2 ; out2 out1
punpckldq xm0, xm2 ; out3 out0
movq xm2, [r6 +strideq*1]
movhps xm2, [dstq+strideq*0]
movq xm3, [r6 +strideq*0]
movhps xm3, [dstq+strideq*1]
%ifidn bdmaxd, bdmaxm
movd xm5, bdmaxd
vpbroadcastw xm5, xm5
%else ; win64: load from stack
vpbroadcastw xm5, bdmaxm
%endif
paddsw xm0, xm2
paddsw xm1, xm3
pmaxsw xm0, xm4
pmaxsw xm1, xm4
pminsw xm0, xm5
pminsw xm1, xm5
movhps [dstq+strideq*0], xm0
movhps [dstq+strideq*1], xm1
movq [r6 +strideq*0], xm1
movq [r6 +strideq*1], xm0
RET
; dst1 = (src1 * coef1 - src2 * coef2 + rnd) >> 12
; dst2 = (src1 * coef2 + src2 * coef1 + rnd) >> 12
; flags: 1 = packed, 2 = inv_dst1, 4 = inv_dst2
; skip round/shift if rnd is not a number
%macro ITX_MULSUB_2D 8-9 0 ; dst/src[1-2], tmp[1-3], rnd, coef[1-2], flags
%if %8 < 32
pmulld m%4, m%1, m%8
pmulld m%3, m%2, m%8
%else
%if %9 & 1
vbroadcasti128 m%3, [pd_%8]
%else
vpbroadcastd m%3, [pd_%8]
%endif
pmulld m%4, m%1, m%3
pmulld m%3, m%2
%endif
%if %7 < 32
pmulld m%1, m%7
pmulld m%2, m%7
%else
%if %9 & 1
vbroadcasti128 m%5, [pd_%7]
%else
vpbroadcastd m%5, [pd_%7]
%endif
pmulld m%1, m%5
pmulld m%2, m%5
%endif
%if %9 & 4
psubd m%4, m%6, m%4
psubd m%2, m%4, m%2
%else
%ifnum %6
paddd m%4, m%6
%endif
paddd m%2, m%4
%endif
%if %9 & 2 ; invert the upper half of dst1 before rounding
vbroadcasti128 m%4, [pw_2048_m2048]
psubd m%1, m%3
psignd m%1, m%4
paddd m%1, m%6
%else
%ifnum %6
paddd m%1, m%6
%endif
psubd m%1, m%3
%endif
%ifnum %6
psrad m%2, 12
psrad m%1, 12
%endif
%endmacro
%macro INV_TXFM_FN 4-5 10 ; type1, type2, eob_offset, size, bitdepth
cglobal inv_txfm_add_%1_%2_%4_%5bpc, 4, 5, 0, dst, stride, c, eob, tx2
%define %%p1 m(i%1_%4_internal_%5bpc)
; Jump to the 1st txfm function if we're not taking the fast path, which
; in turn performs an indirect jump to the 2nd txfm function.
lea tx2q, [m(i%2_%4_internal_%5bpc).pass2]
%ifidn %1_%2, dct_dct
test eobd, eobd
jnz %%p1
%else
%if %3
add eobd, %3
%endif
; jump to the 1st txfm function unless it's located directly after this
times ((%%end - %%p1) >> 31) & 1 jmp %%p1
ALIGN function_align
%%end:
%endif
%endmacro
%macro INV_TXFM_4X4_FN 2 ; type1, type2
INV_TXFM_FN %1, %2, 0, 4x4
%ifidn %1_%2, dct_dct
imul r6d, [cq], 2896
movd xm1, [pw_2896x8]
mov [cq], eobd ; 0
add r6d, 2048
sar r6d, 12
movd xm0, r6d
packssdw xm0, xm0
pmulhrsw xm0, xm1
vpbroadcastw xm0, xm0
mova xm1, xm0
jmp m(iadst_4x4_internal_10bpc).end
%endif
%endmacro
%macro INV_TXFM_4X4_12BPC_FN 2 ; type1, type2
INV_TXFM_FN %1, %2, 0, 4x4, 12
%ifidn %1_%2, dct_dct
imul r6d, [cq], 181
mov [cq], eobd ; 0
add r6d, 128
sar r6d, 8
imul r6d, 181
add r6d, 128
sar r6d, 8
movd xm0, r6d
vpbroadcastd m0, xm0
mova m1, m0
jmp m(iadst_4x4_internal_12bpc).end
%endif
%endmacro
%macro IDCT4_1D_PACKED 6 ; dst/src[1-2], tmp[1-3], rnd
ITX_MULSUB_2D %1, %2, %3, %4, %5, %6, 2896_1567, 2896_3784, 1
punpckhqdq m%3, m%2, m%1 ; t3 t2
punpcklqdq m%2, m%1 ; t0 t1
paddd m%1, m%2, m%3 ; out0 out1
psubd m%2, m%3 ; out3 out2
%endmacro
%macro IDCT4_1D_PACKED_WORD 6 ; dst/src[1-2], tmp[1-3], rnd
vpbroadcastd m%5, [pw_m3784_1567]
punpckhwd m%3, m%2, m%1
vpbroadcastd m%4, [pw_1567_3784]
punpcklwd m%2, m%1
vpbroadcastd m%1, [pw_m2896_2896]
pmaddwd m%5, m%3
pmaddwd m%3, m%4
vpbroadcastd m%4, [pw_2896_2896]
pmaddwd m%1, m%2
pmaddwd m%2, m%4
REPX {paddd x, m%6}, m%5, m%3, m%1, m%2
REPX {psrad x, 12 }, m%5, m%3, m%1, m%2
packssdw m%3, m%5 ; t3 t2
packssdw m%2, m%1 ; t0 t1
paddsw m%1, m%2, m%3 ; out0 out1
psubsw m%2, m%3 ; out3 out2
%endmacro
INV_TXFM_4X4_FN dct, dct
INV_TXFM_4X4_FN dct, identity
INV_TXFM_4X4_FN dct, adst
INV_TXFM_4X4_FN dct, flipadst
cglobal idct_4x4_internal_10bpc, 0, 7, 6, dst, stride, c, eob, tx2
call .main
vbroadcasti128 m2, [idct4_shuf]
packssdw m0, m1
pshufb m0, m2
jmp tx2q
.pass2:
vextracti128 xm1, m0, 1
WRAP_XMM IDCT4_1D_PACKED_WORD 0, 1, 2, 3, 4, 5
packssdw xm5, xm5 ; pw_2048
pmulhrsw xm0, xm5
pmulhrsw xm1, xm5
movq xm2, [dstq+strideq*0]
movhps xm2, [dstq+strideq*1]
lea r6, [dstq+strideq*2]
movq xm3, [r6 +strideq*1]
movhps xm3, [r6 +strideq*0]
vpbroadcastd xm5, [pixel_10bpc_max]
pxor m4, m4
mova [cq+32*0], m4
mova [cq+32*1], m4
paddw xm0, xm2
paddw xm1, xm3
pmaxsw xm0, xm4
pmaxsw xm1, xm4
pminsw xm0, xm5
pminsw xm1, xm5
movq [dstq+strideq*0], xm0
movhps [dstq+strideq*1], xm0
movhps [r6 +strideq*0], xm1
movq [r6 +strideq*1], xm1
RET
ALIGN function_align
.main:
vpermq m0, [cq+32*0], q3120
vpermq m1, [cq+32*1], q3120
vpbroadcastd m5, [pd_2048]
.main2:
IDCT4_1D_PACKED 0, 1, 2, 3, 4, 5
ret
INV_TXFM_4X4_FN adst, dct
INV_TXFM_4X4_FN adst, adst
INV_TXFM_4X4_FN adst, flipadst
INV_TXFM_4X4_FN adst, identity
cglobal iadst_4x4_internal_10bpc, 0, 7, 6, dst, stride, c, eob, tx2
call .main
packssdw m0, m1
vpermd m0, m4, m0
psrld m4, 4
pshufb m0, m4
jmp tx2q
.pass2:
lea r6, [deint_shuf+128]
vextracti128 xm1, m0, 1
call m(iadst_4x4_internal_8bpc).main
.end:
vpbroadcastd xm4, [pw_2048]
movq xm2, [dstq+strideq*0]
movhps xm2, [dstq+strideq*1]
lea r6, [dstq+strideq*2]
movq xm3, [r6 +strideq*0]
movhps xm3, [r6 +strideq*1]
vpbroadcastd xm5, [pixel_10bpc_max]
pmulhrsw xm0, xm4
pmulhrsw xm1, xm4
pxor m4, m4
mova [cq+32*0], m4
mova [cq+32*1], m4
paddw xm0, xm2
paddw xm1, xm3
pmaxsw xm0, xm4
pmaxsw xm1, xm4
pminsw xm0, xm5
pminsw xm1, xm5
movq [dstq+strideq*0], xm0
movhps [dstq+strideq*1], xm0
movq [r6 +strideq*0], xm1
movhps [r6 +strideq*1], xm1
RET
ALIGN function_align
.main:
mova m2, [cq+16*2]
vbroadcasti128 m5, [cq+16*0]
.main2:
mova m0, [pd_1321_2482]
vpbroadcastd m3, [pd_3803]
vpbroadcastd m1, [pd_m3344]
pmulld m4, m0, m2
pmulld m3, m2
pmulld m0, m5
vpbroadcastd m5, [pd_2048]
psubd xm2, [cq+16*3]
psubd m2, [cq+16*0]
pmulld m2, m1 ; t2 t3
vpermq m4, m4, q1032
paddd m4, m3
psubd m0, m4
paddd xm4, xm4
paddd m4, m0 ; t0 t1
vinserti128 m3, m2, xm4, 1 ; t2 t0
paddd m0, m4, m5
psubd xm4, xm2
psubd m1, m0, m2
vpermq m2, m2, q3232 ; t3 t3
psubd m1, m4
mova m4, [itx4_shuf]
paddd m0, m2 ; out0 out1
paddd m1, m3 ; out2 out3
psrad m0, 12
psrad m1, 12
ret
INV_TXFM_4X4_FN flipadst, dct
INV_TXFM_4X4_FN flipadst, adst
INV_TXFM_4X4_FN flipadst, flipadst
INV_TXFM_4X4_FN flipadst, identity
cglobal iflipadst_4x4_internal_10bpc, 0, 7, 6, dst, stride, c, eob, tx2
call m(iadst_4x4_internal_10bpc).main
packssdw m0, m1
psrld m1, m4, 8
vpermd m0, m1, m0
psrld m4, 4
pshufb m0, m4
jmp tx2q
.pass2:
lea r6, [deint_shuf+128]
vextracti128 xm1, m0, 1
call m(iadst_4x4_internal_8bpc).main
vpbroadcastd xm4, [pw_2048]
movq xm3, [dstq+strideq*1]
movhps xm3, [dstq+strideq*0]
lea r6, [dstq+strideq*2]
movq xm2, [r6 +strideq*1]
movhps xm2, [r6 +strideq*0]
vpbroadcastd xm5, [pixel_10bpc_max]
pmulhrsw xm0, xm4
pmulhrsw xm1, xm4
pxor m4, m4
mova [cq+32*0], m4
mova [cq+32*1], m4
paddw xm0, xm2
paddw xm1, xm3
pmaxsw xm0, xm4
pmaxsw xm1, xm4
pminsw xm0, xm5
pminsw xm1, xm5
movhps [dstq+strideq*0], xm1
movq [dstq+strideq*1], xm1
movhps [r6 +strideq*0], xm0
movq [r6 +strideq*1], xm0
RET
INV_TXFM_4X4_FN identity, dct
INV_TXFM_4X4_FN identity, adst
INV_TXFM_4X4_FN identity, flipadst
INV_TXFM_4X4_FN identity, identity
cglobal iidentity_4x4_internal_10bpc, 0, 7, 6, dst, stride, c, eob, tx2
vpbroadcastd m1, [pd_5793]
pmulld m0, m1, [cq+32*0]
pmulld m1, [cq+32*1]
vpbroadcastd m5, [pd_2048]
mova m3, [itx4_shuf]
paddd m0, m5
paddd m1, m5
psrad m0, 12
psrad m1, 12
packssdw m0, m1
vpermd m0, m3, m0
psrld m3, 4
pshufb m0, m3
jmp tx2q
.pass2:
vpbroadcastd m1, [pw_1697x8]
movq xm2, [dstq+strideq*0]
movhps xm2, [dstq+strideq*1]
lea r6, [dstq+strideq*2]
pmulhrsw m1, m0
paddsw m0, m1
movq xm3, [r6 +strideq*0]
movhps xm3, [r6 +strideq*1]
vpbroadcastd xm4, [pixel_10bpc_max]
packssdw m5, m5 ; pw_2048
pmulhrsw m0, m5
pxor m5, m5
mova [cq+32*0], m5
mova [cq+32*1], m5
vextracti128 xm1, m0, 1
paddw xm0, xm2
paddw xm1, xm3
pmaxsw xm0, xm5
pmaxsw xm1, xm5
pminsw xm0, xm4
pminsw xm1, xm4
movq [dstq+strideq*0], xm0
movhps [dstq+strideq*1], xm0
movq [r6 +strideq*0], xm1
movhps [r6 +strideq*1], xm1
RET
INV_TXFM_4X4_12BPC_FN dct, dct
INV_TXFM_4X4_12BPC_FN dct, identity
INV_TXFM_4X4_12BPC_FN dct, adst
INV_TXFM_4X4_12BPC_FN dct, flipadst
cglobal idct_4x4_internal_12bpc, 0, 7, 6, dst, stride, c, eob, tx2
call m(idct_4x4_internal_10bpc).main
mova m3, [idct4_12_shuf]
mova m4, [idct4_12_shuf2]
vpermd m2, m3, m0
vpermd m1, m4, m1
jmp m(iadst_4x4_internal_12bpc).pass1_end
.pass2:
vpermq m0, m0, q3120
vpermq m1, m1, q3120
call m(idct_4x4_internal_10bpc).main2
vpermq m0, m0, q3120
vpermq m1, m1, q2031
jmp m(iadst_4x4_internal_12bpc).end
INV_TXFM_4X4_12BPC_FN adst, dct
INV_TXFM_4X4_12BPC_FN adst, adst
INV_TXFM_4X4_12BPC_FN adst, flipadst
INV_TXFM_4X4_12BPC_FN adst, identity
cglobal iadst_4x4_internal_12bpc, 0, 7, 6, dst, stride, c, eob, tx2
call m(iadst_4x4_internal_10bpc).main
vpermd m2, m4, m0
vpermd m1, m4, m1
.pass1_end:
punpcklqdq m0, m2, m1
punpckhqdq m1, m2, m1
.pass1_end2:
vpbroadcastd m3, [clip_18b_min]
vpbroadcastd m4, [clip_18b_max]
pmaxsd m0, m3
pmaxsd m1, m3
pminsd m0, m4
pminsd m1, m4
jmp tx2q
.pass2:
mova [cq+16*0], m0
vextracti128 [cq+16*3], m1, 1
mova m2, m1
vpermq m5, m0, q1010
call m(iadst_4x4_internal_10bpc).main2
.end:
vpbroadcastd m4, [pw_16384]
movq xm2, [dstq+strideq*0]
movq xm3, [dstq+strideq*1]
lea r6, [dstq+strideq*2]
movhps xm2, [r6 +strideq*0] ; dst0 dst2
movhps xm3, [r6 +strideq*1] ; dst1 dst3
vpbroadcastd m5, [pixel_12bpc_max]
vinserti128 m2, xm3, 1
psrad m0, 3
psrad m1, 3
packssdw m0, m1 ; t0 t2 t1 t3
pmulhrsw m0, m4
pxor m4, m4
mova [cq+32*0], m4
mova [cq+32*1], m4
paddw m0, m2 ; out0 out2 out1 out3
pmaxsw m0, m4
pminsw m0, m5
vextracti128 xm1, m0, 1 ; out1 out3
movq [dstq+strideq*0], xm0
movq [dstq+strideq*1], xm1
movhps [r6 +strideq*0], xm0
movhps [r6 +strideq*1], xm1
RET
INV_TXFM_4X4_12BPC_FN flipadst, dct
INV_TXFM_4X4_12BPC_FN flipadst, adst
INV_TXFM_4X4_12BPC_FN flipadst, flipadst
INV_TXFM_4X4_12BPC_FN flipadst, identity
cglobal iflipadst_4x4_internal_12bpc, 0, 7, 6, dst, stride, c, eob, tx2
call m(iadst_4x4_internal_10bpc).main
psrld m4, 8
vpermd m2, m4, m0
vpermd m1, m4, m1
punpckhqdq m0, m1, m2
punpcklqdq m1, m2
jmp m(iadst_4x4_internal_12bpc).pass1_end2
.pass2:
mova [cq+16*0], m0
vextracti128 [cq+16*3], m1, 1
mova m2, m1
vpermq m5, m0, q1010
call m(iadst_4x4_internal_10bpc).main2
vpermq m2, m0, q1032
vpermq m0, m1, q1032
mova m1, m2
jmp m(iadst_4x4_internal_12bpc).end
INV_TXFM_4X4_12BPC_FN identity, dct
INV_TXFM_4X4_12BPC_FN identity, adst
INV_TXFM_4X4_12BPC_FN identity, flipadst
INV_TXFM_4X4_12BPC_FN identity, identity
cglobal iidentity_4x4_internal_12bpc, 0, 7, 6, dst, stride, c, eob, tx2
vpbroadcastd m1, [pd_5793]
pmulld m0, m1, [cq+32*0]
pmulld m1, [cq+32*1]
vpbroadcastd m5, [pd_2048]
mova m3, [itx4_shuf]
paddd m0, m5
paddd m1, m5
psrad m0, 12
psrad m1, 12
vpermd m2, m3, m0
vpermd m1, m3, m1
jmp m(iadst_4x4_internal_12bpc).pass1_end
.pass2:
; m0 = in0 in1
; m1 = in2 in3
vpbroadcastd m3, [pd_5793]
pmulld m0, m3
pmulld m1, m3
paddd m0, m5 ; 2048
paddd m1, m5
psrad m0, 12
psrad m1, 12
jmp m(iadst_4x4_internal_12bpc).end
%macro INV_TXFM_4X8_FN 2-3 10 ; type1, type2, bitdepth
INV_TXFM_FN %1, %2, 0, 4x8, %3
%ifidn %1_%2, dct_dct
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 8
add r6d, 2048
sar r6d, 12
imul r6d, 2896
add r6d, 2048
sar r6d, 12
.end:
imul r6d, 2896
add r6d, 34816
sar r6d, 16
movd xm0, r6d
vpbroadcastw xm0, xm0
vpbroadcastd xm3, [pixel_%3bpc_max]
pxor xm2, xm2
.end_loop:
movq xm1, [dstq+strideq*0]
movhps xm1, [dstq+strideq*1]
paddw xm1, xm0
pmaxsw xm1, xm2
pminsw xm1, xm3
movq [dstq+strideq*0], xm1
movhps [dstq+strideq*1], xm1
lea dstq, [dstq+strideq*2]
sub r3d, 2
jg .end_loop
WRAP_XMM RET
%endif
%endmacro
%macro IDCT4_1D 8 ; src[1-4], tmp[1-3], rnd
ITX_MULSUB_2D %2, %4, %5, %6, %7, %8, 1567, 3784 ; t2, t3
vpbroadcastd m%5, [pd_2896]
pmulld m%1, m%5
pmulld m%3, m%5
paddd m%1, m%8
paddd m%5, m%1, m%3
psubd m%1, m%3
psrad m%5, 12 ; t0
psrad m%1, 12 ; t1
psubd m%3, m%1, m%2
paddd m%2, m%1
paddd m%1, m%5, m%4
psubd m%4, m%5, m%4
%endmacro
INV_TXFM_4X8_FN dct, dct
INV_TXFM_4X8_FN dct, identity
INV_TXFM_4X8_FN dct, adst
INV_TXFM_4X8_FN dct, flipadst
cglobal idct_4x8_internal_10bpc, 0, 7, 8, dst, stride, c, eob, tx2
.pass1:
vpbroadcastd m3, [pd_2896]
pmulld m0, m3, [cq+32*0]
pmulld m1, m3, [cq+32*1]
pmulld m2, m3, [cq+32*2]
pmulld m3, m3, [cq+32*3]
vpbroadcastd m7, [pd_2048]
REPX {paddd x, m7}, m0, m1, m2, m3
REPX {psrad x, 12}, m0, m1, m2, m3
IDCT4_1D 0, 1, 2, 3, 4, 5, 6, 7
jmp tx2q
.pass2:
packssdw m0, m2
packssdw m1, m3
lea r6, [deint_shuf+128]
punpckhwd m2, m0, m1
punpcklwd m0, m1
punpckhdq m1, m0, m2 ; 2 3
punpckldq m0, m2 ; 0 1
vextracti128 xm2, m0, 1 ; 4 5
vextracti128 xm3, m1, 1 ; 6 7
call m(idct_4x8_internal_8bpc).main
vpbroadcastd xm4, [pw_2048]
REPX {pmulhrsw x, xm4}, xm0, xm1, xm2, xm3
lea r3, [strideq*3]
lea r6, [dstq+strideq*4]
movq xm4, [dstq+strideq*0]
movhps xm4, [dstq+strideq*1]
movq xm5, [dstq+r3 ]
movhps xm5, [dstq+strideq*2]
movq xm6, [r6 +strideq*0]
movhps xm6, [r6 +strideq*1]
movq xm7, [r6 +r3 ]
movhps xm7, [r6 +strideq*2]
paddw xm0, xm4 ; 0 1
paddw xm1, xm5 ; 3 2
paddw xm2, xm6 ; 4 5
paddw xm3, xm7 ; 7 6
vpbroadcastd xm5, [pixel_10bpc_max]
pxor m4, m4
REPX {mova [cq+32*x], m4}, 0, 1, 2, 3
REPX {pmaxsw x, xm4}, xm0, xm1, xm2, xm3
REPX {pminsw x, xm5}, xm0, xm1, xm2, xm3
movq [dstq+strideq*0], xm0
movhps [dstq+strideq*1], xm0
movhps [dstq+strideq*2], xm1
movq [dstq+r3 ], xm1
movq [r6 +strideq*0], xm2
movhps [r6 +strideq*1], xm2
movhps [r6 +strideq*2], xm3
movq [r6 +r3 ], xm3
RET
INV_TXFM_4X8_FN adst, dct
INV_TXFM_4X8_FN adst, adst
INV_TXFM_4X8_FN adst, flipadst
INV_TXFM_4X8_FN adst, identity
cglobal iadst_4x8_internal_10bpc, 0, 7, 8, dst, stride, c, eob, tx2
.pass1:
call m(iadst_8x4_internal_10bpc).main
psrad m0, m4, 12
psrad m1, m5, 12
psrad m2, 12
psrad m3, 12
jmp tx2q
.pass2:
call .pass2_main
mova xm4, [pw_2048_m2048]
REPX {pmulhrsw x, xm4}, xm0, xm1, xm2, xm3
.end:
lea r3, [strideq*3]
lea r6, [dstq+strideq*4]
movq xm4, [dstq+strideq*0]
movhps xm4, [dstq+strideq*1]
movq xm5, [dstq+strideq*2]
movhps xm5, [dstq+r3 ]
movq xm6, [r6 +strideq*0]
movhps xm6, [r6 +strideq*1]
movq xm7, [r6 +strideq*2]
movhps xm7, [r6 +r3 ]
paddw xm0, xm4 ; 0 1
paddw xm1, xm5 ; 2 3
paddw xm2, xm6 ; 4 5
paddw xm3, xm7 ; 6 7
vpbroadcastd xm5, [pixel_10bpc_max]
pxor m4, m4
REPX {mova [cq+32*x], m4}, 0, 1, 2, 3
REPX {pmaxsw x, xm4}, xm0, xm1, xm2, xm3
REPX {pminsw x, xm5}, xm0, xm1, xm2, xm3
movq [dstq+strideq*0], xm0
movhps [dstq+strideq*1], xm0
movq [dstq+strideq*2], xm1
movhps [dstq+r3 ], xm1
movq [r6 +strideq*0], xm2
movhps [r6 +strideq*1], xm2
movq [r6 +strideq*2], xm3
movhps [r6 +r3 ], xm3
RET
ALIGN function_align
.pass2_main:
packssdw m0, m2
packssdw m1, m3
lea r6, [deint_shuf+128]
punpcklwd m4, m0, m1
punpckhwd m0, m1
punpckhdq m5, m4, m0
punpckldq m4, m0
vextracti128 xm2, m4, 1 ; 4 5
vextracti128 xm3, m5, 1 ; 6 7
pshufd xm4, xm4, q1032 ; 1 0
pshufd xm5, xm5, q1032 ; 3 2
jmp m(iadst_4x8_internal_8bpc).main_pass2
ALIGN function_align
.main:
vpbroadcastd m8, [clip_18b_min]
vpbroadcastd m9, [clip_18b_max]
.main2:
vbroadcasti128 m0, [cq+16*0]
vbroadcasti128 m2, [cq+16*2]
vbroadcasti128 m3, [cq+16*5]
vbroadcasti128 m1, [cq+16*7]
vpbroadcastd m6, [pd_2896]
shufpd m0, m2, 0x0c ; 0 2
shufpd m1, m3, 0x0c ; 7 5
vbroadcasti128 m2, [cq+16*4]
vbroadcasti128 m4, [cq+16*6]
vbroadcasti128 m5, [cq+16*1]
vbroadcasti128 m3, [cq+16*3]
vpbroadcastd m7, [pd_2048]
shufpd m2, m4, 0x0c ; 4 6
shufpd m3, m5, 0x0c ; 3 1
REPX {pmulld x, m6}, m0, m1, m2, m3
REPX {paddd x, m7}, m0, m1, m2, m3
REPX {psrad x, 12}, m0, m1, m2, m3
.main3:
ITX_MULSUB_2D 1, 0, 4, 5, 6, 7, 401_1931, 4076_3612, 1
ITX_MULSUB_2D 3, 2, 4, 5, 6, 7, 3166_3920, 2598_1189, 1
psubd m4, m0, m2 ; t4 t6
paddd m0, m2 ; t0 t2
psubd m2, m1, m3 ; t5 t7
paddd m1, m3 ; t1 t3
REPX {pmaxsd x, m8}, m4, m2, m0, m1
REPX {pminsd x, m9}, m4, m2, m0, m1
pxor m5, m5
psubd m5, m4
vpblendd m4, m2, 0xcc ; t4 t7
vpblendd m2, m5, 0xcc ; t5 -t6
ITX_MULSUB_2D 4, 2, 3, 5, 6, 7, 1567, 3784
vpbroadcastd m5, [pd_2896]
vbroadcasti128 m6, [pw_2048_m2048] ; + + - -
punpckhqdq m3, m0, m1
punpcklqdq m0, m1
psubd m1, m0, m3 ; t2 t3
paddd m0, m3 ; out0 -out7
punpckhqdq m3, m4, m2 ; t7a t6a
punpcklqdq m4, m2 ; t5a t4a
psubd m2, m4, m3 ; t7 t6
paddd m4, m3 ; out6 -out1
REPX {pmaxsd x, m8}, m1, m2
REPX {pminsd x, m9}, m1, m2
vpblendd m3, m1, m2, 0xcc
shufpd m1, m2, 0x05
pmulld m3, m5
pmulld m5, m1
psignd m0, m6 ; out0 out7
psignd m4, m6 ; out6 out1
paddd m3, m7
psubd m2, m3, m5
paddd m5, m3
psrad m2, 12 ; out4 -out5
psrad m5, 12 ; -out3 out2
ret
INV_TXFM_4X8_FN flipadst, dct
INV_TXFM_4X8_FN flipadst, adst
INV_TXFM_4X8_FN flipadst, flipadst
INV_TXFM_4X8_FN flipadst, identity
cglobal iflipadst_4x8_internal_10bpc, 0, 7, 8, dst, stride, c, eob, tx2
.pass1:
call m(iadst_8x4_internal_10bpc).main
psrad m0, m3, 12
psrad m1, m2, 12
psrad m2, m5, 12
psrad m3, m4, 12
jmp tx2q
.pass2:
call m(iadst_4x8_internal_10bpc).pass2_main
mova xm4, [pw_2048_m2048]
REPX {pmulhrsw x, xm4}, xm3, xm2, xm1, xm0
lea r3, [strideq*3]
lea r6, [dstq+strideq*4]
movq xm4, [dstq+strideq*1]
movhps xm4, [dstq+strideq*0]
movq xm5, [dstq+r3 ]
movhps xm5, [dstq+strideq*2]
movq xm6, [r6 +strideq*1]
movhps xm6, [r6 +strideq*0]
movq xm7, [r6 +r3 ]
movhps xm7, [r6 +strideq*2]
paddw xm3, xm4 ; 1 0
paddw xm2, xm5 ; 3 2
paddw xm1, xm6 ; 5 4
paddw xm0, xm7 ; 7 6
vpbroadcastd xm5, [pixel_10bpc_max]
pxor m4, m4
REPX {mova [cq+32*x], m4}, 0, 1, 2, 3
REPX {pmaxsw x, xm4}, xm3, xm2, xm1, xm0
REPX {pminsw x, xm5}, xm3, xm2, xm1, xm0
movhps [dstq+strideq*0], xm3
movq [dstq+strideq*1], xm3
movhps [dstq+strideq*2], xm2
movq [dstq+r3 ], xm2
movhps [r6 +strideq*0], xm1
movq [r6 +strideq*1], xm1
movhps [r6 +strideq*2], xm0
movq [r6 +r3 ], xm0
RET
INV_TXFM_4X8_FN identity, dct
INV_TXFM_4X8_FN identity, adst
INV_TXFM_4X8_FN identity, flipadst
INV_TXFM_4X8_FN identity, identity
cglobal iidentity_4x8_internal_10bpc, 0, 7, 8, dst, stride, c, eob, tx2
.pass1:
vpbroadcastd m3, [pd_2896]
pmulld m0, m3, [cq+32*0]
pmulld m1, m3, [cq+32*1]
pmulld m2, m3, [cq+32*2]
pmulld m3, [cq+32*3]
vpbroadcastd m5, [pd_2048]
vpbroadcastd m4, [pd_5793]
REPX {paddd x, m5}, m0, m1, m2, m3
REPX {psrad x, 12}, m0, m1, m2, m3
REPX {pmulld x, m4}, m0, m1, m2, m3
REPX {paddd x, m5}, m0, m1, m2, m3
REPX {psrad x, 12}, m0, m1, m2, m3
jmp tx2q
.pass2:
vpbroadcastd m6, [pixel_10bpc_max]
call .pass2_end
RET
ALIGN function_align
.pass2_end:
vpbroadcastd m4, [pw_4096]
packssdw m0, m2
packssdw m1, m3
punpckhwd m2, m0, m1
punpcklwd m0, m1
pmulhrsw m2, m4
pmulhrsw m0, m4
punpckhdq m1, m0, m2 ; 2 3 6 7
punpckldq m0, m2 ; 0 1 4 5
lea r3, [strideq*3]
lea r6, [dstq+strideq*4]
movq xm2, [dstq+strideq*0]
movhps xm2, [dstq+strideq*1]
vpbroadcastq m4, [r6 +strideq*0]
vpbroadcastq m5, [r6 +strideq*1]
movq xm3, [dstq+strideq*2]
movhps xm3, [dstq+r3 ]
vpblendd m2, m4, 0x30
vpblendd m2, m5, 0xc0
vpbroadcastq m4, [r6 +strideq*2]
vpbroadcastq m5, [r6 +r3 ]
vpblendd m3, m4, 0x30
vpblendd m3, m5, 0xc0
pxor m4, m4
REPX {mova [cq+32*x], m4}, 0, 1, 2, 3
paddw m0, m2 ; out0 out1 out4 out5
paddw m1, m3 ; out2 out3 out6 out7
pmaxsw m0, m4
pmaxsw m1, m4
pminsw m0, m6
pminsw m1, m6
vextracti128 xm2, m0, 1 ; out4 out5
vextracti128 xm3, m1, 1 ; out6 out7
movq [dstq+strideq*0], xm0
movhps [dstq+strideq*1], xm0
movq [dstq+strideq*2], xm1
movhps [dstq+r3 ], xm1
movq [r6 +strideq*0], xm2
movhps [r6 +strideq*1], xm2
movq [r6 +strideq*2], xm3
movhps [r6 +r3 ], xm3
ret
INV_TXFM_4X8_FN dct, dct, 12
INV_TXFM_4X8_FN dct, identity, 12
INV_TXFM_4X8_FN dct, adst, 12
INV_TXFM_4X8_FN dct, flipadst, 12
cglobal idct_4x8_internal_12bpc, 0, 7, 10, dst, stride, c, eob, tx2
jmp m(idct_4x8_internal_10bpc).pass1
.pass2:
vpbroadcastd m8, [clip_18b_min]
vpbroadcastd m9, [clip_18b_max]
REPX {pmaxsd x, m8}, m0, m1, m2, m3
REPX {pminsd x, m9}, m0, m1, m2, m3
; transpose & interleave
pshufd m0, m0, q1320
pshufd m1, m1, q1320
pshufd m2, m2, q1320
pshufd m3, m3, q1320
punpckldq m4, m0, m1
punpckhdq m0, m1
punpckldq m5, m2, m3
punpckhdq m2, m3
vpermq m0, m0, q3102
vpermq m2, m2, q3102
vperm2i128 m1, m0, m2, 0x31 ; 1 5 (interleaved)
vperm2i128 m3, m0, m2, 0x20 ; 7 3 (interleaved)
vperm2i128 m0, m4, m5, 0x20 ; 0 2 (interleaved)
vperm2i128 m2, m4, m5, 0x31 ; 4 6 (interleaved)
vpbroadcastd m7, [pd_2048]
call m(idct_8x4_internal_10bpc).main
psubd m3, m0, m4 ; out7 out6
paddd m0, m4 ; out0 out1
paddd m1, m2, m5 ; out3 out2
psubd m2, m5 ; out4 out5
pshufd m1, m1, q1032
pshufd m3, m3, q1032
jmp m(iadst_4x8_internal_12bpc).end
INV_TXFM_4X8_FN adst, dct, 12
INV_TXFM_4X8_FN adst, adst, 12
INV_TXFM_4X8_FN adst, flipadst, 12
INV_TXFM_4X8_FN adst, identity, 12
cglobal iadst_4x8_internal_12bpc, 0, 7, 10, dst, stride, c, eob, tx2
jmp m(iadst_4x8_internal_10bpc).pass1
.pass2:
vpbroadcastd m8, [clip_18b_min]
vpbroadcastd m9, [clip_18b_max]
REPX {pmaxsd x, m8}, m0, m1, m2, m3
REPX {pminsd x, m9}, m0, m1, m2, m3
call .pass2_main
vpblendd m3, m0, m4, 0x33 ; out6 out7
vpblendd m0, m4, 0xcc ; out0 out1
pshufd m1, m5, q1032
psignd m2, m6 ; out4 out5
psignd m1, m6 ; out2 out3
.end:
vpbroadcastd m4, [pw_16384]
REPX {psrad x, 3}, m0, m1, m2, m3
packssdw m0, m2 ; 0 1 4 5 (interleaved)
packssdw m1, m3 ; 2 3 6 7 (interleaved)
mova m2, [iadst8_12_shuf]
vpermd m0, m2, m0 ; 0 1 4 5
vpermd m1, m2, m1 ; 2 3 6 7
pmulhrsw m0, m4
pmulhrsw m1, m4
lea r3, [strideq*3]
lea r6, [dstq+strideq*4]
movq xm4, [dstq+strideq*0]
movhps xm4, [dstq+strideq*1]
movq xm5, [dstq+strideq*2]
movhps xm5, [dstq+r3 ]
movq xm6, [r6 +strideq*0]
movhps xm6, [r6 +strideq*1]
vinserti128 m4, xm6, 1
movq xm7, [r6 +strideq*2]
movhps xm7, [r6 +r3 ]
vinserti128 m5, xm7, 1
paddw m0, m4 ; 0 1 4 5
paddw m1, m5 ; 2 3 6 7
vpbroadcastd m5, [pixel_12bpc_max]
pxor m4, m4
REPX {mova [cq+32*x], m4}, 0, 1, 2, 3
REPX {pmaxsw x, m4}, m0, m1
REPX {pminsw x, m5}, m0, m1
vextracti128 xm2, m0, 1 ; out4 out5
vextracti128 xm3, m1, 1 ; out6 out7
movq [dstq+strideq*0], xm0
movhps [dstq+strideq*1], xm0
movq [dstq+strideq*2], xm1
movhps [dstq+r3 ], xm1
movq [r6 +strideq*0], xm2
movhps [r6 +strideq*1], xm2
movq [r6 +strideq*2], xm3
movhps [r6 +r3 ], xm3
RET
ALIGN function_align
.pass2_main:
; transpose & interleave
pshufd m0, m0, q1320
pshufd m1, m1, q1320
pshufd m2, m2, q1320
pshufd m3, m3, q1320
punpckldq m4, m0, m1
punpckhdq m0, m1
punpckldq m5, m2, m3
punpckhdq m2, m3
vperm2i128 m1, m0, m2, 0x31 ; 7 5 (interleaved)
vperm2i128 m3, m0, m2, 0x20 ; 3 1 (interleaved)
vperm2i128 m0, m4, m5, 0x20 ; 0 2 (interleaved)
vperm2i128 m2, m4, m5, 0x31 ; 4 6 (interleaved)
vpbroadcastd m7, [pd_2048]
jmp m(iadst_4x8_internal_10bpc).main3
INV_TXFM_4X8_FN flipadst, dct, 12
INV_TXFM_4X8_FN flipadst, adst, 12
INV_TXFM_4X8_FN flipadst, flipadst, 12
INV_TXFM_4X8_FN flipadst, identity, 12
cglobal iflipadst_4x8_internal_12bpc, 0, 7, 10, dst, stride, c, eob, tx2
jmp m(iflipadst_4x8_internal_10bpc).pass1
.pass2:
vpbroadcastd m8, [clip_18b_min]
vpbroadcastd m9, [clip_18b_max]
REPX {pmaxsd x, m8}, m0, m1, m2, m3
REPX {pminsd x, m9}, m0, m1, m2, m3
call m(iadst_4x8_internal_12bpc).pass2_main
shufpd m3, m4, m0, 0x05 ; out1 out0
shufpd m0, m4, 0x05 ; out7 out6
psignd m2, m6
pshufd m6, m6, q1032
pshufd m1, m2, q1032 ; out5 out4
psignd m2, m5, m6 ; out3 out2
jmp m(iadst_4x8_internal_12bpc).end
INV_TXFM_4X8_FN identity, dct, 12
INV_TXFM_4X8_FN identity, adst, 12
INV_TXFM_4X8_FN identity, flipadst, 12
INV_TXFM_4X8_FN identity, identity, 12
cglobal iidentity_4x8_internal_12bpc, 0, 7, 10, dst, stride, c, eob, tx2
jmp m(iidentity_4x8_internal_10bpc).pass1
.pass2:
; m0 = in0 in1
; m1 = in2 in3
; m2 = in4 in5
; m3 = in6 in7
vpbroadcastd m6, [pixel_12bpc_max]
call m(iidentity_4x8_internal_10bpc).pass2_end
RET
%macro INV_TXFM_4X16_FN 2-3 10 ; type1, type2, bitdepth
INV_TXFM_FN %1, %2, 0, 4x16, %3
%ifidn %1_%2, dct_dct
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 16
add r6d, 6144
sar r6d, 13
jmp m(inv_txfm_add_dct_dct_4x8_%3bpc).end
%endif
%endmacro
INV_TXFM_4X16_FN dct, dct
INV_TXFM_4X16_FN dct, identity
INV_TXFM_4X16_FN dct, adst
INV_TXFM_4X16_FN dct, flipadst
cglobal idct_4x16_internal_10bpc, 0, 7, 11, dst, stride, c, eob, tx2
.pass1:
vpbroadcastd m10, [pd_6144]
mova m1, [cq+32*2]
mova m3, [cq+32*6]
mova m5, [cq+32*3]
mova m7, [cq+32*7]
call .pass1_main
pmulld m0, m6, [cq+32*0]
pmulld m2, m6, [cq+32*4]
pmulld m4, m6, [cq+32*1]
pmulld m6, [cq+32*5]
call .pass1_main2
REPX {psrad x, 1}, m0, m1, m2, m3, m4, m5, m6, m7
jmp tx2q
.pass2:
packssdw m0, m4
packssdw m1, m5
packssdw m2, m6
packssdw m3, m7
lea r6, [deint_shuf+128]
punpcklwd m4, m2, m3
punpckhwd m2, m3
punpckhwd m5, m0, m1
punpcklwd m0, m1
punpckhdq m1, m0, m4 ; 2 3
punpckldq m0, m4 ; 0 1
punpckldq m4, m5, m2 ; 8 9
punpckhdq m5, m2 ; a b
vextracti128 xm2, m0, 1 ; 4 5
vextracti128 xm3, m1, 1 ; 6 7
vextracti128 xm6, m4, 1 ; c d
vextracti128 xm7, m5, 1 ; e f
call m(idct_4x16_internal_8bpc).main
vpbroadcastd m9, [pw_2048]
vinserti128 m0, m0, xm1, 1 ; 0 1 3 2
vinserti128 m1, m2, xm3, 1 ; 4 5 7 6
vinserti128 m2, m4, xm5, 1 ; 8 9 b a
vinserti128 m3, m6, xm7, 1 ; c d f e
vpbroadcastd m8, [pixel_10bpc_max]
call .pass2_end
RET
ALIGN function_align
.pass1_main:
vpbroadcastd m4, [pd_3784]
vpbroadcastd m8, [pd_1567]
vpbroadcastd m9, [pd_2048]
vpbroadcastd m6, [pd_2896]
ITX_MULSUB_2D 1, 3, 0, 2, _, 9, 8, 4 ; t2l, t3l
ITX_MULSUB_2D 5, 7, 4, 2, _, 9, 8, 4 ; t2h, t3h
ret
ALIGN function_align
.pass1_main2:
paddd m0, m10
paddd m4, m10
paddd m8, m0, m2
psubd m0, m2
paddd m9, m4, m6
psubd m4, m6
REPX {psrad x, 12}, m8, m0, m9, m4 ; t0l, t1l, t0h, t1h
psubd m2, m0, m1
paddd m1, m0
psubd m6, m4, m5
paddd m5, m4
paddd m0, m8, m3
psubd m3, m8, m3
paddd m4, m9, m7
psubd m7, m9, m7
ret
ALIGN function_align
.pass2_end:
lea r6, [strideq*3]
pxor m7, m7
pmulhrsw m0, m9
call .write_4x4
pmulhrsw m0, m1, m9
call .write_4x4
pmulhrsw m0, m2, m9
call .write_4x4
pmulhrsw m0, m3, m9
call .write_4x4
ret
ALIGN function_align
.write_4x4:
movq xm4, [dstq+strideq*0]
movhps xm4, [dstq+strideq*1]
vpbroadcastq m5, [dstq+strideq*2]
vpbroadcastq m6, [dstq+r6 ]
mova [cq+32*0], m7
mova [cq+32*1], m7
add cq, 32*2
vpblendd m4, m5, 0xc0
vpblendd m4, m6, 0x30
paddw m4, m0
pmaxsw m4, m7
pminsw m4, m8
vextracti128 xm5, m4, 1
movq [dstq+strideq*0], xm4
movhps [dstq+strideq*1], xm4
movhps [dstq+strideq*2], xm5
movq [dstq+r6 ], xm5
lea dstq, [dstq+strideq*4]
ret
INV_TXFM_4X16_FN adst, dct
INV_TXFM_4X16_FN adst, adst
INV_TXFM_4X16_FN adst, flipadst
INV_TXFM_4X16_FN adst, identity
cglobal iadst_4x16_internal_10bpc, 0, 7, 11, dst, stride, c, eob, tx2
.pass1:
call m(iadst_16x4_internal_10bpc).main
vpbroadcastd m6, [pd_6144]
call m(iadst_16x4_internal_10bpc).main_end
psrad m0, m4, 13
psrad m1, m5, 13
psrad m2, 13
psrad m3, 13
psrad m4, m8, 13
psrad m5, m9, 13
psrad m6, 13
psrad m7, 13
jmp tx2q
.pass2:
call .pass2_main
vpbroadcastd m5, [pw_2048]
vpbroadcastd m8, [pixel_10bpc_max]
lea r6, [strideq*3]
vpblendd m4, m3, m0, 0xcc ; -out3 out0 out2 -out1
pshufd m2, m2, q1032 ; -out11 out8 out10 -out9
vpblendd m3, m0, 0x33 ; -out15 out12 out14 -out13
pxor m7, m7
psubw m9, m7, m5
vpblendd m9, m5, 0x3c ; -2048 2048 2048 -2048
pmulhrsw m0, m4, m9
call .write_4x4
pmulhrsw m0, m1, m9
call .write_4x4
pmulhrsw m0, m2, m9
call .write_4x4
pmulhrsw m0, m3, m9
call .write_4x4
RET
ALIGN function_align
.write_4x4:
movq xm4, [dstq+r6 ]
movhps xm4, [dstq+strideq*0]
vpbroadcastq m5, [dstq+strideq*1]
vpbroadcastq m6, [dstq+strideq*2]
mova [cq+32*0], m7
mova [cq+32*1], m7
add cq, 32*2
vpblendd m4, m5, 0xc0
vpblendd m4, m6, 0x30
paddw m4, m0
pmaxsw m4, m7
pminsw m4, m8
vextracti128 xm5, m4, 1
movhps [dstq+strideq*0], xm4
movhps [dstq+strideq*1], xm5
movq [dstq+strideq*2], xm5
movq [dstq+r6 ], xm4
lea dstq, [dstq+strideq*4]
ret
ALIGN function_align
.pass2_main:
packssdw m0, m4
packssdw m1, m5
packssdw m2, m6
packssdw m3, m7
lea r6, [deint_shuf+128]
punpcklwd m4, m2, m3
punpckhwd m2, m3
punpckhwd m5, m0, m1
punpcklwd m0, m1
punpckhdq m1, m0, m4
punpckldq m0, m4
punpckldq m4, m5, m2
punpckhdq m5, m2
vpblendd m3, m0, m1, 0x33
vpblendd m0, m1, 0xcc
shufpd m2, m5, m4, 0x05
shufpd m4, m5, 0x05
vperm2i128 m1, m0, m3, 0x31 ; 4 7 6 5
vinserti128 m0, xm3, 1 ; 0 3 2 1
vperm2i128 m3, m2, m4, 0x31 ; c f e d ; ????
vinserti128 m2, xm4, 1 ; b 8 9 a
call m(iadst_4x16_internal_8bpc).main2
vpbroadcastd m5, [pw_2896x8]
paddsw m1, m2, m4
psubsw m2, m4
pmulhrsw m1, m5 ; -out7 out4 out6 -out5
pmulhrsw m2, m5 ; out8 -out11 -out9 out10
ret
ALIGN function_align
.main:
vbroadcasti128 m0, [cq+16* 0]
vbroadcasti128 m4, [cq+16* 2]
vbroadcasti128 m1, [cq+16*15]
vbroadcasti128 m5, [cq+16*13]
vbroadcasti128 m2, [cq+16* 4]
vbroadcasti128 m6, [cq+16* 6]
vbroadcasti128 m3, [cq+16*11]
vbroadcasti128 m7, [cq+16* 9]
shufpd m0, m4, 0x0c ; 0 2
shufpd m1, m5, 0x0c ; 15 13
shufpd m2, m6, 0x0c ; 4 6
shufpd m3, m7, 0x0c ; 11 9
vbroadcasti128 m4, [cq+16* 8]
vbroadcasti128 m6, [cq+16*10]
vbroadcasti128 m5, [cq+16* 7]
vbroadcasti128 m7, [cq+16* 5]
shufpd m4, m6, 0x0c ; 8 10
shufpd m5, m7, 0x0c ; 7 5
vbroadcasti128 m6, [cq+16*12]
vbroadcasti128 m7, [cq+16*14]
shufpd m6, m7, 0x0c ; 12 14
vbroadcasti128 m7, [cq+16* 3]
vbroadcasti128 m8, [cq+16* 1]
shufpd m7, m8, 0x0c ; 3 1
.main2:
; expects: m12 = clip_min m13 = clip_max
vpbroadcastd m11, [pd_2048]
ITX_MULSUB_2D 1, 0, 8, 9, 10, 11, 201_995, 4091_3973, 1
ITX_MULSUB_2D 3, 2, 8, 9, 10, 11, 1751_2440, 3703_3290, 1
ITX_MULSUB_2D 5, 4, 8, 9, 10, 11, 3035_3513, 2751_2106, 1
ITX_MULSUB_2D 7, 6, 8, 9, 10, 11, 3857_4052, 1380_601, 1
psubd m8, m0, m4 ; t8a t10a
paddd m0, m4 ; t0a t2a
psubd m4, m1, m5 ; t9a t11a
paddd m1, m5 ; t1a t3a
psubd m5, m2, m6 ; t12a t14a
paddd m2, m6 ; t4a t6a
psubd m6, m3, m7 ; t13a t15a
paddd m3, m7 ; t5a t7a
REPX {pmaxsd x, m12}, m0, m1, m2, m3, m4, m5, m6, m8
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m8
ITX_MULSUB_2D 8, 4, 7, 9, 10, 11, 799_3406, 4017_2276, 1
ITX_MULSUB_2D 6, 5, 7, 9, 10, 11, 4017_2276, 10, 1
psubd m7, m0, m2 ; t4 t6
paddd m0, m2 ; t0 t2
psubd m2, m1, m3 ; t5 t7
paddd m1, m3 ; t1 t3
psubd m3, m4, m6 ; t12a t14a
paddd m4, m6 ; t8a t10a
psubd m6, m8, m5 ; t13a t15a
paddd m8, m5 ; t9a t11a
REPX {pmaxsd x, m12}, m0, m1, m2, m3, m4, m6, m7, m8
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m6, m7, m8
punpcklqdq m5, m3, m7 ; t12a t4
punpckhqdq m3, m7 ; t14a t6
punpckhqdq m7, m6, m2 ; t15a t7
punpcklqdq m6, m2 ; t13a t5
ITX_MULSUB_2D 7, 3, 2, 9, 10, 11, 3784, 1567
ITX_MULSUB_2D 5, 6, 2, 9, 10, 11, 1567, 10
vpbroadcastd m10, [pd_2896]
vbroadcasti128 m9, [pw_2048_m2048] ; + + - -
punpckhqdq m2, m4, m0 ; t10a t2
punpcklqdq m4, m0 ; t8a t0
punpckhqdq m0, m8, m1 ; t11a t3
punpcklqdq m8, m1 ; t9a t1
paddd m1, m6, m7 ; out2 -out3
psubd m6, m7 ; t14a t6
paddd m7, m5, m3 ; -out13 out12
psubd m5, m3 ; t15a t7
psubd m3, m8, m0 ; t11 t3a
paddd m8, m0 ; out14 -out15
paddd m0, m4, m2 ; -out1 out0
psubd m4, m2 ; t10 t2a
REPX {pmaxsd x, m12}, m6, m5, m3, m4
REPX {pminsd x, m13}, m6, m5, m3, m4
REPX {pmulld x, m10}, m6, m5, m3, m4
paddd m6, m11
paddd m4, m11
paddd m2, m6, m5 ; -out5 out4
psubd m6, m5 ; out10 -out11
psubd m5, m4, m3 ; -out9 out8
paddd m3, m4 ; out6 -out7
REPX {psrad x, 12}, m2, m3, m5, m6
REPX {psignd x, m9}, m1, m8, m3, m6
pshufd m9, m9, q1032
REPX {psignd x, m9}, m0, m7, m2, m5
ret
INV_TXFM_4X16_FN flipadst, dct
INV_TXFM_4X16_FN flipadst, adst
INV_TXFM_4X16_FN flipadst, flipadst
INV_TXFM_4X16_FN flipadst, identity
cglobal iflipadst_4x16_internal_10bpc, 0, 7, 11, dst, stride, c, eob, tx2
.pass1:
call m(iadst_16x4_internal_10bpc).main
vpbroadcastd m6, [pd_6144]
call m(iadst_16x4_internal_10bpc).main_end
psrad m0, m3, 13
psrad m1, m2, 13
psrad m2, m5, 13
psrad m3, m4, 13
psrad m4, m7, 13
psrad m5, m6, 13
psrad m6, m9, 13
psrad m7, m8, 13
jmp tx2q
.pass2:
call m(iadst_4x16_internal_10bpc).pass2_main
vpbroadcastd m5, [pw_2048]
vpbroadcastd m8, [pixel_10bpc_max]
lea r6, [strideq*3]
vpblendd m4, m3, m0, 0x33 ; -out0 out3 out1 -out2
pshufd m2, m2, q1032 ; -out11 out8 out10 -out9
vpblendd m3, m0, 0xcc ; -out12 out15 out13 -out14
pxor m7, m7
psubw m9, m7, m5
vpblendd m9, m5, 0x3c ; -2048 2048 2048 -2048
pmulhrsw m0, m4, m9
call .write_4x4
pmulhrsw m0, m2, m9
call .write_4x4
pmulhrsw m0, m1, m9
call .write_4x4
pmulhrsw m0, m3, m9
call .write_4x4
RET
ALIGN function_align
.write_4x4:
movq xm4, [dstq+strideq*0]
movhps xm4, [dstq+r6 ]
vpbroadcastq m5, [dstq+strideq*1]
vpbroadcastq m6, [dstq+strideq*2]
mova [cq+32*0], m7
mova [cq+32*1], m7
add cq, 32*2
vpblendd m4, m5, 0x30
vpblendd m4, m6, 0xc0
paddw m4, m0
pmaxsw m4, m7
pminsw m4, m8
vextracti128 xm5, m4, 1
movq [dstq+strideq*0], xm4
movq [dstq+strideq*1], xm5
movhps [dstq+strideq*2], xm5
movhps [dstq+r6 ], xm4
lea dstq, [dstq+strideq*4]
ret
INV_TXFM_4X16_FN identity, dct
INV_TXFM_4X16_FN identity, adst
INV_TXFM_4X16_FN identity, flipadst
INV_TXFM_4X16_FN identity, identity
cglobal iidentity_4x16_internal_10bpc, 0, 7, 11, dst, stride, c, eob, tx2
.pass1:
vpbroadcastd m7, [pd_5793]
pmulld m0, m7, [cq+32*0]
pmulld m4, m7, [cq+32*1]
pmulld m1, m7, [cq+32*2]
pmulld m5, m7, [cq+32*3]
pmulld m2, m7, [cq+32*4]
pmulld m6, m7, [cq+32*5]
pmulld m3, m7, [cq+32*6]
pmulld m7, [cq+32*7]
vpbroadcastd m8, [pd_6144]
REPX {paddd x, m8}, m0, m4, m1, m5, m2, m6, m3, m7
REPX {psrad x, 13}, m0, m4, m1, m5, m2, m6, m3, m7
jmp tx2q
.pass2:
packssdw m0, m4
packssdw m1, m5
packssdw m2, m6
packssdw m3, m7
vpbroadcastd m7, [pw_1697x16]
vpbroadcastd m8, [pw_2048]
pmulhrsw m4, m7, m0
pmulhrsw m5, m7, m1
pmulhrsw m6, m7, m2
pmulhrsw m7, m3
REPX {paddsw x, x}, m0, m1, m2, m3
paddsw m0, m4
paddsw m1, m5
paddsw m2, m6
paddsw m3, m7
vpbroadcastd m4, [pixel_10bpc_max]
call .pass2_end
RET
ALIGN function_align
.pass2_end:
punpckhwd m7, m0, m1
punpcklwd m0, m1
punpckhwd m1, m2, m3
punpcklwd m2, m3
lea r6, [strideq*5]
pxor m3, m3
punpckhdq m5, m0, m2 ; 2 3 6 7
punpckldq m0, m2 ; 0 1 4 5
punpckldq m6, m7, m1 ; 8 9 c d
punpckhdq m7, m1 ; a b e f
pmulhrsw m0, m8
call .write_2x4x2
pmulhrsw m0, m5, m8
call .write_2x4x2
pmulhrsw m0, m6, m8
lea dstq, [dstq+strideq*4]
call .write_2x4x2
pmulhrsw m0, m7, m8
call .write_2x4x2
ret
ALIGN function_align
.write_2x4x2:
movq xm1, [dstq+strideq*0]
movhps xm1, [dstq+strideq*1]
vpbroadcastq m2, [dstq+strideq*4]
vpblendd m1, m2, 0x30
vpbroadcastq m2, [dstq+r6 ]
vpblendd m1, m2, 0xc0
mova [cq+32*0], m3
mova [cq+32*1], m3
add cq, 32*2
paddw m1, m0
pmaxsw m1, m3
pminsw m1, m4
vextracti128 xm2, m1, 1
movq [dstq+strideq*0], xm1
movhps [dstq+strideq*1], xm1
movq [dstq+strideq*4], xm2
movhps [dstq+r6 ], xm2
lea dstq, [dstq+strideq*2]
ret
INV_TXFM_4X16_FN dct, dct, 12
INV_TXFM_4X16_FN dct, identity, 12
INV_TXFM_4X16_FN dct, adst, 12
INV_TXFM_4X16_FN dct, flipadst, 12
cglobal idct_4x16_internal_12bpc, 0, 7, 14, dst, stride, c, eob, tx2
jmp m(idct_4x16_internal_10bpc).pass1
.pass2:
punpckldq m8, m0, m1
punpckhdq m0, m1
punpckldq m9, m2, m3
punpckhdq m2, m3
punpckldq m1, m4, m5
punpckhdq m4, m5
punpckldq m3, m6, m7
punpckhdq m6, m7
punpcklqdq m5, m0, m2 ; 2 6
punpckhqdq m12, m0, m2 ; 3 7
punpcklqdq m0, m8, m9 ; 0 4
punpckhqdq m10, m8, m9 ; 1 5
punpcklqdq m2, m1, m3 ; 8 12
punpckhqdq m13, m1, m3 ; 9 13
punpcklqdq m9, m4, m6 ; 10 14
punpckhqdq m4, m6 ; 11 15
vperm2i128 m1, m5, m9, 0x20 ; 2 10
vperm2i128 m3, m9, m5, 0x31 ; 14 6
vpermq m11, m4, q1302 ; 15 11
; interleave
REPX {vpermq x, x, q3120}, m0, m1, m2, m3, m10
vpbroadcastd m8, [clip_18b_min]
vpbroadcastd m9, [clip_18b_max]
REPX {pmaxsd x, m8}, m0, m1, m2, m3, m10, m11, m12, m13
REPX {pminsd x, m9}, m0, m1, m2, m3, m10, m11, m12, m13
call m(idct_16x4_internal_10bpc).pass1_main
vpermq m6, m12, q1302 ; 7 3
vpermq m5, m13, q3120 ; 9 13
call m(idct_16x4_internal_10bpc).pass1_main2
call m(idct_16x4_internal_10bpc).pass1_main3
REPX {psrad x, 3}, m0, m1, m2, m3, m4, m5, m6, m7
packssdw m0, m1
packssdw m1, m2, m3
packssdw m2, m4, m5
packssdw m3, m6, m7
mova m4, [idct16_12_shuf]
REPX {vpermd x, m4, x}, m0, m1, m2, m3
vpbroadcastd m9, [pw_16384]
vpbroadcastd m8, [pixel_12bpc_max]
call m(idct_4x16_internal_10bpc).pass2_end
RET
INV_TXFM_4X16_FN adst, dct, 12
INV_TXFM_4X16_FN adst, adst, 12
INV_TXFM_4X16_FN adst, flipadst, 12
INV_TXFM_4X16_FN adst, identity, 12
cglobal iadst_4x16_internal_12bpc, 0, 7, 14, dst, stride, c, eob, tx2
jmp m(iadst_4x16_internal_10bpc).pass1
.pass2:
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
REPX {pmaxsd x, m12}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m7
call .transpose_16x4
call m(iadst_4x16_internal_10bpc).main2
pshufd m4, m5, q1032
psrad m5, m6, 3
pshufd m6, m7, q1032
psrad m7, m8, 3
REPX {pshufd x, x, q1032}, m0, m2
REPX {psrad x, 3}, m0, m1, m2, m3, m4, m6
.pass2_end:
packssdw m0, m1
packssdw m1, m2, m3
packssdw m2, m4, m5
packssdw m3, m6, m7
mova m4, [iadst16_12_shuf]
REPX {vpermd x, m4, x}, m0, m1, m2, m3
vpbroadcastd m9, [pw_16384]
vpbroadcastd m8, [pixel_12bpc_max]
lea r6, [strideq*3]
pxor m7, m7
pmulhrsw m0, m9
call m(iadst_4x16_internal_10bpc).write_4x4
pmulhrsw m0, m9, m1
call m(iadst_4x16_internal_10bpc).write_4x4
pmulhrsw m0, m9, m2
call m(iadst_4x16_internal_10bpc).write_4x4
pmulhrsw m0, m9, m3
call m(iadst_4x16_internal_10bpc).write_4x4
RET
ALIGN function_align
.transpose_16x4:
; transpose & interleave
punpckldq m8, m0, m1
punpckhdq m0, m1
punpckldq m9, m2, m3
punpckhdq m2, m3
punpckldq m1, m4, m5
punpckhdq m4, m5
punpckldq m3, m6, m7
punpckhdq m6, m7
punpcklqdq m10, m8, m0
punpckhqdq m0, m8
punpcklqdq m11, m9, m2
punpckhqdq m2, m9
punpcklqdq m8, m1, m4
punpckhqdq m4, m1
punpcklqdq m9, m3, m6
punpckhqdq m6, m3
vperm2i128 m5, m0, m2, 0x31 ; 7 5
vperm2i128 m7, m0, m2, 0x20 ; 3 1
vperm2i128 m0, m10, m11, 0x20 ; 0 2
vperm2i128 m2, m10, m11, 0x31 ; 4 6
vperm2i128 m1, m4, m6, 0x31 ; 15 13
vperm2i128 m3, m4, m6, 0x20 ; 11 9
vperm2i128 m4, m8, m9, 0x20 ; 8 10
vperm2i128 m6, m8, m9, 0x31 ; 12 14
ret
INV_TXFM_4X16_FN flipadst, dct, 12
INV_TXFM_4X16_FN flipadst, adst, 12
INV_TXFM_4X16_FN flipadst, flipadst, 12
INV_TXFM_4X16_FN flipadst, identity, 12
cglobal iflipadst_4x16_internal_12bpc, 0, 7, 14, dst, stride, c, eob, tx2
jmp m(iflipadst_4x16_internal_10bpc).pass1
.pass2:
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
REPX {pmaxsd x, m12}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m7
call m(iadst_4x16_internal_12bpc).transpose_16x4
call m(iadst_4x16_internal_10bpc).main2
pshufd m4, m3, q1032
psrad m3, m5, 3
psrad m5, m2, 3
pshufd m2, m6, q1032
pshufd m6, m1, q1032
psrad m1, m7, 3
psrad m7, m0, 3
pshufd m0, m8, q1032
REPX {psrad x, 3}, m0, m2, m4, m6
jmp m(iadst_4x16_internal_12bpc).pass2_end
INV_TXFM_4X16_FN identity, dct, 12
INV_TXFM_4X16_FN identity, adst, 12
INV_TXFM_4X16_FN identity, flipadst, 12
INV_TXFM_4X16_FN identity, identity, 12
cglobal iidentity_4x16_internal_12bpc, 0, 7, 14, dst, stride, c, eob, tx2
jmp m(iidentity_4x16_internal_10bpc).pass1
.pass2:
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
REPX {pmaxsd x, m12}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m7
vpbroadcastd m8, [pd_11586]
vpbroadcastd m9, [pd_2048]
REPX {pmulld x, m8}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {paddd x, m9}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {psrad x, 15}, m0, m1, m2, m3, m4, m5, m6, m7
packssdw m0, m4
packssdw m1, m5
packssdw m2, m6
packssdw m3, m7
vpbroadcastd m8, [pw_16384]
vpbroadcastd m4, [pixel_12bpc_max]
call m(iidentity_4x16_internal_10bpc).pass2_end
RET
%macro INV_TXFM_8X4_FN 2-3 10 ; type1, type2, bitdepth
INV_TXFM_FN %1, %2, 0, 8x4, %3
%ifidn %1_%2, dct_dct
imul r6d, [cq], 2896
mov [cq], eobd ; 0
add r6d, 2048
sar r6d, 12
imul r6d, 2896
add r6d, 2048
sar r6d, 12
imul r6d, 2896
add r6d, 34816
sar r6d, 16
movd xm0, r6d
vpbroadcastw m0, xm0
.end:
vpbroadcastd m4, [pixel_%3bpc_max]
pxor m3, m3
mova xm1, [dstq+strideq*0]
vinserti128 m1, [dstq+strideq*1], 1
lea r6, [dstq+strideq*2]
mova xm2, [r6 +strideq*0]
vinserti128 m2, [r6 +strideq*1], 1
paddw m1, m0
paddw m2, m0
pmaxsw m1, m3
pmaxsw m2, m3
pminsw m1, m4
pminsw m2, m4
mova [dstq+strideq*0], xm1
vextracti128 [dstq+strideq*1], m1, 1
mova [r6 +strideq*0], xm2
vextracti128 [r6 +strideq*1], m2, 1
RET
%endif
%endmacro
INV_TXFM_8X4_FN dct, dct
INV_TXFM_8X4_FN dct, identity
INV_TXFM_8X4_FN dct, adst
INV_TXFM_8X4_FN dct, flipadst
cglobal idct_8x4_internal_10bpc, 0, 7, 10, dst, stride, c, eob, tx2
vpbroadcastd m8, [clip_18b_min]
vpbroadcastd m9, [clip_18b_max]
.pass1:
vbroadcasti128 m1, [cq+16*1]
vbroadcasti128 m0, [cq+16*5]
vbroadcasti128 m2, [cq+16*3]
vbroadcasti128 m3, [cq+16*7]
vpbroadcastd m6, [pd_2896]
shufpd m1, m0, 0x0c ; 1 5
shufpd m3, m2, 0x0c ; 7 3
vbroadcasti128 m0, [cq+16*0]
vbroadcasti128 m4, [cq+16*2]
vbroadcasti128 m2, [cq+16*4]
vbroadcasti128 m5, [cq+16*6]
vpbroadcastd m7, [pd_2048]
shufpd m0, m4, 0x0c ; 0 2
shufpd m2, m5, 0x0c ; 4 6
REPX {pmulld x, m6}, m1, m3, m0, m2
REPX {paddd x, m7}, m1, m3, m0, m2
REPX {psrad x, 12}, m1, m3, m0, m2
call .main
psubd m3, m0, m4 ; out7 out6 (interleaved)
paddd m0, m4 ; out0 out1 (interleaved)
paddd m1, m2, m5 ; out3 out2 (interleaved)
psubd m2, m5 ; out4 out5 (interleaved)
pshufd m1, m1, q1032
pshufd m3, m3, q1032
jmp tx2q
.pass2:
vbroadcasti128 m4, [deint_shuf]
packssdw m0, m1
packssdw m2, m3
vperm2i128 m1, m0, m2, 0x31
vinserti128 m0, xm2, 1
pshufb m0, m4
pshufb m1, m4
IDCT4_1D_PACKED_WORD 0, 1, 2, 3, 4, 7
vpermq m0, m0, q3120 ; out0 out1
vpermq m2, m1, q2031 ; out2 out3
jmp m(iadst_8x4_internal_10bpc).end
ALIGN function_align
.main:
ITX_MULSUB_2D 1, 3, 4, 5, 6, 7, 799_3406, 4017_2276, 1
IDCT4_1D_PACKED 0, 2, 4, 5, 6, 7
vpbroadcastd m6, [pd_2896]
punpcklqdq m4, m1, m3 ; t4a t7a
punpckhqdq m1, m3 ; t5a t6a
psubd m3, m4, m1 ; t5a t6a
paddd m4, m1 ; t4 t7
REPX {pmaxsd x, m8}, m3, m4, m0, m2
REPX {pminsd x, m9}, m3, m4, m0, m2
pmulld m3, m6
pshufd m1, m3, q1032
paddd m3, m7
psubd m5, m3, m1
paddd m1, m3
psrad m5, 12
psrad m1, 12
vpblendd m5, m4, 0x33 ; t4 t5
punpckhqdq m4, m1 ; t7 t6
ret
INV_TXFM_8X4_FN adst, dct
INV_TXFM_8X4_FN adst, adst
INV_TXFM_8X4_FN adst, flipadst
INV_TXFM_8X4_FN adst, identity
cglobal iadst_8x4_internal_10bpc, 0, 7, 10, dst, stride, c, eob, tx2
call m(iadst_4x8_internal_10bpc).main
vpblendd m3, m0, m4, 0x33 ; out6 out7
vpblendd m0, m4, 0xcc ; out0 out1
pshufd m1, m5, q1032
psignd m2, m6 ; out4 out5
psignd m1, m6 ; out2 out3
jmp tx2q
.pass2:
call .pass2_main
vpermq m0, m0, q3120 ; out0 out1
vpermq m2, m1, q3120 ; out2 out3
.end:
vpbroadcastd m1, [pw_2048]
pmulhrsw m0, m1
pmulhrsw m1, m2
vpbroadcastd m5, [pixel_10bpc_max]
.end2:
mova xm2, [dstq+strideq*0]
vinserti128 m2, [dstq+strideq*1], 1
lea r6, [dstq+strideq*2]
mova xm3, [r6 +strideq*0]
vinserti128 m3, [r6 +strideq*1], 1
pxor m4, m4
REPX {mova [cq+32*x], m4}, 0, 1, 2, 3
paddw m0, m2
paddw m1, m3
pmaxsw m0, m4
pmaxsw m1, m4
pminsw m0, m5
pminsw m1, m5
mova [dstq+strideq*0], xm0
vextracti128 [dstq+strideq*1], m0, 1
mova [r6 +strideq*0], xm1
vextracti128 [r6 +strideq*1], m1, 1
RET
ALIGN function_align
.pass2_main:
vbroadcasti128 m4, [deint_shuf]
packssdw m0, m1
packssdw m2, m3
lea r6, [deint_shuf+128]
vperm2i128 m1, m0, m2, 0x31
vinserti128 m0, xm2, 1
pshufb m0, m4
pshufb m1, m4
jmp m(iadst_8x4_internal_8bpc).main
ALIGN function_align
.main:
vpbroadcastd m1, [pd_2896]
pmulld m0, m1, [cq+32*0]
pmulld m3, m1, [cq+32*3]
pmulld m2, m1, [cq+32*2]
pmulld m1, [cq+32*1]
vpbroadcastd m4, [pd_2048]
REPX {paddd x, m4}, m0, m3, m2, m1
REPX {psrad x, 12}, m0, m3, m2, m1
.main2:
vbroadcasti128 m6, [pd_1321]
vbroadcasti128 m7, [pd_2482]
pmulld m4, m0, m6 ; 1321*in0
pmulld m5, m3, m7 ; 2482*in3
paddd m4, m5 ; 1321*in0 + 2482*in3
pmulld m5, m0, m7 ; 2482*in0
paddd m0, m3 ; in0 + in3
paddd m7, m6 ; pd_3803
pmulld m6, m2 ; 1321*in2
pmulld m3, m7 ; 3803*in3
pmulld m7, m2 ; 3803*in2
psubd m2, m0 ; in2 - in0 - in3
vpbroadcastd m0, [pd_m3344]
psubd m5, m6 ; 2482*in0 - 1321*in2
vpbroadcastd m6, [pd_2048]
psubd m5, m3 ; t1
pmulld m2, m0 ; t2
pmulld m1, m0 ; -t3
paddd m4, m7 ; t0
paddd m5, m6
paddd m3, m4, m5
paddd m4, m6
psubd m4, m1 ; out0 (unshifted)
psubd m5, m1 ; out1 (unshifted)
paddd m2, m6 ; out2 (unshifted)
paddd m3, m1 ; out3 (unshifted)
ret
INV_TXFM_8X4_FN flipadst, dct
INV_TXFM_8X4_FN flipadst, adst
INV_TXFM_8X4_FN flipadst, flipadst
INV_TXFM_8X4_FN flipadst, identity
cglobal iflipadst_8x4_internal_10bpc, 0, 5, 10, dst, stride, c, eob, tx2
call m(iadst_4x8_internal_10bpc).main
shufpd m3, m4, m0, 0x05
shufpd m0, m4, 0x05
psignd m2, m6
pshufd m6, m6, q1032
pshufd m1, m2, q1032
psignd m2, m5, m6
jmp tx2q
.pass2:
call m(iadst_8x4_internal_10bpc).pass2_main
vpermq m2, m0, q2031
vpermq m0, m1, q2031
jmp m(iadst_8x4_internal_10bpc).end
INV_TXFM_8X4_FN identity, dct
INV_TXFM_8X4_FN identity, adst
INV_TXFM_8X4_FN identity, flipadst
INV_TXFM_8X4_FN identity, identity
cglobal iidentity_8x4_internal_10bpc, 0, 7, 10, dst, stride, c, eob, tx2
.pass1:
vpbroadcastd m4, [pd_2896]
vpermq m0, [cq+32*0], q3120
vpermq m1, [cq+32*1], q3120
vpermq m2, [cq+32*2], q3120
vpermq m3, [cq+32*3], q3120
vpbroadcastd m7, [pd_2048]
REPX {pmulld x, m4}, m0, m1, m2, m3
REPX {paddd x, m7}, m0, m1, m2, m3
REPX {psrad x, 12}, m0, m1, m2, m3
REPX {paddd x, x }, m0, m1, m2, m3
jmp tx2q
.pass2:
vpbroadcastd m5, [pixel_10bpc_max]
vpbroadcastd m4, [pw_1697x8]
packssdw m0, m1
packssdw m2, m3
pmulhrsw m1, m4, m0
pmulhrsw m4, m2
paddsw m0, m1
paddsw m2, m4
packssdw m7, m7 ; pw_2048
.pass2_end:
punpckhwd m1, m0, m2
punpcklwd m0, m2
lea r6, [dstq+strideq*2]
punpckhwd m2, m0, m1
punpcklwd m0, m1
pmulhrsw m2, m7
pmulhrsw m0, m7
punpckhwd m1, m0, m2
punpcklwd m0, m2
mova xm2, [dstq+strideq*0]
vinserti128 m2, [r6 +strideq*0], 1
mova xm3, [dstq+strideq*1]
vinserti128 m3, [r6 +strideq*1], 1
pxor m4, m4
REPX {mova [cq+32*x], m4}, 0, 1, 2, 3
paddw m0, m2
paddw m1, m3
pmaxsw m0, m4
pmaxsw m1, m4
pminsw m0, m5
pminsw m1, m5
mova [dstq+strideq*0], xm0
mova [dstq+strideq*1], xm1
vextracti128 [r6 +strideq*0], m0, 1
vextracti128 [r6 +strideq*1], m1, 1
RET
INV_TXFM_8X4_FN dct, dct, 12
INV_TXFM_8X4_FN dct, identity, 12
INV_TXFM_8X4_FN dct, adst, 12
INV_TXFM_8X4_FN dct, flipadst, 12
cglobal idct_8x4_internal_12bpc, 0, 7, 10, dst, stride, c, eob, tx2
vpbroadcastd m8, [clip_20b_min]
vpbroadcastd m9, [clip_20b_max]
jmp m(idct_8x4_internal_10bpc).pass1
.pass2:
vpbroadcastd m8, [clip_18b_min]
vpbroadcastd m9, [clip_18b_max]
REPX {pmaxsd x, m8}, m0, m1, m2, m3
REPX {pminsd x, m9}, m0, m1, m2, m3
call m(iadst_8x4_internal_12bpc).transpose_4x8
IDCT4_1D 0, 1, 2, 3, 4, 5, 6, 7
jmp m(iadst_8x4_internal_12bpc).end
INV_TXFM_8X4_FN adst, dct, 12
INV_TXFM_8X4_FN adst, adst, 12
INV_TXFM_8X4_FN adst, flipadst, 12
INV_TXFM_8X4_FN adst, identity, 12
cglobal iadst_8x4_internal_12bpc, 0, 7, 10, dst, stride, c, eob, tx2
vpbroadcastd m8, [clip_20b_min]
vpbroadcastd m9, [clip_20b_max]
call m(iadst_4x8_internal_10bpc).main2
vpblendd m3, m0, m4, 0x33 ; out6 out7
vpblendd m0, m4, 0xcc ; out0 out1
pshufd m1, m5, q1032
psignd m2, m6 ; out4 out5
psignd m1, m6 ; out2 out3
jmp tx2q
.pass2:
vpbroadcastd m8, [clip_18b_min]
vpbroadcastd m9, [clip_18b_max]
REPX {pmaxsd x, m8}, m0, m1, m2, m3
REPX {pminsd x, m9}, m0, m1, m2, m3
call .pass2_main
psrad m0, m4, 12
psrad m1, m5, 12
psrad m2, 12
psrad m3, 12
.end:
vpbroadcastd m4, [pw_16384]
REPX {psrad x, 3}, m0, m1, m2, m3
packssdw m0, m1
packssdw m2, m3
pmulhrsw m0, m4
pmulhrsw m1, m2, m4
vpermq m0, m0, q3120 ; out0 out1
vpermq m1, m1, q3120 ; out2 out3
vpbroadcastd m5, [pixel_12bpc_max]
jmp m(iadst_8x4_internal_10bpc).end2
ALIGN function_align
.pass2_main:
call .transpose_4x8
jmp m(iadst_8x4_internal_10bpc).main2
ALIGN function_align
.transpose_4x8:
; deinterleave
pshufd m0, m0, q3120
pshufd m1, m1, q3120
pshufd m2, m2, q3120
pshufd m3, m3, q3120
; transpose
punpcklqdq m4, m0, m1
punpckhqdq m0, m1
punpcklqdq m5, m2, m3
punpckhqdq m2, m3
vperm2i128 m1, m0, m2, 0x20 ; out1
vperm2i128 m3, m0, m2, 0x31 ; out3
vperm2i128 m2, m4, m5, 0x31 ; out2
vperm2i128 m0, m4, m5, 0x20 ; out0
ret
INV_TXFM_8X4_FN flipadst, dct, 12
INV_TXFM_8X4_FN flipadst, adst, 12
INV_TXFM_8X4_FN flipadst, flipadst, 12
INV_TXFM_8X4_FN flipadst, identity, 12
cglobal iflipadst_8x4_internal_12bpc, 0, 5, 10, dst, stride, c, eob, tx2
vpbroadcastd m8, [clip_20b_min]
vpbroadcastd m9, [clip_20b_max]
call m(iadst_4x8_internal_10bpc).main2
shufpd m3, m4, m0, 0x05
shufpd m0, m4, 0x05
psignd m2, m6
pshufd m6, m6, q1032
pshufd m1, m2, q1032
psignd m2, m5, m6
jmp tx2q
.pass2:
vpbroadcastd m8, [clip_18b_min]
vpbroadcastd m9, [clip_18b_max]
REPX {pmaxsd x, m8}, m0, m1, m2, m3
REPX {pminsd x, m9}, m0, m1, m2, m3
call m(iadst_8x4_internal_12bpc).pass2_main
psrad m0, m3, 12
psrad m3, m4, 12
psrad m1, m2, 12
psrad m2, m5, 12
jmp m(iadst_8x4_internal_12bpc).end
INV_TXFM_8X4_FN identity, dct, 12
INV_TXFM_8X4_FN identity, adst, 12
INV_TXFM_8X4_FN identity, flipadst, 12
INV_TXFM_8X4_FN identity, identity, 12
cglobal iidentity_8x4_internal_12bpc, 0, 7, 10, dst, stride, c, eob, tx2
jmp m(iidentity_8x4_internal_10bpc).pass1
.pass2:
; m0 = in0 in1 (interleaved)
; m1 = in2 in3 (interleaved)
; m2 = in4 in5 (interleaved)
; m3 = in6 in7 (interleaved)
vpbroadcastd m8, [clip_18b_min]
vpbroadcastd m9, [clip_18b_max]
REPX {pmaxsd x, m8}, m0, m1, m2, m3
REPX {pminsd x, m9}, m0, m1, m2, m3
vpbroadcastd m4, [pd_5793]
REPX {pmulld x, m4}, m0, m1, m2, m3
REPX {paddd x, m7}, m0, m1, m2, m3
REPX {psrad x, 15}, m0, m1, m2, m3
vpbroadcastd m5, [pixel_12bpc_max]
vpbroadcastd m7, [pw_16384]
packssdw m0, m1
packssdw m2, m3
jmp m(iidentity_8x4_internal_10bpc).pass2_end
%macro INV_TXFM_8X8_FN 2-3 10 ; type1, type2, bitdepth
INV_TXFM_FN %1, %2, 0, 8x8, %3
%ifidn %1_%2, dct_dct
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 8
.dconly:
add r6d, 6144
sar r6d, 13
.dconly2:
imul r6d, 2896
add r6d, 34816
sar r6d, 16
movd xm0, r6d
vpbroadcastw m0, xm0
vpbroadcastd m3, [pixel_%3bpc_max]
pxor m2, m2
.dconly_loop:
mova xm1, [dstq+strideq*0]
vinserti128 m1, [dstq+strideq*1], 1
paddw m1, m0
pmaxsw m1, m2
pminsw m1, m3
mova [dstq+strideq*0], xm1
vextracti128 [dstq+strideq*1], m1, 1
lea dstq, [dstq+strideq*2]
sub r3d, 2
jg .dconly_loop
RET
%endif
%endmacro
%macro IADST8_1D 14 ; src[1-8], tmp[1-3], pd_2048, clip[1-2]
ITX_MULSUB_2D %8, %1, %9, %10, %11, %12, 401, 4076 ; t1a, t0a
ITX_MULSUB_2D %2, %7, %9, %10, %11, %12, 3920, 1189 ; t7a, t6a
ITX_MULSUB_2D %6, %3, %9, %10, %11, %12, 1931, 3612 ; t3a, t2a
ITX_MULSUB_2D %4, %5, %9, %10, %11, %12, 3166, 2598 ; t5a, t4a
psubd m%9, m%3, m%7 ; t6
paddd m%3, m%7 ; t2
psubd m%7, m%1, m%5 ; t4
paddd m%1, m%5 ; t0
psubd m%5, m%6, m%2 ; t7
paddd m%6, m%2 ; t3
psubd m%2, m%8, m%4 ; t5
paddd m%8, m%4 ; t1
REPX {pmaxsd x, m%13}, m%7, m%2, m%9, m%5, m%3, m%1, m%6, m%8
REPX {pminsd x, m%14}, m%7, m%2, m%9, m%5, m%3, m%1, m%6, m%8
ITX_MULSUB_2D %7, %2, %4, %10, %11, %12, 1567, 3784 ; t5a, t4a
ITX_MULSUB_2D %5, %9, %4, %10, %11, %12, 3784, %11 ; t6a, t7a
psubd m%10, m%7, m%9 ; t7
paddd m%7, m%9 ; out6
vpbroadcastd m%9, [pd_2896]
psubd m%4, m%8, m%6 ; t3
paddd m%8, m%6 ; -out7
psubd m%6, m%1, m%3 ; t2
paddd m%1, m%3 ; out0
psubd m%3, m%2, m%5 ; t6
paddd m%2, m%5 ; -out1
REPX {pmaxsd x, m%13}, m%6, m%4, m%3, m%10
REPX {pminsd x, m%14}, m%6, m%4, m%3, m%10
REPX {pmulld x, m%9 }, m%6, m%4, m%3, m%10
psubd m%5, m%6, m%4 ; (t2 - t3) * 2896
paddd m%4, m%6 ; (t2 + t3) * 2896
psubd m%6, m%3, m%10 ; (t6 - t7) * 2896
paddd m%3, m%10 ; (t6 + t7) * 2896
%endmacro
INV_TXFM_8X8_FN dct, dct
INV_TXFM_8X8_FN dct, identity
INV_TXFM_8X8_FN dct, adst
INV_TXFM_8X8_FN dct, flipadst
cglobal idct_8x8_internal_10bpc, 0, 7, 14, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
.pass1:
mova m0, [cq+32*0]
mova m1, [cq+32*1]
mova m2, [cq+32*2]
mova m3, [cq+32*3]
mova m4, [cq+32*4]
mova m5, [cq+32*5]
mova m6, [cq+32*6]
mova m7, [cq+32*7]
vpbroadcastd m11, [pd_2048]
call .main
call .round_shift1
jmp tx2q
.pass2:
call .transpose_8x8_packed
call m(idct_8x8_internal_8bpc).main
vpbroadcastd m12, [pw_2048]
vpermq m0, m0, q3120
vpermq m1, m1, q2031
vpermq m2, m2, q3120
vpermq m3, m3, q2031
pmulhrsw m0, m12
pmulhrsw m1, m12
call .write_8x4_start
pmulhrsw m0, m2, m12
pmulhrsw m1, m3, m12
call .write_8x4
RET
ALIGN function_align
.write_8x4_start:
vpbroadcastd m11, [pixel_10bpc_max]
lea r6, [strideq*3]
pxor m10, m10
.write_8x4:
mova xm8, [dstq+strideq*0]
vinserti128 m8, [dstq+strideq*1], 1
mova xm9, [dstq+strideq*2]
vinserti128 m9, [dstq+r6 ], 1
mova [cq+32*0], m10
mova [cq+32*1], m10
mova [cq+32*2], m10
mova [cq+32*3], m10
add cq, 32*4
paddw m0, m8
paddw m1, m9
pmaxsw m0, m10
pmaxsw m1, m10
pminsw m0, m11
pminsw m1, m11
mova [dstq+strideq*0], xm0
vextracti128 [dstq+strideq*1], m0, 1
mova [dstq+strideq*2], xm1
vextracti128 [dstq+r6 ], m1, 1
lea dstq, [dstq+strideq*4]
ret
ALIGN function_align
.transpose_8x8_packed:
packssdw m0, m4
packssdw m1, m5
packssdw m2, m6
packssdw m3, m7
lea r6, [deint_shuf+128]
punpckhwd m4, m0, m1
punpcklwd m0, m1
punpckhwd m1, m2, m3
punpcklwd m2, m3
punpckhdq m3, m0, m2
punpckldq m0, m2
punpckhdq m2, m4, m1
punpckldq m4, m1
vinserti128 m1, m3, xm2, 1
vperm2i128 m3, m2, 0x31
vperm2i128 m2, m0, m4, 0x31
vinserti128 m0, xm4, 1
ret
ALIGN function_align
.main_rect2:
REPX {paddd x, m11}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {psrad x, 12 }, m0, m1, m2, m3, m4, m5, m6, m7
.main:
ITX_MULSUB_2D 5, 3, 8, 9, 10, 11, 3406, 2276 ; t5a t6a
ITX_MULSUB_2D 1, 7, 8, 9, 10, 11, 799, 4017 ; t4a t7a
ITX_MULSUB_2D 2, 6, 8, 9, 10, 11, 1567, 3784 ; t2 t3
paddd m8, m1, m5 ; t4
psubd m1, m5 ; t5a
paddd m9, m7, m3 ; t7
psubd m7, m3 ; t6a
vpbroadcastd m3, [pd_2896]
REPX {pmaxsd x, m12}, m1, m8, m7, m9
REPX {pminsd x, m13}, m1, m8, m7, m9
REPX {pmulld x, m3 }, m0, m4, m7, m1
paddd m0, m11
paddd m7, m11
psubd m5, m0, m4
paddd m0, m4
psubd m4, m7, m1
paddd m7, m1
REPX {psrad x, 12 }, m5, m0, m4, m7
psubd m3, m0, m6 ; dct4 out3
paddd m0, m6 ; dct4 out0
paddd m6, m5, m2 ; dct4 out1
psubd m5, m2 ; dct4 out2
REPX {pmaxsd x, m12}, m0, m6, m5, m3
REPX {pminsd x, m13}, m0, m6, m5, m3
ret
ALIGN function_align
.round_shift1:
pcmpeqd m1, m1
REPX {psubd x, m1}, m0, m6, m5, m3
paddd m1, m6, m7 ; out1
psubd m6, m7 ; out6
psubd m7, m0, m9 ; out7
paddd m0, m9 ; out0
paddd m2, m5, m4 ; out2
psubd m5, m4 ; out5
psubd m4, m3, m8 ; out4
paddd m3, m8 ; out3
REPX {psrad x, 1 }, m0, m1, m2, m3, m4, m5, m6, m7
ret
INV_TXFM_8X8_FN adst, dct
INV_TXFM_8X8_FN adst, adst
INV_TXFM_8X8_FN adst, flipadst
INV_TXFM_8X8_FN adst, identity
cglobal iadst_8x8_internal_10bpc, 0, 7, 14, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
.pass1:
call .main
call .main_end
jmp tx2q
.pass2:
call m(idct_8x8_internal_10bpc).transpose_8x8_packed
pshufd m4, m0, q1032
pshufd m5, m1, q1032
call m(iadst_8x8_internal_8bpc).main_pass2
vpbroadcastd m5, [pw_2048]
vpbroadcastd xm12, [pw_4096]
psubw m12, m5
REPX {vpermq x, x, q3120}, m0, m1, m2, m3
pmulhrsw m0, m12
pmulhrsw m1, m12
call m(idct_8x8_internal_10bpc).write_8x4_start
pmulhrsw m0, m2, m12
pmulhrsw m1, m3, m12
call m(idct_8x8_internal_10bpc).write_8x4
RET
ALIGN function_align
.main:
mova m0, [cq+32*0]
mova m7, [cq+32*7]
mova m1, [cq+32*1]
mova m6, [cq+32*6]
mova m2, [cq+32*2]
mova m5, [cq+32*5]
mova m3, [cq+32*3]
mova m4, [cq+32*4]
vpbroadcastd m11, [pd_2048]
.main2:
IADST8_1D 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
psrld m8, 11 ; pd_1
vpbroadcastd m9, [pd_6144]
ret
ALIGN function_align
.main_end:
paddd m0, m8
psubd m1, m8, m1
paddd m6, m8
psubd m7, m8, m7
REPX {psrad x, 1 }, m0, m1, m6, m7
; (1 + ((x + 2048) >> 12)) >> 1 = (6144 + x) >> 13
; (1 - ((x + 2048) >> 12)) >> 1 = (6143 - x) >> 13
psubd m8, m9, m8 ; pd_6143
paddd m2, m9
psubd m3, m8, m3
paddd m4, m9
psubd m5, m8, m5
REPX {psrad x, 13}, m2, m3, m4, m5
ret
INV_TXFM_8X8_FN flipadst, dct
INV_TXFM_8X8_FN flipadst, adst
INV_TXFM_8X8_FN flipadst, flipadst
INV_TXFM_8X8_FN flipadst, identity
cglobal iflipadst_8x8_internal_10bpc, 0, 7, 14, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
.pass1:
call m(iadst_8x8_internal_10bpc).main
call .main_end
jmp tx2q
.pass2:
call m(idct_8x8_internal_10bpc).transpose_8x8_packed
pshufd m4, m0, q1032
pshufd m5, m1, q1032
call m(iadst_8x8_internal_8bpc).main_pass2
vpbroadcastd m12, [pw_2048]
vpbroadcastd xm5, [pw_4096]
psubw m12, m5
vpermq m8, m3, q2031
vpermq m9, m2, q2031
vpermq m2, m1, q2031
vpermq m3, m0, q2031
pmulhrsw m0, m8, m12
pmulhrsw m1, m9, m12
call m(idct_8x8_internal_10bpc).write_8x4_start
pmulhrsw m0, m2, m12
pmulhrsw m1, m3, m12
call m(idct_8x8_internal_10bpc).write_8x4
RET
ALIGN function_align
.main_end:
paddd m10, m8, m0
psubd m0, m8, m7
psubd m7, m8, m1
paddd m1, m8, m6
psrad m0, 1
psrad m1, 1
psrad m6, m7, 1
psrad m7, m10, 1
psubd m8, m9, m8 ; pd_6143
psubd m10, m8, m5
paddd m5, m9, m2
psubd m2, m8, m3
paddd m3, m9, m4
psrad m4, m2, 13
psrad m2, m10, 13
psrad m3, 13
psrad m5, 13
ret
INV_TXFM_8X8_FN identity, dct
INV_TXFM_8X8_FN identity, adst
INV_TXFM_8X8_FN identity, flipadst
INV_TXFM_8X8_FN identity, identity
cglobal iidentity_8x8_internal_10bpc, 0, 7, 14, dst, stride, c, eob, tx2
.pass1:
mova m0, [cq+32*0]
mova m1, [cq+32*1]
mova m2, [cq+32*2]
mova m3, [cq+32*3]
mova m4, [cq+32*4]
mova m5, [cq+32*5]
mova m6, [cq+32*6]
mova m7, [cq+32*7]
jmp tx2q
.pass2:
packssdw m3, m7
vpbroadcastd m7, [pixel_10bpc_max]
.pass2_main:
packssdw m0, m4
packssdw m1, m5
packssdw m2, m6
vpbroadcastd m12, [pw_4096]
punpckhwd m4, m0, m1
punpcklwd m0, m1
punpckhwd m1, m2, m3
punpcklwd m2, m3
punpckhdq m3, m0, m2
punpckldq m0, m2
punpckldq m2, m4, m1
punpckhdq m4, m1
punpckhqdq m1, m0, m2 ; 1 5
punpcklqdq m0, m2 ; 0 4
punpcklqdq m2, m3, m4 ; 2 6
punpckhqdq m3, m4 ; 3 7
pmulhrsw m0, m12
pmulhrsw m1, m12
call .write_2x8x2_start
pmulhrsw m0, m2, m12
pmulhrsw m1, m3, m12
call .write_2x8x2_zero
RET
.write_2x8x2_start:
lea r6, [strideq*5]
pxor m6, m6
.write_2x8x2_zero:
mova [cq+32*0], m6
mova [cq+32*1], m6
mova [cq+32*2], m6
mova [cq+32*3], m6
add cq, 32*4
.write_2x8x2:
mova xm4, [dstq+strideq*0]
vinserti128 m4, [dstq+strideq*4], 1
mova xm5, [dstq+strideq*1]
vinserti128 m5, [dstq+r6 ], 1
paddw m0, m4
paddw m1, m5
pmaxsw m0, m6
pmaxsw m1, m6
pminsw m0, m7
pminsw m1, m7
mova [dstq+strideq*0], xm0
mova [dstq+strideq*1], xm1
vextracti128 [dstq+strideq*4], m0, 1
vextracti128 [dstq+r6 ], m1, 1
lea dstq, [dstq+strideq*2]
ret
%macro TRANSPOSE_8X8_DWORD 12 ; src/dst[1-8], tmp[1-4]
punpckldq m%9, m%1, m%2 ; aibj emfn
punpckhdq m%1, m%2 ; ckdl gohp
punpckldq m%10, m%3, m%4 ; qyrz uCvD
punpckhdq m%3, m%4 ; sAtB wExF
punpckldq m%11, m%5, m%6 ; GOHP KSLT
punpckhdq m%5, m%6 ; IQJR MUNV
punpckldq m%12, m%7, m%8 ; WeXf aibj
punpckhdq m%7, m%8 ; YgZh ckdl
punpcklqdq m%2, m%9, m%10 ; aiqy emuC
punpckhqdq m%9, m%10 ; bjrz fnvD
punpcklqdq m%4, m%1, m%3 ; cksA gowE
punpckhqdq m%10, m%1, m%3 ; dltB hpxF
punpcklqdq m%6, m%11, m%12 ; GOWe KSai
punpckhqdq m%11, m%12 ; HPXf LTbj
punpcklqdq m%8, m%5, m%7 ; IQYg MUck
punpckhqdq m%12, m%5, m%7 ; JRZh NVdl
vperm2i128 m%1, m%2, m%6, 0x20 ; out0
vperm2i128 m%5, m%2, m%6, 0x31 ; out4
vperm2i128 m%2, m%9, m%11, 0x20 ; out1
vperm2i128 m%6, m%9, m%11, 0x31 ; out5
vperm2i128 m%3, m%4, m%8, 0x20 ; out2
vperm2i128 m%7, m%4, m%8, 0x31 ; out6
vperm2i128 m%4, m%10, m%12, 0x20 ; out3
vperm2i128 m%8, m%10, m%12, 0x31 ; out7
%endmacro
INV_TXFM_8X8_FN dct, dct, 12
INV_TXFM_8X8_FN dct, identity, 12
INV_TXFM_8X8_FN dct, adst, 12
INV_TXFM_8X8_FN dct, flipadst, 12
cglobal idct_8x8_internal_12bpc, 0, 7, 14, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_20b_min]
vpbroadcastd m13, [clip_20b_max]
jmp m(idct_8x8_internal_10bpc).pass1
.pass2:
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
REPX {pmaxsd x, m12}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m7
call .transpose_8x8
vpbroadcastd m11, [pd_2048]
call m(idct_8x8_internal_10bpc).main
call .round_shift4
jmp m(iadst_8x8_internal_12bpc).pass2_end
ALIGN function_align
.write_8x4_start:
vpbroadcastd m11, [pixel_12bpc_max]
lea r6, [strideq*3]
pxor m10, m10
ret
ALIGN function_align
.transpose_8x8:
TRANSPOSE_8X8_DWORD 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
ret
ALIGN function_align
.round_shift4:
vpbroadcastd m1, [pd_8]
REPX {paddd x, m1}, m0, m6, m5, m3
paddd m1, m6, m7 ; out1
psubd m6, m7 ; out6
psubd m7, m0, m9 ; out7
paddd m0, m9 ; out0
paddd m2, m5, m4 ; out2
psubd m5, m4 ; out5
psubd m4, m3, m8 ; out4
paddd m3, m8 ; out3
REPX {psrad x, 4}, m0, m1, m2, m3, m4, m5, m6, m7
ret
INV_TXFM_8X8_FN adst, dct, 12
INV_TXFM_8X8_FN adst, adst, 12
INV_TXFM_8X8_FN adst, flipadst, 12
INV_TXFM_8X8_FN adst, identity, 12
cglobal iadst_8x8_internal_12bpc, 0, 7, 14, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_20b_min]
vpbroadcastd m13, [clip_20b_max]
jmp m(iadst_8x8_internal_10bpc).pass1
.pass2:
call .pass2_main
.pass2_end:
packssdw m0, m1
packssdw m1, m2, m3
REPX {vpermq x, x, q3120}, m0, m1
call m(idct_8x8_internal_12bpc).write_8x4_start
call m(idct_8x8_internal_10bpc).write_8x4
packssdw m0, m4, m5
packssdw m1, m6, m7
REPX {vpermq x, x, q3120}, m0, m1
call m(idct_8x8_internal_10bpc).write_8x4
RET
ALIGN function_align
.pass2_main:
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
REPX {pmaxsd x, m12}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m7
call m(idct_8x8_internal_12bpc).transpose_8x8
vpbroadcastd m11, [pd_2048]
.pass2_main2:
call m(iadst_8x8_internal_10bpc).main2
pslld m9, m8, 3 ; pd_8
paddd m0, m9
psubd m1, m9, m1 ; 8+x
paddd m6, m9
psubd m7, m9, m7
REPX {psrad x, 4}, m0, m1, m6, m7
vpbroadcastd m9, [pd_34816]
psubd m8, m9, m8 ; 34815
paddd m2, m9
psubd m3, m8, m3
paddd m4, m9
psubd m5, m8, m5
REPX {psrad x, 16}, m2, m3, m4, m5
ret
INV_TXFM_8X8_FN flipadst, dct, 12
INV_TXFM_8X8_FN flipadst, adst, 12
INV_TXFM_8X8_FN flipadst, flipadst, 12
INV_TXFM_8X8_FN flipadst, identity, 12
cglobal iflipadst_8x8_internal_12bpc, 0, 7, 14, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_20b_min]
vpbroadcastd m13, [clip_20b_max]
jmp m(iflipadst_8x8_internal_10bpc).pass1
.pass2:
call m(iadst_8x8_internal_12bpc).pass2_main
packssdw m7, m7, m6
packssdw m6, m1, m0
packssdw m1, m5, m4
vpermq m0, m7, q3120
vpermq m1, m1, q3120
call m(idct_8x8_internal_12bpc).write_8x4_start
call m(idct_8x8_internal_10bpc).write_8x4
packssdw m0, m3, m2
vpermq m0, m0, q3120
vpermq m1, m6, q3120
call m(idct_8x8_internal_10bpc).write_8x4
RET
INV_TXFM_8X8_FN identity, dct, 12
INV_TXFM_8X8_FN identity, adst, 12
INV_TXFM_8X8_FN identity, flipadst, 12
INV_TXFM_8X8_FN identity, identity, 12
cglobal iidentity_8x8_internal_12bpc, 0, 7, 14, dst, stride, c, eob, tx2
jmp m(iidentity_8x8_internal_10bpc).pass1
.pass2:
packssdw m3, m7
vpbroadcastd m7, [pixel_12bpc_max]
jmp m(iidentity_8x8_internal_10bpc).pass2_main
%macro INV_TXFM_8X16_FN 2-4 0,10 ; type1, type2, eob_offset, bitdepth
INV_TXFM_FN %1, %2, %3, 8x16, %4
%ifidn %1_%2, dct_dct
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 16
add r6d, 2048
sar r6d, 12
imul r6d, 2896
jmp m(inv_txfm_add_dct_dct_8x8_%4bpc).dconly
%endif
%endmacro
INV_TXFM_8X16_FN dct, dct
INV_TXFM_8X16_FN dct, identity, 35
INV_TXFM_8X16_FN dct, adst
INV_TXFM_8X16_FN dct, flipadst
cglobal idct_8x16_internal_10bpc, 0, 7, 16, dst, stride, c, eob, tx2
%undef cmp
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
.pass1:
vpbroadcastd m14, [pd_2896]
vpbroadcastd m11, [pd_2048]
cmp eobd, 43
jl .fast
add cq, 32
call .pass1_main
sub cq, 32
mova [cq+32* 1], m0
mova [cq+32* 3], m1
mova [cq+32* 5], m2
mova [cq+32* 7], m3
mova [cq+32* 9], m4
mova [cq+32*11], m5
mova [cq+32*13], m6
mova m15, m7
call .pass1_main
mova m8, [cq+32* 1]
mova m9, [cq+32* 3]
mova m10, [cq+32* 5]
mova m11, [cq+32* 7]
mova m12, [cq+32* 9]
mova m13, [cq+32*11]
mova m14, [cq+32*13]
jmp tx2q
.fast:
call .pass1_main
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14, m15
jmp tx2q
.pass2:
call .transpose
call m(idct_8x16_internal_8bpc).main
vpbroadcastd m12, [pw_2048]
REPX {vpermq x, x, q3120}, m0, m2, m4, m6
REPX {vpermq x, x, q2031}, m1, m3, m5, m7
.end:
pmulhrsw m0, m12
pmulhrsw m1, m12
call m(idct_8x8_internal_10bpc).write_8x4_start
pmulhrsw m0, m2, m12
pmulhrsw m1, m3, m12
call m(idct_8x8_internal_10bpc).write_8x4
pmulhrsw m0, m4, m12
pmulhrsw m1, m5, m12
call m(idct_8x8_internal_10bpc).write_8x4
pmulhrsw m0, m6, m12
pmulhrsw m1, m7, m12
call m(idct_8x8_internal_10bpc).write_8x4
RET
ALIGN function_align
.transpose:
packssdw m0, m8
packssdw m1, m9
packssdw m2, m10
packssdw m3, m11
packssdw m4, m12
packssdw m5, m13
packssdw m6, m14
packssdw m7, m15
lea r6, [deint_shuf+128]
punpckhwd m8, m0, m1
punpcklwd m0, m1
punpckhwd m1, m2, m3
punpcklwd m2, m3
punpcklwd m3, m4, m5
punpckhwd m4, m5
punpckhwd m5, m6, m7
punpcklwd m6, m7
punpckhdq m7, m3, m6
punpckldq m3, m6
punpckhdq m6, m4, m5
punpckldq m4, m5
punpckhdq m5, m8, m1
punpckldq m8, m1
punpckhdq m1, m0, m2
punpckldq m0, m2
vperm2i128 m2, m0, m3, 0x31
vinserti128 m0, xm3, 1
vperm2i128 m3, m1, m7, 0x31
vinserti128 m1, xm7, 1
vperm2i128 m7, m5, m6, 0x31
vinserti128 m5, xm6, 1
vperm2i128 m6, m8, m4, 0x31
vinserti128 m4, m8, xm4, 1
ret
ALIGN function_align
.pass1_main:
pmulld m0, m14, [cq+32* 0]
pmulld m1, m14, [cq+32* 2]
pmulld m2, m14, [cq+32* 4]
pmulld m3, m14, [cq+32* 6]
pmulld m4, m14, [cq+32* 8]
pmulld m5, m14, [cq+32*10]
pmulld m6, m14, [cq+32*12]
pmulld m7, m14, [cq+32*14]
call m(idct_8x8_internal_10bpc).main_rect2
jmp m(idct_8x8_internal_10bpc).round_shift1
ALIGN function_align
.main_evenhalf:
paddd m1, m6, m7 ; idct8 out1
psubd m6, m7 ; idct8 out6
psubd m7, m0, m9 ; idct8 out7
paddd m0, m9 ; idct8 out0
paddd m2, m5, m4 ; idct8 out2
psubd m5, m4 ; idct8 out5
psubd m4, m3, m8 ; idct8 out4
paddd m3, m8 ; idct8 out3
REPX {pmaxsd x, m12}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m7
ret
.main_oddhalf_fast_rect2:
REPX {paddd x, m11}, m0, m1, m2, m3
REPX {psrad x, 12 }, m0, m1, m2, m3
.main_oddhalf_fast: ; lower half zero
vpbroadcastd m7, [pd_4076]
vpbroadcastd m8, [pd_401]
vpbroadcastd m6, [pd_m1189]
vpbroadcastd m9, [pd_3920]
vpbroadcastd m5, [pd_3612]
vpbroadcastd m10, [pd_1931]
vpbroadcastd m4, [pd_m2598]
vpbroadcastd m15, [pd_3166]
pmulld m7, m0
pmulld m0, m8
pmulld m6, m1
pmulld m1, m9
pmulld m5, m2
pmulld m2, m10
pmulld m4, m3
pmulld m3, m15
jmp .main_oddhalf_fast2
.main_oddhalf_rect2:
REPX {paddd x, m11}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {psrad x, 12 }, m0, m1, m2, m3, m4, m5, m6, m7
.main_oddhalf:
ITX_MULSUB_2D 0, 7, 8, 9, 10, _, 401, 4076 ; t8a, t15a
ITX_MULSUB_2D 6, 1, 8, 9, 10, _, 3920, 1189 ; t11a, t12a
ITX_MULSUB_2D 2, 5, 8, 9, 10, _, 1931, 3612 ; t10a, t13a
ITX_MULSUB_2D 4, 3, 8, 9, 10, _, 3166, 2598 ; t9a, t14a
.main_oddhalf_fast2:
REPX {paddd x, m11}, m0, m7, m6, m1, m2, m5, m4, m3
REPX {psrad x, 12 }, m0, m4, m6, m2, m1, m5, m7, m3
psubd m8, m0, m4 ; t9
paddd m0, m4 ; t8
psubd m4, m6, m2 ; t10
paddd m2, m6 ; t11
psubd m6, m1, m5 ; t13
paddd m5, m1 ; t12
psubd m1, m7, m3 ; t14
paddd m7, m3 ; t15
REPX {pmaxsd x, m12}, m8, m1, m4, m6, m0, m2, m5, m7
REPX {pminsd x, m13}, m8, m1, m4, m6, m0, m2, m5, m7
vpbroadcastd m15, [pd_3784]
vpbroadcastd m10, [pd_1567]
ITX_MULSUB_2D 1, 8, 3, 9, _, 11, 10, 15
ITX_MULSUB_2D 6, 4, 3, 9, _, 11, 10, 15, 4
psubd m3, m1, m4 ; t10
paddd m1, m4 ; t9
psubd m4, m0, m2 ; t11a
paddd m0, m2 ; t8a
psubd m2, m8, m6 ; t13
paddd m6, m8 ; t14
psubd m8, m7, m5 ; t12a
paddd m7, m5 ; t15a
REPX {pmaxsd x, m12}, m2, m8, m3, m4, m0, m1, m6, m7
REPX {pminsd x, m13}, m2, m8, m3, m4, m0, m1, m6, m7
REPX {pmulld x, m14}, m2, m8, m3, m4
paddd m2, m11
paddd m8, m11
paddd m5, m2, m3 ; t13a
psubd m2, m3 ; t10a
psubd m3, m8, m4 ; t11
paddd m4, m8 ; t12
REPX {psrad x, 12}, m5, m2, m3, m4
mova [r6-32*4], m7
mova [r6-32*3], m6
mova [r6-32*2], m5
mova [r6-32*1], m4
mova [r6+32*0], m3
mova [r6+32*1], m2
mova [r6+32*2], m1
mova [r6+32*3], m0
ret
INV_TXFM_8X16_FN adst, dct
INV_TXFM_8X16_FN adst, adst
INV_TXFM_8X16_FN adst, flipadst
INV_TXFM_8X16_FN adst, identity, 35
cglobal iadst_8x16_internal_10bpc, 0, 7, 16, dst, stride, c, eob, tx2
%undef cmp
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
.pass1:
vpbroadcastd m14, [pd_2896]
vpbroadcastd m11, [pd_2048]
cmp eobd, 43
jl .fast
add cq, 32
call .pass1_main
call m(iadst_8x8_internal_10bpc).main_end
sub cq, 32
mova [cq+32* 1], m0
mova [cq+32* 3], m1
mova [cq+32* 5], m2
mova [cq+32* 7], m3
mova [cq+32* 9], m4
mova [cq+32*11], m5
mova [cq+32*13], m6
mova m15, m7
call .pass1_main
call m(iadst_8x8_internal_10bpc).main_end
mova m8, [cq+32* 1]
mova m9, [cq+32* 3]
mova m10, [cq+32* 5]
mova m11, [cq+32* 7]
mova m12, [cq+32* 9]
mova m13, [cq+32*11]
mova m14, [cq+32*13]
jmp tx2q
.fast:
call .pass1_main
call m(iadst_8x8_internal_10bpc).main_end
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14, m15
jmp tx2q
.pass2:
call m(idct_8x16_internal_10bpc).transpose
call m(iadst_8x16_internal_8bpc).main
call m(iadst_8x16_internal_8bpc).main_pass2_end
vpbroadcastd m8, [pw_2048]
vpbroadcastd xm12, [pw_4096]
REPX {vpermq x, x, q2031}, m0, m1, m2, m3
REPX {vpermq x, x, q3120}, m4, m5, m6, m7
psubw m12, m8
jmp m(idct_8x16_internal_10bpc).end
ALIGN function_align
.pass1_main:
pmulld m0, m14, [cq+32* 0]
pmulld m7, m14, [cq+32*14]
pmulld m1, m14, [cq+32* 2]
pmulld m6, m14, [cq+32*12]
pmulld m2, m14, [cq+32* 4]
pmulld m5, m14, [cq+32*10]
pmulld m3, m14, [cq+32* 6]
pmulld m4, m14, [cq+32* 8]
REPX {paddd x, m11}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {psrad x, 12 }, m0, m1, m2, m3, m4, m5, m6, m7
jmp m(iadst_8x8_internal_10bpc).main2
INV_TXFM_8X16_FN flipadst, dct
INV_TXFM_8X16_FN flipadst, adst
INV_TXFM_8X16_FN flipadst, flipadst
INV_TXFM_8X16_FN flipadst, identity, 35
cglobal iflipadst_8x16_internal_10bpc, 0, 7, 16, dst, stride, c, eob, tx2
%undef cmp
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
.pass1:
vpbroadcastd m14, [pd_2896]
vpbroadcastd m11, [pd_2048]
cmp eobd, 43
jl .fast
add cq, 32
call m(iadst_8x16_internal_10bpc).pass1_main
call m(iflipadst_8x8_internal_10bpc).main_end
sub cq, 32
mova [cq+32* 1], m0
mova [cq+32* 3], m1
mova [cq+32* 5], m2
mova [cq+32* 7], m3
mova [cq+32* 9], m4
mova [cq+32*11], m5
mova [cq+32*13], m6
mova m15, m7
call m(iadst_8x16_internal_10bpc).pass1_main
call m(iflipadst_8x8_internal_10bpc).main_end
mova m8, [cq+32* 1]
mova m9, [cq+32* 3]
mova m10, [cq+32* 5]
mova m11, [cq+32* 7]
mova m12, [cq+32* 9]
mova m13, [cq+32*11]
mova m14, [cq+32*13]
jmp tx2q
.fast:
call m(iadst_8x16_internal_10bpc).pass1_main
call m(iflipadst_8x8_internal_10bpc).main_end
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14, m15
jmp tx2q
.pass2:
call m(idct_8x16_internal_10bpc).transpose
call m(iadst_8x16_internal_8bpc).main
call m(iadst_8x16_internal_8bpc).main_pass2_end
vpbroadcastd m12, [pw_2048]
vpbroadcastd xm13, [pw_4096]
mova m11, m0
vpermq m0, m7, q2031
mova m10, m1
vpermq m1, m6, q2031
mova m9, m2
vpermq m2, m5, q2031
mova m8, m3
vpermq m3, m4, q2031
vpermq m4, m8, q3120
vpermq m5, m9, q3120
vpermq m6, m10, q3120
vpermq m7, m11, q3120
psubw m12, m13
jmp m(idct_8x16_internal_10bpc).end
INV_TXFM_8X16_FN identity, dct
INV_TXFM_8X16_FN identity, adst
INV_TXFM_8X16_FN identity, flipadst
INV_TXFM_8X16_FN identity, identity
%macro IDTX16 3-4 ; src/dst, tmp, pw_1697x16, [pw_16394]
pmulhrsw m%2, m%3, m%1
%if %0 == 4 ; if downshifting by 1
pmulhrsw m%2, m%4
%else
paddsw m%1, m%1
%endif
paddsw m%1, m%2
%endmacro
cglobal iidentity_8x16_internal_10bpc, 0, 7, 16, dst, stride, c, eob, tx2
.pass1:
vpbroadcastd m15, [pd_2896]
pmulld m0, m15, [cq+32* 0]
pmulld m8, m15, [cq+32* 1]
pmulld m1, m15, [cq+32* 2]
pmulld m9, m15, [cq+32* 3]
pmulld m2, m15, [cq+32* 4]
pmulld m10, m15, [cq+32* 5]
pmulld m3, m15, [cq+32* 6]
pmulld m11, m15, [cq+32* 7]
pmulld m4, m15, [cq+32* 8]
pmulld m12, m15, [cq+32* 9]
pmulld m5, m15, [cq+32*10]
pmulld m13, m15, [cq+32*11]
pmulld m6, m15, [cq+32*12]
pmulld m14, m15, [cq+32*13]
pmulld m7, m15, [cq+32*14]
pmulld m15, [cq+32*15]
mova [cq], m7
vpbroadcastd m7, [pd_2048]
REPX {paddd x, m7}, m0, m1, m2, m3, m4, m5, m6, \
m8, m9, m10, m11, m12, m13, m14, m15
paddd m7, [cq]
REPX {psrad x, 12}, m0, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14, m15
jmp tx2q
.pass2:
packssdw m0, m8
packssdw m1, m9
packssdw m2, m10
packssdw m3, m11
packssdw m4, m12
packssdw m5, m13
packssdw m6, m14
packssdw m13, m7, m15
vpbroadcastd m8, [pw_1697x16]
REPX {IDTX16 x, 9, 8}, 0, 1, 2, 3, 4, 5, 6, 13
vpbroadcastd m7, [pixel_10bpc_max]
vpbroadcastd m12, [pw_2048]
call .pass2_end
RET
ALIGN function_align
.pass2_end:
punpckhwd m9, m0, m1
punpcklwd m0, m1
punpckhwd m1, m6, m13
punpcklwd m6, m13
punpckhwd m13, m4, m5
punpcklwd m4, m5
punpcklwd m5, m2, m3
punpckhwd m2, m3
punpckhdq m3, m0, m5
punpckldq m0, m5
punpckhdq m11, m9, m2
punpckldq m9, m2
punpckldq m2, m4, m6
punpckhdq m4, m6
punpckldq m6, m13, m1
punpckhdq m13, m1
punpckhqdq m1, m0, m2
punpcklqdq m0, m2
punpcklqdq m2, m3, m4
punpckhqdq m3, m4
punpcklqdq m8, m9, m6
punpckhqdq m9, m6
punpcklqdq m10, m11, m13
punpckhqdq m11, m13
pmulhrsw m0, m12
pmulhrsw m1, m12
call m(iidentity_8x8_internal_10bpc).write_2x8x2_start
pmulhrsw m0, m12, m2
pmulhrsw m1, m12, m3
call m(iidentity_8x8_internal_10bpc).write_2x8x2_zero
pmulhrsw m0, m12, m8
pmulhrsw m1, m12, m9
lea dstq, [dstq+strideq*4]
call m(iidentity_8x8_internal_10bpc).write_2x8x2_zero
pmulhrsw m0, m12, m10
pmulhrsw m1, m12, m11
call m(iidentity_8x8_internal_10bpc).write_2x8x2_zero
ret
INV_TXFM_8X16_FN dct, dct, 0, 12
INV_TXFM_8X16_FN dct, identity, 35, 12
INV_TXFM_8X16_FN dct, adst, 0, 12
INV_TXFM_8X16_FN dct, flipadst, 0, 12
cglobal idct_8x16_internal_12bpc, 0, 7, 16, 32*8, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_20b_min]
vpbroadcastd m13, [clip_20b_max]
jmp m(idct_8x16_internal_10bpc).pass1
.pass2:
lea r6, [rsp+32*4]
call .transpose
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
mova [cq+32* 8], m0
mova [cq+32*10], m2
mova [cq+32*12], m4
mova [cq+32*14], m6
pmaxsd m0, m12, [cq+32* 1]
pmaxsd m4, m12, m1
pmaxsd m1, m12, [cq+32* 3]
pmaxsd m2, m12, [cq+32* 5]
pmaxsd m6, m12, m5
pmaxsd m5, m12, m3
pmaxsd m3, m12, [cq+32* 7]
pmaxsd m7, m12
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m7
vpbroadcastd m11, [pd_2048]
vpbroadcastd m14, [pd_2896]
call m(idct_8x16_internal_10bpc).main_oddhalf
pmaxsd m0, m12, [cq+32* 0]
pmaxsd m1, m12, [cq+32* 2]
pmaxsd m2, m12, [cq+32* 4]
pmaxsd m3, m12, [cq+32* 6]
pmaxsd m4, m12, [cq+32* 8]
pmaxsd m5, m12, [cq+32*10]
pmaxsd m6, m12, [cq+32*12]
pmaxsd m7, m12, [cq+32*14]
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m7
call m(idct_8x8_internal_10bpc).main
call m(idct_8x16_internal_10bpc).main_evenhalf
vpbroadcastd m11, [pd_8]
REPX {paddd x, m11}, m0, m1, m2, m3, m4, m5, m6, m7
call m(idct_16x8_internal_10bpc).pass1_rotations
REPX {psrad x, 4}, m0, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14, m15
.end:
packssdw m0, m1
packssdw m1, m2, m3
packssdw m2, m4, m5
packssdw m3, m6, m7
packssdw m4, m8, m9
packssdw m5, m10, m11
packssdw m6, m12, m13
packssdw m7, m14, m15
vpermq m0, m0, q3120
vpermq m1, m1, q3120
call m(idct_8x8_internal_12bpc).write_8x4_start
call m(idct_8x8_internal_10bpc).write_8x4
vpermq m0, m2, q3120
vpermq m1, m3, q3120
call m(idct_8x8_internal_10bpc).write_8x4
vpermq m0, m4, q3120
vpermq m1, m5, q3120
call m(idct_8x8_internal_10bpc).write_8x4
vpermq m0, m6, q3120
vpermq m1, m7, q3120
call m(idct_8x8_internal_10bpc).write_8x4
RET
ALIGN function_align
.transpose:
mova [cq+32* 8], m8
mova [cq+32* 9], m9
mova [cq+32*10], m10
mova [cq+32*11], m11
call m(idct_8x8_internal_12bpc).transpose_8x8
mova [cq+32* 0], m0
mova [cq+32* 1], m1
mova [cq+32* 2], m2
mova [cq+32* 3], m3
mova [cq+32* 4], m4
mova [cq+32* 5], m5
mova [cq+32* 6], m6
mova [cq+32* 7], m7
mova m0, [cq+32* 8]
mova m1, [cq+32* 9]
mova m2, [cq+32*10]
mova m3, [cq+32*11]
mova m4, m12
mova m5, m13
mova m6, m14
mova m7, m15
jmp m(idct_8x8_internal_12bpc).transpose_8x8
INV_TXFM_8X16_FN adst, dct, 0, 12
INV_TXFM_8X16_FN adst, adst, 0, 12
INV_TXFM_8X16_FN adst, flipadst, 0, 12
INV_TXFM_8X16_FN adst, identity, 35, 12
cglobal iadst_8x16_internal_12bpc, 0, 7, 16, 32*8, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_20b_min]
vpbroadcastd m13, [clip_20b_max]
jmp m(iadst_8x16_internal_10bpc).pass1
.pass2:
lea r6, [rsp+32*4]
call .pass2_main
call m(iadst_16x8_internal_10bpc).pass1_rotations
.pass2_end:
REPX {psrad x, 4 }, m0, m1, m2, m3, m12, m13, m14, m15
REPX {psrad x, 16}, m4, m5, m6, m7, m8, m9, m10, m11
jmp m(idct_8x16_internal_12bpc).end
ALIGN function_align
.pass2_main:
call m(idct_8x16_internal_12bpc).transpose
vpbroadcastd m13, [clip_18b_min]
vpbroadcastd m14, [clip_18b_max]
mova [cq+32* 8], m0
mova [cq+32*11], m3
mova [cq+32*12], m4
mova [cq+32*15], m7
pmaxsd m0, m13, [cq+32* 2] ; 2
pmaxsd m3, m13, m1 ; 9
pmaxsd m1, m13, m5 ; 13
pmaxsd m4, m13, m2 ; 10
pmaxsd m2, m13, [cq+32* 6] ; 6
pmaxsd m5, m13, [cq+32* 5] ; 5
pmaxsd m6, m13, m6 ; 14
pmaxsd m7, m13, [cq+32* 1] ; 1
REPX {pminsd x, m14}, m0, m1, m2, m3, m4, m5, m6, m7
vpbroadcastd m12, [pd_2048]
vpbroadcastd m15, [pd_2896]
call m(iadst_16x8_internal_10bpc).main_part1
pmaxsd m0, m13, [cq+32* 0] ; 0
pmaxsd m1, m13, [cq+32*15] ; 15
pmaxsd m2, m13, [cq+32* 4] ; 4
pmaxsd m3, m13, [cq+32*11] ; 11
pmaxsd m4, m13, [cq+32* 8] ; 8
pmaxsd m5, m13, [cq+32* 7] ; 7
pmaxsd m6, m13, [cq+32*12] ; 12
pmaxsd m7, m13, [cq+32* 3] ; 3
REPX {pminsd x, m14}, m0, m1, m2, m3, m4, m5, m6, m7
call m(iadst_16x8_internal_10bpc).main_part2
vpbroadcastd m14, [pd_34816]
psrld m15, 11 ; pd_1
psubd m13, m14, m15 ; pd_34815
pslld m15, 3 ; pd_8
ret
INV_TXFM_8X16_FN flipadst, dct, 0, 12
INV_TXFM_8X16_FN flipadst, adst, 0, 12
INV_TXFM_8X16_FN flipadst, flipadst, 0, 12
INV_TXFM_8X16_FN flipadst, identity, 35, 12
cglobal iflipadst_8x16_internal_12bpc, 0, 7, 16, 32*8, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_20b_min]
vpbroadcastd m13, [clip_20b_max]
jmp m(iflipadst_8x16_internal_10bpc).pass1
.pass2:
lea r6, [rsp+32*4]
call m(iadst_8x16_internal_12bpc).pass2_main
call m(iflipadst_16x8_internal_10bpc).pass1_rotations
jmp m(iadst_8x16_internal_12bpc).pass2_end
INV_TXFM_8X16_FN identity, dct, 0, 12
INV_TXFM_8X16_FN identity, adst, 0, 12
INV_TXFM_8X16_FN identity, flipadst, 0, 12
INV_TXFM_8X16_FN identity, identity, 0, 12
cglobal iidentity_8x16_internal_12bpc, 0, 7, 16, 32*8, dst, stride, c, eob, tx2
jmp m(iidentity_8x16_internal_10bpc).pass1
.pass2:
call .pass2_main
packssdw m0, m8
packssdw m1, m9
packssdw m2, m10
packssdw m3, m11
packssdw m4, m12
packssdw m5, m13
packssdw m6, m14
packssdw m13, m7, m15
vpbroadcastd m7, [pixel_12bpc_max]
vpbroadcastd m12, [pw_16384]
call m(iidentity_8x16_internal_10bpc).pass2_end
RET
ALIGN function_align
.pass2_main:
mova [cq], m7
vpbroadcastd m7, [clip_18b_min]
REPX {pmaxsd x, m7}, m0, m1, m2, m3, m4, m5, m6, \
m8, m9, m10, m11, m12, m13, m14, m15
pmaxsd m7, [cq]
mova [cq], m15
vpbroadcastd m15, [clip_18b_max]
REPX {pminsd x, m15}, m0, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14
pminsd m15, [cq]
mova [cq], m7
vpbroadcastd m7, [pd_11586]
REPX {pmulld x, m7}, m0, m1, m2, m3, m4, m5, m6, \
m8, m9, m10, m11, m12, m13, m14, m15
pmulld m7, [cq]
mova [cq], m15
vpbroadcastd m15, [pd_2048]
REPX {paddd x, m15}, m0, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14
paddd m15, [cq]
REPX {psrad x, 15}, m0, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14, m15
ret
%macro INV_TXFM_16X4_FN 2-3 10 ; type1, type2, bitdepth
INV_TXFM_FN %1, %2, 0, 16x4, %3
%ifidn %1_%2, dct_dct
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 4
.dconly:
add r6d, 6144
sar r6d, 13
.dconly2:
imul r6d, 2896
add r6d, 34816
sar r6d, 16
movd xm0, r6d
vpbroadcastw m0, xm0
vpbroadcastd m4, [pixel_%3bpc_max]
pxor m3, m3
.dconly_loop:
paddw m1, m0, [dstq+strideq*0]
paddw m2, m0, [dstq+strideq*1]
pmaxsw m1, m3
pmaxsw m2, m3
pminsw m1, m4
pminsw m2, m4
mova [dstq+strideq*0], m1
mova [dstq+strideq*1], m2
lea dstq, [dstq+strideq*2]
sub r3d, 2
jg .dconly_loop
RET
%endif
%endmacro
INV_TXFM_16X4_FN dct, dct
INV_TXFM_16X4_FN dct, identity
INV_TXFM_16X4_FN dct, adst
INV_TXFM_16X4_FN dct, flipadst
cglobal idct_16x4_internal_10bpc, 0, 7, 14, dst, stride, c, eob, tx2
vpbroadcastd m8, [clip_18b_min]
vpbroadcastd m9, [clip_18b_max]
.pass1:
vbroadcasti128 m0, [cq+16* 0]
vbroadcasti128 m4, [cq+16* 4]
vbroadcasti128 m1, [cq+16* 2]
vbroadcasti128 m7, [cq+16* 6]
vbroadcasti128 m5, [cq+16*10]
vbroadcasti128 m2, [cq+16* 8]
vbroadcasti128 m6, [cq+16*12]
vbroadcasti128 m3, [cq+16*14]
shufpd m0, m4, 0x0c ; 0 4
shufpd m1, m5, 0x0c ; 2 10
shufpd m2, m6, 0x0c ; 8 12
shufpd m3, m7, 0x0c ; 14 6
call .pass1_main
vbroadcasti128 m10, [cq+16* 1]
vbroadcasti128 m4, [cq+16* 5]
vbroadcasti128 m11, [cq+16*15]
vbroadcasti128 m5, [cq+16*11]
shufpd m10, m4, 0x0c ; 1 5
shufpd m11, m5, 0x0c ; 15 11
vbroadcasti128 m5, [cq+16* 9]
vbroadcasti128 m4, [cq+16*13]
shufpd m5, m4, 0x0c ; 9 13
vbroadcasti128 m6, [cq+16* 7]
vbroadcasti128 m4, [cq+16* 3]
shufpd m6, m4, 0x0c ; 7 3
call .pass1_main2
pcmpeqd m4, m4
REPX {psubd x, m4}, m0, m1, m2, m3
call .pass1_main3
REPX {psrad x, 1 }, m0, m1, m2, m3, m4, m5, m6, m7
jmp tx2q
.pass2:
call .transpose_4x16_packed
lea r6, [deint_shuf+128]
call m(idct_16x4_internal_8bpc).main
.end:
vpbroadcastd m4, [pw_2048]
REPX {pmulhrsw x, m4}, m0, m1, m2, m3
vpbroadcastd m5, [pixel_10bpc_max]
.end2:
paddw m0, [dstq+strideq*0]
paddw m1, [dstq+strideq*1]
.end3:
lea r6, [dstq+strideq*2]
paddw m2, [r6 +strideq*0]
paddw m3, [r6 +strideq*1]
pxor m4, m4
REPX {mova [cq+32*x], m4}, 0, 1, 2, 3, 4, 5, 6, 7
REPX {pmaxsw x, m4}, m0, m1, m2, m3
REPX {pminsw x, m5}, m0, m1, m2, m3
mova [dstq+strideq*0], m0
mova [dstq+strideq*1], m1
mova [r6 +strideq*0], m2
mova [r6 +strideq*1], m3
RET
ALIGN function_align
.pass1_main:
vpbroadcastd m7, [pd_2048]
call m(idct_8x4_internal_10bpc).main
psubd m3, m0, m4 ; idct8 out7 out6
paddd m0, m4 ; idct8 out0 out1
paddd m1, m2, m5 ; idct8 out3 out2
psubd m2, m5 ; idct8 out4 out5
ret
ALIGN function_align
.pass1_main2:
ITX_MULSUB_2D 10, 11, 4, 12, 13, 7, 401_1931, 4076_3612, 1
ITX_MULSUB_2D 5, 6, 4, 12, 13, 7, 3166_3920, 2598_1189, 1
psubd m4, m10, m5 ; t9 -t10
paddd m10, m5 ; t8 t11
psubd m5, m11, m6 ; t14 -t13
paddd m11, m6 ; t15 t12
REPX {pmaxsd x, m8}, m4, m5, m10, m11
REPX {pminsd x, m9}, m4, m5, m10, m11
ITX_MULSUB_2D 5, 4, 6, 12, 13, 7, 1567, 3784, 2
vpbroadcastd m12, [pd_2896]
punpckhqdq m6, m11, m5
punpcklqdq m11, m4
punpckhqdq m4, m10, m4
punpcklqdq m10, m5
psubd m5, m11, m6 ; t12a t13
paddd m11, m6 ; t15a t14
psubd m6, m10, m4 ; t11a t10
paddd m10, m4 ; t8a t9
REPX {pmaxsd x, m8}, m5, m6
REPX {pminsd x, m9}, m5, m6
pmulld m5, m12
pmulld m6, m12
REPX {pmaxsd x, m8}, m0, m1, m2, m3, m11, m10
REPX {pminsd x, m9}, m0, m1, m2, m3, m11, m10
ret
ALIGN function_align
.pass1_main3:
paddd m5, m7
psubd m4, m5, m6
paddd m5, m6
psrad m4, 12 ; t11 t10a
psrad m5, 12 ; t12 t13a
psubd m7, m0, m11 ; out15 out14
paddd m0, m11 ; out0 out1
psubd m6, m1, m5 ; out12 out13
paddd m1, m5 ; out3 out2
psubd m5, m2, m4 ; out11 out10
paddd m2, m4 ; out4 out5
psubd m4, m3, m10 ; out8 out9
paddd m3, m10 ; out7 out6
REPX {pshufd x, x, q1032}, m1, m3, m5, m7
ret
ALIGN function_align
.transpose_4x16_packed:
vbroadcasti128 m8, [deint_shuf]
packssdw m0, m1
packssdw m2, m3
packssdw m4, m5
packssdw m6, m7
REPX {pshufb x, m8}, m0, m2, m4, m6
punpckhqdq m1, m0, m2
punpcklqdq m0, m2
punpckhqdq m2, m4, m6
punpcklqdq m4, m6
vperm2i128 m3, m1, m2, 0x31
vinserti128 m1, xm2, 1
vperm2i128 m2, m0, m4, 0x31
vinserti128 m0, xm4, 1
ret
INV_TXFM_16X4_FN adst, dct
INV_TXFM_16X4_FN adst, adst
INV_TXFM_16X4_FN adst, flipadst
INV_TXFM_16X4_FN adst, identity
cglobal iadst_16x4_internal_10bpc, 0, 7, 14, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
.pass1:
call m(iadst_4x16_internal_10bpc).main
psrad m11, 11 ; pd_1
REPX {paddd x, m11}, m0, m1, m2, m3
paddd m4, m5, m11
paddd m5, m6, m11
paddd m6, m7, m11
paddd m7, m8, m11
.pass1_end:
REPX {pshufd x, x, q1032}, m0, m2, m4, m6
REPX {psrad x, 1}, m0, m1, m2, m3, m4, m5, m6, m7
jmp tx2q
.pass2:
call m(idct_16x4_internal_10bpc).transpose_4x16_packed
lea r6, [deint_shuf+128]
call m(iadst_16x4_internal_8bpc).main
jmp m(idct_16x4_internal_10bpc).end
ALIGN function_align
.main:
vbroadcasti128 m6, [pd_1321]
mova m0, [cq+32*0]
mova m1, [cq+32*1]
vbroadcasti128 m7, [pd_2482]
mova m2, [cq+32*6]
mova m3, [cq+32*7]
pmulld m4, m0, m6
pmulld m5, m1, m6 ; 1321*in0
pmulld m9, m2, m7
pmulld m8, m3, m7 ; 2482*in3
paddd m4, m9
paddd m8, m5 ; 1321*in0 + 2482*in3
pmulld m5, m0, m7
pmulld m9, m1, m7 ; 2482*in0
paddd m0, m2
paddd m1, m3 ; in0 + in3
paddd m7, m6 ; pd_3803
pmulld m2, m7
pmulld m3, m7 ; 3803*in3
psubd m5, m2
psubd m9, m3 ; 2482*in0 - 3803*in3
mova m2, [cq+32*4]
pmulld m10, m7, m2
pmulld m3, m6, m2
psubd m2, m0
mova m0, [cq+32*5]
pmulld m7, m0 ; 3803*in2
pmulld m6, m0 ; 1321*in2
psubd m0, m1 ; in2 - in0 - in3
vpbroadcastd m1, [pd_m3344]
paddd m4, m10
paddd m7, m8 ; t0
psubd m5, m3
psubd m9, m6 ; t1
pmulld m2, m1
pmulld m0, m1 ; t2
pmulld m3, m1, [cq+32*2]
pmulld m1, [cq+32*3] ; -t3
ret
ALIGN function_align
.main_end:
; expects: m6 = rnd
paddd m5, m6
paddd m9, m6
paddd m10, m4, m5
paddd m4, m6
paddd m8, m7, m6
paddd m7, m9
psubd m4, m3 ; out0 (unshifted)
psubd m5, m3 ; out1 (unshifted)
paddd m2, m6 ; out2 (unshifted)
paddd m3, m10 ; out3 (unshifted)
psubd m8, m1 ; out4 (unshifted)
psubd m9, m1 ; out5 (unshifted)
paddd m6, m0 ; out6 (unshifted)
paddd m7, m1 ; out7 (unshifted)
ret
INV_TXFM_16X4_FN flipadst, dct
INV_TXFM_16X4_FN flipadst, adst
INV_TXFM_16X4_FN flipadst, flipadst
INV_TXFM_16X4_FN flipadst, identity
cglobal iflipadst_16x4_internal_10bpc, 0, 7, 14, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
.pass1:
call m(iadst_4x16_internal_10bpc).main
psrad m11, 11 ; pd_1
paddd m4, m3, m11
paddd m3, m5, m11
paddd m5, m2, m11
paddd m2, m6, m11
paddd m6, m1, m11
paddd m1, m7, m11
paddd m7, m0, m11
paddd m0, m8, m11
jmp m(iadst_16x4_internal_10bpc).pass1_end
.pass2:
call m(idct_16x4_internal_10bpc).transpose_4x16_packed
lea r6, [deint_shuf+128]
call m(iadst_16x4_internal_8bpc).main
vpbroadcastd m4, [pw_2048]
pmulhrsw m5, m3, m4
pmulhrsw m6, m2, m4
pmulhrsw m2, m1, m4
pmulhrsw m3, m0, m4
paddw m0, m5, [dstq+strideq*0]
paddw m1, m6, [dstq+strideq*1]
vpbroadcastd m5, [pixel_10bpc_max]
jmp m(idct_16x4_internal_10bpc).end3
INV_TXFM_16X4_FN identity, dct
INV_TXFM_16X4_FN identity, adst
INV_TXFM_16X4_FN identity, flipadst
INV_TXFM_16X4_FN identity, identity
cglobal iidentity_16x4_internal_10bpc, 0, 7, 14, dst, stride, c, eob, tx2
.pass1:
vpbroadcastd m8, [pd_11586]
vpermq m0, [cq+32*0], q3120 ; 0 1
vpermq m1, [cq+32*1], q3120 ; 2 3
vpermq m2, [cq+32*2], q3120 ; 4 5
vpermq m3, [cq+32*3], q3120 ; 6 7
vpermq m4, [cq+32*4], q3120 ; 8 9
vpermq m5, [cq+32*5], q3120 ; a b
vpermq m6, [cq+32*6], q3120 ; c d
vpermq m7, [cq+32*7], q3120 ; e f
vpbroadcastd m9, [pd_6144]
REPX {pmulld x, m8}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {paddd x, m9}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {psrad x, 13}, m0, m1, m2, m3, m4, m5, m6, m7
jmp tx2q
.pass2:
call m(idct_16x4_internal_10bpc).transpose_4x16_packed
vpbroadcastd m7, [pw_1697x8]
pmulhrsw m4, m7, m0
pmulhrsw m5, m7, m1
pmulhrsw m6, m7, m2
pmulhrsw m7, m3
paddsw m0, m4
paddsw m1, m5
paddsw m2, m6
paddsw m3, m7
jmp m(idct_16x4_internal_10bpc).end
INV_TXFM_16X4_FN dct, dct, 12
INV_TXFM_16X4_FN dct, identity, 12
INV_TXFM_16X4_FN dct, adst, 12
INV_TXFM_16X4_FN dct, flipadst, 12
cglobal idct_16x4_internal_12bpc, 0, 7, 14, dst, stride, c, eob, tx2
vpbroadcastd m8, [clip_20b_min]
vpbroadcastd m9, [clip_20b_max]
jmp m(idct_16x4_internal_10bpc).pass1
.pass2:
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
REPX {pmaxsd x, m12}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m7
; deinterleave
REPX {pshufd x, x, q3120}, m0, m1, m2, m3, m4, m5, m6, m7
; transpose
punpcklqdq m8, m0, m1
punpckhqdq m0, m1
punpcklqdq m9, m2, m3
punpckhqdq m2, m3
punpcklqdq m10, m4, m5
punpckhqdq m4, m5
punpcklqdq m11, m6, m7
punpckhqdq m6, m7
vperm2i128 m3, m0, m2, 0x31 ; out6
vperm2i128 m1, m0, m2, 0x20 ; out2
vperm2i128 m7, m4, m6, 0x31 ; out7
vperm2i128 m5, m4, m6, 0x20 ; out3
vperm2i128 m13, m10, m11, 0x31 ; out5
vperm2i128 m12, m10, m11, 0x20 ; out1
vperm2i128 m11, m8, m9, 0x31 ; out4
vperm2i128 m10, m8, m9, 0x20 ; out0
call m(idct_4x16_internal_10bpc).pass1_main
pmulld m0, m6, m10
pmulld m2, m6, m11
pmulld m4, m6, m12
pmulld m6, m13
vpbroadcastd m10, [pd_2048]
call m(idct_4x16_internal_10bpc).pass1_main2
REPX {psrad x, 3}, m0, m1, m2, m3, m4, m5, m6, m7
packssdw m0, m4
packssdw m1, m5
packssdw m2, m6
packssdw m3, m7
vpbroadcastd m4, [pw_16384]
vpbroadcastd m5, [pixel_12bpc_max]
REPX {vpermq x, x, q3120}, m0, m1, m2, m3
REPX {pmulhrsw x, m4}, m0, m1, m2, m3
jmp m(idct_16x4_internal_10bpc).end2
INV_TXFM_16X4_FN adst, dct, 12
INV_TXFM_16X4_FN adst, adst, 12
INV_TXFM_16X4_FN adst, flipadst, 12
INV_TXFM_16X4_FN adst, identity, 12
cglobal iadst_16x4_internal_12bpc, 0, 7, 14, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_20b_min]
vpbroadcastd m13, [clip_20b_max]
jmp m(iadst_16x4_internal_10bpc).pass1
.pass2:
call .pass2_main
REPX {vpermq x, x, q3120}, m0, m1, m2, m3
REPX {pmulhrsw x, m4}, m0, m1, m2, m3
jmp m(idct_16x4_internal_10bpc).end2
ALIGN function_align
.pass2_main:
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
REPX {pmaxsd x, m12}, m0, m1, m2, m3, m6, m7
pmaxsd m8, m4, m12
pmaxsd m9, m5, m12
REPX {pminsd x, m13}, m0, m1, m2, m3
call m(iadst_8x4_internal_12bpc).transpose_4x8
mova [cq+32*0], m0
mova [cq+32*2], m1
mova [cq+32*4], m2
mova [cq+32*6], m3
pminsd m0, m8, m13
pminsd m1, m9, m13
pminsd m2, m6, m13
pminsd m3, m7, m13
call m(iadst_8x4_internal_12bpc).transpose_4x8
mova [cq+32*1], m0
mova [cq+32*3], m1
mova [cq+32*5], m2
mova [cq+32*7], m3
call m(iadst_16x4_internal_10bpc).main
vpbroadcastd m6, [pd_2048]
call m(iadst_16x4_internal_10bpc).main_end
psrad m0, m4, 15
psrad m1, m5, 15
psrad m2, 15
psrad m3, 15
psrad m4, m8, 15
psrad m5, m9, 15
psrad m6, 15
psrad m7, 15
packssdw m0, m4
packssdw m1, m5
packssdw m2, m6
packssdw m3, m7
vpbroadcastd m4, [pw_16384]
vpbroadcastd m5, [pixel_12bpc_max]
ret
INV_TXFM_16X4_FN flipadst, dct, 12
INV_TXFM_16X4_FN flipadst, adst, 12
INV_TXFM_16X4_FN flipadst, flipadst, 12
INV_TXFM_16X4_FN flipadst, identity, 12
cglobal iflipadst_16x4_internal_12bpc, 0, 7, 14, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_20b_min]
vpbroadcastd m13, [clip_20b_max]
jmp m(iflipadst_16x4_internal_10bpc).pass1
.pass2:
call m(iadst_16x4_internal_12bpc).pass2_main
vpermq m7, m0, q3120
vpermq m6, m1, q3120
vpermq m1, m2, q3120
vpermq m0, m3, q3120
pmulhrsw m0, m4
pmulhrsw m1, m4
pmulhrsw m2, m6, m4
pmulhrsw m3, m7, m4
jmp m(idct_16x4_internal_10bpc).end2
INV_TXFM_16X4_FN identity, dct, 12
INV_TXFM_16X4_FN identity, adst, 12
INV_TXFM_16X4_FN identity, flipadst, 12
INV_TXFM_16X4_FN identity, identity, 12
cglobal iidentity_16x4_internal_12bpc, 0, 7, 14, dst, stride, c, eob, tx2
jmp m(iidentity_16x4_internal_10bpc).pass1
.pass2:
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
REPX {pmaxsd x, m12}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m7
vpbroadcastd m8, [pd_5793]
vpbroadcastd m9, [pd_2048]
REPX {pmulld x, m8}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {paddd x, m9}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {psrad x, 15}, m0, m1, m2, m3, m4, m5, m6, m7
call m(idct_16x4_internal_10bpc).transpose_4x16_packed
vpbroadcastd m4, [pw_16384]
REPX {pmulhrsw x, m4}, m0, m1, m2, m3
vpbroadcastd m5, [pixel_12bpc_max]
jmp m(idct_16x4_internal_10bpc).end2
%macro INV_TXFM_16X8_FN 2-3 10 ; type1, type2, bitdepth
INV_TXFM_FN %1, %2, 0, 16x8, %3
%ifidn %1_%2, dct_dct
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 8
add r6d, 2048
sar r6d, 12
imul r6d, 2896
jmp m(inv_txfm_add_dct_dct_16x4_%3bpc).dconly
%endif
%endmacro
INV_TXFM_16X8_FN dct, dct
INV_TXFM_16X8_FN dct, identity
INV_TXFM_16X8_FN dct, adst
INV_TXFM_16X8_FN dct, flipadst
cglobal idct_16x8_internal_10bpc, 0, 7, 16, 32*8, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
.pass1:
vpbroadcastd m14, [pd_2896]
pmulld m0, m14, [cq+32* 1]
pmulld m1, m14, [cq+32* 3]
pmulld m2, m14, [cq+32* 5]
pmulld m3, m14, [cq+32* 7]
pmulld m4, m14, [cq+32* 9]
pmulld m5, m14, [cq+32*11]
pmulld m6, m14, [cq+32*13]
pmulld m7, m14, [cq+32*15]
vpbroadcastd m11, [pd_2048]
lea r6, [rsp+32*4]
call m(idct_8x16_internal_10bpc).main_oddhalf_rect2
pmulld m0, m14, [cq+32* 0]
pmulld m1, m14, [cq+32* 2]
pmulld m2, m14, [cq+32* 4]
pmulld m3, m14, [cq+32* 6]
pmulld m4, m14, [cq+32* 8]
pmulld m5, m14, [cq+32*10]
pmulld m6, m14, [cq+32*12]
pmulld m7, m14, [cq+32*14]
call m(idct_8x8_internal_10bpc).main_rect2
call m(idct_8x16_internal_10bpc).main_evenhalf
psrld m11, 11 ; pd_1
REPX {paddd x, m11}, m0, m1, m2, m3, m4, m5, m6, m7
call .pass1_rotations
REPX {psrad x, 1}, m0, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14, m15
jmp tx2q
.pass2:
call .transpose
call m(idct_16x8_internal_8bpc).main
vpbroadcastd m10, [pw_2048]
.end:
pmulhrsw m0, m10
pmulhrsw m1, m10
pmulhrsw m2, m10
pmulhrsw m3, m10
call .write_16x4_start
.end2:
pmulhrsw m0, m4, m10
pmulhrsw m1, m5, m10
pmulhrsw m2, m6, m10
pmulhrsw m3, m7, m10
call .write_16x4_zero
RET
ALIGN function_align
.pass1_rotations:
mova m14, [r6-32*4]
mova m13, [r6-32*3]
mova m12, [r6-32*2]
mova m11, [r6-32*1]
mova m10, [r6+32*0]
mova m9, [r6+32*1]
mova m8, [r6+32*2]
psubd m15, m0, m14 ; out15
paddd m0, m14 ; out0
psubd m14, m1, m13 ; out14
paddd m1, m13 ; out1
psubd m13, m2, m12 ; out13
paddd m2, m12 ; out2
psubd m12, m3, m11 ; out12
paddd m3, m11 ; out3
psubd m11, m4, m10 ; out11
paddd m4, m10 ; out4
psubd m10, m5, m9 ; out10
paddd m5, m9 ; out5
psubd m9, m6, m8 ; out9
paddd m6, m8 ; out6
psubd m8, m7, [r6+32*3] ; out8
paddd m7, [r6+32*3] ; out7
ret
ALIGN function_align
.transpose:
lea r6, [deint_shuf+128]
.transpose2:
packssdw m0, m8
packssdw m1, m9
packssdw m2, m10
packssdw m3, m11
packssdw m4, m12
packssdw m5, m13
packssdw m6, m14
packssdw m7, m15
.transpose3:
punpckhwd m8, m0, m1
punpcklwd m0, m1
punpcklwd m1, m2, m3
punpckhwd m2, m3
punpckhwd m3, m4, m5
punpcklwd m4, m5
punpckhwd m5, m6, m7
punpcklwd m6, m7
punpckhdq m7, m4, m6
punpckldq m4, m6
punpckldq m6, m8, m2
punpckhdq m8, m2
punpckhdq m2, m0, m1
punpckldq m0, m1
punpckhdq m1, m3, m5
punpckldq m3, m5
punpcklqdq m5, m6, m3
punpckhqdq m6, m3
punpckhqdq m3, m2, m7
punpcklqdq m2, m7
punpcklqdq m7, m8, m1
punpckhqdq m8, m1
punpckhqdq m1, m0, m4
punpcklqdq m0, m4
vperm2i128 m4, m0, m5, 0x31
vinserti128 m0, xm5, 1
vperm2i128 m5, m1, m6, 0x31
vinserti128 m1, xm6, 1
vperm2i128 m6, m2, m7, 0x31
vinserti128 m2, xm7, 1
vperm2i128 m7, m3, m8, 0x31
vinserti128 m3, xm8, 1
ret
ALIGN function_align
.write_16x4_start:
vpbroadcastd m9, [pixel_10bpc_max]
lea r3, [strideq*3]
pxor m8, m8
.write_16x4_zero:
REPX {mova [cq+32*x], m8}, 0, 1, 2, 3, 4, 5, 6, 7
add cq, 32*8
.write_16x4:
paddw m0, [dstq+strideq*0]
paddw m1, [dstq+strideq*1]
paddw m2, [dstq+strideq*2]
paddw m3, [dstq+r3 ]
REPX {pmaxsw x, m8}, m0, m1, m2, m3
REPX {pminsw x, m9}, m0, m1, m2, m3
mova [dstq+strideq*0], m0
mova [dstq+strideq*1], m1
mova [dstq+strideq*2], m2
mova [dstq+r3 ], m3
lea dstq, [dstq+strideq*4]
ret
INV_TXFM_16X8_FN adst, dct
INV_TXFM_16X8_FN adst, adst
INV_TXFM_16X8_FN adst, flipadst
INV_TXFM_16X8_FN adst, identity
cglobal iadst_16x8_internal_10bpc, 0, 7, 16, 32*8, dst, stride, c, eob, tx2
vpbroadcastd m13, [clip_18b_min]
vpbroadcastd m14, [clip_18b_max]
.pass1:
lea r6, [rsp+32*4]
call .main
vpbroadcastd m14, [pd_6144]
psrld m15, 11 ; pd_1
psubd m13, m14, m15 ; pd_6143
call .pass1_rotations
.pass1_end:
REPX {psrad x, 1 }, m0, m1, m2, m3, m12, m13, m14, m15
REPX {psrad x, 13}, m4, m5, m6, m7, m8, m9, m10, m11
jmp tx2q
.pass2:
call m(idct_16x8_internal_10bpc).transpose
call m(iadst_16x8_internal_8bpc).main
call m(iadst_16x8_internal_8bpc).main_pass2_end
vpbroadcastd m10, [pw_2048]
pxor m11, m11
psubw m11, m10
pmulhrsw m0, m10
pmulhrsw m1, m11
pmulhrsw m2, m10
pmulhrsw m3, m11
call m(idct_16x8_internal_10bpc).write_16x4_start
pmulhrsw m0, m4, m10
pmulhrsw m1, m5, m11
pmulhrsw m2, m6, m10
pmulhrsw m3, m7, m11
call m(idct_16x8_internal_10bpc).write_16x4_zero
RET
ALIGN function_align
.pass1_rotations:
paddd m0, m15
psubd m1, m15, m1
paddd m2, m15
psubd m3, m15, m3
paddd m4, m14
psubd m5, m13, m5
paddd m6, m14
psubd m7, m13, m7
paddd m8, m14, m9
psubd m9, m13, m10
paddd m10, m14, m11
psubd m11, m13, m12
paddd m12, m15, [r6-32*1]
psubd m13, m15, [r6-32*2]
paddd m14, m15, [r6-32*3]
psubd m15, [r6-32*4]
ret
ALIGN function_align
.main:
; expects: m13 = clip_min m14 = clip_max
vpbroadcastd m15, [pd_2896]
pmulld m0, m15, [cq+32* 2]
pmulld m1, m15, [cq+32*13]
pmulld m2, m15, [cq+32* 6]
pmulld m3, m15, [cq+32* 9]
pmulld m4, m15, [cq+32*10]
pmulld m5, m15, [cq+32* 5]
pmulld m6, m15, [cq+32*14]
pmulld m7, m15, [cq+32* 1]
vpbroadcastd m12, [pd_2048]
REPX {paddd x, m12}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {psrad x, 12 }, m0, m1, m2, m3, m4, m5, m6, m7
call .main_part1
pmulld m0, m15, [cq+32* 0]
pmulld m1, m15, [cq+32*15]
pmulld m2, m15, [cq+32* 4]
pmulld m3, m15, [cq+32*11]
pmulld m4, m15, [cq+32* 8]
pmulld m5, m15, [cq+32* 7]
pmulld m6, m15, [cq+32*12]
pmulld m7, m15, [cq+32* 3]
REPX {paddd x, m12}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {psrad x, 12 }, m0, m1, m2, m3, m4, m5, m6, m7
.main_part2:
ITX_MULSUB_2D 1, 0, 8, 9, 10, 12, 201, 4091
ITX_MULSUB_2D 3, 2, 8, 9, 10, 12, 1751, 3703
ITX_MULSUB_2D 5, 4, 8, 9, 10, 12, 3035, 2751
ITX_MULSUB_2D 7, 6, 8, 9, 10, 12, 3857, 1380
psubd m8, m0, m4 ; t8a
paddd m0, m4 ; t0a
psubd m4, m1, m5 ; t9a
paddd m1, m5 ; t1a
psubd m5, m2, m6 ; t12a
paddd m2, m6 ; t4a
psubd m6, m3, m7 ; t13a
paddd m7, m3 ; t5a
REPX {pmaxsd x, m13}, m8, m4, m5, m6, m0, m1, m2, m7
REPX {pminsd x, m14}, m8, m4, m5, m6, m0, m1, m2, m7
vpbroadcastd m11, [pd_4017]
vpbroadcastd m10, [pd_799]
ITX_MULSUB_2D 8, 4, 3, 9, _, 12, 10, 11
ITX_MULSUB_2D 6, 5, 3, 9, _, 12, 11, 10
psubd m3, m0, m2 ; t4
paddd m0, m2 ; t0
psubd m2, m1, m7 ; t5
paddd m1, m7 ; t1
psubd m7, m4, m6 ; t12a
paddd m4, m6 ; t8a
psubd m6, m8, m5 ; t13a
paddd m5, m8 ; t9a
REPX {pmaxsd x, m13}, m3, m2, m7, m6, m0, m1, m4, m5
REPX {pminsd x, m14}, m3, m2, m7, m6, m0, m1, m4, m5
vpbroadcastd m11, [pd_3784]
vpbroadcastd m10, [pd_1567]
ITX_MULSUB_2D 3, 2, 8, 9, _, 12, 10, 11
ITX_MULSUB_2D 7, 6, 8, 9, _, 12, 10, 11
pminsd m10, m14, [r6-32*4] ; t2
pminsd m8, m14, [r6-32*3] ; t3
psubd m9, m0, m10 ; t2a
paddd m0, m10 ; out0
psubd m10, m1, m8 ; t3a
paddd m1, m8 ; -out15
pmaxsd m9, m13
pmaxsd m10, m13
pminsd m9, m14
pminsd m10, m14
pmulld m9, m15
pmulld m10, m15
mova [r6-32*4], m1
mova m11, [r6-32*1] ; t7a
mova m1, [r6-32*2] ; t6a
psubd m8, m3, m11 ; t7
paddd m11, m3 ; out12
paddd m3, m2, m1 ; -out3
psubd m2, m1 ; t6
pmaxsd m8, m13
pmaxsd m2, m13
pminsd m8, m14
pminsd m2, m14
pmulld m8, m15
mova [r6-32*1], m11
mova [r6-32*3], m2
mova m1, [r6+32*3] ; t15
mova m2, [r6+32*2] ; t14
paddd m12, m7, m1 ; -out13
psubd m7, m1 ; t15a
psubd m11, m6, m2 ; t14a
paddd m2, m6 ; out2
pmaxsd m7, m13
pmaxsd m11, m13
pminsd m7, m14
pminsd m11, m14
pmulld m7, m15
pmulld m11, m15
mova [r6-32*2], m12
pminsd m1, m14, [r6+32*0] ; t10a
pminsd m12, m14, [r6+32*1] ; t11a
psubd m6, m4, m1 ; t10
paddd m1, m4 ; -out1
psubd m4, m5, m12 ; t11
paddd m5, m12 ; out14
pmulld m12, m15, [r6-32*3] ; t6
pmaxsd m6, m13
pmaxsd m4, m13
pminsd m6, m14
pminsd m4, m14
pmulld m6, m15
pmulld m4, m15
mova [r6-32*3], m5
paddd m5, m11, m7 ; -out5 (unshifted)
psubd m11, m7 ; out10 (unshifted)
paddd m7, m9, m10 ; -out7 (unshifted)
psubd m9, m10 ; out8 (unshifted)
psubd m10, m6, m4 ; -out9 (unshifted)
paddd m6, m4 ; out6 (unshifted)
paddd m4, m12, m8 ; out4 (unshifted)
psubd m12, m8 ; -out11 (unshifted)
ret
.main_part1:
ITX_MULSUB_2D 1, 0, 8, 9, 10, 12, 995, 3973
ITX_MULSUB_2D 3, 2, 8, 9, 10, 12, 2440, 3290
ITX_MULSUB_2D 5, 4, 8, 9, 10, 12, 3513, 2106
ITX_MULSUB_2D 7, 6, 8, 9, 10, 12, 4052, 601
psubd m8, m0, m4 ; t10a
paddd m0, m4 ; t2a
psubd m4, m1, m5 ; t11a
paddd m1, m5 ; t3a
psubd m5, m2, m6 ; t14a
paddd m2, m6 ; t6a
psubd m6, m3, m7 ; t15a
paddd m7, m3 ; t7a
REPX {pmaxsd x, m13}, m8, m4, m5, m6, m0, m1, m2, m7
REPX {pminsd x, m14}, m8, m4, m5, m6, m0, m1, m2, m7
vpbroadcastd m11, [pd_2276]
vpbroadcastd m10, [pd_3406]
ITX_MULSUB_2D 8, 4, 3, 9, _, 12, 10, 11
ITX_MULSUB_2D 6, 5, 3, 9, _, 12, 11, 10
psubd m3, m0, m2 ; t6
paddd m0, m2 ; t2
psubd m2, m1, m7 ; t7
paddd m1, m7 ; t3
psubd m7, m4, m6 ; t14a
paddd m4, m6 ; t10a
psubd m6, m8, m5 ; t15a
paddd m5, m8 ; t11a
REPX {pmaxsd x, m13}, m3, m2, m7, m6, m0, m1, m4, m5
REPX {pminsd x, m14}, m3, m2, m7, m6 ; clip the rest later
vpbroadcastd m11, [pd_1567]
vpbroadcastd m10, [pd_3784]
ITX_MULSUB_2D 2, 3, 8, 9, _, 12, 10, 11
ITX_MULSUB_2D 6, 7, 8, 9, _, 12, 10, 11
mova [r6-32*4], m0
mova [r6-32*3], m1
mova [r6+32*0], m4
mova [r6+32*1], m5
mova [r6-32*2], m2
mova [r6-32*1], m3
mova [r6+32*2], m6
mova [r6+32*3], m7
ret
INV_TXFM_16X8_FN flipadst, dct
INV_TXFM_16X8_FN flipadst, adst
INV_TXFM_16X8_FN flipadst, flipadst
INV_TXFM_16X8_FN flipadst, identity
cglobal iflipadst_16x8_internal_10bpc, 0, 7, 16, 32*8, dst, stride, c, eob, tx2
vpbroadcastd m13, [clip_18b_min]
vpbroadcastd m14, [clip_18b_max]
.pass1:
lea r6, [rsp+32*4]
call m(iadst_16x8_internal_10bpc).main
vpbroadcastd m14, [pd_6144]
psrld m15, 11
psubd m13, m14, m15
call .pass1_rotations
jmp m(iadst_16x8_internal_10bpc).pass1_end
.pass2:
call m(idct_16x8_internal_10bpc).transpose
call m(iadst_16x8_internal_8bpc).main
call m(iadst_16x8_internal_8bpc).main_pass2_end
vpbroadcastd m10, [pw_2048]
pxor m11, m11
psubw m11, m10
mova m12, m0
pmulhrsw m0, m7, m11
mova m7, m1
pmulhrsw m1, m6, m10
mova m6, m2
pmulhrsw m2, m5, m11
mova m5, m3
pmulhrsw m3, m4, m10
call m(idct_16x8_internal_10bpc).write_16x4_start
pmulhrsw m0, m5, m11
pmulhrsw m1, m6, m10
pmulhrsw m2, m7, m11
pmulhrsw m3, m12, m10
call m(idct_16x8_internal_10bpc).write_16x4_zero
RET
ALIGN function_align
.pass1_rotations:
psubd m8, m13, m7
paddd m7, m14, m9
paddd m9, m14, m6
psubd m6, m13, m10
psubd m10, m13, m5
paddd m5, m14, m11
paddd m11, m14, m4
psubd m4, m13, m12
psubd m12, m15, m3
paddd m3, m15, [r6-32*1]
paddd m13, m15, m2
psubd m2, m15, [r6-32*2]
psubd m14, m15, m1
mova m1, m15
paddd m15, m0
psubd m0, m1, [r6-32*4]
paddd m1, [r6-32*3]
ret
INV_TXFM_16X8_FN identity, dct
INV_TXFM_16X8_FN identity, adst
INV_TXFM_16X8_FN identity, flipadst
INV_TXFM_16X8_FN identity, identity
cglobal iidentity_16x8_internal_10bpc, 0, 7, 16, 32*8, dst, stride, c, eob, tx2
.pass1:
vpbroadcastd m15, [pd_2896]
pmulld m0, m15, [cq+32* 0]
pmulld m1, m15, [cq+32* 1]
pmulld m2, m15, [cq+32* 2]
pmulld m3, m15, [cq+32* 3]
pmulld m4, m15, [cq+32* 4]
pmulld m5, m15, [cq+32* 5]
pmulld m6, m15, [cq+32* 6]
pmulld m7, m15, [cq+32* 7]
pmulld m8, m15, [cq+32* 8]
pmulld m9, m15, [cq+32* 9]
pmulld m10, m15, [cq+32*10]
pmulld m11, m15, [cq+32*11]
pmulld m12, m15, [cq+32*12]
pmulld m13, m15, [cq+32*13]
pmulld m14, m15, [cq+32*14]
pmulld m15, [cq+32*15]
mova [rsp], m7
vpbroadcastd m7, [pd_2048]
REPX {paddd x, m7 }, m0, m1, m2, m3, m4, m5, m6, \
m8, m9, m10, m11, m12, m13, m14, m15
paddd m7, [rsp]
REPX {psrad x, 12 }, m0, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14, m15
mova [rsp], m15
vpbroadcastd m15, [pd_11586]
REPX {pmulld x, m15}, m0, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14
pmulld m15, [rsp]
mova [rsp], m7
vpbroadcastd m7, [pd_6144]
REPX {paddd x, m7 }, m0, m1, m2, m3, m4, m5, m6, \
m8, m9, m10, m11, m12, m13, m14, m15
paddd m7, [rsp]
REPX {psrad x, 13 }, m0, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14, m15
jmp tx2q
.pass2:
call m(idct_16x8_internal_10bpc).transpose
vpbroadcastd m10, [pw_4096]
jmp m(idct_16x8_internal_10bpc).end
INV_TXFM_16X8_FN dct, dct, 12
INV_TXFM_16X8_FN dct, identity, 12
INV_TXFM_16X8_FN dct, adst, 12
INV_TXFM_16X8_FN dct, flipadst, 12
cglobal idct_16x8_internal_12bpc, 0, 7, 16, 32*8, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_20b_min]
vpbroadcastd m13, [clip_20b_max]
jmp m(idct_16x8_internal_10bpc).pass1
.pass2:
call m(idct_8x16_internal_12bpc).transpose
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
vpbroadcastd m11, [pd_2048]
REPX {pmaxsd x, m12}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m7
call m(idct_8x8_internal_10bpc).main
call m(idct_8x8_internal_12bpc).round_shift4
mova [cq+32* 8], m0
mova [cq+32* 9], m1
mova [cq+32*10], m2
mova [cq+32*11], m3
mova [cq+32*12], m4
mova [cq+32*13], m5
mova [cq+32*14], m6
mova [cq+32*15], m7
pmaxsd m0, m12, [cq+32*0]
pmaxsd m1, m12, [cq+32*1]
pmaxsd m2, m12, [cq+32*2]
pmaxsd m3, m12, [cq+32*3]
pmaxsd m4, m12, [cq+32*4]
pmaxsd m5, m12, [cq+32*5]
pmaxsd m6, m12, [cq+32*6]
pmaxsd m7, m12, [cq+32*7]
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m7
call m(idct_8x8_internal_10bpc).main
call m(idct_8x8_internal_12bpc).round_shift4
.end:
packssdw m0, [cq+32* 8]
packssdw m1, [cq+32* 9]
packssdw m2, [cq+32*10]
packssdw m3, [cq+32*11]
packssdw m4, [cq+32*12]
packssdw m5, [cq+32*13]
packssdw m6, [cq+32*14]
packssdw m7, [cq+32*15]
REPX {vpermq x, x, q3120}, m0, m1, m2, m3
call .write_16x4_start
call m(idct_16x8_internal_10bpc).write_16x4_zero
vpermq m0, m4, q3120
vpermq m1, m5, q3120
vpermq m2, m6, q3120
vpermq m3, m7, q3120
call m(idct_16x8_internal_10bpc).write_16x4_zero
RET
ALIGN function_align
.write_16x4_start:
vpbroadcastd m9, [pixel_12bpc_max]
lea r3, [strideq*3]
pxor m8, m8
ret
INV_TXFM_16X8_FN adst, dct, 12
INV_TXFM_16X8_FN adst, adst, 12
INV_TXFM_16X8_FN adst, flipadst, 12
INV_TXFM_16X8_FN adst, identity, 12
cglobal iadst_16x8_internal_12bpc, 0, 7, 16, 32*8, dst, stride, c, eob, tx2
vpbroadcastd m13, [clip_20b_min]
vpbroadcastd m14, [clip_20b_max]
jmp m(iadst_16x8_internal_10bpc).pass1
.pass2:
call .pass2_main
jmp m(idct_16x8_internal_12bpc).end
ALIGN function_align
.pass2_main:
call m(idct_8x16_internal_12bpc).transpose
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
vpbroadcastd m11, [pd_2048]
REPX {pmaxsd x, m12}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m7
call m(iadst_8x8_internal_12bpc).pass2_main2
mova [cq+32* 8], m0
mova [cq+32* 9], m1
mova [cq+32*10], m2
mova [cq+32*11], m3
mova [cq+32*12], m4
mova [cq+32*13], m5
mova [cq+32*14], m6
mova [cq+32*15], m7
pmaxsd m0, m12, [cq+32*0]
pmaxsd m1, m12, [cq+32*1]
pmaxsd m2, m12, [cq+32*2]
pmaxsd m3, m12, [cq+32*3]
pmaxsd m4, m12, [cq+32*4]
pmaxsd m5, m12, [cq+32*5]
pmaxsd m6, m12, [cq+32*6]
pmaxsd m7, m12, [cq+32*7]
REPX {pminsd x, m13}, m0, m1, m2, m3, m4, m5, m6, m7
call m(iadst_8x8_internal_12bpc).pass2_main2
ret
INV_TXFM_16X8_FN flipadst, dct, 12
INV_TXFM_16X8_FN flipadst, adst, 12
INV_TXFM_16X8_FN flipadst, flipadst, 12
INV_TXFM_16X8_FN flipadst, identity, 12
cglobal iflipadst_16x8_internal_12bpc, 0, 7, 16, 32*8, dst, stride, c, eob, tx2
vpbroadcastd m13, [clip_20b_min]
vpbroadcastd m14, [clip_20b_max]
jmp m(iflipadst_16x8_internal_10bpc).pass1
.pass2:
call m(iadst_16x8_internal_12bpc).pass2_main
packssdw m13, m0, [cq+32* 8]
packssdw m12, m1, [cq+32* 9]
packssdw m11, m2, [cq+32*10]
packssdw m10, m3, [cq+32*11]
packssdw m3, m4, [cq+32*12]
packssdw m2, m5, [cq+32*13]
packssdw m1, m6, [cq+32*14]
packssdw m0, m7, [cq+32*15]
REPX {vpermq x, x, q3120}, m0, m1, m2, m3
call m(idct_16x8_internal_12bpc).write_16x4_start
call m(idct_16x8_internal_10bpc).write_16x4_zero
vpermq m0, m10, q3120
vpermq m1, m11, q3120
vpermq m2, m12, q3120
vpermq m3, m13, q3120
call m(idct_16x8_internal_10bpc).write_16x4_zero
RET
INV_TXFM_16X8_FN identity, dct, 12
INV_TXFM_16X8_FN identity, adst, 12
INV_TXFM_16X8_FN identity, flipadst, 12
INV_TXFM_16X8_FN identity, identity, 12
cglobal iidentity_16x8_internal_12bpc, 0, 7, 16, 32*8, dst, stride, c, eob, tx2
jmp m(iidentity_16x8_internal_10bpc).pass1
.pass2:
call m(idct_16x8_internal_10bpc).transpose2
vpbroadcastd m10, [pw_4096]
pmulhrsw m0, m10
pmulhrsw m1, m10
pmulhrsw m2, m10
pmulhrsw m3, m10
call m(idct_16x8_internal_12bpc).write_16x4_start
call m(idct_16x8_internal_10bpc).write_16x4_zero
jmp m(idct_16x8_internal_10bpc).end2
%macro INV_TXFM_16X16_FN 2-4 0,10 ; type1, type2, eob_offset, bitdepth
INV_TXFM_FN %1, %2, %3, 16x16, %4
%ifidn %1_%2, dct_dct
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 16
add r6d, 10240
sar r6d, 14
jmp m(inv_txfm_add_dct_dct_16x4_%4bpc).dconly2
%endif
%endmacro
INV_TXFM_16X16_FN dct, dct
INV_TXFM_16X16_FN dct, identity, 28
INV_TXFM_16X16_FN dct, adst
INV_TXFM_16X16_FN dct, flipadst
cglobal idct_16x16_internal_10bpc, 0, 7, 16, 32*24, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
.pass1:
vpbroadcastd m11, [pd_2048]
vpbroadcastd m14, [pd_2896]
lea r6, [rsp+32*4]
sub eobd, 36
jl .fast
add cq, 32
call .main
sub cq, 32
mova m10, [r6-32*4]
mova m9, [r6-32*3]
mova m8, [r6-32*2]
psubd m15, m0, m10 ; out15
paddd m0, m10 ; out0
psubd m10, m1, m9 ; out14
paddd m1, m9 ; out1
psubd m9, m2, m8 ; out13
paddd m2, m8 ; out2
REPX {psrad x, 2}, m0, m1, m2
mova [r6-32*4], m0
mova [r6-32*3], m1
mova [r6-32*2], m2
mova m2, [r6-32*1]
mova m1, [r6+32*0]
mova m0, [r6+32*1]
REPX {psrad x, 2}, m9, m10, m15
psubd m8, m3, m2 ; out12
paddd m3, m2 ; out3
psubd m2, m4, m1 ; out11
paddd m4, m1 ; out4
psubd m1, m5, m0 ; out10
paddd m5, m0 ; out5
REPX {psrad x, 2}, m3, m4, m5
mova [r6-32*1], m3
mova [r6+32*0], m4
mova [r6+32*1], m5
mova m4, [r6+32*2]
mova m3, [r6+32*3]
REPX {psrad x, 2}, m1, m2, m8
psubd m5, m6, m4 ; out9
paddd m6, m4 ; out6
psubd m4, m7, m3 ; out8
paddd m7, m3 ; out7
REPX {psrad x, 2}, m6, m7, m4, m5
mova [r6+32*2], m6
mova [r6+32*3], m7
add r6, 32*8
mova [r6-32*4], m4
mova [r6-32*3], m5
mova [r6-32*2], m1
mova [r6-32*1], m2
mova [r6+32*0], m8
mova [r6+32*1], m9
mova [r6+32*2], m10
mova [r6+32*3], m15
.fast:
add r6, 32*8
call .main
mova m14, [r6-32*4]
mova m13, [r6-32*3]
mova m12, [r6-32*2]
mova m11, [r6-32*1]
mova m10, [r6+32*0]
mova m9, [r6+32*1]
mova m8, [r6+32*2]
psubd m15, m0, m14 ; out15
paddd m0, m14 ; out0
psubd m14, m1, m13 ; out14
paddd m1, m13 ; out1
psubd m13, m2, m12 ; out13
paddd m2, m12 ; out2
psubd m12, m3, m11 ; out12
paddd m3, m11 ; out3
psubd m11, m4, m10 ; out11
paddd m4, m10 ; out4
psubd m10, m5, m9 ; out10
paddd m5, m9 ; out5
psubd m9, m6, m8 ; out9
paddd m6, m8 ; out6
psubd m8, m7, [r6+32*3] ; out8
paddd m7, [r6+32*3] ; out7
sub r6, 32*8
REPX {psrad x, 2}, m0, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14, m15
jmp tx2q
.pass2:
call .transpose
lea r6, [pw_5+128]
mova [rsp], m15
call m(idct_16x16_internal_8bpc).main
mova m1, [rsp+32*1]
.end:
call .write_16x16
RET
ALIGN function_align
.write_16x16:
mova [rsp+gprsize+32*0], m8
mova [rsp+gprsize+32*1], m9
mova [rsp+gprsize+32*2], m12
vpbroadcastd m12, [pw_2048]
pmulhrsw m0, m12
pmulhrsw m1, m12
pmulhrsw m2, m12
pmulhrsw m3, m12
call m(idct_16x8_internal_10bpc).write_16x4_start
.write_16x16_2:
pmulhrsw m0, m12, m4
pmulhrsw m1, m12, m5
pmulhrsw m2, m12, m6
pmulhrsw m3, m12, m7
call m(idct_16x8_internal_10bpc).write_16x4_zero
pmulhrsw m0, m12, [rsp+gprsize+32*0]
pmulhrsw m1, m12, [rsp+gprsize+32*1]
pmulhrsw m2, m12, m10
pmulhrsw m3, m12, m11
call m(idct_16x8_internal_10bpc).write_16x4_zero
pmulhrsw m0, m12, [rsp+gprsize+32*2]
pmulhrsw m1, m12, m13
pmulhrsw m2, m12, m14
pmulhrsw m3, m12, m15
jmp m(idct_16x8_internal_10bpc).write_16x4_zero
ALIGN function_align
.transpose:
test eobd, eobd
jl .transpose_fast
packssdw m8, [r6-32*4]
packssdw m9, [r6-32*3]
packssdw m10, [r6-32*2]
packssdw m11, [r6-32*1]
packssdw m12, [r6+32*0]
packssdw m13, [r6+32*1]
packssdw m14, [r6+32*2]
packssdw m15, [r6+32*3]
sub r6, 32*8
packssdw m0, [r6-32*4]
packssdw m1, [r6-32*3]
packssdw m2, [r6-32*2]
packssdw m3, [r6-32*1]
packssdw m4, [r6+32*0]
packssdw m5, [r6+32*1]
packssdw m6, [r6+32*2]
packssdw m7, [r6+32*3]
mova [r6], m8
punpckhwd m8, m0, m1
punpcklwd m0, m1
punpcklwd m1, m2, m3
punpckhwd m2, m3
punpckhwd m3, m6, m7
punpcklwd m6, m7
punpcklwd m7, m4, m5
punpckhwd m4, m5
punpckldq m5, m8, m2
punpckhdq m8, m2
punpckhdq m2, m0, m1
punpckldq m0, m1
punpckhdq m1, m7, m6
punpckldq m7, m6
punpckhdq m6, m4, m3
punpckldq m4, m3
punpckhqdq m3, m2, m1
punpcklqdq m2, m1
punpckhqdq m1, m0, m7
punpcklqdq m0, m7
punpcklqdq m7, m8, m6
punpckhqdq m8, m6
punpckhqdq m6, m5, m4
punpcklqdq m5, m4
mova m4, [r6]
mova [r6], m8
punpcklwd m8, m4, m9
punpckhwd m4, m9
punpcklwd m9, m10, m11
punpckhwd m10, m11
punpckhwd m11, m14, m15
punpcklwd m14, m15
punpckhwd m15, m12, m13
punpcklwd m12, m13
punpckldq m13, m4, m10
punpckhdq m4, m10
punpckhdq m10, m8, m9
punpckldq m8, m9
punpckhdq m9, m12, m14
punpckldq m12, m14
punpckhdq m14, m15, m11
punpckldq m15, m11
punpckhqdq m11, m10, m9
punpcklqdq m10, m9
punpckhqdq m9, m8, m12
punpcklqdq m8, m12
punpcklqdq m12, m13, m15
punpckhqdq m13, m15
punpckhqdq m15, m4, m14
punpcklqdq m14, m4, m14
vperm2i128 m4, m0, m8, 0x31
vinserti128 m0, xm8, 1
vinserti128 m8, m5, xm12, 1
vperm2i128 m12, m5, 0x13
vperm2i128 m5, m1, m9, 0x31
vinserti128 m1, xm9, 1
vinserti128 m9, m6, xm13, 1
vperm2i128 m13, m6, 0x13
vperm2i128 m6, m2, m10, 0x31
vinserti128 m2, xm10, 1
vinserti128 m10, m7, xm14, 1
vperm2i128 m14, m7, 0x13
vperm2i128 m7, m3, m11, 0x31
vinserti128 m3, xm11, 1
mova xm11, [r6]
vinserti128 m11, xm15, 1
vinserti128 m15, [r6+16], 0
ret
.transpose_fast:
call m(idct_16x8_internal_10bpc).transpose2
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14, m15
ret
ALIGN function_align
.main:
mova m0, [cq+64* 1]
mova m1, [cq+64* 3]
mova m2, [cq+64* 5]
mova m3, [cq+64* 7]
mova m4, [cq+64* 9]
mova m5, [cq+64*11]
mova m6, [cq+64*13]
mova m7, [cq+64*15]
call m(idct_8x16_internal_10bpc).main_oddhalf
mova m0, [cq+64* 0]
mova m1, [cq+64* 2]
mova m2, [cq+64* 4]
mova m3, [cq+64* 6]
mova m4, [cq+64* 8]
mova m5, [cq+64*10]
mova m6, [cq+64*12]
mova m7, [cq+64*14]
call m(idct_8x8_internal_10bpc).main
call m(idct_8x16_internal_10bpc).main_evenhalf
psrld m10, m11, 10 ; pd_2
REPX {paddd x, m10}, m0, m1, m2, m3, m4, m5, m6, m7
ret
INV_TXFM_16X16_FN adst, dct
INV_TXFM_16X16_FN adst, adst
INV_TXFM_16X16_FN adst, flipadst
cglobal iadst_16x16_internal_10bpc, 0, 7, 16, 32*24, dst, stride, c, eob, tx2
vpbroadcastd m13, [clip_18b_min]
vpbroadcastd m14, [clip_18b_max]
.pass1:
vpbroadcastd m15, [pd_2896]
lea r6, [rsp+32*4]
sub eobd, 36
jl .fast
add cq, 32
call .main
sub cq, 32
vpbroadcastd m8, [pd_10240]
paddd m4, m8
paddd m6, m8
paddd m9, m8
paddd m11, m8
vpbroadcastd m8, [pd_10239]
psubd m5, m8, m5
psubd m7, m8, m7
psubd m10, m8, m10
psubd m12, m8, m12
REPX {psrad x, 14}, m4, m5, m6, m7, m9, m10, m11, m12
mova [r6+32*0], m4
mova [r6+32*1], m5
mova [r6+32*2], m6
mova [r6+32*3], m7
psrld m4, m15, 10 ; pd_2
paddd m0, m4
psubd m1, m4, m1
paddd m2, m4
psubd m3, m4, m3
psubd m7, m4, [r6-32*4]
paddd m6, m4, [r6-32*3]
psubd m5, m4, [r6-32*2]
paddd m4, [r6-32*1]
REPX {psrad x, 2 }, m0, m1, m2, m3, m4, m5, m6, m7
mova [r6-32*4], m0
mova [r6-32*3], m1
mova [r6-32*2], m2
mova [r6-32*1], m3
add r6, 32*8
mova [r6-32*4], m9
mova [r6-32*3], m10
mova [r6-32*2], m11
mova [r6-32*1], m12
mova [r6+32*0], m4
mova [r6+32*1], m5
mova [r6+32*2], m6
mova [r6+32*3], m7
.fast:
add r6, 32*8
call .main
vpbroadcastd m14, [pd_10240]
vpbroadcastd m13, [pd_10239]
psrld m15, 10 ; pd_2
paddd m0, m15
psubd m1, m15, m1
paddd m2, m15
psubd m3, m15, m3
paddd m4, m14
psubd m5, m13, m5
paddd m6, m14
psubd m7, m13, m7
paddd m8, m14, m9
psubd m9, m13, m10
paddd m10, m14, m11
psubd m11, m13, m12
paddd m12, m15, [r6-32*1]
psubd m13, m15, [r6-32*2]
paddd m14, m15, [r6-32*3]
psubd m15, [r6-32*4]
.pass1_end:
REPX {psrad x, 2 }, m0, m1, m2, m3, m12, m13, m14, m15
REPX {psrad x, 14}, m4, m5, m6, m7, m8, m9, m10, m11
sub r6, 32*8
jmp tx2q
.pass2:
call m(idct_16x16_internal_10bpc).transpose
lea r6, [pw_5+128]
mova [rsp], m15
call m(iadst_16x16_internal_8bpc).main
call m(iadst_16x16_internal_8bpc).main_pass2_end
mova [rsp+32*0], m8
mova [rsp+32*2], m12
mova [rsp+32*3], m13
vpbroadcastd m12, [pw_2048]
pxor m13, m13
psubw m13, m12
pmulhrsw m0, m12
pmulhrsw m1, m13, [rsp+32*1]
mova [rsp+32*1], m9
pmulhrsw m2, m12
pmulhrsw m3, m13
call m(idct_16x8_internal_10bpc).write_16x4_start
pmulhrsw m0, m12, m4
pmulhrsw m1, m13, m5
pmulhrsw m2, m12, m6
pmulhrsw m3, m13, m7
call m(idct_16x8_internal_10bpc).write_16x4_zero
pmulhrsw m0, m12, [rsp+32*0]
pmulhrsw m1, m13, [rsp+32*1]
pmulhrsw m2, m12, m10
pmulhrsw m3, m13, m11
call m(idct_16x8_internal_10bpc).write_16x4_zero
pmulhrsw m0, m12, [rsp+32*2]
pmulhrsw m1, m13, [rsp+32*3]
pmulhrsw m2, m12, m14
pmulhrsw m3, m13, m15
call m(idct_16x8_internal_10bpc).write_16x4_zero
RET
ALIGN function_align
.main:
mova m0, [cq+64* 2]
mova m1, [cq+64*13]
mova m2, [cq+64* 6]
mova m3, [cq+64* 9]
mova m4, [cq+64*10]
mova m5, [cq+64* 5]
mova m6, [cq+64*14]
mova m7, [cq+64* 1]
vpbroadcastd m12, [pd_2048]
call m(iadst_16x8_internal_10bpc).main_part1
mova m0, [cq+64* 0]
mova m1, [cq+64*15]
mova m2, [cq+64* 4]
mova m3, [cq+64*11]
mova m4, [cq+64* 8]
mova m5, [cq+64* 7]
mova m6, [cq+64*12]
mova m7, [cq+64* 3]
jmp m(iadst_16x8_internal_10bpc).main_part2
INV_TXFM_16X16_FN flipadst, dct
INV_TXFM_16X16_FN flipadst, adst
INV_TXFM_16X16_FN flipadst, flipadst
cglobal iflipadst_16x16_internal_10bpc, 0, 7, 16, 32*24, dst, stride, c, eob, tx2
vpbroadcastd m13, [clip_18b_min]
vpbroadcastd m14, [clip_18b_max]
.pass1:
vpbroadcastd m15, [pd_2896]
lea r6, [rsp+32*4]
sub eobd, 36
jl .fast
add cq, 32
call m(iadst_16x16_internal_10bpc).main
sub cq, 32
vpbroadcastd m8, [pd_10240]
paddd m11, m8
paddd m9, m8
paddd m6, m8
paddd m4, m8
vpbroadcastd m8, [pd_10239]
psubd m12, m8, m12
psubd m10, m8, m10
psubd m7, m8, m7
psubd m5, m8, m5
REPX {psrad x, 14}, m12, m11, m10, m9, m7, m6, m5, m4
mova [r6+32*0], m12
mova [r6+32*1], m11
mova [r6+32*2], m10
mova [r6+32*3], m9
psrld m9, m15, 10 ; pd_2
psubd m3, m9, m3
paddd m2, m9
psubd m1, m9, m1
paddd m0, m9
psubd m12, m9, [r6-32*4]
paddd m11, m9, [r6-32*3]
psubd m10, m9, [r6-32*2]
paddd m9, [r6-32*1]
REPX {psrad x, 2 }, m12, m11, m10, m9, m3, m2, m1, m0
mova [r6-32*4], m12
mova [r6-32*3], m11
mova [r6-32*2], m10
mova [r6-32*1], m9
add r6, 32*8
mova [r6-32*4], m7
mova [r6-32*3], m6
mova [r6-32*2], m5
mova [r6-32*1], m4
mova [r6+32*0], m3
mova [r6+32*1], m2
mova [r6+32*2], m1
mova [r6+32*3], m0
.fast:
add r6, 32*8
call m(iadst_16x16_internal_10bpc).main
vpbroadcastd m14, [pd_10240]
vpbroadcastd m13, [pd_10239]
psrld m15, 10 ; pd_2
psubd m8, m13, m7
paddd m7, m14, m9
paddd m9, m14, m6
psubd m6, m13, m10
psubd m10, m13, m5
paddd m5, m14, m11
paddd m11, m14, m4
psubd m4, m13, m12
psubd m12, m15, m3
paddd m3, m15, [r6-32*1]
paddd m13, m15, m2
psubd m2, m15, [r6-32*2]
psubd m14, m15, m1
mova m1, m15
paddd m15, m0
psubd m0, m1, [r6-32*4]
paddd m1, [r6-32*3]
jmp m(iadst_16x16_internal_10bpc).pass1_end
.pass2:
call m(idct_16x16_internal_10bpc).transpose
lea r6, [pw_5+128]
mova [rsp], m15
call m(iadst_16x16_internal_8bpc).main
call m(iadst_16x16_internal_8bpc).main_pass2_end
mova [rsp+32*3], m3
mova [rsp+32*2], m2
mova [rsp+32*0], m0
mova m2, m13
mova m3, m12
vpbroadcastd m12, [pw_2048]
pxor m13, m13
psubw m13, m12
pmulhrsw m0, m13, m15
pmulhrsw m1, m12, m14
pmulhrsw m2, m13
pmulhrsw m3, m12
mova m14, m8
mova m15, m9
call m(idct_16x8_internal_10bpc).write_16x4_start
pmulhrsw m0, m13, m11
pmulhrsw m1, m12, m10
pmulhrsw m2, m13, m15
pmulhrsw m3, m12, m14
call m(idct_16x8_internal_10bpc).write_16x4_zero
pmulhrsw m0, m13, m7
pmulhrsw m1, m12, m6
pmulhrsw m2, m13, m5
pmulhrsw m3, m12, m4
call m(idct_16x8_internal_10bpc).write_16x4_zero
pmulhrsw m0, m13, [rsp+32*3]
pmulhrsw m1, m12, [rsp+32*2]
pmulhrsw m2, m13, [rsp+32*1]
pmulhrsw m3, m12, [rsp+32*0]
call m(idct_16x8_internal_10bpc).write_16x4_zero
RET
INV_TXFM_16X16_FN identity, dct, -92
INV_TXFM_16X16_FN identity, identity
cglobal iidentity_16x16_internal_10bpc, 0, 7, 16, 32*24, dst, stride, c, eob, tx2
.pass1:
vpbroadcastd m15, [pd_11586]
vpbroadcastd m7, [pd_10240]
lea r6, [rsp+32*4]
sub eobd, 36
jl .fast
mov r3, -32*8*4
.righthalf:
pmulld m0, m15, [cq+r3+32*33]
pmulld m1, m15, [cq+r3+32*35]
pmulld m2, m15, [cq+r3+32*37]
pmulld m3, m15, [cq+r3+32*39]
add r6, 32*4
REPX {paddd x, m7}, m0, m1, m2, m3
REPX {psrad x, 14}, m0, m1, m2, m3
mova [r6+32*0], m0
mova [r6+32*1], m1
mova [r6+32*2], m2
mova [r6+32*3], m3
add r3, 32*8
jl .righthalf
.fast:
pmulld m0, m15, [cq+64* 0]
pmulld m1, m15, [cq+64* 1]
pmulld m2, m15, [cq+64* 2]
pmulld m3, m15, [cq+64* 3]
pmulld m4, m15, [cq+64* 4]
pmulld m5, m15, [cq+64* 5]
pmulld m6, m15, [cq+64* 6]
pmulld m8, m15, [cq+64* 7]
mova [cq], m8
pmulld m8, m15, [cq+64* 8]
pmulld m9, m15, [cq+64* 9]
pmulld m10, m15, [cq+64*10]
pmulld m11, m15, [cq+64*11]
pmulld m12, m15, [cq+64*12]
pmulld m13, m15, [cq+64*13]
pmulld m14, m15, [cq+64*14]
pmulld m15, [cq+64*15]
REPX {paddd x, m7}, m0, m1, m2, m3, m4, m5, m6, \
m8, m9, m10, m11, m12, m13, m14, m15
paddd m7, [cq]
REPX {psrad x, 14}, m0, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14, m15
jmp tx2q
.pass2:
call m(idct_16x16_internal_10bpc).transpose
mova [cq+32*0], m15
mova [cq+32*1], m0
vpbroadcastd m15, [pw_1697x16]
REPX {IDTX16 x, 0, 15}, 1, 2, 3, 4, 5, 6, 7, \
8, 9, 10, 11, 12, 13, 14
mova m0, [cq+32*1]
mova [cq+32*1], m1
IDTX16 0, 1, 15
mova m1, [cq+32*0]
pmulhrsw m15, m1
paddsw m1, m1
paddsw m15, m1
mova m1, [cq+32*1]
jmp m(idct_16x16_internal_10bpc).end
INV_TXFM_16X16_FN dct, dct, 0, 12
INV_TXFM_16X16_FN dct, identity, 28, 12
INV_TXFM_16X16_FN dct, adst, 0, 12
INV_TXFM_16X16_FN dct, flipadst, 0, 12
cglobal idct_16x16_internal_12bpc, 0, 7, 16, 32*24, dst, stride, c, eob, tx2
vpbroadcastd m12, [clip_20b_min]
vpbroadcastd m13, [clip_20b_max]
jmp m(idct_16x16_internal_10bpc).pass1
.pass2:
mova [cq+32* 8], m8
mova [cq+32* 9], m9
mova [cq+32*10], m10
mova [cq+32*11], m11
mova [cq+32*12], m12
mova [cq+32*13], m13
mova [cq+32*14], m14
mova [cq+32*15], m15
call .pass2_main
packssdw m0, m1
packssdw m1, m2, m3
packssdw m2, m4, m5
packssdw m3, m6, m7
packssdw m4, m8, m9
packssdw m5, m10, m11
packssdw m6, m12, m13
packssdw m7, m14, m15
mova [r6-32*4], m0
mova [r6-32*3], m1
mova [r6-32*2], m2
mova [r6-32*1], m3
mova [r6+32*0], m4
mova [r6+32*1], m5
mova [r6+32*2], m6
mova [r6+32*3], m7
mova m0, [cq+32* 8]
mova m1, [cq+32* 9]
mova m2, [cq+32*10]
mova m3, [cq+32*11]
mova m4, [cq+32*12]
mova m5, [cq+32*13]
mova m6, [cq+32*14]
mova m7, [cq+32*15]
mov r5, r6
add r6, 32*16
call .pass2_main
jmp m(iadst_16x16_internal_12bpc).end
ALIGN function_align
.write_16x16:
mova [rsp+gprsize+32*0], m8
mova [rsp+gprsize+32*1], m9
mova [rsp+gprsize+32*2], m12
vpbroadcastd m12, [pw_16384]
pmulhrsw m0, m12
pmulhrsw m1, m12
pmulhrsw m2, m12
pmulhrsw m3, m12
call m(idct_16x8_internal_12bpc).write_16x4_start
call m(idct_16x8_internal_10bpc).write_16x4_zero
jmp m(idct_16x16_internal_10bpc).write_16x16_2
ALIGN function_align
.pass2_main:
call m(idct_8x8_internal_12bpc).transpose_8x8
mova [cq+32* 0], m0
mova [cq+32* 1], m2
mova [cq+32* 2], m4
mova [cq+32* 3], m6
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
pmaxsd m0, m12, m1
pmaxsd m1, m12, m3
pmaxsd m2, m12, m5
pmaxsd m3, m12, m7
REPX {pminsd x, m13}, m0, m1, m2, m3
test eobd, eobd
jge .pass2_slow
pxor m4, m4
REPX {mova x, m4}, m5, m6, m7
jmp .pass2_fast
.pass2_slow:
sub r6, 32*8
mova m8, [r6-32*4]
mova m4, [r6-32*3]
mova m10, [r6-32*2]
mova m5, [r6-32*1]
mova m12, [r6+32*0]
mova m6, [r6+32*1]
mova m14, [r6+32*2]
mova m7, [r6+32*3]
TRANSPOSE_8X8_DWORD 8, 4, 10, 5, 12, 6, 14, 7, 9, 11, 13, 15
mova [cq+32* 4], m8
mova [cq+32* 5], m10
mova [cq+32* 6], m12
mova [cq+32* 7], m14
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
REPX {pmaxsd x, m12}, m4, m5, m6, m7
REPX {pminsd x, m13}, m4, m5, m6, m7
.pass2_fast:
vpbroadcastd m11, [pd_2048]
vpbroadcastd m14, [pd_2896]
call m(idct_8x16_internal_10bpc).main_oddhalf
pmaxsd m0, m12, [cq+32* 0]
pmaxsd m1, m12, [cq+32* 1]
pmaxsd m2, m12, [cq+32* 2]
pmaxsd m3, m12, [cq+32* 3]
REPX {pminsd x, m13}, m0, m1, m2, m3
test eobd, eobd
jge .pass2_slow2
pxor m4, m4
REPX {mova x, m4}, m5, m6, m7
jmp .pass2_fast2
.pass2_slow2:
pmaxsd m4, m12, [cq+32* 4]
pmaxsd m5, m12, [cq+32* 5]
pmaxsd m6, m12, [cq+32* 6]
pmaxsd m7, m12, [cq+32* 7]
REPX {pminsd x, m13}, m4, m5, m6, m7
.pass2_fast2:
call m(idct_8x8_internal_10bpc).main
call m(idct_8x16_internal_10bpc).main_evenhalf
psrad m11, 8 ; pd_8
REPX {paddd x, m11}, m0, m1, m2, m3, m4, m5, m6, m7
call m(idct_16x8_internal_10bpc).pass1_rotations
REPX {psrad x, 4}, m0, m1, m2, m3, m4, m5, m6, m7, \
m8, m9, m10, m11, m12, m13, m14, m15
ret
INV_TXFM_16X16_FN adst, dct, 0, 12
INV_TXFM_16X16_FN adst, adst, 0, 12
INV_TXFM_16X16_FN adst, flipadst, 0, 12
cglobal iadst_16x16_internal_12bpc, 0, 7, 16, 32*24, dst, stride, c, eob, tx2
vpbroadcastd m13, [clip_20b_min]
vpbroadcastd m14, [clip_20b_max]
jmp m(iadst_16x16_internal_10bpc).pass1
.pass2:
call .pass2_part1
call m(iadst_16x8_internal_10bpc).pass1_rotations
call .pass2_part2
call m(iadst_16x8_internal_10bpc).pass1_rotations
.pass2_part3:
REPX {psrad x, 4 }, m0, m1, m2, m3, m12, m13, m14, m15
REPX {psrad x, 16}, m4, m5, m6, m7, m8, m9, m10, m11
.end:
packssdw m15, m14
packssdw m14, m13, m12
packssdw m13, m11, m10
packssdw m12, m9, m8
packssdw m11, m7, m6
packssdw m10, m5, m4
packssdw m7, m3, m2
packssdw m6, m1, m0
vpblendd m0, m6, [r5-32*4], 0x33
vpblendd m1, m6, [r5-32*4], 0xcc
vpblendd m2, m7, [r5-32*3], 0x33
vpblendd m3, m7, [r5-32*3], 0xcc
vpermq m0, m0, q3120
vpermq m1, m1, q2031
vpermq m2, m2, q3120
vpermq m3, m3, q2031
call m(idct_16x8_internal_12bpc).write_16x4_start
call m(idct_16x8_internal_10bpc).write_16x4_zero
vpblendd m0, m10, [r5-32*2], 0x33
vpblendd m1, m10, [r5-32*2], 0xcc
vpblendd m2, m11, [r5-32*1], 0x33
vpblendd m3, m11, [r5-32*1], 0xcc
vpermq m0, m0, q3120
vpermq m1, m1, q2031
vpermq m2, m2, q3120
vpermq m3, m3, q2031
call m(idct_16x8_internal_10bpc).write_16x4_zero
vpblendd m0, m12, [r5+32*0], 0x33
vpblendd m1, m12, [r5+32*0], 0xcc
vpblendd m2, m13, [r5+32*1], 0x33
vpblendd m3, m13, [r5+32*1], 0xcc
vpermq m0, m0, q3120
vpermq m1, m1, q2031
vpermq m2, m2, q3120
vpermq m3, m3, q2031
call m(idct_16x8_internal_10bpc).write_16x4_zero
vpblendd m0, m14, [r5+32*2], 0x33
vpblendd m1, m14, [r5+32*2], 0xcc
vpblendd m2, m15, [r5+32*3], 0x33
vpblendd m3, m15, [r5+32*3], 0xcc
vpermq m0, m0, q3120
vpermq m1, m1, q2031
vpermq m2, m2, q3120
vpermq m3, m3, q2031
call m(idct_16x8_internal_10bpc).write_16x4_zero
RET
ALIGN function_align
.pass2_part1:
mova [cq+32* 8], m8
mova [cq+32* 9], m9
mova [cq+32*10], m10
mova [cq+32*11], m11
mova [cq+32*12], m12
mova [cq+32*13], m13
mova [cq+32*14], m14
mova [cq+32*15], m15
.pass2_main:
call m(idct_8x8_internal_12bpc).transpose_8x8
mova [cq+32* 0], m0
mova [cq+32* 1], m3
mova [cq+32* 2], m4
mova [cq+32* 3], m7
vpbroadcastd m13, [clip_18b_min]
vpbroadcastd m14, [clip_18b_max]
pmaxsd m0, m13, m2
pmaxsd m2, m13, m6
pmaxsd m5, m13, m5
pmaxsd m7, m13, m1
REPX {pminsd x, m14}, m0, m2, m5, m7
test eobd, eobd
jge .pass2_slow
pxor m1, m1
REPX {mova x, m1}, m3, m4, m6
jmp .pass2_fast
.pass2_slow:
sub r6, 32*8
mova m8, [r6-32*4]
mova m3, [r6-32*3]
mova m4, [r6-32*2]
mova m11, [r6-32*1]
mova m12, [r6+32*0]
mova m1, [r6+32*1]
mova m6, [r6+32*2]
mova m15, [r6+32*3]
TRANSPOSE_8X8_DWORD 8, 3, 4, 11, 12, 1, 6, 15, 13, 9, 10, 14
mova [cq+32* 4], m8
mova [cq+32* 5], m11
mova [cq+32* 6], m12
mova [cq+32* 7], m15
vpbroadcastd m13, [clip_18b_min]
vpbroadcastd m14, [clip_18b_max]
REPX {pmaxsd x, m13}, m1, m3, m4, m6
REPX {pminsd x, m14}, m1, m3, m4, m6
.pass2_fast:
vpbroadcastd m12, [pd_2048]
vpbroadcastd m15, [pd_2896]
call m(iadst_16x8_internal_10bpc).main_part1
pmaxsd m0, m13, [cq+32* 0] ; 0
pmaxsd m7, m13, [cq+32* 1] ; 3
pmaxsd m2, m13, [cq+32* 2] ; 4
pmaxsd m5, m13, [cq+32* 3] ; 7
REPX {pminsd x, m14}, m0, m2, m5, m7
test eobd, eobd
jge .pass2_slow2
pxor m1, m1
REPX {mova x, m1}, m3, m4, m6
jmp .pass2_fast2
.pass2_slow2:
pmaxsd m4, m13, [cq+32* 4] ; 8
pmaxsd m3, m13, [cq+32* 5] ; 11
pmaxsd m6, m13, [cq+32* 6] ; 12
pmaxsd m1, m13, [cq+32* 7] ; 15
REPX {pminsd x, m14}, m1, m3, m4, m6
.pass2_fast2:
call m(iadst_16x8_internal_10bpc).main_part2
vpbroadcastd m14, [pd_34816]
psrld m15, 11 ; pd_1
psubd m13, m14, m15 ; pd_34815
pslld m15, 3 ; pd_8
ret
ALIGN function_align
.pass2_part2:
REPX {psrad x, 4 }, m0, m1, m2, m3, m12, m13, m14, m15
REPX {psrad x, 16}, m4, m5, m6, m7, m8, m9, m10, m11
packssdw m0, m1
packssdw m1, m2, m3
packssdw m2, m4, m5
packssdw m3, m6, m7
packssdw m4, m8, m9
packssdw m5, m10, m11
packssdw m6, m12, m13
packssdw m7, m14, m15
mova [r6-32*4], m0
mova [r6-32*3], m1
mova [r6-32*2], m2
mova [r6-32*1], m3
mova [r6+32*0], m4
mova [r6+32*1], m5
mova [r6+32*2], m6
mova [r6+32*3], m7
mova m0, [cq+32* 8]
mova m1, [cq+32* 9]
mova m2, [cq+32*10]
mova m3, [cq+32*11]
mova m4, [cq+32*12]
mova m5, [cq+32*13]
mova m6, [cq+32*14]
mova m7, [cq+32*15]
mov r5, r6
add r6, 32*16
jmp .pass2_main
INV_TXFM_16X16_FN flipadst, dct, 0, 12
INV_TXFM_16X16_FN flipadst, adst, 0, 12
INV_TXFM_16X16_FN flipadst, flipadst, 0, 12
cglobal iflipadst_16x16_internal_12bpc, 0, 7, 16, 32*24, dst, stride, c, eob, tx2
vpbroadcastd m13, [clip_20b_min]
vpbroadcastd m14, [clip_20b_max]
jmp m(iflipadst_16x16_internal_10bpc).pass1
.pass2:
call m(iadst_16x16_internal_12bpc).pass2_part1
call m(iflipadst_16x8_internal_10bpc).pass1_rotations
call m(iadst_16x16_internal_12bpc).pass2_part2
call m(iflipadst_16x8_internal_10bpc).pass1_rotations
jmp m(iadst_16x16_internal_12bpc).pass2_part3
INV_TXFM_16X16_FN identity, dct, -92, 12
INV_TXFM_16X16_FN identity, identity, 0, 12
cglobal iidentity_16x16_internal_12bpc, 0, 7, 16, 32*24, dst, stride, c, eob, tx2
jmp m(iidentity_16x16_internal_10bpc).pass1
.pass2:
call m(iidentity_8x16_internal_12bpc).pass2_main
call m(idct_16x16_internal_10bpc).transpose_fast
test eobd, eobd
jl .pass2_fast
mova [cq+32* 8], m0
mova [cq+32* 9], m1
mova [cq+32*10], m2
mova [cq+32*11], m3
mova [cq+32*12], m4
mova [cq+32*13], m5
mova [cq+32*14], m6
mova [cq+32*15], m7
mova m8, [r6-32*4]
mova m9, [r6-32*3]
mova m10, [r6-32*2]
mova m11, [r6-32*1]
mova m12, [r6+32*0]
mova m13, [r6+32*1]
mova m14, [r6+32*2]
mova m15, [r6+32*3]
sub r6, 32*8
mova m0, [r6-32*4]
mova m1, [r6-32*3]
mova m2, [r6-32*2]
mova m3, [r6-32*1]
mova m4, [r6+32*0]
mova m5, [r6+32*1]
mova m6, [r6+32*2]
mova m7, [r6+32*3]
call m(iidentity_8x16_internal_12bpc).pass2_main
call m(idct_16x8_internal_10bpc).transpose2
mova m8, m0
mova m9, m1
mova m10, m2
mova m11, m3
mova m12, m4
mova m13, m5
mova m14, m6
mova m15, m7
mova m0, [cq+32* 8]
mova m1, [cq+32* 9]
mova m2, [cq+32*10]
mova m3, [cq+32*11]
mova m4, [cq+32*12]
mova m5, [cq+32*13]
mova m6, [cq+32*14]
mova m7, [cq+32*15]
.pass2_fast:
call m(idct_16x16_internal_12bpc).write_16x16
RET
%macro IDCT32_END 6 ; in/out1, out2, tmp[1-3], shift
mova m%4, [r6+32*(%1-4)]
mova m%2, [r5+32*(3-%1)]
mova m%5, [r4+32*(%1-4)]
psubd m%3, m%1, m%4 ; idct16 out15 - n
paddd m%1, m%4 ; idct16 out0 + n
pmaxsd m%1, m12
pmaxsd m%3, m12
pminsd m%1, m13
pminsd m%3, m13
paddd m%1, m11
paddd m%3, m11
psubd m%4, m%1, m%2 ; out31 - n
paddd m%1, m%2 ; out0 + n
paddd m%2, m%3, m%5 ; out15 - n
psubd m%3, m%5 ; out16 + n
REPX {psrad x, %6}, m%1, m%3, m%2, m%4
packssdw m%1, m%3 ; out0 + n, out16 + n
packssdw m%2, m%4 ; out15 - n, out31 - n
%endmacro
cglobal inv_txfm_add_dct_dct_8x32_10bpc, 4, 7, 0, dst, stride, c, eob
test eobd, eobd
jz .dconly
PROLOGUE 0, 7, 16, 32*12, dst, stride, c, eob
%undef cmp
vpbroadcastd m11, [pd_2048]
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
vbroadcasti128 m14, [idct32_shuf]
mov r4, cq
call .pass1_main
mova [rsp+32*0], m2
mova [rsp+32*1], m3
cmp eobd, 43
jge .eob43
pxor m4, m4
REPX {mova x, m4}, [rsp+32*2], m2, m3, m11
jmp .pass1_end_fast
.eob43:
lea r6, [rsp+32*8]
mova [r6-32*4], m0
mova [r6-32*3], m1
call .pass1_main
mova [rsp+32*2], m2
cmp eobd, 107
jge .eob107
mova m11, m3
mova m2, m0
mova m3, m1
mova m0, [r6-32*4]
mova m1, [r6-32*3]
pxor m4, m4
.pass1_end_fast:
vpbroadcastd m10, [pw_2048]
lea r6, [deint_shuf+128]
REPX {mova x, m4}, m5, m6, m7
call m(inv_txfm_add_dct_dct_8x32_8bpc).main_fast
jmp .end
.eob107:
mova [rsp+32*3], m3
mova [r6-32*2], m0
mova [r6-32*1], m1
call .pass1_main
cmp eobd, 171
jge .eob171
pshufd m12, m2, q1032
pshufd m13, m3, q1032
mova m4, m0
mova m5, m1
pxor m6, m6
REPX {mova x, m6}, m7, m14, m15
jmp .pass1_end
.eob171:
mova [r6+32*0], m0
mova [r6+32*1], m1
mova [r6+32*2], m2
mova [r6+32*3], m3
call .pass1_main
pshufd m12, [r6+32*2], q1032 ; out19 out17
pshufd m13, [r6+32*3], q1032 ; out23 out21
mova m4, [r6+32*0] ; out16 out18
mova m5, [r6+32*1] ; out20 out22
pshufd m14, m2, q1032 ; out27 out25
pshufd m15, m3, q1032 ; out31 out29
mova m6, m0 ; out24 out26
mova m7, m1 ; out28 out30
.pass1_end:
mova m0, [r6-32*4] ; out0 out2
mova m1, [r6-32*3] ; out4 out6
mova m2, [r6-32*2] ; out8 out10
mova m3, [r6-32*1] ; out12 out14
lea r6, [deint_shuf+128]
mova m11, [rsp+32*3] ; out13 out15
vpbroadcastd m10, [pw_2048]
call m(inv_txfm_add_dct_dct_8x32_8bpc).main
.end: ; [rsp+0*32] = m12
vpbroadcastd m12, [pw_2048]
mov cq, r4
mova [rsp+32*1], m8
mova [rsp+32*2], m9
mova [rsp+32*3], m10
mova [rsp+32*4], m11
vpermq m0, m0, q3120
vpermq m1, m1, q2031
pmulhrsw m0, m12
pmulhrsw m1, m12
call m(idct_8x8_internal_10bpc).write_8x4_start
vpermq m0, m2, q3120
vpermq m1, m3, q2031
pmulhrsw m0, m12
pmulhrsw m1, m12
call m(idct_8x8_internal_10bpc).write_8x4
vpermq m0, m4, q3120
vpermq m1, m5, q2031
pmulhrsw m0, m12
pmulhrsw m1, m12
call m(idct_8x8_internal_10bpc).write_8x4
vpermq m0, m6, q3120
vpermq m1, m7, q2031
pmulhrsw m0, m12
pmulhrsw m1, m12
call m(idct_8x8_internal_10bpc).write_8x4
vpermq m0, [rsp+32*1], q3120
vpermq m1, [rsp+32*2], q2031
pmulhrsw m0, m12
pmulhrsw m1, m12
call m(idct_8x8_internal_10bpc).write_8x4
vpermq m0, [rsp+32*3], q3120
vpermq m1, [rsp+32*4], q2031
pmulhrsw m0, m12
pmulhrsw m1, m12
call m(idct_8x8_internal_10bpc).write_8x4
vpermq m0, [rsp+32*0], q3120
vpermq m1, m13, q2031
pmulhrsw m0, m12
pmulhrsw m1, m12
call m(idct_8x8_internal_10bpc).write_8x4
vpermq m0, m14, q3120
vpermq m1, m15, q2031
pmulhrsw m0, m12
pmulhrsw m1, m12
call m(idct_8x8_internal_10bpc).write_8x4
RET
.dconly:
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 32
add r6d, 10240
sar r6d, 14
jmp m(inv_txfm_add_dct_dct_8x8_10bpc).dconly2
ALIGN function_align
.pass1_main:
mova m0, [cq+128*0]
mova m1, [cq+128*1]
mova m2, [cq+128*2]
mova m3, [cq+128*3]
mova m4, [cq+128*4]
mova m5, [cq+128*5]
mova m6, [cq+128*6]
mova m7, [cq+128*7]
add cq, 32
call m(idct_8x8_internal_10bpc).main
psrld m1, m11, 10 ; pd_2
REPX {paddd x, m1}, m0, m6, m5, m3
paddd m1, m6, m7 ; out1
psubd m6, m7 ; out6
psubd m7, m0, m9 ; out7
paddd m0, m9 ; out0
paddd m2, m5, m4 ; out2
psubd m5, m4 ; out5
psubd m4, m3, m8 ; out4
paddd m3, m8 ; out3
REPX {psrad x, 2 }, m0, m1, m2, m3, m4, m5, m6, m7
packssdw m0, m1
packssdw m2, m3
packssdw m4, m5
packssdw m6, m7
pshufb m0, m14
pshufb m2, m14
pshufb m4, m14
pshufb m6, m14
punpckhdq m3, m0, m2
punpckldq m0, m2
punpckldq m2, m4, m6
punpckhdq m4, m6
vperm2i128 m1, m0, m2, 0x31 ; 4 6
vinserti128 m0, xm2, 1 ; 0 2
vinserti128 m2, m3, xm4, 1 ; 1 3
vperm2i128 m3, m4, 0x31 ; 5 7
ret
.main_oddhalf_part1_fast_rect2:
REPX {paddd x, m11}, m0, m1, m2, m3
REPX {psrad x, 12 }, m0, m1, m2, m3
.main_oddhalf_part1_fast: ; lower half zero
vpbroadcastd m7, [pd_4091]
vpbroadcastd m8, [pd_201]
vpbroadcastd m6, [pd_m1380]
vpbroadcastd m9, [pd_3857]
vpbroadcastd m5, [pd_3703]
vpbroadcastd m10, [pd_1751]
vpbroadcastd m4, [pd_m2751]
vpbroadcastd m15, [pd_3035]
pmulld m7, m0
pmulld m0, m8
pmulld m6, m1
pmulld m1, m9
pmulld m5, m2
pmulld m2, m10
pmulld m4, m3
pmulld m3, m15
jmp .main_oddhalf_part1_fast2
.main_oddhalf_part1_rect2:
REPX {paddd x, m11}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {psrad x, 12 }, m0, m1, m2, m3, m4, m5, m6, m7
.main_oddhalf_part1: ; in1, in7, in9, in15, in17, in23, in25, in31
ITX_MULSUB_2D 0, 7, 8, 9, 10, _, 201, 4091 ; t16a, t31a
ITX_MULSUB_2D 6, 1, 8, 9, 10, _, 3857, 1380 ; t19a, t28a
ITX_MULSUB_2D 2, 5, 8, 9, 10, _, 1751, 3703 ; t18a, t29a
ITX_MULSUB_2D 4, 3, 8, 9, 10, _, 3035, 2751 ; t17a, t30a
.main_oddhalf_part1_fast2:
REPX {paddd x, m11}, m0, m7, m6, m1, m2, m5, m4, m3
REPX {psrad x, 12 }, m0, m4, m6, m2, m1, m5, m7, m3
psubd m8, m0, m4 ; t17
paddd m0, m4 ; t16
psubd m4, m6, m2 ; t18
paddd m6, m2 ; t19
psubd m2, m1, m5 ; t29
paddd m1, m5 ; t28
psubd m5, m7, m3 ; t30
paddd m7, m3 ; t31
REPX {pmaxsd x, m12}, m8, m5, m4, m2, m0, m6, m1, m7
REPX {pminsd x, m13}, m8, m5, m4, m2, m0, m6, m1, m7
vpbroadcastd m15, [pd_4017]
vpbroadcastd m10, [pd_799]
ITX_MULSUB_2D 5, 8, 3, 9, _, 11, 10, 15 ; t17a, t30a
ITX_MULSUB_2D 2, 4, 3, 9, _, 11, 10, 15, 4 ; t29a, t18a
psubd m3, m0, m6 ; t19a
paddd m0, m6 ; t16a
psubd m6, m7, m1 ; t28a
paddd m7, m1 ; t31a
psubd m1, m5, m4 ; t18
paddd m5, m4 ; t17
psubd m4, m8, m2 ; t29
paddd m8, m2 ; t30
REPX {pmaxsd x, m12}, m3, m6, m1, m4, m0, m7, m5, m8
REPX {pminsd x, m13}, m3, m6, m1, m4, m0, m7, m5, m8
vpbroadcastd m15, [pd_3784]
vpbroadcastd m10, [pd_1567]
ITX_MULSUB_2D 4, 1, 2, 9, _, 11, 10, 15 ; t18a, t29a
ITX_MULSUB_2D 6, 3, 2, 9, _, 11, 10, 15 ; t19, t28
mova [r6-32*4], m0
mova [r6-32*3], m5
mova [r6-32*2], m4
mova [r6-32*1], m6
mova [r6+32*0], m3
mova [r6+32*1], m1
mova [r6+32*2], m8
mova [r6+32*3], m7
ret
.main_oddhalf_part2_fast_rect2:
REPX {paddd x, m11}, m0, m1, m2, m3
REPX {psrad x, 12 }, m0, m1, m2, m3
.main_oddhalf_part2_fast: ; lower half zero
vpbroadcastd m7, [pd_m601]
vpbroadcastd m8, [pd_4052]
vpbroadcastd m6, [pd_3973]
vpbroadcastd m9, [pd_995]
vpbroadcastd m5, [pd_m2106]
vpbroadcastd m10, [pd_3513]
vpbroadcastd m4, [pd_3290]
vpbroadcastd m15, [pd_2440]
pmulld m7, m0
pmulld m0, m8
pmulld m6, m1
pmulld m1, m9
pmulld m5, m2
pmulld m2, m10
pmulld m4, m3
pmulld m3, m15
jmp .main_oddhalf_part2_fast2
.main_oddhalf_part2_rect2:
REPX {paddd x, m11}, m0, m1, m2, m3, m4, m5, m6, m7
REPX {psrad x, 12 }, m0, m1, m2, m3, m4, m5, m6, m7
.main_oddhalf_part2: ; in3, in5, in11, in13, in19, in21, in27, in29
ITX_MULSUB_2D 7, 0, 8, 9, 10, _, 4052, 601 ; t23a, t24a
ITX_MULSUB_2D 1, 6, 8, 9, 10, _, 995, 3973 ; t20a, t27a
ITX_MULSUB_2D 5, 2, 8, 9, 10, _, 3513, 2106 ; t21a, t26a
ITX_MULSUB_2D 3, 4, 8, 9, 10, _, 2440, 3290 ; t22a, t25a
.main_oddhalf_part2_fast2:
REPX {paddd x, m11}, m0, m7, m6, m1, m2, m5, m4, m3
REPX {psrad x, 12 }, m0, m4, m6, m2, m1, m5, m7, m3
psubd m8, m0, m4 ; t25
paddd m0, m4 ; t24
psubd m4, m6, m2 ; t26
paddd m6, m2 ; t27
psubd m2, m1, m5 ; t21
paddd m1, m5 ; t20
psubd m5, m7, m3 ; t22
paddd m7, m3 ; t23
REPX {pmaxsd x, m12}, m8, m5, m4, m2, m0, m6, m1, m7
REPX {pminsd x, m13}, m8, m5, m4, m2, m0, m6, m1, m7
vpbroadcastd m15, [pd_2276]
vpbroadcastd m10, [pd_3406]
ITX_MULSUB_2D 4, 2, 3, 9, _, 11, 10, 15 ; t21a, t26a
ITX_MULSUB_2D 8, 5, 3, 9, _, 11, 10, 15, 4 ; t25a, t22a
psubd m3, m0, m6 ; t27a
paddd m0, m6 ; t24a
psubd m6, m7, m1 ; t20a
paddd m7, m1 ; t23a
psubd m1, m5, m4 ; t21
paddd m5, m4 ; t22
psubd m4, m8, m2 ; t26
paddd m8, m2 ; t25
REPX {pmaxsd x, m12}, m3, m6, m1, m4, m0, m7, m5, m8
REPX {pminsd x, m13}, m3, m6, m1, m4, m0, m7, m5, m8
vpbroadcastd m15, [pd_3784]
vpbroadcastd m10, [pd_1567]
ITX_MULSUB_2D 4, 1, 2, 9, _, 11, 10, 15, 4 ; t26a, t21a
ITX_MULSUB_2D 3, 6, 2, 9, _, 11, 10, 15, 4 ; t27, t20
mova m9, [r6-32*4] ; t16a
mova m10, [r6-32*3] ; t17
psubd m2, m9, m7 ; t23
paddd m9, m7 ; t16
psubd m7, m10, m5 ; t22a
paddd m10, m5 ; t17a
REPX {pmaxsd x, m12}, m9, m10, m2, m7
REPX {pminsd x, m13}, m9, m10, m2, m7
mova [r6-32*4], m9
mova [r6-32*3], m10
mova m9, [r6-32*2] ; t18a
mova m10, [r6-32*1] ; t19
psubd m5, m9, m1 ; t21
paddd m9, m1 ; t18
psubd m1, m10, m6 ; t20a
paddd m10, m6 ; t19a
REPX {pmaxsd x, m12}, m9, m10, m5, m1
REPX {pminsd x, m13}, m9, m10, m5, m1
mova [r6-32*2], m9
mova [r6-32*1], m10
mova m9, [r6+32*0] ; t28
mova m10, [r6+32*1] ; t29a
psubd m6, m9, m3 ; t27a
paddd m9, m3 ; t28a
psubd m3, m10, m4 ; t26
paddd m10, m4 ; t29
REPX {pmaxsd x, m12}, m9, m10, m6, m3
REPX {pminsd x, m13}, m9, m10, m6, m3
REPX {pmulld x, m14}, m6, m3, m1, m5
paddd m6, m11
paddd m3, m11
psubd m4, m6, m1 ; t20
paddd m6, m1 ; t27
psubd m1, m3, m5 ; t21a
paddd m3, m5 ; t26a
REPX {psrad x, 12 }, m4, m1, m3, m6
mova [r6+32*0], m4
mova [r6+32*1], m1
mova m4, [r6+32*2] ; t30
mova m1, [r6+32*3] ; t31a
psubd m5, m4, m8 ; t25a
paddd m4, m8 ; t30a
psubd m8, m1, m0 ; t24
paddd m1, m0 ; t31
REPX {pmaxsd x, m12}, m8, m5, m4, m1
REPX {pminsd x, m13}, m8, m5, m4, m1
REPX {pmulld x, m14}, m5, m8, m7, m2
paddd m5, m11
paddd m8, m11
psubd m0, m5, m7 ; t22
paddd m5, m7 ; t25
psubd m7, m8, m2 ; t23a
paddd m2, m8 ; t24a
REPX {psrad x, 12 }, m0, m7, m2, m5
mova [r6+32*2], m0
mova [r6+32*3], m7
mov r4, r6
add r6, 32*8
mova [r6-32*4], m2
mova [r6-32*3], m5
mova [r6-32*2], m3
mova [r6-32*1], m6
mova [r6+32*0], m9
mova [r6+32*1], m10
mova [r6+32*2], m4
mova [r6+32*3], m1
mov r5, r6
add r6, 32*8
ret
ALIGN function_align
.main_end:
psrld m11, 10 ; pd_2
IDCT32_END 0, 15, 8, 9, 10, 2
IDCT32_END 1, 14, 8, 9, 10, 2
punpckhwd m8, m0, m1 ; 16 17
punpcklwd m0, m1 ; 0 1
punpcklwd m1, m14, m15 ; 14 15
punpckhwd m14, m15 ; 30 31
mova [r5+32*3], m8
mova [r5+32*2], m14
IDCT32_END 2, 15, 8, 9, 10, 2
IDCT32_END 3, 14, 8, 9, 10, 2
punpckhwd m8, m2, m3 ; 18 19
punpcklwd m2, m3 ; 2 3
punpcklwd m3, m14, m15 ; 12 13
punpckhwd m14, m15 ; 28 29
mova [r5+32*1], m8
mova [r5+32*0], m14
IDCT32_END 4, 15, 8, 9, 10, 2
IDCT32_END 5, 14, 8, 9, 10, 2
punpckhwd m8, m4, m5 ; 20 21
punpcklwd m4, m5 ; 4 5
punpcklwd m5, m14, m15 ; 10 11
punpckhwd m14, m15 ; 26 27
mova [r5-32*1], m8
mova [r5-32*2], m14
IDCT32_END 6, 15, 8, 9, 10, 2
IDCT32_END 7, 14, 8, 9, 10, 2
punpckhwd m8, m6, m7 ; 22 23
punpcklwd m6, m7 ; 6 7
punpcklwd m7, m14, m15 ; 8 9
punpckhwd m14, m15 ; 24 25
mova [r5-32*3], m8
mova [r5-32*4], m14
.transpose:
punpckhdq m15, m3, m1
punpckldq m3, m1
punpckhdq m1, m4, m6
punpckldq m4, m6
punpckhdq m6, m0, m2
punpckldq m0, m2
punpckhdq m2, m7, m5
punpckldq m7, m5
punpcklqdq m5, m2, m15
punpckhqdq m2, m15
punpckhqdq m15, m7, m3
punpcklqdq m7, m3
punpckhqdq m3, m6, m1
punpcklqdq m6, m1
punpckhqdq m1, m0, m4
punpcklqdq m0, m4
vperm2i128 m4, m0, m7, 0x31
vinserti128 m0, xm7, 1
vperm2i128 m7, m3, m2, 0x31
vinserti128 m3, xm2, 1
vinserti128 m2, m6, xm5, 1
vperm2i128 m6, m5, 0x31
vperm2i128 m5, m1, m15, 0x31
vinserti128 m1, xm15, 1
ret
cglobal inv_txfm_add_identity_identity_8x32_10bpc, 4, 7, 8, dst, stride, c, eob
vpbroadcastd m5, [pw_5]
vpbroadcastd m7, [pixel_10bpc_max]
pxor m6, m6
mov r6d, eobd
add eobb, 21
cmovc eobd, r6d ; 43, 107, 171 -> 64, 128, 192
lea r6, [strideq*3]
lea r5, [strideq*5]
lea r4, [strideq+r6*2] ; strideq*7
.loop:
mova m0, [cq+128*0]
packssdw m0, [cq+128*1]
mova m1, [cq+128*2]
packssdw m1, [cq+128*3]
mova m2, [cq+128*4]
packssdw m2, [cq+128*5]
mova m3, [cq+128*6]
packssdw m3, [cq+128*7]
REPX {paddsw x, m5}, m0, m1, m2, m3
REPX {psraw x, 3 }, m0, m1, m2, m3
call .main_zero
add cq, 32
lea dstq, [dstq+strideq*8]
sub eobd, 64
jge .loop
RET
ALIGN function_align
.main_zero:
REPX {mova [cq+128*x], m6}, 0, 1, 2, 3, 4, 5, 6, 7
.main:
punpckhwd m4, m0, m1
punpcklwd m0, m1
punpckhwd m1, m2, m3
punpcklwd m2, m3
punpckhwd m3, m0, m4
punpcklwd m0, m4
punpckhwd m4, m2, m1
punpcklwd m2, m1
punpckhqdq m1, m0, m2
punpcklqdq m0, m2
punpcklqdq m2, m3, m4
punpckhqdq m3, m4
mova xm4, [dstq+strideq*0]
vinserti128 m4, [dstq+strideq*4], 1
paddw m0, m4
mova xm4, [dstq+strideq*1]
vinserti128 m4, [dstq+r5 ], 1
paddw m1, m4
mova xm4, [dstq+strideq*2]
vinserti128 m4, [dstq+r6*2 ], 1
paddw m2, m4
mova xm4, [dstq+r6 ]
vinserti128 m4, [dstq+r4 ], 1
paddw m3, m4
REPX {pmaxsw x, m6}, m0, m1, m2, m3
REPX {pminsw x, m7}, m0, m1, m2, m3
mova [dstq+strideq*0], xm0
vextracti128 [dstq+strideq*4], m0, 1
mova [dstq+strideq*1], xm1
vextracti128 [dstq+r5 ], m1, 1
mova [dstq+strideq*2], xm2
vextracti128 [dstq+r6*2 ], m2, 1
mova [dstq+r6 ], xm3
vextracti128 [dstq+r4 ], m3, 1
ret
cglobal inv_txfm_add_dct_dct_32x8_10bpc, 4, 7, 0, dst, stride, c, eob
test eobd, eobd
jnz .full
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 8
.dconly:
add r6d, 10240
sar r6d, 14
.dconly2:
imul r6d, 2896
add r6d, 34816
sar r6d, 16
movd xm0, r6d
vpbroadcastw m0, xm0
vpbroadcastd m4, [pixel_10bpc_max]
pxor m3, m3
.dconly_loop:
paddw m1, m0, [dstq+32*0]
paddw m2, m0, [dstq+32*1]
pmaxsw m1, m3
pmaxsw m2, m3
pminsw m1, m4
pminsw m2, m4
mova [dstq+32*0], m1
mova [dstq+32*1], m2
add dstq, strideq
dec r3d
jg .dconly_loop
RET
.full:
PROLOGUE 0, 7, 16, 32*24, dst, stride, c, eob
mova m0, [cq+32* 1]
mova m1, [cq+32* 7]
mova m2, [cq+32* 9]
mova m3, [cq+32*15]
mova m4, [cq+32*17]
mova m5, [cq+32*23]
mova m6, [cq+32*25]
mova m7, [cq+32*31]
vpbroadcastd m11, [pd_2048]
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
vpbroadcastd m14, [pd_2896]
lea r6, [rsp+32*4]
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_oddhalf_part1
mova m0, [cq+32* 3]
mova m1, [cq+32* 5]
mova m2, [cq+32*11]
mova m3, [cq+32*13]
mova m4, [cq+32*19]
mova m5, [cq+32*21]
mova m6, [cq+32*27]
mova m7, [cq+32*29]
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_oddhalf_part2
mova m0, [cq+32* 2]
mova m1, [cq+32* 6]
mova m2, [cq+32*10]
mova m3, [cq+32*14]
mova m4, [cq+32*18]
mova m5, [cq+32*22]
mova m6, [cq+32*26]
mova m7, [cq+32*30]
call m(idct_8x16_internal_10bpc).main_oddhalf
mova m0, [cq+32* 0]
mova m1, [cq+32* 4]
mova m2, [cq+32* 8]
mova m3, [cq+32*12]
mova m4, [cq+32*16]
mova m5, [cq+32*20]
mova m6, [cq+32*24]
mova m7, [cq+32*28]
call m(idct_8x8_internal_10bpc).main
call m(idct_8x16_internal_10bpc).main_evenhalf
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_end
lea r6, [deint_shuf+128]
vpbroadcastd m11, [pw_2048]
mov r4, dstq
call .pass2
mova m0, [r5+32*3] ; 16 17
mova m1, [r5+32*2] ; 30 31
mova m2, [r5+32*1] ; 18 19
mova m3, [r5+32*0] ; 28 29
mova m4, [r5-32*1] ; 20 21
mova m5, [r5-32*2] ; 26 27
mova m6, [r5-32*3] ; 22 23
mova m7, [r5-32*4] ; 24 25
call m(inv_txfm_add_dct_dct_8x32_10bpc).transpose
lea dstq, [r4+32]
call .pass2
RET
ALIGN function_align
.pass2:
call m(idct_16x8_internal_8bpc).main
REPX {pmulhrsw x, m11}, m0, m1, m2, m3
call m(idct_16x8_internal_10bpc).write_16x4_start
pmulhrsw m0, m11, m4
pmulhrsw m1, m11, m5
pmulhrsw m2, m11, m6
pmulhrsw m3, m11, m7
jmp m(idct_16x8_internal_10bpc).write_16x4_zero
cglobal inv_txfm_add_identity_identity_32x8_10bpc, 4, 7, 8, dst, stride, c, eob
vpbroadcastd m5, [pw_4096]
vpbroadcastd m7, [pixel_10bpc_max]
pxor m6, m6
mov r6d, eobd
add eobb, 21
cmovc eobd, r6d
lea r6, [strideq*3]
lea r5, [strideq*5]
lea r4, [strideq+r6*2] ; strideq*7
.loop:
mova m0, [cq+32*0]
packssdw m0, [cq+32*1]
mova m1, [cq+32*2]
packssdw m1, [cq+32*3]
REPX {mova [cq+32*x], m6}, 0, 1, 2, 3
add cq, 32*8
mova m2, [cq-32*4]
packssdw m2, [cq-32*3]
mova m3, [cq-32*2]
packssdw m3, [cq-32*1]
REPX {pmulhrsw x, m5}, m0, m1, m2, m3
REPX {mova [cq+32*x], m6}, -4, -3, -2, -1
call m(inv_txfm_add_identity_identity_8x32_10bpc).main
add dstq, 16
sub eobd, 64
jge .loop
RET
%macro IDCT32_PASS2_END 6 ; coefs[1-2], tmp[1-2], offset[1-2]
mova m%4, [%2]
paddsw m%3, m%1, m%4
psubsw m%1, m%4
%if %1 == 0
pxor m6, m6
%endif
pmulhrsw m%3, m15
pmulhrsw m%1, m15
paddw m%3, [dstq+%5]
paddw m%1, [r2+%6]
pmaxsw m%3, m6
pmaxsw m%1, m6
pminsw m%3, m7
pminsw m%1, m7
mova [dstq+%5], m%3
mova [r2+%6], m%1
%endmacro
cglobal inv_txfm_add_dct_dct_16x32_10bpc, 4, 7, 0, dst, stride, c, eob
test eobd, eobd
jz .dconly
PROLOGUE 0, 8, 16, 32*36, dst, stride, c, eob
%undef cmp
vpbroadcastd m11, [pd_2048]
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
vpbroadcastd m14, [pd_2896]
lea r6, [rsp+32*16]
lea r4, [r6+32*8]
lea r5, [r6+32*16]
call .main
sub eobd, 44
jge .eob44
vperm2i128 m2, m0, m3, 0x31 ; 5
vinserti128 m0, xm3, 1 ; 1
vperm2i128 m3, m1, m4, 0x31 ; 7
vinserti128 m1, xm4, 1 ; 3
pxor m4, m4
REPX {mova x, m4}, m5, m6, m7
REPX {mova [r6+32*x], m4}, 0, 1, 2, 3
jmp .fast
.dconly:
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 32
add r6d, 2048
sar r6d, 12
imul r6d, 2896
jmp m(inv_txfm_add_dct_dct_16x4_10bpc).dconly
.eob44:
mova [r4+16*0], xm0
mova [r4+16*1], xm3
mova [r4+16*2], xm1
mova [r4+16*3], xm4
vextracti128 [r4+16*4], m0, 1
vextracti128 [r4+16*5], m3, 1
vextracti128 [r4+16*6], m1, 1
vextracti128 [r4+16*7], m4, 1
call .main
sub eobd, 107
jge .eob151
vperm2i128 m7, m1, m4, 0x31 ; 15
vinserti128 m5, m1, xm4, 1 ; 11
vperm2i128 m6, m0, m3, 0x31 ; 13
vinserti128 m4, m0, xm3, 1 ; 9
mova m0, [r4+32*0]
mova m1, [r4+32*1]
mova m2, [r4+32*2]
mova m3, [r4+32*3]
.fast:
lea r6, [pw_5+128]
call m(inv_txfm_add_dct_dct_16x32_8bpc).main_oddhalf_fast
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14, m15
jmp .idct16
.eob151:
mova [r4-16*8], xm0
mova [r4-16*7], xm3
mova [r4-16*6], xm1
mova [r4-16*5], xm4
vextracti128 [r4-16*4], m0, 1
vextracti128 [r4-16*3], m3, 1
vextracti128 [r4-16*2], m1, 1
vextracti128 [r4-16*1], m4, 1
call .main
sub eobd, 128
jge .eob279
vperm2i128 m10, m0, m3, 0x31 ; 21
vinserti128 m8, m0, xm3, 1 ; 17
vperm2i128 m11, m1, m4, 0x31 ; 23
vinserti128 m9, m1, xm4, 1 ; 19
pxor m12, m12
REPX {mova x, m12}, m13, m14, m15
REPX {mova [r6+32*x], m12}, 0, 1, 2, 3
jmp .full
.eob279:
mova [r5+16*0], xm0
mova [r5+16*1], xm3
mova [r5+16*2], xm1
mova [r5+16*3], xm4
vextracti128 [r5+16*4], m0, 1
vextracti128 [r5+16*5], m3, 1
vextracti128 [r5+16*6], m1, 1
vextracti128 [r5+16*7], m4, 1
call .main
vperm2i128 m14, m0, m3, 0x31 ; 29
vinserti128 m12, m0, xm3, 1 ; 25
vperm2i128 m15, m1, m4, 0x31 ; 31
vinserti128 m13, m1, xm4, 1 ; 27
mova m8, [r5+32*0]
mova m9, [r5+32*1]
mova m10, [r5+32*2]
mova m11, [r5+32*3]
.full:
mova m0, [r4+32*0]
mova m1, [r4+32*1]
mova m2, [r4+32*2]
mova m3, [r4+32*3]
mova m4, [r4-32*4]
mova m5, [r4-32*3]
mova m6, [r4-32*2]
mova m7, [r4-32*1]
lea r6, [pw_5 + 128]
call m(inv_txfm_add_dct_dct_16x32_8bpc).main_oddhalf
lea r3, [rsp+32*8]
mova m8, [r3+32*0]
mova m9, [r3+32*1]
mova m10, [r3+32*2]
mova m11, [r3+32*3]
mova m12, [r3-32*4]
mova m13, [r3-32*3]
mova m14, [r3-32*2]
mova m15, [r3-32*1]
.idct16:
lea r3, [rsp+32*16]
mova m0, [r3+32*0]
mova m1, [r3+32*1]
mova m2, [r3+32*2]
mova m3, [r3+32*3]
mova m4, [r3-32*4]
mova m5, [r3-32*3]
mova m6, [r3-32*2]
mova m7, [r3-32*1]
mova [rsp], m15
call m(idct_16x16_internal_8bpc).main
imul r2, strideq, 19
lea r3, [strideq*3]
add r2, dstq
call .pass2_end
RET
ALIGN function_align
.main:
pmulld m0, m14, [cq+128* 1]
pmulld m1, m14, [cq+128* 3]
pmulld m2, m14, [cq+128* 5]
pmulld m3, m14, [cq+128* 7]
pmulld m4, m14, [cq+128* 9]
pmulld m5, m14, [cq+128*11]
pmulld m6, m14, [cq+128*13]
pmulld m7, m14, [cq+128*15]
call m(idct_8x16_internal_10bpc).main_oddhalf_rect2
pmulld m0, m14, [cq+128* 0]
pmulld m1, m14, [cq+128* 2]
pmulld m2, m14, [cq+128* 4]
pmulld m3, m14, [cq+128* 6]
pmulld m4, m14, [cq+128* 8]
pmulld m5, m14, [cq+128*10]
pmulld m6, m14, [cq+128*12]
pmulld m7, m14, [cq+128*14]
call m(idct_8x8_internal_10bpc).main_rect2
call m(idct_8x16_internal_10bpc).main_evenhalf
psrld m15, m11, 11 ; pd_1
mova m8, [r6-32*4]
mova m9, [r6-32*3]
REPX {paddd x, m15}, m0, m1, m2, m3, m4, m5, m6, m7
psubd m10, m0, m8 ; out15
paddd m0, m8 ; out0
mova m8, [r6-32*2]
paddd m15, m1, m9 ; out1
psubd m1, m9 ; out14
mova m9, [r6-32*1]
REPX {psrad x, 1}, m0, m15, m10, m1
packssdw m0, m15
packssdw m1, m10
psubd m10, m2, m8 ; out13
paddd m2, m8 ; out2
mova m8, [r6+32*0]
paddd m15, m3, m9 ; out3
psubd m3, m9 ; out12
mova m9, [r6+32*1]
REPX {psrad x, 1}, m2, m15, m10, m3
packssdw m2, m15
packssdw m3, m10
psubd m10, m4, m8 ; out11
paddd m4, m8 ; out4
mova m8, [r6+32*2]
paddd m15, m5, m9 ; out5
psubd m5, m9 ; out10
mova m9, [r6+32*3]
REPX {psrad x, 1}, m4, m10, m15, m5
packssdw m4, m15
packssdw m5, m10
psubd m10, m6, m8 ; out9
paddd m6, m8 ; out6
paddd m15, m7, m9 ; out7
psubd m7, m9 ; out8
REPX {psrad x, 1}, m6, m10, m15, m7
packssdw m6, m15
packssdw m7, m10
punpckhwd m8, m0, m2
punpcklwd m0, m2
punpckhwd m2, m3, m1
punpcklwd m3, m1
punpckhwd m1, m4, m6
punpcklwd m4, m6
punpcklwd m6, m7, m5
punpckhwd m7, m5
pxor m5, m5
mov r7d, 128*13
.main_zero_loop:
mova [cq+r7-128*1], m5
mova [cq+r7+128*0], m5
mova [cq+r7+128*1], m5
mova [cq+r7+128*2], m5
sub r7d, 128*4
jg .main_zero_loop
add cq, 32
punpcklwd m5, m3, m2
punpckhwd m3, m2
punpcklwd m2, m4, m1
punpckhwd m4, m1
punpckhwd m1, m0, m8
punpcklwd m0, m8
punpckhwd m8, m6, m7
punpcklwd m6, m7
punpcklqdq m7, m1, m4
punpckhqdq m1, m4
punpckhqdq m4, m8, m3
punpcklqdq m8, m3
punpckhqdq m3, m6, m5
punpcklqdq m6, m5
punpcklqdq m5, m0, m2
punpckhqdq m0, m2
mova [r6+16*0], xm5
mova [r6+16*1], xm6
mova [r6+16*2], xm7
mova [r6+16*3], xm8
vextracti128 [r6+16*4], m5, 1
vextracti128 [r6+16*5], m6, 1
vextracti128 [r6+16*6], m7, 1
vextracti128 [r6+16*7], m8, 1
sub r6, 32*4
ret
ALIGN function_align
.pass2_end:
mova [rsp+gprsize+32*0], m6
mova [rsp+gprsize+32*2], m7
mova [rsp+gprsize+32*3], m15
vpbroadcastd m15, [pw_2048]
vpbroadcastd m7, [pixel_10bpc_max]
IDCT32_PASS2_END 0, r5+32*3, 1, 6, strideq*0, r3*4
IDCT32_PASS2_END 4, r5-32*1, 0, 1, strideq*4, strideq*8
IDCT32_PASS2_END 8, r4+32*3, 0, 4, strideq*8, strideq*4
IDCT32_PASS2_END 12, r4-32*1, 0, 4, r3*4, strideq*0
add dstq, strideq
sub r2, strideq
mova m1, [rsp+gprsize+32*1]
IDCT32_PASS2_END 1, r5+32*2, 0, 4, strideq*0, r3*4
IDCT32_PASS2_END 5, r5-32*2, 0, 4, strideq*4, strideq*8
IDCT32_PASS2_END 9, r4+32*2, 0, 4, strideq*8, strideq*4
IDCT32_PASS2_END 13, r4-32*2, 0, 4, r3*4, strideq*0
add dstq, strideq
sub r2, strideq
mova m1, [rsp+gprsize+32*0]
IDCT32_PASS2_END 2, r5+32*1, 0, 4, strideq*0, r3*4
IDCT32_PASS2_END 1, r5-32*3, 0, 4, strideq*4, strideq*8
IDCT32_PASS2_END 10, r4+32*1, 0, 4, strideq*8, strideq*4
IDCT32_PASS2_END 14, r4-32*3, 0, 4, r3*4, strideq*0
add dstq, strideq
sub r2, strideq
mova m1, [rsp+gprsize+32*2]
mova m2, [rsp+gprsize+32*3]
IDCT32_PASS2_END 3, r5+32*0, 0, 4, strideq*0, r3*4
IDCT32_PASS2_END 1, r5-32*4, 0, 4, strideq*4, strideq*8
IDCT32_PASS2_END 11, r4+32*0, 0, 4, strideq*8, strideq*4
IDCT32_PASS2_END 2, r4-32*4, 0, 4, r3*4, strideq*0
ret
cglobal inv_txfm_add_identity_identity_16x32_10bpc, 4, 7, 12, dst, stride, c, eob
vpbroadcastd m8, [pw_2896x8]
vpbroadcastd m9, [pw_1697x16]
vpbroadcastd m11, [pw_8192]
vpbroadcastd m7, [pixel_10bpc_max]
lea r6, [strideq*5]
pxor m6, m6
paddw m10, m11, m11 ; pw_16384
mov r5, dstq
call .main
sub eobd, 36
jl .ret
add cq, 128*8
lea dstq, [r5+16]
call .main
sub cq, 128*8-32
lea dstq, [r5+strideq*8]
mov r5, dstq
call .main
sub eobd, 107 ; eob < 143
jl .ret
add cq, 128*8
lea dstq, [r5+16]
call .main
sub cq, 128*8-32
lea dstq, [r5+strideq*8]
mov r5, dstq
call .main
sub eobd, 128 ; eob < 271
jl .ret
add cq, 128*8
lea dstq, [r5+16]
call .main
sub cq, 128*8-32
lea dstq, [r5+strideq*8]
mov r5, dstq
call .main
sub eobd, 128 ; eob < 399
jl .ret
add cq, 128*8
lea dstq, [r5+16]
call .main
.ret:
RET
ALIGN function_align
.main:
mova m0, [cq+128*0]
packssdw m0, [cq+128*1]
mova m1, [cq+128*2]
packssdw m1, [cq+128*3]
mova m2, [cq+128*4]
packssdw m2, [cq+128*5]
mova m3, [cq+128*6]
packssdw m3, [cq+128*7]
REPX {pmulhrsw x, m8 }, m0, m1, m2, m3
REPX {IDTX16 x, 4, 9, 10}, 0, 1, 2, 3
REPX {pmulhrsw x, m11}, m0, m1, m2, m3
REPX {mova [cq+128*x], m6}, 0, 1, 2, 3, 4, 5, 6, 7
.main2:
punpckhwd m4, m0, m1
punpcklwd m0, m1
punpckhwd m1, m2, m3
punpcklwd m2, m3
punpckhwd m3, m0, m4
punpcklwd m0, m4
punpcklwd m4, m2, m1
punpckhwd m2, m1
punpckhqdq m1, m0, m4
punpcklqdq m0, m4
call m(iidentity_8x8_internal_10bpc).write_2x8x2
punpcklqdq m0, m3, m2
punpckhqdq m1, m3, m2
jmp m(iidentity_8x8_internal_10bpc).write_2x8x2
cglobal inv_txfm_add_dct_dct_32x16_10bpc, 4, 7, 0, dst, stride, c, eob
test eobd, eobd
jz .dconly
PROLOGUE 0, 8, 16, 32*40, dst, stride, c, eob
%undef cmp
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
lea r6, [rsp+32*4]
call .main
cmp eobd, 36
jge .full
call m(inv_txfm_add_dct_dct_8x32_10bpc).transpose
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14, [rsp]
lea r6, [pw_5+128]
mov r7, dstq
call m(idct_16x16_internal_8bpc).main
call .write_16x16
mova m0, [r5+32*3]
mova m1, [r5+32*2]
mova m2, [r5+32*1]
mova m3, [r5+32*0]
mova m4, [r5-32*1]
mova m5, [r5-32*2]
mova m6, [r5-32*3]
mova m7, [r5-32*4]
call m(inv_txfm_add_dct_dct_8x32_10bpc).transpose
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14, [rsp]
jmp .end
.dconly:
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 16
add r6d, 2048
sar r6d, 12
imul r6d, 2896
add r6d, 6144
sar r6d, 13
jmp m(inv_txfm_add_dct_dct_32x8_10bpc).dconly2
.full:
add cq, 32
mova [r4+32*3], m0
mova [r4+32*2], m1
mova [r4+32*1], m2
mova [r4+32*0], m3
mova [r4-32*1], m4
mova [r4-32*2], m5
mova [r4-32*3], m6
mova [r4-32*4], m7
call .main
sub r4, 32*16 ; topleft 16x8
call .transpose_16x16
lea r6, [pw_5+128]
mov r7, dstq
call m(idct_16x16_internal_8bpc).main
call .write_16x16
mova m0, [r5+32*3]
mova m1, [r5+32*2]
mova m2, [r5+32*1]
mova m3, [r5+32*0]
mova m4, [r5-32*1]
mova m5, [r5-32*2]
mova m6, [r5-32*3]
mova m7, [r5-32*4]
add r4, 32*8 ; bottomleft 16x8
call .transpose_16x16
.end:
lea dstq, [r7+32]
call m(idct_16x16_internal_8bpc).main
call .write_16x16
RET
ALIGN function_align
.transpose_16x16:
punpckhdq m8, m3, m1
punpckldq m3, m1
punpckhdq m1, m0, m2
punpckldq m0, m2
punpckhdq m2, m7, m5
punpckldq m7, m5
punpckhdq m5, m4, m6
punpckldq m4, m6
punpckhqdq m6, m0, m4
punpcklqdq m0, m4
punpckhqdq m4, m1, m5
punpcklqdq m1, m5
punpckhqdq m5, m7, m3
punpcklqdq m7, m3
punpckhqdq m3, m2, m8
punpcklqdq m2, m8
vinserti128 m8, m0, xm7, 1
vperm2i128 m12, m0, m7, 0x31
vinserti128 m9, m6, xm5, 1
vperm2i128 m13, m6, m5, 0x31
vinserti128 m10, m1, xm2, 1
vperm2i128 m14, m1, m2, 0x31
vinserti128 m11, m4, xm3, 1
vperm2i128 m15, m4, m3, 0x31
mova m0, [r4+32*3]
mova m1, [r4+32*2]
mova m2, [r4+32*1]
mova m3, [r4+32*0]
mova m4, [r4-32*1]
mova m5, [r4-32*2]
mova m6, [r4-32*3]
mova m7, [r4-32*4]
mova [rsp+gprsize], m15
jmp m(inv_txfm_add_dct_dct_8x32_10bpc).transpose
ALIGN function_align
.main:
vpbroadcastd m14, [pd_2896]
vpbroadcastd m11, [pd_2048]
pmulld m0, m14, [cq+64* 1]
pmulld m1, m14, [cq+64* 7]
pmulld m2, m14, [cq+64* 9]
pmulld m3, m14, [cq+64*15]
pmulld m4, m14, [cq+64*17]
pmulld m5, m14, [cq+64*23]
pmulld m6, m14, [cq+64*25]
pmulld m7, m14, [cq+64*31]
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_oddhalf_part1_rect2
pmulld m0, m14, [cq+64* 3]
pmulld m1, m14, [cq+64* 5]
pmulld m2, m14, [cq+64*11]
pmulld m3, m14, [cq+64*13]
pmulld m4, m14, [cq+64*19]
pmulld m5, m14, [cq+64*21]
pmulld m6, m14, [cq+64*27]
pmulld m7, m14, [cq+64*29]
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_oddhalf_part2_rect2
pmulld m0, m14, [cq+64* 2]
pmulld m1, m14, [cq+64* 6]
pmulld m2, m14, [cq+64*10]
pmulld m3, m14, [cq+64*14]
pmulld m4, m14, [cq+64*18]
pmulld m5, m14, [cq+64*22]
pmulld m6, m14, [cq+64*26]
pmulld m7, m14, [cq+64*30]
call m(idct_8x16_internal_10bpc).main_oddhalf_rect2
pmulld m0, m14, [cq+64* 0]
pmulld m1, m14, [cq+64* 4]
pmulld m2, m14, [cq+64* 8]
pmulld m3, m14, [cq+64*12]
pmulld m4, m14, [cq+64*16]
pmulld m5, m14, [cq+64*20]
pmulld m6, m14, [cq+64*24]
pmulld m7, m14, [cq+64*28]
call m(idct_8x8_internal_10bpc).main_rect2
call m(idct_8x16_internal_10bpc).main_evenhalf
pxor m8, m8
mov r7d, 64*30
.main_zero_loop:
mova [cq+r7-64*2], m8
mova [cq+r7-64*1], m8
mova [cq+r7+64*0], m8
mova [cq+r7+64*1], m8
sub r7d, 64*4
jg .main_zero_loop
.main_end:
psrld m11, 11 ; pd_1
IDCT32_END 0, 15, 8, 9, 10, 1
IDCT32_END 1, 14, 8, 9, 10, 1
punpckhwd m8, m0, m1 ; 16 17
punpcklwd m0, m1 ; 0 1
punpcklwd m1, m14, m15 ; 14 15
punpckhwd m14, m15 ; 30 31
mova [r5+32*3], m8
mova [r5+32*2], m14
IDCT32_END 2, 15, 8, 9, 10, 1
IDCT32_END 3, 14, 8, 9, 10, 1
punpckhwd m8, m2, m3 ; 18 19
punpcklwd m2, m3 ; 2 3
punpcklwd m3, m14, m15 ; 12 13
punpckhwd m14, m15 ; 28 29
mova [r5+32*1], m8
mova [r5+32*0], m14
IDCT32_END 4, 15, 8, 9, 10, 1
IDCT32_END 5, 14, 8, 9, 10, 1
punpckhwd m8, m4, m5 ; 20 21
punpcklwd m4, m5 ; 4 5
punpcklwd m5, m14, m15 ; 10 11
punpckhwd m14, m15 ; 26 27
mova [r5-32*1], m8
mova [r5-32*2], m14
IDCT32_END 6, 15, 8, 9, 10, 1
IDCT32_END 7, 14, 8, 9, 10, 1
punpckhwd m8, m6, m7 ; 22 23
punpcklwd m6, m7 ; 6 7
punpcklwd m7, m14, m15 ; 8 9
punpckhwd m14, m15 ; 24 25
mova [r5-32*3], m8
mova [r5-32*4], m14
ret
ALIGN function_align
.write_16x16:
mova m1, [rsp+gprsize+32*1]
mova [rsp+gprsize+32*0], m8
mova [rsp+gprsize+32*1], m9
mova [rsp+gprsize+32*2], m12
vpbroadcastd m12, [pw_2048]
vpbroadcastd m9, [pixel_10bpc_max]
lea r3, [strideq*3]
pxor m8, m8
pmulhrsw m0, m12
pmulhrsw m1, m12
pmulhrsw m2, m12
pmulhrsw m3, m12
call m(idct_16x8_internal_10bpc).write_16x4
pmulhrsw m0, m12, m4
pmulhrsw m1, m12, m5
pmulhrsw m2, m12, m6
pmulhrsw m3, m12, m7
call m(idct_16x8_internal_10bpc).write_16x4
pmulhrsw m0, m12, [rsp+gprsize+32*0]
pmulhrsw m1, m12, [rsp+gprsize+32*1]
pmulhrsw m2, m12, m10
pmulhrsw m3, m12, m11
call m(idct_16x8_internal_10bpc).write_16x4
pmulhrsw m0, m12, [rsp+gprsize+32*2]
pmulhrsw m1, m12, m13
pmulhrsw m2, m12, m14
pmulhrsw m3, m12, m15
jmp m(idct_16x8_internal_10bpc).write_16x4
cglobal inv_txfm_add_identity_identity_32x16_10bpc, 4, 7, 11, dst, stride, c, eob
vpbroadcastd m8, [pw_2896x8]
vpbroadcastd m9, [pw_1697x16]
vpbroadcastd m10, [pw_2048]
vpbroadcastd m7, [pixel_10bpc_max]
lea r6, [strideq*5]
pxor m6, m6
mov r5, dstq
call .main
sub eobd, 36
jl .ret
add cq, 32
lea dstq, [dstq+strideq*4]
call .main
add cq, 64*8-32
lea dstq, [r5+16*1]
call .main
sub eobd, 107 ; eob < 143
jl .ret
add cq, 32
lea dstq, [dstq+strideq*4]
call .main
add cq, 64*8-32
lea dstq, [r5+16*2]
call .main
sub eobd, 128 ; eob < 271
jl .ret
add cq, 32
lea dstq, [dstq+strideq*4]
call .main
add cq, 64*8-32
lea dstq, [r5+16*3]
call .main
sub eobd, 128 ; eob < 399
jl .ret
add cq, 32
lea dstq, [dstq+strideq*4]
call .main
.ret:
RET
ALIGN function_align
.main:
mova m0, [cq+64*0]
packssdw m0, [cq+64*1]
mova m1, [cq+64*2]
packssdw m1, [cq+64*3]
mova m2, [cq+64*4]
packssdw m2, [cq+64*5]
mova m3, [cq+64*6]
packssdw m3, [cq+64*7]
REPX {pmulhrsw x, m8 }, m0, m1, m2, m3
REPX {paddsw x, x }, m0, m1, m2, m3
REPX {IDTX16 x, 4, 9 }, 0, 1, 2, 3
REPX {pmulhrsw x, m10}, m0, m1, m2, m3
REPX {mova [cq+64*x], m6}, 0, 1, 2, 3, 4, 5, 6, 7
jmp m(inv_txfm_add_identity_identity_16x32_10bpc).main2
cglobal inv_txfm_add_dct_dct_32x32_10bpc, 4, 7, 0, dst, stride, c, eob
test eobd, eobd
jz .dconly
PROLOGUE 0, 8, 16, 32*83, dst, stride, c, eob
%undef cmp
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
lea r6, [rsp+32*7]
call .main
cmp eobd, 36
jl .fast
call .main
cmp eobd, 136
jl .fast
call .main
cmp eobd, 300
jl .fast
call .main
jmp .pass2
.dconly:
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 32
jmp m(inv_txfm_add_dct_dct_32x8_10bpc).dconly
.fast:
lea r4, [rsp+32*71]
pxor m0, m0
.fast_loop:
REPX {mova [r6+32*x], m0}, -4, -3, -2, -1, 0, 1, 2, 3
add r6, 32*8
cmp r6, r4
jl .fast_loop
.pass2:
lea r3, [rsp+32*3]
mov r4, r6
lea r5, [r6+32*8]
lea r6, [pw_5+128]
call .pass2_oddhalf
call .pass2_evenhalf
imul r2, strideq, 19
lea r3, [strideq*3]
add r2, dstq
call m(inv_txfm_add_dct_dct_16x32_10bpc).pass2_end
sub dstq, r3
lea r2, [r2+r3+32]
add dstq, 32
lea r3, [rsp+32*11]
call .pass2_oddhalf
call .pass2_evenhalf
lea r3, [strideq*3]
call m(inv_txfm_add_dct_dct_16x32_10bpc).pass2_end
RET
ALIGN function_align
.main:
mova m0, [cq+128* 1]
mova m1, [cq+128* 7]
mova m2, [cq+128* 9]
mova m3, [cq+128*15]
mova m4, [cq+128*17]
mova m5, [cq+128*23]
mova m6, [cq+128*25]
mova m7, [cq+128*31]
vpbroadcastd m11, [pd_2048]
vpbroadcastd m14, [pd_2896]
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_oddhalf_part1
mova m0, [cq+128* 3]
mova m1, [cq+128* 5]
mova m2, [cq+128*11]
mova m3, [cq+128*13]
mova m4, [cq+128*19]
mova m5, [cq+128*21]
mova m6, [cq+128*27]
mova m7, [cq+128*29]
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_oddhalf_part2
mova m0, [cq+128* 2]
mova m1, [cq+128* 6]
mova m2, [cq+128*10]
mova m3, [cq+128*14]
mova m4, [cq+128*18]
mova m5, [cq+128*22]
mova m6, [cq+128*26]
mova m7, [cq+128*30]
call m(idct_8x16_internal_10bpc).main_oddhalf
mova m0, [cq+128* 0]
mova m1, [cq+128* 4]
mova m2, [cq+128* 8]
mova m3, [cq+128*12]
mova m4, [cq+128*16]
mova m5, [cq+128*20]
mova m6, [cq+128*24]
mova m7, [cq+128*28]
call m(idct_8x8_internal_10bpc).main
call m(idct_8x16_internal_10bpc).main_evenhalf
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_end
pxor m15, m15
mov r7d, 128*29
.main_zero_loop:
mova [cq+r7-128*1], m15
mova [cq+r7+128*0], m15
mova [cq+r7+128*1], m15
mova [cq+r7+128*2], m15
sub r7d, 128*4
jg .main_zero_loop
add cq, 32
mova [r4-32*4], m0
mova [r4-32*3], m1
mova [r4-32*2], m2
mova [r4-32*1], m3
mova [r4+32*0], m4
mova [r4+32*1], m5
mova [r4+32*2], m6
mova [r4+32*3], m7
mova m0, [r5+32*3]
mova m1, [r5+32*2]
mova m2, [r5+32*1]
mova m3, [r5+32*0]
mova m4, [r5-32*1]
mova m5, [r5-32*2]
mova m6, [r5-32*3]
mova m7, [r5-32*4]
call m(inv_txfm_add_dct_dct_8x32_10bpc).transpose
mova [r5-32*4], m0
mova [r5-32*3], m1
mova [r5-32*2], m2
mova [r5-32*1], m3
mova [r5+32*0], m4
mova [r5+32*1], m5
mova [r5+32*2], m6
mova [r5+32*3], m7
ret
ALIGN function_align
.pass2_oddhalf:
mova m0, [r3+32* 1] ; 1
mova m1, [r3+32* 3] ; 3
mova m2, [r3+32* 5] ; 5
mova m3, [r3+32* 7] ; 7
mova m4, [r3+32*17] ; 9
mova m5, [r3+32*19] ; 11
mova m6, [r3+32*21] ; 13
mova m7, [r3+32*23] ; 15
mova m8, [r3+32*33] ; 17
mova m9, [r3+32*35] ; 19
mova m10, [r3+32*37] ; 21
mova m11, [r3+32*39] ; 23
mova m12, [r3+32*49] ; 25
mova m13, [r3+32*51] ; 27
mova m14, [r3+32*53] ; 29
mova m15, [r3+32*55] ; 31
jmp m(inv_txfm_add_dct_dct_16x32_8bpc).main_oddhalf
ALIGN function_align
.pass2_evenhalf:
mova m0, [r3+32* 0] ; 0
mova m1, [r3+32* 2] ; 2
mova m2, [r3+32* 4] ; 4
mova m3, [r3+32* 6] ; 6
mova m4, [r3+32*16] ; 8
mova m5, [r3+32*18] ; 10
mova m6, [r3+32*20] ; 12
mova m7, [r3+32*22] ; 14
mova m8, [r3+32*32] ; 16
mova m9, [r3+32*34] ; 18
mova m10, [r3+32*36] ; 20
mova m11, [r3+32*38] ; 22
mova m12, [r3+32*48] ; 24
mova m13, [r3+32*50] ; 26
mova m14, [r3+32*52] ; 28
mova m15, [r3+32*54] ; 30
mova [rsp+gprsize], m15
jmp m(idct_16x16_internal_8bpc).main
cglobal inv_txfm_add_identity_identity_32x32_10bpc, 4, 8, 8, dst, stride, c, eob
%undef cmp
vpbroadcastd m5, [pw_8192]
vpbroadcastd m7, [pixel_10bpc_max]
pxor m6, m6
lea r6, [strideq*3]
lea r5, [strideq*5]
lea r4, [strideq+r6*2] ; strideq*7
call .main ; 0
cmp eobd, 36
jl .ret
add cq, 128*8 ; 0 1
mov r7, dstq ; 1
add dstq, 16
call .main
call .main2
cmp eobd, 136
jl .ret
add cq, 128*16-32 ; 0 1 2
lea dstq, [r7+16*2] ; 1 2
call .main ; 2
call .main2
call .main2
cmp eobd, 300
jl .ret
add cq, 128*24-64 ; 0 1 2 3
add r7, 16*3 ; 1 2 3
mov dstq, r7 ; 2 3
call .main ; 3
call .main2
call .main2
call .main2
cmp eobd, 535
jl .ret
add cq, 128*24-64 ; 0 1 2 3
lea dstq, [r7+strideq*8] ; 1 2 3 4
mov r7, dstq ; 2 3 4
call .main ; 3 4
call .main2
call .main2
cmp eobd, 755
jl .ret
add cq, 128*16-32 ; 0 1 2 3
lea dstq, [r7+strideq*8] ; 1 2 3 4
call .main ; 2 3 4 5
call .main2 ; 3 4 5
cmp eobd, 911
jl .ret
add cq, 128*8 ; 0 1 2 3
add dstq, 16 ; 1 2 3 4
call .main ; 2 3 4 5
.ret: ; 3 4 5 6
RET
ALIGN function_align
.main2:
sub cq, 128*8-32
lea dstq, [dstq+strideq*8-16]
.main:
mova m0, [cq+128*0]
packssdw m0, [cq+128*1]
mova m1, [cq+128*2]
packssdw m1, [cq+128*3]
mova m2, [cq+128*4]
packssdw m2, [cq+128*5]
mova m3, [cq+128*6]
packssdw m3, [cq+128*7]
REPX {pmulhrsw x, m5}, m0, m1, m2, m3
jmp m(inv_txfm_add_identity_identity_8x32_10bpc).main_zero
%macro IDCT64_PART2_END 6-10 ; out, src[1-2], tmp[1-3], (offset[1-4])
%if %1 & 1
mova m%5, [r5-32*(51-%1)] ; idct16 out 0+n
mova m%4, [r4-32*(14+%1)] ; idct32 out31-n
%else
mova m%5, [r4-32*(45-%1)]
mova m%4, [r5-32*(20+%1)]
%endif
paddsw m%6, m%5, m%4 ; idct32 out 0+n
psubsw m%5, m%4 ; idct32 out31-n
paddsw m%4, m%5, m%3 ; out31-n
psubsw m%5, m%3 ; out32+n
paddsw m%3, m%6, m%2 ; out 0+n
psubsw m%6, m%2 ; out63-n
REPX {pmulhrsw x, m14}, m%5, m%6, m%4, m%3
%if %1 & 1
%define %%d0 r2
%define %%d1 dstq
%else
%define %%d0 dstq
%define %%d1 r2
%endif
paddw m%3, [%%d0+%7 ]
paddw m%4, [%%d1+%8 ]
paddw m%5, [%%d0+%9 ]
paddw m%6, [%%d1+%10]
pxor m%2, m%2
REPX {pmaxsw x, m%2}, m%3, m%4, m%5, m%6
vpbroadcastd m%2, [pixel_10bpc_max]
REPX {pminsw x, m%2}, m%3, m%4, m%5, m%6
mova [%%d0+%7 ], m%3
mova [%%d1+%8 ], m%4
mova [%%d0+%9 ], m%5
mova [%%d1+%10], m%6
%endmacro
cglobal inv_txfm_add_dct_dct_16x64_10bpc, 4, 7, 0, dst, stride, c, eob
test eobd, eobd
jz .dconly
PROLOGUE 0, 10, 16, 32*98, dst, stride, c, eob
%undef cmp
vpbroadcastd m11, [pd_2048]
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
vpbroadcastd m14, [pd_2896]
lea r6, [rsp+32*6]
call .main
sub eobd, 44
jl .fast
call .main
sub eobd, 107
jl .fast
call .main
sub eobd, 128
jl .fast
call .main
jmp .pass2
.dconly:
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 64
add r6d, 10240
sar r6d, 14
jmp m(inv_txfm_add_dct_dct_16x4_10bpc).dconly2
.fast:
lea r4, [rsp+32*38]
pxor m0, m0
.fast_loop:
REPX {mova [r6+32*x], m0}, -4, -3, -2, -1, 0, 1, 2, 3
add r6, 32*8
cmp r6, r4
jl .fast_loop
.pass2:
lea r6, [pw_5+128]
mova m0, [rsp+32* 2] ; in0
mova m1, [rsp+32* 6] ; in4
mova m2, [rsp+32*10] ; in8
mova m3, [rsp+32*14] ; in12
mova m4, [rsp+32*18] ; in16
mova m5, [rsp+32*22] ; in20
mova m6, [rsp+32*26] ; in24
mova m7, [rsp+32*30] ; in28
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14
mova [rsp], m8
call m(idct_16x16_internal_8bpc).main
mova m1, [rsp+32*1]
lea r4, [rsp+32*38]
mova [r4-32*4], m0
mova [r4-32*3], m1
mova [r4-32*2], m2
mova [r4-32*1], m3
mova [r4+32*0], m4
mova [r4+32*1], m5
mova [r4+32*2], m6
mova [r4+32*3], m7
add r4, 32*8
mova [r4-32*4], m8
mova [r4-32*3], m9
mova [r4-32*2], m10
mova [r4-32*1], m11
mova [r4+32*0], m12
mova [r4+32*1], m13
mova [r4+32*2], m14
mova [r4+32*3], m15
mova m0, [rsp+32* 4] ; in2
mova m1, [rsp+32* 8] ; in6
mova m2, [rsp+32*12] ; in10
mova m3, [rsp+32*16] ; in14
mova m4, [rsp+32*20] ; in18
mova m5, [rsp+32*24] ; in22
mova m6, [rsp+32*28] ; in26
mova m7, [rsp+32*32] ; in30
lea r5, [r4+32*16]
add r4, 32*8
call m(inv_txfm_add_dct_dct_16x32_8bpc).main_oddhalf_fast
mova m0, [rsp+32* 3] ; in1
mova m1, [rsp+32*33] ; in31
mova m2, [rsp+32*19] ; in17
mova m3, [rsp+32*17] ; in15
mova m4, [rsp+32*11] ; in9
mova m5, [rsp+32*25] ; in23
mova m6, [rsp+32*27] ; in25
mova m7, [rsp+32* 9] ; in7
lea r6, [idct64_mul - 8]
add r4, 32*16
add r5, 32*32
call m(inv_txfm_add_dct_dct_16x64_8bpc).main_part1
mova m0, [rsp+32* 7] ; in5
mova m1, [rsp+32*29] ; in27
mova m2, [rsp+32*23] ; in21
mova m3, [rsp+32*13] ; in11
mova m4, [rsp+32*15] ; in13
mova m5, [rsp+32*21] ; in19
mova m6, [rsp+32*31] ; in29
mova m7, [rsp+32* 5] ; in3
add r6, 8
add r4, 32*8
sub r5, 32*8
call m(inv_txfm_add_dct_dct_16x64_8bpc).main_part1
lea r8, [strideq*4]
lea r9, [strideq*5]
lea r3, [r9+strideq*1] ; stride*6
lea r7, [r9+strideq*2] ; stride*7
call .main_part2_pass2
RET
ALIGN function_align
.main:
mova m0, [cq+128* 1]
mova m1, [cq+128* 3]
mova m2, [cq+128* 5]
mova m3, [cq+128* 7]
mova m4, [cq+128* 9]
mova m5, [cq+128*11]
mova m6, [cq+128*13]
mova m7, [cq+128*15]
call m(idct_8x16_internal_10bpc).main_oddhalf
mova m0, [cq+128* 0]
mova m1, [cq+128* 2]
mova m2, [cq+128* 4]
mova m3, [cq+128* 6]
mova m4, [cq+128* 8]
mova m5, [cq+128*10]
mova m6, [cq+128*12]
mova m7, [cq+128*14]
call m(idct_8x8_internal_10bpc).main
call m(idct_8x16_internal_10bpc).main_evenhalf
pxor m15, m15
mov r7d, 128*13
.main_zero_loop:
mova [cq+r7-128*1], m15
mova [cq+r7+128*0], m15
mova [cq+r7+128*1], m15
mova [cq+r7+128*2], m15
sub r7d, 128*4
jg .main_zero_loop
add cq, 32
psrld m15, m11, 10 ; pd_2
mova m8, [r6-32*4]
mova m9, [r6+32*3]
REPX {paddd x, m15}, m0, m1, m2, m3, m4, m5, m6, m7
psubd m10, m0, m8 ; out15
paddd m0, m8 ; out0
mova m8, [r6-32*3]
psubd m15, m7, m9 ; out8
paddd m7, m9 ; out7
mova m9, [r6+32*2]
REPX {psrad x, 2}, m0, m15, m10, m7
packssdw m0, m15
packssdw m7, m10
psubd m10, m1, m8 ; out14
paddd m1, m8 ; out1
mova m8, [r6-32*2]
psubd m15, m6, m9 ; out9
paddd m6, m9 ; out6
mova m9, [r6+32*1]
REPX {psrad x, 2}, m1, m15, m10, m6
packssdw m1, m15
packssdw m6, m10
psubd m10, m2, m8 ; out13
paddd m2, m8 ; out2
mova m8, [r6-32*1]
psubd m15, m5, m9 ; out10
paddd m5, m9 ; out5
mova m9, [r6+32*0]
REPX {psrad x, 2}, m2, m15, m10, m5
packssdw m2, m15
packssdw m5, m10
psubd m10, m3, m8 ; out12
paddd m3, m8 ; out3
psubd m15, m4, m9 ; out11
paddd m4, m9 ; out4
REPX {psrad x, 2}, m3, m15, m10, m4
packssdw m3, m15
packssdw m4, m10
call m(idct_16x8_internal_10bpc).transpose3
mova [r6-32*4], m0
mova [r6-32*3], m1
mova [r6-32*2], m2
mova [r6-32*1], m3
mova [r6+32*0], m4
mova [r6+32*1], m5
mova [r6+32*2], m6
mova [r6+32*3], m7
add r6, 32*8
ret
.main_part2_pass2:
vpbroadcastd m11, [pw_1567_3784]
vpbroadcastd m12, [pw_m3784_1567]
vpbroadcastd m13, [pw_2896_2896]
lea r6, [pw_5+128]
lea r2, [dstq+r7]
.main_part2_pass2_loop:
vpbroadcastd m14, [pw_m2896_2896]
call m(inv_txfm_add_dct_dct_16x64_8bpc).main_part2_internal
vpbroadcastd m14, [pw_2048]
IDCT64_PART2_END 0, 7, 0, 6, 9, 10, strideq*0, r3*4, r8*8, r7*8
IDCT64_PART2_END 7, 8, 5, 0, 6, 7, strideq*0, r3*4, r8*8, r7*8
IDCT64_PART2_END 8, 2, 1, 0, 6, 7, strideq*8, r8*4, r9*8, r3*8
IDCT64_PART2_END 15, 3, 4, 0, 6, 7, strideq*8, r8*4, r9*8, r3*8
add dstq, strideq
sub r2, strideq
cmp r4, r5
jne .main_part2_pass2_loop
ret
ALIGN function_align
.main_part1_rect2:
REPX {paddd x, m11}, m0, m1, m2, m3
REPX {psrad x, 12 }, m0, m1, m2, m3
.main_part1: ; idct64 steps 1-5
; in1/31/17/15 -> t32a/33/34a/35/60/61a/62/63a
; in7/25/23/ 9 -> t56a/57/58a/59/36/37a/38/39a
; in5/27/21/11 -> t40a/41/42a/43/52/53a/54/55a
; in3/29/19/13 -> t48a/49/50a/51/44/45a/46/47a
vpbroadcastd m7, [r5+4*0]
vpbroadcastd m8, [r5+4*1]
vpbroadcastd m6, [r5+4*2]
vpbroadcastd m9, [r5+4*3]
vpbroadcastd m5, [r5+4*4]
vpbroadcastd m10, [r5+4*5]
vpbroadcastd m4, [r5+4*6]
vpbroadcastd m15, [r5+4*7]
pmulld m7, m0 ; t63a
pmulld m0, m8 ; t32a
pmulld m6, m1 ; t62a
pmulld m1, m9 ; t33a
pmulld m5, m2 ; t61a
pmulld m2, m10 ; t34a
pmulld m4, m3 ; t60a
pmulld m3, m15 ; t35a
vpbroadcastd m10, [r5+4*8]
vpbroadcastd m15, [r5+4*9]
REPX {paddd x, m11}, m7, m0, m6, m1, m5, m2, m4, m3
REPX {psrad x, 12 }, m0, m1, m7, m6, m2, m3, m5, m4
psubd m8, m0, m1 ; t33
paddd m0, m1 ; t32
psubd m1, m7, m6 ; t62
paddd m7, m6 ; t63
psubd m6, m3, m2 ; t34
paddd m3, m2 ; t35
psubd m2, m4, m5 ; t61
paddd m4, m5 ; t60
REPX {pmaxsd x, m12}, m8, m1, m6, m2
REPX {pminsd x, m13}, m8, m1, m6, m2
ITX_MULSUB_2D 1, 8, 5, 9, _, 11, 10, 15 ; t33a, t62a
ITX_MULSUB_2D 2, 6, 5, 9, _, 11, 10, 15, 4 ; t61a, t34a
REPX {pmaxsd x, m12}, m0, m3, m7, m4
REPX {pminsd x, m13}, m0, m3, m7, m4
vpbroadcastd m10, [r5+4*10]
vpbroadcastd m15, [r5+4*11]
psubd m5, m0, m3 ; t35a
paddd m0, m3 ; t32a
psubd m3, m7, m4 ; t60a
paddd m7, m4 ; t63a
psubd m4, m1, m6 ; t34
paddd m1, m6 ; t33
psubd m6, m8, m2 ; t61
paddd m8, m2 ; t62
REPX {pmaxsd x, m12}, m5, m3, m4, m6
REPX {pminsd x, m13}, m5, m3, m4, m6
ITX_MULSUB_2D 3, 5, 2, 9, _, 11, 10, 15 ; t35, t60
ITX_MULSUB_2D 6, 4, 2, 9, _, 11, 10, 15 ; t34a, t61a
REPX {pmaxsd x, m12}, m0, m7, m1, m8
REPX {pminsd x, m13}, m0, m7, m1, m8
add r5, 4*12
mova [r6-32*4], m0
mova [r6+32*3], m7
mova [r6-32*3], m1
mova [r6+32*2], m8
mova [r6-32*2], m6
mova [r6+32*1], m4
mova [r6-32*1], m3
mova [r6+32*0], m5
add r6, 32*8
ret
.main_part2: ; idct64 steps 6-9
lea r5, [r6+32*3]
sub r6, 32*4
vpbroadcastd m10, [pd_1567]
vpbroadcastd m15, [pd_3784]
.main_part2_loop:
mova m0, [r6-32*32] ; t32a
mova m1, [r5-32*24] ; t39a
mova m2, [r5-32*32] ; t63a
mova m3, [r6-32*24] ; t56a
mova m4, [r6-32*16] ; t40a
mova m5, [r5-32* 8] ; t47a
mova m6, [r5-32*16] ; t55a
mova m7, [r6-32* 8] ; t48a
psubd m8, m0, m1 ; t39
paddd m0, m1 ; t32
psubd m1, m2, m3 ; t56
paddd m2, m3 ; t63
psubd m3, m5, m4 ; t40
paddd m5, m4 ; t47
psubd m4, m7, m6 ; t55
paddd m7, m6 ; t48
REPX {pmaxsd x, m12}, m8, m1, m3, m4
REPX {pminsd x, m13}, m8, m1, m3, m4
ITX_MULSUB_2D 1, 8, 6, 9, _, 11, 10, 15 ; t39a, t56a
ITX_MULSUB_2D 4, 3, 6, 9, _, 11, 10, 15, 4 ; t55a, t40a
REPX {pmaxsd x, m12}, m0, m2, m5, m7
REPX {pminsd x, m13}, m0, m5, m2, m7
psubd m6, m2, m7 ; t48a
paddd m2, m7 ; t63a
psubd m7, m0, m5 ; t47a
paddd m0, m5 ; t32a
psubd m5, m8, m4 ; t55
paddd m8, m4 ; t56
psubd m4, m1, m3 ; t40
paddd m1, m3 ; t39
REPX {pmaxsd x, m12}, m6, m7, m5, m4
REPX {pminsd x, m13}, m6, m7, m5, m4
REPX {pmulld x, m14}, m6, m7, m5, m4
REPX {pmaxsd x, m12}, m2, m0, m8, m1
REPX {pminsd x, m13}, m2, m0, m8, m1
paddd m6, m11
paddd m5, m11
psubd m3, m6, m7 ; t47
paddd m6, m7 ; t48
psubd m7, m5, m4 ; t40a
paddd m5, m4 ; t55a
REPX {psrad x, 12}, m3, m6, m7, m5
mova [r5-32* 8], m2
mova [r6-32*32], m0
mova [r6-32* 8], m8
mova [r5-32*32], m1
mova [r5-32*24], m3
mova [r6-32*16], m6
mova [r6-32*24], m7
mova [r5-32*16], m5
add r6, 32
sub r5, 32
cmp r6, r5
jl .main_part2_loop
ret
cglobal inv_txfm_add_dct_dct_32x64_10bpc, 4, 7, 0, dst, stride, c, eob
test eobd, eobd
jz .dconly
PROLOGUE 0, 11, 16, 32*134, dst, stride, c, eob
%undef cmp
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
lea r6, [rsp+32*6]
call .main
cmp eobd, 36
jl .fast
call .main
cmp eobd, 136
jl .fast
call .main
cmp eobd, 300
jl .fast
call .main
jmp .pass2
.dconly:
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 64
add r6d, 2048
sar r6d, 12
imul r6d, 2896
add r6d, 6144
sar r6d, 13
jmp m(inv_txfm_add_dct_dct_32x8_10bpc).dconly2
.fast:
lea r4, [rsp+32*70]
pxor m0, m0
.fast_loop:
REPX {mova [r6+32*x], m0}, -4, -3, -2, -1, 0, 1, 2, 3
add r6, 32*8
cmp r6, r4
jl .fast_loop
.pass2:
lea r6, [pw_5 + 128]
mov r10, rsp
lea r8, [strideq*4]
lea r9, [strideq*5]
lea r3, [r9+strideq*1] ; stride*6
lea r7, [r9+strideq*2] ; stride*7
.pass2_loop:
mova m0, [r10+32* 2] ; in0
mova m1, [r10+32* 6] ; in4
mova m2, [r10+32*18] ; in8
mova m3, [r10+32*22] ; in12
mova m4, [r10+32*34] ; in16
mova m5, [r10+32*38] ; in20
mova m6, [r10+32*50] ; in24
mova m7, [r10+32*54] ; in28
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14
mova [rsp], m8
call m(idct_16x16_internal_8bpc).main
mova m1, [rsp+32*1]
lea r4, [rsp+32*70]
mova [r4-32*4], m0
mova [r4-32*3], m1
mova [r4-32*2], m2
mova [r4-32*1], m3
mova [r4+32*0], m4
mova [r4+32*1], m5
mova [r4+32*2], m6
mova [r4+32*3], m7
add r4, 32*8
mova [r4-32*4], m8
mova [r4-32*3], m9
mova [r4-32*2], m10
mova [r4-32*1], m11
mova [r4+32*0], m12
mova [r4+32*1], m13
mova [r4+32*2], m14
mova [r4+32*3], m15
mova m0, [r10+32* 4] ; in2
mova m1, [r10+32* 8] ; in6
mova m2, [r10+32*20] ; in10
mova m3, [r10+32*24] ; in14
mova m4, [r10+32*36] ; in18
mova m5, [r10+32*40] ; in22
mova m6, [r10+32*52] ; in26
mova m7, [r10+32*56] ; in30
lea r5, [r4+32*16]
add r4, 32*8
call m(inv_txfm_add_dct_dct_16x32_8bpc).main_oddhalf_fast
mova m0, [r10+32* 3] ; in1
mova m1, [r10+32*57] ; in31
mova m2, [r10+32*35] ; in17
mova m3, [r10+32*25] ; in15
mova m4, [r10+32*19] ; in9
mova m5, [r10+32*41] ; in23
mova m6, [r10+32*51] ; in25
mova m7, [r10+32* 9] ; in7
lea r6, [idct64_mul - 8]
add r4, 32*16
add r5, 32*32
call m(inv_txfm_add_dct_dct_16x64_8bpc).main_part1
mova m0, [r10+32* 7] ; in5
mova m1, [r10+32*53] ; in27
mova m2, [r10+32*39] ; in21
mova m3, [r10+32*21] ; in11
mova m4, [r10+32*23] ; in13
mova m5, [r10+32*37] ; in19
mova m6, [r10+32*55] ; in29
mova m7, [r10+32* 5] ; in3
add r6, 8
add r4, 32*8
sub r5, 32*8
call m(inv_txfm_add_dct_dct_16x64_8bpc).main_part1
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part2_pass2
add r10, 32*8
sub r4, 32*98 ; rsp+32*16
sub dstq, r8
add dstq, 32
cmp r10, r4
jl .pass2_loop
RET
ALIGN function_align
.main:
vpbroadcastd m14, [pd_2896]
vpbroadcastd m11, [pd_2048]
pmulld m0, m14, [cq+128* 1]
pmulld m1, m14, [cq+128* 7]
pmulld m2, m14, [cq+128* 9]
pmulld m3, m14, [cq+128*15]
pmulld m4, m14, [cq+128*17]
pmulld m5, m14, [cq+128*23]
pmulld m6, m14, [cq+128*25]
pmulld m7, m14, [cq+128*31]
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_oddhalf_part1_rect2
pmulld m0, m14, [cq+128* 3]
pmulld m1, m14, [cq+128* 5]
pmulld m2, m14, [cq+128*11]
pmulld m3, m14, [cq+128*13]
pmulld m4, m14, [cq+128*19]
pmulld m5, m14, [cq+128*21]
pmulld m6, m14, [cq+128*27]
pmulld m7, m14, [cq+128*29]
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_oddhalf_part2_rect2
pmulld m0, m14, [cq+128* 2]
pmulld m1, m14, [cq+128* 6]
pmulld m2, m14, [cq+128*10]
pmulld m3, m14, [cq+128*14]
pmulld m4, m14, [cq+128*18]
pmulld m5, m14, [cq+128*22]
pmulld m6, m14, [cq+128*26]
pmulld m7, m14, [cq+128*30]
call m(idct_8x16_internal_10bpc).main_oddhalf_rect2
pmulld m0, m14, [cq+128* 0]
pmulld m1, m14, [cq+128* 4]
pmulld m2, m14, [cq+128* 8]
pmulld m3, m14, [cq+128*12]
pmulld m4, m14, [cq+128*16]
pmulld m5, m14, [cq+128*20]
pmulld m6, m14, [cq+128*24]
pmulld m7, m14, [cq+128*28]
pxor m15, m15
mov r7d, 128*29
.main_zero_loop:
mova [cq+r7-128*1], m15
mova [cq+r7+128*0], m15
mova [cq+r7+128*1], m15
mova [cq+r7+128*2], m15
sub r7d, 128*4
jg .main_zero_loop
add cq, 32
call m(idct_8x8_internal_10bpc).main_rect2
call m(idct_8x16_internal_10bpc).main_evenhalf
call m(inv_txfm_add_dct_dct_32x16_10bpc).main_end
call m(inv_txfm_add_dct_dct_8x32_10bpc).transpose
mova [r4-32*4], m0
mova [r4-32*3], m1
mova [r4-32*2], m2
mova [r4-32*1], m3
mova [r4+32*0], m4
mova [r4+32*1], m5
mova [r4+32*2], m6
mova [r4+32*3], m7
mova m0, [r5+32*3]
mova m1, [r5+32*2]
mova m2, [r5+32*1]
mova m3, [r5+32*0]
mova m4, [r5-32*1]
mova m5, [r5-32*2]
mova m6, [r5-32*3]
mova m7, [r5-32*4]
call m(inv_txfm_add_dct_dct_8x32_10bpc).transpose
mova [r5-32*4], m0
mova [r5-32*3], m1
mova [r5-32*2], m2
mova [r5-32*1], m3
mova [r5+32*0], m4
mova [r5+32*1], m5
mova [r5+32*2], m6
mova [r5+32*3], m7
ret
cglobal inv_txfm_add_dct_dct_64x16_10bpc, 4, 7, 0, dst, stride, c, eob
test eobd, eobd
jnz .normal
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 16
.dconly:
add r6d, 10240
sar r6d, 14
.dconly2:
imul r6d, 2896
add r6d, 34816
sar r6d, 16
movd xm0, r6d
%if WIN64
movaps [rsp+8], xmm6
%endif
vpbroadcastw m0, xm0
vpbroadcastd m6, [pixel_10bpc_max]
pxor m5, m5
.dconly_loop:
paddw m1, m0, [dstq+32*0]
paddw m2, m0, [dstq+32*1]
paddw m3, m0, [dstq+32*2]
paddw m4, m0, [dstq+32*3]
REPX {pmaxsw x, m5}, m1, m2, m3, m4
REPX {pminsw x, m6}, m1, m2, m3, m4
mova [dstq+32*0], m1
mova [dstq+32*1], m2
mova [dstq+32*2], m3
mova [dstq+32*3], m4
add dstq, strideq
dec r3d
jg .dconly_loop
%if WIN64
movaps xmm6, [rsp+8]
%endif
RET
.normal:
PROLOGUE 0, 8, 16, 32*96, dst, stride, c, eob
%undef cmp
vpbroadcastd m11, [pd_2048]
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
vpbroadcastd m14, [pd_2896]
lea r6, [rsp+32*4]
call .main
call .shift_transpose
cmp eobd, 36
jl .fast
call .main
call .shift_transpose
jmp .pass2
.fast:
pxor m0, m0
mov r3d, 4
.fast_loop:
REPX {mova [r6+32*x], m0}, -4, -3, -2, -1, 0, 1, 2, 3
add r6, 32*8
dec r3d
jg .fast_loop
.pass2:
lea r7, [r6-32*64]
lea r4, [r6-32*32]
lea r6, [pw_5+128]
mov r5, dstq
.pass2_loop:
mova m0, [r7-32*4]
mova m1, [r7-32*3]
mova m2, [r7-32*2]
mova m3, [r7-32*1]
mova m4, [r7+32*0]
mova m5, [r7+32*1]
mova m6, [r7+32*2]
mova m7, [r7+32*3]
add r7, 32*32
mova m8, [r7-32*4]
mova m9, [r7-32*3]
mova m10, [r7-32*2]
mova m11, [r7-32*1]
mova m12, [r7+32*0]
mova m13, [r7+32*1]
mova m14, [r7+32*2]
mova m15, [r7+32*3]
sub r7, 32*24
mova [rsp], m15
call m(idct_16x16_internal_8bpc).main
mova m1, [rsp+32*1]
call m(inv_txfm_add_dct_dct_32x16_10bpc).write_16x16
add r5, 32
mov dstq, r5
cmp r7, r4
jl .pass2_loop
RET
ALIGN function_align
.main:
lea r5, [idct64_mul_16bpc]
mova m0, [cq+64* 1]
mova m1, [cq+64*31]
mova m2, [cq+64*17]
mova m3, [cq+64*15]
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part1
mova m0, [cq+64* 7]
mova m1, [cq+64*25]
mova m2, [cq+64*23]
mova m3, [cq+64* 9]
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part1
mova m0, [cq+64* 5]
mova m1, [cq+64*27]
mova m2, [cq+64*21]
mova m3, [cq+64*11]
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part1
mova m0, [cq+64* 3]
mova m1, [cq+64*29]
mova m2, [cq+64*19]
mova m3, [cq+64*13]
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part1
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part2
mova m0, [cq+64* 2]
mova m1, [cq+64*14]
mova m2, [cq+64*18]
mova m3, [cq+64*30]
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_oddhalf_part1_fast
mova m0, [cq+64* 6]
mova m1, [cq+64*10]
mova m2, [cq+64*22]
mova m3, [cq+64*26]
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_oddhalf_part2_fast
mova m0, [cq+64* 4]
mova m1, [cq+64*12]
mova m2, [cq+64*20]
mova m3, [cq+64*28]
call m(idct_8x16_internal_10bpc).main_oddhalf_fast
mova m0, [cq+64* 0]
mova m1, [cq+64* 8]
mova m2, [cq+64*16]
mova m3, [cq+64*24]
pxor m15, m15
mov r7d, 64*30
.main_zero_loop:
mova [cq+r7-64*2], m15
mova [cq+r7-64*1], m15
mova [cq+r7+64*0], m15
mova [cq+r7+64*1], m15
sub r7d, 64*4
jg .main_zero_loop
.main_end:
psrld m15, m11, 10 ; pd_2
.main_end2:
add cq, 32
pxor m4, m4
REPX {mova x, m4}, m5, m6, m7
call m(idct_8x8_internal_10bpc).main
add r6, 32*8
call m(idct_8x16_internal_10bpc).main_evenhalf
mova [r6+32*2], m1
mova [r6+32*1], m2
mova [r6+32*0], m3
mova [r6-32*1], m4
mova [r6-32*2], m5
mova [r6-32*3], m6
mova [r6-32*4], m7
jmp .main_end_loop_start
.main_end_loop:
mova m0, [r6+32* 3] ; idct8 0 + n
.main_end_loop_start:
mova m1, [r5+32* 4] ; idct16 15 - n
mova m2, [r5-32*12] ; idct32 16 + n
mova m3, [r6-32*13] ; idct32 31 - n
mova m4, [r6-32*29] ; idct64 63 - n
mova m5, [r5-32*28] ; idct64 48 + n
mova m6, [r6-32*45] ; idct64 47 - n
mova m7, [r5-32*44] ; idct64 32 + n
paddd m8, m0, m1 ; idct16 out0 + n
psubd m0, m1 ; idct16 out15 - n
REPX {pmaxsd x, m12}, m8, m0
REPX {pminsd x, m13}, m8, m0
paddd m1, m8, m3 ; idct32 out0 + n
psubd m8, m3 ; idct32 out31 - n
paddd m3, m0, m2 ; idct32 out15 - n
psubd m0, m2 ; idct32 out16 + n
REPX {pmaxsd x, m12}, m1, m8, m3, m0
REPX {pminsd x, m13}, m1, m3, m8, m0
REPX {paddd x, m15}, m1, m3, m0, m8
paddd m2, m1, m4 ; idct64 out0 + n (unshifted)
psubd m1, m4 ; idct64 out63 - n (unshifted)
paddd m4, m3, m5 ; idct64 out15 - n (unshifted)
psubd m3, m5 ; idct64 out48 + n (unshifted)
paddd m5, m0, m6 ; idct64 out16 + n (unshifted)
psubd m0, m6 ; idct64 out47 - n (unshifted)
paddd m6, m8, m7 ; idct64 out31 - n (unshifted)
psubd m8, m7 ; idct64 out32 + n (unshifted)
mova [r5-32*44], m2
mova [r6+32* 3], m1
mova [r6-32*45], m4
mova [r5+32* 4], m3
mova [r5-32*28], m5
mova [r6-32*13], m0
mova [r6-32*29], m6
mova [r5-32*12], m8
add r5, 32
sub r6, 32
cmp r5, r6
jl .main_end_loop
ret
.shift_transpose:
%macro IDCT64_SHIFT_TRANSPOSE 1 ; shift
sub r6, 32*48
mov r5, r6
%%loop:
mova m0, [r6-32* 4]
mova m4, [r6+32* 4]
mova m1, [r6-32* 3]
mova m5, [r6+32* 5]
mova m2, [r6-32* 2]
mova m6, [r6+32* 6]
mova m3, [r6-32* 1]
mova m7, [r6+32* 7]
REPX {psrad x, %1}, m0, m4, m1, m5, m2, m6, m3, m7
packssdw m0, m4
packssdw m1, m5
packssdw m2, m6
packssdw m3, m7
mova m4, [r6+32* 0]
mova m6, [r6+32* 8]
mova m5, [r6+32* 1]
mova m7, [r6+32* 9]
REPX {psrad x, %1}, m4, m6, m5, m7
packssdw m4, m6
packssdw m5, m7
mova m6, [r6+32* 2]
mova m8, [r6+32*10]
mova m7, [r6+32* 3]
mova m9, [r6+32*11]
REPX {psrad x, %1}, m6, m8, m7, m9
packssdw m6, m8
packssdw m7, m9
call m(idct_16x8_internal_10bpc).transpose3
mova [r5-32*4], m0
mova [r5-32*3], m1
mova [r5-32*2], m2
mova [r5-32*1], m3
mova [r5+32*0], m4
mova [r5+32*1], m5
mova [r5+32*2], m6
mova [r5+32*3], m7
add r6, 32*16
add r5, 32*8
cmp r5, r4
jl %%loop
mov r6, r4
%endmacro
IDCT64_SHIFT_TRANSPOSE 2
ret
cglobal inv_txfm_add_dct_dct_64x32_10bpc, 4, 7, 0, dst, stride, c, eob
test eobd, eobd
jz .dconly
PROLOGUE 0, 8, 16, 32*163, dst, stride, c, eob
%undef cmp
vpbroadcastd m11, [pd_2048]
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
vpbroadcastd m14, [pd_2896]
lea r6, [rsp+32*7]
call .main
cmp eobd, 36
jl .fast
call .main
cmp eobd, 136
jl .fast
call .main
cmp eobd, 300
jl .fast
call .main
jmp .pass2
.dconly:
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 32
add r6d, 2048
sar r6d, 12
imul r6d, 2896
add r6d, 6144
sar r6d, 13
jmp m(inv_txfm_add_dct_dct_64x16_10bpc).dconly2
.fast:
pxor m0, m0
lea r4, [rsp+32*135]
.fast_loop:
REPX {mova [r6+32*x], m0}, -4, -3, -2, -1, 0, 1, 2, 3
add r6, 32*8
cmp r6, r4
jl .fast_loop
.pass2:
lea r7, [r6-32*32]
lea r5, [r6+32*8]
lea r6, [pw_5+128]
imul r2, strideq, 19
lea r3, [strideq*3]
add r2, dstq
.pass2_loop:
mova m0, [r7-32*99]
mova m1, [r7-32*97]
mova m2, [r7-32*95]
mova m3, [r7-32*93]
mova m4, [r7-32*67]
mova m5, [r7-32*65]
mova m6, [r7-32*63]
mova m7, [r7-32*61]
mova m8, [r7-32*35]
mova m9, [r7-32*33]
mova m10, [r7-32*31]
mova m11, [r7-32*29]
mova m12, [r7-32* 3]
mova m13, [r7-32* 1]
mova m14, [r7+32* 1]
mova m15, [r7+32* 3]
call m(inv_txfm_add_dct_dct_16x32_8bpc).main_oddhalf
mova m0, [r7-32*100]
mova m1, [r7-32*98]
mova m2, [r7-32*96]
mova m3, [r7-32*94]
mova m4, [r7-32*68]
mova m5, [r7-32*66]
mova m6, [r7-32*64]
mova m7, [r7-32*62]
mova m8, [r7-32*36]
mova m9, [r7-32*34]
mova m10, [r7-32*32]
mova m11, [r7-32*30]
mova m12, [r7-32* 4]
mova m13, [r7-32* 2]
mova m14, [r7+32* 0]
mova m15, [r7+32* 2]
add r7, 32*8
mova [rsp], m15
call m(idct_16x16_internal_8bpc).main
call m(inv_txfm_add_dct_dct_16x32_10bpc).pass2_end
sub dstq, r3
lea r2, [r2+r3+32]
add dstq, 32
cmp r7, r4
jl .pass2_loop
RET
ALIGN function_align
.main:
lea r5, [idct64_mul_16bpc]
pmulld m0, m14, [cq+128* 1]
pmulld m1, m14, [cq+128*31]
pmulld m2, m14, [cq+128*17]
pmulld m3, m14, [cq+128*15]
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part1_rect2
pmulld m0, m14, [cq+128* 7]
pmulld m1, m14, [cq+128*25]
pmulld m2, m14, [cq+128*23]
pmulld m3, m14, [cq+128* 9]
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part1_rect2
pmulld m0, m14, [cq+128* 5]
pmulld m1, m14, [cq+128*27]
pmulld m2, m14, [cq+128*21]
pmulld m3, m14, [cq+128*11]
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part1_rect2
pmulld m0, m14, [cq+128* 3]
pmulld m1, m14, [cq+128*29]
pmulld m2, m14, [cq+128*19]
pmulld m3, m14, [cq+128*13]
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part1_rect2
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part2
pmulld m0, m14, [cq+128* 2]
pmulld m1, m14, [cq+128*14]
pmulld m2, m14, [cq+128*18]
pmulld m3, m14, [cq+128*30]
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_oddhalf_part1_fast_rect2
pmulld m0, m14, [cq+128* 6]
pmulld m1, m14, [cq+128*10]
pmulld m2, m14, [cq+128*22]
pmulld m3, m14, [cq+128*26]
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_oddhalf_part2_fast_rect2
pmulld m0, m14, [cq+128* 4]
pmulld m1, m14, [cq+128*12]
pmulld m2, m14, [cq+128*20]
pmulld m3, m14, [cq+128*28]
call m(idct_8x16_internal_10bpc).main_oddhalf_fast_rect2
pmulld m0, m14, [cq+128* 0]
pmulld m1, m14, [cq+128* 8]
pmulld m2, m14, [cq+128*16]
pmulld m3, m14, [cq+128*24]
pxor m15, m15
mov r7d, 128*29
.main_zero_loop:
mova [cq+r7-128*1], m15
mova [cq+r7+128*0], m15
mova [cq+r7+128*1], m15
mova [cq+r7+128*2], m15
sub r7d, 128*4
jg .main_zero_loop
psrld m15, m11, 11 ; pd_1
REPX {paddd x, m11}, m0, m1, m2, m3
REPX {psrad x, 12 }, m0, m1, m2, m3
call m(inv_txfm_add_dct_dct_64x16_10bpc).main_end2
IDCT64_SHIFT_TRANSPOSE 1
ret
cglobal inv_txfm_add_dct_dct_64x64_10bpc, 4, 7, 0, dst, stride, c, eob
test eobd, eobd
jz .dconly
PROLOGUE 0, 11, 16, 32*195, dst, stride, c, eob
%undef cmp
vpbroadcastd m11, [pd_2048]
vpbroadcastd m12, [clip_18b_min]
vpbroadcastd m13, [clip_18b_max]
vpbroadcastd m14, [pd_2896]
lea r6, [rsp+32*7]
call .main
cmp eobd, 36
jl .fast
call .main
cmp eobd, 136
jl .fast
call .main
cmp eobd, 300
jl .fast
call .main
jmp .pass2
.dconly:
imul r6d, [cq], 2896
mov [cq], eobd ; 0
mov r3d, 64
jmp m(inv_txfm_add_dct_dct_64x16_10bpc).dconly
.fast:
pxor m0, m0
lea r4, [rsp+32*135]
.fast_loop:
REPX {mova [r6+32*x], m0}, -4, -3, -2, -1, 0, 1, 2, 3
add r6, 32*8
cmp r6, r4
jl .fast_loop
.pass2:
lea r10, [r6-32*32]
lea r6, [pw_5+128]
lea r8, [strideq*4]
lea r9, [strideq*5]
lea r3, [r9+strideq*1] ; stride*6
lea r7, [r9+strideq*2] ; stride*7
.pass2_loop:
mova m0, [r10-32*100] ; in0
mova m1, [r10-32*96] ; in4
mova m2, [r10-32*68] ; in8
mova m3, [r10-32*64] ; in12
mova m4, [r10-32*36] ; in16
mova m5, [r10-32*32] ; in20
mova m6, [r10-32* 4] ; in24
mova m7, [r10+32* 0] ; in28
pxor m8, m8
REPX {mova x, m8}, m9, m10, m11, m12, m13, m14
mova [rsp], m8
call m(idct_16x16_internal_8bpc).main
mova m1, [rsp+32*1]
mova [r4-32*4], m0
mova [r4-32*3], m1
mova [r4-32*2], m2
mova [r4-32*1], m3
mova [r4+32*0], m4
mova [r4+32*1], m5
mova [r4+32*2], m6
mova [r4+32*3], m7
add r4, 32*8
mova [r4-32*4], m8
mova [r4-32*3], m9
mova [r4-32*2], m10
mova [r4-32*1], m11
mova [r4+32*0], m12
mova [r4+32*1], m13
mova [r4+32*2], m14
mova [r4+32*3], m15
mova m0, [r10-32*98] ; in2
mova m1, [r10-32*94] ; in6
mova m2, [r10-32*66] ; in10
mova m3, [r10-32*62] ; in14
mova m4, [r10-32*34] ; in18
mova m5, [r10-32*30] ; in22
mova m6, [r10-32* 2] ; in26
mova m7, [r10+32* 2] ; in30
lea r5, [r4+32*16]
add r4, 32*8
call m(inv_txfm_add_dct_dct_16x32_8bpc).main_oddhalf_fast
mova m0, [r10-32*99] ; in1
mova m1, [r10+32* 3] ; in31
mova m2, [r10-32*35] ; in17
mova m3, [r10-32*61] ; in15
mova m4, [r10-32*67] ; in9
mova m5, [r10-32*29] ; in23
mova m6, [r10-32* 3] ; in25
mova m7, [r10-32*93] ; in7
lea r6, [idct64_mul - 8]
add r4, 32*16
add r5, 32*32
call m(inv_txfm_add_dct_dct_16x64_8bpc).main_part1
mova m0, [r10-32*95] ; in5
mova m1, [r10-32* 1] ; in27
mova m2, [r10-32*31] ; in21
mova m3, [r10-32*65] ; in11
mova m4, [r10-32*63] ; in13
mova m5, [r10-32*33] ; in19
mova m6, [r10+32* 1] ; in29
mova m7, [r10-32*97] ; in3
add r6, 8
add r4, 32*8
sub r5, 32*8
call m(inv_txfm_add_dct_dct_16x64_8bpc).main_part1
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part2_pass2
add r10, 32*8
sub dstq, r8
sub r4, 32*44
add dstq, 32
cmp r10, r4
jl .pass2_loop
RET
ALIGN function_align
.main:
lea r5, [idct64_mul_16bpc]
mova m0, [cq+128* 1]
mova m1, [cq+128*31]
mova m2, [cq+128*17]
mova m3, [cq+128*15]
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part1
mova m0, [cq+128* 7]
mova m1, [cq+128*25]
mova m2, [cq+128*23]
mova m3, [cq+128* 9]
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part1
mova m0, [cq+128* 5]
mova m1, [cq+128*27]
mova m2, [cq+128*21]
mova m3, [cq+128*11]
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part1
mova m0, [cq+128* 3]
mova m1, [cq+128*29]
mova m2, [cq+128*19]
mova m3, [cq+128*13]
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part1
call m(inv_txfm_add_dct_dct_16x64_10bpc).main_part2
mova m0, [cq+128* 2]
mova m1, [cq+128*14]
mova m2, [cq+128*18]
mova m3, [cq+128*30]
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_oddhalf_part1_fast
mova m0, [cq+128* 6]
mova m1, [cq+128*10]
mova m2, [cq+128*22]
mova m3, [cq+128*26]
call m(inv_txfm_add_dct_dct_8x32_10bpc).main_oddhalf_part2_fast
mova m0, [cq+128* 4]
mova m1, [cq+128*12]
mova m2, [cq+128*20]
mova m3, [cq+128*28]
call m(idct_8x16_internal_10bpc).main_oddhalf_fast
mova m0, [cq+128* 0]
mova m1, [cq+128* 8]
mova m2, [cq+128*16]
mova m3, [cq+128*24]
pxor m15, m15
mov r7d, 128*29
.main_zero_loop:
mova [cq+r7-128*1], m15
mova [cq+r7+128*0], m15
mova [cq+r7+128*1], m15
mova [cq+r7+128*2], m15
sub r7d, 128*4
jg .main_zero_loop
call m(inv_txfm_add_dct_dct_64x16_10bpc).main_end
jmp m(inv_txfm_add_dct_dct_64x16_10bpc).shift_transpose
%endif ; ARCH_X86_64
|
<%
from pwnlib.shellcraft.thumb.linux import syscall
%>
<%page args="name"/>
<%docstring>
Invokes the syscall unlink. See 'man 2 unlink' for more information.
Arguments:
name(char): name
</%docstring>
${syscall('SYS_unlink', name)}
|
Name: zel_mut1.asm
Type: file
Size: 149479
Last-Modified: '2016-05-13T04:36:32Z'
SHA-1: 53F22F18712BA63430F58695F8C3A20A4916B395
Description: null
|
C x86_64/fat/sha1-compress-2.asm
ifelse(<
Copyright (C) 2018 Niels Möller
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
>)
define(<fat_transform>, <_$1_sha_ni>)
include_src(<x86_64/sha_ni/sha1-compress.asm>)
|
.exportzp FC_LOCAL
.exportzp FC_REG
.exportzp FC_STACK
.exportzp FC_FASTCALL_REG
.exportzp L ; TODO: そのうち消すこと
.exportzp reg
.exportzp S
.import interrupt
.import start
.import interrupt_irq
.segment "HEADER"
; +--------+------+------------------------------------------+
; | Offset | Size | Content(s) |
; +--------+------+------------------------------------------+
; | 0 | 3 | 'NES' |
; | 3 | 1 | $1A |
; | 4 | 1 | 16K PRG-ROM page count |
; | 5 | 1 | 8K CHR-ROM page count |
; | 6 | 1 | ROM Control Byte #1 |
; | | | %####vTsM |
; | | | | ||||+- 0=Horizontal mirroring |
; | | | | |||| 1=Vertical mirroring |
; | | | | |||+-- 1=SRAM enabled |
; | | | | ||+--- 1=512-byte trainer present |
; | | | | |+---- 1=Four-screen mirroring |
; | | | | | |
; | | | +--+----- Mapper # (lower 4-bits) |
; | 7 | 1 | ROM Control Byte #2 |
; | | | %####0000 |
; | | | | | |
; | | | +--+----- Mapper # (upper 4-bits) |
; | 8-15 | 8 | $00 |
; | 16-.. | | Actual 16K PRG-ROM pages (in linear |
; | ... | | order). If a trainer exists, it precedes |
; | ... | | the first PRG-ROM page. |
; | ..-EOF | | CHR-ROM pages (in ascending order). |
; +--------+------+------------------------------------------+
.byte $4e,$45,$53,$1a ; "NES"^Z
.byte 16 ; ines prg - Specifies the number of 16k prg banks.
.byte 8 ; ines chr - Specifies the number of 8k chr banks.
;; MMC3(4), battery backuped RAM
.byte %01000011 ; ines mir - Specifies VRAM mirroring of the banks.
.byte 0 ; ines map - Specifies the NES mapper used.
.byte 0,0,0,0,0,0,0,0 ; 8 zeroes
.segment "FC_ZEROPAGE": zeropage
FC_LOCAL: .res $10
FC_REG: .res $10
FC_FASTCALL_REG: .res $10
.segment "FC_STACK": zeropage
FC_STACK: .res $80
L = FC_LOCAL
reg = FC_REG
S = FC_STACK
.segment "VECTORS"
.word interrupt
.word start
.word interrupt_irq
.segment "fs_data"
.incbin "../res/fs_data.bin"
|
/***
*
* Copyright (c) 1996-2001, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
#include "cbase.h"
#include "explode.h"
#define SF_TANK_ACTIVE 0x0001
#define SF_TANK_PLAYER 0x0002
#define SF_TANK_HUMANS 0x0004
#define SF_TANK_ALIENS 0x0008
#define SF_TANK_LINEOFSIGHT 0x0010
#define SF_TANK_CANCONTROL 0x0020
#define SF_TANK_SOUNDON 0x8000
enum TANKBULLET
{
TANK_BULLET_NONE = 0,
TANK_BULLET_9MM = 1,
TANK_BULLET_MP5 = 2,
TANK_BULLET_12MM = 3,
};
// Custom damage
// env_laser (duration is 0.5 rate of fire)
// rockets
// explosion?
class COFFuncTank : public CBaseEntity
{
public:
void Spawn() override;
void Precache() override;
bool KeyValue(KeyValueData* pkvd) override;
void Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value) override;
void Think() override;
void TrackTarget();
virtual void Fire(const Vector& barrelEnd, const Vector& forward, entvars_t* pevAttacker);
virtual Vector UpdateTargetPosition(CBaseEntity* pTarget)
{
return pTarget->BodyTarget(pev->origin);
}
void StartRotSound();
void StopRotSound();
// Bmodels don't go across transitions
int ObjectCaps() override { return CBaseEntity::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
inline bool IsActive() { return (pev->spawnflags & SF_TANK_ACTIVE) != 0; }
inline void TankActivate()
{
pev->spawnflags |= SF_TANK_ACTIVE;
pev->nextthink = pev->ltime + 0.1;
m_fireLast = 0;
}
inline void TankDeactivate()
{
pev->spawnflags &= ~SF_TANK_ACTIVE;
m_fireLast = 0;
StopRotSound();
}
inline bool CanFire() { return (gpGlobals->time - m_lastSightTime) < m_persist; }
bool InRange(float range);
// Acquire a target. pPlayer is a player in the PVS
CBaseEntity* FindTarget();
void TankTrace(const Vector& vecStart, const Vector& vecForward, const Vector& vecSpread, TraceResult& tr);
Vector BarrelPosition()
{
Vector forward, right, up;
UTIL_MakeVectorsPrivate(pev->angles, forward, right, up);
return pev->origin + (forward * m_barrelPos.x) + (right * m_barrelPos.y) + (up * m_barrelPos.z);
}
void AdjustAnglesForBarrel(Vector& angles, float distance);
bool Save(CSave& save) override;
bool Restore(CRestore& restore) override;
static TYPEDESCRIPTION m_SaveData[];
bool OnControls(entvars_t* pevTest) override;
bool StartControl(CBasePlayer* pController);
void StopControl();
void ControllerPostFrame();
protected:
CBasePlayer* m_pController;
float m_flNextAttack;
Vector m_vecControllerUsePos;
float m_yawCenter; // "Center" yaw
float m_yawRate; // Max turn rate to track targets
float m_yawRange; // Range of turning motion (one-sided: 30 is +/- 30 degress from center)
// Zero is full rotation
float m_yawTolerance; // Tolerance angle
float m_pitchCenter; // "Center" pitch
float m_pitchRate; // Max turn rate on pitch
float m_pitchRange; // Range of pitch motion as above
float m_pitchTolerance; // Tolerance angle
float m_fireLast; // Last time I fired
float m_fireRate; // How many rounds/second
float m_lastSightTime; // Last time I saw target
float m_persist; // Persistence of firing (how long do I shoot when I can't see)
float m_minRange; // Minimum range to aim/track
float m_maxRange; // Max range to aim/track
Vector m_barrelPos; // Length of the freakin barrel
float m_spriteScale; // Scale of any sprites we shoot
int m_iszSpriteSmoke;
int m_iszSpriteFlash;
TANKBULLET m_bulletType; // Bullet type
int m_iBulletDamage; // 0 means use Bullet type's default damage
Vector m_sightOrigin; // Last sight of target
int m_spread; // firing spread
int m_iszMaster; // Master entity (game_team_master or multisource)
//Not saved, will reacquire after restore
//TODO: could be exploited to make a tank change targets
EHANDLE m_hEnemy;
//0 - player only
//1 - all targets allied to player
int m_iEnemyType;
};
TYPEDESCRIPTION COFFuncTank::m_SaveData[] =
{
DEFINE_FIELD(COFFuncTank, m_yawCenter, FIELD_FLOAT),
DEFINE_FIELD(COFFuncTank, m_yawRate, FIELD_FLOAT),
DEFINE_FIELD(COFFuncTank, m_yawRange, FIELD_FLOAT),
DEFINE_FIELD(COFFuncTank, m_yawTolerance, FIELD_FLOAT),
DEFINE_FIELD(COFFuncTank, m_pitchCenter, FIELD_FLOAT),
DEFINE_FIELD(COFFuncTank, m_pitchRate, FIELD_FLOAT),
DEFINE_FIELD(COFFuncTank, m_pitchRange, FIELD_FLOAT),
DEFINE_FIELD(COFFuncTank, m_pitchTolerance, FIELD_FLOAT),
DEFINE_FIELD(COFFuncTank, m_fireLast, FIELD_TIME),
DEFINE_FIELD(COFFuncTank, m_fireRate, FIELD_FLOAT),
DEFINE_FIELD(COFFuncTank, m_lastSightTime, FIELD_TIME),
DEFINE_FIELD(COFFuncTank, m_persist, FIELD_FLOAT),
DEFINE_FIELD(COFFuncTank, m_minRange, FIELD_FLOAT),
DEFINE_FIELD(COFFuncTank, m_maxRange, FIELD_FLOAT),
DEFINE_FIELD(COFFuncTank, m_barrelPos, FIELD_VECTOR),
DEFINE_FIELD(COFFuncTank, m_spriteScale, FIELD_FLOAT),
DEFINE_FIELD(COFFuncTank, m_iszSpriteSmoke, FIELD_STRING),
DEFINE_FIELD(COFFuncTank, m_iszSpriteFlash, FIELD_STRING),
DEFINE_FIELD(COFFuncTank, m_bulletType, FIELD_INTEGER),
DEFINE_FIELD(COFFuncTank, m_sightOrigin, FIELD_VECTOR),
DEFINE_FIELD(COFFuncTank, m_spread, FIELD_INTEGER),
DEFINE_FIELD(COFFuncTank, m_pController, FIELD_CLASSPTR),
DEFINE_FIELD(COFFuncTank, m_vecControllerUsePos, FIELD_VECTOR),
DEFINE_FIELD(COFFuncTank, m_flNextAttack, FIELD_TIME),
DEFINE_FIELD(COFFuncTank, m_iBulletDamage, FIELD_INTEGER),
DEFINE_FIELD(COFFuncTank, m_iszMaster, FIELD_STRING),
DEFINE_FIELD(COFFuncTank, m_iEnemyType, FIELD_INTEGER),
};
IMPLEMENT_SAVERESTORE(COFFuncTank, CBaseEntity);
static Vector gTankSpread[] =
{
Vector(0, 0, 0), // perfect
Vector(0.025, 0.025, 0.025), // small cone
Vector(0.05, 0.05, 0.05), // medium cone
Vector(0.1, 0.1, 0.1), // large cone
Vector(0.25, 0.25, 0.25), // extra-large cone
};
#define MAX_FIRING_SPREADS std::size(gTankSpread)
void COFFuncTank::Spawn()
{
Precache();
pev->movetype = MOVETYPE_PUSH; // so it doesn't get pushed by anything
pev->solid = SOLID_BSP;
SetModel(STRING(pev->model));
m_yawCenter = pev->angles.y;
m_pitchCenter = pev->angles.x;
if (IsActive())
pev->nextthink = pev->ltime + 1.0;
m_sightOrigin = BarrelPosition(); // Point at the end of the barrel
if (m_fireRate <= 0)
m_fireRate = 1;
//TODO: needs to be >=
if (static_cast<std::size_t>(m_spread) > MAX_FIRING_SPREADS)
m_spread = 0;
pev->oldorigin = pev->origin;
m_hEnemy = nullptr;
}
void COFFuncTank::Precache()
{
if (!FStringNull(m_iszSpriteSmoke))
PrecacheModel(STRING(m_iszSpriteSmoke));
if (!FStringNull(m_iszSpriteFlash))
PrecacheModel(STRING(m_iszSpriteFlash));
if (!FStringNull(pev->noise))
PRECACHE_SOUND(STRING(pev->noise));
}
bool COFFuncTank::KeyValue(KeyValueData* pkvd)
{
if (FStrEq(pkvd->szKeyName, "yawrate"))
{
m_yawRate = atof(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "yawrange"))
{
m_yawRange = atof(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "yawtolerance"))
{
m_yawTolerance = atof(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "pitchrange"))
{
m_pitchRange = atof(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "pitchrate"))
{
m_pitchRate = atof(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "pitchtolerance"))
{
m_pitchTolerance = atof(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "firerate"))
{
m_fireRate = atof(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "barrel"))
{
m_barrelPos.x = atof(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "barrely"))
{
m_barrelPos.y = atof(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "barrelz"))
{
m_barrelPos.z = atof(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "spritescale"))
{
m_spriteScale = atof(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "spritesmoke"))
{
m_iszSpriteSmoke = ALLOC_STRING(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "spriteflash"))
{
m_iszSpriteFlash = ALLOC_STRING(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "rotatesound"))
{
pev->noise = ALLOC_STRING(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "persistence"))
{
m_persist = atof(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "bullet"))
{
m_bulletType = (TANKBULLET)atoi(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "bullet_damage"))
{
m_iBulletDamage = atoi(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "firespread"))
{
m_spread = atoi(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "minRange"))
{
m_minRange = atof(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "maxRange"))
{
m_maxRange = atof(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "master"))
{
m_iszMaster = ALLOC_STRING(pkvd->szValue);
return true;
}
else if (FStrEq(pkvd->szKeyName, "enemytype"))
{
m_iEnemyType = atoi(pkvd->szValue);
return true;
}
return CBaseEntity::KeyValue(pkvd);
}
////////////// START NEW STUFF //////////////
//==================================================================================
// TANK CONTROLLING
bool COFFuncTank::OnControls(entvars_t* pevTest)
{
if ((pev->spawnflags & SF_TANK_CANCONTROL) == 0)
return false;
Vector offset = pevTest->origin - pev->origin;
if ((m_vecControllerUsePos - pevTest->origin).Length() < 30)
return true;
return false;
}
bool COFFuncTank::StartControl(CBasePlayer* pController)
{
if (m_pController != nullptr)
return false;
// Team only or disabled?
if (!FStringNull(m_iszMaster))
{
if (!UTIL_IsMasterTriggered(m_iszMaster, pController))
return false;
}
ALERT(at_console, "using TANK!\n");
m_pController = pController;
if (m_pController->m_pActiveItem)
{
m_pController->m_pActiveItem->Holster();
m_pController->pev->weaponmodel = 0;
m_pController->pev->viewmodel = 0;
}
m_pController->m_iHideHUD |= HIDEHUD_WEAPONS;
m_vecControllerUsePos = m_pController->pev->origin;
pev->nextthink = pev->ltime + 0.1;
return true;
}
void COFFuncTank::StopControl()
{
// TODO: bring back the controllers current weapon
if (!m_pController)
return;
if (m_pController->m_pActiveItem)
m_pController->m_pActiveItem->Deploy();
ALERT(at_console, "stopped using TANK\n");
m_pController->m_iHideHUD &= ~HIDEHUD_WEAPONS;
pev->nextthink = 0;
m_pController = nullptr;
if (IsActive())
pev->nextthink = pev->ltime + 1.0;
}
// Called each frame by the player's ItemPostFrame
void COFFuncTank::ControllerPostFrame()
{
ASSERT(m_pController != nullptr);
if (gpGlobals->time < m_flNextAttack)
return;
if ((m_pController->pev->button & IN_ATTACK) != 0)
{
Vector vecForward;
UTIL_MakeVectorsPrivate(pev->angles, vecForward, nullptr, nullptr);
m_fireLast = gpGlobals->time - (1 / m_fireRate) - 0.01; // to make sure the gun doesn't fire too many bullets
Fire(BarrelPosition(), vecForward, m_pController->pev);
// HACKHACK -- make some noise (that the AI can hear)
if (m_pController && m_pController->IsPlayer())
((CBasePlayer*)m_pController)->m_iWeaponVolume = LOUD_GUN_VOLUME;
m_flNextAttack = gpGlobals->time + (1 / m_fireRate);
}
}
////////////// END NEW STUFF //////////////
void COFFuncTank::Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value)
{
if ((pev->spawnflags & SF_TANK_CANCONTROL) != 0)
{ // player controlled turret
if (pActivator->Classify() != CLASS_PLAYER)
return;
if (value == 2 && useType == USE_SET)
{
ControllerPostFrame();
}
else if (!m_pController && useType != USE_OFF)
{
((CBasePlayer*)pActivator)->m_pTank = this;
StartControl((CBasePlayer*)pActivator);
}
else
{
StopControl();
}
}
else
{
if (!ShouldToggle(useType, IsActive()))
return;
if (IsActive())
TankDeactivate();
else
TankActivate();
}
}
CBaseEntity* COFFuncTank::FindTarget()
{
auto pPlayerTarget = UTIL_FindEntityByClassname(nullptr, "player");
if (!pPlayerTarget)
return pPlayerTarget;
m_pLink = nullptr;
auto flIdealDist = m_maxRange;
CBaseEntity* pIdealTarget = nullptr;
if (pPlayerTarget->IsAlive())
{
const auto distance = (pPlayerTarget->pev->origin - pev->origin).Length2D();
if (0 <= distance && distance <= 2048.0)
{
TraceResult tr;
UTIL_TraceLine(BarrelPosition(), pPlayerTarget->pev->origin + pPlayerTarget->pev->view_ofs, dont_ignore_monsters, edict(), &tr);
if (tr.pHit == pPlayerTarget->pev->pContainingEntity)
{
if (0 == m_iEnemyType)
return pPlayerTarget;
flIdealDist = distance;
pIdealTarget = pPlayerTarget;
}
}
}
Vector size(2048, 2048, 2048);
CBaseEntity* pList[100];
const auto count = UTIL_EntitiesInBox(pList, std::size(pList), pev->origin - size, pev->origin + size, FL_MONSTER | FL_CLIENT);
for (auto i = 0; i < count; ++i)
{
auto pEntity = pList[i];
if (this == pEntity)
continue;
if ((pEntity->pev->spawnflags & SF_MONSTER_PRISONER) != 0)
continue;
if (pEntity->pev->health <= 0)
continue;
auto pMonster = pEntity->MyMonsterPointer();
if (!pMonster)
continue;
if (pMonster->IRelationship(pPlayerTarget) != R_AL)
continue;
if ((pEntity->pev->flags & FL_NOTARGET) != 0)
continue;
if (!FVisible(pEntity))
continue;
if (pEntity->IsPlayer() && (pev->spawnflags & SF_TANK_ACTIVE) != 0)
{
if (pMonster->FInViewCone(this))
{
pev->spawnflags &= ~SF_TANK_ACTIVE;
}
}
pEntity->m_pLink = m_pLink;
m_pLink = pEntity;
}
for (auto pEntity = m_pLink; pEntity; pEntity = pEntity->m_pLink)
{
const auto distance = (pEntity->pev->origin - pev->origin).Length();
if (distance >= 0 && 2048 >= distance && (!pIdealTarget || flIdealDist > distance))
{
TraceResult tr;
UTIL_TraceLine(BarrelPosition(), pEntity->pev->origin + pEntity->pev->view_ofs, dont_ignore_monsters, edict(), &tr);
if ((pev->spawnflags & SF_TANK_LINEOFSIGHT) != 0)
{
if (tr.pHit == pEntity->edict())
{
flIdealDist = distance;
}
if (tr.pHit == pEntity->edict())
pIdealTarget = pEntity;
}
else
{
flIdealDist = distance;
pIdealTarget = pEntity;
}
}
}
return pIdealTarget;
}
bool COFFuncTank::InRange(float range)
{
if (range < m_minRange)
return false;
if (m_maxRange > 0 && range > m_maxRange)
return false;
return true;
}
void COFFuncTank::Think()
{
pev->avelocity = g_vecZero;
TrackTarget();
if (fabs(pev->avelocity.x) > 1 || fabs(pev->avelocity.y) > 1)
StartRotSound();
else
StopRotSound();
}
void COFFuncTank::TrackTarget()
{
TraceResult tr;
edict_t* pPlayer = FIND_CLIENT_IN_PVS(edict());
bool updateTime = false, lineOfSight;
Vector angles, direction, targetPosition, barrelEnd;
CBaseEntity* pTarget;
// Get a position to aim for
if (m_pController)
{
// Tanks attempt to mirror the player's angles
angles = m_pController->pev->v_angle;
angles[0] = 0 - angles[0];
pev->nextthink = pev->ltime + 0.05;
}
else
{
if (IsActive())
pev->nextthink = pev->ltime + 0.1;
else
return;
if (FNullEnt(pPlayer))
{
if (IsActive())
pev->nextthink = pev->ltime + 2; // Wait 2 secs
return;
}
//Keep tracking the same target
if (m_hEnemy && m_hEnemy->IsAlive())
{
pTarget = m_hEnemy;
}
else
{
pTarget = FindTarget();
if (!pTarget)
{
m_hEnemy = nullptr;
return;
}
}
// Calculate angle needed to aim at target
barrelEnd = BarrelPosition();
targetPosition = pTarget->pev->origin + pTarget->pev->view_ofs;
float range = (targetPosition - barrelEnd).Length();
if (!InRange(range))
return;
UTIL_TraceLine(barrelEnd, targetPosition, dont_ignore_monsters, edict(), &tr);
lineOfSight = false;
// No line of sight, don't track
if (tr.flFraction == 1.0 || tr.pHit == pTarget->edict())
{
lineOfSight = true;
if (InRange(range) && pTarget->IsAlive())
{
updateTime = true;
m_sightOrigin = UpdateTargetPosition(pTarget);
}
}
// Track sight origin
// !!! I'm not sure what i changed
direction = m_sightOrigin - pev->origin;
// direction = m_sightOrigin - barrelEnd;
angles = UTIL_VecToAngles(direction);
// Calculate the additional rotation to point the end of the barrel at the target (not the gun's center)
AdjustAnglesForBarrel(angles, direction.Length());
}
angles.x = -angles.x;
// Force the angles to be relative to the center position
angles.y = m_yawCenter + UTIL_AngleDistance(angles.y, m_yawCenter);
angles.x = m_pitchCenter + UTIL_AngleDistance(angles.x, m_pitchCenter);
// Limit against range in y
if (angles.y > m_yawCenter + m_yawRange)
{
angles.y = m_yawCenter + m_yawRange;
updateTime = false; // Don't update if you saw the player, but out of range
}
else if (angles.y < (m_yawCenter - m_yawRange))
{
angles.y = (m_yawCenter - m_yawRange);
updateTime = false; // Don't update if you saw the player, but out of range
}
if (updateTime)
m_lastSightTime = gpGlobals->time;
// Move toward target at rate or less
float distY = UTIL_AngleDistance(angles.y, pev->angles.y);
pev->avelocity.y = distY * 10;
if (pev->avelocity.y > m_yawRate)
pev->avelocity.y = m_yawRate;
else if (pev->avelocity.y < -m_yawRate)
pev->avelocity.y = -m_yawRate;
// Limit against range in x
if (angles.x > m_pitchCenter + m_pitchRange)
angles.x = m_pitchCenter + m_pitchRange;
else if (angles.x < m_pitchCenter - m_pitchRange)
angles.x = m_pitchCenter - m_pitchRange;
// Move toward target at rate or less
float distX = UTIL_AngleDistance(angles.x, pev->angles.x);
pev->avelocity.x = distX * 10;
if (pev->avelocity.x > m_pitchRate)
pev->avelocity.x = m_pitchRate;
else if (pev->avelocity.x < -m_pitchRate)
pev->avelocity.x = -m_pitchRate;
if (m_pController)
return;
if (CanFire() && ((fabs(distX) < m_pitchTolerance && fabs(distY) < m_yawTolerance) || (pev->spawnflags & SF_TANK_LINEOFSIGHT) != 0))
{
bool fire = false;
Vector forward;
UTIL_MakeVectorsPrivate(pev->angles, forward, nullptr, nullptr);
if ((pev->spawnflags & SF_TANK_LINEOFSIGHT) != 0)
{
float length = direction.Length();
UTIL_TraceLine(barrelEnd, barrelEnd + forward * length, dont_ignore_monsters, edict(), &tr);
if (tr.pHit == pTarget->edict())
fire = true;
}
else
fire = true;
if (fire)
{
Fire(BarrelPosition(), forward, pev);
}
else
m_fireLast = 0;
}
else
m_fireLast = 0;
}
// If barrel is offset, add in additional rotation
void COFFuncTank::AdjustAnglesForBarrel(Vector& angles, float distance)
{
float r2, d2;
if (m_barrelPos.y != 0 || m_barrelPos.z != 0)
{
distance -= m_barrelPos.z;
d2 = distance * distance;
if (0 != m_barrelPos.y)
{
r2 = m_barrelPos.y * m_barrelPos.y;
angles.y += (180.0 / M_PI) * atan2(m_barrelPos.y, sqrt(d2 - r2));
}
if (0 != m_barrelPos.z)
{
r2 = m_barrelPos.z * m_barrelPos.z;
angles.x += (180.0 / M_PI) * atan2(-m_barrelPos.z, sqrt(d2 - r2));
}
}
}
// Fire targets and spawn sprites
void COFFuncTank::Fire(const Vector& barrelEnd, const Vector& forward, entvars_t* pevAttacker)
{
if (m_fireLast != 0)
{
if (!FStringNull(m_iszSpriteSmoke))
{
CSprite* pSprite = CSprite::SpriteCreate(STRING(m_iszSpriteSmoke), barrelEnd, true);
pSprite->AnimateAndDie(RANDOM_FLOAT(15.0, 20.0));
pSprite->SetTransparency(kRenderTransAlpha, pev->rendercolor.x, pev->rendercolor.y, pev->rendercolor.z, 255, kRenderFxNone);
pSprite->pev->velocity.z = RANDOM_FLOAT(40, 80);
pSprite->SetScale(m_spriteScale);
}
if (!FStringNull(m_iszSpriteFlash))
{
CSprite* pSprite = CSprite::SpriteCreate(STRING(m_iszSpriteFlash), barrelEnd, true);
pSprite->AnimateAndDie(60);
pSprite->SetTransparency(kRenderTransAdd, 255, 255, 255, 255, kRenderFxNoDissipation);
pSprite->SetScale(m_spriteScale);
// Hack Hack, make it stick around for at least 100 ms.
pSprite->pev->nextthink += 0.1;
}
SUB_UseTargets(this, USE_TOGGLE, 0);
}
m_fireLast = gpGlobals->time;
}
void COFFuncTank::TankTrace(const Vector& vecStart, const Vector& vecForward, const Vector& vecSpread, TraceResult& tr)
{
// get circular gaussian spread
float x, y, z;
do
{
x = RANDOM_FLOAT(-0.5, 0.5) + RANDOM_FLOAT(-0.5, 0.5);
y = RANDOM_FLOAT(-0.5, 0.5) + RANDOM_FLOAT(-0.5, 0.5);
z = x * x + y * y;
} while (z > 1);
Vector vecDir = vecForward +
x * vecSpread.x * gpGlobals->v_right +
y * vecSpread.y * gpGlobals->v_up;
Vector vecEnd;
vecEnd = vecStart + vecDir * 4096;
UTIL_TraceLine(vecStart, vecEnd, dont_ignore_monsters, edict(), &tr);
}
void COFFuncTank::StartRotSound()
{
if (FStringNull(pev->noise) || (pev->spawnflags & SF_TANK_SOUNDON) != 0)
return;
pev->spawnflags |= SF_TANK_SOUNDON;
EMIT_SOUND(edict(), CHAN_STATIC, STRING(pev->noise), 0.85, ATTN_NORM);
}
void COFFuncTank::StopRotSound()
{
if ((pev->spawnflags & SF_TANK_SOUNDON) != 0)
STOP_SOUND(edict(), CHAN_STATIC, STRING(pev->noise));
pev->spawnflags &= ~SF_TANK_SOUNDON;
}
class COFFuncTankGun : public COFFuncTank
{
public:
void Fire(const Vector& barrelEnd, const Vector& forward, entvars_t* pevAttacker) override;
};
LINK_ENTITY_TO_CLASS(func_tank_of, COFFuncTankGun);
void COFFuncTankGun::Fire(const Vector& barrelEnd, const Vector& forward, entvars_t* pevAttacker)
{
int i;
if (m_fireLast != 0)
{
// FireBullets needs gpGlobals->v_up, etc.
UTIL_MakeAimVectors(pev->angles);
int bulletCount = (gpGlobals->time - m_fireLast) * m_fireRate;
if (bulletCount > 0)
{
for (i = 0; i < bulletCount; i++)
{
switch (m_bulletType)
{
case TANK_BULLET_9MM:
FireBullets(1, barrelEnd, forward, gTankSpread[m_spread], 4096, BULLET_MONSTER_9MM, 1, m_iBulletDamage, pevAttacker);
break;
case TANK_BULLET_MP5:
FireBullets(1, barrelEnd, forward, gTankSpread[m_spread], 4096, BULLET_MONSTER_MP5, 1, m_iBulletDamage, pevAttacker);
break;
case TANK_BULLET_12MM:
FireBullets(1, barrelEnd, forward, gTankSpread[m_spread], 4096, BULLET_MONSTER_12MM, 1, m_iBulletDamage, pevAttacker);
break;
default:
case TANK_BULLET_NONE:
break;
}
}
COFFuncTank::Fire(barrelEnd, forward, pevAttacker);
}
}
else
COFFuncTank::Fire(barrelEnd, forward, pevAttacker);
}
class COFFuncTankLaser : public COFFuncTank
{
public:
void Activate() override;
bool KeyValue(KeyValueData* pkvd) override;
void Fire(const Vector& barrelEnd, const Vector& forward, entvars_t* pevAttacker) override;
void Think() override;
CLaser* GetLaser();
bool Save(CSave& save) override;
bool Restore(CRestore& restore) override;
static TYPEDESCRIPTION m_SaveData[];
private:
CLaser* m_pLaser;
float m_laserTime;
};
LINK_ENTITY_TO_CLASS(func_tanklaser_of, COFFuncTankLaser);
TYPEDESCRIPTION COFFuncTankLaser::m_SaveData[] =
{
DEFINE_FIELD(COFFuncTankLaser, m_pLaser, FIELD_CLASSPTR),
DEFINE_FIELD(COFFuncTankLaser, m_laserTime, FIELD_TIME),
};
IMPLEMENT_SAVERESTORE(COFFuncTankLaser, COFFuncTank);
void COFFuncTankLaser::Activate()
{
if (!GetLaser())
{
UTIL_Remove(this);
ALERT(at_error, "Laser tank with no env_laser!\n");
}
else
{
m_pLaser->TurnOff();
}
}
bool COFFuncTankLaser::KeyValue(KeyValueData* pkvd)
{
if (FStrEq(pkvd->szKeyName, "laserentity"))
{
pev->message = ALLOC_STRING(pkvd->szValue);
return true;
}
return COFFuncTank::KeyValue(pkvd);
}
CLaser* COFFuncTankLaser::GetLaser()
{
if (m_pLaser)
return m_pLaser;
edict_t* pentLaser;
pentLaser = FIND_ENTITY_BY_TARGETNAME(nullptr, STRING(pev->message));
while (!FNullEnt(pentLaser))
{
// Found the landmark
if (FClassnameIs(pentLaser, "env_laser"))
{
m_pLaser = (CLaser*)CBaseEntity::Instance(pentLaser);
break;
}
else
pentLaser = FIND_ENTITY_BY_TARGETNAME(pentLaser, STRING(pev->message));
}
return m_pLaser;
}
void COFFuncTankLaser::Think()
{
if (m_pLaser && (gpGlobals->time > m_laserTime))
m_pLaser->TurnOff();
COFFuncTank::Think();
}
void COFFuncTankLaser::Fire(const Vector& barrelEnd, const Vector& forward, entvars_t* pevAttacker)
{
int i;
TraceResult tr;
if (m_fireLast != 0 && GetLaser())
{
// TankTrace needs gpGlobals->v_up, etc.
UTIL_MakeAimVectors(pev->angles);
int bulletCount = (gpGlobals->time - m_fireLast) * m_fireRate;
if (0 != bulletCount)
{
for (i = 0; i < bulletCount; i++)
{
m_pLaser->pev->origin = barrelEnd;
TankTrace(barrelEnd, forward, gTankSpread[m_spread], tr);
m_laserTime = gpGlobals->time;
m_pLaser->TurnOn();
m_pLaser->pev->dmgtime = gpGlobals->time - 1.0;
m_pLaser->FireAtPoint(tr);
m_pLaser->pev->nextthink = 0;
}
COFFuncTank::Fire(barrelEnd, forward, pev);
}
}
else
{
COFFuncTank::Fire(barrelEnd, forward, pev);
}
}
class COFFuncTankRocket : public COFFuncTank
{
public:
void Precache() override;
void Fire(const Vector& barrelEnd, const Vector& forward, entvars_t* pevAttacker) override;
};
LINK_ENTITY_TO_CLASS(func_tankrocket_of, COFFuncTankRocket);
void COFFuncTankRocket::Precache()
{
UTIL_PrecacheOther("rpg_rocket");
COFFuncTank::Precache();
}
void COFFuncTankRocket::Fire(const Vector& barrelEnd, const Vector& forward, entvars_t* pevAttacker)
{
int i;
if (m_fireLast != 0)
{
int bulletCount = (gpGlobals->time - m_fireLast) * m_fireRate;
if (bulletCount > 0)
{
for (i = 0; i < bulletCount; i++)
{
CBaseEntity* pRocket = CBaseEntity::Create("rpg_rocket", barrelEnd, pev->angles, edict());
}
COFFuncTank::Fire(barrelEnd, forward, pev);
}
}
else
COFFuncTank::Fire(barrelEnd, forward, pev);
}
class COFFuncTankMortar : public COFFuncTank
{
public:
bool KeyValue(KeyValueData* pkvd) override;
void Fire(const Vector& barrelEnd, const Vector& forward, entvars_t* pevAttacker) override;
};
LINK_ENTITY_TO_CLASS(func_tankmortar_of, COFFuncTankMortar);
bool COFFuncTankMortar::KeyValue(KeyValueData* pkvd)
{
if (FStrEq(pkvd->szKeyName, "iMagnitude"))
{
pev->impulse = atoi(pkvd->szValue);
return true;
}
return COFFuncTank::KeyValue(pkvd);
}
void COFFuncTankMortar::Fire(const Vector& barrelEnd, const Vector& forward, entvars_t* pevAttacker)
{
if (m_fireLast != 0)
{
int bulletCount = (gpGlobals->time - m_fireLast) * m_fireRate;
// Only create 1 explosion
if (bulletCount > 0)
{
TraceResult tr;
// TankTrace needs gpGlobals->v_up, etc.
UTIL_MakeAimVectors(pev->angles);
TankTrace(barrelEnd, forward, gTankSpread[m_spread], tr);
ExplosionCreate(tr.vecEndPos, pev->angles, edict(), pev->impulse, true);
COFFuncTank::Fire(barrelEnd, forward, pev);
}
}
else
COFFuncTank::Fire(barrelEnd, forward, pev);
}
//============================================================================
// FUNC TANK CONTROLS
//============================================================================
class COFFuncTankControls : public CBaseEntity
{
public:
int ObjectCaps() override;
void Spawn() override;
void Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value) override;
void Think() override;
bool Save(CSave& save) override;
bool Restore(CRestore& restore) override;
static TYPEDESCRIPTION m_SaveData[];
COFFuncTank* m_pTank;
};
LINK_ENTITY_TO_CLASS(func_tankcontrols_of, COFFuncTankControls);
TYPEDESCRIPTION COFFuncTankControls::m_SaveData[] =
{
DEFINE_FIELD(COFFuncTankControls, m_pTank, FIELD_CLASSPTR),
};
IMPLEMENT_SAVERESTORE(COFFuncTankControls, CBaseEntity);
int COFFuncTankControls::ObjectCaps()
{
return (CBaseEntity::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | FCAP_IMPULSE_USE;
}
void COFFuncTankControls::Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value)
{ // pass the Use command onto the controls
if (m_pTank)
m_pTank->Use(pActivator, pCaller, useType, value);
ASSERT(m_pTank != nullptr); // if this fails, most likely means save/restore hasn't worked properly
}
void COFFuncTankControls::Think()
{
edict_t* pTarget = nullptr;
do
{
pTarget = FIND_ENTITY_BY_TARGETNAME(pTarget, STRING(pev->target));
} while (!FNullEnt(pTarget) && 0 != strncmp(STRING(pTarget->v.classname), "func_tank", 9));
if (FNullEnt(pTarget))
{
ALERT(at_console, "No tank %s\n", STRING(pev->target));
return;
}
m_pTank = (COFFuncTank*)Instance(pTarget);
}
void COFFuncTankControls::Spawn()
{
pev->solid = SOLID_TRIGGER;
pev->movetype = MOVETYPE_NONE;
pev->effects |= EF_NODRAW;
SetModel(STRING(pev->model));
UTIL_SetSize(pev, pev->mins, pev->maxs);
UTIL_SetOrigin(pev, pev->origin);
pev->nextthink = gpGlobals->time + 0.3; // After all the func_tank's have spawned
CBaseEntity::Spawn();
}
|
#define BOOST_TEST_MODULE "test_get_or"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp>
#include <map>
#include <unordered_map>
#include <list>
#include <deque>
#include <array>
#include <tuple>
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
#include <string_view>
#endif
using test_value_types = std::tuple<
toml::basic_value<toml::discard_comments>,
toml::basic_value<toml::preserve_comments>,
toml::basic_value<toml::discard_comments, std::map, std::deque>,
toml::basic_value<toml::preserve_comments, std::map, std::deque>
>;
namespace test
{
// to compare result values in BOOST_TEST().
//
// BOOST_TEST outputs the expected and actual values. Thus it includes the
// output stream operator inside. To compile it, we need operator<<s for
// containers to compare.
template<typename charT, typename traits, typename T, typename Alloc>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const std::vector<T, Alloc>& v)
{
os << "[ ";
for(const auto& i : v) {os << i << ' ';}
os << ']';
return os;
}
template<typename charT, typename traits, typename T, typename Alloc>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const std::deque<T, Alloc>& v)
{
os << "[ ";
for(const auto& i : v) {os << i << ' ';}
os << ']';
return os;
}
template<typename charT, typename traits, typename T, typename Alloc>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os, const std::list<T, Alloc>& v)
{
os << "[ ";
for(const auto& i : v) {os << i << ' ';}
os << ']';
return os;
}
template<typename charT, typename traits,
typename Key, typename Value, typename Comp, typename Alloc>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os,
const std::map<Key, Value, Comp, Alloc>& v)
{
os << "[ ";
for(const auto& i : v) {os << '{' << i.first << ", " << i.second << "} ";}
os << ']';
return os;
}
template<typename charT, typename traits,
typename Key, typename Value, typename Hash, typename Eq, typename Alloc>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& os,
const std::unordered_map<Key, Value, Hash, Eq, Alloc>& v)
{
os << "[ ";
for(const auto& i : v) {os << '{' << i.first << ", " << i.second << "} ";}
os << ']';
return os;
}
} // test
#define TOML11_TEST_GET_OR_EXACT(toml_type, init_expr, opt_expr)\
{ \
using namespace test; \
const toml::toml_type init init_expr ; \
const toml::toml_type opt opt_expr ; \
const value_type v(init); \
BOOST_TEST(init != opt); \
BOOST_TEST(init == toml::get_or(v, opt)); \
} \
/**/
BOOST_AUTO_TEST_CASE_TEMPLATE(test_get_or_exact, value_type, test_value_types)
{
TOML11_TEST_GET_OR_EXACT(boolean, ( true), (false))
TOML11_TEST_GET_OR_EXACT(integer, ( 42), ( 54))
TOML11_TEST_GET_OR_EXACT(floating, ( 3.14), ( 2.71))
TOML11_TEST_GET_OR_EXACT(string, ("foo"), ("bar"))
TOML11_TEST_GET_OR_EXACT(local_time, (12, 30, 45), (6, 0, 30))
TOML11_TEST_GET_OR_EXACT(local_date, (2019, toml::month_t::Apr, 1),
(1999, toml::month_t::Jan, 2))
TOML11_TEST_GET_OR_EXACT(local_datetime,
(toml::local_date(2019, toml::month_t::Apr, 1), toml::local_time(12, 30, 45)),
(toml::local_date(1999, toml::month_t::Jan, 2), toml::local_time( 6, 0, 30))
)
TOML11_TEST_GET_OR_EXACT(offset_datetime,
(toml::local_date(2019, toml::month_t::Apr, 1), toml::local_time(12, 30, 45), toml::time_offset( 9, 0)),
(toml::local_date(1999, toml::month_t::Jan, 2), toml::local_time( 6, 0, 30), toml::time_offset(-3, 0))
)
{
const typename value_type::array_type init{1,2,3,4,5};
const typename value_type::array_type opt {6,7,8,9,10};
const value_type v(init);
BOOST_TEST(init != opt);
BOOST_TEST(init == toml::get_or(v, opt));
}
{
const typename value_type::table_type init{{"key1", 42}, {"key2", "foo"}};
const typename value_type::table_type opt {{"key1", 54}, {"key2", "bar"}};
const value_type v(init);
BOOST_TEST(init != opt);
BOOST_TEST(init == toml::get_or(v, opt));
}
}
#undef TOML11_TEST_GET_OR_EXACT
#define TOML11_TEST_GET_OR_MOVE_EXACT(toml_type, init_expr, opt_expr)\
{ \
using namespace test; \
const toml::toml_type init init_expr ; \
toml::toml_type opt opt_expr ; \
value_type v(init); \
BOOST_TEST(init != opt); \
const auto opt_ = toml::get_or(std::move(v), std::move(opt));\
BOOST_TEST(init == opt_); \
} \
/**/
BOOST_AUTO_TEST_CASE_TEMPLATE(test_get_or_move, value_type, test_value_types)
{
TOML11_TEST_GET_OR_MOVE_EXACT(boolean, ( true), (false))
TOML11_TEST_GET_OR_MOVE_EXACT(integer, ( 42), ( 54))
TOML11_TEST_GET_OR_MOVE_EXACT(floating, ( 3.14), ( 2.71))
TOML11_TEST_GET_OR_MOVE_EXACT(string, ("foo"), ("bar"))
TOML11_TEST_GET_OR_MOVE_EXACT(local_time, (12, 30, 45), (6, 0, 30))
TOML11_TEST_GET_OR_MOVE_EXACT(local_date, (2019, toml::month_t::Apr, 1),
(1999, toml::month_t::Jan, 2))
TOML11_TEST_GET_OR_MOVE_EXACT(local_datetime,
(toml::local_date(2019, toml::month_t::Apr, 1), toml::local_time(12, 30, 45)),
(toml::local_date(1999, toml::month_t::Jan, 2), toml::local_time( 6, 0, 30))
)
TOML11_TEST_GET_OR_MOVE_EXACT(offset_datetime,
(toml::local_date(2019, toml::month_t::Apr, 1), toml::local_time(12, 30, 45), toml::time_offset( 9, 0)),
(toml::local_date(1999, toml::month_t::Jan, 2), toml::local_time( 6, 0, 30), toml::time_offset(-3, 0))
)
{
const typename value_type::array_type init{1,2,3,4,5};
typename value_type::array_type opt {6,7,8,9,10};
value_type v(init);
BOOST_TEST(init != opt);
const auto opt_ = toml::get_or(std::move(v), std::move(opt));
BOOST_TEST(init == opt_);
}
{
const typename value_type::table_type init{{"key1", 42}, {"key2", "foo"}};
typename value_type::table_type opt {{"key1", 54}, {"key2", "bar"}};
value_type v(init);
BOOST_TEST(init != opt);
const auto opt_ = toml::get_or(std::move(v), std::move(opt));
BOOST_TEST(init == opt_);
}
}
#undef TOML11_TEST_GET_OR_MOVE_EXACT
#define TOML11_TEST_GET_OR_MODIFY(toml_type, init_expr, opt_expr)\
{ \
using namespace test; \
const toml::toml_type init init_expr ; \
toml::toml_type opt1 opt_expr ; \
toml::toml_type opt2 opt_expr ; \
value_type v(init); \
BOOST_TEST(init != opt1); \
toml::get_or(v, opt2) = opt1; \
BOOST_TEST(opt1 == toml::get<toml::toml_type>(v)); \
} \
/**/
BOOST_AUTO_TEST_CASE_TEMPLATE(test_get_or_modify, value_type, test_value_types)
{
TOML11_TEST_GET_OR_MODIFY(boolean, ( true), (false))
TOML11_TEST_GET_OR_MODIFY(integer, ( 42), ( 54))
TOML11_TEST_GET_OR_MODIFY(floating, ( 3.14), ( 2.71))
TOML11_TEST_GET_OR_MODIFY(string, ("foo"), ("bar"))
TOML11_TEST_GET_OR_MODIFY(local_time, (12, 30, 45), (6, 0, 30))
TOML11_TEST_GET_OR_MODIFY(local_date, (2019, toml::month_t::Apr, 1),
(1999, toml::month_t::Jan, 2))
TOML11_TEST_GET_OR_MODIFY(local_datetime,
(toml::local_date(2019, toml::month_t::Apr, 1), toml::local_time(12, 30, 45)),
(toml::local_date(1999, toml::month_t::Jan, 2), toml::local_time( 6, 0, 30))
)
TOML11_TEST_GET_OR_MODIFY(offset_datetime,
(toml::local_date(2019, toml::month_t::Apr, 1), toml::local_time(12, 30, 45), toml::time_offset( 9, 0)),
(toml::local_date(1999, toml::month_t::Jan, 2), toml::local_time( 6, 0, 30), toml::time_offset(-3, 0))
)
{
typename value_type::array_type init{1,2,3,4,5};
typename value_type::array_type opt1{6,7,8,9,10};
typename value_type::array_type opt2{6,7,8,9,10};
BOOST_TEST(init != opt1);
value_type v(init);
toml::get_or(v, opt2) = opt1;
BOOST_TEST(opt1 == toml::get<typename value_type::array_type>(v));
}
{
typename value_type::table_type init{{"key1", 42}, {"key2", "foo"}};
typename value_type::table_type opt1{{"key1", 54}, {"key2", "bar"}};
typename value_type::table_type opt2{{"key1", 54}, {"key2", "bar"}};
value_type v(init);
BOOST_TEST(init != opt1);
toml::get_or(v, opt2) = opt1;
BOOST_TEST(opt1 == toml::get<typename value_type::table_type>(v));
}
}
#undef TOML11_TEST_GET_OR_MODIFY
#define TOML11_TEST_GET_OR_FALLBACK(init_type, opt_type) \
{ \
using namespace test; \
value_type v(init_type); \
BOOST_TEST(opt_type == toml::get_or(v, opt_type));\
} \
/**/
BOOST_AUTO_TEST_CASE_TEMPLATE(test_get_or_fallback, value_type, test_value_types)
{
const toml::boolean boolean (true);
const toml::integer integer (42);
const toml::floating floating (3.14);
const toml::string string ("foo");
const toml::local_time local_time (12, 30, 45);
const toml::local_date local_date (2019, toml::month_t::Apr, 1);
const toml::local_datetime local_datetime (
toml::local_date(2019, toml::month_t::Apr, 1),
toml::local_time(12, 30, 45));
const toml::offset_datetime offset_datetime(
toml::local_date(2019, toml::month_t::Apr, 1),
toml::local_time(12, 30, 45), toml::time_offset( 9, 0));
using array_type = typename value_type::array_type;
using table_type = typename value_type::table_type;
const array_type array{1, 2, 3, 4, 5};
const table_type table{{"key1", 42}, {"key2", "foo"}};
TOML11_TEST_GET_OR_FALLBACK(boolean, integer );
TOML11_TEST_GET_OR_FALLBACK(boolean, floating );
TOML11_TEST_GET_OR_FALLBACK(boolean, string );
TOML11_TEST_GET_OR_FALLBACK(boolean, local_time );
TOML11_TEST_GET_OR_FALLBACK(boolean, local_date );
TOML11_TEST_GET_OR_FALLBACK(boolean, local_datetime );
TOML11_TEST_GET_OR_FALLBACK(boolean, offset_datetime);
TOML11_TEST_GET_OR_FALLBACK(boolean, array );
TOML11_TEST_GET_OR_FALLBACK(boolean, table );
TOML11_TEST_GET_OR_FALLBACK(integer, boolean );
TOML11_TEST_GET_OR_FALLBACK(integer, floating );
TOML11_TEST_GET_OR_FALLBACK(integer, string );
TOML11_TEST_GET_OR_FALLBACK(integer, local_time );
TOML11_TEST_GET_OR_FALLBACK(integer, local_date );
TOML11_TEST_GET_OR_FALLBACK(integer, local_datetime );
TOML11_TEST_GET_OR_FALLBACK(integer, offset_datetime);
TOML11_TEST_GET_OR_FALLBACK(integer, array );
TOML11_TEST_GET_OR_FALLBACK(integer, table );
TOML11_TEST_GET_OR_FALLBACK(floating, boolean );
TOML11_TEST_GET_OR_FALLBACK(floating, integer );
TOML11_TEST_GET_OR_FALLBACK(floating, string );
TOML11_TEST_GET_OR_FALLBACK(floating, local_time );
TOML11_TEST_GET_OR_FALLBACK(floating, local_date );
TOML11_TEST_GET_OR_FALLBACK(floating, local_datetime );
TOML11_TEST_GET_OR_FALLBACK(floating, offset_datetime);
TOML11_TEST_GET_OR_FALLBACK(floating, array );
TOML11_TEST_GET_OR_FALLBACK(floating, table );
TOML11_TEST_GET_OR_FALLBACK(string, boolean );
TOML11_TEST_GET_OR_FALLBACK(string, integer );
TOML11_TEST_GET_OR_FALLBACK(string, floating );
TOML11_TEST_GET_OR_FALLBACK(string, local_time );
TOML11_TEST_GET_OR_FALLBACK(string, local_date );
TOML11_TEST_GET_OR_FALLBACK(string, local_datetime );
TOML11_TEST_GET_OR_FALLBACK(string, offset_datetime);
TOML11_TEST_GET_OR_FALLBACK(string, array );
TOML11_TEST_GET_OR_FALLBACK(string, table );
TOML11_TEST_GET_OR_FALLBACK(local_time, boolean );
TOML11_TEST_GET_OR_FALLBACK(local_time, integer );
TOML11_TEST_GET_OR_FALLBACK(local_time, floating );
TOML11_TEST_GET_OR_FALLBACK(local_time, string );
TOML11_TEST_GET_OR_FALLBACK(local_time, local_date );
TOML11_TEST_GET_OR_FALLBACK(local_time, local_datetime );
TOML11_TEST_GET_OR_FALLBACK(local_time, offset_datetime);
TOML11_TEST_GET_OR_FALLBACK(local_time, array );
TOML11_TEST_GET_OR_FALLBACK(local_time, table );
TOML11_TEST_GET_OR_FALLBACK(local_date, boolean );
TOML11_TEST_GET_OR_FALLBACK(local_date, integer );
TOML11_TEST_GET_OR_FALLBACK(local_date, floating );
TOML11_TEST_GET_OR_FALLBACK(local_date, string );
TOML11_TEST_GET_OR_FALLBACK(local_date, local_time );
TOML11_TEST_GET_OR_FALLBACK(local_date, local_datetime );
TOML11_TEST_GET_OR_FALLBACK(local_date, offset_datetime);
TOML11_TEST_GET_OR_FALLBACK(local_date, array );
TOML11_TEST_GET_OR_FALLBACK(local_date, table );
TOML11_TEST_GET_OR_FALLBACK(local_datetime, boolean );
TOML11_TEST_GET_OR_FALLBACK(local_datetime, integer );
TOML11_TEST_GET_OR_FALLBACK(local_datetime, floating );
TOML11_TEST_GET_OR_FALLBACK(local_datetime, string );
TOML11_TEST_GET_OR_FALLBACK(local_datetime, local_time );
TOML11_TEST_GET_OR_FALLBACK(local_datetime, local_date );
TOML11_TEST_GET_OR_FALLBACK(local_datetime, offset_datetime);
TOML11_TEST_GET_OR_FALLBACK(local_datetime, array );
TOML11_TEST_GET_OR_FALLBACK(local_datetime, table );
TOML11_TEST_GET_OR_FALLBACK(offset_datetime, boolean );
TOML11_TEST_GET_OR_FALLBACK(offset_datetime, integer );
TOML11_TEST_GET_OR_FALLBACK(offset_datetime, floating );
TOML11_TEST_GET_OR_FALLBACK(offset_datetime, string );
TOML11_TEST_GET_OR_FALLBACK(offset_datetime, local_time );
TOML11_TEST_GET_OR_FALLBACK(offset_datetime, local_date );
TOML11_TEST_GET_OR_FALLBACK(offset_datetime, local_datetime );
TOML11_TEST_GET_OR_FALLBACK(offset_datetime, array );
TOML11_TEST_GET_OR_FALLBACK(offset_datetime, table );
TOML11_TEST_GET_OR_FALLBACK(array, boolean );
TOML11_TEST_GET_OR_FALLBACK(array, integer );
TOML11_TEST_GET_OR_FALLBACK(array, floating );
TOML11_TEST_GET_OR_FALLBACK(array, string );
TOML11_TEST_GET_OR_FALLBACK(array, local_time );
TOML11_TEST_GET_OR_FALLBACK(array, local_date );
TOML11_TEST_GET_OR_FALLBACK(array, local_datetime );
TOML11_TEST_GET_OR_FALLBACK(array, offset_datetime);
TOML11_TEST_GET_OR_FALLBACK(array, table );
TOML11_TEST_GET_OR_FALLBACK(table, boolean );
TOML11_TEST_GET_OR_FALLBACK(table, integer );
TOML11_TEST_GET_OR_FALLBACK(table, floating );
TOML11_TEST_GET_OR_FALLBACK(table, string );
TOML11_TEST_GET_OR_FALLBACK(table, local_time );
TOML11_TEST_GET_OR_FALLBACK(table, local_date );
TOML11_TEST_GET_OR_FALLBACK(table, local_datetime );
TOML11_TEST_GET_OR_FALLBACK(table, offset_datetime);
TOML11_TEST_GET_OR_FALLBACK(table, array );
}
#undef TOML11_TEST_GET_OR_FALLBACK
BOOST_AUTO_TEST_CASE(test_get_or_integer)
{
{
toml::value v1(42);
toml::value v2(3.14);
BOOST_TEST(42u == toml::get_or(v1, 0u));
BOOST_TEST(0u == toml::get_or(v2, 0u));
}
{
toml::value v1(42);
toml::value v2(3.14);
BOOST_TEST(42u == toml::get_or(std::move(v1), 0u));
BOOST_TEST(0u == toml::get_or(std::move(v2), 0u));
}
}
BOOST_AUTO_TEST_CASE(test_get_or_floating)
{
{
toml::value v1(42);
toml::value v2(3.14);
BOOST_TEST(2.71f == toml::get_or(v1, 2.71f));
BOOST_TEST(static_cast<float>(v2.as_floating()) == toml::get_or(v2, 2.71f));
}
{
toml::value v1(42);
toml::value v2(3.14);
BOOST_TEST(2.71f == toml::get_or(std::move(v1), 2.71f));
BOOST_TEST(static_cast<float>(3.14) == toml::get_or(std::move(v2), 2.71f));
}
}
BOOST_AUTO_TEST_CASE(test_get_or_string)
{
{
toml::value v1("foobar");
toml::value v2(42);
std::string s1("bazqux");
const std::string s2("bazqux");
BOOST_TEST("foobar" == toml::get_or(v1, s1));
BOOST_TEST("bazqux" == toml::get_or(v2, s1));
std::string& v1r = toml::get_or(v1, s1);
std::string& s1r = toml::get_or(v2, s1);
BOOST_TEST("foobar" == v1r);
BOOST_TEST("bazqux" == s1r);
BOOST_TEST("foobar" == toml::get_or(v1, s2));
BOOST_TEST("bazqux" == toml::get_or(v2, s2));
BOOST_TEST("foobar" == toml::get_or(v1, std::move(s1)));
BOOST_TEST("bazqux" == toml::get_or(v2, std::move(s1)));
}
{
toml::value v1("foobar");
toml::value v2(42);
std::string s1("bazqux");
const std::string s2("bazqux");
BOOST_TEST("foobar" == toml::get_or(std::move(v1), s1));
BOOST_TEST("bazqux" == toml::get_or(std::move(v2), s1));
}
{
toml::value v1("foobar");
toml::value v2(42);
BOOST_TEST("foobar" == toml::get_or(v1, "bazqux"));
BOOST_TEST("bazqux" == toml::get_or(v2, "bazqux"));
const char* lit = "bazqux";
BOOST_TEST("foobar" == toml::get_or(v1, lit));
BOOST_TEST("bazqux" == toml::get_or(v2, lit));
}
{
toml::value v1("foobar");
toml::value v2(42);
BOOST_TEST("foobar" == toml::get_or(std::move(v1), "bazqux"));
BOOST_TEST("bazqux" == toml::get_or(std::move(v2), "bazqux"));
}
{
toml::value v1("foobar");
toml::value v2(42);
const char* lit = "bazqux";
BOOST_TEST("foobar" == toml::get_or(v1, lit));
BOOST_TEST("bazqux" == toml::get_or(v2, lit));
}
}
|
title bubbleSortingDSC
include irvine32.inc
.data
tab db 12,9,4,5,7,3,1,8
count EQU ($-tab)
dab db count dup(?)
.code
main proc
mov cx,count
mov si,0
put1:
movsx eax,tab[si]
call writeint
mov al,32
call writechar
inc si
loop put1
mov al,10
call writechar
mov cx,count
mov si,0
s:
mov bl,tab[si]
mov dab[si],bl
inc si
loop s
mov cx,count
dec cx
lop1:
mov di,cx
mov si,0
lop2:
mov al,dab[si]
cmp al,dab[si+1]
jg go_on
xchg al,dab[si+1]
mov dab[si],al
go_on:
add si,1
loop lop2
mov cx,di
loop lop1
mov cx,count
mov si,0
put2:
movsx eax,dab[si]
call writeint
mov al,32
call writechar
inc si
loop put2
exit
main endp
end main
|
title "Injection Thunk Assembly Routine"
;++
;
; Copyright (c) 2017 Trent Nelson <trent@trent.me>
;
; Module Name:
;
; InjectionThunk4.asm
;
; Abstract:
;
; This module implements the injection thunk routine as a NESTED_ENTRY.
;
;--
include ksamd64.inc
;
; Define a home parameter + return address structure. Before alloc_stack in
; the prologue, this struct is used against rsp. After rsp, we use rbp.
;
Home struct
ReturnAddress dq ? ; 8 32 40 (28h)
union
Thunk dq ? ; 8 24 32 (20h)
SavedRcx dq ? ; 8 24 32 (20h)
Param1 dq ? ; 8 24 32 (20h)
ends
union
SavedR12 dq ? ; 8 16 24 (18h)
Param2 dq ? ; 8 16 24 (18h)
ends
union
SavedRbp dq ? ; 8 8 16 (10h)
SavedR8 dq ? ; 8 8 16 (10h)
Param3 dq ? ; 8 8 16 (10h)
ends
union
SavedR9 dq ? ; 8 0 8 (08h)
Param4 dq ? ; 8 0 8 (08h)
ends
Home ends
;
; Define flags for RTL_INJECTION_THUNK_CONTEXT.Flags.
;
AddRuntimeFunction equ 1
TestExceptionHandler equ 2
TestAccessViolation equ 4
TestIllegalInstruction equ 8
;
; Define the RTL_INJECTION_THUNK_CONTEXT structure.
;
Thunk struct
Flags dd ?
EntryCount dd ?
FunctionTable dq ?
BaseAddress dq ?
RtlAddFunctionTable dq ?
ContextAddress dq ?
BasePointer dq ?
StackPointer dq ?
ReturnAddress dq ?
ExitThread dq ?
LoadLibraryW dq ?
GetProcAddress dq ?
ModulePath dq ?
ModuleHandle dq ?
FunctionName dq ?
FunctionAddress dq ?
Thunk ends
;
; Define error codes.
;
RtlAddFunctionTableFailed equ -1
LoadLibraryWFailed equ -2
GetProcAddressFailed equ -3
;
; Forward declarations of Fault/Resume addresses in InjectionThunk body.
;
altentry InjectionThunkAVFault
altentry InjectionThunkAVResume
altentry InjectionThunkIllInstFault
altentry InjectionThunkIllInstResume
;++
;
; LONG
; InjectionThunk4ExceptionHandler(
; _In_ PEXCEPTION_RECORD ExceptionRecord,
; _In_ PVOID EstablisherFrame,
; _Inout_ PCONTEXT ContextRecord,
; _Inout_ DispatcherContext
; )
;
; Routine Description:
;
; This is the exception handler for our injection thunk routine. Its purpose
; is to trap the access violation that the thunk can be directed to trigger
; and ignore it, returning execution back to the thunk. This isn't used in
; practice -- it's simply a test that we grok how to write exception handlers
; in assembly, and that they can be effectively relocated as part of dynamic
; injection.
;
; Arguments:
;
; ExceptionRecord (rcx) - Supplies a pointer to an exception record.
;
; EstablisherFrame (rdx) - Supplies the frame pointer of the establisher
; of this exception handler.
;
; ContextRecord (r8) - Supplies a pointer to a context record.
;
; DispatcherContext (r9) - Supplies a pointer to the dispatcher context
; record.
;
; Return Value:
;
; If we correctly detect that the exception was triggered by our expected
; access violation, we adjust the RIP and return ExceptionContinueExecution.
; Return ExceptionContinueSearch in all other cases.
;
;--
LEAF_ENTRY InjectionThunkHandler, _TEXT$00
;
; If this is an unwind, return ExceptionContinueSearch.
;
test dword ptr ErExceptionFlags[rcx], EXCEPTION_UNWIND
jnz short Injh90 ; This is an unwind, return.
;
; Check to see if this is an access violation exception. If it isn't, it won't
; (or shouldn't) have come from our injection thunk routine.
;
xor rax, rax
mov eax, dword ptr ErExceptionCode[rcx] ; Load exception code.
cmp eax, STATUS_ACCESS_VIOLATION ; Was this an AV?
jne short Injh90 ; Wasn't an AV, return.
;
; Load the known fault address into rax and compare against the actual fault
; IP of the triggering exception.
;
lea rax, InjectionThunkAVFault ; Load RIP of known fault.
cmp rax, CxRip[r8] ; Compare to actual RIP.
jne short Injh90 ; Doesn't match, return.
;
; The exception occurred on our fault address. Update the RIP in the context
; to skip past the faulting exception, then return ExceptionContinueExecution.
;
lea rax, InjectionThunkAVResume ; Load resume address.
mov CxRip[r8], rax ; Save into RIP.
mov eax, ExceptionContinueExecution ; Load return code.
ret
Injh90: mov eax, ExceptionContinueSearch
ret
LEAF_END InjectionThunkHandler, _TEXT$00
;++
;
; LONG
; InjectionThunk4(
; _In_ PRTL_INJECTION_THUNK_CONTEXT Thunk
; );
;
; Routine Description:
;
; This routine is the initial entry point of our injection logic. That is,
; newly created remoted threads in a target process have their start address
; set to a copy of this routine (that was prepared in a separate process and
; then injected via WriteProcessMemory()).
;
; It is responsible for registering a runtime function for itself, such that
; appropriate unwind data can be found by the kernel if an exception occurs
; and the stack is being unwound. It then loads a library designated by the
; fully qualified path in the thunk's module path field via LoadLibraryW,
; then calls GetProcAddress on the returned module for the function name also
; contained within the thunk. If an address is successfully resolved, the
; routine is called with the thunk back as the first parameter, and the return
; value is propagated back to our caller (typically, this will be the routine
; kernel32!UserBaseInitThunk).
;
; In practice, the module path we attempt to load is InjectionThunk.dll, and
; the function name we resolve is "InjectionRemoteThreadEntry". This routine
; is responsible for doing more heavy lifting in C prior to calling the actual
; caller's end routine.
;
; Arguments:
;
; Thunk (rcx) - Supplies a pointer to the injection context thunk.
;
; Return Value:
;
; If an error occured in this routine, an error code (see above) will be
; returned (ranging in value from -1 to -3). If this routine succeeded,
; the return value of the function we were requested to execute will be
; returned instead. (Unfortunately, there's no guarantee that this won't
; overlap with our error codes.)
;
; This return value will end up as the exit code for the thread if being
; called in the injection context.
;
;--
NESTED_ENTRY InjectionThunk4, _TEXT$00, InjectionThunkHandler
;
; This routine uses the non-volatile r12 to store the Thunk pointer (initially
; passed in via rcx). As we only have one parameter, we use the home parameter
; space reserved for rdx for saving r12 (instead of pushing it to the stack).
;
save_reg r12, Home.SavedR12 ; Use rdx home to save r12.
;
; We use rbp as our frame pointer. As with r12, we repurpose r8's home area
; instead of pushing to the stack, then call set_frame (which sets rsp to rbp).
;
save_reg rbp, Home.SavedRbp ; Use r8 home to save rbp.
set_frame rbp, 0 ; Use rbp as frame pointer.
;
; As we are calling other functions, we need to reserve 32 bytes for their
; parameter home space.
;
alloc_stack 20h ; Reserve home param space.
END_PROLOGUE
;
; Home our Thunk parameter register, then save in r12. The homing of rcx isn't
; technically necessary (as we never re-load it from rcx), but it doesn't hurt,
; and it is useful during development and debugging to help detect anomalies
; (if we clobber r12 accidentally, for example).
;
mov Home.Thunk[rbp], rcx ; Home Thunk (rcx) parameter.
mov r12, rcx ; Move Thunk into r12.
;
; Determine if we need to register a runtime function entry for this thunk.
;
mov r8d, Thunk.Flags[r12] ; Load flags into r8d.
test r8d, AddRuntimeFunction ; Is flag set?
jz short Inj10 ; No, jump to EH check.
;
; Register a runtime function for this currently executing piece of code. This
; is done when we've been copied into memory at runtime.
;
mov rcx, Thunk.FunctionTable[r12] ; Load FunctionTable.
xor rdx, rdx ; Clear rdx.
xor r9, r9 ; Clear r9.
mov edx, dword ptr Thunk.EntryCount[r12] ; Load EntryCount.
mov r8, Thunk.BaseAddress[r12] ; Load BaseAddress.
mov rax, Thunk.RtlAddFunctionTable[r12] ; Load Function.
call rax ; Invoke function.
test rax, rax ; Check result.
jz short @F ; Function failed.
jmp short Inj10 ; Function succeeded.
@@: mov rax, RtlAddFunctionTableFailed ; Load error code.
jmp Inj90 ; Jump to epilogue.
;
; Determine if an access violation test has been requested. Note that this is
; only ever performed after a runtime function table has been added. It is used
; solely for testing our exception handling logic.
;
Inj10: mov r8d, Thunk.Flags[r12] ; Load flags into r8d.
test r8d, TestExceptionHandler ; Is flag set?
jnz Inj15 ; Yes, jump to test.
jmp Inj20 ; No, jump to main.
Inj15: test r8d, TestAccessViolation ; Is AV test?
jnz Inj18 ; Yes, jump to test.
test r8d, TestIllegalInstruction ; Is IL test?
jnz Inj17 ; Yes, jump to test.
int 3 ; Invariant failed: no flags set
jmp short Inj90
Inj17: nop
ALTERNATE_ENTRY InjectionThunkIllInstFault
db 0fh ; Trigger illegal inst fault.
db 0bh
ALTERNATE_ENTRY InjectionThunkIllInstResume
jmp Inj20 ; Jump to main.
align 16
Inj18: xor rax, rax ; Zero rax.
ALTERNATE_ENTRY InjectionThunkAVFault
mov [rax], rax ; Force trap.
ALTERNATE_ENTRY InjectionThunkAVResume
;
; Prepare for a LoadLibraryW() call against the module path in the thunk.
;
Inj20: mov rcx, Thunk.ModulePath[r12] ; Load ModulePath.
call Thunk.LoadLibraryW[r12] ; Call LoadLibraryW().
test rax, rax ; Check Handle != NULL.
jz short @F ; Handle is NULL.
jmp short Inj40 ; Handle is valid.
@@: mov rax, LoadLibraryWFailed ; Load error code.
jmp short Inj90 ; Jump to epilogue.
;
; Module was loaded successfully. The Handle value lives in rax. Save a copy
; in the thunk, then prepare arguments for a call to GetProcAddress().
;
Inj40: mov Thunk.ModuleHandle[r12], rax ; Save Handle.
mov rcx, rax ; Load as 1st param.
mov rdx, Thunk.FunctionName[r12] ; Load name as 2nd.
call Thunk.GetProcAddress[r12] ; Call GetProcAddress.
test rax, rax ; Check return value.
jz short @F ; Lookup failed.
jmp short Inj60 ; Lookup succeeded.
@@: mov rax, GetProcAddressFailed ; Load error code.
jmp short Inj90 ; Jump to return.
;
; The function name was resolved successfully. The function address lives in
; rax. Save a copy in the thunk, and then prepare arguments for a call to it.
;
Inj60: mov Thunk.FunctionAddress[r12], rax ; Save func ptr.
mov rcx, r12 ; Load thunk into rcx.
call rax ; Call the function.
;
; Intentional follow-on to Inj90 to exit the function; rax will be returned back
; to the caller.
;
Inj90:
;
; Begin epilogue. Restore r12 and rbp from home parameter space and return
; rsp to its original value.
;
mov r12, Home.SavedR12[rbp] ; Restore non-vol r12.
mov rbp, Home.SavedRbp[rbp] ; Restore non-vol rbp.
add rsp, 20h ; Restore home space.
ret
NESTED_END InjectionThunk4, _TEXT$00
; vim:set tw=80 ts=8 sw=4 sts=4 et syntax=masm fo=croql comments=:; :
end
|
_usertests: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
return randstate;
}
int
main(int argc, char *argv[])
{
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 51 push %ecx
e: 83 ec 0c sub $0xc,%esp
printf(1, "usertests starting\n");
11: 68 46 4d 00 00 push $0x4d46
16: 6a 01 push $0x1
18: e8 e3 39 00 00 call 3a00 <printf>
if(open("usertests.ran", 0) >= 0){
1d: 59 pop %ecx
1e: 58 pop %eax
1f: 6a 00 push $0x0
21: 68 5a 4d 00 00 push $0x4d5a
26: e8 b7 38 00 00 call 38e2 <open>
2b: 83 c4 10 add $0x10,%esp
2e: 85 c0 test %eax,%eax
30: 78 13 js 45 <main+0x45>
printf(1, "already ran user tests -- rebuild fs.img\n");
32: 52 push %edx
33: 52 push %edx
34: 68 c4 54 00 00 push $0x54c4
39: 6a 01 push $0x1
3b: e8 c0 39 00 00 call 3a00 <printf>
exit();
40: e8 5d 38 00 00 call 38a2 <exit>
}
close(open("usertests.ran", O_CREATE));
45: 50 push %eax
46: 50 push %eax
47: 68 00 02 00 00 push $0x200
4c: 68 5a 4d 00 00 push $0x4d5a
51: e8 8c 38 00 00 call 38e2 <open>
56: 89 04 24 mov %eax,(%esp)
59: e8 6c 38 00 00 call 38ca <close>
argptest();
5e: e8 5d 35 00 00 call 35c0 <argptest>
createdelete();
63: e8 a8 11 00 00 call 1210 <createdelete>
linkunlink();
68: e8 63 1a 00 00 call 1ad0 <linkunlink>
concreate();
6d: e8 5e 17 00 00 call 17d0 <concreate>
fourfiles();
72: e8 99 0f 00 00 call 1010 <fourfiles>
sharedfd();
77: e8 d4 0d 00 00 call e50 <sharedfd>
bigargtest();
7c: e8 ff 31 00 00 call 3280 <bigargtest>
bigwrite();
81: e8 6a 23 00 00 call 23f0 <bigwrite>
bigargtest();
86: e8 f5 31 00 00 call 3280 <bigargtest>
bsstest();
8b: e8 70 31 00 00 call 3200 <bsstest>
sbrktest();
90: e8 9b 2c 00 00 call 2d30 <sbrktest>
validatetest();
95: e8 b6 30 00 00 call 3150 <validatetest>
opentest();
9a: e8 51 03 00 00 call 3f0 <opentest>
writetest();
9f: e8 dc 03 00 00 call 480 <writetest>
writetest1();
a4: e8 b7 05 00 00 call 660 <writetest1>
createtest();
a9: e8 82 07 00 00 call 830 <createtest>
openiputtest();
ae: e8 3d 02 00 00 call 2f0 <openiputtest>
exitiputtest();
b3: e8 48 01 00 00 call 200 <exitiputtest>
iputtest();
b8: e8 63 00 00 00 call 120 <iputtest>
mem();
bd: e8 be 0c 00 00 call d80 <mem>
pipe1();
c2: e8 49 09 00 00 call a10 <pipe1>
preempt();
c7: e8 e4 0a 00 00 call bb0 <preempt>
exitwait();
cc: e8 1f 0c 00 00 call cf0 <exitwait>
rmdot();
d1: e8 0a 27 00 00 call 27e0 <rmdot>
fourteen();
d6: e8 c5 25 00 00 call 26a0 <fourteen>
bigfile();
db: e8 f0 23 00 00 call 24d0 <bigfile>
subdir();
e0: e8 2b 1c 00 00 call 1d10 <subdir>
linktest();
e5: e8 d6 14 00 00 call 15c0 <linktest>
unlinkread();
ea: e8 41 13 00 00 call 1430 <unlinkread>
dirfile();
ef: e8 6c 28 00 00 call 2960 <dirfile>
iref();
f4: e8 67 2a 00 00 call 2b60 <iref>
forktest();
f9: e8 82 2b 00 00 call 2c80 <forktest>
bigdir(); // slow
fe: e8 dd 1a 00 00 call 1be0 <bigdir>
uio();
103: e8 48 34 00 00 call 3550 <uio>
exectest();
108: e8 b3 08 00 00 call 9c0 <exectest>
exit();
10d: e8 90 37 00 00 call 38a2 <exit>
112: 66 90 xchg %ax,%ax
114: 66 90 xchg %ax,%ax
116: 66 90 xchg %ax,%ax
118: 66 90 xchg %ax,%ax
11a: 66 90 xchg %ax,%ax
11c: 66 90 xchg %ax,%ax
11e: 66 90 xchg %ax,%ax
00000120 <iputtest>:
{
120: 55 push %ebp
121: 89 e5 mov %esp,%ebp
123: 83 ec 10 sub $0x10,%esp
printf(stdout, "iput test\n");
126: 68 ec 3d 00 00 push $0x3dec
12b: ff 35 08 5e 00 00 pushl 0x5e08
131: e8 ca 38 00 00 call 3a00 <printf>
if(mkdir("iputdir") < 0){
136: c7 04 24 7f 3d 00 00 movl $0x3d7f,(%esp)
13d: e8 c8 37 00 00 call 390a <mkdir>
142: 83 c4 10 add $0x10,%esp
145: 85 c0 test %eax,%eax
147: 78 58 js 1a1 <iputtest+0x81>
if(chdir("iputdir") < 0){
149: 83 ec 0c sub $0xc,%esp
14c: 68 7f 3d 00 00 push $0x3d7f
151: e8 bc 37 00 00 call 3912 <chdir>
156: 83 c4 10 add $0x10,%esp
159: 85 c0 test %eax,%eax
15b: 0f 88 85 00 00 00 js 1e6 <iputtest+0xc6>
if(unlink("../iputdir") < 0){
161: 83 ec 0c sub $0xc,%esp
164: 68 7c 3d 00 00 push $0x3d7c
169: e8 84 37 00 00 call 38f2 <unlink>
16e: 83 c4 10 add $0x10,%esp
171: 85 c0 test %eax,%eax
173: 78 5a js 1cf <iputtest+0xaf>
if(chdir("/") < 0){
175: 83 ec 0c sub $0xc,%esp
178: 68 a1 3d 00 00 push $0x3da1
17d: e8 90 37 00 00 call 3912 <chdir>
182: 83 c4 10 add $0x10,%esp
185: 85 c0 test %eax,%eax
187: 78 2f js 1b8 <iputtest+0x98>
printf(stdout, "iput test ok\n");
189: 83 ec 08 sub $0x8,%esp
18c: 68 24 3e 00 00 push $0x3e24
191: ff 35 08 5e 00 00 pushl 0x5e08
197: e8 64 38 00 00 call 3a00 <printf>
}
19c: 83 c4 10 add $0x10,%esp
19f: c9 leave
1a0: c3 ret
printf(stdout, "mkdir failed\n");
1a1: 50 push %eax
1a2: 50 push %eax
1a3: 68 58 3d 00 00 push $0x3d58
1a8: ff 35 08 5e 00 00 pushl 0x5e08
1ae: e8 4d 38 00 00 call 3a00 <printf>
exit();
1b3: e8 ea 36 00 00 call 38a2 <exit>
printf(stdout, "chdir / failed\n");
1b8: 50 push %eax
1b9: 50 push %eax
1ba: 68 a3 3d 00 00 push $0x3da3
1bf: ff 35 08 5e 00 00 pushl 0x5e08
1c5: e8 36 38 00 00 call 3a00 <printf>
exit();
1ca: e8 d3 36 00 00 call 38a2 <exit>
printf(stdout, "unlink ../iputdir failed\n");
1cf: 52 push %edx
1d0: 52 push %edx
1d1: 68 87 3d 00 00 push $0x3d87
1d6: ff 35 08 5e 00 00 pushl 0x5e08
1dc: e8 1f 38 00 00 call 3a00 <printf>
exit();
1e1: e8 bc 36 00 00 call 38a2 <exit>
printf(stdout, "chdir iputdir failed\n");
1e6: 51 push %ecx
1e7: 51 push %ecx
1e8: 68 66 3d 00 00 push $0x3d66
1ed: ff 35 08 5e 00 00 pushl 0x5e08
1f3: e8 08 38 00 00 call 3a00 <printf>
exit();
1f8: e8 a5 36 00 00 call 38a2 <exit>
1fd: 8d 76 00 lea 0x0(%esi),%esi
00000200 <exitiputtest>:
{
200: 55 push %ebp
201: 89 e5 mov %esp,%ebp
203: 83 ec 10 sub $0x10,%esp
printf(stdout, "exitiput test\n");
206: 68 b3 3d 00 00 push $0x3db3
20b: ff 35 08 5e 00 00 pushl 0x5e08
211: e8 ea 37 00 00 call 3a00 <printf>
pid = fork();
216: e8 7f 36 00 00 call 389a <fork>
if(pid < 0){
21b: 83 c4 10 add $0x10,%esp
21e: 85 c0 test %eax,%eax
220: 0f 88 82 00 00 00 js 2a8 <exitiputtest+0xa8>
if(pid == 0){
226: 75 48 jne 270 <exitiputtest+0x70>
if(mkdir("iputdir") < 0){
228: 83 ec 0c sub $0xc,%esp
22b: 68 7f 3d 00 00 push $0x3d7f
230: e8 d5 36 00 00 call 390a <mkdir>
235: 83 c4 10 add $0x10,%esp
238: 85 c0 test %eax,%eax
23a: 0f 88 96 00 00 00 js 2d6 <exitiputtest+0xd6>
if(chdir("iputdir") < 0){
240: 83 ec 0c sub $0xc,%esp
243: 68 7f 3d 00 00 push $0x3d7f
248: e8 c5 36 00 00 call 3912 <chdir>
24d: 83 c4 10 add $0x10,%esp
250: 85 c0 test %eax,%eax
252: 78 6b js 2bf <exitiputtest+0xbf>
if(unlink("../iputdir") < 0){
254: 83 ec 0c sub $0xc,%esp
257: 68 7c 3d 00 00 push $0x3d7c
25c: e8 91 36 00 00 call 38f2 <unlink>
261: 83 c4 10 add $0x10,%esp
264: 85 c0 test %eax,%eax
266: 78 28 js 290 <exitiputtest+0x90>
exit();
268: e8 35 36 00 00 call 38a2 <exit>
26d: 8d 76 00 lea 0x0(%esi),%esi
wait();
270: e8 35 36 00 00 call 38aa <wait>
printf(stdout, "exitiput test ok\n");
275: 83 ec 08 sub $0x8,%esp
278: 68 d6 3d 00 00 push $0x3dd6
27d: ff 35 08 5e 00 00 pushl 0x5e08
283: e8 78 37 00 00 call 3a00 <printf>
}
288: 83 c4 10 add $0x10,%esp
28b: c9 leave
28c: c3 ret
28d: 8d 76 00 lea 0x0(%esi),%esi
printf(stdout, "unlink ../iputdir failed\n");
290: 83 ec 08 sub $0x8,%esp
293: 68 87 3d 00 00 push $0x3d87
298: ff 35 08 5e 00 00 pushl 0x5e08
29e: e8 5d 37 00 00 call 3a00 <printf>
exit();
2a3: e8 fa 35 00 00 call 38a2 <exit>
printf(stdout, "fork failed\n");
2a8: 51 push %ecx
2a9: 51 push %ecx
2aa: 68 99 4c 00 00 push $0x4c99
2af: ff 35 08 5e 00 00 pushl 0x5e08
2b5: e8 46 37 00 00 call 3a00 <printf>
exit();
2ba: e8 e3 35 00 00 call 38a2 <exit>
printf(stdout, "child chdir failed\n");
2bf: 50 push %eax
2c0: 50 push %eax
2c1: 68 c2 3d 00 00 push $0x3dc2
2c6: ff 35 08 5e 00 00 pushl 0x5e08
2cc: e8 2f 37 00 00 call 3a00 <printf>
exit();
2d1: e8 cc 35 00 00 call 38a2 <exit>
printf(stdout, "mkdir failed\n");
2d6: 52 push %edx
2d7: 52 push %edx
2d8: 68 58 3d 00 00 push $0x3d58
2dd: ff 35 08 5e 00 00 pushl 0x5e08
2e3: e8 18 37 00 00 call 3a00 <printf>
exit();
2e8: e8 b5 35 00 00 call 38a2 <exit>
2ed: 8d 76 00 lea 0x0(%esi),%esi
000002f0 <openiputtest>:
{
2f0: 55 push %ebp
2f1: 89 e5 mov %esp,%ebp
2f3: 83 ec 10 sub $0x10,%esp
printf(stdout, "openiput test\n");
2f6: 68 e8 3d 00 00 push $0x3de8
2fb: ff 35 08 5e 00 00 pushl 0x5e08
301: e8 fa 36 00 00 call 3a00 <printf>
if(mkdir("oidir") < 0){
306: c7 04 24 f7 3d 00 00 movl $0x3df7,(%esp)
30d: e8 f8 35 00 00 call 390a <mkdir>
312: 83 c4 10 add $0x10,%esp
315: 85 c0 test %eax,%eax
317: 0f 88 88 00 00 00 js 3a5 <openiputtest+0xb5>
pid = fork();
31d: e8 78 35 00 00 call 389a <fork>
if(pid < 0){
322: 85 c0 test %eax,%eax
324: 0f 88 92 00 00 00 js 3bc <openiputtest+0xcc>
if(pid == 0){
32a: 75 34 jne 360 <openiputtest+0x70>
int fd = open("oidir", O_RDWR);
32c: 83 ec 08 sub $0x8,%esp
32f: 6a 02 push $0x2
331: 68 f7 3d 00 00 push $0x3df7
336: e8 a7 35 00 00 call 38e2 <open>
if(fd >= 0){
33b: 83 c4 10 add $0x10,%esp
33e: 85 c0 test %eax,%eax
340: 78 5e js 3a0 <openiputtest+0xb0>
printf(stdout, "open directory for write succeeded\n");
342: 83 ec 08 sub $0x8,%esp
345: 68 7c 4d 00 00 push $0x4d7c
34a: ff 35 08 5e 00 00 pushl 0x5e08
350: e8 ab 36 00 00 call 3a00 <printf>
exit();
355: e8 48 35 00 00 call 38a2 <exit>
35a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
sleep(1);
360: 83 ec 0c sub $0xc,%esp
363: 6a 01 push $0x1
365: e8 c8 35 00 00 call 3932 <sleep>
if(unlink("oidir") != 0){
36a: c7 04 24 f7 3d 00 00 movl $0x3df7,(%esp)
371: e8 7c 35 00 00 call 38f2 <unlink>
376: 83 c4 10 add $0x10,%esp
379: 85 c0 test %eax,%eax
37b: 75 56 jne 3d3 <openiputtest+0xe3>
wait();
37d: e8 28 35 00 00 call 38aa <wait>
printf(stdout, "openiput test ok\n");
382: 83 ec 08 sub $0x8,%esp
385: 68 20 3e 00 00 push $0x3e20
38a: ff 35 08 5e 00 00 pushl 0x5e08
390: e8 6b 36 00 00 call 3a00 <printf>
395: 83 c4 10 add $0x10,%esp
}
398: c9 leave
399: c3 ret
39a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
exit();
3a0: e8 fd 34 00 00 call 38a2 <exit>
printf(stdout, "mkdir oidir failed\n");
3a5: 51 push %ecx
3a6: 51 push %ecx
3a7: 68 fd 3d 00 00 push $0x3dfd
3ac: ff 35 08 5e 00 00 pushl 0x5e08
3b2: e8 49 36 00 00 call 3a00 <printf>
exit();
3b7: e8 e6 34 00 00 call 38a2 <exit>
printf(stdout, "fork failed\n");
3bc: 52 push %edx
3bd: 52 push %edx
3be: 68 99 4c 00 00 push $0x4c99
3c3: ff 35 08 5e 00 00 pushl 0x5e08
3c9: e8 32 36 00 00 call 3a00 <printf>
exit();
3ce: e8 cf 34 00 00 call 38a2 <exit>
printf(stdout, "unlink failed\n");
3d3: 50 push %eax
3d4: 50 push %eax
3d5: 68 11 3e 00 00 push $0x3e11
3da: ff 35 08 5e 00 00 pushl 0x5e08
3e0: e8 1b 36 00 00 call 3a00 <printf>
exit();
3e5: e8 b8 34 00 00 call 38a2 <exit>
3ea: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
000003f0 <opentest>:
{
3f0: 55 push %ebp
3f1: 89 e5 mov %esp,%ebp
3f3: 83 ec 10 sub $0x10,%esp
printf(stdout, "open test\n");
3f6: 68 32 3e 00 00 push $0x3e32
3fb: ff 35 08 5e 00 00 pushl 0x5e08
401: e8 fa 35 00 00 call 3a00 <printf>
fd = open("echo", 0);
406: 58 pop %eax
407: 5a pop %edx
408: 6a 00 push $0x0
40a: 68 3d 3e 00 00 push $0x3e3d
40f: e8 ce 34 00 00 call 38e2 <open>
if(fd < 0){
414: 83 c4 10 add $0x10,%esp
417: 85 c0 test %eax,%eax
419: 78 36 js 451 <opentest+0x61>
close(fd);
41b: 83 ec 0c sub $0xc,%esp
41e: 50 push %eax
41f: e8 a6 34 00 00 call 38ca <close>
fd = open("doesnotexist", 0);
424: 5a pop %edx
425: 59 pop %ecx
426: 6a 00 push $0x0
428: 68 55 3e 00 00 push $0x3e55
42d: e8 b0 34 00 00 call 38e2 <open>
if(fd >= 0){
432: 83 c4 10 add $0x10,%esp
435: 85 c0 test %eax,%eax
437: 79 2f jns 468 <opentest+0x78>
printf(stdout, "open test ok\n");
439: 83 ec 08 sub $0x8,%esp
43c: 68 80 3e 00 00 push $0x3e80
441: ff 35 08 5e 00 00 pushl 0x5e08
447: e8 b4 35 00 00 call 3a00 <printf>
}
44c: 83 c4 10 add $0x10,%esp
44f: c9 leave
450: c3 ret
printf(stdout, "open echo failed!\n");
451: 50 push %eax
452: 50 push %eax
453: 68 42 3e 00 00 push $0x3e42
458: ff 35 08 5e 00 00 pushl 0x5e08
45e: e8 9d 35 00 00 call 3a00 <printf>
exit();
463: e8 3a 34 00 00 call 38a2 <exit>
printf(stdout, "open doesnotexist succeeded!\n");
468: 50 push %eax
469: 50 push %eax
46a: 68 62 3e 00 00 push $0x3e62
46f: ff 35 08 5e 00 00 pushl 0x5e08
475: e8 86 35 00 00 call 3a00 <printf>
exit();
47a: e8 23 34 00 00 call 38a2 <exit>
47f: 90 nop
00000480 <writetest>:
{
480: 55 push %ebp
481: 89 e5 mov %esp,%ebp
483: 56 push %esi
484: 53 push %ebx
printf(stdout, "small file test\n");
485: 83 ec 08 sub $0x8,%esp
488: 68 8e 3e 00 00 push $0x3e8e
48d: ff 35 08 5e 00 00 pushl 0x5e08
493: e8 68 35 00 00 call 3a00 <printf>
fd = open("small", O_CREATE|O_RDWR);
498: 58 pop %eax
499: 5a pop %edx
49a: 68 02 02 00 00 push $0x202
49f: 68 9f 3e 00 00 push $0x3e9f
4a4: e8 39 34 00 00 call 38e2 <open>
if(fd >= 0){
4a9: 83 c4 10 add $0x10,%esp
4ac: 85 c0 test %eax,%eax
4ae: 0f 88 88 01 00 00 js 63c <writetest+0x1bc>
printf(stdout, "creat small succeeded; ok\n");
4b4: 83 ec 08 sub $0x8,%esp
4b7: 89 c6 mov %eax,%esi
for(i = 0; i < 100; i++){
4b9: 31 db xor %ebx,%ebx
printf(stdout, "creat small succeeded; ok\n");
4bb: 68 a5 3e 00 00 push $0x3ea5
4c0: ff 35 08 5e 00 00 pushl 0x5e08
4c6: e8 35 35 00 00 call 3a00 <printf>
4cb: 83 c4 10 add $0x10,%esp
4ce: 66 90 xchg %ax,%ax
if(write(fd, "aaaaaaaaaa", 10) != 10){
4d0: 83 ec 04 sub $0x4,%esp
4d3: 6a 0a push $0xa
4d5: 68 dc 3e 00 00 push $0x3edc
4da: 56 push %esi
4db: e8 e2 33 00 00 call 38c2 <write>
4e0: 83 c4 10 add $0x10,%esp
4e3: 83 f8 0a cmp $0xa,%eax
4e6: 0f 85 d9 00 00 00 jne 5c5 <writetest+0x145>
if(write(fd, "bbbbbbbbbb", 10) != 10){
4ec: 83 ec 04 sub $0x4,%esp
4ef: 6a 0a push $0xa
4f1: 68 e7 3e 00 00 push $0x3ee7
4f6: 56 push %esi
4f7: e8 c6 33 00 00 call 38c2 <write>
4fc: 83 c4 10 add $0x10,%esp
4ff: 83 f8 0a cmp $0xa,%eax
502: 0f 85 d6 00 00 00 jne 5de <writetest+0x15e>
for(i = 0; i < 100; i++){
508: 83 c3 01 add $0x1,%ebx
50b: 83 fb 64 cmp $0x64,%ebx
50e: 75 c0 jne 4d0 <writetest+0x50>
printf(stdout, "writes ok\n");
510: 83 ec 08 sub $0x8,%esp
513: 68 f2 3e 00 00 push $0x3ef2
518: ff 35 08 5e 00 00 pushl 0x5e08
51e: e8 dd 34 00 00 call 3a00 <printf>
close(fd);
523: 89 34 24 mov %esi,(%esp)
526: e8 9f 33 00 00 call 38ca <close>
fd = open("small", O_RDONLY);
52b: 5b pop %ebx
52c: 5e pop %esi
52d: 6a 00 push $0x0
52f: 68 9f 3e 00 00 push $0x3e9f
534: e8 a9 33 00 00 call 38e2 <open>
if(fd >= 0){
539: 83 c4 10 add $0x10,%esp
53c: 85 c0 test %eax,%eax
fd = open("small", O_RDONLY);
53e: 89 c3 mov %eax,%ebx
if(fd >= 0){
540: 0f 88 b1 00 00 00 js 5f7 <writetest+0x177>
printf(stdout, "open small succeeded ok\n");
546: 83 ec 08 sub $0x8,%esp
549: 68 fd 3e 00 00 push $0x3efd
54e: ff 35 08 5e 00 00 pushl 0x5e08
554: e8 a7 34 00 00 call 3a00 <printf>
i = read(fd, buf, 2000);
559: 83 c4 0c add $0xc,%esp
55c: 68 d0 07 00 00 push $0x7d0
561: 68 e0 85 00 00 push $0x85e0
566: 53 push %ebx
567: e8 4e 33 00 00 call 38ba <read>
if(i == 2000){
56c: 83 c4 10 add $0x10,%esp
56f: 3d d0 07 00 00 cmp $0x7d0,%eax
574: 0f 85 94 00 00 00 jne 60e <writetest+0x18e>
printf(stdout, "read succeeded ok\n");
57a: 83 ec 08 sub $0x8,%esp
57d: 68 31 3f 00 00 push $0x3f31
582: ff 35 08 5e 00 00 pushl 0x5e08
588: e8 73 34 00 00 call 3a00 <printf>
close(fd);
58d: 89 1c 24 mov %ebx,(%esp)
590: e8 35 33 00 00 call 38ca <close>
if(unlink("small") < 0){
595: c7 04 24 9f 3e 00 00 movl $0x3e9f,(%esp)
59c: e8 51 33 00 00 call 38f2 <unlink>
5a1: 83 c4 10 add $0x10,%esp
5a4: 85 c0 test %eax,%eax
5a6: 78 7d js 625 <writetest+0x1a5>
printf(stdout, "small file test ok\n");
5a8: 83 ec 08 sub $0x8,%esp
5ab: 68 59 3f 00 00 push $0x3f59
5b0: ff 35 08 5e 00 00 pushl 0x5e08
5b6: e8 45 34 00 00 call 3a00 <printf>
}
5bb: 83 c4 10 add $0x10,%esp
5be: 8d 65 f8 lea -0x8(%ebp),%esp
5c1: 5b pop %ebx
5c2: 5e pop %esi
5c3: 5d pop %ebp
5c4: c3 ret
printf(stdout, "error: write aa %d new file failed\n", i);
5c5: 83 ec 04 sub $0x4,%esp
5c8: 53 push %ebx
5c9: 68 a0 4d 00 00 push $0x4da0
5ce: ff 35 08 5e 00 00 pushl 0x5e08
5d4: e8 27 34 00 00 call 3a00 <printf>
exit();
5d9: e8 c4 32 00 00 call 38a2 <exit>
printf(stdout, "error: write bb %d new file failed\n", i);
5de: 83 ec 04 sub $0x4,%esp
5e1: 53 push %ebx
5e2: 68 c4 4d 00 00 push $0x4dc4
5e7: ff 35 08 5e 00 00 pushl 0x5e08
5ed: e8 0e 34 00 00 call 3a00 <printf>
exit();
5f2: e8 ab 32 00 00 call 38a2 <exit>
printf(stdout, "error: open small failed!\n");
5f7: 51 push %ecx
5f8: 51 push %ecx
5f9: 68 16 3f 00 00 push $0x3f16
5fe: ff 35 08 5e 00 00 pushl 0x5e08
604: e8 f7 33 00 00 call 3a00 <printf>
exit();
609: e8 94 32 00 00 call 38a2 <exit>
printf(stdout, "read failed\n");
60e: 52 push %edx
60f: 52 push %edx
610: 68 5d 42 00 00 push $0x425d
615: ff 35 08 5e 00 00 pushl 0x5e08
61b: e8 e0 33 00 00 call 3a00 <printf>
exit();
620: e8 7d 32 00 00 call 38a2 <exit>
printf(stdout, "unlink small failed\n");
625: 50 push %eax
626: 50 push %eax
627: 68 44 3f 00 00 push $0x3f44
62c: ff 35 08 5e 00 00 pushl 0x5e08
632: e8 c9 33 00 00 call 3a00 <printf>
exit();
637: e8 66 32 00 00 call 38a2 <exit>
printf(stdout, "error: creat small failed!\n");
63c: 50 push %eax
63d: 50 push %eax
63e: 68 c0 3e 00 00 push $0x3ec0
643: ff 35 08 5e 00 00 pushl 0x5e08
649: e8 b2 33 00 00 call 3a00 <printf>
exit();
64e: e8 4f 32 00 00 call 38a2 <exit>
653: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
659: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000660 <writetest1>:
{
660: 55 push %ebp
661: 89 e5 mov %esp,%ebp
663: 56 push %esi
664: 53 push %ebx
printf(stdout, "big files test\n");
665: 83 ec 08 sub $0x8,%esp
668: 68 6d 3f 00 00 push $0x3f6d
66d: ff 35 08 5e 00 00 pushl 0x5e08
673: e8 88 33 00 00 call 3a00 <printf>
fd = open("big", O_CREATE|O_RDWR);
678: 58 pop %eax
679: 5a pop %edx
67a: 68 02 02 00 00 push $0x202
67f: 68 e7 3f 00 00 push $0x3fe7
684: e8 59 32 00 00 call 38e2 <open>
if(fd < 0){
689: 83 c4 10 add $0x10,%esp
68c: 85 c0 test %eax,%eax
68e: 0f 88 61 01 00 00 js 7f5 <writetest1+0x195>
694: 89 c6 mov %eax,%esi
for(i = 0; i < MAXFILE; i++){
696: 31 db xor %ebx,%ebx
698: 90 nop
699: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
if(write(fd, buf, 512) != 512){
6a0: 83 ec 04 sub $0x4,%esp
((int*)buf)[0] = i;
6a3: 89 1d e0 85 00 00 mov %ebx,0x85e0
if(write(fd, buf, 512) != 512){
6a9: 68 00 02 00 00 push $0x200
6ae: 68 e0 85 00 00 push $0x85e0
6b3: 56 push %esi
6b4: e8 09 32 00 00 call 38c2 <write>
6b9: 83 c4 10 add $0x10,%esp
6bc: 3d 00 02 00 00 cmp $0x200,%eax
6c1: 0f 85 b3 00 00 00 jne 77a <writetest1+0x11a>
for(i = 0; i < MAXFILE; i++){
6c7: 83 c3 01 add $0x1,%ebx
6ca: 81 fb 8c 00 00 00 cmp $0x8c,%ebx
6d0: 75 ce jne 6a0 <writetest1+0x40>
close(fd);
6d2: 83 ec 0c sub $0xc,%esp
6d5: 56 push %esi
6d6: e8 ef 31 00 00 call 38ca <close>
fd = open("big", O_RDONLY);
6db: 5b pop %ebx
6dc: 5e pop %esi
6dd: 6a 00 push $0x0
6df: 68 e7 3f 00 00 push $0x3fe7
6e4: e8 f9 31 00 00 call 38e2 <open>
if(fd < 0){
6e9: 83 c4 10 add $0x10,%esp
6ec: 85 c0 test %eax,%eax
fd = open("big", O_RDONLY);
6ee: 89 c6 mov %eax,%esi
if(fd < 0){
6f0: 0f 88 e8 00 00 00 js 7de <writetest1+0x17e>
n = 0;
6f6: 31 db xor %ebx,%ebx
6f8: eb 1d jmp 717 <writetest1+0xb7>
6fa: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
} else if(i != 512){
700: 3d 00 02 00 00 cmp $0x200,%eax
705: 0f 85 9f 00 00 00 jne 7aa <writetest1+0x14a>
if(((int*)buf)[0] != n){
70b: a1 e0 85 00 00 mov 0x85e0,%eax
710: 39 d8 cmp %ebx,%eax
712: 75 7f jne 793 <writetest1+0x133>
n++;
714: 83 c3 01 add $0x1,%ebx
i = read(fd, buf, 512);
717: 83 ec 04 sub $0x4,%esp
71a: 68 00 02 00 00 push $0x200
71f: 68 e0 85 00 00 push $0x85e0
724: 56 push %esi
725: e8 90 31 00 00 call 38ba <read>
if(i == 0){
72a: 83 c4 10 add $0x10,%esp
72d: 85 c0 test %eax,%eax
72f: 75 cf jne 700 <writetest1+0xa0>
if(n == MAXFILE - 1){
731: 81 fb 8b 00 00 00 cmp $0x8b,%ebx
737: 0f 84 86 00 00 00 je 7c3 <writetest1+0x163>
close(fd);
73d: 83 ec 0c sub $0xc,%esp
740: 56 push %esi
741: e8 84 31 00 00 call 38ca <close>
if(unlink("big") < 0){
746: c7 04 24 e7 3f 00 00 movl $0x3fe7,(%esp)
74d: e8 a0 31 00 00 call 38f2 <unlink>
752: 83 c4 10 add $0x10,%esp
755: 85 c0 test %eax,%eax
757: 0f 88 af 00 00 00 js 80c <writetest1+0x1ac>
printf(stdout, "big files ok\n");
75d: 83 ec 08 sub $0x8,%esp
760: 68 0e 40 00 00 push $0x400e
765: ff 35 08 5e 00 00 pushl 0x5e08
76b: e8 90 32 00 00 call 3a00 <printf>
}
770: 83 c4 10 add $0x10,%esp
773: 8d 65 f8 lea -0x8(%ebp),%esp
776: 5b pop %ebx
777: 5e pop %esi
778: 5d pop %ebp
779: c3 ret
printf(stdout, "error: write big file failed\n", i);
77a: 83 ec 04 sub $0x4,%esp
77d: 53 push %ebx
77e: 68 97 3f 00 00 push $0x3f97
783: ff 35 08 5e 00 00 pushl 0x5e08
789: e8 72 32 00 00 call 3a00 <printf>
exit();
78e: e8 0f 31 00 00 call 38a2 <exit>
printf(stdout, "read content of block %d is %d\n",
793: 50 push %eax
794: 53 push %ebx
795: 68 e8 4d 00 00 push $0x4de8
79a: ff 35 08 5e 00 00 pushl 0x5e08
7a0: e8 5b 32 00 00 call 3a00 <printf>
exit();
7a5: e8 f8 30 00 00 call 38a2 <exit>
printf(stdout, "read failed %d\n", i);
7aa: 83 ec 04 sub $0x4,%esp
7ad: 50 push %eax
7ae: 68 eb 3f 00 00 push $0x3feb
7b3: ff 35 08 5e 00 00 pushl 0x5e08
7b9: e8 42 32 00 00 call 3a00 <printf>
exit();
7be: e8 df 30 00 00 call 38a2 <exit>
printf(stdout, "read only %d blocks from big", n);
7c3: 52 push %edx
7c4: 68 8b 00 00 00 push $0x8b
7c9: 68 ce 3f 00 00 push $0x3fce
7ce: ff 35 08 5e 00 00 pushl 0x5e08
7d4: e8 27 32 00 00 call 3a00 <printf>
exit();
7d9: e8 c4 30 00 00 call 38a2 <exit>
printf(stdout, "error: open big failed!\n");
7de: 51 push %ecx
7df: 51 push %ecx
7e0: 68 b5 3f 00 00 push $0x3fb5
7e5: ff 35 08 5e 00 00 pushl 0x5e08
7eb: e8 10 32 00 00 call 3a00 <printf>
exit();
7f0: e8 ad 30 00 00 call 38a2 <exit>
printf(stdout, "error: creat big failed!\n");
7f5: 50 push %eax
7f6: 50 push %eax
7f7: 68 7d 3f 00 00 push $0x3f7d
7fc: ff 35 08 5e 00 00 pushl 0x5e08
802: e8 f9 31 00 00 call 3a00 <printf>
exit();
807: e8 96 30 00 00 call 38a2 <exit>
printf(stdout, "unlink big failed\n");
80c: 50 push %eax
80d: 50 push %eax
80e: 68 fb 3f 00 00 push $0x3ffb
813: ff 35 08 5e 00 00 pushl 0x5e08
819: e8 e2 31 00 00 call 3a00 <printf>
exit();
81e: e8 7f 30 00 00 call 38a2 <exit>
823: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
829: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000830 <createtest>:
{
830: 55 push %ebp
831: 89 e5 mov %esp,%ebp
833: 53 push %ebx
name[2] = '\0';
834: bb 30 00 00 00 mov $0x30,%ebx
{
839: 83 ec 0c sub $0xc,%esp
printf(stdout, "many creates, followed by unlink test\n");
83c: 68 08 4e 00 00 push $0x4e08
841: ff 35 08 5e 00 00 pushl 0x5e08
847: e8 b4 31 00 00 call 3a00 <printf>
name[0] = 'a';
84c: c6 05 e0 a5 00 00 61 movb $0x61,0xa5e0
name[2] = '\0';
853: c6 05 e2 a5 00 00 00 movb $0x0,0xa5e2
85a: 83 c4 10 add $0x10,%esp
85d: 8d 76 00 lea 0x0(%esi),%esi
fd = open(name, O_CREATE|O_RDWR);
860: 83 ec 08 sub $0x8,%esp
name[1] = '0' + i;
863: 88 1d e1 a5 00 00 mov %bl,0xa5e1
869: 83 c3 01 add $0x1,%ebx
fd = open(name, O_CREATE|O_RDWR);
86c: 68 02 02 00 00 push $0x202
871: 68 e0 a5 00 00 push $0xa5e0
876: e8 67 30 00 00 call 38e2 <open>
close(fd);
87b: 89 04 24 mov %eax,(%esp)
87e: e8 47 30 00 00 call 38ca <close>
for(i = 0; i < 52; i++){
883: 83 c4 10 add $0x10,%esp
886: 80 fb 64 cmp $0x64,%bl
889: 75 d5 jne 860 <createtest+0x30>
name[0] = 'a';
88b: c6 05 e0 a5 00 00 61 movb $0x61,0xa5e0
name[2] = '\0';
892: c6 05 e2 a5 00 00 00 movb $0x0,0xa5e2
899: bb 30 00 00 00 mov $0x30,%ebx
89e: 66 90 xchg %ax,%ax
unlink(name);
8a0: 83 ec 0c sub $0xc,%esp
name[1] = '0' + i;
8a3: 88 1d e1 a5 00 00 mov %bl,0xa5e1
8a9: 83 c3 01 add $0x1,%ebx
unlink(name);
8ac: 68 e0 a5 00 00 push $0xa5e0
8b1: e8 3c 30 00 00 call 38f2 <unlink>
for(i = 0; i < 52; i++){
8b6: 83 c4 10 add $0x10,%esp
8b9: 80 fb 64 cmp $0x64,%bl
8bc: 75 e2 jne 8a0 <createtest+0x70>
printf(stdout, "many creates, followed by unlink; ok\n");
8be: 83 ec 08 sub $0x8,%esp
8c1: 68 30 4e 00 00 push $0x4e30
8c6: ff 35 08 5e 00 00 pushl 0x5e08
8cc: e8 2f 31 00 00 call 3a00 <printf>
}
8d1: 83 c4 10 add $0x10,%esp
8d4: 8b 5d fc mov -0x4(%ebp),%ebx
8d7: c9 leave
8d8: c3 ret
8d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000008e0 <dirtest>:
{
8e0: 55 push %ebp
8e1: 89 e5 mov %esp,%ebp
8e3: 83 ec 10 sub $0x10,%esp
printf(stdout, "mkdir test\n");
8e6: 68 1c 40 00 00 push $0x401c
8eb: ff 35 08 5e 00 00 pushl 0x5e08
8f1: e8 0a 31 00 00 call 3a00 <printf>
if(mkdir("dir0") < 0){
8f6: c7 04 24 28 40 00 00 movl $0x4028,(%esp)
8fd: e8 08 30 00 00 call 390a <mkdir>
902: 83 c4 10 add $0x10,%esp
905: 85 c0 test %eax,%eax
907: 78 58 js 961 <dirtest+0x81>
if(chdir("dir0") < 0){
909: 83 ec 0c sub $0xc,%esp
90c: 68 28 40 00 00 push $0x4028
911: e8 fc 2f 00 00 call 3912 <chdir>
916: 83 c4 10 add $0x10,%esp
919: 85 c0 test %eax,%eax
91b: 0f 88 85 00 00 00 js 9a6 <dirtest+0xc6>
if(chdir("..") < 0){
921: 83 ec 0c sub $0xc,%esp
924: 68 cd 45 00 00 push $0x45cd
929: e8 e4 2f 00 00 call 3912 <chdir>
92e: 83 c4 10 add $0x10,%esp
931: 85 c0 test %eax,%eax
933: 78 5a js 98f <dirtest+0xaf>
if(unlink("dir0") < 0){
935: 83 ec 0c sub $0xc,%esp
938: 68 28 40 00 00 push $0x4028
93d: e8 b0 2f 00 00 call 38f2 <unlink>
942: 83 c4 10 add $0x10,%esp
945: 85 c0 test %eax,%eax
947: 78 2f js 978 <dirtest+0x98>
printf(stdout, "mkdir test ok\n");
949: 83 ec 08 sub $0x8,%esp
94c: 68 65 40 00 00 push $0x4065
951: ff 35 08 5e 00 00 pushl 0x5e08
957: e8 a4 30 00 00 call 3a00 <printf>
}
95c: 83 c4 10 add $0x10,%esp
95f: c9 leave
960: c3 ret
printf(stdout, "mkdir failed\n");
961: 50 push %eax
962: 50 push %eax
963: 68 58 3d 00 00 push $0x3d58
968: ff 35 08 5e 00 00 pushl 0x5e08
96e: e8 8d 30 00 00 call 3a00 <printf>
exit();
973: e8 2a 2f 00 00 call 38a2 <exit>
printf(stdout, "unlink dir0 failed\n");
978: 50 push %eax
979: 50 push %eax
97a: 68 51 40 00 00 push $0x4051
97f: ff 35 08 5e 00 00 pushl 0x5e08
985: e8 76 30 00 00 call 3a00 <printf>
exit();
98a: e8 13 2f 00 00 call 38a2 <exit>
printf(stdout, "chdir .. failed\n");
98f: 52 push %edx
990: 52 push %edx
991: 68 40 40 00 00 push $0x4040
996: ff 35 08 5e 00 00 pushl 0x5e08
99c: e8 5f 30 00 00 call 3a00 <printf>
exit();
9a1: e8 fc 2e 00 00 call 38a2 <exit>
printf(stdout, "chdir dir0 failed\n");
9a6: 51 push %ecx
9a7: 51 push %ecx
9a8: 68 2d 40 00 00 push $0x402d
9ad: ff 35 08 5e 00 00 pushl 0x5e08
9b3: e8 48 30 00 00 call 3a00 <printf>
exit();
9b8: e8 e5 2e 00 00 call 38a2 <exit>
9bd: 8d 76 00 lea 0x0(%esi),%esi
000009c0 <exectest>:
{
9c0: 55 push %ebp
9c1: 89 e5 mov %esp,%ebp
9c3: 83 ec 10 sub $0x10,%esp
printf(stdout, "exec test\n");
9c6: 68 74 40 00 00 push $0x4074
9cb: ff 35 08 5e 00 00 pushl 0x5e08
9d1: e8 2a 30 00 00 call 3a00 <printf>
if(exec("echo", echoargv) < 0){
9d6: 5a pop %edx
9d7: 59 pop %ecx
9d8: 68 0c 5e 00 00 push $0x5e0c
9dd: 68 3d 3e 00 00 push $0x3e3d
9e2: e8 f3 2e 00 00 call 38da <exec>
9e7: 83 c4 10 add $0x10,%esp
9ea: 85 c0 test %eax,%eax
9ec: 78 02 js 9f0 <exectest+0x30>
}
9ee: c9 leave
9ef: c3 ret
printf(stdout, "exec echo failed\n");
9f0: 50 push %eax
9f1: 50 push %eax
9f2: 68 7f 40 00 00 push $0x407f
9f7: ff 35 08 5e 00 00 pushl 0x5e08
9fd: e8 fe 2f 00 00 call 3a00 <printf>
exit();
a02: e8 9b 2e 00 00 call 38a2 <exit>
a07: 89 f6 mov %esi,%esi
a09: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000a10 <pipe1>:
{
a10: 55 push %ebp
a11: 89 e5 mov %esp,%ebp
a13: 57 push %edi
a14: 56 push %esi
a15: 53 push %ebx
if(pipe(fds) != 0){
a16: 8d 45 e0 lea -0x20(%ebp),%eax
{
a19: 83 ec 38 sub $0x38,%esp
if(pipe(fds) != 0){
a1c: 50 push %eax
a1d: e8 90 2e 00 00 call 38b2 <pipe>
a22: 83 c4 10 add $0x10,%esp
a25: 85 c0 test %eax,%eax
a27: 0f 85 3e 01 00 00 jne b6b <pipe1+0x15b>
a2d: 89 c3 mov %eax,%ebx
pid = fork();
a2f: e8 66 2e 00 00 call 389a <fork>
if(pid == 0){
a34: 83 f8 00 cmp $0x0,%eax
a37: 0f 84 84 00 00 00 je ac1 <pipe1+0xb1>
} else if(pid > 0){
a3d: 0f 8e 3b 01 00 00 jle b7e <pipe1+0x16e>
close(fds[1]);
a43: 83 ec 0c sub $0xc,%esp
a46: ff 75 e4 pushl -0x1c(%ebp)
cc = 1;
a49: bf 01 00 00 00 mov $0x1,%edi
close(fds[1]);
a4e: e8 77 2e 00 00 call 38ca <close>
while((n = read(fds[0], buf, cc)) > 0){
a53: 83 c4 10 add $0x10,%esp
total = 0;
a56: c7 45 d4 00 00 00 00 movl $0x0,-0x2c(%ebp)
while((n = read(fds[0], buf, cc)) > 0){
a5d: 83 ec 04 sub $0x4,%esp
a60: 57 push %edi
a61: 68 e0 85 00 00 push $0x85e0
a66: ff 75 e0 pushl -0x20(%ebp)
a69: e8 4c 2e 00 00 call 38ba <read>
a6e: 83 c4 10 add $0x10,%esp
a71: 85 c0 test %eax,%eax
a73: 0f 8e ab 00 00 00 jle b24 <pipe1+0x114>
if((buf[i] & 0xff) != (seq++ & 0xff)){
a79: 89 d9 mov %ebx,%ecx
a7b: 8d 34 18 lea (%eax,%ebx,1),%esi
a7e: f7 d9 neg %ecx
a80: 38 9c 0b e0 85 00 00 cmp %bl,0x85e0(%ebx,%ecx,1)
a87: 8d 53 01 lea 0x1(%ebx),%edx
a8a: 75 1b jne aa7 <pipe1+0x97>
for(i = 0; i < n; i++){
a8c: 39 f2 cmp %esi,%edx
a8e: 89 d3 mov %edx,%ebx
a90: 75 ee jne a80 <pipe1+0x70>
cc = cc * 2;
a92: 01 ff add %edi,%edi
total += n;
a94: 01 45 d4 add %eax,-0x2c(%ebp)
a97: b8 00 20 00 00 mov $0x2000,%eax
a9c: 81 ff 00 20 00 00 cmp $0x2000,%edi
aa2: 0f 4f f8 cmovg %eax,%edi
aa5: eb b6 jmp a5d <pipe1+0x4d>
printf(1, "pipe1 oops 2\n");
aa7: 83 ec 08 sub $0x8,%esp
aaa: 68 ae 40 00 00 push $0x40ae
aaf: 6a 01 push $0x1
ab1: e8 4a 2f 00 00 call 3a00 <printf>
return;
ab6: 83 c4 10 add $0x10,%esp
}
ab9: 8d 65 f4 lea -0xc(%ebp),%esp
abc: 5b pop %ebx
abd: 5e pop %esi
abe: 5f pop %edi
abf: 5d pop %ebp
ac0: c3 ret
close(fds[0]);
ac1: 83 ec 0c sub $0xc,%esp
ac4: ff 75 e0 pushl -0x20(%ebp)
ac7: 31 db xor %ebx,%ebx
ac9: be 09 04 00 00 mov $0x409,%esi
ace: e8 f7 2d 00 00 call 38ca <close>
ad3: 83 c4 10 add $0x10,%esp
ad6: 89 d8 mov %ebx,%eax
ad8: 89 f2 mov %esi,%edx
ada: f7 d8 neg %eax
adc: 29 da sub %ebx,%edx
ade: 66 90 xchg %ax,%ax
buf[i] = seq++;
ae0: 88 84 03 e0 85 00 00 mov %al,0x85e0(%ebx,%eax,1)
ae7: 83 c0 01 add $0x1,%eax
for(i = 0; i < 1033; i++)
aea: 39 d0 cmp %edx,%eax
aec: 75 f2 jne ae0 <pipe1+0xd0>
if(write(fds[1], buf, 1033) != 1033){
aee: 83 ec 04 sub $0x4,%esp
af1: 68 09 04 00 00 push $0x409
af6: 68 e0 85 00 00 push $0x85e0
afb: ff 75 e4 pushl -0x1c(%ebp)
afe: e8 bf 2d 00 00 call 38c2 <write>
b03: 83 c4 10 add $0x10,%esp
b06: 3d 09 04 00 00 cmp $0x409,%eax
b0b: 0f 85 80 00 00 00 jne b91 <pipe1+0x181>
b11: 81 eb 09 04 00 00 sub $0x409,%ebx
for(n = 0; n < 5; n++){
b17: 81 fb d3 eb ff ff cmp $0xffffebd3,%ebx
b1d: 75 b7 jne ad6 <pipe1+0xc6>
exit();
b1f: e8 7e 2d 00 00 call 38a2 <exit>
if(total != 5 * 1033){
b24: 81 7d d4 2d 14 00 00 cmpl $0x142d,-0x2c(%ebp)
b2b: 75 29 jne b56 <pipe1+0x146>
close(fds[0]);
b2d: 83 ec 0c sub $0xc,%esp
b30: ff 75 e0 pushl -0x20(%ebp)
b33: e8 92 2d 00 00 call 38ca <close>
wait();
b38: e8 6d 2d 00 00 call 38aa <wait>
printf(1, "pipe1 ok\n");
b3d: 5a pop %edx
b3e: 59 pop %ecx
b3f: 68 d3 40 00 00 push $0x40d3
b44: 6a 01 push $0x1
b46: e8 b5 2e 00 00 call 3a00 <printf>
b4b: 83 c4 10 add $0x10,%esp
}
b4e: 8d 65 f4 lea -0xc(%ebp),%esp
b51: 5b pop %ebx
b52: 5e pop %esi
b53: 5f pop %edi
b54: 5d pop %ebp
b55: c3 ret
printf(1, "pipe1 oops 3 total %d\n", total);
b56: 53 push %ebx
b57: ff 75 d4 pushl -0x2c(%ebp)
b5a: 68 bc 40 00 00 push $0x40bc
b5f: 6a 01 push $0x1
b61: e8 9a 2e 00 00 call 3a00 <printf>
exit();
b66: e8 37 2d 00 00 call 38a2 <exit>
printf(1, "pipe() failed\n");
b6b: 57 push %edi
b6c: 57 push %edi
b6d: 68 91 40 00 00 push $0x4091
b72: 6a 01 push $0x1
b74: e8 87 2e 00 00 call 3a00 <printf>
exit();
b79: e8 24 2d 00 00 call 38a2 <exit>
printf(1, "fork() failed\n");
b7e: 50 push %eax
b7f: 50 push %eax
b80: 68 dd 40 00 00 push $0x40dd
b85: 6a 01 push $0x1
b87: e8 74 2e 00 00 call 3a00 <printf>
exit();
b8c: e8 11 2d 00 00 call 38a2 <exit>
printf(1, "pipe1 oops 1\n");
b91: 56 push %esi
b92: 56 push %esi
b93: 68 a0 40 00 00 push $0x40a0
b98: 6a 01 push $0x1
b9a: e8 61 2e 00 00 call 3a00 <printf>
exit();
b9f: e8 fe 2c 00 00 call 38a2 <exit>
ba4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
baa: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000bb0 <preempt>:
{
bb0: 55 push %ebp
bb1: 89 e5 mov %esp,%ebp
bb3: 57 push %edi
bb4: 56 push %esi
bb5: 53 push %ebx
bb6: 83 ec 24 sub $0x24,%esp
printf(1, "preempt: ");
bb9: 68 ec 40 00 00 push $0x40ec
bbe: 6a 01 push $0x1
bc0: e8 3b 2e 00 00 call 3a00 <printf>
pid1 = fork();
bc5: e8 d0 2c 00 00 call 389a <fork>
if(pid1 == 0)
bca: 83 c4 10 add $0x10,%esp
bcd: 85 c0 test %eax,%eax
bcf: 75 02 jne bd3 <preempt+0x23>
bd1: eb fe jmp bd1 <preempt+0x21>
bd3: 89 c7 mov %eax,%edi
pid2 = fork();
bd5: e8 c0 2c 00 00 call 389a <fork>
if(pid2 == 0)
bda: 85 c0 test %eax,%eax
pid2 = fork();
bdc: 89 c6 mov %eax,%esi
if(pid2 == 0)
bde: 75 02 jne be2 <preempt+0x32>
be0: eb fe jmp be0 <preempt+0x30>
pipe(pfds);
be2: 8d 45 e0 lea -0x20(%ebp),%eax
be5: 83 ec 0c sub $0xc,%esp
be8: 50 push %eax
be9: e8 c4 2c 00 00 call 38b2 <pipe>
pid3 = fork();
bee: e8 a7 2c 00 00 call 389a <fork>
if(pid3 == 0){
bf3: 83 c4 10 add $0x10,%esp
bf6: 85 c0 test %eax,%eax
pid3 = fork();
bf8: 89 c3 mov %eax,%ebx
if(pid3 == 0){
bfa: 75 46 jne c42 <preempt+0x92>
close(pfds[0]);
bfc: 83 ec 0c sub $0xc,%esp
bff: ff 75 e0 pushl -0x20(%ebp)
c02: e8 c3 2c 00 00 call 38ca <close>
if(write(pfds[1], "x", 1) != 1)
c07: 83 c4 0c add $0xc,%esp
c0a: 6a 01 push $0x1
c0c: 68 b1 46 00 00 push $0x46b1
c11: ff 75 e4 pushl -0x1c(%ebp)
c14: e8 a9 2c 00 00 call 38c2 <write>
c19: 83 c4 10 add $0x10,%esp
c1c: 83 e8 01 sub $0x1,%eax
c1f: 74 11 je c32 <preempt+0x82>
printf(1, "preempt write error");
c21: 50 push %eax
c22: 50 push %eax
c23: 68 f6 40 00 00 push $0x40f6
c28: 6a 01 push $0x1
c2a: e8 d1 2d 00 00 call 3a00 <printf>
c2f: 83 c4 10 add $0x10,%esp
close(pfds[1]);
c32: 83 ec 0c sub $0xc,%esp
c35: ff 75 e4 pushl -0x1c(%ebp)
c38: e8 8d 2c 00 00 call 38ca <close>
c3d: 83 c4 10 add $0x10,%esp
c40: eb fe jmp c40 <preempt+0x90>
close(pfds[1]);
c42: 83 ec 0c sub $0xc,%esp
c45: ff 75 e4 pushl -0x1c(%ebp)
c48: e8 7d 2c 00 00 call 38ca <close>
if(read(pfds[0], buf, sizeof(buf)) != 1){
c4d: 83 c4 0c add $0xc,%esp
c50: 68 00 20 00 00 push $0x2000
c55: 68 e0 85 00 00 push $0x85e0
c5a: ff 75 e0 pushl -0x20(%ebp)
c5d: e8 58 2c 00 00 call 38ba <read>
c62: 83 c4 10 add $0x10,%esp
c65: 83 e8 01 sub $0x1,%eax
c68: 74 19 je c83 <preempt+0xd3>
printf(1, "preempt read error");
c6a: 50 push %eax
c6b: 50 push %eax
c6c: 68 0a 41 00 00 push $0x410a
c71: 6a 01 push $0x1
c73: e8 88 2d 00 00 call 3a00 <printf>
return;
c78: 83 c4 10 add $0x10,%esp
}
c7b: 8d 65 f4 lea -0xc(%ebp),%esp
c7e: 5b pop %ebx
c7f: 5e pop %esi
c80: 5f pop %edi
c81: 5d pop %ebp
c82: c3 ret
close(pfds[0]);
c83: 83 ec 0c sub $0xc,%esp
c86: ff 75 e0 pushl -0x20(%ebp)
c89: e8 3c 2c 00 00 call 38ca <close>
printf(1, "kill... ");
c8e: 58 pop %eax
c8f: 5a pop %edx
c90: 68 1d 41 00 00 push $0x411d
c95: 6a 01 push $0x1
c97: e8 64 2d 00 00 call 3a00 <printf>
kill(pid1);
c9c: 89 3c 24 mov %edi,(%esp)
c9f: e8 2e 2c 00 00 call 38d2 <kill>
kill(pid2);
ca4: 89 34 24 mov %esi,(%esp)
ca7: e8 26 2c 00 00 call 38d2 <kill>
kill(pid3);
cac: 89 1c 24 mov %ebx,(%esp)
caf: e8 1e 2c 00 00 call 38d2 <kill>
printf(1, "wait... ");
cb4: 59 pop %ecx
cb5: 5b pop %ebx
cb6: 68 26 41 00 00 push $0x4126
cbb: 6a 01 push $0x1
cbd: e8 3e 2d 00 00 call 3a00 <printf>
wait();
cc2: e8 e3 2b 00 00 call 38aa <wait>
wait();
cc7: e8 de 2b 00 00 call 38aa <wait>
wait();
ccc: e8 d9 2b 00 00 call 38aa <wait>
printf(1, "preempt ok\n");
cd1: 5e pop %esi
cd2: 5f pop %edi
cd3: 68 2f 41 00 00 push $0x412f
cd8: 6a 01 push $0x1
cda: e8 21 2d 00 00 call 3a00 <printf>
cdf: 83 c4 10 add $0x10,%esp
ce2: eb 97 jmp c7b <preempt+0xcb>
ce4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
cea: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000cf0 <exitwait>:
{
cf0: 55 push %ebp
cf1: 89 e5 mov %esp,%ebp
cf3: 56 push %esi
cf4: be 64 00 00 00 mov $0x64,%esi
cf9: 53 push %ebx
cfa: eb 14 jmp d10 <exitwait+0x20>
cfc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
if(pid){
d00: 74 6f je d71 <exitwait+0x81>
if(wait() != pid){
d02: e8 a3 2b 00 00 call 38aa <wait>
d07: 39 d8 cmp %ebx,%eax
d09: 75 2d jne d38 <exitwait+0x48>
for(i = 0; i < 100; i++){
d0b: 83 ee 01 sub $0x1,%esi
d0e: 74 48 je d58 <exitwait+0x68>
pid = fork();
d10: e8 85 2b 00 00 call 389a <fork>
if(pid < 0){
d15: 85 c0 test %eax,%eax
pid = fork();
d17: 89 c3 mov %eax,%ebx
if(pid < 0){
d19: 79 e5 jns d00 <exitwait+0x10>
printf(1, "fork failed\n");
d1b: 83 ec 08 sub $0x8,%esp
d1e: 68 99 4c 00 00 push $0x4c99
d23: 6a 01 push $0x1
d25: e8 d6 2c 00 00 call 3a00 <printf>
return;
d2a: 83 c4 10 add $0x10,%esp
}
d2d: 8d 65 f8 lea -0x8(%ebp),%esp
d30: 5b pop %ebx
d31: 5e pop %esi
d32: 5d pop %ebp
d33: c3 ret
d34: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
printf(1, "wait wrong pid\n");
d38: 83 ec 08 sub $0x8,%esp
d3b: 68 3b 41 00 00 push $0x413b
d40: 6a 01 push $0x1
d42: e8 b9 2c 00 00 call 3a00 <printf>
return;
d47: 83 c4 10 add $0x10,%esp
}
d4a: 8d 65 f8 lea -0x8(%ebp),%esp
d4d: 5b pop %ebx
d4e: 5e pop %esi
d4f: 5d pop %ebp
d50: c3 ret
d51: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
printf(1, "exitwait ok\n");
d58: 83 ec 08 sub $0x8,%esp
d5b: 68 4b 41 00 00 push $0x414b
d60: 6a 01 push $0x1
d62: e8 99 2c 00 00 call 3a00 <printf>
d67: 83 c4 10 add $0x10,%esp
}
d6a: 8d 65 f8 lea -0x8(%ebp),%esp
d6d: 5b pop %ebx
d6e: 5e pop %esi
d6f: 5d pop %ebp
d70: c3 ret
exit();
d71: e8 2c 2b 00 00 call 38a2 <exit>
d76: 8d 76 00 lea 0x0(%esi),%esi
d79: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000d80 <mem>:
{
d80: 55 push %ebp
d81: 89 e5 mov %esp,%ebp
d83: 57 push %edi
d84: 56 push %esi
d85: 53 push %ebx
d86: 31 db xor %ebx,%ebx
d88: 83 ec 14 sub $0x14,%esp
printf(1, "mem test\n");
d8b: 68 58 41 00 00 push $0x4158
d90: 6a 01 push $0x1
d92: e8 69 2c 00 00 call 3a00 <printf>
ppid = getpid();
d97: e8 86 2b 00 00 call 3922 <getpid>
d9c: 89 c6 mov %eax,%esi
if((pid = fork()) == 0){
d9e: e8 f7 2a 00 00 call 389a <fork>
da3: 83 c4 10 add $0x10,%esp
da6: 85 c0 test %eax,%eax
da8: 74 0a je db4 <mem+0x34>
daa: e9 89 00 00 00 jmp e38 <mem+0xb8>
daf: 90 nop
*(char**)m2 = m1;
db0: 89 18 mov %ebx,(%eax)
db2: 89 c3 mov %eax,%ebx
while((m2 = malloc(10001)) != 0){
db4: 83 ec 0c sub $0xc,%esp
db7: 68 11 27 00 00 push $0x2711
dbc: e8 9f 2e 00 00 call 3c60 <malloc>
dc1: 83 c4 10 add $0x10,%esp
dc4: 85 c0 test %eax,%eax
dc6: 75 e8 jne db0 <mem+0x30>
while(m1){
dc8: 85 db test %ebx,%ebx
dca: 74 18 je de4 <mem+0x64>
dcc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
m2 = *(char**)m1;
dd0: 8b 3b mov (%ebx),%edi
free(m1);
dd2: 83 ec 0c sub $0xc,%esp
dd5: 53 push %ebx
dd6: 89 fb mov %edi,%ebx
dd8: e8 f3 2d 00 00 call 3bd0 <free>
while(m1){
ddd: 83 c4 10 add $0x10,%esp
de0: 85 db test %ebx,%ebx
de2: 75 ec jne dd0 <mem+0x50>
m1 = malloc(1024*20);
de4: 83 ec 0c sub $0xc,%esp
de7: 68 00 50 00 00 push $0x5000
dec: e8 6f 2e 00 00 call 3c60 <malloc>
if(m1 == 0){
df1: 83 c4 10 add $0x10,%esp
df4: 85 c0 test %eax,%eax
df6: 74 20 je e18 <mem+0x98>
free(m1);
df8: 83 ec 0c sub $0xc,%esp
dfb: 50 push %eax
dfc: e8 cf 2d 00 00 call 3bd0 <free>
printf(1, "mem ok\n");
e01: 58 pop %eax
e02: 5a pop %edx
e03: 68 7c 41 00 00 push $0x417c
e08: 6a 01 push $0x1
e0a: e8 f1 2b 00 00 call 3a00 <printf>
exit();
e0f: e8 8e 2a 00 00 call 38a2 <exit>
e14: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
printf(1, "couldn't allocate mem?!!\n");
e18: 83 ec 08 sub $0x8,%esp
e1b: 68 62 41 00 00 push $0x4162
e20: 6a 01 push $0x1
e22: e8 d9 2b 00 00 call 3a00 <printf>
kill(ppid);
e27: 89 34 24 mov %esi,(%esp)
e2a: e8 a3 2a 00 00 call 38d2 <kill>
exit();
e2f: e8 6e 2a 00 00 call 38a2 <exit>
e34: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
}
e38: 8d 65 f4 lea -0xc(%ebp),%esp
e3b: 5b pop %ebx
e3c: 5e pop %esi
e3d: 5f pop %edi
e3e: 5d pop %ebp
wait();
e3f: e9 66 2a 00 00 jmp 38aa <wait>
e44: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
e4a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000e50 <sharedfd>:
{
e50: 55 push %ebp
e51: 89 e5 mov %esp,%ebp
e53: 57 push %edi
e54: 56 push %esi
e55: 53 push %ebx
e56: 83 ec 34 sub $0x34,%esp
printf(1, "sharedfd test\n");
e59: 68 84 41 00 00 push $0x4184
e5e: 6a 01 push $0x1
e60: e8 9b 2b 00 00 call 3a00 <printf>
unlink("sharedfd");
e65: c7 04 24 93 41 00 00 movl $0x4193,(%esp)
e6c: e8 81 2a 00 00 call 38f2 <unlink>
fd = open("sharedfd", O_CREATE|O_RDWR);
e71: 59 pop %ecx
e72: 5b pop %ebx
e73: 68 02 02 00 00 push $0x202
e78: 68 93 41 00 00 push $0x4193
e7d: e8 60 2a 00 00 call 38e2 <open>
if(fd < 0){
e82: 83 c4 10 add $0x10,%esp
e85: 85 c0 test %eax,%eax
e87: 0f 88 33 01 00 00 js fc0 <sharedfd+0x170>
e8d: 89 c6 mov %eax,%esi
memset(buf, pid==0?'c':'p', sizeof(buf));
e8f: bb e8 03 00 00 mov $0x3e8,%ebx
pid = fork();
e94: e8 01 2a 00 00 call 389a <fork>
memset(buf, pid==0?'c':'p', sizeof(buf));
e99: 83 f8 01 cmp $0x1,%eax
pid = fork();
e9c: 89 c7 mov %eax,%edi
memset(buf, pid==0?'c':'p', sizeof(buf));
e9e: 19 c0 sbb %eax,%eax
ea0: 83 ec 04 sub $0x4,%esp
ea3: 83 e0 f3 and $0xfffffff3,%eax
ea6: 6a 0a push $0xa
ea8: 83 c0 70 add $0x70,%eax
eab: 50 push %eax
eac: 8d 45 de lea -0x22(%ebp),%eax
eaf: 50 push %eax
eb0: e8 4b 28 00 00 call 3700 <memset>
eb5: 83 c4 10 add $0x10,%esp
eb8: eb 0b jmp ec5 <sharedfd+0x75>
eba: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
for(i = 0; i < 1000; i++){
ec0: 83 eb 01 sub $0x1,%ebx
ec3: 74 29 je eee <sharedfd+0x9e>
if(write(fd, buf, sizeof(buf)) != sizeof(buf)){
ec5: 8d 45 de lea -0x22(%ebp),%eax
ec8: 83 ec 04 sub $0x4,%esp
ecb: 6a 0a push $0xa
ecd: 50 push %eax
ece: 56 push %esi
ecf: e8 ee 29 00 00 call 38c2 <write>
ed4: 83 c4 10 add $0x10,%esp
ed7: 83 f8 0a cmp $0xa,%eax
eda: 74 e4 je ec0 <sharedfd+0x70>
printf(1, "fstests: write sharedfd failed\n");
edc: 83 ec 08 sub $0x8,%esp
edf: 68 84 4e 00 00 push $0x4e84
ee4: 6a 01 push $0x1
ee6: e8 15 2b 00 00 call 3a00 <printf>
break;
eeb: 83 c4 10 add $0x10,%esp
if(pid == 0)
eee: 85 ff test %edi,%edi
ef0: 0f 84 fe 00 00 00 je ff4 <sharedfd+0x1a4>
wait();
ef6: e8 af 29 00 00 call 38aa <wait>
close(fd);
efb: 83 ec 0c sub $0xc,%esp
nc = np = 0;
efe: 31 db xor %ebx,%ebx
f00: 31 ff xor %edi,%edi
close(fd);
f02: 56 push %esi
f03: 8d 75 e8 lea -0x18(%ebp),%esi
f06: e8 bf 29 00 00 call 38ca <close>
fd = open("sharedfd", 0);
f0b: 58 pop %eax
f0c: 5a pop %edx
f0d: 6a 00 push $0x0
f0f: 68 93 41 00 00 push $0x4193
f14: e8 c9 29 00 00 call 38e2 <open>
if(fd < 0){
f19: 83 c4 10 add $0x10,%esp
f1c: 85 c0 test %eax,%eax
fd = open("sharedfd", 0);
f1e: 89 45 d4 mov %eax,-0x2c(%ebp)
if(fd < 0){
f21: 0f 88 b3 00 00 00 js fda <sharedfd+0x18a>
f27: 89 f8 mov %edi,%eax
f29: 89 df mov %ebx,%edi
f2b: 89 c3 mov %eax,%ebx
f2d: 8d 76 00 lea 0x0(%esi),%esi
while((n = read(fd, buf, sizeof(buf))) > 0){
f30: 8d 45 de lea -0x22(%ebp),%eax
f33: 83 ec 04 sub $0x4,%esp
f36: 6a 0a push $0xa
f38: 50 push %eax
f39: ff 75 d4 pushl -0x2c(%ebp)
f3c: e8 79 29 00 00 call 38ba <read>
f41: 83 c4 10 add $0x10,%esp
f44: 85 c0 test %eax,%eax
f46: 7e 28 jle f70 <sharedfd+0x120>
f48: 8d 45 de lea -0x22(%ebp),%eax
f4b: eb 15 jmp f62 <sharedfd+0x112>
f4d: 8d 76 00 lea 0x0(%esi),%esi
np++;
f50: 80 fa 70 cmp $0x70,%dl
f53: 0f 94 c2 sete %dl
f56: 0f b6 d2 movzbl %dl,%edx
f59: 01 d7 add %edx,%edi
f5b: 83 c0 01 add $0x1,%eax
for(i = 0; i < sizeof(buf); i++){
f5e: 39 f0 cmp %esi,%eax
f60: 74 ce je f30 <sharedfd+0xe0>
if(buf[i] == 'c')
f62: 0f b6 10 movzbl (%eax),%edx
f65: 80 fa 63 cmp $0x63,%dl
f68: 75 e6 jne f50 <sharedfd+0x100>
nc++;
f6a: 83 c3 01 add $0x1,%ebx
f6d: eb ec jmp f5b <sharedfd+0x10b>
f6f: 90 nop
close(fd);
f70: 83 ec 0c sub $0xc,%esp
f73: 89 d8 mov %ebx,%eax
f75: ff 75 d4 pushl -0x2c(%ebp)
f78: 89 fb mov %edi,%ebx
f7a: 89 c7 mov %eax,%edi
f7c: e8 49 29 00 00 call 38ca <close>
unlink("sharedfd");
f81: c7 04 24 93 41 00 00 movl $0x4193,(%esp)
f88: e8 65 29 00 00 call 38f2 <unlink>
if(nc == 10000 && np == 10000){
f8d: 83 c4 10 add $0x10,%esp
f90: 81 ff 10 27 00 00 cmp $0x2710,%edi
f96: 75 61 jne ff9 <sharedfd+0x1a9>
f98: 81 fb 10 27 00 00 cmp $0x2710,%ebx
f9e: 75 59 jne ff9 <sharedfd+0x1a9>
printf(1, "sharedfd ok\n");
fa0: 83 ec 08 sub $0x8,%esp
fa3: 68 9c 41 00 00 push $0x419c
fa8: 6a 01 push $0x1
faa: e8 51 2a 00 00 call 3a00 <printf>
faf: 83 c4 10 add $0x10,%esp
}
fb2: 8d 65 f4 lea -0xc(%ebp),%esp
fb5: 5b pop %ebx
fb6: 5e pop %esi
fb7: 5f pop %edi
fb8: 5d pop %ebp
fb9: c3 ret
fba: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
printf(1, "fstests: cannot open sharedfd for writing");
fc0: 83 ec 08 sub $0x8,%esp
fc3: 68 58 4e 00 00 push $0x4e58
fc8: 6a 01 push $0x1
fca: e8 31 2a 00 00 call 3a00 <printf>
return;
fcf: 83 c4 10 add $0x10,%esp
}
fd2: 8d 65 f4 lea -0xc(%ebp),%esp
fd5: 5b pop %ebx
fd6: 5e pop %esi
fd7: 5f pop %edi
fd8: 5d pop %ebp
fd9: c3 ret
printf(1, "fstests: cannot open sharedfd for reading\n");
fda: 83 ec 08 sub $0x8,%esp
fdd: 68 a4 4e 00 00 push $0x4ea4
fe2: 6a 01 push $0x1
fe4: e8 17 2a 00 00 call 3a00 <printf>
return;
fe9: 83 c4 10 add $0x10,%esp
}
fec: 8d 65 f4 lea -0xc(%ebp),%esp
fef: 5b pop %ebx
ff0: 5e pop %esi
ff1: 5f pop %edi
ff2: 5d pop %ebp
ff3: c3 ret
exit();
ff4: e8 a9 28 00 00 call 38a2 <exit>
printf(1, "sharedfd oops %d %d\n", nc, np);
ff9: 53 push %ebx
ffa: 57 push %edi
ffb: 68 a9 41 00 00 push $0x41a9
1000: 6a 01 push $0x1
1002: e8 f9 29 00 00 call 3a00 <printf>
exit();
1007: e8 96 28 00 00 call 38a2 <exit>
100c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00001010 <fourfiles>:
{
1010: 55 push %ebp
1011: 89 e5 mov %esp,%ebp
1013: 57 push %edi
1014: 56 push %esi
1015: 53 push %ebx
printf(1, "fourfiles test\n");
1016: be be 41 00 00 mov $0x41be,%esi
for(pi = 0; pi < 4; pi++){
101b: 31 db xor %ebx,%ebx
{
101d: 83 ec 34 sub $0x34,%esp
char *names[] = { "f0", "f1", "f2", "f3" };
1020: c7 45 d8 be 41 00 00 movl $0x41be,-0x28(%ebp)
1027: c7 45 dc 07 43 00 00 movl $0x4307,-0x24(%ebp)
printf(1, "fourfiles test\n");
102e: 68 c4 41 00 00 push $0x41c4
1033: 6a 01 push $0x1
char *names[] = { "f0", "f1", "f2", "f3" };
1035: c7 45 e0 0b 43 00 00 movl $0x430b,-0x20(%ebp)
103c: c7 45 e4 c1 41 00 00 movl $0x41c1,-0x1c(%ebp)
printf(1, "fourfiles test\n");
1043: e8 b8 29 00 00 call 3a00 <printf>
1048: 83 c4 10 add $0x10,%esp
unlink(fname);
104b: 83 ec 0c sub $0xc,%esp
104e: 56 push %esi
104f: e8 9e 28 00 00 call 38f2 <unlink>
pid = fork();
1054: e8 41 28 00 00 call 389a <fork>
if(pid < 0){
1059: 83 c4 10 add $0x10,%esp
105c: 85 c0 test %eax,%eax
105e: 0f 88 68 01 00 00 js 11cc <fourfiles+0x1bc>
if(pid == 0){
1064: 0f 84 df 00 00 00 je 1149 <fourfiles+0x139>
for(pi = 0; pi < 4; pi++){
106a: 83 c3 01 add $0x1,%ebx
106d: 83 fb 04 cmp $0x4,%ebx
1070: 74 06 je 1078 <fourfiles+0x68>
1072: 8b 74 9d d8 mov -0x28(%ebp,%ebx,4),%esi
1076: eb d3 jmp 104b <fourfiles+0x3b>
wait();
1078: e8 2d 28 00 00 call 38aa <wait>
for(i = 0; i < 2; i++){
107d: 31 ff xor %edi,%edi
wait();
107f: e8 26 28 00 00 call 38aa <wait>
1084: e8 21 28 00 00 call 38aa <wait>
1089: e8 1c 28 00 00 call 38aa <wait>
108e: c7 45 d0 be 41 00 00 movl $0x41be,-0x30(%ebp)
fd = open(fname, 0);
1095: 83 ec 08 sub $0x8,%esp
total = 0;
1098: 31 db xor %ebx,%ebx
fd = open(fname, 0);
109a: 6a 00 push $0x0
109c: ff 75 d0 pushl -0x30(%ebp)
109f: e8 3e 28 00 00 call 38e2 <open>
while((n = read(fd, buf, sizeof(buf))) > 0){
10a4: 83 c4 10 add $0x10,%esp
fd = open(fname, 0);
10a7: 89 45 d4 mov %eax,-0x2c(%ebp)
10aa: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
while((n = read(fd, buf, sizeof(buf))) > 0){
10b0: 83 ec 04 sub $0x4,%esp
10b3: 68 00 20 00 00 push $0x2000
10b8: 68 e0 85 00 00 push $0x85e0
10bd: ff 75 d4 pushl -0x2c(%ebp)
10c0: e8 f5 27 00 00 call 38ba <read>
10c5: 83 c4 10 add $0x10,%esp
10c8: 85 c0 test %eax,%eax
10ca: 7e 26 jle 10f2 <fourfiles+0xe2>
for(j = 0; j < n; j++){
10cc: 31 d2 xor %edx,%edx
10ce: 66 90 xchg %ax,%ax
if(buf[j] != '0'+i){
10d0: 0f be b2 e0 85 00 00 movsbl 0x85e0(%edx),%esi
10d7: 83 ff 01 cmp $0x1,%edi
10da: 19 c9 sbb %ecx,%ecx
10dc: 83 c1 31 add $0x31,%ecx
10df: 39 ce cmp %ecx,%esi
10e1: 0f 85 be 00 00 00 jne 11a5 <fourfiles+0x195>
for(j = 0; j < n; j++){
10e7: 83 c2 01 add $0x1,%edx
10ea: 39 d0 cmp %edx,%eax
10ec: 75 e2 jne 10d0 <fourfiles+0xc0>
total += n;
10ee: 01 c3 add %eax,%ebx
10f0: eb be jmp 10b0 <fourfiles+0xa0>
close(fd);
10f2: 83 ec 0c sub $0xc,%esp
10f5: ff 75 d4 pushl -0x2c(%ebp)
10f8: e8 cd 27 00 00 call 38ca <close>
if(total != 12*500){
10fd: 83 c4 10 add $0x10,%esp
1100: 81 fb 70 17 00 00 cmp $0x1770,%ebx
1106: 0f 85 d3 00 00 00 jne 11df <fourfiles+0x1cf>
unlink(fname);
110c: 83 ec 0c sub $0xc,%esp
110f: ff 75 d0 pushl -0x30(%ebp)
1112: e8 db 27 00 00 call 38f2 <unlink>
for(i = 0; i < 2; i++){
1117: 83 c4 10 add $0x10,%esp
111a: 83 ff 01 cmp $0x1,%edi
111d: 75 1a jne 1139 <fourfiles+0x129>
printf(1, "fourfiles ok\n");
111f: 83 ec 08 sub $0x8,%esp
1122: 68 02 42 00 00 push $0x4202
1127: 6a 01 push $0x1
1129: e8 d2 28 00 00 call 3a00 <printf>
}
112e: 83 c4 10 add $0x10,%esp
1131: 8d 65 f4 lea -0xc(%ebp),%esp
1134: 5b pop %ebx
1135: 5e pop %esi
1136: 5f pop %edi
1137: 5d pop %ebp
1138: c3 ret
1139: 8b 45 dc mov -0x24(%ebp),%eax
113c: bf 01 00 00 00 mov $0x1,%edi
1141: 89 45 d0 mov %eax,-0x30(%ebp)
1144: e9 4c ff ff ff jmp 1095 <fourfiles+0x85>
fd = open(fname, O_CREATE | O_RDWR);
1149: 83 ec 08 sub $0x8,%esp
114c: 68 02 02 00 00 push $0x202
1151: 56 push %esi
1152: e8 8b 27 00 00 call 38e2 <open>
if(fd < 0){
1157: 83 c4 10 add $0x10,%esp
115a: 85 c0 test %eax,%eax
fd = open(fname, O_CREATE | O_RDWR);
115c: 89 c6 mov %eax,%esi
if(fd < 0){
115e: 78 59 js 11b9 <fourfiles+0x1a9>
memset(buf, '0'+pi, 512);
1160: 83 ec 04 sub $0x4,%esp
1163: 83 c3 30 add $0x30,%ebx
1166: 68 00 02 00 00 push $0x200
116b: 53 push %ebx
116c: bb 0c 00 00 00 mov $0xc,%ebx
1171: 68 e0 85 00 00 push $0x85e0
1176: e8 85 25 00 00 call 3700 <memset>
117b: 83 c4 10 add $0x10,%esp
if((n = write(fd, buf, 500)) != 500){
117e: 83 ec 04 sub $0x4,%esp
1181: 68 f4 01 00 00 push $0x1f4
1186: 68 e0 85 00 00 push $0x85e0
118b: 56 push %esi
118c: e8 31 27 00 00 call 38c2 <write>
1191: 83 c4 10 add $0x10,%esp
1194: 3d f4 01 00 00 cmp $0x1f4,%eax
1199: 75 57 jne 11f2 <fourfiles+0x1e2>
for(i = 0; i < 12; i++){
119b: 83 eb 01 sub $0x1,%ebx
119e: 75 de jne 117e <fourfiles+0x16e>
exit();
11a0: e8 fd 26 00 00 call 38a2 <exit>
printf(1, "wrong char\n");
11a5: 83 ec 08 sub $0x8,%esp
11a8: 68 e5 41 00 00 push $0x41e5
11ad: 6a 01 push $0x1
11af: e8 4c 28 00 00 call 3a00 <printf>
exit();
11b4: e8 e9 26 00 00 call 38a2 <exit>
printf(1, "create failed\n");
11b9: 51 push %ecx
11ba: 51 push %ecx
11bb: 68 5f 44 00 00 push $0x445f
11c0: 6a 01 push $0x1
11c2: e8 39 28 00 00 call 3a00 <printf>
exit();
11c7: e8 d6 26 00 00 call 38a2 <exit>
printf(1, "fork failed\n");
11cc: 53 push %ebx
11cd: 53 push %ebx
11ce: 68 99 4c 00 00 push $0x4c99
11d3: 6a 01 push $0x1
11d5: e8 26 28 00 00 call 3a00 <printf>
exit();
11da: e8 c3 26 00 00 call 38a2 <exit>
printf(1, "wrong length %d\n", total);
11df: 50 push %eax
11e0: 53 push %ebx
11e1: 68 f1 41 00 00 push $0x41f1
11e6: 6a 01 push $0x1
11e8: e8 13 28 00 00 call 3a00 <printf>
exit();
11ed: e8 b0 26 00 00 call 38a2 <exit>
printf(1, "write failed %d\n", n);
11f2: 52 push %edx
11f3: 50 push %eax
11f4: 68 d4 41 00 00 push $0x41d4
11f9: 6a 01 push $0x1
11fb: e8 00 28 00 00 call 3a00 <printf>
exit();
1200: e8 9d 26 00 00 call 38a2 <exit>
1205: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
1209: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00001210 <createdelete>:
{
1210: 55 push %ebp
1211: 89 e5 mov %esp,%ebp
1213: 57 push %edi
1214: 56 push %esi
1215: 53 push %ebx
for(pi = 0; pi < 4; pi++){
1216: 31 db xor %ebx,%ebx
{
1218: 83 ec 44 sub $0x44,%esp
printf(1, "createdelete test\n");
121b: 68 10 42 00 00 push $0x4210
1220: 6a 01 push $0x1
1222: e8 d9 27 00 00 call 3a00 <printf>
1227: 83 c4 10 add $0x10,%esp
pid = fork();
122a: e8 6b 26 00 00 call 389a <fork>
if(pid < 0){
122f: 85 c0 test %eax,%eax
1231: 0f 88 be 01 00 00 js 13f5 <createdelete+0x1e5>
if(pid == 0){
1237: 0f 84 0b 01 00 00 je 1348 <createdelete+0x138>
for(pi = 0; pi < 4; pi++){
123d: 83 c3 01 add $0x1,%ebx
1240: 83 fb 04 cmp $0x4,%ebx
1243: 75 e5 jne 122a <createdelete+0x1a>
1245: 8d 7d c8 lea -0x38(%ebp),%edi
name[0] = name[1] = name[2] = 0;
1248: be ff ff ff ff mov $0xffffffff,%esi
wait();
124d: e8 58 26 00 00 call 38aa <wait>
1252: e8 53 26 00 00 call 38aa <wait>
1257: e8 4e 26 00 00 call 38aa <wait>
125c: e8 49 26 00 00 call 38aa <wait>
name[0] = name[1] = name[2] = 0;
1261: c6 45 ca 00 movb $0x0,-0x36(%ebp)
1265: 8d 76 00 lea 0x0(%esi),%esi
1268: 8d 46 31 lea 0x31(%esi),%eax
126b: 88 45 c7 mov %al,-0x39(%ebp)
126e: 8d 46 01 lea 0x1(%esi),%eax
1271: 83 f8 09 cmp $0x9,%eax
1274: 89 45 c0 mov %eax,-0x40(%ebp)
1277: 0f 9f c3 setg %bl
127a: 85 c0 test %eax,%eax
127c: 0f 94 c0 sete %al
127f: 09 c3 or %eax,%ebx
1281: 88 5d c6 mov %bl,-0x3a(%ebp)
name[2] = '\0';
1284: bb 70 00 00 00 mov $0x70,%ebx
name[1] = '0' + i;
1289: 0f b6 45 c7 movzbl -0x39(%ebp),%eax
fd = open(name, 0);
128d: 83 ec 08 sub $0x8,%esp
name[0] = 'p' + pi;
1290: 88 5d c8 mov %bl,-0x38(%ebp)
fd = open(name, 0);
1293: 6a 00 push $0x0
1295: 57 push %edi
name[1] = '0' + i;
1296: 88 45 c9 mov %al,-0x37(%ebp)
fd = open(name, 0);
1299: e8 44 26 00 00 call 38e2 <open>
if((i == 0 || i >= N/2) && fd < 0){
129e: 83 c4 10 add $0x10,%esp
12a1: 80 7d c6 00 cmpb $0x0,-0x3a(%ebp)
12a5: 0f 84 85 00 00 00 je 1330 <createdelete+0x120>
12ab: 85 c0 test %eax,%eax
12ad: 0f 88 1a 01 00 00 js 13cd <createdelete+0x1bd>
} else if((i >= 1 && i < N/2) && fd >= 0){
12b3: 83 fe 08 cmp $0x8,%esi
12b6: 0f 86 54 01 00 00 jbe 1410 <createdelete+0x200>
close(fd);
12bc: 83 ec 0c sub $0xc,%esp
12bf: 50 push %eax
12c0: e8 05 26 00 00 call 38ca <close>
12c5: 83 c4 10 add $0x10,%esp
12c8: 83 c3 01 add $0x1,%ebx
for(pi = 0; pi < 4; pi++){
12cb: 80 fb 74 cmp $0x74,%bl
12ce: 75 b9 jne 1289 <createdelete+0x79>
12d0: 8b 75 c0 mov -0x40(%ebp),%esi
for(i = 0; i < N; i++){
12d3: 83 fe 13 cmp $0x13,%esi
12d6: 75 90 jne 1268 <createdelete+0x58>
12d8: be 70 00 00 00 mov $0x70,%esi
12dd: 8d 76 00 lea 0x0(%esi),%esi
12e0: 8d 46 c0 lea -0x40(%esi),%eax
name[0] = name[1] = name[2] = 0;
12e3: bb 04 00 00 00 mov $0x4,%ebx
12e8: 88 45 c7 mov %al,-0x39(%ebp)
name[0] = 'p' + i;
12eb: 89 f0 mov %esi,%eax
unlink(name);
12ed: 83 ec 0c sub $0xc,%esp
name[0] = 'p' + i;
12f0: 88 45 c8 mov %al,-0x38(%ebp)
name[1] = '0' + i;
12f3: 0f b6 45 c7 movzbl -0x39(%ebp),%eax
unlink(name);
12f7: 57 push %edi
name[1] = '0' + i;
12f8: 88 45 c9 mov %al,-0x37(%ebp)
unlink(name);
12fb: e8 f2 25 00 00 call 38f2 <unlink>
for(pi = 0; pi < 4; pi++){
1300: 83 c4 10 add $0x10,%esp
1303: 83 eb 01 sub $0x1,%ebx
1306: 75 e3 jne 12eb <createdelete+0xdb>
1308: 83 c6 01 add $0x1,%esi
for(i = 0; i < N; i++){
130b: 89 f0 mov %esi,%eax
130d: 3c 84 cmp $0x84,%al
130f: 75 cf jne 12e0 <createdelete+0xd0>
printf(1, "createdelete ok\n");
1311: 83 ec 08 sub $0x8,%esp
1314: 68 23 42 00 00 push $0x4223
1319: 6a 01 push $0x1
131b: e8 e0 26 00 00 call 3a00 <printf>
}
1320: 8d 65 f4 lea -0xc(%ebp),%esp
1323: 5b pop %ebx
1324: 5e pop %esi
1325: 5f pop %edi
1326: 5d pop %ebp
1327: c3 ret
1328: 90 nop
1329: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
} else if((i >= 1 && i < N/2) && fd >= 0){
1330: 83 fe 08 cmp $0x8,%esi
1333: 0f 86 cf 00 00 00 jbe 1408 <createdelete+0x1f8>
if(fd >= 0)
1339: 85 c0 test %eax,%eax
133b: 78 8b js 12c8 <createdelete+0xb8>
133d: e9 7a ff ff ff jmp 12bc <createdelete+0xac>
1342: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
name[0] = 'p' + pi;
1348: 83 c3 70 add $0x70,%ebx
name[2] = '\0';
134b: c6 45 ca 00 movb $0x0,-0x36(%ebp)
134f: 8d 7d c8 lea -0x38(%ebp),%edi
name[0] = 'p' + pi;
1352: 88 5d c8 mov %bl,-0x38(%ebp)
name[2] = '\0';
1355: 31 db xor %ebx,%ebx
1357: eb 0f jmp 1368 <createdelete+0x158>
1359: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
for(i = 0; i < N; i++){
1360: 83 fb 13 cmp $0x13,%ebx
1363: 74 63 je 13c8 <createdelete+0x1b8>
1365: 83 c3 01 add $0x1,%ebx
fd = open(name, O_CREATE | O_RDWR);
1368: 83 ec 08 sub $0x8,%esp
name[1] = '0' + i;
136b: 8d 43 30 lea 0x30(%ebx),%eax
fd = open(name, O_CREATE | O_RDWR);
136e: 68 02 02 00 00 push $0x202
1373: 57 push %edi
name[1] = '0' + i;
1374: 88 45 c9 mov %al,-0x37(%ebp)
fd = open(name, O_CREATE | O_RDWR);
1377: e8 66 25 00 00 call 38e2 <open>
if(fd < 0){
137c: 83 c4 10 add $0x10,%esp
137f: 85 c0 test %eax,%eax
1381: 78 5f js 13e2 <createdelete+0x1d2>
close(fd);
1383: 83 ec 0c sub $0xc,%esp
1386: 50 push %eax
1387: e8 3e 25 00 00 call 38ca <close>
if(i > 0 && (i % 2 ) == 0){
138c: 83 c4 10 add $0x10,%esp
138f: 85 db test %ebx,%ebx
1391: 74 d2 je 1365 <createdelete+0x155>
1393: f6 c3 01 test $0x1,%bl
1396: 75 c8 jne 1360 <createdelete+0x150>
if(unlink(name) < 0){
1398: 83 ec 0c sub $0xc,%esp
name[1] = '0' + (i / 2);
139b: 89 d8 mov %ebx,%eax
139d: d1 f8 sar %eax
if(unlink(name) < 0){
139f: 57 push %edi
name[1] = '0' + (i / 2);
13a0: 83 c0 30 add $0x30,%eax
13a3: 88 45 c9 mov %al,-0x37(%ebp)
if(unlink(name) < 0){
13a6: e8 47 25 00 00 call 38f2 <unlink>
13ab: 83 c4 10 add $0x10,%esp
13ae: 85 c0 test %eax,%eax
13b0: 79 ae jns 1360 <createdelete+0x150>
printf(1, "unlink failed\n");
13b2: 52 push %edx
13b3: 52 push %edx
13b4: 68 11 3e 00 00 push $0x3e11
13b9: 6a 01 push $0x1
13bb: e8 40 26 00 00 call 3a00 <printf>
exit();
13c0: e8 dd 24 00 00 call 38a2 <exit>
13c5: 8d 76 00 lea 0x0(%esi),%esi
exit();
13c8: e8 d5 24 00 00 call 38a2 <exit>
printf(1, "oops createdelete %s didn't exist\n", name);
13cd: 83 ec 04 sub $0x4,%esp
13d0: 57 push %edi
13d1: 68 d0 4e 00 00 push $0x4ed0
13d6: 6a 01 push $0x1
13d8: e8 23 26 00 00 call 3a00 <printf>
exit();
13dd: e8 c0 24 00 00 call 38a2 <exit>
printf(1, "create failed\n");
13e2: 51 push %ecx
13e3: 51 push %ecx
13e4: 68 5f 44 00 00 push $0x445f
13e9: 6a 01 push $0x1
13eb: e8 10 26 00 00 call 3a00 <printf>
exit();
13f0: e8 ad 24 00 00 call 38a2 <exit>
printf(1, "fork failed\n");
13f5: 53 push %ebx
13f6: 53 push %ebx
13f7: 68 99 4c 00 00 push $0x4c99
13fc: 6a 01 push $0x1
13fe: e8 fd 25 00 00 call 3a00 <printf>
exit();
1403: e8 9a 24 00 00 call 38a2 <exit>
} else if((i >= 1 && i < N/2) && fd >= 0){
1408: 85 c0 test %eax,%eax
140a: 0f 88 b8 fe ff ff js 12c8 <createdelete+0xb8>
printf(1, "oops createdelete %s did exist\n", name);
1410: 50 push %eax
1411: 57 push %edi
1412: 68 f4 4e 00 00 push $0x4ef4
1417: 6a 01 push $0x1
1419: e8 e2 25 00 00 call 3a00 <printf>
exit();
141e: e8 7f 24 00 00 call 38a2 <exit>
1423: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
1429: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00001430 <unlinkread>:
{
1430: 55 push %ebp
1431: 89 e5 mov %esp,%ebp
1433: 56 push %esi
1434: 53 push %ebx
printf(1, "unlinkread test\n");
1435: 83 ec 08 sub $0x8,%esp
1438: 68 34 42 00 00 push $0x4234
143d: 6a 01 push $0x1
143f: e8 bc 25 00 00 call 3a00 <printf>
fd = open("unlinkread", O_CREATE | O_RDWR);
1444: 5b pop %ebx
1445: 5e pop %esi
1446: 68 02 02 00 00 push $0x202
144b: 68 45 42 00 00 push $0x4245
1450: e8 8d 24 00 00 call 38e2 <open>
if(fd < 0){
1455: 83 c4 10 add $0x10,%esp
1458: 85 c0 test %eax,%eax
145a: 0f 88 e6 00 00 00 js 1546 <unlinkread+0x116>
write(fd, "hello", 5);
1460: 83 ec 04 sub $0x4,%esp
1463: 89 c3 mov %eax,%ebx
1465: 6a 05 push $0x5
1467: 68 6a 42 00 00 push $0x426a
146c: 50 push %eax
146d: e8 50 24 00 00 call 38c2 <write>
close(fd);
1472: 89 1c 24 mov %ebx,(%esp)
1475: e8 50 24 00 00 call 38ca <close>
fd = open("unlinkread", O_RDWR);
147a: 58 pop %eax
147b: 5a pop %edx
147c: 6a 02 push $0x2
147e: 68 45 42 00 00 push $0x4245
1483: e8 5a 24 00 00 call 38e2 <open>
if(fd < 0){
1488: 83 c4 10 add $0x10,%esp
148b: 85 c0 test %eax,%eax
fd = open("unlinkread", O_RDWR);
148d: 89 c3 mov %eax,%ebx
if(fd < 0){
148f: 0f 88 10 01 00 00 js 15a5 <unlinkread+0x175>
if(unlink("unlinkread") != 0){
1495: 83 ec 0c sub $0xc,%esp
1498: 68 45 42 00 00 push $0x4245
149d: e8 50 24 00 00 call 38f2 <unlink>
14a2: 83 c4 10 add $0x10,%esp
14a5: 85 c0 test %eax,%eax
14a7: 0f 85 e5 00 00 00 jne 1592 <unlinkread+0x162>
fd1 = open("unlinkread", O_CREATE | O_RDWR);
14ad: 83 ec 08 sub $0x8,%esp
14b0: 68 02 02 00 00 push $0x202
14b5: 68 45 42 00 00 push $0x4245
14ba: e8 23 24 00 00 call 38e2 <open>
write(fd1, "yyy", 3);
14bf: 83 c4 0c add $0xc,%esp
fd1 = open("unlinkread", O_CREATE | O_RDWR);
14c2: 89 c6 mov %eax,%esi
write(fd1, "yyy", 3);
14c4: 6a 03 push $0x3
14c6: 68 a2 42 00 00 push $0x42a2
14cb: 50 push %eax
14cc: e8 f1 23 00 00 call 38c2 <write>
close(fd1);
14d1: 89 34 24 mov %esi,(%esp)
14d4: e8 f1 23 00 00 call 38ca <close>
if(read(fd, buf, sizeof(buf)) != 5){
14d9: 83 c4 0c add $0xc,%esp
14dc: 68 00 20 00 00 push $0x2000
14e1: 68 e0 85 00 00 push $0x85e0
14e6: 53 push %ebx
14e7: e8 ce 23 00 00 call 38ba <read>
14ec: 83 c4 10 add $0x10,%esp
14ef: 83 f8 05 cmp $0x5,%eax
14f2: 0f 85 87 00 00 00 jne 157f <unlinkread+0x14f>
if(buf[0] != 'h'){
14f8: 80 3d e0 85 00 00 68 cmpb $0x68,0x85e0
14ff: 75 6b jne 156c <unlinkread+0x13c>
if(write(fd, buf, 10) != 10){
1501: 83 ec 04 sub $0x4,%esp
1504: 6a 0a push $0xa
1506: 68 e0 85 00 00 push $0x85e0
150b: 53 push %ebx
150c: e8 b1 23 00 00 call 38c2 <write>
1511: 83 c4 10 add $0x10,%esp
1514: 83 f8 0a cmp $0xa,%eax
1517: 75 40 jne 1559 <unlinkread+0x129>
close(fd);
1519: 83 ec 0c sub $0xc,%esp
151c: 53 push %ebx
151d: e8 a8 23 00 00 call 38ca <close>
unlink("unlinkread");
1522: c7 04 24 45 42 00 00 movl $0x4245,(%esp)
1529: e8 c4 23 00 00 call 38f2 <unlink>
printf(1, "unlinkread ok\n");
152e: 58 pop %eax
152f: 5a pop %edx
1530: 68 ed 42 00 00 push $0x42ed
1535: 6a 01 push $0x1
1537: e8 c4 24 00 00 call 3a00 <printf>
}
153c: 83 c4 10 add $0x10,%esp
153f: 8d 65 f8 lea -0x8(%ebp),%esp
1542: 5b pop %ebx
1543: 5e pop %esi
1544: 5d pop %ebp
1545: c3 ret
printf(1, "create unlinkread failed\n");
1546: 51 push %ecx
1547: 51 push %ecx
1548: 68 50 42 00 00 push $0x4250
154d: 6a 01 push $0x1
154f: e8 ac 24 00 00 call 3a00 <printf>
exit();
1554: e8 49 23 00 00 call 38a2 <exit>
printf(1, "unlinkread write failed\n");
1559: 51 push %ecx
155a: 51 push %ecx
155b: 68 d4 42 00 00 push $0x42d4
1560: 6a 01 push $0x1
1562: e8 99 24 00 00 call 3a00 <printf>
exit();
1567: e8 36 23 00 00 call 38a2 <exit>
printf(1, "unlinkread wrong data\n");
156c: 53 push %ebx
156d: 53 push %ebx
156e: 68 bd 42 00 00 push $0x42bd
1573: 6a 01 push $0x1
1575: e8 86 24 00 00 call 3a00 <printf>
exit();
157a: e8 23 23 00 00 call 38a2 <exit>
printf(1, "unlinkread read failed");
157f: 56 push %esi
1580: 56 push %esi
1581: 68 a6 42 00 00 push $0x42a6
1586: 6a 01 push $0x1
1588: e8 73 24 00 00 call 3a00 <printf>
exit();
158d: e8 10 23 00 00 call 38a2 <exit>
printf(1, "unlink unlinkread failed\n");
1592: 50 push %eax
1593: 50 push %eax
1594: 68 88 42 00 00 push $0x4288
1599: 6a 01 push $0x1
159b: e8 60 24 00 00 call 3a00 <printf>
exit();
15a0: e8 fd 22 00 00 call 38a2 <exit>
printf(1, "open unlinkread failed\n");
15a5: 50 push %eax
15a6: 50 push %eax
15a7: 68 70 42 00 00 push $0x4270
15ac: 6a 01 push $0x1
15ae: e8 4d 24 00 00 call 3a00 <printf>
exit();
15b3: e8 ea 22 00 00 call 38a2 <exit>
15b8: 90 nop
15b9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000015c0 <linktest>:
{
15c0: 55 push %ebp
15c1: 89 e5 mov %esp,%ebp
15c3: 53 push %ebx
15c4: 83 ec 0c sub $0xc,%esp
printf(1, "linktest\n");
15c7: 68 fc 42 00 00 push $0x42fc
15cc: 6a 01 push $0x1
15ce: e8 2d 24 00 00 call 3a00 <printf>
unlink("lf1");
15d3: c7 04 24 06 43 00 00 movl $0x4306,(%esp)
15da: e8 13 23 00 00 call 38f2 <unlink>
unlink("lf2");
15df: c7 04 24 0a 43 00 00 movl $0x430a,(%esp)
15e6: e8 07 23 00 00 call 38f2 <unlink>
fd = open("lf1", O_CREATE|O_RDWR);
15eb: 58 pop %eax
15ec: 5a pop %edx
15ed: 68 02 02 00 00 push $0x202
15f2: 68 06 43 00 00 push $0x4306
15f7: e8 e6 22 00 00 call 38e2 <open>
if(fd < 0){
15fc: 83 c4 10 add $0x10,%esp
15ff: 85 c0 test %eax,%eax
1601: 0f 88 1e 01 00 00 js 1725 <linktest+0x165>
if(write(fd, "hello", 5) != 5){
1607: 83 ec 04 sub $0x4,%esp
160a: 89 c3 mov %eax,%ebx
160c: 6a 05 push $0x5
160e: 68 6a 42 00 00 push $0x426a
1613: 50 push %eax
1614: e8 a9 22 00 00 call 38c2 <write>
1619: 83 c4 10 add $0x10,%esp
161c: 83 f8 05 cmp $0x5,%eax
161f: 0f 85 98 01 00 00 jne 17bd <linktest+0x1fd>
close(fd);
1625: 83 ec 0c sub $0xc,%esp
1628: 53 push %ebx
1629: e8 9c 22 00 00 call 38ca <close>
if(link("lf1", "lf2") < 0){
162e: 5b pop %ebx
162f: 58 pop %eax
1630: 68 0a 43 00 00 push $0x430a
1635: 68 06 43 00 00 push $0x4306
163a: e8 c3 22 00 00 call 3902 <link>
163f: 83 c4 10 add $0x10,%esp
1642: 85 c0 test %eax,%eax
1644: 0f 88 60 01 00 00 js 17aa <linktest+0x1ea>
unlink("lf1");
164a: 83 ec 0c sub $0xc,%esp
164d: 68 06 43 00 00 push $0x4306
1652: e8 9b 22 00 00 call 38f2 <unlink>
if(open("lf1", 0) >= 0){
1657: 58 pop %eax
1658: 5a pop %edx
1659: 6a 00 push $0x0
165b: 68 06 43 00 00 push $0x4306
1660: e8 7d 22 00 00 call 38e2 <open>
1665: 83 c4 10 add $0x10,%esp
1668: 85 c0 test %eax,%eax
166a: 0f 89 27 01 00 00 jns 1797 <linktest+0x1d7>
fd = open("lf2", 0);
1670: 83 ec 08 sub $0x8,%esp
1673: 6a 00 push $0x0
1675: 68 0a 43 00 00 push $0x430a
167a: e8 63 22 00 00 call 38e2 <open>
if(fd < 0){
167f: 83 c4 10 add $0x10,%esp
1682: 85 c0 test %eax,%eax
fd = open("lf2", 0);
1684: 89 c3 mov %eax,%ebx
if(fd < 0){
1686: 0f 88 f8 00 00 00 js 1784 <linktest+0x1c4>
if(read(fd, buf, sizeof(buf)) != 5){
168c: 83 ec 04 sub $0x4,%esp
168f: 68 00 20 00 00 push $0x2000
1694: 68 e0 85 00 00 push $0x85e0
1699: 50 push %eax
169a: e8 1b 22 00 00 call 38ba <read>
169f: 83 c4 10 add $0x10,%esp
16a2: 83 f8 05 cmp $0x5,%eax
16a5: 0f 85 c6 00 00 00 jne 1771 <linktest+0x1b1>
close(fd);
16ab: 83 ec 0c sub $0xc,%esp
16ae: 53 push %ebx
16af: e8 16 22 00 00 call 38ca <close>
if(link("lf2", "lf2") >= 0){
16b4: 58 pop %eax
16b5: 5a pop %edx
16b6: 68 0a 43 00 00 push $0x430a
16bb: 68 0a 43 00 00 push $0x430a
16c0: e8 3d 22 00 00 call 3902 <link>
16c5: 83 c4 10 add $0x10,%esp
16c8: 85 c0 test %eax,%eax
16ca: 0f 89 8e 00 00 00 jns 175e <linktest+0x19e>
unlink("lf2");
16d0: 83 ec 0c sub $0xc,%esp
16d3: 68 0a 43 00 00 push $0x430a
16d8: e8 15 22 00 00 call 38f2 <unlink>
if(link("lf2", "lf1") >= 0){
16dd: 59 pop %ecx
16de: 5b pop %ebx
16df: 68 06 43 00 00 push $0x4306
16e4: 68 0a 43 00 00 push $0x430a
16e9: e8 14 22 00 00 call 3902 <link>
16ee: 83 c4 10 add $0x10,%esp
16f1: 85 c0 test %eax,%eax
16f3: 79 56 jns 174b <linktest+0x18b>
if(link(".", "lf1") >= 0){
16f5: 83 ec 08 sub $0x8,%esp
16f8: 68 06 43 00 00 push $0x4306
16fd: 68 ce 45 00 00 push $0x45ce
1702: e8 fb 21 00 00 call 3902 <link>
1707: 83 c4 10 add $0x10,%esp
170a: 85 c0 test %eax,%eax
170c: 79 2a jns 1738 <linktest+0x178>
printf(1, "linktest ok\n");
170e: 83 ec 08 sub $0x8,%esp
1711: 68 a4 43 00 00 push $0x43a4
1716: 6a 01 push $0x1
1718: e8 e3 22 00 00 call 3a00 <printf>
}
171d: 83 c4 10 add $0x10,%esp
1720: 8b 5d fc mov -0x4(%ebp),%ebx
1723: c9 leave
1724: c3 ret
printf(1, "create lf1 failed\n");
1725: 50 push %eax
1726: 50 push %eax
1727: 68 0e 43 00 00 push $0x430e
172c: 6a 01 push $0x1
172e: e8 cd 22 00 00 call 3a00 <printf>
exit();
1733: e8 6a 21 00 00 call 38a2 <exit>
printf(1, "link . lf1 succeeded! oops\n");
1738: 50 push %eax
1739: 50 push %eax
173a: 68 88 43 00 00 push $0x4388
173f: 6a 01 push $0x1
1741: e8 ba 22 00 00 call 3a00 <printf>
exit();
1746: e8 57 21 00 00 call 38a2 <exit>
printf(1, "link non-existant succeeded! oops\n");
174b: 52 push %edx
174c: 52 push %edx
174d: 68 3c 4f 00 00 push $0x4f3c
1752: 6a 01 push $0x1
1754: e8 a7 22 00 00 call 3a00 <printf>
exit();
1759: e8 44 21 00 00 call 38a2 <exit>
printf(1, "link lf2 lf2 succeeded! oops\n");
175e: 50 push %eax
175f: 50 push %eax
1760: 68 6a 43 00 00 push $0x436a
1765: 6a 01 push $0x1
1767: e8 94 22 00 00 call 3a00 <printf>
exit();
176c: e8 31 21 00 00 call 38a2 <exit>
printf(1, "read lf2 failed\n");
1771: 51 push %ecx
1772: 51 push %ecx
1773: 68 59 43 00 00 push $0x4359
1778: 6a 01 push $0x1
177a: e8 81 22 00 00 call 3a00 <printf>
exit();
177f: e8 1e 21 00 00 call 38a2 <exit>
printf(1, "open lf2 failed\n");
1784: 53 push %ebx
1785: 53 push %ebx
1786: 68 48 43 00 00 push $0x4348
178b: 6a 01 push $0x1
178d: e8 6e 22 00 00 call 3a00 <printf>
exit();
1792: e8 0b 21 00 00 call 38a2 <exit>
printf(1, "unlinked lf1 but it is still there!\n");
1797: 50 push %eax
1798: 50 push %eax
1799: 68 14 4f 00 00 push $0x4f14
179e: 6a 01 push $0x1
17a0: e8 5b 22 00 00 call 3a00 <printf>
exit();
17a5: e8 f8 20 00 00 call 38a2 <exit>
printf(1, "link lf1 lf2 failed\n");
17aa: 51 push %ecx
17ab: 51 push %ecx
17ac: 68 33 43 00 00 push $0x4333
17b1: 6a 01 push $0x1
17b3: e8 48 22 00 00 call 3a00 <printf>
exit();
17b8: e8 e5 20 00 00 call 38a2 <exit>
printf(1, "write lf1 failed\n");
17bd: 50 push %eax
17be: 50 push %eax
17bf: 68 21 43 00 00 push $0x4321
17c4: 6a 01 push $0x1
17c6: e8 35 22 00 00 call 3a00 <printf>
exit();
17cb: e8 d2 20 00 00 call 38a2 <exit>
000017d0 <concreate>:
{
17d0: 55 push %ebp
17d1: 89 e5 mov %esp,%ebp
17d3: 57 push %edi
17d4: 56 push %esi
17d5: 53 push %ebx
for(i = 0; i < 40; i++){
17d6: 31 f6 xor %esi,%esi
17d8: 8d 5d ad lea -0x53(%ebp),%ebx
if(pid && (i % 3) == 1){
17db: bf ab aa aa aa mov $0xaaaaaaab,%edi
{
17e0: 83 ec 64 sub $0x64,%esp
printf(1, "concreate test\n");
17e3: 68 b1 43 00 00 push $0x43b1
17e8: 6a 01 push $0x1
17ea: e8 11 22 00 00 call 3a00 <printf>
file[0] = 'C';
17ef: c6 45 ad 43 movb $0x43,-0x53(%ebp)
file[2] = '\0';
17f3: c6 45 af 00 movb $0x0,-0x51(%ebp)
17f7: 83 c4 10 add $0x10,%esp
17fa: eb 4c jmp 1848 <concreate+0x78>
17fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
if(pid && (i % 3) == 1){
1800: 89 f0 mov %esi,%eax
1802: 89 f1 mov %esi,%ecx
1804: f7 e7 mul %edi
1806: d1 ea shr %edx
1808: 8d 04 52 lea (%edx,%edx,2),%eax
180b: 29 c1 sub %eax,%ecx
180d: 83 f9 01 cmp $0x1,%ecx
1810: 0f 84 ba 00 00 00 je 18d0 <concreate+0x100>
fd = open(file, O_CREATE | O_RDWR);
1816: 83 ec 08 sub $0x8,%esp
1819: 68 02 02 00 00 push $0x202
181e: 53 push %ebx
181f: e8 be 20 00 00 call 38e2 <open>
if(fd < 0){
1824: 83 c4 10 add $0x10,%esp
1827: 85 c0 test %eax,%eax
1829: 78 67 js 1892 <concreate+0xc2>
close(fd);
182b: 83 ec 0c sub $0xc,%esp
for(i = 0; i < 40; i++){
182e: 83 c6 01 add $0x1,%esi
close(fd);
1831: 50 push %eax
1832: e8 93 20 00 00 call 38ca <close>
1837: 83 c4 10 add $0x10,%esp
wait();
183a: e8 6b 20 00 00 call 38aa <wait>
for(i = 0; i < 40; i++){
183f: 83 fe 28 cmp $0x28,%esi
1842: 0f 84 aa 00 00 00 je 18f2 <concreate+0x122>
unlink(file);
1848: 83 ec 0c sub $0xc,%esp
file[1] = '0' + i;
184b: 8d 46 30 lea 0x30(%esi),%eax
unlink(file);
184e: 53 push %ebx
file[1] = '0' + i;
184f: 88 45 ae mov %al,-0x52(%ebp)
unlink(file);
1852: e8 9b 20 00 00 call 38f2 <unlink>
pid = fork();
1857: e8 3e 20 00 00 call 389a <fork>
if(pid && (i % 3) == 1){
185c: 83 c4 10 add $0x10,%esp
185f: 85 c0 test %eax,%eax
1861: 75 9d jne 1800 <concreate+0x30>
} else if(pid == 0 && (i % 5) == 1){
1863: 89 f0 mov %esi,%eax
1865: ba cd cc cc cc mov $0xcccccccd,%edx
186a: f7 e2 mul %edx
186c: c1 ea 02 shr $0x2,%edx
186f: 8d 04 92 lea (%edx,%edx,4),%eax
1872: 29 c6 sub %eax,%esi
1874: 83 fe 01 cmp $0x1,%esi
1877: 74 37 je 18b0 <concreate+0xe0>
fd = open(file, O_CREATE | O_RDWR);
1879: 83 ec 08 sub $0x8,%esp
187c: 68 02 02 00 00 push $0x202
1881: 53 push %ebx
1882: e8 5b 20 00 00 call 38e2 <open>
if(fd < 0){
1887: 83 c4 10 add $0x10,%esp
188a: 85 c0 test %eax,%eax
188c: 0f 89 28 02 00 00 jns 1aba <concreate+0x2ea>
printf(1, "concreate create %s failed\n", file);
1892: 83 ec 04 sub $0x4,%esp
1895: 53 push %ebx
1896: 68 c4 43 00 00 push $0x43c4
189b: 6a 01 push $0x1
189d: e8 5e 21 00 00 call 3a00 <printf>
exit();
18a2: e8 fb 1f 00 00 call 38a2 <exit>
18a7: 89 f6 mov %esi,%esi
18a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
link("C0", file);
18b0: 83 ec 08 sub $0x8,%esp
18b3: 53 push %ebx
18b4: 68 c1 43 00 00 push $0x43c1
18b9: e8 44 20 00 00 call 3902 <link>
18be: 83 c4 10 add $0x10,%esp
exit();
18c1: e8 dc 1f 00 00 call 38a2 <exit>
18c6: 8d 76 00 lea 0x0(%esi),%esi
18c9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
link("C0", file);
18d0: 83 ec 08 sub $0x8,%esp
for(i = 0; i < 40; i++){
18d3: 83 c6 01 add $0x1,%esi
link("C0", file);
18d6: 53 push %ebx
18d7: 68 c1 43 00 00 push $0x43c1
18dc: e8 21 20 00 00 call 3902 <link>
18e1: 83 c4 10 add $0x10,%esp
wait();
18e4: e8 c1 1f 00 00 call 38aa <wait>
for(i = 0; i < 40; i++){
18e9: 83 fe 28 cmp $0x28,%esi
18ec: 0f 85 56 ff ff ff jne 1848 <concreate+0x78>
memset(fa, 0, sizeof(fa));
18f2: 8d 45 c0 lea -0x40(%ebp),%eax
18f5: 83 ec 04 sub $0x4,%esp
18f8: 6a 28 push $0x28
18fa: 6a 00 push $0x0
18fc: 50 push %eax
18fd: e8 fe 1d 00 00 call 3700 <memset>
fd = open(".", 0);
1902: 5f pop %edi
1903: 58 pop %eax
1904: 6a 00 push $0x0
1906: 68 ce 45 00 00 push $0x45ce
190b: 8d 7d b0 lea -0x50(%ebp),%edi
190e: e8 cf 1f 00 00 call 38e2 <open>
while(read(fd, &de, sizeof(de)) > 0){
1913: 83 c4 10 add $0x10,%esp
fd = open(".", 0);
1916: 89 c6 mov %eax,%esi
n = 0;
1918: c7 45 a4 00 00 00 00 movl $0x0,-0x5c(%ebp)
191f: 90 nop
while(read(fd, &de, sizeof(de)) > 0){
1920: 83 ec 04 sub $0x4,%esp
1923: 6a 10 push $0x10
1925: 57 push %edi
1926: 56 push %esi
1927: e8 8e 1f 00 00 call 38ba <read>
192c: 83 c4 10 add $0x10,%esp
192f: 85 c0 test %eax,%eax
1931: 7e 3d jle 1970 <concreate+0x1a0>
if(de.inum == 0)
1933: 66 83 7d b0 00 cmpw $0x0,-0x50(%ebp)
1938: 74 e6 je 1920 <concreate+0x150>
if(de.name[0] == 'C' && de.name[2] == '\0'){
193a: 80 7d b2 43 cmpb $0x43,-0x4e(%ebp)
193e: 75 e0 jne 1920 <concreate+0x150>
1940: 80 7d b4 00 cmpb $0x0,-0x4c(%ebp)
1944: 75 da jne 1920 <concreate+0x150>
i = de.name[1] - '0';
1946: 0f be 45 b3 movsbl -0x4d(%ebp),%eax
194a: 83 e8 30 sub $0x30,%eax
if(i < 0 || i >= sizeof(fa)){
194d: 83 f8 27 cmp $0x27,%eax
1950: 0f 87 4e 01 00 00 ja 1aa4 <concreate+0x2d4>
if(fa[i]){
1956: 80 7c 05 c0 00 cmpb $0x0,-0x40(%ebp,%eax,1)
195b: 0f 85 2d 01 00 00 jne 1a8e <concreate+0x2be>
fa[i] = 1;
1961: c6 44 05 c0 01 movb $0x1,-0x40(%ebp,%eax,1)
n++;
1966: 83 45 a4 01 addl $0x1,-0x5c(%ebp)
196a: eb b4 jmp 1920 <concreate+0x150>
196c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
close(fd);
1970: 83 ec 0c sub $0xc,%esp
1973: 56 push %esi
1974: e8 51 1f 00 00 call 38ca <close>
if(n != 40){
1979: 83 c4 10 add $0x10,%esp
197c: 83 7d a4 28 cmpl $0x28,-0x5c(%ebp)
1980: 0f 85 f5 00 00 00 jne 1a7b <concreate+0x2ab>
for(i = 0; i < 40; i++){
1986: 31 f6 xor %esi,%esi
1988: eb 48 jmp 19d2 <concreate+0x202>
198a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
((i % 3) == 1 && pid != 0)){
1990: 85 ff test %edi,%edi
1992: 74 05 je 1999 <concreate+0x1c9>
1994: 83 fa 01 cmp $0x1,%edx
1997: 74 64 je 19fd <concreate+0x22d>
unlink(file);
1999: 83 ec 0c sub $0xc,%esp
199c: 53 push %ebx
199d: e8 50 1f 00 00 call 38f2 <unlink>
unlink(file);
19a2: 89 1c 24 mov %ebx,(%esp)
19a5: e8 48 1f 00 00 call 38f2 <unlink>
unlink(file);
19aa: 89 1c 24 mov %ebx,(%esp)
19ad: e8 40 1f 00 00 call 38f2 <unlink>
unlink(file);
19b2: 89 1c 24 mov %ebx,(%esp)
19b5: e8 38 1f 00 00 call 38f2 <unlink>
19ba: 83 c4 10 add $0x10,%esp
if(pid == 0)
19bd: 85 ff test %edi,%edi
19bf: 0f 84 fc fe ff ff je 18c1 <concreate+0xf1>
for(i = 0; i < 40; i++){
19c5: 83 c6 01 add $0x1,%esi
wait();
19c8: e8 dd 1e 00 00 call 38aa <wait>
for(i = 0; i < 40; i++){
19cd: 83 fe 28 cmp $0x28,%esi
19d0: 74 7e je 1a50 <concreate+0x280>
file[1] = '0' + i;
19d2: 8d 46 30 lea 0x30(%esi),%eax
19d5: 88 45 ae mov %al,-0x52(%ebp)
pid = fork();
19d8: e8 bd 1e 00 00 call 389a <fork>
if(pid < 0){
19dd: 85 c0 test %eax,%eax
pid = fork();
19df: 89 c7 mov %eax,%edi
if(pid < 0){
19e1: 0f 88 80 00 00 00 js 1a67 <concreate+0x297>
if(((i % 3) == 0 && pid == 0) ||
19e7: b8 ab aa aa aa mov $0xaaaaaaab,%eax
19ec: f7 e6 mul %esi
19ee: d1 ea shr %edx
19f0: 8d 04 52 lea (%edx,%edx,2),%eax
19f3: 89 f2 mov %esi,%edx
19f5: 29 c2 sub %eax,%edx
19f7: 89 d0 mov %edx,%eax
19f9: 09 f8 or %edi,%eax
19fb: 75 93 jne 1990 <concreate+0x1c0>
close(open(file, 0));
19fd: 83 ec 08 sub $0x8,%esp
1a00: 6a 00 push $0x0
1a02: 53 push %ebx
1a03: e8 da 1e 00 00 call 38e2 <open>
1a08: 89 04 24 mov %eax,(%esp)
1a0b: e8 ba 1e 00 00 call 38ca <close>
close(open(file, 0));
1a10: 58 pop %eax
1a11: 5a pop %edx
1a12: 6a 00 push $0x0
1a14: 53 push %ebx
1a15: e8 c8 1e 00 00 call 38e2 <open>
1a1a: 89 04 24 mov %eax,(%esp)
1a1d: e8 a8 1e 00 00 call 38ca <close>
close(open(file, 0));
1a22: 59 pop %ecx
1a23: 58 pop %eax
1a24: 6a 00 push $0x0
1a26: 53 push %ebx
1a27: e8 b6 1e 00 00 call 38e2 <open>
1a2c: 89 04 24 mov %eax,(%esp)
1a2f: e8 96 1e 00 00 call 38ca <close>
close(open(file, 0));
1a34: 58 pop %eax
1a35: 5a pop %edx
1a36: 6a 00 push $0x0
1a38: 53 push %ebx
1a39: e8 a4 1e 00 00 call 38e2 <open>
1a3e: 89 04 24 mov %eax,(%esp)
1a41: e8 84 1e 00 00 call 38ca <close>
1a46: 83 c4 10 add $0x10,%esp
1a49: e9 6f ff ff ff jmp 19bd <concreate+0x1ed>
1a4e: 66 90 xchg %ax,%ax
printf(1, "concreate ok\n");
1a50: 83 ec 08 sub $0x8,%esp
1a53: 68 16 44 00 00 push $0x4416
1a58: 6a 01 push $0x1
1a5a: e8 a1 1f 00 00 call 3a00 <printf>
}
1a5f: 8d 65 f4 lea -0xc(%ebp),%esp
1a62: 5b pop %ebx
1a63: 5e pop %esi
1a64: 5f pop %edi
1a65: 5d pop %ebp
1a66: c3 ret
printf(1, "fork failed\n");
1a67: 83 ec 08 sub $0x8,%esp
1a6a: 68 99 4c 00 00 push $0x4c99
1a6f: 6a 01 push $0x1
1a71: e8 8a 1f 00 00 call 3a00 <printf>
exit();
1a76: e8 27 1e 00 00 call 38a2 <exit>
printf(1, "concreate not enough files in directory listing\n");
1a7b: 51 push %ecx
1a7c: 51 push %ecx
1a7d: 68 60 4f 00 00 push $0x4f60
1a82: 6a 01 push $0x1
1a84: e8 77 1f 00 00 call 3a00 <printf>
exit();
1a89: e8 14 1e 00 00 call 38a2 <exit>
printf(1, "concreate duplicate file %s\n", de.name);
1a8e: 8d 45 b2 lea -0x4e(%ebp),%eax
1a91: 53 push %ebx
1a92: 50 push %eax
1a93: 68 f9 43 00 00 push $0x43f9
1a98: 6a 01 push $0x1
1a9a: e8 61 1f 00 00 call 3a00 <printf>
exit();
1a9f: e8 fe 1d 00 00 call 38a2 <exit>
printf(1, "concreate weird file %s\n", de.name);
1aa4: 8d 45 b2 lea -0x4e(%ebp),%eax
1aa7: 56 push %esi
1aa8: 50 push %eax
1aa9: 68 e0 43 00 00 push $0x43e0
1aae: 6a 01 push $0x1
1ab0: e8 4b 1f 00 00 call 3a00 <printf>
exit();
1ab5: e8 e8 1d 00 00 call 38a2 <exit>
close(fd);
1aba: 83 ec 0c sub $0xc,%esp
1abd: 50 push %eax
1abe: e8 07 1e 00 00 call 38ca <close>
1ac3: 83 c4 10 add $0x10,%esp
1ac6: e9 f6 fd ff ff jmp 18c1 <concreate+0xf1>
1acb: 90 nop
1acc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00001ad0 <linkunlink>:
{
1ad0: 55 push %ebp
1ad1: 89 e5 mov %esp,%ebp
1ad3: 57 push %edi
1ad4: 56 push %esi
1ad5: 53 push %ebx
1ad6: 83 ec 24 sub $0x24,%esp
printf(1, "linkunlink test\n");
1ad9: 68 24 44 00 00 push $0x4424
1ade: 6a 01 push $0x1
1ae0: e8 1b 1f 00 00 call 3a00 <printf>
unlink("x");
1ae5: c7 04 24 b1 46 00 00 movl $0x46b1,(%esp)
1aec: e8 01 1e 00 00 call 38f2 <unlink>
pid = fork();
1af1: e8 a4 1d 00 00 call 389a <fork>
if(pid < 0){
1af6: 83 c4 10 add $0x10,%esp
1af9: 85 c0 test %eax,%eax
pid = fork();
1afb: 89 45 e4 mov %eax,-0x1c(%ebp)
if(pid < 0){
1afe: 0f 88 b6 00 00 00 js 1bba <linkunlink+0xea>
unsigned int x = (pid ? 1 : 97);
1b04: 83 7d e4 01 cmpl $0x1,-0x1c(%ebp)
1b08: bb 64 00 00 00 mov $0x64,%ebx
if((x % 3) == 0){
1b0d: be ab aa aa aa mov $0xaaaaaaab,%esi
unsigned int x = (pid ? 1 : 97);
1b12: 19 ff sbb %edi,%edi
1b14: 83 e7 60 and $0x60,%edi
1b17: 83 c7 01 add $0x1,%edi
1b1a: eb 1e jmp 1b3a <linkunlink+0x6a>
1b1c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
} else if((x % 3) == 1){
1b20: 83 fa 01 cmp $0x1,%edx
1b23: 74 7b je 1ba0 <linkunlink+0xd0>
unlink("x");
1b25: 83 ec 0c sub $0xc,%esp
1b28: 68 b1 46 00 00 push $0x46b1
1b2d: e8 c0 1d 00 00 call 38f2 <unlink>
1b32: 83 c4 10 add $0x10,%esp
for(i = 0; i < 100; i++){
1b35: 83 eb 01 sub $0x1,%ebx
1b38: 74 3d je 1b77 <linkunlink+0xa7>
x = x * 1103515245 + 12345;
1b3a: 69 cf 6d 4e c6 41 imul $0x41c64e6d,%edi,%ecx
1b40: 8d b9 39 30 00 00 lea 0x3039(%ecx),%edi
if((x % 3) == 0){
1b46: 89 f8 mov %edi,%eax
1b48: f7 e6 mul %esi
1b4a: d1 ea shr %edx
1b4c: 8d 04 52 lea (%edx,%edx,2),%eax
1b4f: 89 fa mov %edi,%edx
1b51: 29 c2 sub %eax,%edx
1b53: 75 cb jne 1b20 <linkunlink+0x50>
close(open("x", O_RDWR | O_CREATE));
1b55: 83 ec 08 sub $0x8,%esp
1b58: 68 02 02 00 00 push $0x202
1b5d: 68 b1 46 00 00 push $0x46b1
1b62: e8 7b 1d 00 00 call 38e2 <open>
1b67: 89 04 24 mov %eax,(%esp)
1b6a: e8 5b 1d 00 00 call 38ca <close>
1b6f: 83 c4 10 add $0x10,%esp
for(i = 0; i < 100; i++){
1b72: 83 eb 01 sub $0x1,%ebx
1b75: 75 c3 jne 1b3a <linkunlink+0x6a>
if(pid)
1b77: 8b 45 e4 mov -0x1c(%ebp),%eax
1b7a: 85 c0 test %eax,%eax
1b7c: 74 4f je 1bcd <linkunlink+0xfd>
wait();
1b7e: e8 27 1d 00 00 call 38aa <wait>
printf(1, "linkunlink ok\n");
1b83: 83 ec 08 sub $0x8,%esp
1b86: 68 39 44 00 00 push $0x4439
1b8b: 6a 01 push $0x1
1b8d: e8 6e 1e 00 00 call 3a00 <printf>
}
1b92: 8d 65 f4 lea -0xc(%ebp),%esp
1b95: 5b pop %ebx
1b96: 5e pop %esi
1b97: 5f pop %edi
1b98: 5d pop %ebp
1b99: c3 ret
1b9a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
link("cat", "x");
1ba0: 83 ec 08 sub $0x8,%esp
1ba3: 68 b1 46 00 00 push $0x46b1
1ba8: 68 35 44 00 00 push $0x4435
1bad: e8 50 1d 00 00 call 3902 <link>
1bb2: 83 c4 10 add $0x10,%esp
1bb5: e9 7b ff ff ff jmp 1b35 <linkunlink+0x65>
printf(1, "fork failed\n");
1bba: 52 push %edx
1bbb: 52 push %edx
1bbc: 68 99 4c 00 00 push $0x4c99
1bc1: 6a 01 push $0x1
1bc3: e8 38 1e 00 00 call 3a00 <printf>
exit();
1bc8: e8 d5 1c 00 00 call 38a2 <exit>
exit();
1bcd: e8 d0 1c 00 00 call 38a2 <exit>
1bd2: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
1bd9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00001be0 <bigdir>:
{
1be0: 55 push %ebp
1be1: 89 e5 mov %esp,%ebp
1be3: 57 push %edi
1be4: 56 push %esi
1be5: 53 push %ebx
1be6: 83 ec 24 sub $0x24,%esp
printf(1, "bigdir test\n");
1be9: 68 48 44 00 00 push $0x4448
1bee: 6a 01 push $0x1
1bf0: e8 0b 1e 00 00 call 3a00 <printf>
unlink("bd");
1bf5: c7 04 24 55 44 00 00 movl $0x4455,(%esp)
1bfc: e8 f1 1c 00 00 call 38f2 <unlink>
fd = open("bd", O_CREATE);
1c01: 5a pop %edx
1c02: 59 pop %ecx
1c03: 68 00 02 00 00 push $0x200
1c08: 68 55 44 00 00 push $0x4455
1c0d: e8 d0 1c 00 00 call 38e2 <open>
if(fd < 0){
1c12: 83 c4 10 add $0x10,%esp
1c15: 85 c0 test %eax,%eax
1c17: 0f 88 de 00 00 00 js 1cfb <bigdir+0x11b>
close(fd);
1c1d: 83 ec 0c sub $0xc,%esp
1c20: 8d 7d de lea -0x22(%ebp),%edi
for(i = 0; i < 500; i++){
1c23: 31 f6 xor %esi,%esi
close(fd);
1c25: 50 push %eax
1c26: e8 9f 1c 00 00 call 38ca <close>
1c2b: 83 c4 10 add $0x10,%esp
1c2e: 66 90 xchg %ax,%ax
name[1] = '0' + (i / 64);
1c30: 89 f0 mov %esi,%eax
if(link("bd", name) != 0){
1c32: 83 ec 08 sub $0x8,%esp
name[0] = 'x';
1c35: c6 45 de 78 movb $0x78,-0x22(%ebp)
name[1] = '0' + (i / 64);
1c39: c1 f8 06 sar $0x6,%eax
if(link("bd", name) != 0){
1c3c: 57 push %edi
1c3d: 68 55 44 00 00 push $0x4455
name[1] = '0' + (i / 64);
1c42: 83 c0 30 add $0x30,%eax
name[3] = '\0';
1c45: c6 45 e1 00 movb $0x0,-0x1f(%ebp)
name[1] = '0' + (i / 64);
1c49: 88 45 df mov %al,-0x21(%ebp)
name[2] = '0' + (i % 64);
1c4c: 89 f0 mov %esi,%eax
1c4e: 83 e0 3f and $0x3f,%eax
1c51: 83 c0 30 add $0x30,%eax
1c54: 88 45 e0 mov %al,-0x20(%ebp)
if(link("bd", name) != 0){
1c57: e8 a6 1c 00 00 call 3902 <link>
1c5c: 83 c4 10 add $0x10,%esp
1c5f: 85 c0 test %eax,%eax
1c61: 89 c3 mov %eax,%ebx
1c63: 75 6e jne 1cd3 <bigdir+0xf3>
for(i = 0; i < 500; i++){
1c65: 83 c6 01 add $0x1,%esi
1c68: 81 fe f4 01 00 00 cmp $0x1f4,%esi
1c6e: 75 c0 jne 1c30 <bigdir+0x50>
unlink("bd");
1c70: 83 ec 0c sub $0xc,%esp
1c73: 68 55 44 00 00 push $0x4455
1c78: e8 75 1c 00 00 call 38f2 <unlink>
1c7d: 83 c4 10 add $0x10,%esp
name[1] = '0' + (i / 64);
1c80: 89 d8 mov %ebx,%eax
if(unlink(name) != 0){
1c82: 83 ec 0c sub $0xc,%esp
name[0] = 'x';
1c85: c6 45 de 78 movb $0x78,-0x22(%ebp)
name[1] = '0' + (i / 64);
1c89: c1 f8 06 sar $0x6,%eax
if(unlink(name) != 0){
1c8c: 57 push %edi
name[3] = '\0';
1c8d: c6 45 e1 00 movb $0x0,-0x1f(%ebp)
name[1] = '0' + (i / 64);
1c91: 83 c0 30 add $0x30,%eax
1c94: 88 45 df mov %al,-0x21(%ebp)
name[2] = '0' + (i % 64);
1c97: 89 d8 mov %ebx,%eax
1c99: 83 e0 3f and $0x3f,%eax
1c9c: 83 c0 30 add $0x30,%eax
1c9f: 88 45 e0 mov %al,-0x20(%ebp)
if(unlink(name) != 0){
1ca2: e8 4b 1c 00 00 call 38f2 <unlink>
1ca7: 83 c4 10 add $0x10,%esp
1caa: 85 c0 test %eax,%eax
1cac: 75 39 jne 1ce7 <bigdir+0x107>
for(i = 0; i < 500; i++){
1cae: 83 c3 01 add $0x1,%ebx
1cb1: 81 fb f4 01 00 00 cmp $0x1f4,%ebx
1cb7: 75 c7 jne 1c80 <bigdir+0xa0>
printf(1, "bigdir ok\n");
1cb9: 83 ec 08 sub $0x8,%esp
1cbc: 68 97 44 00 00 push $0x4497
1cc1: 6a 01 push $0x1
1cc3: e8 38 1d 00 00 call 3a00 <printf>
}
1cc8: 83 c4 10 add $0x10,%esp
1ccb: 8d 65 f4 lea -0xc(%ebp),%esp
1cce: 5b pop %ebx
1ccf: 5e pop %esi
1cd0: 5f pop %edi
1cd1: 5d pop %ebp
1cd2: c3 ret
printf(1, "bigdir link failed\n");
1cd3: 83 ec 08 sub $0x8,%esp
1cd6: 68 6e 44 00 00 push $0x446e
1cdb: 6a 01 push $0x1
1cdd: e8 1e 1d 00 00 call 3a00 <printf>
exit();
1ce2: e8 bb 1b 00 00 call 38a2 <exit>
printf(1, "bigdir unlink failed");
1ce7: 83 ec 08 sub $0x8,%esp
1cea: 68 82 44 00 00 push $0x4482
1cef: 6a 01 push $0x1
1cf1: e8 0a 1d 00 00 call 3a00 <printf>
exit();
1cf6: e8 a7 1b 00 00 call 38a2 <exit>
printf(1, "bigdir create failed\n");
1cfb: 50 push %eax
1cfc: 50 push %eax
1cfd: 68 58 44 00 00 push $0x4458
1d02: 6a 01 push $0x1
1d04: e8 f7 1c 00 00 call 3a00 <printf>
exit();
1d09: e8 94 1b 00 00 call 38a2 <exit>
1d0e: 66 90 xchg %ax,%ax
00001d10 <subdir>:
{
1d10: 55 push %ebp
1d11: 89 e5 mov %esp,%ebp
1d13: 53 push %ebx
1d14: 83 ec 0c sub $0xc,%esp
printf(1, "subdir test\n");
1d17: 68 a2 44 00 00 push $0x44a2
1d1c: 6a 01 push $0x1
1d1e: e8 dd 1c 00 00 call 3a00 <printf>
unlink("ff");
1d23: c7 04 24 2b 45 00 00 movl $0x452b,(%esp)
1d2a: e8 c3 1b 00 00 call 38f2 <unlink>
if(mkdir("dd") != 0){
1d2f: c7 04 24 c8 45 00 00 movl $0x45c8,(%esp)
1d36: e8 cf 1b 00 00 call 390a <mkdir>
1d3b: 83 c4 10 add $0x10,%esp
1d3e: 85 c0 test %eax,%eax
1d40: 0f 85 b3 05 00 00 jne 22f9 <subdir+0x5e9>
fd = open("dd/ff", O_CREATE | O_RDWR);
1d46: 83 ec 08 sub $0x8,%esp
1d49: 68 02 02 00 00 push $0x202
1d4e: 68 01 45 00 00 push $0x4501
1d53: e8 8a 1b 00 00 call 38e2 <open>
if(fd < 0){
1d58: 83 c4 10 add $0x10,%esp
1d5b: 85 c0 test %eax,%eax
fd = open("dd/ff", O_CREATE | O_RDWR);
1d5d: 89 c3 mov %eax,%ebx
if(fd < 0){
1d5f: 0f 88 81 05 00 00 js 22e6 <subdir+0x5d6>
write(fd, "ff", 2);
1d65: 83 ec 04 sub $0x4,%esp
1d68: 6a 02 push $0x2
1d6a: 68 2b 45 00 00 push $0x452b
1d6f: 50 push %eax
1d70: e8 4d 1b 00 00 call 38c2 <write>
close(fd);
1d75: 89 1c 24 mov %ebx,(%esp)
1d78: e8 4d 1b 00 00 call 38ca <close>
if(unlink("dd") >= 0){
1d7d: c7 04 24 c8 45 00 00 movl $0x45c8,(%esp)
1d84: e8 69 1b 00 00 call 38f2 <unlink>
1d89: 83 c4 10 add $0x10,%esp
1d8c: 85 c0 test %eax,%eax
1d8e: 0f 89 3f 05 00 00 jns 22d3 <subdir+0x5c3>
if(mkdir("/dd/dd") != 0){
1d94: 83 ec 0c sub $0xc,%esp
1d97: 68 dc 44 00 00 push $0x44dc
1d9c: e8 69 1b 00 00 call 390a <mkdir>
1da1: 83 c4 10 add $0x10,%esp
1da4: 85 c0 test %eax,%eax
1da6: 0f 85 14 05 00 00 jne 22c0 <subdir+0x5b0>
fd = open("dd/dd/ff", O_CREATE | O_RDWR);
1dac: 83 ec 08 sub $0x8,%esp
1daf: 68 02 02 00 00 push $0x202
1db4: 68 fe 44 00 00 push $0x44fe
1db9: e8 24 1b 00 00 call 38e2 <open>
if(fd < 0){
1dbe: 83 c4 10 add $0x10,%esp
1dc1: 85 c0 test %eax,%eax
fd = open("dd/dd/ff", O_CREATE | O_RDWR);
1dc3: 89 c3 mov %eax,%ebx
if(fd < 0){
1dc5: 0f 88 24 04 00 00 js 21ef <subdir+0x4df>
write(fd, "FF", 2);
1dcb: 83 ec 04 sub $0x4,%esp
1dce: 6a 02 push $0x2
1dd0: 68 1f 45 00 00 push $0x451f
1dd5: 50 push %eax
1dd6: e8 e7 1a 00 00 call 38c2 <write>
close(fd);
1ddb: 89 1c 24 mov %ebx,(%esp)
1dde: e8 e7 1a 00 00 call 38ca <close>
fd = open("dd/dd/../ff", 0);
1de3: 58 pop %eax
1de4: 5a pop %edx
1de5: 6a 00 push $0x0
1de7: 68 22 45 00 00 push $0x4522
1dec: e8 f1 1a 00 00 call 38e2 <open>
if(fd < 0){
1df1: 83 c4 10 add $0x10,%esp
1df4: 85 c0 test %eax,%eax
fd = open("dd/dd/../ff", 0);
1df6: 89 c3 mov %eax,%ebx
if(fd < 0){
1df8: 0f 88 de 03 00 00 js 21dc <subdir+0x4cc>
cc = read(fd, buf, sizeof(buf));
1dfe: 83 ec 04 sub $0x4,%esp
1e01: 68 00 20 00 00 push $0x2000
1e06: 68 e0 85 00 00 push $0x85e0
1e0b: 50 push %eax
1e0c: e8 a9 1a 00 00 call 38ba <read>
if(cc != 2 || buf[0] != 'f'){
1e11: 83 c4 10 add $0x10,%esp
1e14: 83 f8 02 cmp $0x2,%eax
1e17: 0f 85 3a 03 00 00 jne 2157 <subdir+0x447>
1e1d: 80 3d e0 85 00 00 66 cmpb $0x66,0x85e0
1e24: 0f 85 2d 03 00 00 jne 2157 <subdir+0x447>
close(fd);
1e2a: 83 ec 0c sub $0xc,%esp
1e2d: 53 push %ebx
1e2e: e8 97 1a 00 00 call 38ca <close>
if(link("dd/dd/ff", "dd/dd/ffff") != 0){
1e33: 5b pop %ebx
1e34: 58 pop %eax
1e35: 68 62 45 00 00 push $0x4562
1e3a: 68 fe 44 00 00 push $0x44fe
1e3f: e8 be 1a 00 00 call 3902 <link>
1e44: 83 c4 10 add $0x10,%esp
1e47: 85 c0 test %eax,%eax
1e49: 0f 85 c6 03 00 00 jne 2215 <subdir+0x505>
if(unlink("dd/dd/ff") != 0){
1e4f: 83 ec 0c sub $0xc,%esp
1e52: 68 fe 44 00 00 push $0x44fe
1e57: e8 96 1a 00 00 call 38f2 <unlink>
1e5c: 83 c4 10 add $0x10,%esp
1e5f: 85 c0 test %eax,%eax
1e61: 0f 85 16 03 00 00 jne 217d <subdir+0x46d>
if(open("dd/dd/ff", O_RDONLY) >= 0){
1e67: 83 ec 08 sub $0x8,%esp
1e6a: 6a 00 push $0x0
1e6c: 68 fe 44 00 00 push $0x44fe
1e71: e8 6c 1a 00 00 call 38e2 <open>
1e76: 83 c4 10 add $0x10,%esp
1e79: 85 c0 test %eax,%eax
1e7b: 0f 89 2c 04 00 00 jns 22ad <subdir+0x59d>
if(chdir("dd") != 0){
1e81: 83 ec 0c sub $0xc,%esp
1e84: 68 c8 45 00 00 push $0x45c8
1e89: e8 84 1a 00 00 call 3912 <chdir>
1e8e: 83 c4 10 add $0x10,%esp
1e91: 85 c0 test %eax,%eax
1e93: 0f 85 01 04 00 00 jne 229a <subdir+0x58a>
if(chdir("dd/../../dd") != 0){
1e99: 83 ec 0c sub $0xc,%esp
1e9c: 68 96 45 00 00 push $0x4596
1ea1: e8 6c 1a 00 00 call 3912 <chdir>
1ea6: 83 c4 10 add $0x10,%esp
1ea9: 85 c0 test %eax,%eax
1eab: 0f 85 b9 02 00 00 jne 216a <subdir+0x45a>
if(chdir("dd/../../../dd") != 0){
1eb1: 83 ec 0c sub $0xc,%esp
1eb4: 68 bc 45 00 00 push $0x45bc
1eb9: e8 54 1a 00 00 call 3912 <chdir>
1ebe: 83 c4 10 add $0x10,%esp
1ec1: 85 c0 test %eax,%eax
1ec3: 0f 85 a1 02 00 00 jne 216a <subdir+0x45a>
if(chdir("./..") != 0){
1ec9: 83 ec 0c sub $0xc,%esp
1ecc: 68 cb 45 00 00 push $0x45cb
1ed1: e8 3c 1a 00 00 call 3912 <chdir>
1ed6: 83 c4 10 add $0x10,%esp
1ed9: 85 c0 test %eax,%eax
1edb: 0f 85 21 03 00 00 jne 2202 <subdir+0x4f2>
fd = open("dd/dd/ffff", 0);
1ee1: 83 ec 08 sub $0x8,%esp
1ee4: 6a 00 push $0x0
1ee6: 68 62 45 00 00 push $0x4562
1eeb: e8 f2 19 00 00 call 38e2 <open>
if(fd < 0){
1ef0: 83 c4 10 add $0x10,%esp
1ef3: 85 c0 test %eax,%eax
fd = open("dd/dd/ffff", 0);
1ef5: 89 c3 mov %eax,%ebx
if(fd < 0){
1ef7: 0f 88 e0 04 00 00 js 23dd <subdir+0x6cd>
if(read(fd, buf, sizeof(buf)) != 2){
1efd: 83 ec 04 sub $0x4,%esp
1f00: 68 00 20 00 00 push $0x2000
1f05: 68 e0 85 00 00 push $0x85e0
1f0a: 50 push %eax
1f0b: e8 aa 19 00 00 call 38ba <read>
1f10: 83 c4 10 add $0x10,%esp
1f13: 83 f8 02 cmp $0x2,%eax
1f16: 0f 85 ae 04 00 00 jne 23ca <subdir+0x6ba>
close(fd);
1f1c: 83 ec 0c sub $0xc,%esp
1f1f: 53 push %ebx
1f20: e8 a5 19 00 00 call 38ca <close>
if(open("dd/dd/ff", O_RDONLY) >= 0){
1f25: 59 pop %ecx
1f26: 5b pop %ebx
1f27: 6a 00 push $0x0
1f29: 68 fe 44 00 00 push $0x44fe
1f2e: e8 af 19 00 00 call 38e2 <open>
1f33: 83 c4 10 add $0x10,%esp
1f36: 85 c0 test %eax,%eax
1f38: 0f 89 65 02 00 00 jns 21a3 <subdir+0x493>
if(open("dd/ff/ff", O_CREATE|O_RDWR) >= 0){
1f3e: 83 ec 08 sub $0x8,%esp
1f41: 68 02 02 00 00 push $0x202
1f46: 68 16 46 00 00 push $0x4616
1f4b: e8 92 19 00 00 call 38e2 <open>
1f50: 83 c4 10 add $0x10,%esp
1f53: 85 c0 test %eax,%eax
1f55: 0f 89 35 02 00 00 jns 2190 <subdir+0x480>
if(open("dd/xx/ff", O_CREATE|O_RDWR) >= 0){
1f5b: 83 ec 08 sub $0x8,%esp
1f5e: 68 02 02 00 00 push $0x202
1f63: 68 3b 46 00 00 push $0x463b
1f68: e8 75 19 00 00 call 38e2 <open>
1f6d: 83 c4 10 add $0x10,%esp
1f70: 85 c0 test %eax,%eax
1f72: 0f 89 0f 03 00 00 jns 2287 <subdir+0x577>
if(open("dd", O_CREATE) >= 0){
1f78: 83 ec 08 sub $0x8,%esp
1f7b: 68 00 02 00 00 push $0x200
1f80: 68 c8 45 00 00 push $0x45c8
1f85: e8 58 19 00 00 call 38e2 <open>
1f8a: 83 c4 10 add $0x10,%esp
1f8d: 85 c0 test %eax,%eax
1f8f: 0f 89 df 02 00 00 jns 2274 <subdir+0x564>
if(open("dd", O_RDWR) >= 0){
1f95: 83 ec 08 sub $0x8,%esp
1f98: 6a 02 push $0x2
1f9a: 68 c8 45 00 00 push $0x45c8
1f9f: e8 3e 19 00 00 call 38e2 <open>
1fa4: 83 c4 10 add $0x10,%esp
1fa7: 85 c0 test %eax,%eax
1fa9: 0f 89 b2 02 00 00 jns 2261 <subdir+0x551>
if(open("dd", O_WRONLY) >= 0){
1faf: 83 ec 08 sub $0x8,%esp
1fb2: 6a 01 push $0x1
1fb4: 68 c8 45 00 00 push $0x45c8
1fb9: e8 24 19 00 00 call 38e2 <open>
1fbe: 83 c4 10 add $0x10,%esp
1fc1: 85 c0 test %eax,%eax
1fc3: 0f 89 85 02 00 00 jns 224e <subdir+0x53e>
if(link("dd/ff/ff", "dd/dd/xx") == 0){
1fc9: 83 ec 08 sub $0x8,%esp
1fcc: 68 aa 46 00 00 push $0x46aa
1fd1: 68 16 46 00 00 push $0x4616
1fd6: e8 27 19 00 00 call 3902 <link>
1fdb: 83 c4 10 add $0x10,%esp
1fde: 85 c0 test %eax,%eax
1fe0: 0f 84 55 02 00 00 je 223b <subdir+0x52b>
if(link("dd/xx/ff", "dd/dd/xx") == 0){
1fe6: 83 ec 08 sub $0x8,%esp
1fe9: 68 aa 46 00 00 push $0x46aa
1fee: 68 3b 46 00 00 push $0x463b
1ff3: e8 0a 19 00 00 call 3902 <link>
1ff8: 83 c4 10 add $0x10,%esp
1ffb: 85 c0 test %eax,%eax
1ffd: 0f 84 25 02 00 00 je 2228 <subdir+0x518>
if(link("dd/ff", "dd/dd/ffff") == 0){
2003: 83 ec 08 sub $0x8,%esp
2006: 68 62 45 00 00 push $0x4562
200b: 68 01 45 00 00 push $0x4501
2010: e8 ed 18 00 00 call 3902 <link>
2015: 83 c4 10 add $0x10,%esp
2018: 85 c0 test %eax,%eax
201a: 0f 84 a9 01 00 00 je 21c9 <subdir+0x4b9>
if(mkdir("dd/ff/ff") == 0){
2020: 83 ec 0c sub $0xc,%esp
2023: 68 16 46 00 00 push $0x4616
2028: e8 dd 18 00 00 call 390a <mkdir>
202d: 83 c4 10 add $0x10,%esp
2030: 85 c0 test %eax,%eax
2032: 0f 84 7e 01 00 00 je 21b6 <subdir+0x4a6>
if(mkdir("dd/xx/ff") == 0){
2038: 83 ec 0c sub $0xc,%esp
203b: 68 3b 46 00 00 push $0x463b
2040: e8 c5 18 00 00 call 390a <mkdir>
2045: 83 c4 10 add $0x10,%esp
2048: 85 c0 test %eax,%eax
204a: 0f 84 67 03 00 00 je 23b7 <subdir+0x6a7>
if(mkdir("dd/dd/ffff") == 0){
2050: 83 ec 0c sub $0xc,%esp
2053: 68 62 45 00 00 push $0x4562
2058: e8 ad 18 00 00 call 390a <mkdir>
205d: 83 c4 10 add $0x10,%esp
2060: 85 c0 test %eax,%eax
2062: 0f 84 3c 03 00 00 je 23a4 <subdir+0x694>
if(unlink("dd/xx/ff") == 0){
2068: 83 ec 0c sub $0xc,%esp
206b: 68 3b 46 00 00 push $0x463b
2070: e8 7d 18 00 00 call 38f2 <unlink>
2075: 83 c4 10 add $0x10,%esp
2078: 85 c0 test %eax,%eax
207a: 0f 84 11 03 00 00 je 2391 <subdir+0x681>
if(unlink("dd/ff/ff") == 0){
2080: 83 ec 0c sub $0xc,%esp
2083: 68 16 46 00 00 push $0x4616
2088: e8 65 18 00 00 call 38f2 <unlink>
208d: 83 c4 10 add $0x10,%esp
2090: 85 c0 test %eax,%eax
2092: 0f 84 e6 02 00 00 je 237e <subdir+0x66e>
if(chdir("dd/ff") == 0){
2098: 83 ec 0c sub $0xc,%esp
209b: 68 01 45 00 00 push $0x4501
20a0: e8 6d 18 00 00 call 3912 <chdir>
20a5: 83 c4 10 add $0x10,%esp
20a8: 85 c0 test %eax,%eax
20aa: 0f 84 bb 02 00 00 je 236b <subdir+0x65b>
if(chdir("dd/xx") == 0){
20b0: 83 ec 0c sub $0xc,%esp
20b3: 68 ad 46 00 00 push $0x46ad
20b8: e8 55 18 00 00 call 3912 <chdir>
20bd: 83 c4 10 add $0x10,%esp
20c0: 85 c0 test %eax,%eax
20c2: 0f 84 90 02 00 00 je 2358 <subdir+0x648>
if(unlink("dd/dd/ffff") != 0){
20c8: 83 ec 0c sub $0xc,%esp
20cb: 68 62 45 00 00 push $0x4562
20d0: e8 1d 18 00 00 call 38f2 <unlink>
20d5: 83 c4 10 add $0x10,%esp
20d8: 85 c0 test %eax,%eax
20da: 0f 85 9d 00 00 00 jne 217d <subdir+0x46d>
if(unlink("dd/ff") != 0){
20e0: 83 ec 0c sub $0xc,%esp
20e3: 68 01 45 00 00 push $0x4501
20e8: e8 05 18 00 00 call 38f2 <unlink>
20ed: 83 c4 10 add $0x10,%esp
20f0: 85 c0 test %eax,%eax
20f2: 0f 85 4d 02 00 00 jne 2345 <subdir+0x635>
if(unlink("dd") == 0){
20f8: 83 ec 0c sub $0xc,%esp
20fb: 68 c8 45 00 00 push $0x45c8
2100: e8 ed 17 00 00 call 38f2 <unlink>
2105: 83 c4 10 add $0x10,%esp
2108: 85 c0 test %eax,%eax
210a: 0f 84 22 02 00 00 je 2332 <subdir+0x622>
if(unlink("dd/dd") < 0){
2110: 83 ec 0c sub $0xc,%esp
2113: 68 dd 44 00 00 push $0x44dd
2118: e8 d5 17 00 00 call 38f2 <unlink>
211d: 83 c4 10 add $0x10,%esp
2120: 85 c0 test %eax,%eax
2122: 0f 88 f7 01 00 00 js 231f <subdir+0x60f>
if(unlink("dd") < 0){
2128: 83 ec 0c sub $0xc,%esp
212b: 68 c8 45 00 00 push $0x45c8
2130: e8 bd 17 00 00 call 38f2 <unlink>
2135: 83 c4 10 add $0x10,%esp
2138: 85 c0 test %eax,%eax
213a: 0f 88 cc 01 00 00 js 230c <subdir+0x5fc>
printf(1, "subdir ok\n");
2140: 83 ec 08 sub $0x8,%esp
2143: 68 aa 47 00 00 push $0x47aa
2148: 6a 01 push $0x1
214a: e8 b1 18 00 00 call 3a00 <printf>
}
214f: 83 c4 10 add $0x10,%esp
2152: 8b 5d fc mov -0x4(%ebp),%ebx
2155: c9 leave
2156: c3 ret
printf(1, "dd/dd/../ff wrong content\n");
2157: 50 push %eax
2158: 50 push %eax
2159: 68 47 45 00 00 push $0x4547
215e: 6a 01 push $0x1
2160: e8 9b 18 00 00 call 3a00 <printf>
exit();
2165: e8 38 17 00 00 call 38a2 <exit>
printf(1, "chdir dd/../../dd failed\n");
216a: 50 push %eax
216b: 50 push %eax
216c: 68 a2 45 00 00 push $0x45a2
2171: 6a 01 push $0x1
2173: e8 88 18 00 00 call 3a00 <printf>
exit();
2178: e8 25 17 00 00 call 38a2 <exit>
printf(1, "unlink dd/dd/ff failed\n");
217d: 52 push %edx
217e: 52 push %edx
217f: 68 6d 45 00 00 push $0x456d
2184: 6a 01 push $0x1
2186: e8 75 18 00 00 call 3a00 <printf>
exit();
218b: e8 12 17 00 00 call 38a2 <exit>
printf(1, "create dd/ff/ff succeeded!\n");
2190: 50 push %eax
2191: 50 push %eax
2192: 68 1f 46 00 00 push $0x461f
2197: 6a 01 push $0x1
2199: e8 62 18 00 00 call 3a00 <printf>
exit();
219e: e8 ff 16 00 00 call 38a2 <exit>
printf(1, "open (unlinked) dd/dd/ff succeeded!\n");
21a3: 52 push %edx
21a4: 52 push %edx
21a5: 68 04 50 00 00 push $0x5004
21aa: 6a 01 push $0x1
21ac: e8 4f 18 00 00 call 3a00 <printf>
exit();
21b1: e8 ec 16 00 00 call 38a2 <exit>
printf(1, "mkdir dd/ff/ff succeeded!\n");
21b6: 52 push %edx
21b7: 52 push %edx
21b8: 68 b3 46 00 00 push $0x46b3
21bd: 6a 01 push $0x1
21bf: e8 3c 18 00 00 call 3a00 <printf>
exit();
21c4: e8 d9 16 00 00 call 38a2 <exit>
printf(1, "link dd/ff dd/dd/ffff succeeded!\n");
21c9: 51 push %ecx
21ca: 51 push %ecx
21cb: 68 74 50 00 00 push $0x5074
21d0: 6a 01 push $0x1
21d2: e8 29 18 00 00 call 3a00 <printf>
exit();
21d7: e8 c6 16 00 00 call 38a2 <exit>
printf(1, "open dd/dd/../ff failed\n");
21dc: 50 push %eax
21dd: 50 push %eax
21de: 68 2e 45 00 00 push $0x452e
21e3: 6a 01 push $0x1
21e5: e8 16 18 00 00 call 3a00 <printf>
exit();
21ea: e8 b3 16 00 00 call 38a2 <exit>
printf(1, "create dd/dd/ff failed\n");
21ef: 51 push %ecx
21f0: 51 push %ecx
21f1: 68 07 45 00 00 push $0x4507
21f6: 6a 01 push $0x1
21f8: e8 03 18 00 00 call 3a00 <printf>
exit();
21fd: e8 a0 16 00 00 call 38a2 <exit>
printf(1, "chdir ./.. failed\n");
2202: 50 push %eax
2203: 50 push %eax
2204: 68 d0 45 00 00 push $0x45d0
2209: 6a 01 push $0x1
220b: e8 f0 17 00 00 call 3a00 <printf>
exit();
2210: e8 8d 16 00 00 call 38a2 <exit>
printf(1, "link dd/dd/ff dd/dd/ffff failed\n");
2215: 51 push %ecx
2216: 51 push %ecx
2217: 68 bc 4f 00 00 push $0x4fbc
221c: 6a 01 push $0x1
221e: e8 dd 17 00 00 call 3a00 <printf>
exit();
2223: e8 7a 16 00 00 call 38a2 <exit>
printf(1, "link dd/xx/ff dd/dd/xx succeeded!\n");
2228: 53 push %ebx
2229: 53 push %ebx
222a: 68 50 50 00 00 push $0x5050
222f: 6a 01 push $0x1
2231: e8 ca 17 00 00 call 3a00 <printf>
exit();
2236: e8 67 16 00 00 call 38a2 <exit>
printf(1, "link dd/ff/ff dd/dd/xx succeeded!\n");
223b: 50 push %eax
223c: 50 push %eax
223d: 68 2c 50 00 00 push $0x502c
2242: 6a 01 push $0x1
2244: e8 b7 17 00 00 call 3a00 <printf>
exit();
2249: e8 54 16 00 00 call 38a2 <exit>
printf(1, "open dd wronly succeeded!\n");
224e: 50 push %eax
224f: 50 push %eax
2250: 68 8f 46 00 00 push $0x468f
2255: 6a 01 push $0x1
2257: e8 a4 17 00 00 call 3a00 <printf>
exit();
225c: e8 41 16 00 00 call 38a2 <exit>
printf(1, "open dd rdwr succeeded!\n");
2261: 50 push %eax
2262: 50 push %eax
2263: 68 76 46 00 00 push $0x4676
2268: 6a 01 push $0x1
226a: e8 91 17 00 00 call 3a00 <printf>
exit();
226f: e8 2e 16 00 00 call 38a2 <exit>
printf(1, "create dd succeeded!\n");
2274: 50 push %eax
2275: 50 push %eax
2276: 68 60 46 00 00 push $0x4660
227b: 6a 01 push $0x1
227d: e8 7e 17 00 00 call 3a00 <printf>
exit();
2282: e8 1b 16 00 00 call 38a2 <exit>
printf(1, "create dd/xx/ff succeeded!\n");
2287: 50 push %eax
2288: 50 push %eax
2289: 68 44 46 00 00 push $0x4644
228e: 6a 01 push $0x1
2290: e8 6b 17 00 00 call 3a00 <printf>
exit();
2295: e8 08 16 00 00 call 38a2 <exit>
printf(1, "chdir dd failed\n");
229a: 50 push %eax
229b: 50 push %eax
229c: 68 85 45 00 00 push $0x4585
22a1: 6a 01 push $0x1
22a3: e8 58 17 00 00 call 3a00 <printf>
exit();
22a8: e8 f5 15 00 00 call 38a2 <exit>
printf(1, "open (unlinked) dd/dd/ff succeeded\n");
22ad: 50 push %eax
22ae: 50 push %eax
22af: 68 e0 4f 00 00 push $0x4fe0
22b4: 6a 01 push $0x1
22b6: e8 45 17 00 00 call 3a00 <printf>
exit();
22bb: e8 e2 15 00 00 call 38a2 <exit>
printf(1, "subdir mkdir dd/dd failed\n");
22c0: 53 push %ebx
22c1: 53 push %ebx
22c2: 68 e3 44 00 00 push $0x44e3
22c7: 6a 01 push $0x1
22c9: e8 32 17 00 00 call 3a00 <printf>
exit();
22ce: e8 cf 15 00 00 call 38a2 <exit>
printf(1, "unlink dd (non-empty dir) succeeded!\n");
22d3: 50 push %eax
22d4: 50 push %eax
22d5: 68 94 4f 00 00 push $0x4f94
22da: 6a 01 push $0x1
22dc: e8 1f 17 00 00 call 3a00 <printf>
exit();
22e1: e8 bc 15 00 00 call 38a2 <exit>
printf(1, "create dd/ff failed\n");
22e6: 50 push %eax
22e7: 50 push %eax
22e8: 68 c7 44 00 00 push $0x44c7
22ed: 6a 01 push $0x1
22ef: e8 0c 17 00 00 call 3a00 <printf>
exit();
22f4: e8 a9 15 00 00 call 38a2 <exit>
printf(1, "subdir mkdir dd failed\n");
22f9: 50 push %eax
22fa: 50 push %eax
22fb: 68 af 44 00 00 push $0x44af
2300: 6a 01 push $0x1
2302: e8 f9 16 00 00 call 3a00 <printf>
exit();
2307: e8 96 15 00 00 call 38a2 <exit>
printf(1, "unlink dd failed\n");
230c: 50 push %eax
230d: 50 push %eax
230e: 68 98 47 00 00 push $0x4798
2313: 6a 01 push $0x1
2315: e8 e6 16 00 00 call 3a00 <printf>
exit();
231a: e8 83 15 00 00 call 38a2 <exit>
printf(1, "unlink dd/dd failed\n");
231f: 52 push %edx
2320: 52 push %edx
2321: 68 83 47 00 00 push $0x4783
2326: 6a 01 push $0x1
2328: e8 d3 16 00 00 call 3a00 <printf>
exit();
232d: e8 70 15 00 00 call 38a2 <exit>
printf(1, "unlink non-empty dd succeeded!\n");
2332: 51 push %ecx
2333: 51 push %ecx
2334: 68 98 50 00 00 push $0x5098
2339: 6a 01 push $0x1
233b: e8 c0 16 00 00 call 3a00 <printf>
exit();
2340: e8 5d 15 00 00 call 38a2 <exit>
printf(1, "unlink dd/ff failed\n");
2345: 53 push %ebx
2346: 53 push %ebx
2347: 68 6e 47 00 00 push $0x476e
234c: 6a 01 push $0x1
234e: e8 ad 16 00 00 call 3a00 <printf>
exit();
2353: e8 4a 15 00 00 call 38a2 <exit>
printf(1, "chdir dd/xx succeeded!\n");
2358: 50 push %eax
2359: 50 push %eax
235a: 68 56 47 00 00 push $0x4756
235f: 6a 01 push $0x1
2361: e8 9a 16 00 00 call 3a00 <printf>
exit();
2366: e8 37 15 00 00 call 38a2 <exit>
printf(1, "chdir dd/ff succeeded!\n");
236b: 50 push %eax
236c: 50 push %eax
236d: 68 3e 47 00 00 push $0x473e
2372: 6a 01 push $0x1
2374: e8 87 16 00 00 call 3a00 <printf>
exit();
2379: e8 24 15 00 00 call 38a2 <exit>
printf(1, "unlink dd/ff/ff succeeded!\n");
237e: 50 push %eax
237f: 50 push %eax
2380: 68 22 47 00 00 push $0x4722
2385: 6a 01 push $0x1
2387: e8 74 16 00 00 call 3a00 <printf>
exit();
238c: e8 11 15 00 00 call 38a2 <exit>
printf(1, "unlink dd/xx/ff succeeded!\n");
2391: 50 push %eax
2392: 50 push %eax
2393: 68 06 47 00 00 push $0x4706
2398: 6a 01 push $0x1
239a: e8 61 16 00 00 call 3a00 <printf>
exit();
239f: e8 fe 14 00 00 call 38a2 <exit>
printf(1, "mkdir dd/dd/ffff succeeded!\n");
23a4: 50 push %eax
23a5: 50 push %eax
23a6: 68 e9 46 00 00 push $0x46e9
23ab: 6a 01 push $0x1
23ad: e8 4e 16 00 00 call 3a00 <printf>
exit();
23b2: e8 eb 14 00 00 call 38a2 <exit>
printf(1, "mkdir dd/xx/ff succeeded!\n");
23b7: 50 push %eax
23b8: 50 push %eax
23b9: 68 ce 46 00 00 push $0x46ce
23be: 6a 01 push $0x1
23c0: e8 3b 16 00 00 call 3a00 <printf>
exit();
23c5: e8 d8 14 00 00 call 38a2 <exit>
printf(1, "read dd/dd/ffff wrong len\n");
23ca: 50 push %eax
23cb: 50 push %eax
23cc: 68 fb 45 00 00 push $0x45fb
23d1: 6a 01 push $0x1
23d3: e8 28 16 00 00 call 3a00 <printf>
exit();
23d8: e8 c5 14 00 00 call 38a2 <exit>
printf(1, "open dd/dd/ffff failed\n");
23dd: 50 push %eax
23de: 50 push %eax
23df: 68 e3 45 00 00 push $0x45e3
23e4: 6a 01 push $0x1
23e6: e8 15 16 00 00 call 3a00 <printf>
exit();
23eb: e8 b2 14 00 00 call 38a2 <exit>
000023f0 <bigwrite>:
{
23f0: 55 push %ebp
23f1: 89 e5 mov %esp,%ebp
23f3: 56 push %esi
23f4: 53 push %ebx
for(sz = 499; sz < 12*512; sz += 471){
23f5: bb f3 01 00 00 mov $0x1f3,%ebx
printf(1, "bigwrite test\n");
23fa: 83 ec 08 sub $0x8,%esp
23fd: 68 b5 47 00 00 push $0x47b5
2402: 6a 01 push $0x1
2404: e8 f7 15 00 00 call 3a00 <printf>
unlink("bigwrite");
2409: c7 04 24 c4 47 00 00 movl $0x47c4,(%esp)
2410: e8 dd 14 00 00 call 38f2 <unlink>
2415: 83 c4 10 add $0x10,%esp
2418: 90 nop
2419: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
fd = open("bigwrite", O_CREATE | O_RDWR);
2420: 83 ec 08 sub $0x8,%esp
2423: 68 02 02 00 00 push $0x202
2428: 68 c4 47 00 00 push $0x47c4
242d: e8 b0 14 00 00 call 38e2 <open>
if(fd < 0){
2432: 83 c4 10 add $0x10,%esp
2435: 85 c0 test %eax,%eax
fd = open("bigwrite", O_CREATE | O_RDWR);
2437: 89 c6 mov %eax,%esi
if(fd < 0){
2439: 78 7e js 24b9 <bigwrite+0xc9>
int cc = write(fd, buf, sz);
243b: 83 ec 04 sub $0x4,%esp
243e: 53 push %ebx
243f: 68 e0 85 00 00 push $0x85e0
2444: 50 push %eax
2445: e8 78 14 00 00 call 38c2 <write>
if(cc != sz){
244a: 83 c4 10 add $0x10,%esp
244d: 39 d8 cmp %ebx,%eax
244f: 75 55 jne 24a6 <bigwrite+0xb6>
int cc = write(fd, buf, sz);
2451: 83 ec 04 sub $0x4,%esp
2454: 53 push %ebx
2455: 68 e0 85 00 00 push $0x85e0
245a: 56 push %esi
245b: e8 62 14 00 00 call 38c2 <write>
if(cc != sz){
2460: 83 c4 10 add $0x10,%esp
2463: 39 d8 cmp %ebx,%eax
2465: 75 3f jne 24a6 <bigwrite+0xb6>
close(fd);
2467: 83 ec 0c sub $0xc,%esp
for(sz = 499; sz < 12*512; sz += 471){
246a: 81 c3 d7 01 00 00 add $0x1d7,%ebx
close(fd);
2470: 56 push %esi
2471: e8 54 14 00 00 call 38ca <close>
unlink("bigwrite");
2476: c7 04 24 c4 47 00 00 movl $0x47c4,(%esp)
247d: e8 70 14 00 00 call 38f2 <unlink>
for(sz = 499; sz < 12*512; sz += 471){
2482: 83 c4 10 add $0x10,%esp
2485: 81 fb 07 18 00 00 cmp $0x1807,%ebx
248b: 75 93 jne 2420 <bigwrite+0x30>
printf(1, "bigwrite ok\n");
248d: 83 ec 08 sub $0x8,%esp
2490: 68 f7 47 00 00 push $0x47f7
2495: 6a 01 push $0x1
2497: e8 64 15 00 00 call 3a00 <printf>
}
249c: 83 c4 10 add $0x10,%esp
249f: 8d 65 f8 lea -0x8(%ebp),%esp
24a2: 5b pop %ebx
24a3: 5e pop %esi
24a4: 5d pop %ebp
24a5: c3 ret
printf(1, "write(%d) ret %d\n", sz, cc);
24a6: 50 push %eax
24a7: 53 push %ebx
24a8: 68 e5 47 00 00 push $0x47e5
24ad: 6a 01 push $0x1
24af: e8 4c 15 00 00 call 3a00 <printf>
exit();
24b4: e8 e9 13 00 00 call 38a2 <exit>
printf(1, "cannot create bigwrite\n");
24b9: 83 ec 08 sub $0x8,%esp
24bc: 68 cd 47 00 00 push $0x47cd
24c1: 6a 01 push $0x1
24c3: e8 38 15 00 00 call 3a00 <printf>
exit();
24c8: e8 d5 13 00 00 call 38a2 <exit>
24cd: 8d 76 00 lea 0x0(%esi),%esi
000024d0 <bigfile>:
{
24d0: 55 push %ebp
24d1: 89 e5 mov %esp,%ebp
24d3: 57 push %edi
24d4: 56 push %esi
24d5: 53 push %ebx
24d6: 83 ec 14 sub $0x14,%esp
printf(1, "bigfile test\n");
24d9: 68 04 48 00 00 push $0x4804
24de: 6a 01 push $0x1
24e0: e8 1b 15 00 00 call 3a00 <printf>
unlink("bigfile");
24e5: c7 04 24 20 48 00 00 movl $0x4820,(%esp)
24ec: e8 01 14 00 00 call 38f2 <unlink>
fd = open("bigfile", O_CREATE | O_RDWR);
24f1: 58 pop %eax
24f2: 5a pop %edx
24f3: 68 02 02 00 00 push $0x202
24f8: 68 20 48 00 00 push $0x4820
24fd: e8 e0 13 00 00 call 38e2 <open>
if(fd < 0){
2502: 83 c4 10 add $0x10,%esp
2505: 85 c0 test %eax,%eax
2507: 0f 88 5e 01 00 00 js 266b <bigfile+0x19b>
250d: 89 c6 mov %eax,%esi
for(i = 0; i < 20; i++){
250f: 31 db xor %ebx,%ebx
2511: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
memset(buf, i, 600);
2518: 83 ec 04 sub $0x4,%esp
251b: 68 58 02 00 00 push $0x258
2520: 53 push %ebx
2521: 68 e0 85 00 00 push $0x85e0
2526: e8 d5 11 00 00 call 3700 <memset>
if(write(fd, buf, 600) != 600){
252b: 83 c4 0c add $0xc,%esp
252e: 68 58 02 00 00 push $0x258
2533: 68 e0 85 00 00 push $0x85e0
2538: 56 push %esi
2539: e8 84 13 00 00 call 38c2 <write>
253e: 83 c4 10 add $0x10,%esp
2541: 3d 58 02 00 00 cmp $0x258,%eax
2546: 0f 85 f8 00 00 00 jne 2644 <bigfile+0x174>
for(i = 0; i < 20; i++){
254c: 83 c3 01 add $0x1,%ebx
254f: 83 fb 14 cmp $0x14,%ebx
2552: 75 c4 jne 2518 <bigfile+0x48>
close(fd);
2554: 83 ec 0c sub $0xc,%esp
2557: 56 push %esi
2558: e8 6d 13 00 00 call 38ca <close>
fd = open("bigfile", 0);
255d: 5e pop %esi
255e: 5f pop %edi
255f: 6a 00 push $0x0
2561: 68 20 48 00 00 push $0x4820
2566: e8 77 13 00 00 call 38e2 <open>
if(fd < 0){
256b: 83 c4 10 add $0x10,%esp
256e: 85 c0 test %eax,%eax
fd = open("bigfile", 0);
2570: 89 c6 mov %eax,%esi
if(fd < 0){
2572: 0f 88 e0 00 00 00 js 2658 <bigfile+0x188>
total = 0;
2578: 31 db xor %ebx,%ebx
for(i = 0; ; i++){
257a: 31 ff xor %edi,%edi
257c: eb 30 jmp 25ae <bigfile+0xde>
257e: 66 90 xchg %ax,%ax
if(cc != 300){
2580: 3d 2c 01 00 00 cmp $0x12c,%eax
2585: 0f 85 91 00 00 00 jne 261c <bigfile+0x14c>
if(buf[0] != i/2 || buf[299] != i/2){
258b: 0f be 05 e0 85 00 00 movsbl 0x85e0,%eax
2592: 89 fa mov %edi,%edx
2594: d1 fa sar %edx
2596: 39 d0 cmp %edx,%eax
2598: 75 6e jne 2608 <bigfile+0x138>
259a: 0f be 15 0b 87 00 00 movsbl 0x870b,%edx
25a1: 39 d0 cmp %edx,%eax
25a3: 75 63 jne 2608 <bigfile+0x138>
total += cc;
25a5: 81 c3 2c 01 00 00 add $0x12c,%ebx
for(i = 0; ; i++){
25ab: 83 c7 01 add $0x1,%edi
cc = read(fd, buf, 300);
25ae: 83 ec 04 sub $0x4,%esp
25b1: 68 2c 01 00 00 push $0x12c
25b6: 68 e0 85 00 00 push $0x85e0
25bb: 56 push %esi
25bc: e8 f9 12 00 00 call 38ba <read>
if(cc < 0){
25c1: 83 c4 10 add $0x10,%esp
25c4: 85 c0 test %eax,%eax
25c6: 78 68 js 2630 <bigfile+0x160>
if(cc == 0)
25c8: 75 b6 jne 2580 <bigfile+0xb0>
close(fd);
25ca: 83 ec 0c sub $0xc,%esp
25cd: 56 push %esi
25ce: e8 f7 12 00 00 call 38ca <close>
if(total != 20*600){
25d3: 83 c4 10 add $0x10,%esp
25d6: 81 fb e0 2e 00 00 cmp $0x2ee0,%ebx
25dc: 0f 85 9c 00 00 00 jne 267e <bigfile+0x1ae>
unlink("bigfile");
25e2: 83 ec 0c sub $0xc,%esp
25e5: 68 20 48 00 00 push $0x4820
25ea: e8 03 13 00 00 call 38f2 <unlink>
printf(1, "bigfile test ok\n");
25ef: 58 pop %eax
25f0: 5a pop %edx
25f1: 68 af 48 00 00 push $0x48af
25f6: 6a 01 push $0x1
25f8: e8 03 14 00 00 call 3a00 <printf>
}
25fd: 83 c4 10 add $0x10,%esp
2600: 8d 65 f4 lea -0xc(%ebp),%esp
2603: 5b pop %ebx
2604: 5e pop %esi
2605: 5f pop %edi
2606: 5d pop %ebp
2607: c3 ret
printf(1, "read bigfile wrong data\n");
2608: 83 ec 08 sub $0x8,%esp
260b: 68 7c 48 00 00 push $0x487c
2610: 6a 01 push $0x1
2612: e8 e9 13 00 00 call 3a00 <printf>
exit();
2617: e8 86 12 00 00 call 38a2 <exit>
printf(1, "short read bigfile\n");
261c: 83 ec 08 sub $0x8,%esp
261f: 68 68 48 00 00 push $0x4868
2624: 6a 01 push $0x1
2626: e8 d5 13 00 00 call 3a00 <printf>
exit();
262b: e8 72 12 00 00 call 38a2 <exit>
printf(1, "read bigfile failed\n");
2630: 83 ec 08 sub $0x8,%esp
2633: 68 53 48 00 00 push $0x4853
2638: 6a 01 push $0x1
263a: e8 c1 13 00 00 call 3a00 <printf>
exit();
263f: e8 5e 12 00 00 call 38a2 <exit>
printf(1, "write bigfile failed\n");
2644: 83 ec 08 sub $0x8,%esp
2647: 68 28 48 00 00 push $0x4828
264c: 6a 01 push $0x1
264e: e8 ad 13 00 00 call 3a00 <printf>
exit();
2653: e8 4a 12 00 00 call 38a2 <exit>
printf(1, "cannot open bigfile\n");
2658: 53 push %ebx
2659: 53 push %ebx
265a: 68 3e 48 00 00 push $0x483e
265f: 6a 01 push $0x1
2661: e8 9a 13 00 00 call 3a00 <printf>
exit();
2666: e8 37 12 00 00 call 38a2 <exit>
printf(1, "cannot create bigfile");
266b: 50 push %eax
266c: 50 push %eax
266d: 68 12 48 00 00 push $0x4812
2672: 6a 01 push $0x1
2674: e8 87 13 00 00 call 3a00 <printf>
exit();
2679: e8 24 12 00 00 call 38a2 <exit>
printf(1, "read bigfile wrong total\n");
267e: 51 push %ecx
267f: 51 push %ecx
2680: 68 95 48 00 00 push $0x4895
2685: 6a 01 push $0x1
2687: e8 74 13 00 00 call 3a00 <printf>
exit();
268c: e8 11 12 00 00 call 38a2 <exit>
2691: eb 0d jmp 26a0 <fourteen>
2693: 90 nop
2694: 90 nop
2695: 90 nop
2696: 90 nop
2697: 90 nop
2698: 90 nop
2699: 90 nop
269a: 90 nop
269b: 90 nop
269c: 90 nop
269d: 90 nop
269e: 90 nop
269f: 90 nop
000026a0 <fourteen>:
{
26a0: 55 push %ebp
26a1: 89 e5 mov %esp,%ebp
26a3: 83 ec 10 sub $0x10,%esp
printf(1, "fourteen test\n");
26a6: 68 c0 48 00 00 push $0x48c0
26ab: 6a 01 push $0x1
26ad: e8 4e 13 00 00 call 3a00 <printf>
if(mkdir("12345678901234") != 0){
26b2: c7 04 24 fb 48 00 00 movl $0x48fb,(%esp)
26b9: e8 4c 12 00 00 call 390a <mkdir>
26be: 83 c4 10 add $0x10,%esp
26c1: 85 c0 test %eax,%eax
26c3: 0f 85 97 00 00 00 jne 2760 <fourteen+0xc0>
if(mkdir("12345678901234/123456789012345") != 0){
26c9: 83 ec 0c sub $0xc,%esp
26cc: 68 b8 50 00 00 push $0x50b8
26d1: e8 34 12 00 00 call 390a <mkdir>
26d6: 83 c4 10 add $0x10,%esp
26d9: 85 c0 test %eax,%eax
26db: 0f 85 de 00 00 00 jne 27bf <fourteen+0x11f>
fd = open("123456789012345/123456789012345/123456789012345", O_CREATE);
26e1: 83 ec 08 sub $0x8,%esp
26e4: 68 00 02 00 00 push $0x200
26e9: 68 08 51 00 00 push $0x5108
26ee: e8 ef 11 00 00 call 38e2 <open>
if(fd < 0){
26f3: 83 c4 10 add $0x10,%esp
26f6: 85 c0 test %eax,%eax
26f8: 0f 88 ae 00 00 00 js 27ac <fourteen+0x10c>
close(fd);
26fe: 83 ec 0c sub $0xc,%esp
2701: 50 push %eax
2702: e8 c3 11 00 00 call 38ca <close>
fd = open("12345678901234/12345678901234/12345678901234", 0);
2707: 58 pop %eax
2708: 5a pop %edx
2709: 6a 00 push $0x0
270b: 68 78 51 00 00 push $0x5178
2710: e8 cd 11 00 00 call 38e2 <open>
if(fd < 0){
2715: 83 c4 10 add $0x10,%esp
2718: 85 c0 test %eax,%eax
271a: 78 7d js 2799 <fourteen+0xf9>
close(fd);
271c: 83 ec 0c sub $0xc,%esp
271f: 50 push %eax
2720: e8 a5 11 00 00 call 38ca <close>
if(mkdir("12345678901234/12345678901234") == 0){
2725: c7 04 24 ec 48 00 00 movl $0x48ec,(%esp)
272c: e8 d9 11 00 00 call 390a <mkdir>
2731: 83 c4 10 add $0x10,%esp
2734: 85 c0 test %eax,%eax
2736: 74 4e je 2786 <fourteen+0xe6>
if(mkdir("123456789012345/12345678901234") == 0){
2738: 83 ec 0c sub $0xc,%esp
273b: 68 14 52 00 00 push $0x5214
2740: e8 c5 11 00 00 call 390a <mkdir>
2745: 83 c4 10 add $0x10,%esp
2748: 85 c0 test %eax,%eax
274a: 74 27 je 2773 <fourteen+0xd3>
printf(1, "fourteen ok\n");
274c: 83 ec 08 sub $0x8,%esp
274f: 68 0a 49 00 00 push $0x490a
2754: 6a 01 push $0x1
2756: e8 a5 12 00 00 call 3a00 <printf>
}
275b: 83 c4 10 add $0x10,%esp
275e: c9 leave
275f: c3 ret
printf(1, "mkdir 12345678901234 failed\n");
2760: 50 push %eax
2761: 50 push %eax
2762: 68 cf 48 00 00 push $0x48cf
2767: 6a 01 push $0x1
2769: e8 92 12 00 00 call 3a00 <printf>
exit();
276e: e8 2f 11 00 00 call 38a2 <exit>
printf(1, "mkdir 12345678901234/123456789012345 succeeded!\n");
2773: 50 push %eax
2774: 50 push %eax
2775: 68 34 52 00 00 push $0x5234
277a: 6a 01 push $0x1
277c: e8 7f 12 00 00 call 3a00 <printf>
exit();
2781: e8 1c 11 00 00 call 38a2 <exit>
printf(1, "mkdir 12345678901234/12345678901234 succeeded!\n");
2786: 52 push %edx
2787: 52 push %edx
2788: 68 e4 51 00 00 push $0x51e4
278d: 6a 01 push $0x1
278f: e8 6c 12 00 00 call 3a00 <printf>
exit();
2794: e8 09 11 00 00 call 38a2 <exit>
printf(1, "open 12345678901234/12345678901234/12345678901234 failed\n");
2799: 51 push %ecx
279a: 51 push %ecx
279b: 68 a8 51 00 00 push $0x51a8
27a0: 6a 01 push $0x1
27a2: e8 59 12 00 00 call 3a00 <printf>
exit();
27a7: e8 f6 10 00 00 call 38a2 <exit>
printf(1, "create 123456789012345/123456789012345/123456789012345 failed\n");
27ac: 51 push %ecx
27ad: 51 push %ecx
27ae: 68 38 51 00 00 push $0x5138
27b3: 6a 01 push $0x1
27b5: e8 46 12 00 00 call 3a00 <printf>
exit();
27ba: e8 e3 10 00 00 call 38a2 <exit>
printf(1, "mkdir 12345678901234/123456789012345 failed\n");
27bf: 50 push %eax
27c0: 50 push %eax
27c1: 68 d8 50 00 00 push $0x50d8
27c6: 6a 01 push $0x1
27c8: e8 33 12 00 00 call 3a00 <printf>
exit();
27cd: e8 d0 10 00 00 call 38a2 <exit>
27d2: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
27d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000027e0 <rmdot>:
{
27e0: 55 push %ebp
27e1: 89 e5 mov %esp,%ebp
27e3: 83 ec 10 sub $0x10,%esp
printf(1, "rmdot test\n");
27e6: 68 17 49 00 00 push $0x4917
27eb: 6a 01 push $0x1
27ed: e8 0e 12 00 00 call 3a00 <printf>
if(mkdir("dots") != 0){
27f2: c7 04 24 23 49 00 00 movl $0x4923,(%esp)
27f9: e8 0c 11 00 00 call 390a <mkdir>
27fe: 83 c4 10 add $0x10,%esp
2801: 85 c0 test %eax,%eax
2803: 0f 85 b0 00 00 00 jne 28b9 <rmdot+0xd9>
if(chdir("dots") != 0){
2809: 83 ec 0c sub $0xc,%esp
280c: 68 23 49 00 00 push $0x4923
2811: e8 fc 10 00 00 call 3912 <chdir>
2816: 83 c4 10 add $0x10,%esp
2819: 85 c0 test %eax,%eax
281b: 0f 85 1d 01 00 00 jne 293e <rmdot+0x15e>
if(unlink(".") == 0){
2821: 83 ec 0c sub $0xc,%esp
2824: 68 ce 45 00 00 push $0x45ce
2829: e8 c4 10 00 00 call 38f2 <unlink>
282e: 83 c4 10 add $0x10,%esp
2831: 85 c0 test %eax,%eax
2833: 0f 84 f2 00 00 00 je 292b <rmdot+0x14b>
if(unlink("..") == 0){
2839: 83 ec 0c sub $0xc,%esp
283c: 68 cd 45 00 00 push $0x45cd
2841: e8 ac 10 00 00 call 38f2 <unlink>
2846: 83 c4 10 add $0x10,%esp
2849: 85 c0 test %eax,%eax
284b: 0f 84 c7 00 00 00 je 2918 <rmdot+0x138>
if(chdir("/") != 0){
2851: 83 ec 0c sub $0xc,%esp
2854: 68 a1 3d 00 00 push $0x3da1
2859: e8 b4 10 00 00 call 3912 <chdir>
285e: 83 c4 10 add $0x10,%esp
2861: 85 c0 test %eax,%eax
2863: 0f 85 9c 00 00 00 jne 2905 <rmdot+0x125>
if(unlink("dots/.") == 0){
2869: 83 ec 0c sub $0xc,%esp
286c: 68 6b 49 00 00 push $0x496b
2871: e8 7c 10 00 00 call 38f2 <unlink>
2876: 83 c4 10 add $0x10,%esp
2879: 85 c0 test %eax,%eax
287b: 74 75 je 28f2 <rmdot+0x112>
if(unlink("dots/..") == 0){
287d: 83 ec 0c sub $0xc,%esp
2880: 68 89 49 00 00 push $0x4989
2885: e8 68 10 00 00 call 38f2 <unlink>
288a: 83 c4 10 add $0x10,%esp
288d: 85 c0 test %eax,%eax
288f: 74 4e je 28df <rmdot+0xff>
if(unlink("dots") != 0){
2891: 83 ec 0c sub $0xc,%esp
2894: 68 23 49 00 00 push $0x4923
2899: e8 54 10 00 00 call 38f2 <unlink>
289e: 83 c4 10 add $0x10,%esp
28a1: 85 c0 test %eax,%eax
28a3: 75 27 jne 28cc <rmdot+0xec>
printf(1, "rmdot ok\n");
28a5: 83 ec 08 sub $0x8,%esp
28a8: 68 be 49 00 00 push $0x49be
28ad: 6a 01 push $0x1
28af: e8 4c 11 00 00 call 3a00 <printf>
}
28b4: 83 c4 10 add $0x10,%esp
28b7: c9 leave
28b8: c3 ret
printf(1, "mkdir dots failed\n");
28b9: 50 push %eax
28ba: 50 push %eax
28bb: 68 28 49 00 00 push $0x4928
28c0: 6a 01 push $0x1
28c2: e8 39 11 00 00 call 3a00 <printf>
exit();
28c7: e8 d6 0f 00 00 call 38a2 <exit>
printf(1, "unlink dots failed!\n");
28cc: 50 push %eax
28cd: 50 push %eax
28ce: 68 a9 49 00 00 push $0x49a9
28d3: 6a 01 push $0x1
28d5: e8 26 11 00 00 call 3a00 <printf>
exit();
28da: e8 c3 0f 00 00 call 38a2 <exit>
printf(1, "unlink dots/.. worked!\n");
28df: 52 push %edx
28e0: 52 push %edx
28e1: 68 91 49 00 00 push $0x4991
28e6: 6a 01 push $0x1
28e8: e8 13 11 00 00 call 3a00 <printf>
exit();
28ed: e8 b0 0f 00 00 call 38a2 <exit>
printf(1, "unlink dots/. worked!\n");
28f2: 51 push %ecx
28f3: 51 push %ecx
28f4: 68 72 49 00 00 push $0x4972
28f9: 6a 01 push $0x1
28fb: e8 00 11 00 00 call 3a00 <printf>
exit();
2900: e8 9d 0f 00 00 call 38a2 <exit>
printf(1, "chdir / failed\n");
2905: 50 push %eax
2906: 50 push %eax
2907: 68 a3 3d 00 00 push $0x3da3
290c: 6a 01 push $0x1
290e: e8 ed 10 00 00 call 3a00 <printf>
exit();
2913: e8 8a 0f 00 00 call 38a2 <exit>
printf(1, "rm .. worked!\n");
2918: 50 push %eax
2919: 50 push %eax
291a: 68 5c 49 00 00 push $0x495c
291f: 6a 01 push $0x1
2921: e8 da 10 00 00 call 3a00 <printf>
exit();
2926: e8 77 0f 00 00 call 38a2 <exit>
printf(1, "rm . worked!\n");
292b: 50 push %eax
292c: 50 push %eax
292d: 68 4e 49 00 00 push $0x494e
2932: 6a 01 push $0x1
2934: e8 c7 10 00 00 call 3a00 <printf>
exit();
2939: e8 64 0f 00 00 call 38a2 <exit>
printf(1, "chdir dots failed\n");
293e: 50 push %eax
293f: 50 push %eax
2940: 68 3b 49 00 00 push $0x493b
2945: 6a 01 push $0x1
2947: e8 b4 10 00 00 call 3a00 <printf>
exit();
294c: e8 51 0f 00 00 call 38a2 <exit>
2951: eb 0d jmp 2960 <dirfile>
2953: 90 nop
2954: 90 nop
2955: 90 nop
2956: 90 nop
2957: 90 nop
2958: 90 nop
2959: 90 nop
295a: 90 nop
295b: 90 nop
295c: 90 nop
295d: 90 nop
295e: 90 nop
295f: 90 nop
00002960 <dirfile>:
{
2960: 55 push %ebp
2961: 89 e5 mov %esp,%ebp
2963: 53 push %ebx
2964: 83 ec 0c sub $0xc,%esp
printf(1, "dir vs file\n");
2967: 68 c8 49 00 00 push $0x49c8
296c: 6a 01 push $0x1
296e: e8 8d 10 00 00 call 3a00 <printf>
fd = open("dirfile", O_CREATE);
2973: 59 pop %ecx
2974: 5b pop %ebx
2975: 68 00 02 00 00 push $0x200
297a: 68 d5 49 00 00 push $0x49d5
297f: e8 5e 0f 00 00 call 38e2 <open>
if(fd < 0){
2984: 83 c4 10 add $0x10,%esp
2987: 85 c0 test %eax,%eax
2989: 0f 88 43 01 00 00 js 2ad2 <dirfile+0x172>
close(fd);
298f: 83 ec 0c sub $0xc,%esp
2992: 50 push %eax
2993: e8 32 0f 00 00 call 38ca <close>
if(chdir("dirfile") == 0){
2998: c7 04 24 d5 49 00 00 movl $0x49d5,(%esp)
299f: e8 6e 0f 00 00 call 3912 <chdir>
29a4: 83 c4 10 add $0x10,%esp
29a7: 85 c0 test %eax,%eax
29a9: 0f 84 10 01 00 00 je 2abf <dirfile+0x15f>
fd = open("dirfile/xx", 0);
29af: 83 ec 08 sub $0x8,%esp
29b2: 6a 00 push $0x0
29b4: 68 0e 4a 00 00 push $0x4a0e
29b9: e8 24 0f 00 00 call 38e2 <open>
if(fd >= 0){
29be: 83 c4 10 add $0x10,%esp
29c1: 85 c0 test %eax,%eax
29c3: 0f 89 e3 00 00 00 jns 2aac <dirfile+0x14c>
fd = open("dirfile/xx", O_CREATE);
29c9: 83 ec 08 sub $0x8,%esp
29cc: 68 00 02 00 00 push $0x200
29d1: 68 0e 4a 00 00 push $0x4a0e
29d6: e8 07 0f 00 00 call 38e2 <open>
if(fd >= 0){
29db: 83 c4 10 add $0x10,%esp
29de: 85 c0 test %eax,%eax
29e0: 0f 89 c6 00 00 00 jns 2aac <dirfile+0x14c>
if(mkdir("dirfile/xx") == 0){
29e6: 83 ec 0c sub $0xc,%esp
29e9: 68 0e 4a 00 00 push $0x4a0e
29ee: e8 17 0f 00 00 call 390a <mkdir>
29f3: 83 c4 10 add $0x10,%esp
29f6: 85 c0 test %eax,%eax
29f8: 0f 84 46 01 00 00 je 2b44 <dirfile+0x1e4>
if(unlink("dirfile/xx") == 0){
29fe: 83 ec 0c sub $0xc,%esp
2a01: 68 0e 4a 00 00 push $0x4a0e
2a06: e8 e7 0e 00 00 call 38f2 <unlink>
2a0b: 83 c4 10 add $0x10,%esp
2a0e: 85 c0 test %eax,%eax
2a10: 0f 84 1b 01 00 00 je 2b31 <dirfile+0x1d1>
if(link("README", "dirfile/xx") == 0){
2a16: 83 ec 08 sub $0x8,%esp
2a19: 68 0e 4a 00 00 push $0x4a0e
2a1e: 68 72 4a 00 00 push $0x4a72
2a23: e8 da 0e 00 00 call 3902 <link>
2a28: 83 c4 10 add $0x10,%esp
2a2b: 85 c0 test %eax,%eax
2a2d: 0f 84 eb 00 00 00 je 2b1e <dirfile+0x1be>
if(unlink("dirfile") != 0){
2a33: 83 ec 0c sub $0xc,%esp
2a36: 68 d5 49 00 00 push $0x49d5
2a3b: e8 b2 0e 00 00 call 38f2 <unlink>
2a40: 83 c4 10 add $0x10,%esp
2a43: 85 c0 test %eax,%eax
2a45: 0f 85 c0 00 00 00 jne 2b0b <dirfile+0x1ab>
fd = open(".", O_RDWR);
2a4b: 83 ec 08 sub $0x8,%esp
2a4e: 6a 02 push $0x2
2a50: 68 ce 45 00 00 push $0x45ce
2a55: e8 88 0e 00 00 call 38e2 <open>
if(fd >= 0){
2a5a: 83 c4 10 add $0x10,%esp
2a5d: 85 c0 test %eax,%eax
2a5f: 0f 89 93 00 00 00 jns 2af8 <dirfile+0x198>
fd = open(".", 0);
2a65: 83 ec 08 sub $0x8,%esp
2a68: 6a 00 push $0x0
2a6a: 68 ce 45 00 00 push $0x45ce
2a6f: e8 6e 0e 00 00 call 38e2 <open>
if(write(fd, "x", 1) > 0){
2a74: 83 c4 0c add $0xc,%esp
fd = open(".", 0);
2a77: 89 c3 mov %eax,%ebx
if(write(fd, "x", 1) > 0){
2a79: 6a 01 push $0x1
2a7b: 68 b1 46 00 00 push $0x46b1
2a80: 50 push %eax
2a81: e8 3c 0e 00 00 call 38c2 <write>
2a86: 83 c4 10 add $0x10,%esp
2a89: 85 c0 test %eax,%eax
2a8b: 7f 58 jg 2ae5 <dirfile+0x185>
close(fd);
2a8d: 83 ec 0c sub $0xc,%esp
2a90: 53 push %ebx
2a91: e8 34 0e 00 00 call 38ca <close>
printf(1, "dir vs file OK\n");
2a96: 58 pop %eax
2a97: 5a pop %edx
2a98: 68 a5 4a 00 00 push $0x4aa5
2a9d: 6a 01 push $0x1
2a9f: e8 5c 0f 00 00 call 3a00 <printf>
}
2aa4: 83 c4 10 add $0x10,%esp
2aa7: 8b 5d fc mov -0x4(%ebp),%ebx
2aaa: c9 leave
2aab: c3 ret
printf(1, "create dirfile/xx succeeded!\n");
2aac: 50 push %eax
2aad: 50 push %eax
2aae: 68 19 4a 00 00 push $0x4a19
2ab3: 6a 01 push $0x1
2ab5: e8 46 0f 00 00 call 3a00 <printf>
exit();
2aba: e8 e3 0d 00 00 call 38a2 <exit>
printf(1, "chdir dirfile succeeded!\n");
2abf: 50 push %eax
2ac0: 50 push %eax
2ac1: 68 f4 49 00 00 push $0x49f4
2ac6: 6a 01 push $0x1
2ac8: e8 33 0f 00 00 call 3a00 <printf>
exit();
2acd: e8 d0 0d 00 00 call 38a2 <exit>
printf(1, "create dirfile failed\n");
2ad2: 52 push %edx
2ad3: 52 push %edx
2ad4: 68 dd 49 00 00 push $0x49dd
2ad9: 6a 01 push $0x1
2adb: e8 20 0f 00 00 call 3a00 <printf>
exit();
2ae0: e8 bd 0d 00 00 call 38a2 <exit>
printf(1, "write . succeeded!\n");
2ae5: 51 push %ecx
2ae6: 51 push %ecx
2ae7: 68 91 4a 00 00 push $0x4a91
2aec: 6a 01 push $0x1
2aee: e8 0d 0f 00 00 call 3a00 <printf>
exit();
2af3: e8 aa 0d 00 00 call 38a2 <exit>
printf(1, "open . for writing succeeded!\n");
2af8: 53 push %ebx
2af9: 53 push %ebx
2afa: 68 88 52 00 00 push $0x5288
2aff: 6a 01 push $0x1
2b01: e8 fa 0e 00 00 call 3a00 <printf>
exit();
2b06: e8 97 0d 00 00 call 38a2 <exit>
printf(1, "unlink dirfile failed!\n");
2b0b: 50 push %eax
2b0c: 50 push %eax
2b0d: 68 79 4a 00 00 push $0x4a79
2b12: 6a 01 push $0x1
2b14: e8 e7 0e 00 00 call 3a00 <printf>
exit();
2b19: e8 84 0d 00 00 call 38a2 <exit>
printf(1, "link to dirfile/xx succeeded!\n");
2b1e: 50 push %eax
2b1f: 50 push %eax
2b20: 68 68 52 00 00 push $0x5268
2b25: 6a 01 push $0x1
2b27: e8 d4 0e 00 00 call 3a00 <printf>
exit();
2b2c: e8 71 0d 00 00 call 38a2 <exit>
printf(1, "unlink dirfile/xx succeeded!\n");
2b31: 50 push %eax
2b32: 50 push %eax
2b33: 68 54 4a 00 00 push $0x4a54
2b38: 6a 01 push $0x1
2b3a: e8 c1 0e 00 00 call 3a00 <printf>
exit();
2b3f: e8 5e 0d 00 00 call 38a2 <exit>
printf(1, "mkdir dirfile/xx succeeded!\n");
2b44: 50 push %eax
2b45: 50 push %eax
2b46: 68 37 4a 00 00 push $0x4a37
2b4b: 6a 01 push $0x1
2b4d: e8 ae 0e 00 00 call 3a00 <printf>
exit();
2b52: e8 4b 0d 00 00 call 38a2 <exit>
2b57: 89 f6 mov %esi,%esi
2b59: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00002b60 <iref>:
{
2b60: 55 push %ebp
2b61: 89 e5 mov %esp,%ebp
2b63: 53 push %ebx
printf(1, "empty file name\n");
2b64: bb 33 00 00 00 mov $0x33,%ebx
{
2b69: 83 ec 0c sub $0xc,%esp
printf(1, "empty file name\n");
2b6c: 68 b5 4a 00 00 push $0x4ab5
2b71: 6a 01 push $0x1
2b73: e8 88 0e 00 00 call 3a00 <printf>
2b78: 83 c4 10 add $0x10,%esp
2b7b: 90 nop
2b7c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
if(mkdir("irefd") != 0){
2b80: 83 ec 0c sub $0xc,%esp
2b83: 68 c6 4a 00 00 push $0x4ac6
2b88: e8 7d 0d 00 00 call 390a <mkdir>
2b8d: 83 c4 10 add $0x10,%esp
2b90: 85 c0 test %eax,%eax
2b92: 0f 85 bb 00 00 00 jne 2c53 <iref+0xf3>
if(chdir("irefd") != 0){
2b98: 83 ec 0c sub $0xc,%esp
2b9b: 68 c6 4a 00 00 push $0x4ac6
2ba0: e8 6d 0d 00 00 call 3912 <chdir>
2ba5: 83 c4 10 add $0x10,%esp
2ba8: 85 c0 test %eax,%eax
2baa: 0f 85 b7 00 00 00 jne 2c67 <iref+0x107>
mkdir("");
2bb0: 83 ec 0c sub $0xc,%esp
2bb3: 68 7b 41 00 00 push $0x417b
2bb8: e8 4d 0d 00 00 call 390a <mkdir>
link("README", "");
2bbd: 59 pop %ecx
2bbe: 58 pop %eax
2bbf: 68 7b 41 00 00 push $0x417b
2bc4: 68 72 4a 00 00 push $0x4a72
2bc9: e8 34 0d 00 00 call 3902 <link>
fd = open("", O_CREATE);
2bce: 58 pop %eax
2bcf: 5a pop %edx
2bd0: 68 00 02 00 00 push $0x200
2bd5: 68 7b 41 00 00 push $0x417b
2bda: e8 03 0d 00 00 call 38e2 <open>
if(fd >= 0)
2bdf: 83 c4 10 add $0x10,%esp
2be2: 85 c0 test %eax,%eax
2be4: 78 0c js 2bf2 <iref+0x92>
close(fd);
2be6: 83 ec 0c sub $0xc,%esp
2be9: 50 push %eax
2bea: e8 db 0c 00 00 call 38ca <close>
2bef: 83 c4 10 add $0x10,%esp
fd = open("xx", O_CREATE);
2bf2: 83 ec 08 sub $0x8,%esp
2bf5: 68 00 02 00 00 push $0x200
2bfa: 68 b0 46 00 00 push $0x46b0
2bff: e8 de 0c 00 00 call 38e2 <open>
if(fd >= 0)
2c04: 83 c4 10 add $0x10,%esp
2c07: 85 c0 test %eax,%eax
2c09: 78 0c js 2c17 <iref+0xb7>
close(fd);
2c0b: 83 ec 0c sub $0xc,%esp
2c0e: 50 push %eax
2c0f: e8 b6 0c 00 00 call 38ca <close>
2c14: 83 c4 10 add $0x10,%esp
unlink("xx");
2c17: 83 ec 0c sub $0xc,%esp
2c1a: 68 b0 46 00 00 push $0x46b0
2c1f: e8 ce 0c 00 00 call 38f2 <unlink>
for(i = 0; i < 50 + 1; i++){
2c24: 83 c4 10 add $0x10,%esp
2c27: 83 eb 01 sub $0x1,%ebx
2c2a: 0f 85 50 ff ff ff jne 2b80 <iref+0x20>
chdir("/");
2c30: 83 ec 0c sub $0xc,%esp
2c33: 68 a1 3d 00 00 push $0x3da1
2c38: e8 d5 0c 00 00 call 3912 <chdir>
printf(1, "empty file name OK\n");
2c3d: 58 pop %eax
2c3e: 5a pop %edx
2c3f: 68 f4 4a 00 00 push $0x4af4
2c44: 6a 01 push $0x1
2c46: e8 b5 0d 00 00 call 3a00 <printf>
}
2c4b: 83 c4 10 add $0x10,%esp
2c4e: 8b 5d fc mov -0x4(%ebp),%ebx
2c51: c9 leave
2c52: c3 ret
printf(1, "mkdir irefd failed\n");
2c53: 83 ec 08 sub $0x8,%esp
2c56: 68 cc 4a 00 00 push $0x4acc
2c5b: 6a 01 push $0x1
2c5d: e8 9e 0d 00 00 call 3a00 <printf>
exit();
2c62: e8 3b 0c 00 00 call 38a2 <exit>
printf(1, "chdir irefd failed\n");
2c67: 83 ec 08 sub $0x8,%esp
2c6a: 68 e0 4a 00 00 push $0x4ae0
2c6f: 6a 01 push $0x1
2c71: e8 8a 0d 00 00 call 3a00 <printf>
exit();
2c76: e8 27 0c 00 00 call 38a2 <exit>
2c7b: 90 nop
2c7c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00002c80 <forktest>:
{
2c80: 55 push %ebp
2c81: 89 e5 mov %esp,%ebp
2c83: 53 push %ebx
for(n=0; n<1000; n++){
2c84: 31 db xor %ebx,%ebx
{
2c86: 83 ec 0c sub $0xc,%esp
printf(1, "fork test\n");
2c89: 68 08 4b 00 00 push $0x4b08
2c8e: 6a 01 push $0x1
2c90: e8 6b 0d 00 00 call 3a00 <printf>
2c95: 83 c4 10 add $0x10,%esp
2c98: eb 13 jmp 2cad <forktest+0x2d>
2c9a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
if(pid == 0)
2ca0: 74 62 je 2d04 <forktest+0x84>
for(n=0; n<1000; n++){
2ca2: 83 c3 01 add $0x1,%ebx
2ca5: 81 fb e8 03 00 00 cmp $0x3e8,%ebx
2cab: 74 43 je 2cf0 <forktest+0x70>
pid = fork();
2cad: e8 e8 0b 00 00 call 389a <fork>
if(pid < 0)
2cb2: 85 c0 test %eax,%eax
2cb4: 79 ea jns 2ca0 <forktest+0x20>
for(; n > 0; n--){
2cb6: 85 db test %ebx,%ebx
2cb8: 74 14 je 2cce <forktest+0x4e>
2cba: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
if(wait() < 0){
2cc0: e8 e5 0b 00 00 call 38aa <wait>
2cc5: 85 c0 test %eax,%eax
2cc7: 78 40 js 2d09 <forktest+0x89>
for(; n > 0; n--){
2cc9: 83 eb 01 sub $0x1,%ebx
2ccc: 75 f2 jne 2cc0 <forktest+0x40>
if(wait() != -1){
2cce: e8 d7 0b 00 00 call 38aa <wait>
2cd3: 83 f8 ff cmp $0xffffffff,%eax
2cd6: 75 45 jne 2d1d <forktest+0x9d>
printf(1, "fork test OK\n");
2cd8: 83 ec 08 sub $0x8,%esp
2cdb: 68 3a 4b 00 00 push $0x4b3a
2ce0: 6a 01 push $0x1
2ce2: e8 19 0d 00 00 call 3a00 <printf>
}
2ce7: 8b 5d fc mov -0x4(%ebp),%ebx
2cea: c9 leave
2ceb: c3 ret
2cec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
printf(1, "fork claimed to work 1000 times!\n");
2cf0: 83 ec 08 sub $0x8,%esp
2cf3: 68 a8 52 00 00 push $0x52a8
2cf8: 6a 01 push $0x1
2cfa: e8 01 0d 00 00 call 3a00 <printf>
exit();
2cff: e8 9e 0b 00 00 call 38a2 <exit>
exit();
2d04: e8 99 0b 00 00 call 38a2 <exit>
printf(1, "wait stopped early\n");
2d09: 83 ec 08 sub $0x8,%esp
2d0c: 68 13 4b 00 00 push $0x4b13
2d11: 6a 01 push $0x1
2d13: e8 e8 0c 00 00 call 3a00 <printf>
exit();
2d18: e8 85 0b 00 00 call 38a2 <exit>
printf(1, "wait got too many\n");
2d1d: 50 push %eax
2d1e: 50 push %eax
2d1f: 68 27 4b 00 00 push $0x4b27
2d24: 6a 01 push $0x1
2d26: e8 d5 0c 00 00 call 3a00 <printf>
exit();
2d2b: e8 72 0b 00 00 call 38a2 <exit>
00002d30 <sbrktest>:
{
2d30: 55 push %ebp
2d31: 89 e5 mov %esp,%ebp
2d33: 57 push %edi
2d34: 56 push %esi
2d35: 53 push %ebx
for(i = 0; i < 5000; i++){
2d36: 31 ff xor %edi,%edi
{
2d38: 83 ec 64 sub $0x64,%esp
printf(stdout, "sbrk test\n");
2d3b: 68 48 4b 00 00 push $0x4b48
2d40: ff 35 08 5e 00 00 pushl 0x5e08
2d46: e8 b5 0c 00 00 call 3a00 <printf>
oldbrk = sbrk(0);
2d4b: c7 04 24 00 00 00 00 movl $0x0,(%esp)
2d52: e8 d3 0b 00 00 call 392a <sbrk>
a = sbrk(0);
2d57: c7 04 24 00 00 00 00 movl $0x0,(%esp)
oldbrk = sbrk(0);
2d5e: 89 c3 mov %eax,%ebx
a = sbrk(0);
2d60: e8 c5 0b 00 00 call 392a <sbrk>
2d65: 83 c4 10 add $0x10,%esp
2d68: 89 c6 mov %eax,%esi
2d6a: eb 06 jmp 2d72 <sbrktest+0x42>
2d6c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
a = b + 1;
2d70: 89 c6 mov %eax,%esi
b = sbrk(1);
2d72: 83 ec 0c sub $0xc,%esp
2d75: 6a 01 push $0x1
2d77: e8 ae 0b 00 00 call 392a <sbrk>
if(b != a){
2d7c: 83 c4 10 add $0x10,%esp
2d7f: 39 f0 cmp %esi,%eax
2d81: 0f 85 62 02 00 00 jne 2fe9 <sbrktest+0x2b9>
for(i = 0; i < 5000; i++){
2d87: 83 c7 01 add $0x1,%edi
*b = 1;
2d8a: c6 06 01 movb $0x1,(%esi)
a = b + 1;
2d8d: 8d 46 01 lea 0x1(%esi),%eax
for(i = 0; i < 5000; i++){
2d90: 81 ff 88 13 00 00 cmp $0x1388,%edi
2d96: 75 d8 jne 2d70 <sbrktest+0x40>
pid = fork();
2d98: e8 fd 0a 00 00 call 389a <fork>
if(pid < 0){
2d9d: 85 c0 test %eax,%eax
pid = fork();
2d9f: 89 c7 mov %eax,%edi
if(pid < 0){
2da1: 0f 88 82 03 00 00 js 3129 <sbrktest+0x3f9>
c = sbrk(1);
2da7: 83 ec 0c sub $0xc,%esp
if(c != a + 1){
2daa: 83 c6 02 add $0x2,%esi
c = sbrk(1);
2dad: 6a 01 push $0x1
2daf: e8 76 0b 00 00 call 392a <sbrk>
c = sbrk(1);
2db4: c7 04 24 01 00 00 00 movl $0x1,(%esp)
2dbb: e8 6a 0b 00 00 call 392a <sbrk>
if(c != a + 1){
2dc0: 83 c4 10 add $0x10,%esp
2dc3: 39 f0 cmp %esi,%eax
2dc5: 0f 85 47 03 00 00 jne 3112 <sbrktest+0x3e2>
if(pid == 0)
2dcb: 85 ff test %edi,%edi
2dcd: 0f 84 3a 03 00 00 je 310d <sbrktest+0x3dd>
wait();
2dd3: e8 d2 0a 00 00 call 38aa <wait>
a = sbrk(0);
2dd8: 83 ec 0c sub $0xc,%esp
2ddb: 6a 00 push $0x0
2ddd: e8 48 0b 00 00 call 392a <sbrk>
2de2: 89 c6 mov %eax,%esi
amt = (BIG) - (uint)a;
2de4: b8 00 00 40 06 mov $0x6400000,%eax
2de9: 29 f0 sub %esi,%eax
p = sbrk(amt);
2deb: 89 04 24 mov %eax,(%esp)
2dee: e8 37 0b 00 00 call 392a <sbrk>
if (p != a) {
2df3: 83 c4 10 add $0x10,%esp
2df6: 39 c6 cmp %eax,%esi
2df8: 0f 85 f8 02 00 00 jne 30f6 <sbrktest+0x3c6>
a = sbrk(0);
2dfe: 83 ec 0c sub $0xc,%esp
*lastaddr = 99;
2e01: c6 05 ff ff 3f 06 63 movb $0x63,0x63fffff
a = sbrk(0);
2e08: 6a 00 push $0x0
2e0a: e8 1b 0b 00 00 call 392a <sbrk>
c = sbrk(-4096);
2e0f: c7 04 24 00 f0 ff ff movl $0xfffff000,(%esp)
a = sbrk(0);
2e16: 89 c6 mov %eax,%esi
c = sbrk(-4096);
2e18: e8 0d 0b 00 00 call 392a <sbrk>
if(c == (char*)0xffffffff){
2e1d: 83 c4 10 add $0x10,%esp
2e20: 83 f8 ff cmp $0xffffffff,%eax
2e23: 0f 84 b6 02 00 00 je 30df <sbrktest+0x3af>
c = sbrk(0);
2e29: 83 ec 0c sub $0xc,%esp
2e2c: 6a 00 push $0x0
2e2e: e8 f7 0a 00 00 call 392a <sbrk>
if(c != a - 4096){
2e33: 8d 96 00 f0 ff ff lea -0x1000(%esi),%edx
2e39: 83 c4 10 add $0x10,%esp
2e3c: 39 d0 cmp %edx,%eax
2e3e: 0f 85 84 02 00 00 jne 30c8 <sbrktest+0x398>
a = sbrk(0);
2e44: 83 ec 0c sub $0xc,%esp
2e47: 6a 00 push $0x0
2e49: e8 dc 0a 00 00 call 392a <sbrk>
2e4e: 89 c6 mov %eax,%esi
c = sbrk(4096);
2e50: c7 04 24 00 10 00 00 movl $0x1000,(%esp)
2e57: e8 ce 0a 00 00 call 392a <sbrk>
if(c != a || sbrk(0) != a + 4096){
2e5c: 83 c4 10 add $0x10,%esp
2e5f: 39 c6 cmp %eax,%esi
c = sbrk(4096);
2e61: 89 c7 mov %eax,%edi
if(c != a || sbrk(0) != a + 4096){
2e63: 0f 85 48 02 00 00 jne 30b1 <sbrktest+0x381>
2e69: 83 ec 0c sub $0xc,%esp
2e6c: 6a 00 push $0x0
2e6e: e8 b7 0a 00 00 call 392a <sbrk>
2e73: 8d 96 00 10 00 00 lea 0x1000(%esi),%edx
2e79: 83 c4 10 add $0x10,%esp
2e7c: 39 d0 cmp %edx,%eax
2e7e: 0f 85 2d 02 00 00 jne 30b1 <sbrktest+0x381>
if(*lastaddr == 99){
2e84: 80 3d ff ff 3f 06 63 cmpb $0x63,0x63fffff
2e8b: 0f 84 09 02 00 00 je 309a <sbrktest+0x36a>
a = sbrk(0);
2e91: 83 ec 0c sub $0xc,%esp
2e94: 6a 00 push $0x0
2e96: e8 8f 0a 00 00 call 392a <sbrk>
c = sbrk(-(sbrk(0) - oldbrk));
2e9b: c7 04 24 00 00 00 00 movl $0x0,(%esp)
a = sbrk(0);
2ea2: 89 c6 mov %eax,%esi
c = sbrk(-(sbrk(0) - oldbrk));
2ea4: e8 81 0a 00 00 call 392a <sbrk>
2ea9: 89 d9 mov %ebx,%ecx
2eab: 29 c1 sub %eax,%ecx
2ead: 89 0c 24 mov %ecx,(%esp)
2eb0: e8 75 0a 00 00 call 392a <sbrk>
if(c != a){
2eb5: 83 c4 10 add $0x10,%esp
2eb8: 39 c6 cmp %eax,%esi
2eba: 0f 85 c3 01 00 00 jne 3083 <sbrktest+0x353>
for(a = (char*)(KERNBASE); a < (char*) (KERNBASE+2000000); a += 50000){
2ec0: be 00 00 00 80 mov $0x80000000,%esi
ppid = getpid();
2ec5: e8 58 0a 00 00 call 3922 <getpid>
2eca: 89 c7 mov %eax,%edi
pid = fork();
2ecc: e8 c9 09 00 00 call 389a <fork>
if(pid < 0){
2ed1: 85 c0 test %eax,%eax
2ed3: 0f 88 93 01 00 00 js 306c <sbrktest+0x33c>
if(pid == 0){
2ed9: 0f 84 6b 01 00 00 je 304a <sbrktest+0x31a>
for(a = (char*)(KERNBASE); a < (char*) (KERNBASE+2000000); a += 50000){
2edf: 81 c6 50 c3 00 00 add $0xc350,%esi
wait();
2ee5: e8 c0 09 00 00 call 38aa <wait>
for(a = (char*)(KERNBASE); a < (char*) (KERNBASE+2000000); a += 50000){
2eea: 81 fe 80 84 1e 80 cmp $0x801e8480,%esi
2ef0: 75 d3 jne 2ec5 <sbrktest+0x195>
if(pipe(fds) != 0){
2ef2: 8d 45 b8 lea -0x48(%ebp),%eax
2ef5: 83 ec 0c sub $0xc,%esp
2ef8: 50 push %eax
2ef9: e8 b4 09 00 00 call 38b2 <pipe>
2efe: 83 c4 10 add $0x10,%esp
2f01: 85 c0 test %eax,%eax
2f03: 0f 85 2e 01 00 00 jne 3037 <sbrktest+0x307>
2f09: 8d 7d c0 lea -0x40(%ebp),%edi
2f0c: 89 fe mov %edi,%esi
2f0e: eb 23 jmp 2f33 <sbrktest+0x203>
if(pids[i] != -1)
2f10: 83 f8 ff cmp $0xffffffff,%eax
2f13: 74 14 je 2f29 <sbrktest+0x1f9>
read(fds[0], &scratch, 1);
2f15: 8d 45 b7 lea -0x49(%ebp),%eax
2f18: 83 ec 04 sub $0x4,%esp
2f1b: 6a 01 push $0x1
2f1d: 50 push %eax
2f1e: ff 75 b8 pushl -0x48(%ebp)
2f21: e8 94 09 00 00 call 38ba <read>
2f26: 83 c4 10 add $0x10,%esp
for(i = 0; i < sizeof(pids)/sizeof(pids[0]); i++){
2f29: 8d 45 e8 lea -0x18(%ebp),%eax
2f2c: 83 c6 04 add $0x4,%esi
2f2f: 39 c6 cmp %eax,%esi
2f31: 74 4f je 2f82 <sbrktest+0x252>
if((pids[i] = fork()) == 0){
2f33: e8 62 09 00 00 call 389a <fork>
2f38: 85 c0 test %eax,%eax
2f3a: 89 06 mov %eax,(%esi)
2f3c: 75 d2 jne 2f10 <sbrktest+0x1e0>
sbrk(BIG - (uint)sbrk(0));
2f3e: 83 ec 0c sub $0xc,%esp
2f41: 6a 00 push $0x0
2f43: e8 e2 09 00 00 call 392a <sbrk>
2f48: ba 00 00 40 06 mov $0x6400000,%edx
2f4d: 29 c2 sub %eax,%edx
2f4f: 89 14 24 mov %edx,(%esp)
2f52: e8 d3 09 00 00 call 392a <sbrk>
write(fds[1], "x", 1);
2f57: 83 c4 0c add $0xc,%esp
2f5a: 6a 01 push $0x1
2f5c: 68 b1 46 00 00 push $0x46b1
2f61: ff 75 bc pushl -0x44(%ebp)
2f64: e8 59 09 00 00 call 38c2 <write>
2f69: 83 c4 10 add $0x10,%esp
2f6c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
for(;;) sleep(1000);
2f70: 83 ec 0c sub $0xc,%esp
2f73: 68 e8 03 00 00 push $0x3e8
2f78: e8 b5 09 00 00 call 3932 <sleep>
2f7d: 83 c4 10 add $0x10,%esp
2f80: eb ee jmp 2f70 <sbrktest+0x240>
c = sbrk(4096);
2f82: 83 ec 0c sub $0xc,%esp
2f85: 68 00 10 00 00 push $0x1000
2f8a: e8 9b 09 00 00 call 392a <sbrk>
2f8f: 83 c4 10 add $0x10,%esp
2f92: 89 45 a4 mov %eax,-0x5c(%ebp)
if(pids[i] == -1)
2f95: 8b 07 mov (%edi),%eax
2f97: 83 f8 ff cmp $0xffffffff,%eax
2f9a: 74 11 je 2fad <sbrktest+0x27d>
kill(pids[i]);
2f9c: 83 ec 0c sub $0xc,%esp
2f9f: 50 push %eax
2fa0: e8 2d 09 00 00 call 38d2 <kill>
wait();
2fa5: e8 00 09 00 00 call 38aa <wait>
2faa: 83 c4 10 add $0x10,%esp
2fad: 83 c7 04 add $0x4,%edi
for(i = 0; i < sizeof(pids)/sizeof(pids[0]); i++){
2fb0: 39 fe cmp %edi,%esi
2fb2: 75 e1 jne 2f95 <sbrktest+0x265>
if(c == (char*)0xffffffff){
2fb4: 83 7d a4 ff cmpl $0xffffffff,-0x5c(%ebp)
2fb8: 74 66 je 3020 <sbrktest+0x2f0>
if(sbrk(0) > oldbrk)
2fba: 83 ec 0c sub $0xc,%esp
2fbd: 6a 00 push $0x0
2fbf: e8 66 09 00 00 call 392a <sbrk>
2fc4: 83 c4 10 add $0x10,%esp
2fc7: 39 d8 cmp %ebx,%eax
2fc9: 77 3c ja 3007 <sbrktest+0x2d7>
printf(stdout, "sbrk test OK\n");
2fcb: 83 ec 08 sub $0x8,%esp
2fce: 68 f0 4b 00 00 push $0x4bf0
2fd3: ff 35 08 5e 00 00 pushl 0x5e08
2fd9: e8 22 0a 00 00 call 3a00 <printf>
}
2fde: 83 c4 10 add $0x10,%esp
2fe1: 8d 65 f4 lea -0xc(%ebp),%esp
2fe4: 5b pop %ebx
2fe5: 5e pop %esi
2fe6: 5f pop %edi
2fe7: 5d pop %ebp
2fe8: c3 ret
printf(stdout, "sbrk test failed %d %x %x\n", i, a, b);
2fe9: 83 ec 0c sub $0xc,%esp
2fec: 50 push %eax
2fed: 56 push %esi
2fee: 57 push %edi
2fef: 68 53 4b 00 00 push $0x4b53
2ff4: ff 35 08 5e 00 00 pushl 0x5e08
2ffa: e8 01 0a 00 00 call 3a00 <printf>
exit();
2fff: 83 c4 20 add $0x20,%esp
3002: e8 9b 08 00 00 call 38a2 <exit>
sbrk(-(sbrk(0) - oldbrk));
3007: 83 ec 0c sub $0xc,%esp
300a: 6a 00 push $0x0
300c: e8 19 09 00 00 call 392a <sbrk>
3011: 29 c3 sub %eax,%ebx
3013: 89 1c 24 mov %ebx,(%esp)
3016: e8 0f 09 00 00 call 392a <sbrk>
301b: 83 c4 10 add $0x10,%esp
301e: eb ab jmp 2fcb <sbrktest+0x29b>
printf(stdout, "failed sbrk leaked memory\n");
3020: 50 push %eax
3021: 50 push %eax
3022: 68 d5 4b 00 00 push $0x4bd5
3027: ff 35 08 5e 00 00 pushl 0x5e08
302d: e8 ce 09 00 00 call 3a00 <printf>
exit();
3032: e8 6b 08 00 00 call 38a2 <exit>
printf(1, "pipe() failed\n");
3037: 52 push %edx
3038: 52 push %edx
3039: 68 91 40 00 00 push $0x4091
303e: 6a 01 push $0x1
3040: e8 bb 09 00 00 call 3a00 <printf>
exit();
3045: e8 58 08 00 00 call 38a2 <exit>
printf(stdout, "oops could read %x = %x\n", a, *a);
304a: 0f be 06 movsbl (%esi),%eax
304d: 50 push %eax
304e: 56 push %esi
304f: 68 bc 4b 00 00 push $0x4bbc
3054: ff 35 08 5e 00 00 pushl 0x5e08
305a: e8 a1 09 00 00 call 3a00 <printf>
kill(ppid);
305f: 89 3c 24 mov %edi,(%esp)
3062: e8 6b 08 00 00 call 38d2 <kill>
exit();
3067: e8 36 08 00 00 call 38a2 <exit>
printf(stdout, "fork failed\n");
306c: 51 push %ecx
306d: 51 push %ecx
306e: 68 99 4c 00 00 push $0x4c99
3073: ff 35 08 5e 00 00 pushl 0x5e08
3079: e8 82 09 00 00 call 3a00 <printf>
exit();
307e: e8 1f 08 00 00 call 38a2 <exit>
printf(stdout, "sbrk downsize failed, a %x c %x\n", a, c);
3083: 50 push %eax
3084: 56 push %esi
3085: 68 9c 53 00 00 push $0x539c
308a: ff 35 08 5e 00 00 pushl 0x5e08
3090: e8 6b 09 00 00 call 3a00 <printf>
exit();
3095: e8 08 08 00 00 call 38a2 <exit>
printf(stdout, "sbrk de-allocation didn't really deallocate\n");
309a: 53 push %ebx
309b: 53 push %ebx
309c: 68 6c 53 00 00 push $0x536c
30a1: ff 35 08 5e 00 00 pushl 0x5e08
30a7: e8 54 09 00 00 call 3a00 <printf>
exit();
30ac: e8 f1 07 00 00 call 38a2 <exit>
printf(stdout, "sbrk re-allocation failed, a %x c %x\n", a, c);
30b1: 57 push %edi
30b2: 56 push %esi
30b3: 68 44 53 00 00 push $0x5344
30b8: ff 35 08 5e 00 00 pushl 0x5e08
30be: e8 3d 09 00 00 call 3a00 <printf>
exit();
30c3: e8 da 07 00 00 call 38a2 <exit>
printf(stdout, "sbrk deallocation produced wrong address, a %x c %x\n", a, c);
30c8: 50 push %eax
30c9: 56 push %esi
30ca: 68 0c 53 00 00 push $0x530c
30cf: ff 35 08 5e 00 00 pushl 0x5e08
30d5: e8 26 09 00 00 call 3a00 <printf>
exit();
30da: e8 c3 07 00 00 call 38a2 <exit>
printf(stdout, "sbrk could not deallocate\n");
30df: 56 push %esi
30e0: 56 push %esi
30e1: 68 a1 4b 00 00 push $0x4ba1
30e6: ff 35 08 5e 00 00 pushl 0x5e08
30ec: e8 0f 09 00 00 call 3a00 <printf>
exit();
30f1: e8 ac 07 00 00 call 38a2 <exit>
printf(stdout, "sbrk test failed to grow big address space; enough phys mem?\n");
30f6: 57 push %edi
30f7: 57 push %edi
30f8: 68 cc 52 00 00 push $0x52cc
30fd: ff 35 08 5e 00 00 pushl 0x5e08
3103: e8 f8 08 00 00 call 3a00 <printf>
exit();
3108: e8 95 07 00 00 call 38a2 <exit>
exit();
310d: e8 90 07 00 00 call 38a2 <exit>
printf(stdout, "sbrk test failed post-fork\n");
3112: 50 push %eax
3113: 50 push %eax
3114: 68 85 4b 00 00 push $0x4b85
3119: ff 35 08 5e 00 00 pushl 0x5e08
311f: e8 dc 08 00 00 call 3a00 <printf>
exit();
3124: e8 79 07 00 00 call 38a2 <exit>
printf(stdout, "sbrk test fork failed\n");
3129: 50 push %eax
312a: 50 push %eax
312b: 68 6e 4b 00 00 push $0x4b6e
3130: ff 35 08 5e 00 00 pushl 0x5e08
3136: e8 c5 08 00 00 call 3a00 <printf>
exit();
313b: e8 62 07 00 00 call 38a2 <exit>
00003140 <validateint>:
{
3140: 55 push %ebp
3141: 89 e5 mov %esp,%ebp
}
3143: 5d pop %ebp
3144: c3 ret
3145: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
3149: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00003150 <validatetest>:
{
3150: 55 push %ebp
3151: 89 e5 mov %esp,%ebp
3153: 56 push %esi
3154: 53 push %ebx
for(p = 0; p <= (uint)hi; p += 4096){
3155: 31 db xor %ebx,%ebx
printf(stdout, "validate test\n");
3157: 83 ec 08 sub $0x8,%esp
315a: 68 fe 4b 00 00 push $0x4bfe
315f: ff 35 08 5e 00 00 pushl 0x5e08
3165: e8 96 08 00 00 call 3a00 <printf>
316a: 83 c4 10 add $0x10,%esp
316d: 8d 76 00 lea 0x0(%esi),%esi
if((pid = fork()) == 0){
3170: e8 25 07 00 00 call 389a <fork>
3175: 85 c0 test %eax,%eax
3177: 89 c6 mov %eax,%esi
3179: 74 63 je 31de <validatetest+0x8e>
sleep(0);
317b: 83 ec 0c sub $0xc,%esp
317e: 6a 00 push $0x0
3180: e8 ad 07 00 00 call 3932 <sleep>
sleep(0);
3185: c7 04 24 00 00 00 00 movl $0x0,(%esp)
318c: e8 a1 07 00 00 call 3932 <sleep>
kill(pid);
3191: 89 34 24 mov %esi,(%esp)
3194: e8 39 07 00 00 call 38d2 <kill>
wait();
3199: e8 0c 07 00 00 call 38aa <wait>
if(link("nosuchfile", (char*)p) != -1){
319e: 58 pop %eax
319f: 5a pop %edx
31a0: 53 push %ebx
31a1: 68 0d 4c 00 00 push $0x4c0d
31a6: e8 57 07 00 00 call 3902 <link>
31ab: 83 c4 10 add $0x10,%esp
31ae: 83 f8 ff cmp $0xffffffff,%eax
31b1: 75 30 jne 31e3 <validatetest+0x93>
for(p = 0; p <= (uint)hi; p += 4096){
31b3: 81 c3 00 10 00 00 add $0x1000,%ebx
31b9: 81 fb 00 40 11 00 cmp $0x114000,%ebx
31bf: 75 af jne 3170 <validatetest+0x20>
printf(stdout, "validate ok\n");
31c1: 83 ec 08 sub $0x8,%esp
31c4: 68 31 4c 00 00 push $0x4c31
31c9: ff 35 08 5e 00 00 pushl 0x5e08
31cf: e8 2c 08 00 00 call 3a00 <printf>
}
31d4: 83 c4 10 add $0x10,%esp
31d7: 8d 65 f8 lea -0x8(%ebp),%esp
31da: 5b pop %ebx
31db: 5e pop %esi
31dc: 5d pop %ebp
31dd: c3 ret
exit();
31de: e8 bf 06 00 00 call 38a2 <exit>
printf(stdout, "link should not succeed\n");
31e3: 83 ec 08 sub $0x8,%esp
31e6: 68 18 4c 00 00 push $0x4c18
31eb: ff 35 08 5e 00 00 pushl 0x5e08
31f1: e8 0a 08 00 00 call 3a00 <printf>
exit();
31f6: e8 a7 06 00 00 call 38a2 <exit>
31fb: 90 nop
31fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00003200 <bsstest>:
{
3200: 55 push %ebp
3201: 89 e5 mov %esp,%ebp
3203: 83 ec 10 sub $0x10,%esp
printf(stdout, "bss test\n");
3206: 68 3e 4c 00 00 push $0x4c3e
320b: ff 35 08 5e 00 00 pushl 0x5e08
3211: e8 ea 07 00 00 call 3a00 <printf>
if(uninit[i] != '\0'){
3216: 83 c4 10 add $0x10,%esp
3219: 80 3d c0 5e 00 00 00 cmpb $0x0,0x5ec0
3220: 75 39 jne 325b <bsstest+0x5b>
for(i = 0; i < sizeof(uninit); i++){
3222: b8 01 00 00 00 mov $0x1,%eax
3227: 89 f6 mov %esi,%esi
3229: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
if(uninit[i] != '\0'){
3230: 80 b8 c0 5e 00 00 00 cmpb $0x0,0x5ec0(%eax)
3237: 75 22 jne 325b <bsstest+0x5b>
for(i = 0; i < sizeof(uninit); i++){
3239: 83 c0 01 add $0x1,%eax
323c: 3d 10 27 00 00 cmp $0x2710,%eax
3241: 75 ed jne 3230 <bsstest+0x30>
printf(stdout, "bss test ok\n");
3243: 83 ec 08 sub $0x8,%esp
3246: 68 59 4c 00 00 push $0x4c59
324b: ff 35 08 5e 00 00 pushl 0x5e08
3251: e8 aa 07 00 00 call 3a00 <printf>
}
3256: 83 c4 10 add $0x10,%esp
3259: c9 leave
325a: c3 ret
printf(stdout, "bss test failed\n");
325b: 83 ec 08 sub $0x8,%esp
325e: 68 48 4c 00 00 push $0x4c48
3263: ff 35 08 5e 00 00 pushl 0x5e08
3269: e8 92 07 00 00 call 3a00 <printf>
exit();
326e: e8 2f 06 00 00 call 38a2 <exit>
3273: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
3279: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00003280 <bigargtest>:
{
3280: 55 push %ebp
3281: 89 e5 mov %esp,%ebp
3283: 83 ec 14 sub $0x14,%esp
unlink("bigarg-ok");
3286: 68 66 4c 00 00 push $0x4c66
328b: e8 62 06 00 00 call 38f2 <unlink>
pid = fork();
3290: e8 05 06 00 00 call 389a <fork>
if(pid == 0){
3295: 83 c4 10 add $0x10,%esp
3298: 85 c0 test %eax,%eax
329a: 74 3f je 32db <bigargtest+0x5b>
} else if(pid < 0){
329c: 0f 88 c2 00 00 00 js 3364 <bigargtest+0xe4>
wait();
32a2: e8 03 06 00 00 call 38aa <wait>
fd = open("bigarg-ok", 0);
32a7: 83 ec 08 sub $0x8,%esp
32aa: 6a 00 push $0x0
32ac: 68 66 4c 00 00 push $0x4c66
32b1: e8 2c 06 00 00 call 38e2 <open>
if(fd < 0){
32b6: 83 c4 10 add $0x10,%esp
32b9: 85 c0 test %eax,%eax
32bb: 0f 88 8c 00 00 00 js 334d <bigargtest+0xcd>
close(fd);
32c1: 83 ec 0c sub $0xc,%esp
32c4: 50 push %eax
32c5: e8 00 06 00 00 call 38ca <close>
unlink("bigarg-ok");
32ca: c7 04 24 66 4c 00 00 movl $0x4c66,(%esp)
32d1: e8 1c 06 00 00 call 38f2 <unlink>
}
32d6: 83 c4 10 add $0x10,%esp
32d9: c9 leave
32da: c3 ret
32db: b8 20 5e 00 00 mov $0x5e20,%eax
args[i] = "bigargs test: failed\n ";
32e0: c7 00 c0 53 00 00 movl $0x53c0,(%eax)
32e6: 83 c0 04 add $0x4,%eax
for(i = 0; i < MAXARG-1; i++)
32e9: 3d 9c 5e 00 00 cmp $0x5e9c,%eax
32ee: 75 f0 jne 32e0 <bigargtest+0x60>
printf(stdout, "bigarg test\n");
32f0: 51 push %ecx
32f1: 51 push %ecx
32f2: 68 70 4c 00 00 push $0x4c70
32f7: ff 35 08 5e 00 00 pushl 0x5e08
args[MAXARG-1] = 0;
32fd: c7 05 9c 5e 00 00 00 movl $0x0,0x5e9c
3304: 00 00 00
printf(stdout, "bigarg test\n");
3307: e8 f4 06 00 00 call 3a00 <printf>
exec("echo", args);
330c: 58 pop %eax
330d: 5a pop %edx
330e: 68 20 5e 00 00 push $0x5e20
3313: 68 3d 3e 00 00 push $0x3e3d
3318: e8 bd 05 00 00 call 38da <exec>
printf(stdout, "bigarg test ok\n");
331d: 59 pop %ecx
331e: 58 pop %eax
331f: 68 7d 4c 00 00 push $0x4c7d
3324: ff 35 08 5e 00 00 pushl 0x5e08
332a: e8 d1 06 00 00 call 3a00 <printf>
fd = open("bigarg-ok", O_CREATE);
332f: 58 pop %eax
3330: 5a pop %edx
3331: 68 00 02 00 00 push $0x200
3336: 68 66 4c 00 00 push $0x4c66
333b: e8 a2 05 00 00 call 38e2 <open>
close(fd);
3340: 89 04 24 mov %eax,(%esp)
3343: e8 82 05 00 00 call 38ca <close>
exit();
3348: e8 55 05 00 00 call 38a2 <exit>
printf(stdout, "bigarg test failed!\n");
334d: 50 push %eax
334e: 50 push %eax
334f: 68 a6 4c 00 00 push $0x4ca6
3354: ff 35 08 5e 00 00 pushl 0x5e08
335a: e8 a1 06 00 00 call 3a00 <printf>
exit();
335f: e8 3e 05 00 00 call 38a2 <exit>
printf(stdout, "bigargtest: fork failed\n");
3364: 52 push %edx
3365: 52 push %edx
3366: 68 8d 4c 00 00 push $0x4c8d
336b: ff 35 08 5e 00 00 pushl 0x5e08
3371: e8 8a 06 00 00 call 3a00 <printf>
exit();
3376: e8 27 05 00 00 call 38a2 <exit>
337b: 90 nop
337c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00003380 <fsfull>:
{
3380: 55 push %ebp
3381: 89 e5 mov %esp,%ebp
3383: 57 push %edi
3384: 56 push %esi
3385: 53 push %ebx
for(nfiles = 0; ; nfiles++){
3386: 31 db xor %ebx,%ebx
{
3388: 83 ec 54 sub $0x54,%esp
printf(1, "fsfull test\n");
338b: 68 bb 4c 00 00 push $0x4cbb
3390: 6a 01 push $0x1
3392: e8 69 06 00 00 call 3a00 <printf>
3397: 83 c4 10 add $0x10,%esp
339a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
name[1] = '0' + nfiles / 1000;
33a0: b8 d3 4d 62 10 mov $0x10624dd3,%eax
name[3] = '0' + (nfiles % 100) / 10;
33a5: b9 cd cc cc cc mov $0xcccccccd,%ecx
printf(1, "writing %s\n", name);
33aa: 83 ec 04 sub $0x4,%esp
name[1] = '0' + nfiles / 1000;
33ad: f7 e3 mul %ebx
name[0] = 'f';
33af: c6 45 a8 66 movb $0x66,-0x58(%ebp)
name[5] = '\0';
33b3: c6 45 ad 00 movb $0x0,-0x53(%ebp)
name[1] = '0' + nfiles / 1000;
33b7: c1 ea 06 shr $0x6,%edx
33ba: 8d 42 30 lea 0x30(%edx),%eax
name[2] = '0' + (nfiles % 1000) / 100;
33bd: 69 d2 e8 03 00 00 imul $0x3e8,%edx,%edx
name[1] = '0' + nfiles / 1000;
33c3: 88 45 a9 mov %al,-0x57(%ebp)
name[2] = '0' + (nfiles % 1000) / 100;
33c6: 89 d8 mov %ebx,%eax
33c8: 29 d0 sub %edx,%eax
33ca: 89 c2 mov %eax,%edx
33cc: b8 1f 85 eb 51 mov $0x51eb851f,%eax
33d1: f7 e2 mul %edx
name[3] = '0' + (nfiles % 100) / 10;
33d3: b8 1f 85 eb 51 mov $0x51eb851f,%eax
name[2] = '0' + (nfiles % 1000) / 100;
33d8: c1 ea 05 shr $0x5,%edx
33db: 83 c2 30 add $0x30,%edx
33de: 88 55 aa mov %dl,-0x56(%ebp)
name[3] = '0' + (nfiles % 100) / 10;
33e1: f7 e3 mul %ebx
33e3: 89 d8 mov %ebx,%eax
33e5: c1 ea 05 shr $0x5,%edx
33e8: 6b d2 64 imul $0x64,%edx,%edx
33eb: 29 d0 sub %edx,%eax
33ed: f7 e1 mul %ecx
name[4] = '0' + (nfiles % 10);
33ef: 89 d8 mov %ebx,%eax
name[3] = '0' + (nfiles % 100) / 10;
33f1: c1 ea 03 shr $0x3,%edx
33f4: 83 c2 30 add $0x30,%edx
33f7: 88 55 ab mov %dl,-0x55(%ebp)
name[4] = '0' + (nfiles % 10);
33fa: f7 e1 mul %ecx
33fc: 89 d9 mov %ebx,%ecx
33fe: c1 ea 03 shr $0x3,%edx
3401: 8d 04 92 lea (%edx,%edx,4),%eax
3404: 01 c0 add %eax,%eax
3406: 29 c1 sub %eax,%ecx
3408: 89 c8 mov %ecx,%eax
340a: 83 c0 30 add $0x30,%eax
340d: 88 45 ac mov %al,-0x54(%ebp)
printf(1, "writing %s\n", name);
3410: 8d 45 a8 lea -0x58(%ebp),%eax
3413: 50 push %eax
3414: 68 c8 4c 00 00 push $0x4cc8
3419: 6a 01 push $0x1
341b: e8 e0 05 00 00 call 3a00 <printf>
int fd = open(name, O_CREATE|O_RDWR);
3420: 58 pop %eax
3421: 8d 45 a8 lea -0x58(%ebp),%eax
3424: 5a pop %edx
3425: 68 02 02 00 00 push $0x202
342a: 50 push %eax
342b: e8 b2 04 00 00 call 38e2 <open>
if(fd < 0){
3430: 83 c4 10 add $0x10,%esp
3433: 85 c0 test %eax,%eax
int fd = open(name, O_CREATE|O_RDWR);
3435: 89 c7 mov %eax,%edi
if(fd < 0){
3437: 78 57 js 3490 <fsfull+0x110>
int total = 0;
3439: 31 f6 xor %esi,%esi
343b: eb 05 jmp 3442 <fsfull+0xc2>
343d: 8d 76 00 lea 0x0(%esi),%esi
total += cc;
3440: 01 c6 add %eax,%esi
int cc = write(fd, buf, 512);
3442: 83 ec 04 sub $0x4,%esp
3445: 68 00 02 00 00 push $0x200
344a: 68 e0 85 00 00 push $0x85e0
344f: 57 push %edi
3450: e8 6d 04 00 00 call 38c2 <write>
if(cc < 512)
3455: 83 c4 10 add $0x10,%esp
3458: 3d ff 01 00 00 cmp $0x1ff,%eax
345d: 7f e1 jg 3440 <fsfull+0xc0>
printf(1, "wrote %d bytes\n", total);
345f: 83 ec 04 sub $0x4,%esp
3462: 56 push %esi
3463: 68 e4 4c 00 00 push $0x4ce4
3468: 6a 01 push $0x1
346a: e8 91 05 00 00 call 3a00 <printf>
close(fd);
346f: 89 3c 24 mov %edi,(%esp)
3472: e8 53 04 00 00 call 38ca <close>
if(total == 0)
3477: 83 c4 10 add $0x10,%esp
347a: 85 f6 test %esi,%esi
347c: 74 28 je 34a6 <fsfull+0x126>
for(nfiles = 0; ; nfiles++){
347e: 83 c3 01 add $0x1,%ebx
3481: e9 1a ff ff ff jmp 33a0 <fsfull+0x20>
3486: 8d 76 00 lea 0x0(%esi),%esi
3489: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
printf(1, "open %s failed\n", name);
3490: 8d 45 a8 lea -0x58(%ebp),%eax
3493: 83 ec 04 sub $0x4,%esp
3496: 50 push %eax
3497: 68 d4 4c 00 00 push $0x4cd4
349c: 6a 01 push $0x1
349e: e8 5d 05 00 00 call 3a00 <printf>
break;
34a3: 83 c4 10 add $0x10,%esp
name[1] = '0' + nfiles / 1000;
34a6: bf d3 4d 62 10 mov $0x10624dd3,%edi
name[2] = '0' + (nfiles % 1000) / 100;
34ab: be 1f 85 eb 51 mov $0x51eb851f,%esi
name[1] = '0' + nfiles / 1000;
34b0: 89 d8 mov %ebx,%eax
name[3] = '0' + (nfiles % 100) / 10;
34b2: b9 cd cc cc cc mov $0xcccccccd,%ecx
unlink(name);
34b7: 83 ec 0c sub $0xc,%esp
name[1] = '0' + nfiles / 1000;
34ba: f7 e7 mul %edi
name[0] = 'f';
34bc: c6 45 a8 66 movb $0x66,-0x58(%ebp)
name[5] = '\0';
34c0: c6 45 ad 00 movb $0x0,-0x53(%ebp)
name[1] = '0' + nfiles / 1000;
34c4: c1 ea 06 shr $0x6,%edx
34c7: 8d 42 30 lea 0x30(%edx),%eax
name[2] = '0' + (nfiles % 1000) / 100;
34ca: 69 d2 e8 03 00 00 imul $0x3e8,%edx,%edx
name[1] = '0' + nfiles / 1000;
34d0: 88 45 a9 mov %al,-0x57(%ebp)
name[2] = '0' + (nfiles % 1000) / 100;
34d3: 89 d8 mov %ebx,%eax
34d5: 29 d0 sub %edx,%eax
34d7: f7 e6 mul %esi
name[3] = '0' + (nfiles % 100) / 10;
34d9: 89 d8 mov %ebx,%eax
name[2] = '0' + (nfiles % 1000) / 100;
34db: c1 ea 05 shr $0x5,%edx
34de: 83 c2 30 add $0x30,%edx
34e1: 88 55 aa mov %dl,-0x56(%ebp)
name[3] = '0' + (nfiles % 100) / 10;
34e4: f7 e6 mul %esi
34e6: 89 d8 mov %ebx,%eax
34e8: c1 ea 05 shr $0x5,%edx
34eb: 6b d2 64 imul $0x64,%edx,%edx
34ee: 29 d0 sub %edx,%eax
34f0: f7 e1 mul %ecx
name[4] = '0' + (nfiles % 10);
34f2: 89 d8 mov %ebx,%eax
name[3] = '0' + (nfiles % 100) / 10;
34f4: c1 ea 03 shr $0x3,%edx
34f7: 83 c2 30 add $0x30,%edx
34fa: 88 55 ab mov %dl,-0x55(%ebp)
name[4] = '0' + (nfiles % 10);
34fd: f7 e1 mul %ecx
34ff: 89 d9 mov %ebx,%ecx
nfiles--;
3501: 83 eb 01 sub $0x1,%ebx
name[4] = '0' + (nfiles % 10);
3504: c1 ea 03 shr $0x3,%edx
3507: 8d 04 92 lea (%edx,%edx,4),%eax
350a: 01 c0 add %eax,%eax
350c: 29 c1 sub %eax,%ecx
350e: 89 c8 mov %ecx,%eax
3510: 83 c0 30 add $0x30,%eax
3513: 88 45 ac mov %al,-0x54(%ebp)
unlink(name);
3516: 8d 45 a8 lea -0x58(%ebp),%eax
3519: 50 push %eax
351a: e8 d3 03 00 00 call 38f2 <unlink>
while(nfiles >= 0){
351f: 83 c4 10 add $0x10,%esp
3522: 83 fb ff cmp $0xffffffff,%ebx
3525: 75 89 jne 34b0 <fsfull+0x130>
printf(1, "fsfull test finished\n");
3527: 83 ec 08 sub $0x8,%esp
352a: 68 f4 4c 00 00 push $0x4cf4
352f: 6a 01 push $0x1
3531: e8 ca 04 00 00 call 3a00 <printf>
}
3536: 83 c4 10 add $0x10,%esp
3539: 8d 65 f4 lea -0xc(%ebp),%esp
353c: 5b pop %ebx
353d: 5e pop %esi
353e: 5f pop %edi
353f: 5d pop %ebp
3540: c3 ret
3541: eb 0d jmp 3550 <uio>
3543: 90 nop
3544: 90 nop
3545: 90 nop
3546: 90 nop
3547: 90 nop
3548: 90 nop
3549: 90 nop
354a: 90 nop
354b: 90 nop
354c: 90 nop
354d: 90 nop
354e: 90 nop
354f: 90 nop
00003550 <uio>:
{
3550: 55 push %ebp
3551: 89 e5 mov %esp,%ebp
3553: 83 ec 10 sub $0x10,%esp
printf(1, "uio test\n");
3556: 68 0a 4d 00 00 push $0x4d0a
355b: 6a 01 push $0x1
355d: e8 9e 04 00 00 call 3a00 <printf>
pid = fork();
3562: e8 33 03 00 00 call 389a <fork>
if(pid == 0){
3567: 83 c4 10 add $0x10,%esp
356a: 85 c0 test %eax,%eax
356c: 74 1b je 3589 <uio+0x39>
} else if(pid < 0){
356e: 78 3d js 35ad <uio+0x5d>
wait();
3570: e8 35 03 00 00 call 38aa <wait>
printf(1, "uio test done\n");
3575: 83 ec 08 sub $0x8,%esp
3578: 68 14 4d 00 00 push $0x4d14
357d: 6a 01 push $0x1
357f: e8 7c 04 00 00 call 3a00 <printf>
}
3584: 83 c4 10 add $0x10,%esp
3587: c9 leave
3588: c3 ret
asm volatile("outb %0,%1"::"a"(val), "d" (port));
3589: b8 09 00 00 00 mov $0x9,%eax
358e: ba 70 00 00 00 mov $0x70,%edx
3593: ee out %al,(%dx)
asm volatile("inb %1,%0" : "=a" (val) : "d" (port));
3594: ba 71 00 00 00 mov $0x71,%edx
3599: ec in (%dx),%al
printf(1, "uio: uio succeeded; test FAILED\n");
359a: 52 push %edx
359b: 52 push %edx
359c: 68 a0 54 00 00 push $0x54a0
35a1: 6a 01 push $0x1
35a3: e8 58 04 00 00 call 3a00 <printf>
exit();
35a8: e8 f5 02 00 00 call 38a2 <exit>
printf (1, "fork failed\n");
35ad: 50 push %eax
35ae: 50 push %eax
35af: 68 99 4c 00 00 push $0x4c99
35b4: 6a 01 push $0x1
35b6: e8 45 04 00 00 call 3a00 <printf>
exit();
35bb: e8 e2 02 00 00 call 38a2 <exit>
000035c0 <argptest>:
{
35c0: 55 push %ebp
35c1: 89 e5 mov %esp,%ebp
35c3: 53 push %ebx
35c4: 83 ec 0c sub $0xc,%esp
fd = open("init", O_RDONLY);
35c7: 6a 00 push $0x0
35c9: 68 23 4d 00 00 push $0x4d23
35ce: e8 0f 03 00 00 call 38e2 <open>
if (fd < 0) {
35d3: 83 c4 10 add $0x10,%esp
35d6: 85 c0 test %eax,%eax
35d8: 78 39 js 3613 <argptest+0x53>
read(fd, sbrk(0) - 1, -1);
35da: 83 ec 0c sub $0xc,%esp
35dd: 89 c3 mov %eax,%ebx
35df: 6a 00 push $0x0
35e1: e8 44 03 00 00 call 392a <sbrk>
35e6: 83 c4 0c add $0xc,%esp
35e9: 83 e8 01 sub $0x1,%eax
35ec: 6a ff push $0xffffffff
35ee: 50 push %eax
35ef: 53 push %ebx
35f0: e8 c5 02 00 00 call 38ba <read>
close(fd);
35f5: 89 1c 24 mov %ebx,(%esp)
35f8: e8 cd 02 00 00 call 38ca <close>
printf(1, "arg test passed\n");
35fd: 58 pop %eax
35fe: 5a pop %edx
35ff: 68 35 4d 00 00 push $0x4d35
3604: 6a 01 push $0x1
3606: e8 f5 03 00 00 call 3a00 <printf>
}
360b: 83 c4 10 add $0x10,%esp
360e: 8b 5d fc mov -0x4(%ebp),%ebx
3611: c9 leave
3612: c3 ret
printf(2, "open failed\n");
3613: 51 push %ecx
3614: 51 push %ecx
3615: 68 28 4d 00 00 push $0x4d28
361a: 6a 02 push $0x2
361c: e8 df 03 00 00 call 3a00 <printf>
exit();
3621: e8 7c 02 00 00 call 38a2 <exit>
3626: 8d 76 00 lea 0x0(%esi),%esi
3629: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00003630 <rand>:
randstate = randstate * 1664525 + 1013904223;
3630: 69 05 04 5e 00 00 0d imul $0x19660d,0x5e04,%eax
3637: 66 19 00
{
363a: 55 push %ebp
363b: 89 e5 mov %esp,%ebp
}
363d: 5d pop %ebp
randstate = randstate * 1664525 + 1013904223;
363e: 05 5f f3 6e 3c add $0x3c6ef35f,%eax
3643: a3 04 5e 00 00 mov %eax,0x5e04
}
3648: c3 ret
3649: 66 90 xchg %ax,%ax
364b: 66 90 xchg %ax,%ax
364d: 66 90 xchg %ax,%ax
364f: 90 nop
00003650 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
3650: 55 push %ebp
3651: 89 e5 mov %esp,%ebp
3653: 53 push %ebx
3654: 8b 45 08 mov 0x8(%ebp),%eax
3657: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
365a: 89 c2 mov %eax,%edx
365c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
3660: 83 c1 01 add $0x1,%ecx
3663: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
3667: 83 c2 01 add $0x1,%edx
366a: 84 db test %bl,%bl
366c: 88 5a ff mov %bl,-0x1(%edx)
366f: 75 ef jne 3660 <strcpy+0x10>
;
return os;
}
3671: 5b pop %ebx
3672: 5d pop %ebp
3673: c3 ret
3674: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
367a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00003680 <strcmp>:
int
strcmp(const char *p, const char *q)
{
3680: 55 push %ebp
3681: 89 e5 mov %esp,%ebp
3683: 53 push %ebx
3684: 8b 55 08 mov 0x8(%ebp),%edx
3687: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
368a: 0f b6 02 movzbl (%edx),%eax
368d: 0f b6 19 movzbl (%ecx),%ebx
3690: 84 c0 test %al,%al
3692: 75 1c jne 36b0 <strcmp+0x30>
3694: eb 2a jmp 36c0 <strcmp+0x40>
3696: 8d 76 00 lea 0x0(%esi),%esi
3699: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
36a0: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
36a3: 0f b6 02 movzbl (%edx),%eax
p++, q++;
36a6: 83 c1 01 add $0x1,%ecx
36a9: 0f b6 19 movzbl (%ecx),%ebx
while(*p && *p == *q)
36ac: 84 c0 test %al,%al
36ae: 74 10 je 36c0 <strcmp+0x40>
36b0: 38 d8 cmp %bl,%al
36b2: 74 ec je 36a0 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
36b4: 29 d8 sub %ebx,%eax
}
36b6: 5b pop %ebx
36b7: 5d pop %ebp
36b8: c3 ret
36b9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
36c0: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
36c2: 29 d8 sub %ebx,%eax
}
36c4: 5b pop %ebx
36c5: 5d pop %ebp
36c6: c3 ret
36c7: 89 f6 mov %esi,%esi
36c9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000036d0 <strlen>:
uint
strlen(const char *s)
{
36d0: 55 push %ebp
36d1: 89 e5 mov %esp,%ebp
36d3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
36d6: 80 39 00 cmpb $0x0,(%ecx)
36d9: 74 15 je 36f0 <strlen+0x20>
36db: 31 d2 xor %edx,%edx
36dd: 8d 76 00 lea 0x0(%esi),%esi
36e0: 83 c2 01 add $0x1,%edx
36e3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
36e7: 89 d0 mov %edx,%eax
36e9: 75 f5 jne 36e0 <strlen+0x10>
;
return n;
}
36eb: 5d pop %ebp
36ec: c3 ret
36ed: 8d 76 00 lea 0x0(%esi),%esi
for(n = 0; s[n]; n++)
36f0: 31 c0 xor %eax,%eax
}
36f2: 5d pop %ebp
36f3: c3 ret
36f4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
36fa: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00003700 <memset>:
void*
memset(void *dst, int c, uint n)
{
3700: 55 push %ebp
3701: 89 e5 mov %esp,%ebp
3703: 57 push %edi
3704: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
3707: 8b 4d 10 mov 0x10(%ebp),%ecx
370a: 8b 45 0c mov 0xc(%ebp),%eax
370d: 89 d7 mov %edx,%edi
370f: fc cld
3710: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
3712: 89 d0 mov %edx,%eax
3714: 5f pop %edi
3715: 5d pop %ebp
3716: c3 ret
3717: 89 f6 mov %esi,%esi
3719: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00003720 <strchr>:
char*
strchr(const char *s, char c)
{
3720: 55 push %ebp
3721: 89 e5 mov %esp,%ebp
3723: 53 push %ebx
3724: 8b 45 08 mov 0x8(%ebp),%eax
3727: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
372a: 0f b6 10 movzbl (%eax),%edx
372d: 84 d2 test %dl,%dl
372f: 74 1d je 374e <strchr+0x2e>
if(*s == c)
3731: 38 d3 cmp %dl,%bl
3733: 89 d9 mov %ebx,%ecx
3735: 75 0d jne 3744 <strchr+0x24>
3737: eb 17 jmp 3750 <strchr+0x30>
3739: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
3740: 38 ca cmp %cl,%dl
3742: 74 0c je 3750 <strchr+0x30>
for(; *s; s++)
3744: 83 c0 01 add $0x1,%eax
3747: 0f b6 10 movzbl (%eax),%edx
374a: 84 d2 test %dl,%dl
374c: 75 f2 jne 3740 <strchr+0x20>
return (char*)s;
return 0;
374e: 31 c0 xor %eax,%eax
}
3750: 5b pop %ebx
3751: 5d pop %ebp
3752: c3 ret
3753: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
3759: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00003760 <gets>:
char*
gets(char *buf, int max)
{
3760: 55 push %ebp
3761: 89 e5 mov %esp,%ebp
3763: 57 push %edi
3764: 56 push %esi
3765: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
3766: 31 f6 xor %esi,%esi
3768: 89 f3 mov %esi,%ebx
{
376a: 83 ec 1c sub $0x1c,%esp
376d: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
3770: eb 2f jmp 37a1 <gets+0x41>
3772: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
3778: 8d 45 e7 lea -0x19(%ebp),%eax
377b: 83 ec 04 sub $0x4,%esp
377e: 6a 01 push $0x1
3780: 50 push %eax
3781: 6a 00 push $0x0
3783: e8 32 01 00 00 call 38ba <read>
if(cc < 1)
3788: 83 c4 10 add $0x10,%esp
378b: 85 c0 test %eax,%eax
378d: 7e 1c jle 37ab <gets+0x4b>
break;
buf[i++] = c;
378f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
3793: 83 c7 01 add $0x1,%edi
3796: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
3799: 3c 0a cmp $0xa,%al
379b: 74 23 je 37c0 <gets+0x60>
379d: 3c 0d cmp $0xd,%al
379f: 74 1f je 37c0 <gets+0x60>
for(i=0; i+1 < max; ){
37a1: 83 c3 01 add $0x1,%ebx
37a4: 3b 5d 0c cmp 0xc(%ebp),%ebx
37a7: 89 fe mov %edi,%esi
37a9: 7c cd jl 3778 <gets+0x18>
37ab: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
37ad: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
37b0: c6 03 00 movb $0x0,(%ebx)
}
37b3: 8d 65 f4 lea -0xc(%ebp),%esp
37b6: 5b pop %ebx
37b7: 5e pop %esi
37b8: 5f pop %edi
37b9: 5d pop %ebp
37ba: c3 ret
37bb: 90 nop
37bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
37c0: 8b 75 08 mov 0x8(%ebp),%esi
37c3: 8b 45 08 mov 0x8(%ebp),%eax
37c6: 01 de add %ebx,%esi
37c8: 89 f3 mov %esi,%ebx
buf[i] = '\0';
37ca: c6 03 00 movb $0x0,(%ebx)
}
37cd: 8d 65 f4 lea -0xc(%ebp),%esp
37d0: 5b pop %ebx
37d1: 5e pop %esi
37d2: 5f pop %edi
37d3: 5d pop %ebp
37d4: c3 ret
37d5: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
37d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000037e0 <stat>:
int
stat(const char *n, struct stat *st)
{
37e0: 55 push %ebp
37e1: 89 e5 mov %esp,%ebp
37e3: 56 push %esi
37e4: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
37e5: 83 ec 08 sub $0x8,%esp
37e8: 6a 00 push $0x0
37ea: ff 75 08 pushl 0x8(%ebp)
37ed: e8 f0 00 00 00 call 38e2 <open>
if(fd < 0)
37f2: 83 c4 10 add $0x10,%esp
37f5: 85 c0 test %eax,%eax
37f7: 78 27 js 3820 <stat+0x40>
return -1;
r = fstat(fd, st);
37f9: 83 ec 08 sub $0x8,%esp
37fc: ff 75 0c pushl 0xc(%ebp)
37ff: 89 c3 mov %eax,%ebx
3801: 50 push %eax
3802: e8 f3 00 00 00 call 38fa <fstat>
close(fd);
3807: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
380a: 89 c6 mov %eax,%esi
close(fd);
380c: e8 b9 00 00 00 call 38ca <close>
return r;
3811: 83 c4 10 add $0x10,%esp
}
3814: 8d 65 f8 lea -0x8(%ebp),%esp
3817: 89 f0 mov %esi,%eax
3819: 5b pop %ebx
381a: 5e pop %esi
381b: 5d pop %ebp
381c: c3 ret
381d: 8d 76 00 lea 0x0(%esi),%esi
return -1;
3820: be ff ff ff ff mov $0xffffffff,%esi
3825: eb ed jmp 3814 <stat+0x34>
3827: 89 f6 mov %esi,%esi
3829: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00003830 <atoi>:
int
atoi(const char *s)
{
3830: 55 push %ebp
3831: 89 e5 mov %esp,%ebp
3833: 53 push %ebx
3834: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
3837: 0f be 11 movsbl (%ecx),%edx
383a: 8d 42 d0 lea -0x30(%edx),%eax
383d: 3c 09 cmp $0x9,%al
n = 0;
383f: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
3844: 77 1f ja 3865 <atoi+0x35>
3846: 8d 76 00 lea 0x0(%esi),%esi
3849: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
3850: 8d 04 80 lea (%eax,%eax,4),%eax
3853: 83 c1 01 add $0x1,%ecx
3856: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
while('0' <= *s && *s <= '9')
385a: 0f be 11 movsbl (%ecx),%edx
385d: 8d 5a d0 lea -0x30(%edx),%ebx
3860: 80 fb 09 cmp $0x9,%bl
3863: 76 eb jbe 3850 <atoi+0x20>
return n;
}
3865: 5b pop %ebx
3866: 5d pop %ebp
3867: c3 ret
3868: 90 nop
3869: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00003870 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
3870: 55 push %ebp
3871: 89 e5 mov %esp,%ebp
3873: 56 push %esi
3874: 53 push %ebx
3875: 8b 5d 10 mov 0x10(%ebp),%ebx
3878: 8b 45 08 mov 0x8(%ebp),%eax
387b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
387e: 85 db test %ebx,%ebx
3880: 7e 14 jle 3896 <memmove+0x26>
3882: 31 d2 xor %edx,%edx
3884: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
3888: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
388c: 88 0c 10 mov %cl,(%eax,%edx,1)
388f: 83 c2 01 add $0x1,%edx
while(n-- > 0)
3892: 39 d3 cmp %edx,%ebx
3894: 75 f2 jne 3888 <memmove+0x18>
return vdst;
}
3896: 5b pop %ebx
3897: 5e pop %esi
3898: 5d pop %ebp
3899: c3 ret
0000389a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
389a: b8 01 00 00 00 mov $0x1,%eax
389f: cd 40 int $0x40
38a1: c3 ret
000038a2 <exit>:
SYSCALL(exit)
38a2: b8 02 00 00 00 mov $0x2,%eax
38a7: cd 40 int $0x40
38a9: c3 ret
000038aa <wait>:
SYSCALL(wait)
38aa: b8 03 00 00 00 mov $0x3,%eax
38af: cd 40 int $0x40
38b1: c3 ret
000038b2 <pipe>:
SYSCALL(pipe)
38b2: b8 04 00 00 00 mov $0x4,%eax
38b7: cd 40 int $0x40
38b9: c3 ret
000038ba <read>:
SYSCALL(read)
38ba: b8 05 00 00 00 mov $0x5,%eax
38bf: cd 40 int $0x40
38c1: c3 ret
000038c2 <write>:
SYSCALL(write)
38c2: b8 10 00 00 00 mov $0x10,%eax
38c7: cd 40 int $0x40
38c9: c3 ret
000038ca <close>:
SYSCALL(close)
38ca: b8 15 00 00 00 mov $0x15,%eax
38cf: cd 40 int $0x40
38d1: c3 ret
000038d2 <kill>:
SYSCALL(kill)
38d2: b8 06 00 00 00 mov $0x6,%eax
38d7: cd 40 int $0x40
38d9: c3 ret
000038da <exec>:
SYSCALL(exec)
38da: b8 07 00 00 00 mov $0x7,%eax
38df: cd 40 int $0x40
38e1: c3 ret
000038e2 <open>:
SYSCALL(open)
38e2: b8 0f 00 00 00 mov $0xf,%eax
38e7: cd 40 int $0x40
38e9: c3 ret
000038ea <mknod>:
SYSCALL(mknod)
38ea: b8 11 00 00 00 mov $0x11,%eax
38ef: cd 40 int $0x40
38f1: c3 ret
000038f2 <unlink>:
SYSCALL(unlink)
38f2: b8 12 00 00 00 mov $0x12,%eax
38f7: cd 40 int $0x40
38f9: c3 ret
000038fa <fstat>:
SYSCALL(fstat)
38fa: b8 08 00 00 00 mov $0x8,%eax
38ff: cd 40 int $0x40
3901: c3 ret
00003902 <link>:
SYSCALL(link)
3902: b8 13 00 00 00 mov $0x13,%eax
3907: cd 40 int $0x40
3909: c3 ret
0000390a <mkdir>:
SYSCALL(mkdir)
390a: b8 14 00 00 00 mov $0x14,%eax
390f: cd 40 int $0x40
3911: c3 ret
00003912 <chdir>:
SYSCALL(chdir)
3912: b8 09 00 00 00 mov $0x9,%eax
3917: cd 40 int $0x40
3919: c3 ret
0000391a <dup>:
SYSCALL(dup)
391a: b8 0a 00 00 00 mov $0xa,%eax
391f: cd 40 int $0x40
3921: c3 ret
00003922 <getpid>:
SYSCALL(getpid)
3922: b8 0b 00 00 00 mov $0xb,%eax
3927: cd 40 int $0x40
3929: c3 ret
0000392a <sbrk>:
SYSCALL(sbrk)
392a: b8 0c 00 00 00 mov $0xc,%eax
392f: cd 40 int $0x40
3931: c3 ret
00003932 <sleep>:
SYSCALL(sleep)
3932: b8 0d 00 00 00 mov $0xd,%eax
3937: cd 40 int $0x40
3939: c3 ret
0000393a <uptime>:
SYSCALL(uptime)
393a: b8 0e 00 00 00 mov $0xe,%eax
393f: cd 40 int $0x40
3941: c3 ret
00003942 <reentrant>:
SYSCALL(reentrant)
3942: b8 16 00 00 00 mov $0x16,%eax
3947: cd 40 int $0x40
3949: c3 ret
0000394a <barrier>:
SYSCALL(barrier)
394a: b8 17 00 00 00 mov $0x17,%eax
394f: cd 40 int $0x40
3951: c3 ret
00003952 <init_barrier>:
3952: b8 18 00 00 00 mov $0x18,%eax
3957: cd 40 int $0x40
3959: c3 ret
395a: 66 90 xchg %ax,%ax
395c: 66 90 xchg %ax,%ax
395e: 66 90 xchg %ax,%ax
00003960 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
3960: 55 push %ebp
3961: 89 e5 mov %esp,%ebp
3963: 57 push %edi
3964: 56 push %esi
3965: 53 push %ebx
3966: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
3969: 85 d2 test %edx,%edx
{
396b: 89 45 c0 mov %eax,-0x40(%ebp)
neg = 1;
x = -xx;
396e: 89 d0 mov %edx,%eax
if(sgn && xx < 0){
3970: 79 76 jns 39e8 <printint+0x88>
3972: f6 45 08 01 testb $0x1,0x8(%ebp)
3976: 74 70 je 39e8 <printint+0x88>
x = -xx;
3978: f7 d8 neg %eax
neg = 1;
397a: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
} else {
x = xx;
}
i = 0;
3981: 31 f6 xor %esi,%esi
3983: 8d 5d d7 lea -0x29(%ebp),%ebx
3986: eb 0a jmp 3992 <printint+0x32>
3988: 90 nop
3989: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
do{
buf[i++] = digits[x % base];
3990: 89 fe mov %edi,%esi
3992: 31 d2 xor %edx,%edx
3994: 8d 7e 01 lea 0x1(%esi),%edi
3997: f7 f1 div %ecx
3999: 0f b6 92 f8 54 00 00 movzbl 0x54f8(%edx),%edx
}while((x /= base) != 0);
39a0: 85 c0 test %eax,%eax
buf[i++] = digits[x % base];
39a2: 88 14 3b mov %dl,(%ebx,%edi,1)
}while((x /= base) != 0);
39a5: 75 e9 jne 3990 <printint+0x30>
if(neg)
39a7: 8b 45 c4 mov -0x3c(%ebp),%eax
39aa: 85 c0 test %eax,%eax
39ac: 74 08 je 39b6 <printint+0x56>
buf[i++] = '-';
39ae: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1)
39b3: 8d 7e 02 lea 0x2(%esi),%edi
39b6: 8d 74 3d d7 lea -0x29(%ebp,%edi,1),%esi
39ba: 8b 7d c0 mov -0x40(%ebp),%edi
39bd: 8d 76 00 lea 0x0(%esi),%esi
39c0: 0f b6 06 movzbl (%esi),%eax
write(fd, &c, 1);
39c3: 83 ec 04 sub $0x4,%esp
39c6: 83 ee 01 sub $0x1,%esi
39c9: 6a 01 push $0x1
39cb: 53 push %ebx
39cc: 57 push %edi
39cd: 88 45 d7 mov %al,-0x29(%ebp)
39d0: e8 ed fe ff ff call 38c2 <write>
while(--i >= 0)
39d5: 83 c4 10 add $0x10,%esp
39d8: 39 de cmp %ebx,%esi
39da: 75 e4 jne 39c0 <printint+0x60>
putc(fd, buf[i]);
}
39dc: 8d 65 f4 lea -0xc(%ebp),%esp
39df: 5b pop %ebx
39e0: 5e pop %esi
39e1: 5f pop %edi
39e2: 5d pop %ebp
39e3: c3 ret
39e4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
39e8: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
39ef: eb 90 jmp 3981 <printint+0x21>
39f1: eb 0d jmp 3a00 <printf>
39f3: 90 nop
39f4: 90 nop
39f5: 90 nop
39f6: 90 nop
39f7: 90 nop
39f8: 90 nop
39f9: 90 nop
39fa: 90 nop
39fb: 90 nop
39fc: 90 nop
39fd: 90 nop
39fe: 90 nop
39ff: 90 nop
00003a00 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
3a00: 55 push %ebp
3a01: 89 e5 mov %esp,%ebp
3a03: 57 push %edi
3a04: 56 push %esi
3a05: 53 push %ebx
3a06: 83 ec 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
3a09: 8b 75 0c mov 0xc(%ebp),%esi
3a0c: 0f b6 1e movzbl (%esi),%ebx
3a0f: 84 db test %bl,%bl
3a11: 0f 84 b3 00 00 00 je 3aca <printf+0xca>
ap = (uint*)(void*)&fmt + 1;
3a17: 8d 45 10 lea 0x10(%ebp),%eax
3a1a: 83 c6 01 add $0x1,%esi
state = 0;
3a1d: 31 ff xor %edi,%edi
ap = (uint*)(void*)&fmt + 1;
3a1f: 89 45 d4 mov %eax,-0x2c(%ebp)
3a22: eb 2f jmp 3a53 <printf+0x53>
3a24: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
3a28: 83 f8 25 cmp $0x25,%eax
3a2b: 0f 84 a7 00 00 00 je 3ad8 <printf+0xd8>
write(fd, &c, 1);
3a31: 8d 45 e2 lea -0x1e(%ebp),%eax
3a34: 83 ec 04 sub $0x4,%esp
3a37: 88 5d e2 mov %bl,-0x1e(%ebp)
3a3a: 6a 01 push $0x1
3a3c: 50 push %eax
3a3d: ff 75 08 pushl 0x8(%ebp)
3a40: e8 7d fe ff ff call 38c2 <write>
3a45: 83 c4 10 add $0x10,%esp
3a48: 83 c6 01 add $0x1,%esi
for(i = 0; fmt[i]; i++){
3a4b: 0f b6 5e ff movzbl -0x1(%esi),%ebx
3a4f: 84 db test %bl,%bl
3a51: 74 77 je 3aca <printf+0xca>
if(state == 0){
3a53: 85 ff test %edi,%edi
c = fmt[i] & 0xff;
3a55: 0f be cb movsbl %bl,%ecx
3a58: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
3a5b: 74 cb je 3a28 <printf+0x28>
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
3a5d: 83 ff 25 cmp $0x25,%edi
3a60: 75 e6 jne 3a48 <printf+0x48>
if(c == 'd'){
3a62: 83 f8 64 cmp $0x64,%eax
3a65: 0f 84 05 01 00 00 je 3b70 <printf+0x170>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
3a6b: 81 e1 f7 00 00 00 and $0xf7,%ecx
3a71: 83 f9 70 cmp $0x70,%ecx
3a74: 74 72 je 3ae8 <printf+0xe8>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
3a76: 83 f8 73 cmp $0x73,%eax
3a79: 0f 84 99 00 00 00 je 3b18 <printf+0x118>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
3a7f: 83 f8 63 cmp $0x63,%eax
3a82: 0f 84 08 01 00 00 je 3b90 <printf+0x190>
putc(fd, *ap);
ap++;
} else if(c == '%'){
3a88: 83 f8 25 cmp $0x25,%eax
3a8b: 0f 84 ef 00 00 00 je 3b80 <printf+0x180>
write(fd, &c, 1);
3a91: 8d 45 e7 lea -0x19(%ebp),%eax
3a94: 83 ec 04 sub $0x4,%esp
3a97: c6 45 e7 25 movb $0x25,-0x19(%ebp)
3a9b: 6a 01 push $0x1
3a9d: 50 push %eax
3a9e: ff 75 08 pushl 0x8(%ebp)
3aa1: e8 1c fe ff ff call 38c2 <write>
3aa6: 83 c4 0c add $0xc,%esp
3aa9: 8d 45 e6 lea -0x1a(%ebp),%eax
3aac: 88 5d e6 mov %bl,-0x1a(%ebp)
3aaf: 6a 01 push $0x1
3ab1: 50 push %eax
3ab2: ff 75 08 pushl 0x8(%ebp)
3ab5: 83 c6 01 add $0x1,%esi
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
3ab8: 31 ff xor %edi,%edi
write(fd, &c, 1);
3aba: e8 03 fe ff ff call 38c2 <write>
for(i = 0; fmt[i]; i++){
3abf: 0f b6 5e ff movzbl -0x1(%esi),%ebx
write(fd, &c, 1);
3ac3: 83 c4 10 add $0x10,%esp
for(i = 0; fmt[i]; i++){
3ac6: 84 db test %bl,%bl
3ac8: 75 89 jne 3a53 <printf+0x53>
}
}
}
3aca: 8d 65 f4 lea -0xc(%ebp),%esp
3acd: 5b pop %ebx
3ace: 5e pop %esi
3acf: 5f pop %edi
3ad0: 5d pop %ebp
3ad1: c3 ret
3ad2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
state = '%';
3ad8: bf 25 00 00 00 mov $0x25,%edi
3add: e9 66 ff ff ff jmp 3a48 <printf+0x48>
3ae2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
printint(fd, *ap, 16, 0);
3ae8: 83 ec 0c sub $0xc,%esp
3aeb: b9 10 00 00 00 mov $0x10,%ecx
3af0: 6a 00 push $0x0
3af2: 8b 7d d4 mov -0x2c(%ebp),%edi
3af5: 8b 45 08 mov 0x8(%ebp),%eax
3af8: 8b 17 mov (%edi),%edx
3afa: e8 61 fe ff ff call 3960 <printint>
ap++;
3aff: 89 f8 mov %edi,%eax
3b01: 83 c4 10 add $0x10,%esp
state = 0;
3b04: 31 ff xor %edi,%edi
ap++;
3b06: 83 c0 04 add $0x4,%eax
3b09: 89 45 d4 mov %eax,-0x2c(%ebp)
3b0c: e9 37 ff ff ff jmp 3a48 <printf+0x48>
3b11: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
s = (char*)*ap;
3b18: 8b 45 d4 mov -0x2c(%ebp),%eax
3b1b: 8b 08 mov (%eax),%ecx
ap++;
3b1d: 83 c0 04 add $0x4,%eax
3b20: 89 45 d4 mov %eax,-0x2c(%ebp)
if(s == 0)
3b23: 85 c9 test %ecx,%ecx
3b25: 0f 84 8e 00 00 00 je 3bb9 <printf+0x1b9>
while(*s != 0){
3b2b: 0f b6 01 movzbl (%ecx),%eax
state = 0;
3b2e: 31 ff xor %edi,%edi
s = (char*)*ap;
3b30: 89 cb mov %ecx,%ebx
while(*s != 0){
3b32: 84 c0 test %al,%al
3b34: 0f 84 0e ff ff ff je 3a48 <printf+0x48>
3b3a: 89 75 d0 mov %esi,-0x30(%ebp)
3b3d: 89 de mov %ebx,%esi
3b3f: 8b 5d 08 mov 0x8(%ebp),%ebx
3b42: 8d 7d e3 lea -0x1d(%ebp),%edi
3b45: 8d 76 00 lea 0x0(%esi),%esi
write(fd, &c, 1);
3b48: 83 ec 04 sub $0x4,%esp
s++;
3b4b: 83 c6 01 add $0x1,%esi
3b4e: 88 45 e3 mov %al,-0x1d(%ebp)
write(fd, &c, 1);
3b51: 6a 01 push $0x1
3b53: 57 push %edi
3b54: 53 push %ebx
3b55: e8 68 fd ff ff call 38c2 <write>
while(*s != 0){
3b5a: 0f b6 06 movzbl (%esi),%eax
3b5d: 83 c4 10 add $0x10,%esp
3b60: 84 c0 test %al,%al
3b62: 75 e4 jne 3b48 <printf+0x148>
3b64: 8b 75 d0 mov -0x30(%ebp),%esi
state = 0;
3b67: 31 ff xor %edi,%edi
3b69: e9 da fe ff ff jmp 3a48 <printf+0x48>
3b6e: 66 90 xchg %ax,%ax
printint(fd, *ap, 10, 1);
3b70: 83 ec 0c sub $0xc,%esp
3b73: b9 0a 00 00 00 mov $0xa,%ecx
3b78: 6a 01 push $0x1
3b7a: e9 73 ff ff ff jmp 3af2 <printf+0xf2>
3b7f: 90 nop
write(fd, &c, 1);
3b80: 83 ec 04 sub $0x4,%esp
3b83: 88 5d e5 mov %bl,-0x1b(%ebp)
3b86: 8d 45 e5 lea -0x1b(%ebp),%eax
3b89: 6a 01 push $0x1
3b8b: e9 21 ff ff ff jmp 3ab1 <printf+0xb1>
putc(fd, *ap);
3b90: 8b 7d d4 mov -0x2c(%ebp),%edi
write(fd, &c, 1);
3b93: 83 ec 04 sub $0x4,%esp
putc(fd, *ap);
3b96: 8b 07 mov (%edi),%eax
write(fd, &c, 1);
3b98: 6a 01 push $0x1
ap++;
3b9a: 83 c7 04 add $0x4,%edi
putc(fd, *ap);
3b9d: 88 45 e4 mov %al,-0x1c(%ebp)
write(fd, &c, 1);
3ba0: 8d 45 e4 lea -0x1c(%ebp),%eax
3ba3: 50 push %eax
3ba4: ff 75 08 pushl 0x8(%ebp)
3ba7: e8 16 fd ff ff call 38c2 <write>
ap++;
3bac: 89 7d d4 mov %edi,-0x2c(%ebp)
3baf: 83 c4 10 add $0x10,%esp
state = 0;
3bb2: 31 ff xor %edi,%edi
3bb4: e9 8f fe ff ff jmp 3a48 <printf+0x48>
s = "(null)";
3bb9: bb f0 54 00 00 mov $0x54f0,%ebx
while(*s != 0){
3bbe: b8 28 00 00 00 mov $0x28,%eax
3bc3: e9 72 ff ff ff jmp 3b3a <printf+0x13a>
3bc8: 66 90 xchg %ax,%ax
3bca: 66 90 xchg %ax,%ax
3bcc: 66 90 xchg %ax,%ax
3bce: 66 90 xchg %ax,%ax
00003bd0 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
3bd0: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
3bd1: a1 a0 5e 00 00 mov 0x5ea0,%eax
{
3bd6: 89 e5 mov %esp,%ebp
3bd8: 57 push %edi
3bd9: 56 push %esi
3bda: 53 push %ebx
3bdb: 8b 5d 08 mov 0x8(%ebp),%ebx
bp = (Header*)ap - 1;
3bde: 8d 4b f8 lea -0x8(%ebx),%ecx
3be1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
3be8: 39 c8 cmp %ecx,%eax
3bea: 8b 10 mov (%eax),%edx
3bec: 73 32 jae 3c20 <free+0x50>
3bee: 39 d1 cmp %edx,%ecx
3bf0: 72 04 jb 3bf6 <free+0x26>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
3bf2: 39 d0 cmp %edx,%eax
3bf4: 72 32 jb 3c28 <free+0x58>
break;
if(bp + bp->s.size == p->s.ptr){
3bf6: 8b 73 fc mov -0x4(%ebx),%esi
3bf9: 8d 3c f1 lea (%ecx,%esi,8),%edi
3bfc: 39 fa cmp %edi,%edx
3bfe: 74 30 je 3c30 <free+0x60>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
3c00: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
3c03: 8b 50 04 mov 0x4(%eax),%edx
3c06: 8d 34 d0 lea (%eax,%edx,8),%esi
3c09: 39 f1 cmp %esi,%ecx
3c0b: 74 3a je 3c47 <free+0x77>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
3c0d: 89 08 mov %ecx,(%eax)
freep = p;
3c0f: a3 a0 5e 00 00 mov %eax,0x5ea0
}
3c14: 5b pop %ebx
3c15: 5e pop %esi
3c16: 5f pop %edi
3c17: 5d pop %ebp
3c18: c3 ret
3c19: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
3c20: 39 d0 cmp %edx,%eax
3c22: 72 04 jb 3c28 <free+0x58>
3c24: 39 d1 cmp %edx,%ecx
3c26: 72 ce jb 3bf6 <free+0x26>
{
3c28: 89 d0 mov %edx,%eax
3c2a: eb bc jmp 3be8 <free+0x18>
3c2c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
bp->s.size += p->s.ptr->s.size;
3c30: 03 72 04 add 0x4(%edx),%esi
3c33: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
3c36: 8b 10 mov (%eax),%edx
3c38: 8b 12 mov (%edx),%edx
3c3a: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
3c3d: 8b 50 04 mov 0x4(%eax),%edx
3c40: 8d 34 d0 lea (%eax,%edx,8),%esi
3c43: 39 f1 cmp %esi,%ecx
3c45: 75 c6 jne 3c0d <free+0x3d>
p->s.size += bp->s.size;
3c47: 03 53 fc add -0x4(%ebx),%edx
freep = p;
3c4a: a3 a0 5e 00 00 mov %eax,0x5ea0
p->s.size += bp->s.size;
3c4f: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
3c52: 8b 53 f8 mov -0x8(%ebx),%edx
3c55: 89 10 mov %edx,(%eax)
}
3c57: 5b pop %ebx
3c58: 5e pop %esi
3c59: 5f pop %edi
3c5a: 5d pop %ebp
3c5b: c3 ret
3c5c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00003c60 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
3c60: 55 push %ebp
3c61: 89 e5 mov %esp,%ebp
3c63: 57 push %edi
3c64: 56 push %esi
3c65: 53 push %ebx
3c66: 83 ec 0c sub $0xc,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
3c69: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
3c6c: 8b 15 a0 5e 00 00 mov 0x5ea0,%edx
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
3c72: 8d 78 07 lea 0x7(%eax),%edi
3c75: c1 ef 03 shr $0x3,%edi
3c78: 83 c7 01 add $0x1,%edi
if((prevp = freep) == 0){
3c7b: 85 d2 test %edx,%edx
3c7d: 0f 84 9d 00 00 00 je 3d20 <malloc+0xc0>
3c83: 8b 02 mov (%edx),%eax
3c85: 8b 48 04 mov 0x4(%eax),%ecx
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
3c88: 39 cf cmp %ecx,%edi
3c8a: 76 6c jbe 3cf8 <malloc+0x98>
3c8c: 81 ff 00 10 00 00 cmp $0x1000,%edi
3c92: bb 00 10 00 00 mov $0x1000,%ebx
3c97: 0f 43 df cmovae %edi,%ebx
p = sbrk(nu * sizeof(Header));
3c9a: 8d 34 dd 00 00 00 00 lea 0x0(,%ebx,8),%esi
3ca1: eb 0e jmp 3cb1 <malloc+0x51>
3ca3: 90 nop
3ca4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
3ca8: 8b 02 mov (%edx),%eax
if(p->s.size >= nunits){
3caa: 8b 48 04 mov 0x4(%eax),%ecx
3cad: 39 f9 cmp %edi,%ecx
3caf: 73 47 jae 3cf8 <malloc+0x98>
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
3cb1: 39 05 a0 5e 00 00 cmp %eax,0x5ea0
3cb7: 89 c2 mov %eax,%edx
3cb9: 75 ed jne 3ca8 <malloc+0x48>
p = sbrk(nu * sizeof(Header));
3cbb: 83 ec 0c sub $0xc,%esp
3cbe: 56 push %esi
3cbf: e8 66 fc ff ff call 392a <sbrk>
if(p == (char*)-1)
3cc4: 83 c4 10 add $0x10,%esp
3cc7: 83 f8 ff cmp $0xffffffff,%eax
3cca: 74 1c je 3ce8 <malloc+0x88>
hp->s.size = nu;
3ccc: 89 58 04 mov %ebx,0x4(%eax)
free((void*)(hp + 1));
3ccf: 83 ec 0c sub $0xc,%esp
3cd2: 83 c0 08 add $0x8,%eax
3cd5: 50 push %eax
3cd6: e8 f5 fe ff ff call 3bd0 <free>
return freep;
3cdb: 8b 15 a0 5e 00 00 mov 0x5ea0,%edx
if((p = morecore(nunits)) == 0)
3ce1: 83 c4 10 add $0x10,%esp
3ce4: 85 d2 test %edx,%edx
3ce6: 75 c0 jne 3ca8 <malloc+0x48>
return 0;
}
}
3ce8: 8d 65 f4 lea -0xc(%ebp),%esp
return 0;
3ceb: 31 c0 xor %eax,%eax
}
3ced: 5b pop %ebx
3cee: 5e pop %esi
3cef: 5f pop %edi
3cf0: 5d pop %ebp
3cf1: c3 ret
3cf2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
if(p->s.size == nunits)
3cf8: 39 cf cmp %ecx,%edi
3cfa: 74 54 je 3d50 <malloc+0xf0>
p->s.size -= nunits;
3cfc: 29 f9 sub %edi,%ecx
3cfe: 89 48 04 mov %ecx,0x4(%eax)
p += p->s.size;
3d01: 8d 04 c8 lea (%eax,%ecx,8),%eax
p->s.size = nunits;
3d04: 89 78 04 mov %edi,0x4(%eax)
freep = prevp;
3d07: 89 15 a0 5e 00 00 mov %edx,0x5ea0
}
3d0d: 8d 65 f4 lea -0xc(%ebp),%esp
return (void*)(p + 1);
3d10: 83 c0 08 add $0x8,%eax
}
3d13: 5b pop %ebx
3d14: 5e pop %esi
3d15: 5f pop %edi
3d16: 5d pop %ebp
3d17: c3 ret
3d18: 90 nop
3d19: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
base.s.ptr = freep = prevp = &base;
3d20: c7 05 a0 5e 00 00 a4 movl $0x5ea4,0x5ea0
3d27: 5e 00 00
3d2a: c7 05 a4 5e 00 00 a4 movl $0x5ea4,0x5ea4
3d31: 5e 00 00
base.s.size = 0;
3d34: b8 a4 5e 00 00 mov $0x5ea4,%eax
3d39: c7 05 a8 5e 00 00 00 movl $0x0,0x5ea8
3d40: 00 00 00
3d43: e9 44 ff ff ff jmp 3c8c <malloc+0x2c>
3d48: 90 nop
3d49: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
prevp->s.ptr = p->s.ptr;
3d50: 8b 08 mov (%eax),%ecx
3d52: 89 0a mov %ecx,(%edx)
3d54: eb b1 jmp 3d07 <malloc+0xa7>
|
#ifndef _AFJHAYYTA_PYOPENCL_HEADER_SEEN_WRAP_CL_HPP
#define _AFJHAYYTA_PYOPENCL_HEADER_SEEN_WRAP_CL_HPP
// CL 1.2 undecided:
// clSetPrintfCallback
// {{{ includes
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
// #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#ifdef __APPLE__
// Mac ------------------------------------------------------------------------
#include <OpenCL/opencl.h>
#include "pyopencl_ext.h"
#ifdef HAVE_GL
#define PYOPENCL_GL_SHARING_VERSION 1
#include <OpenGL/OpenGL.h>
#include <OpenCL/cl_gl.h>
#include <OpenCL/cl_gl_ext.h>
#endif
#else
// elsewhere ------------------------------------------------------------------
#define CL_TARGET_OPENCL_VERSION 220
#include <CL/cl.h>
#include "pyopencl_ext.h"
#if defined(_WIN32)
#define NOMINMAX
#include <windows.h>
#endif
#ifdef HAVE_GL
#include <GL/gl.h>
#include <CL/cl_gl.h>
#endif
#if defined(cl_khr_gl_sharing) && (cl_khr_gl_sharing >= 1)
#define PYOPENCL_GL_SHARING_VERSION cl_khr_gl_sharing
#endif
#endif
#include <thread>
#include <mutex>
#include <condition_variable>
#include <cstdio>
#include <stdexcept>
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include "wrap_helpers.hpp"
#include "numpy_init.hpp"
#include "tools.hpp"
#ifdef PYOPENCL_PRETEND_CL_VERSION
#define PYOPENCL_CL_VERSION PYOPENCL_PRETEND_CL_VERSION
#else
#if defined(CL_VERSION_2_2)
#define PYOPENCL_CL_VERSION 0x2020
#elif defined(CL_VERSION_2_1)
#define PYOPENCL_CL_VERSION 0x2010
#elif defined(CL_VERSION_2_0)
#define PYOPENCL_CL_VERSION 0x2000
#elif defined(CL_VERSION_1_2)
#define PYOPENCL_CL_VERSION 0x1020
#elif defined(CL_VERSION_1_1)
#define PYOPENCL_CL_VERSION 0x1010
#else
#define PYOPENCL_CL_VERSION 0x1000
#endif
#endif
#if (PY_VERSION_HEX >= 0x03000000) or defined(PYPY_VERSION)
#define PYOPENCL_USE_NEW_BUFFER_INTERFACE
#define PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(s) std::move(s)
#else
#define PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(s) (s)
#endif
#if defined(_WIN32)
// MSVC does not understand variable-length arrays
#define PYOPENCL_STACK_CONTAINER(TYPE, NAME, COUNT) std::vector<TYPE> NAME(COUNT)
#define PYOPENCL_STACK_CONTAINER_GET_PTR(NAME) (NAME.size() ? NAME.data() : nullptr)
#else
// gcc et al complain about stripping attributes in template arguments
#define PYOPENCL_STACK_CONTAINER(TYPE, NAME, COUNT) TYPE NAME[COUNT]
#define PYOPENCL_STACK_CONTAINER_GET_PTR(NAME) NAME
#endif
// }}}
// {{{ tools
#if PY_VERSION_HEX >= 0x02050000
typedef Py_ssize_t PYOPENCL_BUFFER_SIZE_T;
#else
typedef int PYOPENCL_BUFFER_SIZE_T;
#endif
#define PYOPENCL_CAST_BOOL(B) ((B) ? CL_TRUE : CL_FALSE)
#define PYOPENCL_DEPRECATED(WHAT, KILL_VERSION, EXTRA_MSG) \
{ \
PyErr_Warn( \
PyExc_DeprecationWarning, \
WHAT " is deprecated and will stop working in PyOpenCL " KILL_VERSION". " \
EXTRA_MSG); \
}
#if PYOPENCL_CL_VERSION >= 0x1020
#define PYOPENCL_GET_EXT_FUN(PLATFORM, NAME, VAR) \
NAME##_fn VAR \
= (NAME##_fn) \
clGetExtensionFunctionAddressForPlatform(PLATFORM, #NAME); \
\
if (!VAR) \
throw error(#NAME, CL_INVALID_VALUE, #NAME \
"not available");
#else
#define PYOPENCL_GET_EXT_FUN(PLATFORM, NAME, VAR) \
NAME##_fn VAR \
= (NAME##_fn) \
clGetExtensionFunctionAddress(#NAME); \
\
if (!VAR) \
throw error(#NAME, CL_INVALID_VALUE, #NAME \
"not available");
#endif
#define PYOPENCL_PARSE_PY_DEVICES \
std::vector<cl_device_id> devices_vec; \
cl_uint num_devices; \
cl_device_id *devices; \
\
if (py_devices.ptr() == Py_None) \
{ \
num_devices = 0; \
devices = 0; \
} \
else \
{ \
for (py::handle py_dev: py_devices) \
devices_vec.push_back( \
(py_dev).cast<device &>().data()); \
num_devices = devices_vec.size(); \
devices = devices_vec.empty( ) ? nullptr : &devices_vec.front(); \
} \
#define PYOPENCL_RETRY_RETURN_IF_MEM_ERROR(OPERATION) \
try \
{ \
OPERATION \
} \
catch (pyopencl::error &e) \
{ \
if (!e.is_out_of_memory()) \
throw; \
} \
\
/* If we get here, we got an error from CL.
* We should run the Python GC to try and free up
* some memory references. */ \
run_python_gc(); \
\
/* Now retry the allocation. If it fails again,
* let it fail. */ \
{ \
OPERATION \
}
#define PYOPENCL_RETRY_IF_MEM_ERROR(OPERATION) \
{ \
bool failed_with_mem_error = false; \
try \
{ \
OPERATION \
} \
catch (pyopencl::error &e) \
{ \
failed_with_mem_error = true; \
if (!e.is_out_of_memory()) \
throw; \
} \
\
if (failed_with_mem_error) \
{ \
/* If we get here, we got an error from CL.
* We should run the Python GC to try and free up
* some memory references. */ \
run_python_gc(); \
\
/* Now retry the allocation. If it fails again,
* let it fail. */ \
{ \
OPERATION \
} \
} \
}
// }}}
// {{{ tracing and error reporting
#ifdef PYOPENCL_TRACE
#define PYOPENCL_PRINT_CALL_TRACE(NAME) \
std::cerr << NAME << std::endl;
#define PYOPENCL_PRINT_CALL_TRACE_INFO(NAME, EXTRA_INFO) \
std::cerr << NAME << " (" << EXTRA_INFO << ')' << std::endl;
#else
#define PYOPENCL_PRINT_CALL_TRACE(NAME) /*nothing*/
#define PYOPENCL_PRINT_CALL_TRACE_INFO(NAME, EXTRA_INFO) /*nothing*/
#endif
#define PYOPENCL_CALL_GUARDED_THREADED_WITH_TRACE_INFO(NAME, ARGLIST, TRACE_INFO) \
{ \
PYOPENCL_PRINT_CALL_TRACE_INFO(#NAME, TRACE_INFO); \
cl_int status_code; \
{ \
py::gil_scoped_release release; \
status_code = NAME ARGLIST; \
} \
if (status_code != CL_SUCCESS) \
throw pyopencl::error(#NAME, status_code);\
}
#define PYOPENCL_CALL_GUARDED_WITH_TRACE_INFO(NAME, ARGLIST, TRACE_INFO) \
{ \
PYOPENCL_PRINT_CALL_TRACE_INFO(#NAME, TRACE_INFO); \
cl_int status_code; \
status_code = NAME ARGLIST; \
if (status_code != CL_SUCCESS) \
throw pyopencl::error(#NAME, status_code);\
}
#define PYOPENCL_CALL_GUARDED_THREADED(NAME, ARGLIST) \
{ \
PYOPENCL_PRINT_CALL_TRACE(#NAME); \
cl_int status_code; \
{ \
py::gil_scoped_release release; \
status_code = NAME ARGLIST; \
} \
if (status_code != CL_SUCCESS) \
throw pyopencl::error(#NAME, status_code);\
}
#define PYOPENCL_CALL_GUARDED(NAME, ARGLIST) \
{ \
PYOPENCL_PRINT_CALL_TRACE(#NAME); \
cl_int status_code; \
status_code = NAME ARGLIST; \
if (status_code != CL_SUCCESS) \
throw pyopencl::error(#NAME, status_code);\
}
#define PYOPENCL_CALL_GUARDED_CLEANUP(NAME, ARGLIST) \
{ \
PYOPENCL_PRINT_CALL_TRACE(#NAME); \
cl_int status_code; \
status_code = NAME ARGLIST; \
if (status_code != CL_SUCCESS) \
std::cerr \
<< "PyOpenCL WARNING: a clean-up operation failed (dead context maybe?)" \
<< std::endl \
<< #NAME " failed with code " << status_code \
<< std::endl; \
}
// }}}
// {{{ get_info helpers
#define PYOPENCL_GET_OPAQUE_INFO(WHAT, FIRST_ARG, SECOND_ARG, CL_TYPE, TYPE) \
{ \
CL_TYPE param_value; \
PYOPENCL_CALL_GUARDED(clGet##WHAT##Info, \
(FIRST_ARG, SECOND_ARG, sizeof(param_value), ¶m_value, 0)); \
if (param_value) \
return py::object(handle_from_new_ptr( \
new TYPE(param_value, /*retain*/ true))); \
else \
return py::none(); \
}
#define PYOPENCL_GET_VEC_INFO(WHAT, FIRST_ARG, SECOND_ARG, RES_VEC) \
{ \
size_t size; \
PYOPENCL_CALL_GUARDED(clGet##WHAT##Info, \
(FIRST_ARG, SECOND_ARG, 0, 0, &size)); \
\
RES_VEC.resize(size / sizeof(RES_VEC.front())); \
\
PYOPENCL_CALL_GUARDED(clGet##WHAT##Info, \
(FIRST_ARG, SECOND_ARG, size, \
RES_VEC.empty( ) ? nullptr : &RES_VEC.front(), &size)); \
}
#define PYOPENCL_GET_STR_INFO(WHAT, FIRST_ARG, SECOND_ARG) \
{ \
size_t param_value_size; \
PYOPENCL_CALL_GUARDED(clGet##WHAT##Info, \
(FIRST_ARG, SECOND_ARG, 0, 0, ¶m_value_size)); \
\
std::vector<char> param_value(param_value_size); \
PYOPENCL_CALL_GUARDED(clGet##WHAT##Info, \
(FIRST_ARG, SECOND_ARG, param_value_size, \
param_value.empty( ) ? nullptr : ¶m_value.front(), ¶m_value_size)); \
\
return py::cast( \
param_value.empty( ) ? "" : std::string(¶m_value.front(), param_value_size-1)); \
}
#define PYOPENCL_GET_INTEGRAL_INFO(WHAT, FIRST_ARG, SECOND_ARG, TYPE) \
{ \
TYPE param_value; \
PYOPENCL_CALL_GUARDED(clGet##WHAT##Info, \
(FIRST_ARG, SECOND_ARG, sizeof(param_value), ¶m_value, 0)); \
return py::cast(param_value); \
}
// }}}
// {{{ event helpers --------------------------------------------------------------
#define PYOPENCL_PARSE_WAIT_FOR \
cl_uint num_events_in_wait_list = 0; \
std::vector<cl_event> event_wait_list; \
\
if (py_wait_for.ptr() != Py_None) \
{ \
event_wait_list.resize(len(py_wait_for)); \
for (py::handle evt: py_wait_for) \
event_wait_list[num_events_in_wait_list++] = \
evt.cast<const event &>().data(); \
}
#define PYOPENCL_WAITLIST_ARGS \
num_events_in_wait_list, event_wait_list.empty( ) ? nullptr : &event_wait_list.front()
#define PYOPENCL_RETURN_NEW_NANNY_EVENT(evt, obj) \
try \
{ \
return new nanny_event(evt, false, obj); \
} \
catch (...) \
{ \
clReleaseEvent(evt); \
throw; \
}
#define PYOPENCL_RETURN_NEW_EVENT(evt) \
try \
{ \
return new event(evt, false); \
} \
catch (...) \
{ \
clReleaseEvent(evt); \
throw; \
}
// }}}
// {{{ equality testing
#define PYOPENCL_EQUALITY_TESTS(cls) \
bool operator==(cls const &other) const \
{ return data() == other.data(); } \
bool operator!=(cls const &other) const \
{ return data() != other.data(); } \
long hash() const \
{ return (long) (intptr_t) data(); }
// }}}
namespace pyopencl
{
class program;
// {{{ error
class error : public std::runtime_error
{
private:
std::string m_routine;
cl_int m_code;
// This is here because clLinkProgram returns a program
// object *just* so that there is somewhere for it to
// stuff the linker logs. :/
bool m_program_initialized;
cl_program m_program;
public:
error(const char *routine, cl_int c, const char *msg="")
: std::runtime_error(msg), m_routine(routine), m_code(c),
m_program_initialized(false), m_program(nullptr)
{ }
error(const char *routine, cl_program prg, cl_int c,
const char *msg="")
: std::runtime_error(msg), m_routine(routine), m_code(c),
m_program_initialized(true), m_program(prg)
{ }
virtual ~error()
{
if (m_program_initialized)
clReleaseProgram(m_program);
}
const std::string &routine() const
{
return m_routine;
}
cl_int code() const
{
return m_code;
}
bool is_out_of_memory() const
{
return (code() == CL_MEM_OBJECT_ALLOCATION_FAILURE
|| code() == CL_OUT_OF_RESOURCES
|| code() == CL_OUT_OF_HOST_MEMORY);
}
program *get_program() const;
};
// }}}
// {{{ buffer interface helper
//
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
class py_buffer_wrapper : public noncopyable
{
private:
bool m_initialized;
public:
Py_buffer m_buf;
py_buffer_wrapper()
: m_initialized(false)
{}
void get(PyObject *obj, int flags)
{
#ifdef PYPY_VERSION
// work around https://bitbucket.org/pypy/pypy/issues/2873
if (flags & PyBUF_ANY_CONTIGUOUS)
{
int flags_wo_cont = flags & ~PyBUF_ANY_CONTIGUOUS;
if (PyObject_GetBuffer(obj, &m_buf, flags_wo_cont | PyBUF_C_CONTIGUOUS))
{
PyErr_Clear();
if (PyObject_GetBuffer(obj, &m_buf, flags_wo_cont | PyBUF_F_CONTIGUOUS))
throw py::error_already_set();
}
}
else
#endif
if (PyObject_GetBuffer(obj, &m_buf, flags))
throw py::error_already_set();
m_initialized = true;
}
virtual ~py_buffer_wrapper()
{
if (m_initialized)
PyBuffer_Release(&m_buf);
}
};
#endif
// }}}
inline
py::tuple get_cl_header_version()
{
return py::make_tuple(
PYOPENCL_CL_VERSION >> (3*4),
(PYOPENCL_CL_VERSION >> (1*4)) & 0xff
);
}
// {{{ platform
class platform : noncopyable
{
private:
cl_platform_id m_platform;
public:
platform(cl_platform_id pid)
: m_platform(pid)
{ }
platform(cl_platform_id pid, bool /*retain (ignored)*/)
: m_platform(pid)
{ }
cl_platform_id data() const
{
return m_platform;
}
PYOPENCL_EQUALITY_TESTS(platform);
py::object get_info(cl_platform_info param_name) const
{
switch (param_name)
{
case CL_PLATFORM_PROFILE:
case CL_PLATFORM_VERSION:
case CL_PLATFORM_NAME:
case CL_PLATFORM_VENDOR:
#if !(defined(CL_PLATFORM_NVIDIA) && CL_PLATFORM_NVIDIA == 0x3001)
case CL_PLATFORM_EXTENSIONS:
#endif
PYOPENCL_GET_STR_INFO(Platform, m_platform, param_name);
default:
throw error("Platform.get_info", CL_INVALID_VALUE);
}
}
py::list get_devices(cl_device_type devtype);
};
inline
py::list get_platforms()
{
cl_uint num_platforms = 0;
PYOPENCL_CALL_GUARDED(clGetPlatformIDs, (0, 0, &num_platforms));
std::vector<cl_platform_id> platforms(num_platforms);
PYOPENCL_CALL_GUARDED(clGetPlatformIDs,
(num_platforms, platforms.empty( ) ? nullptr : &platforms.front(), &num_platforms));
py::list result;
for (cl_platform_id pid: platforms)
result.append(handle_from_new_ptr(
new platform(pid)));
return result;
}
// }}}
// {{{ device
class device : noncopyable
{
public:
enum reference_type_t {
REF_NOT_OWNABLE,
#if PYOPENCL_CL_VERSION >= 0x1020
REF_CL_1_2,
#endif
};
private:
cl_device_id m_device;
reference_type_t m_ref_type;
public:
device(cl_device_id did)
: m_device(did), m_ref_type(REF_NOT_OWNABLE)
{ }
device(cl_device_id did, bool retain, reference_type_t ref_type=REF_NOT_OWNABLE)
: m_device(did), m_ref_type(ref_type)
{
if (retain && ref_type != REF_NOT_OWNABLE)
{
if (false)
{ }
#if PYOPENCL_CL_VERSION >= 0x1020
else if (ref_type == REF_CL_1_2)
{
PYOPENCL_CALL_GUARDED(clRetainDevice, (did));
}
#endif
else
throw error("Device", CL_INVALID_VALUE,
"cannot own references to devices when device fission or CL 1.2 is not available");
}
}
~device()
{
#if PYOPENCL_CL_VERSION >= 0x1020
if (m_ref_type == REF_CL_1_2)
PYOPENCL_CALL_GUARDED_CLEANUP(clReleaseDevice, (m_device));
#endif
}
cl_device_id data() const
{
return m_device;
}
PYOPENCL_EQUALITY_TESTS(device);
py::object get_info(cl_device_info param_name) const
{
#define DEV_GET_INT_INF(TYPE) \
PYOPENCL_GET_INTEGRAL_INFO(Device, m_device, param_name, TYPE);
switch (param_name)
{
case CL_DEVICE_TYPE: DEV_GET_INT_INF(cl_device_type);
case CL_DEVICE_VENDOR_ID: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_MAX_COMPUTE_UNITS: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_MAX_WORK_GROUP_SIZE: DEV_GET_INT_INF(size_t);
case CL_DEVICE_MAX_WORK_ITEM_SIZES:
{
std::vector<size_t> result;
PYOPENCL_GET_VEC_INFO(Device, m_device, param_name, result);
PYOPENCL_RETURN_VECTOR(size_t, result);
}
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_MAX_CLOCK_FREQUENCY: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_ADDRESS_BITS: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_MAX_READ_IMAGE_ARGS: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_MAX_WRITE_IMAGE_ARGS: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_MAX_MEM_ALLOC_SIZE: DEV_GET_INT_INF(cl_ulong);
case CL_DEVICE_IMAGE2D_MAX_WIDTH: DEV_GET_INT_INF(size_t);
case CL_DEVICE_IMAGE2D_MAX_HEIGHT: DEV_GET_INT_INF(size_t);
case CL_DEVICE_IMAGE3D_MAX_WIDTH: DEV_GET_INT_INF(size_t);
case CL_DEVICE_IMAGE3D_MAX_HEIGHT: DEV_GET_INT_INF(size_t);
case CL_DEVICE_IMAGE3D_MAX_DEPTH: DEV_GET_INT_INF(size_t);
case CL_DEVICE_IMAGE_SUPPORT: DEV_GET_INT_INF(cl_bool);
case CL_DEVICE_MAX_PARAMETER_SIZE: DEV_GET_INT_INF(size_t);
case CL_DEVICE_MAX_SAMPLERS: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_MEM_BASE_ADDR_ALIGN: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_SINGLE_FP_CONFIG: DEV_GET_INT_INF(cl_device_fp_config);
#ifdef CL_DEVICE_DOUBLE_FP_CONFIG
case CL_DEVICE_DOUBLE_FP_CONFIG: DEV_GET_INT_INF(cl_device_fp_config);
#endif
#ifdef CL_DEVICE_HALF_FP_CONFIG
case CL_DEVICE_HALF_FP_CONFIG: DEV_GET_INT_INF(cl_device_fp_config);
#endif
case CL_DEVICE_GLOBAL_MEM_CACHE_TYPE: DEV_GET_INT_INF(cl_device_mem_cache_type);
case CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_GLOBAL_MEM_CACHE_SIZE: DEV_GET_INT_INF(cl_ulong);
case CL_DEVICE_GLOBAL_MEM_SIZE: DEV_GET_INT_INF(cl_ulong);
case CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE: DEV_GET_INT_INF(cl_ulong);
case CL_DEVICE_MAX_CONSTANT_ARGS: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_LOCAL_MEM_TYPE: DEV_GET_INT_INF(cl_device_local_mem_type);
case CL_DEVICE_LOCAL_MEM_SIZE: DEV_GET_INT_INF(cl_ulong);
case CL_DEVICE_ERROR_CORRECTION_SUPPORT: DEV_GET_INT_INF(cl_bool);
case CL_DEVICE_PROFILING_TIMER_RESOLUTION: DEV_GET_INT_INF(size_t);
case CL_DEVICE_ENDIAN_LITTLE: DEV_GET_INT_INF(cl_bool);
case CL_DEVICE_AVAILABLE: DEV_GET_INT_INF(cl_bool);
case CL_DEVICE_COMPILER_AVAILABLE: DEV_GET_INT_INF(cl_bool);
case CL_DEVICE_EXECUTION_CAPABILITIES: DEV_GET_INT_INF(cl_device_exec_capabilities);
#if PYOPENCL_CL_VERSION >= 0x2000
case CL_DEVICE_QUEUE_ON_HOST_PROPERTIES: DEV_GET_INT_INF(cl_command_queue_properties);
#else
case CL_DEVICE_QUEUE_PROPERTIES: DEV_GET_INT_INF(cl_command_queue_properties);
#endif
case CL_DEVICE_NAME:
case CL_DEVICE_VENDOR:
case CL_DRIVER_VERSION:
case CL_DEVICE_PROFILE:
case CL_DEVICE_VERSION:
case CL_DEVICE_EXTENSIONS:
PYOPENCL_GET_STR_INFO(Device, m_device, param_name);
case CL_DEVICE_PLATFORM:
PYOPENCL_GET_OPAQUE_INFO(Device, m_device, param_name, cl_platform_id, platform);
#if PYOPENCL_CL_VERSION >= 0x1010
case CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_NATIVE_VECTOR_WIDTH_INT: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_HOST_UNIFIED_MEMORY: DEV_GET_INT_INF(cl_bool);
case CL_DEVICE_OPENCL_C_VERSION:
PYOPENCL_GET_STR_INFO(Device, m_device, param_name);
#endif
#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
case CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV:
case CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV:
case CL_DEVICE_REGISTERS_PER_BLOCK_NV:
case CL_DEVICE_WARP_SIZE_NV:
DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_GPU_OVERLAP_NV:
case CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV:
case CL_DEVICE_INTEGRATED_MEMORY_NV:
DEV_GET_INT_INF(cl_bool);
#endif
#ifdef CL_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT_NV
case CL_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT_NV:
DEV_GET_INT_INF(cl_uint);
#endif
#ifdef CL_DEVICE_PCI_BUS_ID_NV
case CL_DEVICE_PCI_BUS_ID_NV:
DEV_GET_INT_INF(cl_uint);
#endif
#ifdef CL_DEVICE_PCI_SLOT_ID_NV
case CL_DEVICE_PCI_SLOT_ID_NV:
DEV_GET_INT_INF(cl_uint);
#endif
#ifdef CL_DEVICE_THREAD_TRACE_SUPPORTED_AMD
case CL_DEVICE_THREAD_TRACE_SUPPORTED_AMD: DEV_GET_INT_INF(cl_bool);
#endif
#ifdef CL_DEVICE_GFXIP_MAJOR_AMD
case CL_DEVICE_GFXIP_MAJOR_AMD: DEV_GET_INT_INF(cl_uint);
#endif
#ifdef CL_DEVICE_GFXIP_MINOR_AMD
case CL_DEVICE_GFXIP_MINOR_AMD: DEV_GET_INT_INF(cl_uint);
#endif
#ifdef CL_DEVICE_AVAILABLE_ASYNC_QUEUES_AMD
case CL_DEVICE_AVAILABLE_ASYNC_QUEUES_AMD: DEV_GET_INT_INF(cl_uint);
#endif
#if PYOPENCL_CL_VERSION >= 0x1020
case CL_DEVICE_LINKER_AVAILABLE: DEV_GET_INT_INF(cl_bool);
case CL_DEVICE_BUILT_IN_KERNELS:
PYOPENCL_GET_STR_INFO(Device, m_device, param_name);
case CL_DEVICE_IMAGE_MAX_BUFFER_SIZE: DEV_GET_INT_INF(size_t);
case CL_DEVICE_IMAGE_MAX_ARRAY_SIZE: DEV_GET_INT_INF(size_t);
case CL_DEVICE_PARENT_DEVICE:
PYOPENCL_GET_OPAQUE_INFO(Device, m_device, param_name, cl_device_id, device);
case CL_DEVICE_PARTITION_MAX_SUB_DEVICES: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_PARTITION_TYPE:
case CL_DEVICE_PARTITION_PROPERTIES:
{
std::vector<cl_device_partition_property> result;
PYOPENCL_GET_VEC_INFO(Device, m_device, param_name, result);
PYOPENCL_RETURN_VECTOR(cl_device_partition_property, result);
}
case CL_DEVICE_PARTITION_AFFINITY_DOMAIN:
{
#if defined(__GNUG__) && !defined(__clang__)
#pragma GCC diagnostic push
// what's being ignored here is an alignment attribute to native size, which
// shouldn't matter on the relevant ABIs that I'm aware of.
#pragma GCC diagnostic ignored "-Wignored-attributes"
#endif
std::vector<cl_device_affinity_domain> result;
#if defined(__GNUG__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
PYOPENCL_GET_VEC_INFO(Device, m_device, param_name, result);
PYOPENCL_RETURN_VECTOR(cl_device_affinity_domain, result);
}
case CL_DEVICE_REFERENCE_COUNT: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_PREFERRED_INTEROP_USER_SYNC: DEV_GET_INT_INF(cl_bool);
case CL_DEVICE_PRINTF_BUFFER_SIZE: DEV_GET_INT_INF(cl_bool);
#endif
// {{{ AMD dev attrs cl_amd_device_attribute_query
//
// types of AMD dev attrs divined from
// https://www.khronos.org/registry/cl/api/1.2/cl.hpp
#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
case CL_DEVICE_PROFILING_TIMER_OFFSET_AMD: DEV_GET_INT_INF(cl_ulong);
#endif
/* FIXME
#ifdef CL_DEVICE_TOPOLOGY_AMD
case CL_DEVICE_TOPOLOGY_AMD:
#endif
*/
#ifdef CL_DEVICE_BOARD_NAME_AMD
case CL_DEVICE_BOARD_NAME_AMD: ;
PYOPENCL_GET_STR_INFO(Device, m_device, param_name);
#endif
#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
case CL_DEVICE_GLOBAL_FREE_MEMORY_AMD:
{
std::vector<size_t> result;
PYOPENCL_GET_VEC_INFO(Device, m_device, param_name, result);
PYOPENCL_RETURN_VECTOR(size_t, result);
}
#endif
#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
case CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD: DEV_GET_INT_INF(cl_uint);
#endif
#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
case CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD: DEV_GET_INT_INF(cl_uint);
#endif
#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
case CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD: DEV_GET_INT_INF(cl_uint);
#endif
#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
case CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD: DEV_GET_INT_INF(cl_uint);
#endif
#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
case CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD: DEV_GET_INT_INF(cl_uint);
#endif
#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
case CL_DEVICE_LOCAL_MEM_BANKS_AMD: DEV_GET_INT_INF(cl_uint);
#endif
// }}}
#ifdef CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT
case CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT: DEV_GET_INT_INF(cl_uint);
#endif
#if PYOPENCL_CL_VERSION >= 0x2000
case CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE: DEV_GET_INT_INF(size_t);
case CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES: DEV_GET_INT_INF(cl_command_queue_properties);
case CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_MAX_ON_DEVICE_QUEUES: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_MAX_ON_DEVICE_EVENTS: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_SVM_CAPABILITIES: DEV_GET_INT_INF(cl_device_svm_capabilities);
case CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE: DEV_GET_INT_INF(size_t);
case CL_DEVICE_MAX_PIPE_ARGS: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_PIPE_MAX_PACKET_SIZE: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT: DEV_GET_INT_INF(cl_uint);
#endif
#if PYOPENCL_CL_VERSION >= 0x2010
case CL_DEVICE_IL_VERSION:
PYOPENCL_GET_STR_INFO(Device, m_device, param_name);
case CL_DEVICE_MAX_NUM_SUB_GROUPS: DEV_GET_INT_INF(cl_uint);
case CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS: DEV_GET_INT_INF(cl_bool);
#endif
#ifdef CL_DEVICE_ME_VERSION_INTEL
case CL_DEVICE_ME_VERSION_INTEL: DEV_GET_INT_INF(cl_uint);
#endif
#ifdef CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM
case CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM: DEV_GET_INT_INF(cl_uint);
#endif
#ifdef CL_DEVICE_PAGE_SIZE_QCOM
case CL_DEVICE_PAGE_SIZE_QCOM: DEV_GET_INT_INF(cl_uint);
#endif
#ifdef CL_DEVICE_SPIR_VERSIONS
case CL_DEVICE_SPIR_VERSIONS:
PYOPENCL_GET_STR_INFO(Device, m_device, param_name);
#endif
#ifdef CL_DEVICE_CORE_TEMPERATURE_ALTERA
case CL_DEVICE_CORE_TEMPERATURE_ALTERA: DEV_GET_INT_INF(cl_int);
#endif
#ifdef CL_DEVICE_SIMULTANEOUS_INTEROPS_INTEL
case CL_DEVICE_SIMULTANEOUS_INTEROPS_INTEL:
{
std::vector<cl_uint> result;
PYOPENCL_GET_VEC_INFO(Device, m_device, param_name, result);
PYOPENCL_RETURN_VECTOR(cl_uint, result);
}
#endif
#ifdef CL_DEVICE_NUM_SIMULTANEOUS_INTEROPS_INTEL
case CL_DEVICE_NUM_SIMULTANEOUS_INTEROPS_INTEL: DEV_GET_INT_INF(cl_uint);
#endif
default:
throw error("Device.get_info", CL_INVALID_VALUE);
}
}
#if PYOPENCL_CL_VERSION >= 0x1020
py::list create_sub_devices(py::object py_properties)
{
std::vector<cl_device_partition_property> properties;
COPY_PY_LIST(cl_device_partition_property, properties);
properties.push_back(0);
cl_device_partition_property *props_ptr
= properties.empty( ) ? nullptr : &properties.front();
cl_uint num_entries;
PYOPENCL_CALL_GUARDED(clCreateSubDevices,
(m_device, props_ptr, 0, nullptr, &num_entries));
std::vector<cl_device_id> result;
result.resize(num_entries);
PYOPENCL_CALL_GUARDED(clCreateSubDevices,
(m_device, props_ptr, num_entries, &result.front(), nullptr));
py::list py_result;
for (cl_device_id did: result)
py_result.append(handle_from_new_ptr(
new pyopencl::device(did, /*retain*/true,
device::REF_CL_1_2)));
return py_result;
}
#endif
};
inline py::list platform::get_devices(cl_device_type devtype)
{
cl_uint num_devices = 0;
PYOPENCL_PRINT_CALL_TRACE("clGetDeviceIDs");
{
cl_int status_code;
status_code = clGetDeviceIDs(m_platform, devtype, 0, 0, &num_devices);
if (status_code == CL_DEVICE_NOT_FOUND)
num_devices = 0;
else if (status_code != CL_SUCCESS) \
throw pyopencl::error("clGetDeviceIDs", status_code);
}
if (num_devices == 0)
return py::list();
std::vector<cl_device_id> devices(num_devices);
PYOPENCL_CALL_GUARDED(clGetDeviceIDs,
(m_platform, devtype,
num_devices, devices.empty( ) ? nullptr : &devices.front(), &num_devices));
py::list result;
for (cl_device_id did: devices)
result.append(handle_from_new_ptr(
new device(did)));
return result;
}
// }}}
// {{{ context
class context : public noncopyable
{
private:
cl_context m_context;
public:
context(cl_context ctx, bool retain)
: m_context(ctx)
{
if (retain)
PYOPENCL_CALL_GUARDED(clRetainContext, (ctx));
}
~context()
{
PYOPENCL_CALL_GUARDED_CLEANUP(clReleaseContext,
(m_context));
}
cl_context data() const
{
return m_context;
}
PYOPENCL_EQUALITY_TESTS(context);
py::object get_info(cl_context_info param_name) const
{
switch (param_name)
{
case CL_CONTEXT_REFERENCE_COUNT:
PYOPENCL_GET_INTEGRAL_INFO(
Context, m_context, param_name, cl_uint);
case CL_CONTEXT_DEVICES:
{
std::vector<cl_device_id> result;
PYOPENCL_GET_VEC_INFO(Context, m_context, param_name, result);
py::list py_result;
for (cl_device_id did: result)
py_result.append(handle_from_new_ptr(
new pyopencl::device(did)));
return py_result;
}
case CL_CONTEXT_PROPERTIES:
{
std::vector<cl_context_properties> result;
PYOPENCL_GET_VEC_INFO(Context, m_context, param_name, result);
py::list py_result;
for (size_t i = 0; i < result.size(); i+=2)
{
cl_context_properties key = result[i];
py::object value;
switch (key)
{
case CL_CONTEXT_PLATFORM:
{
value = py::object(
handle_from_new_ptr(new platform(
reinterpret_cast<cl_platform_id>(result[i+1]))));
break;
}
#if defined(PYOPENCL_GL_SHARING_VERSION) && (PYOPENCL_GL_SHARING_VERSION >= 1)
#if defined(__APPLE__) && defined(HAVE_GL)
case CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE:
#else
case CL_GL_CONTEXT_KHR:
case CL_EGL_DISPLAY_KHR:
case CL_GLX_DISPLAY_KHR:
case CL_WGL_HDC_KHR:
case CL_CGL_SHAREGROUP_KHR:
#endif
value = py::cast(result[i+1]);
break;
#endif
case 0:
break;
default:
throw error("Context.get_info", CL_INVALID_VALUE,
"unknown context_property key encountered");
}
py_result.append(py::make_tuple(result[i], value));
}
return py_result;
}
#if PYOPENCL_CL_VERSION >= 0x1010
case CL_CONTEXT_NUM_DEVICES:
PYOPENCL_GET_INTEGRAL_INFO(
Context, m_context, param_name, cl_uint);
#endif
default:
throw error("Context.get_info", CL_INVALID_VALUE);
}
}
// not exposed to python
int get_hex_platform_version() const
{
std::vector<cl_device_id> devices;
PYOPENCL_GET_VEC_INFO(Context, m_context, CL_CONTEXT_DEVICES, devices);
if (devices.size() == 0)
throw error("Context._get_hex_version", CL_INVALID_VALUE,
"platform has no devices");
cl_platform_id plat;
PYOPENCL_CALL_GUARDED(clGetDeviceInfo,
(devices[0], CL_DEVICE_PLATFORM, sizeof(plat), &plat, nullptr));
std::string plat_version;
{
size_t param_value_size;
PYOPENCL_CALL_GUARDED(clGetPlatformInfo,
(plat, CL_PLATFORM_VERSION, 0, 0, ¶m_value_size));
std::vector<char> param_value(param_value_size);
PYOPENCL_CALL_GUARDED(clGetPlatformInfo,
(plat, CL_PLATFORM_VERSION, param_value_size,
param_value.empty( ) ? nullptr : ¶m_value.front(), ¶m_value_size));
plat_version =
param_value.empty( ) ? "" : std::string(¶m_value.front(), param_value_size-1);
}
int major_ver, minor_ver;
errno = 0;
int match_count = sscanf(plat_version.c_str(), "OpenCL %d.%d ", &major_ver, &minor_ver);
if (errno || match_count != 2)
throw error("Context._get_hex_version", CL_INVALID_VALUE,
"Platform version string did not have expected format");
return major_ver << 12 | minor_ver << 4;
}
};
inline
std::vector<cl_context_properties> parse_context_properties(
py::object py_properties)
{
std::vector<cl_context_properties> props;
if (py_properties.ptr() != Py_None)
{
for (py::handle prop_tuple_py: py_properties)
{
py::tuple prop_tuple(prop_tuple_py.cast<py::tuple>());
if (len(prop_tuple) != 2)
throw error("Context", CL_INVALID_VALUE, "property tuple must have length 2");
cl_context_properties prop = prop_tuple[0].cast<cl_context_properties>();
props.push_back(prop);
if (prop == CL_CONTEXT_PLATFORM)
{
props.push_back(
reinterpret_cast<cl_context_properties>(
prop_tuple[1].cast<const platform &>().data()));
}
#if defined(PYOPENCL_GL_SHARING_VERSION) && (PYOPENCL_GL_SHARING_VERSION >= 1)
#if defined(_WIN32)
else if (prop == CL_WGL_HDC_KHR)
{
// size_t is a stand-in for HANDLE, hopefully has the same size.
size_t hnd = (prop_tuple[1]).cast<size_t>();
props.push_back(hnd);
}
#endif
else if (
#if defined(__APPLE__) && defined(HAVE_GL)
prop == CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE
#else
prop == CL_GL_CONTEXT_KHR
|| prop == CL_EGL_DISPLAY_KHR
|| prop == CL_GLX_DISPLAY_KHR
|| prop == CL_CGL_SHAREGROUP_KHR
#endif
)
{
py::object ctypes = py::module::import("ctypes");
py::object prop = prop_tuple[1], c_void_p = ctypes.attr("c_void_p");
py::object ptr = ctypes.attr("cast")(prop, c_void_p);
props.push_back(ptr.attr("value").cast<cl_context_properties>());
}
#endif
else
throw error("Context", CL_INVALID_VALUE, "invalid context property");
}
props.push_back(0);
}
return props;
}
inline
context *create_context_inner(py::object py_devices, py::object py_properties,
py::object py_dev_type)
{
std::vector<cl_context_properties> props
= parse_context_properties(py_properties);
cl_context_properties *props_ptr
= props.empty( ) ? nullptr : &props.front();
cl_int status_code;
cl_context ctx;
// from device list
if (py_devices.ptr() != Py_None)
{
if (py_dev_type.ptr() != Py_None)
throw error("Context", CL_INVALID_VALUE,
"one of 'devices' or 'dev_type' must be None");
std::vector<cl_device_id> devices;
for (py::handle py_dev: py_devices)
devices.push_back(py_dev.cast<const device &>().data());
PYOPENCL_PRINT_CALL_TRACE("clCreateContext");
ctx = clCreateContext(
props_ptr,
devices.size(),
devices.empty( ) ? nullptr : &devices.front(),
0, 0, &status_code);
}
// from dev_type
else
{
cl_device_type dev_type = CL_DEVICE_TYPE_DEFAULT;
if (py_dev_type.ptr() != Py_None)
dev_type = py_dev_type.cast<cl_device_type>();
PYOPENCL_PRINT_CALL_TRACE("clCreateContextFromType");
ctx = clCreateContextFromType(props_ptr, dev_type, 0, 0, &status_code);
}
if (status_code != CL_SUCCESS)
throw pyopencl::error("Context", status_code);
try
{
return new context(ctx, false);
}
catch (...)
{
PYOPENCL_CALL_GUARDED(clReleaseContext, (ctx));
throw;
}
}
inline
context *create_context(py::object py_devices, py::object py_properties,
py::object py_dev_type)
{
PYOPENCL_RETRY_RETURN_IF_MEM_ERROR(
return create_context_inner(py_devices, py_properties, py_dev_type);
)
}
// }}}
// {{{ command_queue
class command_queue
{
private:
cl_command_queue m_queue;
public:
command_queue(cl_command_queue q, bool retain)
: m_queue(q)
{
if (retain)
PYOPENCL_CALL_GUARDED(clRetainCommandQueue, (q));
}
command_queue(command_queue const &src)
: m_queue(src.m_queue)
{
PYOPENCL_CALL_GUARDED(clRetainCommandQueue, (m_queue));
}
command_queue(
const context &ctx,
const device *py_dev=nullptr,
py::object py_props=py::none())
{
cl_device_id dev;
if (py_dev)
dev = py_dev->data();
else
{
std::vector<cl_device_id> devs;
PYOPENCL_GET_VEC_INFO(Context, ctx.data(), CL_CONTEXT_DEVICES, devs);
if (devs.size() == 0)
throw pyopencl::error("CommandQueue", CL_INVALID_VALUE,
"context doesn't have any devices? -- don't know which one to default to");
dev = devs[0];
}
int hex_plat_version = ctx.get_hex_platform_version();
bool props_given_as_numeric;
cl_command_queue_properties num_props;
if (py_props.is_none())
{
num_props = 0;
props_given_as_numeric = true;
}
else
{
try
{
num_props = py::cast<cl_command_queue_properties>(py_props);
props_given_as_numeric = true;
}
catch (py::cast_error &)
{
props_given_as_numeric = false;
}
}
if (props_given_as_numeric)
{
#if PYOPENCL_CL_VERSION >= 0x2000
if (hex_plat_version >= 0x2000)
{
cl_queue_properties props_list[] = { CL_QUEUE_PROPERTIES, num_props, 0 };
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clCreateCommandQueueWithProperties");
m_queue = clCreateCommandQueueWithProperties(
ctx.data(), dev, props_list, &status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("CommandQueue", status_code);
}
else
#endif
{
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clCreateCommandQueue");
#if defined(__GNUG__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
m_queue = clCreateCommandQueue(
ctx.data(), dev, num_props, &status_code);
#if defined(__GNUG__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
if (status_code != CL_SUCCESS)
throw pyopencl::error("CommandQueue", status_code);
}
}
else
{
#if PYOPENCL_CL_VERSION < 0x2000
throw error("CommandQueue", CL_INVALID_VALUE,
"queue properties given as an iterable, "
"which is only allowed when PyOpenCL was built "
"against an OpenCL 2+ header");
#else
if (hex_plat_version < 0x2000)
{
std::cerr <<
"queue properties given as an iterable, "
"which uses an OpenCL 2+-only interface, "
"but the context's platform does not "
"declare OpenCL 2 support. Proceeding "
"as requested, but the next thing you see "
"may be a crash." << std:: endl;
}
PYOPENCL_STACK_CONTAINER(cl_queue_properties, props, py::len(py_props) + 1);
{
size_t i = 0;
for (auto prop: py_props)
props[i++] = py::cast<cl_queue_properties>(prop);
props[i++] = 0;
}
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clCreateCommandQueueWithProperties");
m_queue = clCreateCommandQueueWithProperties(
ctx.data(), dev, PYOPENCL_STACK_CONTAINER_GET_PTR(props), &status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("CommandQueue", status_code);
#endif
}
}
~command_queue()
{
PYOPENCL_CALL_GUARDED_CLEANUP(clReleaseCommandQueue,
(m_queue));
}
const cl_command_queue data() const
{ return m_queue; }
PYOPENCL_EQUALITY_TESTS(command_queue);
py::object get_info(cl_command_queue_info param_name) const
{
switch (param_name)
{
case CL_QUEUE_CONTEXT:
PYOPENCL_GET_OPAQUE_INFO(CommandQueue, m_queue, param_name,
cl_context, context);
case CL_QUEUE_DEVICE:
PYOPENCL_GET_OPAQUE_INFO(CommandQueue, m_queue, param_name,
cl_device_id, device);
case CL_QUEUE_REFERENCE_COUNT:
PYOPENCL_GET_INTEGRAL_INFO(CommandQueue, m_queue, param_name,
cl_uint);
case CL_QUEUE_PROPERTIES:
PYOPENCL_GET_INTEGRAL_INFO(CommandQueue, m_queue, param_name,
cl_command_queue_properties);
default:
throw error("CommandQueue.get_info", CL_INVALID_VALUE);
}
}
std::unique_ptr<context> get_context() const
{
cl_context param_value;
PYOPENCL_CALL_GUARDED(clGetCommandQueueInfo,
(m_queue, CL_QUEUE_CONTEXT, sizeof(param_value), ¶m_value, 0));
return std::unique_ptr<context>(
new context(param_value, /*retain*/ true));
}
#if PYOPENCL_CL_VERSION < 0x1010
cl_command_queue_properties set_property(
cl_command_queue_properties prop,
bool enable)
{
cl_command_queue_properties old_prop;
PYOPENCL_CALL_GUARDED(clSetCommandQueueProperty,
(m_queue, prop, PYOPENCL_CAST_BOOL(enable), &old_prop));
return old_prop;
}
#endif
void flush()
{ PYOPENCL_CALL_GUARDED(clFlush, (m_queue)); }
void finish()
{ PYOPENCL_CALL_GUARDED_THREADED(clFinish, (m_queue)); }
};
// }}}
// {{{ event/synchronization
class event : noncopyable
{
private:
cl_event m_event;
public:
event(cl_event event, bool retain)
: m_event(event)
{
if (retain)
PYOPENCL_CALL_GUARDED(clRetainEvent, (event));
}
event(event const &src)
: m_event(src.m_event)
{ PYOPENCL_CALL_GUARDED(clRetainEvent, (m_event)); }
virtual ~event()
{
PYOPENCL_CALL_GUARDED_CLEANUP(clReleaseEvent,
(m_event));
}
const cl_event data() const
{ return m_event; }
PYOPENCL_EQUALITY_TESTS(event);
py::object get_info(cl_event_info param_name) const
{
switch (param_name)
{
case CL_EVENT_COMMAND_QUEUE:
PYOPENCL_GET_OPAQUE_INFO(Event, m_event, param_name,
cl_command_queue, command_queue);
case CL_EVENT_COMMAND_TYPE:
PYOPENCL_GET_INTEGRAL_INFO(Event, m_event, param_name,
cl_command_type);
case CL_EVENT_COMMAND_EXECUTION_STATUS:
PYOPENCL_GET_INTEGRAL_INFO(Event, m_event, param_name,
cl_int);
case CL_EVENT_REFERENCE_COUNT:
PYOPENCL_GET_INTEGRAL_INFO(Event, m_event, param_name,
cl_uint);
#if PYOPENCL_CL_VERSION >= 0x1010
case CL_EVENT_CONTEXT:
PYOPENCL_GET_OPAQUE_INFO(Event, m_event, param_name,
cl_context, context);
#endif
default:
throw error("Event.get_info", CL_INVALID_VALUE);
}
}
py::object get_profiling_info(cl_profiling_info param_name) const
{
switch (param_name)
{
case CL_PROFILING_COMMAND_QUEUED:
case CL_PROFILING_COMMAND_SUBMIT:
case CL_PROFILING_COMMAND_START:
case CL_PROFILING_COMMAND_END:
#if PYOPENCL_CL_VERSION >= 0x2000
case CL_PROFILING_COMMAND_COMPLETE:
#endif
PYOPENCL_GET_INTEGRAL_INFO(EventProfiling, m_event, param_name,
cl_ulong);
default:
throw error("Event.get_profiling_info", CL_INVALID_VALUE);
}
}
virtual void wait()
{
PYOPENCL_CALL_GUARDED_THREADED(clWaitForEvents, (1, &m_event));
}
#if PYOPENCL_CL_VERSION >= 0x1010
// {{{ set_callback, by way of a a thread-based construction
private:
struct event_callback_info_t
{
std::mutex m_mutex;
std::condition_variable m_condvar;
py::object m_py_event;
py::object m_py_callback;
bool m_set_callback_suceeded;
bool m_notify_thread_wakeup_is_genuine;
cl_event m_event;
cl_int m_command_exec_status;
event_callback_info_t(py::object py_event, py::object py_callback)
: m_py_event(py_event), m_py_callback(py_callback), m_set_callback_suceeded(true),
m_notify_thread_wakeup_is_genuine(false)
{}
};
static void evt_callback(cl_event evt, cl_int command_exec_status, void *user_data)
{
event_callback_info_t *cb_info = reinterpret_cast<event_callback_info_t *>(user_data);
{
std::lock_guard<std::mutex> lg(cb_info->m_mutex);
cb_info->m_event = evt;
cb_info->m_command_exec_status = command_exec_status;
cb_info->m_notify_thread_wakeup_is_genuine = true;
}
cb_info->m_condvar.notify_one();
}
public:
void set_callback(cl_int command_exec_callback_type, py::object pfn_event_notify)
{
// The reason for doing this via a thread is that we're able to wait on
// acquiring the GIL. (which we can't in the callback)
std::unique_ptr<event_callback_info_t> cb_info_holder(
new event_callback_info_t(
handle_from_new_ptr(new event(*this)),
pfn_event_notify));
event_callback_info_t *cb_info = cb_info_holder.get();
std::thread notif_thread([cb_info]()
{
{
std::unique_lock<std::mutex> ulk(cb_info->m_mutex);
cb_info->m_condvar.wait(
ulk,
[&](){ return cb_info->m_notify_thread_wakeup_is_genuine; });
// ulk no longer held here, cb_info ready for deletion
}
{
py::gil_scoped_acquire acquire;
if (cb_info->m_set_callback_suceeded)
{
try {
cb_info->m_py_callback(
// cb_info->m_py_event,
cb_info->m_command_exec_status);
}
catch (std::exception &exc)
{
std::cerr
<< "[pyopencl] event callback handler threw an exception, ignoring: "
<< exc.what()
<< std::endl;
}
}
// Need to hold GIL to delete py::object instances in
// event_callback_info_t
delete cb_info;
}
});
// Thread is away--it is now its responsibility to free cb_info.
cb_info_holder.release();
// notif_thread should no longer be coupled to the lifetime of the thread.
notif_thread.detach();
try
{
PYOPENCL_CALL_GUARDED(clSetEventCallback, (
data(), command_exec_callback_type, &event::evt_callback, cb_info));
}
catch (...) {
// Setting the callback did not succeed. The thread would never
// be woken up. Wake it up to let it know that it can stop.
{
std::lock_guard<std::mutex> lg(cb_info->m_mutex);
cb_info->m_set_callback_suceeded = false;
cb_info->m_notify_thread_wakeup_is_genuine = true;
}
cb_info->m_condvar.notify_one();
throw;
}
}
// }}}
#endif
};
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
class nanny_event : public event
{
// In addition to everything an event does, the nanny event holds a reference
// to a Python object and waits for its own completion upon destruction.
protected:
std::unique_ptr<py_buffer_wrapper> m_ward;
public:
nanny_event(cl_event evt, bool retain, std::unique_ptr<py_buffer_wrapper> &ward)
: event(evt, retain), m_ward(std::move(ward))
{ }
~nanny_event()
{ wait(); }
py::object get_ward() const
{
if (m_ward.get())
{
return py::reinterpret_borrow<py::object>(m_ward->m_buf.obj);
}
else
return py::none();
}
virtual void wait()
{
event::wait();
m_ward.reset();
}
};
#else
class nanny_event : public event
{
// In addition to everything an event does, the nanny event holds a reference
// to a Python object and waits for its own completion upon destruction.
protected:
py::object m_ward;
public:
nanny_event(cl_event evt, bool retain, py::object ward)
: event(evt, retain), m_ward(ward)
{ }
nanny_event(nanny_event const &src)
: event(src), m_ward(src.m_ward)
{ }
~nanny_event()
{ wait(); }
py::object get_ward() const
{ return m_ward; }
virtual void wait()
{
event::wait();
m_ward = py::none();
}
};
#endif
inline
void wait_for_events(py::object events)
{
cl_uint num_events_in_wait_list = 0;
std::vector<cl_event> event_wait_list(len(events));
for (py::handle evt: events)
event_wait_list[num_events_in_wait_list++] =
evt.cast<event &>().data();
PYOPENCL_CALL_GUARDED_THREADED(clWaitForEvents, (
PYOPENCL_WAITLIST_ARGS));
}
#if PYOPENCL_CL_VERSION >= 0x1020
inline
event *enqueue_marker_with_wait_list(command_queue &cq,
py::object py_wait_for)
{
PYOPENCL_PARSE_WAIT_FOR;
cl_event evt;
PYOPENCL_CALL_GUARDED(clEnqueueMarkerWithWaitList, (
cq.data(), PYOPENCL_WAITLIST_ARGS, &evt));
PYOPENCL_RETURN_NEW_EVENT(evt);
}
inline
event *enqueue_barrier_with_wait_list(command_queue &cq,
py::object py_wait_for)
{
PYOPENCL_PARSE_WAIT_FOR;
cl_event evt;
PYOPENCL_CALL_GUARDED(clEnqueueBarrierWithWaitList,
(cq.data(), PYOPENCL_WAITLIST_ARGS, &evt));
PYOPENCL_RETURN_NEW_EVENT(evt);
}
#endif
// {{{ used internally for pre-OpenCL-1.2 contexts
inline
event *enqueue_marker(command_queue &cq)
{
cl_event evt;
PYOPENCL_CALL_GUARDED(clEnqueueMarker, (
cq.data(), &evt));
PYOPENCL_RETURN_NEW_EVENT(evt);
}
inline
void enqueue_wait_for_events(command_queue &cq, py::object py_events)
{
cl_uint num_events = 0;
std::vector<cl_event> event_list(len(py_events));
for (py::handle py_evt: py_events)
event_list[num_events++] = py_evt.cast<event &>().data();
PYOPENCL_CALL_GUARDED(clEnqueueWaitForEvents, (
cq.data(), num_events, event_list.empty( ) ? nullptr : &event_list.front()));
}
inline
void enqueue_barrier(command_queue &cq)
{
PYOPENCL_CALL_GUARDED(clEnqueueBarrier, (cq.data()));
}
// }}}
#if PYOPENCL_CL_VERSION >= 0x1010
class user_event : public event
{
public:
user_event(cl_event evt, bool retain)
: event(evt, retain)
{ }
void set_status(cl_int execution_status)
{
PYOPENCL_CALL_GUARDED(clSetUserEventStatus, (data(), execution_status));
}
};
inline
user_event *create_user_event(context &ctx)
{
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clCreateUserEvent");
cl_event evt = clCreateUserEvent(ctx.data(), &status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("UserEvent", status_code);
try
{
return new user_event(evt, false);
}
catch (...)
{
clReleaseEvent(evt);
throw;
}
}
#endif
// }}}
// {{{ memory_object
py::object create_mem_object_wrapper(cl_mem mem, bool retain);
class memory_object_holder
{
public:
virtual const cl_mem data() const = 0;
PYOPENCL_EQUALITY_TESTS(memory_object_holder);
size_t size() const
{
size_t param_value;
PYOPENCL_CALL_GUARDED(clGetMemObjectInfo,
(data(), CL_MEM_SIZE, sizeof(param_value), ¶m_value, 0));
return param_value;
}
py::object get_info(cl_mem_info param_name) const;
};
class memory_object : noncopyable, public memory_object_holder
{
public:
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
typedef std::unique_ptr<py_buffer_wrapper> hostbuf_t;
#else
typedef py::object hostbuf_t;
#endif
private:
bool m_valid;
cl_mem m_mem;
hostbuf_t m_hostbuf;
public:
memory_object(cl_mem mem, bool retain, hostbuf_t hostbuf=hostbuf_t())
: m_valid(true), m_mem(mem)
{
if (retain)
PYOPENCL_CALL_GUARDED(clRetainMemObject, (mem));
m_hostbuf = PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(hostbuf);
}
memory_object(memory_object &src)
: m_valid(true), m_mem(src.m_mem),
m_hostbuf(PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(src.m_hostbuf))
{
PYOPENCL_CALL_GUARDED(clRetainMemObject, (m_mem));
}
memory_object(memory_object_holder const &src)
: m_valid(true), m_mem(src.data())
{
PYOPENCL_CALL_GUARDED(clRetainMemObject, (m_mem));
}
void release()
{
if (!m_valid)
throw error("MemoryObject.free", CL_INVALID_VALUE,
"trying to double-unref mem object");
PYOPENCL_CALL_GUARDED_CLEANUP(clReleaseMemObject, (m_mem));
m_valid = false;
}
virtual ~memory_object()
{
if (m_valid)
release();
}
py::object hostbuf()
{
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
if (m_hostbuf.get())
return py::reinterpret_borrow<py::object>(m_hostbuf->m_buf.obj);
else
return py::none();
#else
return m_hostbuf;
#endif
}
const cl_mem data() const
{ return m_mem; }
};
#if PYOPENCL_CL_VERSION >= 0x1020
inline
event *enqueue_migrate_mem_objects(
command_queue &cq,
py::object py_mem_objects,
cl_mem_migration_flags flags,
py::object py_wait_for)
{
PYOPENCL_PARSE_WAIT_FOR;
std::vector<cl_mem> mem_objects;
for (py::handle mo: py_mem_objects)
mem_objects.push_back(mo.cast<const memory_object &>().data());
cl_event evt;
PYOPENCL_RETRY_IF_MEM_ERROR(
PYOPENCL_CALL_GUARDED(clEnqueueMigrateMemObjects, (
cq.data(),
mem_objects.size(), mem_objects.empty( ) ? nullptr : &mem_objects.front(),
flags,
PYOPENCL_WAITLIST_ARGS, &evt
));
);
PYOPENCL_RETURN_NEW_EVENT(evt);
}
#endif
// }}}
// {{{ buffer
inline cl_mem create_buffer(
cl_context ctx,
cl_mem_flags flags,
size_t size,
void *host_ptr)
{
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clCreateBuffer");
cl_mem mem = clCreateBuffer(ctx, flags, size, host_ptr, &status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("create_buffer", status_code);
return mem;
}
inline cl_mem create_buffer_gc(
cl_context ctx,
cl_mem_flags flags,
size_t size,
void *host_ptr)
{
PYOPENCL_RETRY_RETURN_IF_MEM_ERROR(
return create_buffer(ctx, flags, size, host_ptr);
);
}
#if PYOPENCL_CL_VERSION >= 0x1010
inline cl_mem create_sub_buffer(
cl_mem buffer, cl_mem_flags flags, cl_buffer_create_type bct,
const void *buffer_create_info)
{
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clCreateSubBuffer");
cl_mem mem = clCreateSubBuffer(buffer, flags,
bct, buffer_create_info, &status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("clCreateSubBuffer", status_code);
return mem;
}
inline cl_mem create_sub_buffer_gc(
cl_mem buffer, cl_mem_flags flags, cl_buffer_create_type bct,
const void *buffer_create_info)
{
PYOPENCL_RETRY_RETURN_IF_MEM_ERROR(
return create_sub_buffer(buffer, flags, bct, buffer_create_info);
);
}
#endif
class buffer : public memory_object
{
public:
buffer(cl_mem mem, bool retain, hostbuf_t hostbuf=hostbuf_t())
: memory_object(mem, retain, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(hostbuf))
{ }
#if PYOPENCL_CL_VERSION >= 0x1010
buffer *get_sub_region(
size_t origin, size_t size, cl_mem_flags flags) const
{
cl_buffer_region region = { origin, size};
cl_mem mem = create_sub_buffer_gc(
data(), flags, CL_BUFFER_CREATE_TYPE_REGION, ®ion);
try
{
return new buffer(mem, false);
}
catch (...)
{
PYOPENCL_CALL_GUARDED(clReleaseMemObject, (mem));
throw;
}
}
buffer *getitem(py::slice slc) const
{
PYOPENCL_BUFFER_SIZE_T start, end, stride, length;
size_t my_length;
PYOPENCL_CALL_GUARDED(clGetMemObjectInfo,
(data(), CL_MEM_SIZE, sizeof(my_length), &my_length, 0));
#if PY_VERSION_HEX >= 0x03020000
if (PySlice_GetIndicesEx(slc.ptr(),
my_length, &start, &end, &stride, &length) != 0)
throw py::error_already_set();
#else
if (PySlice_GetIndicesEx(reinterpret_cast<PySliceObject *>(slc.ptr()),
my_length, &start, &end, &stride, &length) != 0)
throw py::error_already_set();
#endif
if (stride != 1)
throw pyopencl::error("Buffer.__getitem__", CL_INVALID_VALUE,
"Buffer slice must have stride 1");
cl_mem_flags my_flags;
PYOPENCL_CALL_GUARDED(clGetMemObjectInfo,
(data(), CL_MEM_FLAGS, sizeof(my_flags), &my_flags, 0));
my_flags &= ~CL_MEM_COPY_HOST_PTR;
if (end <= start)
throw pyopencl::error("Buffer.__getitem__", CL_INVALID_VALUE,
"Buffer slice have end > start");
return get_sub_region(start, end-start, my_flags);
}
#endif
};
// {{{ buffer creation
inline
buffer *create_buffer_py(
context &ctx,
cl_mem_flags flags,
size_t size,
py::object py_hostbuf
)
{
if (py_hostbuf.ptr() != Py_None &&
!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
PyErr_Warn(PyExc_UserWarning, "'hostbuf' was passed, "
"but no memory flags to make use of it.");
void *buf = 0;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
std::unique_ptr<py_buffer_wrapper> retained_buf_obj;
if (py_hostbuf.ptr() != Py_None)
{
retained_buf_obj = std::unique_ptr<py_buffer_wrapper>(new py_buffer_wrapper);
int py_buf_flags = PyBUF_ANY_CONTIGUOUS;
if ((flags & CL_MEM_USE_HOST_PTR)
&& ((flags & CL_MEM_READ_WRITE)
|| (flags & CL_MEM_WRITE_ONLY)))
py_buf_flags |= PyBUF_WRITABLE;
retained_buf_obj->get(py_hostbuf.ptr(), py_buf_flags);
buf = retained_buf_obj->m_buf.buf;
if (size > size_t(retained_buf_obj->m_buf.len))
throw pyopencl::error("Buffer", CL_INVALID_VALUE,
"specified size is greater than host buffer size");
if (size == 0)
size = retained_buf_obj->m_buf.len;
}
#else
py::object retained_buf_obj;
if (py_hostbuf.ptr() != Py_None)
{
PYOPENCL_BUFFER_SIZE_T len;
if ((flags & CL_MEM_USE_HOST_PTR)
&& ((flags & CL_MEM_READ_WRITE)
|| (flags & CL_MEM_WRITE_ONLY)))
{
if (PyObject_AsWriteBuffer(py_hostbuf.ptr(), &buf, &len))
throw py::error_already_set();
}
else
{
if (PyObject_AsReadBuffer(
py_hostbuf.ptr(), const_cast<const void **>(&buf), &len))
throw py::error_already_set();
}
if (flags & CL_MEM_USE_HOST_PTR)
retained_buf_obj = py_hostbuf;
if (size > size_t(len))
throw pyopencl::error("Buffer", CL_INVALID_VALUE,
"specified size is greater than host buffer size");
if (size == 0)
size = len;
}
#endif
cl_mem mem = create_buffer_gc(ctx.data(), flags, size, buf);
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
if (!(flags & CL_MEM_USE_HOST_PTR))
retained_buf_obj.reset();
#endif
try
{
return new buffer(mem, false, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(retained_buf_obj));
}
catch (...)
{
PYOPENCL_CALL_GUARDED(clReleaseMemObject, (mem));
throw;
}
}
// }}}
// {{{ buffer transfers
// {{{ byte-for-byte transfers
inline
event *enqueue_read_buffer(
command_queue &cq,
memory_object_holder &mem,
py::object buffer,
size_t device_offset,
py::object py_wait_for,
bool is_blocking)
{
PYOPENCL_PARSE_WAIT_FOR;
void *buf;
PYOPENCL_BUFFER_SIZE_T len;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
std::unique_ptr<py_buffer_wrapper> ward(new py_buffer_wrapper);
ward->get(buffer.ptr(), PyBUF_ANY_CONTIGUOUS | PyBUF_WRITABLE);
buf = ward->m_buf.buf;
len = ward->m_buf.len;
#else
py::object ward = buffer;
if (PyObject_AsWriteBuffer(buffer.ptr(), &buf, &len))
throw py::error_already_set();
#endif
cl_event evt;
PYOPENCL_RETRY_IF_MEM_ERROR(
PYOPENCL_CALL_GUARDED_THREADED(clEnqueueReadBuffer, (
cq.data(),
mem.data(),
PYOPENCL_CAST_BOOL(is_blocking),
device_offset, len, buf,
PYOPENCL_WAITLIST_ARGS, &evt
))
);
PYOPENCL_RETURN_NEW_NANNY_EVENT(evt, ward);
}
inline
event *enqueue_write_buffer(
command_queue &cq,
memory_object_holder &mem,
py::object buffer,
size_t device_offset,
py::object py_wait_for,
bool is_blocking)
{
PYOPENCL_PARSE_WAIT_FOR;
const void *buf;
PYOPENCL_BUFFER_SIZE_T len;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
std::unique_ptr<py_buffer_wrapper> ward(new py_buffer_wrapper);
ward->get(buffer.ptr(), PyBUF_ANY_CONTIGUOUS);
buf = ward->m_buf.buf;
len = ward->m_buf.len;
#else
py::object ward = buffer;
if (PyObject_AsReadBuffer(buffer.ptr(), &buf, &len))
throw py::error_already_set();
#endif
cl_event evt;
PYOPENCL_RETRY_IF_MEM_ERROR(
PYOPENCL_CALL_GUARDED_THREADED(clEnqueueWriteBuffer, (
cq.data(),
mem.data(),
PYOPENCL_CAST_BOOL(is_blocking),
device_offset, len, buf,
PYOPENCL_WAITLIST_ARGS, &evt
))
);
PYOPENCL_RETURN_NEW_NANNY_EVENT(evt, ward);
}
inline
event *enqueue_copy_buffer(
command_queue &cq,
memory_object_holder &src,
memory_object_holder &dst,
ptrdiff_t byte_count,
size_t src_offset,
size_t dst_offset,
py::object py_wait_for)
{
PYOPENCL_PARSE_WAIT_FOR;
if (byte_count < 0)
{
size_t byte_count_src = 0;
size_t byte_count_dst = 0;
PYOPENCL_CALL_GUARDED(clGetMemObjectInfo,
(src.data(), CL_MEM_SIZE, sizeof(byte_count), &byte_count_src, 0));
PYOPENCL_CALL_GUARDED(clGetMemObjectInfo,
(src.data(), CL_MEM_SIZE, sizeof(byte_count), &byte_count_dst, 0));
byte_count = std::min(byte_count_src, byte_count_dst);
}
cl_event evt;
PYOPENCL_RETRY_IF_MEM_ERROR(
PYOPENCL_CALL_GUARDED(clEnqueueCopyBuffer, (
cq.data(),
src.data(), dst.data(),
src_offset, dst_offset,
byte_count,
PYOPENCL_WAITLIST_ARGS,
&evt
))
);
PYOPENCL_RETURN_NEW_EVENT(evt);
}
// }}}
// {{{ rectangular transfers
#if PYOPENCL_CL_VERSION >= 0x1010
inline
event *enqueue_read_buffer_rect(
command_queue &cq,
memory_object_holder &mem,
py::object buffer,
py::object py_buffer_origin,
py::object py_host_origin,
py::object py_region,
py::sequence py_buffer_pitches,
py::sequence py_host_pitches,
py::object py_wait_for,
bool is_blocking
)
{
PYOPENCL_PARSE_WAIT_FOR;
COPY_PY_COORD_TRIPLE(buffer_origin);
COPY_PY_COORD_TRIPLE(host_origin);
COPY_PY_REGION_TRIPLE(region);
COPY_PY_PITCH_TUPLE(buffer_pitches);
COPY_PY_PITCH_TUPLE(host_pitches);
void *buf;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
std::unique_ptr<py_buffer_wrapper> ward(new py_buffer_wrapper);
ward->get(buffer.ptr(), PyBUF_ANY_CONTIGUOUS | PyBUF_WRITABLE);
buf = ward->m_buf.buf;
#else
py::object ward = buffer;
PYOPENCL_BUFFER_SIZE_T len;
if (PyObject_AsWriteBuffer(buffer.ptr(), &buf, &len))
throw py::error_already_set();
#endif
cl_event evt;
PYOPENCL_RETRY_IF_MEM_ERROR(
PYOPENCL_CALL_GUARDED_THREADED(clEnqueueReadBufferRect, (
cq.data(),
mem.data(),
PYOPENCL_CAST_BOOL(is_blocking),
buffer_origin, host_origin, region,
buffer_pitches[0], buffer_pitches[1],
host_pitches[0], host_pitches[1],
buf,
PYOPENCL_WAITLIST_ARGS, &evt
))
);
PYOPENCL_RETURN_NEW_NANNY_EVENT(evt, ward);
}
inline
event *enqueue_write_buffer_rect(
command_queue &cq,
memory_object_holder &mem,
py::object buffer,
py::object py_buffer_origin,
py::object py_host_origin,
py::object py_region,
py::sequence py_buffer_pitches,
py::sequence py_host_pitches,
py::object py_wait_for,
bool is_blocking
)
{
PYOPENCL_PARSE_WAIT_FOR;
COPY_PY_COORD_TRIPLE(buffer_origin);
COPY_PY_COORD_TRIPLE(host_origin);
COPY_PY_REGION_TRIPLE(region);
COPY_PY_PITCH_TUPLE(buffer_pitches);
COPY_PY_PITCH_TUPLE(host_pitches);
const void *buf;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
std::unique_ptr<py_buffer_wrapper> ward(new py_buffer_wrapper);
ward->get(buffer.ptr(), PyBUF_ANY_CONTIGUOUS);
buf = ward->m_buf.buf;
#else
py::object ward = buffer;
PYOPENCL_BUFFER_SIZE_T len;
if (PyObject_AsReadBuffer(buffer.ptr(), &buf, &len))
throw py::error_already_set();
#endif
cl_event evt;
PYOPENCL_RETRY_IF_MEM_ERROR(
PYOPENCL_CALL_GUARDED_THREADED(clEnqueueWriteBufferRect, (
cq.data(),
mem.data(),
PYOPENCL_CAST_BOOL(is_blocking),
buffer_origin, host_origin, region,
buffer_pitches[0], buffer_pitches[1],
host_pitches[0], host_pitches[1],
buf,
PYOPENCL_WAITLIST_ARGS, &evt
))
);
PYOPENCL_RETURN_NEW_NANNY_EVENT(evt, ward);
}
inline
event *enqueue_copy_buffer_rect(
command_queue &cq,
memory_object_holder &src,
memory_object_holder &dst,
py::object py_src_origin,
py::object py_dst_origin,
py::object py_region,
py::sequence py_src_pitches,
py::sequence py_dst_pitches,
py::object py_wait_for)
{
PYOPENCL_PARSE_WAIT_FOR;
COPY_PY_COORD_TRIPLE(src_origin);
COPY_PY_COORD_TRIPLE(dst_origin);
COPY_PY_REGION_TRIPLE(region);
COPY_PY_PITCH_TUPLE(src_pitches);
COPY_PY_PITCH_TUPLE(dst_pitches);
cl_event evt;
PYOPENCL_RETRY_IF_MEM_ERROR(
PYOPENCL_CALL_GUARDED(clEnqueueCopyBufferRect, (
cq.data(),
src.data(), dst.data(),
src_origin, dst_origin, region,
src_pitches[0], src_pitches[1],
dst_pitches[0], dst_pitches[1],
PYOPENCL_WAITLIST_ARGS,
&evt
))
);
PYOPENCL_RETURN_NEW_EVENT(evt);
}
#endif
// }}}
// }}}
#if PYOPENCL_CL_VERSION >= 0x1020
inline
event *enqueue_fill_buffer(
command_queue &cq,
memory_object_holder &mem,
py::object pattern,
size_t offset,
size_t size,
py::object py_wait_for
)
{
PYOPENCL_PARSE_WAIT_FOR;
const void *pattern_buf;
PYOPENCL_BUFFER_SIZE_T pattern_len;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
std::unique_ptr<py_buffer_wrapper> ward(new py_buffer_wrapper);
ward->get(pattern.ptr(), PyBUF_ANY_CONTIGUOUS);
pattern_buf = ward->m_buf.buf;
pattern_len = ward->m_buf.len;
#else
if (PyObject_AsReadBuffer(pattern.ptr(), &pattern_buf, &pattern_len))
throw py::error_already_set();
#endif
cl_event evt;
PYOPENCL_RETRY_IF_MEM_ERROR(
PYOPENCL_CALL_GUARDED(clEnqueueFillBuffer, (
cq.data(),
mem.data(),
pattern_buf, pattern_len, offset, size,
PYOPENCL_WAITLIST_ARGS, &evt
))
);
PYOPENCL_RETURN_NEW_EVENT(evt);
}
#endif
// }}}
// {{{ image
class image : public memory_object
{
public:
image(cl_mem mem, bool retain, hostbuf_t hostbuf=hostbuf_t())
: memory_object(mem, retain, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(hostbuf))
{ }
py::object get_image_info(cl_image_info param_name) const
{
switch (param_name)
{
case CL_IMAGE_FORMAT:
PYOPENCL_GET_INTEGRAL_INFO(Image, data(), param_name,
cl_image_format);
case CL_IMAGE_ELEMENT_SIZE:
case CL_IMAGE_ROW_PITCH:
case CL_IMAGE_SLICE_PITCH:
case CL_IMAGE_WIDTH:
case CL_IMAGE_HEIGHT:
case CL_IMAGE_DEPTH:
#if PYOPENCL_CL_VERSION >= 0x1020
case CL_IMAGE_ARRAY_SIZE:
#endif
PYOPENCL_GET_INTEGRAL_INFO(Image, data(), param_name, size_t);
#if PYOPENCL_CL_VERSION >= 0x1020
case CL_IMAGE_BUFFER:
{
cl_mem param_value;
PYOPENCL_CALL_GUARDED(clGetImageInfo, \
(data(), param_name, sizeof(param_value), ¶m_value, 0));
if (param_value == 0)
{
// no associated memory object? no problem.
return py::none();
}
return create_mem_object_wrapper(param_value, /* retain */ true);
}
case CL_IMAGE_NUM_MIP_LEVELS:
case CL_IMAGE_NUM_SAMPLES:
PYOPENCL_GET_INTEGRAL_INFO(Image, data(), param_name, cl_uint);
#endif
default:
throw error("MemoryObject.get_image_info", CL_INVALID_VALUE);
}
}
};
// {{{ image formats
inline
cl_image_format *make_image_format(cl_channel_order ord, cl_channel_type tp)
{
std::unique_ptr<cl_image_format> result(new cl_image_format);
result->image_channel_order = ord;
result->image_channel_data_type = tp;
return result.release();
}
inline
py::list get_supported_image_formats(
context const &ctx,
cl_mem_flags flags,
cl_mem_object_type image_type)
{
cl_uint num_image_formats;
PYOPENCL_CALL_GUARDED(clGetSupportedImageFormats, (
ctx.data(), flags, image_type,
0, nullptr, &num_image_formats));
std::vector<cl_image_format> formats(num_image_formats);
PYOPENCL_CALL_GUARDED(clGetSupportedImageFormats, (
ctx.data(), flags, image_type,
formats.size(), formats.empty( ) ? nullptr : &formats.front(), nullptr));
PYOPENCL_RETURN_VECTOR(cl_image_format, formats);
}
inline
cl_uint get_image_format_channel_count(cl_image_format const &fmt)
{
switch (fmt.image_channel_order)
{
case CL_R: return 1;
case CL_A: return 1;
case CL_RG: return 2;
case CL_RA: return 2;
case CL_RGB: return 3;
case CL_RGBA: return 4;
case CL_BGRA: return 4;
case CL_INTENSITY: return 1;
case CL_LUMINANCE: return 1;
default:
throw pyopencl::error("ImageFormat.channel_dtype_size",
CL_INVALID_VALUE,
"unrecognized channel order");
}
}
inline
cl_uint get_image_format_channel_dtype_size(cl_image_format const &fmt)
{
switch (fmt.image_channel_data_type)
{
case CL_SNORM_INT8: return 1;
case CL_SNORM_INT16: return 2;
case CL_UNORM_INT8: return 1;
case CL_UNORM_INT16: return 2;
case CL_UNORM_SHORT_565: return 2;
case CL_UNORM_SHORT_555: return 2;
case CL_UNORM_INT_101010: return 4;
case CL_SIGNED_INT8: return 1;
case CL_SIGNED_INT16: return 2;
case CL_SIGNED_INT32: return 4;
case CL_UNSIGNED_INT8: return 1;
case CL_UNSIGNED_INT16: return 2;
case CL_UNSIGNED_INT32: return 4;
case CL_HALF_FLOAT: return 2;
case CL_FLOAT: return 4;
default:
throw pyopencl::error("ImageFormat.channel_dtype_size",
CL_INVALID_VALUE,
"unrecognized channel data type");
}
}
inline
cl_uint get_image_format_item_size(cl_image_format const &fmt)
{
return get_image_format_channel_count(fmt)
* get_image_format_channel_dtype_size(fmt);
}
// }}}
// {{{ image creation
inline
image *create_image(
context const &ctx,
cl_mem_flags flags,
cl_image_format const &fmt,
py::sequence shape,
py::sequence pitches,
py::object buffer)
{
if (shape.ptr() == Py_None)
throw pyopencl::error("Image", CL_INVALID_VALUE,
"'shape' must be given");
void *buf = 0;
PYOPENCL_BUFFER_SIZE_T len = 0;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
std::unique_ptr<py_buffer_wrapper> retained_buf_obj;
if (buffer.ptr() != Py_None)
{
retained_buf_obj = std::unique_ptr<py_buffer_wrapper>(new py_buffer_wrapper);
int py_buf_flags = PyBUF_ANY_CONTIGUOUS;
if ((flags & CL_MEM_USE_HOST_PTR)
&& ((flags & CL_MEM_READ_WRITE)
|| (flags & CL_MEM_WRITE_ONLY)))
py_buf_flags |= PyBUF_WRITABLE;
retained_buf_obj->get(buffer.ptr(), py_buf_flags);
buf = retained_buf_obj->m_buf.buf;
len = retained_buf_obj->m_buf.len;
}
#else
py::object retained_buf_obj;
if (buffer.ptr() != Py_None)
{
if ((flags & CL_MEM_USE_HOST_PTR)
&& ((flags & CL_MEM_READ_WRITE)
|| (flags & CL_MEM_WRITE_ONLY)))
{
if (PyObject_AsWriteBuffer(buffer.ptr(), &buf, &len))
throw py::error_already_set();
}
else
{
if (PyObject_AsReadBuffer(
buffer.ptr(), const_cast<const void **>(&buf), &len))
throw py::error_already_set();
}
if (flags & CL_MEM_USE_HOST_PTR)
retained_buf_obj = buffer;
}
#endif
unsigned dims = py::len(shape);
cl_int status_code;
cl_mem mem;
if (dims == 2)
{
size_t width = (shape[0]).cast<size_t>();
size_t height = (shape[1]).cast<size_t>();
size_t pitch = 0;
if (pitches.ptr() != Py_None)
{
if (py::len(pitches) != 1)
throw pyopencl::error("Image", CL_INVALID_VALUE,
"invalid length of pitch tuple");
pitch = (pitches[0]).cast<size_t>();
}
// check buffer size
cl_int itemsize = get_image_format_item_size(fmt);
if (buf && std::max(pitch, width*itemsize)*height > cl_uint(len))
throw pyopencl::error("Image", CL_INVALID_VALUE,
"buffer too small");
PYOPENCL_PRINT_CALL_TRACE("clCreateImage2D");
PYOPENCL_RETRY_IF_MEM_ERROR(
{
mem = clCreateImage2D(ctx.data(), flags, &fmt,
width, height, pitch, buf, &status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("clCreateImage2D", status_code);
} );
}
else if (dims == 3)
{
size_t width = (shape[0]).cast<size_t>();
size_t height = (shape[1]).cast<size_t>();
size_t depth = (shape[2]).cast<size_t>();
size_t pitch_x = 0;
size_t pitch_y = 0;
if (pitches.ptr() != Py_None)
{
if (py::len(pitches) != 2)
throw pyopencl::error("Image", CL_INVALID_VALUE,
"invalid length of pitch tuple");
pitch_x = (pitches[0]).cast<size_t>();
pitch_y = (pitches[1]).cast<size_t>();
}
// check buffer size
cl_int itemsize = get_image_format_item_size(fmt);
if (buf &&
std::max(std::max(pitch_x, width*itemsize)*height, pitch_y)
* depth > cl_uint(len))
throw pyopencl::error("Image", CL_INVALID_VALUE,
"buffer too small");
PYOPENCL_PRINT_CALL_TRACE("clCreateImage3D");
PYOPENCL_RETRY_IF_MEM_ERROR(
{
mem = clCreateImage3D(ctx.data(), flags, &fmt,
width, height, depth, pitch_x, pitch_y, buf, &status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("clCreateImage3D", status_code);
} );
}
else
throw pyopencl::error("Image", CL_INVALID_VALUE,
"invalid dimension");
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
if (!(flags & CL_MEM_USE_HOST_PTR))
retained_buf_obj.reset();
#endif
try
{
return new image(mem, false, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(retained_buf_obj));
}
catch (...)
{
PYOPENCL_CALL_GUARDED(clReleaseMemObject, (mem));
throw;
}
}
#if PYOPENCL_CL_VERSION >= 0x1020
inline
image *create_image_from_desc(
context const &ctx,
cl_mem_flags flags,
cl_image_format const &fmt,
cl_image_desc &desc,
py::object buffer)
{
if (buffer.ptr() != Py_None &&
!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
PyErr_Warn(PyExc_UserWarning, "'hostbuf' was passed, "
"but no memory flags to make use of it.");
void *buf = 0;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
std::unique_ptr<py_buffer_wrapper> retained_buf_obj;
if (buffer.ptr() != Py_None)
{
retained_buf_obj = std::unique_ptr<py_buffer_wrapper>(new py_buffer_wrapper);
int py_buf_flags = PyBUF_ANY_CONTIGUOUS;
if ((flags & CL_MEM_USE_HOST_PTR)
&& ((flags & CL_MEM_READ_WRITE)
|| (flags & CL_MEM_WRITE_ONLY)))
py_buf_flags |= PyBUF_WRITABLE;
retained_buf_obj->get(buffer.ptr(), py_buf_flags);
buf = retained_buf_obj->m_buf.buf;
}
#else
py::object retained_buf_obj;
PYOPENCL_BUFFER_SIZE_T len;
if (buffer.ptr() != Py_None)
{
if ((flags & CL_MEM_USE_HOST_PTR)
&& ((flags & CL_MEM_READ_WRITE)
|| (flags & CL_MEM_WRITE_ONLY)))
{
if (PyObject_AsWriteBuffer(buffer.ptr(), &buf, &len))
throw py::error_already_set();
}
else
{
if (PyObject_AsReadBuffer(
buffer.ptr(), const_cast<const void **>(&buf), &len))
throw py::error_already_set();
}
if (flags & CL_MEM_USE_HOST_PTR)
retained_buf_obj = buffer;
}
#endif
PYOPENCL_PRINT_CALL_TRACE("clCreateImage");
cl_int status_code;
cl_mem mem = clCreateImage(ctx.data(), flags, &fmt, &desc, buf, &status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("clCreateImage", status_code);
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
if (!(flags & CL_MEM_USE_HOST_PTR))
retained_buf_obj.reset();
#endif
try
{
return new image(mem, false, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(retained_buf_obj));
}
catch (...)
{
PYOPENCL_CALL_GUARDED(clReleaseMemObject, (mem));
throw;
}
}
#endif
// }}}
// {{{ image transfers
inline
event *enqueue_read_image(
command_queue &cq,
image &img,
py::object py_origin, py::object py_region,
py::object buffer,
size_t row_pitch, size_t slice_pitch,
py::object py_wait_for,
bool is_blocking)
{
PYOPENCL_PARSE_WAIT_FOR;
COPY_PY_COORD_TRIPLE(origin);
COPY_PY_REGION_TRIPLE(region);
void *buf;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
std::unique_ptr<py_buffer_wrapper> ward(new py_buffer_wrapper);
ward->get(buffer.ptr(), PyBUF_ANY_CONTIGUOUS | PyBUF_WRITABLE);
buf = ward->m_buf.buf;
#else
py::object ward = buffer;
PYOPENCL_BUFFER_SIZE_T len;
if (PyObject_AsWriteBuffer(buffer.ptr(), &buf, &len))
throw py::error_already_set();
#endif
cl_event evt;
PYOPENCL_RETRY_IF_MEM_ERROR(
PYOPENCL_CALL_GUARDED(clEnqueueReadImage, (
cq.data(),
img.data(),
PYOPENCL_CAST_BOOL(is_blocking),
origin, region, row_pitch, slice_pitch, buf,
PYOPENCL_WAITLIST_ARGS, &evt
));
);
PYOPENCL_RETURN_NEW_NANNY_EVENT(evt, ward);
}
inline
event *enqueue_write_image(
command_queue &cq,
image &img,
py::object py_origin, py::object py_region,
py::object buffer,
size_t row_pitch, size_t slice_pitch,
py::object py_wait_for,
bool is_blocking)
{
PYOPENCL_PARSE_WAIT_FOR;
COPY_PY_COORD_TRIPLE(origin);
COPY_PY_REGION_TRIPLE(region);
const void *buf;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
std::unique_ptr<py_buffer_wrapper> ward(new py_buffer_wrapper);
ward->get(buffer.ptr(), PyBUF_ANY_CONTIGUOUS);
buf = ward->m_buf.buf;
#else
py::object ward = buffer;
PYOPENCL_BUFFER_SIZE_T len;
if (PyObject_AsReadBuffer(buffer.ptr(), &buf, &len))
throw py::error_already_set();
#endif
cl_event evt;
PYOPENCL_RETRY_IF_MEM_ERROR(
PYOPENCL_CALL_GUARDED(clEnqueueWriteImage, (
cq.data(),
img.data(),
PYOPENCL_CAST_BOOL(is_blocking),
origin, region, row_pitch, slice_pitch, buf,
PYOPENCL_WAITLIST_ARGS, &evt
));
);
PYOPENCL_RETURN_NEW_NANNY_EVENT(evt, ward);
}
inline
event *enqueue_copy_image(
command_queue &cq,
memory_object_holder &src,
memory_object_holder &dest,
py::object py_src_origin,
py::object py_dest_origin,
py::object py_region,
py::object py_wait_for
)
{
PYOPENCL_PARSE_WAIT_FOR;
COPY_PY_COORD_TRIPLE(src_origin);
COPY_PY_COORD_TRIPLE(dest_origin);
COPY_PY_REGION_TRIPLE(region);
cl_event evt;
PYOPENCL_RETRY_IF_MEM_ERROR(
PYOPENCL_CALL_GUARDED(clEnqueueCopyImage, (
cq.data(), src.data(), dest.data(),
src_origin, dest_origin, region,
PYOPENCL_WAITLIST_ARGS, &evt
));
);
PYOPENCL_RETURN_NEW_EVENT(evt);
}
inline
event *enqueue_copy_image_to_buffer(
command_queue &cq,
memory_object_holder &src,
memory_object_holder &dest,
py::object py_origin,
py::object py_region,
size_t offset,
py::object py_wait_for
)
{
PYOPENCL_PARSE_WAIT_FOR;
COPY_PY_COORD_TRIPLE(origin);
COPY_PY_REGION_TRIPLE(region);
cl_event evt;
PYOPENCL_RETRY_IF_MEM_ERROR(
PYOPENCL_CALL_GUARDED(clEnqueueCopyImageToBuffer, (
cq.data(), src.data(), dest.data(),
origin, region, offset,
PYOPENCL_WAITLIST_ARGS, &evt
));
);
PYOPENCL_RETURN_NEW_EVENT(evt);
}
inline
event *enqueue_copy_buffer_to_image(
command_queue &cq,
memory_object_holder &src,
memory_object_holder &dest,
size_t offset,
py::object py_origin,
py::object py_region,
py::object py_wait_for
)
{
PYOPENCL_PARSE_WAIT_FOR;
COPY_PY_COORD_TRIPLE(origin);
COPY_PY_REGION_TRIPLE(region);
cl_event evt;
PYOPENCL_RETRY_IF_MEM_ERROR(
PYOPENCL_CALL_GUARDED(clEnqueueCopyBufferToImage, (
cq.data(), src.data(), dest.data(),
offset, origin, region,
PYOPENCL_WAITLIST_ARGS, &evt
));
);
PYOPENCL_RETURN_NEW_EVENT(evt);
}
// }}}
#if PYOPENCL_CL_VERSION >= 0x1020
inline
event *enqueue_fill_image(
command_queue &cq,
memory_object_holder &mem,
py::object color,
py::object py_origin, py::object py_region,
py::object py_wait_for
)
{
PYOPENCL_PARSE_WAIT_FOR;
COPY_PY_COORD_TRIPLE(origin);
COPY_PY_REGION_TRIPLE(region);
const void *color_buf;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
std::unique_ptr<py_buffer_wrapper> ward(new py_buffer_wrapper);
ward->get(color.ptr(), PyBUF_ANY_CONTIGUOUS);
color_buf = ward->m_buf.buf;
#else
PYOPENCL_BUFFER_SIZE_T color_len;
if (PyObject_AsReadBuffer(color.ptr(), &color_buf, &color_len))
throw py::error_already_set();
#endif
cl_event evt;
PYOPENCL_RETRY_IF_MEM_ERROR(
PYOPENCL_CALL_GUARDED(clEnqueueFillImage, (
cq.data(),
mem.data(),
color_buf, origin, region,
PYOPENCL_WAITLIST_ARGS, &evt
));
);
PYOPENCL_RETURN_NEW_EVENT(evt);
}
#endif
// }}}
// {{{ maps
class memory_map
{
private:
bool m_valid;
std::shared_ptr<command_queue> m_queue;
memory_object m_mem;
void *m_ptr;
public:
memory_map(std::shared_ptr<command_queue> cq, memory_object const &mem, void *ptr)
: m_valid(true), m_queue(cq), m_mem(mem), m_ptr(ptr)
{
}
~memory_map()
{
if (m_valid)
delete release(0, py::none());
}
event *release(command_queue *cq, py::object py_wait_for)
{
PYOPENCL_PARSE_WAIT_FOR;
if (cq == 0)
cq = m_queue.get();
cl_event evt;
PYOPENCL_CALL_GUARDED(clEnqueueUnmapMemObject, (
cq->data(), m_mem.data(), m_ptr,
PYOPENCL_WAITLIST_ARGS, &evt
));
m_valid = false;
PYOPENCL_RETURN_NEW_EVENT(evt);
}
};
// FIXME: Reenable in pypy
#ifndef PYPY_VERSION
inline
py::object enqueue_map_buffer(
std::shared_ptr<command_queue> cq,
memory_object_holder &buf,
cl_map_flags flags,
size_t offset,
py::object py_shape, py::object dtype,
py::object py_order, py::object py_strides,
py::object py_wait_for,
bool is_blocking
)
{
PYOPENCL_PARSE_WAIT_FOR;
PYOPENCL_PARSE_NUMPY_ARRAY_SPEC;
npy_uintp size_in_bytes = tp_descr->elsize;
for (npy_intp sdim: shape)
size_in_bytes *= sdim;
py::object result;
cl_event evt;
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clEnqueueMapBuffer");
void *mapped;
PYOPENCL_RETRY_IF_MEM_ERROR(
{
{
py::gil_scoped_release release;
mapped = clEnqueueMapBuffer(
cq->data(), buf.data(),
PYOPENCL_CAST_BOOL(is_blocking), flags,
offset, size_in_bytes,
PYOPENCL_WAITLIST_ARGS, &evt,
&status_code);
}
if (status_code != CL_SUCCESS)
throw pyopencl::error("clEnqueueMapBuffer", status_code);
} );
event evt_handle(evt, false);
std::unique_ptr<memory_map> map;
try
{
result = py::object(py::reinterpret_steal<py::object>(PyArray_NewFromDescr(
&PyArray_Type, tp_descr,
shape.size(),
shape.empty() ? nullptr : &shape.front(),
strides.empty() ? nullptr : &strides.front(),
mapped, ary_flags, /*obj*/nullptr)));
if (size_in_bytes != (npy_uintp) PyArray_NBYTES(result.ptr()))
throw pyopencl::error("enqueue_map_buffer", CL_INVALID_VALUE,
"miscalculated numpy array size (not contiguous?)");
map = std::unique_ptr<memory_map>(new memory_map(cq, buf, mapped));
}
catch (...)
{
PYOPENCL_CALL_GUARDED_CLEANUP(clEnqueueUnmapMemObject, (
cq->data(), buf.data(), mapped, 0, 0, 0));
throw;
}
py::object map_py(handle_from_new_ptr(map.release()));
PyArray_BASE(result.ptr()) = map_py.ptr();
Py_INCREF(map_py.ptr());
return py::make_tuple(
result,
handle_from_new_ptr(new event(evt_handle)));
}
#endif
// FIXME: Reenable in pypy
#ifndef PYPY_VERSION
inline
py::object enqueue_map_image(
std::shared_ptr<command_queue> cq,
memory_object_holder &img,
cl_map_flags flags,
py::object py_origin,
py::object py_region,
py::object py_shape, py::object dtype,
py::object py_order, py::object py_strides,
py::object py_wait_for,
bool is_blocking
)
{
PYOPENCL_PARSE_WAIT_FOR;
PYOPENCL_PARSE_NUMPY_ARRAY_SPEC;
COPY_PY_COORD_TRIPLE(origin);
COPY_PY_REGION_TRIPLE(region);
cl_event evt;
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clEnqueueMapImage");
size_t row_pitch, slice_pitch;
void *mapped;
PYOPENCL_RETRY_IF_MEM_ERROR(
{
{
py::gil_scoped_release release;
mapped = clEnqueueMapImage(
cq->data(), img.data(),
PYOPENCL_CAST_BOOL(is_blocking), flags,
origin, region, &row_pitch, &slice_pitch,
PYOPENCL_WAITLIST_ARGS, &evt,
&status_code);
}
if (status_code != CL_SUCCESS)
throw pyopencl::error("clEnqueueMapImage", status_code);
} );
event evt_handle(evt, false);
std::unique_ptr<memory_map> map;
try
{
map = std::unique_ptr<memory_map>(new memory_map(cq, img, mapped));
}
catch (...)
{
PYOPENCL_CALL_GUARDED_CLEANUP(clEnqueueUnmapMemObject, (
cq->data(), img.data(), mapped, 0, 0, 0));
throw;
}
py::object result = py::reinterpret_steal<py::object>(PyArray_NewFromDescr(
&PyArray_Type, tp_descr,
shape.size(),
shape.empty() ? nullptr : &shape.front(),
strides.empty() ? nullptr : &strides.front(),
mapped, ary_flags, /*obj*/nullptr));
py::object map_py(handle_from_new_ptr(map.release()));
PyArray_BASE(result.ptr()) = map_py.ptr();
Py_INCREF(map_py.ptr());
return py::make_tuple(
result,
handle_from_new_ptr(new event(evt_handle)),
row_pitch, slice_pitch);
}
#endif
// }}}
// {{{ svm
#if PYOPENCL_CL_VERSION >= 0x2000
class svm_arg_wrapper
{
private:
void *m_ptr;
PYOPENCL_BUFFER_SIZE_T m_size;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
std::unique_ptr<py_buffer_wrapper> ward;
#endif
public:
svm_arg_wrapper(py::object holder)
{
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
ward = std::unique_ptr<py_buffer_wrapper>(new py_buffer_wrapper);
#ifdef PYPY_VERSION
// FIXME: get a read-only buffer
// Not quite honest, but Pypy doesn't consider numpy arrays
// created from objects with the __aray_interface__ writeable.
ward->get(holder.ptr(), PyBUF_ANY_CONTIGUOUS);
#else
ward->get(holder.ptr(), PyBUF_ANY_CONTIGUOUS | PyBUF_WRITABLE);
#endif
m_ptr = ward->m_buf.buf;
m_size = ward->m_buf.len;
#else
py::object ward = holder;
if (PyObject_AsWriteBuffer(holder.ptr(), &m_ptr, &m_size))
throw py::error_already_set();
#endif
}
void *ptr() const
{
return m_ptr;
}
size_t size() const
{
return m_size;
}
};
class svm_allocation : noncopyable
{
private:
std::shared_ptr<context> m_context;
void *m_allocation;
public:
svm_allocation(std::shared_ptr<context> const &ctx, size_t size, cl_uint alignment, cl_svm_mem_flags flags)
: m_context(ctx)
{
PYOPENCL_PRINT_CALL_TRACE("clSVMalloc");
m_allocation = clSVMAlloc(
ctx->data(),
flags, size, alignment);
if (!m_allocation)
throw pyopencl::error("clSVMAlloc", CL_OUT_OF_RESOURCES);
}
~svm_allocation()
{
if (m_allocation)
release();
}
void release()
{
if (!m_allocation)
throw error("SVMAllocation.release", CL_INVALID_VALUE,
"trying to double-unref svm allocation");
clSVMFree(m_context->data(), m_allocation);
m_allocation = nullptr;
}
void enqueue_release(command_queue &queue, py::object py_wait_for)
{
PYOPENCL_PARSE_WAIT_FOR;
if (!m_allocation)
throw error("SVMAllocation.release", CL_INVALID_VALUE,
"trying to double-unref svm allocation");
cl_event evt;
PYOPENCL_CALL_GUARDED_CLEANUP(clEnqueueSVMFree, (
queue.data(), 1, &m_allocation,
nullptr, nullptr,
PYOPENCL_WAITLIST_ARGS, &evt));
m_allocation = nullptr;
}
void *ptr() const
{
return m_allocation;
}
intptr_t ptr_as_int() const
{
return (intptr_t) m_allocation;
}
bool operator==(svm_allocation const &other) const
{
return m_allocation == other.m_allocation;
}
bool operator!=(svm_allocation const &other) const
{
return m_allocation != other.m_allocation;
}
};
inline
event *enqueue_svm_memcpy(
command_queue &cq,
cl_bool is_blocking,
svm_arg_wrapper &dst, svm_arg_wrapper &src,
py::object py_wait_for
)
{
PYOPENCL_PARSE_WAIT_FOR;
if (src.size() != dst.size())
throw error("_enqueue_svm_memcpy", CL_INVALID_VALUE,
"sizes of source and destination buffer do not match");
cl_event evt;
PYOPENCL_CALL_GUARDED(
clEnqueueSVMMemcpy,
(
cq.data(),
is_blocking,
dst.ptr(), src.ptr(),
dst.size(),
PYOPENCL_WAITLIST_ARGS,
&evt
));
PYOPENCL_RETURN_NEW_EVENT(evt);
}
inline
event *enqueue_svm_memfill(
command_queue &cq,
svm_arg_wrapper &dst, py::object py_pattern,
py::object byte_count,
py::object py_wait_for
)
{
PYOPENCL_PARSE_WAIT_FOR;
const void *pattern_ptr;
PYOPENCL_BUFFER_SIZE_T pattern_len;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
std::unique_ptr<py_buffer_wrapper> pattern_ward(new py_buffer_wrapper);
pattern_ward->get(py_pattern.ptr(), PyBUF_ANY_CONTIGUOUS);
pattern_ptr = pattern_ward->m_buf.buf;
pattern_len = pattern_ward->m_buf.len;
#else
py::object pattern_ward = py_pattern;
if (PyObject_AsReadBuffer(py_pattern.ptr(), &pattern_ptr, &pattern_len))
throw py::error_already_set();
#endif
size_t fill_size = dst.size();
if (!byte_count.is_none())
fill_size = py::cast<size_t>(byte_count);
cl_event evt;
PYOPENCL_CALL_GUARDED(
clEnqueueSVMMemFill,
(
cq.data(),
dst.ptr(), pattern_ptr,
pattern_len,
fill_size,
PYOPENCL_WAITLIST_ARGS,
&evt
));
PYOPENCL_RETURN_NEW_EVENT(evt);
}
inline
event *enqueue_svm_map(
command_queue &cq,
cl_bool is_blocking,
cl_map_flags flags,
svm_arg_wrapper &svm,
py::object py_wait_for
)
{
PYOPENCL_PARSE_WAIT_FOR;
cl_event evt;
PYOPENCL_CALL_GUARDED(
clEnqueueSVMMap,
(
cq.data(),
is_blocking,
flags,
svm.ptr(), svm.size(),
PYOPENCL_WAITLIST_ARGS,
&evt
));
PYOPENCL_RETURN_NEW_EVENT(evt);
}
inline
event *enqueue_svm_unmap(
command_queue &cq,
svm_arg_wrapper &svm,
py::object py_wait_for
)
{
PYOPENCL_PARSE_WAIT_FOR;
cl_event evt;
PYOPENCL_CALL_GUARDED(
clEnqueueSVMUnmap,
(
cq.data(),
svm.ptr(),
PYOPENCL_WAITLIST_ARGS,
&evt
));
PYOPENCL_RETURN_NEW_EVENT(evt);
}
#endif
#if PYOPENCL_CL_VERSION >= 0x2010
inline
event *enqueue_svm_migratemem(
command_queue &cq,
py::sequence svms,
cl_mem_migration_flags flags,
py::object py_wait_for
)
{
PYOPENCL_PARSE_WAIT_FOR;
std::vector<const void *> svm_pointers;
std::vector<size_t> sizes;
for (py::handle py_svm: svms)
{
svm_arg_wrapper &svm(py::cast<svm_arg_wrapper &>(py_svm));
svm_pointers.push_back(svm.ptr());
sizes.push_back(svm.size());
}
cl_event evt;
PYOPENCL_CALL_GUARDED(
clEnqueueSVMMigrateMem,
(
cq.data(),
svm_pointers.size(),
svm_pointers.empty() ? nullptr : &svm_pointers.front(),
sizes.empty() ? nullptr : &sizes.front(),
flags,
PYOPENCL_WAITLIST_ARGS,
&evt
));
PYOPENCL_RETURN_NEW_EVENT(evt);
}
#endif
// }}}
// {{{ sampler
class sampler : noncopyable
{
private:
cl_sampler m_sampler;
public:
#if PYOPENCL_CL_VERSION >= 0x2000
sampler(context const &ctx, py::sequence py_props)
{
int hex_plat_version = ctx.get_hex_platform_version();
if (hex_plat_version < 0x2000)
{
std::cerr <<
"sampler properties given as an iterable, "
"which uses an OpenCL 2+-only interface, "
"but the context's platform does not "
"declare OpenCL 2 support. Proceeding "
"as requested, but the next thing you see "
"may be a crash." << std:: endl;
}
PYOPENCL_STACK_CONTAINER(cl_sampler_properties, props, py::len(py_props) + 1);
{
size_t i = 0;
for (auto prop: py_props)
props[i++] = py::cast<cl_sampler_properties>(prop);
props[i++] = 0;
}
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clCreateSamplerWithProperties");
m_sampler = clCreateSamplerWithProperties(
ctx.data(),
PYOPENCL_STACK_CONTAINER_GET_PTR(props),
&status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("Sampler", status_code);
}
#endif
sampler(context const &ctx, bool normalized_coordinates,
cl_addressing_mode am, cl_filter_mode fm)
{
PYOPENCL_PRINT_CALL_TRACE("clCreateSampler");
int hex_plat_version = ctx.get_hex_platform_version();
#if PYOPENCL_CL_VERSION >= 0x2000
if (hex_plat_version >= 0x2000)
{
cl_sampler_properties props_list[] = {
CL_SAMPLER_NORMALIZED_COORDS, normalized_coordinates,
CL_SAMPLER_ADDRESSING_MODE, am,
CL_SAMPLER_FILTER_MODE, fm,
0,
};
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clCreateSamplerWithProperties");
m_sampler = clCreateSamplerWithProperties(
ctx.data(), props_list, &status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("Sampler", status_code);
}
else
#endif
{
cl_int status_code;
#if defined(__GNUG__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
m_sampler = clCreateSampler(
ctx.data(),
normalized_coordinates,
am, fm, &status_code);
#if defined(__GNUG__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
if (status_code != CL_SUCCESS)
throw pyopencl::error("Sampler", status_code);
}
}
sampler(cl_sampler samp, bool retain)
: m_sampler(samp)
{
if (retain)
PYOPENCL_CALL_GUARDED(clRetainSampler, (samp));
}
~sampler()
{
PYOPENCL_CALL_GUARDED_CLEANUP(clReleaseSampler, (m_sampler));
}
cl_sampler data() const
{
return m_sampler;
}
PYOPENCL_EQUALITY_TESTS(sampler);
py::object get_info(cl_sampler_info param_name) const
{
switch (param_name)
{
case CL_SAMPLER_REFERENCE_COUNT:
PYOPENCL_GET_INTEGRAL_INFO(Sampler, m_sampler, param_name,
cl_uint);
case CL_SAMPLER_CONTEXT:
PYOPENCL_GET_OPAQUE_INFO(Sampler, m_sampler, param_name,
cl_context, context);
case CL_SAMPLER_ADDRESSING_MODE:
PYOPENCL_GET_INTEGRAL_INFO(Sampler, m_sampler, param_name,
cl_addressing_mode);
case CL_SAMPLER_FILTER_MODE:
PYOPENCL_GET_INTEGRAL_INFO(Sampler, m_sampler, param_name,
cl_filter_mode);
case CL_SAMPLER_NORMALIZED_COORDS:
PYOPENCL_GET_INTEGRAL_INFO(Sampler, m_sampler, param_name,
cl_bool);
default:
throw error("Sampler.get_info", CL_INVALID_VALUE);
}
}
};
// }}}
// {{{ program
class program : noncopyable
{
public:
enum program_kind_type { KND_UNKNOWN, KND_SOURCE, KND_BINARY };
private:
cl_program m_program;
program_kind_type m_program_kind;
public:
program(cl_program prog, bool retain, program_kind_type progkind=KND_UNKNOWN)
: m_program(prog), m_program_kind(progkind)
{
if (retain)
PYOPENCL_CALL_GUARDED(clRetainProgram, (prog));
}
~program()
{
PYOPENCL_CALL_GUARDED_CLEANUP(clReleaseProgram, (m_program));
}
cl_program data() const
{
return m_program;
}
program_kind_type kind() const
{
return m_program_kind;
}
PYOPENCL_EQUALITY_TESTS(program);
py::object get_info(cl_program_info param_name) const
{
switch (param_name)
{
case CL_PROGRAM_REFERENCE_COUNT:
PYOPENCL_GET_INTEGRAL_INFO(Program, m_program, param_name,
cl_uint);
case CL_PROGRAM_CONTEXT:
PYOPENCL_GET_OPAQUE_INFO(Program, m_program, param_name,
cl_context, context);
case CL_PROGRAM_NUM_DEVICES:
PYOPENCL_GET_INTEGRAL_INFO(Program, m_program, param_name,
cl_uint);
case CL_PROGRAM_DEVICES:
{
std::vector<cl_device_id> result;
PYOPENCL_GET_VEC_INFO(Program, m_program, param_name, result);
py::list py_result;
for (cl_device_id did: result)
py_result.append(handle_from_new_ptr(
new pyopencl::device(did)));
return py_result;
}
case CL_PROGRAM_SOURCE:
PYOPENCL_GET_STR_INFO(Program, m_program, param_name);
case CL_PROGRAM_BINARY_SIZES:
{
std::vector<size_t> result;
PYOPENCL_GET_VEC_INFO(Program, m_program, param_name, result);
PYOPENCL_RETURN_VECTOR(size_t, result);
}
case CL_PROGRAM_BINARIES:
// {{{
{
std::vector<size_t> sizes;
PYOPENCL_GET_VEC_INFO(Program, m_program, CL_PROGRAM_BINARY_SIZES, sizes);
size_t total_size = std::accumulate(sizes.begin(), sizes.end(), 0);
std::unique_ptr<unsigned char []> result(
new unsigned char[total_size]);
std::vector<unsigned char *> result_ptrs;
unsigned char *ptr = result.get();
for (unsigned i = 0; i < sizes.size(); ++i)
{
result_ptrs.push_back(ptr);
ptr += sizes[i];
}
PYOPENCL_CALL_GUARDED(clGetProgramInfo,
(m_program, param_name, sizes.size()*sizeof(unsigned char *),
result_ptrs.empty( ) ? nullptr : &result_ptrs.front(), 0)); \
py::list py_result;
ptr = result.get();
for (unsigned i = 0; i < sizes.size(); ++i)
{
py::object binary_pyobj(
py::reinterpret_steal<py::object>(
#if PY_VERSION_HEX >= 0x03000000
PyBytes_FromStringAndSize(
reinterpret_cast<char *>(ptr), sizes[i])
#else
PyString_FromStringAndSize(
reinterpret_cast<char *>(ptr), sizes[i])
#endif
));
py_result.append(binary_pyobj);
ptr += sizes[i];
}
return py_result;
}
// }}}
#if PYOPENCL_CL_VERSION >= 0x1020
case CL_PROGRAM_NUM_KERNELS:
PYOPENCL_GET_INTEGRAL_INFO(Program, m_program, param_name,
size_t);
case CL_PROGRAM_KERNEL_NAMES:
PYOPENCL_GET_STR_INFO(Program, m_program, param_name);
#endif
default:
throw error("Program.get_info", CL_INVALID_VALUE);
}
}
py::object get_build_info(
device const &dev,
cl_program_build_info param_name) const
{
switch (param_name)
{
#define PYOPENCL_FIRST_ARG m_program, dev.data() // hackety hack
case CL_PROGRAM_BUILD_STATUS:
PYOPENCL_GET_INTEGRAL_INFO(ProgramBuild,
PYOPENCL_FIRST_ARG, param_name,
cl_build_status);
case CL_PROGRAM_BUILD_OPTIONS:
case CL_PROGRAM_BUILD_LOG:
PYOPENCL_GET_STR_INFO(ProgramBuild,
PYOPENCL_FIRST_ARG, param_name);
#if PYOPENCL_CL_VERSION >= 0x1020
case CL_PROGRAM_BINARY_TYPE:
PYOPENCL_GET_INTEGRAL_INFO(ProgramBuild,
PYOPENCL_FIRST_ARG, param_name,
cl_program_binary_type);
#endif
#if PYOPENCL_CL_VERSION >= 0x2000
case CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE:
PYOPENCL_GET_INTEGRAL_INFO(ProgramBuild,
PYOPENCL_FIRST_ARG, param_name,
size_t);
#endif
#undef PYOPENCL_FIRST_ARG
default:
throw error("Program.get_build_info", CL_INVALID_VALUE);
}
}
void build(std::string options, py::object py_devices)
{
PYOPENCL_PARSE_PY_DEVICES;
PYOPENCL_CALL_GUARDED_THREADED(clBuildProgram,
(m_program, num_devices, devices,
options.c_str(), 0 ,0));
}
#if PYOPENCL_CL_VERSION >= 0x1020
void compile(std::string options, py::object py_devices,
py::object py_headers)
{
PYOPENCL_PARSE_PY_DEVICES;
// {{{ pick apart py_headers
// py_headers is a list of tuples *(name, program)*
std::vector<std::string> header_names;
std::vector<cl_program> programs;
for (py::handle name_hdr_tup_py: py_headers)
{
py::tuple name_hdr_tup = py::reinterpret_borrow<py::tuple>(name_hdr_tup_py);
if (py::len(name_hdr_tup) != 2)
throw error("Program.compile", CL_INVALID_VALUE,
"epxected (name, header) tuple in headers list");
std::string name = (name_hdr_tup[0]).cast<std::string>();
program &prg = (name_hdr_tup[1]).cast<program &>();
header_names.push_back(name);
programs.push_back(prg.data());
}
std::vector<const char *> header_name_ptrs;
for (std::string const &name: header_names)
header_name_ptrs.push_back(name.c_str());
// }}}
PYOPENCL_CALL_GUARDED_THREADED(clCompileProgram,
(m_program, num_devices, devices,
options.c_str(), header_names.size(),
programs.empty() ? nullptr : &programs.front(),
header_name_ptrs.empty() ? nullptr : &header_name_ptrs.front(),
0, 0));
}
#endif
};
inline
program *create_program_with_source(
context &ctx,
std::string const &src)
{
const char *string = src.c_str();
size_t length = src.size();
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clCreateProgramWithSource");
cl_program result = clCreateProgramWithSource(
ctx.data(), 1, &string, &length, &status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("clCreateProgramWithSource", status_code);
try
{
return new program(result, false, program::KND_SOURCE);
}
catch (...)
{
clReleaseProgram(result);
throw;
}
}
inline
program *create_program_with_binary(
context &ctx,
py::sequence py_devices,
py::sequence py_binaries)
{
std::vector<cl_device_id> devices;
std::vector<const unsigned char *> binaries;
std::vector<size_t> sizes;
size_t num_devices = len(py_devices);
if (len(py_binaries) != num_devices)
throw error("create_program_with_binary", CL_INVALID_VALUE,
"device and binary counts don't match");
for (size_t i = 0; i < num_devices; ++i)
{
devices.push_back(
(py_devices[i]).cast<device const &>().data());
const void *buf;
PYOPENCL_BUFFER_SIZE_T len;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
py_buffer_wrapper buf_wrapper;
buf_wrapper.get(py::object(py_binaries[i]).ptr(), PyBUF_ANY_CONTIGUOUS);
buf = buf_wrapper.m_buf.buf;
len = buf_wrapper.m_buf.len;
#else
if (PyObject_AsReadBuffer(
py::object(py_binaries[i]).ptr(), &buf, &len))
throw py::error_already_set();
#endif
binaries.push_back(reinterpret_cast<const unsigned char *>(buf));
sizes.push_back(len);
}
PYOPENCL_STACK_CONTAINER(cl_int, binary_statuses, num_devices);
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clCreateProgramWithBinary");
cl_program result = clCreateProgramWithBinary(
ctx.data(), num_devices,
devices.empty( ) ? nullptr : &devices.front(),
sizes.empty( ) ? nullptr : &sizes.front(),
binaries.empty( ) ? nullptr : &binaries.front(),
PYOPENCL_STACK_CONTAINER_GET_PTR(binary_statuses),
&status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("clCreateProgramWithBinary", status_code);
/*
for (int i = 0; i < num_devices; ++i)
printf("%d:%d\n", i, binary_statuses[i]);
*/
try
{
return new program(result, false, program::KND_BINARY);
}
catch (...)
{
clReleaseProgram(result);
throw;
}
}
#if (PYOPENCL_CL_VERSION >= 0x1020) || \
((PYOPENCL_CL_VERSION >= 0x1030) && defined(__APPLE__))
inline
program *create_program_with_built_in_kernels(
context &ctx,
py::object py_devices,
std::string const &kernel_names)
{
PYOPENCL_PARSE_PY_DEVICES;
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clCreateProgramWithBuiltInKernels");
cl_program result = clCreateProgramWithBuiltInKernels(
ctx.data(), num_devices, devices,
kernel_names.c_str(), &status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("clCreateProgramWithBuiltInKernels", status_code);
try
{
return new program(result, false);
}
catch (...)
{
clReleaseProgram(result);
throw;
}
}
#endif
#if PYOPENCL_CL_VERSION >= 0x1020
inline
program *link_program(
context &ctx,
py::object py_programs,
std::string const &options,
py::object py_devices
)
{
PYOPENCL_PARSE_PY_DEVICES;
std::vector<cl_program> programs;
for (py::handle py_prg: py_programs)
{
program &prg = (py_prg).cast<program &>();
programs.push_back(prg.data());
}
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clLinkProgram");
cl_program result = clLinkProgram(
ctx.data(), num_devices, devices,
options.c_str(),
programs.size(),
programs.empty() ? nullptr : &programs.front(),
0, 0,
&status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("clLinkProgram", result, status_code);
try
{
return new program(result, false);
}
catch (...)
{
clReleaseProgram(result);
throw;
}
}
#endif
#if PYOPENCL_CL_VERSION >= 0x1020
inline
void unload_platform_compiler(platform &plat)
{
PYOPENCL_CALL_GUARDED(clUnloadPlatformCompiler, (plat.data()));
}
#endif
// }}}
// {{{ kernel
class local_memory
{
private:
size_t m_size;
public:
local_memory(size_t size)
: m_size(size)
{ }
size_t size() const
{ return m_size; }
};
class kernel : noncopyable
{
private:
cl_kernel m_kernel;
public:
kernel(cl_kernel knl, bool retain)
: m_kernel(knl)
{
if (retain)
PYOPENCL_CALL_GUARDED(clRetainKernel, (knl));
}
kernel(program const &prg, std::string const &kernel_name)
{
cl_int status_code;
PYOPENCL_PRINT_CALL_TRACE("clCreateKernel");
m_kernel = clCreateKernel(prg.data(), kernel_name.c_str(),
&status_code);
if (status_code != CL_SUCCESS)
throw pyopencl::error("clCreateKernel", status_code);
}
~kernel()
{
PYOPENCL_CALL_GUARDED_CLEANUP(clReleaseKernel, (m_kernel));
}
cl_kernel data() const
{
return m_kernel;
}
PYOPENCL_EQUALITY_TESTS(kernel);
void set_arg_null(cl_uint arg_index)
{
cl_mem m = 0;
PYOPENCL_CALL_GUARDED(clSetKernelArg, (m_kernel, arg_index,
sizeof(cl_mem), &m));
}
void set_arg_mem(cl_uint arg_index, memory_object_holder &moh)
{
cl_mem m = moh.data();
PYOPENCL_CALL_GUARDED(clSetKernelArg,
(m_kernel, arg_index, sizeof(cl_mem), &m));
}
void set_arg_local(cl_uint arg_index, local_memory const &loc)
{
PYOPENCL_CALL_GUARDED(clSetKernelArg,
(m_kernel, arg_index, loc.size(), 0));
}
void set_arg_sampler(cl_uint arg_index, sampler const &smp)
{
cl_sampler s = smp.data();
PYOPENCL_CALL_GUARDED(clSetKernelArg,
(m_kernel, arg_index, sizeof(cl_sampler), &s));
}
void set_arg_command_queue(cl_uint arg_index, command_queue const &queue)
{
cl_command_queue q = queue.data();
PYOPENCL_CALL_GUARDED(clSetKernelArg,
(m_kernel, arg_index, sizeof(cl_command_queue), &q));
}
void set_arg_buf(cl_uint arg_index, py::object py_buffer)
{
const void *buf;
PYOPENCL_BUFFER_SIZE_T len;
#ifdef PYOPENCL_USE_NEW_BUFFER_INTERFACE
py_buffer_wrapper buf_wrapper;
try
{
buf_wrapper.get(py_buffer.ptr(), PyBUF_ANY_CONTIGUOUS);
}
catch (py::error_already_set &)
{
PyErr_Clear();
throw error("Kernel.set_arg", CL_INVALID_VALUE,
"invalid kernel argument");
}
buf = buf_wrapper.m_buf.buf;
len = buf_wrapper.m_buf.len;
#else
if (PyObject_AsReadBuffer(py_buffer.ptr(), &buf, &len))
{
PyErr_Clear();
throw error("Kernel.set_arg", CL_INVALID_VALUE,
"invalid kernel argument");
}
#endif
PYOPENCL_CALL_GUARDED(clSetKernelArg,
(m_kernel, arg_index, len, buf));
}
#if PYOPENCL_CL_VERSION >= 0x2000
void set_arg_svm(cl_uint arg_index, svm_arg_wrapper const &wrp)
{
PYOPENCL_CALL_GUARDED(clSetKernelArgSVMPointer,
(m_kernel, arg_index, wrp.ptr()));
}
#endif
void set_arg(cl_uint arg_index, py::object arg)
{
if (arg.ptr() == Py_None)
{
set_arg_null(arg_index);
return;
}
try
{
set_arg_mem(arg_index, arg.cast<memory_object_holder &>());
return;
}
catch (py::cast_error &) { }
#if PYOPENCL_CL_VERSION >= 0x2000
try
{
set_arg_svm(arg_index, arg.cast<svm_arg_wrapper const &>());
return;
}
catch (py::cast_error &) { }
#endif
try
{
set_arg_local(arg_index, arg.cast<local_memory>());
return;
}
catch (py::cast_error &) { }
try
{
set_arg_sampler(arg_index, arg.cast<const sampler &>());
return;
}
catch (py::cast_error &) { }
try
{
set_arg_command_queue(arg_index, arg.cast<const command_queue &>());
return;
}
catch (py::cast_error &) { }
set_arg_buf(arg_index, arg);
}
py::object get_info(cl_kernel_info param_name) const
{
switch (param_name)
{
case CL_KERNEL_FUNCTION_NAME:
PYOPENCL_GET_STR_INFO(Kernel, m_kernel, param_name);
case CL_KERNEL_NUM_ARGS:
case CL_KERNEL_REFERENCE_COUNT:
PYOPENCL_GET_INTEGRAL_INFO(Kernel, m_kernel, param_name,
cl_uint);
case CL_KERNEL_CONTEXT:
PYOPENCL_GET_OPAQUE_INFO(Kernel, m_kernel, param_name,
cl_context, context);
case CL_KERNEL_PROGRAM:
PYOPENCL_GET_OPAQUE_INFO(Kernel, m_kernel, param_name,
cl_program, program);
#if PYOPENCL_CL_VERSION >= 0x1020
case CL_KERNEL_ATTRIBUTES:
PYOPENCL_GET_STR_INFO(Kernel, m_kernel, param_name);
#endif
default:
throw error("Kernel.get_info", CL_INVALID_VALUE);
}
}
py::object get_work_group_info(
cl_kernel_work_group_info param_name,
device const &dev
) const
{
switch (param_name)
{
#define PYOPENCL_FIRST_ARG m_kernel, dev.data() // hackety hack
case CL_KERNEL_WORK_GROUP_SIZE:
PYOPENCL_GET_INTEGRAL_INFO(KernelWorkGroup,
PYOPENCL_FIRST_ARG, param_name,
size_t);
case CL_KERNEL_COMPILE_WORK_GROUP_SIZE:
{
std::vector<size_t> result;
PYOPENCL_GET_VEC_INFO(KernelWorkGroup,
PYOPENCL_FIRST_ARG, param_name, result);
PYOPENCL_RETURN_VECTOR(size_t, result);
}
case CL_KERNEL_LOCAL_MEM_SIZE:
#if PYOPENCL_CL_VERSION >= 0x1010
case CL_KERNEL_PRIVATE_MEM_SIZE:
#endif
PYOPENCL_GET_INTEGRAL_INFO(KernelWorkGroup,
PYOPENCL_FIRST_ARG, param_name,
cl_ulong);
#if PYOPENCL_CL_VERSION >= 0x1010
case CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE:
PYOPENCL_GET_INTEGRAL_INFO(KernelWorkGroup,
PYOPENCL_FIRST_ARG, param_name,
size_t);
#endif
default:
throw error("Kernel.get_work_group_info", CL_INVALID_VALUE);
#undef PYOPENCL_FIRST_ARG
}
}
#if PYOPENCL_CL_VERSION >= 0x1020
py::object get_arg_info(
cl_uint arg_index,
cl_kernel_arg_info param_name
) const
{
switch (param_name)
{
#define PYOPENCL_FIRST_ARG m_kernel, arg_index // hackety hack
case CL_KERNEL_ARG_ADDRESS_QUALIFIER:
PYOPENCL_GET_INTEGRAL_INFO(KernelArg,
PYOPENCL_FIRST_ARG, param_name,
cl_kernel_arg_address_qualifier);
case CL_KERNEL_ARG_ACCESS_QUALIFIER:
PYOPENCL_GET_INTEGRAL_INFO(KernelArg,
PYOPENCL_FIRST_ARG, param_name,
cl_kernel_arg_access_qualifier);
case CL_KERNEL_ARG_TYPE_NAME:
case CL_KERNEL_ARG_NAME:
PYOPENCL_GET_STR_INFO(KernelArg, PYOPENCL_FIRST_ARG, param_name);
#undef PYOPENCL_FIRST_ARG
default:
throw error("Kernel.get_arg_info", CL_INVALID_VALUE);
}
}
#endif
};
inline
py::list create_kernels_in_program(program &pgm)
{
cl_uint num_kernels;
PYOPENCL_CALL_GUARDED(clCreateKernelsInProgram, (
pgm.data(), 0, 0, &num_kernels));
std::vector<cl_kernel> kernels(num_kernels);
PYOPENCL_CALL_GUARDED(clCreateKernelsInProgram, (
pgm.data(), num_kernels,
kernels.empty( ) ? nullptr : &kernels.front(), &num_kernels));
py::list result;
for (cl_kernel knl: kernels)
result.append(handle_from_new_ptr(new kernel(knl, true)));
return result;
}
inline
event *enqueue_nd_range_kernel(
command_queue &cq,
kernel &knl,
py::object py_global_work_size,
py::object py_local_work_size,
py::object py_global_work_offset,
py::object py_wait_for,
bool g_times_l)
{
PYOPENCL_PARSE_WAIT_FOR;
cl_uint work_dim = len(py_global_work_size);
std::vector<size_t> global_work_size;
COPY_PY_LIST(size_t, global_work_size);
size_t *local_work_size_ptr = 0;
std::vector<size_t> local_work_size;
if (py_local_work_size.ptr() != Py_None)
{
if (g_times_l)
work_dim = std::max(work_dim, unsigned(len(py_local_work_size)));
else
if (work_dim != unsigned(len(py_local_work_size)))
throw error("enqueue_nd_range_kernel", CL_INVALID_VALUE,
"global/local work sizes have differing dimensions");
COPY_PY_LIST(size_t, local_work_size);
while (local_work_size.size() < work_dim)
local_work_size.push_back(1);
while (global_work_size.size() < work_dim)
global_work_size.push_back(1);
local_work_size_ptr = local_work_size.empty( ) ? nullptr : &local_work_size.front();
}
if (g_times_l && local_work_size_ptr)
{
for (cl_uint work_axis = 0; work_axis < work_dim; ++work_axis)
global_work_size[work_axis] *= local_work_size[work_axis];
}
size_t *global_work_offset_ptr = 0;
std::vector<size_t> global_work_offset;
if (py_global_work_offset.ptr() != Py_None)
{
if (work_dim != unsigned(len(py_global_work_offset)))
throw error("enqueue_nd_range_kernel", CL_INVALID_VALUE,
"global work size and offset have differing dimensions");
COPY_PY_LIST(size_t, global_work_offset);
if (g_times_l && local_work_size_ptr)
{
for (cl_uint work_axis = 0; work_axis < work_dim; ++work_axis)
global_work_offset[work_axis] *= local_work_size[work_axis];
}
global_work_offset_ptr = global_work_offset.empty( ) ? nullptr : &global_work_offset.front();
}
PYOPENCL_RETRY_RETURN_IF_MEM_ERROR( {
cl_event evt;
PYOPENCL_CALL_GUARDED(clEnqueueNDRangeKernel, (
cq.data(),
knl.data(),
work_dim,
global_work_offset_ptr,
global_work_size.empty( ) ? nullptr : &global_work_size.front(),
local_work_size_ptr,
PYOPENCL_WAITLIST_ARGS, &evt
));
PYOPENCL_RETURN_NEW_EVENT(evt);
} );
}
// }}}
// {{{ gl interop
inline
bool have_gl()
{
#ifdef HAVE_GL
return true;
#else
return false;
#endif
}
#ifdef HAVE_GL
#ifdef __APPLE__
inline
cl_context_properties get_apple_cgl_share_group()
{
CGLContextObj kCGLContext = CGLGetCurrentContext();
CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);
return (cl_context_properties) kCGLShareGroup;
}
#endif /* __APPLE__ */
class gl_buffer : public memory_object
{
public:
gl_buffer(cl_mem mem, bool retain, hostbuf_t hostbuf=hostbuf_t())
: memory_object(mem, retain, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(hostbuf))
{ }
};
class gl_renderbuffer : public memory_object
{
public:
gl_renderbuffer(cl_mem mem, bool retain, hostbuf_t hostbuf=hostbuf_t())
: memory_object(mem, retain, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(hostbuf))
{ }
};
class gl_texture : public image
{
public:
gl_texture(cl_mem mem, bool retain, hostbuf_t hostbuf=hostbuf_t())
: image(mem, retain, PYOPENCL_STD_MOVE_IF_NEW_BUF_INTF(hostbuf))
{ }
py::object get_gl_texture_info(cl_gl_texture_info param_name)
{
switch (param_name)
{
case CL_GL_TEXTURE_TARGET:
PYOPENCL_GET_INTEGRAL_INFO(GLTexture, data(), param_name, GLenum);
case CL_GL_MIPMAP_LEVEL:
PYOPENCL_GET_INTEGRAL_INFO(GLTexture, data(), param_name, GLint);
default:
throw error("MemoryObject.get_gl_texture_info", CL_INVALID_VALUE);
}
}
};
#define PYOPENCL_WRAP_BUFFER_CREATOR(TYPE, NAME, CL_NAME, ARGS, CL_ARGS) \
inline \
TYPE *NAME ARGS \
{ \
cl_int status_code; \
PYOPENCL_PRINT_CALL_TRACE(#CL_NAME); \
cl_mem mem = CL_NAME CL_ARGS; \
\
if (status_code != CL_SUCCESS) \
throw pyopencl::error(#CL_NAME, status_code); \
\
try \
{ \
return new TYPE(mem, false); \
} \
catch (...) \
{ \
PYOPENCL_CALL_GUARDED(clReleaseMemObject, (mem)); \
throw; \
} \
}
PYOPENCL_WRAP_BUFFER_CREATOR(gl_buffer,
create_from_gl_buffer, clCreateFromGLBuffer,
(context &ctx, cl_mem_flags flags, GLuint bufobj),
(ctx.data(), flags, bufobj, &status_code));
PYOPENCL_WRAP_BUFFER_CREATOR(gl_texture,
create_from_gl_texture_2d, clCreateFromGLTexture2D,
(context &ctx, cl_mem_flags flags,
GLenum texture_target, GLint miplevel, GLuint texture),
(ctx.data(), flags, texture_target, miplevel, texture, &status_code));
PYOPENCL_WRAP_BUFFER_CREATOR(gl_texture,
create_from_gl_texture_3d, clCreateFromGLTexture3D,
(context &ctx, cl_mem_flags flags,
GLenum texture_target, GLint miplevel, GLuint texture),
(ctx.data(), flags, texture_target, miplevel, texture, &status_code));
PYOPENCL_WRAP_BUFFER_CREATOR(gl_renderbuffer,
create_from_gl_renderbuffer, clCreateFromGLRenderbuffer,
(context &ctx, cl_mem_flags flags, GLuint renderbuffer),
(ctx.data(), flags, renderbuffer, &status_code));
inline
gl_texture *create_from_gl_texture(
context &ctx, cl_mem_flags flags,
GLenum texture_target, GLint miplevel,
GLuint texture, unsigned dims)
{
if (dims == 2)
return create_from_gl_texture_2d(ctx, flags, texture_target, miplevel, texture);
else if (dims == 3)
return create_from_gl_texture_3d(ctx, flags, texture_target, miplevel, texture);
else
throw pyopencl::error("Image", CL_INVALID_VALUE,
"invalid dimension");
}
inline
py::tuple get_gl_object_info(memory_object_holder const &mem)
{
cl_gl_object_type otype;
GLuint gl_name;
PYOPENCL_CALL_GUARDED(clGetGLObjectInfo, (mem.data(), &otype, &gl_name));
return py::make_tuple(otype, gl_name);
}
#define WRAP_GL_ENQUEUE(what, What) \
inline \
event *enqueue_##what##_gl_objects( \
command_queue &cq, \
py::object py_mem_objects, \
py::object py_wait_for) \
{ \
PYOPENCL_PARSE_WAIT_FOR; \
\
std::vector<cl_mem> mem_objects; \
for (py::handle mo: py_mem_objects) \
mem_objects.push_back((mo).cast<memory_object_holder &>().data()); \
\
cl_event evt; \
PYOPENCL_CALL_GUARDED(clEnqueue##What##GLObjects, ( \
cq.data(), \
mem_objects.size(), mem_objects.empty( ) ? nullptr : &mem_objects.front(), \
PYOPENCL_WAITLIST_ARGS, &evt \
)); \
\
PYOPENCL_RETURN_NEW_EVENT(evt); \
}
WRAP_GL_ENQUEUE(acquire, Acquire);
WRAP_GL_ENQUEUE(release, Release);
#endif
#if defined(cl_khr_gl_sharing) && (cl_khr_gl_sharing >= 1)
inline
py::object get_gl_context_info_khr(
py::object py_properties,
cl_gl_context_info param_name,
py::object py_platform
)
{
std::vector<cl_context_properties> props
= parse_context_properties(py_properties);
typedef CL_API_ENTRY cl_int (CL_API_CALL
*func_ptr_type)(const cl_context_properties * /* properties */,
cl_gl_context_info /* param_name */,
size_t /* param_value_size */,
void * /* param_value */,
size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0;
func_ptr_type func_ptr;
#if PYOPENCL_CL_VERSION >= 0x1020
if (py_platform.ptr() != Py_None)
{
platform &plat = (py_platform).cast<platform &>();
func_ptr = (func_ptr_type) clGetExtensionFunctionAddressForPlatform(
plat.data(), "clGetGLContextInfoKHR");
}
else
{
PYOPENCL_DEPRECATED("get_gl_context_info_khr with platform=None", "2013.1", );
func_ptr = (func_ptr_type) clGetExtensionFunctionAddress(
"clGetGLContextInfoKHR");
}
#else
func_ptr = (func_ptr_type) clGetExtensionFunctionAddress(
"clGetGLContextInfoKHR");
#endif
if (!func_ptr)
throw error("Context.get_info", CL_INVALID_PLATFORM,
"clGetGLContextInfoKHR extension function not present");
cl_context_properties *props_ptr
= props.empty( ) ? nullptr : &props.front();
switch (param_name)
{
case CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR:
{
cl_device_id param_value;
PYOPENCL_CALL_GUARDED(func_ptr,
(props_ptr, param_name, sizeof(param_value), ¶m_value, 0));
return py::object(handle_from_new_ptr( \
new device(param_value, /*retain*/ true)));
}
case CL_DEVICES_FOR_GL_CONTEXT_KHR:
{
size_t size;
PYOPENCL_CALL_GUARDED(func_ptr,
(props_ptr, param_name, 0, 0, &size));
std::vector<cl_device_id> devices;
devices.resize(size / sizeof(devices.front()));
PYOPENCL_CALL_GUARDED(func_ptr,
(props_ptr, param_name, size,
devices.empty( ) ? nullptr : &devices.front(), &size));
py::list result;
for (cl_device_id did: devices)
result.append(handle_from_new_ptr(
new device(did)));
return result;
}
default:
throw error("get_gl_context_info_khr", CL_INVALID_VALUE);
}
}
#endif
// }}}
// {{{ deferred implementation bits
inline program *error::get_program() const
{
return new program(m_program, /* retain */ true);
}
inline py::object create_mem_object_wrapper(cl_mem mem, bool retain=true)
{
cl_mem_object_type mem_obj_type;
PYOPENCL_CALL_GUARDED(clGetMemObjectInfo, \
(mem, CL_MEM_TYPE, sizeof(mem_obj_type), &mem_obj_type, 0));
switch (mem_obj_type)
{
case CL_MEM_OBJECT_BUFFER:
return py::object(handle_from_new_ptr(
new buffer(mem, retain)));
case CL_MEM_OBJECT_IMAGE2D:
case CL_MEM_OBJECT_IMAGE3D:
#if PYOPENCL_CL_VERSION >= 0x1020
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
case CL_MEM_OBJECT_IMAGE1D:
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
case CL_MEM_OBJECT_IMAGE1D_BUFFER:
#endif
return py::object(handle_from_new_ptr(
new image(mem, retain)));
default:
return py::object(handle_from_new_ptr(
new memory_object(mem, retain)));
}
}
inline
py::object memory_object_from_int(intptr_t cl_mem_as_int, bool retain)
{
return create_mem_object_wrapper((cl_mem) cl_mem_as_int, retain);
}
inline
py::object memory_object_holder::get_info(cl_mem_info param_name) const
{
switch (param_name)
{
case CL_MEM_TYPE:
PYOPENCL_GET_INTEGRAL_INFO(MemObject, data(), param_name,
cl_mem_object_type);
case CL_MEM_FLAGS:
PYOPENCL_GET_INTEGRAL_INFO(MemObject, data(), param_name,
cl_mem_flags);
case CL_MEM_SIZE:
PYOPENCL_GET_INTEGRAL_INFO(MemObject, data(), param_name,
size_t);
case CL_MEM_HOST_PTR:
throw pyopencl::error("MemoryObject.get_info", CL_INVALID_VALUE,
"Use MemoryObject.get_host_array to get host pointer.");
case CL_MEM_MAP_COUNT:
PYOPENCL_GET_INTEGRAL_INFO(MemObject, data(), param_name,
cl_uint);
case CL_MEM_REFERENCE_COUNT:
PYOPENCL_GET_INTEGRAL_INFO(MemObject, data(), param_name,
cl_uint);
case CL_MEM_CONTEXT:
PYOPENCL_GET_OPAQUE_INFO(MemObject, data(), param_name,
cl_context, context);
#if PYOPENCL_CL_VERSION >= 0x1010
case CL_MEM_ASSOCIATED_MEMOBJECT:
{
cl_mem param_value;
PYOPENCL_CALL_GUARDED(clGetMemObjectInfo, \
(data(), param_name, sizeof(param_value), ¶m_value, 0));
if (param_value == 0)
{
// no associated memory object? no problem.
return py::none();
}
return create_mem_object_wrapper(param_value);
}
case CL_MEM_OFFSET:
PYOPENCL_GET_INTEGRAL_INFO(MemObject, data(), param_name,
size_t);
#endif
default:
throw error("MemoryObjectHolder.get_info", CL_INVALID_VALUE);
}
}
// FIXME: Reenable in pypy
#ifndef PYPY_VERSION
inline
py::object get_mem_obj_host_array(
py::object mem_obj_py,
py::object shape, py::object dtype,
py::object order_py)
{
memory_object_holder const &mem_obj =
(mem_obj_py).cast<memory_object_holder const &>();
PyArray_Descr *tp_descr;
if (PyArray_DescrConverter(dtype.ptr(), &tp_descr) != NPY_SUCCEED)
throw py::error_already_set();
cl_mem_flags mem_flags;
PYOPENCL_CALL_GUARDED(clGetMemObjectInfo,
(mem_obj.data(), CL_MEM_FLAGS, sizeof(mem_flags), &mem_flags, 0));
if (!(mem_flags & CL_MEM_USE_HOST_PTR))
throw pyopencl::error("MemoryObject.get_host_array", CL_INVALID_VALUE,
"Only MemoryObject with USE_HOST_PTR "
"is supported.");
std::vector<npy_intp> dims;
try
{
dims.push_back(py::cast<npy_intp>(shape));
}
catch (py::cast_error &)
{
for (auto it: shape)
dims.push_back(it.cast<npy_intp>());
}
NPY_ORDER order = PyArray_CORDER;
PyArray_OrderConverter(order_py.ptr(), &order);
int ary_flags = 0;
if (order == PyArray_FORTRANORDER)
ary_flags |= NPY_FARRAY;
else if (order == PyArray_CORDER)
ary_flags |= NPY_CARRAY;
else
throw std::runtime_error("unrecognized order specifier");
void *host_ptr;
size_t mem_obj_size;
PYOPENCL_CALL_GUARDED(clGetMemObjectInfo,
(mem_obj.data(), CL_MEM_HOST_PTR, sizeof(host_ptr),
&host_ptr, 0));
PYOPENCL_CALL_GUARDED(clGetMemObjectInfo,
(mem_obj.data(), CL_MEM_SIZE, sizeof(mem_obj_size),
&mem_obj_size, 0));
py::object result = py::reinterpret_steal<py::object>(PyArray_NewFromDescr(
&PyArray_Type, tp_descr,
dims.size(), &dims.front(), /*strides*/ nullptr,
host_ptr, ary_flags, /*obj*/nullptr));
if ((size_t) PyArray_NBYTES(result.ptr()) > mem_obj_size)
throw pyopencl::error("MemoryObject.get_host_array",
CL_INVALID_VALUE,
"Resulting array is larger than memory object.");
PyArray_BASE(result.ptr()) = mem_obj_py.ptr();
Py_INCREF(mem_obj_py.ptr());
return result;
}
#endif
// }}}
}
#endif
// vim: foldmethod=marker
|
/**
* Test for the KalmanFilter class with 1D projectile motion.
*
* @author: Hayk Martirosyan
* @date: 2014.11.15
*/
#include <iostream>
#include <iomanip>
#include <vector>
#include <Eigen/Dense>
#include "kalman.hpp"
// to remove
//************************************************************************************
#define COLUMN_WIDTH 20
int random_sign(double probability)
{
int result = 1;
if( (double) rand() / RAND_MAX < probability )
{
result *= -1;
}
return result;
}
// probability -> that the number will be negative
double random_float(double truth, double range, double probability=0)
{
double result = truth + (double) rand() / RAND_MAX * range * random_sign(0.5);
result *= random_sign(probability);
return result;
}
//************************************************************************************
int main(int argc, char* argv[]) {
int n = 3; // Number of states
int m = 1; // Number of measurements
double dt = 1.0/30; // Time step
Eigen::MatrixXd A(n, n); // System dynamics matrix
Eigen::MatrixXd C(m, n); // Output matrix
Eigen::MatrixXd Q(n, n); // Process noise covariance
Eigen::MatrixXd R(m, m); // Measurement noise covariance
Eigen::MatrixXd P(n, n); // Estimate error covariance
// Discrete LTI projectile motion, measuring position only
A << 0.1, dt, 0, 0, 1, dt, 0, 0, 1;
// A << 0.1, dt, 0, 0, 1, dt, 0, 0, 1;
// A << 0.01, dt, 0, 0, 1, dt, 0, 0, 1;
C << 1, 0, 0;
// Reasonable covariance matrices
Q << .1, .1, .0, .1, .1, .0, .0, .0, .0;
// Q << .01, .01, .0, .01, .01, .0, .0, .0, .0;
R << 15;
// R << 0.5;
// P << .1, .1, .1, .1, 10000, 10, .1, 10, 100;
P << 1, 1, 1, 1, 100, 1000, 10, 100, 10000;
/*
std::cout << "A: \n" << A << std::endl;
std::cout << "C: \n" << C << std::endl;
std::cout << "Q: \n" << Q << std::endl;
std::cout << "R: \n" << R << std::endl;
std::cout << "P: \n" << P << std::endl;
*/
// Construct the filter
KalmanFilter kf(dt,A, C, Q, R, P);
/*
// List of noisy position measurements (y)
std::vector<double> measurements = {
1.04202710058, 1.10726790452, 1.2913511148, 1.48485250951, 1.72825901034,
1.74216489744, 2.11672039768, 2.14529225112, 2.16029641405, 2.21269371128,
2.57709350237, 2.6682215744, 2.51641839428, 2.76034056782, 2.88131780617,
2.88373786518, 2.9448468727, 2.82866600131, 3.0006601946, 3.12920591669,
2.858361783, 2.83808170354, 2.68975330958, 2.66533185589, 2.81613499531,
2.81003612051, 2.88321849354, 2.69789264832, 2.4342229249, 2.23464791825,
2.30278776224, 2.02069770395, 1.94393985809, 1.82498398739, 1.52526230354,
1.86967808173, 1.18073207847, 1.10729605087, 0.916168349913, 0.678547664519,
0.562381751596, 0.355468474885, -0.155607486619, -0.287198661013, -0.602973173813
};
*/
// Best guess of initial states
Eigen::VectorXd x0(n);
double t = 0;
// x0 << 20, 0, -9.81;
x0 << 0, 0, 0;
// x0 << measurements[0], 0, -9.81;
kf.init(t, x0);
// Feed measurements into filter, output estimated states
double initial_position = 20;
double velocity = 1;
Eigen::VectorXd y(m);
std::cout << "Time,Measurement,Estimate"
<< ",velocity,acceleration"
<< std::endl;
for(double time = 0; time < 20; time += 0.01)
{
// dt = random_float(1.0/30, 0.1);
dt = 0.1;
t += dt;
double true_position = initial_position - velocity*time;
double measured_position = random_float(true_position, 1, 0.1);
Eigen::MatrixXd A_temp(n, n); // System dynamics matrix
y << measured_position;
kf.update(y);
// kf.update(y, dt, A_temp);
std::cout << t
<< ","
<< y.transpose()
<< ","
<< kf.state().transpose()[0]
<< ","
<< kf.state().transpose()[1]
<< ","
<< kf.state().transpose()[2]
<< std::endl;
}
return 0;
}
|
HelpString:
db 'TEST_PPU_READ_BUFFER -- Secret Reference Emulation Mode',13,10
db 'Commandline options:',13,10
db ' /D',9,'Do disassembly trace (note: does not set /T automatically)',13,10
db ' /T',9,'Text only: Do not do graphics mode',13,10
db ' /P',9,'Palette only: No NTSC simulation, no borders, no correct aspect ratio',13,10
db ' /M',9,'Mode-X only: Do not use VESA to provide NTSC in RGB32 without dithering',13,10
db ' /H,/?',9,'This help',13,10
db 10
db "The assembler trace, and the test ROM's console output, will",13,10
db 'both be output to STDOUT. Suggest redirecting with "> file.txt".',13,10
db 10
db 'I.e. like this: program /D /T > trace.log', 13,10
db 10
db 'If you do not redirect the output, there will be minor artifacts on the',13,10
db 'screen while the test runs; this is because the text is rendered on the',13,10
db 'graphical screen, but the BIOS does not support the Mode-X graphics used.',13,10
db 10
db 'Thank you for using this self-testing NES emulator.',13,10
db 'Written in April 2012 by Joel Yliluoma - http://iki.fi/bisqwit/',13,10
db 10
db 'P.S. Load any sub-40k NROM/CNROM/GxROM cart with :filename',13,10
db 0
|
// Copyright (c) 2006 Xiaogang Zhang
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_MATH_BESSEL_I0_HPP
#define BOOST_MATH_BESSEL_I0_HPP
#include <boost/math/tools/rational.hpp>
#include <boost/assert.hpp>
// Modified Bessel function of the first kind of order zero
// minimax rational approximations on intervals, see
// Blair and Edwards, Chalk River Report AECL-4928, 1974
namespace boost { namespace math { namespace detail{
template <typename T>
T bessel_i0(T x)
{
static const T P1[] = {
static_cast<T>(-2.2335582639474375249e+15L),
static_cast<T>(-5.5050369673018427753e+14L),
static_cast<T>(-3.2940087627407749166e+13L),
static_cast<T>(-8.4925101247114157499e+11L),
static_cast<T>(-1.1912746104985237192e+10L),
static_cast<T>(-1.0313066708737980747e+08L),
static_cast<T>(-5.9545626019847898221e+05L),
static_cast<T>(-2.4125195876041896775e+03L),
static_cast<T>(-7.0935347449210549190e+00L),
static_cast<T>(-1.5453977791786851041e-02L),
static_cast<T>(-2.5172644670688975051e-05L),
static_cast<T>(-3.0517226450451067446e-08L),
static_cast<T>(-2.6843448573468483278e-11L),
static_cast<T>(-1.5982226675653184646e-14L),
static_cast<T>(-5.2487866627945699800e-18L),
};
static const T Q1[] = {
static_cast<T>(-2.2335582639474375245e+15L),
static_cast<T>(7.8858692566751002988e+12L),
static_cast<T>(-1.2207067397808979846e+10L),
static_cast<T>(1.0377081058062166144e+07L),
static_cast<T>(-4.8527560179962773045e+03L),
static_cast<T>(1.0L),
};
static const T P2[] = {
static_cast<T>(-2.2210262233306573296e-04L),
static_cast<T>(1.3067392038106924055e-02L),
static_cast<T>(-4.4700805721174453923e-01L),
static_cast<T>(5.5674518371240761397e+00L),
static_cast<T>(-2.3517945679239481621e+01L),
static_cast<T>(3.1611322818701131207e+01L),
static_cast<T>(-9.6090021968656180000e+00L),
};
static const T Q2[] = {
static_cast<T>(-5.5194330231005480228e-04L),
static_cast<T>(3.2547697594819615062e-02L),
static_cast<T>(-1.1151759188741312645e+00L),
static_cast<T>(1.3982595353892851542e+01L),
static_cast<T>(-6.0228002066743340583e+01L),
static_cast<T>(8.5539563258012929600e+01L),
static_cast<T>(-3.1446690275135491500e+01L),
static_cast<T>(1.0L),
};
T value, factor, r;
BOOST_MATH_STD_USING
using namespace boost::math::tools;
if (x < 0)
{
x = -x; // even function
}
if (x == 0)
{
return static_cast<T>(1);
}
if (x <= 15) // x in (0, 15]
{
T y = x * x;
value = evaluate_polynomial(P1, y) / evaluate_polynomial(Q1, y);
}
else // x in (15, \infty)
{
T y = 1 / x - T(1) / 15;
r = evaluate_polynomial(P2, y) / evaluate_polynomial(Q2, y);
factor = exp(x) / sqrt(x);
value = factor * r;
}
return value;
}
}}} // namespaces
#endif // BOOST_MATH_BESSEL_I0_HPP
|
; A208253: Number of n X 3 0..2 arrays with new values 0..2 introduced in row major order and no element equal to more than one of its immediate leftward or upward neighbors.
; Submitted by Christian Krause
; 5,96,2040,43344,920928,19566912,415737216,8833148160,187677464064,3987573838848,84723785029632,1800122089230336,38247105402593280,812634365429366784,17266002353004576768,366849901919230820352,7794441804575004819456,165608121269942412902400,3518667599065533006741504,74760957239122647541874688,1588442377675649717813379072,33749556993038331431224344576,717075175804032896001921515520,15235660955800110409142683828224,323711338214737902665108299972608,6877878865431432092086099658145792
seq $0,184688 ; 1/3 the number of n X 3 0..2 arrays with no element equal both to the element above and to the element to its left.
sub $0,1
div $0,2
add $0,1
|
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include "sdk_stores.h"
#include "telemetry_data.h"
#include "memory_structure.h"
#include "memory.h"
fmod_manager* fmod_manager_instance = nullptr;
telemetry_data_t telemetry_data;
scs_log_t scs_log;
uintptr_t economy_base_offset = NULL;
uintptr_t game_base = NULL;
DWORD image_size = 0;
uint32_t stored_engine_state = 0;
byte indicator_stick_state = false;
bool was_indicator_light_on = false;
bool was_park_brake_on = false;
uint32_t prev_retarder_level = 0;
bool high_beams_enabled = false;
bool wipers_enabled = false;
float hazard_warning_state = 0.0f;
float light_horn_state = 0.0f;
float light_stick_state = 0.0f;
float wipers_stick_state = 0.0f;
scs_telemetry_register_for_channel_t register_for_channel = nullptr;
scs_telemetry_unregister_from_channel_t unregister_from_channel = nullptr;
#define register_channel(name, index, type, field) register_for_channel(SCS_TELEMETRY_##name, index, SCS_VALUE_TYPE_##type, SCS_TELEMETRY_CHANNEL_FLAG_no_value, telemetry_store_##type, &telemetry_data.field);
SCSAPI_VOID telemetry_pause(const scs_event_t event, const void* const event_info, scs_context_t context)
{
fmod_manager_instance->set_paused(event == SCS_TELEMETRY_EVENT_paused);
}
bool should_engine_brake_sound_play()
{
return telemetry_data.engine_brake && telemetry_data.effective_throttle < 0.05f && telemetry_data.gear != 0 && telemetry_data.effective_clutch < 0.05f;
}
SCSAPI_VOID telemetry_tick(const scs_event_t event, const void* const event_info, scs_context_t context)
{
fmod_manager_instance->set_event_parameter("engine/engine", "rpm", telemetry_data.rpm);
fmod_manager_instance->set_event_parameter("engine/exhaust", "rpm", telemetry_data.rpm);
fmod_manager_instance->set_event_parameter("engine/engine", "load", telemetry_data.effective_throttle); // The game might use some other value, but this seems close enough
fmod_manager_instance->set_event_parameter("engine/exhaust", "load", telemetry_data.effective_throttle);
if (reinterpret_cast<economy_base_t*>(economy_base_offset) != nullptr && economy_base_offset != NULL)
{
auto* const economy_base = reinterpret_cast<economy_base_t*>(economy_base_offset);
auto* const some_truck_telem_parent = economy_base->get_truck_telem_parent();
if (some_truck_telem_parent != nullptr)
{
auto* const truck_telem_data = some_truck_telem_parent->get_truck_telem_data();
if (truck_telem_data != nullptr)
{
const auto turbo_pressure = truck_telem_data->get_turbo_pressure();
if (turbo_pressure >= 0 && turbo_pressure <= 1)
{
fmod_manager_instance->set_event_parameter("engine/turbo", "turbo", turbo_pressure);
}
const auto engine_state = truck_telem_data->get_engine_state();
if (engine_state != stored_engine_state) // engine state changed TODO: Find start_bad
{
if (engine_state > 0 && stored_engine_state == 0) { // engine is starting/running
fmod_manager_instance->set_event_parameter("engine/engine", "play", 1);
fmod_manager_instance->set_event_parameter("engine/exhaust", "play", 1);
fmod_manager_instance->set_event_state("engine/engine", true);
fmod_manager_instance->set_event_state("engine/exhaust", true);
fmod_manager_instance->set_event_parameter("engine/turbo", "play", 1);
fmod_manager_instance->set_event_state("engine/turbo", true);
}
else if (engine_state == 0 || engine_state == 3) // engine is no longer running
{
fmod_manager_instance->set_event_parameter("engine/engine", "play", 0);
fmod_manager_instance->set_event_parameter("engine/exhaust", "play", 0);
fmod_manager_instance->set_event_parameter("engine/turbo", "play", 0);
}
stored_engine_state = engine_state;
}
fmod_manager_instance->set_event_parameter("engine/engine", "brake", should_engine_brake_sound_play() ? truck_telem_data->get_engine_brake_state() : 0.0f);
const auto hazard_warning = truck_telem_data->get_hazard_warning_state();
if (!common::cmpf(hazard_warning, hazard_warning_state))
{
fmod_manager_instance->set_event_state("interior/stick_hazard_warning", true);
hazard_warning_state = hazard_warning;
}
const auto light_horn = truck_telem_data->get_light_horn_state();
if (!common::cmpf(light_horn, light_horn_state))
{
fmod_manager_instance->set_event_state("interior/stick_light_horn", true);
light_horn_state = light_horn;
}
const auto stick_lights = truck_telem_data->get_light_switch_state();
if (!common::cmpf(stick_lights, light_stick_state))
{
fmod_manager_instance->set_event_state("interior/stick_lights", true);
light_stick_state = stick_lights;
}
const auto wipers_stick = truck_telem_data->get_wipers_state();
if (!common::cmpf(wipers_stick, wipers_stick_state))
{
fmod_manager_instance->set_event_state("interior/stick_wipers", true);
wipers_stick_state = wipers_stick;
}
}
}
auto* const unk_interior_parent = economy_base->get_unk_interior_parent();
if (unk_interior_parent != nullptr)
{
const auto window_pos = unk_interior_parent->get_window_state();
if (window_pos.x >= 0 && window_pos.x <= 1) fmod_manager_instance->set_global_parameter("wnd_left", window_pos.x);
if (window_pos.y >= 0 && window_pos.y <= 1) fmod_manager_instance->set_global_parameter("wnd_right", window_pos.y);
if (common::cmpf(window_pos.x, 0) && common::cmpf(window_pos.y, 0) && unk_interior_parent->get_is_camera_inside())
{
fmod_manager_instance->set_bus_volume("outside", fmod_manager_instance->sound_levels.windows_closed);
fmod_manager_instance->set_bus_volume("exterior", fmod_manager_instance->sound_levels.windows_closed); // backward compatibility
}
else
{
fmod_manager_instance->set_bus_volume("outside", 1);
fmod_manager_instance->set_bus_volume("exterior", 1); // backward compatibility
}
if (unk_interior_parent->get_is_on_interior_cam())
{
fmod_manager_instance->set_bus_volume("cabin/interior", fmod_manager_instance->sound_levels.interior);
}
else
{
fmod_manager_instance->set_bus_volume("cabin/interior", 0);
}
auto* const unk_cabin = unk_interior_parent->get_unk_cabin();
if (unk_cabin != nullptr)
{
fmod_manager_instance->set_global_parameter("cabin_out", unk_cabin->get_cabin_out());
}
fmod_manager_instance->set_global_parameter("cabin_rot", unk_interior_parent->get_camera_rotation_in_cabin());
fmod_manager_instance->set_global_parameter("surr_type", unk_interior_parent->get_has_echo());
}
}
#pragma region interior
if (telemetry_data.brake_air_pressure_warning && telemetry_data.engine_enabled)
{
fmod_manager_instance->set_event_state("interior/air_warning", true, true);
}
if ((telemetry_data.light_lblinker || telemetry_data.light_rblinker) && !was_indicator_light_on)
{
fmod_manager_instance->set_event_state("interior/blinker_on", true);
was_indicator_light_on = true;
}
else if (!telemetry_data.light_lblinker && !telemetry_data.light_rblinker && was_indicator_light_on)
{
fmod_manager_instance->set_event_state("interior/blinker_off", true);
was_indicator_light_on = false;
}
if (telemetry_data.park_brake_on != was_park_brake_on)
{
if (was_park_brake_on) fmod_manager_instance->set_event_state("interior/stick_park_brake_off", true);
else fmod_manager_instance->set_event_state("interior/stick_park_brake", true);
was_park_brake_on = telemetry_data.park_brake_on;
}
const byte current_blinker_stick = telemetry_data.lblinker ? 1 : telemetry_data.rblinker ? 2 : 0; // 1 if lblinker, 2 if rblinker, 0 if off
if (current_blinker_stick != indicator_stick_state && current_blinker_stick != 0)
{
fmod_manager_instance->set_event_state("interior/stick_blinker", true);
indicator_stick_state = current_blinker_stick;
}
else if (current_blinker_stick == 0 && indicator_stick_state != 0)
{
fmod_manager_instance->set_event_state("interior/stick_blinker_off", true);
indicator_stick_state = 0;
}
if (telemetry_data.retarder_level != prev_retarder_level)
{
fmod_manager_instance->set_event_state("interior/stick_retarder", true);
prev_retarder_level = telemetry_data.retarder_level;
}
if (telemetry_data.high_beam != high_beams_enabled)
{
fmod_manager_instance->set_event_state("interior/stick_high_beam", true);
high_beams_enabled = telemetry_data.high_beam;
}
#pragma endregion
fmod_manager_instance->update();
}
void register_telem_channels()
{
register_channel(TRUCK_CHANNEL_engine_rpm, SCS_U32_NIL, float, rpm)
register_channel(TRUCK_CHANNEL_effective_throttle, SCS_U32_NIL, float, effective_throttle)
register_channel(TRUCK_CHANNEL_effective_clutch, SCS_U32_NIL, float, effective_clutch)
register_channel(TRUCK_CHANNEL_motor_brake, SCS_U32_NIL, bool, engine_brake)
register_channel(TRUCK_CHANNEL_brake_air_pressure_warning, SCS_U32_NIL, bool, brake_air_pressure_warning)
register_channel(TRUCK_CHANNEL_engine_enabled, SCS_U32_NIL, bool, engine_enabled)
register_channel(TRUCK_CHANNEL_lblinker, SCS_U32_NIL, bool, lblinker)
register_channel(TRUCK_CHANNEL_rblinker, SCS_U32_NIL, bool, rblinker)
register_channel(TRUCK_CHANNEL_light_lblinker, SCS_U32_NIL, bool, light_lblinker)
register_channel(TRUCK_CHANNEL_light_rblinker, SCS_U32_NIL, bool, light_rblinker)
register_channel(TRUCK_CHANNEL_head_offset, SCS_U32_NIL, fplacement, head_offset)
register_channel(TRUCK_CHANNEL_parking_brake, SCS_U32_NIL, bool, park_brake_on)
register_channel(TRUCK_CHANNEL_retarder_level, SCS_U32_NIL, u32, retarder_level)
register_channel(TRUCK_CHANNEL_light_high_beam, SCS_U32_NIL, bool, high_beam)
register_channel(TRUCK_CHANNEL_wipers, SCS_U32_NIL, bool, wipers)
register_channel(TRUCK_CHANNEL_engine_gear, SCS_U32_NIL, s32, gear)
}
SCSAPI_RESULT scs_telemetry_init(const scs_u32_t version, const scs_telemetry_init_params_t* const params)
{
const auto* const version_params = reinterpret_cast<const scs_telemetry_init_params_v101_t*>(params);
scs_log = version_params->common.log;
scs_log(0, "[ts-fmod-plugin V1.43] Searching for economy offset... If this is one of the last messages in the log after a crash, try disabling this plugin.");
auto addr = pattern::scan("48 8B 05 ? ? ? ? 48 8B D9 8B 90 ? ? ? ? 48 8B 80 ? ? ? ? 48 8B 88 ? ? ? ? E8", game_base, image_size);
economy_base_offset = addr + *reinterpret_cast<uint32_t*>(addr + 3) + 7 - 0x48;
std::stringstream ss;
ss << "[ts-fmod-plugin] Found economy offset &" << std::hex << (economy_base_offset - game_base);
scs_log(0, ss.str().c_str());
const auto events_registered =
(version_params->register_for_event(SCS_TELEMETRY_EVENT_paused, telemetry_pause, nullptr) == SCS_RESULT_ok) &&
(version_params->register_for_event(SCS_TELEMETRY_EVENT_started, telemetry_pause, nullptr) == SCS_RESULT_ok) &&
(version_params->register_for_event(SCS_TELEMETRY_EVENT_frame_end, telemetry_tick, nullptr) == SCS_RESULT_ok);
if (!events_registered)
{
version_params->common.log(SCS_LOG_TYPE_error, "[ts-fmod-plugin] Unable to register event callbacks");
return SCS_RESULT_generic_error;
}
register_for_channel = version_params->register_for_channel;
fmod_manager_instance = new fmod_manager(scs_log);
if (!fmod_manager_instance->init())
{
scs_log(SCS_LOG_TYPE_error, "[ts-fmod-plugin] Could not init fmod");
return SCS_RESULT_generic_error;
}
if (economy_base_offset == NULL)
{
version_params->common.log(SCS_LOG_TYPE_error, "[ts-fmod-plugin] Unable to find economy base");
return SCS_RESULT_generic_error;
}
register_telem_channels();
scs_log(0, "[ts-fmod-plugin] Plugin loaded");
return SCS_RESULT_ok;
}
void shutdown()
{
if (fmod_manager_instance != nullptr)
{
delete fmod_manager_instance;
fmod_manager_instance = nullptr;
}
}
SCSAPI_VOID scs_telemetry_shutdown(void)
{
shutdown();
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
game_base = reinterpret_cast<uintptr_t>(GetModuleHandleA(NULL));
const auto* const header = reinterpret_cast<const IMAGE_DOS_HEADER*>(game_base);
const auto* const nt_header = reinterpret_cast<const IMAGE_NT_HEADERS64*>(reinterpret_cast<const uint8_t*>(header) + header->e_lfanew);
image_size = nt_header->OptionalHeader.SizeOfImage;
}
return TRUE;
}
|
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
#include <QFileDialog>
#include <QKeyEvent>
#include <QMessageBox>
#include <QPixmap>
#include <QRegularExpression>
#include "controller/PolygonController.hpp"
#include "controller/RectController.hpp"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), fileMenu(nullptr), viewMenu(nullptr),
currentImage(nullptr) {
initUI();
}
MainWindow::~MainWindow() {}
void MainWindow::initUI() {
this->resize(800, 600);
// setup menubar
fileMenu = menuBar()->addMenu("&File");
viewMenu = menuBar()->addMenu("&View");
// setup toolbar
fileToolBar = addToolBar("File");
viewToolBar = addToolBar("View");
// main area for image display
imageScene = new QGraphicsScene(this);
imageView = new QGraphicsView(imageScene);
setCentralWidget(imageView);
// setup status bar
mainStatusBar = statusBar();
mainStatusLabel = new QLabel(mainStatusBar);
mainStatusBar->addPermanentWidget(mainStatusLabel);
mainStatusLabel->setText("Image Information will be here!");
createActions();
}
void MainWindow::createActions() {
// create actions, add them to menus
openAction = new QAction("&Open", this);
fileMenu->addAction(openAction);
saveAsAction = new QAction("&Save as", this);
fileMenu->addAction(saveAsAction);
exitAction = new QAction("E&xit", this);
fileMenu->addAction(exitAction);
prevAction = new QAction("&Previous Image", this);
viewMenu->addAction(prevAction);
nextAction = new QAction("&Next Image", this);
viewMenu->addAction(nextAction);
zoomInAction = new QAction("Zoom in", this);
viewMenu->addAction(zoomInAction);
zoomOutAction = new QAction("Zoom Out", this);
viewMenu->addAction(zoomOutAction);
rectAction = new QAction("&Select Rectangle", this);
viewMenu->addAction(rectAction);
polygonAction = new QAction("&Select Polygon", this);
viewMenu->addAction(polygonAction);
// add actions to toolbars
fileToolBar->addAction(openAction);
viewToolBar->addAction(prevAction);
viewToolBar->addAction(nextAction);
viewToolBar->addAction(zoomInAction);
viewToolBar->addAction(zoomOutAction);
viewToolBar->addAction(rectAction);
viewToolBar->addAction(polygonAction);
// connect the signals and slots
connect(exitAction, SIGNAL(triggered(bool)), QApplication::instance(), SLOT(quit()));
connect(openAction, SIGNAL(triggered(bool)), this, SLOT(openImage()));
connect(saveAsAction, SIGNAL(triggered(bool)), this, SLOT(saveAs()));
connect(zoomInAction, SIGNAL(triggered(bool)), this, SLOT(zoomIn()));
connect(zoomOutAction, SIGNAL(triggered(bool)), this, SLOT(zoomOut()));
connect(prevAction, SIGNAL(triggered(bool)), this, SLOT(prevImage()));
connect(nextAction, SIGNAL(triggered(bool)), this, SLOT(nextImage()));
connect(rectAction, SIGNAL(triggered(bool)), this, SLOT(rectROI()));
connect(polygonAction, SIGNAL(triggered(bool)), this, SLOT(polygonROI()));
setupShortcuts();
}
void MainWindow::openImage() {
QFileDialog dialog(this);
dialog.setWindowTitle("Open Image");
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilter(tr("Images (*.png *.bmp *.jpg)"));
QStringList filePaths;
if (dialog.exec()) {
filePaths = dialog.selectedFiles();
showImage(filePaths.at(0));
}
}
void MainWindow::showImage(QString path) {
imageScene->clear();
imageView->resetTransform();
QPixmap image(path);
currentImage = imageScene->addPixmap(image);
imageScene->update();
imageView->setSceneRect(image.rect());
QString status = QString("%1, %2x%3, %4 Bytes").arg(path).arg(image.width()).arg(image.height()).arg(
QFile(path).size());
mainStatusLabel->setText(status);
currentImagePath = path;
}
void MainWindow::zoomIn() {
imageView->scale(1.2, 1.2);
}
void MainWindow::zoomOut() {
imageView->scale(1 / 1.2, 1 / 1.2);
}
void MainWindow::prevImage() {
QFileInfo current(currentImagePath);
QDir dir = current.absoluteDir();
QStringList nameFilters;
nameFilters << "*.png"
<< "*.bmp"
<< "*.jpg";
QStringList fileNames = dir.entryList(nameFilters, QDir::Files, QDir::Name);
if (fileNames.size()) {
int idx = fileNames.indexOf(current.fileName());
--idx;
if (idx < 0) {
idx += fileNames.size();
}
showImage(dir.absoluteFilePath(fileNames.at(idx)));
} else {
QMessageBox::information(this, "Information", "No image files.");
}
}
void MainWindow::nextImage() {
QFileInfo current(currentImagePath);
QDir dir = current.absoluteDir();
QStringList nameFilters;
nameFilters << "*.png"
<< "*.bmp"
<< "*.jpg";
QStringList fileNames = dir.entryList(nameFilters, QDir::Files, QDir::Name);
if (fileNames.size()) {
int idx = fileNames.indexOf(current.fileName());
++idx;
if (idx >= fileNames.size()) {
idx -= fileNames.size();
}
showImage(dir.absoluteFilePath(fileNames.at(idx)));
} else {
QMessageBox::information(this, "Information", "No image files.");
}
}
void MainWindow::saveAs() {
if (currentImage == nullptr) {
QMessageBox::information(this, "Information", "Nothing to save.");
return;
}
QFileDialog dialog(this);
dialog.setWindowTitle("Save Image As ...");
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setNameFilter(tr("Images (*.png *.bmp *.jpg)"));
QStringList fileNames;
if (dialog.exec()) {
fileNames = dialog.selectedFiles();
QString pattern(".+\\.(png|bmp|jpg)");
QRegularExpression re(QRegularExpression::anchoredPattern(pattern));
QRegularExpressionMatch match = re.match(fileNames.at(0));
if (match.hasMatch()) {
currentImage->pixmap().save(fileNames.at(0));
} else {
QMessageBox::information(this, "Information", "Save error: bad format or filename.");
}
}
}
void MainWindow::rectROI() {
QFileInfo current(currentImagePath);
QDir dir = current.absoluteDir();
std::string filename = dir.absoluteFilePath(current.fileName()).toStdString();
rect::Controller controller;
std::string log_file_name = QDir::currentPath().toStdString() + "/" + "glcm-analysis.csv";
controller.Run(filename, 1, 256, log_file_name);
}
void MainWindow::polygonROI() {
QFileInfo current(currentImagePath);
QDir dir = current.absoluteDir();
std::string filename = dir.absoluteFilePath(current.fileName()).toStdString();
polygon::Controller controller;
std::string log_file_name = QDir::currentPath().toStdString() + "/" + "glcm-analysis.csv";
controller.Run(filename, 1, 256, log_file_name);
}
void MainWindow::setupShortcuts() {
QList<QKeySequence> shortcuts;
shortcuts << Qt::Key_Plus << Qt::Key_Equal;
zoomInAction->setShortcuts(shortcuts);
shortcuts.clear();
shortcuts << Qt::Key_Minus << Qt::Key_Underscore;
zoomOutAction->setShortcuts(shortcuts);
shortcuts.clear();
shortcuts << Qt::Key_Up << Qt::Key_Left;
prevAction->setShortcuts(shortcuts);
shortcuts.clear();
shortcuts << Qt::Key_Down << Qt::Key_Right;
nextAction->setShortcuts(shortcuts);
shortcuts.clear();
shortcuts << QKeySequence(Qt::CTRL | Qt::Key_R);
rectAction->setShortcuts(shortcuts);
shortcuts.clear();
shortcuts << QKeySequence(Qt::CTRL | Qt::Key_P);
polygonAction->setShortcuts(shortcuts);
}
|
; void *heap_alloc_fixed(void *heap, void *p, size_t size)
INCLUDE "clib_cfg.asm"
SECTION code_alloc_malloc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IF __CLIB_OPT_MULTITHREAD & $01
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC heap_alloc_fixed
EXTERN asm_heap_alloc_fixed
heap_alloc_fixed:
pop af
pop hl
pop bc
pop de
push de
push bc
push hl
push af
jp asm_heap_alloc_fixed
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ELSE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC heap_alloc_fixed
EXTERN heap_alloc_fixed_unlocked
defc heap_alloc_fixed = heap_alloc_fixed_unlocked
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ENDIF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
; A189479: Fixed point starting with 0 of the morphism 0->01, 1->101.
; 0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1
mov $4,2
mov $6,$0
lpb $4
mov $0,$6
sub $4,1
add $0,$4
sub $0,1
mov $2,$0
mul $2,$0
lpb $2
sub $2,$0
add $0,2
trn $2,1
lpe
mov $3,$4
mov $5,$0
lpb $3
mov $1,$5
sub $3,1
lpe
lpe
lpb $6
sub $1,$5
mov $6,0
lpe
div $1,2
|
//=================================================================================================
/*!
// \file src/mathtest/smatdmatsub/SCaLDb.cpp
// \brief Source file for the SCaLDb sparse matrix/dense matrix subtraction math test
//
// Copyright (C) 2012-2018 Klaus Iglberger - All Rights Reserved
//
// This file is part of the Blaze library. You can redistribute it and/or modify it under
// the terms of the New (Revised) BSD License. Redistribution and use in source and binary
// forms, with or without modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
// 3. Neither the names of the Blaze development group nor the names of its contributors
// may be used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
*/
//=================================================================================================
//*************************************************************************************************
// Includes
//*************************************************************************************************
#include <cstdlib>
#include <iostream>
#include <blaze/math/CompressedMatrix.h>
#include <blaze/math/DynamicMatrix.h>
#include <blaze/math/LowerMatrix.h>
#include <blaze/math/SymmetricMatrix.h>
#include <blazetest/mathtest/Creator.h>
#include <blazetest/mathtest/smatdmatsub/OperationTest.h>
#include <blazetest/system/MathTest.h>
//=================================================================================================
//
// MAIN FUNCTION
//
//=================================================================================================
//*************************************************************************************************
int main()
{
std::cout << " Running 'SCaLDb'..." << std::endl;
using blazetest::mathtest::TypeA;
using blazetest::mathtest::TypeB;
try
{
// Matrix type definitions
typedef blaze::SymmetricMatrix< blaze::CompressedMatrix<TypeA> > SCa;
typedef blaze::LowerMatrix< blaze::DynamicMatrix<TypeB> > LDb;
// Creator type definitions
typedef blazetest::Creator<SCa> CSCa;
typedef blazetest::Creator<LDb> CLDb;
// Running tests with small matrices
for( size_t i=0UL; i<=6UL; ++i ) {
for( size_t j=0UL; j<=i*i; ++j ) {
RUN_SMATDMATSUB_OPERATION_TEST( CSCa( i, j ), CLDb( i ) );
}
}
// Running tests with large matrices
RUN_SMATDMATSUB_OPERATION_TEST( CSCa( 67UL, 7UL ), CLDb( 67UL ) );
RUN_SMATDMATSUB_OPERATION_TEST( CSCa( 128UL, 16UL ), CLDb( 128UL ) );
}
catch( std::exception& ex ) {
std::cerr << "\n\n ERROR DETECTED during sparse matrix/dense matrix subtraction:\n"
<< ex.what() << "\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
//*************************************************************************************************
|
; A070346: a(n) = 3^n mod 37.
; 1,3,9,27,7,21,26,4,12,36,34,28,10,30,16,11,33,25,1,3,9,27,7,21,26,4,12,36,34,28,10,30,16,11,33,25,1,3,9,27,7,21,26,4,12,36,34,28,10,30,16,11,33,25,1,3,9,27,7,21,26,4,12,36,34,28,10,30,16,11,33,25,1,3,9,27,7,21,26,4,12,36,34,28,10,30,16,11,33,25,1,3,9,27,7,21,26,4,12,36,34,28,10,30,16,11,33,25,1,3,9,27,7,21,26,4,12,36,34,28,10,30,16,11,33,25,1,3,9,27,7,21,26,4,12,36,34,28,10,30,16,11,33,25,1,3,9,27,7,21,26,4,12,36,34,28,10,30,16,11,33,25,1,3,9,27,7,21,26,4,12,36,34,28,10,30,16,11,33,25,1,3,9,27,7,21,26,4,12,36,34,28,10,30,16,11,33,25,1,3,9,27,7,21,26,4,12,36,34,28,10,30,16,11,33,25,1,3,9,27,7,21,26,4,12,36,34,28,10,30,16,11,33,25,1,3,9,27,7,21,26,4,12,36,34,28,10,30,16,11
mov $1,1
mov $2,$0
lpb $2,1
mul $1,3
mod $1,37
sub $2,1
lpe
|
; A021122: Decimal expansion of 1/118.
; Submitted by Jon Maiga
; 0,0,8,4,7,4,5,7,6,2,7,1,1,8,6,4,4,0,6,7,7,9,6,6,1,0,1,6,9,4,9,1,5,2,5,4,2,3,7,2,8,8,1,3,5,5,9,3,2,2,0,3,3,8,9,8,3,0,5,0,8,4,7,4,5,7,6,2,7,1,1,8,6,4,4,0,6,7,7,9,6,6,1,0,1,6,9,4,9,1,5,2,5,4,2,3,7,2,8
seq $0,42 ; Unary representation of natural numbers.
mul $0,9
div $0,118
mod $0,10
|
[bits 64]
section .text
initialize_sse:
mov eax, 1
cpuid
bt edx, 25
jnc .no_sse
mov rax, cr0
btr eax, 2
bts eax, 1
mov cr0, rax
mov rax, cr4
bts eax, 9
bts eax, 10
mov cr4, rax
ret
.no_sse:
ret
initialize_osxsave:
mov eax, 1
cpuid
bt ecx, 26
jnc .no_osxsave
mov rax, cr4
bts rax, 18 ; Set OSXSAVE bit for access to xgetbv and xsetbv and possibly xsave, xsaveopt and xrestor
mov cr4, rax
ret
.no_osxsave:
ret
initialize_efer:
mov ecx, 0xC0000080 ; IA32_EFER
rdmsr
bts eax, 0 ; Set SCE for the syscall and sysret instructions
bts eax, 11 ; Set NXE for No-Execute-Support
; LME and thus LMA are already set by the bootloader
wrmsr
ret
initialize_cr0:
mov rax, cr0
bts rax, 16 ; Set Write Protect bit so the CPU will enfore the Writable paging bit in kernel mode
mov cr0, rax
ret
initialize_cr4:
xor rax, rax
mov eax, 1
cpuid
bt edx, 13
jnc .no_pge
mov rax, cr4
bts rax, 7 ; Set Page Global Enable
mov cr4, rax
.no_pge:
ret
global _kernel_early
_kernel_early:
cld
cli
mov rsp, bsp_stack_top
and rsp, ~8 ; Make sure rsp + 8 is 16 byte aligned as mandated by the SysV ABI
mov rbp, 0 ; Set to zero to provide stack trace stop
call initialize_sse
call initialize_osxsave
call initialize_efer
call initialize_cr0
call initialize_cr4
extern _init
call _init
extern kernel_main
call kernel_main
extern _fini
call _fini
cli
hlt
global _smp_kernel_early
_smp_kernel_early:
cli
cld
mov rax, qword [trampoline_paging]
mov cr3, rax
mov rsp, qword [trampoline_stack]
and rsp, ~0xF ; Align stack for ABI requirements
mov rbp, 0 ; Set to zero to provide stack trace stop
mov byte [trampoline_booted], 1
call initialize_sse
call initialize_osxsave
call initialize_efer
call initialize_cr0
call initialize_cr4
extern smp_kernel_main
call smp_kernel_main
cli
hlt
section .data
global trampoline_stack
trampoline_stack: dq 0
global trampoline_paging
trampoline_paging: dq 0
global trampoline_booted
trampoline_booted: db 0
section .bss
align 16
bsp_stack_bottom:
resb 0x8000
bsp_stack_top: |
; function formatInteger (var buffer : array of char; i : integer;
; width, flags, base : byte) : byte
; ----------------------------------------------------------------
; This procedure formats an integer for printing.
;
section .code
global _formatInteger
;CHAR_SPACEPAD equ ' '
;FLAG_LEFTALIGN equ 00h
;FLAG_ZEROPAD equ 02h
;FLAG_UPPERCASE equ 40h
CHAR_MINUS equ '-'
_formatInteger:
push rbp
mov rbp, rsp
push rdi
push rsi
push rbx
mov rdx, 0
mov r8, 0
mov ax, si
and ax, 0x8000
jz prepare
not si
inc si
mov byte [rdi], CHAR_MINUS
inc rdi
prepare:
mov ax, 10000
mov cx, 0
mov bx, 0
digit:
cmp si, ax
jb mWriteDigit
inc bx
sub si, ax
jmp digit
mWriteDigit:
cmp bx, 0
jne writeDigit
cmp r8, 0
je nextDigit
writeDigit:
call near writeDigitToMemory
nextDigit:
mov bx, 10
div bx
cmp ax, 0
je finish
mov bx, 0
cmp ax, 1
jne digit
mov r8, 1
jmp digit
finish:
mov byte [rdi], 0x0
pop rbx
pop rsi
pop rdi
pop rbp
mov ax, cx ;return number of characters written
and rax, 0xff
ret
writeDigitToMemory:
push rbp
mov rbp, rsp
mov r8, 1
add bl, 0x30
mov byte [rdi], bl
inc rdi
inc cx
mov bx, 0
pop rbp
ret
|
;------------------------------------------------------------------------------
;
; Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
; SPDX-License-Identifier: BSD-2-Clause-Patent
;
; Module Name:
;
; InterlockedCompareExchange32.Asm
;
; Abstract:
;
; InterlockedCompareExchange32 function
;
; Notes:
;
;------------------------------------------------------------------------------
SECTION .text
;------------------------------------------------------------------------------
; UINT32
; EFIAPI
; InternalSyncCompareExchange32 (
; IN volatile UINT32 *Value,
; IN UINT32 CompareValue,
; IN UINT32 ExchangeValue
; );
;------------------------------------------------------------------------------
global ASM_PFX(InternalSyncCompareExchange32)
ASM_PFX(InternalSyncCompareExchange32):
mov ecx, [esp + 4]
mov eax, [esp + 8]
mov edx, [esp + 12]
lock cmpxchg [ecx], edx
ret
|
#################################################################################################
# Disclaimer: #
#################################################################################################
# Made by: Giovanni Sullutrone #
# Date: 8 march 2020 #
#################################################################################################
#################################################################################################
# .data #
#################################################################################################
# precision: number of factors in of taylor's approximation #
# array: values to compute (can be any number of floats) #
# size_of_array: size of the array to compute #
#################################################################################################
.data
precision: .word 20 #Can be changed
one: .word 1
neg_one: .word -1
zero.s: .float 0.0
one.s: .float 1.0
e.s: .float 2.71828182846
array: .float 0.5, 1.0, 1.5 #Can be changed
size_of_array: .word 3 #Can be changed
nl: .asciiz "\n"
.text
#################################################################################################
# functions #
#################################################################################################
# factorial: ($a0) => ($v0) #
# factorial_minus_1: ($a0) => ($f0) #
# pow.s: ($f1, $a0) => ($f0) #
# centered_pow.s: ($f1, $f2, $a0) => ($f0) #
# taylor_of_exp.s: ($f1) => ($f0) #
# sigmoid.s: ($f1) => ($f0) #
# sigmoid_array.s: ($a0, $a1, $a2) #
# print_array.s: ($a0, $a1) #
#################################################################################################
#################################################################################################
# Heap Map #
#################################################################################################
# 4 * precision - bytes for coefficients of taylor series #
# #
# To store array to computer allocate double that amount #
# 4 * (size of array * 2) #
#################################################################################################
#################################################################################################
# s registers map #
#################################################################################################
# $s0 => Heap pointer #
# $s1 => int one #
# $s2 => precision const #
# $s3 => size of array #
# $s4 => int neg one #
#################################################################################################
#################################################################################################
# f registers map #
#################################################################################################
# $f0 => results #
# $f1 => first paramater #
# $f2 => second parameter #
# $f28 => -one #
# $f29 => zero #
# $f30 => one #
# $f31 => e #
# $f14 to $f26 => temp values #
#################################################################################################
main:
#Allocate memory and generate coeff
jal alloc_constants
jal alloc_heap_memory
jal alloc_array
jal alloc_taylor_coeff
#Print taylor coeffs
addi $a0, $s0, 0
addi $a1, $s2, 0
jal print_array.s
#Print array to compute
jal get_address_of_first_array
addi $a0, $v0, 0
addi $a1, $s3, 0
jal print_array.s
#Calculate sigmoid of array
jal get_address_of_first_array
addi $a0, $v0, 0
jal get_address_of_second_array
addi $a1, $v0, 0
addi $a2, $s3, 0
jal sigmoid_array.s
#Print sigmoid_array result
jal get_address_of_second_array
addi $a0, $v0, 0
addi $a1, $s3, 0
jal print_array.s
li $v0, 10
syscall
#################################################################################################
# alloc_constants #
#################################################################################################
# Allocate in registers the previously defined constants as specified in s/f registers map #
# #
# Parameters: #
# #
# Returns: #
# #
#################################################################################################
alloc_constants:
#s registers
lw $s1, one
lw $s2, precision
lw $s3, size_of_array
lw $s4, neg_one
#f registers
l.s $f29, zero.s
l.s $f30, one.s
l.s $f31, e.s
jr $ra
#################################################################################################
# alloc_heap_memory #
#################################################################################################
# Allocate in Heap taylor coefficients and array to compute as specified in Heap Map #
# #
# Parameters: #
# #
# Returns: #
# #
#################################################################################################
alloc_heap_memory:
#Get precision + size_of_array + size_of_array
add $t0, $s2, $s3
addi $t0, $s3, 0
#Allocate $t0 * 4 bytes
sll $t0, $t0, 2
addi $s0, $gp, 0
add $gp, $gp, $t0
jr $ra
#################################################################################################
# alloc_array #
#################################################################################################
# Allocate in the Heap the array to compute from the .data as specified in the Heap Map #
# #
# Parameters: #
# #
# Returns: #
# #
#################################################################################################
alloc_array:
#Save size_of_array in $t0
lw $t0, size_of_array
#Create counter_loop
li $t1, 0
#Create counter_array_data
li $t2, 0
#Create counter_array_heap
li $t3, 0
#Starting position of array_data
la $t4, array
#Starting position of array_heap
#precision * 4 + $s0
addi $t5, $s2, 0
sll $t5, $t5, 2
add $t5, $t5, $s0
alloc_array_loop:
#If counter_loop == size_of_array
beq $t1, $t0, alloc_array_loop_end
#Else:
#Get current position in the array_data
addi $t2, $t1, 0
sll $t2, $t2, 2
add $t2, $t2, $t4
#Get current position in the array_heap
addi $t3, $t1, 0
sll $t3, $t3, 2
add $t3, $t3, $t5
#Load the value of the array_data into $f15
l.s $f15, 0($t2)
#Store the value of $f15 into current array_heap position
s.s $f15, 0($t3)
#Increment counter_loop and recall loop
addi $t1, $t1, 1
j alloc_array_loop
alloc_array_loop_end:
jr $ra
#################################################################################################
# get_address_of_first_array #
#################################################################################################
# Get address of the first array to compute as specified in the Heap Map #
# #
# Parameters: #
# #
# Returns: #
# $v0: the address of the first array #
#################################################################################################
get_address_of_first_array:
#Load the allocated heap starting position in $v0
addi $v0, $s0, 0
#Get offset caused by taylor coeffs
addi $t0, $s2, 0
sll $t0, $t0, 2
#Add offset to base address
add $v0, $v0, $t0
jr $ra
#################################################################################################
# get_address_of_second_array #
#################################################################################################
# Get address of the second array to compute as specified in the Heap Map #
# #
# Parameters: #
# #
# Returns: #
# $v0: the address of the second array #
#################################################################################################
get_address_of_second_array:
#Store the current $ra in stack
addi $sp, $sp, -4
sw $ra, 0($sp)
#Get address of first array
jal get_address_of_first_array
#Calculate offset caused by the first array size
addi $t0, $s3, 0
sll $t0, $t0, 2
#Add the offset
add $v0, $v0, $t0
#Load the old $ra and return
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
#################################################################################################
# alloc_taylor_coeff #
#################################################################################################
# Takes the precision const and allocates in heap (precision) taylor coefficients #
# #
# Parameters: #
# #
# Returns: #
# #
#################################################################################################
alloc_taylor_coeff:
#TODO: Should add error checking
#Store the current $ra in stack
addi $sp, $sp, -4
sw $ra, 0($sp)
#Save precision in $t7
addi $t7, $s2, 0
#Create counter_loop
li $t8, 0
#Create counter_array
li $t9, 0
alloc_taylor_coeff_loop:
#If counter_loop == precision
beq $t8, $t7, alloc_taylor_coeff_loop_end
#Else:
#Get current position in the heap
addi $t9, $t8, 0
sll $t9, $t9, 2
add $t9, $t9, $s0
#Get factorial of counter_loop
#Set the param
addi $a0, $t8, 0
#Call the function
jal factorial_minus_1
#Store the float from $f0 to heap
#Move $f0 to $t0
mfc1 $t0, $f0
#Store $t0
sw $t0, 0($t9)
#Increment counter and recall loop
addi $t8, $t8, 1
j alloc_taylor_coeff_loop
alloc_taylor_coeff_loop_end:
#Load the old $ra and return
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
#################################################################################################
# factorial #
#################################################################################################
# Takes an integer and computes n! #
# #
# Parameters: #
# $a0: an integer #
# #
# Returns: #
# $v0: n! #
#################################################################################################
factorial:
#If $a0 is equal to zero => 1
beq $a0, $zero, factorial_return_1
#Else:
#Load the putput with 1
li $v0, 1
#Create counter_loop
li $t0, 1
factorial_loop:
#If the counter is greater than $a0
bgt $t0, $a0, factorial_loop_end
#Else:
#Multiply $vo with the counter
mul $v0, $v0, $t0
#Increase the counter_loop
addi $t0, $t0, 1
j factorial_loop
factorial_loop_end:
jr $ra
factorial_return_1:
li $v0, 1
jr $ra
#################################################################################################
# factorial_minus_1 #
#################################################################################################
# Takes an integer and computes 1/(n!) #
# #
# Parameters: #
# $a0: an integer #
# #
# Returns: #
# $f0: 1/(n!) #
#################################################################################################
factorial_minus_1:
#Store this function's $ra in stack
addi $sp, $sp, -4
sw $ra, 0($sp)
#Get factorial of n
jal factorial
#Store the factorial from $v0
addi $t0, $v0, 0
#Move $t0 to $f15 of the coproc1
mtc1 $t0, $f15
#Convert it to float
cvt.s.w $f15, $f15
#In $f0 save (1.0 / $f15)
div.s $f0, $f30, $f15
#Load the old $ra and return
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
#################################################################################################
# pow.s #
#################################################################################################
# Take a float and an integer and return (float) ^ (int) #
# #
# Parameters: #
# $f1: a single percision float #
# $a0: an integer #
# #
# Returns: #
# $f0: ($f1)^$a0 #
#################################################################################################
pow.s:
#If $a0 == 0
beq $a0, $zero, pow.s_return_1
#Else if $a0 < 0:
blt $a0, $zero, pow.s_neg
#Create a counter_loop
li $t0, 2
#Assign $f1 to $f0
add.s $f0, $f1, $f29
pow.s_loop:
#If counter_loop > $a0:
bgt $t0, $a0, pow.s_loop_end
#Else:
#Mul $f0 by $f0 and store it in $f0
mul.s $f0, $f0, $f0
#Increment counter_loop and recall loop
addi $t0, $t0, 1
j pow.s_loop
pow.s_loop_end:
jr $ra
pow.s_return_1:
l.s $f0, one.s
jr $ra
pow.s_neg:
#Store this function's $ra in stack
addi $sp, $sp, -4
sw $ra, 0($sp)
#Change sign of $a0
mul $a0, $a0, $s4
#Recall pow.s with the new $a0
jal pow.s
#Divide 1 by the result of pow.s
div.s $f0, $f30, $f0
#Load the old $ra and return
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
#################################################################################################
# centered_pow.s #
#################################################################################################
# Take two float (x, x0), one int and calculates (x - x0)^(int) #
# #
# Parameters: #
# $f1: a single precision float => x #
# $f2: a single precision float => center (x0) #
# $a0: an integer #
# #
# Returns: #
# $f0: ($f1 - $f2)^$a0 #
#################################################################################################
centered_pow.s:
#Store this function's $ra in stack
addi $sp, $sp, -4
sw $ra, 0($sp)
#Get ($f1 - $f2) ^ $a0
#Store $f1 - $f2 in $f1
sub.s $f1, $f1, $f2
#Get the new $f1 ^ $a0
jal pow.s
#The result is already in $f0 so:
#Load the old $ra and return
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
#################################################################################################
# taylor_of_exp.s #
#################################################################################################
# Takes one float (x) and returns an approximation of e^x #
# #
# Parameters: #
# $f1: a single precision float => x #
# #
# Returns: #
# $f0: e^($f1) #
# #
# or #
# $f0: taylor series with precision number of factors and centered around x0 #
# Where x0 = floor of x #
#################################################################################################
taylor_of_exp.s:
#Store $f1 inside $f15
add.s $f15, $f1, $f29
#Store floor of $f1 inside $f16 (x0)
floor.w.s $f16, $f1
#Store the integer to $t9
mfc1 $t9, $f16
#Convert it back to float
cvt.s.w $f16, $f16
#Objective: series of beta=0 to beta=precision - 1 of (alpha_of_beta) * e^(x0) * (x - x0)^(beta)
#Store this function's $ra in stack
addi $sp, $sp, -4
sw $ra, 0($sp)
#Get e^(x0) and store it inside $f17
add.s $f1, $f31, $f29
addi $a0, $t9, 0
jal pow.s
add.s $f17, $f0, $f29
#Save precision in %t7
addi $t7, $s2, 0
#Create counter_loop
li $t8, 0
#Create counter_array
li $t9, 0
#Set $f0 to 0
add.s $f0, $f29, $f29
taylor_of_exp.s_loop:
#If counter_loop == precision
beq $t8, $t7, taylor_of_exp.s_loop_end
#Else:
#Get current position in the heap
addi $t9, $t8, 0
sll $t9, $t9, 2
add $t9, $t9, $s0
#Store inside $f18 e^x0
add.s $f18, $f17, $f29
#Store the current taylor coeff inside $f20
l.s $f20, 0($t9)
#Mul $f20 by $f18 and store it inside $f18 (alpha * e^(x0))
mul.s $f18, $f20, $f18
#Store centered_pow.s inside $f19
#Set parameters
add.s $f1, $f15, $f29
add.s $f2, $f16, $f29
addi $a0, $t8, 0
#Get centered_pow.s
jal centered_pow.s
add.s $f20, $f0, $f29
#Mul $f20 by $f18 and store it inside $f18 (alpha_of_beta * e^(x0) * (x - x0)^(beta))
mul.s $f18, $f20, $f18
#Add $f18 to $f0 ($f0 = $f0 + beta order of approx)
add.s $f21, $f21, $f18
#Increment counter and recall loop
addi $t8, $t8, 1
j taylor_of_exp.s_loop
taylor_of_exp.s_loop_end:
#Move $f21 to $f0
add.s $f0, $f21, $f29
#Clear $f21
add.s $f21, $f29, $f29
#Load the old $ra and return
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
#################################################################################################
# sigmoid.s #
#################################################################################################
# Takes one float (x) and returns an approximation of the sigmoid(x) #
# #
# Parameters: #
# $f1: a single precision float #
# #
# Returns: #
# $f0: sigmoid($f1) #
#################################################################################################
sigmoid.s:
#Store this function's $ra in stack
addi $sp, $sp, -4
sw $ra, 0($sp)
#Change sign of $f1
neg.s $f1, $f1
#Get approximation of exp($f1) (i.e.: e^(-x)) and store it inside $f15
#The parameters are already in the right place
jal taylor_of_exp.s
add.s $f15, $f0, $f29
#Add 1.0 to $f15
add.s $f15, $f15, $f30
#Divide 1 / ($f15) (i.e.: 1/ (1 + e^(-x)))
div.s $f0, $f30, $f15
#Load the old $ra and return
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
#################################################################################################
# sigmoid_array.s #
#################################################################################################
# Takes the address of the array, the address of a second array of the same size, its size #
# and assign the sigmoid of the first array (element-wise) to the second array #
# #
# Parameters: #
# $a0: address first array #
# $a1: address of second array #
# $a2: size of array #
# #
# Returns: #
# #
#################################################################################################
sigmoid_array.s:
#Store this function's $ra in stack
addi $sp, $sp, -4
sw $ra, 0($sp)
#Save size_of_array in $t1
addi $t1, $a2, 0
#Create counter_loop
li $t2, 0
#Create counter_array
li $t3, 0
#Create counter_array_output
li $t4, 0
#Save starting position of the first array (source)
addi $t5, $a0, 0
#sll $t5, $t5, 2
#Save starting position of the second array (destination)
addi $t6, $a1, 0
#add $t6, $t6, $a2
#sll $t6, $t6, 2
sigmoid_array.s_loop:
#If counter_loop == size_of_array
beq $t2, $t1, sigmoid_array.s_loop_end
#Else:
#Get current position in the first array_heap
addi $t3, $t2, 0
sll $t3, $t3, 2
add $t3, $t3, $t5
#Get current position in the second array_heap
addi $t4, $t2, 0
sll $t4, $t4, 2
add $t4, $t4, $t6
#Get sigmoid of current element
#Get value from the array and store it inside $f1
l.s $f1, 0($t3)
jal sigmoid.s
#Store the result inside the second array
s.s $f0, 0($t4)
#Increment counter_loop and recall loop
addi $t2, $t2, 1
j sigmoid_array.s_loop
sigmoid_array.s_loop_end:
#Load the old $ra and return
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
#################################################################################################
# print_array.s #
#################################################################################################
# Takes the address of the array, its size and prints the stored values #
# #
# Parameters: #
# $a0: address of the array #
# $a1: size of the array #
# #
# Returns: #
# #
#################################################################################################
print_array.s:
#Save size_of_array in $t0
addi $t0, $a1, 0
#Create counter_loop
li $t1, 0
#Create counter_array
li $t2, 0
print_array.s_loop:
#If counter_loop == size_of_array
beq $t1, $t0, print_array.s_loop_end
#Else:
#Get current position in the heap
addi $t2, $t1, 0
sll $t2, $t2, 2
add $t2, $t2, $a0
#Set syscall instruction for float print
li $v0, 2
#Load the value to $f12
l.s $f12, 0($t2)
#Execute print
syscall
#Store the original $a0 in stack
addi $sp, $sp, -4
sw $a0, 0($sp)
#Print new-line
li $v0, 4
la $a0, nl
syscall
#Restore original $a0
lw $a0, 0($sp)
addi $sp, $sp, 4
#Increment counter_loop and recall loop
addi $t1, $t1, 1
j print_array.s_loop
print_array.s_loop_end:
jr $ra
|
.size 8000
.text@48
jp lstatint
.text@100
jp lbegin
.data@143
c0
.text@150
lbegin:
ld b, 98
call lwaitly_b
ld a, 01
ldff(45), a
ld a, 40
ldff(41), a
ld a, 00
ld(8000), a
ld a, 01
ld(c000), a
ld a, c0
ldff(51), a
xor a, a
ldff(52), a
ldff(54), a
ld a, 80
ldff(53), a
xor a, a
ldff(0f), a
ld a, 02
ldff(ff), a
ei
ld hl, 8000
ld a, 03
ldff(43), a
halt
.text@1000
lstatint:
ld a, 80
ldff(55), a
ld b, 03
.text@109a
ldff a, (41)
and a, b
jp lprint_a
.text@7000
lprint_a:
push af
ld b, 91
call lwaitly_b
xor a, a
ldff(40), a
pop af
ld(9800), a
ld bc, 7a00
ld hl, 8000
ld d, a0
lprint_copytiles:
ld a, (bc)
inc bc
ld(hl++), a
dec d
jrnz lprint_copytiles
ld a, c0
ldff(47), a
ld a, 80
ldff(68), a
ld a, ff
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
xor a, a
ldff(69), a
ldff(69), a
ldff(43), a
ld a, 91
ldff(40), a
lprint_limbo:
jr lprint_limbo
.text@7400
lwaitly_b:
ld c, 44
lwaitly_b_loop:
ldff a, (c)
cmp a, b
jrnz lwaitly_b_loop
ret
.data@7a00
00 00 7f 7f 41 41 41 41
41 41 41 41 41 41 7f 7f
00 00 08 08 08 08 08 08
08 08 08 08 08 08 08 08
00 00 7f 7f 01 01 01 01
7f 7f 40 40 40 40 7f 7f
00 00 7f 7f 01 01 01 01
3f 3f 01 01 01 01 7f 7f
00 00 41 41 41 41 41 41
7f 7f 01 01 01 01 01 01
00 00 7f 7f 40 40 40 40
7e 7e 01 01 01 01 7e 7e
00 00 7f 7f 40 40 40 40
7f 7f 41 41 41 41 7f 7f
00 00 7f 7f 01 01 02 02
04 04 08 08 10 10 10 10
00 00 3e 3e 41 41 41 41
3e 3e 41 41 41 41 3e 3e
00 00 7f 7f 41 41 41 41
7f 7f 01 01 01 01 7f 7f
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.