Advertisement
sbalko74

Untitled

May 7th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6.  
  7. #include "ppapi/c/pp_bool.h"
  8. #include "ppapi/c/pp_errors.h"
  9. #include "ppapi/c/pp_module.h"
  10. #include "ppapi/c/pp_instance.h"
  11.  
  12. #include "ppapi/c/ppp.h"
  13. #include "ppapi/c/ppp_instance.h"
  14.  
  15. typedef uint16_t vec_uint16_t __attribute__((vector_size(16)));
  16.  
  17. #define LENGTH 64
  18.  
  19. static int testfunc(uint8_t *a, uint8_t *b) {
  20. vec_uint16_t sumv = {0, 0, 0, 0, 0, 0, 0, 0};
  21. vec_uint16_t v1, v2, gt;
  22.  
  23.  
  24. for (int x=0; x<LENGTH; x+=8) {
  25. v1 = (vec_uint16_t){a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]};
  26. v2 = (vec_uint16_t){b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]};
  27.  
  28. gt = v1>v2;
  29. sumv += (gt & (v1-v2)) + (~gt & (v2-v1));
  30. }
  31. return sumv[0]+sumv[1]+sumv[2]+sumv[3]+
  32. sumv[4]+sumv[5]+sumv[6]+sumv[7];
  33. }
  34.  
  35. static PP_Bool Instance_DidCreate(PP_Instance instance,
  36. uint32_t argc,
  37. const char* argn[],
  38. const char* argv[]) {
  39.  
  40. printf("Instance_DidCreate\n");
  41.  
  42. srand(time(NULL));
  43.  
  44. uint8_t a[LENGTH], b[LENGTH];
  45. for (int i=0; i<LENGTH; ++i) {
  46. a[i] = rand() % 256;
  47. b[i] = rand() % 256;
  48. printf("a[%i]=%i, b[%i]=%i\n", i, a[i], i, b[i]);
  49. }
  50.  
  51. int sum = testfunc(a, b);
  52. printf("sum: %i\n", sum);
  53.  
  54. return PP_TRUE;
  55. }
  56.  
  57. static void Instance_DidDestroy(PP_Instance instance) {
  58. printf("Instance_DidDestroy\n");
  59. }
  60.  
  61. static void Instance_DidChangeView(PP_Instance instance, PP_Resource view) {
  62. printf("Instance_DidChangeView\n");
  63. }
  64.  
  65. static void Instance_DidChangeFocus(PP_Instance instance, PP_Bool has_focus) {
  66. printf("Instance_DidChangeFocus\n");
  67. }
  68.  
  69. static PP_Bool Instance_HandleDocumentLoad(PP_Instance instance, PP_Resource url_loader) {
  70. printf("Instance_HandleDocumentLoad\n");
  71. return PP_FALSE;
  72. }
  73.  
  74. PP_EXPORT const void* PPP_GetInterface(const char* interface_name) {
  75. // Create structs for each PPP interface.
  76. // Assign the interface functions to the data fields.
  77. if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) {
  78. static PPP_Instance instance_interface = {
  79. &Instance_DidCreate,
  80. &Instance_DidDestroy,
  81. &Instance_DidChangeView,
  82. &Instance_DidChangeFocus,
  83. &Instance_HandleDocumentLoad
  84. };
  85. return &instance_interface;
  86. }
  87.  
  88. // Return NULL for interfaces that you do not implement.
  89. return NULL;
  90. }
  91.  
  92. // Define PPP_InitializeModule, the entry point of your module.
  93. // Retrieve the API for the browser-side (PPB) interfaces you will use.
  94. PP_EXPORT int32_t PPP_InitializeModule(PP_Module module, PPB_GetInterface get_browser_interface) {
  95. printf("PPP_InitializeModule\n");
  96.  
  97. return PP_OK;
  98. }
  99.  
  100. PP_EXPORT void PPP_ShutdownModule() {
  101. printf("PPP_ShutdownModule\n");
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement