Skip to content

Instantly share code, notes, and snippets.

View kammce's full-sized avatar

Khalil Estell kammce

  • Bay Area, California
  • 04:53 (UTC -08:00)
View GitHub Profile
@kammce
kammce / xstdbitset.cpp
Last active August 6, 2021 14:28
[Benchmark] C-style multibit insert vs C++ bitset
#include <bitset>
#include <cinttypes>
#include <cstdio>
#include <limits>
#include <type_traits>
namespace xstd {
struct bitrange {
uint32_t position;
@kammce
kammce / picolibc_attempt_notes.cpp
Created July 3, 2021 16:58
Getting picolibc to work
struct _reent r = {0, (FILE *) 0, (FILE *) 1, (FILE *) 0};
struct _reent *_impure_ptr = &r;
extern "C" void __cxa_pure_virtual()
{
// put your error handling here
}
extern "C" void __cxa_atexit() {}
@kammce
kammce / MockGpio.hpp
Created December 8, 2020 15:22
Partial implementation of a mock peripheral for SJSU. This was used in test to verify if using a hand written mock was faster than FakeIt (24 seconds for small test). It was, but only by 1s.
namespace sjsu
{
/// Mock Gpio for usage in testing
class MockGpio : public sjsu::Gpio
{
public:
// Return values
std::deque<bool> read_;
std::deque<std::variant<Direction, State, std::pair<InterruptCallback, Edge>>>
captures_;
@kammce
kammce / FixedAllocator.hpp
Created December 6, 2020 17:50
Fixed size stack based allocator for std::containers. Removing this from SJSU-Dev2 but wanted to preserve it here for those who may want to use it. This allocator will be replaced with std::pmr going forward.
#pragma once
#include <cstdint>
#include <cstdlib>
#include "utility/log.hpp"
namespace sjsu
{
/// Arena class is a memory management class that takes an external buffer and
@kammce
kammce / pll_constants_calculator.cpp
Created April 5, 2020 04:54
PLL Constants Calculator
#include <cstdio>
#include <cstdint>
#include <cinttypes>
struct PllSettings_t
{
uint32_t multiplier;
uint32_t feedback_divider;
uint32_t output_divider;
@kammce
kammce / source_location_dummy.cpp
Last active March 8, 2020 17:02
source_location_dummy
#include <cstdint>
namespace std::experimental
{
class source_location
{
public:
constexpr const char * file_name() const { return ""; }
constexpr const char * function_name() const { return ""; }
@kammce
kammce / constexpr-constuctor.cpp
Last active November 8, 2018 15:39
Demonstrates that C++ constexpr constructors do not appear in symbol tables if their objects are defined globally even at optimization level 0.
// Using g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
// Notice: that I am using optimization level 0 here.
//
// To compile:
// g++ -g3 -O0 -std=c++17 -o constexpr-constuctor.exe constexpr-constuctor.cpp
//
// To dump disassembly along with symbol table:
// objdump --disassemble --all-headers --source --demangle --wide constexpr-constuctor.exe > constexpr-constuctor.asm
//
// To dump contents of .data section: