- 1
https://github.com/catboost/catboost
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
https://github.com/catboost/catboost
Похоже яндекс заопенсорсил свежую версию аркадии. Давайте обсирать эти их велосипеды.
0
void PPU::scanline() noexcept
{
if (control & CONTROL_MASK_BG_DISPLAY)
{
const int st = control & CONTROL_MASK_BG_WINDOW_TILE_DATA_SELECT ? 0x0000 : 0x0800;
const int sm = control & CONTROL_MASK_BG_TILE_MAP_DISPLAY_SELECT ? 0x1C00 : 0x1800;
for (int i = 0; i < 160; ++i)
{
const int im = sm + (scx + i) / 8 % 32 + (scy + ly) / 8 % 32 * 32;
const int vm = st == 0x0000 ? vram[im] :
(signed char) vram[im] + 128;
const unsigned px =
(vram[st + vm * 16 + (scy + ly) % 8 * 2 ] >> (7 - (scx + i) % 8) & 1) << 1 |
(vram[st + vm * 16 + (scy + ly) % 8 * 2 + 1] >> (7 - (scx + i) % 8) & 1);
framebuffer[(i + ly * 160) / 8 * 2] &= ~((px << 6) >> i % 8 * 2);
framebuffer[(i + ly * 160) / 8 * 2] |= (px << 6) >> i % 8 * 2;
framebuffer[(i + ly * 160) / 8 * 2 + 1] &= ~((px << 14) >> (i % 8 * 2));
framebuffer[(i + ly * 160) / 8 * 2 + 1] |= (px << 14) >> (i % 8 * 2);
}
}
...
0
#include <type_traits>
struct TPred1 {};
struct TPred2 {};
template<typename P1, typename P2> struct TAnd1: P1, P2 {TAnd1(P1, P2) {}};
template<typename P1, typename P2> struct TAnd2: P1, P2 {TAnd2(P1, P2) {}};
template<typename T, T v> struct my_integral_constant {enum {value=v};};
template<class T, class From> struct my_is_base_of:
my_integral_constant<bool, __is_base_of(T, From)> {};
template<typename P1, typename P2> std::enable_if_t<
my_is_base_of<TPred1, P1>::value &&
my_is_base_of<TPred1, P2>::value,
TAnd1<P1, P2>> operator&&(P1 p1, P2 p2)
{return {p1, p2};}
template<typename P1, typename P2> std::enable_if_t<
my_is_base_of<TPred2, P1>::value &&
my_is_base_of<TPred2, P2>::value,
TAnd2<P1, P2>> operator&&(P1 p1, P2 p2)
{return {(p1, p2};}
template<typename T> struct is_callable
{
template<typename T1> struct dummy;
template<typename CheckType> static short check(dummy<decltype(
std::declval<std::remove_reference_t<CheckType>>()())>*);
template<typename CheckType> static char check(...);
enum: bool {value = sizeof(check<T>(nullptr)) == sizeof(short)};
};
struct IntellisenseKiller
{
template<typename T, typename = std::enable_if_t<
std::is_function<T>::value &&
is_callable<T>::value
>> IntellisenseKiller(const T&) {}
IntellisenseKiller(bool) {}
};
IntellisenseKiller eat4GbRam = true;
Обнаружился ещё один способ превратить Visual Studio 2017 в тормозной, пожирающий 4 ГБ оперативы, блокнот с подсветкой синтаксиса.
Это минимальный пример, который я выделил из своей библиотеки и порезал всё, что не вызывает баг. Вроде бы не связанные между собой куски кода, но глюки студии вызывают только вместе. Целый день потратил на поиск причины глюка.
Случайно обнаружил, что длина получившегося фрагмента кода 42 строки. Я не подгонял, честно. Так что можно сказать, что ошибка в 42 строке. Без этой строки Intellisense заработает.
0
#include <algorithm>
#include <exception>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#define __CL_ENABLE_EXCEPTIONS
#include "cl.hpp"
using namespace std::string_literals;
int main(int argc, char * argv[]) {
size_t data_len = (1024 * 1024 * strtoul(argv[1], nullptr, 10)) / sizeof(uint32_t),
out_len = strtoul(argv[2], nullptr, 10),
iter = strtoul(argv[3], nullptr, 10),
block_size = strtoul(argv[4], nullptr, 10);
std::string src = R"(
typedef unsigned int uint32_t;
__kernel void bench(global const uint32_t * data, global uint32_t * out) {
uint32_t res = 0, id = get_global_id(0), next = id;
for(uint32_t i = 0; i < )"s + std::to_string(iter) + R"(; ++i) {
for(uint32_t j = 0; j < )" + std::to_string(block_size / sizeof(uint32_t)) + R"(; ++j)
res ^= data[next + j];
next = data[next];
}
out[id] = res;
}
)"s;
cl::Program::Sources sources = {{src.data(), src.size()}};
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
std::vector<uint32_t> data(data_len);
std::vector<uint32_t> out(out_len);
std::generate(std::begin(data), std::end(data), [=,gen = std::mt19937{}]() mutable {
return gen() % (data_len - (block_size / sizeof(uint32_t)));
});
for(auto & platform : platforms) {
std::cout << "Using platform: " << platform.getInfo<CL_PLATFORM_NAME>() << "\n";
std::vector<cl::Device> devices;
platform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
for(auto & device : devices) {
try {
std::cout << "Using device: " << device.getInfo<CL_DEVICE_NAME>() << "\n";
cl::Context ctx({device});
cl::Program program(ctx, sources);
program.build({device});
cl::Buffer data_buffer(ctx, CL_MEM_READ_WRITE, data.size() * sizeof(uint32_t));
cl::Buffer out_buffer(ctx, CL_MEM_READ_WRITE, out.size() * sizeof(uint32_t));
cl::CommandQueue queue(ctx, device);
queue.enqueueWriteBuffer(data_buffer, CL_TRUE, 0, data.size() * sizeof(uint32_t), data.data());
cl::make_kernel<cl::Buffer &, cl::Buffer &> bench(program, "bench");
cl::EnqueueArgs eargs(queue,cl::NullRange,cl::NDRange(out.size()),cl::NullRange);
auto start = std::chrono::high_resolution_clock::now();
bench(eargs, data_buffer, out_buffer).wait();
auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now() - start).count();
size_t ops = out_len * iter;
size_t total_tp = ops * block_size;
double miops = (ops / time) / (1000 * 1000);
double tpgbps = (total_tp / time) / (1024 * 1024 * 1024);
fprintf(stderr, "Result: %.2fMIOPS, %.2fGB/s, %.2fsec\n", miops, tpgbps, time);
queue.enqueueReadBuffer(out_buffer, CL_TRUE, 0, out.size() * sizeof(uint32_t), out.data());
} catch(cl::Error e) {
std::cout << e.what() << " : " << e.err() << std::endl;
std::terminate();
}
}
}
}
Код Царя
https://www.linux.org.ru/forum/development/13489159
https://github.com/superhackkiller1997/gpu_mem_benchmark/blob/master/main.cpp
0
int32 documentColorIndex(DocumentData *document, QString &ext) {
int32 colorIndex = 0;
QString name = document ? (document->name.isEmpty() ? (document->sticker() ? lang(lng_in_dlg_sticker) : qsl("Unknown File")) : document->name) : lang(lng_message_empty);
name = name.toLower();
int32 lastDot = name.lastIndexOf('.');
QString mime = document ? document->mime.toLower() : QString();
if (name.endsWith(qstr(".doc")) ||
name.endsWith(qstr(".txt")) ||
name.endsWith(qstr(".psd")) ||
mime.startsWith(qstr("text/"))
) {
colorIndex = 0;
} else if (
name.endsWith(qstr(".xls")) ||
name.endsWith(qstr(".csv"))
) {
colorIndex = 1;
} else if (
name.endsWith(qstr(".pdf")) ||
name.endsWith(qstr(".ppt")) ||
name.endsWith(qstr(".key"))
) {
colorIndex = 2;
} else if (
name.endsWith(qstr(".zip")) ||
name.endsWith(qstr(".rar")) ||
name.endsWith(qstr(".ai")) ||
name.endsWith(qstr(".mp3")) ||
name.endsWith(qstr(".mov")) ||
name.endsWith(qstr(".avi"))
) {
colorIndex = 3;
} else {
QChar ch = (lastDot >= 0 && lastDot + 1 < name.size()) ? name.at(lastDot + 1) : (name.isEmpty() ? (mime.isEmpty() ? '0' : mime.at(0)) : name.at(0));
colorIndex = (ch.unicode() % 4);
}
ext = document ? ((lastDot < 0 || lastDot + 2 > name.size()) ? name : name.mid(lastDot + 1)) : QString();
return colorIndex;
}
https://github.com/telegramdesktop/tdesktop/blob/5f5770dd46491133b135a71fc2d4f92d13107ade/Telegram/SourceFiles/layout.cpp#L170-L211+2
switch (address & 0xF000)
{
case 0x0000:
case 0x1000:
case 0x2000:
case 0x3000:
return rom[address];
case 0x4000:
case 0x5000:
case 0x6000:
case 0x7000:
return rom[address + 0x4000 * (bank_index - 1)];
case 0x8000:
case 0x9000:
return vram[address - 0x8000];
case 0xA000:
case 0xB000:
return sram[address - 0xA000];
case 0xC000:
case 0xD000:
return wram[address - 0xC000];
case 0xE000:
case 0xF000:
switch (address & 0x0F00)
{
case 0x0000:
case 0x0100:
case 0x0200:
case 0x0300:
case 0x0400:
case 0x0500:
case 0x0600:
case 0x0700:
case 0x0800:
case 0x0900:
case 0x0A00:
case 0x0B00:
case 0x0C00:
case 0x0D00:
return wram[address - 0xF000];
case 0x0E00:
switch (address & 0x00F0)
{
case 0x0000:
case 0x0010:
case 0x0020:
case 0x0030:
case 0x0040:
case 0x0050:
case 0x0060:
case 0x0070:
case 0x0080:
case 0x0090:
return oam[address - 0xFE00];
case 0x00A0:
case 0x00B0:
case 0x00C0:
case 0x00D0:
case 0x00E0:
case 0x00F0:
return 0b00;
}
case 0x0F00:
switch (address & 0x00F0)
{
case 0x0000:
case 0x0010:
case 0x0020:
case 0x0030:
case 0x0040:
case 0x0050:
case 0x0060:
case 0x0070:
return io_regs[address - 0xFF00];
case 0x0080:
case 0x0090:
case 0x00A0:
case 0x00B0:
case 0x00C0:
case 0x00D0:
case 0x00E0:
case 0x00F0:
switch (address & 0x000F)
{
case 0x0000:
case 0x0001:
case 0x0002:
case 0x0003:
case 0x0004:
case 0x0005:
case 0x0007:
case 0x0008:
case 0x0009:
case 0x000A:
case 0x000B:
case 0x000C:
case 0x000D:
case 0x000E:
return hram[address - 0xFF80];
case 0x000F:
0
#include <optional>
namespace aim {
template <typename T, template <typename> typename Cont>
struct is_valid {};
template <typename T, template <typename> typename Cont>
struct chain;
template <typename T, template <typename> typename Cont>
struct chain {
using value_type_t = T;
using holder_t = Cont<value_type_t>;
chain()
{}
chain(holder_t&& value_)
: value(std::move(value_))
{}
template <typename Func>
constexpr auto otherwise(Func&& func) {
return chain<T, Cont>{std::move(func())};
}
template <typename Func>
constexpr auto with(Func&& func) -> chain<value_type_t, Cont> {
if (bool(value)) {
return chain<value_type_t, Cont>{Cont<value_type_t>{func(*value)}};
}
else {
return chain<value_type_t, Cont>{};
}
}
holder_t value;
};
template <typename T, template <typename> typename Cont>
chain(Cont<T>&&) -> chain<T, Cont>;
template <typename T, template <typename> typename Cont>
struct use {
using value_type_t = T;
using holder_t = Cont<value_type_t>;
use(holder_t&& value)
: value(std::move(value))
{}
template <typename Func>
constexpr auto with(Func&& func) -> chain<value_type_t, Cont> {
if (is_valid<T, Cont>{}(value)) {
return chain<value_type_t, Cont>{Cont<value_type_t>{func(*value)}};
}
else {
return chain<value_type_t, Cont>{};
}
}
holder_t value;
};
template <typename T, template <typename> typename Cont>
use(Cont<T>&&) -> use<T, Cont>;
}
namespace aim {
template <typename T>
struct is_valid<T, std::optional> {
constexpr bool operator()(std::optional<T> const& value) {
return bool(value);
}
};
}
#include <iostream>
#include <memory>
int main() {
{
std::optional<int> a;
aim::use(std::move(a)).with([](auto v) {
std::cout << v << '\n';
return 1;
}).otherwise([](){
std::cout << "it's none!\n";
return 2;
}).with([](auto v){
std::cout << v << '\n';
return 3;
});
}
}
говно
0
#include <iostream>
#include <string>
int main()
{
std::cout << "Купи слона!" << std::endl;
while(true)
{
std::string temp;
std::getline(std::cin, temp);
std::printf("Все говорят: \"%s\", а ты купи слона!\n", temp.c_str());
}
}
Когда не любишь 1c.
0
void DrawLine(Vec2Si32 a, Vec2Si32 b, Rgba color_a, Rgba color_b) { // https://pastebin.com/p26FvZdd
Vec2Si32 ab = b - a;
Vec2Si32 abs_ab(std::abs(ab.x), std::abs(ab.y));
if (abs_ab.x >= abs_ab.y) {
if (a.x > b.x) {
DrawLine(b, a, color_b, color_a);
} else {
Sprite back = GetEngine()->GetBackbuffer();
Vec2Si32 back_size = back.Size();
if (ab.x == 0) {
if (a.x >= 0 && a.x < back_size.x &&
a.y >= 0 && a.y < back_size.y) {
back.RgbaData()[a.x + a.y * back.StridePixels()] = color_a;
}
return;
}
Si32 x1 = std::max(0, a.x);
Si32 x2 = std::min(back_size.x - 1, b.x);
Si32 y1 = a.y + ab.y * (x1 - a.x) / ab.x;
Si32 y2 = a.y + ab.y * (x2 - a.x) / ab.x;
if (y1 < 0) {
if (y2 < 0) {
return;
}
// lower left -> upper right
y1 = 0;
x1 = a.x + ab.x * (y1 - a.y) / ab.y;
x1 = std::max(0, x1);
} else if (y1 >= back_size.y) {
if (y2 >= back_size.y) {
return;
}
// upper left -> lower right
y1 = back_size.y - 1;
x1 = a.x + ab.x * (y1 - a.y) / ab.y;
x1 = std::max(0, x1);
}
if (y2 < 0) {
// upper left -> lower right
y2 = 0;
x2 = a.x + ab.x * (y2 - a.y) / ab.y;
x2 = std::min(back_size.x - 1, x2);
} else if (y2 >= back_size.y) {
// lower left -> upper right
y2 = back_size.y - 1;
x2 = a.x + ab.x * (y2 - a.y) / ab.y;
x2 = std::min(back_size.x - 1, x2);
}
Vec4Si32 rgba_a(static_cast<Si32>(color_a.r),static_cast<Si32>(color_a.g),static_cast<Si32>(color_a.b),static_cast<Si32>(color_a.a));
Vec4Si32 rgba_b(static_cast<Si32>(color_b.r),static_cast<Si32>(color_b.g),static_cast<Si32>(color_b.b),static_cast<Si32>(color_b.a));
Vec4Si32 rgba_ab = rgba_b - rgba_a;
Vec4Si32 rgba_1 = rgba_a + rgba_ab * (x1 - a.x) / ab.x;
Vec4Si32 rgba_2 = rgba_a + rgba_ab * (x2 - a.x) / ab.x;
Vec4Si32 rgba_12 = rgba_2 - rgba_1;
if (x2 <= x1) {
if (x2 == x1) {
Rgba color(rgba_1.x, rgba_1.y, rgba_1.z, rgba_1.w);
back.RgbaData()[x1 + y1 * back.StridePixels()] = color;
}
return;
}
Vec4Si32 rgba_16 = rgba_1 * 65536;
Vec4Si32 rgba_12_16 = rgba_12 * 65536;
Vec4Si32 rgba_12_16_step = rgba_12_16 / (x2 - x1);
Si32 y_16 = y1 * 65536;
Si32 y12_16_step = ((y2 - y1) * 65536) / (x2 - x1);
Si32 stride = back.StridePixels();
for (Si32 x = x1; x <= x2; ++x) {
Rgba color(rgba_16.x >> 16,rgba_16.y >> 16,rgba_16.z >> 16,rgba_16.w >> 16);
back.RgbaData()[x + (y_16 >> 16) * stride] = color;
rgba_16 += rgba_12_16_step;
y_16 += y12_16_step;
}
}
} else { // тут почти тоже самое
if (a.y > b.y) {
DrawLine(b, a, color_b, color_a);
} else {
Sprite back = GetEngine()->GetBackbuffer();
Vec2Si32 back_size = back.Size();
if (ab.y == 0) {
if (a.y >= 0 && a.y < back_size.y && a.x >= 0 && a.x < back_size.x) {
back.RgbaData()[a.x + a.y * back.StridePixels()] = color_a;
}
return;
}
Si32 y1 = std::max(0, a.y);
Si32 y2 = std::min(back_size.y - 1, b.y);
Si32 x1 = a.x + ab.x * (y1 - a.y) / ab.y;
Si32 x2 = a.x + ab.x * (y2 - a.y) / ab.y;
if (x1 < 0) {
if (x2 < 0) {
return;
}
// lower left -> upper right
x1 = 0;
y1 = a.y + ab.y * (x1 - a.x) / ab.x;
y1 = std::max(0, y1);
} else if (x1 >= back_size.x) {
if (x2 >= back_size.x) {
Взято отсюда https://github.com/FrostyMorning/arctic/blob/master/engine/easy.cpp
https://pastebin.com/p26FvZdd
−2
throw new runtime_error
https://github.com/search?l=C%2B%2B&q=%22throw+new+runtime_ error%22&type=Code&utf8=%E2%9C%93