#include <ios.h>
#include <hw.h>
#include <iostypes.h>
#include <ioslibc.h>

#define STACK_SIZE 4096
const u8 _initStack[STACK_SIZE];
const u32 _initStackSize = sizeof(_initStack);
const u32 _initPriority = 10;

/* Thread created by idle process */
u8 testthrStack[1024]; /* 1024 is hardwired as stack size for this thread
                        * when the idle thread starts it. Please change
                        * it if you change this.
                        */

extern void memcpyNew(void *d, const void *s, u32 z);
extern void memcpySNew(void *d, const void *s, u32 z);
extern void memcpyBSD(void *d, const void *s, u32 z);
char src[4096] __attribute__((aligned(32)));
char dst[4096] __attribute__((aligned(32)));
void
__cpyTest(char *dst, char *src, u32 z)
{
  u32 start, end, i;
  memset(src, 0xa, z);
  memset(dst, 0xb, z);
  start = busRd32(SYS_TIMER_REG);
  for (i = 0; i < 100; ++i) {
      memcpy(dst, src, z);
      memcpy(dst, src, z);
      memcpy(dst, src, z);
      memcpy(dst, src, z);
      memcpy(dst, src, z);
  }
  end = busRd32(SYS_TIMER_REG);
  printf("%u %u\n", z, end - start);
}

void
main(u32 arg)
{
  u32 z;
//  char *dst_napa = (char *)0;
  for (z = 0; z <= 4096; z += 1) {
      __cpyTest(dst, src, z);
  }
  IOS_DestroyThread(0, NULL);
}
