Skip to content

Instantly share code, notes, and snippets.

@oyvindln
oyvindln / spec_range.rs
Created January 9, 2018 22:22
Range specialisation
macro_rules! spec_range { ($($t:ty)*) =>
($(
impl Iterator for ops::Range<$t> {
#[inline]
default fn next(&mut self) -> Option<Self::Item> {
if self.start < self.end && self.start < <$t>::max_value() {
let temp = self.start;
self.start += 1;
Some(temp)
} else {
@oyvindln
oyvindln / const.rs
Created August 17, 2017 14:51
const
#![crate_type = "lib"]
#![feature(const_fn)]
const fn foo() -> usize {
10
}
// Ends up as simply return 25 in the mir output.
pub fn test1<T>() -> usize {
if true {
@oyvindln
oyvindln / vec.cpp
Last active August 11, 2017 18:08
rust vs cpp diff
// clang++ -S -std=c++11 -emit-llvm -vec.cpp -o vec_cpp.ll
// lines: 891
// ( wc -l vec_cpp.ll )
// with stripped blank lines and comments:
// ( sed '/^\s*;/d;/^\s*$/d' vec_cpp.ll | wc -l )
// 698
#include <cinttypes>
#include <vector>
@oyvindln
oyvindln / foo.cpp
Last active July 20, 2017 11:55
cpp version
#include <stdint.h>
#include <initializer_list>
typedef uint64_t u64;
typedef uint32_t u32;
typedef std::size_t usize;
const u32 SHIFT_MASK = (1 << 6) - 1;
// Putting these in an anonymous namespace makes them internal to this compilation unit, similar
DEBUG:rustc_mir::transform::inline: Inline cost for DefId { krate: CrateNum(5), node: DefIndex(145)DEBUG:rustc_metadata::decoder: def_path(id=DefIndex(145))
DEBUG:rustc::hir::map::definitions: DefPath::make: krate=CrateNum(5) index=Some(DefIndex(145))
DEBUG:rustc::hir::map::definitions: DefPath::make: key=DefKey { parent: Some(DefIndex(143)), disambiguated_data: DisambiguatedDefPathData { data: ValueNs("new"), disambiguator: 0 } }
DEBUG:rustc::hir::map::definitions: DefPath::make: krate=CrateNum(5) index=Some(DefIndex(143))
DEBUG:rustc::hir::map::definitions: DefPath::make: key=DefKey { parent: Some(DefIndex(66)), disambiguated_data: DisambiguatedDefPathData { data: Impl, disambiguator: 6 } }
DEBUG:rustc::hir::map::definitions: DefPath::make: krate=CrateNum(5) index=Some(DefIndex(66))
DEBUG:rustc::hir::map::definitions: DefPath::make: key=DefKey { parent: Some(DefIndex(0)), disambiguated_data: DisambiguatedDefPathData { data: Module("boxed"), disambiguator: 0 } }
DEBUG:rustc::hir::map::definitions: DefPath::m
@oyvindln
oyvindln / issue_example.s
Last active May 11, 2017 12:49
Box inlining
.text
.file "test2.cgu-0.rs"
.section .text._ZN5test25clone17h3c4e58d6a2d910d1E,"ax",@progbits
.globl _ZN5test25clone17h3c4e58d6a2d910d1E
.p2align 4, 0x90
.type _ZN5test25clone17h3c4e58d6a2d910d1E,@function
_ZN5test25clone17h3c4e58d6a2d910d1E:
.cfi_startproc
pushq %rbx
.Lcfi0:
Compiling inflate v0.1.1 (file:///<removed>/inflate)
warning: All variants have the same prefix: `Block`, #[warn(enum_variant_names)] on by default
--> src/lib.rs:660:1
|
660 | enum BitsNext {
| ^
|
= help: remove the prefixes and use full paths to the variants instead of glob imports
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#enum_variant_names
@oyvindln
oyvindln / Dirt.material
Created November 3, 2014 10:41
dirt material file
import RTSS/NormalMapping_MultiPass from "RTShaderSystem.material"
material Dirt : RTSS/NormalMapping_MultiPass
{
technique
{
pass lighting
{
// Override the normal map.
rtshader_system
{