質問編集履歴

7

修正

2017/12/16 04:50

投稿

strike1217
strike1217

スコア651

test CHANGED
File without changes
test CHANGED
@@ -470,4 +470,6 @@
470
470
 
471
471
  > C++だと、cstdintに「Nbitの精度を保証して、かつ処理効率が最速になる型」というものが定義されている
472
472
 
473
+
474
+
473
475
  単に、機械語だけだとすると、上記のような型を定義する必要はありませんよね??

6

追記

2017/12/16 04:50

投稿

strike1217
strike1217

スコア651

test CHANGED
File without changes
test CHANGED
@@ -465,3 +465,9 @@
465
465
  とのことです。
466
466
 
467
467
  これは、変数のサイズがCPUのレジスタ長と一致していれば相性が良いということなんでしょうかね??
468
+
469
+
470
+
471
+ > C++だと、cstdintに「Nbitの精度を保証して、かつ処理効率が最速になる型」というものが定義されている
472
+
473
+ 単に、機械語だけだとすると、上記のような型を定義する必要はありませんよね??

5

追記

2017/12/16 04:49

投稿

strike1217
strike1217

スコア651

test CHANGED
File without changes
test CHANGED
@@ -451,3 +451,17 @@
451
451
  [整数の型にint型ばかりを使うのは何故でしょうか。](https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q126888327)
452
452
 
453
453
  [C言語の型による処理速度の違い](https://oshiete.goo.ne.jp/qa/2168550.html)
454
+
455
+ [short と int の計算速度](http://dixq.net/forum/viewtopic.php?f=3&t=14756)
456
+
457
+ [最も速い数値型](http://cpp.aquariuscode.com/int_fast_t)
458
+
459
+
460
+
461
+ > CPUには得意なデータ型というものがあります。
462
+
463
+
464
+
465
+ とのことです。
466
+
467
+ これは、変数のサイズがCPUのレジスタ長と一致していれば相性が良いということなんでしょうかね??

4

追記

2017/12/16 04:46

投稿

strike1217
strike1217

スコア651

test CHANGED
File without changes
test CHANGED
@@ -439,3 +439,15 @@
439
439
  84d: 00 00 00
440
440
 
441
441
  ```
442
+
443
+
444
+
445
+ [追記3]
446
+
447
+ 同じようなことを議論しているサイトを見つけました。
448
+
449
+ [64bit化による処理速度の影響 ](https://social.msdn.microsoft.com/Forums/ja-JP/64914bbd-cb0c-4a90-9c99-375a44cf9137/64bit?forum=windowsgeneraldevelopmentissuesja)
450
+
451
+ [整数の型にint型ばかりを使うのは何故でしょうか。](https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q126888327)
452
+
453
+ [C言語の型による処理速度の違い](https://oshiete.goo.ne.jp/qa/2168550.html)

3

追記

2017/12/16 04:39

投稿

strike1217
strike1217

スコア651

test CHANGED
File without changes
test CHANGED
@@ -184,4 +184,258 @@
184
184
 
185
185
 
186
186
 
187
+ Intel Core i7-4650U @ 4x 3.3GHz
188
+
187
- CPUはIntelです。
189
+ Linux 64bit環境
190
+
191
+
192
+
193
+ [追記2]
194
+
195
+ objdump -d による結果を載せます。64bitコンパイルの方です。
196
+
197
+ main()を一応全部載せておきます。
198
+
199
+
200
+
201
+ ```ここに言語を入力
202
+
203
+ 000000000000068a <main>:
204
+
205
+ 68a: 55 push %rbp
206
+
207
+ 68b: 48 89 e5 mov %rsp,%rbp
208
+
209
+ 68e: 48 83 ec 50 sub $0x50,%rsp
210
+
211
+ 692: c6 45 f7 7b movb $0x7b,-0x9(%rbp)
212
+
213
+ 696: c6 45 f6 2d movb $0x2d,-0xa(%rbp)
214
+
215
+ 69a: e8 b1 fe ff ff callq 550 <clock@plt>
216
+
217
+ 69f: 89 45 f0 mov %eax,-0x10(%rbp)
218
+
219
+ 6a2: 48 c7 45 f8 00 00 00 movq $0x0,-0x8(%rbp)
220
+
221
+ 6a9: 00
222
+
223
+ 6aa: eb 13 jmp 6bf <main+0x35>
224
+
225
+ 6ac: 0f be 45 f7 movsbl -0x9(%rbp),%eax
226
+
227
+ 6b0: 0f be 4d f6 movsbl -0xa(%rbp),%ecx
228
+
229
+ 6b4: 99 cltd
230
+
231
+ 6b5: f7 f9 idiv %ecx
232
+
233
+ 6b7: 88 45 b5 mov %al,-0x4b(%rbp)
234
+
235
+ 6ba: 48 83 45 f8 01 addq $0x1,-0x8(%rbp)
236
+
237
+ 6bf: 48 81 7d f8 00 e1 f5 cmpq $0x5f5e100,-0x8(%rbp)
238
+
239
+ 6c6: 05
240
+
241
+ 6c7: 7e e3 jle 6ac <main+0x22>
242
+
243
+ 6c9: e8 82 fe ff ff callq 550 <clock@plt>
244
+
245
+ 6ce: 89 45 ec mov %eax,-0x14(%rbp)
246
+
247
+ 6d1: 8b 45 ec mov -0x14(%rbp),%eax
248
+
249
+ 6d4: 2b 45 f0 sub -0x10(%rbp),%eax
250
+
251
+ 6d7: f2 0f 2a c0 cvtsi2sd %eax,%xmm0
252
+
253
+ 6db: f2 0f 10 0d 95 02 00 movsd 0x295(%rip),%xmm1 # 978 <_IO_stdin_used+0xa8>
254
+
255
+ 6e2: 00
256
+
257
+ 6e3: f2 0f 5e c1 divsd %xmm1,%xmm0
258
+
259
+ 6e7: 48 8d 3d ea 01 00 00 lea 0x1ea(%rip),%rdi # 8d8 <_IO_stdin_used+0x8>
260
+
261
+ 6ee: b8 01 00 00 00 mov $0x1,%eax
262
+
263
+ 6f3: e8 68 fe ff ff callq 560 <printf@plt>
264
+
265
+ 6f8: 66 c7 45 ea 7b 00 movw $0x7b,-0x16(%rbp)
266
+
267
+ 6fe: 66 c7 45 e8 2d 00 movw $0x2d,-0x18(%rbp)
268
+
269
+ 704: e8 47 fe ff ff callq 550 <clock@plt>
270
+
271
+ 709: 89 45 f0 mov %eax,-0x10(%rbp)
272
+
273
+ 70c: 48 c7 45 f8 00 00 00 movq $0x0,-0x8(%rbp)
274
+
275
+ 713: 00
276
+
277
+ 714: eb 14 jmp 72a <main+0xa0>
278
+
279
+ 716: 0f bf 45 ea movswl -0x16(%rbp),%eax
280
+
281
+ 71a: 0f bf 75 e8 movswl -0x18(%rbp),%esi
282
+
283
+ 71e: 99 cltd
284
+
285
+ 71f: f7 fe idiv %esi
286
+
287
+ 721: 66 89 45 b6 mov %ax,-0x4a(%rbp)
288
+
289
+ 725: 48 83 45 f8 01 addq $0x1,-0x8(%rbp)
290
+
291
+ 72a: 48 81 7d f8 00 e1 f5 cmpq $0x5f5e100,-0x8(%rbp)
292
+
293
+ 731: 05
294
+
295
+ 732: 7e e2 jle 716 <main+0x8c>
296
+
297
+ 734: e8 17 fe ff ff callq 550 <clock@plt>
298
+
299
+ 739: 89 45 ec mov %eax,-0x14(%rbp)
300
+
301
+ 73c: 8b 45 ec mov -0x14(%rbp),%eax
302
+
303
+ 73f: 2b 45 f0 sub -0x10(%rbp),%eax
304
+
305
+ 742: f2 0f 2a c0 cvtsi2sd %eax,%xmm0
306
+
307
+ 746: f2 0f 10 0d 2a 02 00 movsd 0x22a(%rip),%xmm1 # 978 <_IO_stdin_used+0xa8>
308
+
309
+ 74d: 00
310
+
311
+ 74e: f2 0f 5e c1 divsd %xmm1,%xmm0
312
+
313
+ 752: 48 8d 3d a7 01 00 00 lea 0x1a7(%rip),%rdi # 900 <_IO_stdin_used+0x30>
314
+
315
+ 759: b8 01 00 00 00 mov $0x1,%eax
316
+
317
+ 75e: e8 fd fd ff ff callq 560 <printf@plt>
318
+
319
+ 763: 48 c7 45 e0 7b 00 00 movq $0x7b,-0x20(%rbp)
320
+
321
+ 76a: 00
322
+
323
+ 76b: 48 c7 45 d8 2d 00 00 movq $0x2d,-0x28(%rbp)
324
+
325
+ 772: 00
326
+
327
+ 773: e8 d8 fd ff ff callq 550 <clock@plt>
328
+
329
+ 778: 89 45 f0 mov %eax,-0x10(%rbp)
330
+
331
+ 77b: 48 c7 45 f8 00 00 00 movq $0x0,-0x8(%rbp)
332
+
333
+ 782: 00
334
+
335
+ 783: eb 13 jmp 798 <main+0x10e>
336
+
337
+ 785: 48 8b 45 e0 mov -0x20(%rbp),%rax
338
+
339
+ 789: 48 99 cqto
340
+
341
+ 78b: 48 f7 7d d8 idivq -0x28(%rbp)
342
+
343
+ 78f: 48 89 45 b8 mov %rax,-0x48(%rbp)
344
+
345
+ 793: 48 83 45 f8 01 addq $0x1,-0x8(%rbp)
346
+
347
+ 798: 48 81 7d f8 00 e1 f5 cmpq $0x5f5e100,-0x8(%rbp)
348
+
349
+ 79f: 05
350
+
351
+ 7a0: 7e e3 jle 785 <main+0xfb>
352
+
353
+ 7a2: e8 a9 fd ff ff callq 550 <clock@plt>
354
+
355
+ 7a7: 89 45 ec mov %eax,-0x14(%rbp)
356
+
357
+ 7aa: 8b 45 ec mov -0x14(%rbp),%eax
358
+
359
+ 7ad: 2b 45 f0 sub -0x10(%rbp),%eax
360
+
361
+ 7b0: f2 0f 2a c0 cvtsi2sd %eax,%xmm0
362
+
363
+ 7b4: f2 0f 10 0d bc 01 00 movsd 0x1bc(%rip),%xmm1 # 978 <_IO_stdin_used+0xa8>
364
+
365
+ 7bb: 00
366
+
367
+ 7bc: f2 0f 5e c1 divsd %xmm1,%xmm0
368
+
369
+ 7c0: 48 8d 3d 61 01 00 00 lea 0x161(%rip),%rdi # 928 <_IO_stdin_used+0x58>
370
+
371
+ 7c7: b8 01 00 00 00 mov $0x1,%eax
372
+
373
+ 7cc: e8 8f fd ff ff callq 560 <printf@plt>
374
+
375
+ 7d1: 48 c7 45 d0 7b 00 00 movq $0x7b,-0x30(%rbp)
376
+
377
+ 7d8: 00
378
+
379
+ 7d9: 48 c7 45 c8 2d 00 00 movq $0x2d,-0x38(%rbp)
380
+
381
+ 7e0: 00
382
+
383
+ 7e1: e8 6a fd ff ff callq 550 <clock@plt>
384
+
385
+ 7e6: 89 45 f0 mov %eax,-0x10(%rbp)
386
+
387
+ 7e9: 48 c7 45 f8 00 00 00 movq $0x0,-0x8(%rbp)
388
+
389
+ 7f0: 00
390
+
391
+ 7f1: eb 13 jmp 806 <main+0x17c>
392
+
393
+ 7f3: 48 8b 45 d0 mov -0x30(%rbp),%rax
394
+
395
+ 7f7: 48 99 cqto
396
+
397
+ 7f9: 48 f7 7d c8 idivq -0x38(%rbp)
398
+
399
+ 7fd: 48 89 45 c0 mov %rax,-0x40(%rbp)
400
+
401
+ 801: 48 83 45 f8 01 addq $0x1,-0x8(%rbp)
402
+
403
+ 806: 48 81 7d f8 00 e1 f5 cmpq $0x5f5e100,-0x8(%rbp)
404
+
405
+ 80d: 05
406
+
407
+ 80e: 7e e3 jle 7f3 <main+0x169>
408
+
409
+ 810: e8 3b fd ff ff callq 550 <clock@plt>
410
+
411
+ 815: 89 45 ec mov %eax,-0x14(%rbp)
412
+
413
+ 818: 8b 45 ec mov -0x14(%rbp),%eax
414
+
415
+ 81b: 2b 45 f0 sub -0x10(%rbp),%eax
416
+
417
+ 81e: f2 0f 2a c0 cvtsi2sd %eax,%xmm0
418
+
419
+ 822: f2 0f 10 0d 4e 01 00 movsd 0x14e(%rip),%xmm1 # 978 <_IO_stdin_used+0xa8>
420
+
421
+ 829: 00
422
+
423
+ 82a: f2 0f 5e c1 divsd %xmm1,%xmm0
424
+
425
+ 82e: 48 8d 3d 1b 01 00 00 lea 0x11b(%rip),%rdi # 950 <_IO_stdin_used+0x80>
426
+
427
+ 835: b8 01 00 00 00 mov $0x1,%eax
428
+
429
+ 83a: e8 21 fd ff ff callq 560 <printf@plt>
430
+
431
+ 83f: b8 00 00 00 00 mov $0x0,%eax
432
+
433
+ 844: c9 leaveq
434
+
435
+ 845: c3 retq
436
+
437
+ 846: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
438
+
439
+ 84d: 00 00 00
440
+
441
+ ```

2

追記

2017/12/15 12:47

投稿

strike1217
strike1217

スコア651

test CHANGED
File without changes
test CHANGED
@@ -181,3 +181,7 @@
181
181
  書くのを忘れていました。最適化は行っていません。
182
182
 
183
183
  今回の場合、最適化を行うと実験の意味がなくなってしまいます。
184
+
185
+
186
+
187
+ CPUはIntelです。

1

追記

2017/12/15 12:19

投稿

strike1217
strike1217

スコア651

test CHANGED
File without changes
test CHANGED
@@ -173,3 +173,11 @@
173
173
  わかる方いますか??
174
174
 
175
175
  Linux 64bit OS で実験しました。
176
+
177
+
178
+
179
+ [追記]
180
+
181
+ 書くのを忘れていました。最適化は行っていません。
182
+
183
+ 今回の場合、最適化を行うと実験の意味がなくなってしまいます。