1 #include "DivTest.h"
2 #include "MemStream.h"
3 
4 #define VALUE_REL0	(0xFFFF8000)
5 #define VALUE_REL1	(0x8000FFFF)
6 #define VALUE_CST0	(0x80004040)
7 #define VALUE_CST1	(0x40408000)
8 
CDivTest(bool isSigned)9 CDivTest::CDivTest(bool isSigned)
10 : m_isSigned(isSigned)
11 {
12 
13 }
14 
Run()15 void CDivTest::Run()
16 {
17 	memset(&m_context, 0, sizeof(m_context));
18 
19 	m_context.relArg0 = VALUE_REL0;
20 	m_context.relArg1 = VALUE_REL1;
21 
22 	m_function(&m_context);
23 
24 	if(m_isSigned)
25 	{
26 		TEST_VERIFY(m_context.cstResultLo == static_cast<int32>(VALUE_CST0) / static_cast<int32>(VALUE_CST1));
27 		TEST_VERIFY(m_context.cstResultHi == static_cast<int32>(VALUE_CST0) % static_cast<int32>(VALUE_CST1));
28 
29 		TEST_VERIFY(m_context.relResultLo == static_cast<int32>(VALUE_REL0) / static_cast<int32>(VALUE_REL1));
30 		TEST_VERIFY(m_context.relResultHi == static_cast<int32>(VALUE_REL0) % static_cast<int32>(VALUE_REL1));
31 	}
32 	else
33 	{
34 		TEST_VERIFY(m_context.cstResultLo == static_cast<uint32>(VALUE_CST0) / static_cast<uint32>(VALUE_CST1));
35 		TEST_VERIFY(m_context.cstResultHi == static_cast<uint32>(VALUE_CST0) % static_cast<uint32>(VALUE_CST1));
36 
37 		TEST_VERIFY(m_context.relResultLo == static_cast<uint32>(VALUE_REL0) / static_cast<uint32>(VALUE_REL1));
38 		TEST_VERIFY(m_context.relResultHi == static_cast<uint32>(VALUE_REL0) % static_cast<uint32>(VALUE_REL1));
39 	}
40 }
41 
Compile(Jitter::CJitter & jitter)42 void CDivTest::Compile(Jitter::CJitter& jitter)
43 {
44 	Framework::CMemStream codeStream;
45 	jitter.SetStream(&codeStream);
46 
47 	jitter.Begin();
48 	{
49 		//Cst x Cst
50 		jitter.PushCst(VALUE_CST0);
51 		jitter.PushCst(VALUE_CST1);
52 
53 		if(m_isSigned)
54 		{
55 			jitter.DivS();
56 		}
57 		else
58 		{
59 			jitter.Div();
60 		}
61 
62 		jitter.PushTop();
63 
64 		jitter.ExtLow64();
65 		jitter.PullRel(offsetof(CONTEXT, cstResultLo));
66 
67 		jitter.ExtHigh64();
68 		jitter.PullRel(offsetof(CONTEXT, cstResultHi));
69 
70 		//Rel x Rel
71 		jitter.PushRel(offsetof(CONTEXT, relArg0));
72 		jitter.PushRel(offsetof(CONTEXT, relArg1));
73 
74 		if(m_isSigned)
75 		{
76 			jitter.DivS();
77 		}
78 		else
79 		{
80 			jitter.Div();
81 		}
82 
83 		jitter.PushTop();
84 
85 		jitter.ExtLow64();
86 		jitter.PullRel(offsetof(CONTEXT, relResultLo));
87 
88 		jitter.ExtHigh64();
89 		jitter.PullRel(offsetof(CONTEXT, relResultHi));
90 	}
91 	jitter.End();
92 
93 	m_function = CMemoryFunction(codeStream.GetBuffer(), codeStream.GetSize());
94 }
95