From 400b00aa87a98f0601a566f94038d2b2197aae1a Mon Sep 17 00:00:00 2001 From: Laban Kimotho Date: Fri, 24 Jan 2014 10:59:53 +0200 Subject: typo fixes + view generated low level code --- julia.html.markdown | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 2 deletions(-) (limited to 'julia.html.markdown') diff --git a/julia.html.markdown b/julia.html.markdown index 4b946d46..58ff7608 100644 --- a/julia.html.markdown +++ b/julia.html.markdown @@ -427,7 +427,7 @@ end keyword_args(name2="ness") #=> ["name2"=>"ness","k1"=>4] keyword_args(k1="mine") #=> ["k1"=>"mine","name2"=>"hello"] -keyword_args() #=> ["name2"=>"hello","k2"=>4] +keyword_args() #=> ["name2"=>"hello","k1"=>4] # You can combine all kinds of arguments in the same function function all_the_args(normal_arg, optional_positional_arg=2; keyword_arg="foo") @@ -560,7 +560,7 @@ type Panther <: Cat # Panther is also a subtype of Cat Panther() = new("green") # Panthers will only have this constructor, and no default constructor. end -# Using inner constructors, like Panter does, gives you control +# Using inner constructors, like Panther does, gives you control # over how values of the type can be created. # When possible, you should use outer constructors rather than inner ones. @@ -657,6 +657,81 @@ fight(Lion("RAR"),Lion("brown","rarrr")) #=> prints The victorious cat says rarr fight(l::Lion,l2::Lion) = println("The lions come to a tie") fight(Lion("RAR"),Lion("brown","rarrr")) #=> prints The lions come to a tie + +# Under the hood +# You can take a look at the llvm intermediate code and the assembly code generated. + +square_area(l) = l * l # square_area (generic function with 1 method) + +square_area(5) #25 + +code_native(square_area, (Int32,)) # What happens when we feed square_area an integer? + # .section __TEXT,__text,regular,pure_instructions + # Filename: none + # Source line: 1 # Prologue + # push RBP + # mov RBP, RSP + # Source line: 1 + # movsxd RAX, EDI # Fetch l from memory? + # imul RAX, RAX # 32bit square of l and store the result in RAX + # pop RBP # Restore old base pointer + # ret # Result will still be in RAX + +code_native(square_area, (Float32,)) + # .section __TEXT,__text,regular,pure_instructions + # Filename: none + # Source line: 1 + # push RBP + # mov RBP, RSP + # Source line: 1 + # vmulss XMM0, XMM0, XMM0 # Scalar single precision multiplication (AVX) (in this case square the number) + # pop RBP + # ret + +code_native(square_area, (Float64,)) + # .section __TEXT,__text,regular,pure_instructions + # Filename: none + # Source line: 1 + # push RBP + # mov RBP, RSP + # Source line: 1 + # vmulsd XMM0, XMM0, XMM0 # Scalar double precision multiplacation (AVX) + # pop RBP + # ret + # +# Note that julia will use floating point instructions if any of the arguements are floats. +# Let's calculate the area of a circle +circle_area(r) = pi * r * r # circle_area (generic function with 1 method) +circle_area(5) # 78.53981633974483 + +code_native(circle_area, (Int32,)) + # .section __TEXT,__text,regular,pure_instructions + # Filename: none + # Source line: 1 + # push RBP + # mov RBP, RSP + # Source line: 1 + # vcvtsi2sd XMM0, XMM0, EDI # Load integer (r) from memory + # movabs RAX, 4593140240 # Load pi + # vmulsd XMM1, XMM0, QWORD PTR [RAX] # pi * r + # vmulsd XMM0, XMM0, XMM1 # (pi * r) * r + # pop RBP + # ret + # + +code_native(circle_area, (Float64,)) + # .section __TEXT,__text,regular,pure_instructions + # Filename: none + # Source line: 1 + # push RBP + # mov RBP, RSP + # movabs RAX, 4593140496 + # Source line: 1 + # vmulsd XMM1, XMM0, QWORD PTR [RAX] + # vmulsd XMM0, XMM1, XMM0 + # pop RBP + # ret + # ``` ## Further Reading -- cgit v1.2.3 From c705d16a3e0b49f274564b3e61faa219ab63bd78 Mon Sep 17 00:00:00 2001 From: Laban Kimotho Date: Fri, 24 Jan 2014 11:06:41 +0200 Subject: style fixes --- julia.html.markdown | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'julia.html.markdown') diff --git a/julia.html.markdown b/julia.html.markdown index 58ff7608..3bc660cf 100644 --- a/julia.html.markdown +++ b/julia.html.markdown @@ -659,23 +659,24 @@ fight(Lion("RAR"),Lion("brown","rarrr")) #=> prints The lions come to a tie # Under the hood -# You can take a look at the llvm intermediate code and the assembly code generated. +# You can take a look at the llvm and the assembly code generated. square_area(l) = l * l # square_area (generic function with 1 method) square_area(5) #25 -code_native(square_area, (Int32,)) # What happens when we feed square_area an integer? +# What happens when we feed square_area an integer? +code_native(square_area, (Int32,)) # .section __TEXT,__text,regular,pure_instructions # Filename: none - # Source line: 1 # Prologue + # Source line: 1 # Prologue # push RBP # mov RBP, RSP # Source line: 1 - # movsxd RAX, EDI # Fetch l from memory? - # imul RAX, RAX # 32bit square of l and store the result in RAX - # pop RBP # Restore old base pointer - # ret # Result will still be in RAX + # movsxd RAX, EDI # Fetch l from memory? + # imul RAX, RAX # Square l and store the result in RAX + # pop RBP # Restore old base pointer + # ret # Result will still be in RAX code_native(square_area, (Float32,)) # .section __TEXT,__text,regular,pure_instructions @@ -684,7 +685,7 @@ code_native(square_area, (Float32,)) # push RBP # mov RBP, RSP # Source line: 1 - # vmulss XMM0, XMM0, XMM0 # Scalar single precision multiplication (AVX) (in this case square the number) + # vmulss XMM0, XMM0, XMM0 # Scalar single precision multiply (AVX) # pop RBP # ret @@ -695,11 +696,12 @@ code_native(square_area, (Float64,)) # push RBP # mov RBP, RSP # Source line: 1 - # vmulsd XMM0, XMM0, XMM0 # Scalar double precision multiplacation (AVX) + # vmulsd XMM0, XMM0, XMM0 # Scalar double precision multiply (AVX) # pop RBP # ret # -# Note that julia will use floating point instructions if any of the arguements are floats. +# Note that julia will use floating point instructions if any of the +# arguements are floats. # Let's calculate the area of a circle circle_area(r) = pi * r * r # circle_area (generic function with 1 method) circle_area(5) # 78.53981633974483 @@ -711,10 +713,10 @@ code_native(circle_area, (Int32,)) # push RBP # mov RBP, RSP # Source line: 1 - # vcvtsi2sd XMM0, XMM0, EDI # Load integer (r) from memory - # movabs RAX, 4593140240 # Load pi - # vmulsd XMM1, XMM0, QWORD PTR [RAX] # pi * r - # vmulsd XMM0, XMM0, XMM1 # (pi * r) * r + # vcvtsi2sd XMM0, XMM0, EDI # Load integer (r) from memory + # movabs RAX, 4593140240 # Load pi + # vmulsd XMM1, XMM0, QWORD PTR [RAX] # pi * r + # vmulsd XMM0, XMM0, XMM1 # (pi * r) * r # pop RBP # ret # -- cgit v1.2.3