F16StagesTest.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright 2017 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "src/core/SkRasterPipeline.h"
  8. #include "tests/Test.h"
  9. DEF_TEST(F16Stages, r) {
  10. // Make sure SkRasterPipeline::load_f16 and store_f16 can handle a range of
  11. // ordinary (0<=x<=1) and interesting (x<0, x>1) values.
  12. float floats[16] = {
  13. 0.0f, 0.25f, 0.5f, 1.0f,
  14. -1.25f, -0.5f, 1.25f, 2.0f,
  15. 0,0,0,0, 0,0,0,0, // pad a bit to make sure we qualify for platform-specific code
  16. };
  17. uint64_t halfs[4] = {0,0,0,0};
  18. SkRasterPipeline_MemoryCtx f32 = { floats, 0 },
  19. f16 = { halfs, 0 };
  20. {
  21. SkRasterPipeline_<256> p;
  22. p.append(SkRasterPipeline:: load_f32, &f32);
  23. p.append(SkRasterPipeline::store_f16, &f16);
  24. p.run(0,0,16/4,1);
  25. }
  26. REPORTER_ASSERT(r, ((halfs[0] >> 0) & 0xffff) == 0x0000);
  27. REPORTER_ASSERT(r, ((halfs[0] >> 16) & 0xffff) == 0x3400);
  28. REPORTER_ASSERT(r, ((halfs[0] >> 32) & 0xffff) == 0x3800);
  29. REPORTER_ASSERT(r, ((halfs[0] >> 48) & 0xffff) == 0x3c00);
  30. REPORTER_ASSERT(r, ((halfs[1] >> 0) & 0xffff) == 0xbd00);
  31. REPORTER_ASSERT(r, ((halfs[1] >> 16) & 0xffff) == 0xb800);
  32. REPORTER_ASSERT(r, ((halfs[1] >> 32) & 0xffff) == 0x3d00);
  33. REPORTER_ASSERT(r, ((halfs[1] >> 48) & 0xffff) == 0x4000);
  34. {
  35. SkRasterPipeline_<256> p;
  36. p.append(SkRasterPipeline:: load_f16, &f16);
  37. p.append(SkRasterPipeline::store_f32, &f32);
  38. p.run(0,0,16/4,1);
  39. }
  40. REPORTER_ASSERT(r, floats[0] == 0.00f);
  41. REPORTER_ASSERT(r, floats[1] == 0.25f);
  42. REPORTER_ASSERT(r, floats[2] == 0.50f);
  43. REPORTER_ASSERT(r, floats[3] == 1.00f);
  44. REPORTER_ASSERT(r, floats[4] == -1.25f);
  45. REPORTER_ASSERT(r, floats[5] == -0.50f);
  46. REPORTER_ASSERT(r, floats[6] == 1.25f);
  47. REPORTER_ASSERT(r, floats[7] == 2.00f);
  48. }