OSDN Git Service

opengl: Implement fast tls forwarders for x86
authorChih-Wei Huang <cwhuang@linux.org.tw>
Wed, 25 Sep 2013 18:13:32 +0000 (02:13 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Mon, 9 Dec 2013 14:32:12 +0000 (22:32 +0800)
Based on android-ia and rebased to KitKat.

opengl/libs/EGL/getProcAddress.cpp
opengl/libs/GLES2/gl2.cpp
opengl/libs/GLES_CM/gl.cpp

index add2a79..76ed538 100644 (file)
@@ -56,6 +56,45 @@ namespace android {
             :                                                   \
             );
 
+#elif defined(__i386__)
+
+        /* Tell gcc 4.4+ to always omit the frame pointer to have working code
+         * independ of compiler flag
+         */
+        #define API_ENTRY(_api) __attribute__((noinline))            \
+                __attribute__((optimize("omit-frame-pointer")))      \
+                _api
+
+        /* pop %%ebp only because x86 doesn't support naked functions */
+        /* 4.4+ supports __attribute__((optimize)) that disable function
+         * prologues
+         */
+        #if __GNUC__ < 4 || \
+        (__GNUC__ == 4 && __GNUC_MINOR__ < 4 )
+             #define PROLOGUE  "pop %%ebp   \n"
+        #else
+             #define PROLOGUE  ""
+        #endif
+
+        #define CALL_GL_EXTENSION_API(_api)                         \
+            asm volatile(                                           \
+                PROLOGUE                                            \
+                "movl %%gs:0, %%ecx         \n"                     \
+                "movl %c[tls](%%ecx), %%eax \n"                     \
+                "test %%eax, %%eax          \n"                     \
+                "je out" #_api "            \n"                     \
+                "movl %c[api](%%eax), %%ecx \n"                     \
+                "test %%ecx, %%ecx          \n"                     \
+                "je out" #_api "            \n"                     \
+                "jmp *%%ecx                 \n"                     \
+                "out" #_api ": ret          \n"                     \
+                :                                                   \
+                : [tls] "i"(TLS_SLOT_OPENGL_API*4),                 \
+                  [api] "i"(__builtin_offsetof(gl_hooks_t,          \
+                                          ext.extensions[_api]))    \
+                :                                                   \
+                );
+
 #elif defined(__mips__)
 
         #define API_ENTRY(_api) __attribute__((noinline)) _api
index 3134e56..a56f12d 100644 (file)
@@ -58,6 +58,42 @@ using namespace android;
             :                                                   \
             );
 
+#elif defined(__i386__) && !USE_SLOW_BINDING
+
+    /* Tell gcc 4.4+ to always omit the frame pointer to have working code
+     * independ of compiler flag
+     */
+    #define API_ENTRY(_api) __attribute__((noinline))            \
+            __attribute__((optimize("omit-frame-pointer")))      \
+            _api
+
+    /* pop %%ebp only because x86 doesn't support naked functions */
+    /* 4.4+ supports __attribute__((optimize)) that disable function
+     * prologues
+     */
+    #if __GNUC__ < 4 || \
+    (__GNUC__ == 4 && __GNUC_MINOR__ < 4 )
+         #define PROLOGUE  "pop %%ebp   \n"
+    #else
+         #define PROLOGUE  ""
+    #endif
+
+    #define CALL_GL_API(_api, ...)                              \
+        asm volatile(                                           \
+            PROLOGUE                                            \
+            "movl %%gs:0, %%ecx         \n"                     \
+            "movl %c[tls](%%ecx), %%eax \n"                     \
+            "test %%eax, %%eax          \n"                     \
+            "je out" #_api "            \n"                     \
+            "movl %c[api](%%eax), %%ecx \n"                     \
+            "jmp *%%ecx                 \n"                     \
+            "out" #_api ": ret          \n"                     \
+            :                                                   \
+            : [tls] "i"(TLS_SLOT_OPENGL_API*4),                 \
+              [api] "i"(__builtin_offsetof(gl_hooks_t, gl._api))    \
+            :                                                   \
+            );
+
 #elif defined(__mips__) && !USE_SLOW_BINDING
 
     #define API_ENTRY(_api) __attribute__((noinline)) _api
index 18ef6f9..ad8f506 100644 (file)
@@ -110,6 +110,42 @@ GL_API void GL_APIENTRY glWeightPointerOESBounds(GLint size, GLenum type,
             :                                                   \
             );
 
+#elif defined(__i386__) && !USE_SLOW_BINDING
+
+    /* Tell gcc 4.4+ to always omit the frame pointer to have working code
+     * independ of compiler flag
+     */
+    #define API_ENTRY(_api) __attribute__((noinline))            \
+            __attribute__((optimize("omit-frame-pointer")))      \
+            _api
+
+    /* pop %%ebp only because x86 doesn't support naked functions */
+    /* 4.4+ supports __attribute__((optimize)) that disable function
+     * prologues
+     */
+    #if __GNUC__ < 4 || \
+    (__GNUC__ == 4 && __GNUC_MINOR__ < 4 )
+         #define PROLOGUE  "pop %%ebp   \n"
+    #else
+         #define PROLOGUE  ""
+    #endif
+
+    #define CALL_GL_API(_api, ...)                              \
+        asm volatile(                                           \
+            PROLOGUE                                            \
+            "movl %%gs:0, %%ecx         \n"                     \
+            "movl %c[tls](%%ecx), %%eax \n"                     \
+            "test %%eax, %%eax          \n"                     \
+            "je out" #_api "            \n"                     \
+            "movl %c[api](%%eax), %%ecx \n"                     \
+            "jmp *%%ecx                 \n"                     \
+            "out" #_api ": ret          \n"                     \
+            :                                                   \
+            : [tls] "i"(TLS_SLOT_OPENGL_API*4),                 \
+              [api] "i"(__builtin_offsetof(gl_hooks_t, gl._api))    \
+            :                                                   \
+            );
+
 #elif defined(__mips__) && !USE_SLOW_BINDING
 
     #define API_ENTRY(_api) __attribute__((noinline)) _api