pkubaj commented on code in PR #3696:
URL: https://github.com/apache/brpc/pull/3696#discussion_r4440493245
##########
test/bthread_context_unittest.cpp:
##########
@@ -110,3 +111,238 @@ TEST(BthreadContextTest, preserves_xmm6_through_xmm15) {
} // namespace
#endif // BTHREAD_CONTEXT_PLATFORM_linux_x86_64
+
+#if defined(BTHREAD_CONTEXT_PLATFORM_linux_ppc64)
+
+namespace {
+
+constexpr size_t kStackSize = 64 * 1024;
+// Non-volatile floating-point state of the ELFv2 ABI: f14-f31 and, when
+// AltiVec is enabled, v20-v31. The layout is what jump_with_fp_state loads
+// and stores.
+constexpr size_t kFprCount = 18;
+#ifdef __ALTIVEC__
+constexpr size_t kVrCount = 12;
+#endif
+
+struct alignas(16) FpState {
+ double fprs[kFprCount]; // f14-f31 at offsets 0..143
+#ifdef __ALTIVEC__
+ uint8_t vrs[kVrCount][16]; // v20-v31 at offsets 144..335
+#endif
+};
+
+bthread_fcontext_t g_main_context;
+bthread_fcontext_t g_test_context;
+FpState g_clobber_state;
+bool g_context_saw_its_state;
+int g_context_entry_rounding_mode;
+int g_context_rounding_mode;
+
+extern "C" intptr_t jump_with_fp_state(
+ bthread_fcontext_t* old_context, bthread_fcontext_t new_context,
+ intptr_t value, const FpState* input, FpState* output);
+
+// Load the registers from *input, switch to new_context and store them into
+// *output once this context is resumed, all in one assembly function so the
+// compiler cannot use any of them in between. The output pointer lives in
+// r31 across the switch, which exercises the GPR part of the frame too.
+__asm__(
+".text\n"
+".align 2\n"
+".type jump_with_fp_state, @function\n"
+"jump_with_fp_state:\n"
+" addis %r2, %r12, .TOC.-jump_with_fp_state@ha\n"
+" addi %r2, %r2, .TOC.-jump_with_fp_state@l\n"
+" .localentry jump_with_fp_state, . - jump_with_fp_state\n"
+" mflr %r0\n"
+" std %r0, 16(%r1)\n"
+" stdu %r1, -48(%r1)\n"
+" std %r2, 24(%r1)\n"
+" std %r31, 32(%r1)\n"
+" mr %r31, %r7\n"
+" lfd %f14, 0(%r6)\n"
+" lfd %f15, 8(%r6)\n"
+" lfd %f16, 16(%r6)\n"
+" lfd %f17, 24(%r6)\n"
+" lfd %f18, 32(%r6)\n"
+" lfd %f19, 40(%r6)\n"
+" lfd %f20, 48(%r6)\n"
+" lfd %f21, 56(%r6)\n"
+" lfd %f22, 64(%r6)\n"
+" lfd %f23, 72(%r6)\n"
+" lfd %f24, 80(%r6)\n"
+" lfd %f25, 88(%r6)\n"
+" lfd %f26, 96(%r6)\n"
+" lfd %f27, 104(%r6)\n"
+" lfd %f28, 112(%r6)\n"
+" lfd %f29, 120(%r6)\n"
+" lfd %f30, 128(%r6)\n"
+" lfd %f31, 136(%r6)\n"
+#ifdef __ALTIVEC__
+" li %r11, 144\n"
+" lvx %v20, %r6, %r11\n"
+" li %r11, 160\n"
+" lvx %v21, %r6, %r11\n"
+" li %r11, 176\n"
+" lvx %v22, %r6, %r11\n"
+" li %r11, 192\n"
+" lvx %v23, %r6, %r11\n"
+" li %r11, 208\n"
+" lvx %v24, %r6, %r11\n"
+" li %r11, 224\n"
+" lvx %v25, %r6, %r11\n"
+" li %r11, 240\n"
+" lvx %v26, %r6, %r11\n"
+" li %r11, 256\n"
+" lvx %v27, %r6, %r11\n"
+" li %r11, 272\n"
+" lvx %v28, %r6, %r11\n"
+" li %r11, 288\n"
+" lvx %v29, %r6, %r11\n"
+" li %r11, 304\n"
+" lvx %v30, %r6, %r11\n"
+" li %r11, 320\n"
+" lvx %v31, %r6, %r11\n"
+#endif
+" # preserve_fpu = false\n"
+" li %r6, 0\n"
+" bl bthread_jump_fcontext\n"
+" nop\n"
+" stfd %f14, 0(%r31)\n"
+" stfd %f15, 8(%r31)\n"
+" stfd %f16, 16(%r31)\n"
+" stfd %f17, 24(%r31)\n"
+" stfd %f18, 32(%r31)\n"
+" stfd %f19, 40(%r31)\n"
+" stfd %f20, 48(%r31)\n"
+" stfd %f21, 56(%r31)\n"
+" stfd %f22, 64(%r31)\n"
+" stfd %f23, 72(%r31)\n"
+" stfd %f24, 80(%r31)\n"
+" stfd %f25, 88(%r31)\n"
+" stfd %f26, 96(%r31)\n"
+" stfd %f27, 104(%r31)\n"
+" stfd %f28, 112(%r31)\n"
+" stfd %f29, 120(%r31)\n"
+" stfd %f30, 128(%r31)\n"
+" stfd %f31, 136(%r31)\n"
+#ifdef __ALTIVEC__
+" li %r11, 144\n"
+" stvx %v20, %r31, %r11\n"
+" li %r11, 160\n"
+" stvx %v21, %r31, %r11\n"
+" li %r11, 176\n"
+" stvx %v22, %r31, %r11\n"
+" li %r11, 192\n"
+" stvx %v23, %r31, %r11\n"
+" li %r11, 208\n"
+" stvx %v24, %r31, %r11\n"
+" li %r11, 224\n"
+" stvx %v25, %r31, %r11\n"
+" li %r11, 240\n"
+" stvx %v26, %r31, %r11\n"
+" li %r11, 256\n"
+" stvx %v27, %r31, %r11\n"
+" li %r11, 272\n"
+" stvx %v28, %r31, %r11\n"
+" li %r11, 288\n"
+" stvx %v29, %r31, %r11\n"
+" li %r11, 304\n"
+" stvx %v30, %r31, %r11\n"
+" li %r11, 320\n"
+" stvx %v31, %r31, %r11\n"
+#endif
+" ld %r31, 32(%r1)\n"
+" addi %r1, %r1, 48\n"
+" ld %r0, 16(%r1)\n"
+" mtlr %r0\n"
+" blr\n"
Review Comment:
Fixed in 73421c2eaae6: the helper saves the incoming f14-f31 and v20-v31 in
its frame on entry and restores them after the switched-in values have been
captured.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]