Skip to content

Instantly share code, notes, and snippets.

Avatar

Danila Kutenin danlark1

  • London
View GitHub Profile
View median_3_killer.h
struct Median3Killer {
static std::vector<uint32_t> Gen(size_t size) {
size_t k = size / 2;
std::vector<uint32_t> v;
v.reserve(size);
for (size_t i = 1; i < k + 1; ++i) {
if (i & 1) {
v.push_back(i);
} else {
v.push_back(k + i - 1);
View inline.cpp
// Implicitly "inline"d
constexpr int foo() {
//...
}
// Implicitly "inline"d
template <class T>
int bar() {
//...
}
View inline.h
// inline.h
// With inline everything compiles, without it is a linkage error failure
/* inline */ int f(int x) {
return x + 42;
}
// TU1.cpp
#include "inline.h"
View tg_contest.proto
syntax = "proto3";
package tgnews_index;
message Doc {
bytes title = 1;
bytes url = 2;
string lang = 3;
string category = 4;
repeated float embed = 5;
View lock_free_queue.h
#include <cinttypes>
#include <atomic>
#include <memory>
#include <type_traits>
//start 00:20
// genius idea https://en.wikipedia.org/wiki/Tagged_pointer
template <class T>
View benchmark_int128.cc
// Installation.
// Abseil, compile with -labseil
// Libdivide as header.
// GMP as header, compile with -lgmp
// Change the private constructor of absl::uin128 to public in order to use public inheritance.
// GMOCK, GUNIT, compile it.
#include "absl/numeric/int128.h"
#include <random>
View gmp_div.h
struct GmpDiv {
uint64_t operator()(uint64_t u1, uint64_t u0, uint64_t v, du_int* r) const {
mp_limb_t q[2] = {u0, u1};
mp_limb_t result[2] = {0, 0};
*r = mpn_divrem_1(result, 0, q, 2, v);
return result[0];
}
};
View shift_subtract_branch_free.c
// dividend / divisor, remainder is stored in rem.
uint128 __udivmodti4(uint128 dividend, uint128 divisor, uint128* rem) {
if (divisor > dividend) {
if (rem)
*rem = dividend;
return 0;
}
// 64 bit divisor implementation
...
// end
View optimizing_all_64_bit.cpp
#if defined(__x86_64__)
inline uint64_t Divide128Div64To64(uint64_t high, uint64_t low,
uint64_t divisor, uint64_t* remainder) {
uint64_t result;
__asm__("divq %[v]"
: "=a"(result), "=d"(*remainder) // Ouput parametrs, =a for rax, =d for rdx, [v] is an
// alias for divisor, input paramters "a" and "d" for low and high.
: [v] "r"(divisor), "a"(low), "d"(high));
return result;
}
View optimizing_64_bit.cpp
#if defined(__x86_64__)
inline uint64_t Divide128Div64To64(uint64_t high, uint64_t low,
uint64_t divisor, uint64_t* remainder) {
uint64_t result;
__asm__("divq %[v]"
: "=a"(result), "=d"(*remainder) // Output parametrs, =a for rax, =d for rdx, [v] is an
// alias for divisor, input paramters "a" and "d" for low and high.
: [v] "r"(divisor), "a"(low), "d"(high));
return result;
}
You can’t perform that action at this time.