Three etudes on compiling, or How to use the Julia language to study generated machine code
https://doi.org/10.32517/2221-1993-2023-22-6-18-30
Abstract
The article demonstrates the ability of the Julia programming language to output an assembly text for any function written in Julia, which is interesting for education. The executable code for three illustrative examples is examined in detail: calculation by formula, branching and cyclic fragments. It is shown that Julia compiler really generates a carefully optimized program, trying to use the fastest executing instructions of the Intel processor. It successfully tries to do without time-consuming arithmetic operations (if possible, the values are calculated in advance, multiplication is replaced by shift and so on). The results for integer data are especially impressive. It is possible to see a whole range of optimization techniques, including those that take into account the features of the algorithm itself: for example, the compiler is able to predict the results of the simplest loop and exclude this loop from the final program. The problem of overflow control in a program is also discussed.
The consideration carried out convincingly confirms the usefulness of theoretical knowledge for developing an effectively working program. The described analysis technique is interesting for education, because the importance of a deep understanding by modern specialists of the programming process essence cannot be overestimated. The material can be useful in teaching programming ideas at different levels. The detailed presentation makes the article readable without special preparation.
About the Author
E. A. EreminRussian Federation
Perm
References
1. Антонюк В. А. Язык Julia как инструмент исследователя. М.: Физ. фак. МГУ имени М. В. Ломоносова, 2019. 48 с. https://cmp.phys.msu.ru/sites/default/files/VA_Antonyk_Julia_2019.pdf
2. Белов Г. В. Краткое описание языка программирования Julia и примеры его использования. М.: МГТУ им. Н. Э. Баумана, 2023. 105 с. http://ihed.ras.ru/~thermo/Julia/BriefdescriptionofJulialanguage.pdf
3. Белов Г. В., Аристова Н. М. О возможностях использования языка программирования Julia для решения научных и технических задач // Вестник МГТУ им. Н. Э. Баумана. Серия «Приборостроение». 2020. № 2 (131). С. 27–43. EDN: XODPOB. DOI: 10.18698/0236-3933-2020-2-27-43
4. Белов Г. В., Аристова Н. М., Мальцев М. А. Использование языка программирования Julia для расчета равновесного состава многокомпонентной газофазной системы // Вестник Объединенного института высоких температур. 2022. Т. 7. № 1. С. 52–55. EDN: OIBSEI.
5. Гук М. Ю. Процессоры Intel: от 8086 до Pentium II. СПб.: Питер, 1997. 224 с.
6. Еремин Е. А. Компилятор? Это довольно просто! Пермь: Изд-во ПРИПИТ, 1998. 120 с.
7. Еремин Е. А. Стек // Информатика. 2008. № 2. С. 37–38; 2008. № 3. С. 42–44; 2008. № 4. С. 41–44; 2008. № 6. С. 43–45; 2008. № 8. С. 43–45; 2008. № 9. С. 39–42. http://emc.orgfree.com/theory/raznoe/d4.html
8. Ефремова Т. Ф. Самый полный толковый словарь русского языка. В 3 т. М.: АСТ, 2015. 3312 с.
9. Иванова Е. М. Программная модель процессора и базовые инструкции процессоров Intel и MIPS. М.: НИУ ВШЭ, 2019. 139 с. https://publications.hse.ru/pubs/share/direct/317732672.pdf
10. ИТ-шники всего мира назвали самый любимый и самый ненавистный язык программирования // CNews, 4 августа 2021. https://www.cnews.ru/news/top/2021-08-03_programmisty_vsego_mira
11. Кулябов Д. С., Корольковa А. В. Компьютерная алгебра на Julia // Программирование. 2021. № 2. С. 44–50. EDN: HETTIQ.
12. Лопес Б. К., Аулер Р. LLVM: инфраструктура для разработки компиляторов. М.: ДМК Пресс, 2015. 342 с.
13. Ожегов С. И., Шведова Н. Ю. Толковый словарь русского языка. М.: Азбуковник, 1997. 944 с.
14. Оконешникова Е. А. Новый язык программирования в учебном процессе и научных исследованиях // Наука. Информатизация. Технологии. Образование. Материалы XIII международной научно-практической конференции (Екатеринбург, 24–28 февраля 2020 г.). Екатеринбург: Российский государственный профессионально-педагогический университет, 2020. С. 123–129. EDN: WVFCHN.
15. Смит Б. Э., Джонсон М. Т. Архитектура и программирование микропроцессора INTEL 80386. М.: Конкорд, 1992. 334 с.
16. Таненбаум Э. С. Архитектура компьютера. СПб.: Питер, 2003. 704 с.
17. Устинин Д. М. Использование языка научных вычислений Julia для моделирования внутриклеточных процессов методом броуновской динамики // Доклады Международной конференции «Математическая биология и биоинформатика». 2018. № 7. С. e29.1–e29.4. EDN: YPPYWL. DOI: 10.17537/icmbb18.93
18. Шагурин И. И., Бердышев Е. М. Процессоры семейства Intel P6. Архитектура, программирование, интерфейс. М.: Горячая линия — Телеком, 2000. 248 с.
19. Шадрин Ю. А., Грюмова Е. А., Гумирова А. И. Обзор языка программирования Julia // Технологии инженерных и информационных систем. 2019. № 3. С. 43–52. EDN: IIUXHP.
20. Шеррингтон М. Осваиваем язык Julia. Совершенствование мастерства в области аналитики и программирования. М: ДМК-Пресс, 2017. 416 с.
21. Шиндин А. В. Язык программирования математических вычислений Julia. Базовое руководство. Нижний Новгород: ННГУ, 2016. 24 с. http://www.unn.ru/books/met_files/JULIA_tutorial.pdf
22. Энгхейм Э. Julia в качестве второго языка. М.: ДМК Пресс, 2023. 446 с.
23. Ben-Ari M. Constructivism in computer science education // Journal of Computers in Mathematics and Science Teaching. 2001. Vol. 20. No. 1. P. 45–73.
24. Bezanson J., Chen J., Chung B., Karpinski S., Shah V. B., Vitek J., Zoubritzky L. Julia: Dynamism and performance reconciled by design // Proceedings of the ACM on Programming Languages. 2018. Vol. 2 (OOPSLA). P. 120.1–120.23. DOI: 10.1145/3276490
25. Bezanson J., Edelman A., Karpinski S., Shah V. B. Julia: A fresh approach to numerical computing // SIAM Review. 2017. Vol. 59. No. 1. P. 65–98. DOI: 10.1137/141000671
26. Bezanson J., Karpinski S., Shah V. B., Edelman A. Julia: A fast dynamic language for technical computing // arXiv preprint. arXiv:1209.5145. 2012. DOI: 10.48550/arXiv.1209.5145
27. Dijkstra E. W. Go to statement considered harmful // Communications of the ACM. 1968. Vol. 11. No. 3. P. 147–148. DOI: 10.1145/362929.362947. (Русский перевод: http://hosting.vspu.ac.ru/~chul/dijkstra/goto/goto.htm)
28. Du Boulay B. Some difficulties of learning to program // Journal of Educational Computing Research. 1986. Vol. 2. No. 1. P. 57–73. DOI: 10.2190/3LFX-9RRF-67T8-UVK9
29. Eremin E. A. Educational Pascal compiler into MMIX code // Proceedings of the 6th Baltic Sea Conference on Computing Education Research, Koli Calling. 2007. P. 143–144. EDN: MWQNJR.
30. Gao K., Mei G., Piccialli F., Cuomo S., Tu J., Huo Z. Julia language in machine learning: Algorithms, applications, and open issues // Computer Science Review. 2020. Vol. 37. P. 100254.1–100254.13. DOI: 10.1016/j.cosrev.2020.100254
31. Gevorkyan M. N., Korolkova A. V., Kulyabov D. S. Julia language features for processing statistical data // Discrete and Continuous Models and Applied Computational Science. 2023. Vol. 31. No. 1. P. 5–26. EDN: VNJCSU. DOI:10.22363/2658-46702023-31-1-5-26
32. Intel 64 and IA-32 Architectures Software Developer’s Manual. 2023. 5066 p. http://asmcourse.cs.msu.ru/wp-content/uploads/2022/01/325383-sdm-vol-2abcd.pdf
33. Lattner C. LLVM // The Architecture of Open Source Applications. 2011. Vol. 1. P. 155–170. (Русский перевод: https://rus-linux.net/MyLDP/BOOKS/Architecture-Open-Source-Applications/Vol-1/llvm-1.html)
34. Lattner C., Adve V. LLVM: a compilation framework for lifelong program analysis & transformation // Proceedings of the International Symposium on Code Generation and Optimization (CGO 2004). San Jose, CA, USA, 2004. P. 75–86. DOI: 10.1109/CGO.2004.1281665
35. Miller E. Why I’m betting on Julia. https://www.evanmiller.org/why-im-betting-on-julia.html. (Русский перевод: https://habr.com/ru/articles/210298/)
36. Nazarathy Y., Klok H. Statistics with Julia: Fundamentals for data science, machine learning and artificial intelligence. Springer Series in the Data Sciences. Springer Nature, 2021. 527 p. DOI: 10.1007/978-3-030-70901-3
37. Salceanu A. Julia Programming Projects: Learn Julia 1.x by building apps for data analysis, visualization, machine learning, and the web. Birmingham: Packt Publishing Ltd, 2018. 500 p.
38. Sengupta A., Edelman A. Julia High Performance: Optimizations, distributed computing, multithreading, and GPU programming with Julia 1.0 and beyond. 2nd Edition. Birmingham: Packt Publishing Ltd, 2019. 218 p.
39. The Julia Language. V.1.9.2. The Julia Project. July 6, 2023. 1644 p. https://docs.julialang.org/en/v1/
Review
For citations:
Eremin E.A. Three etudes on compiling, or How to use the Julia language to study generated machine code. Informatics in school. 2023;(6):18-30. (In Russ.) https://doi.org/10.32517/2221-1993-2023-22-6-18-30