Skip to content

Instantly share code, notes, and snippets.

View tejainece's full-sized avatar

Ravi Teja Gudapati tejainece

View GitHub Profile
@tejainece
tejainece / pthread_cv.cpp
Created May 2, 2024 09:33
WIP! Fiddling around with pthread_cond_t
//
// Created by tejag on 2024-04-26.
//
#include <cstdint>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <syncstream>
template <typename I>
const char *tcNegSlow(I *out, const I *inp, uint64_t nel) {
constexpr size_t laneSize = simdSize<I>();
uint16_t concurrency = std::thread::hardware_concurrency();
uint64_t totalLanes = (nel + laneSize - 1) / laneSize;
uint64_t lanesPerThread = std::max(
uint64_t((totalLanes + concurrency - 1) / concurrency), uint64_t(1)
);
std::vector<std::future<void>> futures(concurrency);
@tejainece
tejainece / incomplete_dig_at_cross_platform_simd.cpp
Created April 28, 2024 14:35
Experimental dig at cross platform SIMD
template <typename T> class Simd;
#if defined(TC_ARCH_X86)
#include <bits/stdc++.h>
#include <x86intrin.h>
uint16_t simdSize = 128;
uint16_t detectSimdSize() {
if (__builtin_cpu_supports("avx512f")) {
@tejainece
tejainece / __cxa_demangle.cpp
Created April 27, 2024 17:55
Print demangled type of a variable in C++
//
// Created by tejag on 2024-04-26.
//
#include <iostream>
#include <type_traits>
#include <typeinfo>
#include <cstdint>
#include <cxxabi.h>
//
// Created by tejag on 2024-04-26.
//
#include <cxxabi.h>
#include <experimental/simd>
#include <iostream>
#include <vector>
template <typename T> void printType() {
@tejainece
tejainece / ramblings.md
Created April 18, 2024 11:14
ramblings

x86 GAS uses reverse order of destination and source registers compared to Intel documentation. This was very confusing.

@tejainece
tejainece / configure_modelsim.sh
Last active April 16, 2024 14:40
This script installs all the 32 bit library dependencies of modelsim and also compiles freetype.
#!/bin/bash
ALTERA_PATH=~/altera/13.1/
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install gcc-multilib g++-multilib \
lib32z1 lib32stdc++6 lib32gcc1 \
expat:i386 fontconfig:i386 libfreetype6:i386 libexpat1:i386 libc6:i386 libgtk-3-0:i386 \
libcanberra0:i386 libpng12-0:i386 libice6:i386 libsm6:i386 libncurses5:i386 zlib1g:i386 \
@tejainece
tejainece / cgo1.go
Last active March 27, 2024 04:29
Examples of calling C code from Golang
package main
//#include<stdio.h>
//void inC() {
// printf("I am in C code now!\n");
//}
import "C"
import "fmt"
func main() {
@tejainece
tejainece / StreamToString.go
Created April 2, 2014 18:29
Golang: io.Reader stream to string or byte slice
import "bytes"
func StreamToByte(stream io.Reader) []byte {
buf := new(bytes.Buffer)
buf.ReadFrom(stream)
return buf.Bytes()
}
func StreamToString(stream io.Reader) string {
buf := new(bytes.Buffer)
@tejainece
tejainece / main.cpp
Last active March 18, 2024 21:21
Shared pointer implementation in C++
#include<iostream>
#include "shared_ptr.hpp"
using namespace std;
class A {
public:
int i;
explicit A(int _i) : i(_i) {
}