insn.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2015 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef __ASM_TILE_INSN_H
  15. #define __ASM_TILE_INSN_H
  16. #include <arch/opcode.h>
  17. static inline tilegx_bundle_bits NOP(void)
  18. {
  19. return create_UnaryOpcodeExtension_X0(FNOP_UNARY_OPCODE_X0) |
  20. create_RRROpcodeExtension_X0(UNARY_RRR_0_OPCODE_X0) |
  21. create_Opcode_X0(RRR_0_OPCODE_X0) |
  22. create_UnaryOpcodeExtension_X1(NOP_UNARY_OPCODE_X1) |
  23. create_RRROpcodeExtension_X1(UNARY_RRR_0_OPCODE_X1) |
  24. create_Opcode_X1(RRR_0_OPCODE_X1);
  25. }
  26. static inline tilegx_bundle_bits tilegx_gen_branch(unsigned long pc,
  27. unsigned long addr,
  28. bool link)
  29. {
  30. tilegx_bundle_bits opcode_x0, opcode_x1;
  31. long pcrel_by_instr = (addr - pc) >> TILEGX_LOG2_BUNDLE_SIZE_IN_BYTES;
  32. if (link) {
  33. /* opcode: jal addr */
  34. opcode_x1 =
  35. create_Opcode_X1(JUMP_OPCODE_X1) |
  36. create_JumpOpcodeExtension_X1(JAL_JUMP_OPCODE_X1) |
  37. create_JumpOff_X1(pcrel_by_instr);
  38. } else {
  39. /* opcode: j addr */
  40. opcode_x1 =
  41. create_Opcode_X1(JUMP_OPCODE_X1) |
  42. create_JumpOpcodeExtension_X1(J_JUMP_OPCODE_X1) |
  43. create_JumpOff_X1(pcrel_by_instr);
  44. }
  45. /* opcode: fnop */
  46. opcode_x0 =
  47. create_UnaryOpcodeExtension_X0(FNOP_UNARY_OPCODE_X0) |
  48. create_RRROpcodeExtension_X0(UNARY_RRR_0_OPCODE_X0) |
  49. create_Opcode_X0(RRR_0_OPCODE_X0);
  50. return opcode_x1 | opcode_x0;
  51. }
  52. #endif /* __ASM_TILE_INSN_H */