1010
1111namespace aiebu {
1212
13- void
14- aie2ps_encoder::
15- fill_scratchpad (std::shared_ptr<section_writer> padwriter, const std::map<std::string, std::shared_ptr<scratchpad_info>>& scratchpads)
16- {
17- for (const auto & pad : scratchpads)
18- {
19- const auto & content = pad.second ->get_content ();
20- if (content.size ())
21- {
22- assert ((void (" Pad content size and size doesnt match\n " ), content.size () == pad.second ->get_size ()));
23- padwriter->write_bytes (content);
24- } else {
25- auto size = pad.second ->get_size ();
26- std::vector<uint8_t > zeros (size, 0x00 );
27- padwriter->write_bytes (zeros);
28- }
29- }
30- }
3113
3214void
3315aie2ps_encoder::
@@ -66,16 +48,10 @@ process(std::shared_ptr<preprocessed_output> input)
6648
6749 // for each colnum encode each page
6850 for (const auto & coldata: totalcoldata) {
69- auto colnum = coldata.first ;
7051 for (auto & lpage : coldata.second ->m_pages )
7152 page_writer (lpage, coldata.second ->m_scratchpad , coldata.second ->m_labelpageindex ,
7253 ctrlpkt_id_map, optimizatiom_level);
7354
74- if (coldata.second ->m_scratchpad .size ()) {
75- auto padwriter = std::make_shared<section_writer>(get_PadSectionName (colnum), code_section::data);
76- fill_scratchpad (padwriter, coldata.second ->m_scratchpad );
77- twriter.push_back (padwriter);
78- }
7955
8056 for (const auto & pair : ctrlpkt_id_map) {
8157 auto ctrlpktwriter = std::make_shared<section_writer>(pair.second , code_section::data);
@@ -180,6 +156,7 @@ page_writer(page& lpage, std::map<std::string, std::shared_ptr<scratchpad_info>>
180156 if (text->isOpcode ())
181157 {
182158 page_state->set_pos (textwriter->tell () - offset);
159+ page_state->set_is_save_restore_op (text->get_is_save_restore ()); // Track if this is save/restore op
183160 std::vector<uint8_t > ret = (*m_isa)[name]->serializer (text->get_operation ()->get_args ())
184161 ->serialize (page_state, tsym, colnum, pagenum);
185162 textwriter->write_bytes (ret);
@@ -218,6 +195,15 @@ page_writer(page& lpage, std::map<std::string, std::shared_ptr<scratchpad_info>>
218195 for (auto & arg : spad.second )
219196 {
220197 offset = page_state->parse_num_arg (arg);
198+ // Log patch information
199+ log_info () << " Patching scratchpad: label=" << spad.first
200+ << " , arg=" << arg
201+ << " , offset=" << offset
202+ << " , base=" << page_state->m_scratchpad [spad.first .substr (1 )]->get_base ()
203+ << " , offset=" << page_state->m_scratchpad [spad.first .substr (1 )]->get_offset ()
204+ << " , patch=" << (page_state->m_scratchpad [spad.first .substr (1 )]->get_base () +
205+ page_state->m_scratchpad [spad.first .substr (1 )]->get_offset ())
206+ << std::endl;
221207 patch57 (textwriter, datawriter, offset + static_cast <offset_type>(page_header.size ()),
222208 page_state->m_scratchpad [spad.first .substr (1 )]->get_base () + page_state->m_scratchpad [spad.first .substr (1 )]->get_offset ());
223209 }
@@ -243,6 +229,12 @@ patch57(const std::shared_ptr<section_writer> textwriter, std::shared_ptr<sectio
243229 uint64_t bd2 = datawriter->read_word (offset + 2 *4 ); // NOLINT
244230 uint64_t bd8 = datawriter->read_word (offset + 8 *4 ); // NOLINT
245231 uint64_t arg = ((bd8 & 0x1FF ) << 48 ) + ((bd2 & 0xFFFF ) << 32 ) + (bd1 & 0xFFFFFFFF ); // NOLINT
232+ // Add log for debugging patching
233+ log_info () << " aie2ps_encoder::patch57: offset=" << offset
234+ << " , patch=0x" << std::hex << patch
235+ << " , arg=0x" << std::hex << arg
236+ << " , after patch=0x" << std::hex << patch + arg
237+ << std::dec << std::endl;
246238 patch = arg + patch;
247239 datawriter->write_word_at (offset + 1 *4 , patch & 0xFFFFFFFF ); // NOLINT
248240 datawriter->write_word_at (offset + 2 *4 , ((patch >> 32 ) & 0xFFFF ) | (bd2 & 0xFFFF0000 )); // NOLINT
0 commit comments