Last active
August 29, 2015 14:01
-
-
Save SiegeLord/f7d41ab653d9f519afe4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- out.ll 2014-05-12 13:20:11.501655442 -0400 | |
+++ in.ll 2014-05-12 13:20:06.781655392 -0400 | |
@@ -1,9 +1,8 @@ | |
-; Function Attrs: uwtable | |
-define internal void @_ZN4test3bug20hf04dd765537e803c3Ua4v0.0E(%struct.Vector* nocapture) unnamed_addr #1 { | |
+; Function Attrs: inlinehint uwtable | |
+define internal void @_ZN4test14vec_speed_vec212closure.2554E(i8*) unnamed_addr #2 { | |
entry-block: | |
%fmt.i = alloca %"struct.std::fmt::Arguments[#1]"* | |
%num = alloca %str_slice | |
- %a = alloca %struct.Vector* | |
%num = alloca %"struct.core::iter::Range<int>[#3]" | |
%match = alloca %"struct.core::iter::Range<int>[#3]"* | |
%__llmatch = alloca %"struct.core::iter::Range<int>[#3]"** | |
@@ -31,7 +30,10 @@ | |
%__args = alloca %"struct.std::fmt::Arguments[#1]" | |
%__adjust = alloca { %"enum.std::fmt::rt::Piece[#1]"*, i64 } | |
%__adjust21 = alloca { %"struct.std::fmt::Argument[#1]"*, i64 } | |
- store %struct.Vector* %num, %struct.Vector** %a | |
+ %num = bitcast i8* %num to { i64, void (i8*)*, i8*, i8*, { %struct.Vector** } }* | |
+ %num = getelementptr inbounds { i64, void (i8*)*, i8*, i8*, { %struct.Vector** } }* %num, i32 0, i32 4 | |
+ %num = getelementptr inbounds { %struct.Vector** }* %num, i32 0, i32 0 | |
+ %num = load %struct.Vector*** %num | |
call void @_ZN4iter5range20h31963039699350522584v0.0E(%"struct.core::iter::Range<int>[#3]"* noalias nocapture sret %num, i64 0, i64 100) | |
store %"struct.core::iter::Range<int>[#3]"* %num, %"struct.core::iter::Range<int>[#3]"** %match | |
store %"struct.core::iter::Range<int>[#3]"** %match, %"struct.core::iter::Range<int>[#3]"*** %__llmatch | |
@@ -59,11 +61,11 @@ | |
br label %loop_exit | |
case_body2: ; preds = %match_else | |
- %num = load %struct.Vector** %a | |
- call void @"_ZN89_$BP$$x27l$x20Vector.Mul$LT$RHS$C$$x20Multiplier$LT$$BP$$x27l$x20Vector$C$$x20RHS$GT$$GT$3mul21h136623623032751540554v0.0E"(%"struct.Multiplier<&'static Vector,&'static Vector>"* noalias nocapture sret %num, %struct.Vector** %a, %struct.Vector** %a) | |
- call void @"_ZN84_$BP$$x27l$x20Vector.Add$LT$RHS$C$$x20Adder$LT$$BP$$x27l$x20Vector$C$$x20RHS$GT$$GT$3add19h5325904014821771314v0.0E"(%"struct.Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>"* noalias nocapture sret %num, %struct.Vector** %a, %"struct.Multiplier<&'static Vector,&'static Vector>"* %num) | |
- call void @"_ZN95Adder$LT$TA$C$$x20TB$GT$.Div$LT$RHS$C$$x20Divider$LT$Adder$LT$TA$C$$x20TB$GT$$C$$x20RHS$GT$$GT$3div21h174445449624808822424v0.0E"(%"struct.Divider<Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>,&'static Vector>"* noalias nocapture sret %num, %"struct.Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>"* %num, %struct.Vector** %a) | |
- call void @"_ZN27LHS.VectorAssign$LT$RHS$GT$6assign20h23778977453831471604v0.0E"(%struct.Vector* %num, %"struct.Divider<Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>,&'static Vector>"* nocapture %num) | |
+ %num = load %struct.Vector** %num | |
+ call void @"_ZN89_$BP$$x27l$x20Vector.Mul$LT$RHS$C$$x20Multiplier$LT$$BP$$x27l$x20Vector$C$$x20RHS$GT$$GT$3mul21h110020191613969668624v0.0E"(%"struct.Multiplier<&'static Vector,&'static Vector>"* noalias nocapture sret %num, %struct.Vector** %num, %struct.Vector** %num) | |
+ call void @"_ZN84_$BP$$x27l$x20Vector.Add$LT$RHS$C$$x20Adder$LT$$BP$$x27l$x20Vector$C$$x20RHS$GT$$GT$3add20h37116036193821267254v0.0E"(%"struct.Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>"* noalias nocapture sret %num, %struct.Vector** %num, %"struct.Multiplier<&'static Vector,&'static Vector>"* %num) | |
+ call void @"_ZN95Adder$LT$TA$C$$x20TB$GT$.Div$LT$RHS$C$$x20Divider$LT$Adder$LT$TA$C$$x20TB$GT$$C$$x20RHS$GT$$GT$3div21h112760573393165344564v0.0E"(%"struct.Divider<Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>,&'static Vector>"* noalias nocapture sret %num, %"struct.Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>"* %num, %struct.Vector** %num) | |
+ call void @"_ZN27LHS.VectorAssign$LT$RHS$GT$6assign21h138954633945060915114v0.0E"(%struct.Vector* %num, %"struct.Divider<Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>,&'static Vector>"* nocapture %num) | |
br label %join | |
match_else: ; preds = %loop_body | |
@@ -79,8 +81,8 @@ | |
join3: ; preds = %loop_exit | |
store float 0.000000e+00, float* %sum | |
- %num = load %struct.Vector** %a | |
- call void @_ZN12T.VectorIter5iter220h96865371617387078084v0.0E(%"struct.VectorIterator<&'static Vector>"* noalias nocapture sret %num, %struct.Vector* %num) | |
+ %num = load %struct.Vector** %num | |
+ call void @_ZN12T.VectorIter5iter221h179086565220225010404v0.0E(%"struct.VectorIterator<&'static Vector>"* noalias nocapture sret %num, %struct.Vector* %num) | |
store %"struct.VectorIterator<&'static Vector>"* %num, %"struct.VectorIterator<&'static Vector>"** %match4 | |
store %"struct.VectorIterator<&'static Vector>"** %match4, %"struct.VectorIterator<&'static Vector>"*** %__llmatch6 | |
br label %case_body5 | |
@@ -96,7 +98,7 @@ | |
loop_body9: ; preds = %join16, %case_body5 | |
%num = load %"struct.VectorIterator<&'static Vector>"** %i7 | |
- %num = call %"enum.core::option::Option<f32>[#3]" @"_ZN43VectorIterator$LT$T$GT$.Iterator$LT$f32$GT$4next20h85624075393725754504v0.0E"(%"struct.VectorIterator<&'static Vector>"* %num) | |
+ %num = call %"enum.core::option::Option<f32>[#3]" @"_ZN43VectorIterator$LT$T$GT$.Iterator$LT$f32$GT$4next20h94997776737551477954v0.0E"(%"struct.VectorIterator<&'static Vector>"* %num) | |
store %"enum.core::option::Option<f32>[#3]" %num, %"enum.core::option::Option<f32>[#3]"* %num | |
%num = load %"enum.core::option::Option<f32>[#3]"* %num | |
store %"enum.core::option::Option<f32>[#3]" %num, %"enum.core::option::Option<f32>[#3]"* %match10 | |
@@ -138,9 +140,9 @@ | |
%num = icmp eq i8 %num, 0 | |
%num = select i1 %num, i8 1, i8 0 | |
%num = icmp ne i8 %num, 0 | |
- br i1 %num, label %then-block-2977-, label %next-block | |
+ br i1 %num, label %then-block-3181-, label %next-block | |
-then-block-2977-: ; preds = %join17 | |
+then-block-3181-: ; preds = %join17 | |
%num = getelementptr inbounds { %str_slice* }* %num, i32 0, i32 0 | |
%num = getelementptr inbounds %str_slice* %num, i32 0, i32 0 | |
store i8* getelementptr inbounds ([11 x i8]* @str2497, i32 0, i32 0), i8** %num | |
@@ -153,7 +155,7 @@ | |
store %str_slice** %num, %str_slice*** %__llmatch20 | |
br label %case_body19 | |
-case_body19: ; preds = %then-block-2977- | |
+case_body19: ; preds = %then-block-3181- | |
%num = load %str_slice*** %__llmatch20 | |
%num = load %str_slice** %num | |
store %str_slice* %num, %str_slice** %__arg0 | |
@@ -166,7 +168,7 @@ | |
%num = getelementptr inbounds { %"struct.std::fmt::Argument[#1]"*, i64 }* %__args_vec, i32 0, i32 1 | |
store i64 1, i64* %num | |
%num = getelementptr inbounds { %"enum.std::fmt::rt::Piece[#1]"*, i64 }* %__adjust, i32 0, i32 0 | |
- store %"enum.std::fmt::rt::Piece[#1]"* getelementptr inbounds ([2 x %"enum.std::fmt::rt::Piece[#1]"]* bitcast ({ { i8, { i8*, i64 }, [56 x i8] }, { i8, { { i8, [15 x i8] }, { i32, i8, i64, { i8, [15 x i8] }, { i8, [15 x i8] } }, { i8* } }, [0 x i8] } }* @_ZN4test3bug15__STATIC_FMTSTR20hed05baae85484b14BWa4v0.0E to [2 x %"enum.std::fmt::rt::Piece[#1]"]*), i32 0, i32 0), %"enum.std::fmt::rt::Piece[#1]"** %num | |
+ store %"enum.std::fmt::rt::Piece[#1]"* getelementptr inbounds ([2 x %"enum.std::fmt::rt::Piece[#1]"]* bitcast ({ { i8, { i8*, i64 }, [56 x i8] }, { i8, { { i8, [15 x i8] }, { i32, i8, i64, { i8, [15 x i8] }, { i8, [15 x i8] } }, { i8* } }, [0 x i8] } }* @_ZN4test14vec_speed_vec215__STATIC_FMTSTR20hed05baae85484b14TZa4v0.0E to [2 x %"enum.std::fmt::rt::Piece[#1]"]*), i32 0, i32 0), %"enum.std::fmt::rt::Piece[#1]"** %num | |
%num = getelementptr inbounds { %"enum.std::fmt::rt::Piece[#1]"*, i64 }* %__adjust, i32 0, i32 1 | |
store i64 2, i64* %num | |
%num = getelementptr inbounds { %"struct.std::fmt::Argument[#1]"*, i64 }* %__args_vec, i32 0, i32 0 | |
@@ -184,10 +186,10 @@ | |
store i8* getelementptr inbounds ([10 x i8]* @str2205, i32 0, i32 0), i8** %num | |
%num = getelementptr inbounds %str_slice* %num, i32 0, i32 1 | |
store i64 10, i64* %num | |
- call void @_ZN2rt6unwind16begin_unwind_fmt20h1360f91e7709ea39KsF9v0.11.preE(%"struct.std::fmt::Arguments[#1]"* nocapture %num, %str_slice* nocapture %num, i64 322) | |
+ call void @_ZN2rt6unwind16begin_unwind_fmt20h1360f91e7709ea39KsF9v0.11.preE(%"struct.std::fmt::Arguments[#1]"* nocapture %num, %str_slice* nocapture %num, i64 353) | |
unreachable | |
-_ZN4test3bug7run_fmt20h53f137bbae5b7448fWa4v0.0E.exit: ; No predecessors! | |
+_ZN4test14vec_speed_vec27run_fmt20h073e9dfb0fdb01b4xZa4v0.0E.exit: ; No predecessors! | |
unreachable | |
join22: ; No predecessors! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Function Attrs: inlinehint uwtable | |
define internal void @_ZN4test14vec_speed_vec112closure.2550E(i8*) unnamed_addr #2 { | |
entry-block: | |
%1 = bitcast i8* %0 to { i64, void (i8*)*, i8*, i8*, { %struct.Vector** } }* | |
%2 = getelementptr inbounds { i64, void (i8*)*, i8*, i8*, { %struct.Vector** } }* %1, i32 0, i32 4 | |
%3 = getelementptr inbounds { %struct.Vector** }* %2, i32 0, i32 0 | |
%4 = load %struct.Vector*** %3 | |
%5 = load %struct.Vector** %4 | |
call void @_ZN4test3bug20hf04dd765537e803c3Ua4v0.0E(%struct.Vector* nocapture %5) | |
ret void | |
} | |
; Function Attrs: uwtable | |
define internal void @_ZN4test3bug20hf04dd765537e803c3Ua4v0.0E(%struct.Vector* nocapture) unnamed_addr #1 { | |
entry-block: | |
%fmt.i = alloca %"struct.std::fmt::Arguments[#1]"* | |
%1 = alloca %str_slice | |
%a = alloca %struct.Vector* | |
%2 = alloca %"struct.core::iter::Range<int>[#3]" | |
%match = alloca %"struct.core::iter::Range<int>[#3]"* | |
%__llmatch = alloca %"struct.core::iter::Range<int>[#3]"** | |
%i = alloca %"struct.core::iter::Range<int>[#3]"* | |
%3 = alloca %"enum.core::option::Option<int>[#3]" | |
%4 = alloca %"struct.Divider<Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>,&'static Vector>" | |
%5 = alloca %"struct.Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>" | |
%6 = alloca %"struct.Multiplier<&'static Vector,&'static Vector>" | |
%sum = alloca float | |
%7 = alloca %"struct.VectorIterator<&'static Vector>" | |
%match4 = alloca %"struct.VectorIterator<&'static Vector>"* | |
%__llmatch6 = alloca %"struct.VectorIterator<&'static Vector>"** | |
%i7 = alloca %"struct.VectorIterator<&'static Vector>"* | |
%8 = alloca %"enum.core::option::Option<f32>[#3]" | |
%match10 = alloca %"enum.core::option::Option<f32>[#3]" | |
%__llmatch13 = alloca float* | |
%v = alloca float | |
%9 = alloca { %str_slice* } | |
%10 = alloca %str_slice | |
%match18 = alloca { %str_slice* } | |
%__llmatch20 = alloca %str_slice** | |
%__arg0 = alloca %str_slice* | |
%__args_vec = alloca { %"struct.std::fmt::Argument[#1]"*, i64 } | |
%11 = alloca %"struct.std::fmt::Argument[#1]" | |
%__args = alloca %"struct.std::fmt::Arguments[#1]" | |
%__adjust = alloca { %"enum.std::fmt::rt::Piece[#1]"*, i64 } | |
%__adjust21 = alloca { %"struct.std::fmt::Argument[#1]"*, i64 } | |
store %struct.Vector* %0, %struct.Vector** %a | |
call void @_ZN4iter5range20h31963039699350522584v0.0E(%"struct.core::iter::Range<int>[#3]"* noalias nocapture sret %2, i64 0, i64 100) | |
store %"struct.core::iter::Range<int>[#3]"* %2, %"struct.core::iter::Range<int>[#3]"** %match | |
store %"struct.core::iter::Range<int>[#3]"** %match, %"struct.core::iter::Range<int>[#3]"*** %__llmatch | |
br label %case_body | |
case_body: ; preds = %entry-block | |
%12 = load %"struct.core::iter::Range<int>[#3]"*** %__llmatch | |
%13 = load %"struct.core::iter::Range<int>[#3]"** %12 | |
store %"struct.core::iter::Range<int>[#3]"* %13, %"struct.core::iter::Range<int>[#3]"** %i | |
br label %loop_body | |
loop_exit: ; preds = %case_body1 | |
br label %join3 | |
loop_body: ; preds = %join, %case_body | |
%14 = load %"struct.core::iter::Range<int>[#3]"** %i | |
call void @"_ZN4iter32Range$LT$A$GT$.Iterator$LT$A$GT$4next20h26386583843574046064v0.0E"(%"enum.core::option::Option<int>[#3]"* noalias nocapture sret %3, %"struct.core::iter::Range<int>[#3]"* %14) | |
%15 = getelementptr inbounds %"enum.core::option::Option<int>[#3]"* %3, i32 0, i32 0 | |
%16 = load i8* %15, !range !0 | |
switch i8 %16, label %match_else [ | |
i8 0, label %match_case | |
] | |
case_body1: ; preds = %match_case | |
br label %loop_exit | |
case_body2: ; preds = %match_else | |
%17 = load %struct.Vector** %a | |
call void @"_ZN89_$BP$$x27l$x20Vector.Mul$LT$RHS$C$$x20Multiplier$LT$$BP$$x27l$x20Vector$C$$x20RHS$GT$$GT$3mul21h136623623032751540554v0.0E"(%"struct.Multiplier<&'static Vector,&'static Vector>"* noalias nocapture sret %6, %struct.Vector** %a, %struct.Vector** %a) | |
call void @"_ZN84_$BP$$x27l$x20Vector.Add$LT$RHS$C$$x20Adder$LT$$BP$$x27l$x20Vector$C$$x20RHS$GT$$GT$3add19h5325904014821771314v0.0E"(%"struct.Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>"* noalias nocapture sret %5, %struct.Vector** %a, %"struct.Multiplier<&'static Vector,&'static Vector>"* %6) | |
call void @"_ZN95Adder$LT$TA$C$$x20TB$GT$.Div$LT$RHS$C$$x20Divider$LT$Adder$LT$TA$C$$x20TB$GT$$C$$x20RHS$GT$$GT$3div21h174445449624808822424v0.0E"(%"struct.Divider<Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>,&'static Vector>"* noalias nocapture sret %4, %"struct.Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>"* %5, %struct.Vector** %a) | |
call void @"_ZN27LHS.VectorAssign$LT$RHS$GT$6assign20h23778977453831471604v0.0E"(%struct.Vector* %17, %"struct.Divider<Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>,&'static Vector>"* nocapture %4) | |
br label %join | |
match_else: ; preds = %loop_body | |
%18 = bitcast %"enum.core::option::Option<int>[#3]"* %3 to { i8, i64 }* | |
%19 = getelementptr inbounds { i8, i64 }* %18, i32 0, i32 1 | |
br label %case_body2 | |
match_case: ; preds = %loop_body | |
br label %case_body1 | |
join: ; preds = %case_body2 | |
br label %loop_body | |
join3: ; preds = %loop_exit | |
store float 0.000000e+00, float* %sum | |
%20 = load %struct.Vector** %a | |
call void @_ZN12T.VectorIter5iter220h96865371617387078084v0.0E(%"struct.VectorIterator<&'static Vector>"* noalias nocapture sret %7, %struct.Vector* %20) | |
store %"struct.VectorIterator<&'static Vector>"* %7, %"struct.VectorIterator<&'static Vector>"** %match4 | |
store %"struct.VectorIterator<&'static Vector>"** %match4, %"struct.VectorIterator<&'static Vector>"*** %__llmatch6 | |
br label %case_body5 | |
case_body5: ; preds = %join3 | |
%21 = load %"struct.VectorIterator<&'static Vector>"*** %__llmatch6 | |
%22 = load %"struct.VectorIterator<&'static Vector>"** %21 | |
store %"struct.VectorIterator<&'static Vector>"* %22, %"struct.VectorIterator<&'static Vector>"** %i7 | |
br label %loop_body9 | |
loop_exit8: ; preds = %case_body11 | |
br label %join17 | |
loop_body9: ; preds = %join16, %case_body5 | |
%23 = load %"struct.VectorIterator<&'static Vector>"** %i7 | |
%24 = call %"enum.core::option::Option<f32>[#3]" @"_ZN43VectorIterator$LT$T$GT$.Iterator$LT$f32$GT$4next20h85624075393725754504v0.0E"(%"struct.VectorIterator<&'static Vector>"* %23) | |
store %"enum.core::option::Option<f32>[#3]" %24, %"enum.core::option::Option<f32>[#3]"* %8 | |
%25 = load %"enum.core::option::Option<f32>[#3]"* %8 | |
store %"enum.core::option::Option<f32>[#3]" %25, %"enum.core::option::Option<f32>[#3]"* %match10 | |
%26 = getelementptr inbounds %"enum.core::option::Option<f32>[#3]"* %match10, i32 0, i32 0 | |
%27 = load i8* %26, !range !0 | |
switch i8 %27, label %match_else14 [ | |
i8 0, label %match_case15 | |
] | |
case_body11: ; preds = %match_case15 | |
br label %loop_exit8 | |
case_body12: ; preds = %match_else14 | |
%28 = load float** %__llmatch13 | |
%29 = load float* %28 | |
store float %29, float* %v | |
%30 = load float* %sum | |
%31 = load float* %v | |
%32 = fadd float %30, %31 | |
store float %32, float* %sum | |
br label %join16 | |
match_else14: ; preds = %loop_body9 | |
%33 = bitcast %"enum.core::option::Option<f32>[#3]"* %match10 to { i8, float }* | |
%34 = getelementptr inbounds { i8, float }* %33, i32 0, i32 1 | |
store float* %34, float** %__llmatch13 | |
br label %case_body12 | |
match_case15: ; preds = %loop_body9 | |
br label %case_body11 | |
join16: ; preds = %case_body12 | |
br label %loop_body9 | |
join17: ; preds = %loop_exit8 | |
%35 = load float* %sum | |
%36 = fcmp une float %35, 9.600000e+01 | |
%37 = zext i1 %36 to i8 | |
%38 = icmp eq i8 %37, 0 | |
%39 = select i1 %38, i8 1, i8 0 | |
%40 = icmp ne i8 %39, 0 | |
br i1 %40, label %then-block-2977-, label %next-block | |
then-block-2977-: ; preds = %join17 | |
%41 = getelementptr inbounds { %str_slice* }* %9, i32 0, i32 0 | |
%42 = getelementptr inbounds %str_slice* %10, i32 0, i32 0 | |
store i8* getelementptr inbounds ([11 x i8]* @str2497, i32 0, i32 0), i8** %42 | |
%43 = getelementptr inbounds %str_slice* %10, i32 0, i32 1 | |
store i64 11, i64* %43 | |
store %str_slice* %10, %str_slice** %41 | |
%44 = load { %str_slice* }* %9 | |
store { %str_slice* } %44, { %str_slice* }* %match18 | |
%45 = getelementptr inbounds { %str_slice* }* %match18, i32 0, i32 0 | |
store %str_slice** %45, %str_slice*** %__llmatch20 | |
br label %case_body19 | |
case_body19: ; preds = %then-block-2977- | |
%46 = load %str_slice*** %__llmatch20 | |
%47 = load %str_slice** %46 | |
store %str_slice* %47, %str_slice** %__arg0 | |
%48 = bitcast %"struct.std::fmt::Argument[#1]"* %11 to [1 x %"struct.std::fmt::Argument[#1]"]* | |
%49 = getelementptr inbounds %"struct.std::fmt::Argument[#1]"* %11, i32 0 | |
%50 = load %str_slice** %__arg0 | |
call void @_ZN3fmt8argument20h80294545790776888184v0.0E(%"struct.std::fmt::Argument[#1]"* noalias nocapture sret %49, void (%"enum.core::result::Result<(),std::io::IoError>[#3]"*, %str_slice*, %"struct.std::fmt::Formatter[#1]"*)* @_ZN3fmt13secret_string20h57687284095775914444v0.0E, %str_slice* %50) | |
%51 = getelementptr inbounds { %"struct.std::fmt::Argument[#1]"*, i64 }* %__args_vec, i32 0, i32 0 | |
store %"struct.std::fmt::Argument[#1]"* %11, %"struct.std::fmt::Argument[#1]"** %51 | |
%52 = getelementptr inbounds { %"struct.std::fmt::Argument[#1]"*, i64 }* %__args_vec, i32 0, i32 1 | |
store i64 1, i64* %52 | |
%53 = getelementptr inbounds { %"enum.std::fmt::rt::Piece[#1]"*, i64 }* %__adjust, i32 0, i32 0 | |
store %"enum.std::fmt::rt::Piece[#1]"* getelementptr inbounds ([2 x %"enum.std::fmt::rt::Piece[#1]"]* bitcast ({ { i8, { i8*, i64 }, [56 x i8] }, { i8, { { i8, [15 x i8] }, { i32, i8, i64, { i8, [15 x i8] }, { i8, [15 x i8] } }, { i8* } }, [0 x i8] } }* @_ZN4test3bug15__STATIC_FMTSTR20hed05baae85484b14BWa4v0.0E to [2 x %"enum.std::fmt::rt::Piece[#1]"]*), i32 0, i32 0), %"enum.std::fmt::rt::Piece[#1]"** %53 | |
%54 = getelementptr inbounds { %"enum.std::fmt::rt::Piece[#1]"*, i64 }* %__adjust, i32 0, i32 1 | |
store i64 2, i64* %54 | |
%55 = getelementptr inbounds { %"struct.std::fmt::Argument[#1]"*, i64 }* %__args_vec, i32 0, i32 0 | |
%56 = load %"struct.std::fmt::Argument[#1]"** %55 | |
%57 = getelementptr inbounds { %"struct.std::fmt::Argument[#1]"*, i64 }* %__args_vec, i32 0, i32 1 | |
%58 = load i64* %57 | |
%59 = getelementptr inbounds { %"struct.std::fmt::Argument[#1]"*, i64 }* %__adjust21, i32 0, i32 0 | |
store %"struct.std::fmt::Argument[#1]"* %56, %"struct.std::fmt::Argument[#1]"** %59 | |
%60 = getelementptr inbounds { %"struct.std::fmt::Argument[#1]"*, i64 }* %__adjust21, i32 0, i32 1 | |
store i64 %58, i64* %60 | |
call void @"_ZN3fmt22Arguments$LT$$x27a$GT$3new20h2445e004e4ad48b6nvb4v0.0E"(%"struct.std::fmt::Arguments[#1]"* noalias nocapture sret %__args, { %"enum.std::fmt::rt::Piece[#1]"*, i64 }* nocapture %__adjust, { %"struct.std::fmt::Argument[#1]"*, i64 }* nocapture %__adjust21) | |
store %"struct.std::fmt::Arguments[#1]"* %__args, %"struct.std::fmt::Arguments[#1]"** %fmt.i | |
%61 = load %"struct.std::fmt::Arguments[#1]"** %fmt.i | |
%62 = getelementptr inbounds %str_slice* %1, i32 0, i32 0 | |
store i8* getelementptr inbounds ([10 x i8]* @str2205, i32 0, i32 0), i8** %62 | |
%63 = getelementptr inbounds %str_slice* %1, i32 0, i32 1 | |
store i64 10, i64* %63 | |
call void @_ZN2rt6unwind16begin_unwind_fmt20h1360f91e7709ea39KsF9v0.11.preE(%"struct.std::fmt::Arguments[#1]"* nocapture %61, %str_slice* nocapture %1, i64 322) | |
unreachable | |
_ZN4test3bug7run_fmt20h53f137bbae5b7448fWa4v0.0E.exit: ; No predecessors! | |
unreachable | |
join22: ; No predecessors! | |
unreachable | |
next-block: ; preds = %join17 | |
ret void | |
} | |
----------------------------------------------------- | |
; Function Attrs: inlinehint uwtable | |
define internal void @_ZN4test14vec_speed_vec212closure.2554E(i8*) unnamed_addr #2 { | |
entry-block: | |
%fmt.i = alloca %"struct.std::fmt::Arguments[#1]"* | |
%1 = alloca %str_slice | |
%2 = alloca %"struct.core::iter::Range<int>[#3]" | |
%match = alloca %"struct.core::iter::Range<int>[#3]"* | |
%__llmatch = alloca %"struct.core::iter::Range<int>[#3]"** | |
%i = alloca %"struct.core::iter::Range<int>[#3]"* | |
%3 = alloca %"enum.core::option::Option<int>[#3]" | |
%4 = alloca %"struct.Divider<Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>,&'static Vector>" | |
%5 = alloca %"struct.Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>" | |
%6 = alloca %"struct.Multiplier<&'static Vector,&'static Vector>" | |
%sum = alloca float | |
%7 = alloca %"struct.VectorIterator<&'static Vector>" | |
%match4 = alloca %"struct.VectorIterator<&'static Vector>"* | |
%__llmatch6 = alloca %"struct.VectorIterator<&'static Vector>"** | |
%i7 = alloca %"struct.VectorIterator<&'static Vector>"* | |
%8 = alloca %"enum.core::option::Option<f32>[#3]" | |
%match10 = alloca %"enum.core::option::Option<f32>[#3]" | |
%__llmatch13 = alloca float* | |
%v = alloca float | |
%9 = alloca { %str_slice* } | |
%10 = alloca %str_slice | |
%match18 = alloca { %str_slice* } | |
%__llmatch20 = alloca %str_slice** | |
%__arg0 = alloca %str_slice* | |
%__args_vec = alloca { %"struct.std::fmt::Argument[#1]"*, i64 } | |
%11 = alloca %"struct.std::fmt::Argument[#1]" | |
%__args = alloca %"struct.std::fmt::Arguments[#1]" | |
%__adjust = alloca { %"enum.std::fmt::rt::Piece[#1]"*, i64 } | |
%__adjust21 = alloca { %"struct.std::fmt::Argument[#1]"*, i64 } | |
%12 = bitcast i8* %0 to { i64, void (i8*)*, i8*, i8*, { %struct.Vector** } }* | |
%13 = getelementptr inbounds { i64, void (i8*)*, i8*, i8*, { %struct.Vector** } }* %12, i32 0, i32 4 | |
%14 = getelementptr inbounds { %struct.Vector** }* %13, i32 0, i32 0 | |
%15 = load %struct.Vector*** %14 | |
call void @_ZN4iter5range20h31963039699350522584v0.0E(%"struct.core::iter::Range<int>[#3]"* noalias nocapture sret %2, i64 0, i64 100) | |
store %"struct.core::iter::Range<int>[#3]"* %2, %"struct.core::iter::Range<int>[#3]"** %match | |
store %"struct.core::iter::Range<int>[#3]"** %match, %"struct.core::iter::Range<int>[#3]"*** %__llmatch | |
br label %case_body | |
case_body: ; preds = %entry-block | |
%16 = load %"struct.core::iter::Range<int>[#3]"*** %__llmatch | |
%17 = load %"struct.core::iter::Range<int>[#3]"** %16 | |
store %"struct.core::iter::Range<int>[#3]"* %17, %"struct.core::iter::Range<int>[#3]"** %i | |
br label %loop_body | |
loop_exit: ; preds = %case_body1 | |
br label %join3 | |
loop_body: ; preds = %join, %case_body | |
%18 = load %"struct.core::iter::Range<int>[#3]"** %i | |
call void @"_ZN4iter32Range$LT$A$GT$.Iterator$LT$A$GT$4next20h26386583843574046064v0.0E"(%"enum.core::option::Option<int>[#3]"* noalias nocapture sret %3, %"struct.core::iter::Range<int>[#3]"* %18) | |
%19 = getelementptr inbounds %"enum.core::option::Option<int>[#3]"* %3, i32 0, i32 0 | |
%20 = load i8* %19, !range !0 | |
switch i8 %20, label %match_else [ | |
i8 0, label %match_case | |
] | |
case_body1: ; preds = %match_case | |
br label %loop_exit | |
case_body2: ; preds = %match_else | |
%21 = load %struct.Vector** %15 | |
call void @"_ZN89_$BP$$x27l$x20Vector.Mul$LT$RHS$C$$x20Multiplier$LT$$BP$$x27l$x20Vector$C$$x20RHS$GT$$GT$3mul21h110020191613969668624v0.0E"(%"struct.Multiplier<&'static Vector,&'static Vector>"* noalias nocapture sret %6, %struct.Vector** %15, %struct.Vector** %15) | |
call void @"_ZN84_$BP$$x27l$x20Vector.Add$LT$RHS$C$$x20Adder$LT$$BP$$x27l$x20Vector$C$$x20RHS$GT$$GT$3add20h37116036193821267254v0.0E"(%"struct.Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>"* noalias nocapture sret %5, %struct.Vector** %15, %"struct.Multiplier<&'static Vector,&'static Vector>"* %6) | |
call void @"_ZN95Adder$LT$TA$C$$x20TB$GT$.Div$LT$RHS$C$$x20Divider$LT$Adder$LT$TA$C$$x20TB$GT$$C$$x20RHS$GT$$GT$3div21h112760573393165344564v0.0E"(%"struct.Divider<Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>,&'static Vector>"* noalias nocapture sret %4, %"struct.Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>"* %5, %struct.Vector** %15) | |
call void @"_ZN27LHS.VectorAssign$LT$RHS$GT$6assign21h138954633945060915114v0.0E"(%struct.Vector* %21, %"struct.Divider<Adder<&'static Vector,Multiplier<&'static Vector,&'static Vector>>,&'static Vector>"* nocapture %4) | |
br label %join | |
match_else: ; preds = %loop_body | |
%22 = bitcast %"enum.core::option::Option<int>[#3]"* %3 to { i8, i64 }* | |
%23 = getelementptr inbounds { i8, i64 }* %22, i32 0, i32 1 | |
br label %case_body2 | |
match_case: ; preds = %loop_body | |
br label %case_body1 | |
join: ; preds = %case_body2 | |
br label %loop_body | |
join3: ; preds = %loop_exit | |
store float 0.000000e+00, float* %sum | |
%24 = load %struct.Vector** %15 | |
call void @_ZN12T.VectorIter5iter221h179086565220225010404v0.0E(%"struct.VectorIterator<&'static Vector>"* noalias nocapture sret %7, %struct.Vector* %24) | |
store %"struct.VectorIterator<&'static Vector>"* %7, %"struct.VectorIterator<&'static Vector>"** %match4 | |
store %"struct.VectorIterator<&'static Vector>"** %match4, %"struct.VectorIterator<&'static Vector>"*** %__llmatch6 | |
br label %case_body5 | |
case_body5: ; preds = %join3 | |
%25 = load %"struct.VectorIterator<&'static Vector>"*** %__llmatch6 | |
%26 = load %"struct.VectorIterator<&'static Vector>"** %25 | |
store %"struct.VectorIterator<&'static Vector>"* %26, %"struct.VectorIterator<&'static Vector>"** %i7 | |
br label %loop_body9 | |
loop_exit8: ; preds = %case_body11 | |
br label %join17 | |
loop_body9: ; preds = %join16, %case_body5 | |
%27 = load %"struct.VectorIterator<&'static Vector>"** %i7 | |
%28 = call %"enum.core::option::Option<f32>[#3]" @"_ZN43VectorIterator$LT$T$GT$.Iterator$LT$f32$GT$4next20h94997776737551477954v0.0E"(%"struct.VectorIterator<&'static Vector>"* %27) | |
store %"enum.core::option::Option<f32>[#3]" %28, %"enum.core::option::Option<f32>[#3]"* %8 | |
%29 = load %"enum.core::option::Option<f32>[#3]"* %8 | |
store %"enum.core::option::Option<f32>[#3]" %29, %"enum.core::option::Option<f32>[#3]"* %match10 | |
%30 = getelementptr inbounds %"enum.core::option::Option<f32>[#3]"* %match10, i32 0, i32 0 | |
%31 = load i8* %30, !range !0 | |
switch i8 %31, label %match_else14 [ | |
i8 0, label %match_case15 | |
] | |
case_body11: ; preds = %match_case15 | |
br label %loop_exit8 | |
case_body12: ; preds = %match_else14 | |
%32 = load float** %__llmatch13 | |
%33 = load float* %32 | |
store float %33, float* %v | |
%34 = load float* %sum | |
%35 = load float* %v | |
%36 = fadd float %34, %35 | |
store float %36, float* %sum | |
br label %join16 | |
match_else14: ; preds = %loop_body9 | |
%37 = bitcast %"enum.core::option::Option<f32>[#3]"* %match10 to { i8, float }* | |
%38 = getelementptr inbounds { i8, float }* %37, i32 0, i32 1 | |
store float* %38, float** %__llmatch13 | |
br label %case_body12 | |
match_case15: ; preds = %loop_body9 | |
br label %case_body11 | |
join16: ; preds = %case_body12 | |
br label %loop_body9 | |
join17: ; preds = %loop_exit8 | |
%39 = load float* %sum | |
%40 = fcmp une float %39, 9.600000e+01 | |
%41 = zext i1 %40 to i8 | |
%42 = icmp eq i8 %41, 0 | |
%43 = select i1 %42, i8 1, i8 0 | |
%44 = icmp ne i8 %43, 0 | |
br i1 %44, label %then-block-3181-, label %next-block | |
then-block-3181-: ; preds = %join17 | |
%45 = getelementptr inbounds { %str_slice* }* %9, i32 0, i32 0 | |
%46 = getelementptr inbounds %str_slice* %10, i32 0, i32 0 | |
store i8* getelementptr inbounds ([11 x i8]* @str2497, i32 0, i32 0), i8** %46 | |
%47 = getelementptr inbounds %str_slice* %10, i32 0, i32 1 | |
store i64 11, i64* %47 | |
store %str_slice* %10, %str_slice** %45 | |
%48 = load { %str_slice* }* %9 | |
store { %str_slice* } %48, { %str_slice* }* %match18 | |
%49 = getelementptr inbounds { %str_slice* }* %match18, i32 0, i32 0 | |
store %str_slice** %49, %str_slice*** %__llmatch20 | |
br label %case_body19 | |
case_body19: ; preds = %then-block-3181- | |
%50 = load %str_slice*** %__llmatch20 | |
%51 = load %str_slice** %50 | |
store %str_slice* %51, %str_slice** %__arg0 | |
%52 = bitcast %"struct.std::fmt::Argument[#1]"* %11 to [1 x %"struct.std::fmt::Argument[#1]"]* | |
%53 = getelementptr inbounds %"struct.std::fmt::Argument[#1]"* %11, i32 0 | |
%54 = load %str_slice** %__arg0 | |
call void @_ZN3fmt8argument20h80294545790776888184v0.0E(%"struct.std::fmt::Argument[#1]"* noalias nocapture sret %53, void (%"enum.core::result::Result<(),std::io::IoError>[#3]"*, %str_slice*, %"struct.std::fmt::Formatter[#1]"*)* @_ZN3fmt13secret_string20h57687284095775914444v0.0E, %str_slice* %54) | |
%55 = getelementptr inbounds { %"struct.std::fmt::Argument[#1]"*, i64 }* %__args_vec, i32 0, i32 0 | |
store %"struct.std::fmt::Argument[#1]"* %11, %"struct.std::fmt::Argument[#1]"** %55 | |
%56 = getelementptr inbounds { %"struct.std::fmt::Argument[#1]"*, i64 }* %__args_vec, i32 0, i32 1 | |
store i64 1, i64* %56 | |
%57 = getelementptr inbounds { %"enum.std::fmt::rt::Piece[#1]"*, i64 }* %__adjust, i32 0, i32 0 | |
store %"enum.std::fmt::rt::Piece[#1]"* getelementptr inbounds ([2 x %"enum.std::fmt::rt::Piece[#1]"]* bitcast ({ { i8, { i8*, i64 }, [56 x i8] }, { i8, { { i8, [15 x i8] }, { i32, i8, i64, { i8, [15 x i8] }, { i8, [15 x i8] } }, { i8* } }, [0 x i8] } }* @_ZN4test14vec_speed_vec215__STATIC_FMTSTR20hed05baae85484b14TZa4v0.0E to [2 x %"enum.std::fmt::rt::Piece[#1]"]*), i32 0, i32 0), %"enum.std::fmt::rt::Piece[#1]"** %57 | |
%58 = getelementptr inbounds { %"enum.std::fmt::rt::Piece[#1]"*, i64 }* %__adjust, i32 0, i32 1 | |
store i64 2, i64* %58 | |
%59 = getelementptr inbounds { %"struct.std::fmt::Argument[#1]"*, i64 }* %__args_vec, i32 0, i32 0 | |
%60 = load %"struct.std::fmt::Argument[#1]"** %59 | |
%61 = getelementptr inbounds { %"struct.std::fmt::Argument[#1]"*, i64 }* %__args_vec, i32 0, i32 1 | |
%62 = load i64* %61 | |
%63 = getelementptr inbounds { %"struct.std::fmt::Argument[#1]"*, i64 }* %__adjust21, i32 0, i32 0 | |
store %"struct.std::fmt::Argument[#1]"* %60, %"struct.std::fmt::Argument[#1]"** %63 | |
%64 = getelementptr inbounds { %"struct.std::fmt::Argument[#1]"*, i64 }* %__adjust21, i32 0, i32 1 | |
store i64 %62, i64* %64 | |
call void @"_ZN3fmt22Arguments$LT$$x27a$GT$3new20h2445e004e4ad48b6nvb4v0.0E"(%"struct.std::fmt::Arguments[#1]"* noalias nocapture sret %__args, { %"enum.std::fmt::rt::Piece[#1]"*, i64 }* nocapture %__adjust, { %"struct.std::fmt::Argument[#1]"*, i64 }* nocapture %__adjust21) | |
store %"struct.std::fmt::Arguments[#1]"* %__args, %"struct.std::fmt::Arguments[#1]"** %fmt.i | |
%65 = load %"struct.std::fmt::Arguments[#1]"** %fmt.i | |
%66 = getelementptr inbounds %str_slice* %1, i32 0, i32 0 | |
store i8* getelementptr inbounds ([10 x i8]* @str2205, i32 0, i32 0), i8** %66 | |
%67 = getelementptr inbounds %str_slice* %1, i32 0, i32 1 | |
store i64 10, i64* %67 | |
call void @_ZN2rt6unwind16begin_unwind_fmt20h1360f91e7709ea39KsF9v0.11.preE(%"struct.std::fmt::Arguments[#1]"* nocapture %65, %str_slice* nocapture %1, i64 353) | |
unreachable | |
_ZN4test14vec_speed_vec27run_fmt20h073e9dfb0fdb01b4xZa4v0.0E.exit: ; No predecessors! | |
unreachable | |
join22: ; No predecessors! | |
unreachable | |
next-block: ; preds = %join17 | |
ret void | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rustc new_lib.rs --test --opt-level 3 | |
$ ./new_lib --bench | |
running 2 tests | |
test test::vec_speed_vec1 ... bench: 2299 ns/iter (+/- 21) | |
test test::vec_speed_vec2 ... bench: 5351 ns/iter (+/- 37) | |
test result: ok. 0 passed; 0 failed; 0 ignored; 2 measured |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(globs, macro_rules)] | |
#![crate_type="lib"] | |
#![crate_id="new_lib"] | |
use std::cell::Cell; | |
pub trait VectorGet | |
{ | |
unsafe fn unsafe_get(&self, idx: uint) -> f32; | |
fn get(&self, idx: uint) -> f32; | |
} | |
pub trait VectorSet | |
{ | |
unsafe fn unsafe_set(&self, idx: uint, val: f32); | |
fn set(&self, idx: uint, val: f32); | |
} | |
pub trait VectorAssign<T> | |
{ | |
fn assign(&self, v: T); | |
} | |
pub trait VectorIter | |
{ | |
fn iter2(self) -> VectorIterator<Self>; | |
} | |
impl<LHS: VectorSet + Container, | |
RHS: VectorGet + Container> | |
VectorAssign<RHS> for | |
LHS | |
{ | |
fn assign(&self, v: RHS) | |
{ | |
assert!(self.len() == v.len()); | |
for i in range(0, v.len()) | |
{ | |
unsafe | |
{ | |
self.unsafe_set(i, v.unsafe_get(i)); | |
} | |
} | |
} | |
} | |
impl<T: VectorGet + Container> | |
VectorIter for | |
T | |
{ | |
fn iter2(self) -> VectorIterator<T> | |
{ | |
VectorIterator::new(self) | |
} | |
} | |
pub struct Vector | |
{ | |
data: Vec<Cell<f32>> | |
} | |
impl Vector | |
{ | |
pub fn new(data: &[f32]) -> Vector | |
{ | |
Vector{ data: data.iter().map(|&v| Cell::new(v)).collect() } | |
} | |
} | |
impl | |
FromIterator<f32> for | |
Vector | |
{ | |
fn from_iter<T: Iterator<f32>>(mut it: T) -> Vector | |
{ | |
Vector{ data: it.by_ref().map(|v| Cell::new(v)).collect() } | |
} | |
} | |
impl<'l> | |
VectorGet for | |
&'l Vector | |
{ | |
unsafe fn unsafe_get(&self, idx: uint) -> f32 | |
{ | |
(*self.data.as_slice().unsafe_ref(idx)).get() | |
} | |
fn get(&self, idx: uint) -> f32 | |
{ | |
self.data.get(idx).get() | |
} | |
} | |
impl<'l> | |
Container for | |
&'l Vector | |
{ | |
fn len(&self) -> uint | |
{ | |
self.data.len() | |
} | |
} | |
impl<'l> | |
VectorSet for | |
Vector | |
{ | |
unsafe fn unsafe_set(&self, idx: uint, val: f32) | |
{ | |
self.data.as_slice().unsafe_ref(idx).set(val); | |
} | |
fn set(&self, idx: uint, val: f32) | |
{ | |
self.data.get(idx).set(val); | |
} | |
} | |
impl<'l> | |
Container for | |
Vector | |
{ | |
fn len(&self) -> uint | |
{ | |
self.data.len() | |
} | |
} | |
pub struct VectorIterator<T> | |
{ | |
base: T, | |
idx: uint | |
} | |
impl<T: VectorGet + Container> | |
VectorIterator<T> | |
{ | |
fn new(base: T) -> VectorIterator<T> | |
{ | |
VectorIterator{ base: base, idx: 0 } | |
} | |
} | |
impl<T: VectorGet + Container> | |
Iterator<f32> for | |
VectorIterator<T> | |
{ | |
fn next(&mut self) -> Option<f32> | |
{ | |
let ret = if self.idx < self.base.len() | |
{ | |
unsafe | |
{ | |
Some(self.base.unsafe_get(self.idx)) | |
} | |
} | |
else | |
{ | |
None | |
}; | |
self.idx += 1; | |
ret | |
} | |
} | |
macro_rules! expr | |
{ | |
($e: expr) => { $e } | |
} | |
macro_rules! bin_op | |
{ | |
($op_name: ident, $op_method: ident, $op_struct_name: ident, $op: tt) => | |
{ | |
pub struct $op_struct_name<TA, TB> | |
{ | |
a: TA, | |
b: TB, | |
} | |
impl<TA: Container, | |
TB: Container> | |
$op_struct_name<TA, TB> | |
{ | |
pub unsafe fn unsafe_new(a: TA, b: TB) -> $op_struct_name<TA, TB> | |
{ | |
$op_struct_name{ a: a, b: b } | |
} | |
pub fn new(a: TA, b: TB) -> $op_struct_name<TA, TB> | |
{ | |
assert!(a.len() == b.len()); | |
$op_struct_name{ a: a, b: b } | |
} | |
} | |
impl<TA: Clone, | |
TB: Clone> | |
Clone for | |
$op_struct_name<TA, TB> | |
{ | |
fn clone(&self) -> $op_struct_name<TA, TB> | |
{ | |
$op_struct_name{ a: self.a.clone(), b: self.b.clone() } | |
} | |
} | |
impl<'l, | |
TA: VectorGet + Container, | |
TB: VectorGet + Container> | |
VectorGet for | |
$op_struct_name<TA, TB> | |
{ | |
unsafe fn unsafe_get(&self, idx: uint) -> f32 | |
{ | |
expr!(self.a.unsafe_get(idx) $op self.b.unsafe_get(idx)) | |
} | |
fn get(&self, idx: uint) -> f32 | |
{ | |
assert!(idx < self.len()); | |
unsafe | |
{ | |
expr!(self.a.unsafe_get(idx) $op self.b.unsafe_get(idx)) | |
} | |
} | |
} | |
impl<'l, | |
TA: Container, | |
TB: Container> | |
Container for $op_struct_name<TA, TB> | |
{ | |
fn len(&self) -> uint | |
{ | |
self.a.len() | |
} | |
} | |
impl<'l, | |
RHS: VectorGet + Clone + Container> | |
$op_name<RHS, $op_struct_name<&'l Vector, RHS>> for | |
&'l Vector | |
{ | |
fn $op_method(&self, rhs: &RHS) -> $op_struct_name<&'l Vector, RHS> | |
{ | |
$op_struct_name::new(self.clone(), rhs.clone()) | |
} | |
} | |
} | |
} | |
macro_rules! connect_op | |
{ | |
($op_struct_lhs: ident : $($op_name: ident, $op_method: ident, $op_struct_name: ident);+) => | |
{ | |
$( | |
impl<RHS: VectorGet + Clone + Container, | |
TA: VectorGet + Clone + Container, | |
TB: VectorGet + Clone + Container> | |
$op_name<RHS, $op_struct_name<$op_struct_lhs<TA, TB>, RHS>> for | |
$op_struct_lhs<TA, TB> | |
{ | |
fn $op_method(&self, rhs: &RHS) -> $op_struct_name<$op_struct_lhs<TA, TB>, RHS> | |
{ | |
$op_struct_name::new(self.clone(), rhs.clone()) | |
} | |
} | |
)+ | |
} | |
} | |
macro_rules! connect_ops | |
{ | |
($($op_struct: ident),+) => | |
{ | |
$( | |
connect_op!($op_struct: | |
Add, add, Adder; | |
Sub, sub, Subtracter; | |
Mul, mul, Multiplier; | |
Div, div, Divider) | |
)+ | |
} | |
} | |
bin_op!(Add, add, Adder, +) | |
bin_op!(Sub, sub, Subtracter, -) | |
bin_op!(Mul, mul, Multiplier, *) | |
bin_op!(Div, div, Divider, /) | |
connect_ops!(Adder, | |
Subtracter, | |
Multiplier, | |
Divider) | |
#[cfg(test)] | |
mod test | |
{ | |
extern crate test; | |
extern crate rand; | |
use super::*; | |
use self::test::Bencher; | |
use self::rand::{weak_rng, Rng}; | |
fn bug(a: &Vector) | |
{ | |
for _ in range(0, 100) | |
{ | |
a.assign((a + a * a) / a); | |
} | |
let mut sum = 0f32; | |
for v in a.iter2() | |
{ | |
sum += v; | |
} | |
assert!(sum != 96.0); | |
} | |
#[bench] | |
fn vec_speed_vec1(bh: &mut Bencher) { | |
let mut rng = weak_rng(); | |
let a = &Vector::new(rng.gen_vec(10).slice(0, 10)); | |
bh.iter(|| { | |
bug(a) | |
}) | |
} | |
#[bench] | |
fn vec_speed_vec2(bh: &mut Bencher) { | |
let mut rng = weak_rng(); | |
let a = &Vector::new(rng.gen_vec(10).slice(0, 10)); | |
bh.iter(|| { | |
for _ in range(0, 100) | |
{ | |
a.assign((a + a * a) / a); | |
} | |
let mut sum = 0f32; | |
for v in a.iter2() | |
{ | |
sum += v; | |
} | |
assert!(sum != 96.0); | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment