#include #include int suma1(int *begin, int *end) { int total = 0; asm("0: cmp %0,%2 \n" " je 1f \n" " add $4,%0 \n" // esto se " add -4(%0),%1 \n" // ve raro " jmp 0b \n" "1: \n" : "+r"(begin), "+r"(total) : "r"(end) : "cc"); return total; } int suma2(int *begin, int *end) { int total = 0; asm("0: cmp %0,%2 \n" " je 1f \n" " add (%0),%1 \n" // ahora no, " add $4,%0 \n" // verdad? " jmp 0b \n" "1: \n" : "+r"(begin), "+r"(total) : "r"(end) : "cc"); return total; } int main(int argc, char **) { const std::size_t N = 1'000'000, R = 100; int v[N], resultado = 0; std::random_device device; std::mt19937 generator(device()); std::bernoulli_distribution distribution; auto _5050 = [&]() { return distribution(generator); }; std::iota(v, v + N, argc); for (std::size_t i = 0; i < R; ++i) if (_5050()) resultado ^= suma1(v, v + N) + suma2(v, v + N); else resultado ^= suma2(v, v + N) + suma1(v, v + N); return resultado; }