/ externals / xbyak / test / test_mmx.cpp
test_mmx.cpp
 1  #if defined(_MSC_VER) && (_MSC_VER <= 1200)
 2  	#pragma warning(disable:4514)
 3  	#pragma warning(disable:4786)
 4  #endif
 5  #include <stdio.h>
 6  #include <stdlib.h>
 7  #include "../../include.mie/mie_thread.h"
 8  #include "xbyak/xbyak.h"
 9  
10  class WriteMMX : public Xbyak::CodeGenerator {
11  public:
12  	WriteMMX()
13  	{
14  #ifdef XBYAK32
15  		mov(ecx, ptr [esp + 4]);
16  #endif
17  		movd(mm0, ecx);
18  		ret();
19  	}
20  	void (*set() const)(int x) { return (void (*)(int x))getCode(); }
21  };
22  
23  class ReadMMX : public Xbyak::CodeGenerator {
24  public:
25  	ReadMMX()
26  	{
27  		movd(eax, mm0);
28  		ret();
29  	}
30  	int (*get() const)() { return (int (*)())getCode(); }
31  };
32  
33  class Test : public MIE::ThreadBase<Test> {
34  	int n_;
35  public:
36  	Test(int n)
37  		: n_(n)
38  	{
39  	}
40  	void threadEntry()
41  	{
42  		printf("n=%d\n", n_);
43  		WriteMMX w;
44  		w.set()(n_);
45  		ReadMMX r;
46  		for (;;) {
47  			int b = r.get()();
48  			printf("b=%d\n", b);
49  			if (b != n_) {
50  				printf("mm0 has changed!\n");
51  			}
52  			MIE::MIE_Sleep(1000);
53  		}
54  	}
55  	void stopThread() { }
56  };
57  
58  int main(int argc, char *argv[])
59  {
60  #ifdef XBYAK32
61  	puts("32bit");
62  #else
63  	puts("64bit");
64  #endif
65  	try {
66  		int n = atoi(argc == 1 ? "1223" : argv[1]);
67  		Test test0(n), test1(n + 1);
68  		test0.beginThread();
69  		test1.beginThread();
70  
71  		test0.joinThread();
72  		test1.joinThread();
73  	} catch (std::exception& e) {
74  		printf("ERR:%s\n", e.what());
75  	} catch (...) {
76  		printf("unknown error\n");
77  	}
78  }