【正文】
treelike fashion ? permuteArguments() ? collectArguments() ? filterArguments() ? filterReturn() ? Method Handles have added benefits (high level models matter!) ? We’ve already observed good code with Method Handles, so let’s try it! ? Coding this way can elide the need to box Long2/4/8? 32 Software and Services Group Expressions Bind to Method Handles. 33 * + y y x (x,y) MHm256_vaddps MHm256_vmulps x y AST Visitor Software and Services Group There’s more!! 34 * + y y x (x,y) MHm256_vaddps MHm256_vmulps x y 256_visitor MHm128_vaddps MHm128_vmulps x y MHmXYZ_vaddps MHmXYZ_vmulps x y 128_visitor XYZ_visitor Software and Services Group Baby’s First EDSL interface ExpressionE { default ExpressionE add(ExpressionE right){return new AddExpression(this,right)。} default ExpressionE mul(ExpressionE right){return new MulExpression(this,right)。} default ExpressionE not(){return new NotExpression(this)。 … default ExpressionE trace(ConsumerE f){return new TraceExpression(this,f)。} … default ExpressionFloat fromFloat(Float f){return new ConstExpression(f)。} … R R evaluate(ExpressionEvaluatorE,R e)。 } 35 Careful! Software and Services Group BinaryOperationExpressionFloat expr = (l,r) { ExpressionFloat e1 = (r)。 return (r)。 } 36 (,)。 To populate leaf nodes. Symbol nonpublic. Software and Services Group MethodHandle binaryReduction(float[] left, float[] right, float[] dst, BinaryOperatorExprFloat)。 MethodHandle br = binaryReduction(left,right,dst,(l,r) { ExpressionFloat e1 = (r)。 return (r)。 })。 //Execute the entire putation ()。 //Making it hot for inspection for(int i = 0。 i BIGNUMBER。 i++) () 37 Software and Services Group 38 Loads Array Base Addrs Software and Services Group 39 Vectorized Add Store Loop Bookkeeping Vectorized Mul Software and Services Group Why Not Just Expression Trees? ? Reasoning about a vector putation in an elementwise fashion is great, but has a tradeoff. ? Control flow is tricky ? Branching on element N, but N+1 doesn’t want to branch, and it’s in the same vector! ? Masking operations can help some for ternarystyle branching. TBD. ? The Vector API remains important for precise control ? Finegrained control with course grained data ? Coursegrained control with fine grained data 40 Wrap Up Software and Services Group Challenges to an Idiomatic Design ? Elements are (currently) boxed by the (current) nature of generics ? Value types can help ? Handspecialization to get away from boxing ? Immutability is facilitated by new or a constructor encapsulating it ? Escape analysis must work well at all times in the current paradigm. ? Tight loops + large data sets with no escape analysis = a lot of garbage. ? “Optimizations assemantics” seems risky, but could bridge us to value types. ? “Idiomatic” is a moving target in Java. ? Value types will make our lives easier, but they’re not quite here yet! ? Functional idioms are being more mon, but APIs need to be approachable Software and Services Group Continuing Work ? Enhancing the baseline Vector API ? Removing Excessive boxing and preventing codegen artifacting ? Establishing the “minimum viable” API ? Exploring higher order functionality more ? What’s the right approach? ? Analyzing flexibility vs code quality tradeoffs still ? Reporting back at JavaOne! 43 Software and Services Group Interested? ? Check out the Panama Project! ? Discussion on panamadev. ? ? Vector API Code: ? jdk/test/panama/vectorapipatchable ? Prototype Implementation ? Runs on x8664 ABIpliant using AVX2 ? Unixbased platforms currently