[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ft-devel] Question about TTF
From: |
Werner LEMBERG |
Subject: |
Re: [ft-devel] Question about TTF |
Date: |
Thu, 24 May 2018 06:57:27 +0200 (CEST) |
> We translate the bytecode to IR by symbolic execution. So, for
> now, we try every function, (i.e., try one, if it works, mark it
> as a candidate then restore the states before call instruction
> and try the next...). I don't think it's a good idea though.
I don't have sufficient knowledge to have an opinion here :-)
> But how do you translate
>
> (4096 DIV MIN(MAX(0, 64 SUB F26Dot6)
>
> into
>
> min(max(round(x) - 1.0, 0), 3) + 44
OK, step by step now.
// function 17, expecting (at least) one argument, `x'
//
// bytecode stack comment
// -----------------------------------------------------
PUSH[ ]
17 // 17 x
FDEF[ ] // define function 17
DUP[ ] // x x
ROUND[01] // round(x) x
PUSHB[ ]
64 // 64 round(x) x int(64) = 1.0
SUB[ ] // round(x)-1 x a = round(x) - 1
PUSHB[ ]
0 // 0 a x
MAX[ ] // b x b = max(0.0, x)
DUP[ ] // b b x
PUSHB[ ]
44 192 // 192 44 b b x
ROLL[ ] // b 192 44 b x int(192) = 3.0
MIN[ ] // c 44 b x c = min(3.0, b)
PUSHW[ ]
4096 // 4096 c 44 b x int(4096) = 64.0
DIV[ ] // d 44 b x d = int(c) [*]
ADD[ ] // e b x e = 44 + d
CALL[ ] // call function e with (at
// least) args b and x on the
// stack
...
[*] The DIV operator divides a 26.6 number by another 26.6 number,
returning the result in 26.6 format. In other words, it always
multiplies the division result by 64 to achieve that.
To convert from 26.6 to 32.0 format, we have to divide by 64.
To compensate the internal multiplication by 64, we have to
give 64 * 64 = 4096 as the value.
Werner