c-kyhäelmä testaamassa prosessoria

En tiedä miten harvoin minkäkinlaiset tietokoneet tekevät fysikaalisen virheen eli kääntävät bitin ykkösestä nollaksi tai nollasta ykköseksi jostain ohjelmiston ulkopuolisesta syystä, eli kai kosmisen säteilyn tai kvanttifluktuaation seurauksena. Onko se yksi miljardista laskusta, sadasta miljardista vai...

Siksi tein tämän:

#include
#include

unsigned int x=1;
unsigned int a=1;
unsigned int b=1;
unsigned int c=1;
unsigned int d=1;
int tes=1;
main(void)
{
alku:
a=1; b=1; c=1; d=1;
for(x=1; x
4522
Äänestä

Muut lukivat myös

Vastaukset 4

Vanhimmat

tee ennemmin while-silmukassa.

aika pitkään saat odottaa virhettä jos koneesi on täysin kunnossa ja lämmöt pysyvät matalana.

kellota konetta hieman ja kokeile sitten, virheitä alkaa tulla useammin ja useammin mitä korkeammalle kellot nousevat.

Äänestä

Ohjelmasi on sellainen, että kääntäjät saattavat optimoida hyvinkin paljon koodia pois.

Normaalit optimoinnit päällä, eli komennolla "gcc -O2 a.c", kääntäjä optimoi koko for-silmukan muotoon

movl $0x7ffffff9,0x8049600
movl $0x7ffffff9,0x8049610
movl $0x7ffffff9,0x804960c
movl $0x7ffffff9,0x8049608
movl $0x7ffffff9,0x8049604

eli tässä sijoitetaan muuttujien x, a, b, c ja d muistipaikkoihin suoraan arvo 2147483641. Vielä pahempaa on, että koko seuraava if-lause, joka vertaa muuttujien erisuuruuksia, on myös optimoitu pois. Näin ollen ohjelma ei tulosta koskaan virhettä. Ei edes silloin, kun muistipaikkaan 0x8049608 olisi tallennettu kosmisen säteilyn takia väärä luku.

Kääntäjän tuottamaa koodia voi tutkia antamani käännös komennon jälkeen esimerkiksi komennolla "objdump -d a.out".

Jos optimointi estetään, ohjelmasi saa prosessorin tekemään mitä halusitkin.

Äänestä
  • Mikä parametri gcc:lle pitää antaa, jotta ne optimoinnit menee pois?

    Mikä on c-listaukseni yksinkertaisin monimutkaistus tai muutos, jotta kääntäjä ei normaaliparametreillä pääse tekemään mitä ei ole tarkoitettu?

    "
    "objdump -d a.out".
    "
    tulos:

    a.out: file format elf32-i386

    Disassembly of section .init:

    08048278 :
    8048278: 55 push %ebp
    8048279: 89 e5 mov %esp,%ebp
    804827b: 83 ec 08 sub $0x8,%esp
    804827e: e8 71 00 00 00 call 80482f4
    8048283: e8 c8 00 00 00 call 8048350
    8048288: e8 13 02 00 00 call 80484a0
    804828d: c9 leave
    804828e: c3 ret
    Disassembly of section .plt:

    08048290 :
    8048290: ff 35 08 96 04 08 pushl 0x8049608
    8048296: ff 25 0c 96 04 08 jmp *0x804960c
    804829c: 00 00 add %al,(%eax)
    ...

    080482a0 :
    80482a0: ff 25 10 96 04 08 jmp *0x8049610
    80482a6: 68 00 00 00 00 push $0x0
    80482ab: e9 e0 ff ff ff jmp 8048290

    080482b0 :
    80482b0: ff 25 14 96 04 08 jmp *0x8049614
    80482b6: 68 08 00 00 00 push $0x8
    80482bb: e9 d0 ff ff ff jmp 8048290

    080482c0 :
    80482c0: ff 25 18 96 04 08 jmp *0x8049618
    80482c6: 68 10 00 00 00 push $0x10
    80482cb: e9 c0 ff ff ff jmp 8048290
    Disassembly of section .text:

    080482d0 :
    80482d0: 31 ed xor %ebp,%ebp
    80482d2: 5e pop %esi
    80482d3: 89 e1 mov %esp,%ecx
    80482d5: 83 e4 f0 and $0xfffffff0,%esp
    80482d8: 50 push %eax
    80482d9: 54 push %esp
    80482da: 52 push %edx
    80482db: 68 20 84 04 08 push $0x8048420
    80482e0: 68 30 84 04 08 push $0x8048430
    80482e5: 51 push %ecx
    80482e6: 56 push %esi
    80482e7: 68 80 83 04 08 push $0x8048380
    80482ec: e8 bf ff ff ff call 80482b0
    80482f1: f4 hlt
    80482f2: 90 nop
    80482f3: 90 nop

    080482f4 :
    80482f4: 55 push %ebp
    80482f5: 89 e5 mov %esp,%ebp
    80482f7: 53 push %ebx
    80482f8: 83 ec 04 sub $0x4,%esp
    80482fb: e8 00 00 00 00 call 8048300
    8048300: 5b pop %ebx
    8048301: 81 c3 04 13 00 00 add $0x1304,%ebx
    8048307: 8b 93 fc ff ff ff mov 0xfffffffc(%ebx),%edx
    804830d: 85 d2 test %edx,%edx
    804830f: 74 05 je 8048316
    8048311: e8 8a ff ff ff call 80482a0
    8048316: 58 pop %eax
    8048317: 5b pop %ebx
    8048318: c9 leave
    8048319: c3 ret
    804831a: 90 nop
    804831b: 90 nop
    804831c: 90 nop
    804831d: 90 nop
    804831e: 90 nop
    804831f: 90 nop

    08048320 :
    8048320: 55 push %ebp
    8048321: 89 e5 mov %esp,%ebp
    8048323: 83 ec 08 sub $0x8,%esp
    8048326: 80 3d 40 96 04 08 00 cmpb $0x0,0x8049640
    804832d: 74 0c je 804833b
    804832f: eb 1c jmp 804834d
    8048331: 83 c0 04 add $0x4,%eax
    8048334: a3 24 96 04 08 mov %eax,0x8049624
    8048339: ff d2 call *%edx
    804833b: a1 24 96 04 08 mov 0x8049624,%eax
    8048340: 8b 10 mov (%eax),%edx
    8048342: 85 d2 test %edx,%edx
    8048344: 75 eb jne 8048331
    8048346: c6 05 40 96 04 08 01 movb $0x1,0x8049640
    804834d: c9 leave
    804834e: c3 ret
    804834f: 90 nop

    08048350 :
    8048350: 55 push %ebp
    8048351: 89 e5 mov %esp,%ebp
    8048353: 83 ec 08 sub $0x8,%esp
    8048356: a1 2c 95 04 08 mov 0x804952c,%eax
    804835b: 85 c0 test %eax,%eax
    804835d: 74 12 je 8048371
    804835f: b8 00 00 00 00 mov $0x0,%eax
    8048364: 85 c0 test %eax,%eax
    8048366: 74 09 je 8048371
    8048368: c7 04 24 2c 95 04 08 movl $0x804952c,(%esp)
    804836f: ff d0 call *%eax
    8048371: c9 leave
    8048372: c3 ret
    8048373: 90 nop
    8048374: 90 nop
    8048375: 90 nop
    8048376: 90 nop
    8048377: 90 nop
    8048378: 90 nop
    8048379: 90 nop
    804837a: 90 nop
    804837b: 90 nop
    804837c: 90 nop
    804837d: 90 nop
    804837e: 90 nop
    804837f: 90 nop

    08048380 :
    8048380: 8d 4c 24 04 lea 0x4(%esp),%ecx
    8048384: 83 e4 f0 and $0xfffffff0,%esp
    8048387: ff 71 fc pushl 0xfffffffc(%ecx)
    804838a: 55 push %ebp
    804838b: 89 e5 mov %esp,%ebp
    804838d: 51 push %ecx
    804838e: 83 ec 24 sub $0x24,%esp
    8048391: a1 3c 96 04 08 mov 0x804963c,%eax
    8048396: c7 05 28 96 04 08 f9 movl $0x7ffffff9,0x8049628
    804839d: ff ff 7f
    80483a0: c7 05 38 96 04 08 f9 movl $0x7ffffff9,0x8049638
    80483a7: ff ff 7f
    80483aa: c7 05 34 96 04 08 f9 movl $0x7ffffff9,0x8049634
    80483b1: ff ff 7f
    80483b4: c7 05 30 96 04 08 f9 movl $0x7ffffff9,0x8049630
    80483bb: ff ff 7f
    80483be: c7 05 2c 96 04 08 f9 movl $0x7ffffff9,0x804962c
    80483c5: ff ff 7f
    80483c8: 89 44 24 04 mov %eax,0x4(%esp)
    80483cc: c7 04 24 ec 84 04 08 movl $0x80484ec,(%esp)
    80483d3: e8 e8 fe ff ff call 80482c0
    80483d8: a1 38 96 04 08 mov 0x8049638,%eax
    80483dd: c7 04 24 f4 84 04 08 movl $0x80484f4,(%esp)
    80483e4: 89 44 24 14 mov %eax,0x14(%esp)
    80483e8: a1 34 96 04 08 mov 0x8049634,%eax
    80483ed: 89 44 24 10 mov %eax,0x10(%esp)
    80483f1: a1 30 96 04 08 mov 0x8049630,%eax
    80483f6: 89 44 24 0c mov %eax,0xc(%esp)
    80483fa: a1 2c 96 04 08 mov 0x804962c,%eax
    80483ff: 89 44 24 08 mov %eax,0x8(%esp)
    8048403: a1 28 96 04 08 mov 0x8049628,%eax
    8048408: 89 44 24 04 mov %eax,0x4(%esp)
    804840c: e8 af fe ff ff call 80482c0
    8048411: 83 05 3c 96 04 08 01 addl $0x1,0x804963c
    8048418: e9 74 ff ff ff jmp 8048391
    804841d: 90 nop
    804841e: 90 nop
    804841f: 90 nop

    08048420 :
    8048420: 55 push %ebp
    8048421: 89 e5 mov %esp,%ebp
    8048423: 5d pop %ebp
    8048424: c3 ret
    8048425: 8d 74 26 00 lea 0x0(%esi),%esi
    8048429: 8d bc 27 00 00 00 00 lea 0x0(%edi),%edi

    08048430 :
    8048430: 55 push %ebp
    8048431: 89 e5 mov %esp,%ebp
    8048433: 57 push %edi
    8048434: 56 push %esi
    8048435: 53 push %ebx
    8048436: e8 5e 00 00 00 call 8048499
    804843b: 81 c3 c9 11 00 00 add $0x11c9,%ebx
    8048441: 83 ec 1c sub $0x1c,%esp
    8048444: e8 2f fe ff ff call 8048278
    8048449: 8d 83 18 ff ff ff lea 0xffffff18(%ebx),%eax
    804844f: 89 45 f0 mov %eax,0xfffffff0(%ebp)
    8048452: 8d 83 18 ff ff ff lea 0xffffff18(%ebx),%eax
    8048458: 29 45 f0 sub %eax,0xfffffff0(%ebp)
    804845b: c1 7d f0 02 sarl $0x2,0xfffffff0(%ebp)
    804845f: 8b 55 f0 mov 0xfffffff0(%ebp),%edx
    8048462: 85 d2 test %edx,%edx
    8048464: 74 2b je 8048491
    8048466: 31 ff xor %edi,%edi
    8048468: 89 c6 mov %eax,%esi
    804846a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
    8048470: 8b 45 10 mov 0x10(%ebp),%eax
    8048473: 83 c7 01 add $0x1,%edi
    8048476: 89 44 24 08 mov %eax,0x8(%esp)
    804847a: 8b 45 0c mov 0xc(%ebp),%eax
    804847d: 89 44 24 04 mov %eax,0x4(%esp)
    8048481: 8b 45 08 mov 0x8(%ebp),%eax
    8048484: 89 04 24 mov %eax,(%esp)
    8048487: ff 16 call *(%esi)
    8048489: 83 c6 04 add $0x4,%esi
    804848c: 39 7d f0 cmp %edi,0xfffffff0(%ebp)
    804848f: 75 df jne 8048470
    8048491: 83 c4 1c add $0x1c,%esp
    8048494: 5b pop %ebx
    8048495: 5e pop %esi
    8048496: 5f pop %edi
    8048497: 5d pop %ebp
    8048498: c3 ret

    08048499 :
    8048499: 8b 1c 24 mov (%esp),%ebx
    804849c: c3 ret
    804849d: 90 nop
    804849e: 90 nop
    804849f: 90 nop

    080484a0 :
    80484a0: 55 push %ebp
    80484a1: 89 e5 mov %esp,%ebp
    80484a3: 53 push %ebx
    80484a4: bb 1c 95 04 08 mov $0x804951c,%ebx
    80484a9: 83 ec 04 sub $0x4,%esp
    80484ac: a1 1c 95 04 08 mov 0x804951c,%eax
    80484b1: 83 f8 ff cmp $0xffffffff,%eax
    80484b4: 74 0c je 80484c2
    80484b6: 83 eb 04 sub $0x4,%ebx
    80484b9: ff d0 call *%eax
    80484bb: 8b 03 mov (%ebx),%eax
    80484bd: 83 f8 ff cmp $0xffffffff,%eax
    80484c0: 75 f4 jne 80484b6
    80484c2: 83 c4 04 add $0x4,%esp
    80484c5: 5b pop %ebx
    80484c6: 5d pop %ebp
    80484c7: c3 ret
    Disassembly of section .fini:

    080484c8 :
    80484c8: 55 push %ebp
    80484c9: 89 e5 mov %esp,%ebp
    80484cb: 53 push %ebx
    80484cc: 83 ec 04 sub $0x4,%esp
    80484cf: e8 00 00 00 00 call 80484d4
    80484d4: 5b pop %ebx
    80484d5: 81 c3 30 11 00 00 add $0x1130,%ebx
    80484db: e8 40 fe ff ff call 8048320
    80484e0: 59 pop %ecx
    80484e1: 5b pop %ebx
    80484e2: c9 leave
    80484e3: c3 ret

    Äänestä

  • Fysikaalikko kirjoitti:

    Mikä parametri gcc:lle pitää antaa, jotta ne optimoinnit menee pois?

    Mikä on c-listaukseni yksinkertaisin monimutkaistus tai muutos, jotta kääntäjä ei normaaliparametreillä pääse tekemään mitä ei ole tarkoitettu?

    "
    "objdump -d a.out".
    "
    tulos:

    a.out: file format elf32-i386

    Disassembly of section .init:

    08048278 :
    8048278: 55 push %ebp
    8048279: 89 e5 mov %esp,%ebp
    804827b: 83 ec 08 sub $0x8,%esp
    804827e: e8 71 00 00 00 call 80482f4
    8048283: e8 c8 00 00 00 call 8048350
    8048288: e8 13 02 00 00 call 80484a0
    804828d: c9 leave
    804828e: c3 ret
    Disassembly of section .plt:

    08048290 :
    8048290: ff 35 08 96 04 08 pushl 0x8049608
    8048296: ff 25 0c 96 04 08 jmp *0x804960c
    804829c: 00 00 add %al,(%eax)
    ...

    080482a0 :
    80482a0: ff 25 10 96 04 08 jmp *0x8049610
    80482a6: 68 00 00 00 00 push $0x0
    80482ab: e9 e0 ff ff ff jmp 8048290

    080482b0 :
    80482b0: ff 25 14 96 04 08 jmp *0x8049614
    80482b6: 68 08 00 00 00 push $0x8
    80482bb: e9 d0 ff ff ff jmp 8048290

    080482c0 :
    80482c0: ff 25 18 96 04 08 jmp *0x8049618
    80482c6: 68 10 00 00 00 push $0x10
    80482cb: e9 c0 ff ff ff jmp 8048290
    Disassembly of section .text:

    080482d0 :
    80482d0: 31 ed xor %ebp,%ebp
    80482d2: 5e pop %esi
    80482d3: 89 e1 mov %esp,%ecx
    80482d5: 83 e4 f0 and $0xfffffff0,%esp
    80482d8: 50 push %eax
    80482d9: 54 push %esp
    80482da: 52 push %edx
    80482db: 68 20 84 04 08 push $0x8048420
    80482e0: 68 30 84 04 08 push $0x8048430
    80482e5: 51 push %ecx
    80482e6: 56 push %esi
    80482e7: 68 80 83 04 08 push $0x8048380
    80482ec: e8 bf ff ff ff call 80482b0
    80482f1: f4 hlt
    80482f2: 90 nop
    80482f3: 90 nop

    080482f4 :
    80482f4: 55 push %ebp
    80482f5: 89 e5 mov %esp,%ebp
    80482f7: 53 push %ebx
    80482f8: 83 ec 04 sub $0x4,%esp
    80482fb: e8 00 00 00 00 call 8048300
    8048300: 5b pop %ebx
    8048301: 81 c3 04 13 00 00 add $0x1304,%ebx
    8048307: 8b 93 fc ff ff ff mov 0xfffffffc(%ebx),%edx
    804830d: 85 d2 test %edx,%edx
    804830f: 74 05 je 8048316
    8048311: e8 8a ff ff ff call 80482a0
    8048316: 58 pop %eax
    8048317: 5b pop %ebx
    8048318: c9 leave
    8048319: c3 ret
    804831a: 90 nop
    804831b: 90 nop
    804831c: 90 nop
    804831d: 90 nop
    804831e: 90 nop
    804831f: 90 nop

    08048320 :
    8048320: 55 push %ebp
    8048321: 89 e5 mov %esp,%ebp
    8048323: 83 ec 08 sub $0x8,%esp
    8048326: 80 3d 40 96 04 08 00 cmpb $0x0,0x8049640
    804832d: 74 0c je 804833b
    804832f: eb 1c jmp 804834d
    8048331: 83 c0 04 add $0x4,%eax
    8048334: a3 24 96 04 08 mov %eax,0x8049624
    8048339: ff d2 call *%edx
    804833b: a1 24 96 04 08 mov 0x8049624,%eax
    8048340: 8b 10 mov (%eax),%edx
    8048342: 85 d2 test %edx,%edx
    8048344: 75 eb jne 8048331
    8048346: c6 05 40 96 04 08 01 movb $0x1,0x8049640
    804834d: c9 leave
    804834e: c3 ret
    804834f: 90 nop

    08048350 :
    8048350: 55 push %ebp
    8048351: 89 e5 mov %esp,%ebp
    8048353: 83 ec 08 sub $0x8,%esp
    8048356: a1 2c 95 04 08 mov 0x804952c,%eax
    804835b: 85 c0 test %eax,%eax
    804835d: 74 12 je 8048371
    804835f: b8 00 00 00 00 mov $0x0,%eax
    8048364: 85 c0 test %eax,%eax
    8048366: 74 09 je 8048371
    8048368: c7 04 24 2c 95 04 08 movl $0x804952c,(%esp)
    804836f: ff d0 call *%eax
    8048371: c9 leave
    8048372: c3 ret
    8048373: 90 nop
    8048374: 90 nop
    8048375: 90 nop
    8048376: 90 nop
    8048377: 90 nop
    8048378: 90 nop
    8048379: 90 nop
    804837a: 90 nop
    804837b: 90 nop
    804837c: 90 nop
    804837d: 90 nop
    804837e: 90 nop
    804837f: 90 nop

    08048380 :
    8048380: 8d 4c 24 04 lea 0x4(%esp),%ecx
    8048384: 83 e4 f0 and $0xfffffff0,%esp
    8048387: ff 71 fc pushl 0xfffffffc(%ecx)
    804838a: 55 push %ebp
    804838b: 89 e5 mov %esp,%ebp
    804838d: 51 push %ecx
    804838e: 83 ec 24 sub $0x24,%esp
    8048391: a1 3c 96 04 08 mov 0x804963c,%eax
    8048396: c7 05 28 96 04 08 f9 movl $0x7ffffff9,0x8049628
    804839d: ff ff 7f
    80483a0: c7 05 38 96 04 08 f9 movl $0x7ffffff9,0x8049638
    80483a7: ff ff 7f
    80483aa: c7 05 34 96 04 08 f9 movl $0x7ffffff9,0x8049634
    80483b1: ff ff 7f
    80483b4: c7 05 30 96 04 08 f9 movl $0x7ffffff9,0x8049630
    80483bb: ff ff 7f
    80483be: c7 05 2c 96 04 08 f9 movl $0x7ffffff9,0x804962c
    80483c5: ff ff 7f
    80483c8: 89 44 24 04 mov %eax,0x4(%esp)
    80483cc: c7 04 24 ec 84 04 08 movl $0x80484ec,(%esp)
    80483d3: e8 e8 fe ff ff call 80482c0
    80483d8: a1 38 96 04 08 mov 0x8049638,%eax
    80483dd: c7 04 24 f4 84 04 08 movl $0x80484f4,(%esp)
    80483e4: 89 44 24 14 mov %eax,0x14(%esp)
    80483e8: a1 34 96 04 08 mov 0x8049634,%eax
    80483ed: 89 44 24 10 mov %eax,0x10(%esp)
    80483f1: a1 30 96 04 08 mov 0x8049630,%eax
    80483f6: 89 44 24 0c mov %eax,0xc(%esp)
    80483fa: a1 2c 96 04 08 mov 0x804962c,%eax
    80483ff: 89 44 24 08 mov %eax,0x8(%esp)
    8048403: a1 28 96 04 08 mov 0x8049628,%eax
    8048408: 89 44 24 04 mov %eax,0x4(%esp)
    804840c: e8 af fe ff ff call 80482c0
    8048411: 83 05 3c 96 04 08 01 addl $0x1,0x804963c
    8048418: e9 74 ff ff ff jmp 8048391
    804841d: 90 nop
    804841e: 90 nop
    804841f: 90 nop

    08048420 :
    8048420: 55 push %ebp
    8048421: 89 e5 mov %esp,%ebp
    8048423: 5d pop %ebp
    8048424: c3 ret
    8048425: 8d 74 26 00 lea 0x0(%esi),%esi
    8048429: 8d bc 27 00 00 00 00 lea 0x0(%edi),%edi

    08048430 :
    8048430: 55 push %ebp
    8048431: 89 e5 mov %esp,%ebp
    8048433: 57 push %edi
    8048434: 56 push %esi
    8048435: 53 push %ebx
    8048436: e8 5e 00 00 00 call 8048499
    804843b: 81 c3 c9 11 00 00 add $0x11c9,%ebx
    8048441: 83 ec 1c sub $0x1c,%esp
    8048444: e8 2f fe ff ff call 8048278
    8048449: 8d 83 18 ff ff ff lea 0xffffff18(%ebx),%eax
    804844f: 89 45 f0 mov %eax,0xfffffff0(%ebp)
    8048452: 8d 83 18 ff ff ff lea 0xffffff18(%ebx),%eax
    8048458: 29 45 f0 sub %eax,0xfffffff0(%ebp)
    804845b: c1 7d f0 02 sarl $0x2,0xfffffff0(%ebp)
    804845f: 8b 55 f0 mov 0xfffffff0(%ebp),%edx
    8048462: 85 d2 test %edx,%edx
    8048464: 74 2b je 8048491
    8048466: 31 ff xor %edi,%edi
    8048468: 89 c6 mov %eax,%esi
    804846a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
    8048470: 8b 45 10 mov 0x10(%ebp),%eax
    8048473: 83 c7 01 add $0x1,%edi
    8048476: 89 44 24 08 mov %eax,0x8(%esp)
    804847a: 8b 45 0c mov 0xc(%ebp),%eax
    804847d: 89 44 24 04 mov %eax,0x4(%esp)
    8048481: 8b 45 08 mov 0x8(%ebp),%eax
    8048484: 89 04 24 mov %eax,(%esp)
    8048487: ff 16 call *(%esi)
    8048489: 83 c6 04 add $0x4,%esi
    804848c: 39 7d f0 cmp %edi,0xfffffff0(%ebp)
    804848f: 75 df jne 8048470
    8048491: 83 c4 1c add $0x1c,%esp
    8048494: 5b pop %ebx
    8048495: 5e pop %esi
    8048496: 5f pop %edi
    8048497: 5d pop %ebp
    8048498: c3 ret

    08048499 :
    8048499: 8b 1c 24 mov (%esp),%ebx
    804849c: c3 ret
    804849d: 90 nop
    804849e: 90 nop
    804849f: 90 nop

    080484a0 :
    80484a0: 55 push %ebp
    80484a1: 89 e5 mov %esp,%ebp
    80484a3: 53 push %ebx
    80484a4: bb 1c 95 04 08 mov $0x804951c,%ebx
    80484a9: 83 ec 04 sub $0x4,%esp
    80484ac: a1 1c 95 04 08 mov 0x804951c,%eax
    80484b1: 83 f8 ff cmp $0xffffffff,%eax
    80484b4: 74 0c je 80484c2
    80484b6: 83 eb 04 sub $0x4,%ebx
    80484b9: ff d0 call *%eax
    80484bb: 8b 03 mov (%ebx),%eax
    80484bd: 83 f8 ff cmp $0xffffffff,%eax
    80484c0: 75 f4 jne 80484b6
    80484c2: 83 c4 04 add $0x4,%esp
    80484c5: 5b pop %ebx
    80484c6: 5d pop %ebp
    80484c7: c3 ret
    Disassembly of section .fini:

    080484c8 :
    80484c8: 55 push %ebp
    80484c9: 89 e5 mov %esp,%ebp
    80484cb: 53 push %ebx
    80484cc: 83 ec 04 sub $0x4,%esp
    80484cf: e8 00 00 00 00 call 80484d4
    80484d4: 5b pop %ebx
    80484d5: 81 c3 30 11 00 00 add $0x1130,%ebx
    80484db: e8 40 fe ff ff call 8048320
    80484e0: 59 pop %ecx
    80484e1: 5b pop %ebx
    80484e2: c9 leave
    80484e3: c3 ret

    gcc:stä saa optimoinnit saa pois päältä vivulla -O0 (eli iso oo ja nolla). man-sivun mukaan tämän pitäisi olla oletusarvo, mutta lähettämästäsi koodista for-silmukka oli optimoitu pois.

    Toinen hyödyllinen juttu tällaisia testejä tehdessä on avainsana "volatile". Jos määrittelet muuttujat näin:

    volatile unsigned int a=1;
    volatile unsigned int b=1;
    volatile unsigned int c=1;
    volatile unsigned int d=1;

    kerrot samalla kääntäjälle, että jokainen näihin muuttujiin tehty kirjoitus- ja lukuoperaatio pitää ihan oikeasti tehdä muistiin/muistista --- niitä ei saa optimoida pois, eikä myöskään tehdä vain prosessorin rekistereistä kirjoittaen/lukien.

    Äänestä

Kommentoi aloitusta


Fysikaalikko kirjoitti:

En tiedä miten harvoin minkäkinlaiset tietokoneet tekevät fysikaalisen virheen eli kääntävät bitin ykkösestä nollaksi tai nollasta ykköseksi jostain ohjelmiston ulkopuolisesta syystä, eli kai kosmisen säteilyn tai kvanttifluktuaation seurauksena. Onko se yksi miljardista laskusta, sadasta miljardista vai...

Siksi tein tämän:

#include
#include

unsigned int x=1;
unsigned int a=1;
unsigned int b=1;
unsigned int c=1;
unsigned int d=1;
int tes=1;
main(void)
{
alku:
a=1; b=1; c=1; d=1;
for(x=1; x

Anonyymi
5000

Ilmoita asiaton sisältö

  • Sisältää materiaalia, joka on loukkaavaa, herjaavaa, rasistista, uhkailevaa tai ahdistelevaa.

  • Materiaali sisältää nimiä, yhteystietoja tai muita henkilökohtaisia tietoja. Julkisuuden henkilöistä, julkisissa viroissa toimivista ihmisistä sekä yritysten vastuuhenkilöistä saa keskustella työhön liittyen. Myös yksityiselämään liittyvistä asioista voi keskustella siltä osin, kuin niistä on julkisesti kerrottu.

  • Sisältää lapsille haitallista tai heiltä kiellettyä materiaalia. Seksuaalinen sisältö on sallittua aiheeseen tarkoitetuilla palstoilla, joiden ikäraja on 18 vuotta.

  • Lainvastaista sisältöä voi olla mm. yksityiselämää loukkaavan tiedon levitys, kiihottaminen kansanryhmää vastaan, laiton uhkaaminen, alaikäisiin liittyvä seksuaalinen sisältö/grooming, petokset, identiteettivarkaudet, kunnianloukkaukset ja tekijänoikeusrikkomukset.

  • Sisältö ei liity palstan tai keskusteluketjun aiheeseen.

  • Viesti ei ole suomea tai ruotsia (pl. International Forums), se sisältää mainontaa, se sisältää tekijänoikeuksin suojattua materiaalia, se on massapostitus tai jokin muu syy.

Jaa keskustelu