Skip to content

Instantly share code, notes, and snippets.

View pftbest's full-sized avatar

Vadzim Dambrouski pftbest

View GitHub Profile
[user@ws-073 lockfree]$ RUSTFLAGS="-Z sanitizer=thread" cargo run --target x86_64-unknown-linux-gnu --release
Compiling lockfree v0.1.0 (file:///home/user/Downloads/lockfree)
Finished release [optimized] target(s) in 2.69 secs
Running `target/x86_64-unknown-linux-gnu/release/lockfree`
Hello, world!
==================
WARNING: ThreadSanitizer: data race (pid=19847)
Read of size 1 at 0x556297041018 by thread T2:
#0 _$LT$heapless..ring_buffer..spsc..Consumer$LT$$u27$a$C$$u20$T$C$$u20$A$GT$$GT$::dequeue::h31f23327099559ac <null> (lockfree+0xcb7b)
#1 std::sys_common::backtrace::__rust_begin_short_backtrace::hff50da7ea01f1850 <null> (lockfree+0xa6b7)
static const uint8_t reverse_lookup[16] = {
0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf,
};
uint8_t reverse_bits(uint8_t n)
{
return (reverse_lookup[n & 0xf] << 4) | reverse_lookup[n >> 4];
}
/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
|* *|
|* DAG Instruction Selector for the MSP430 target *|
|* *|
|* Automatically generated file, do not edit! *|
|* *|
\*===----------------------------------------------------------------------===*/
// *** NOTE: This file is #included into the middle of the target
// *** instruction selector class. These functions are really methods.
target triple = "msp430-none-elf"
@bar = global i32 0, align 2
define void @foo() {
start:
%0 = load i32, i32* @bar, align 2
%1 = add i32 %0, 1
store i32 %1, i32* @bar, align 2
ret void
diff --git a/lib/Target/MSP430/MSP430InstrInfo.td b/lib/Target/MSP430/MSP430InstrInfo.td
index cec43040f60..44869e78649 100644
--- a/lib/Target/MSP430/MSP430InstrInfo.td
+++ b/lib/Target/MSP430/MSP430InstrInfo.td
@@ -1178,6 +1178,8 @@ def : Pat<(store (addc (load addr:$dst), GR16:$src), addr:$dst),
(ADD16mr addr:$dst, GR16:$src)>;
def : Pat<(store (addc (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
(ADD16mm addr:$dst, addr:$src)>;
+def : Pat<(store (addc (load addr:$dst), (i16 imm:$src)), addr:$dst),
+ (ADD16mi addr:$dst, imm:$src)>;
//===-- MSP430InstrInfo.td - MSP430 Instruction defs -------*- tablegen -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file describes the MSP430 instructions in TableGen format.
$ ./llvm-build/bin/llc func.ll -debug-only=isel
=== foo
Initial selection DAG: BB#0 'foo:start'
SelectionDAG has 9 nodes:
t2: i16 = Constant<0>
t0: ch = EntryToken
t4: i32,ch = load<LD4[@bar](align=2)(dereferenceable)> t0, GlobalAddress:i16<i32* @bar> 0, undef:i16
extern crate core;
use core::default::Default;
use core::sync::atomic::{AtomicUsize, Ordering};
use core::cell::UnsafeCell;
const RING_SIZE: usize = 32;
pub struct Ring<T: Clone + Copy> {
head: AtomicUsize,
@pftbest
pftbest / ring.c
Created June 24, 2017 15:53
ring_t
#include "ring.h"
int ring_add(ring_t *ring, ring_data_t data)
{
ring_pos_t next_head = (ring->head + 1) % RING_SIZE;
if (next_head != ring->tail) {
ring->data[ring->head] = data;
ring->head = next_head;
return 0;
} else {
use std::str;
use std::process;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::collections::HashMap;
fn main() {
let mut args = std::env::args();
if args.len() < 4 {
let prog = args.next().unwrap();