RicardasSim

testing C inline

Feb 26th, 2019
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.73 KB | None | 0 0
  1. /*
  2. testing C inline
  3. -std=c99 -Wall -Wextra -Wpedantic -Wshadow -O3
  4. */
  5.  
  6. //main.c
  7. //---------
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include "dar1.h"
  12. #include "dar2.h"
  13.  
  14. int main (int argc, char **argv)
  15. {
  16.  
  17.     float fV = 0.0f;
  18.     int iCount = 0;
  19.  
  20.     printf("Enter float number: ");
  21.     iCount = scanf("%f", &fV);
  22.  
  23.     if(iCount!=1||iCount==EOF)
  24.     {
  25.         printf("error occurred\n");
  26.         return 1;
  27.     }
  28.    
  29.     printf("Test 1: %f\n",testas1(1.0f,fV));
  30.  
  31.     printf("Test 2: %f\n",testas2(1.0f,fV));
  32.  
  33. return 0;
  34. }
  35.  
  36. //drc.h
  37. //---------
  38.  
  39. #ifndef DRC_H
  40. #define DRC_H
  41.  
  42. inline float tstPlus(float a)
  43. {
  44.     return a+1.0f;
  45. }
  46.  
  47. #endif
  48.  
  49. dar1.c
  50. ----------
  51.  
  52. #include <stdio.h>
  53. #include <stdlib.h>
  54.  
  55. #include "dar1.h"
  56. #include "drc.h"
  57.  
  58. inline float tstPlus(float);
  59.  
  60. float testas1(float a,float b)
  61. {
  62.     b = tstPlus(b);
  63.     return a+b;
  64. }
  65.  
  66. //dar2.c
  67. //----------
  68.  
  69. #include <stdio.h>
  70. #include <stdlib.h>
  71.  
  72. #include "dar2.h"
  73. #include "drc.h"
  74.  
  75. inline float tstPlus(float);
  76.  
  77. float testas2(float a,float b)
  78. {
  79.     b = tstPlus(b);
  80.     return a-b;
  81. }
  82.  
  83. //dar1.h
  84. //----------
  85.  
  86. #ifndef DAR1_H
  87. #define DAR1_H
  88.  
  89. float testas1(float,float);
  90.  
  91. #endif
  92.  
  93. //dar2.h
  94. //----------
  95.  
  96. #ifndef DAR2_H
  97. #define DAR2_H
  98.  
  99. float testas2(float, float);
  100.  
  101. #endif
  102.  
  103. //drc.h without inline
  104. //=====================
  105.  
  106. #ifndef DRC_H
  107. #define DRC_H
  108.  
  109. float tstPlus(float a);
  110.  
  111. #endif
  112.  
  113. //drc.c without inline
  114. //=====================
  115.  
  116. #include <stdio.h>
  117. #include <stdlib.h>
  118. #include <math.h>
  119.  
  120. #include "drc.h"
  121.  
  122. float tstPlus(float a)
  123. {
  124.     return a+1.0f;
  125. }
  126.  
  127. //dar1.c without inline
  128. //======================
  129.  
  130. #include <stdio.h>
  131. #include <stdlib.h>
  132.  
  133. #include "dar1.h"
  134. #include "drc.h"
  135.  
  136. float testas1(float a,float b)
  137. {
  138.     b = tstPlus(b);
  139.     return a+b;
  140. }
  141.  
  142. /*
  143.  *───────────────────*
  144. *  asm without inline *
  145.  *───────────────────*
  146.  
  147. sym.testas1 ();
  148.     sub rsp, 0x18
  149.     movss dword [local_ch], xmm0
  150.     movaps xmm0, xmm1
  151.     call sym.tstPlus
  152.     addss xmm0, dword [local_ch]
  153.     add rsp, 0x18
  154.     ret
  155.  
  156. sym.testas2 ();
  157.     sub rsp, 0x18
  158.     movss dword [local_ch], xmm0
  159.     movaps xmm0, xmm1
  160.     call sym.tstPlus
  161.     movss xmm2, dword [local_ch] ; [0xc:4]=0
  162.     add rsp, 0x18
  163.     subss xmm2, xmm0
  164.     movaps xmm0, xmm2
  165.     ret
  166.  
  167. sym.tstPlus ();
  168.     addss xmm0, dword [0x00000944]
  169.     ret
  170.  
  171.  *───────────────────*
  172. *    asm with inline   *
  173.  *───────────────────*
  174.  
  175. sym.testas1 ();
  176.     addss xmm1, dword [0x00000904]
  177.     addss xmm0, xmm1 ;
  178.     ret
  179.  
  180. sym.testas2 ();
  181.     addss xmm1, dword [0x00000904]
  182.     subss xmm0, xmm1
  183.     ret
  184.  
  185. */
Advertisement
Add Comment
Please, Sign In to add comment