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