1、Hardware Synthesizable Exceptions using ContinuationsPaul TengMcGill University,CanadaChristophe DubachMcGill University/MILA,Canada1ASPDAC 25,Thursday,January 23,2025,Tokyo,Japanint mydiv(int r)return 100/r;int main(int n)return mydiv(n);2Code that is potentially erroneousint mydiv(int r)return 100
2、/r;int main(int n)return mydiv(n);3Code that is potentially erroneousMaybe your codeDivides by zeroOverflows during computationAccesses invalid parts of an arraySomething else?Solution:Runtime Exceptions4int mydiv(int r)if(r=0)throw std:runtime_error(Cannot divide by zero);return 100/r;int main(int
3、n)return mydiv(n);5throw:an abort that can be handled laterint mydiv(int r)if(r=0)throw std:runtime_error(Cannot divide by zero);return 100/r;int main(int n)return mydiv(n);6int mydiv(int r)if(r=0)throw std:runtime_error(Cannot divide by zero);return 100/r;int main(int n)try return mydiv(n);catch(.)
4、return INT_MAX;7try/catch:the handler for the abortsRuntime exceptions:try/catch/throwEither throws on error or continues on success(error and success cases are disjoint)Typical software implementation depends a call stack +HLS prefers plain state machines over call stack =HLS tools do not support e
5、xceptions8Stepping through runtime exceptions9 1.int mydiv(int r)2.if(r=0)3.throw std:runtime_error(Cannot divide by zero);4.return 100/r;5.6.int main(int n)7.try 8.return mydiv(n);9.catch(.)10.return INT_MAX;11.12.10 1.int mydiv(int r)2.if(r=0)3.throw std:runtime_error(Cannot divide by zero);4.retu
6、rn 100/r;5.6.int main(int n)7.try 8.return mydiv(n);9.catch(.)10.return INT_MAX;11.12.11main(0)External code 1.int mydiv(int r)2.if(r=0)3.throw std:runtime_error(Cannot divide by zero);4.return 100/r;5.6.int main(int n)7.try 8.return mydiv(n);9.catch(.)10.return INT_MAX;11.12.12main(0)External code