flat assembler
Message board for the users of flat assembler.
Index
> Main > Convert text to SSE2 code ! Breaking your brain :) Goto page Previous 1, 2 
Author 

tthsqe
Roman, I don't see how removing parentheses is going to help you evaluate your expression.
Here is what I am talking about: First, we define a function RegCount which gives the minimum number of registers necessary to evaluate an expression. It can be calculated by calling the following function on the root of the tree. Code: RegCount(node x): if x.ChildCount = 0, ; if we are at a leaf number x.RegCount = 1, ; then we need 1 register to load this number else call RegCount on all of the children of x and put the results into a list S; sort S in decreasing order; for 0 <= i < x.ChildCount, do S[i] += i; x.RegCount = max(S) end if return x.RegCount If you call this on the root, then the RegCount member of each node will be filled in. Now, when you are generating code, start at the root and handle the children in decreasing order of their RegCount member. This will insure that the minimum number of registers is used. In the parsing phase, operators with more than 2 operands should should be left associated into binary operators, since we can't operate on more than two numbers at a time in x86. EX: 2+2/(1+4*4)/17 Code: Tree: '+' / \ / \ '2' '/' /  \ /  \ /  \ '2'  '17' '+' / \ / \ / \ '1' '*' / \ / \ / \ '4' '4' RegCount: 3 / \ / \ 1 3 /  \ /  \ /  \ 1  1 2 / \ / \ / \ 1 2 / \ / \ / \ 1 1 RegAlloc: x1 / \ / \ x2 x1 /  \ /  \ /  \ x2  x3 x1 / \ / \ / \ x2 x1 / \ / \ / \ x1 x2 Code: x1 = 4 x2 = 4 x1 = x1 * x2 x2 = 1 x1 = x2 + x1 x2 = 2 x3 = 17 x1 = x2 / x1 / x3 x2 = 2 x1 = x2 + x1 

27 Jul 2013, 05:52 

pabloreda
Roman:
if you have the expresion in postfix notation is the same of forth notation. an optimiced forth compile try to hold in registers the cells on stack. it's all. operations between constant numbers in the tree not have sense, first evaluate and then compile. 

29 Jul 2013, 12:28 

Goto page Previous 1, 2 < Last Thread  Next Thread > 
Forum Rules:

Copyright © 19992020, Tomasz Grysztar. Also on YouTube, Twitter.
Website powered by rwasa.