Izlanish nuqtalari orasida bir nechta ko'rsatmalarga ruxsat berishda ISO-C muvofiq kodini qanday yozish kerak?

Menda nozik savol bor; Men ko'chma kodni yozishni istayman (shu sababli men so'nggi uchta ISO-C standarti ta'rifiga yopishib olganman) va mashinadan mustaqil emas (shuning uchun assembler bu savolga javob bermaydi), lekin derleyici komplektini bir necha bir CPU aylanishi davomida ko'rsatmalar).

Menga vergul operatoridan foydalanish hiyla-nayrang qilishini o'ylardim, lekin standartda, har bir koma bir navbati nuqta, shuning uchun buni qilmaydi.

Men bir nechta mustaqil topshiriqlardan, qo'shimchalar va hokazolardan foydalanmoqchiman (registr o'zgaruvchisi iloji boricha optimallashtirishni va operatsiyalarning mustaqilligini ko'rsatadi).

Hech kimning fikri yo'qmi?

1

8 javoblar

Derivatorni optimallashtirish qilsin.

Derleyici mustaqilligini va o'zaro ta'sirsizligini tan olganda, ketma-ketlik nuqtalari bo'ylab optimallashtirishi mumkin.

Masalan, kodda:

a = x+y;
b = y+z;

Bir derleyici, a va b funktsiyalarining bir-biridan to'liq mustaqil ekanligini va bir vaqtning o'zida ketma-ketlik nuqtasiga qaramay, em>.

Umumiy qoida sifatida, kompilyatordan ko'ra yaxshiroq ish qilolmaysiz. . Foydalanuvchining profili Derivat tezkor, samarali kod yaratish ishini bajarishi kerak va siz o'zingizning ishingizga e'tibor qaratishingiz kerak: bugsiz algoritmlar uchun aniq, aniq yo'riqnomalarni yozib oling. .

5
qo'shib qo'ydi

Derivatorni optimallashtirish qilsin.

Derleyici mustaqilligini va o'zaro ta'sirsizligini tan olganda, ketma-ketlik nuqtalari bo'ylab optimallashtirishi mumkin.

Masalan, kodda:

a = x+y;
b = y+z;

Bir derleyici, a va b funktsiyalarining bir-biridan to'liq mustaqil ekanligini va bir vaqtning o'zida ketma-ketlik nuqtasiga qaramay, em>.

Umumiy qoida sifatida, kompilyatordan ko'ra yaxshiroq ish qilolmaysiz. . Foydalanuvchining profili Derivat tezkor, samarali kod yaratish ishini bajarishi kerak va siz o'zingizning ishingizga e'tibor qaratishingiz kerak: bugsiz algoritmlar uchun aniq, aniq yo'riqnomalarni yozib oling. .

5
qo'shib qo'ydi

Derleyici kod ishlab chiqaradi. Protsessor uni bajaradi. Protsessor tsiklda bir nechta buyruqni bajarishi kerak, shuning uchun zamonaviy protsessorlar juda yaxshi. Agar operatsiyalar mustaqil bo'lsa, protsessor buni aniqlaydi.

Protsessor shuningdek ko'rsatmalarni o'zgartiradi va ko'pincha manba kodingizda hech qanday joyda bo'lmagan bir nechta ko'rsatmalarni bajaradi. Manba kodida yordam berish uchun hech narsa qila olmaysiz.

2
qo'shib qo'ydi

Derleyici kod ishlab chiqaradi. Protsessor uni bajaradi. Protsessor tsiklda bir nechta buyruqni bajarishi kerak, shuning uchun zamonaviy protsessorlar juda yaxshi. Agar operatsiyalar mustaqil bo'lsa, protsessor buni aniqlaydi.

Protsessor shuningdek ko'rsatmalarni o'zgartiradi va ko'pincha manba kodingizda hech qanday joyda bo'lmagan bir nechta ko'rsatmalarni bajaradi. Manba kodida yordam berish uchun hech narsa qila olmaysiz.

2
qo'shib qo'ydi

Sizning savolingiz chuqur yolg'ondir, chunki boshqa javob beruvchilar ta'kidladilar. (Kompilyatorlar odatda narsalarni qayta tartibga soladi va narsalar ketma-ketlik nuqtalari bilan ajralib turganda ham har qanday dahshatli narsalarni qiladilar, aksincha, ketma-ketlik bilan ajralib turilmaydigan ikkita narsalar belgilanmaydi - bu aniqlanmagan xatti-harakatlardir). Biroq, siz mumkin siz biroz ahmoqona usulda so'raganingizni bajaring.

Funktsiya chaqiruviga turli argumentlarni baholash bir-biriga nisbatan tartiblangan emas, shuning uchun quyidagi kabi bir qo'g'irchoq funktsiyani yaratishingiz mumkin:

void dont_sequence(int, int) {}

va shunga o'xshash tarzda foydalaning:

dont_sequence(i += 2, j += 4);

Shunga qaramay, men bunga hech qanday maqsad yo'qligiga ishonmayman. Bu men foydalanadigan kompilyatorga yordam bermaydi. Derleyici ko'rsatmalarga amal qilish shart emas; faqat sizning ko'rsatmangizga amal qilganidek, o'zini tutadigan kodni ishlab chiqarish talab etiladi, va zamonaviy kompilyatorlar bunga o'xshaydi.

1
qo'shib qo'ydi

Sizning savolingiz chuqur yolg'ondir, chunki boshqa javob beruvchilar ta'kidladilar. (Kompilyatorlar odatda narsalarni qayta tartibga soladi va narsalar ketma-ketlik nuqtalari bilan ajralib turganda ham har qanday dahshatli narsalarni qiladilar, aksincha, ketma-ketlik bilan ajralib turilmaydigan ikkita narsalar belgilanmaydi - bu aniqlanmagan xatti-harakatlardir). Biroq, siz mumkin siz biroz ahmoqona usulda so'raganingizni bajaring.

Funktsiya chaqiruviga turli argumentlarni baholash bir-biriga nisbatan tartiblangan emas, shuning uchun quyidagi kabi bir qo'g'irchoq funktsiyani yaratishingiz mumkin:

void dont_sequence(int, int) {}

va shunga o'xshash tarzda foydalaning:

dont_sequence(i += 2, j += 4);

Shunga qaramay, men bunga hech qanday maqsad yo'qligiga ishonmayman. Bu men foydalanadigan kompilyatorga yordam bermaydi. Derleyici ko'rsatmalarga amal qilish shart emas; faqat sizning ko'rsatmangizga amal qilganidek, o'zini tutadigan kodni ishlab chiqarish talab etiladi, va zamonaviy kompilyatorlar bunga o'xshaydi.

1
qo'shib qo'ydi

TL;DR there is no such trick available. Choose different language

1. C language was designed to be portable and machine-independent but does not have language constructs to clearly express data flow independence or other hints that might be utilized by compilers when targeting processors with different parallel granularity (see e.g. article Threading and Parallel Programming Constructs used in multicore systems development: Part 2 for discussion of such constructs).

2. Abstract machine-independent compiler target (which reflects current processor architectures) was described by computer scientist Donald Knuth as MMIX. There is also GCC compiler available that can target this processor. So you might check your C code against this output

3. For more detail explanation of how compilers and processors derive their hints (you call them sequencing points) see e.g. book Processor Architecture: From Dataflow to Superscalar and Beyond ; with 34 Tables - Jurij Silc, Borut Robic, Theo Ungerer

3. For list of portable and machine-independent languages that explicitly support paralelism see e.g. Wikipedia: List of concurrent and parallel programming languages

4. For some discussion about how to use C for parallel programming see e.g. Which is the best parallel programming language for initiating undergraduate students in the world of multicore/parallel computing?

0
qo'shib qo'ydi

TL;DR there is no such trick available. Choose different language

1. C language was designed to be portable and machine-independent but does not have language constructs to clearly express data flow independence or other hints that might be utilized by compilers when targeting processors with different parallel granularity (see e.g. article Threading and Parallel Programming Constructs used in multicore systems development: Part 2 for discussion of such constructs).

2. Abstract machine-independent compiler target (which reflects current processor architectures) was described by computer scientist Donald Knuth as MMIX. There is also GCC compiler available that can target this processor. So you might check your C code against this output

3. For more detail explanation of how compilers and processors derive their hints (you call them sequencing points) see e.g. book Processor Architecture: From Dataflow to Superscalar and Beyond ; with 34 Tables - Jurij Silc, Borut Robic, Theo Ungerer

3. For list of portable and machine-independent languages that explicitly support paralelism see e.g. Wikipedia: List of concurrent and parallel programming languages

4. For some discussion about how to use C for parallel programming see e.g. Which is the best parallel programming language for initiating undergraduate students in the world of multicore/parallel computing?

0
qo'shib qo'ydi