program_jun_quick.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Aplica o back-end do juninho
  2. @target : mipsjun
  3. // Especifica o tipo de metodo empregado para salvar o resultado da compilação
  4. //@export : MultCoreJun
  5. @export : simulation
  6. // Diretorio onde o resultado da compilação será gravado
  7. @outputDirectory : `C:\Users\EUGENIO CARVALHO\Desktop\tmp\lu`
  8. // Quantidade de palavras de um bloco 32 palavras de 4bytes
  9. @cacheBlockSize: `32`
  10. /**
  11. Profile de compilacao do back-end
  12. O formato da string é um json que descreve um array de definições de cada core
  13. {
  14. "stackBaseAddress" : 5888, -> endereço da base da pilha do core em questão
  15. "initFunction": "multiplica(0)", -> define a main de cada core. aceita ate 4 parametros com valores de constantes
  16. "id": "core0" -> label que define o codigo de cada core
  17. },
  18. Se "stackBaseAddress" não for definido o compilador irá inferir o valor iniciando do ultimo endereço da memoria
  19. */
  20. @profile: `[
  21. {
  22. "id" : "core0",
  23. "initFunction" : "bitCount(0)",
  24. "filename" : "%s_core_0.txt"
  25. },
  26. {
  27. "id" : "core1",
  28. "initFunction" : "bitCount(18750)",
  29. "filename" : "%s_core_1.txt"
  30. },
  31. {
  32. "id" : "core2",
  33. "initFunction" : "bitCount(37500)",
  34. "filename" : "%s_core_2.txt"
  35. },
  36. {
  37. "id" : "core3",
  38. "initFunction" : "bitCount(56250)",
  39. "filename" : "%s_core_3.txt"
  40. }
  41. ]`
  42. package main;
  43. const (
  44. ArraySize = 8
  45. )
  46. var (
  47. arr [ArraySize]int32
  48. )
  49. /* This function is same in both iterative and recursive*/
  50. func partition(l, h int32) int32 {
  51. var (
  52. limit, index, x, i, tmp int32
  53. )
  54. x = arr[h]
  55. i = l - 1
  56. for j := l; j < h; j++ {
  57. if arr[j] <= x {
  58. i++
  59. tmp = arr[i]
  60. arr[i] = arr[j]
  61. arr[j] = tmp
  62. }
  63. }
  64. index = i + 1
  65. //arr[h], arr[tmp] = , arr[h]
  66. tmp = arr[index]
  67. arr[index] = arr[h]
  68. arr[h] = tmp
  69. return i + 1
  70. }
  71. func quickSortIterative(l, h int32) {
  72. var (
  73. top, p int32
  74. // Create an auxiliary stack
  75. stack [ArraySize]int32
  76. // initialize top of stack
  77. )
  78. // push initial values of l and h to stack
  79. stack[top] = l
  80. top++
  81. stack[top] = h
  82. // Keep popping from stack while is not empty
  83. for top >= 0 {
  84. // Pop h and l
  85. h = stack[top]
  86. top--
  87. l = stack[top]
  88. top--
  89. // Set pivot element at its correct position
  90. // in sorted array
  91. p = partition(l, h)
  92. // If there are elements on left side of pivot,
  93. // then push left side to stack
  94. if p-1 > l {
  95. top++
  96. stack[top] = l
  97. top++
  98. stack[top] = p - 1
  99. }
  100. // If there are elements on right side of pivot,
  101. // then push right side to stack
  102. if p+1 < h {
  103. top++
  104. stack[top] = p + 1
  105. top++
  106. stack[top] = h
  107. }
  108. }
  109. }
  110. // Driver program to test above functions
  111. func main() {
  112. /*
  113. arr[0] = 4
  114. arr[1] = 3
  115. arr[2] = 5
  116. arr[3] = 2
  117. arr[4] = 1
  118. arr[5] = 3
  119. arr[6] = 2
  120. arr[7] = 3
  121. */
  122. size := ArraySize - 1
  123. j := 0
  124. for i := size; i > 0; i-- {
  125. arr[j] = i
  126. j++
  127. }
  128. //partition(0,7)
  129. quickSortIterative(0, 7)
  130. //quickSortIterative(0, 4)
  131. //quickSortIterative(4, 7)
  132. }