Skip to content

Instantly share code, notes, and snippets.

View JinShil's full-sized avatar

Mike JinShil

View GitHub Profile
@JinShil
JinShil / memcpy.d
Created June 14, 2019 09:27
memcpy implemented in D
/*
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
@JinShil
JinShil / rte_memcpy.d
Created June 6, 2019 12:38
rte_memcpy in D
import core.simd: void16, loadUnaligned, storeUnaligned;
pragma(inline, true)
void rte_mov16(ubyte *dst, ubyte*src) {
storeUnaligned(cast(void16*)(dst), loadUnaligned(cast(void16*)(src)));
}
pragma(inline, true)
void rte_mov32(ubyte *dst, ubyte *src) {
storeUnaligned(cast(void16*)(dst), loadUnaligned(cast(void16*)(src)));
@JinShil
JinShil / BitField2.rs
Last active December 18, 2016 14:12
Another step closer at what I'm looking for out of a BitField implementation.
#![feature(const_fn)]
#![feature(associated_consts)]
#![allow(dead_code)]
#![allow(non_camel_case_types)]
use std::marker::PhantomData;
use std::ptr;
pub trait ConstantValue<T> {
const VALUE: T;
@JinShil
JinShil / multi-impl.rs
Created December 16, 2016 13:10
Macro to implement multiple traits in one statement
trait Foo {
fn foo(&self) {}
}
trait Bar {
fn bar(&self) {}
}
macro_rules! manyimpl {
($st: ty, $tr: ty) => { impl $tr for $st { } };
@JinShil
JinShil / Volatile-NonVolatile-Type.rs
Last active December 15, 2016 01:10
Volatile and Non-volatile implementation of the same type (special thanks to @mbrubeck)
use std::ptr;
use std::marker::PhantomData;
trait ReadWrite {
unsafe fn read<T>(src: *const T) -> T;
unsafe fn write<T>(dst: *mut T, src: T);
}
enum Volatile {}
enum NonVolatile {}
@JinShil
JinShil / BitFields.rs
Last active December 7, 2016 12:08
A technique for implementing memory-mapped IO bitfields in Rust using zero-sized types
#![feature(const_fn)]
#![feature(associated_consts)]
use std::ptr::*;
use std::mem;
#[derive(Copy, Clone)]
pub struct BitField (u8, u8);
trait FromBits<T> {