Advertisement
chemoelectric

How to call memcpy

Sep 23rd, 2018
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. fn {}
  2. copy_cells {size_dest, size_src : table_size}
  3. {i_dest, i_src : nat | i_dest < size_dest;
  4. i_src < size_src}
  5. {p_dest, p_src : addr | null < p_dest; null < p_src}
  6. {n : pos | i_dest + n - 1 < size_dest;
  7. i_src + n - 1 < size_src}
  8. (pf_dest : !table_storage_v (size_dest, p_dest) >> _,
  9. pf_src : !table_storage_v (size_src, p_src) >> _,
  10. pf_nonoverlapping : NONOVERLAPPING (p_dest, n, p_src, n) |
  11. p_dest : ptr p_dest,
  12. i_dest : int i_dest,
  13. p_src : ptr p_src,
  14. i_src : int i_src,
  15. n : int) :<!wrt> void =
  16. let
  17. prval () =
  18. lemma_cell_subdivision_fits {size_dest} {i_dest, i_dest + n - 1} ()
  19. prval () =
  20. lemma_cell_subdivision_fits {size_src} {i_src, i_src + n - 1} ()
  21.  
  22. stadef pfd_size = (2 * sizeof bitmap) + (size_dest * sizeof node_i)
  23. stadef pfd1_size = (2 * sizeof bitmap) + (i_dest * sizeof node_i)
  24. stadef pfd2_size = n * sizeof node_i
  25. stadef pfd3_size = pfd_size - pfd1_size - pfd2_size
  26.  
  27. stadef pfs_size = (2 * sizeof bitmap) + (size_src * sizeof node_i)
  28. stadef pfs1_size = (2 * sizeof bitmap) + (i_src * sizeof node_i)
  29. stadef pfs2_size = n * sizeof node_i
  30. stadef pfs3_size = pfs_size - pfs1_size - pfs2_size
  31.  
  32. prval (pfd1, pfd2, pfd3) =
  33. array_v_subdivide3 {byte} {p_dest}
  34. {pfd1_size, pfd2_size, pfd3_size} pf_dest
  35. prval (pfs1, pfs2, pfs3) =
  36. array_v_subdivide3 {byte} {p_src}
  37. {pfs1_size, pfs2_size, pfs3_size} pf_src
  38.  
  39. val pd = ptr_add<byte> (p_dest, 2 * sizeof<bitmap>)
  40. val pd = ptr_add<byte> (pd, i_dest * sizeof<node_i>)
  41.  
  42. val ps = ptr_add<byte> (p_src, 2 * sizeof<bitmap>)
  43. val ps = ptr_add<byte> (ps, i_src * sizeof<node_i>)
  44.  
  45. val num_cells = $UN.cast {size_t n} n
  46.  
  47. val () = copy_bytes (pfd2, pfs2, assume_nonoverlapping (pfd2, pfs2) |
  48. pd, ps, num_cells * sizeof<node_i>)
  49.  
  50. prval () =
  51. pf_dest := array_v_join3 {byte} {p_dest}
  52. {pfd1_size, pfd2_size, pfd3_size}
  53. (pfd1, pfd2, pfd3)
  54. prval () =
  55. pf_src := array_v_join3 {byte} {p_src}
  56. {pfs1_size, pfs2_size, pfs3_size}
  57. (pfs1, pfs2, pfs3)
  58. in
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement