1 #include <stdio.h>
2 #include <stdint.h>
3 
4 #include "private/pixelflinger/ggl_context.h"
5 
6 #include "buffer.h"
7 #include "scanline.h"
8 
9 #include "codeflinger/CodeCache.h"
10 #include "codeflinger/GGLAssembler.h"
11 #include "codeflinger/ARMAssembler.h"
12 #if defined(__mips__) && !defined(__LP64__) && __mips_isa_rev < 6
13 #include "codeflinger/MIPSAssembler.h"
14 #endif
15 #include "codeflinger/Arm64Assembler.h"
16 
17 #if defined(__arm__) || (defined(__mips__) && !defined(__LP64__) && __mips_isa_rev < 6) || defined(__aarch64__)
18 #   define ANDROID_ARM_CODEGEN  1
19 #else
20 #   define ANDROID_ARM_CODEGEN  0
21 #endif
22 
23 #if defined(__mips__) && !defined(__LP64__) && __mips_isa_rev < 6
24 #define ASSEMBLY_SCRATCH_SIZE   4096
25 #elif defined(__aarch64__)
26 #define ASSEMBLY_SCRATCH_SIZE   8192
27 #else
28 #define ASSEMBLY_SCRATCH_SIZE   2048
29 #endif
30 
31 using namespace android;
32 
33 class ScanlineAssembly : public Assembly {
34     AssemblyKey<needs_t> mKey;
35 public:
ScanlineAssembly(needs_t needs,size_t size)36     ScanlineAssembly(needs_t needs, size_t size)
37         : Assembly(size), mKey(needs) { }
key() const38     const AssemblyKey<needs_t>& key() const { return mKey; }
39 };
40 
ggl_test_codegen(uint32_t n,uint32_t p,uint32_t t0,uint32_t t1)41 static void ggl_test_codegen(uint32_t n, uint32_t p, uint32_t t0, uint32_t t1)
42 {
43 #if ANDROID_ARM_CODEGEN
44     GGLContext* c;
45     gglInit(&c);
46     needs_t needs;
47     needs.n = n;
48     needs.p = p;
49     needs.t[0] = t0;
50     needs.t[1] = t1;
51     sp<ScanlineAssembly> a(new ScanlineAssembly(needs, ASSEMBLY_SCRATCH_SIZE));
52 
53 #if defined(__arm__)
54     GGLAssembler assembler( new ARMAssembler(a) );
55 #endif
56 
57 #if defined(__mips__) && !defined(__LP64__) && __mips_isa_rev < 6
58     GGLAssembler assembler( new ArmToMipsAssembler(a) );
59 #endif
60 
61 #if defined(__aarch64__)
62     GGLAssembler assembler( new ArmToArm64Assembler(a) );
63 #endif
64 
65     int err = assembler.scanline(needs, (context_t*)c);
66     if (err != 0) {
67         printf("error %08x (%s)\n", err, strerror(-err));
68     }
69     gglUninit(c);
70 #else
71     printf("This test runs only on ARM, Arm64 or MIPS\n");
72 #endif
73 }
74 
main(int argc,char ** argv)75 int main(int argc, char** argv)
76 {
77     if (argc != 2) {
78         printf("usage: %s 00000117:03454504_00001501_00000000\n", argv[0]);
79         return 0;
80     }
81     uint32_t n;
82     uint32_t p;
83     uint32_t t0;
84     uint32_t t1;
85     sscanf(argv[1], "%08x:%08x_%08x_%08x", &p, &n, &t0, &t1);
86     ggl_test_codegen(n, p,  t0, t1);
87     return 0;
88 }
89