rationale.qbk 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. [/
  2. Copyright Oliver Kowalke 2014.
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt
  6. ]
  7. [section:rationale Rationale]
  8. [heading No inline-assembler]
  9. Some newer compiler (for instance MSVC 10 for x86_64 and itanium) do not
  10. support inline assembler.
  11. [footnote [@http://msdn.microsoft.com/en-us/library/4ks26t93.aspx MSDN article
  12. 'Inline Assembler']].
  13. Inlined assembler generates code bloating which is not welcome on embedded
  14. systems.
  15. [heading fcontext_t]
  16. __boost_context__ provides the low level API fcontext_t which is
  17. implemented in assembler to provide context swapping operations.
  18. fcontext_t is the part to port to new platforms.
  19. [note Context switches do not preserve the signal mask on UNIX systems.]
  20. __fcontext__ is an opaque pointer.
  21. [section Other APIs ]
  22. [heading setjmp()/longjmp()]
  23. C99 defines `setjmp()`/`longjmp()` to provide non-local jumps but it does not
  24. require that ['longjmp()] preserves the current stack frame. Therefore, jumping
  25. into a function which was exited via a call to ['longjmp()] is undefined
  26. [footnote ISO/IEC 9899:1999, 2005, 7.13.2.1:2].
  27. [#ucontext]
  28. [heading ucontext_t]
  29. Since POSIX.1-2004 `ucontext_t` is deprecated and was removed in POSIX.1-2008!
  30. The function signature of `makecontext()` is:
  31. void makecontext(ucontext_t *ucp, void (*func)(), int argc, ...);
  32. The third argument of `makecontext()` specifies the number of integer arguments
  33. that follow which will require function pointer cast if `func` will accept those
  34. arguments which is undefined in C99
  35. [footnote ISO/IEC 9899:1999, 2005, J.2].
  36. The arguments in the var-arg list are required to be integers, passing pointers
  37. in var-arg list is not guaranteed to work, especially it will fail for
  38. architectures where pointers are larger than integers.
  39. `ucontext_t` preserves signal mask between context switches which involves system
  40. calls consuming a lot of CPU cycles (ucontext_t is slower; a context switch
  41. takes [link performance ['two magnitutes of order more CPU cycles]] more than
  42. __fcontext__).
  43. [heading Windows fibers]
  44. A drawback of Windows Fiber API is that `CreateFiber()` does not accept a
  45. pointer to user allocated stack space preventing the reuse of stacks for other
  46. context instances. Because the Windows Fiber API requires to call
  47. `ConvertThreadToFiber()` if `SwitchFiber()` is called for a thread which has not
  48. been converted to a fiber. For the same reason `ConvertFiberToThread()`
  49. must be called after return from `SwitchFiber()` if the thread was forced to be
  50. converted to a fiber before (which is inefficient).
  51. if ( ! is_a_fiber() )
  52. {
  53. ConvertThreadToFiber( 0);
  54. SwitchToFiber( ctx);
  55. ConvertFiberToThread();
  56. }
  57. If the condition `_WIN32_WINNT >= _WIN32_WINNT_VISTA` is met function
  58. `IsThreadAFiber()` is provided in order to detect if the current thread was
  59. already converted. Unfortunately Windows XP + SP 2/3 defines
  60. `_WIN32_WINNT >= _WIN32_WINNT_VISTA` without providing `IsThreadAFiber()`.
  61. [endsect]
  62. [section x86 and floating-point env]
  63. [heading i386]
  64. "The FpCsr and the MxCsr register must be saved and restored before any call or return
  65. by any procedure that needs to modify them ..."
  66. [footnote 'Calling Conventions', Agner Fog].
  67. [heading x86_64]
  68. [heading Windows]
  69. MxCsr - "A callee that modifies any of the non-volatile fields within MxCsr must restore
  70. them before returning to its caller. Furthermore, a caller that has modified any
  71. of these fields must restore them to their standard values before invoking a callee ..."
  72. [footnote [@http://http://msdn.microsoft.com/en-us/library/yxty7t75.aspx MSDN article
  73. 'MxCsr']].
  74. FpCsr - "A callee that modifies any of the fields within FpCsr must restore them before
  75. returning to its caller. Furthermore, a caller that has modified any of these
  76. fields must restore them to their standard values before invoking a callee ..."
  77. [footnote [@http://http://msdn.microsoft.com/en-us/library/ms235300.aspx MSDN article
  78. 'FpCsr']].
  79. "The MMX and floating-point stack registers (MM0-MM7/ST0-ST7) are preserved across
  80. context switches. There is no explicit calling convention for these registers."
  81. [footnote [@http://msdn.microsoft.com/en-us/library/a32tsf7t%28VS.80%29.aspx MSDN article
  82. 'Legacy Floating-Point Support']].
  83. "The 64-bit Microsoft compiler does not use ST(0)-ST(7)/MM0-MM7".
  84. [footnote 'Calling Conventions', Agner Fog].
  85. "XMM6-XMM15 must be preserved"
  86. [footnote [@http://msdn.microsoft.com/en-us/library/9z1stfyw%28v=vs.100%29.aspx MSDN
  87. article 'Register Usage']]
  88. [heading SysV]
  89. "The control bits of the MxCsr register are callee-saved (preserved across calls),
  90. while the status bits are caller-saved (not preserved). The x87 status word register is
  91. caller-saved, whereas the x87 control word (FpCsr) is callee-saved."
  92. [footnote SysV ABI AMD64 Architecture Processor Supplement Draft Version 0.99.4, 3.2.1].
  93. [endsect]
  94. [endsect]