freetype/truetype: odd/even opcodes.
Also re-arrange some of the switch cases to be in opcode order. R=bsiegert CC=golang-dev http://codereview.appspot.com/6352097
This commit is contained in:
parent
20ce6ab4df
commit
f2517f3940
3 changed files with 37 additions and 13 deletions
|
@ -251,16 +251,9 @@ func (h *hinter) run(program []byte) error {
|
|||
top--
|
||||
h.stack[top-1] = bool2int32(h.stack[top-1] != h.stack[top])
|
||||
|
||||
case opAND:
|
||||
top--
|
||||
h.stack[top-1] = bool2int32(h.stack[top-1] != 0 && h.stack[top] != 0)
|
||||
|
||||
case opOR:
|
||||
top--
|
||||
h.stack[top-1] = bool2int32(h.stack[top-1]|h.stack[top] != 0)
|
||||
|
||||
case opNOT:
|
||||
h.stack[top-1] = bool2int32(h.stack[top-1] == 0)
|
||||
case opODD, opEVEN:
|
||||
i := h.round(f26dot6(h.stack[top-1])) >> 6
|
||||
h.stack[top-1] = int32(i&1) ^ int32(opcode-opODD)
|
||||
|
||||
case opIF:
|
||||
top--
|
||||
|
@ -272,6 +265,17 @@ func (h *hinter) run(program []byte) error {
|
|||
case opEIF:
|
||||
// No-op.
|
||||
|
||||
case opAND:
|
||||
top--
|
||||
h.stack[top-1] = bool2int32(h.stack[top-1] != 0 && h.stack[top] != 0)
|
||||
|
||||
case opOR:
|
||||
top--
|
||||
h.stack[top-1] = bool2int32(h.stack[top-1]|h.stack[top] != 0)
|
||||
|
||||
case opNOT:
|
||||
h.stack[top-1] = bool2int32(h.stack[top-1] == 0)
|
||||
|
||||
case opADD:
|
||||
top--
|
||||
h.stack[top-1] += h.stack[top]
|
||||
|
|
|
@ -187,6 +187,26 @@ func TestBytecode(t *testing.T) {
|
|||
[]int32{1, 0},
|
||||
"",
|
||||
},
|
||||
{
|
||||
"odd/even",
|
||||
// Calculate odd(2+31/64), odd(2+32/64), even(2), even(1).
|
||||
[]byte{
|
||||
opPUSHB000, // [159]
|
||||
159,
|
||||
opODD, // [0]
|
||||
opPUSHB000, // [0, 160]
|
||||
160,
|
||||
opODD, // [0, 1]
|
||||
opPUSHB000, // [0, 1, 128]
|
||||
128,
|
||||
opEVEN, // [0, 1, 1]
|
||||
opPUSHB000, // [0, 1, 1, 64]
|
||||
64,
|
||||
opEVEN, // [0, 1, 1, 0]
|
||||
},
|
||||
[]int32{0, 1, 1, 0},
|
||||
"",
|
||||
},
|
||||
{
|
||||
"if true",
|
||||
[]byte{
|
||||
|
|
|
@ -96,8 +96,8 @@ const (
|
|||
opGTEQ = 0x53 // Greater Than or EQual
|
||||
opEQ = 0x54 // EQual
|
||||
opNEQ = 0x55 // Not EQual
|
||||
opODD = 0x56
|
||||
opEVEN = 0x57
|
||||
opODD = 0x56 // ODD
|
||||
opEVEN = 0x57 // EVEN
|
||||
opIF = 0x58 // IF test
|
||||
opEIF = 0x59 // End IF
|
||||
opAND = 0x5a // logical AND
|
||||
|
@ -276,7 +276,7 @@ var popCount = [256]uint8{
|
|||
1, 1, 0, 2, 0, 1, 1, q, q, q, q, q, q, q, q, q, // 0x20 - 0x2f
|
||||
q, q, q, q, q, q, q, q, q, q, q, q, q, 0, q, q, // 0x30 - 0x3f
|
||||
0, 0, 2, 1, q, q, q, q, q, q, q, q, q, q, q, 0, // 0x40 - 0x4f
|
||||
2, 2, 2, 2, 2, 2, q, q, 1, 0, 2, 2, 1, q, q, q, // 0x50 - 0x5f
|
||||
2, 2, 2, 2, 2, 2, 1, 1, 1, 0, 2, 2, 1, q, q, q, // 0x50 - 0x5f
|
||||
2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 - 0x6f
|
||||
q, q, q, q, q, q, 1, 1, 2, 2, 0, q, 0, 0, 1, 1, // 0x70 - 0x7f
|
||||
q, q, q, q, q, q, q, q, q, 1, 3, 2, 2, q, q, q, // 0x80 - 0x8f
|
||||
|
|
Loading…
Reference in a new issue