asm.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (C) 2026 Waldemar Brodkorb <wbx@uclibc-ng.org>
  3. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. */
  5. /* Miscellaneous macros.
  6. Copyright (C) 2022-2026 Free Software Foundation, Inc.
  7. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  11. The GNU C Library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with the GNU C Library. If not, see
  17. <https://www.gnu.org/licenses/>. */
  18. #ifndef _SYS_ASM_H
  19. #define _SYS_ASM_H
  20. #include <sys/regdef.h>
  21. /* Macros to handle different pointer/register sizes for 32/64-bit code. */
  22. #if __loongarch_grlen == 64
  23. #define SZREG 8
  24. #define REG_L ld.d
  25. #define REG_S st.d
  26. #define SRLI srli.d
  27. #define SLLI slli.d
  28. #define ADDI addi.d
  29. #define ADD add.d
  30. #define SUB sub.d
  31. #define LI li.d
  32. #define BSTRINS bstrins.d
  33. #elif __loongarch_grlen == 32
  34. #define SZREG 4
  35. #define REG_L ld.w
  36. #define REG_S st.w
  37. #define SRLI srli.w
  38. #define SLLI slli.w
  39. #define ADDI addi.w
  40. #define ADD add.w
  41. #define SUB sub.w
  42. #define LI li.w
  43. #define BSTRINS bstrins.w
  44. #else
  45. #error __loongarch_grlen must equal 32 or 64
  46. #endif
  47. #if __loongarch_frlen == 64
  48. #define SZFREG 8
  49. #define FREG_L fld.d
  50. #define FREG_S fst.d
  51. #elif __loongarch_frlen == 32
  52. #define SZFREG 4
  53. #define FREG_L fld.s
  54. #define FREG_S fst.s
  55. #endif
  56. #define SZVREG 16
  57. #define SZXREG 32
  58. /* Declare leaf routine.
  59. The usage of macro LEAF/ENTRY is as follows:
  60. 1. LEAF(fcn) -- the align value of fcn is .align 3 (default value)
  61. 2. LEAF(fcn, 6) -- the align value of fcn is .align 6
  62. */
  63. #define LEAF_IMPL(symbol, aln, ...) \
  64. .text; \
  65. .globl symbol; \
  66. .align aln; \
  67. .type symbol, @function; \
  68. symbol:
  69. #define LEAF(...) LEAF_IMPL(__VA_ARGS__, 3)
  70. #define ENTRY(...) LEAF(__VA_ARGS__)
  71. #define LEAF_NO_ALIGN(symbol) \
  72. .text; \
  73. .globl symbol; \
  74. .type symbol, @function; \
  75. symbol:
  76. #define ENTRY_NO_ALIGN(symbol) LEAF_NO_ALIGN(symbol)
  77. /* Mark end of function. */
  78. #undef END
  79. #define END(function) \
  80. .size function, .- function;
  81. /* Stack alignment. */
  82. #define ALMASK ~15
  83. #endif /* sys/asm.h */