Skip to content

Instantly share code, notes, and snippets.

@rechardchen
rechardchen / ordering.cpp
Last active January 16, 2020 03:00
StoreLoad reordering on x86 architecture
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <intrin.h>
#include <stdio.h>
//#include <atomic>
// Set either of these to 1 to prevent CPU reordering
#define USE_CPU_FENCE 0
#define USE_SINGLE_HW_THREAD 0
@rechardchen
rechardchen / unicode_utf8.cc
Created August 11, 2012 06:30
C++: convert between utf8 and unicode
wstring UTF8toUnicode(const string& s)
{
wstring ws;
wchar_t wc;
for( int i = 0;i < s.length(); )
{
char c = s[i];
if ( (c & 0x80) == 0 )
{
wc = c;