News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

ChatGTP

Started by ken_k, Dec 16, 2022, 02:36 AM

Previous topic - Next topic

Parmin

Quote from: top204 on Feb 24, 2025, 09:55 AMI been trying to get on the other AI Chinese DeepSeek platform, but have not managed to yet. When I try to sign up, it does not send an email, and I have tried different valid email address' and waited long times for the email of the "code", but it never turns up.



Deepseek has stop registration for foreign users not too long ago.

https://www.registrationchina.com/articles/deepseek-blocks-foreign-registrations/

kcsl

I've been having problems with my ISR not being able to keep up with incoming CAN bus data when it's receiving large bursts of data from a PC, so off I went to do some optimisation work. There was some debug code to remove, I'd used a variable that didn't need to be a long, lots of little things that needed tidying up. Anyway, after my efforts everything was fine and it can now keep up. The one thing I didn't do was switch on the BASIC optimiser - I like to work with it off to save on compile times. Anyway, when I switched it on, it shaved another 1.5K off my program but what I didn't know was if it had done any work in my nice new shiny ISR. I started to look at the assembly but was getting a headache, so I gave the before optimisation and after optimisation assembler files to ChatGPT and said "you figure it out", and it did.

What I wanted to know is if I'd missed any big (or small) wins when I did my refactoring of the code.

ChatGPT said:
Yes, the optimiser did make changes to the interrupt service routine (ISR) code, but not in the logic or structure — it mainly optimized instruction sequences and reduced redundant instructions.

🔍 Key Observations
The logic and flow are nearly identical in both versions — the loop that reads 16 bytes from the CAN FIFO and stores it in your buffer is present in both and follows the same memory accesses (movff, decf, addwf, etc).

Instruction usage is marginally tighter in the optimiser-on version:

Fewer intermediate variables are used.

Some conditional branches and flag checks are done more efficiently.

The optimiser removes or simplifies some movlw 0 / addwfc sequences where possible.

Instruction ordering and register usage is a little more compact in the optimised version — for example, some goto vs bra, or register bank usage switches more efficiently.

No high-level logic or safety-critical code changes were made in the ISR between versions, which is excellent — it means your manual optimisation work is what truly improved performance.

✅ Conclusion
Your suspicion is correct: the optimiser probably did not significantly improve ISR performance. The improvement you're seeing now is almost entirely due to your own changes (saving 178 instructions), and the optimiser's savings likely came from other parts of the codebase.



I then asked:
But it's fair to say that it did remove instructions which can only help performance ?


ChatGPT said:
Yes — absolutely. It's fair and accurate to say that the optimiser did remove or tighten up instructions, and that helps performance, even if only marginally within the ISR.

Even if the savings weren't dramatic in the ISR itself, the optimiser:

✅ Eliminated redundant instructions

✅ Reduced register shuffling and flag handling overhead

✅ Compressed logic in subtle ways, especially in common code paths

✅ Freed up program memory, which can sometimes improve access efficiency (depending on paging)

So while your manual changes did the heavy lifting, the optimiser definitely contributed some extra polish — and in tight timing scenarios, every saved instruction counts.

You've now got a double-win:

The ISR works well even with optimisation off

And with it on, you've likely bought yourself additional safety margin on a busy bus



What I'm still amazed at is how quick it was. It took around 10 seconds for it to scan the two files and provide it's analysis.
There's no room for optimism in software or hardware engineering.

trastikata

Don't trust ChatGPT to de-compile PIC Assembler code!

When I tried, it got many of the mnemonics wrong, especially the bit tests, however the explanation it spitted out sounded so convincing, that it almost made me doubt my own logic  :)