0

Is it possible to do modular arithmetic on integers with AVX or SSE? i.e. perform several mods all at once.

Bipman

Bipman
  • 53
  • 8
  • Yes but it's annoying, except in special cases. Do you have some more details? – harold Apr 28 '17 at 15:43
  • Yes, it's for speeding up one pad encryption. – Bipman Apr 28 '17 at 15:52
  • 1
    OTP? Isn't that just a XOR with a huge key? – harold Apr 28 '17 at 15:54
  • It can be but I wondered if it could be done on several say words at once. – Bipman Apr 28 '17 at 15:56
  • 1
    With XOR, trivially. I still don't get where the modular arithmetic comes in though. – harold Apr 28 '17 at 16:00
  • For what I am doing, mod arithmetic on several words at once would be good, if not then I'll do it conventionally. – Bipman Apr 28 '17 at 19:16
  • OK then the question is still, do you have more details - not a high level purpose, but specifically what operation are you executing. A general modulo operation is annoying, so it's important to know whether you're in any of the special cases. – harold Apr 28 '17 at 19:33
  • Forget mod arithmetic, I meant xor as per your message. x is the byte in the key (same length as file) and y is the byte from the message so x xor y produces z the encrypted byte. If several xor processes could be done at once it would save time with large files. – Bipman Apr 29 '17 at 06:32
  • 1
    In GCC and Clang you can just write a normal loop with byte-by-byte XORs and it will be vectorized automatically – harold Apr 29 '17 at 11:23
  • OK, thanks. Using assembler though. – Bipman Apr 29 '17 at 11:40
  • 1
    Ok well use `pxor` or `vpxor`, do you know how to do the rest? It's basically like [this](http://stackoverflow.com/a/9603039/555045) but XOR instead of ADD. – harold Apr 29 '17 at 11:44
  • Yep, that code looks good thanks. – Bipman Apr 29 '17 at 18:25
  • Is the actual question still relevant? If so, clarify if what you need (e.g., is the divisor a compile-time constant?) – chtz Jun 10 '17 at 11:19

0 Answers0